Eliminated compilation warnings.
[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  * $Id$
9  */
10
11 #include <h/mh.h>
12
13 extern char *mhlibdir;
14 extern char *mhetcdir;
15
16 char *sbackup = BACKUP_PREFIX;
17 char *slink = LINK;
18
19 static struct swit switches[] = {
20 #define COMPSW    0
21     { "components", 0 },
22 #define NCOMPSW   1
23     { "nocomponents", 0 },
24 #define ALLSW     2
25     { "all", 0 },
26 #define VERSIONSW 3
27     { "version", 0 },
28 #define HELPSW    4
29     { "help", 4 },
30 #define DEBUGSW   5
31     { "debug", -5 },
32     { NULL, 0 }
33 };
34
35 struct proc {
36     char *p_name;
37     char **p_field;
38 };
39
40 static struct proc procs [] = {
41      { "context",       &context },
42      { "mh-sequences",  &mh_seq },
43      { "buildmimeproc", &buildmimeproc },
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      { "mshproc",       &mshproc },
55      { "packproc",      &packproc },
56      { "postproc",      &postproc },
57      { "rmfproc",       &rmfproc },
58      { "rmmproc",       &rmmproc },
59      { "sendproc",      &sendproc },
60      { "showmimeproc",  &showmimeproc },
61      { "showproc",      &showproc },
62      { "version",       &version_num },
63      { "vmhproc",       &vmhproc },
64      { "whatnowproc",   &whatnowproc },
65      { "whomproc",      &whomproc },
66      { "etcdir",        &mhetcdir },
67      { "libdir",        &mhlibdir },
68      { "sbackup",       &sbackup },
69      { "link",          &slink },
70      { NULL,            NULL },
71 };
72
73
74 /*
75  * static prototypes
76  */
77 static char *p_find(char *);
78
79
80 int
81 main(int argc, char **argv)
82 {
83     int i, compp = 0, missed = 0;
84     int all = 0, debug = 0;
85     int components = -1;
86     char *cp, buf[BUFSIZ], **argp;
87     char **arguments, *comps[MAXARGS];
88
89     invo_name = r1bindex (argv[0], '/');
90
91     /* read user profile/context */
92     context_read();
93
94     arguments = getarguments (invo_name, argc, argv, 1);
95     argp = arguments;
96
97     while ((cp = *argp++)) {
98         if (*cp == '-') {
99             switch (smatch (++cp, switches)) {
100                 case AMBIGSW: 
101                     ambigsw (cp, switches);
102                     done (1);
103                 case UNKWNSW: 
104                     adios (NULL, "-%s unknown", cp);
105
106                 case HELPSW: 
107                     snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
108                         invo_name);
109                     print_help (buf, switches, 1);
110                     done (1);
111                 case VERSIONSW:
112                     print_version(invo_name);
113                     done (1);
114
115                 case COMPSW:
116                     components = 1;
117                     break;
118                 case NCOMPSW:
119                     components = 0;
120                     break;
121
122                 case ALLSW:
123                     all = 1;
124                     break;
125
126                 case DEBUGSW:
127                     debug = 1;
128                     break;
129             }
130         } else {
131             comps[compp++] = cp;
132         }
133     }
134
135     if (all) {
136         struct node *np;
137
138         if (compp)
139             advise(NULL, "profile-components ignored with -all");
140
141         if (components >= 0)
142             advise(NULL, "-%scomponents ignored with -all",
143                    components ? "" : "no");
144
145         /* print all entries in context/profile list */
146         for (np = m_defs; np; np = np->n_next)
147             printf("%s: %s\n", np->n_name, np->n_field);
148
149     } if (debug) {
150         struct proc *ps;
151
152         /*
153          * Print the current value of everything in
154          * procs array.  This will show their current
155          * value (as determined after context is read).
156          */
157         for (ps = procs; ps->p_name; ps++)
158             printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
159
160     } else {
161         if (components < 0)
162             components = compp > 1;
163
164         for (i = 0; i < compp; i++)  {
165             register char *value;
166
167             value = context_find (comps[i]);
168             if (!value)
169                 value = p_find (comps[i]);
170             if (value) {
171                 if (components)
172                     printf("%s: ", comps[i]);
173
174                 printf("%s\n", value);
175             } else
176                 missed++;
177         }
178     }
179     
180     return done (missed);
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 (!strcasecmp (ps->p_name, str))
191             return (*ps->p_field);
192
193     return NULL;
194 }