Simple shell interpreter.
More...
Simple shell interpreter.
|
file | shell.h |
| Shell interface definition.
|
|
◆ SHELL_COMMAND
#define SHELL_COMMAND |
( |
|
name, |
|
|
|
help, |
|
|
|
func |
|
) |
| |
Value:
static
const shell_command_t _xfa_ ## name ## _cmd = { #name, help, &func }; \
XFA_ADD_PTR(shell_commands_xfa, name, name, &_xfa_ ## name ## _cmd)
A single command in the list of the supported commands.
#define XFA_USE_CONST(type, name)
Declare an external read-only cross-file array.
Define shell command.
This macro is a helper for defining a shell command and adding it to the shell commands XFA (cross file array).
Shell commands added using this macros will be sorted after builtins and commands passed via parameter to shell_run_once()
. If a command with the same name exists in any of those, they will make a command added via this macro inaccassible.
Commands added with this macro will be sorted alphanumerically by name
.
- Warning
- This feature is experimental!
This should be considered experimental API, subject to change without notice!
Example:
static int _my_command(int argc, char **argv) {
}
#define SHELL_COMMAND(name, help, func)
Define shell command.
Shell interface definition.
Definition at line 208 of file shell.h.
◆ shell_command_handler_t
typedef int(* shell_command_handler_t) (int argc, char **argv) |
Protype of a shell callback handler.
The functions supplied to shell_run() must use this signature. The argument list is terminated with a NULL, i.e argv[argc] == NULL`.
argv[0]`` is the function name.
Escape sequences are removed before the function is called.
The called function may edit argv
and the contained strings, but it must be taken care of not to leave the boundaries of the array. This functionality can be used by getopt() or a similar function.
- Parameters
-
[in] | argc | Number of arguments supplied to the function invocation. |
[in] | argv | The supplied argument list. |
- Returns
- 0 on success
-
Anything else on failure
Definition at line 125 of file shell.h.
◆ shell_command_t
A single command in the list of the supported commands.
The list of commands is NULL terminated, i.e. the last element must be { NULL, NULL, NULL }
.
◆ shell_post_command_hook()
void shell_post_command_hook |
( |
int |
ret, |
|
|
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Optional hook after shell command is called.
User implemented function gets called before a valid shell command will be called.
- Note
- Only executed with the
shell_hooks
module.
- Parameters
-
[in] | ret | Return value of the shell command. |
[in] | argc | Number of arguments supplied to the function invocation. |
[in] | argv | The supplied argument list. |
◆ shell_post_readline_hook()
void shell_post_readline_hook |
( |
void |
| ) |
|
Optional hook after readline has triggered.
User implemented function gets called after the shell readline is complete.
- Note
- Only executed with the
shell_hooks
module.
◆ shell_pre_command_hook()
void shell_pre_command_hook |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Optional hook before shell command is called.
User implemented function gets called before a valid shell command will be called.
- Note
- Only executed with the
shell_hooks
module.
- Parameters
-
[in] | argc | Number of arguments supplied to the function invocation. |
[in] | argv | The supplied argument list. |
◆ shell_run()
static void shell_run |
( |
const shell_command_t * |
commands, |
|
|
char * |
line_buf, |
|
|
int |
len |
|
) |
| |
|
inlinestatic |
Back-porting alias for shell_run_forever.
- Parameters
-
[in] | commands | ptr to array of command structs |
[in] | line_buf | Buffer that will be used for reading a line |
[in] | len | nr of bytes that fit in line_buf |
Definition at line 176 of file shell.h.
◆ shell_run_forever()
static void shell_run_forever |
( |
const shell_command_t * |
commands, |
|
|
char * |
line_buf, |
|
|
int |
len |
|
) |
| |
|
inlinestatic |
Start a shell and restart it if it exits.
If `CONFIG_SHELL_SHUTDOWN_ON_EXIT` is set (e.g. on native)
the shell will instead shut down RIOT once EOF is reached.
- Parameters
-
[in] | commands | ptr to array of command structs |
[in] | line_buf | Buffer that will be used for reading a line |
[in] | len | nr of bytes that fit in line_buf |
Definition at line 157 of file shell.h.
◆ shell_run_once()
void shell_run_once |
( |
const shell_command_t * |
commands, |
|
|
char * |
line_buf, |
|
|
int |
len |
|
) |
| |
Start a shell and exit once EOF is reached.
- Parameters
-
[in] | commands | ptr to array of command structs |
[in] | line_buf | Buffer that will be used for reading a line |
[in] | len | nr of bytes that fit in line_buf |