]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Update pending-release-notes.
[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 char *mimetypeproc =
65 #ifdef MIMETYPEPROC
66 MIMETYPEPROC;
67 #else
68 "";
69 #endif
70
71 char *mimeencodingproc =
72 #ifdef MIMEENCODINGPROC
73 MIMEENCODINGPROC;
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 { "sbackup", &sbackup },
112 { "lockmethod", &lockmethod },
113 { "sasl", &sasl },
114 { "tls", &tls },
115 { NULL, NULL },
116 };
117
118
119 /*
120 * static prototypes
121 */
122 static char *p_find(char *);
123
124
125 int
126 main(int argc, char **argv)
127 {
128 int i, compp = 0, missed = 0;
129 int all = 0, debug = 0;
130 int components = -1;
131 char *cp, buf[BUFSIZ], **argp;
132 char **arguments, *comps[MAXARGS];
133
134 if (nmh_init(argv[0], 1)) { return 1; }
135
136 arguments = getarguments (invo_name, argc, argv, 1);
137 argp = arguments;
138
139 while ((cp = *argp++)) {
140 if (*cp == '-') {
141 switch (smatch (++cp, switches)) {
142 case AMBIGSW:
143 ambigsw (cp, switches);
144 done (1);
145 case UNKWNSW:
146 adios (NULL, "-%s unknown", cp);
147
148 case HELPSW:
149 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
150 invo_name);
151 print_help (buf, switches, 1);
152 done (0);
153 case VERSIONSW:
154 print_version(invo_name);
155 done (0);
156
157 case COMPSW:
158 components = 1;
159 break;
160 case NCOMPSW:
161 components = 0;
162 break;
163
164 case ALLSW:
165 all = 1;
166 break;
167
168 case DEBUGSW:
169 debug = 1;
170 break;
171 }
172 } else {
173 comps[compp++] = cp;
174 }
175 }
176
177 if (all) {
178 struct node *np;
179
180 if (compp)
181 advise(NULL, "profile-components ignored with -all");
182
183 if (components >= 0)
184 advise(NULL, "-%scomponents ignored with -all",
185 components ? "" : "no");
186
187 /* print all entries in context/profile list */
188 for (np = m_defs; np; np = np->n_next)
189 printf("%s: %s\n", np->n_name, np->n_field);
190
191 } else if (debug) {
192 struct proc *ps;
193
194 /*
195 * Print the current value of everything in
196 * procs array. This will show their current
197 * value (as determined after context is read).
198 */
199 for (ps = procs; ps->p_name; ps++)
200 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
201
202 } else {
203 if (components < 0)
204 components = compp > 1;
205
206 for (i = 0; i < compp; i++) {
207 register char *value;
208
209 value = context_find (comps[i]);
210 if (!value)
211 value = p_find (comps[i]);
212 if (value) {
213 if (components)
214 printf("%s: ", comps[i]);
215
216 printf("%s\n", value);
217 } else
218 missed++;
219 }
220 }
221
222 done (missed);
223 return 1;
224 }
225
226
227 static char *
228 p_find(char *str)
229 {
230 struct proc *ps;
231
232 for (ps = procs; ps->p_name; ps++)
233 if (!strcasecmp (ps->p_name, str ? str : ""))
234 return (*ps->p_field);
235
236 return NULL;
237 }