]> diplodocus.org Git - nmh/blob - sbr/readconfig.c
Fix stupid accidental dependence on a bash quirk in previous
[nmh] / sbr / readconfig.c
1
2 /*
3 * readconfig.c -- base routine to read nmh configuration files
4 * -- such as nmh profile, context file, or mhn.defaults.
5 *
6 * $Id$
7 *
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
11 */
12
13 #include <h/mh.h>
14
15 struct procstr {
16 char *procname;
17 char **procnaddr;
18 };
19
20 static struct procstr procs[] = {
21 { "context", &context },
22 { "mh-sequences", &mh_seq },
23 { "buildmimeproc", &buildmimeproc },
24 { "faceproc", &faceproc },
25 { "fileproc", &fileproc },
26 { "incproc", &incproc },
27 { "installproc", &installproc },
28 { "lproc", &lproc },
29 { "mailproc", &mailproc },
30 { "mhlproc", &mhlproc },
31 { "moreproc", &moreproc },
32 { "mshproc", &mshproc },
33 { "packproc", &packproc },
34 { "postproc", &postproc },
35 { "rmfproc", &rmfproc },
36 { "rmmproc", &rmmproc },
37 { "sendproc", &sendproc },
38 { "showmimeproc", &showmimeproc },
39 { "showproc", &showproc },
40 { "vmhproc", &vmhproc },
41 { "whatnowproc", &whatnowproc },
42 { "whomproc", &whomproc },
43 { NULL, NULL }
44 };
45
46 static struct node **opp = NULL;
47
48
49 void
50 readconfig (struct node **npp, FILE *ib, char *file, int ctx)
51 {
52 register int state;
53 register char *cp;
54 char name[NAMESZ], field[BUFSIZ];
55 register struct node *np;
56 register struct procstr *ps;
57
58 if (npp == NULL && (npp = opp) == NULL) {
59 admonish (NULL, "bug: readconfig called but pump not primed");
60 return;
61 }
62
63 for (state = FLD;;) {
64 switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
65 case FLD:
66 case FLDPLUS:
67 case FLDEOF:
68 if (!(np = (struct node *) malloc (sizeof(*np))))
69 adios (NULL, "unable to allocate profile storage");
70 *npp = np;
71 *(npp = &np->n_next) = NULL;
72 np->n_name = getcpy (name);
73 if (state == FLDPLUS) {
74 cp = getcpy (field);
75 while (state == FLDPLUS) {
76 state = m_getfld (state, name, field, sizeof(field), ib);
77 cp = add (field, cp);
78 }
79 np->n_field = trimcpy (cp);
80 free (cp);
81 } else {
82 np->n_field = trimcpy (field);
83 }
84 np->n_context = ctx;
85
86 /*
87 * Now scan the list of `procs' and link in the
88 * field value to the global variable.
89 */
90 for (ps = procs; ps->procname; ps++)
91 if (strcmp (np->n_name, ps->procname) == 0) {
92 *ps->procnaddr = np->n_field;
93 break;
94 }
95 if (state == FLDEOF)
96 break;
97 continue;
98
99 case BODY:
100 case BODYEOF:
101 adios (NULL, "no blank lines are permitted in %s", file);
102
103 case FILEEOF:
104 break;
105
106 default:
107 adios (NULL, "%s is poorly formatted", file);
108 }
109 break;
110 }
111
112 opp = npp;
113 }