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