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