Reworked LINK, now named `altmsglink', similar to BACKUP_PREFIX.
[mmh] / 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     { "backup-prefix", &backup_prefix },
23     { "altmsg-link",   &altmsglink },
24     { "buildmimeproc", &buildmimeproc },
25     { "faceproc",      &faceproc },
26     { "fileproc",      &fileproc },
27     { "incproc",       &incproc },
28     { "installproc",   &installproc },
29     { "lproc",         &lproc },
30     { "mailproc",      &mailproc },
31     { "mhlproc",       &mhlproc },
32     { "moreproc",      &moreproc },
33     { "mshproc",       &mshproc },
34     { "packproc",      &packproc },
35     { "postproc",      &postproc },
36     { "rmfproc",       &rmfproc },
37     { "rmmproc",       &rmmproc },
38     { "sendmail",      &sendmail },
39     { "sendproc",      &sendproc },
40     { "showmimeproc",  &showmimeproc },
41     { "showproc",      &showproc },
42     { "vmhproc",       &vmhproc },
43     { "whatnowproc",   &whatnowproc },
44     { "whomproc",      &whomproc },
45     { NULL,            NULL }
46 };
47
48 static struct node **opp = NULL;
49
50
51 void
52 readconfig (struct node **npp, FILE *ib, char *file, int ctx)
53 {
54     register int state;
55     register char *cp;
56     char name[NAMESZ], field[BUFSIZ];
57     register struct node *np;
58     register struct procstr *ps;
59
60     if (npp == NULL && (npp = opp) == NULL) {
61         admonish (NULL, "bug: readconfig called but pump not primed");
62         return;
63     }
64
65     for (state = FLD;;) {
66         switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
67             case FLD:
68             case FLDPLUS:
69             case FLDEOF:
70                 np = (struct node *) mh_xmalloc (sizeof(*np));
71                 *npp = np;
72                 *(npp = &np->n_next) = NULL;
73                 np->n_name = getcpy (name);
74                 if (state == FLDPLUS) {
75                     cp = getcpy (field);
76                     while (state == FLDPLUS) {
77                         state = m_getfld (state, name, field, sizeof(field), ib);
78                         cp = add (field, cp);
79                     }
80                     np->n_field = trimcpy (cp);
81                     free (cp);
82                 } else {
83                     np->n_field = trimcpy (field);
84                 }
85                 np->n_context = ctx;
86
87                 /*
88                  * Now scan the list of `procs' and link in the
89                  * field value to the global variable.
90                  */
91                 for (ps = procs; ps->procname; ps++)
92                     if (strcmp (np->n_name, ps->procname) == 0) {
93                         *ps->procnaddr = np->n_field;
94                         break;
95                     }
96                 if (state == FLDEOF)
97                     break;
98                 continue;
99
100             case BODY:
101             case BODYEOF:
102                 adios (NULL, "no blank lines are permitted in %s", file);
103
104             case FILEEOF:
105                 break;
106
107             default:
108                 adios (NULL, "%s is poorly formatted", file);
109         }
110         break;
111     }
112
113     opp = npp;
114 }