Mercurial > hg > toybox
changeset 392:4fb1fa3e6603
Fix "tar cvjfC file dir", make @ not eat an argument, add debug check for (as yet) unsupported multi-function option (ala "x*@").
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 28 Nov 2011 00:22:15 -0600 |
parents | 56d07d82e691 |
children | bfc208c5ac79 |
files | lib/args.c |
diffstat | 1 files changed, 12 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/args.c Tue Nov 22 06:08:26 2011 -0600 +++ b/lib/args.c Mon Nov 28 00:22:15 2011 -0600 @@ -108,32 +108,28 @@ // Does this option take an argument? gof->arg++; type = opt->type; - if (type) { + if (type == '@') ++*(opt->arg); + else if (type) { + char *arg = gof->arg; // Handle "-xblah" and "-x blah", but also a third case: "abxc blah" // to make "tar xCjfv blah1 blah2 thingy" work like // "tar -x -C blah1 -j -f blah2 -v thingy" - if (!gof->nodash_now && !gof->arg[0]) { - gof->arg = toys.argv[++gof->argc]; - // TODO: The following line doesn't display --longopt correctly - if (!gof->arg) error_exit("Missing argument to -%c",opt->c); - } + if (gof->nodash_now || !gof->arg[0]) arg = toys.argv[++gof->argc]; + // TODO: The following line doesn't display --longopt correctly + if (!arg) error_exit("Missing argument to -%c", opt->c); - // Grab argument. - if (!gof->arg && !(gof->arg = toys.argv[++(gof->argc)])) - error_exit("Missing argument"); - if (type == ':') *(opt->arg) = (long)gof->arg; + if (type == ':') *(opt->arg) = (long)arg; else if (type == '*') { struct arg_list **list; list = (struct arg_list **)opt->arg; while (*list) list=&((*list)->next); *list = xzalloc(sizeof(struct arg_list)); - (*list)->arg = gof->arg; - } else if (type == '#') *(opt->arg) = atolx((char *)gof->arg); - else if (type == '@') ++*(opt->arg); + (*list)->arg = arg; + } else if (type == '#') *(opt->arg) = atolx((char *)arg); - gof->arg = ""; + if (!gof->nodash_now) gof->arg = ""; } gof->this = NULL; @@ -217,6 +213,8 @@ // If this is the start of a new option that wasn't a longopt, } else if (strchr(":*#@", *options)) { + if (CFG_TOYBOX_DEBUG && gof.this->type) + error_exit("Bug4 in get_opt"); gof.this->type = *options; } else if (0 != (temp = strchr(plustildenot, *options))) { int i=0, idx = temp - plustildenot;