]>
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
= 0;
52 if (npp
== NULL
&& (npp
= opp
) == NULL
) {
53 inform("bug: readconfig called but pump not primed, continuing...");
58 int fieldsz
= sizeof field
;
59 switch (state
= m_getfld (&gstate
, name
, field
, &fieldsz
, ib
)) {
64 *(npp
= &np
->n_next
) = NULL
;
65 np
->n_name
= mh_xstrdup(name
);
66 if (state
== FLDPLUS
) {
67 cp
= mh_xstrdup(field
);
68 while (state
== FLDPLUS
) {
69 fieldsz
= sizeof field
;
70 state
= m_getfld (&gstate
, name
, field
, &fieldsz
, ib
);
73 np
->n_field
= trimcpy (cp
);
76 np
->n_field
= trimcpy (field
);
81 * Now scan the list of `procs' and link in the
82 * field value to the global variable.
84 for (ps
= procs
; ps
->procname
; ps
++)
85 if (strcmp (np
->n_name
, ps
->procname
) == 0) {
86 *ps
->procnaddr
= np
->n_field
;
92 adios (NULL
, "no blank lines are permitted in %s", file
);
98 adios (NULL
, "%s is poorly formatted", file
);
102 m_getfld_state_destroy (&gstate
);
105 * Special handling for the pager processes: lproc and moreproc.
107 * If they are not set by the profile, use the callers $PAGER if
108 * available, otherwise set them to DEFAULT_PAGER.
111 lproc
= getenv("PAGER");
112 if (lproc
== NULL
|| lproc
[0] == '\0')
113 lproc
= DEFAULT_PAGER
;
115 if (moreproc
== NULL
) {
116 moreproc
= getenv("PAGER");
117 if (moreproc
== NULL
|| moreproc
[0] == '\0')
118 moreproc
= DEFAULT_PAGER
;
122 /* Check for duplicated non-null profile entries. Except
123 allow multiple profile entries named "#", because that's
124 what the mh-profile man page suggests using for comments.
126 Only do this check on the very first call from
127 context_read(), when opp is NULL. That way, entries in
128 mhn.defaults can be overridden without triggering
131 Note that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
132 $MHSTORE all put their entries into just one list, m_defs,
133 the same list that the profile uses. */
136 for (np
= m_defs
; np
; np
= np
->n_next
) {
137 /* Yes, this is O(N^2). The profile should be small enough so
138 that's not a performance problem. */
139 if (*np
->n_name
&& strcmp("#", np
->n_name
)) {
141 for (np2
= np
->n_next
; np2
; np2
= np2
->n_next
) {
142 if (! strcasecmp (np
->n_name
, np2
->n_name
)) {
143 inform("multiple \"%s\" profile components in %s, "
144 "ignoring \"%s\", continuing...",
145 np
->n_name
, defpath
, np2
->n_field
);
157 add_profile_entry (const char *key
, const char *value
) {
158 struct node
*newnode
;
160 /* This inserts the new node at the beginning of m_defs because
161 that doesn't require traversing it or checking to see if it's
164 newnode
->n_name
= getcpy (key
);
165 newnode
->n_field
= getcpy (value
);
166 newnode
->n_context
= 0;
167 newnode
->n_next
= m_defs
;