1: #ifndef lint
   2: static char sccsid[] = "@(#)getargs.c	5.3 (Berkeley) 6/19/85";
   3: #endif
   4: 
   5: #include "uucp.h"
   6: 
   7: /*LINTLIBRARY*/
   8: 
   9: /*
  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:  *
  23:  *	return - the number of subfields, or -1 if >= maxargs.
  24:  */
  25: 
  26: getargs(s, arps, maxargs)
  27: register char *s;
  28: char *arps[];
  29: int maxargs;
  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
  39:     while (i < maxargs) {
  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
  52:     while (i < maxargs) {
  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:     }
  93: #endif
  94:     if (i >= maxargs)
  95:         return FAIL;
  96:     arps[i] = NULL;
  97:     return i;
  98: }
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 536
Valid CSS Valid XHTML 1.0 Strict