summaryrefslogtreecommitdiff
path: root/usr.bin
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 /usr.bin
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@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sed/compile.c17
1 files changed, 10 insertions, 7 deletions
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;