diff options
author | Miguel Pineiro Jr <mpj@pineiro.cc> | 2021-04-16 20:31:36 -0400 |
---|---|---|
committer | Miguel Pineiro Jr <mpj@pineiro.cc> | 2021-04-16 20:31:36 -0400 |
commit | feaf62d159df0f26dfbd18d03ef428ce3ded812d (patch) | |
tree | 72811456da00fca0fb61c9d39fb536b594beb9d7 | |
parent | c0f4e97e4561ff42544e92512bbaf3d7d1f6a671 (diff) | |
download | one-true-awk-feaf62d159df0f26dfbd18d03ef428ce3ded812d.tar.gz |
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)
-rw-r--r-- | lib.c | 1 | ||||
-rwxr-xr-x | testdir/T.misc | 18 |
2 files changed, 19 insertions, 0 deletions
@@ -176,6 +176,7 @@ int getrec(char **pbuf, int *pbufsize, bool isrecord) /* get next input record * 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); diff --git a/testdir/T.misc b/testdir/T.misc index dff57db..77e6dd1 100755 --- a/testdir/T.misc +++ b/testdir/T.misc @@ -195,6 +195,24 @@ aa1a2a 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 } |