summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2010-07-01 17:04:25 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2010-07-01 17:04:25 +0000
commit182e947e13afa8bdf48abca878046f822e1d324d (patch)
tree206c652ba58933ad90ad0e72b6235e23499e30b0
parent3269b215277e7b004ef6c5cb1b64da4552cc625c (diff)
Follow POSIX (IEEE Std 1003.1, 2004 Edition) in the implementation
of the y (translate) command. "If a backslash character is immediately followed by a backslash character in string1 or string2, the two backslash characters shall be counted as a single literal backslash character" From FreeBSD; ok millert@ halex@
-rw-r--r--regress/usr.bin/sed/sedtest.expected6
-rw-r--r--regress/usr.bin/sed/sedtest.sh6
-rw-r--r--usr.bin/sed/compile.c17
3 files changed, 21 insertions, 8 deletions
diff --git a/regress/usr.bin/sed/sedtest.expected b/regress/usr.bin/sed/sedtest.expected
index 38a934093ff..48f9c63d592 100644
--- a/regress/usr.bin/sed/sedtest.expected
+++ b/regress/usr.bin/sed/sedtest.expected
@@ -4561,3 +4561,9 @@ X[_11
X[_12
X[_13
X[_14
+\ in y command
+
+=============
+Test 8.20:189
+=============
+a-b-c
diff --git a/regress/usr.bin/sed/sedtest.sh b/regress/usr.bin/sed/sedtest.sh
index f350dd736f0..56e68b23450 100644
--- a/regress/usr.bin/sed/sedtest.sh
+++ b/regress/usr.bin/sed/sedtest.sh
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $OpenBSD: sedtest.sh,v 1.2 2010/07/01 17:02:02 naddy Exp $
+# $OpenBSD: sedtest.sh,v 1.3 2010/07/01 17:04:24 naddy Exp $
#
# Copyright (c) 1992 Diomidis Spinellis.
# Copyright (c) 1992, 1993
@@ -415,6 +415,10 @@ u2/g' lines1
# if it is preceded by a backslash
mark '8.18' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X['
mark '8.19' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X\[['
+ echo '\ in y command'
+ mark '8.20'
+ printf 'a\\b(c' |
+ $SED 'y%ABCDEFGHIJKLMNOPQRSTUVWXYZ, /\\()"%abcdefghijklmnopqrstuvwxyz,------%'
}
test_error()
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index 4b5b33b95db..aa8ee56dca4 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compile.c,v 1.32 2010/07/01 17:02:02 naddy Exp $ */
+/* $OpenBSD: compile.c,v 1.33 2010/07/01 17:04:24 naddy Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -59,7 +59,7 @@ static struct labhash {
static char *compile_addr(char *, struct s_addr *);
static char *compile_ccl(char **, char *);
-static char *compile_delimited(char *, char *);
+static char *compile_delimited(char *, char *, int);
static char *compile_flags(char *, struct s_subst *);
static char *compile_re(char *, regex_t **);
static char *compile_subst(char *, struct s_subst *);
@@ -345,7 +345,7 @@ nonsel: /* Now parse the command */
* with the processed string.
*/
static char *
-compile_delimited(char *p, char *d)
+compile_delimited(char *p, char *d, int is_tr)
{
char c;
@@ -370,7 +370,10 @@ compile_delimited(char *p, char *d)
p += 2;
continue;
} else if (*p == '\\' && p[1] == '\\') {
- *d++ = *p++;
+ if (is_tr)
+ p++;
+ else
+ *d++ = *p++;
} else if (*p == c) {
*d = '\0';
return (p + 1);
@@ -427,7 +430,7 @@ compile_re(char *p, regex_t **repp)
char *re;
re = xmalloc(strlen(p) + 1); /* strlen(re) <= strlen(p) */
- p = compile_delimited(p, re);
+ p = compile_delimited(p, re, 0);
if (p && strlen(re) == 0) {
*repp = NULL;
free(re);
@@ -617,13 +620,13 @@ compile_tr(char *p, char **transtab)
err(COMPILE,
"transform pattern can not be delimited by newline or backslash");
old = xmalloc(strlen(p) + 1);
- p = compile_delimited(p, old);
+ p = compile_delimited(p, old, 1);
if (p == NULL) {
err(COMPILE, "unterminated transform source string");
goto bad;
}
new = xmalloc(strlen(p) + 1);
- p = compile_delimited(--p, new);
+ p = compile_delimited(--p, new, 1);
if (p == NULL) {
err(COMPILE, "unterminated transform target string");
goto bad;