Shell

Simple shell interpreter. More...

Detailed Description

Simple shell interpreter.

Files

file  shell.h
 Shell interface definition.
 

Data Structures

struct  shell_command_t
 A single command in the list of the supported commands. More...
 

Macros

#define SHELL_DEFAULT_BUFSIZE   (128)
 Default shell buffer size (maximum line length shell can handle)
 

Typedefs

typedef int(* shell_command_handler_t) (int argc, char **argv)
 Protype of a shell callback handler. More...
 
typedef struct shell_command_t shell_command_t
 A single command in the list of the supported commands. More...
 

Functions

void shell_run_once (const shell_command_t *commands, char *line_buf, int len)
 Start a shell and exit once EOF is reached. More...
 
static void shell_run_forever (const shell_command_t *commands, char *line_buf, int len)
 Start a shell and restart it if it exits. More...
 
static void shell_run (const shell_command_t *commands, char *line_buf, int len)
 Back-porting alias for shell_run_forever. More...
 

Typedef Documentation

◆ 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]argcNumber of arguments supplied to the function invocation.
[in]argvThe supplied argument list.
Returns
0 on success
Anything else on failure

Definition at line 53 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 }.

Function Documentation

◆ 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]commandsptr to array of command structs
[in]line_bufBuffer that will be used for reading a line
[in]lennr of bytes that fit in line_buf

Definition at line 97 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.

Parameters
[in]commandsptr to array of command structs
[in]line_bufBuffer that will be used for reading a line
[in]lennr of bytes that fit in line_buf

Definition at line 82 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]commandsptr to array of command structs
[in]line_bufBuffer that will be used for reading a line
[in]lennr of bytes that fit in line_buf