Mercurial > flash_v2
comparison packages/redboot/current/src/parse.c @ 183:9160a8005d76
Merge from eCos master repository on 2001-09-12-03:52:30-BST
| author | jlarmour |
|---|---|
| date | Wed, 12 Sep 2001 04:21:13 +0000 |
| parents | f62680ef1804 |
| children | ea3f0bd33a73 |
comparison
equal
deleted
inserted
replaced
| 182:f62680ef1804 | 183:9160a8005d76 |
|---|---|
| 54 extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__; | 54 extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__; |
| 55 | 55 |
| 56 // | 56 // |
| 57 // Scan through an input line and break it into "arguments". These | 57 // Scan through an input line and break it into "arguments". These |
| 58 // are space delimited strings. Return a structure which points to | 58 // are space delimited strings. Return a structure which points to |
| 59 // the strings, similar to a Unix program. | 59 // the strings, similar to a Unix program. Multiple commands in the line |
| 60 // are separated by ; similar to sh. If we find a semi we stop processing the | |
| 61 // line, terminate the current command with a null and return the start | |
| 62 // of the next command in *line. parse() can then be called again to | |
| 63 // process the next command on the line. | |
| 60 // Note: original input is destroyed by replacing the delimiters with | 64 // Note: original input is destroyed by replacing the delimiters with |
| 61 // null ('\0') characters for ease of use. | 65 // null ('\0') characters for ease of use. |
| 62 // | 66 // |
| 63 struct cmd * | 67 struct cmd * |
| 64 parse(char *line, int *argc, char **argv) | 68 parse(char **line, int *argc, char **argv) |
| 65 { | 69 { |
| 66 char *cp = line; | 70 char *cp = *line; |
| 67 char *pp; | 71 char *pp; |
| 68 int indx = 0; | 72 int indx = 0; |
| 73 int semi = 0; | |
| 69 | 74 |
| 70 while (*cp) { | 75 while (*cp) { |
| 71 // Skip leading spaces | 76 // Skip leading spaces |
| 72 while (*cp && *cp == ' ') cp++; | 77 while (*cp && *cp == ' ') cp++; |
| 73 if (!*cp) { | 78 if (!*cp) { |
| 74 break; // Line ended with a string of spaces | 79 break; // Line ended with a string of spaces |
| 75 } | 80 } |
| 81 if (*cp == ';') { | |
| 82 *cp = '\0'; | |
| 83 semi=1; | |
| 84 break; | |
| 85 } | |
| 76 if (indx < MAX_ARGV) { | 86 if (indx < MAX_ARGV) { |
| 77 argv[indx++] = cp; | 87 argv[indx++] = cp; |
| 78 } else { | 88 } else { |
| 79 diag_printf("Too many arguments - stopped at: '%s'\n", cp); | 89 diag_printf("Too many arguments - stopped at: '%s'\n", cp); |
| 80 } | 90 } |
| 81 while (*cp) { | 91 while (*cp) { |
| 82 if (*cp == ' ') { | 92 if (*cp == ' ') { |
| 83 *cp++ = '\0'; | 93 *cp++ = '\0'; |
| 84 break; | 94 break; |
| 85 } else if (*cp == '"') { | 95 } else if (*cp == ';') { |
| 96 break; | |
| 97 } else if (*cp == '"') { | |
| 86 // Swallow quote, scan till following one | 98 // Swallow quote, scan till following one |
| 87 if (argv[indx-1] == cp) { | 99 if (argv[indx-1] == cp) { |
| 88 argv[indx-1] = ++cp; | 100 argv[indx-1] = ++cp; |
| 89 } | 101 } |
| 90 pp = cp; | 102 pp = cp; |
| 105 } | 117 } |
| 106 } else { | 118 } else { |
| 107 cp++; | 119 cp++; |
| 108 } | 120 } |
| 109 } | 121 } |
| 122 } | |
| 123 if (semi) { | |
| 124 *line = cp + 1; | |
| 125 } else { | |
| 126 *line = cp; | |
| 110 } | 127 } |
| 111 *argc = indx; | 128 *argc = indx; |
| 112 return cmd_search(__RedBoot_CMD_TAB__, &__RedBoot_CMD_TAB_END__, argv[0]); | 129 return cmd_search(__RedBoot_CMD_TAB__, &__RedBoot_CMD_TAB_END__, argv[0]); |
| 113 } | 130 } |
| 114 | 131 |
