X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/b0e4f7e5bf9f344a9ef4642a3ce3441ada206941..ed7d7fd35e5cf408fd9cf7e900308b4ce318be7c:/avr/cli.c diff --git a/avr/cli.c b/avr/cli.c index 046859c..43b5be0 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -1,3 +1,16 @@ +/* + * (C) Copyright 2014 Leo C. + * + * (C) Copyright 2000 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * Add to readline cmdline-editing by + * (C) Copyright 2005 + * JinHua Luo, GuangDong Linux Center, + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include @@ -14,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...) \ @@ -33,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; @@ -42,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; @@ -58,7 +74,7 @@ static int cli_parse_line(char *line, char *argv[]) } break; - case 3: + case 3: /* in quote */ if (c == '\\' && quote == '\"') { ++state; continue; @@ -69,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; @@ -239,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; } @@ -296,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_...)