Shell

Simple shell interpreter.

int(* shell_command_handler_t()

Protype of a shell callback handler.

The functions supplied to shell.h::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

argc:Number of arguments supplied to the function invocation.
argv:The supplied argument list.

Return values

  • 0 on success
  • Anything else on failure
struct shell_command_t 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 }.

void shell_run(const shell_command_t * commands, char * line_buf, int len)

Start a shell.

Parameters

commands:ptr to array of command structs
line_buf:Buffer that will be used for reading a line
len:nr of bytes that fit in line_buf

SHELL_DEFAULT_BUFSIZE

Default shell buffer size (maximum line length shell can handle)

1
(128)
struct 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 }.

const char * name

Name of the function.

const char * desc

Description to print in the “help” command.

shell.h::shell_command_handler_t handler

The callback function.