summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/sed/compile.c')
-rw-r--r--usr.bin/sed/compile.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index 53e2af7..cea8e07 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -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;
@@ -387,7 +387,7 @@ compile_delimited(char *p, char *d)
errx(1, "%lu: %s: newline can not be used as a string delimiter",
linenum, fname);
while (*p) {
- if (*p == '[') {
+ if (*p == '[' && *p != c) {
if ((d = compile_ccl(&p, d)) == NULL)
errx(1, "%lu: %s: unbalanced brackets ([])", linenum, fname);
continue;
@@ -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);
}
@@ -429,8 +432,7 @@ compile_ccl(char **sp, char *t)
for (c = *s; (*t = *s) != ']' || c != d; s++, t++)
if ((c = *s) == '\0')
return NULL;
- } else if (*s == '\\' && s[1] == 'n')
- *t = '\n', s++;
+ }
return (*s == ']') ? *sp = ++s, ++t : NULL;
}
@@ -654,11 +656,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 +783,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 */
OpenPOWER on IntegriCloud