Activated Jon's attachment system by default and steamlined it.
[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         { "buildmimeproc", &buildmimeproc },
26         { "fileproc",      &fileproc },
27         { "incproc",       &incproc },
28         { "lproc",         &lproc },
29         { "mailproc",      &mailproc },
30         { "mhlproc",       &mhlproc },
31         { "moreproc",      &moreproc },
32         { "postproc",      &postproc },
33         { "rmmproc",       &rmmproc },
34         { "sendmail",      &sendmail },
35         { "sendproc",      &sendproc },
36         { "showmimeproc",  &showmimeproc },
37         { "showproc",      &showproc },
38         { "whatnowproc",   &whatnowproc },
39         { NULL, NULL }
40 };
41
42 static struct node **opp = NULL;
43
44
45 void
46 readconfig(struct node **npp, FILE *ib, char *file, int ctx)
47 {
48         register int state;
49         register char *cp;
50         char name[NAMESZ], field[BUFSIZ];
51         register struct node *np;
52         register struct procstr *ps;
53
54         if (npp == NULL && (npp = opp) == NULL) {
55                 admonish(NULL, "bug: readconfig called but pump not primed");
56                 return;
57         }
58
59         for (state = FLD;;) {
60                 switch (state = m_getfld(state, name, field, sizeof(field),
61                                 ib)) {
62                 case FLD:
63                 case FLDPLUS:
64                 case FLDEOF:
65                         np = (struct node *) mh_xmalloc(sizeof(*np));
66                         *npp = np;
67                         *(npp = &np->n_next) = NULL;
68                         np->n_name = getcpy(name);
69                         if (state == FLDPLUS) {
70                                 cp = getcpy(field);
71                                 while (state == FLDPLUS) {
72                                         state = m_getfld(state, name, field,
73                                                         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
85                         ** the field value to the global variable.
86                         */
87                         for (ps = procs; ps->procname; ps++)
88                                 if (mh_strcasecmp(np->n_name,
89                                                 ps->procname) == 0) {
90                                         *ps->procnaddr = np->n_field;
91                                         break;
92                                 }
93                         if (state == FLDEOF)
94                                 break;
95                         continue;
96
97                 case BODY:
98                 case BODYEOF:
99                         adios(NULL, "no blank lines are permitted in %s",
100                                         file);
101
102                 case FILEEOF:
103                         break;
104
105                 default:
106                         adios(NULL, "%s is poorly formatted", file);
107                 }
108                 break;
109         }
110
111         opp = npp;
112 }