]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Changed unused symbol that gen-ctype-checked creates with NDEBUG
[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
15 #define MHPARAM_SWITCHES \
16 X("components", 0, COMPSW) \
17 X("nocomponents", 0, NCOMPSW) \
18 X("all", 0, ALLSW) \
19 X("version", 0, VERSIONSW) \
20 X("help", 0, HELPSW) \
21 X("debug", 5, DEBUGSW) \
22
23 #define X(sw, minchars, id) id,
24 DEFINE_SWITCH_ENUM(MHPARAM);
25 #undef X
26
27 #define X(sw, minchars, id) { sw, minchars, id },
28 DEFINE_SWITCH_ARRAY(MHPARAM, switches);
29 #undef X
30
31 extern char *mhlibdir;
32 extern char *mhetcdir;
33
34 char *sbackup = BACKUP_PREFIX;
35
36 char *datalocking = "fcntl";
37
38 extern char *spoollocking;
39
40 char *sasl =
41 #ifdef CYRUS_SASL
42 "cyrus_sasl";
43 #else
44 "";
45 #endif
46
47 char *tls =
48 #ifdef TLS_SUPPORT
49 "tls";
50 #else
51 "";
52 #endif
53
54 char *mimetypeproc =
55 #ifdef MIMETYPEPROC
56 MIMETYPEPROC;
57 #else
58 "";
59 #endif
60
61 char *mimeencodingproc =
62 #ifdef MIMEENCODINGPROC
63 MIMEENCODINGPROC;
64 #else
65 "";
66 #endif
67
68 struct proc {
69 char *p_name;
70 char **p_field;
71 };
72
73 static struct proc procs [] = {
74 { "context", &context },
75 { "mh-sequences", &mh_seq },
76 { "buildmimeproc", &buildmimeproc },
77 { "fileproc", &fileproc },
78 { "foldprot", &foldprot },
79 { "formatproc", &formatproc },
80 { "incproc", &incproc },
81 { "lproc", &lproc },
82 { "mailproc", &mailproc },
83 { "mhlproc", &mhlproc },
84 { "mimetypeproc", &mimetypeproc },
85 { "mimeencodingproc", &mimeencodingproc },
86 { "moreproc", &moreproc },
87 { "msgprot", &msgprot },
88 { "mshproc", &mshproc },
89 { "packproc", &packproc },
90 { "postproc", &postproc },
91 { "rmmproc", &rmmproc },
92 { "sendproc", &sendproc },
93 { "showmimeproc", &showmimeproc },
94 { "showproc", &showproc },
95 { "version", &version_num },
96 { "vmhproc", &vmhproc },
97 { "whatnowproc", &whatnowproc },
98 { "whomproc", &whomproc },
99 { "etcdir", &mhetcdir },
100 { "libdir", &mhlibdir },
101 { "sbackup", &sbackup },
102 { "datalocking", &datalocking },
103 { "spoollocking", &spoollocking },
104 { "sasl", &sasl },
105 { "tls", &tls },
106 { NULL, NULL },
107 };
108
109
110 /*
111 * static prototypes
112 */
113 static char *p_find(char *);
114
115
116 int
117 main(int argc, char **argv)
118 {
119 int i, compp = 0, missed = 0;
120 int all = 0, debug = 0;
121 int components = -1;
122 char *cp, buf[BUFSIZ], **argp;
123 char **arguments, *comps[MAXARGS];
124
125 if (nmh_init(argv[0], 1)) { return 1; }
126
127 arguments = getarguments (invo_name, argc, argv, 1);
128 argp = arguments;
129
130 while ((cp = *argp++)) {
131 if (*cp == '-') {
132 switch (smatch (++cp, switches)) {
133 case AMBIGSW:
134 ambigsw (cp, switches);
135 done (1);
136 case UNKWNSW:
137 adios (NULL, "-%s unknown", cp);
138
139 case HELPSW:
140 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
141 invo_name);
142 print_help (buf, switches, 1);
143 done (0);
144 case VERSIONSW:
145 print_version(invo_name);
146 done (0);
147
148 case COMPSW:
149 components = 1;
150 break;
151 case NCOMPSW:
152 components = 0;
153 break;
154
155 case ALLSW:
156 all = 1;
157 break;
158
159 case DEBUGSW:
160 debug = 1;
161 break;
162 }
163 } else {
164 comps[compp++] = cp;
165 }
166 }
167
168 if (all) {
169 struct node *np;
170
171 if (compp)
172 advise(NULL, "profile-components ignored with -all");
173
174 if (components >= 0)
175 advise(NULL, "-%scomponents ignored with -all",
176 components ? "" : "no");
177
178 /* print all entries in context/profile list */
179 for (np = m_defs; np; np = np->n_next)
180 printf("%s: %s\n", np->n_name, np->n_field);
181
182 } else if (debug) {
183 struct proc *ps;
184
185 /* Need to see if datalocking was set in profile. */
186 if ((cp = context_find("datalocking"))) { datalocking = cp; }
187
188 /*
189 * Print the current value of everything in
190 * procs array. This will show their current
191 * value (as determined after context is read).
192 */
193 for (ps = procs; ps->p_name; ps++)
194 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
195
196 } else {
197 if (components < 0)
198 components = compp > 1;
199
200 for (i = 0; i < compp; i++) {
201 register char *value;
202
203 value = context_find (comps[i]);
204 if (!value)
205 value = p_find (comps[i]);
206 if (value) {
207 if (components)
208 printf("%s: ", comps[i]);
209
210 printf("%s\n", value);
211 } else
212 missed++;
213 }
214 }
215
216 done (missed);
217 return 1;
218 }
219
220
221 static char *
222 p_find(char *str)
223 {
224 struct proc *ps;
225
226 for (ps = procs; ps->p_name; ps++)
227 if (!strcasecmp (ps->p_name, str ? str : ""))
228 return (*ps->p_field);
229
230 return NULL;
231 }