ed

simple ed
git clone git://git.2f30.org/ed.git
Log | Files | Refs

commit ad6ecb08f5018c8d3656c6e2669272724b214658
parent 7cbfcd7c0bb79bae25cc05deddaa1bf4e684ec6f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu Dec 10 20:56:58 +0100

Add support for % in execsh()

Execsh is modeled like is explained in POSIX specification,
even with the non sense of printing the command line
when ! or % are substited.

Diffstat:
ed.c | 34+++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/ed.c b/ed.c @@ -733,17 +733,41 @@ execsh(void) { static char *cmd; static size_t siz, cap; - char c; + char c, *p; + int repl = 0; skipblank(); if ((c = input()) != '!') { + back(c); siz = 0; - while ((c = input()) != EOF && c != '\n') - cmd = addchar(c, cmd, &cap, &siz); - cmd = addchar('\0', cmd, &cap, &siz); - } else if (!cmd) { + } else if (cmd) { + --siz; + repl = 1; + } else { error("no previous command"); } + + while ((c = input()) != EOF && c != '\n') { + if (c == '\\') { + cmd = addchar(*p, cmd, &cap, &siz); + if ((c = input()) == EOF) + break; + cmd = addchar(input(), cmd, &cap, &siz); + } + if (c == '%') { + if (savfname[0] == '\0') + error("no current filename"); + repl = 1; + for (p = savfname; *p; ++p) + cmd = addchar(*p, cmd, &cap, &siz); + continue; + } + cmd = addchar(c, cmd, &cap, &siz); + } + cmd = addchar('\0', cmd, &cap, &siz); + + if (repl) + puts(cmd); system(cmd); puts("!"); }