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