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