commit 16de770359370224129f23df745178efe518c02c Author: Arnold D. Robbins Date: Thu Jul 28 22:12:48 2011 +0300 Revert sub/gsub behavior to that of gawk 3.x. diff --git a/builtin.c b/builtin.c index 8685d29..4d87592 100644 --- a/builtin.c +++ b/builtin.c @@ -2546,13 +2546,30 @@ set_how_many: repllen--; scan++; } - } else { + } else if (do_posix) { /* \& --> &, \\ --> \ */ if (scan[1] == '&' || scan[1] == '\\') { repllen--; scan++; } /* else leave alone, it goes into the output */ + } else { + /* gawk default behavior since 1996 */ + if (strncmp(scan, "\\\\\\&", 4) == 0) { + /* \\\& --> \& */ + repllen -= 2; + scan += 3; + } else if (strncmp(scan, "\\\\&", 3) == 0) { + /* \\& --> \ */ + ampersands++; + repllen--; + scan += 2; + } else if (scan[1] == '&') { + /* \& --> & */ + repllen--; + scan++; + } /* else + leave alone, it goes into the output */ } } } @@ -2630,11 +2647,30 @@ set_how_many: scan++; } else /* \q for any q --> q */ *bp++ = *++scan; - } else { + } else if (do_posix) { /* \& --> &, \\ --> \ */ if (scan[1] == '&' || scan[1] == '\\') scan++; *bp++ = *scan; + } else { + /* gawk default behavior since 1996 */ + if (strncmp(scan, "\\\\\\&", 4) == 0) { + /* \\\& --> \& */ + *bp++ = '\\'; + *bp++ = '&'; + scan += 3; + } else if (strncmp(scan, "\\\\&", 3) == 0) { + /* \\& --> \ */ + *bp++ = '\\'; + for (cp = matchstart; cp < matchend; cp++) + *bp++ = *cp; + scan += 2; + } else if (scan[1] == '&') { + /* \& --> & */ + *bp++ = '&'; + scan++; + } else + *bp++ = *scan; } } else *bp++ = *scan; diff --git a/test/Makefile.am b/test/Makefile.am index 82e0834..9780e79 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1376,9 +1376,14 @@ profile3: @sed 1,2d < awkprof.out > _$@; rm awkprof.out @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +posix2008sub: + @echo $@ + @$(AWK) --posix -f $(srcdir)/$@.awk > _$@ 2>&1 + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + next: @echo $@ - @-AWK="$(AWKPROG)" $(srcdir)/$@.sh > _$@ 2>&1 + @-AWK="$(AWKPROG)" $(srcdir)/$@.sh @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ exit: diff --git a/test/backgsub.ok b/test/backgsub.ok index 2d3f17f..e2e265f 100644 --- a/test/backgsub.ok +++ b/test/backgsub.ok @@ -1 +1 @@ -\x\y\z +\\x\\y\\z