| 1 |
#include <stdlib.h> |
| 2 |
#include <string.h> |
| 3 |
|
| 4 |
char ** |
| 5 |
buildargv (char *input) |
| 6 |
{ |
| 7 |
static char *arglist[256]; |
| 8 |
int numargs = 0; |
| 9 |
|
| 10 |
while (1) |
| 11 |
{ |
| 12 |
while (*input == ' ') |
| 13 |
input++; |
| 14 |
if (*input == 0) |
| 15 |
break; |
| 16 |
arglist [numargs++] = input; |
| 17 |
while (*input != ' ' && *input != 0) |
| 18 |
input++; |
| 19 |
if (*input == 0) |
| 20 |
break; |
| 21 |
*(input++) = 0; |
| 22 |
} |
| 23 |
arglist [numargs] = NULL; |
| 24 |
return arglist; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
int main() |
| 29 |
{ |
| 30 |
char **args; |
| 31 |
char input[256]; |
| 32 |
int i; |
| 33 |
|
| 34 |
strcpy(input, " a b"); |
| 35 |
args = buildargv(input); |
| 36 |
|
| 37 |
if (strcmp (args[0], "a")) |
| 38 |
abort (); |
| 39 |
if (strcmp (args[1], "b")) |
| 40 |
abort (); |
| 41 |
if (args[2] != NULL) |
| 42 |
abort (); |
| 43 |
|
| 44 |
exit (0); |
| 45 |
} |