diff options
author | Rob Landley <rob@landley.net> | 2014-12-31 21:30:59 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-12-31 21:30:59 -0600 |
commit | f3e56f4e4ff773de95fa2c9daf979734d826fc33 (patch) | |
tree | 8a8e75b3530b504569ebe4fae09020073534c6db /toys/posix | |
parent | 5834ddd6df659d9c9dc7333284fc86762dea061a (diff) | |
download | toybox-f3e56f4e4ff773de95fa2c9daf979734d826fc33.tar.gz |
Redo option parsing infrastructure so #define FORCE_FLAGS can unzero flag macros for a disabled command (needed when multiple commands share infrastructure with a common set of flags).
This means the flag space is no longer packed, but leaves gaps where the zeroes
go. (Actual flag bit positions are the same for all configs.) Since the
option parsing needs to know where the holes are, the OPTSTR values are
now generated as part of flags.h with ascii 1 values for the disabled values.
(So generated/oldflags.h went away.)
This also means that the option string argument for OLDTOY() went away, it now
uses the same arguments as the NEWTOY() it references.
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/chgrp.c | 2 | ||||
-rw-r--r-- | toys/posix/grep.c | 4 | ||||
-rw-r--r-- | toys/posix/id.c | 30 | ||||
-rw-r--r-- | toys/posix/true.c | 2 |
4 files changed, 23 insertions, 15 deletions
diff --git a/toys/posix/chgrp.c b/toys/posix/chgrp.c index 3aa25147..f573add4 100644 --- a/toys/posix/chgrp.c +++ b/toys/posix/chgrp.c @@ -8,7 +8,7 @@ * TODO: group only one of [HLP] USE_CHGRP(NEWTOY(chgrp, "<2hPLHRfv", TOYFLAG_BIN)) -USE_CHGRP(OLDTOY(chown, chgrp, OPTSTR_chgrp, TOYFLAG_BIN)) +USE_CHGRP(OLDTOY(chown, chgrp, TOYFLAG_BIN)) config CHGRP bool "chgrp/chown" diff --git a/toys/posix/grep.c b/toys/posix/grep.c index aba70878..18a27e3e 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -5,8 +5,8 @@ * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html USE_GREP(NEWTOY(grep, "ZzEFHabhinorsvwclqe*f*m#x[!wx][!EFw]", TOYFLAG_BIN)) -USE_GREP(OLDTOY(egrep, grep, OPTSTR_grep, TOYFLAG_BIN)) -USE_GREP(OLDTOY(fgrep, grep, OPTSTR_grep, TOYFLAG_BIN)) +USE_GREP(OLDTOY(egrep, grep, TOYFLAG_BIN)) +USE_GREP(OLDTOY(fgrep, grep, TOYFLAG_BIN)) config GREP bool "grep" diff --git a/toys/posix/id.c b/toys/posix/id.c index 000d7b4c..dd48cf0b 100644 --- a/toys/posix/id.c +++ b/toys/posix/id.c @@ -7,9 +7,9 @@ * See http://opengroup.org/onlinepubs/9699919799/utilities/id.html USE_ID(NEWTOY(id, ">1nGgru[!Ggu]", TOYFLAG_BIN)) -USE_GROUPS(OLDTOY(groups, id, NULL, TOYFLAG_USR|TOYFLAG_BIN)) -USE_LOGNAME(OLDTOY(logname, id, ">0", TOYFLAG_BIN)) -USE_WHOAMI(OLDTOY(whoami, id, ">0", TOYFLAG_BIN)) +USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN)) +USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_BIN)) +USE_WHOAMI(OLDTOY(whoami, logname, TOYFLAG_BIN)) config ID bool "id" @@ -133,15 +133,23 @@ void do_id(char *username) void id_main(void) { // FLAG macros can be 0 if "id" command not enabled, so snapshot them here. - if (FLAG_u) TT.do_u = toys.optflags & FLAG_u; - if (FLAG_n) TT.do_n = toys.optflags & FLAG_n; - if (FLAG_G) TT.do_G = toys.optflags & FLAG_G; - - // And set the variables for non-id commands. - TT.is_groups = toys.which->name[0] == 'g'; - if (TT.is_groups) TT.do_G = TT.do_n = 1; - else if (toys.which->name[0] != 'i') TT.do_u = TT.do_n = 1; + if (FLAG_u) TT.do_u |= toys.optflags & FLAG_u; + if (FLAG_n) TT.do_n |= toys.optflags & FLAG_n; + if (FLAG_G) TT.do_G |= toys.optflags & FLAG_G; if (toys.optc) while(*toys.optargs) do_id(*toys.optargs++); else do_id(NULL); } + +void groups_main(void) +{ + TT.is_groups = 1; + TT.do_G = TT.do_n = 1; + id_main(); +} + +void logname_main(void) +{ + TT.do_u = TT.do_n = 1; + id_main(); +} diff --git a/toys/posix/true.c b/toys/posix/true.c index b22b7ac1..0fbb1786 100644 --- a/toys/posix/true.c +++ b/toys/posix/true.c @@ -5,7 +5,7 @@ * See http://opengroup.org/onlinepubs/9699919799/utilities/true.html USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN)) -USE_TRUE(OLDTOY(:, true, 0, TOYFLAG_NOFORK)) +USE_TRUE(OLDTOY(:, true, TOYFLAG_NOFORK)) config TRUE bool "true" |