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