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