aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2011-07-28 22:12:48 +0300
committerArnold D. Robbins <arnold@skeeve.com>2011-07-28 22:12:48 +0300
commit16de770359370224129f23df745178efe518c02c (patch)
tree478fec9f11a3db6bc760ff82ce66230edc7d273c /builtin.c
parent75649aeb8a920d7b7b8c9a4197bbe1255981f66b (diff)
downloadegawk-16de770359370224129f23df745178efe518c02c.tar.gz
egawk-16de770359370224129f23df745178efe518c02c.tar.bz2
egawk-16de770359370224129f23df745178efe518c02c.zip
Revert sub/gsub behavior to that of gawk 3.x.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/builtin.c b/builtin.c
index 8685d290..4d87592e 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;