aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-03-27 21:25:44 -0500
committerRob Landley <rob@landley.net>2015-03-27 21:25:44 -0500
commit8d3b3987b8861ea09e2f7f5bd8fcd7b1195e6ae1 (patch)
tree1ec0b27c76dbf7666cbfa39985cf52ba3fa2f1f6
parent9c25bcb645c754f4c09d9d6b8da41bbded862f6c (diff)
downloadtoybox-8d3b3987b8861ea09e2f7f5bd8fcd7b1195e6ae1.tar.gz
tail: add old -123 support and comment out #-f until it's actually implemented.
-rw-r--r--toys/posix/tail.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/toys/posix/tail.c b/toys/posix/tail.c
index e92c0446..41d46338 100644
--- a/toys/posix/tail.c
+++ b/toys/posix/tail.c
@@ -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 @@ config TAIL
-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 @@ static void do_tail(int fd, char *name)
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;
- loopfiles(toys.optargs, do_tail);
+ if (!(toys.optflags&(FLAG_n|FLAG_c))) {
+ char *arg = *args;
+
+ // 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
}