sbase

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

commit b089261c3a7bdc6fb1efd84b7f097667d9f1fced
parent 1e10bf6069f472637450f3f1f1933b73dff88a83
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Nov 2023 09:21:13 +0100

ed: Read from input in append()

This enables using a and i commands in a global command
because the input is not anymore taken from stdin.

Diffstat:
Med.c | 30++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/ed.c b/ed.c @@ -692,6 +692,15 @@ getinput(void) } } +static int +moreinput(void) +{ + if (!uflag) + return cmdline.str[inputidx] != '\0'; + + getinput(); + return 1; +} static void dowrite(const char *, int); @@ -876,7 +885,7 @@ dohelp(void) static void chkprint(int flag) { - char c; + int c; if (flag) { if ((c = input()) == 'p' || c == 'l' || c == 'n') @@ -884,7 +893,7 @@ chkprint(int flag) else back(c); } - if (input() != '\0') + if ((c = input()) != '\0' && c != '\n') error("invalid command suffix"); } @@ -919,16 +928,21 @@ getfname(int comm) static void append(int num) { - char *s = NULL; - size_t len = 0; + int ch; + static String line; curln = num; - while (getline(&s, &len, stdin) > 0) { - if (*s == '.' && s[1] == '\n') + while (moreinput()) { + string(&line); + while ((ch = input()) != '\n' && ch != '\0') + addchar(ch, &line); + addchar('\n', &line); + addchar('\0', &line); + + if (!strcmp(line.str, ".\n") || !strcmp(line.str, ".")) break; - inject(s, AFTER); + inject(line.str, AFTER); } - free(s); } static void