]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Use va_copy() to get a copy of va_list, instead of using original.
[nmh] / uip / mhparam.c
1 /* mhparam.c -- print mh_profile values
2 *
3 * Originally contributed by
4 * Jeffrey C Honig <Jeffrey_C_Honig@cornell.edu>
5 *
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.
9 */
10
11 #include <h/mh.h>
12 #include <h/mts.h>
13 #include "h/done.h"
14 #include <h/utils.h>
15
16 #define MHPARAM_SWITCHES \
17 X("components", 0, COMPSW) \
18 X("nocomponents", 0, NCOMPSW) \
19 X("all", 0, ALLSW) \
20 X("version", 0, VERSIONSW) \
21 X("help", 0, HELPSW) \
22 X("debug", 5, DEBUGSW) \
23
24 #define X(sw, minchars, id) id,
25 DEFINE_SWITCH_ENUM(MHPARAM);
26 #undef X
27
28 #define X(sw, minchars, id) { sw, minchars, id },
29 DEFINE_SWITCH_ARRAY(MHPARAM, switches);
30 #undef X
31
32 extern char *mhbindir;
33 extern char *mhlibexecdir;
34 extern char *mhetcdir;
35 extern char *mhdocdir;
36
37 static char *sbackup = BACKUP_PREFIX;
38
39 static char *datalocking = "fcntl";
40 static char *localmbox = "";
41 static bool localmbox_primed;
42
43 extern char *spoollocking;
44
45 static char *sasl =
46 #ifdef CYRUS_SASL
47 "cyrus_sasl";
48 #else
49 "";
50 #endif
51
52 static char *tls =
53 #ifdef TLS_SUPPORT
54 "tls";
55 #else
56 "";
57 #endif
58
59 static char *mimetypeproc =
60 #ifdef MIMETYPEPROC
61 MIMETYPEPROC;
62 #else
63 "";
64 #endif
65
66 static char *mimeencodingproc =
67 #ifdef MIMEENCODINGPROC
68 MIMEENCODINGPROC;
69 #else
70 "";
71 #endif
72
73 static char *iconv =
74 #ifdef HAVE_ICONV
75 "iconv";
76 #else
77 "";
78 #endif
79
80 static char *oauth =
81 #ifdef OAUTH_SUPPORT
82 "oauth";
83 #else
84 "";
85 #endif
86
87 struct proc {
88 char *p_name;
89 char **p_field;
90 };
91
92 static struct proc procs [] = {
93 { "context", &context },
94 { "mh-sequences", &mh_seq },
95 { "buildmimeproc", &buildmimeproc },
96 { "fileproc", &fileproc },
97 { "foldprot", &foldprot },
98 { "formatproc", &formatproc },
99 { "incproc", &incproc },
100 { "lproc", &lproc },
101 { "mailproc", &mailproc },
102 { "mhlproc", &mhlproc },
103 { "mimetypeproc", &mimetypeproc },
104 { "mimeencodingproc", &mimeencodingproc },
105 { "moreproc", &moreproc },
106 { "msgprot", &msgprot },
107 { "packproc", &packproc },
108 { "postproc", &postproc },
109 { "rmmproc", &rmmproc },
110 { "sendproc", &sendproc },
111 { "showmimeproc", &showmimeproc },
112 { "showproc", &showproc },
113 { "version", &version_num },
114 { "whatnowproc", &whatnowproc },
115 { "whomproc", &whomproc },
116 { "bindir", &mhbindir },
117 { "libexecdir", &mhlibexecdir },
118 { "etcdir", &mhetcdir },
119 { "docdir", &mhdocdir },
120 { "localmbox", &localmbox },
121 { "sbackup", &sbackup },
122 { "datalocking", &datalocking },
123 { "spoollocking", &spoollocking },
124 { "iconv", &iconv },
125 { "oauth", &oauth },
126 { "sasl", &sasl },
127 { "tls", &tls },
128 { NULL, NULL },
129 };
130
131
132 /*
133 * static prototypes
134 */
135 static char *p_find(char *) PURE;
136
137
138 int
139 main(int argc, char **argv)
140 {
141 int i, compp = 0;
142 bool missed;
143 bool all = false;
144 bool debug = false;
145 int components = -1;
146 char *cp, buf[BUFSIZ], **argp;
147 char **arguments, *comps[MAXARGS];
148
149 if (nmh_init(argv[0], true, false)) { return 1; }
150
151 arguments = getarguments (invo_name, argc, argv, 1);
152 argp = arguments;
153
154 while ((cp = *argp++)) {
155 if (*cp == '-') {
156 switch (smatch (++cp, switches)) {
157 case AMBIGSW:
158 ambigsw (cp, switches);
159 done (1);
160 case UNKWNSW:
161 die("-%s unknown", cp);
162
163 case HELPSW:
164 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
165 invo_name);
166 print_help (buf, switches, 1);
167 done (0);
168 case VERSIONSW:
169 print_version(invo_name);
170 done (0);
171
172 case COMPSW:
173 components = 1;
174 break;
175 case NCOMPSW:
176 components = 0;
177 break;
178
179 case ALLSW:
180 all = true;
181 break;
182
183 case DEBUGSW:
184 debug = true;
185 break;
186 }
187 } else {
188 comps[compp++] = cp;
189 if (strcmp("localmbox", cp) == 0 && ! localmbox_primed) {
190 localmbox = getlocalmbox();
191 localmbox_primed = true;
192 }
193 }
194 }
195
196 if (all) {
197 struct node *np;
198
199 if (compp)
200 inform("profile-components ignored with -all");
201
202 if (components >= 0)
203 inform("-%scomponents ignored with -all",
204 components ? "" : "no");
205
206 /* Print all entries in context/profile list. That does not
207 include entries in mts.conf, such as spoollocking. */
208 for (np = m_defs; np; np = np->n_next)
209 printf("%s: %s\n", np->n_name, np->n_field);
210
211 }
212
213 if (debug) {
214 struct proc *ps;
215
216 /* In case datalocking was set in profile. */
217 if ((cp = context_find("datalocking"))) { datalocking = cp; }
218
219 /* In case spoollocking was set in mts.conf. */
220 mts_init();
221
222 /* Also set localmbox here */
223 if (! localmbox_primed) {
224 localmbox = getlocalmbox();
225 localmbox_primed = true;
226 }
227
228 /*
229 * Print the current value of everything in
230 * procs array. This will show their current
231 * value (as determined after context is read).
232 */
233 for (ps = procs; ps->p_name; ps++)
234 printf ("%s: %s\n", ps->p_name, FENDNULL(*ps->p_field));
235
236 }
237
238 missed = false;
239 if (! all) {
240 if (components < 0)
241 components = compp > 1;
242
243 for (i = 0; i < compp; i++) {
244 char *value;
245
246 if (! strcmp ("spoollocking", comps[i])) {
247 /* In case spoollocking was set in mts.conf. */
248 mts_init();
249 }
250
251 value = context_find (comps[i]);
252 if (!value)
253 value = p_find (comps[i]);
254 if (value) {
255 if (components)
256 printf("%s: ", comps[i]);
257
258 puts(value);
259 } else
260 missed = true;
261 }
262 }
263
264 done(missed);
265 }
266
267
268 static char *
269 p_find(char *str)
270 {
271 struct proc *ps;
272
273 for (ps = procs; ps->p_name; ps++)
274 if (!strcasecmp (ps->p_name, str))
275 return *ps->p_field;
276
277 return NULL;
278 }