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