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