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