Fix missing va_end call in uip/mhmisc.c
[mmh] / uip / mhparam.c
1 /*
2 ** mhparam.c -- print mh_profile values
3 **
4 ** Originally contributed by
5 ** Jeffrey C Honig <Jeffrey_C_Honig@cornell.edu>
6 **
7 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
8 ** COPYRIGHT file in the root directory of the nmh distribution for
9 ** complete copyright information.
10 */
11
12 #include <h/mh.h>
13 #include <sysexits.h>
14
15 static struct swit switches[] = {
16 #define COMPSW  0
17         { "components", 0 },
18 #define NCOMPSW  1
19         { "nocomponents", 2 },
20 #define ALLSW  2
21         { "all", 0 },
22 #define VERSIONSW 3
23         { "Version", 0 },
24 #define HELPSW  4
25         { "help", 0 },
26 #define DEBUGSW   5
27         { "debug", -5 },
28         { NULL, 0 }
29 };
30
31 struct proc {
32         char *p_name;
33         char **p_field;
34 };
35
36 char *empty = "";
37
38 /*
39 ** This list should contain all values of h/mh.h and config/config.c
40 ** TODO: Add the constants Nbby, MAXARGS, NUMATTRS, NAMESZ
41 */
42 static struct proc procs [] = {
43         { "#--Version--", &empty },
44         { "version",          &version_num },
45         { "version-str",      &version_str },
46
47         { "#--Path-and-File-Names--", &empty },
48         { "mypath",          &mypath },
49         { "mmhdir",          &mmhdir },
50         { "mmhpath",         &mmhpath },
51         { "profile",         &profile },
52         { "defpath",         &defpath },
53         { "context",         &context },
54         { "ctxpath",         &ctxpath },
55         { "mhetcdir",        &mhetcdir },
56         { "mailspool",       &mailspool },
57         { "mailstore",       &mailstore },
58         { "mh-sequences",    &mh_seq },
59
60         { "#--Default-Programs--", &empty },
61         { "editor",        &defaulteditor },
62         { "pager",         &defaultpager },
63         { "sendmail",      &sendmail },
64         { "listproc",      &listproc },
65         { "whatnowproc",   &whatnowproc },
66         { "mimetypequeryproc", &mimetypequeryproc },
67
68         { "#--Mail-Folder-Names--", &empty },
69         { "inbox",          &defaultfolder },
70         { "draftfolder",    &draftfolder },
71         { "trashfolder",    &trashfolder },
72
73         { "#--Profile-and-Context-Component-Names--", &empty },
74         { "curfolder-component",         &curfolder },
75         { "inbox-component",             &inbox },
76         { "mimetypequery-component",     &mimetypequery },
77         { "nmhstorage-component",        &nmhstorage },
78         { "nsequence-component",         &nsequence },
79         { "psequence-component",         &psequence },
80         { "usequence-component",         &usequence },
81
82         { "#--Mmh-specific-Mail-Header-Names--", &empty },
83         { "attachment-header", &attach_hdr },
84         { "enc-header",        &enc_hdr },
85         { "sign-header",       &sign_hdr },
86
87         { "#--File-Permissions--", &empty },
88         { "foldprot",      &foldprot },
89         { "msgprot",       &msgprot },
90
91         { "#--Template-File-Names--", &empty },
92         { "components",        &components },
93         { "digestcomps",       &digestcomps },
94         { "distcomps",         &distcomps },
95         { "forwcomps",         &forwcomps },
96         { "rcvdistcomps",      &rcvdistcomps },
97         { "replcomps",         &replcomps },
98         { "replgroupcomps",    &replgroupcomps },
99         { "mhlformat",         &mhlformat },
100         { "mhlreply",          &mhlreply },
101         { "scanformat",        &scanformat },
102
103         { "#--Default-Sequence-Names--", &empty },
104         { "seq-all",           &seq_all },
105         { "seq-beyond",        &seq_beyond },
106         { "seq-cur",           &seq_cur },
107         { "seq-first",         &seq_first },
108         { "seq-last",          &seq_last },
109         { "seq-next",          &seq_next },
110         { "previous-sequence", &seq_prev },
111         { "unseen-sequence",   &seq_unseen },
112         { "sequence-negation", &seq_neg },
113
114         { NULL,            NULL },
115 };
116
117
118 /*
119 ** static prototypes
120 */
121 static char *p_find(char *);
122
123
124 int
125 main(int argc, char **argv)
126 {
127         int i, compp = 0, missed = 0;
128         int all = 0, debug = 0;
129         int components = -1;
130         char *cp, buf[BUFSIZ], **argp;
131         char **arguments, *comps[MAXARGS];
132
133         invo_name = mhbasename(argv[0]);
134
135         context_read();
136
137         arguments = getarguments(invo_name, argc, argv, 1);
138         argp = arguments;
139
140         while ((cp = *argp++)) {
141                 if (*cp == '-') {
142                         switch (smatch(++cp, switches)) {
143                         case AMBIGSW:
144                                 ambigsw(cp, switches);
145                                 exit(EX_USAGE);
146                         case UNKWNSW:
147                                 adios(EX_USAGE, NULL, "-%s unknown", cp);
148
149                         case HELPSW:
150                                 snprintf(buf, sizeof(buf), "%s [profile-components] [switches]", invo_name);
151                                 print_help(buf, switches, 1);
152                                 exit(argc == 2 ? EX_OK : EX_USAGE);
153                         case VERSIONSW:
154                                 print_version(invo_name);
155                                 exit(argc == 2 ? EX_OK : EX_USAGE);
156
157                         case COMPSW:
158                                 components = 1;
159                                 break;
160                         case NCOMPSW:
161                                 components = 0;
162                                 break;
163
164                         case ALLSW:
165                                 all = 1;
166                                 break;
167
168                         case DEBUGSW:
169                                 debug = 1;
170                                 break;
171                         }
172                 } else {
173                         comps[compp++] = cp;
174                 }
175         }
176
177         if (all) {
178                 struct node *np;
179
180                 if (compp)
181                         advise(NULL, "profile-components ignored with -all");
182
183                 if (components >= 0)
184                         advise(NULL, "-%scomponents ignored with -all",
185                                         components ? "" : "no");
186
187                 /* print all entries in context/profile list */
188                 for (np = m_defs; np; np = np->n_next)
189                         printf("%s: %s\n", np->n_name, np->n_field);
190
191         } else if (debug) {
192                 struct proc *ps;
193
194                 /*
195                 ** Print the current value of everything in
196                 ** procs array.  This will show their current
197                 ** value (as determined after context is read).
198                 */
199                 for (ps = procs; ps->p_name; ps++)
200                         printf("%s: %s\n", ps->p_name,
201                                         *ps->p_field ? *ps->p_field : "");
202
203         } else {
204                 if (components < 0)
205                         components = compp > 1;
206
207                 for (i = 0; i < compp; i++)  {
208                         char *value;
209
210                         value = context_find(comps[i]);
211                         if (!value)
212                                 value = p_find(comps[i]);
213                         if (value) {
214                                 if (components)
215                                         printf("%s: ", comps[i]);
216
217                                 printf("%s\n", value);
218                         } else
219                                 missed++;
220                 }
221         }
222
223         return missed;
224 }
225
226
227 static char *
228 p_find(char *str)
229 {
230         struct proc *ps;
231
232         for (ps = procs; ps->p_name; ps++)
233                 if (!mh_strcasecmp(ps->p_name, str))
234                         return (*ps->p_field);
235
236         return NULL;
237 }