X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/35edb766593d019b89a3f40b6d6cdd2b50f18032..ed7d7fd35e5cf408fd9cf7e900308b4ce318be7c:/avr/cli.c diff --git a/avr/cli.c b/avr/cli.c index 52c85db..43b5be0 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -27,6 +27,9 @@ #include "con-utils.h" #include "cli.h" + +/* FIXME: Quoting problems */ + #define DEBUG_PARSER 0 /* set to 1 to debug */ #define debug_parser(fmt, args...) \ @@ -46,7 +49,7 @@ static int cli_parse_line(char *line, char *argv[]) inp++) { switch (state) { - case 0: + case 0: /* before arg string, waiting for arg start */ if (isblank(c)) continue; @@ -55,7 +58,7 @@ static int cli_parse_line(char *line, char *argv[]) state = 1; /* fall thru */ - case 1: + case 1: /* in arg string, waiting for end of arg string */ if (c == '\\') { ++state; continue; @@ -71,7 +74,7 @@ static int cli_parse_line(char *line, char *argv[]) } break; - case 3: + case 3: /* in quote */ if (c == '\\' && quote == '\"') { ++state; continue; @@ -82,7 +85,7 @@ static int cli_parse_line(char *line, char *argv[]) } break; - case 2: + case 2: /* waiting for next char */ case 4: --state; break; @@ -252,12 +255,13 @@ static int cli_run_command(const char *cmd, int flag) */ for (inquotes = 0, sep = str; *sep; sep++) { if ((*sep == '\'') && - (*(sep - 1) != '\\')) + (sep != str) && /* past string start */ + (*(sep - 1) != '\\')) /* and NOT escaped */ inquotes = !inquotes; if (!inquotes && - (*sep == ';' || *sep == '\n') && /* separator */ - (sep != str) && /* past string start */ + (*sep == ';' || *sep == '\n') && /* separator */ + (sep != str) && /* past string start */ (*(sep - 1) != '\\')) /* and NOT escaped */ break; } @@ -309,7 +313,7 @@ static int cli_run_command_list(const char *cmd) /* - * Run a command using the selected parser. + * Run a command. * * @param cmd Command to run * @param flag Execution flags (CMD_FLAG_...)