Hello,
The patch below adds a regress test to check the behaviour of cat when
invoked with the flags '-se' to ensure blank lines contain a dollar sign.
The attached patch reverts the fix from r1.13 on the latest version of
cat which allowed me to perform a comparison test.
This fix was committed to the tree over 14 years ago, I understand if
it's not of interest, I benefited from putting together the test.
Sevan Janiyan
Index: regress/bin/Makefile
===================================================================
RCS file: /cvs/src/regress/bin/Makefile,v
retrieving revision 1.9
diff -u -p -u -r1.9 Makefile
--- regress/bin/Makefile 15 Jun 2015 09:25:22 -0000 1.9
+++ regress/bin/Makefile 23 Jun 2016 02:43:46 -0000
@@ -1,6 +1,6 @@
# $OpenBSD: Makefile,v 1.9 2015/06/15 09:25:22 florian Exp $
-SUBDIR+= chmod ksh ln md5 pax ps systrace test
+SUBDIR+= cat chmod ksh ln md5 pax ps systrace test
install:
Index: regress/bin/cat/Makefile
===================================================================
RCS file: regress/bin/cat/Makefile
diff -N regress/bin/cat/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/bin/cat/Makefile 23 Jun 2016 02:43:46 -0000
@@ -0,0 +1,8 @@
+# $OpenBSD$
+
+REGRESS_TARGETS=cat_se
+
+cat_se:
+ cat -se ${.CURDIR}/cat_se.in | cmp -s ${.CURDIR}/cat_se.out /dev/stdin
+
+.include <bsd.regress.mk>
Index: regress/bin/cat/cat_se.in
===================================================================
RCS file: regress/bin/cat/cat_se.in
diff -N regress/bin/cat/cat_se.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/bin/cat/cat_se.in 23 Jun 2016 02:43:46 -0000
@@ -0,0 +1,3 @@
+
+Free, functional and secure
+
Index: regress/bin/cat/cat_se.out
===================================================================
RCS file: regress/bin/cat/cat_se.out
diff -N regress/bin/cat/cat_se.out
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ regress/bin/cat/cat_se.out 23 Jun 2016 02:43:46 -0000
@@ -0,0 +1,3 @@
+$
+Free, functional and secure$
+$
Index: cat.c
===================================================================
RCS file: /cvs/src/bin/cat/cat.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 cat.c
--- cat.c 4 Nov 2015 21:28:01 -0000 1.24
+++ cat.c 23 Jun 2016 02:35:15 -0000
@@ -145,23 +145,29 @@ cook_buf(FILE *fp)
line = gobble = 0;
for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
if (prev == '\n') {
- if (sflag) {
- if (ch == '\n') {
- if (gobble)
- continue;
+ if (ch == '\n') {
+ if (sflag) {
+ if (!gobble && putchar(ch) == EOF)
+ break;
gobble = 1;
- } else
- gobble = 0;
- }
- if (nflag && (!bflag || ch != '\n')) {
+ continue;
+ }
+ if (nflag && !bflag) {
+ (void)fprintf(stdout, "%6d\t", ++line);
+ if (ferror(stdout))
+ break;
+ }
+ } else if (nflag) {
(void)fprintf(stdout, "%6d\t", ++line);
if (ferror(stdout))
break;
}
}
+ gobble = 0;
if (ch == '\n') {
- if (eflag && putchar('$') == EOF)
- break;
+ if (eflag)
+ if (putchar('$') == EOF)
+ break;
} else if (ch == '\t') {
if (tflag) {
if (putchar('^') == EOF || putchar('I') == EOF)