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