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