Move execsh() to use String type

This commit is contained in:
Roberto E. Vargas Caballero 2018-03-04 14:06:24 +01:00 committed by sin
parent 8d59405ae0
commit a5d268c409

21
ed.c
View File

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