Commit | Line | Data |
---|---|---|
1a5078b8 BJ |
1 | #include "sh.h" |
2 | ||
3 | execute(t, pf1, pf2) | |
4 | int *t, *pf1, *pf2; | |
5 | { | |
6 | int i, f, pv[2]; | |
7 | register *t1; | |
8 | char *cp1, *cp2; | |
9 | char *scp; | |
10 | ||
11 | if (t == 0) | |
12 | return; | |
13 | switch(t[DTYP]) { | |
14 | case TCOM: | |
15 | i = 100; | |
16 | do | |
17 | if (func(t)) | |
18 | return; | |
19 | while (--i && alias(&t[DCOM])); | |
20 | if (i == 0) { | |
21 | bferr2(t[DCOM], ": Alias loop detected"); | |
22 | return; | |
23 | } | |
24 | case TPAR: | |
25 | t1 = t; | |
26 | f = t1[DFLG]; | |
27 | i = 0; | |
28 | if ((f&FPAR) == 0) | |
29 | i = fork(); | |
30 | if (i == -1) { | |
31 | err("No more processes"); | |
32 | return; | |
33 | } | |
34 | if (i != 0) { | |
35 | if ((f&FPIN) != 0) { | |
36 | close(pf1[0]); | |
37 | close(pf1[1]); | |
38 | } | |
39 | if ((f&FPRS) != 0) { | |
40 | prn(i); | |
41 | prs("\n"); | |
42 | set(pcs, putn(i)); | |
43 | } | |
44 | if ((f&FAND) != 0) | |
45 | return; | |
46 | if ((f&FPOU) == 0) | |
47 | pwait(i); | |
48 | return; | |
49 | } | |
50 | set(prompt,""); | |
51 | unsetv(prompt); | |
52 | if ((cp1 = t1[DLEF]) != 0) { | |
53 | close(0); | |
54 | cp1 = globone(cp1); | |
55 | if (cp1 == 0) | |
56 | exit(1); | |
57 | strip(cp1); | |
58 | if (open(cp1, 0) < 0) { | |
59 | prs(cp1); | |
60 | err(": Cannot open"); | |
61 | exit(1); | |
62 | } | |
63 | } | |
64 | if ((cp2 = t1[DRIT]) != 0) { | |
65 | while (*cp2) | |
66 | *cp2++ =& 0177; | |
67 | strip(cp2); | |
68 | cp2 = t1[DRIT]; | |
69 | close(1); | |
70 | if ((f&FCAT) != 0 && open(cp2, 1) >= 0) | |
71 | seek(1, 0, 2); | |
72 | else if (creat(cp2, 0644) < 0) { | |
73 | prs(t1[DRIT]); | |
74 | err(": Cannot create"); | |
75 | exit(1); | |
76 | } | |
77 | } | |
78 | if ((f&FPIN) != 0) { | |
79 | close(0); | |
80 | dup(pf1[0]); | |
81 | close(pf1[0]); | |
82 | close(pf1[1]); | |
83 | } | |
84 | if ((f&FPOU) != 0) { | |
85 | close(1); | |
86 | dup(pf2[1]); | |
87 | close(pf2[0]); | |
88 | close(pf2[1]); | |
89 | } | |
90 | if (f&FDIAG) { | |
91 | close(2); | |
92 | dup(1); | |
93 | } | |
94 | if ((f&FINT)!=0 && t1[DLEF]==0 && (f&FPIN)==0) { | |
95 | close(0); | |
96 | open("/dev/null", 0); | |
97 | } | |
98 | if ((f&FINT) == 0 && setintr) { | |
99 | signal(INTR, 0); | |
100 | signal(QUIT, 0); | |
101 | } | |
102 | if (t1[DTYP] == TPAR) { | |
103 | if (t1 = t1[DSPR]) | |
104 | t1[DFLG] =| f&FINT; | |
105 | execute(t1); | |
106 | exit(1); | |
107 | } | |
108 | doexec(t1); | |
109 | /* no return */ | |
110 | case TFIL: | |
111 | f = t[DFLG]; | |
112 | pipe(pv); | |
113 | t1 = t[DLEF]; | |
114 | t1[DFLG] =| FPOU | (f&(FPIN|FINT|FPRS|FDIAG)); | |
115 | execute(t1, pf1, pv); | |
116 | t1 = t[DRIT]; | |
117 | t1[DFLG] =| FPIN | (f&(FPOU|FINT|FAND|FPRS)); | |
118 | execute(t1, pv, pf2); | |
119 | return; | |
120 | case TLST: | |
121 | f = t[DFLG]&FINT; | |
122 | if (t1 = t[DLEF]) | |
123 | t1[DFLG] =| f; | |
124 | execute(t1); | |
125 | if (t1 = t[DRIT]) | |
126 | t1[DFLG] =| f; | |
127 | execute(t1); | |
128 | return; | |
129 | } | |
130 | } | |
131 | ||
132 | strip(cp) | |
133 | register char *cp; | |
134 | { | |
135 | ||
136 | while (*cp++ =& 0177) | |
137 | continue; | |
138 | } |