Annotation of researchv10no/cmd/netnews/src/process.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * process - process options for readnews
                      3:  */
                      4: 
                      5: static char *SccsId = "@(#)process.c   2.7     4/23/83";
                      6: 
                      7: #include "rparams.h"
                      8: 
                      9: #define OPTION 0       /* pick up an option string */
                     10: #define STRING 1       /* pick up a string of arguments */
                     11: 
                     12: struct optable *optpt, options[] = { /*
                     13: optlet filchar flag    newstate oldmode        newmode buf     */
                     14: 'p',   '\0',   FALSE,  OPTION, UNKNOWN,        UNKNOWN,(char *)NULL,   
                     15: 't',   '\0',   FALSE,  STRING, ANY,            UNKNOWN,header.title,   
                     16: 'a',   ' ',    FALSE,  STRING, ANY,            UNKNOWN,datebuf,
                     17: 'n',   NGDELIM,        FALSE,  STRING, ANY,            UNKNOWN,header.nbuf,
                     18: 'c',   ' ',    FALSE,  STRING, UNKNOWN,        UNKNOWN,coptbuf,        
                     19: 'l',   ' ',    FALSE,  OPTION, UNKNOWN,        UNKNOWN,(char *)NULL,
                     20: 'r',   '\0',   FALSE,  OPTION, ANY,            UNKNOWN,(char *)NULL,
                     21: 's',   NGDELIM,        FALSE,  STRING, ANY,            UNKNOWN,header.nbuf,
                     22: 'x',   '\0',   FALSE,  OPTION, ANY,            UNKNOWN,(char *)NULL,
                     23: 'h',   '\0',   FALSE,  OPTION, ANY,            UNKNOWN,(char *)NULL,
                     24: 'M',   '\0',   FALSE,  OPTION, UNKNOWN,        MAIL,   (char *)NULL,
                     25: 'f',   '\0',   FALSE,  OPTION, ANY,            UNKNOWN,(char *)NULL,
                     26: 'u',   '\0',   FALSE,  OPTION, ANY,            UNKNOWN,(char *)NULL,
                     27: 'e',   '\0',   FALSE,  OPTION, ANY,            UNKNOWN,(char *)NULL,
                     28: '\0',  '\0',   0,      0,      0,              0,      (char *)NULL
                     29: };
                     30: 
                     31: process(argc,argv)
                     32: register int argc;
                     33: register char **argv;
                     34: {
                     35:        register int state = OPTION;
                     36:        register char *ptr;
                     37:        char filchar;
                     38:        int len, tlen;
                     39: 
                     40:        /* loop once per arg. */
                     41: 
                     42:        while (--argc) {
                     43:            if (state == OPTION) {
                     44:                if (**argv != '-') {
                     45:                        sprintf(bfr, "Bad option string \"%s\"", *argv);
                     46:                        xerror(bfr);
                     47:                }
                     48:                while (*++*argv != '\0') {
                     49:                        for (optpt = options; optpt->optlet != '\0'; ++optpt) {
                     50:                                if (optpt->optlet == **argv)
                     51:                                        goto found;
                     52:                        }
                     53:                        /* unknown option letter */
                     54:                        fprintf(stderr, "Usage: readnews [ -a [ date ]] [ -n newsgroups ] [ -t titles ] [ -lprxhfuM ]\n");
                     55:                        fprintf(stderr, "\t[ -c [ ``mailer'' ]]\n\n");
                     56:                        fprintf(stderr, "       readnews -s\n");
                     57:                        exit(1);
                     58: 
                     59:                    found:;
                     60:                        if (mode != UNKNOWN && (mode&optpt->oldmode) == 0) {
                     61:                                sprintf(bfr, "Bad %c option", **argv);
                     62:                                xerror(bfr);
                     63:                        }
                     64:                        if (mode == UNKNOWN)
                     65:                                mode = optpt->newmode;
                     66:                        filchar = optpt->filchar;
                     67:                        optpt->flag = TRUE;
                     68:                        state = optpt->newstate;
                     69:                        ptr = optpt->buf;
                     70:                        len = LBUFLEN;
                     71:                }
                     72: 
                     73:                argv++;         /* done with this option arg. */
                     74: 
                     75:            } else {
                     76: 
                     77:                /*
                     78:                 * Pick up a piece of a string and put it into
                     79:                 * the appropriate buffer.
                     80:                 */
                     81:                if (**argv == '-') {
                     82:                        state = OPTION;
                     83:                        argc++; /* uncount this arg. */
                     84:                        continue;
                     85:                }
                     86: 
                     87:                if ((tlen = strlen(*argv)) >= len)
                     88:                        xerror("Argument string too long");
                     89:                strcpy(ptr, *argv++);
                     90:                ptr += tlen;
                     91:                if (*(ptr-1) != filchar)
                     92:                        *ptr++ = filchar;
                     93:                len -= tlen + 1;
                     94:                *ptr = '\0';
                     95:            }
                     96:        }
                     97:        return;
                     98: }

unix.superglobalmegacorp.com

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