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