sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 39b99b6b51c3daabb8fd3ca574fa45721c14b81f
parent 061f4d7af01c4b512e3a9cf5692b90107c78eec6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed Dec 16 19:39:21 +0100

Discard input at the end of global commands

If there is no any match, then the rest of the line
is not read, and it means that ed thins it is a new
command.

Diffstat:
ed.c | 26+++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/ed.c b/ed.c @@ -65,28 +65,35 @@ static struct undo udata; static int newcmd; -static void undo(void); static void -error(char *msg) +discard(void) { int c; + /* discard until end of line */ + if (repidx < 0 && + ((cmdsiz > 0 && cmdline[cmdsiz-1] != '\n') || cmdsiz == 0)) { + while ((c = getchar()) != '\n' && c != EOF) + /* nothing */; + } +} + +static void undo(void); + +static void +error(char *msg) +{ exstatus = 1; lasterr = msg; fputs("?\n", stderr); if (optverbose) fprintf(stderr, "%s\n", msg); - - /* discard until end of line */ - if (repidx < 0 && cmdsiz > 0 && cmdline[cmdsiz-1] != '\n') { - while ((c = getchar()) != '\n' && c != EOF) - /* nothing */; - } - if (!newcmd) undo(); + + discard(); curln = ocurln; longjmp(savesp, 1); } @@ -1293,6 +1300,7 @@ doglobal(void) } docmd(); } + discard(); /* cover the case of not matchingc anything */ } static void