Removed the whom program, which relayed on post(8) functionality.
[mmh] / sbr / readconfig.c
1 /*
2  * readconfig.c -- base routine to read nmh configuration files
3  *              -- such as nmh profile, context file, or mhn.defaults.
4  *
5  * This code is Copyright (c) 2002, by the authors of nmh.  See the
6  * COPYRIGHT file in the root directory of the nmh distribution for
7  * complete copyright information.
8  */
9
10 #include <h/mh.h>
11 #include <h/utils.h>
12
13 struct procstr {
14         char *procname;
15         char **procnaddr;
16 };
17
18 static struct procstr procs[] = {
19         { "context",       &context },
20         { "mh-sequences",  &mh_seq },
21         { "backup-prefix", &backup_prefix },
22         { "altmsg-link",   &altmsglink },
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         { "packproc",      &packproc },
33         { "postproc",      &postproc },
34         { "rmfproc",       &rmfproc },
35         { "rmmproc",       &rmmproc },
36         { "sendmail",      &sendmail },
37         { "sendproc",      &sendproc },
38         { "showmimeproc",  &showmimeproc },
39         { "showproc",      &showproc },
40         { "whatnowproc",   &whatnowproc },
41         { NULL, NULL }
42 };
43
44 static struct node **opp = NULL;
45
46
47 void
48 readconfig (struct node **npp, FILE *ib, char *file, int ctx)
49 {
50         register int state;
51         register char *cp;
52         char name[NAMESZ], field[BUFSIZ];
53         register struct node *np;
54         register struct procstr *ps;
55
56         if (npp == NULL && (npp = opp) == NULL) {
57                 admonish (NULL, "bug: readconfig called but pump not primed");
58                 return;
59         }
60
61         for (state = FLD;;) {
62                 switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
63                         case FLD:
64                         case FLDPLUS:
65                         case FLDEOF:
66                                 np = (struct node *) mh_xmalloc (sizeof(*np));
67                                 *npp = np;
68                                 *(npp = &np->n_next) = NULL;
69                                 np->n_name = getcpy (name);
70                                 if (state == FLDPLUS) {
71                                         cp = getcpy (field);
72                                         while (state == FLDPLUS) {
73                                                 state = m_getfld (state, name, field, sizeof(field), ib);
74                                                 cp = add (field, cp);
75                                         }
76                                         np->n_field = trimcpy (cp);
77                                         free (cp);
78                                 } else {
79                                         np->n_field = trimcpy (field);
80                                 }
81                                 np->n_context = ctx;
82
83                                 /*
84                                  * Now scan the list of `procs' and link in the
85                                  * field value to the global variable.
86                                  */
87                                 for (ps = procs; ps->procname; ps++)
88                                         if (strcmp (np->n_name, ps->procname) == 0) {
89                                                 *ps->procnaddr = np->n_field;
90                                                 break;
91                                         }
92                                 if (state == FLDEOF)
93                                         break;
94                                 continue;
95
96                         case BODY:
97                         case BODYEOF:
98                                 adios (NULL, "no blank lines are permitted in %s", file);
99
100                         case FILEEOF:
101                                 break;
102
103                         default:
104                                 adios (NULL, "%s is poorly formatted", file);
105                 }
106                 break;
107         }
108
109         opp = npp;
110 }