xref: /illumos-gate/usr/src/cmd/sh/mode.h (revision d6b882a974afe4a3ab38793d5de10bae2e078d39)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50b46ffbaSmj162486  * Common Development and Distribution License (the "License").
60b46ffbaSmj162486  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
210b46ffbaSmj162486 /*
22*d6b882a9SNobutomo Nakano  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230b46ffbaSmj162486  * Use is subject to license terms.
240b46ffbaSmj162486  */
257c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
267c478bd9Sstevel@tonic-gate /* All Rights Reserved */
277c478bd9Sstevel@tonic-gate 
280b46ffbaSmj162486 #ifndef _MODE_H
290b46ffbaSmj162486 #define	_MODE_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  *	UNIX shell
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef pdp11
387c478bd9Sstevel@tonic-gate typedef char BOOL;
397c478bd9Sstevel@tonic-gate #else
407c478bd9Sstevel@tonic-gate typedef short BOOL;
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	BYTESPERWORD	(sizeof (char *))
440b46ffbaSmj162486 #define	ALIGNSIZ	(sizeof (double))
457c478bd9Sstevel@tonic-gate #define	NIL	((char *)0)
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate 
480b46ffbaSmj162486 /*
490b46ffbaSmj162486  * the following nonsense is required
507c478bd9Sstevel@tonic-gate  * because casts turn an Lvalue
517c478bd9Sstevel@tonic-gate  * into an Rvalue so two cheats
527c478bd9Sstevel@tonic-gate  * are necessary, one for each context.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #define	Rcheat(a)	((int)(a))
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* address puns for storage allocation */
587c478bd9Sstevel@tonic-gate typedef union
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	struct forknod	*_forkptr;
617c478bd9Sstevel@tonic-gate 	struct comnod	*_comptr;
627c478bd9Sstevel@tonic-gate 	struct fndnod	*_fndptr;
637c478bd9Sstevel@tonic-gate 	struct parnod	*_parptr;
647c478bd9Sstevel@tonic-gate 	struct ifnod	*_ifptr;
657c478bd9Sstevel@tonic-gate 	struct whnod	*_whptr;
667c478bd9Sstevel@tonic-gate 	struct fornod	*_forptr;
677c478bd9Sstevel@tonic-gate 	struct lstnod	*_lstptr;
687c478bd9Sstevel@tonic-gate 	struct blk	*_blkptr;
697c478bd9Sstevel@tonic-gate 	struct namnod	*_namptr;
707c478bd9Sstevel@tonic-gate 	char	*_bytptr;
717c478bd9Sstevel@tonic-gate } address;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /* heap storage */
757c478bd9Sstevel@tonic-gate struct blk
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate 	struct blk	*word;
780b46ffbaSmj162486 	char		pad[ALIGNSIZ - sizeof (struct blk *)];
797c478bd9Sstevel@tonic-gate };
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * largefile converson hack note.
837c478bd9Sstevel@tonic-gate  * the shell uses the *fnxt and *fend pointers when
847c478bd9Sstevel@tonic-gate  * parsing a script. However, it was also using the
857c478bd9Sstevel@tonic-gate  * difference between them when doing lseeks. Because
867c478bd9Sstevel@tonic-gate  * that doesn't work in the largefile world, I have
877c478bd9Sstevel@tonic-gate  * added a parallel set of offset counters that need to
887c478bd9Sstevel@tonic-gate  * be updated whenever the "buffer" offsets the shell
897c478bd9Sstevel@tonic-gate  * uses get changed. Most of this code is in word.c.
907c478bd9Sstevel@tonic-gate  * If you change it, have fun...
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	BUFFERSIZE	128
947c478bd9Sstevel@tonic-gate struct fileblk
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 	int	fdes;
977c478bd9Sstevel@tonic-gate 	unsigned flin;
987c478bd9Sstevel@tonic-gate 	BOOL	feof;
997c478bd9Sstevel@tonic-gate 	unsigned char	fsiz;
1007c478bd9Sstevel@tonic-gate 	unsigned char	*fnxt;
1017c478bd9Sstevel@tonic-gate 	unsigned char	*fend;
1027c478bd9Sstevel@tonic-gate 	off_t		nxtoff;		/* file offset */
1037c478bd9Sstevel@tonic-gate 	off_t		endoff;		/* file offset */
1047c478bd9Sstevel@tonic-gate 	unsigned char	**feval;
1057c478bd9Sstevel@tonic-gate 	struct fileblk	*fstak;
1067c478bd9Sstevel@tonic-gate 	unsigned char	fbuf[BUFFERSIZE];
1077c478bd9Sstevel@tonic-gate };
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate struct tempblk
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	int fdes;
1127c478bd9Sstevel@tonic-gate 	struct tempblk *fstak;
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /* for files not used with file descriptors */
1177c478bd9Sstevel@tonic-gate struct filehdr
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	int	fdes;
1207c478bd9Sstevel@tonic-gate 	unsigned	flin;
1217c478bd9Sstevel@tonic-gate 	BOOL	feof;
1227c478bd9Sstevel@tonic-gate 	unsigned char	fsiz;
1237c478bd9Sstevel@tonic-gate 	unsigned char	*fnxt;
1247c478bd9Sstevel@tonic-gate 	unsigned char	*fend;
1257c478bd9Sstevel@tonic-gate 	off_t		nxtoff;		/* file offset */
1267c478bd9Sstevel@tonic-gate 	off_t		endoff;		/* file offset */
1277c478bd9Sstevel@tonic-gate 	unsigned char	**feval;
1287c478bd9Sstevel@tonic-gate 	struct fileblk	*fstak;
1297c478bd9Sstevel@tonic-gate 	unsigned char	_fbuf[1];
1307c478bd9Sstevel@tonic-gate };
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate struct sysnod
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	char	*sysnam;
1357c478bd9Sstevel@tonic-gate 	int	sysval;
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /* this node is a proforma for those that follow */
1397c478bd9Sstevel@tonic-gate struct trenod
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	int	tretyp;
1427c478bd9Sstevel@tonic-gate 	struct ionod	*treio;
1437c478bd9Sstevel@tonic-gate };
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate /* dummy for access only */
1467c478bd9Sstevel@tonic-gate struct argnod
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate 	struct argnod	*argnxt;
1497c478bd9Sstevel@tonic-gate 	unsigned char	argval[1];
1507c478bd9Sstevel@tonic-gate };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate struct dolnod
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate 	struct dolnod	*dolnxt;
1557c478bd9Sstevel@tonic-gate 	int	doluse;
1567c478bd9Sstevel@tonic-gate 	unsigned char	**dolarg;
1577c478bd9Sstevel@tonic-gate };
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate struct forknod
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate 	int	forktyp;
1627c478bd9Sstevel@tonic-gate 	struct ionod	*forkio;
1637c478bd9Sstevel@tonic-gate 	struct trenod	*forktre;
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate struct comnod
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate 	int	comtyp;
1697c478bd9Sstevel@tonic-gate 	struct ionod	*comio;
1707c478bd9Sstevel@tonic-gate 	struct argnod	*comarg;
1717c478bd9Sstevel@tonic-gate 	struct argnod	*comset;
1727c478bd9Sstevel@tonic-gate };
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate struct fndnod
1757c478bd9Sstevel@tonic-gate {
1767c478bd9Sstevel@tonic-gate 	int 	fndtyp;
1777c478bd9Sstevel@tonic-gate 	unsigned char	*fndnam;
1787c478bd9Sstevel@tonic-gate 	struct trenod	*fndval;
179*d6b882a9SNobutomo Nakano 	int	fndref;
1807c478bd9Sstevel@tonic-gate };
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate struct ifnod
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	int	iftyp;
1857c478bd9Sstevel@tonic-gate 	struct trenod	*iftre;
1867c478bd9Sstevel@tonic-gate 	struct trenod	*thtre;
1877c478bd9Sstevel@tonic-gate 	struct trenod	*eltre;
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate struct whnod
1917c478bd9Sstevel@tonic-gate {
1927c478bd9Sstevel@tonic-gate 	int	whtyp;
1937c478bd9Sstevel@tonic-gate 	struct trenod	*whtre;
1947c478bd9Sstevel@tonic-gate 	struct trenod	*dotre;
1957c478bd9Sstevel@tonic-gate };
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate struct fornod
1987c478bd9Sstevel@tonic-gate {
1997c478bd9Sstevel@tonic-gate 	int	fortyp;
2007c478bd9Sstevel@tonic-gate 	struct trenod	*fortre;
2017c478bd9Sstevel@tonic-gate 	unsigned char	*fornam;
2027c478bd9Sstevel@tonic-gate 	struct comnod	*forlst;
2037c478bd9Sstevel@tonic-gate };
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate struct swnod
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 	int	swtyp;
2087c478bd9Sstevel@tonic-gate 	unsigned char *swarg;
2097c478bd9Sstevel@tonic-gate 	struct regnod	*swlst;
2107c478bd9Sstevel@tonic-gate };
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate struct regnod
2137c478bd9Sstevel@tonic-gate {
2147c478bd9Sstevel@tonic-gate 	struct argnod	*regptr;
2157c478bd9Sstevel@tonic-gate 	struct trenod	*regcom;
2167c478bd9Sstevel@tonic-gate 	struct regnod	*regnxt;
2177c478bd9Sstevel@tonic-gate };
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate struct parnod
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	int	partyp;
2227c478bd9Sstevel@tonic-gate 	struct trenod	*partre;
2237c478bd9Sstevel@tonic-gate };
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate struct lstnod
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	int	lsttyp;
2287c478bd9Sstevel@tonic-gate 	struct trenod	*lstlef;
2297c478bd9Sstevel@tonic-gate 	struct trenod	*lstrit;
2307c478bd9Sstevel@tonic-gate };
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate struct ionod
2337c478bd9Sstevel@tonic-gate {
2347c478bd9Sstevel@tonic-gate 	int	iofile;
2357c478bd9Sstevel@tonic-gate 	char	*ioname;
2367c478bd9Sstevel@tonic-gate 	char	*iolink;
2377c478bd9Sstevel@tonic-gate 	struct ionod	*ionxt;
2387c478bd9Sstevel@tonic-gate 	struct ionod	*iolst;
2397c478bd9Sstevel@tonic-gate };
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate struct fdsave
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate 	int org_fd;
2447c478bd9Sstevel@tonic-gate 	int dup_fd;
2457c478bd9Sstevel@tonic-gate };
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate #define		fndptr(x)	((struct fndnod *)x)
2497c478bd9Sstevel@tonic-gate #define		comptr(x)	((struct comnod *)x)
2507c478bd9Sstevel@tonic-gate #define		forkptr(x)	((struct forknod *)x)
2517c478bd9Sstevel@tonic-gate #define		parptr(x)	((struct parnod *)x)
2527c478bd9Sstevel@tonic-gate #define		lstptr(x)	((struct lstnod *)x)
2537c478bd9Sstevel@tonic-gate #define		forptr(x)	((struct fornod *)x)
2547c478bd9Sstevel@tonic-gate #define		whptr(x)	((struct whnod *)x)
2557c478bd9Sstevel@tonic-gate #define		ifptr(x)	((struct ifnod *)x)
2567c478bd9Sstevel@tonic-gate #define		swptr(x)	((struct swnod *)x)
2570b46ffbaSmj162486 
2580b46ffbaSmj162486 #endif /* _MODE_H */
259