aboutsummaryrefslogtreecommitdiff
path: root/run.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2020-01-19 20:37:33 +0200
committerArnold D. Robbins <arnold@skeeve.com>2020-01-19 20:37:33 +0200
commitde6284e0377e1c10f6249586df1a67311e9c5b2f (patch)
treec1250ac5c844611d0720188dda84b38a65685e24 /run.c
parentdf6ccd29820f4e51d15eff6dab3c62014e877550 (diff)
downloadone-true-awk-de6284e0377e1c10f6249586df1a67311e9c5b2f.tar.gz
Fix Issue 60; sub/gsub follow POSIX if POSIXLY_CORRECT in the environment.
Diffstat (limited to 'run.c')
-rw-r--r--run.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/run.c b/run.c
index 136e20a..2bef988 100644
--- a/run.c
+++ b/run.c
@@ -1983,6 +1983,13 @@ void backsub(char **pb_ptr, const char **sptr_ptr) /* handle \\& variations */
{ /* sptr[0] == '\\' */
char *pb = *pb_ptr;
const char *sptr = *sptr_ptr;
+ static bool first = true;
+ static bool do_posix = false;
+
+ if (first) {
+ first = false;
+ do_posix = (getenv("POSIXLY_CORRECT") != NULL);
+ }
if (sptr[1] == '\\') {
if (sptr[2] == '\\' && sptr[3] == '&') { /* \\\& -> \& */
@@ -1992,6 +1999,9 @@ void backsub(char **pb_ptr, const char **sptr_ptr) /* handle \\& variations */
} else if (sptr[2] == '&') { /* \\& -> \ + matched */
*pb++ = '\\';
sptr += 2;
+ } else if (do_posix) { /* \\x -> \x */
+ sptr++;
+ *pb++ = *sptr++;
} else { /* \\x -> \\x */
*pb++ = *sptr++;
*pb++ = *sptr++;