# 2.11BSD#431 - /usr/src/new/notes/src/expand.c

##### Functions

    addgrp            X
    delgroup          X
    expand            X
    nextgroup         X
    readrc            X
    setseq            X

##### Macros

    MAXGROUP          X

       1: #include "parms.h"
       2: #include "structs.h"
       3: #include <ctype.h>
       4: #include <signal.h>
       5:
       6: #ifdef  RCSIDENT
       7: static char *rcsident = "$Header: expand.c,v 1.7.0.1 85/11/08 08:10:41 notes Rel $";
       8: #endif
       9:
      10: /*
      11:  *	Routines to expand notesgroups specifications
      12:  *
      13:  *	Rick L Spickelmier, UC Berkeley
      14:  *	Lou Salkind, NYU
      15:  */
      16:
      17: #define     MAXGROUP    700         /* lots of them */
      18:                             /* was 1000 -sms */
      19:
      20:
      21: static int  seqtyp = NOSEQ;             /* sequencer mode */
      22: static int  last_group = 0;             /* active in list */
      23: static int  this_group = 0;             /* next one to show */
      24: static struct nflist_f  groups[MAXGROUP];       /* and the groups */
      25:
      26: /*
      27:  * set the sequencer type (external interface)
      28:  */
      29:
      30: setseq (i)
      31: {
      32:     seqtyp = i;
      33: }
      34:
      35: /*
      36:  * add a notesfile to the active list
      37:  */
      38:
      39: addgrp (string)
      40: char   *string;
      41: {
      42:     int     i;
      43:
      44:     /* see if it already exists */
      45:     for (i = 0; i < last_group; i++)
      46:     {
      47:     if (strcmp (groups[i].nf_name, string) == 0)
      48:     {                       /* already in table */
      49:         groups[i].nf_active = TRUE;         /* deleted earlier? */
      50:         groups[i].nf_seqmode = seqtyp;
      51:         return;
      52:     }
      53:     }
      54:     if (last_group >= MAXGROUP)
      55:     {
      56:     printf ("addgrp: array overflow, ignoring %s\n", string);
      57:     return;
      58:     }
      59:     groups[last_group].nf_active = TRUE;
      60:     groups[last_group].nf_seqmode = seqtyp;
      61:     groups[last_group++].nf_name = strsave (string);
      62: }
      63:
      64: /*
      65:  * delete the notesfile from the active list
      66:  */
      67:
      68: delgroup (string)
      69: char   *string;
      70: {
      71:     register int    i;                  /* might as well be fast */
      72:
      73:     for (i = 0; i < last_group; i++)
      74:     {
      75:     if (strcmp (groups[i].nf_name, string) == 0)
      76:     {
      77:         groups[i].nf_active = FALSE;
      78:         return;
      79:     }
      80:     }
      81: }
      82:
      83: /*
      84:  * given a command line argument, expand it into
      85:  * the appropriate sequence command or notesfile
      86:  * specification
      87:  */
      88:
      89: expand (argp)
      90: char   *argp;
      91: {
      92:     char   *endp;
      93:
      94:     while (1)                       /* do entire string */
      95:     {
      96:     while (isspace (*argp))             /* skip trash chars */
      97:         argp++;
      98:     if (*argp == '\0')              /* fell off end */
      99:         return;
     100:     endp = argp;
     101:     while (*endp)
     102:     {
     103:         if (isspace (*endp) || *endp == ',')
     104:         {
     105:         *endp++ = '\0';
     106:         break;
     107:         }
     108:         endp++;                 /* now points at next (or NULL) */
     109:     }
     110:
     111:     switch (argp[0])                /* on first character */
     112:     {
     113: /*
     114:  *	Parse options that make sense at this point.
     115:  */
     116:         case '-':                   /* options */
     117:         {
     118:             switch (argp[1])
     119:             {
     120:             case 's':           /* -S-equencer */
     121:                 seqtyp = NORMSEQ;
     122:                 break;
     123:             case 'x':           /* e-X-tended sequencer */
     124:                 seqtyp = EXTSEQ;
     125:                 break;
     126:             case 'i':           /* indexing sequencer */
     127:                 seqtyp = INDXSEQ;
     128:                 break;
     129:             case 'n':           /* -N-o sequencer */
     130:                 seqtyp = NOSEQ;
     131:                 break;
     132:
     133:             default:
     134:                 break;          /* ignore it */
     135:             }
     136:             break;
     137:         }
     138:
     139: /*
     140:  *	specified a file  the hard way (via colon).  This usually
     141:  *	happens in the NFSEQ definition
     142:  */
     143:
     144:         case ':':                   /* include a file */
     145:         readrc (&argp[1]);          /* do it */
     146:         break;
     147:
     148: /*
     149:  *	Eliminate notesfles.  If the arg is "! pattern", we remove the
     150:  *	notesfiles that "pattern" matches from the list of notesfiles
     151:  *	to read.
     152:  *
     153:  */
     154:         case '!':                   /* eliminate notesfiles */
     155:         {
     156:             if (patcheck (&argp[1]))        /* wildcard */
     157:             dopat (&argp[1], delgroup);
     158:             else
     159:             delgroup (&argp[1]);
     160:             break;
     161:         }
     162: /*
     163:  *	Anything else is just a "pattern" and specifies some notesfiles
     164:  *	to be added to the list.
     165:  */
     166:         default:                    /* add notesfiles */
     167:         {
     168:             if (patcheck (argp))        /* wildcard check */
     169:             dopat (argp, addgrp);
     170:             else
     171:             addgrp (argp);
     172:             break;
     173:         }
     174:     }
     175:     argp = endp;
     176:     }
     177:                             /* NOT REACHED */
     178: }
     179:
     180: /*
     181:  * read a file which contains the command line arguments
     182:  */
     183:
     184: readrc (s)
     185: char   *s;
     186: {
     187:     FILE * f;
     188:     char    buf[BUFSIZ];
     189:
     190:     if ((f = fopen (s, "r")) == NULL)
     191:     {
     192:     fprintf (stderr, "%s: unable to read file ", Invokedas);
     193:     perror (s);                 /* and the error */
     194:     return (-1);
     195:     }
     196:     while (fgets (buf, sizeof buf - 1, f))
     197:     expand (buf);
     198:     fclose (f);
     199:     return (0);
     200: }
     201:
     202: /*
     203:  *	return the next active notesfile in the list
     204:  */
     205:
     206: struct nflist_f *nextgroup ()
     207: {
     208:     while           (this_group < last_group)
     209:     {
     210:     if              (groups[this_group].nf_active)
     211:                         return (&groups[this_group++]);/* give it */
     212:     else
     213:         this_group++;               /* try another */
     214:     }
     215:     return ((struct nflist_f *) NULL);          /* no more */
     216: }

#### Defined functions

addgrp defined in line 39; used 2 times

- in line 169-171(2)

delgroup defined in line 68; used 2 times

- in line 157-159(2)

expand defined in line 89; used 17 times

- in line 197
- in /usr/src/new/notes/src/checknotes.c line 114, 155
- in /usr/src/new/notes/src/main.c line 82, 96, 166, 185, 194
- in /usr/src/new/notes/src/newsinput.c line 146
- in /usr/src/new/notes/src/newsoutput.c line 185
- in /usr/src/new/notes/src/nfaccess.c line 48
- in /usr/src/new/notes/src/nfadmin.c line 127
- in /usr/src/new/notes/src/nfarchive.c line 106
- in /usr/src/new/notes/src/nfstats.c line 139
- in /usr/src/new/notes/src/nftimestamp.c line 91
- in /usr/src/new/notes/src/nfxmit.c line 190
- in /usr/src/new/notes/src/rmnf.c line 56

nextgroup defined in line 206; used 12 times

- in /usr/src/new/notes/src/checknotes.c line 157
- in /usr/src/new/notes/src/main.c line 208
- in /usr/src/new/notes/src/newsinput.c line 147
- in /usr/src/new/notes/src/newsoutput.c line 235
- in /usr/src/new/notes/src/nfaccess.c line 51
- in /usr/src/new/notes/src/nfadmin.c line 130
- in /usr/src/new/notes/src/nfarchive.c line 113
- in /usr/src/new/notes/src/nfstats.c line 142
- in /usr/src/new/notes/src/nftimestamp.c line 94
- in /usr/src/new/notes/src/nfxmit.c line 207
- in /usr/src/new/notes/src/rmnf.c line 59
- in /usr/src/new/notes/src/structs.h line 418

readrc defined in line 184; used 8 times

- in line 145
- in /usr/src/new/notes/src/main.c line 114, 193
- in /usr/src/new/notes/src/newsoutput.c line 145
- in /usr/src/new/notes/src/nfadmin.c line 36
- in /usr/src/new/notes/src/nfarchive.c line 98
- in /usr/src/new/notes/src/nftimestamp.c line 70
- in /usr/src/new/notes/src/nfxmit.c line 180

setseq defined in line 30; used 2 times

- in /usr/src/new/notes/src/main.c line 59, 146

#### Defined variables

groups defined in line 24; used 10 times

- in line 47-50(3), 59-61(3), 75-77(2), 210-211(2)

last_group defined in line 22; used 7 times

- in line 45, 54-61(4), 73, 208

rcsident defined in line 7; never used
seqtyp defined in line 21; used 7 times

- in line 32, 50, 60, 121-130(4)

this_group defined in line 23; used 4 times

- in line 208-213(4)

#### Defined macros

MAXGROUP defined in line 17; used 2 times

- in line 24, 54

Last modified: 1989-07-18 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 947 |