1*48652Sbostic /*- 2*48652Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*48652Sbostic * All rights reserved. 4*48652Sbostic * 5*48652Sbostic * %sccs.include.proprietary.c% 6*48652Sbostic */ 7*48652Sbostic 813646Ssam #ifndef lint 9*48652Sbostic static char sccsid[] = "@(#)getargs.c 5.4 (Berkeley) 04/24/91"; 10*48652Sbostic #endif /* not lint */ 1113646Ssam 1217835Sralph #include "uucp.h" 1313646Ssam 1423602Sbloom /*LINTLIBRARY*/ 1523602Sbloom 1617835Sralph /* 1713646Ssam * getargs - this routine will generate a vector of 1813646Ssam * pointers (arps) to the substrings in string "s". 1913646Ssam * Each substring is separated by blanks and/or tabs. 2013646Ssam * 2113646Ssam * If FANCYARGS is defined, you get the following: 2213646Ssam * Strings containing blanks may be specified by quoting, 2313646Ssam * in a manner similar to using the shell. 2413646Ssam * Control characters are entered by ^X where X is any 2513646Ssam * character; ^? gets you a rubout and ^^ is a real ^. 2613646Ssam * Warning (rti!trt): I doubt FANCYARGS is wise, since getargs 2713646Ssam * is used all over the place. Its features may be useful 2813646Ssam * but a separate fancy_getargs() should be called instead. 2913646Ssam * 3017835Sralph * return - the number of subfields, or -1 if >= maxargs. 3113646Ssam */ 3213646Ssam 3317835Sralph getargs(s, arps, maxargs) 3413646Ssam register char *s; 3513646Ssam char *arps[]; 3617835Sralph int maxargs; 3713646Ssam { 3813646Ssam register int i; 3913646Ssam #ifdef FANCYARGS 4013646Ssam register char *sp; 4113646Ssam register char qchar; 4213646Ssam #endif 4313646Ssam 4413646Ssam i = 0; 4513646Ssam #ifndef FANCYARGS 4617835Sralph while (i < maxargs) { 4713646Ssam while (*s == ' ' || *s == '\t') 4813646Ssam *s++ = '\0'; 4913646Ssam if (*s == '\n') 5013646Ssam *s = '\0'; 5113646Ssam if (*s == '\0') 5213646Ssam break; 5313646Ssam arps[i++] = s++; 5413646Ssam while (*s != '\0' && *s != ' ' 5513646Ssam && *s != '\t' && *s != '\n') 5613646Ssam s++; 5713646Ssam } 5813646Ssam #else 5917835Sralph while (i < maxargs) { 6013646Ssam while (*s == ' ' || *s == '\t') 6113646Ssam ++s; 6213646Ssam if (*s == '\n' || *s == '\0') 6313646Ssam break; 6413646Ssam arps[i++] = sp = s; 6513646Ssam qchar = 0; 6613646Ssam while(*s != '\0' && *s != '\n') { 6713646Ssam if (qchar == 0 && (*s == ' ' || *s == '\t')) { 6813646Ssam ++s; 6913646Ssam break; 7013646Ssam } 7113646Ssam switch(*s) { 7213646Ssam default: 7313646Ssam *sp++ = *s++; 7413646Ssam break; 7513646Ssam case '^': 7613646Ssam if(*++s == '^') 7713646Ssam *sp++ = '^'; 7813646Ssam else if(*s == '?') 7913646Ssam *sp++ = 0177; 8013646Ssam else 8113646Ssam *sp++ = *s & 037; 8213646Ssam s++; 8313646Ssam break; 8413646Ssam case '"': 8513646Ssam case '\'': 8613646Ssam if(qchar == *s) { 8713646Ssam qchar = 0; 8813646Ssam ++s; 8913646Ssam break; 9013646Ssam } 9113646Ssam if(qchar) 9213646Ssam *sp++ = *s++; 9313646Ssam else 9413646Ssam qchar = *s++; 9513646Ssam break; 9613646Ssam } 9713646Ssam } 9813646Ssam *sp++ = 0; 9913646Ssam } 10017835Sralph #endif 10117835Sralph if (i >= maxargs) 10217835Sralph return FAIL; 10313646Ssam arps[i] = NULL; 10417835Sralph return i; 10513646Ssam } 106