source: trunk/third/nmh/sbr/readconfig.c @ 12455

Revision 12455, 2.6 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12454, which included commits to RCS files with non-trunk default branches.
Line 
1
2/*
3 * readconfig.c -- base routine to read nmh configuration files
4 *              -- such as nmh profile, context file, or mhn.defaults.
5 *
6 * $Id: readconfig.c,v 1.1.1.1 1999-02-07 18:14:09 danw Exp $
7 */
8
9#include <h/mh.h>
10
11struct procstr {
12    char *procname;
13    char **procnaddr;
14};
15
16static struct procstr procs[] = {
17    { "context",       &context },
18    { "mh-sequences",  &mh_seq },
19    { "buildmimeproc", &buildmimeproc },
20    { "faceproc",      &faceproc },
21    { "fileproc",      &fileproc },
22    { "incproc",       &incproc },
23    { "installproc",   &installproc },
24    { "lproc",         &lproc },
25    { "mailproc",      &mailproc },
26    { "mhlproc",       &mhlproc },
27    { "moreproc",      &moreproc },
28    { "mshproc",       &mshproc },
29    { "packproc",      &packproc },
30    { "postproc",      &postproc },
31    { "rmfproc",       &rmfproc },
32    { "rmmproc",       &rmmproc },
33    { "sendproc",      &sendproc },
34    { "showmimeproc",  &showmimeproc },
35    { "showproc",      &showproc },
36    { "vmhproc",       &vmhproc },
37    { "whatnowproc",   &whatnowproc },
38    { "whomproc",      &whomproc },
39    { NULL,            NULL }
40};
41
42static struct node **opp = NULL;
43
44
45void
46readconfig (struct node **npp, FILE *ib, char *file, int ctx)
47{
48    register int state;
49    register char *cp;
50    char name[NAMESZ], field[BUFSIZ];
51    register struct node *np;
52    register struct procstr *ps;
53
54    if (npp == NULL && (npp = opp) == NULL) {
55        admonish (NULL, "bug: readconfig called but pump not primed");
56        return;
57    }
58
59    for (state = FLD;;) {
60        switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
61            case FLD:
62            case FLDPLUS:
63            case FLDEOF:
64                if (!(np = (struct node *) malloc (sizeof(*np))))
65                    adios (NULL, "unable to allocate profile storage");
66                *npp = np;
67                *(npp = &np->n_next) = NULL;
68                np->n_name = getcpy (name);
69                if (state == FLDPLUS) {
70                    cp = getcpy (field);
71                    while (state == FLDPLUS) {
72                        state = m_getfld (state, name, field, 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 the
84                 * field value to the global variable.
85                 */
86                for (ps = procs; ps->procname; ps++)
87                    if (strcmp (np->n_name, ps->procname) == 0) {
88                        *ps->procnaddr = np->n_field;
89                        break;
90                    }
91                if (state == FLDEOF)
92                    break;
93                continue;
94
95            case BODY:
96            case BODYEOF:
97                adios (NULL, "no blank lines are permitted in %s", file);
98
99            case FILEEOF:
100                break;
101
102            default:
103                adios (NULL, "%s is poorly formatted", file);
104        }
105        break;
106    }
107
108    opp = npp;
109}
Note: See TracBrowser for help on using the repository browser.