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/id.c | |
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/id.c')
-rw-r--r-- | toys/posix/id.c | 30 |
1 files changed, 19 insertions, 11 deletions
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(); +} |