efficient $(<<<foo) and $(<<EOF … ) implementation, requested by izabera

This commit is contained in:
tg
2016-06-26 00:44:59 +00:00
parent 582e745958
commit a41a62dad7
4 changed files with 54 additions and 15 deletions

31
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.188 2016/06/25 23:54:59 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.189 2016/06/26 00:44:57 tg Exp $");
/*
* string expansion
@ -1326,14 +1326,31 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
struct ioword *io = *t->ioact;
char *name;
if ((io->ioflag & IOTYPE) != IOREAD)
switch (io->ioflag & IOTYPE) {
case IOREAD:
shf = shf_open(name = evalstr(io->ioname, DOTILDE),
O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
if (shf == NULL)
warningf(!Flag(FTALKING), "%s: %s %s: %s",
name, "can't open", "$(<...) input",
cstrerror(errno));
break;
case IOHERE:
if (!herein(io, &name)) {
xp->str = name;
/* as $(…) requires, trim trailing newlines */
name += strlen(name);
while (name > xp->str && name[-1] == '\n')
--name;
*name = '\0';
return (XSUB);
}
shf = NULL;
break;
default:
errorf("%s: %s", T_funny_command,
snptreef(NULL, 32, "%R", io));
shf = shf_open(name = evalstr(io->ioname, DOTILDE), O_RDONLY,
0, SHF_MAPHI | SHF_CLEXEC);
if (shf == NULL)
warningf(!Flag(FTALKING), "%s: %s %s: %s", name,
"can't open", "$(<...) input", cstrerror(errno));
}
} else if (fn == FUNSUB) {
int ofd1;
struct temp *tf = NULL;