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