Disable utmpx support for systems that lack getutxent.
[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 char *sbackup = BACKUP_PREFIX;
19
20 static struct swit switches[] = {
21 #define COMPSW    0
22     { "components", 0 },
23 #define NCOMPSW   1
24     { "nocomponents", 0 },
25 #define ALLSW     2
26     { "all", 0 },
27 #define VERSIONSW 3
28     { "version", 0 },
29 #define HELPSW    4
30     { "help", 0 },
31 #define DEBUGSW   5
32     { "debug", -5 },
33     { NULL, 0 }
34 };
35
36 struct proc {
37     char *p_name;
38     char **p_field;
39 };
40
41 static struct proc procs [] = {
42      { "context",       &context },
43      { "mh-sequences",  &mh_seq },
44      { "buildmimeproc", &buildmimeproc },
45      { "faceproc",      &faceproc },
46      { "fileproc",      &fileproc },
47      { "foldprot",      &foldprot },
48      { "formatproc",    &formatproc },
49      { "incproc",       &incproc },
50      { "installproc",   &installproc  },
51      { "lproc",         &lproc },
52      { "mailproc",      &mailproc },
53      { "mhlproc",       &mhlproc },
54      { "moreproc",      &moreproc },
55      { "msgprot",       &msgprot },
56      { "mshproc",       &mshproc },
57      { "packproc",      &packproc },
58      { "postproc",      &postproc },
59      { "rmmproc",       &rmmproc },
60      { "sendproc",      &sendproc },
61      { "showmimeproc",  &showmimeproc },
62      { "showproc",      &showproc },
63      { "version",       &version_num },
64      { "vmhproc",       &vmhproc },
65      { "whatnowproc",   &whatnowproc },
66      { "whomproc",      &whomproc },
67      { "etcdir",        &mhetcdir },
68      { "libdir",        &mhlibdir },
69      { "sbackup",       &sbackup },
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     } else 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     done (missed);
181     return 1;
182 }
183
184
185 static char *
186 p_find(char *str)
187 {
188     struct proc *ps;
189
190     for (ps = procs; ps->p_name; ps++)
191         if (!mh_strcasecmp (ps->p_name, str))
192             return (*ps->p_field);
193
194     return NULL;
195 }