tech-userlevel archive

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

Fix for '$' not being printed for blank lines when invoked with -se



Hello,
Obtained from OpenBSD r1.13 of src/bin/cat/cat.c.

When 'cat -se' is used, a '$' is not printed for blank lines, attached
diff fixes that.

Ok to commit?


Sevan
Index: cat.c
===================================================================
RCS file: /cvsroot/src/bin/cat/cat.c,v
retrieving revision 1.55
diff -u -p -u -r1.55 cat.c
--- cat.c	25 Jul 2015 16:17:01 -0000	1.55
+++ cat.c	3 Jun 2016 01:17:35 -0000
@@ -174,18 +174,16 @@ cook_buf(FILE *fp)
 	line = gobble = 0;
 	for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
 		if (prev == '\n') {
-			if (ch == '\n') {
-				if (sflag) {
-					if (!gobble && nflag && !bflag)
-						(void)fprintf(stdout,
-							"%6d\t\n", ++line);
-					else if (!gobble && putchar(ch) == EOF)
-						break;
+			if (sflag) {
+				if (ch == '\n') {
+					if (gobble)
+						continue;
 					gobble = 1;
-					continue;
+				} else
+					gobble = 0;
 				}
 				if (nflag) {
-					if (!bflag) {
+					if (!bflag || ch != '\n') {
 						(void)fprintf(stdout,
 						    "%6d\t", ++line);
 						if (ferror(stdout))
@@ -197,13 +195,7 @@ cook_buf(FILE *fp)
 							break;
 					}
 				}
-			} else if (nflag) {
-				(void)fprintf(stdout, "%6d\t", ++line);
-				if (ferror(stdout))
-					break;
 			}
-		}
-		gobble = 0;
 		if (ch == '\n') {
 			if (eflag)
 				if (putchar('$') == EOF)


Home | Main Index | Thread Index | Old Index