Fix command line parsing escape handling. Further process all commands
on the command line.
---
 ed.c             | 15 +++++++++------
 tests/0025-ed.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 6 deletions(-)
 create mode 100755 tests/0025-ed.sh

diff --git a/ed.c b/ed.c
index 0839232..535fadf 100644
--- a/ed.c
+++ b/ed.c
@@ -679,10 +679,8 @@ getinput(void)
                if (ch == '\\') {
                        if ((ch = getchar()) == EOF)
                                break;
-                       if (ch != '\n') {
-                               ungetc(ch, stdin);
-                               ch = '\\';
-                       }
+                       if (ch != '\n')
+                               addchar('\\', &cmdline);
                }
                addchar(ch, &cmdline);
        }
@@ -1550,7 +1548,7 @@ savecmd(void)
 static void
 doglobal(void)
 {
-       int cnt, ln, k, idx;
+       int cnt, ln, k, idx, c;
 
        skipblank();
        gflag = 1;
@@ -1569,7 +1567,12 @@ doglobal(void)
                        if (!uflag) {
                                idx = inputidx;
                                getlst();
-                               docmd();
+                               for (;;) {
+                                       docmd();
+                                       if (!(c = input()))
+                                               break;
+                                       back(c);
+                               }
                                inputidx = idx;
                                continue;
                        }
diff --git a/tests/0025-ed.sh b/tests/0025-ed.sh
new file mode 100755
index 0000000..9fe02b5
--- /dev/null
+++ b/tests/0025-ed.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+tmp=tmp.$$
+
+trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp; kill -KILL $$' HUP INT TERM
+
+cat <<EOF > $tmp
+LLL\\
+static int xflag = 0;
+static int gflag = 0;
+extern long arflag = 0;
+EOF
+
+ed -s /dev/null <<EOF | diff -u $tmp -
+i
+LLL
+.
+s/$/\\\\
+g/^L/ a\\
+static int xflag = 0;\\
+static int gflag = 0;\\
+static int arflag = 0;
+v! .flag!s/^static/extern/\\
+s# int # long #
+g_^[^a-z]_d
+,p
+Q
+EOF
-- 
2.42.0


Reply via email to