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