shell functions More...
#include "config.h"
Go to the source code of this file.
Data Structures | |
struct | gpsflags_s |
Defines | |
#define | SHELL_BUFSIZE (80) |
command line buffer capacity | |
#define | ARGP_MAX ((SHELL_BUFSIZE+1)/2+1) |
maximum number of arguments | |
Typedefs | |
typedef int( | shell_function_t )(const uint8_t argc, const char *const argv[]) |
function called by a shell command | |
typedef struct gpsflags_s | gpsflags_t |
Functions | |
void | shell_recv_char (int c) |
feed one input character (as read from fgetc()) to command interpreter | |
int | shell_exec (const char *cmd, const uint8_t argc, const char *argv[]) |
execute a command | |
Variables | |
gpsflags_t | gpsflags [] |
shell functions
int shell_exec | ( | const char * | cmd, | |
const uint8_t | argc, | |||
const char * | argv[] | |||
) |
execute a command
Executes the command given by cmd. This function is inspired by the exec()-family interface in Unix. Parsing is assumed to be complete.
cmd | name of command to execute | |
argc | highest valid index into argv[] | |
argv[] | command arguments, argv[0] is the command itself, argv[1] is the first actual argument, argv[argc] is the last argument |
{ const char * const *nptr; shell_function_t * const * fptr; /* find in list */ for (nptr = shell_names, fptr = shell_commands; ; nptr++, fptr++) { const const char * name = (PGM_P)pgm_read_word (nptr); if (!name) { printf_P (PSTR("command '%s' not found\r\n"), argv[0]); return -1; } if (strcmp_P (argv[0], name) == 0) { break; } } /* now execute */ return (*(shell_function_t*)pgm_read_word(fptr))(argc, argv); }
void shell_recv_char | ( | int | c | ) |
feed one input character (as read from fgetc()) to command interpreter
shell_recv_char() buffers the read characters until a complete input line has been received. The command in that line is then executed - depending on the command, the execution may take some time.
{ int retval; /* handle captured STDIN */ if (shell_status.stdin_func) { retval = shell_status.stdin_func(shell_status.stdin_datap, c); if (!shell_status.stdin_func) { shell_status.last_retval = retval; } return; } switch (c) { default: /* ignore characters which don't fit into buffer */ if (shell_status.cmdbufidx < SHELL_BUFSIZE) { shell_status.cmdbuffer[shell_status.cmdbufidx++] = c; putchar(c); } return; case '\n': /* ignore */ return; case '\r': putchar (c); putchar ('\n'); shell_status.cmdbuffer[shell_status.cmdbufidx] = '\0'; shell_status.last_retval = shell_execute (shell_status.cmdbuffer); shell_status.cmdbufidx = 0; return; case '\377': case '\b': /* erase until start of line */ if (shell_status.cmdbufidx > 0) { putchar ('\b'); putchar (' '); putchar ('\b'); shell_status.cmdbufidx--; } return; } }