]>
diplodocus.org Git - nmh/blob - sbr/readconfig.c
4e02738ca1e0aeba0f462dc26c0767b754e92b5d
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
},
26 { "installproc", &installproc
},
28 { "mailproc", &mailproc
},
29 { "mhlproc", &mhlproc
},
30 { "moreproc", &moreproc
},
31 { "mshproc", &mshproc
},
32 { "packproc", &packproc
},
33 { "postproc", &postproc
},
34 { "rmmproc", &rmmproc
},
35 { "sendproc", &sendproc
},
36 { "showmimeproc", &showmimeproc
},
37 { "showproc", &showproc
},
38 { "vmhproc", &vmhproc
},
39 { "whatnowproc", &whatnowproc
},
40 { "whomproc", &whomproc
},
44 static struct node
**opp
= NULL
;
48 readconfig (struct node
**npp
, FILE *ib
, char *file
, int ctx
)
52 char name
[NAMESZ
], field
[BUFSIZ
];
53 register struct node
*np
;
54 register struct procstr
*ps
;
55 m_getfld_state_t gstate
;
57 if (npp
== NULL
&& (npp
= opp
) == NULL
) {
58 admonish (NULL
, "bug: readconfig called but pump not primed");
62 m_getfld_state_init (&gstate
);
64 int fieldsz
= sizeof field
;
65 switch (state
= m_getfld (gstate
, name
, field
, &fieldsz
, ib
)) {
68 np
= (struct node
*) mh_xmalloc (sizeof(*np
));
70 *(npp
= &np
->n_next
) = NULL
;
71 np
->n_name
= getcpy (name
);
72 if (state
== FLDPLUS
) {
74 while (state
== FLDPLUS
) {
75 fieldsz
= sizeof field
;
76 state
= m_getfld (gstate
, name
, field
, &fieldsz
, ib
);
79 np
->n_field
= trimcpy (cp
);
82 np
->n_field
= trimcpy (field
);
87 * Now scan the list of `procs' and link in the
88 * field value to the global variable.
90 for (ps
= procs
; ps
->procname
; ps
++)
91 if (strcmp (np
->n_name
, ps
->procname
) == 0) {
92 *ps
->procnaddr
= np
->n_field
;
98 adios (NULL
, "no blank lines are permitted in %s", file
);
104 adios (NULL
, "%s is poorly formatted", file
);
108 m_getfld_state_destroy (&gstate
);
111 * Special handling for the pager processes: lproc and moreproc.
113 * If they are not set by the profile, use the callers $PAGER if
114 * available, otherwise set them to DEFAULT_PAGER.
117 lproc
= getenv("PAGER");
118 if (lproc
== NULL
|| lproc
[0] == '\0')
119 lproc
= DEFAULT_PAGER
;
121 if (moreproc
== NULL
) {
122 moreproc
= getenv("PAGER");
123 if (moreproc
== NULL
|| moreproc
[0] == '\0')
124 moreproc
= DEFAULT_PAGER
;
128 /* Check for duplicated non-null profile entries. Except
129 allow multiple profile entries named "#", because that's
130 what the mh-profile man page suggests using for comments.
132 Only do this check on the very first call from
133 context_read(), when opp is NULL. That way, entries in
134 mhn.defaults can be overridden without triggering
137 Note that that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
138 $MHSTORE all put their entries into just one list, m_defs,
139 the same list that the profile uses. */
142 for (np
= m_defs
; np
; np
= np
->n_next
) {
143 /* Yes, this is O(N^2). The profile should be small enough so
144 that's not a performance problem. */
145 if (strlen (np
->n_name
) > 0 && strcmp ("#", np
->n_name
)) {
147 for (np2
= np
->n_next
; np2
; np2
= np2
->n_next
) {
148 if (! mh_strcasecmp (np
->n_name
, np2
->n_name
)) {
149 admonish (NULL
, "multiple \"%s\" profile components "
150 "in %s, ignoring \"%s\"",
151 np
->n_name
, defpath
, np2
->n_field
);