changeset 1612:eec3b88f2d58 draft

Make sed a\ line continuations work properly for different pattern input modes.
author Rob Landley <rob@landley.net>
date Sun, 14 Dec 2014 13:51:28 -0600
parents 50dc30893f9d
children 96aa7ec74936
files tests/sed.test toys/pending/sed.c
diffstat 2 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tests/sed.test	Sat Dec 13 18:35:11 2014 -0600
+++ b/tests/sed.test	Sun Dec 14 13:51:28 2014 -0600
@@ -119,6 +119,17 @@
 	"sed -e '/one/,/three/{' -e 'i meep' -e'N;2D;}'" \
 	"meep\nmeep\ntwo\nthree\n" "" "one\ntwo\nthree\n"
 
+# Different ways of parsing line continuations
+
+testing "" "sed -e '1a\' -e 'huh'" "meep\nhuh\n" "" "meep"
+testing "" "sed -f input" "blah\nboom\n" '1a\\\nboom' 'blah'
+testing "" "sed '1a\
+hello'" "merp\nhello\n" "" "merp"
+#echo meep | sed/sed -e '1a\' -e 'huh'
+#echo blah | sed/sed -f <(echo -e "1a\\\\\nboom")
+#echo merp | sed/sed "1a\\
+#hello"
+
 # -i with $ last line test
 
 exit $FAILCOUNT
--- a/toys/pending/sed.c	Sat Dec 13 18:35:11 2014 -0600
+++ b/toys/pending/sed.c	Sun Dec 14 13:51:28 2014 -0600
@@ -913,10 +913,15 @@
       reg = extend_string((void *)&corwin, line, reg - (char *)corwin, end); 
       line += end;
 
-      // Line continuation?
-      if (class && reg[-1] == '\\') {
-        reg[-1] = 0;
-        corwin->hit++;
+      // Line continuation? (Two slightly different input methods, -e with
+      // embedded newline vs -f line by line. Must parse both correctly.)
+      if (class && line[-1] == '\\') {
+        reg[-2] = 0;
+        if (*line && line[1]) {
+          reg -= 2;
+          line++;
+          goto append;
+        } else corwin->hit++;
       }
 
     // Commands that take no arguments