* Copyright (c) 1991 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)show.c 5.2 (Berkeley) 4/12/91";
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
) {
#endif /* not_this_way */
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
);