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