]>
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.
10 #include "sbr/context_find.h"
14 #include "readconfig.h"
18 static void checkconfig();
25 static struct procstr procs
[] = {
26 { "context", &context
},
27 { "mh-sequences", &mh_seq
},
28 { "buildmimeproc", &buildmimeproc
},
29 { "fileproc", &fileproc
},
30 { "formatproc", &formatproc
},
31 { "incproc", &incproc
},
33 { "mailproc", &mailproc
},
34 { "mhlproc", &mhlproc
},
35 { "moreproc", &moreproc
},
36 { "packproc", &packproc
},
37 { "postproc", &postproc
},
38 { "rmmproc", &rmmproc
},
39 { "sendproc", &sendproc
},
40 { "showmimeproc", &showmimeproc
},
41 { "showproc", &showproc
},
42 { "whatnowproc", &whatnowproc
},
43 { "whomproc", &whomproc
},
47 static struct node
**opp
= NULL
;
51 readconfig (struct node
**npp
, FILE *ib
, const char *file
, int ctx
)
55 char name
[NAMESZ
], field
[NMH_BUFSIZ
];
58 m_getfld_state_t gstate
;
60 if (npp
== NULL
&& (npp
= opp
) == NULL
) {
61 inform("bug: readconfig called but pump not primed, continuing...");
65 gstate
= m_getfld_state_init(ib
);
67 int fieldsz
= sizeof field
;
68 switch (state
= m_getfld2(&gstate
, name
, field
, &fieldsz
)) {
73 *(npp
= &np
->n_next
) = NULL
;
74 np
->n_name
= mh_xstrdup(name
);
75 if (state
== FLDPLUS
) {
76 cp
= mh_xstrdup(field
);
77 while (state
== FLDPLUS
) {
78 fieldsz
= sizeof field
;
79 state
= m_getfld2(&gstate
, name
, field
, &fieldsz
);
82 np
->n_field
= trimcpy (cp
);
85 np
->n_field
= trimcpy (field
);
90 * Now scan the list of `procs' and link in the
91 * field value to the global variable.
93 for (ps
= procs
; ps
->procname
; ps
++)
94 if (strcmp (np
->n_name
, ps
->procname
) == 0) {
95 *ps
->procnaddr
= np
->n_field
;
101 die("no blank lines are permitted in %s", file
);
107 die("%s is poorly formatted", file
);
111 m_getfld_state_destroy (&gstate
);
114 * Special handling for the pager processes: lproc and moreproc.
116 * If they are not set by the profile, use the callers $PAGER if
117 * available, otherwise set them to DEFAULT_PAGER.
120 lproc
= getenv("PAGER");
121 if (lproc
== NULL
|| lproc
[0] == '\0')
122 lproc
= DEFAULT_PAGER
;
124 if (moreproc
== NULL
) {
125 moreproc
= getenv("PAGER");
126 if (moreproc
== NULL
|| moreproc
[0] == '\0')
127 moreproc
= DEFAULT_PAGER
;
139 add_profile_entry (const char *key
, const char *value
)
141 struct node
*newnode
;
143 /* This inserts the new node at the beginning of m_defs because
144 that doesn't require traversing it or checking to see if it's
147 newnode
->n_name
= getcpy (key
);
148 newnode
->n_field
= getcpy (value
);
149 newnode
->n_context
= 0;
150 newnode
->n_next
= m_defs
;
155 /* Check profile for issues to warn about. */
158 /* Check for duplicated non-null profile entries. Except
159 allow multiple profile entries named "#", because that's
160 what mh-profile(5) suggests using for comments.
162 Only do this check on the very first call from
163 context_read(), when opp is NULL. That way, entries in
164 mhn.defaults can be overridden without triggering
167 Note that mhn.defaults, $MHN, $MHBUILD, $MHSHOW, and
168 $MHSTORE all put their entries into just one list, m_defs,
169 the same list that the profile uses. */
171 bool has_post
= false;
172 bool post_warning_disabled
= false;
173 for (np
= m_defs
; np
; np
= np
->n_next
) {
175 if (isatty(fileno(stderr
))) {
176 /* Check for post component in profile. */
177 if (strcasecmp(np
->n_name
, "post") == 0) {
179 } else if (strcasecmp(np
->n_name
, "postproc") == 0 &&
180 np
->n_field
!= NULL
) {
181 post_warning_disabled
= true;
185 if (strcmp("#", np
->n_name
)) {
186 /* Yes, this is O(N^2). The profile should be small enough so
187 that's not a performance problem. */
189 for (np2
= np
->n_next
; np2
; np2
= np2
->n_next
) {
190 if (! strcasecmp (np
->n_name
, np2
->n_name
)) {
191 inform("multiple \"%s\" profile components in %s, "
192 "ignoring \"%s\", continuing...",
193 np
->n_name
, defpath
, np2
->n_field
);
200 if (has_post
&& ! post_warning_disabled
) {
201 inform("post profile component will be ignored. To suppress "
203 "either remove it, comment it with #:, or "
204 "add the following to %s:\npostproc: %s\n",