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