Shell enhancements.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8914 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
27e1398be3
commit
22a386b454
|
@ -55,21 +55,37 @@ event_source_t shell_terminated;
|
||||||
/* Module local functions. */
|
/* Module local functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
static char *_strtok(char *str, const char *delim, char **saveptr) {
|
static char *parse_arguments(char *str, char **saveptr) {
|
||||||
char *token;
|
char *p;
|
||||||
if (str)
|
|
||||||
|
if (str != NULL)
|
||||||
*saveptr = str;
|
*saveptr = str;
|
||||||
token = *saveptr;
|
|
||||||
|
|
||||||
if (!token)
|
p = *saveptr;
|
||||||
|
if (!p) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
token += strspn(token, delim);
|
/* Skipping white space.*/
|
||||||
*saveptr = strpbrk(token, delim);
|
p += strspn(p, " \t");
|
||||||
if (*saveptr)
|
|
||||||
|
if (*p == '"') {
|
||||||
|
/* If an argument starts with a double quote then its delimiter is another
|
||||||
|
quote.*/
|
||||||
|
p++;
|
||||||
|
*saveptr = strpbrk(p, "\"");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* The delimiter is white space.*/
|
||||||
|
*saveptr = strpbrk(p, " \t");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Replacing the delimiter with a zero.*/
|
||||||
|
if (*saveptr != NULL) {
|
||||||
*(*saveptr)++ = '\0';
|
*(*saveptr)++ = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
return *token ? token : NULL;
|
return *p != '\0' ? p : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(BaseSequentialStream *chp, char *p) {
|
static void usage(BaseSequentialStream *chp, char *p) {
|
||||||
|
@ -122,10 +138,10 @@ THD_FUNCTION(shellThread, p) {
|
||||||
chprintf(chp, "\r\nlogout");
|
chprintf(chp, "\r\nlogout");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lp = _strtok(line, " \t", &tokp);
|
lp = parse_arguments(line, &tokp);
|
||||||
cmd = lp;
|
cmd = lp;
|
||||||
n = 0;
|
n = 0;
|
||||||
while ((lp = _strtok(NULL, " \t", &tokp)) != NULL) {
|
while ((lp = parse_arguments(NULL, &tokp)) != NULL) {
|
||||||
if (n >= SHELL_MAX_ARGUMENTS) {
|
if (n >= SHELL_MAX_ARGUMENTS) {
|
||||||
chprintf(chp, "too many arguments\r\n");
|
chprintf(chp, "too many arguments\r\n");
|
||||||
cmd = NULL;
|
cmd = NULL;
|
||||||
|
|
|
@ -93,6 +93,18 @@ static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (SHELL_CMD_ECHO_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||||
|
static void cmd_echo(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
|
|
||||||
|
(void)argv;
|
||||||
|
if (argc != 1) {
|
||||||
|
usage(chp, "echo \"message\"");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chprintf(chp, "%s\r\n", argv[0]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (SHELL_CMD_SYSTIME_ENABLED == TRUE) || defined(__DOXYGEN__)
|
#if (SHELL_CMD_SYSTIME_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||||
static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
|
static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
|
|
||||||
|
@ -175,6 +187,9 @@ ShellCommand shell_local_commands[] = {
|
||||||
#if SHELL_CMD_INFO_ENABLED == TRUE
|
#if SHELL_CMD_INFO_ENABLED == TRUE
|
||||||
{"info", cmd_info},
|
{"info", cmd_info},
|
||||||
#endif
|
#endif
|
||||||
|
#if SHELL_CMD_ECHO_ENABLED == TRUE
|
||||||
|
{"echo", cmd_echo},
|
||||||
|
#endif
|
||||||
#if SHELL_CMD_SYSTIME_ENABLED == TRUE
|
#if SHELL_CMD_SYSTIME_ENABLED == TRUE
|
||||||
{"systime", cmd_systime},
|
{"systime", cmd_systime},
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
#define SHELL_CMD_INFO_ENABLED TRUE
|
#define SHELL_CMD_INFO_ENABLED TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SHELL_CMD_ECHO_ENABLED) || defined(__DOXYGEN__)
|
||||||
|
#define SHELL_CMD_ECHO_ENABLED TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(SHELL_CMD_SYSTIME_ENABLED) || defined(__DOXYGEN__)
|
#if !defined(SHELL_CMD_SYSTIME_ENABLED) || defined(__DOXYGEN__)
|
||||||
#define SHELL_CMD_SYSTIME_ENABLED TRUE
|
#define SHELL_CMD_SYSTIME_ENABLED TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,6 +76,8 @@
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
|
|
||||||
*** Next ***
|
*** Next ***
|
||||||
|
- VAR: Centralized all usual shell commands into a single shell_cmd.c file.
|
||||||
|
- VAR: The shell now accepts quoted arguments.
|
||||||
- ALL: Reorganized source tree, now ports are shared between RT and NIL.
|
- ALL: Reorganized source tree, now ports are shared between RT and NIL.
|
||||||
- RT: Merged RT4.
|
- RT: Merged RT4.
|
||||||
- NIL: Merged NIL2.
|
- NIL: Merged NIL2.
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
|
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
|
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="vt_delta-null-chVTDoSetI-(format)" val="4"/><content id="r3-(format)" val="4"/></contentList>"/>
|
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="r3-(format)" val="4"/><content id="vt_delta-null-chVTDoSetI-(format)" val="4"/></contentList>"/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
|
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList> <memoryBlockExpressionItem> <expression text="0x20010744"/> </memoryBlockExpressionItem> </memoryBlockExpressionList> "/>
|
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList> <memoryBlockExpressionItem> <expression text="0x20010744"/> </memoryBlockExpressionItem> </memoryBlockExpressionList> "/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
|
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
|
||||||
|
|
Loading…
Reference in New Issue