* Copyright (c) 1991 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)show.c 5.1 (Berkeley) %G%";
static shtree(), shcmd(), sharg(), indent();
trputs("showtree called\n");
shtree(n
, 1, NULL
, stdout
);
shtree(n
->nbinary
.ch1
, ind
, NULL
, fp
);
shtree(n
->nbinary
.ch2
, ind
, NULL
, fp
);
for (lp
= n
->npipe
.cmdlist
; lp
; lp
= lp
->next
) {
fprintf(fp
, "<node type %d>", n
->type
);
for (np
= cmd
->ncmd
.args
; np
; np
= np
->narg
.next
) {
for (np
= cmd
->ncmd
.redirect
; np
; np
= np
->nfile
.next
) {
switch (np
->nfile
.type
) {
case NTO
: s
= ">"; dftfd
= 1; break;
case NAPPEND
: s
= ">>"; dftfd
= 1; break;
case NTOFD
: s
= ">&"; dftfd
= 1; break;
case NFROM
: s
= "<"; dftfd
= 0; break;
case NFROMFD
: s
= "<&"; dftfd
= 0; break;
if (np
->nfile
.fd
!= dftfd
)
fprintf(fp
, "%d", np
->nfile
.fd
);
if (np
->nfile
.type
== NTOFD
|| np
->nfile
.type
== NFROMFD
) {
fprintf(fp
, "%d", np
->ndup
.dupfd
);
sharg(np
->nfile
.fname
, fp
);
printf("<node type %d>\n", arg
->type
);
bqlist
= arg
->narg
.backquote
;
for (p
= arg
->narg
.text
; *p
; p
++) {
switch (subtype
& VSTYPE
) {
printf("<subtype %d>", subtype
);
shtree(bqlist
->n
, -1, NULL
, fp
);
for (i
= 0 ; i
< amount
; i
++) {
if (pfx
&& i
== amount
- 1)
trace(fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
)
fprintf(tracefile
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
case '\n': c
= 'n'; goto backslash
;
case '\t': c
= 't'; goto backslash
;
case '\r': c
= 'r'; goto backslash
;
case '"': c
= '"'; goto backslash
;
case '\\': c
= '\\'; goto backslash
;
case CTLESC
: c
= 'e'; goto backslash
;
case CTLVAR
: c
= 'v'; goto backslash
;
case CTLVAR
+CTLQUOTE
: c
= 'V'; goto backslash
;
case CTLBACKQ
: c
= 'q'; goto backslash
;
case CTLBACKQ
+CTLQUOTE
: c
= 'Q'; goto backslash
;
backslash
: putc('\\', tracefile
);
if (*p
>= ' ' && *p
<= '~')
putc(*p
>> 6 & 03, tracefile
);
putc(*p
>> 3 & 07, tracefile
);
putc(*p
& 07, tracefile
);
if ((p
= getenv("HOME")) == NULL
)
if ((tracefile
= fopen(s
, "a")) == NULL
) {
fprintf(stderr
, "Can't open %s\n", s
);
if ((flags
= fcntl(fileno(tracefile
), F_GETFL
, 0)) >= 0)
fcntl(fileno(tracefile
), F_SETFL
, flags
| O_APPEND
);
fputs("\nTracing started.\n", tracefile
);