]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Fix stupid accidental dependence on a bash quirk in previous
[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 * $Id$
9 *
10 * This code is Copyright (c) 2002, by the authors of nmh. See the
11 * COPYRIGHT file in the root directory of the nmh distribution for
12 * complete copyright information.
13 */
14
15 #include <h/mh.h>
16
17 extern char *mhlibdir;
18 extern char *mhetcdir;
19
20 char *sbackup = BACKUP_PREFIX;
21 char *slink = LINK;
22
23 static struct swit switches[] = {
24 #define COMPSW 0
25 { "components", 0 },
26 #define NCOMPSW 1
27 { "nocomponents", 0 },
28 #define ALLSW 2
29 { "all", 0 },
30 #define VERSIONSW 3
31 { "version", 0 },
32 #define HELPSW 4
33 { "help", 0 },
34 #define DEBUGSW 5
35 { "debug", -5 },
36 { NULL, 0 }
37 };
38
39 struct proc {
40 char *p_name;
41 char **p_field;
42 };
43
44 static struct proc procs [] = {
45 { "context", &context },
46 { "mh-sequences", &mh_seq },
47 { "buildmimeproc", &buildmimeproc },
48 { "faceproc", &faceproc },
49 { "fileproc", &fileproc },
50 { "foldprot", &foldprot },
51 { "incproc", &incproc },
52 { "installproc", &installproc },
53 { "lproc", &lproc },
54 { "mailproc", &mailproc },
55 { "mhlproc", &mhlproc },
56 { "moreproc", &moreproc },
57 { "msgprot", &msgprot },
58 { "mshproc", &mshproc },
59 { "packproc", &packproc },
60 { "postproc", &postproc },
61 { "rmfproc", &rmfproc },
62 { "rmmproc", &rmmproc },
63 { "sendproc", &sendproc },
64 { "showmimeproc", &showmimeproc },
65 { "showproc", &showproc },
66 { "version", &version_num },
67 { "vmhproc", &vmhproc },
68 { "whatnowproc", &whatnowproc },
69 { "whomproc", &whomproc },
70 { "etcdir", &mhetcdir },
71 { "libdir", &mhlibdir },
72 { "sbackup", &sbackup },
73 { "link", &slink },
74 { NULL, NULL },
75 };
76
77
78 /*
79 * static prototypes
80 */
81 static char *p_find(char *);
82
83
84 int
85 main(int argc, char **argv)
86 {
87 int i, compp = 0, missed = 0;
88 int all = 0, debug = 0;
89 int components = -1;
90 char *cp, buf[BUFSIZ], **argp;
91 char **arguments, *comps[MAXARGS];
92
93 invo_name = r1bindex (argv[0], '/');
94
95 /* read user profile/context */
96 context_read();
97
98 arguments = getarguments (invo_name, argc, argv, 1);
99 argp = arguments;
100
101 while ((cp = *argp++)) {
102 if (*cp == '-') {
103 switch (smatch (++cp, switches)) {
104 case AMBIGSW:
105 ambigsw (cp, switches);
106 done (1);
107 case UNKWNSW:
108 adios (NULL, "-%s unknown", cp);
109
110 case HELPSW:
111 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
112 invo_name);
113 print_help (buf, switches, 1);
114 done (1);
115 case VERSIONSW:
116 print_version(invo_name);
117 done (1);
118
119 case COMPSW:
120 components = 1;
121 break;
122 case NCOMPSW:
123 components = 0;
124 break;
125
126 case ALLSW:
127 all = 1;
128 break;
129
130 case DEBUGSW:
131 debug = 1;
132 break;
133 }
134 } else {
135 comps[compp++] = cp;
136 }
137 }
138
139 if (all) {
140 struct node *np;
141
142 if (compp)
143 advise(NULL, "profile-components ignored with -all");
144
145 if (components >= 0)
146 advise(NULL, "-%scomponents ignored with -all",
147 components ? "" : "no");
148
149 /* print all entries in context/profile list */
150 for (np = m_defs; np; np = np->n_next)
151 printf("%s: %s\n", np->n_name, np->n_field);
152
153 } if (debug) {
154 struct proc *ps;
155
156 /*
157 * Print the current value of everything in
158 * procs array. This will show their current
159 * value (as determined after context is read).
160 */
161 for (ps = procs; ps->p_name; ps++)
162 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
163
164 } else {
165 if (components < 0)
166 components = compp > 1;
167
168 for (i = 0; i < compp; i++) {
169 register char *value;
170
171 value = context_find (comps[i]);
172 if (!value)
173 value = p_find (comps[i]);
174 if (value) {
175 if (components)
176 printf("%s: ", comps[i]);
177
178 printf("%s\n", value);
179 } else
180 missed++;
181 }
182 }
183
184 return done (missed);
185 }
186
187
188 static char *
189 p_find(char *str)
190 {
191 struct proc *ps;
192
193 for (ps = procs; ps->p_name; ps++)
194 if (!strcasecmp (ps->p_name, str))
195 return (*ps->p_field);
196
197 return NULL;
198 }