Annotation of 42BSD/usr.bin/uucp/getargs.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.