]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Added cast of MB_CUR_MAX to size_t to silence compiler warning on
[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 *mhlibdir;
33 extern char *mhetcdir;
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 struct proc {
79 char *p_name;
80 char **p_field;
81 };
82
83 static struct proc procs [] = {
84 { "context", &context },
85 { "mh-sequences", &mh_seq },
86 { "buildmimeproc", &buildmimeproc },
87 { "fileproc", &fileproc },
88 { "foldprot", &foldprot },
89 { "formatproc", &formatproc },
90 { "incproc", &incproc },
91 { "lproc", &lproc },
92 { "mailproc", &mailproc },
93 { "mhlproc", &mhlproc },
94 { "mimetypeproc", &mimetypeproc },
95 { "mimeencodingproc", &mimeencodingproc },
96 { "moreproc", &moreproc },
97 { "msgprot", &msgprot },
98 { "packproc", &packproc },
99 { "postproc", &postproc },
100 { "rmmproc", &rmmproc },
101 { "sendproc", &sendproc },
102 { "showmimeproc", &showmimeproc },
103 { "showproc", &showproc },
104 { "version", &version_num },
105 { "whatnowproc", &whatnowproc },
106 { "whomproc", &whomproc },
107 { "etcdir", &mhetcdir },
108 { "libdir", &mhlibdir },
109 { "localmbox", &localmbox },
110 { "sbackup", &sbackup },
111 { "datalocking", &datalocking },
112 { "spoollocking", &spoollocking },
113 { "iconv", &iconv },
114 { "sasl", &sasl },
115 { "tls", &tls },
116 { NULL, NULL },
117 };
118
119
120 /*
121 * static prototypes
122 */
123 static char *p_find(char *);
124
125
126 int
127 main(int argc, char **argv)
128 {
129 int i, compp = 0, missed = 0;
130 int all = 0, debug = 0;
131 int components = -1;
132 char *cp, buf[BUFSIZ], **argp;
133 char **arguments, *comps[MAXARGS];
134
135 if (nmh_init(argv[0], 1)) { return 1; }
136
137 arguments = getarguments (invo_name, argc, argv, 1);
138 argp = arguments;
139
140 while ((cp = *argp++)) {
141 if (*cp == '-') {
142 switch (smatch (++cp, switches)) {
143 case AMBIGSW:
144 ambigsw (cp, switches);
145 done (1);
146 case UNKWNSW:
147 adios (NULL, "-%s unknown", cp);
148
149 case HELPSW:
150 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
151 invo_name);
152 print_help (buf, switches, 1);
153 done (0);
154 case VERSIONSW:
155 print_version(invo_name);
156 done (0);
157
158 case COMPSW:
159 components = 1;
160 break;
161 case NCOMPSW:
162 components = 0;
163 break;
164
165 case ALLSW:
166 all = 1;
167 break;
168
169 case DEBUGSW:
170 debug = 1;
171 break;
172 }
173 } else {
174 comps[compp++] = cp;
175 if (strcmp("localmbox", cp) == 0 && ! localmbox_primed) {
176 localmbox = getlocalmbox();
177 localmbox_primed = 1;
178 }
179 }
180 }
181
182 if (all) {
183 struct node *np;
184
185 if (compp)
186 advise(NULL, "profile-components ignored with -all");
187
188 if (components >= 0)
189 advise(NULL, "-%scomponents ignored with -all",
190 components ? "" : "no");
191
192 /* Print all entries in context/profile list. That does not
193 include entries in mts.conf, such as spoollocking. */
194 for (np = m_defs; np; np = np->n_next)
195 printf("%s: %s\n", np->n_name, np->n_field);
196
197 } else if (debug) {
198 struct proc *ps;
199
200 /* In case datalocking was set in profile. */
201 if ((cp = context_find("datalocking"))) { datalocking = cp; }
202
203 /* In case spoollocking was set in mts.conf. */
204 mts_init(invo_name);
205
206 /* Also set localmbox here */
207 if (! localmbox_primed) {
208 localmbox = getlocalmbox();
209 localmbox_primed = 1;
210 }
211
212 /*
213 * Print the current value of everything in
214 * procs array. This will show their current
215 * value (as determined after context is read).
216 */
217 for (ps = procs; ps->p_name; ps++)
218 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
219
220 } else {
221 if (components < 0)
222 components = compp > 1;
223
224 for (i = 0; i < compp; i++) {
225 register char *value;
226
227 if (! strcmp ("spoollocking", comps[i])) {
228 /* In case spoollocking was set in mts.conf. */
229 mts_init(invo_name);
230 }
231
232 value = context_find (comps[i]);
233 if (!value)
234 value = p_find (comps[i]);
235 if (value) {
236 if (components)
237 printf("%s: ", comps[i]);
238
239 printf("%s\n", value);
240 } else
241 missed++;
242 }
243 }
244
245 done (missed);
246 return 1;
247 }
248
249
250 static char *
251 p_find(char *str)
252 {
253 struct proc *ps;
254
255 for (ps = procs; ps->p_name; ps++)
256 if (!strcasecmp (ps->p_name, str ? str : ""))
257 return (*ps->p_field);
258
259 return NULL;
260 }