# HG changeset patch # User Rob Landley # Date 1164479691 18000 # Node ID 993eab821bd540886a14dbc5fb8e13c9c60368b8 # Parent 7d3f0ff39878c402d9b5551bf8f6bdbc07ca6ca6 More work on option parsing. "df -t tmpfs" actually seems to work now. diff -r 7d3f0ff39878 -r 993eab821bd5 lib/args.c --- a/lib/args.c Sat Nov 25 13:32:01 2006 -0500 +++ b/lib/args.c Sat Nov 25 13:34:51 2006 -0500 @@ -56,7 +56,7 @@ char c; int type; int shift; - void *arg; + long *arg; }; struct getoptflagstate @@ -79,21 +79,21 @@ // 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 @@ gof.arg = ""; } + + gof.this = NULL; } // Fill out toys.optflags and toys.optargs. This isn't reentrant because @@ -180,8 +182,8 @@ } 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 == '~') { diff -r 7d3f0ff39878 -r 993eab821bd5 toys/df.c --- a/toys/df.c Sat Nov 25 13:32:01 2006 -0500 +++ b/toys/df.c Sat Nov 25 13:34:51 2006 -0500 @@ -21,11 +21,12 @@ // If we have -t, skip other filesystem types if (toy.df.fstype) { - struct string_list *sl; + struct arg_list *al; - for (sl = toy.df.fstype; sl; sl = sl->next) - if (!strcmp(mt->type, sl->str)) break; - if (!sl) return; + for (al = toy.df.fstype; al; al = al->next) { + if (!strcmp(mt->type, al->arg)) break; + } + if (!al) return; } // If we don't have -a, skip synthetic filesystems diff -r 7d3f0ff39878 -r 993eab821bd5 toys/toylist.h --- a/toys/toylist.h Sat Nov 25 13:32:01 2006 -0500 +++ b/toys/toylist.h Sat Nov 25 13:34:51 2006 -0500 @@ -54,7 +54,7 @@ // The rest of these are alphabetical, for binary search. USE_TOYSH(NEWTOY(cd, NULL, TOYFLAG_NOFORK)) -USE_DF(NEWTOY(df, "Pkt:a", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN)) USE_TOYSH(NEWTOY(exit, NULL, TOYFLAG_NOFORK)) USE_HELLO(NEWTOY(hello, NULL, TOYFLAG_NOFORK|TOYFLAG_USR)) USE_PWD(NEWTOY(pwd, NULL, TOYFLAG_BIN))