]> diplodocus.org Git - nmh/blob - sbr/readconfig.c
Fix a segfault that happens when using the -file option.
[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 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
9 */
10
11 #include <h/mh.h>
12 #include <h/utils.h>
13
14 struct procstr {
15 char *procname;
16 char **procnaddr;
17 };
18
19 static struct procstr procs[] = {
20 { "context", &context },
21 { "mh-sequences", &mh_seq },
22 { "buildmimeproc", &buildmimeproc },
23 { "faceproc", &faceproc },
24 { "fileproc", &fileproc },
25 { "formatproc", &formatproc },
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 np = (struct node *) mh_xmalloc (sizeof(*np));
69 *npp = np;
70 *(npp = &np->n_next) = NULL;
71 np->n_name = getcpy (name);
72 if (state == FLDPLUS) {
73 cp = getcpy (field);
74 while (state == FLDPLUS) {
75 state = m_getfld (state, name, field, sizeof(field), ib);
76 cp = add (field, cp);
77 }
78 np->n_field = trimcpy (cp);
79 free (cp);
80 } else {
81 np->n_field = trimcpy (field);
82 }
83 np->n_context = ctx;
84
85 /*
86 * Now scan the list of `procs' and link in the
87 * field value to the global variable.
88 */
89 for (ps = procs; ps->procname; ps++)
90 if (strcmp (np->n_name, ps->procname) == 0) {
91 *ps->procnaddr = np->n_field;
92 break;
93 }
94 if (state == FLDEOF)
95 break;
96 continue;
97
98 case BODY:
99 case BODYEOF:
100 adios (NULL, "no blank lines are permitted in %s", file);
101
102 case FILEEOF:
103 break;
104
105 default:
106 adios (NULL, "%s is poorly formatted", file);
107 }
108 break;
109 }
110
111 opp = npp;
112 }