]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cli.c
fatfs f_mount now allways done globally at start up
[z180-stamp.git] / avr / cli.c
index 52c85db1b4b17c1f192f008730e655cb6f986d2c..6b26b6f09cc77d09542271af3eb54999837f9379 100644 (file)
--- 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;
                }