-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintTree.c
68 lines (64 loc) · 1.61 KB
/
printTree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "tree.h"
void make_shift(int n){
while(n--)
putc(' ', stderr);
}
void print_argv(char **p, int shift){
char **q=p;
if(p!=NULL){
while(*p!=NULL){
make_shift(shift);
fprintf(stderr, "argv[%d]=%s\n",(int) (p-q), *p);
p++;
}
}
}
void print_tree(tree t, int shift){
char **p;
if(t==NULL)
return;
p=t->argv;
if(p!=NULL)
print_argv(p, shift);
else{
make_shift(shift);
fprintf(stderr, "psubshell\n");
}
make_shift(shift);
if(t->infile==NULL)
fprintf(stderr, "infile=NULL\n");
else
fprintf(stderr, "infile=%s\n", t->infile);
make_shift(shift);
if(t->outfile==NULL)
fprintf(stderr, "outfile=NULL\n");
else
fprintf(stderr, "outfile=%s\n", t->outfile);
make_shift(shift);
fprintf(stderr, "append=%d\n", t->append);
make_shift(shift);
fprintf(stderr, "background=%d\n", t->backgrnd);
make_shift(shift);
fprintf(stderr, "type=%s\n", t->type==NXT?"NXT": t->type==OR?"OR": "AND" );
make_shift(shift);
if(t->psubcmd==NULL)
fprintf(stderr, "psubcmd=NULL \n");
else{
fprintf(stderr, "psubcmd---> \n");
print_tree(t->psubcmd, shift+5);
}
make_shift(shift);
if(t->pipe==NULL)
fprintf(stderr, "pipe=NULL \n");
else{
fprintf(stderr, "pipe---> \n");
print_tree(t->pipe, shift+5);
}
make_shift(shift);
if(t->next==NULL)
fprintf(stderr, "next=NULL \n");
else{
fprintf(stderr, "next---> \n");
print_tree(t->next, shift+5);
}
}