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.14	1/17/86";
  20: #endif /* SCCSID */
  21: 
  22: #include "rparams.h"
  23: 
  24: #define OPTION  0   /* pick up an option string */
  25: #define STRING  1   /* pick up a string of arguments */
  26: 
  27: struct optable *optpt, options[] = { /*
  28: optlet	filchar	flag	newstate oldmode	newmode	buf	*/
  29: 'p',    '\0',   FALSE,  OPTION, UNKNOWN,    UNKNOWN,(char *)NULL,
  30: 't',    '\0',   FALSE,  STRING, ANY,        UNKNOWN,header.title,
  31: 'a',    ' ',    FALSE,  STRING, ANY,        UNKNOWN,datebuf,
  32: 'n',   NGDELIM, FALSE,  STRING, ANY,        UNKNOWN,header.nbuf,
  33: 'c',    ' ',    FALSE,  STRING, UNKNOWN,    UNKNOWN,coptbuf,
  34: 'l',    ' ',    FALSE,  OPTION, UNKNOWN,    UNKNOWN,(char *)NULL,
  35: 'r',    '\0',   FALSE,  OPTION, ANY,        UNKNOWN,(char *)NULL,
  36: 's',   NGDELIM, FALSE,  STRING, ANY,        UNKNOWN,header.nbuf,
  37: 'x',    '\0',   FALSE,  OPTION, ANY,        UNKNOWN,(char *)NULL,
  38: 'h',    '\0',   FALSE,  OPTION, ANY,        UNKNOWN,(char *)NULL,
  39: #ifdef TMAIL
  40: 'M',    '\0',   FALSE,  OPTION, UNKNOWN,    MAIL,   (char *)NULL,
  41: #else /* !TMAIL */
  42: '\377', '\0',   FALSE,  OPTION, UNKNOWN,    UNKNOWN,(char *)NULL,
  43: #endif /* !TMAIL */
  44: 'f',    '\0',   FALSE,  OPTION, ANY,        UNKNOWN,(char *)NULL,
  45: 'u',    '\0',   FALSE,  OPTION, ANY,        UNKNOWN,(char *)NULL,
  46: 'e',    '\0',   FALSE,  OPTION, ANY,        UNKNOWN,(char *)NULL,
  47: '\0',   '\0',   0,  0,  0,      0,  (char *)NULL
  48: };
  49: 
  50: process(argc,argv)
  51: register int argc;
  52: register char **argv;
  53: {
  54:     register int state = STRING;
  55:     register char *ptr = header.nbuf;
  56:     char filchar = NGDELIM;
  57:     int len = BUFLEN, tlen;
  58: 
  59:     /* loop once per arg. */
  60: 
  61:     if (argc > 1 && **argv != '-')
  62:         nflag = TRUE;
  63: 
  64:     while (--argc) {
  65:         if (state == OPTION) {
  66:         if (**argv != '-') {
  67:             xerror("Bad option string \"%s\"", *argv);
  68:         }
  69:         while (*++*argv != '\0') {
  70:             for (optpt = options; optpt->optlet != '\0'; ++optpt) {
  71:                 if (optpt->optlet == **argv)
  72:                     goto found;
  73:             }
  74:             /* unknown option letter */
  75: #ifdef TMAIL
  76:             fprintf(stderr, "Usage: %s [ -a [ date ]] [ -n newsgroups ] [ -t titles ] [ -lprxhfuM ]\n", Progname);
  77: #else /* !TMAIL */
  78:             fprintf(stderr, "Usage: %s [ -a [ date ]] [ -n newsgroups ] [ -t titles ] [ -lprxhfu ]\n", Progname);
  79: #endif /* !TMAIL */
  80:             fprintf(stderr, "\t[ -c [ ``mailer'' ]]\n\n");
  81:             fprintf(stderr, "       %s -s\n", Progname);
  82:             exit(1);
  83: 
  84:             found:;
  85:             if (mode != UNKNOWN && (mode&optpt->oldmode) == 0) {
  86:                 xerror("Bad %c option", **argv);
  87:             }
  88:             if (mode == UNKNOWN)
  89:                 mode = optpt->newmode;
  90:             filchar = optpt->filchar;
  91:             optpt->flag = TRUE;
  92:             state = optpt->newstate;
  93:             ptr = optpt->buf;
  94:             len = BUFLEN;
  95:         }
  96: 
  97:         argv++;     /* done with this option arg. */
  98: 
  99:         } else {
 100: 
 101:         /*
 102: 		 * Pick up a piece of a string and put it into
 103: 		 * the appropriate buffer.
 104: 		 */
 105:         if (**argv == '-') {
 106:             state = OPTION;
 107:             argc++; /* uncount this arg. */
 108:             continue;
 109:         }
 110: 
 111:         if ((tlen = strlen(*argv)) >= len)
 112:             xerror("Argument string too long");
 113:         strcpy(ptr, *argv++);
 114:         ptr += tlen;
 115:         if (*(ptr-1) != filchar)
 116:             *ptr++ = filchar;
 117:         len -= tlen + 1;
 118:         *ptr = '\0';
 119:         }
 120:     }
 121:     return;
 122: }

Defined functions

Defined variables

SccsId defined in line 19; never used
options defined in line 27; used 15 times
optpt defined in line 27; used 10 times

Defined macros

OPTION defined in line 24; used 12 times
STRING defined in line 25; used 6 times
Last modified: 1986-01-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1045
Valid CSS Valid XHTML 1.0 Strict