changeset 1759:fa8f0a5dfc11

tail: add old -123 support and comment out #-f until it's actually implemented.
author Rob Landley <rob@landley.net>
date Fri, 27 Mar 2015 21:25:44 -0500
parents f9bb7e69402d
children c21fe4bc2249
files toys/posix/tail.c
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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;
 
-  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
 }