sbase

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

commit a5d268c40990ffe064a5b1f5b8a819238c2fb5d7
parent 8d59405ae01449e60e9aeb665de664467ee067fd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  4 Mar 2018 14:06:24 +0100

Move execsh() to use String type

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

diff --git a/ed.c b/ed.c @@ -887,38 +887,37 @@ quit(void) static void execsh(void) { - static char *cmd; - static size_t siz, cap; + static String cmd; char c, *p; int repl = 0; skipblank(); if ((c = input()) != '!') { back(c); - siz = 0; - } else if (cmd) { - --siz; + cmd.siz = 0; + } else if (cmd.siz) { + --cmd.siz; repl = 1; } else { error("no previous command"); } while ((c = input()) != EOF && c != '\n') { - if (c == '%' && (siz == 0 || cmd[siz - 1] != '\\')) { + if (c == '%' && (cmd.siz == 0 || cmd.str[cmd.siz - 1] != '\\')) { if (savfname[0] == '\0') error("no current filename"); repl = 1; for (p = savfname; *p; ++p) - cmd = addchar(*p, cmd, &cap, &siz); + addchar_(*p, &cmd); } else { - cmd = addchar(c, cmd, &cap, &siz); + addchar_(c, &cmd); } } - cmd = addchar('\0', cmd, &cap, &siz); + addchar_('\0', &cmd); if (repl) - puts(cmd); - system(cmd); + puts(cmd.str); + system(cmd.str); if (optdiag) puts("!"); }