]>
diplodocus.org Git - nmh/blob - sbr/readconfig.c
1 /* readconfig.c -- base routine to read nmh configuration files
2 * -- such as nmh profile, context file, or mhn.defaults.
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
17 static struct procstr procs
[] = {
18 { "context", &context
},
19 { "mh-sequences", &mh_seq
},
20 { "buildmimeproc", &buildmimeproc
},
21 { "fileproc", &fileproc
},
22 { "formatproc", &formatproc
},
23 { "incproc", &incproc
},
25 { "mailproc", &mailproc
},
26 { "mhlproc", &mhlproc
},
27 { "moreproc", &moreproc
},
28 { "packproc", &packproc
},
29 { "postproc", &postproc
},
30 { "rmmproc", &rmmproc
},
31 { "sendproc", &sendproc
},
32 { "showmimeproc", &showmimeproc
},
33 { "showproc", &showproc
},
34 { "whatnowproc", &whatnowproc
},
35 { "whomproc", &whomproc
},
39 static struct node
**opp
= NULL
;
43 readconfig (struct node
**npp
, FILE *ib
, const char *file
, int ctx
)
47 char name
[NAMESZ
], field
[NMH_BUFSIZ
];
50 m_getfld_state_t gstate
;
52 if (npp
== NULL
&& (npp
= opp
) == NULL
) {
53 inform("bug: readconfig called but pump not primed, continuing...");
57 gstate
= m_getfld_state_init(ib
);
59 int fieldsz
= sizeof field
;
60 switch (state
= m_getfld2(&gstate
, name
, field
, &fieldsz
)) {
65 *(npp
= &np
->n_next
) = NULL
;
66 np
->n_name
= mh_xstrdup(name
);
67 if (state
== FLDPLUS
) {
68 cp
= mh_xstrdup(field
);
69 while (state
== FLDPLUS
) {
70 fieldsz
= sizeof field
;
71 state
= m_getfld2(&gstate
, name
, field
, &fieldsz
);
74 np
->n_field
= trimcpy (cp
);
77 np
->n_field
= trimcpy (field
);
82 * Now scan the list of `procs' and link in the
83 * field value to the global variable.
85 for (ps
= procs
; ps
->procname
; ps
++)
86 if (strcmp (np
->n_name
, ps
->procname
) == 0) {
87 *ps
->procnaddr
= np
->n_field
;
93 adios (NULL
, "no blank lines are permitted in %s", file
);
99 adios (NULL
, "%s is poorly formatted", file
);
103 m_getfld_state_destroy (&gstate
);
106 * Special handling for the pager processes: lproc and moreproc.
108 * If they are not set by the profile, use the callers $PAGER if
109 * available, otherwise set them to DEFAULT_PAGER.
112 lproc
= getenv("PAGER");
113 if (lproc
== NULL
|| lproc
[0] == '\0')
114 lproc
= DEFAULT_PAGER
;
116 if (moreproc
== NULL
) {
117 moreproc
= getenv("PAGER");
118 if (moreproc
== NULL
|| moreproc
[0] == '\0')
119 moreproc
= DEFAULT_PAGER
;
123 /* Check for duplicated non-null profile entries. Except
124 allow multiple profile entries named "#", because that's
125 what mh-profile(5) suggests using for comments.
127 Only do this check on the very first call from
128 context_read(), when opp is NULL. That way, entries in
129 mhn.defaults can be overridden without triggering
132 Note that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
133 $MHSTORE all put their entries into just one list, m_defs,
134 the same list that the profile uses. */
137 for (np
= m_defs
; np
; np
= np
->n_next
) {
138 /* Yes, this is O(N^2). The profile should be small enough so
139 that's not a performance problem. */
140 if (*np
->n_name
&& strcmp("#", np
->n_name
)) {
142 for (np2
= np
->n_next
; np2
; np2
= np2
->n_next
) {
143 if (! strcasecmp (np
->n_name
, np2
->n_name
)) {
144 inform("multiple \"%s\" profile components in %s, "
145 "ignoring \"%s\", continuing...",
146 np
->n_name
, defpath
, np2
->n_field
);
158 add_profile_entry (const char *key
, const char *value
) {
159 struct node
*newnode
;
161 /* This inserts the new node at the beginning of m_defs because
162 that doesn't require traversing it or checking to see if it's
165 newnode
->n_name
= getcpy (key
);
166 newnode
->n_field
= getcpy (value
);
167 newnode
->n_context
= 0;
168 newnode
->n_next
= m_defs
;