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