Removed msh, vmh and wmh.
[mmh] / uip / mhparam.c
1
2 /*
3  * mhparam.c -- print mh_profile values
4  *
5  * Originally contributed by
6  * Jeffrey C Honig <Jeffrey_C_Honig@cornell.edu>
7  *
8  * This code is Copyright (c) 2002, by the authors of nmh.  See the
9  * COPYRIGHT file in the root directory of the nmh distribution for
10  * complete copyright information.
11  */
12
13 #include <h/mh.h>
14
15 extern char *mhlibdir;
16 extern char *mhetcdir;
17
18 static struct swit switches[] = {
19 #define COMPSW    0
20     { "components", 0 },
21 #define NCOMPSW   1
22     { "nocomponents", 0 },
23 #define ALLSW     2
24     { "all", 0 },
25 #define VERSIONSW 3
26     { "version", 0 },
27 #define HELPSW    4
28     { "help", 0 },
29 #define DEBUGSW   5
30     { "debug", -5 },
31     { NULL, 0 }
32 };
33
34 struct proc {
35     char *p_name;
36     char **p_field;
37 };
38
39 static struct proc procs [] = {
40      { "context",       &context },
41      { "mh-sequences",  &mh_seq },
42      { "buildmimeproc", &buildmimeproc },
43      { "editor",        &defaulteditor },
44      { "faceproc",      &faceproc },
45      { "fileproc",      &fileproc },
46      { "foldprot",      &foldprot },
47      { "incproc",       &incproc },
48      { "installproc",   &installproc  },
49      { "lproc",         &lproc },
50      { "mailproc",      &mailproc },
51      { "mhlproc",       &mhlproc },
52      { "moreproc",      &moreproc },
53      { "msgprot",       &msgprot },
54      { "packproc",      &packproc },
55      { "postproc",      &postproc },
56      { "rmfproc",       &rmfproc },
57      { "rmmproc",       &rmmproc },
58      { "sendmail",      &sendmail },
59      { "sendproc",      &sendproc },
60      { "showmimeproc",  &showmimeproc },
61      { "showproc",      &showproc },
62      { "version",       &version_num },
63      { "whatnowproc",   &whatnowproc },
64      { "whomproc",      &whomproc },
65      { "etcdir",        &mhetcdir },
66      { "libdir",        &mhlibdir },
67      { "backup-prefix", &backup_prefix },
68      { "altmsg-link",   &altmsglink },
69      { NULL,            NULL },
70 };
71
72
73 /*
74  * static prototypes
75  */
76 static char *p_find(char *);
77
78
79 int
80 main(int argc, char **argv)
81 {
82     int i, compp = 0, missed = 0;
83     int all = 0, debug = 0;
84     int components = -1;
85     char *cp, buf[BUFSIZ], **argp;
86     char **arguments, *comps[MAXARGS];
87
88     invo_name = r1bindex (argv[0], '/');
89
90     /* read user profile/context */
91     context_read();
92
93     arguments = getarguments (invo_name, argc, argv, 1);
94     argp = arguments;
95
96     while ((cp = *argp++)) {
97         if (*cp == '-') {
98             switch (smatch (++cp, switches)) {
99                 case AMBIGSW: 
100                     ambigsw (cp, switches);
101                     done (1);
102                 case UNKWNSW: 
103                     adios (NULL, "-%s unknown", cp);
104
105                 case HELPSW: 
106                     snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
107                         invo_name);
108                     print_help (buf, switches, 1);
109                     done (1);
110                 case VERSIONSW:
111                     print_version(invo_name);
112                     done (1);
113
114                 case COMPSW:
115                     components = 1;
116                     break;
117                 case NCOMPSW:
118                     components = 0;
119                     break;
120
121                 case ALLSW:
122                     all = 1;
123                     break;
124
125                 case DEBUGSW:
126                     debug = 1;
127                     break;
128             }
129         } else {
130             comps[compp++] = cp;
131         }
132     }
133
134     if (all) {
135         struct node *np;
136
137         if (compp)
138             advise(NULL, "profile-components ignored with -all");
139
140         if (components >= 0)
141             advise(NULL, "-%scomponents ignored with -all",
142                    components ? "" : "no");
143
144         /* print all entries in context/profile list */
145         for (np = m_defs; np; np = np->n_next)
146             printf("%s: %s\n", np->n_name, np->n_field);
147
148     } else if (debug) {
149         struct proc *ps;
150
151         /*
152          * Print the current value of everything in
153          * procs array.  This will show their current
154          * value (as determined after context is read).
155          */
156         for (ps = procs; ps->p_name; ps++)
157             printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
158
159     } else {
160         if (components < 0)
161             components = compp > 1;
162
163         for (i = 0; i < compp; i++)  {
164             register char *value;
165
166             value = context_find (comps[i]);
167             if (!value)
168                 value = p_find (comps[i]);
169             if (value) {
170                 if (components)
171                     printf("%s: ", comps[i]);
172
173                 printf("%s\n", value);
174             } else
175                 missed++;
176         }
177     }
178     
179     done (missed);
180     return 1;
181 }
182
183
184 static char *
185 p_find(char *str)
186 {
187     struct proc *ps;
188
189     for (ps = procs; ps->p_name; ps++)
190         if (!mh_strcasecmp (ps->p_name, str))
191             return (*ps->p_field);
192
193     return NULL;
194 }