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