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