diff options
author | Rob Landley <rob@landley.net> | 2006-11-25 13:34:51 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-11-25 13:34:51 -0500 |
commit | 58c6c1be60d96df4b7cb8d77625948b0da297144 (patch) | |
tree | fecf653c1fefbc45e5ad534f4e77866122d8eaa1 /lib | |
parent | f06af2bef5fe73c4ff50ed177fab244ed9db9182 (diff) | |
download | toybox-58c6c1be60d96df4b7cb8d77625948b0da297144.tar.gz |
More work on option parsing. "df -t tmpfs" actually seems to work now.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/args.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -56,7 +56,7 @@ struct opts { char c; int type; int shift; - void *arg; + long *arg; }; struct getoptflagstate @@ -79,21 +79,21 @@ static void gotflag(void) // Does this option take an argument? gof.arg++; - if (gof.this->type & 255) { - // Make "tar xCjfv blah1 blah2 thingy" work like + type = gof.this->type & 255; + if (type) { + + // 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) { gof.arg = toys.argv[++gof.argc]; if (!gof.arg) error_exit("Missing argument"); } - } else gof.this = NULL; - // If the last option had an argument, grab it. - if (gof.this) { - type = gof.this->type & 255; + // Grab argument. if (!gof.arg && !(gof.arg = toys.argv[++gof.argc])) error_exit("Missing argument"); - if (type == ':') gof.this->arg = gof.arg; + if (type == ':') *(gof.this->arg) = (long)gof.arg; else if (type == '*') { struct arg_list *temp, **list; list = (struct arg_list **)gof.this->arg; @@ -107,6 +107,8 @@ static void gotflag(void) gof.arg = ""; } + + gof.this = NULL; } // Fill out toys.optflags and toys.optargs. This isn't reentrant because @@ -180,8 +182,8 @@ void get_optflags(void) } else if (index(":*?@", *options)) { gof.this->type |= *options; // Pointer and long guaranteed to be the same size by LP64. - *(++nextarg) = 0; gof.this->arg = (void *)nextarg; + *(nextarg++) = 0; } else if (*options == '|') { } else if (*options == '+') { } else if (*options == '~') { |