]>
diplodocus.org Git - nmh/blob - sbr/readconfig.c
3 * readconfig.c -- base routine to read nmh configuration files
4 * -- such as nmh profile, context file, or mhn.defaults.
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.
19 static struct procstr procs
[] = {
20 { "context", &context
},
21 { "mh-sequences", &mh_seq
},
22 { "buildmimeproc", &buildmimeproc
},
23 { "fileproc", &fileproc
},
24 { "formatproc", &formatproc
},
25 { "incproc", &incproc
},
27 { "mailproc", &mailproc
},
28 { "mhlproc", &mhlproc
},
29 { "moreproc", &moreproc
},
30 { "mshproc", &mshproc
},
31 { "packproc", &packproc
},
32 { "postproc", &postproc
},
33 { "rmmproc", &rmmproc
},
34 { "sendproc", &sendproc
},
35 { "showmimeproc", &showmimeproc
},
36 { "showproc", &showproc
},
37 { "vmhproc", &vmhproc
},
38 { "whatnowproc", &whatnowproc
},
39 { "whomproc", &whomproc
},
43 static struct node
**opp
= NULL
;
47 readconfig (struct node
**npp
, FILE *ib
, char *file
, int ctx
)
51 char name
[NAMESZ
], field
[BUFSIZ
];
52 register struct node
*np
;
53 register struct procstr
*ps
;
54 m_getfld_state_t gstate
= 0;
56 if (npp
== NULL
&& (npp
= opp
) == NULL
) {
57 admonish (NULL
, "bug: readconfig called but pump not primed");
62 int fieldsz
= sizeof field
;
63 switch (state
= m_getfld (&gstate
, name
, field
, &fieldsz
, ib
)) {
66 np
= (struct node
*) mh_xmalloc (sizeof(*np
));
68 *(npp
= &np
->n_next
) = NULL
;
69 np
->n_name
= getcpy (name
);
70 if (state
== FLDPLUS
) {
72 while (state
== FLDPLUS
) {
73 fieldsz
= sizeof field
;
74 state
= m_getfld (&gstate
, name
, field
, &fieldsz
, ib
);
77 np
->n_field
= trimcpy (cp
);
80 np
->n_field
= trimcpy (field
);
85 * Now scan the list of `procs' and link in the
86 * field value to the global variable.
88 for (ps
= procs
; ps
->procname
; ps
++)
89 if (strcmp (np
->n_name
, ps
->procname
) == 0) {
90 *ps
->procnaddr
= np
->n_field
;
96 adios (NULL
, "no blank lines are permitted in %s", file
);
102 adios (NULL
, "%s is poorly formatted", file
);
106 m_getfld_state_destroy (&gstate
);
109 * Special handling for the pager processes: lproc and moreproc.
111 * If they are not set by the profile, use the callers $PAGER if
112 * available, otherwise set them to DEFAULT_PAGER.
115 lproc
= getenv("PAGER");
116 if (lproc
== NULL
|| lproc
[0] == '\0')
117 lproc
= DEFAULT_PAGER
;
119 if (moreproc
== NULL
) {
120 moreproc
= getenv("PAGER");
121 if (moreproc
== NULL
|| moreproc
[0] == '\0')
122 moreproc
= DEFAULT_PAGER
;
126 /* Check for duplicated non-null profile entries. Except
127 allow multiple profile entries named "#", because that's
128 what the mh-profile man page suggests using for comments.
130 Only do this check on the very first call from
131 context_read(), when opp is NULL. That way, entries in
132 mhn.defaults can be overridden without triggering
135 Note that that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
136 $MHSTORE all put their entries into just one list, m_defs,
137 the same list that the profile uses. */
140 for (np
= m_defs
; np
; np
= np
->n_next
) {
141 /* Yes, this is O(N^2). The profile should be small enough so
142 that's not a performance problem. */
143 if (strlen (np
->n_name
) > 0 && strcmp ("#", np
->n_name
)) {
145 for (np2
= np
->n_next
; np2
; np2
= np2
->n_next
) {
146 if (! mh_strcasecmp (np
->n_name
, np2
->n_name
)) {
147 admonish (NULL
, "multiple \"%s\" profile components "
148 "in %s, ignoring \"%s\"",
149 np
->n_name
, defpath
, np2
->n_field
);