# HG changeset patch # User Rob Landley # Date 1427509544 18000 # Node ID fa8f0a5dfc1158672db6fbe00826f4b27344ffa6 # Parent f9bb7e69402db859160560ea4e1347e280074926 tail: add old -123 support and comment out #-f until it's actually implemented. diff -r f9bb7e69402d -r fa8f0a5dfc11 toys/posix/tail.c --- a/toys/posix/tail.c Fri Mar 27 20:50:28 2015 -0500 +++ b/toys/posix/tail.c Fri Mar 27 21:25:44 2015 -0500 @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/tail.html -USE_TAIL(NEWTOY(tail, "fc-n-[-cn]", TOYFLAG_BIN)) +USE_TAIL(NEWTOY(tail, "?fc-n-[-cn]", TOYFLAG_BIN)) config TAIL bool "tail" @@ -17,7 +17,7 @@ -n output the last NUMBER lines (default 10), +X counts from start. -c output the last NUMBER bytes, +NUMBER counts from start - -f follow FILE(s), waiting for more data to be appended + #-f follow FILE(s), waiting for more data to be appended [TODO] config TAIL_SEEK bool "tail seek support" @@ -213,10 +213,22 @@ void tail_main(void) { - // if nothing specified, default -n to -10 - if (!(toys.optflags&(FLAG_n|FLAG_c))) TT.lines = -10; + char **args = toys.optargs; + + if (!(toys.optflags&(FLAG_n|FLAG_c))) { + char *arg = *args; - loopfiles(toys.optargs, do_tail); + // handle old "-42" style arguments + if (arg && *arg == '-' && arg[1]) { + TT.lines = atolx(*(args++)); + toys.optc--; + } + + // if nothing specified, default -n to -10 + TT.lines = -10; + } + + loopfiles(args, do_tail); // do -f stuff }