comparison rvinterf/asyncshell/parse.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 implements the parser helper function that allows
3 * the same code to be reused between interactive and one-shot
4 * versions of the same command.
5 */
6
7 #include <stdio.h>
8 #include <ctype.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h>
12
13 parse_interactive_command_into_argv(argstr, argv, min_arg, max_arg, argcp)
14 char *argstr, **argv;
15 int min_arg, max_arg, *argcp;
16 {
17 char *cp, **ap;
18
19 cp = argstr;
20 for (ap = argv; ; ) {
21 while (isspace(*cp))
22 cp++;
23 if (!*cp || *cp == '#')
24 break;
25 if (ap - argv >= max_arg) {
26 printf("error: too many arguments\n");
27 return(-1);
28 }
29 if (*cp == '"') {
30 *ap++ = ++cp;
31 while (*cp && *cp != '"')
32 cp++;
33 if (*cp != '"') {
34 printf("error: unterminated quoted string\n");
35 return(-1);
36 }
37 *cp++ = '\0';
38 } else {
39 *ap++ = cp;
40 while (*cp && !isspace(*cp))
41 cp++;
42 if (*cp)
43 *cp++ = '\0';
44 }
45 }
46 if (ap - argv < min_arg) {
47 printf("error: too few arguments\n");
48 return(-1);
49 }
50 *ap = 0;
51 *argcp = ap - argv;
52 return(0);
53 }