Commit fb84d1e3 fb84d1e35a1f9247e3c79919b52230adf6592f9f by Sergey Poznyakoff

Fix pick --component NAME

* mh/mh_getopt.c (mh_getopt0): New function.
(mh_getopt): Rewrite as alternative entry point to .
* mh/mh_getopt.h (mh_getopt0): New proto.
* mh/pick.c: Use mh_getopt0
* mh/tests/pick.at: Add new testcase.
1 parent 89fb41d0
...@@ -178,9 +178,11 @@ has_folder_option (struct mu_option *opt) ...@@ -178,9 +178,11 @@ has_folder_option (struct mu_option *opt)
178 } 178 }
179 179
180 void 180 void
181 mh_getopt (int *pargc, char ***pargv, struct mu_option *options, 181 mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options,
182 int mhflags, 182 int mhflags,
183 char *argdoc, char *progdoc, char *extradoc) 183 char *argdoc, char *progdoc, char *extradoc,
184 int (*eatarg) (int argc, char **argv, void *data),
185 void *data)
184 { 186 {
185 int argc = *pargc; 187 int argc = *pargc;
186 char **argv = *pargv; 188 char **argv = *pargv;
...@@ -197,6 +199,9 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, ...@@ -197,6 +199,9 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
197 po.po_negation = "no"; 199 po.po_negation = "no";
198 flags |= MU_PARSEOPT_NEGATION; 200 flags |= MU_PARSEOPT_NEGATION;
199 201
202 if (eatarg)
203 flags |= MU_PARSEOPT_IN_ORDER;
204
200 if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options)) 205 if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options))
201 { 206 {
202 po.po_special_args = N_("[+FOLDER]"); 207 po.po_special_args = N_("[+FOLDER]");
...@@ -255,11 +260,28 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, ...@@ -255,11 +260,28 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
255 optv[i++] = options; 260 optv[i++] = options;
256 optv[i] = NULL; 261 optv[i] = NULL;
257 262
263 do
264 {
258 if (mu_parseopt (&po, argc, argv, optv, flags)) 265 if (mu_parseopt (&po, argc, argv, optv, flags))
259 exit (po.po_exit_error); 266 exit (po.po_exit_error);
260
261 argc -= po.po_arg_start; 267 argc -= po.po_arg_start;
262 argv += po.po_arg_start; 268 argv += po.po_arg_start;
269 if (eatarg)
270 {
271 int consumed = eatarg (argc, argv, data);
272 if (consumed == 0)
273 break;
274 else
275 {
276 argc -= consumed;
277 argv += consumed;
278 }
279 flags |= MU_PARSEOPT_ARGV0;
280 }
281 else
282 break;
283 }
284 while (argc > 0);
263 285
264 process_std_options (argc, argv, &po); 286 process_std_options (argc, argv, &po);
265 287
...@@ -283,6 +305,15 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options, ...@@ -283,6 +305,15 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
283 } 305 }
284 306
285 void 307 void
308 mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
309 int mhflags,
310 char *argdoc, char *progdoc, char *extradoc)
311 {
312 return mh_getopt0 (pargc, pargv, options, mhflags, argdoc, progdoc, extradoc,
313 NULL, NULL);
314 }
315
316 void
286 mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg) 317 mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
287 { 318 {
288 mu_error (_("option is not yet implemented: %s"), opt->opt_long); 319 mu_error (_("option is not yet implemented: %s"), opt->opt_long);
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
23 void mh_getopt (int *pargc, char ***pargv, struct mu_option *options, 23 void mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
24 int flags, 24 int flags,
25 char *argdoc, char *progdoc, char *extradoc); 25 char *argdoc, char *progdoc, char *extradoc);
26 void mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options,
27 int mhflags,
28 char *argdoc, char *progdoc, char *extradoc,
29 int (*eatarg) (int argc, char **argv, void *data),
30 void *data);
26 31
27 void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, 32 void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt,
28 char const *arg); 33 char const *arg);
......
...@@ -260,6 +260,19 @@ parse_comp_match (int *pargc, char **argv) ...@@ -260,6 +260,19 @@ parse_comp_match (int *pargc, char **argv)
260 *pargc = j; 260 *pargc = j;
261 } 261 }
262 262
263 static int
264 comp_match_arg (int argc, char **argv, void *data)
265 {
266 if (argc >= 2 && strncmp (argv[0], "--", 2) == 0)
267 {
268 mu_list_t *lp = data;
269 pick_add_token (lp, T_COMP, argv[0] + 2);
270 pick_add_token (lp, T_STRING, argv[1]);
271 return 2;
272 }
273 return 0;
274 }
275
263 int 276 int
264 main (int argc, char **argv) 277 main (int argc, char **argv)
265 { 278 {
...@@ -267,8 +280,8 @@ main (int argc, char **argv) ...@@ -267,8 +280,8 @@ main (int argc, char **argv)
267 mu_mailbox_t mbox; 280 mu_mailbox_t mbox;
268 mu_msgset_t msgset; 281 mu_msgset_t msgset;
269 282
270 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, 283 mh_getopt0 (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
271 args_doc, prog_doc, NULL); 284 args_doc, prog_doc, NULL, comp_match_arg, &lexlist);
272 285
273 parse_comp_match (&argc, argv); 286 parse_comp_match (&argc, argv);
274 287
......
...@@ -342,5 +342,38 @@ pick --X-Envelope-Sender hare ...@@ -342,5 +342,38 @@ pick --X-Envelope-Sender hare
342 71 342 71
343 ]) 343 ])
344 344
345 MH_CHECK([pick --Component pattern -or ...],[pick12 pick-component0or],[
346 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
347 pick --X-Envelope-Sender hare -or -to hare
348 ],
349 [0],
350 [1
351 2
352 3
353 4
354 5
355 6
356 7
357 8
358 9
359 10
360 11
361 12
362 13
363 14
364 16
365 21
366 22
367 23
368 24
369 35
370 42
371 58
372 59
373 62
374 71
375 72
376 ])
377
345 m4_popdef[MH_KEYWORDS]) 378 m4_popdef[MH_KEYWORDS])
346 # End of pick.at 379 # End of pick.at
......