Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / sbr / m_readefs.c
1 /* m_readefs.c - read a profile/context file */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: m_readefs.c,v 1.2 1994/04/29 04:58:00 jromine Exp $";
4 #endif
5
6 #include "../h/mh.h"
7 #include <stdio.h>
8
9
10 static struct procs {
11         char    *procname;
12         char    **procnaddr;
13 } procs [] = {
14         { "context",    &context        },
15         { "mh-sequences",
16                         &mh_seq         },
17         { "faceproc",   &faceproc       },
18         { "fileproc",   &fileproc       },
19         { "incproc",    &incproc        },
20         { "installproc",&installproc    },
21         { "lproc",      &lproc          },
22         { "mailproc",   &mailproc       },
23         { "mhlproc",    &mhlproc        },
24         { "moreproc",   &moreproc       },
25         { "mshproc",    &mshproc        },
26         { "packproc",   &packproc       },
27         { "postproc",   &postproc       },
28         { "rmfproc",    &rmfproc        },
29         { "rmmproc",    &rmmproc        },
30         { "sendproc",   &sendproc       },
31         { "showproc",   &showproc       },
32         { "slocalproc", &slocalproc     },
33         { "vmhproc",    &vmhproc        },
34         { "whatnowproc",
35                         &whatnowproc    },
36         { "whomproc",   &whomproc       },
37         { NULL,         NULL            }
38 };
39
40 static struct node **opp = NULL;
41
42
43 void    m_readefs (npp, ib, file, ctx)
44 register struct node **npp;
45 register FILE   *ib;
46 register char   *file;
47 register int     ctx;
48 {
49     register int    state;
50     register char  *cp;
51     char    name[NAMESZ],
52             field[BUFSIZ];
53     register struct node   *np;
54     register struct procs  *ps;
55
56     if (npp == NULL && (npp = opp) == NULL) {
57         admonish (NULLCP, "bug: m_readefs called but pump not primed");
58         return;
59     }
60
61     for (state = FLD;;) {
62         switch (state = m_getfld (state, name, field, sizeof field, ib)) {
63             case FLD:
64             case FLDPLUS:
65             case FLDEOF:
66                 np = (struct node *) malloc (sizeof *np);
67                 if (np == NULL)
68                     adios (NULLCP, "unable to allocate profile storage");
69                 *npp = np;
70                 *(npp = &np -> n_next) = NULL;
71                 np -> n_name = getcpy (name);
72                 if (state == FLDPLUS) {
73                     cp = getcpy (field);
74                     while (state == FLDPLUS) {
75                         state = m_getfld
76                                     (state, name, field, sizeof field, ib);
77                         cp = add (field, cp);
78                     }
79                     np -> n_field = trimcpy (cp);
80                     free (cp);
81                 }
82                 else
83                     np -> n_field = trimcpy (field);
84                 np -> n_context = ctx;
85                 for (ps = procs; ps -> procname; ps++)
86                     if (strcmp (np -> n_name, ps -> procname) == 0) {
87                         *ps -> procnaddr = np -> n_field;
88                         break;
89                     }
90                 if (state == FLDEOF)
91                     break;
92                 continue;
93
94             case BODY:
95             case BODYEOF:
96                 adios (NULLCP, "no blank lines are permitted in %s", file);
97
98             case FILEEOF:
99                 break;
100
101             default:
102                 adios (NULLCP, "%s is poorly formatted", file);
103         }
104         break;
105     }
106
107     opp = npp;
108 }