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