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