Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
68f7b909
Commit
68f7b909
authored
11 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
Make shell buffer size a shell property
parent
04b9d7a1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/shell.h
+5
-3
5 additions, 3 deletions
sys/include/shell.h
sys/shell/shell.c
+8
-6
8 additions, 6 deletions
sys/shell/shell.c
with
13 additions
and
9 deletions
sys/include/shell.h
+
5
−
3
View file @
68f7b909
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#ifndef __SHELL_H
#ifndef __SHELL_H
#define __SHELL_H
#define __SHELL_H
#include
<stdint.h>
typedef
struct
shell_command_t
{
typedef
struct
shell_command_t
{
char
*
name
;
char
*
name
;
...
@@ -29,20 +30,21 @@ typedef struct shell_command_t {
...
@@ -29,20 +30,21 @@ typedef struct shell_command_t {
typedef
struct
shell_t
{
typedef
struct
shell_t
{
const
shell_command_t
*
command_list
;
const
shell_command_t
*
command_list
;
uint16_t
shell_buffer_size
;
int
(
*
readchar
)(
void
);
int
(
*
readchar
)(
void
);
void
(
*
put_char
)(
int
);
void
(
*
put_char
)(
int
);
}
shell_t
;
}
shell_t
;
#define SHELL_BUFFER_SIZE (127)
/**
/**
* @brief Initialize a shell object
* @brief Initialize a shell object
* @param shell Pointer to preallocated shell object
* @param shell Pointer to preallocated shell object
* @param shell_commands Pointer to shell command structure. See test_shell project for example.
* @param shell_commands Pointer to shell command structure. See test_shell project for example.
* @param shell_buffer_size The size of the shell buffer.
* @param read_char Pointer to input device read function. Should return exactly one byte or block.
* @param read_char Pointer to input device read function. Should return exactly one byte or block.
* @param put_char Pointer to output funtion. currently unused, shell code will use printf.
* @param put_char Pointer to output funtion. currently unused, shell code will use printf.
*/
*/
void
shell_init
(
shell_t
*
shell
,
/*@null@*/
const
shell_command_t
*
shell_commands
,
int
(
*
read_char
)(
void
),
void
(
*
put_char
)(
int
));
void
shell_init
(
shell_t
*
shell
,
/*@null@*/
const
shell_command_t
*
shell_commands
,
uint16_t
shell_buffer_size
,
int
(
*
read_char
)(
void
),
void
(
*
put_char
)(
int
));
/**
/**
* @brief Endless loop that waits for command and executes handler.
* @brief Endless loop that waits for command and executes handler.
...
...
This diff is collapsed.
Click to expand it.
sys/shell/shell.c
+
8
−
6
View file @
68f7b909
/**
/**
* Shell interpreter
* Shell interpreter
*
*
* Copyright (C) 2009, Freie Universitaet Berlin (FUB).
* Copyright (C) 2009, Freie Universitaet Berlin (FUB).
* Copyright (C) 2013, INRIA.
* Copyright (C) 2013, INRIA.
...
@@ -45,7 +45,7 @@ static void(*find_handler(const shell_command_t *command_list, char *command))(c
...
@@ -45,7 +45,7 @@ static void(*find_handler(const shell_command_t *command_list, char *command))(c
const
shell_command_t
*
entry
;
const
shell_command_t
*
entry
;
/* iterating over command_lists */
/* iterating over command_lists */
for
(
unsigned
int
i
=
0
;
i
<
sizeof
(
command_lists
)
/
sizeof
(
entry
);
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
sizeof
(
command_lists
)
/
sizeof
(
entry
);
i
++
)
{
if
((
entry
=
command_lists
[
i
]))
{
if
((
entry
=
command_lists
[
i
]))
{
/* iterating over commands in command_lists entry */
/* iterating over commands in command_lists entry */
while
(
entry
->
name
!=
NULL
)
{
while
(
entry
->
name
!=
NULL
)
{
...
@@ -77,7 +77,7 @@ static void print_help(const shell_command_t *command_list)
...
@@ -77,7 +77,7 @@ static void print_help(const shell_command_t *command_list)
const
shell_command_t
*
entry
;
const
shell_command_t
*
entry
;
/* iterating over command_lists */
/* iterating over command_lists */
for
(
unsigned
int
i
=
0
;
i
<
sizeof
(
command_lists
)
/
sizeof
(
entry
);
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
sizeof
(
command_lists
)
/
sizeof
(
entry
);
i
++
)
{
if
((
entry
=
command_lists
[
i
]))
{
if
((
entry
=
command_lists
[
i
]))
{
/* iterating over commands in command_lists entry */
/* iterating over commands in command_lists entry */
while
(
entry
->
name
!=
NULL
)
{
while
(
entry
->
name
!=
NULL
)
{
...
@@ -90,7 +90,7 @@ static void print_help(const shell_command_t *command_list)
...
@@ -90,7 +90,7 @@ static void print_help(const shell_command_t *command_list)
static
void
handle_input_line
(
shell_t
*
shell
,
char
*
line
)
static
void
handle_input_line
(
shell_t
*
shell
,
char
*
line
)
{
{
char
line_copy
[
SHELL_BUFFER_SIZE
];
char
line_copy
[
shell
->
shell_buffer_size
];
char
*
saveptr
;
char
*
saveptr
;
strncpy
(
line_copy
,
line
,
sizeof
(
line_copy
));
strncpy
(
line_copy
,
line
,
sizeof
(
line_copy
));
char
*
command
=
strtok_r
(
line_copy
,
" "
,
&
saveptr
);
char
*
command
=
strtok_r
(
line_copy
,
" "
,
&
saveptr
);
...
@@ -152,7 +152,7 @@ static inline void print_prompt(shell_t *shell)
...
@@ -152,7 +152,7 @@ static inline void print_prompt(shell_t *shell)
void
shell_run
(
shell_t
*
shell
)
void
shell_run
(
shell_t
*
shell
)
{
{
char
line_buf
[
SHELL_BUFFER_SIZE
];
char
line_buf
[
shell
->
shell_buffer_size
];
print_prompt
(
shell
);
print_prompt
(
shell
);
...
@@ -167,9 +167,11 @@ void shell_run(shell_t *shell)
...
@@ -167,9 +167,11 @@ void shell_run(shell_t *shell)
}
}
}
}
void
shell_init
(
shell_t
*
shell
,
const
shell_command_t
*
shell_commands
,
int
(
*
readchar
)(
void
),
void
(
*
put_char
)(
int
))
void
shell_init
(
shell_t
*
shell
,
const
shell_command_t
*
shell_commands
,
uint16_t
shell_buffer_size
,
int
(
*
readchar
)(
void
),
void
(
*
put_char
)(
int
))
{
{
shell
->
command_list
=
shell_commands
;
shell
->
command_list
=
shell_commands
;
shell
->
shell_buffer_size
=
shell_buffer_size
;
shell
->
readchar
=
readchar
;
shell
->
readchar
=
readchar
;
shell
->
put_char
=
put_char
;
shell
->
put_char
=
put_char
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment