summaryrefslogtreecommitdiff
path: root/textproc/nbsed/files
diff options
context:
space:
mode:
authorminskim <minskim>2004-06-12 05:18:23 +0000
committerminskim <minskim>2004-06-12 05:18:23 +0000
commita29e4152fa36bccca5269455f52a2b1978ddf926 (patch)
treef3db490ae94a19221ac8dc60f465da5565973522 /textproc/nbsed/files
parent584b89bcaad10629c45b31371b74d0b02c2157f1 (diff)
downloadpkgsrc-a29e4152fa36bccca5269455f52a2b1978ddf926.tar.gz
Sync nbsed with -current and bump its version to 20040612. This fixes
a bug reported in PR bin/25899 that makes sed(1) fail if the last character of the line buffer is a backslash.
Diffstat (limited to 'textproc/nbsed/files')
-rw-r--r--textproc/nbsed/files/compile.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/textproc/nbsed/files/compile.c b/textproc/nbsed/files/compile.c
index aa9bb118cfe..f572c4b49cf 100644
--- a/textproc/nbsed/files/compile.c
+++ b/textproc/nbsed/files/compile.c
@@ -1,4 +1,4 @@
-/* $NetBSD: compile.c,v 1.1.1.1 2003/08/18 17:34:55 agc Exp $ */
+/* $NetBSD: compile.c,v 1.2 2004/06/12 05:18:31 minskim Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -47,7 +47,7 @@
#if 0
static char sccsid[] = "@(#)compile.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: compile.c,v 1.1.1.1 2003/08/18 17:34:55 agc Exp $");
+__RCSID("$NetBSD: compile.c,v 1.2 2004/06/12 05:18:31 minskim Exp $");
#endif
#endif /* not lint */
@@ -466,6 +466,7 @@ compile_subst(char *p, struct s_subst *s)
static char lbuf[_POSIX2_LINE_MAX + 1];
int asize, ref, size;
char c, *text, *op, *sp;
+ int sawesc = 0;
c = *p++; /* Terminator character */
if (c == '\0')
@@ -479,9 +480,29 @@ compile_subst(char *p, struct s_subst *s)
do {
op = sp = text + size;
for (; *p; p++) {
- if (*p == '\\') {
- p++;
- if (strchr("123456789", *p) != NULL) {
+ if (*p == '\\' || sawesc) {
+ /*
+ * If this is a continuation from the last
+ * buffer, we won't have a character to
+ * skip over.
+ */
+ if (sawesc)
+ sawesc = 0;
+ else
+ p++;
+
+ if (*p == '\0') {
+ /*
+ * This escaped character is continued
+ * in the next part of the line. Note
+ * this fact, then cause the loop to
+ * exit w/ normal EOL case and reenter
+ * above with the new buffer.
+ */
+ sawesc = 1;
+ p--;
+ continue;
+ } else if (strchr("123456789", *p) != NULL) {
*sp++ = '\\';
ref = *p - '0';
if (s->re != NULL &&