shithub: trueawk

Download patch

ref: feaf62d159df0f26dfbd18d03ef428ce3ded812d
parent: c0f4e97e4561ff42544e92512bbaf3d7d1f6a671
author: Miguel Pineiro Jr <mpj@pineiro.cc>
date: Fri Apr 16 16:31:36 EDT 2021

Fix regular expression RS ^-anchoring

RS ^-anchoring needs to know if it's reading the first record of a file.
Unfortunately, innew, the flag that the main i/o loop uses to track
this, didn't make it from NetBSD unscathed. This commit restores the
last of the wayward lines.

Without this fix, when reading the first record of an input file named
on the command line, the regular expression machinery will be
misconfigured, precluding a successful match.

Relevant commits:
1. 643a5a3dad633431c6ce8831944c23059a6be309 (Initial import)
2. ffee7780fe08fa77f662a0903477545d9e26334f (Restoring innew)

--- a/lib.c
+++ b/lib.c
@@ -176,6 +176,7 @@
 				infile = stdin;
 			else if ((infile = fopen(file, "r")) == NULL)
 				FATAL("can't open file %s", file);
+			innew = true;
 			setfval(fnrloc, 0.0);
 		}
 		c = readrec(&buf, &bufsize, infile, innew);
--- a/testdir/T.misc
+++ b/testdir/T.misc
@@ -195,6 +195,24 @@
 EOF
 diff foo1 foo2 || echo 'BAD: T.misc ^regex reapplied fails'
 
+# ^-anchored RS matching should be active at the start of each input file
+tee foo1 foo2 >foo3 << \EOF
+aaa
+EOF
+$awk 1 RS='^a' foo1 foo2 foo3 >foo4
+cat << \EOF > foo5
+
+aa
+
+
+aa
+
+
+aa
+
+EOF
+diff foo4 foo5 || echo 'BAD: T.misc ^RS matches the start of every input file fails'
+
 # The following should not produce a warning about changing a constant
 # nor about a curdled tempcell list
 $awk 'function f(x) { x = 2 }
--