1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1982-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                  David Korn <dgk@research.att.com>                   *
18*4887Schin *                                                                      *
19*4887Schin ***********************************************************************/
20*4887Schin #pragma prototyped
21*4887Schin #ifndef _SHNODES_H
22*4887Schin #define _SHNODES_H	1
23*4887Schin /*
24*4887Schin  *	UNIX shell
25*4887Schin  *	Written by David Korn
26*4887Schin  *
27*4887Schin  */
28*4887Schin 
29*4887Schin 
30*4887Schin #include	<ast.h>
31*4887Schin #include	"argnod.h"
32*4887Schin 
33*4887Schin /* command tree for tretyp */
34*4887Schin #define FINT		(02<<COMBITS)		/* non-interruptable */
35*4887Schin #define FAMP		(04<<COMBITS)		/* background */
36*4887Schin #define FPIN		(010<<COMBITS)		/* input is a pipe */
37*4887Schin #define FPOU		(040<<COMBITS)		/* output is a pipe */
38*4887Schin #define FPCL		(0100<<COMBITS)		/* close the pipe */
39*4887Schin #define FCOOP		(0200<<COMBITS)		/* cooperating process */
40*4887Schin #define FSHOWME		(0400<<COMBITS)		/* set for showme commands  */
41*4887Schin #define FPOSIX		(02<<COMBITS)		/* posix semantics function */
42*4887Schin #define FLINENO		(04<<COMBITS)		/* for/case has line number */
43*4887Schin 
44*4887Schin #define TNEGATE		(01<<COMBITS)		/* ! inside [[...]] */
45*4887Schin #define TBINARY		(02<<COMBITS)		/* binary operator in [[...]] */
46*4887Schin #define TUNARY		(04<<COMBITS)		/* unary operator in [[...]] */
47*4887Schin #define TTEST		(010<<COMBITS)
48*4887Schin #define TPAREN		(TBINARY|TUNARY)
49*4887Schin #define TSHIFT		(COMBITS+4)
50*4887Schin #define TNSPACE		(TFUN|COMSCAN)
51*4887Schin 
52*4887Schin #define TCOM	0
53*4887Schin #define TPAR	1
54*4887Schin #define TFIL	2
55*4887Schin #define TLST	3
56*4887Schin #define TIF	4
57*4887Schin #define TWH	5
58*4887Schin #define TUN	(TWH|COMSCAN)
59*4887Schin #define TTST	6
60*4887Schin #define TSW	7
61*4887Schin #define TAND	8
62*4887Schin #define TORF	9
63*4887Schin #define TFORK	10
64*4887Schin #define TFOR	11
65*4887Schin #define TSELECT	(TFOR|COMSCAN)
66*4887Schin #define TARITH	12
67*4887Schin #define	TTIME	13
68*4887Schin #define TSETIO	14
69*4887Schin #define TFUN	15
70*4887Schin 
71*4887Schin /* this node is a proforma for those that follow */
72*4887Schin 
73*4887Schin struct trenod
74*4887Schin {
75*4887Schin 	int		tretyp;
76*4887Schin 	struct ionod	*treio;
77*4887Schin };
78*4887Schin 
79*4887Schin 
80*4887Schin struct forknod
81*4887Schin {
82*4887Schin 	int		forktyp;
83*4887Schin 	struct ionod	*forkio;
84*4887Schin 	Shnode_t	*forktre;
85*4887Schin 	int		forkline;
86*4887Schin };
87*4887Schin 
88*4887Schin 
89*4887Schin struct ifnod
90*4887Schin {
91*4887Schin 	int		iftyp;
92*4887Schin 	Shnode_t	*iftre;
93*4887Schin 	Shnode_t	*thtre;
94*4887Schin 	Shnode_t	*eltre;
95*4887Schin };
96*4887Schin 
97*4887Schin struct whnod
98*4887Schin {
99*4887Schin 	int		whtyp;
100*4887Schin 	Shnode_t	*whtre;
101*4887Schin 	Shnode_t	*dotre;
102*4887Schin 	struct arithnod	*whinc;
103*4887Schin };
104*4887Schin 
105*4887Schin struct fornod
106*4887Schin {
107*4887Schin 	int		fortyp;
108*4887Schin 	char	 	*fornam;
109*4887Schin 	Shnode_t	*fortre;
110*4887Schin 	struct comnod	*forlst;
111*4887Schin 	int		forline;
112*4887Schin };
113*4887Schin 
114*4887Schin struct swnod
115*4887Schin {
116*4887Schin 	int		swtyp;
117*4887Schin 	struct argnod	*swarg;
118*4887Schin 	struct regnod	*swlst;
119*4887Schin 	struct ionod	*swio;
120*4887Schin 	int		swline;
121*4887Schin };
122*4887Schin 
123*4887Schin struct regnod
124*4887Schin {
125*4887Schin 	struct argnod	*regptr;
126*4887Schin 	Shnode_t	*regcom;
127*4887Schin 	struct regnod	*regnxt;
128*4887Schin 	char		regflag;
129*4887Schin };
130*4887Schin 
131*4887Schin struct parnod
132*4887Schin {
133*4887Schin 	int		partyp;
134*4887Schin 	Shnode_t	*partre;
135*4887Schin };
136*4887Schin 
137*4887Schin struct lstnod
138*4887Schin {
139*4887Schin 	int		lsttyp;
140*4887Schin 	Shnode_t	*lstlef;
141*4887Schin 	Shnode_t	*lstrit;
142*4887Schin };
143*4887Schin 
144*4887Schin /* tst is same as lst, but with extra field for line number */
145*4887Schin struct tstnod
146*4887Schin {
147*4887Schin 	struct lstnod	tstlst;
148*4887Schin 	int		tstline;
149*4887Schin };
150*4887Schin 
151*4887Schin struct functnod
152*4887Schin {
153*4887Schin 	int		functtyp;
154*4887Schin 	char		*functnam;
155*4887Schin 	Shnode_t	*functtre;
156*4887Schin 	int		functline;
157*4887Schin 	off_t		functloc;
158*4887Schin 	struct slnod	*functstak;
159*4887Schin 	struct comnod	*functargs;
160*4887Schin };
161*4887Schin 
162*4887Schin struct arithnod
163*4887Schin {
164*4887Schin 	int		artyp;
165*4887Schin 	int		arline;
166*4887Schin 	struct argnod	*arexpr;
167*4887Schin 	void		*arcomp;
168*4887Schin };
169*4887Schin 
170*4887Schin 
171*4887Schin /* types of ionodes stored in iofile  */
172*4887Schin #define IOUFD	0x3f		/* file descriptor number mask */
173*4887Schin #define IOPUT	0x40		/* > redirection operator */
174*4887Schin #define IOAPP	0x80		/* >> redirection operator */
175*4887Schin #define IODOC	0x100		/* << redirection operator */
176*4887Schin #define IOMOV	0x200		/* <& or >& operators */
177*4887Schin #define IOCLOB	0x400		/* noclobber bit */
178*4887Schin #define IORDW	0x800		/* <> redirection operator */
179*4887Schin #define IORAW	0x1000		/* no expansion needed for filename */
180*4887Schin #define IOSTRG	0x2000		/* here-document stored as incore string */
181*4887Schin #define IOSTRIP 0x4000		/* strip leading tabs for here-document */
182*4887Schin #define IOQUOTE	0x8000		/* here-document delimiter was quoted */
183*4887Schin #define IOVNM	0x10000		/* iovname field is non-zero */
184*4887Schin #define IOLSEEK	0x20000		/* seek operators <# or >#  */
185*4887Schin #define IOARITH	0x40000		/* arithmetic seek <# ((expr))  */
186*4887Schin #define IOCOPY	IOCLOB		/* copy skipped lines onto standard output */
187*4887Schin 
188*4887Schin union Shnode_u
189*4887Schin {
190*4887Schin 	struct argnod	arg;
191*4887Schin 	struct ionod	io;
192*4887Schin 	struct whnod	wh;
193*4887Schin 	struct swnod	sw;
194*4887Schin 	struct ifnod	if_;
195*4887Schin 	struct dolnod	dol;
196*4887Schin 	struct comnod	com;
197*4887Schin 	struct trenod	tre;
198*4887Schin 	struct forknod	fork;
199*4887Schin 	struct fornod	for_;
200*4887Schin 	struct regnod	reg;
201*4887Schin 	struct parnod	par;
202*4887Schin 	struct lstnod	lst;
203*4887Schin 	struct tstnod	tst;
204*4887Schin 	struct functnod	funct;
205*4887Schin 	struct arithnod	ar;
206*4887Schin };
207*4887Schin 
208*4887Schin extern void			sh_freeup(void);
209*4887Schin extern void			sh_funstaks(struct slnod*,int);
210*4887Schin extern Sfio_t 			*sh_subshell(Shnode_t*, int, int);
211*4887Schin #if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
212*4887Schin    __EXPORT__
213*4887Schin #endif
214*4887Schin extern int			sh_tdump(Sfio_t*, const Shnode_t*);
215*4887Schin extern Shnode_t			*sh_dolparen(void);
216*4887Schin extern Shnode_t			*sh_trestore(Sfio_t*);
217*4887Schin #if SHOPT_KIA
218*4887Schin     extern int 			kiaclose(void);
219*4887Schin     extern unsigned long 	kiaentity(const char*,int,int,int,int,unsigned long,int,int,const char*);
220*4887Schin #endif /* SHOPT_KIA */
221*4887Schin 
222*4887Schin #endif /* _SHNODES_H */
223