Replace done with exit at uip
[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
14 static struct swit switches[] = {
15 #define COMPSW  0
16         { "components", 0 },
17 #define NCOMPSW  1
18         { "nocomponents", 2 },
19 #define ALLSW  2
20         { "all", 0 },
21 #define VERSIONSW 3
22         { "Version", 0 },
23 #define HELPSW  4
24         { "help", 0 },
25 #define DEBUGSW   5
26         { "debug", -5 },
27         { NULL, 0 }
28 };
29
30 struct proc {
31         char *p_name;
32         char **p_field;
33 };
34
35 char *empty = "";
36
37 /*
38 ** This list should contain all values of h/mh.h and config/config.c
39 ** TODO: Add the constants Nbby, MAXARGS, NUMATTRS, NAMESZ
40 */
41 static struct proc procs [] = {
42         { "#--Version--", &empty },
43         { "version",          &version_num },
44         { "version-str",      &version_str },
45
46         { "#--Path-and-File-Names--", &empty },
47         { "mypath",          &mypath },
48         { "mmhdir",          &mmhdir },
49         { "mmhpath",         &mmhpath },
50         { "profile",         &profile },
51         { "defpath",         &defpath },
52         { "context",         &context },
53         { "ctxpath",         &ctxpath },
54         { "mhetcdir",        &mhetcdir },
55         { "mailspool",       &mailspool },
56         { "mailstore",       &mailstore },
57         { "mh-sequences",    &mh_seq },
58
59         { "#--Default-Programs--", &empty },
60         { "editor",        &defaulteditor },
61         { "pager",         &defaultpager },
62         { "sendmail",      &sendmail },
63         { "listproc",      &listproc },
64         { "whatnowproc",   &whatnowproc },
65         { "mimetypequeryproc", &mimetypequeryproc },
66
67         { "#--Mail-Folder-Names--", &empty },
68         { "inbox",          &defaultfolder },
69         { "draftfolder",    &draftfolder },
70         { "trashfolder",    &trashfolder },
71
72         { "#--Profile-and-Context-Component-Names--", &empty },
73         { "curfolder-component",         &curfolder },
74         { "inbox-component",             &inbox },
75         { "mimetypequery-component",     &mimetypequery },
76         { "nmhstorage-component",        &nmhstorage },
77         { "nsequence-component",         &nsequence },
78         { "psequence-component",         &psequence },
79         { "usequence-component",         &usequence },
80
81         { "#--Mmh-specific-Mail-Header-Names--", &empty },
82         { "attachment-header", &attach_hdr },
83         { "enc-header",        &enc_hdr },
84         { "sign-header",       &sign_hdr },
85
86         { "#--File-Permissions--", &empty },
87         { "foldprot",      &foldprot },
88         { "msgprot",       &msgprot },
89
90         { "#--Template-File-Names--", &empty },
91         { "components",        &components },
92         { "digestcomps",       &digestcomps },
93         { "distcomps",         &distcomps },
94         { "forwcomps",         &forwcomps },
95         { "rcvdistcomps",      &rcvdistcomps },
96         { "replcomps",         &replcomps },
97         { "replgroupcomps",    &replgroupcomps },
98         { "mhlformat",         &mhlformat },
99         { "mhlreply",          &mhlreply },
100
101         { "#--Default-Sequence-Names--", &empty },
102         { "seq-all",           &seq_all },
103         { "seq-beyond",        &seq_beyond },
104         { "seq-cur",           &seq_cur },
105         { "seq-first",         &seq_first },
106         { "seq-last",          &seq_last },
107         { "seq-next",          &seq_next },
108         { "previous-sequence", &seq_prev },
109         { "unseen-sequence",   &seq_unseen },
110         { "sequence-negation", &seq_neg },
111
112         { NULL,            NULL },
113 };
114
115
116 /*
117 ** static prototypes
118 */
119 static char *p_find(char *);
120
121
122 int
123 main(int argc, char **argv)
124 {
125         int i, compp = 0, missed = 0;
126         int all = 0, debug = 0;
127         int components = -1;
128         char *cp, buf[BUFSIZ], **argp;
129         char **arguments, *comps[MAXARGS];
130
131         invo_name = mhbasename(argv[0]);
132
133         context_read();
134
135         arguments = getarguments(invo_name, argc, argv, 1);
136         argp = arguments;
137
138         while ((cp = *argp++)) {
139                 if (*cp == '-') {
140                         switch (smatch(++cp, switches)) {
141                         case AMBIGSW:
142                                 ambigsw(cp, switches);
143                                 /*sysexits.h EX_USAGE*/
144                                 exit(1);
145                         case UNKWNSW:
146                                 adios(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(0);
152                         case VERSIONSW:
153                                 print_version(invo_name);
154                                 exit(0);
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                         register 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 }