remove unnecessary casts
[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 <sysexits.h>
11 #include <h/mh.h>
12 #include <h/utils.h>
13
14 struct procstr {
15         char *procname;
16         char **procnaddr;
17 };
18
19 static struct procstr procs[] = {
20         { "attachment-header",  &attach_hdr },
21         { "sign-header",   &sign_hdr },
22         { "enc-header",    &enc_hdr },
23         { "context",       &context },
24         { "mh-sequences",  &mh_seq },
25         { "draft-folder",  &draftfolder },
26         { "listproc",      &listproc },
27         { "sendmail",      &sendmail },
28         { "trash-folder",  &trashfolder },
29         { "whatnowproc",   &whatnowproc },
30         { NULL, NULL }
31 };
32
33 static struct node **opp = NULL;
34
35
36 void
37 readconfig(struct node **npp, FILE *ib, char *file, int ctx)
38 {
39         int state;
40         char *cp;
41         char name[NAMESZ], field[BUFSIZ];
42         struct node *np;
43         struct procstr *ps;
44
45         if (npp == NULL && (npp = opp) == NULL) {
46                 admonish(NULL, "bug: readconfig called but pump not primed");
47                 return;
48         }
49
50         for (state = FLD;;) {
51                 switch (state = m_getfld(state, name, field, sizeof(field),
52                                 ib)) {
53                 case FLD:
54                 case FLDPLUS:
55                         np = mh_xcalloc(1, sizeof(*np));
56                         *npp = np;
57                         *(npp = &np->n_next) = NULL;
58                         np->n_name = getcpy(name);
59                         if (state == FLDPLUS) {
60                                 cp = getcpy(field);
61                                 while (state == FLDPLUS) {
62                                         state = m_getfld(state, name, field,
63                                                         sizeof(field), ib);
64                                         cp = add(field, cp);
65                                 }
66                                 np->n_field = trimcpy(cp);
67                                 free(cp);
68                         } else {
69                                 np->n_field = trimcpy(field);
70                         }
71                         np->n_context = ctx;
72
73                         /*
74                         ** Now scan the list of `procs' and link in
75                         ** the field value to the global variable.
76                         */
77                         for (ps = procs; ps->procname; ps++)
78                                 if (mh_strcasecmp(np->n_name,
79                                                 ps->procname) == 0) {
80                                         *ps->procnaddr = np->n_field;
81                                         break;
82                                 }
83                         continue;
84
85                 case BODY:
86                         adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
87                                         file);
88
89                 case FILEEOF:
90                         break;
91
92                 default:
93                         adios(EX_CONFIG, NULL, "%s is poorly formatted", file);
94                 }
95                 break;
96         }
97
98         opp = npp;
99 }