97 |
#else |
#else |
98 |
STATIC void evalcommand(union node *, int); |
STATIC void evalcommand(union node *, int); |
99 |
#endif |
#endif |
100 |
STATIC int evalbltin(const struct builtincmd *, int, char **); |
STATIC int evalbltin(const struct builtincmd *, int, char **, int); |
101 |
STATIC int evalfun(struct funcnode *, int, char **, int); |
STATIC int evalfun(struct funcnode *, int, char **, int); |
102 |
STATIC void prehash(union node *); |
STATIC void prehash(union node *); |
103 |
STATIC int eprintlist(struct output *, struct strlist *, int); |
STATIC int eprintlist(struct output *, struct strlist *, int); |
129 |
* The eval commmand. |
* The eval commmand. |
130 |
*/ |
*/ |
131 |
|
|
132 |
int |
static int evalcmd(int argc, char **argv, int flags) |
|
evalcmd(int argc, char **argv) |
|
133 |
{ |
{ |
134 |
char *p; |
char *p; |
135 |
char *concat; |
char *concat; |
149 |
STPUTC('\0', concat); |
STPUTC('\0', concat); |
150 |
p = grabstackstr(concat); |
p = grabstackstr(concat); |
151 |
} |
} |
152 |
return evalstring(p, ~SKIPEVAL); |
return evalstring(p, flags & EV_TESTED); |
153 |
} |
} |
154 |
return 0; |
return 0; |
155 |
} |
} |
160 |
*/ |
*/ |
161 |
|
|
162 |
int |
int |
163 |
evalstring(char *s, int mask) |
evalstring(char *s, int flags) |
164 |
{ |
{ |
165 |
union node *n; |
union node *n; |
166 |
struct stackmark smark; |
struct stackmark smark; |
171 |
|
|
172 |
status = 0; |
status = 0; |
173 |
while ((n = parsecmd(0)) != NEOF) { |
while ((n = parsecmd(0)) != NEOF) { |
174 |
evaltree(n, 0); |
evaltree(n, flags); |
175 |
status = exitstatus; |
status = exitstatus; |
176 |
popstackmark(&smark); |
popstackmark(&smark); |
177 |
if (evalskip) |
if (evalskip) |
179 |
} |
} |
180 |
popfile(); |
popfile(); |
181 |
|
|
|
evalskip &= mask; |
|
182 |
return status; |
return status; |
183 |
} |
} |
184 |
|
|
309 |
break; |
break; |
310 |
} |
} |
311 |
out: |
out: |
312 |
if ((checkexit & exitstatus)) |
if ((checkexit & exitstatus) || |
313 |
evalskip |= SKIPEVAL; |
(pendingsigs && dotrap()) || |
314 |
else if (pendingsigs && dotrap()) |
(flags & EV_EXIT)) |
|
goto exexit; |
|
|
|
|
|
if (flags & EV_EXIT) { |
|
|
exexit: |
|
315 |
exraise(EXEXIT); |
exraise(EXEXIT); |
|
} |
|
316 |
} |
} |
317 |
|
|
318 |
|
|
319 |
#if !defined(__alpha__) || (defined(__GNUC__) && __GNUC__ >= 3) |
#if !defined(__alpha__) || (defined(__GNUC__) && __GNUC__ >= 3) |
320 |
STATIC |
STATIC |
321 |
#endif |
#endif |
322 |
void evaltreenr(union node *, int) __attribute__ ((alias("evaltree"))); |
void evaltreenr(union node *n, int flags) |
323 |
|
#ifdef HAVE_ATTRIBUTE_ALIAS |
324 |
|
__attribute__ ((alias("evaltree"))); |
325 |
|
#else |
326 |
|
{ |
327 |
|
evaltree(n, flags); |
328 |
|
abort(); |
329 |
|
} |
330 |
|
#endif |
331 |
|
|
332 |
|
|
333 |
STATIC void |
STATIC void |
378 |
setstackmark(&smark); |
setstackmark(&smark); |
379 |
arglist.lastp = &arglist.list; |
arglist.lastp = &arglist.list; |
380 |
for (argp = n->nfor.args ; argp ; argp = argp->narg.next) { |
for (argp = n->nfor.args ; argp ; argp = argp->narg.next) { |
381 |
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE | EXP_RECORD); |
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); |
382 |
/* XXX */ |
/* XXX */ |
383 |
if (evalskip) |
if (evalskip) |
384 |
goto out; |
goto out; |
578 |
void |
void |
579 |
evalbackcmd(union node *n, struct backcmd *result) |
evalbackcmd(union node *n, struct backcmd *result) |
580 |
{ |
{ |
|
int saveherefd; |
|
|
|
|
581 |
result->fd = -1; |
result->fd = -1; |
582 |
result->buf = NULL; |
result->buf = NULL; |
583 |
result->nleft = 0; |
result->nleft = 0; |
586 |
goto out; |
goto out; |
587 |
} |
} |
588 |
|
|
|
saveherefd = herefd; |
|
|
herefd = -1; |
|
|
|
|
589 |
#ifdef notyet |
#ifdef notyet |
590 |
/* |
/* |
591 |
* For now we disable executing builtins in the same |
* For now we disable executing builtins in the same |
632 |
result->fd = pip[0]; |
result->fd = pip[0]; |
633 |
result->jp = jp; |
result->jp = jp; |
634 |
} |
} |
|
herefd = saveherefd; |
|
635 |
out: |
out: |
636 |
TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n", |
TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n", |
637 |
result->fd, result->buf, result->nleft, result->jp)); |
result->fd, result->buf, result->nleft, result->jp)); |
722 |
argc++; |
argc++; |
723 |
} |
} |
724 |
|
|
725 |
argv = nargv = stalloc(sizeof (char *) * (argc + 1)); |
/* Reserve one extra spot at the front for shellexec. */ |
726 |
|
nargv = stalloc(sizeof (char *) * (argc + 2)); |
727 |
|
argv = ++nargv; |
728 |
for (sp = arglist.list ; sp ; sp = sp->next) { |
for (sp = arglist.list ; sp ; sp = sp->next) { |
729 |
TRACE(("evalcommand arg: %s\n", sp->text)); |
TRACE(("evalcommand arg: %s\n", sp->text)); |
730 |
*nargv++ = sp->text; |
*nargv++ = sp->text; |
854 |
} |
} |
855 |
listsetvar(list, i); |
listsetvar(list, i); |
856 |
} |
} |
857 |
if (evalbltin(cmdentry.u.cmd, argc, argv)) { |
if (evalbltin(cmdentry.u.cmd, argc, argv, flags)) { |
858 |
int status; |
int status; |
859 |
int i, j; |
int i; |
860 |
|
|
861 |
i = exception; |
i = exception; |
862 |
if (i == EXEXIT) |
if (i == EXEXIT) |
863 |
goto raise; |
goto raise; |
864 |
|
|
865 |
status = 2; |
status = (i == EXINT) ? SIGINT + 128 : 2; |
|
j = 0; |
|
|
if (i == EXINT) |
|
|
j = SIGINT; |
|
|
if (i == EXSIG) |
|
|
j = pendingsigs; |
|
|
if (j) |
|
|
status = j + 128; |
|
866 |
exitstatus = status; |
exitstatus = status; |
867 |
|
|
868 |
if (i == EXINT || spclbltin > 0) { |
if (i == EXINT || spclbltin > 0) { |
892 |
} |
} |
893 |
|
|
894 |
STATIC int |
STATIC int |
895 |
evalbltin(const struct builtincmd *cmd, int argc, char **argv) { |
evalbltin(const struct builtincmd *cmd, int argc, char **argv, int flags) |
896 |
|
{ |
897 |
char *volatile savecmdname; |
char *volatile savecmdname; |
898 |
struct jmploc *volatile savehandler; |
struct jmploc *volatile savehandler; |
899 |
struct jmploc jmploc; |
struct jmploc jmploc; |
900 |
|
int status; |
901 |
int i; |
int i; |
902 |
|
|
903 |
savecmdname = commandname; |
savecmdname = commandname; |
908 |
commandname = argv[0]; |
commandname = argv[0]; |
909 |
argptr = argv + 1; |
argptr = argv + 1; |
910 |
optptr = NULL; /* initialize nextopt */ |
optptr = NULL; /* initialize nextopt */ |
911 |
exitstatus = (*cmd->builtin)(argc, argv); |
if (cmd == EVALCMD) |
912 |
|
status = evalcmd(argc, argv, flags); |
913 |
|
else |
914 |
|
status = (*cmd->builtin)(argc, argv); |
915 |
flushall(); |
flushall(); |
916 |
|
status |= outerr(out1); |
917 |
|
exitstatus = status; |
918 |
cmddone: |
cmddone: |
|
exitstatus |= outerr(out1); |
|
919 |
freestdout(); |
freestdout(); |
920 |
commandname = savecmdname; |
commandname = savecmdname; |
|
exsig = 0; |
|
921 |
handler = savehandler; |
handler = savehandler; |
922 |
|
|
923 |
return i; |
return i; |
1022 |
int n = argc > 1 ? number(argv[1]) : 1; |
int n = argc > 1 ? number(argv[1]) : 1; |
1023 |
|
|
1024 |
if (n <= 0) |
if (n <= 0) |
1025 |
sh_error(illnum, argv[1]); |
badnum(argv[1]); |
1026 |
if (n > loopnest) |
if (n > loopnest) |
1027 |
n = loopnest; |
n = loopnest; |
1028 |
if (n > 0) { |
if (n > 0) { |