Trash folder replaces rmmproc. Rework of rmm(1) and refile(1).
[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 static struct swit switches[] = {
15 #define COMPSW  0
16         { "components", 0 },
17 #define NCOMPSW  1
18         { "nocomponents", 0 },
19 #define ALLSW  2
20         { "all", 0 },
21 #define VERSIONSW 3
22         { "version", 0 },
23 #define HELPSW  4
24         { "help", 0 },
25 #define DEBUGSW   5
26         { "debug", -5 },
27         { NULL, 0 }
28 };
29
30 struct proc {
31         char *p_name;
32         char **p_field;
33 };
34
35 static struct proc procs [] = {
36         { "attachment-header",  &attach_hdr },
37         { "context",       &context },
38         { "mh-sequences",  &mh_seq },
39         { "editor",        &defaulteditor },
40         { "fileproc",      &fileproc },
41         { "foldprot",      &foldprot },
42         { "listproc",      &listproc },
43         { "mimetypequeryproc", &mimetypequeryproc },
44         { "msgprot",       &msgprot },
45         { "pager",         &defaultpager },
46         { "sendmail",      &sendmail },
47         { "version",       &version_num },
48         { "whatnowproc",   &whatnowproc },
49         { "etcdir",        &mhetcdir },
50         { "backup-prefix", &backup_prefix },
51         { "altmsg-link",   &altmsglink },
52         { "draft-folder",  &draftfolder },
53         { "trash-folder",  &trashfolder },
54         { NULL,            NULL },
55 };
56
57
58 /*
59 ** static prototypes
60 */
61 static char *p_find(char *);
62
63
64 int
65 main(int argc, char **argv)
66 {
67         int i, compp = 0, missed = 0;
68         int all = 0, debug = 0;
69         int components = -1;
70         char *cp, buf[BUFSIZ], **argp;
71         char **arguments, *comps[MAXARGS];
72
73         invo_name = mhbasename(argv[0]);
74
75         /* read user profile/context */
76         context_read();
77
78         arguments = getarguments(invo_name, argc, argv, 1);
79         argp = arguments;
80
81         while ((cp = *argp++)) {
82                 if (*cp == '-') {
83                         switch (smatch(++cp, switches)) {
84                         case AMBIGSW:
85                                 ambigsw(cp, switches);
86                                 done(1);
87                         case UNKWNSW:
88                                 adios(NULL, "-%s unknown", cp);
89
90                         case HELPSW:
91                                 snprintf(buf, sizeof(buf), "%s [profile-components] [switches]", invo_name);
92                                 print_help(buf, switches, 1);
93                                 done(1);
94                         case VERSIONSW:
95                                 print_version(invo_name);
96                                 done(1);
97
98                         case COMPSW:
99                                 components = 1;
100                                 break;
101                         case NCOMPSW:
102                                 components = 0;
103                                 break;
104
105                         case ALLSW:
106                                 all = 1;
107                                 break;
108
109                         case DEBUGSW:
110                                 debug = 1;
111                                 break;
112                         }
113                 } else {
114                         comps[compp++] = cp;
115                 }
116         }
117
118         if (all) {
119                 struct node *np;
120
121                 if (compp)
122                         advise(NULL, "profile-components ignored with -all");
123
124                 if (components >= 0)
125                         advise(NULL, "-%scomponents ignored with -all",
126                                         components ? "" : "no");
127
128                 /* print all entries in context/profile list */
129                 for (np = m_defs; np; np = np->n_next)
130                         printf("%s: %s\n", np->n_name, np->n_field);
131
132         } else if (debug) {
133                 struct proc *ps;
134
135                 /*
136                 ** Print the current value of everything in
137                 ** procs array.  This will show their current
138                 ** value (as determined after context is read).
139                 */
140                 for (ps = procs; ps->p_name; ps++)
141                         printf("%s: %s\n", ps->p_name,
142                                         *ps->p_field ? *ps->p_field : "");
143
144         } else {
145                 if (components < 0)
146                         components = compp > 1;
147
148                 for (i = 0; i < compp; i++)  {
149                         register char *value;
150
151                         value = context_find(comps[i]);
152                         if (!value)
153                                 value = p_find(comps[i]);
154                         if (value) {
155                                 if (components)
156                                         printf("%s: ", comps[i]);
157
158                                 printf("%s\n", value);
159                         } else
160                                 missed++;
161                 }
162         }
163
164         done(missed);
165         return 1;
166 }
167
168
169 static char *
170 p_find(char *str)
171 {
172         struct proc *ps;
173
174         for (ps = procs; ps->p_name; ps++)
175                 if (!mh_strcasecmp(ps->p_name, str))
176                         return (*ps->p_field);
177
178         return NULL;
179 }