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