summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-09-18 14:55:07 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-09-18 14:55:07 +0300
commite982b94885a2c9136fe37322d8b96346837f9389 (patch)
tree964ff19496e850d5aca8ab33d4520d92d88fd85e
parent26ab51cc70109abd04ac04ff75bb58abb2eb957f (diff)
downloadgawk-e982b94885a2c9136fe37322d8b96346837f9389.tar.gz
Bug fix to FPAT field parsing.
-rw-r--r--ChangeLog7
-rw-r--r--field.c5
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am5
-rw-r--r--test/Makefile.in10
-rw-r--r--test/Maketests5
-rw-r--r--test/fpat5.awk8
-rw-r--r--test/fpat5.in1
-rw-r--r--test/fpat5.ok1
9 files changed, 42 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 209c07f2..2d89bc34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-09-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * field.c (fpat_parse_field): Always use rp->non_empty instead
+ of only if in_middle. The latter can be true even if we've
+ already parsed part of the record. Thanks to Ed Morton
+ for the bug report.
+
2015-09-04 Arnold D. Robbins <arnold@skeeve.com>
* profile.c (pp_num): Use format_val to print integral values
diff --git a/field.c b/field.c
index 6a7c6b1d..ed310984 100644
--- a/field.c
+++ b/field.c
@@ -1598,9 +1598,8 @@ fpat_parse_field(long up_to, /* parse only up to this field number */
if (in_middle) {
regex_flags |= RE_NO_BOL;
- non_empty = rp->non_empty;
- } else
- non_empty = false;
+ }
+ non_empty = rp->non_empty;
eosflag = false;
need_to_set_sep = true;
diff --git a/test/ChangeLog b/test/ChangeLog
index 2de6750f..10bccd5a 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (fpat5): New test.
+ * fpat5.awk, fpat5.in, fpat5.ok: New files.
+
2015-09-04 Arnold D. Robbins <arnold@skeeve.com>
* profile.ok: Updated after code change.
diff --git a/test/Makefile.am b/test/Makefile.am
index 14ebf544..6996b1c7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -290,6 +290,9 @@ EXTRA_DIST = \
fpat3.ok \
fpat4.awk \
fpat4.ok \
+ fpat5.awk \
+ fpat5.in \
+ fpat5.ok \
fpatnull.awk \
fpatnull.in \
fpatnull.ok \
@@ -1058,7 +1061,7 @@ GAWK_EXT_TESTS = \
aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \
backw badargs beginfile1 beginfile2 binmode1 charasbytes \
colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \
- fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \
+ fieldwdth fpat1 fpat2 fpat3 fpat4 fpat5 fpatnull fsfwfs funlen \
functab1 functab2 functab3 fwtest fwtest2 fwtest3 \
genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \
icasefs icasers id igncdym igncfs ignrcas2 ignrcase \
diff --git a/test/Makefile.in b/test/Makefile.in
index a78b3e6a..ba5da05f 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -547,6 +547,9 @@ EXTRA_DIST = \
fpat3.ok \
fpat4.awk \
fpat4.ok \
+ fpat5.awk \
+ fpat5.in \
+ fpat5.ok \
fpatnull.awk \
fpatnull.in \
fpatnull.ok \
@@ -1314,7 +1317,7 @@ GAWK_EXT_TESTS = \
aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \
backw badargs beginfile1 beginfile2 binmode1 charasbytes \
colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \
- fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \
+ fieldwdth fpat1 fpat2 fpat3 fpat4 fpat5 fpatnull fsfwfs funlen \
functab1 functab2 functab3 fwtest fwtest2 fwtest3 \
genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \
icasefs icasers id igncdym igncfs ignrcas2 ignrcase \
@@ -3540,6 +3543,11 @@ fpat4:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+fpat5:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
fpatnull:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 651ff03b..7c55a443 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1017,6 +1017,11 @@ fpat4:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+fpat5:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
fpatnull:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/fpat5.awk b/test/fpat5.awk
new file mode 100644
index 00000000..b508f068
--- /dev/null
+++ b/test/fpat5.awk
@@ -0,0 +1,8 @@
+BEGIN {
+ FPAT = "([^,]*)|(\"[^\"]+\")"
+ OFS = ";"
+}
+
+p != 0 { print NF }
+
+{ $1 = $1 ; print }
diff --git a/test/fpat5.in b/test/fpat5.in
new file mode 100644
index 00000000..15d874ef
--- /dev/null
+++ b/test/fpat5.in
@@ -0,0 +1 @@
+"A","B","C"
diff --git a/test/fpat5.ok b/test/fpat5.ok
new file mode 100644
index 00000000..cc9295ce
--- /dev/null
+++ b/test/fpat5.ok
@@ -0,0 +1 @@
+"A";"B";"C"