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