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