xref: /onnv-gate/usr/src/lib/libshell/common/include/shnodes.h (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                  David Korn <dgk@research.att.com>                   *
184887Schin *                                                                      *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin #ifndef _SHNODES_H
224887Schin #define _SHNODES_H	1
234887Schin /*
244887Schin  *	UNIX shell
254887Schin  *	Written by David Korn
264887Schin  *
274887Schin  */
284887Schin 
294887Schin 
304887Schin #include	<ast.h>
314887Schin #include	"argnod.h"
324887Schin 
334887Schin /* command tree for tretyp */
344887Schin #define FINT		(02<<COMBITS)		/* non-interruptable */
354887Schin #define FAMP		(04<<COMBITS)		/* background */
364887Schin #define FPIN		(010<<COMBITS)		/* input is a pipe */
374887Schin #define FPOU		(040<<COMBITS)		/* output is a pipe */
384887Schin #define FPCL		(0100<<COMBITS)		/* close the pipe */
394887Schin #define FCOOP		(0200<<COMBITS)		/* cooperating process */
404887Schin #define FSHOWME		(0400<<COMBITS)		/* set for showme commands  */
414887Schin #define FPOSIX		(02<<COMBITS)		/* posix semantics function */
424887Schin #define FLINENO		(04<<COMBITS)		/* for/case has line number */
438462SApril.Chin@Sun.COM #define FOPTGET		(010<<COMBITS)		/* function calls getopts */
444887Schin 
454887Schin #define TNEGATE		(01<<COMBITS)		/* ! inside [[...]] */
464887Schin #define TBINARY		(02<<COMBITS)		/* binary operator in [[...]] */
474887Schin #define TUNARY		(04<<COMBITS)		/* unary operator in [[...]] */
484887Schin #define TTEST		(010<<COMBITS)
494887Schin #define TPAREN		(TBINARY|TUNARY)
504887Schin #define TSHIFT		(COMBITS+4)
514887Schin #define TNSPACE		(TFUN|COMSCAN)
524887Schin 
534887Schin #define TCOM	0
544887Schin #define TPAR	1
554887Schin #define TFIL	2
564887Schin #define TLST	3
574887Schin #define TIF	4
584887Schin #define TWH	5
594887Schin #define TUN	(TWH|COMSCAN)
604887Schin #define TTST	6
614887Schin #define TSW	7
624887Schin #define TAND	8
634887Schin #define TORF	9
644887Schin #define TFORK	10
654887Schin #define TFOR	11
664887Schin #define TSELECT	(TFOR|COMSCAN)
674887Schin #define TARITH	12
684887Schin #define	TTIME	13
694887Schin #define TSETIO	14
704887Schin #define TFUN	15
714887Schin 
724887Schin /* this node is a proforma for those that follow */
734887Schin 
744887Schin struct trenod
754887Schin {
764887Schin 	int		tretyp;
774887Schin 	struct ionod	*treio;
784887Schin };
794887Schin 
804887Schin 
814887Schin struct forknod
824887Schin {
834887Schin 	int		forktyp;
844887Schin 	struct ionod	*forkio;
854887Schin 	Shnode_t	*forktre;
864887Schin 	int		forkline;
874887Schin };
884887Schin 
894887Schin 
904887Schin struct ifnod
914887Schin {
924887Schin 	int		iftyp;
934887Schin 	Shnode_t	*iftre;
944887Schin 	Shnode_t	*thtre;
954887Schin 	Shnode_t	*eltre;
964887Schin };
974887Schin 
984887Schin struct whnod
994887Schin {
1004887Schin 	int		whtyp;
1014887Schin 	Shnode_t	*whtre;
1024887Schin 	Shnode_t	*dotre;
1034887Schin 	struct arithnod	*whinc;
1044887Schin };
1054887Schin 
1064887Schin struct fornod
1074887Schin {
1084887Schin 	int		fortyp;
1094887Schin 	char	 	*fornam;
1104887Schin 	Shnode_t	*fortre;
1114887Schin 	struct comnod	*forlst;
1124887Schin 	int		forline;
1134887Schin };
1144887Schin 
1154887Schin struct swnod
1164887Schin {
1174887Schin 	int		swtyp;
1184887Schin 	struct argnod	*swarg;
1194887Schin 	struct regnod	*swlst;
1204887Schin 	struct ionod	*swio;
1214887Schin 	int		swline;
1224887Schin };
1234887Schin 
1244887Schin struct regnod
1254887Schin {
1264887Schin 	struct argnod	*regptr;
1274887Schin 	Shnode_t	*regcom;
1284887Schin 	struct regnod	*regnxt;
1294887Schin 	char		regflag;
1304887Schin };
1314887Schin 
1324887Schin struct parnod
1334887Schin {
1344887Schin 	int		partyp;
1354887Schin 	Shnode_t	*partre;
1364887Schin };
1374887Schin 
1384887Schin struct lstnod
1394887Schin {
1404887Schin 	int		lsttyp;
1414887Schin 	Shnode_t	*lstlef;
1424887Schin 	Shnode_t	*lstrit;
1434887Schin };
1444887Schin 
1454887Schin /* tst is same as lst, but with extra field for line number */
1464887Schin struct tstnod
1474887Schin {
1484887Schin 	struct lstnod	tstlst;
1494887Schin 	int		tstline;
1504887Schin };
1514887Schin 
1524887Schin struct functnod
1534887Schin {
1544887Schin 	int		functtyp;
1554887Schin 	char		*functnam;
1564887Schin 	Shnode_t	*functtre;
1574887Schin 	int		functline;
1584887Schin 	off_t		functloc;
1594887Schin 	struct slnod	*functstak;
1604887Schin 	struct comnod	*functargs;
1614887Schin };
1624887Schin 
1634887Schin struct arithnod
1644887Schin {
1654887Schin 	int		artyp;
1664887Schin 	int		arline;
1674887Schin 	struct argnod	*arexpr;
1684887Schin 	void		*arcomp;
1694887Schin };
1704887Schin 
1714887Schin 
1724887Schin /* types of ionodes stored in iofile  */
1738462SApril.Chin@Sun.COM #define IOUFD		0x3f	/* file descriptor number mask */
1748462SApril.Chin@Sun.COM #define IOPUT		0x40	/* > redirection operator */
1758462SApril.Chin@Sun.COM #define IOAPP		0x80	/* >> redirection operator */
1768462SApril.Chin@Sun.COM #define IODOC		0x100	/* << redirection operator */
1778462SApril.Chin@Sun.COM #define IOMOV		0x200	/* <& or >& operators */
1788462SApril.Chin@Sun.COM #define IOCLOB		0x400	/* noclobber bit */
1798462SApril.Chin@Sun.COM #define IORDW		0x800	/* <> redirection operator */
1808462SApril.Chin@Sun.COM #define IORAW		0x1000	/* no expansion needed for filename */
1818462SApril.Chin@Sun.COM #define IOSTRG		0x2000	/* here-document stored as incore string */
1828462SApril.Chin@Sun.COM #define IOSTRIP 	0x4000	/* strip leading tabs for here-document */
1838462SApril.Chin@Sun.COM #define IOQUOTE		0x8000	/* here-document delimiter was quoted */
1848462SApril.Chin@Sun.COM #define IOVNM		0x10000	/* iovname field is non-zero */
1858462SApril.Chin@Sun.COM #define IOLSEEK		0x20000	/* seek operators <# or >#  */
1868462SApril.Chin@Sun.COM #define IOARITH		0x40000	/* arithmetic seek <# ((expr))  */
1878462SApril.Chin@Sun.COM #define IOREWRITE	0x80000	/* arithmetic seek <# ((expr))  */
1888462SApril.Chin@Sun.COM #define IOCOPY		IOCLOB	/* copy skipped lines onto standard output */
18910898Sroland.mainz@nrubsig.org #define IOPROCSUB	IOARITH	/* process substitution redirection */
1904887Schin 
1914887Schin union Shnode_u
1924887Schin {
1934887Schin 	struct argnod	arg;
1944887Schin 	struct ionod	io;
1954887Schin 	struct whnod	wh;
1964887Schin 	struct swnod	sw;
1974887Schin 	struct ifnod	if_;
1984887Schin 	struct dolnod	dol;
1994887Schin 	struct comnod	com;
2004887Schin 	struct trenod	tre;
2014887Schin 	struct forknod	fork;
2024887Schin 	struct fornod	for_;
2034887Schin 	struct regnod	reg;
2044887Schin 	struct parnod	par;
2054887Schin 	struct lstnod	lst;
2064887Schin 	struct tstnod	tst;
2074887Schin 	struct functnod	funct;
2084887Schin 	struct arithnod	ar;
2094887Schin };
2104887Schin 
2118462SApril.Chin@Sun.COM extern void			sh_freeup(Shell_t*);
2124887Schin extern void			sh_funstaks(struct slnod*,int);
2134887Schin extern Sfio_t 			*sh_subshell(Shnode_t*, int, int);
2144887Schin #if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
2154887Schin    __EXPORT__
2164887Schin #endif
2174887Schin extern int			sh_tdump(Sfio_t*, const Shnode_t*);
2188462SApril.Chin@Sun.COM extern Shnode_t			*sh_trestore(Shell_t*, Sfio_t*);
2194887Schin 
2204887Schin #endif /* _SHNODES_H */
221