annotate target-utils/libcommon/parseargs.c @ 255:c33fb341faeb

ffstools/tiffs-rd/README deleted, superceded by ffstools/README
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 03 Feb 2014 06:35:29 +0000
parents f4fc449a64ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the parse_args() function, which parses the "rest"
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * part of an entered command into an argc/argv-style argument array.
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 parse_args(unparsed, minargs, maxargs, argv, argcp)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 char *unparsed;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 int minargs, maxargs;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 char **argv;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 int *argcp;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 {
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 int argc;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 char *cp;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 argc = 0;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 for (cp = unparsed; ; ) {
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 while (*cp == ' ')
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 cp++;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 if (!*cp)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 break;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 if (argc >= maxargs) {
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 printf("ERROR: too many arguments\n");
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 return(-1);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 }
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 argv[argc++] = cp;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 while (*cp && *cp != ' ')
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 cp++;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 if (*cp)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 *cp++ = '\0';
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 if (argc < minargs) {
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 printf("ERROR: too few arguments\n");
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 return(-1);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 }
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 argv[argc] = 0;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 if (argcp)
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 *argcp = argc;
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 return(0);
f4fc449a64ea target-utils libcommon infrastructure for interactive commands
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 }