Commit fb8195c0 fb8195c07ba6c6a3afa7da1f028410723e9073a4 by Sergey Poznyakoff

Fix fb84d1e3

The commit didn't take into account all possible option/argument combinations.

* mh/pick.c (main): Preprocess command line prior to parsing it,
expanding --COMP NAME in -component COMP -pattern NAME.
* mh/mh_getopt.c: Revert fb84d1e3
* mh/mh_getopt.h: Likewise.
1 parent 8ce30633
......@@ -178,11 +178,9 @@ has_folder_option (struct mu_option *opt)
}
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)
mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
int mhflags,
char *argdoc, char *progdoc, char *extradoc)
{
int argc = *pargc;
char **argv = *pargv;
......@@ -199,9 +197,6 @@ mh_getopt0 (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]");
......@@ -259,29 +254,12 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options,
if (options)
optv[i++] = options;
optv[i] = NULL;
if (mu_parseopt (&po, argc, argv, optv, flags))
exit (po.po_exit_error);
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);
argc -= po.po_arg_start;
argv += po.po_arg_start;
process_std_options (argc, argv, &po);
......@@ -305,15 +283,6 @@ mh_getopt0 (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,11 +23,6 @@
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,28 +260,44 @@ 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)
{
int status;
int i, status;
mu_mailbox_t mbox;
mu_msgset_t msgset;
mh_getopt0 (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL, comp_match_arg, &lexlist);
int argv_alloc = 0;
for (i = 1; i < argc;)
{
if (strncmp (argv[i], "--", 2) == 0 && argv[i][3] && i + 1 < argc)
{
size_t n = argc + 2;
if (argv_alloc)
argv = mu_realloc (argv, (n + 1) * sizeof (argv[0]));
else
{
char **p = mu_calloc (n + 1, sizeof p[0]);
memcpy (p, argv, (argc + 1) * sizeof argv[0]);
argv = p;
argv_alloc = 1;
}
memmove (argv + i + 4, argv + i + 2,
(argc - i - 1) * sizeof argv[0]);
argv[i + 3] = argv[i + 1];
argv[i + 2] = mu_strdup ("-pattern");
argv[i + 1] = mu_strdup (argv[i] + 2);
argv[i] = mu_strdup ("-component");
argc = n;
i += 4;
}
else
i++;
}
mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
parse_comp_match (&argc, argv);
......