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
expand
defined in line
89; used 17 times
Defined variables
groups
defined in line
24; used 10 times
Defined macros