Drop register storage class
[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
102         { "#--Default-Sequence-Names--", &empty },
103         { "seq-all",           &seq_all },
104         { "seq-beyond",        &seq_beyond },
105         { "seq-cur",           &seq_cur },
106         { "seq-first",         &seq_first },
107         { "seq-last",          &seq_last },
108         { "seq-next",          &seq_next },
109         { "previous-sequence", &seq_prev },
110         { "unseen-sequence",   &seq_unseen },
111         { "sequence-negation", &seq_neg },
112
113         { NULL,            NULL },
114 };
115
116
117 /*
118 ** static prototypes
119 */
120 static char *p_find(char *);
121
122
123 int
124 main(int argc, char **argv)
125 {
126         int i, compp = 0, missed = 0;
127         int all = 0, debug = 0;
128         int components = -1;
129         char *cp, buf[BUFSIZ], **argp;
130         char **arguments, *comps[MAXARGS];
131
132         invo_name = mhbasename(argv[0]);
133
134         context_read();
135
136         arguments = getarguments(invo_name, argc, argv, 1);
137         argp = arguments;
138
139         while ((cp = *argp++)) {
140                 if (*cp == '-') {
141                         switch (smatch(++cp, switches)) {
142                         case AMBIGSW:
143                                 ambigsw(cp, switches);
144                                 exit(EX_USAGE);
145                         case UNKWNSW:
146                                 adios(EX_USAGE, NULL, "-%s unknown", cp);
147
148                         case HELPSW:
149                                 snprintf(buf, sizeof(buf), "%s [profile-components] [switches]", invo_name);
150                                 print_help(buf, switches, 1);
151                                 exit(argc == 2 ? EX_OK : EX_USAGE);
152                         case VERSIONSW:
153                                 print_version(invo_name);
154                                 exit(argc == 2 ? EX_OK : EX_USAGE);
155
156                         case COMPSW:
157                                 components = 1;
158                                 break;
159                         case NCOMPSW:
160                                 components = 0;
161                                 break;
162
163                         case ALLSW:
164                                 all = 1;
165                                 break;
166
167                         case DEBUGSW:
168                                 debug = 1;
169                                 break;
170                         }
171                 } else {
172                         comps[compp++] = cp;
173                 }
174         }
175
176         if (all) {
177                 struct node *np;
178
179                 if (compp)
180                         advise(NULL, "profile-components ignored with -all");
181
182                 if (components >= 0)
183                         advise(NULL, "-%scomponents ignored with -all",
184                                         components ? "" : "no");
185
186                 /* print all entries in context/profile list */
187                 for (np = m_defs; np; np = np->n_next)
188                         printf("%s: %s\n", np->n_name, np->n_field);
189
190         } else if (debug) {
191                 struct proc *ps;
192
193                 /*
194                 ** Print the current value of everything in
195                 ** procs array.  This will show their current
196                 ** value (as determined after context is read).
197                 */
198                 for (ps = procs; ps->p_name; ps++)
199                         printf("%s: %s\n", ps->p_name,
200                                         *ps->p_field ? *ps->p_field : "");
201
202         } else {
203                 if (components < 0)
204                         components = compp > 1;
205
206                 for (i = 0; i < compp; i++)  {
207                         char *value;
208
209                         value = context_find(comps[i]);
210                         if (!value)
211                                 value = p_find(comps[i]);
212                         if (value) {
213                                 if (components)
214                                         printf("%s: ", comps[i]);
215
216                                 printf("%s\n", value);
217                         } else
218                                 missed++;
219                 }
220         }
221
222         return missed;
223 }
224
225
226 static char *
227 p_find(char *str)
228 {
229         struct proc *ps;
230
231         for (ps = procs; ps->p_name; ps++)
232                 if (!mh_strcasecmp(ps->p_name, str))
233                         return (*ps->p_field);
234
235         return NULL;
236 }