Commit | Line | Data |
---|---|---|
31ddb04a | 1 | #ifndef lint |
46b15d8a | 2 | static char sccsid[] = "@(#)getargs.c 5.2 (Berkeley) %G%"; |
31ddb04a SL |
3 | #endif |
4 | ||
46b15d8a | 5 | #include "uucp.h" |
31ddb04a | 6 | |
46b15d8a | 7 | /* |
31ddb04a SL |
8 | * getargs - this routine will generate a vector of |
9 | * pointers (arps) to the substrings in string "s". | |
10 | * Each substring is separated by blanks and/or tabs. | |
11 | * | |
12 | * If FANCYARGS is defined, you get the following: | |
13 | * Strings containing blanks may be specified by quoting, | |
14 | * in a manner similar to using the shell. | |
15 | * Control characters are entered by ^X where X is any | |
16 | * character; ^? gets you a rubout and ^^ is a real ^. | |
17 | * Warning (rti!trt): I doubt FANCYARGS is wise, since getargs | |
18 | * is used all over the place. Its features may be useful | |
19 | * but a separate fancy_getargs() should be called instead. | |
20 | * | |
46b15d8a | 21 | * return - the number of subfields, or -1 if >= maxargs. |
31ddb04a SL |
22 | */ |
23 | ||
46b15d8a | 24 | getargs(s, arps, maxargs) |
31ddb04a SL |
25 | register char *s; |
26 | char *arps[]; | |
46b15d8a | 27 | int maxargs; |
31ddb04a SL |
28 | { |
29 | register int i; | |
30 | #ifdef FANCYARGS | |
31 | register char *sp; | |
32 | register char qchar; | |
33 | #endif | |
34 | ||
35 | i = 0; | |
36 | #ifndef FANCYARGS | |
46b15d8a | 37 | while (i < maxargs) { |
31ddb04a SL |
38 | while (*s == ' ' || *s == '\t') |
39 | *s++ = '\0'; | |
40 | if (*s == '\n') | |
41 | *s = '\0'; | |
42 | if (*s == '\0') | |
43 | break; | |
44 | arps[i++] = s++; | |
45 | while (*s != '\0' && *s != ' ' | |
46 | && *s != '\t' && *s != '\n') | |
47 | s++; | |
48 | } | |
49 | #else | |
46b15d8a | 50 | while (i < maxargs) { |
31ddb04a SL |
51 | while (*s == ' ' || *s == '\t') |
52 | ++s; | |
53 | if (*s == '\n' || *s == '\0') | |
54 | break; | |
55 | arps[i++] = sp = s; | |
56 | qchar = 0; | |
57 | while(*s != '\0' && *s != '\n') { | |
58 | if (qchar == 0 && (*s == ' ' || *s == '\t')) { | |
59 | ++s; | |
60 | break; | |
61 | } | |
62 | switch(*s) { | |
63 | default: | |
64 | *sp++ = *s++; | |
65 | break; | |
66 | case '^': | |
67 | if(*++s == '^') | |
68 | *sp++ = '^'; | |
69 | else if(*s == '?') | |
70 | *sp++ = 0177; | |
71 | else | |
72 | *sp++ = *s & 037; | |
73 | s++; | |
74 | break; | |
75 | case '"': | |
76 | case '\'': | |
77 | if(qchar == *s) { | |
78 | qchar = 0; | |
79 | ++s; | |
80 | break; | |
81 | } | |
82 | if(qchar) | |
83 | *sp++ = *s++; | |
84 | else | |
85 | qchar = *s++; | |
86 | break; | |
87 | } | |
88 | } | |
89 | *sp++ = 0; | |
90 | } | |
31ddb04a | 91 | #endif |
46b15d8a RC |
92 | if (i >= maxargs) |
93 | return FAIL; | |
94 | arps[i] = NULL; | |
95 | return i; | |
31ddb04a | 96 | } |