Removed the `mhbuild' indirection via `buildmimeproc'.
[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", 0 },
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 static struct proc procs [] = {
36         { "attachment-header",  &attach_hdr },
37         { "context",       &context },
38         { "mh-sequences",  &mh_seq },
39         { "editor",        &defaulteditor },
40         { "fileproc",      &fileproc },
41         { "foldprot",      &foldprot },
42         { "incproc",       &incproc },
43         { "lproc",         &lproc },
44         { "mailproc",      &mailproc },
45         { "mhlproc",       &mhlproc },
46         { "mimetypequeryproc", &mimetypequeryproc },
47         { "msgprot",       &msgprot },
48         { "pager",         &defaultpager },
49         { "postproc",      &postproc },
50         { "rmmproc",       &rmmproc },
51         { "sendmail",      &sendmail },
52         { "sendproc",      &sendproc },
53         { "showmimeproc",  &showmimeproc },
54         { "showproc",      &showproc },
55         { "version",       &version_num },
56         { "whatnowproc",   &whatnowproc },
57         { "etcdir",        &mhetcdir },
58         { "backup-prefix", &backup_prefix },
59         { "altmsg-link",   &altmsglink },
60         { "draft-folder",  &draftfolder },
61         { NULL,            NULL },
62 };
63
64
65 /*
66 ** static prototypes
67 */
68 static char *p_find(char *);
69
70
71 int
72 main(int argc, char **argv)
73 {
74         int i, compp = 0, missed = 0;
75         int all = 0, debug = 0;
76         int components = -1;
77         char *cp, buf[BUFSIZ], **argp;
78         char **arguments, *comps[MAXARGS];
79
80         invo_name = mhbasename(argv[0]);
81
82         /* read user profile/context */
83         context_read();
84
85         arguments = getarguments(invo_name, argc, argv, 1);
86         argp = arguments;
87
88         while ((cp = *argp++)) {
89                 if (*cp == '-') {
90                         switch (smatch(++cp, switches)) {
91                         case AMBIGSW:
92                                 ambigsw(cp, switches);
93                                 done(1);
94                         case UNKWNSW:
95                                 adios(NULL, "-%s unknown", cp);
96
97                         case HELPSW:
98                                 snprintf(buf, sizeof(buf), "%s [profile-components] [switches]", invo_name);
99                                 print_help(buf, switches, 1);
100                                 done(1);
101                         case VERSIONSW:
102                                 print_version(invo_name);
103                                 done(1);
104
105                         case COMPSW:
106                                 components = 1;
107                                 break;
108                         case NCOMPSW:
109                                 components = 0;
110                                 break;
111
112                         case ALLSW:
113                                 all = 1;
114                                 break;
115
116                         case DEBUGSW:
117                                 debug = 1;
118                                 break;
119                         }
120                 } else {
121                         comps[compp++] = cp;
122                 }
123         }
124
125         if (all) {
126                 struct node *np;
127
128                 if (compp)
129                         advise(NULL, "profile-components ignored with -all");
130
131                 if (components >= 0)
132                         advise(NULL, "-%scomponents ignored with -all",
133                                         components ? "" : "no");
134
135                 /* print all entries in context/profile list */
136                 for (np = m_defs; np; np = np->n_next)
137                         printf("%s: %s\n", np->n_name, np->n_field);
138
139         } else if (debug) {
140                 struct proc *ps;
141
142                 /*
143                 ** Print the current value of everything in
144                 ** procs array.  This will show their current
145                 ** value (as determined after context is read).
146                 */
147                 for (ps = procs; ps->p_name; ps++)
148                         printf("%s: %s\n", ps->p_name,
149                                         *ps->p_field ? *ps->p_field : "");
150
151         } else {
152                 if (components < 0)
153                         components = compp > 1;
154
155                 for (i = 0; i < compp; i++)  {
156                         register char *value;
157
158                         value = context_find(comps[i]);
159                         if (!value)
160                                 value = p_find(comps[i]);
161                         if (value) {
162                                 if (components)
163                                         printf("%s: ", comps[i]);
164
165                                 printf("%s\n", value);
166                         } else
167                                 missed++;
168                 }
169         }
170
171         done(missed);
172         return 1;
173 }
174
175
176 static char *
177 p_find(char *str)
178 {
179         struct proc *ps;
180
181         for (ps = procs; ps->p_name; ps++)
182                 if (!mh_strcasecmp(ps->p_name, str))
183                         return (*ps->p_field);
184
185         return NULL;
186 }