SHA256
3
0
forked from pool/gawk
gawk/gawk-revert-gsub-gawk3.patch
Dirk Mueller 1754206727 Accepting request 85073 from home:namtrac:bugfix
- Revert sub/gsub behavior to that of gawk 3.x. Upstream commit
  16de770359370224129f23df745178efe518c02c  
  
  This fixes build of virtuoso in KDE:Distro:Factory and possibly many others.
  Please forward to Factory.

OBS-URL: https://build.opensuse.org/request/show/85073
OBS-URL: https://build.opensuse.org/package/show/Base:System/gawk?expand=0&rev=14
2011-09-27 12:34:28 +00:00

102 lines
2.5 KiB
Diff

commit 16de770359370224129f23df745178efe518c02c
Author: Arnold D. Robbins <arnold@skeeve.com>
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) {
+ /* \\& --> \<string> */
+ 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) {
+ /* \\& --> \<string> */
+ *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