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. 643a5a3dad (Initial import)
2. ffee7780fe (Restoring innew)
This commit is contained in:
Miguel Pineiro Jr 2021-04-16 20:31:36 -04:00
parent c0f4e97e45
commit feaf62d159
2 changed files with 19 additions and 0 deletions

1
lib.c
View File

@ -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);

View File

@ -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 }