1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-01 21:51:40 +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 */
if (xtr) {
printprompt4();
fprintf(stderr, "%s", name);
fprintf(xtrerr, "%s", name);
if (xarg)
fprintf(stderr, " %s", xarg);
fprintf(xtrerr, " %s", xarg);
while (*oargv)
fprintf(stderr, " %s", *oargv++);
fputc('\n', stderr);
fflush(stderr);
fprintf(xtrerr, " %s", *oargv++);
fputc('\n', xtrerr);
fflush(xtrerr);
}
/* call the handler function, and return its return value */
return (*(bn->handlerfunc)) (name, argv, ops, bn->funcid);

View file

@ -50,12 +50,12 @@ evalcond(Estate state)
switch (ctype) {
case COND_NOT:
if (tracingcond)
fprintf(stderr, " %s", condstr[ctype]);
fprintf(xtrerr, " %s", condstr[ctype]);
return !evalcond(state);
case COND_AND:
if (evalcond(state)) {
if (tracingcond)
fprintf(stderr, " %s", condstr[ctype]);
fprintf(xtrerr, " %s", condstr[ctype]);
return evalcond(state);
} else {
state->pc = pcode + (WC_COND_SKIP(code) + 1);
@ -64,7 +64,7 @@ evalcond(Estate state)
case COND_OR:
if (!evalcond(state)) {
if (tracingcond)
fprintf(stderr, " %s", condstr[ctype]);
fprintf(xtrerr, " %s", condstr[ctype]);
return evalcond(state);
} else {
state->pc = pcode + (WC_COND_SKIP(code) + 1);
@ -136,9 +136,9 @@ evalcond(Estate state)
singsub(&rt);
untokenize(rt);
}
fprintf(stderr, " %s %s %s", left, condstr[ctype], rt);
fprintf(xtrerr, " %s %s %s", left, condstr[ctype], rt);
} else
fprintf(stderr, " -%c %s", ctype, left);
fprintf(xtrerr, " -%c %s", ctype, left);
}
if (ctype >= COND_EQ && ctype <= COND_GE) {
@ -410,10 +410,10 @@ tracemodcond(char *name, char **args, int inf)
for (aptr = args; *aptr; aptr++)
untokenize(*aptr);
if (inf) {
fprintf(stderr, " %s %s %s", args[0], name, args[1]);
fprintf(xtrerr, " %s %s %s", args[0], name, args[1]);
} else {
fprintf(stderr, " %s", name);
fprintf(xtrerr, " %s", name);
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)) {
*ptr++ = (char *)getdata(node);
zputs(getdata(node), stderr);
zputs(getdata(node), xtrerr);
if (nextnode(node))
fputc(' ', stderr);
fputc(' ', xtrerr);
}
fputc('\n', stderr);
fflush(stderr);
fputc('\n', xtrerr);
fflush(xtrerr);
} else {
for (node = firstnode(list); node; incnode(node))
*ptr++ = (char *)getdata(node);
@ -1404,7 +1404,7 @@ addvars(Estate state, Wordcode pc, int export)
name = ecgetstr(state, 1);
untokenize(name);
if (xtr)
fprintf(stderr, "%s=", name);
fprintf(xtrerr, "%s=", name);
if ((isstr = (WC_ASSIGN_TYPE(ac) == WC_ASSIGN_SCALAR))) {
vl = newlinklist();
addlinknode(vl, ecgetstr(state, 1));
@ -1437,7 +1437,7 @@ addvars(Estate state, Wordcode pc, int export)
val = ztrdup(ugetnode(vl));
}
if (xtr)
fprintf(stderr, "%s ", val);
fprintf(xtrerr, "%s ", val);
if (export && !strchr(name, '[')) {
if (export < 0 && isset(RESTRICTED) &&
(pm = (Param) paramtab->removenode(paramtab, name)) &&
@ -1470,10 +1470,10 @@ addvars(Estate state, Wordcode pc, int export)
*ptr = NULL;
if (xtr) {
fprintf(stderr, "( ");
fprintf(xtrerr, "( ");
for (ptr = arr; *ptr; ptr++)
fprintf(stderr, "%s ", *ptr);
fprintf(stderr, ") ");
fprintf(xtrerr, "%s ", *ptr);
fprintf(xtrerr, ") ");
}
setaparam(name, arr);
if (errflag) {
@ -1698,8 +1698,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
else
lastval = cmdoutval;
if (isset(XTRACE)) {
fputc('\n', stderr);
fflush(stderr);
fputc('\n', xtrerr);
fflush(xtrerr);
}
return;
}
@ -1935,6 +1935,12 @@ execcmd(Estate state, int input, int output, int how, int last1)
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 */
if (input)
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++)
if (save[i] != -2)
zclose(save[i]);
return;
goto done;
}
/*
* 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);
lastval = errflag ? errflag : cmdoutval;
if (isset(XTRACE)) {
fputc('\n', stderr);
fflush(stderr);
fputc('\n', xtrerr);
fflush(xtrerr);
}
} else if (isset(EXECOPT) && !errflag) {
/*
@ -2138,7 +2144,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
restore_params(restorelist, removelist);
lastval = 1;
fixfds(save);
return;
goto done;
}
}
@ -2239,6 +2245,14 @@ execcmd(Estate state, int input, int output, int how, int last1)
if (forked)
_exit(lastval);
fixfds(save);
done:
if (xtrerr != stderr) {
fil = fileno(xtrerr);
fclose(xtrerr);
zclose(fil);
xtrerr = stderr;
}
}
/* Arrange to have variables restored. */
@ -2870,13 +2884,13 @@ execcond(Estate state, int do_exec)
state->pc--;
if (isset(XTRACE)) {
printprompt4();
fprintf(stderr, "[[");
fprintf(xtrerr, "[[");
tracingcond++;
}
stat = !evalcond(state);
if (isset(XTRACE)) {
fprintf(stderr, " ]]\n");
fflush(stderr);
fprintf(xtrerr, " ]]\n");
fflush(xtrerr);
tracingcond--;
}
return stat;
@ -2893,18 +2907,18 @@ execarith(Estate state, int do_exec)
if (isset(XTRACE)) {
printprompt4();
fprintf(stderr, "((");
fprintf(xtrerr, "((");
}
e = ecgetstr(state, 1);
singsub(&e);
if (isset(XTRACE))
fprintf(stderr, " %s", e);
fprintf(xtrerr, " %s", e);
val = mathevali(e);
if (isset(XTRACE)) {
fprintf(stderr, " ))\n");
fflush(stderr);
fprintf(xtrerr, " ))\n");
fflush(xtrerr);
}
errflag = 0;
return !val;
@ -3017,11 +3031,11 @@ execshfunc(Shfunc shf, LinkList args)
if (args)
for (lptr = firstnode(args); lptr; incnode(lptr)) {
if (lptr != firstnode(args))
fputc(' ', stderr);
fprintf(stderr, "%s", (char *)getdata(lptr));
fputc(' ', xtrerr);
fprintf(xtrerr, "%s", (char *)getdata(lptr));
}
fputc('\n', stderr);
fflush(stderr);
fputc('\n', xtrerr);
fflush(xtrerr);
}
ocs = cmdstack;
ocsp = cmdsp;

View file

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

View file

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

View file

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