]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Compare character with EOF using signed comparison because
[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 { "mshproc", &mshproc },
99 { "packproc", &packproc },
100 { "postproc", &postproc },
101 { "rmmproc", &rmmproc },
102 { "sendproc", &sendproc },
103 { "showmimeproc", &showmimeproc },
104 { "showproc", &showproc },
105 { "version", &version_num },
106 { "vmhproc", &vmhproc },
107 { "whatnowproc", &whatnowproc },
108 { "whomproc", &whomproc },
109 { "etcdir", &mhetcdir },
110 { "libdir", &mhlibdir },
111 { "localmbox", &localmbox },
112 { "sbackup", &sbackup },
113 { "datalocking", &datalocking },
114 { "spoollocking", &spoollocking },
115 { "iconv", &iconv },
116 { "sasl", &sasl },
117 { "tls", &tls },
118 { NULL, NULL },
119 };
120
121
122 /*
123 * static prototypes
124 */
125 static char *p_find(char *);
126
127
128 int
129 main(int argc, char **argv)
130 {
131 int i, compp = 0, missed = 0;
132 int all = 0, debug = 0;
133 int components = -1;
134 char *cp, buf[BUFSIZ], **argp;
135 char **arguments, *comps[MAXARGS];
136
137 if (nmh_init(argv[0], 1)) { return 1; }
138
139 arguments = getarguments (invo_name, argc, argv, 1);
140 argp = arguments;
141
142 while ((cp = *argp++)) {
143 if (*cp == '-') {
144 switch (smatch (++cp, switches)) {
145 case AMBIGSW:
146 ambigsw (cp, switches);
147 done (1);
148 case UNKWNSW:
149 adios (NULL, "-%s unknown", cp);
150
151 case HELPSW:
152 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
153 invo_name);
154 print_help (buf, switches, 1);
155 done (0);
156 case VERSIONSW:
157 print_version(invo_name);
158 done (0);
159
160 case COMPSW:
161 components = 1;
162 break;
163 case NCOMPSW:
164 components = 0;
165 break;
166
167 case ALLSW:
168 all = 1;
169 break;
170
171 case DEBUGSW:
172 debug = 1;
173 break;
174 }
175 } else {
176 comps[compp++] = cp;
177 if (strcmp("localmbox", cp) == 0 && ! localmbox_primed) {
178 localmbox = getlocalmbox();
179 localmbox_primed = 1;
180 }
181 }
182 }
183
184 if (all) {
185 struct node *np;
186
187 if (compp)
188 advise(NULL, "profile-components ignored with -all");
189
190 if (components >= 0)
191 advise(NULL, "-%scomponents ignored with -all",
192 components ? "" : "no");
193
194 /* print all entries in context/profile list */
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 /* Need to see if datalocking was set in profile. */
202 if ((cp = context_find("datalocking"))) { datalocking = cp; }
203
204 /* Also set localmbox here */
205 if (! localmbox_primed) {
206 localmbox = getlocalmbox();
207 localmbox_primed = 1;
208 }
209
210 /*
211 * Print the current value of everything in
212 * procs array. This will show their current
213 * value (as determined after context is read).
214 */
215 for (ps = procs; ps->p_name; ps++)
216 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
217
218 } else {
219 if (components < 0)
220 components = compp > 1;
221
222 for (i = 0; i < compp; i++) {
223 register char *value;
224
225 value = context_find (comps[i]);
226 if (!value)
227 value = p_find (comps[i]);
228 if (value) {
229 if (components)
230 printf("%s: ", comps[i]);
231
232 printf("%s\n", value);
233 } else
234 missed++;
235 }
236 }
237
238 done (missed);
239 return 1;
240 }
241
242
243 static char *
244 p_find(char *str)
245 {
246 struct proc *ps;
247
248 for (ps = procs; ps->p_name; ps++)
249 if (!strcasecmp (ps->p_name, str ? str : ""))
250 return (*ps->p_field);
251
252 return NULL;
253 }