113646Ssam #ifndef lint 2*17835Sralph static char sccsid[] = "@(#)getargs.c 5.2 (Berkeley) 01/22/85"; 313646Ssam #endif 413646Ssam 5*17835Sralph #include "uucp.h" 613646Ssam 7*17835Sralph /* 813646Ssam * getargs - this routine will generate a vector of 913646Ssam * pointers (arps) to the substrings in string "s". 1013646Ssam * Each substring is separated by blanks and/or tabs. 1113646Ssam * 1213646Ssam * If FANCYARGS is defined, you get the following: 1313646Ssam * Strings containing blanks may be specified by quoting, 1413646Ssam * in a manner similar to using the shell. 1513646Ssam * Control characters are entered by ^X where X is any 1613646Ssam * character; ^? gets you a rubout and ^^ is a real ^. 1713646Ssam * Warning (rti!trt): I doubt FANCYARGS is wise, since getargs 1813646Ssam * is used all over the place. Its features may be useful 1913646Ssam * but a separate fancy_getargs() should be called instead. 2013646Ssam * 21*17835Sralph * return - the number of subfields, or -1 if >= maxargs. 2213646Ssam */ 2313646Ssam 24*17835Sralph getargs(s, arps, maxargs) 2513646Ssam register char *s; 2613646Ssam char *arps[]; 27*17835Sralph int maxargs; 2813646Ssam { 2913646Ssam register int i; 3013646Ssam #ifdef FANCYARGS 3113646Ssam register char *sp; 3213646Ssam register char qchar; 3313646Ssam #endif 3413646Ssam 3513646Ssam i = 0; 3613646Ssam #ifndef FANCYARGS 37*17835Sralph while (i < maxargs) { 3813646Ssam while (*s == ' ' || *s == '\t') 3913646Ssam *s++ = '\0'; 4013646Ssam if (*s == '\n') 4113646Ssam *s = '\0'; 4213646Ssam if (*s == '\0') 4313646Ssam break; 4413646Ssam arps[i++] = s++; 4513646Ssam while (*s != '\0' && *s != ' ' 4613646Ssam && *s != '\t' && *s != '\n') 4713646Ssam s++; 4813646Ssam } 4913646Ssam #else 50*17835Sralph while (i < maxargs) { 5113646Ssam while (*s == ' ' || *s == '\t') 5213646Ssam ++s; 5313646Ssam if (*s == '\n' || *s == '\0') 5413646Ssam break; 5513646Ssam arps[i++] = sp = s; 5613646Ssam qchar = 0; 5713646Ssam while(*s != '\0' && *s != '\n') { 5813646Ssam if (qchar == 0 && (*s == ' ' || *s == '\t')) { 5913646Ssam ++s; 6013646Ssam break; 6113646Ssam } 6213646Ssam switch(*s) { 6313646Ssam default: 6413646Ssam *sp++ = *s++; 6513646Ssam break; 6613646Ssam case '^': 6713646Ssam if(*++s == '^') 6813646Ssam *sp++ = '^'; 6913646Ssam else if(*s == '?') 7013646Ssam *sp++ = 0177; 7113646Ssam else 7213646Ssam *sp++ = *s & 037; 7313646Ssam s++; 7413646Ssam break; 7513646Ssam case '"': 7613646Ssam case '\'': 7713646Ssam if(qchar == *s) { 7813646Ssam qchar = 0; 7913646Ssam ++s; 8013646Ssam break; 8113646Ssam } 8213646Ssam if(qchar) 8313646Ssam *sp++ = *s++; 8413646Ssam else 8513646Ssam qchar = *s++; 8613646Ssam break; 8713646Ssam } 8813646Ssam } 8913646Ssam *sp++ = 0; 9013646Ssam } 91*17835Sralph #endif 92*17835Sralph if (i >= maxargs) 93*17835Sralph return FAIL; 9413646Ssam arps[i] = NULL; 95*17835Sralph return i; 9613646Ssam } 97