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