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