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