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