]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Fix bug #42718; ali(1) still refers to removed options -normalize and
[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 */
193 for (np = m_defs; np; np = np->n_next)
194 printf("%s: %s\n", np->n_name, np->n_field);
195
196 } else if (debug) {
197 struct proc *ps;
198
199 /* Need to see if datalocking was set in profile. */
200 if ((cp = context_find("datalocking"))) { datalocking = cp; }
201
202 /* Also set localmbox here */
203 if (! localmbox_primed) {
204 localmbox = getlocalmbox();
205 localmbox_primed = 1;
206 }
207
208 /*
209 * Print the current value of everything in
210 * procs array. This will show their current
211 * value (as determined after context is read).
212 */
213 for (ps = procs; ps->p_name; ps++)
214 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
215
216 } else {
217 if (components < 0)
218 components = compp > 1;
219
220 for (i = 0; i < compp; i++) {
221 register char *value;
222
223 value = context_find (comps[i]);
224 if (!value)
225 value = p_find (comps[i]);
226 if (value) {
227 if (components)
228 printf("%s: ", comps[i]);
229
230 printf("%s\n", value);
231 } else
232 missed++;
233 }
234 }
235
236 done (missed);
237 return 1;
238 }
239
240
241 static char *
242 p_find(char *str)
243 {
244 struct proc *ps;
245
246 for (ps = procs; ps->p_name; ps++)
247 if (!strcasecmp (ps->p_name, str ? str : ""))
248 return (*ps->p_field);
249
250 return NULL;
251 }