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