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.
Showing
3 changed files
with
35 additions
and
55 deletions
... | @@ -178,11 +178,9 @@ has_folder_option (struct mu_option *opt) | ... | @@ -178,11 +178,9 @@ has_folder_option (struct mu_option *opt) |
178 | } | 178 | } |
179 | 179 | ||
180 | void | 180 | void |
181 | mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, | 181 | mh_getopt (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) | ||
186 | { | 184 | { |
187 | int argc = *pargc; | 185 | int argc = *pargc; |
188 | char **argv = *pargv; | 186 | char **argv = *pargv; |
... | @@ -199,9 +197,6 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, | ... | @@ -199,9 +197,6 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, |
199 | po.po_negation = "no"; | 197 | po.po_negation = "no"; |
200 | flags |= MU_PARSEOPT_NEGATION; | 198 | flags |= MU_PARSEOPT_NEGATION; |
201 | 199 | ||
202 | if (eatarg) | ||
203 | flags |= MU_PARSEOPT_IN_ORDER; | ||
204 | |||
205 | if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options)) | 200 | if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options)) |
206 | { | 201 | { |
207 | po.po_special_args = N_("[+FOLDER]"); | 202 | po.po_special_args = N_("[+FOLDER]"); |
... | @@ -260,28 +255,11 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, | ... | @@ -260,28 +255,11 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, |
260 | optv[i++] = options; | 255 | optv[i++] = options; |
261 | optv[i] = NULL; | 256 | optv[i] = NULL; |
262 | 257 | ||
263 | do | ||
264 | { | ||
265 | if (mu_parseopt (&po, argc, argv, optv, flags)) | 258 | if (mu_parseopt (&po, argc, argv, optv, flags)) |
266 | exit (po.po_exit_error); | 259 | exit (po.po_exit_error); |
260 | |||
267 | argc -= po.po_arg_start; | 261 | argc -= po.po_arg_start; |
268 | argv += po.po_arg_start; | 262 | 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); | ||
285 | 263 | ||
286 | process_std_options (argc, argv, &po); | 264 | process_std_options (argc, argv, &po); |
287 | 265 | ||
... | @@ -305,15 +283,6 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, | ... | @@ -305,15 +283,6 @@ mh_getopt0 (int *pargc, char ***pargv, struct mu_option *options, |
305 | } | 283 | } |
306 | 284 | ||
307 | void | 285 | 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 | ||
317 | mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg) | 286 | mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg) |
318 | { | 287 | { |
319 | mu_error (_("option is not yet implemented: %s"), opt->opt_long); | 288 | mu_error (_("option is not yet implemented: %s"), opt->opt_long); | ... | ... |
... | @@ -23,11 +23,6 @@ | ... | @@ -23,11 +23,6 @@ |
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); | ||
31 | 26 | ||
32 | void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, | 27 | void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, |
33 | char const *arg); | 28 | char const *arg); | ... | ... |
... | @@ -260,28 +260,44 @@ parse_comp_match (int *pargc, char **argv) | ... | @@ -260,28 +260,44 @@ 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 | |||
276 | int | 263 | int |
277 | main (int argc, char **argv) | 264 | main (int argc, char **argv) |
278 | { | 265 | { |
279 | int status; | 266 | int i, status; |
280 | mu_mailbox_t mbox; | 267 | mu_mailbox_t mbox; |
281 | mu_msgset_t msgset; | 268 | mu_msgset_t msgset; |
269 | int argv_alloc = 0; | ||
270 | |||
271 | for (i = 1; i < argc;) | ||
272 | { | ||
273 | if (strncmp (argv[i], "--", 2) == 0 && argv[i][3] && i + 1 < argc) | ||
274 | { | ||
275 | size_t n = argc + 2; | ||
276 | if (argv_alloc) | ||
277 | argv = mu_realloc (argv, (n + 1) * sizeof (argv[0])); | ||
278 | else | ||
279 | { | ||
280 | char **p = mu_calloc (n + 1, sizeof p[0]); | ||
281 | memcpy (p, argv, (argc + 1) * sizeof argv[0]); | ||
282 | argv = p; | ||
283 | argv_alloc = 1; | ||
284 | } | ||
285 | |||
286 | memmove (argv + i + 4, argv + i + 2, | ||
287 | (argc - i - 1) * sizeof argv[0]); | ||
288 | argv[i + 3] = argv[i + 1]; | ||
289 | argv[i + 2] = mu_strdup ("-pattern"); | ||
290 | argv[i + 1] = mu_strdup (argv[i] + 2); | ||
291 | argv[i] = mu_strdup ("-component"); | ||
292 | argc = n; | ||
293 | i += 4; | ||
294 | } | ||
295 | else | ||
296 | i++; | ||
297 | } | ||
282 | 298 | ||
283 | mh_getopt0 (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, | 299 | mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, |
284 | args_doc, prog_doc, NULL, comp_match_arg, &lexlist); | 300 | args_doc, prog_doc, NULL); |
285 | 301 | ||
286 | parse_comp_match (&argc, argv); | 302 | parse_comp_match (&argc, argv); |
287 | 303 | ... | ... |
-
Please register or sign in to post a comment