]> diplodocus.org Git - nmh/blob - uip/mhparam.c
33f0657477adecbf6816e8c8ca23f331fe6eeb08
[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
40 extern char *spoollocking;
41
42 static char *sasl =
43 #ifdef CYRUS_SASL
44 "cyrus_sasl";
45 #else
46 "";
47 #endif
48
49 static char *tls =
50 #ifdef TLS_SUPPORT
51 "tls";
52 #else
53 "";
54 #endif
55
56 static char *mimetypeproc =
57 #ifdef MIMETYPEPROC
58 MIMETYPEPROC;
59 #else
60 "";
61 #endif
62
63 static char *mimeencodingproc =
64 #ifdef MIMEENCODINGPROC
65 MIMEENCODINGPROC;
66 #else
67 "";
68 #endif
69
70 static char *iconv =
71 #ifdef HAVE_ICONV
72 "iconv";
73 #else
74 "";
75 #endif
76
77 struct proc {
78 char *p_name;
79 char **p_field;
80 };
81
82 static struct proc procs [] = {
83 { "context", &context },
84 { "mh-sequences", &mh_seq },
85 { "buildmimeproc", &buildmimeproc },
86 { "fileproc", &fileproc },
87 { "foldprot", &foldprot },
88 { "formatproc", &formatproc },
89 { "incproc", &incproc },
90 { "lproc", &lproc },
91 { "mailproc", &mailproc },
92 { "mhlproc", &mhlproc },
93 { "mimetypeproc", &mimetypeproc },
94 { "mimeencodingproc", &mimeencodingproc },
95 { "moreproc", &moreproc },
96 { "msgprot", &msgprot },
97 { "mshproc", &mshproc },
98 { "packproc", &packproc },
99 { "postproc", &postproc },
100 { "rmmproc", &rmmproc },
101 { "sendproc", &sendproc },
102 { "showmimeproc", &showmimeproc },
103 { "showproc", &showproc },
104 { "version", &version_num },
105 { "vmhproc", &vmhproc },
106 { "whatnowproc", &whatnowproc },
107 { "whomproc", &whomproc },
108 { "etcdir", &mhetcdir },
109 { "libdir", &mhlibdir },
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 }
177 }
178
179 if (all) {
180 struct node *np;
181
182 if (compp)
183 advise(NULL, "profile-components ignored with -all");
184
185 if (components >= 0)
186 advise(NULL, "-%scomponents ignored with -all",
187 components ? "" : "no");
188
189 /* print all entries in context/profile list */
190 for (np = m_defs; np; np = np->n_next)
191 printf("%s: %s\n", np->n_name, np->n_field);
192
193 } else if (debug) {
194 struct proc *ps;
195
196 /* Need to see if datalocking was set in profile. */
197 if ((cp = context_find("datalocking"))) { datalocking = cp; }
198
199 /* Also set localmbox here */
200 localmbox = getlocalmbox();
201
202 /*
203 * Print the current value of everything in
204 * procs array. This will show their current
205 * value (as determined after context is read).
206 */
207 for (ps = procs; ps->p_name; ps++)
208 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
209
210 } else {
211 if (components < 0)
212 components = compp > 1;
213
214 for (i = 0; i < compp; i++) {
215 register char *value;
216
217 value = context_find (comps[i]);
218 if (!value)
219 value = p_find (comps[i]);
220 if (value) {
221 if (components)
222 printf("%s: ", comps[i]);
223
224 printf("%s\n", value);
225 } else
226 missed++;
227 }
228 }
229
230 done (missed);
231 return 1;
232 }
233
234
235 static char *
236 p_find(char *str)
237 {
238 struct proc *ps;
239
240 for (ps = procs; ps->p_name; ps++)
241 if (!strcasecmp (ps->p_name, str ? str : ""))
242 return (*ps->p_field);
243
244 return NULL;
245 }