1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 10:01:11 +02:00

zsh-workers/9792

This commit is contained in:
Tanaka Akira 2000-02-19 19:35:26 +00:00
parent 8e939f069e
commit ac64870850
6 changed files with 72 additions and 50 deletions

View file

@ -351,13 +351,13 @@ execbuiltin(LinkList args, Builtin bn)
/* display execution trace information, if required */ /* display execution trace information, if required */
if (xtr) { if (xtr) {
printprompt4(); printprompt4();
fprintf(stderr, "%s", name); fprintf(xtrerr, "%s", name);
if (xarg) if (xarg)
fprintf(stderr, " %s", xarg); fprintf(xtrerr, " %s", xarg);
while (*oargv) while (*oargv)
fprintf(stderr, " %s", *oargv++); fprintf(xtrerr, " %s", *oargv++);
fputc('\n', stderr); fputc('\n', xtrerr);
fflush(stderr); fflush(xtrerr);
} }
/* call the handler function, and return its return value */ /* call the handler function, and return its return value */
return (*(bn->handlerfunc)) (name, argv, ops, bn->funcid); return (*(bn->handlerfunc)) (name, argv, ops, bn->funcid);

View file

@ -50,12 +50,12 @@ evalcond(Estate state)
switch (ctype) { switch (ctype) {
case COND_NOT: case COND_NOT:
if (tracingcond) if (tracingcond)
fprintf(stderr, " %s", condstr[ctype]); fprintf(xtrerr, " %s", condstr[ctype]);
return !evalcond(state); return !evalcond(state);
case COND_AND: case COND_AND:
if (evalcond(state)) { if (evalcond(state)) {
if (tracingcond) if (tracingcond)
fprintf(stderr, " %s", condstr[ctype]); fprintf(xtrerr, " %s", condstr[ctype]);
return evalcond(state); return evalcond(state);
} else { } else {
state->pc = pcode + (WC_COND_SKIP(code) + 1); state->pc = pcode + (WC_COND_SKIP(code) + 1);
@ -64,7 +64,7 @@ evalcond(Estate state)
case COND_OR: case COND_OR:
if (!evalcond(state)) { if (!evalcond(state)) {
if (tracingcond) if (tracingcond)
fprintf(stderr, " %s", condstr[ctype]); fprintf(xtrerr, " %s", condstr[ctype]);
return evalcond(state); return evalcond(state);
} else { } else {
state->pc = pcode + (WC_COND_SKIP(code) + 1); state->pc = pcode + (WC_COND_SKIP(code) + 1);
@ -136,9 +136,9 @@ evalcond(Estate state)
singsub(&rt); singsub(&rt);
untokenize(rt); untokenize(rt);
} }
fprintf(stderr, " %s %s %s", left, condstr[ctype], rt); fprintf(xtrerr, " %s %s %s", left, condstr[ctype], rt);
} else } else
fprintf(stderr, " -%c %s", ctype, left); fprintf(xtrerr, " -%c %s", ctype, left);
} }
if (ctype >= COND_EQ && ctype <= COND_GE) { if (ctype >= COND_EQ && ctype <= COND_GE) {
@ -410,10 +410,10 @@ tracemodcond(char *name, char **args, int inf)
for (aptr = args; *aptr; aptr++) for (aptr = args; *aptr; aptr++)
untokenize(*aptr); untokenize(*aptr);
if (inf) { if (inf) {
fprintf(stderr, " %s %s %s", args[0], name, args[1]); fprintf(xtrerr, " %s %s %s", args[0], name, args[1]);
} else { } else {
fprintf(stderr, " %s", name); fprintf(xtrerr, " %s", name);
while (*args) while (*args)
fprintf(stderr, " %s", *args++); fprintf(xtrerr, " %s", *args++);
} }
} }

View file

@ -1195,12 +1195,12 @@ makecline(LinkList list)
for (node = firstnode(list); node; incnode(node)) { for (node = firstnode(list); node; incnode(node)) {
*ptr++ = (char *)getdata(node); *ptr++ = (char *)getdata(node);
zputs(getdata(node), stderr); zputs(getdata(node), xtrerr);
if (nextnode(node)) if (nextnode(node))
fputc(' ', stderr); fputc(' ', xtrerr);
} }
fputc('\n', stderr); fputc('\n', xtrerr);
fflush(stderr); fflush(xtrerr);
} else { } else {
for (node = firstnode(list); node; incnode(node)) for (node = firstnode(list); node; incnode(node))
*ptr++ = (char *)getdata(node); *ptr++ = (char *)getdata(node);
@ -1404,7 +1404,7 @@ addvars(Estate state, Wordcode pc, int export)
name = ecgetstr(state, 1); name = ecgetstr(state, 1);
untokenize(name); untokenize(name);
if (xtr) if (xtr)
fprintf(stderr, "%s=", name); fprintf(xtrerr, "%s=", name);
if ((isstr = (WC_ASSIGN_TYPE(ac) == WC_ASSIGN_SCALAR))) { if ((isstr = (WC_ASSIGN_TYPE(ac) == WC_ASSIGN_SCALAR))) {
vl = newlinklist(); vl = newlinklist();
addlinknode(vl, ecgetstr(state, 1)); addlinknode(vl, ecgetstr(state, 1));
@ -1437,7 +1437,7 @@ addvars(Estate state, Wordcode pc, int export)
val = ztrdup(ugetnode(vl)); val = ztrdup(ugetnode(vl));
} }
if (xtr) if (xtr)
fprintf(stderr, "%s ", val); fprintf(xtrerr, "%s ", val);
if (export && !strchr(name, '[')) { if (export && !strchr(name, '[')) {
if (export < 0 && isset(RESTRICTED) && if (export < 0 && isset(RESTRICTED) &&
(pm = (Param) paramtab->removenode(paramtab, name)) && (pm = (Param) paramtab->removenode(paramtab, name)) &&
@ -1470,10 +1470,10 @@ addvars(Estate state, Wordcode pc, int export)
*ptr = NULL; *ptr = NULL;
if (xtr) { if (xtr) {
fprintf(stderr, "( "); fprintf(xtrerr, "( ");
for (ptr = arr; *ptr; ptr++) for (ptr = arr; *ptr; ptr++)
fprintf(stderr, "%s ", *ptr); fprintf(xtrerr, "%s ", *ptr);
fprintf(stderr, ") "); fprintf(xtrerr, ") ");
} }
setaparam(name, arr); setaparam(name, arr);
if (errflag) { if (errflag) {
@ -1698,8 +1698,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
else else
lastval = cmdoutval; lastval = cmdoutval;
if (isset(XTRACE)) { if (isset(XTRACE)) {
fputc('\n', stderr); fputc('\n', xtrerr);
fflush(stderr); fflush(xtrerr);
} }
return; return;
} }
@ -1935,6 +1935,12 @@ execcmd(Estate state, int input, int output, int how, int last1)
goto err; goto err;
} }
/* Make a copy of stderr for xtrace output before redirecting */
fflush(xtrerr);
if (xtrerr == stderr &&
!(xtrerr = fdopen(movefd(dup(fileno(stderr))), "w")))
xtrerr = stderr;
/* Add pipeline input/output to mnodes */ /* Add pipeline input/output to mnodes */
if (input) if (input)
addfd(forked, save, mfds, 0, input, 0); addfd(forked, save, mfds, 0, input, 0);
@ -2088,7 +2094,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
if (save[i] != -2) if (save[i] != -2)
zclose(save[i]); zclose(save[i]);
return; goto done;
} }
/* /*
* If nullexec is 2, we have variables to add with the redirections * If nullexec is 2, we have variables to add with the redirections
@ -2098,8 +2104,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
addvars(state, varspc, 0); addvars(state, varspc, 0);
lastval = errflag ? errflag : cmdoutval; lastval = errflag ? errflag : cmdoutval;
if (isset(XTRACE)) { if (isset(XTRACE)) {
fputc('\n', stderr); fputc('\n', xtrerr);
fflush(stderr); fflush(xtrerr);
} }
} else if (isset(EXECOPT) && !errflag) { } else if (isset(EXECOPT) && !errflag) {
/* /*
@ -2138,7 +2144,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
restore_params(restorelist, removelist); restore_params(restorelist, removelist);
lastval = 1; lastval = 1;
fixfds(save); fixfds(save);
return; goto done;
} }
} }
@ -2239,6 +2245,14 @@ execcmd(Estate state, int input, int output, int how, int last1)
if (forked) if (forked)
_exit(lastval); _exit(lastval);
fixfds(save); fixfds(save);
done:
if (xtrerr != stderr) {
fil = fileno(xtrerr);
fclose(xtrerr);
zclose(fil);
xtrerr = stderr;
}
} }
/* Arrange to have variables restored. */ /* Arrange to have variables restored. */
@ -2870,13 +2884,13 @@ execcond(Estate state, int do_exec)
state->pc--; state->pc--;
if (isset(XTRACE)) { if (isset(XTRACE)) {
printprompt4(); printprompt4();
fprintf(stderr, "[["); fprintf(xtrerr, "[[");
tracingcond++; tracingcond++;
} }
stat = !evalcond(state); stat = !evalcond(state);
if (isset(XTRACE)) { if (isset(XTRACE)) {
fprintf(stderr, " ]]\n"); fprintf(xtrerr, " ]]\n");
fflush(stderr); fflush(xtrerr);
tracingcond--; tracingcond--;
} }
return stat; return stat;
@ -2893,18 +2907,18 @@ execarith(Estate state, int do_exec)
if (isset(XTRACE)) { if (isset(XTRACE)) {
printprompt4(); printprompt4();
fprintf(stderr, "(("); fprintf(xtrerr, "((");
} }
e = ecgetstr(state, 1); e = ecgetstr(state, 1);
singsub(&e); singsub(&e);
if (isset(XTRACE)) if (isset(XTRACE))
fprintf(stderr, " %s", e); fprintf(xtrerr, " %s", e);
val = mathevali(e); val = mathevali(e);
if (isset(XTRACE)) { if (isset(XTRACE)) {
fprintf(stderr, " ))\n"); fprintf(xtrerr, " ))\n");
fflush(stderr); fflush(xtrerr);
} }
errflag = 0; errflag = 0;
return !val; return !val;
@ -3017,11 +3031,11 @@ execshfunc(Shfunc shf, LinkList args)
if (args) if (args)
for (lptr = firstnode(args); lptr; incnode(lptr)) { for (lptr = firstnode(args); lptr; incnode(lptr)) {
if (lptr != firstnode(args)) if (lptr != firstnode(args))
fputc(' ', stderr); fputc(' ', xtrerr);
fprintf(stderr, "%s", (char *)getdata(lptr)); fprintf(xtrerr, "%s", (char *)getdata(lptr));
} }
fputc('\n', stderr); fputc('\n', xtrerr);
fflush(stderr); fflush(xtrerr);
} }
ocs = cmdstack; ocs = cmdstack;
ocsp = cmdsp; ocsp = cmdsp;

View file

@ -331,6 +331,9 @@ init_io(void)
SHTTY = -1; SHTTY = -1;
} }
/* Send xtrace output to stderr -- see execcmd() */
xtrerr = stderr;
/* Make sure the tty is opened read/write. */ /* Make sure the tty is opened read/write. */
if (isatty(0)) { if (isatty(0)) {
zsfree(ttystrname); zsfree(ttystrname);

View file

@ -66,8 +66,8 @@ execfor(Estate state, int do_exec)
char *str2 = dupstring(str); char *str2 = dupstring(str);
untokenize(str2); untokenize(str2);
printprompt4(); printprompt4();
fprintf(stderr, "%s\n", str2); fprintf(xtrerr, "%s\n", str2);
fflush(stderr); fflush(xtrerr);
} }
if (!errflag) if (!errflag)
matheval(str); matheval(str);
@ -105,8 +105,8 @@ execfor(Estate state, int do_exec)
if (*str) { if (*str) {
if (isset(XTRACE)) { if (isset(XTRACE)) {
printprompt4(); printprompt4();
fprintf(stderr, "%s\n", str); fprintf(xtrerr, "%s\n", str);
fflush(stderr); fflush(xtrerr);
} }
val = mathevali(str); val = mathevali(str);
} else } else
@ -125,8 +125,8 @@ execfor(Estate state, int do_exec)
break; break;
if (isset(XTRACE)) { if (isset(XTRACE)) {
printprompt4(); printprompt4();
fprintf(stderr, "%s=%s\n", name, str); fprintf(xtrerr, "%s=%s\n", name, str);
fflush(stderr); fflush(xtrerr);
} }
setsparam(name, ztrdup(str)); setsparam(name, ztrdup(str));
} }
@ -144,8 +144,8 @@ execfor(Estate state, int do_exec)
str = dupstring(advance); str = dupstring(advance);
if (isset(XTRACE)) { if (isset(XTRACE)) {
printprompt4(); printprompt4();
fprintf(stderr, "%s\n", str); fprintf(xtrerr, "%s\n", str);
fflush(stderr); fflush(xtrerr);
} }
singsub(&str); singsub(&str);
if (!errflag) if (!errflag)
@ -517,8 +517,8 @@ execcase(Estate state, int do_exec)
pat2 = dupstring(pat); pat2 = dupstring(pat);
untokenize(pat2); untokenize(pat2);
printprompt4(); printprompt4();
fprintf(stderr, "case %s (%s)\n", word, pat2); fprintf(xtrerr, "case %s (%s)\n", word, pat2);
fflush(stderr); fflush(xtrerr);
state->pc++; state->pc++;
} else } else
state->pc += 2; state->pc += 2;

View file

@ -790,10 +790,15 @@ checkmailpath(char **s)
/* This prints the XTRACE prompt. */ /* This prints the XTRACE prompt. */
/**/
FILE *xtrerr = 0;
/**/ /**/
void void
printprompt4(void) printprompt4(void)
{ {
if (!xtrerr)
xtrerr = stderr;
if (prompt4) { if (prompt4) {
int l; int l;
char *s = dupstring(prompt4); char *s = dupstring(prompt4);
@ -801,7 +806,7 @@ printprompt4(void)
unmetafy(s, &l); unmetafy(s, &l);
s = unmetafy(promptexpand(metafy(s, l, META_NOALLOC), 0, NULL, NULL), &l); s = unmetafy(promptexpand(metafy(s, l, META_NOALLOC), 0, NULL, NULL), &l);
fprintf(stderr, "%s", s); fprintf(xtrerr, "%s", s);
} }
} }