]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Feed fileproc and mhlproc from rcvdist, send, and whatnow to post.
[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 { "incproc", &incproc },
50 { "installproc", &installproc },
51 { "lproc", &lproc },
52 { "mailproc", &mailproc },
53 { "mhlproc", &mhlproc },
54 { "moreproc", &moreproc },
55 { "msgprot", &msgprot },
56 { "mshproc", &mshproc },
57 { "packproc", &packproc },
58 { "postproc", &postproc },
59 { "rmfproc", &rmfproc },
60 { "rmmproc", &rmmproc },
61 { "sendproc", &sendproc },
62 { "showmimeproc", &showmimeproc },
63 { "showproc", &showproc },
64 { "version", &version_num },
65 { "vmhproc", &vmhproc },
66 { "whatnowproc", &whatnowproc },
67 { "whomproc", &whomproc },
68 { "etcdir", &mhetcdir },
69 { "libdir", &mhlibdir },
70 { "sbackup", &sbackup },
71 { "link", &slink },
72 { NULL, NULL },
73 };
74
75
76 /*
77 * static prototypes
78 */
79 static char *p_find(char *);
80
81
82 int
83 main(int argc, char **argv)
84 {
85 int i, compp = 0, missed = 0;
86 int all = 0, debug = 0;
87 int components = -1;
88 char *cp, buf[BUFSIZ], **argp;
89 char **arguments, *comps[MAXARGS];
90
91 invo_name = r1bindex (argv[0], '/');
92
93 /* read user profile/context */
94 context_read();
95
96 arguments = getarguments (invo_name, argc, argv, 1);
97 argp = arguments;
98
99 while ((cp = *argp++)) {
100 if (*cp == '-') {
101 switch (smatch (++cp, switches)) {
102 case AMBIGSW:
103 ambigsw (cp, switches);
104 done (1);
105 case UNKWNSW:
106 adios (NULL, "-%s unknown", cp);
107
108 case HELPSW:
109 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
110 invo_name);
111 print_help (buf, switches, 1);
112 done (1);
113 case VERSIONSW:
114 print_version(invo_name);
115 done (1);
116
117 case COMPSW:
118 components = 1;
119 break;
120 case NCOMPSW:
121 components = 0;
122 break;
123
124 case ALLSW:
125 all = 1;
126 break;
127
128 case DEBUGSW:
129 debug = 1;
130 break;
131 }
132 } else {
133 comps[compp++] = cp;
134 }
135 }
136
137 if (all) {
138 struct node *np;
139
140 if (compp)
141 advise(NULL, "profile-components ignored with -all");
142
143 if (components >= 0)
144 advise(NULL, "-%scomponents ignored with -all",
145 components ? "" : "no");
146
147 /* print all entries in context/profile list */
148 for (np = m_defs; np; np = np->n_next)
149 printf("%s: %s\n", np->n_name, np->n_field);
150
151 } else if (debug) {
152 struct proc *ps;
153
154 /*
155 * Print the current value of everything in
156 * procs array. This will show their current
157 * value (as determined after context is read).
158 */
159 for (ps = procs; ps->p_name; ps++)
160 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
161
162 } else {
163 if (components < 0)
164 components = compp > 1;
165
166 for (i = 0; i < compp; i++) {
167 register char *value;
168
169 value = context_find (comps[i]);
170 if (!value)
171 value = p_find (comps[i]);
172 if (value) {
173 if (components)
174 printf("%s: ", comps[i]);
175
176 printf("%s\n", value);
177 } else
178 missed++;
179 }
180 }
181
182 done (missed);
183 return 1;
184 }
185
186
187 static char *
188 p_find(char *str)
189 {
190 struct proc *ps;
191
192 for (ps = procs; ps->p_name; ps++)
193 if (!mh_strcasecmp (ps->p_name, str))
194 return (*ps->p_field);
195
196 return NULL;
197 }