Do not skip over the null terminator
This commit is contained in:
parent
0eb7597ab1
commit
28c4ef45f7
@ -94,38 +94,48 @@ static void handle_input_line(shell_t *shell, char *line)
|
|||||||
|
|
||||||
/* first we need to calculate the number of arguments */
|
/* first we need to calculate the number of arguments */
|
||||||
unsigned argc = 0;
|
unsigned argc = 0;
|
||||||
char *pos;
|
char *pos = line;
|
||||||
for (pos = line; *pos; ++pos) {
|
while (1) {
|
||||||
if (*pos <= ' ') {
|
if (*pos > ' ') {
|
||||||
*pos = 0;
|
/* found an argument */
|
||||||
continue;
|
if (*pos == '"') {
|
||||||
}
|
/* it's an quoted argument */
|
||||||
else if (*pos == '"') {
|
do {
|
||||||
do {
|
++pos;
|
||||||
++pos;
|
if (!*pos) {
|
||||||
if (!*pos) {
|
puts(INCORRECT_QUOTING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} while (*pos != '"');
|
||||||
|
if (pos[1] > ' ') {
|
||||||
puts(INCORRECT_QUOTING);
|
puts(INCORRECT_QUOTING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (*pos != '"');
|
|
||||||
if (pos[1] > ' ') {
|
|
||||||
puts(INCORRECT_QUOTING);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* it's an unquoted argument */
|
||||||
|
do {
|
||||||
|
++pos;
|
||||||
|
if (*pos == '"') {
|
||||||
|
puts(INCORRECT_QUOTING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} while (*pos > ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count the number of arguments we got */
|
||||||
|
++argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* zero out the current position (space or quotation mark) and advance */
|
||||||
|
if (*pos > 0) {
|
||||||
|
*pos = 0;
|
||||||
|
++pos;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
do {
|
break;
|
||||||
++pos;
|
|
||||||
if (*pos == '"') {
|
|
||||||
puts(INCORRECT_QUOTING);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} while (*pos > ' ');
|
|
||||||
}
|
}
|
||||||
++argc;
|
|
||||||
*pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user