1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright (c) 1996, by Sun Microsystems, Inc.
28  * All rights reserved.
29  */
30 
31 /*
32  * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
33  *
34  * Sccsid @(#)mode.h	1.5 (gritter) 6/15/05
35  */
36 /* from OpenSolaris "mode.h	1.12	05/06/08 SMI"	 SVr4.0 1.8.1.2 */
37 /*
38  *	UNIX shell
39  */
40 
41 #include <unistd.h>
42 #include <sys/types.h>
43 
44 #ifdef pdp11
45 typedef char BOOL;
46 #else
47 typedef short BOOL;
48 #endif
49 
50 #define	BYTESPERWORD	(sizeof (char *))
51 #define	NIL	((char*)0)
52 
53 
54 /* the following nonsense is required
55  * because casts turn an Lvalue
56  * into an Rvalue so two cheats
57  * are necessary, one for each context.
58  */
59 #define	Rcheat(a)	((intptr_t)(a))
60 
61 
62 /* address puns for storage allocation */
63 typedef union
64 {
65 	struct forknod	*_forkptr;
66 	struct comnod	*_comptr;
67 	struct fndnod	*_fndptr;
68 	struct parnod	*_parptr;
69 	struct ifnod	*_ifptr;
70 	struct whnod	*_whptr;
71 	struct fornod	*_forptr;
72 	struct lstnod	*_lstptr;
73 	struct blk	*_blkptr;
74 	struct namnod	*_namptr;
75 	char	*_bytptr;
76 } address;
77 
78 
79 /* heap storage */
80 struct blk
81 {
82 	struct blk	*word;
83 };
84 
85 /*
86  * largefile converson hack note.
87  * the shell uses the *fnxt and *fend pointers when
88  * parsing a script. However, it was also using the
89  * difference between them when doing lseeks. Because
90  * that doesn't work in the largefile world, I have
91  * added a parallel set of offset counters that need to
92  * be updated whenever the "buffer" offsets the shell
93  * uses get changed. Most of this code is in word.c.
94  * If you change it, have fun...
95  */
96 
97 #define	BUFFERSIZE	128
98 struct fileblk
99 {
100 	int	fdes;
101 	unsigned flin;
102 	BOOL	feof;
103 	unsigned char	fsiz;
104 	unsigned char	*fnxt;
105 	unsigned char	*fend;
106 	off_t		nxtoff;		/* file offset */
107 	off_t		endoff;		/* file offset */
108 	unsigned char	**feval;
109 	struct fileblk	*fstak;
110 	unsigned char	fbuf[BUFFERSIZE];
111 };
112 
113 struct tempblk
114 {
115 	int fdes;
116 	struct tempblk *fstak;
117 };
118 
119 
120 /* for files not used with file descriptors */
121 struct filehdr
122 {
123 	int	fdes;
124 	unsigned	flin;
125 	BOOL	feof;
126 	unsigned char	fsiz;
127 	unsigned char	*fnxt;
128 	unsigned char	*fend;
129 	off_t		nxtoff;		/* file offset */
130 	off_t		endoff;		/* file offset */
131 	unsigned char	**feval;
132 	struct fileblk	*fstak;
133 	unsigned char	_fbuf[1];
134 };
135 
136 struct sysnod
137 {
138 	char	*sysnam;
139 	int	sysval;
140 };
141 
142 /* this node is a proforma for those that follow */
143 struct trenod
144 {
145 	int	tretyp;
146 	struct ionod	*treio;
147 };
148 
149 /* dummy for access only */
150 struct argnod
151 {
152 	struct argnod	*argnxt;
153 	unsigned char	argval[1];
154 };
155 
156 struct dolnod
157 {
158 	struct dolnod	*dolnxt;
159 	int	doluse;
160 	unsigned char	**dolarg;
161 };
162 
163 struct forknod
164 {
165 	int	forktyp;
166 	struct ionod	*forkio;
167 	struct trenod	*forktre;
168 };
169 
170 struct comnod
171 {
172 	int	comtyp;
173 	struct ionod	*comio;
174 	struct argnod	*comarg;
175 	struct argnod	*comset;
176 };
177 
178 struct fndnod
179 {
180 	int 	fndtyp;
181 	unsigned char	*fndnam;
182 	struct trenod	*fndval;
183 };
184 
185 struct ifnod
186 {
187 	int	iftyp;
188 	struct trenod	*iftre;
189 	struct trenod	*thtre;
190 	struct trenod	*eltre;
191 };
192 
193 struct whnod
194 {
195 	int	whtyp;
196 	struct trenod	*whtre;
197 	struct trenod	*dotre;
198 };
199 
200 struct fornod
201 {
202 	int	fortyp;
203 	struct trenod	*fortre;
204 	unsigned char	*fornam;
205 	struct comnod	*forlst;
206 };
207 
208 struct swnod
209 {
210 	int	swtyp;
211 	unsigned char *swarg;
212 	struct regnod	*swlst;
213 };
214 
215 struct regnod
216 {
217 	struct argnod	*regptr;
218 	struct trenod	*regcom;
219 	struct regnod	*regnxt;
220 };
221 
222 struct parnod
223 {
224 	int	partyp;
225 	struct trenod	*partre;
226 };
227 
228 struct lstnod
229 {
230 	int	lsttyp;
231 	struct trenod	*lstlef;
232 	struct trenod	*lstrit;
233 };
234 
235 struct ionod
236 {
237 	int	iofile;
238 	char	*ioname;
239 	char	*iolink;
240 	struct ionod	*ionxt;
241 	struct ionod	*iolst;
242 };
243 
244 struct fdsave
245 {
246 	int org_fd;
247 	int dup_fd;
248 };
249 
250 
251 #define		fndptr(x)	((struct fndnod *)x)
252 #define		comptr(x)	((struct comnod *)x)
253 #define		forkptr(x)	((struct forknod *)x)
254 #define		parptr(x)	((struct parnod *)x)
255 #define		lstptr(x)	((struct lstnod *)x)
256 #define		forptr(x)	((struct fornod *)x)
257 #define		whptr(x)	((struct whnod *)x)
258 #define		ifptr(x)	((struct ifnod *)x)
259 #define		swptr(x)	((struct swnod *)x)
260