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