diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2011-08-10 23:00:53 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2011-08-10 23:00:53 +0300 |
commit | ee77c260899fdce1cec5cf51053ccdb107f76d62 (patch) | |
tree | 10d32755f9c6a0e4795d9a8ef2bb16470652ea10 | |
parent | b8c993f5a867f38fa9edd343d7d90b4b36800be2 (diff) | |
download | egawk-ee77c260899fdce1cec5cf51053ccdb107f76d62.tar.gz egawk-ee77c260899fdce1cec5cf51053ccdb107f76d62.tar.bz2 egawk-ee77c260899fdce1cec5cf51053ccdb107f76d62.zip |
Fix bug with FPAT.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | awk.h | 1 | ||||
-rw-r--r-- | field.c | 15 | ||||
-rw-r--r-- | test/ChangeLog | 3 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/Makefile.in | 11 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/fpat3.awk | 10 | ||||
-rw-r--r-- | test/fpat3.in | 1 | ||||
-rw-r--r-- | test/fpat3.ok | 4 |
10 files changed, 54 insertions, 8 deletions
@@ -33,6 +33,12 @@ * field.c (set_FIELDWIDTHS): Adjust calculations. + Fix problem with FPAT, reported by "T. X. G." <leopardie333@yahoo.com> + + * awk.h (Regexp): Add new member 'non_empty'. + * field.c (fpat_parse_field): Save/restore local variable non_empty + from member in Regexp struct. + 2011-08-09 Arnold D. Robbins <arnold@skeeve.com> Fix pty issue reported by "T. X. G." <leopardie333@yahoo.com> @@ -205,6 +205,7 @@ typedef struct Regexp { struct dfa *dfareg; short dfa; short has_anchor; /* speed up of avoid_dfa kludge, temporary */ + short non_empty; /* for use in fpat_parse_field */ } Regexp; #define RESTART(rp,s) (rp)->regs.start[0] #define REEND(rp,s) (rp)->regs.end[0] @@ -849,7 +849,8 @@ get_field(long requested, Func_ptr *assign) if (assign != NULL) field0_valid = FALSE; /* $0 needs reconstruction */ #else - /* keep things uniform. Also, mere intention of assigning something + /* + * Keep things uniform. Also, mere intention of assigning something * to $n should not make $0 invalid. Makes sense to invalidate $0 * after the actual assignment is performed. Not a real issue in * the interpreter otherwise, but causes problem in the @@ -1584,9 +1585,6 @@ fpat_parse_field(long up_to, /* parse only up to this field number */ memset(&mbs, 0, sizeof(mbstate_t)); #endif - if (in_middle) - regex_flags |= RE_NO_BOL; - if (up_to == UNLIMITED) nf = 0; @@ -1596,7 +1594,13 @@ fpat_parse_field(long up_to, /* parse only up to this field number */ if (rp == NULL) /* use FPAT */ rp = FPAT_regexp; - eosflag = non_empty = FALSE; + if (in_middle) { + regex_flags |= RE_NO_BOL; + non_empty = rp->non_empty; + } else + non_empty = FALSE; + + eosflag = FALSE; need_to_set_sep = TRUE; start = scan; while (research(rp, scan, 0, (end - scan), regex_flags) != -1 @@ -1675,5 +1679,6 @@ fpat_parse_field(long up_to, /* parse only up to this field number */ } *buf = scan; + rp->non_empty = non_empty; return nf; } diff --git a/test/ChangeLog b/test/ChangeLog index 334f1961..8c165b04 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,7 +1,8 @@ 2011-08-10 Arnold D. Robbins <arnold@skeeve.com> - * Makefile.am (beginfile2, fwtest3): New tests. + * Makefile.am (beginfile2, fpat3, fwtest3): New tests. * beginfile2.awk, beginfile2.in, beginfile2.ok: New files. + * fpat3.awk, fpat3.in, fpat3.ok: New files. * fwtest3.awk, fwtest3.in, fwtest3.ok: New files. 2011-08-09 Arnold D. Robbins <arnold@skeeve.com> diff --git a/test/Makefile.am b/test/Makefile.am index a7789953..3d259afe 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -234,6 +234,9 @@ EXTRA_DIST = \ fpat1.ok \ fpat2.awk \ fpat2.ok \ + fpat3.awk \ + fpat3.in \ + fpat3.ok \ fpatnull.awk \ fpatnull.in \ fpatnull.ok \ @@ -811,7 +814,8 @@ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 \ binmode1 clos1way delsub devfd devfd1 \ - devfd2 dumpvars exit fieldwdth fpat1 fpat2 fpatnull fsfwfs funlen \ + devfd2 dumpvars exit fieldwdth fpat1 fpat2 fpat3 \ + fpatnull fsfwfs funlen \ fwtest fwtest2 fwtest3 \ gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ icasefs icasers igncdym igncfs ignrcas2 ignrcase indirectcall lint \ diff --git a/test/Makefile.in b/test/Makefile.in index 1f1f5820..3dd318f9 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -419,6 +419,9 @@ EXTRA_DIST = \ fpat1.ok \ fpat2.awk \ fpat2.ok \ + fpat3.awk \ + fpat3.in \ + fpat3.ok \ fpatnull.awk \ fpatnull.in \ fpatnull.ok \ @@ -996,7 +999,8 @@ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 \ binmode1 clos1way delsub devfd devfd1 \ - devfd2 dumpvars exit fieldwdth fpat1 fpat2 fpatnull fsfwfs funlen \ + devfd2 dumpvars exit fieldwdth fpat1 fpat2 fpat3 \ + fpatnull fsfwfs funlen \ fwtest fwtest2 fwtest3 \ gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ icasefs icasers igncdym igncfs ignrcas2 ignrcase indirectcall lint \ @@ -2689,6 +2693,11 @@ fpat2: @AWKPATH=$(srcdir) $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +fpat3: + @echo fpat3 + @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + fpatnull: @echo fpatnull @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index cfbfc79e..c76769f4 100644 --- a/test/Maketests +++ b/test/Maketests @@ -930,6 +930,11 @@ fpat2: @AWKPATH=$(srcdir) $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +fpat3: + @echo fpat3 + @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + fpatnull: @echo fpatnull @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/fpat3.awk b/test/fpat3.awk new file mode 100644 index 00000000..801bb58e --- /dev/null +++ b/test/fpat3.awk @@ -0,0 +1,10 @@ +BEGIN { + FPAT = "[^,]*" + +} + +{ + if (x) NF + for (i = 1; i <= 4; ++i) + print i, $i +} diff --git a/test/fpat3.in b/test/fpat3.in new file mode 100644 index 00000000..28416a42 --- /dev/null +++ b/test/fpat3.in @@ -0,0 +1 @@ +a,b,,c diff --git a/test/fpat3.ok b/test/fpat3.ok new file mode 100644 index 00000000..543bb429 --- /dev/null +++ b/test/fpat3.ok @@ -0,0 +1,4 @@ +1 a +2 b +3 +4 c |