|
|
1.1 ! root 1: /* ! 2: * This software is Copyright (c) 1986 by Rick Adams. ! 3: * ! 4: * Permission is hereby granted to copy, reproduce, redistribute or ! 5: * otherwise use this software as long as: there is no monetary ! 6: * profit gained specifically from the use or reproduction or this ! 7: * software, it is not sold, rented, traded or otherwise marketed, and ! 8: * this copyright notice is included prominently in any copy ! 9: * made. ! 10: * ! 11: * The author make no claims as to the fitness or correctness of ! 12: * this software for any use whatsoever, and it is provided as is. ! 13: * Any use of this software is at the user's own risk. ! 14: * ! 15: * process - process options for readnews/vnews ! 16: */ ! 17: ! 18: #ifdef SCCSID ! 19: static char *SccsId = "@(#)process.c 2.17 12/16/86"; ! 20: #endif /* SCCSID */ ! 21: ! 22: #include "rparams.h" ! 23: ! 24: char coptbuf[LBUFLEN], datebuf[LBUFLEN]; ! 25: ! 26: #define OPTION 0 /* pick up an option string */ ! 27: #define STRING 1 /* pick up a string of arguments */ ! 28: ! 29: struct optable *optpt, options[] = { /* ! 30: optlet filchar flag newstate oldmode newmode buf */ ! 31: 'p', '\0', FALSE, OPTION, UNKNOWN, UNKNOWN,(char *)NULL, ! 32: 't', '\0', FALSE, STRING, ANY, UNKNOWN,header.title, ! 33: 'a', ' ', FALSE, STRING, ANY, UNKNOWN,datebuf, ! 34: 'n', NGDELIM, FALSE, STRING, ANY, UNKNOWN,header.nbuf, ! 35: 'c', ' ', FALSE, STRING, UNKNOWN, UNKNOWN,coptbuf, ! 36: 'l', ' ', FALSE, OPTION, UNKNOWN, UNKNOWN,(char *)NULL, ! 37: 'r', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 38: 's', NGDELIM, FALSE, STRING, ANY, UNKNOWN,header.nbuf, ! 39: 'x', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 40: 'h', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 41: #ifdef TMAIL ! 42: 'M', '\0', FALSE, OPTION, UNKNOWN, MAIL, (char *)NULL, ! 43: #else /* !TMAIL */ ! 44: '\377', '\0', FALSE, OPTION, UNKNOWN, UNKNOWN,(char *)NULL, ! 45: #endif /* !TMAIL */ ! 46: 'f', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 47: 'u', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 48: 'e', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 49: 'K', '\0', FALSE, OPTION, ANY, UNKNOWN,(char *)NULL, ! 50: '\0', '\0', 0, 0, 0, 0, (char *)NULL ! 51: }; ! 52: ! 53: process(argc,argv) ! 54: register int argc; ! 55: register char **argv; ! 56: { ! 57: register int state = STRING; ! 58: register char *ptr = header.nbuf; ! 59: char filchar = NGDELIM; ! 60: int len = LBUFLEN, tlen; ! 61: ! 62: /* loop once per arg. */ ! 63: ! 64: if (argc > 1 && **argv != '-') ! 65: nflag = TRUE; ! 66: ! 67: while (--argc) { ! 68: if (state == OPTION) { ! 69: if (**argv != '-') { ! 70: xerror("Bad option string \"%s\"", *argv); ! 71: } ! 72: while (*++*argv != '\0') { ! 73: for (optpt = options; optpt->optlet != '\0'; ++optpt) { ! 74: if (optpt->optlet == **argv) ! 75: goto found; ! 76: } ! 77: /* unknown option letter */ ! 78: #ifdef TMAIL ! 79: fprintf(stderr, "Usage: %s [ -a [ date ]] [ -n newsgroups ] [ -t titles ] [ -lprxhfuMK ]\n", Progname); ! 80: #else /* !TMAIL */ ! 81: fprintf(stderr, "Usage: %s [ -a [ date ]] [ -n newsgroups ] [ -t titles ] [ -lprxhfuK ]\n", Progname); ! 82: #endif /* !TMAIL */ ! 83: fprintf(stderr, "\t[ -c [ ``mailer'' ]]\n\n"); ! 84: fprintf(stderr, " %s -s\n", Progname); ! 85: exit(1); ! 86: ! 87: found:; ! 88: if (mode != UNKNOWN && (mode&optpt->oldmode) == 0) { ! 89: xerror("Bad %c option", **argv); ! 90: } ! 91: if (mode == UNKNOWN) ! 92: mode = optpt->newmode; ! 93: filchar = optpt->filchar; ! 94: optpt->flag = TRUE; ! 95: state = optpt->newstate; ! 96: ptr = optpt->buf; ! 97: len = LBUFLEN; ! 98: } ! 99: ! 100: argv++; /* done with this option arg. */ ! 101: ! 102: } else { ! 103: ! 104: /* ! 105: * Pick up a piece of a string and put it into ! 106: * the appropriate buffer. ! 107: */ ! 108: if (**argv == '-') { ! 109: state = OPTION; ! 110: argc++; /* uncount this arg. */ ! 111: continue; ! 112: } ! 113: ! 114: if ((tlen = strlen(*argv)) >= len) ! 115: xerror("Argument string too long"); ! 116: strcpy(ptr, *argv++); ! 117: ptr += tlen; ! 118: if (*(ptr-1) != filchar) ! 119: *ptr++ = filchar; ! 120: len -= tlen + 1; ! 121: *ptr = '\0'; ! 122: } ! 123: } ! 124: return; ! 125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.