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