commit 60d9f7a5a9f0b55660915b06fdc73db6811a9f9d
parent c11a21f426d661f4c20a19c4769f7de42668435d
Author: Santtu Lakkala <inz@inz.fi>
Date: Tue, 16 Dec 2025 17:59:21 +0200
ed: Fix multiline commands
Fix command line parsing escape handling. Further process all
commands on the command line.
Diffstat:
3 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/TODO b/TODO
@@ -28,11 +28,6 @@ Bugs
ed
--
-* cat <<EOF | ed
- i
- LLL
- .
- s/$/\\
* Editing huge files doesn't work well.
diff --git 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
@@ -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