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)
}
void
mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options,
int mhflags,
char *argdoc, char *progdoc, char *extradoc)
char *argdoc, char *progdoc, char *extradoc,
int (*eatarg) (int argc, char **argv, void *data),
void *data)
{
int argc = *pargc;
char **argv = *pargv;
......@@ -197,6 +199,9 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
po.po_negation = "no";
flags |= MU_PARSEOPT_NEGATION;
if (eatarg)
flags |= MU_PARSEOPT_IN_ORDER;
if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options))
{
po.po_special_args = N_("[+FOLDER]");
......@@ -255,11 +260,28 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
optv[i++] = options;
optv[i] = NULL;
do
{
if (mu_parseopt (&po, argc, argv, optv, flags))
exit (po.po_exit_error);
argc -= po.po_arg_start;
argv += po.po_arg_start;
if (eatarg)
{
int consumed = eatarg (argc, argv, data);
if (consumed == 0)
break;
else
{
argc -= consumed;
argv += consumed;
}
flags |= MU_PARSEOPT_ARGV0;
}
else
break;
}
while (argc > 0);
process_std_options (argc, argv, &po);
......@@ -283,6 +305,15 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
}
void
mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
int mhflags,
char *argdoc, char *progdoc, char *extradoc)
{
return mh_getopt0 (pargc, pargv, options, mhflags, argdoc, progdoc, extradoc,
NULL, NULL);
}
void
mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
mu_error (_("option is not yet implemented: %s"), opt->opt_long);
......
......@@ -23,6 +23,11 @@
void mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
int flags,
char *argdoc, char *progdoc, char *extradoc);
void mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options,
int mhflags,
char *argdoc, char *progdoc, char *extradoc,
int (*eatarg) (int argc, char **argv, void *data),
void *data);
void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt,
char const *arg);
......
......@@ -260,6 +260,19 @@ parse_comp_match (int *pargc, char **argv)
*pargc = j;
}
static int
comp_match_arg (int argc, char **argv, void *data)
{
if (argc >= 2 && strncmp (argv[0], "--", 2) == 0)
{
mu_list_t *lp = data;
pick_add_token (lp, T_COMP, argv[0] + 2);
pick_add_token (lp, T_STRING, argv[1]);
return 2;
}
return 0;
}
int
main (int argc, char **argv)
{
......@@ -267,8 +280,8 @@ main (int argc, char **argv)
mu_mailbox_t mbox;
mu_msgset_t msgset;
mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
mh_getopt0 (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL, comp_match_arg, &lexlist);
parse_comp_match (&argc, argv);
......
......@@ -342,5 +342,38 @@ pick --X-Envelope-Sender hare
71
])
MH_CHECK([pick --Component pattern -or ...],[pick12 pick-component0or],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
pick --X-Envelope-Sender hare -or -to hare
],
[0],
[1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
21
22
23
24
35
42
58
59
62
71
72
])
m4_popdef[MH_KEYWORDS])
# End of pick.at
......