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