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