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