comparison target-utils/libcommon/parseargs.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module contains the parse_args() function, which parses the "rest"
3 * part of an entered command into an argc/argv-style argument array.
4 */
5
6 parse_args(unparsed, minargs, maxargs, argv, argcp)
7 char *unparsed;
8 int minargs, maxargs;
9 char **argv;
10 int *argcp;
11 {
12 int argc;
13 char *cp;
14
15 argc = 0;
16 for (cp = unparsed; ; ) {
17 while (*cp == ' ')
18 cp++;
19 if (!*cp)
20 break;
21 if (argc >= maxargs) {
22 printf("ERROR: too many arguments\n");
23 return(-1);
24 }
25 argv[argc++] = cp;
26 while (*cp && *cp != ' ')
27 cp++;
28 if (*cp)
29 *cp++ = '\0';
30 }
31 if (argc < minargs) {
32 printf("ERROR: too few arguments\n");
33 return(-1);
34 }
35 argv[argc] = 0;
36 if (argcp)
37 *argcp = argc;
38 return(0);
39 }