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