[hackers] [sbase][PATCH] ed: Allow newlines in a Substitute Command

From: Rene Kita <mail_AT_rkta.de>
Date: Fri, 3 Nov 2023 13:32:37 +0100

The Open Group Base Specifications Issue 7, 2018 edition:
| Substitute Command
|
| Synopsis:
|
| (.,.)s/RE/replacement/flags
[...]
| A line can be split by substituting a <newline> into it. The
| application shall ensure it escapes the <newline> in the replacement
| by preceding it by <backslash>.
---
 ed.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ed.c b/ed.c
index b430e74..e2b2a6f 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -1049,8 +1049,11 @@ getrhs(int delim)
 	static String s;
 
 	string(&s);
-	while ((c = input()) != '\n' && c != EOF && c != delim)
+	while ((c = input()) != '\n' && c != EOF && c != delim) {
+		if (c == '\\' && (c = input()) != '\n')
+			addchar('\\', &s);
 		addchar(c, &s);
+	}
 	addchar('\0', &s);
 	if (c == EOF)
 		error("invalid pattern delimiter");
-- 
2.43.0.rc0
Received on Fri Nov 03 2023 - 13:32:37 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 03 2023 - 14:12:34 CET