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