Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Sep 2009 15:17:41 +0000 (UTC)
From:      Diomidis Spinellis <dds@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r197361 - in head: tools/regression/usr.bin/sed tools/regression/usr.bin/sed/regress.multitest.out usr.bin/sed
Message-ID:  <200909201517.n8KFHfbN060399@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dds
Date: Sun Sep 20 15:17:40 2009
New Revision: 197361
URL: http://svn.freebsd.org/changeset/base/197361

Log:
  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"
  
  Pointed by:	Marius Strobl
  Obtained from:	Mac OS X

Added:
  head/tools/regression/usr.bin/sed/regress.multitest.out/8.21   (contents, props changed)
Modified:
  head/tools/regression/usr.bin/sed/multitest.t
  head/usr.bin/sed/compile.c

Modified: head/tools/regression/usr.bin/sed/multitest.t
==============================================================================
--- head/tools/regression/usr.bin/sed/multitest.t	Sun Sep 20 15:04:50 2009	(r197360)
+++ head/tools/regression/usr.bin/sed/multitest.t	Sun Sep 20 15:17:40 2009	(r197361)
@@ -445,6 +445,10 @@ u2/g' lines1
 	# set specification (both with --posix and without).
 	mark '8.19' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X['
 	mark '8.20' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X\[['
+	COMMENT='\ in y command'
+	mark '8.21'
+	echo 'a\b(c' |
+	$SED 'y%ABCDEFGHIJKLMNOPQRSTUVWXYZ, /\\()"%abcdefghijklmnopqrstuvwxyz,------%'
 }
 
 test_error()

Added: head/tools/regression/usr.bin/sed/regress.multitest.out/8.21
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/sed/regress.multitest.out/8.21	Sun Sep 20 15:17:40 2009	(r197361)
@@ -0,0 +1 @@
+a-b-c

Modified: head/usr.bin/sed/compile.c
==============================================================================
--- head/usr.bin/sed/compile.c	Sun Sep 20 15:04:50 2009	(r197360)
+++ head/usr.bin/sed/compile.c	Sun Sep 20 15:17:40 2009	(r197361)
@@ -66,7 +66,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 regex_t	 *compile_re(char *, int);
 static char	 *compile_subst(char *, struct s_subst *);
@@ -320,7 +320,7 @@ nonsel:		/* Now parse the command */
 					linenum, fname);
 			if ((cmd->u.s = calloc(1, sizeof(struct s_subst))) == NULL)
 				err(1, "malloc");
-			p = compile_delimited(p, re);
+			p = compile_delimited(p, re, 0);
 			if (p == NULL)
 				errx(1,
 				"%lu: %s: unterminated substitute pattern", linenum, fname);
@@ -373,7 +373,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;
 
@@ -399,9 +399,12 @@ compile_delimited(char *p, char *d)
 			*d++ = '\n';
 			p += 2;
 			continue;
-		} else if (*p == '\\' && p[1] == '\\')
-			*d++ = *p++;
-		else if (*p == c) {
+		} else if (*p == '\\' && p[1] == '\\') {
+			if (is_tr)
+				p++;
+			else
+				*d++ = *p++;
+		} else if (*p == c) {
 			*d = '\0';
 			return (p + 1);
 		}
@@ -654,11 +657,11 @@ compile_tr(char *p, struct s_tr **py)
 		errx(1,
 	"%lu: %s: transform pattern can not be delimited by newline or backslash",
 			linenum, fname);
-	p = compile_delimited(p, old);
+	p = compile_delimited(p, old, 1);
 	if (p == NULL)
 		errx(1, "%lu: %s: unterminated transform source string",
 				linenum, fname);
-	p = compile_delimited(p - 1, new);
+	p = compile_delimited(p - 1, new, 1);
 	if (p == NULL)
 		errx(1, "%lu: %s: unterminated transform target string",
 				linenum, fname);
@@ -781,7 +784,7 @@ compile_addr(char *p, struct s_addr *a)
 		++p;
 		/* FALLTHROUGH */
 	case '/':				/* Context address */
-		p = compile_delimited(p, re);
+		p = compile_delimited(p, re, 0);
 		if (p == NULL)
 			errx(1, "%lu: %s: unterminated regular expression", linenum, fname);
 		/* Check for case insensitive regexp flag */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909201517.n8KFHfbN060399>