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