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