Removed configure option --with-hash-prefix and moved backup-prefix to profile
[mmh] / sbr / readconfig.c
1
2 /*
3  * readconfig.c -- base routine to read nmh configuration files
4  *              -- such as nmh profile, context file, or mhn.defaults.
5  *
6  * This code is Copyright (c) 2002, by the authors of nmh.  See the
7  * COPYRIGHT file in the root directory of the nmh distribution for
8  * complete copyright information.
9  */
10
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     { "context",       &context },
21     { "mh-sequences",  &mh_seq },
22     { "backup-prefix", &backup_prefix },
23     { "buildmimeproc", &buildmimeproc },
24     { "faceproc",      &faceproc },
25     { "fileproc",      &fileproc },
26     { "incproc",       &incproc },
27     { "installproc",   &installproc },
28     { "lproc",         &lproc },
29     { "mailproc",      &mailproc },
30     { "mhlproc",       &mhlproc },
31     { "moreproc",      &moreproc },
32     { "mshproc",       &mshproc },
33     { "packproc",      &packproc },
34     { "postproc",      &postproc },
35     { "rmfproc",       &rmfproc },
36     { "rmmproc",       &rmmproc },
37     { "sendmail",      &sendmail },
38     { "sendproc",      &sendproc },
39     { "showmimeproc",  &showmimeproc },
40     { "showproc",      &showproc },
41     { "vmhproc",       &vmhproc },
42     { "whatnowproc",   &whatnowproc },
43     { "whomproc",      &whomproc },
44     { NULL,            NULL }
45 };
46
47 static struct node **opp = NULL;
48
49
50 void
51 readconfig (struct node **npp, FILE *ib, char *file, int ctx)
52 {
53     register int state;
54     register char *cp;
55     char name[NAMESZ], field[BUFSIZ];
56     register struct node *np;
57     register struct procstr *ps;
58
59     if (npp == NULL && (npp = opp) == NULL) {
60         admonish (NULL, "bug: readconfig called but pump not primed");
61         return;
62     }
63
64     for (state = FLD;;) {
65         switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
66             case FLD:
67             case FLDPLUS:
68             case FLDEOF:
69                 np = (struct node *) mh_xmalloc (sizeof(*np));
70                 *npp = np;
71                 *(npp = &np->n_next) = NULL;
72                 np->n_name = getcpy (name);
73                 if (state == FLDPLUS) {
74                     cp = getcpy (field);
75                     while (state == FLDPLUS) {
76                         state = m_getfld (state, name, field, sizeof(field), ib);
77                         cp = add (field, cp);
78                     }
79                     np->n_field = trimcpy (cp);
80                     free (cp);
81                 } else {
82                     np->n_field = trimcpy (field);
83                 }
84                 np->n_context = ctx;
85
86                 /*
87                  * Now scan the list of `procs' and link in the
88                  * field value to the global variable.
89                  */
90                 for (ps = procs; ps->procname; ps++)
91                     if (strcmp (np->n_name, ps->procname) == 0) {
92                         *ps->procnaddr = np->n_field;
93                         break;
94                     }
95                 if (state == FLDEOF)
96                     break;
97                 continue;
98
99             case BODY:
100             case BODYEOF:
101                 adios (NULL, "no blank lines are permitted in %s", file);
102
103             case FILEEOF:
104                 break;
105
106             default:
107                 adios (NULL, "%s is poorly formatted", file);
108         }
109         break;
110     }
111
112     opp = npp;
113 }