From 435c438649584eb00de06e07faf6827d4bb6f9fc Mon Sep 17 00:00:00 2001
From: "Arnold D. Robbins" <arnold@skeeve.com>
Date: Sun, 21 Apr 2019 15:01:03 +0300
Subject: [PATCH] Fix bug with ^ in FS.

---
 field.c          |  1 +
 test/Makefile.am |  5 ++++-
 test/Makefile.in | 10 +++++++++-
 test/Maketests   |  5 +++++
 test/fscaret.awk |  8 ++++++++
 test/fscaret.in  |  1 +
 test/fscaret.ok  |  1 +
 7 files changed, 29 insertions(+), 2 deletions(-)
 create mode 100644 test/fscaret.awk
 create mode 100644 test/fscaret.in
 create mode 100644 test/fscaret.ok

diff --git a/field.c b/field.c
index 52963249..f6a3241c 100644
--- a/field.c
+++ b/field.c
@@ -840,6 +840,7 @@ get_field(long requested, Func_ptr *assign)
 		if (! field0_valid) {
 			/* first, parse remainder of input record */
 			if (NF == -1) {
+				in_middle = (parse_high_water != 0);
 				NF = (*parse_field)(UNLIMITED - 1, &parse_extent,
 		    			fields_arr[0]->stlen -
 					(parse_extent - fields_arr[0]->stptr),
diff --git a/test/Makefile.am b/test/Makefile.am
index f5546067..13f53f95 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -350,6 +350,9 @@ EXTRA_DIST = \
 	fsbs.awk \
 	fsbs.in \
 	fsbs.ok \
+	fscaret.awk \
+	fscaret.in \
+	fscaret.ok \
 	fsfwfs.awk \
 	fsfwfs.in \
 	fsfwfs.ok \
@@ -1234,7 +1237,7 @@ BASIC_TESTS = \
 	datanonl defref delargv delarpm2 delarprm delfunc dfamb1 dfastress dynlj \
 	eofsplit exit2 exitval1 exitval2 exitval3 fcall_exit fcall_exit2 \
 	fldchg fldchgnf fldterm fnamedat fnarray fnarray2 fnaryscl fnasgnm fnmisc \
-	fordel forref forsimp fsbs fsnul1 fsrs fsspcoln fstabplus funsemnl \
+	fordel forref forsimp fsbs fscaret fsnul1 fsrs fsspcoln fstabplus funsemnl \
 	funsmnam funstack \
 	getline getline2 getline3 getline4 getline5 getlnbuf getnr2tb getnr2tm \
 	gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 gsubtst6 gsubtst7 \
diff --git a/test/Makefile.in b/test/Makefile.in
index 4133b58a..b23bd8ea 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -608,6 +608,9 @@ EXTRA_DIST = \
 	fsbs.awk \
 	fsbs.in \
 	fsbs.ok \
+	fscaret.awk \
+	fscaret.in \
+	fscaret.ok \
 	fsfwfs.awk \
 	fsfwfs.in \
 	fsfwfs.ok \
@@ -1491,7 +1494,7 @@ BASIC_TESTS = \
 	datanonl defref delargv delarpm2 delarprm delfunc dfamb1 dfastress dynlj \
 	eofsplit exit2 exitval1 exitval2 exitval3 fcall_exit fcall_exit2 \
 	fldchg fldchgnf fldterm fnamedat fnarray fnarray2 fnaryscl fnasgnm fnmisc \
-	fordel forref forsimp fsbs fsnul1 fsrs fsspcoln fstabplus funsemnl \
+	fordel forref forsimp fsbs fscaret fsnul1 fsrs fsspcoln fstabplus funsemnl \
 	funsmnam funstack \
 	getline getline2 getline3 getline4 getline5 getlnbuf getnr2tb getnr2tm \
 	gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 gsubtst6 gsubtst7 \
@@ -3279,6 +3282,11 @@ fsbs:
 	@AWKPATH="$(srcdir)" $(AWK) -f $@.awk  < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
 	@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
 
+fscaret:
+	@echo $@
+	@AWKPATH="$(srcdir)" $(AWK) -f $@.awk  < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+	@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
 fsnul1:
 	@echo $@
 	@AWKPATH="$(srcdir)" $(AWK) -f $@.awk  < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 4a90e3e9..f5840e5f 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -345,6 +345,11 @@ fsbs:
 	@AWKPATH="$(srcdir)" $(AWK) -f $@.awk  < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
 	@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
 
+fscaret:
+	@echo $@
+	@AWKPATH="$(srcdir)" $(AWK) -f $@.awk  < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+	@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
 fsnul1:
 	@echo $@
 	@AWKPATH="$(srcdir)" $(AWK) -f $@.awk  < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/fscaret.awk b/test/fscaret.awk
new file mode 100644
index 00000000..134820d7
--- /dev/null
+++ b/test/fscaret.awk
@@ -0,0 +1,8 @@
+BEGIN {
+	FS="^."
+	OFS="|"
+}
+{
+	$1 = $1
+}
+1
diff --git a/test/fscaret.in b/test/fscaret.in
new file mode 100644
index 00000000..257cc564
--- /dev/null
+++ b/test/fscaret.in
@@ -0,0 +1 @@
+foo
diff --git a/test/fscaret.ok b/test/fscaret.ok
new file mode 100644
index 00000000..38287d58
--- /dev/null
+++ b/test/fscaret.ok
@@ -0,0 +1 @@
+|oo
-- 
2.19.1

