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