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