Commit 74d00d22 74d00d22582cb9d6ca06a39157015e4d1b5874ee by Sergey Poznyakoff

A framework for pick command

1 parent 94450bc8
Showing 1 changed file with 188 additions and 0 deletions
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 /* MH pick command */
19
20 #include <mh.h>
21 #include <regex.h>
22
23 const char *argp_program_version = "pick (" PACKAGE_STRING ")";
24 static char doc[] = N_("GNU MH pick\v"
25 "Options marked with `*' are not yet implemented.\n"
26 "Use -help to obtain the list of traditional MH options.");
27 static char args_doc[] = N_("[messages]");
28
29 /* GNU options */
30 static struct argp_option options[] = {
31 {"folder", ARG_FOLDER, N_("FOLDER"), 0,
32 N_("Specify folder to operate upon"), 0},
33
34 {N_("Specifying search patterns:"), 0, NULL, OPTION_DOC, NULL, 0},
35 {"component", ARG_COMPONENT, N_("FIELD"), 0,
36 N_("Search the named header field"), 1},
37 {"pattern", ARG_PATTERN, N_("STRING"), 0,
38 N_("A pattern to look for"), 1},
39 {"search", 0, NULL, OPTION_ALIAS, NULL, 1},
40 {"cc", ARG_CC, N_("STRING"), 0,
41 N_("Same as --component cc --pattern STRING"), 1},
42 {"date", ARG_DATE, N_("STRING"), 0,
43 N_("Same as --component date --pattern STRING"), 1},
44 {"from", ARG_FROM, N_("STRING"), 0,
45 N_("Same as --component from --pattern STRING"), 1},
46 {"subject", ARG_SUBJECT, N_("STRING"), 0,
47 N_("Same as --component subject --pattern STRING"), 1},
48 {"to", ARG_TO, N_("STRING"), 0,
49 N_("Same as --component to --pattern STRING"), 1},
50
51 {N_("Date constraint operations:"), 0, NULL, OPTION_DOC, NULL, 1},
52 {"datefield",ARG_DATEFIELD, N_("STRING"), 0,
53 N_("Search in the named date header field (default is `Date:')"), 2},
54 {"after", ARG_AFTER, N_("DATE"), 0,
55 N_("Match messages after the given date"), 2},
56 {"before", ARG_BEFORE, N_("DATE"), 0,
57 N_("Match messages before the given date"), 2},
58
59 {N_("Logical operations and grouping:"), 0, NULL, OPTION_DOC, NULL, 2},
60 {"and", ARG_AND, NULL, 0,
61 N_("Logical AND (default)"), 3 },
62 {"or", ARG_OR, NULL, 0,
63 N_("Logical OR"), 3 },
64 {"not", ARG_NOT, NULL, 0,
65 N_("Logical NOT"), 3},
66 {"lbrace", ARG_LBRACE, NULL, 0,
67 N_("Open group"), 3},
68 {"(", 0, NULL, OPTION_ALIAS, NULL, 3},
69 {"rbrace", ARG_RBRACE, NULL, 0,
70 N_("Close group"), 3},
71 {")", 0, NULL, OPTION_ALIAS, NULL, 3},
72
73 {N_("Operations over the selected messages:"), 0, NULL, OPTION_DOC, NULL, 3},
74 {"list", ARG_LIST, N_("BOOL"), OPTION_ARG_OPTIONAL,
75 N_("List the numbers of the selected messages (default)"), 4},
76 {"nolist", ARG_NOLIST, NULL, OPTION_HIDDEN, "", 4 },
77 {"sequence", ARG_SEQUENCE, N_("NAME"), 0,
78 N_("Add matching messages to the given sequence"), 4},
79 {"public", ARG_PUBLIC, N_("BOOL"), OPTION_ARG_OPTIONAL,
80 N_("Create public sequence"), 4},
81 {"nopublic", ARG_NOPUBLIC, NULL, OPTION_HIDDEN, "", 4 },
82 {"zero", ARG_ZERO, N_("BOOL"), OPTION_ARG_OPTIONAL,
83 N_("Empty the sequence before adding messages"), 4},
84 {"nozero", ARG_NOZERO, NULL, OPTION_HIDDEN, "", 4 },
85 {NULL},
86 };
87
88 /* Traditional MH options */
89 struct mh_option mh_option[] = {
90 {"component", 1, 0, "field" },
91 {"pattern", 1, 0, "pattern" },
92 {"search", 1, 0, "pattern" },
93 {"cc", 1, 0, "pattern" },
94 {"date", 1, 0, "pattern" },
95 {"from", 1, 0, "pattern" },
96 {"subject", 1, 0, "pattern" },
97 {"to", 1, 0, "pattern" },
98 {"datefield", 1, 0, "field" },
99 {"after", 1, 0, "date" },
100 {"before", 1, 0, "date"},
101 {"and", 1, 0, NULL },
102 {"or", 1, 0, NULL },
103 {"not", 1, 0, NULL },
104 {"lbrace", 1, 0, NULL },
105 {"rbrace", 1, 0, NULL },
106
107 {"list", 1, MH_OPT_BOOL, },
108 {"sequence", 1, 0, NULL },
109 {"public", 1, MH_OPT_BOOL },
110 {"zero", 1, MH_OPT_BOOL },
111 {NULL}
112 };
113
114 static int list;
115 static int mode_public = 1;
116 static int mode_zero = 0;
117
118 static int
119 opt_handler (int key, char *arg, void *unused)
120 {
121 switch (key)
122 {
123 case '+':
124 case ARG_FOLDER:
125 current_folder = arg;
126 break;
127
128 case ARG_SEQUENCE:
129 /* add_sequence (arg); */
130 break;
131
132 case ARG_LIST:
133 list = is_true (arg);
134 break;
135
136 case ARG_NOLIST:
137 list = 0;
138 break;
139
140 case ARG_COMPONENT:
141 case ARG_PATTERN:
142 case ARG_CC:
143 case ARG_DATE:
144 case ARG_FROM:
145 case ARG_SUBJECT:
146 case ARG_TO:
147 case ARG_DATEFIELD:
148 case ARG_AFTER:
149 case ARG_BEFORE:
150 case ARG_AND:
151 case ARG_OR:
152 case ARG_NOT:
153 case ARG_LBRACE:
154 case ARG_RBRACE:
155 break;
156
157 case ARG_PUBLIC:
158 mode_public = is_true (arg);
159 break;
160
161 case ARG_NOPUBLIC:
162 mode_public = 0;
163 break;
164
165 case ARG_ZERO:
166 mode_zero = is_true (arg);
167 break;
168
169 case ARG_NOZERO:
170 mode_zero = 0;
171 break;
172
173 default:
174 return 1;
175 }
176 return 0;
177 }
178
179 int
180 main (int argc, char **argv)
181 {
182 int index;
183
184 mu_init_nls ();
185 mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
186 opt_handler, NULL, &index);
187 }
188