tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

GNU shellery



Hi

reversing lines currently:
BSDs: tail -r
GNU: tac

Anyone writing portable code: sed '1!G;h;$!d'
(Yes that actually works)

Attached diff adds a hard link tac (need set lists adjusted though, and
I have a man page). it doesn't add any of the GNU tac options.

Cost: a hard link.
Index: Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/tail/Makefile,v
retrieving revision 1.3
diff -u -r1.3 Makefile
--- Makefile	23 Nov 1994 07:41:55 -0000	1.3
+++ Makefile	1 Oct 2017 14:42:34 -0000
@@ -1,7 +1,8 @@
 #	$NetBSD: Makefile,v 1.3 1994/11/23 07:41:55 jtc Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-
 PROG=	tail
 SRCS=	forward.c misc.c read.c reverse.c tail.c
 
+LINKS=	${BINDIR}/tail ${BINDIR}/tac
+
 .include <bsd.prog.mk>
Index: tail.c
===================================================================
RCS file: /cvsroot/src/usr.bin/tail/tail.c,v
retrieving revision 1.17
diff -u -r1.17 tail.c
--- tail.c	31 Jan 2013 23:09:06 -0000	1.17
+++ tail.c	1 Oct 2017 14:42:34 -0000
@@ -105,30 +105,35 @@
 
 	obsolete(argv);
 	style = NOTSET;
-	while ((ch = getopt(argc, argv, "Fb:c:fn:r")) != -1)
-		switch(ch) {
-		case 'F':
-			fflag = 2;
-			break;
-		case 'b':
-			ARG(512, FBYTES, RBYTES);
-			break;
-		case 'c':
-			ARG(1, FBYTES, RBYTES);
-			break;
-		case 'f':
-			fflag = 1;
-			break;
-		case 'n':
-			ARG(1, FLINES, RLINES);
-			break;
-		case 'r':
-			rflag = 1;
-			break;
-		case '?':
-		default:
-			usage();
-		}
+	if (strcmp(getprogname(), "tail") == 0) {
+		while ((ch = getopt(argc, argv, "Fb:c:fn:r")) != -1)
+			switch(ch) {
+			case 'F':
+				fflag = 2;
+				break;
+			case 'b':
+				ARG(512, FBYTES, RBYTES);
+				break;
+			case 'c':
+				ARG(1, FBYTES, RBYTES);
+				break;
+			case 'f':
+				fflag = 1;
+				break;
+			case 'n':
+				ARG(1, FLINES, RLINES);
+				break;
+			case 'r':
+				rflag = 1;
+				break;
+			case '?':
+			default:
+				usage();
+			}
+	} else { /* tac */
+		rflag = 1;
+	}
+
 	argc -= optind;
 	argv += optind;
 


Home | Main Index | Thread Index | Old Index