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