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