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