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