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