]>
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 { "packproc", &packproc
},
31 { "postproc", &postproc
},
32 { "rmmproc", &rmmproc
},
33 { "sendproc", &sendproc
},
34 { "showmimeproc", &showmimeproc
},
35 { "showproc", &showproc
},
36 { "whatnowproc", &whatnowproc
},
37 { "whomproc", &whomproc
},
41 static struct node
**opp
= NULL
;
45 readconfig (struct node
**npp
, FILE *ib
, const char *file
, int ctx
)
49 char name
[NAMESZ
], field
[BUFSIZ
];
52 m_getfld_state_t gstate
= 0;
54 if (npp
== NULL
&& (npp
= opp
) == NULL
) {
55 admonish (NULL
, "bug: readconfig called but pump not primed");
60 int fieldsz
= sizeof field
;
61 switch (state
= m_getfld (&gstate
, name
, field
, &fieldsz
, ib
)) {
66 *(npp
= &np
->n_next
) = NULL
;
67 np
->n_name
= mh_xstrdup(name
);
68 if (state
== FLDPLUS
) {
69 cp
= mh_xstrdup(field
);
70 while (state
== FLDPLUS
) {
71 fieldsz
= sizeof field
;
72 state
= m_getfld (&gstate
, name
, field
, &fieldsz
, ib
);
75 np
->n_field
= trimcpy (cp
);
78 np
->n_field
= trimcpy (field
);
83 * Now scan the list of `procs' and link in the
84 * field value to the global variable.
86 for (ps
= procs
; ps
->procname
; ps
++)
87 if (strcmp (np
->n_name
, ps
->procname
) == 0) {
88 *ps
->procnaddr
= np
->n_field
;
94 adios (NULL
, "no blank lines are permitted in %s", file
);
100 adios (NULL
, "%s is poorly formatted", file
);
104 m_getfld_state_destroy (&gstate
);
107 * Special handling for the pager processes: lproc and moreproc.
109 * If they are not set by the profile, use the callers $PAGER if
110 * available, otherwise set them to DEFAULT_PAGER.
113 lproc
= getenv("PAGER");
114 if (lproc
== NULL
|| lproc
[0] == '\0')
115 lproc
= DEFAULT_PAGER
;
117 if (moreproc
== NULL
) {
118 moreproc
= getenv("PAGER");
119 if (moreproc
== NULL
|| moreproc
[0] == '\0')
120 moreproc
= DEFAULT_PAGER
;
124 /* Check for duplicated non-null profile entries. Except
125 allow multiple profile entries named "#", because that's
126 what the mh-profile man page suggests using for comments.
128 Only do this check on the very first call from
129 context_read(), when opp is NULL. That way, entries in
130 mhn.defaults can be overridden without triggering
133 Note that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
134 $MHSTORE all put their entries into just one list, m_defs,
135 the same list that the profile uses. */
138 for (np
= m_defs
; np
; np
= np
->n_next
) {
139 /* Yes, this is O(N^2). The profile should be small enough so
140 that's not a performance problem. */
141 if (*np
->n_name
&& strcmp("#", np
->n_name
)) {
143 for (np2
= np
->n_next
; np2
; np2
= np2
->n_next
) {
144 if (! strcasecmp (np
->n_name
, np2
->n_name
)) {
145 admonish (NULL
, "multiple \"%s\" profile components "
146 "in %s, ignoring \"%s\"",
147 np
->n_name
, defpath
, np2
->n_field
);
159 add_profile_entry (const char *key
, const char *value
) {
160 struct node
*newnode
;
162 /* This inserts the new node at the beginning of m_defs because
163 that doesn't require traversing it or checking to see if it's
166 newnode
->n_name
= getcpy (key
);
167 newnode
->n_field
= getcpy (value
);
168 newnode
->n_context
= 0;
169 newnode
->n_next
= m_defs
;