Removed the `mhbuild' indirection via `buildmimeproc'.
[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         { "attachment-header",  &attach_hdr },
20         { "context",       &context },
21         { "mh-sequences",  &mh_seq },
22         { "backup-prefix", &backup_prefix },
23         { "draft-folder",  &draftfolder },
24         { "altmsg-link",   &altmsglink },
25         { "fileproc",      &fileproc },
26         { "incproc",       &incproc },
27         { "lproc",         &lproc },
28         { "mailproc",      &mailproc },
29         { "mhlproc",       &mhlproc },
30         { "postproc",      &postproc },
31         { "rmmproc",       &rmmproc },
32         { "sendmail",      &sendmail },
33         { "sendproc",      &sendproc },
34         { "showmimeproc",  &showmimeproc },
35         { "showproc",      &showproc },
36         { "whatnowproc",   &whatnowproc },
37         { NULL, NULL }
38 };
39
40 static struct node **opp = NULL;
41
42
43 void
44 readconfig(struct node **npp, FILE *ib, char *file, int ctx)
45 {
46         register int state;
47         register char *cp;
48         char name[NAMESZ], field[BUFSIZ];
49         register struct node *np;
50         register struct procstr *ps;
51
52         if (npp == NULL && (npp = opp) == NULL) {
53                 admonish(NULL, "bug: readconfig called but pump not primed");
54                 return;
55         }
56
57         for (state = FLD;;) {
58                 switch (state = m_getfld(state, name, field, sizeof(field),
59                                 ib)) {
60                 case FLD:
61                 case FLDPLUS:
62                 case FLDEOF:
63                         np = (struct node *) mh_xmalloc(sizeof(*np));
64                         *npp = np;
65                         *(npp = &np->n_next) = NULL;
66                         np->n_name = getcpy(name);
67                         if (state == FLDPLUS) {
68                                 cp = getcpy(field);
69                                 while (state == FLDPLUS) {
70                                         state = m_getfld(state, name, field,
71                                                         sizeof(field), ib);
72                                         cp = add(field, cp);
73                                 }
74                                 np->n_field = trimcpy(cp);
75                                 free(cp);
76                         } else {
77                                 np->n_field = trimcpy(field);
78                         }
79                         np->n_context = ctx;
80
81                         /*
82                         ** Now scan the list of `procs' and link in
83                         ** the field value to the global variable.
84                         */
85                         for (ps = procs; ps->procname; ps++)
86                                 if (mh_strcasecmp(np->n_name,
87                                                 ps->procname) == 0) {
88                                         *ps->procnaddr = np->n_field;
89                                         break;
90                                 }
91                         if (state == FLDEOF)
92                                 break;
93                         continue;
94
95                 case BODY:
96                 case BODYEOF:
97                         adios(NULL, "no blank lines are permitted in %s",
98                                         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 }