26 #define SHL_DEFAULT_PROMPT "~>"
29 static const char * _prompt = SHL_DEFAULT_PROMPT;
34 bool (*cmd_exec)(
int argc,
const char *args[]);
38 bool cmd_ ## CMD ## _exec (int argc, const char *args[]); \
39 extern const char cmd_ ## CMD ## _help[];
46 { #CMD, &(cmd_ ## CMD ## _help[0]), cmd_ ## CMD ## _exec },
61 const char cmd_help_help[] =
"Shows this help";
63 bool cmd_help_exec(
int argc,
const char *args[])
67 while (entry->help != 0)
69 printf(
" %-10s - %s\n", entry->name, entry->help);
76 #define _SHL_MAX_CMD_LEN 80
77 #define _SHL_MAX_TOKENS 8
79 static char _shlCmdBuf[_SHL_MAX_CMD_LEN];
80 static int _shlCursor = 0;
81 static char * tokptr[_SHL_MAX_TOKENS];
82 static bool _first =
true;
87 if (newPrompt == NULL) {
88 _prompt = SHL_DEFAULT_PROMPT;
94 static void shellPrompt()
96 printf(
"\n%s", _prompt);
100 static void shellExecCommand()
102 if (_shlCursor > 1) {
106 while(n < _SHL_MAX_TOKENS)
108 while(_shlCmdBuf[i] ==
' ') _shlCmdBuf[i++] =
'\0';
110 if(_shlCmdBuf[i] ==
'\n')
113 tokptr [n++] = &(_shlCmdBuf[i]);
114 while(_shlCmdBuf[i] !=
' ' && _shlCmdBuf[i] !=
'\n') i++;
116 if(_shlCmdBuf[i] ==
'\n')
120 _shlCmdBuf[i] =
'\0';
127 if(*tokptr[0] ==
'#')
133 for(i=0; _entries[i].cmd_exec; i++)
135 if(!strcmp(_entries[i].name, tokptr[0]))
138 if (!_entries[i].cmd_exec(n - 1, (
const char **) ( tokptr + 1 ) ))
140 puts(
"Command failed");
152 puts(
"\nUnknown command\n\n");
162 puts(
"Type 'help' for more information\n");
171 if (c >=
' ' && c <=
'~' && _shlCursor < (_SHL_MAX_CMD_LEN - 1) )
173 _shlCmdBuf[_shlCursor++] = c;
176 else if (c ==
'\x7f' && _shlCursor > 0)
179 printf(
"\033[1D\033[1P");
181 else if (c ==
'\n' || c ==
'\r')
183 _shlCmdBuf[_shlCursor] =
'\n';
184 if (_shlCursor > 0) shellExecCommand();
bool errHas()
Returns whether there is an error pending.
The shell is a ASCII command interpreter and effort has been made to simplify creation of additional ...
int _shellChar()
Stub function.
Configures the shell commands.
Manages the global system error.
#define SHELL_COMMANDS
List of shell commands.
void errPrint(bool clear)
Prints the last error.
void shellSetPrompt(const char *newPrompt)
Sets the prompt for the shell.
void shellDo()
Checks if there is any ASCII characters of the UART, and execute any commands issued.