ed

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

commit f3783089b8859be798df289b9cd75b604d8050a8
parent 3a265e90269f21d447251c7f305787f5da071b44
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Dec 2015 17:25:18 +0100

Save the content of full previous command line

This is needed for '&' command, because it can
reference the current line, and the previous
solution based in static variables for
line1 and line2 was wrong.

Diffstat:
Med.c | 33+++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/ed.c b/ed.c @@ -42,6 +42,8 @@ size_t sizetxt, memtxt; int scratch; int pflag, modflag, uflag; size_t csize; +char *cmd; +size_t cmdsiz, cmdcap; static void error(char *msg) @@ -55,18 +57,6 @@ error(char *msg) } static int -input(void) -{ - return getchar(); -} - -static int -back(int c) -{ - return ungetc(c, stdin); -} - -static int nextln(int line) { ++line; @@ -96,6 +86,24 @@ addchar(char c, char *t, size_t *capacity, size_t *size) } static int +input(void) +{ + int c; + + if ((c = getchar()) != EOF) + cmd = addchar(c, cmd, &cmdcap, &cmdsiz); + return c; +} + +static int +back(int c) +{ + ungetc(c, stdin); + --cmdsiz; + return c; +} + +static int makeline(char *s, int *off) { struct hline *lp; @@ -1057,6 +1065,7 @@ main(int argc, char *argv[]) } for (;;) { + cmdsiz = 0; if (optprompt) fputs(prompt, stdout); getlst();