xref: /onnv-gate/usr/src/lib/libshell/amd64/include/ast/shell.h (revision 12068:08a39a083754)
14887Schin 
24887Schin /* : : generated by proto : : */
34887Schin /***********************************************************************
44887Schin *                                                                      *
54887Schin *               This software is part of the ast package               *
6*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
74887Schin *                      and is licensed under the                       *
84887Schin *                  Common Public License, Version 1.0                  *
98462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
104887Schin *                                                                      *
114887Schin *                A copy of the License is available at                 *
124887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
134887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
144887Schin *                                                                      *
154887Schin *              Information and Software Systems Research               *
164887Schin *                            AT&T Research                             *
174887Schin *                           Florham Park NJ                            *
184887Schin *                                                                      *
194887Schin *                  David Korn <dgk@research.att.com>                   *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin 
234887Schin #ifndef SH_INTERACTIVE
244887Schin #if !defined(__PROTO__)
254887Schin #include <prototyped.h>
264887Schin #endif
274887Schin #if !defined(__LINKAGE__)
284887Schin #define __LINKAGE__		/* 2004-08-11 transition */
294887Schin #endif
304887Schin 
314887Schin /*
324887Schin  * David Korn
334887Schin  * AT&T Labs
344887Schin  *
354887Schin  * Interface definitions for shell command language
364887Schin  *
374887Schin  */
384887Schin 
398462SApril.Chin@Sun.COM #include	<ast.h>
404887Schin #include	<cdt.h>
414887Schin #ifdef _SH_PRIVATE
424887Schin #   include	"name.h"
434887Schin #else
444887Schin #   include	<nval.h>
454887Schin #endif /* _SH_PRIVATE */
464887Schin 
478462SApril.Chin@Sun.COM #define SH_VERSION	20071012
484887Schin 
494887Schin #undef NOT_USED
504887Schin #define NOT_USED(x)	(&x,1)
514887Schin 
524887Schin /* options */
534887Schin typedef struct
544887Schin {
554887Schin 	unsigned long v[4];
564887Schin }
574887Schin Shopt_t;
584887Schin 
598462SApril.Chin@Sun.COM typedef struct Shell_s Shell_t;
608462SApril.Chin@Sun.COM 
618462SApril.Chin@Sun.COM typedef void	(*Shinit_f) __PROTO__((Shell_t*, int));
624887Schin typedef int	(*Shwait_f) __PROTO__((int, long, int));
634887Schin 
644887Schin union Shnode_u;
654887Schin typedef union Shnode_u Shnode_t;
664887Schin 
674887Schin #define SH_CFLAG	0
684887Schin #define SH_HISTORY	1	/* used also as a state */
694887Schin #define	SH_ERREXIT	2	/* used also as a state */
704887Schin #define	SH_VERBOSE	3	/* used also as a state */
714887Schin #define SH_MONITOR	4	/* used also as a state */
724887Schin #define	SH_INTERACTIVE	5	/* used also as a state */
734887Schin #define	SH_RESTRICTED	6
744887Schin #define	SH_XTRACE	7
754887Schin #define	SH_KEYWORD	8
764887Schin #define SH_NOUNSET	9
774887Schin #define SH_NOGLOB	10
784887Schin #define SH_ALLEXPORT	11
794887Schin #define SH_PFSH		12
804887Schin #define SH_IGNOREEOF	13
814887Schin #define SH_NOCLOBBER	14
824887Schin #define SH_MARKDIRS	15
834887Schin #define SH_BGNICE	16
844887Schin #define SH_VI		17
854887Schin #define SH_VIRAW	18
864887Schin #define	SH_TFLAG	19
874887Schin #define SH_TRACKALL	20
884887Schin #define	SH_SFLAG	21
894887Schin #define	SH_NOEXEC	22
904887Schin #define SH_GMACS	24
914887Schin #define SH_EMACS	25
924887Schin #define SH_PRIVILEGED	26
934887Schin #define SH_SUBSHARE	27	/* subshell shares state with parent */
944887Schin #define SH_NOLOG	28
954887Schin #define SH_NOTIFY	29
964887Schin #define SH_DICTIONARY	30
974887Schin #define SH_PIPEFAIL	32
984887Schin #define SH_GLOBSTARS	33
994887Schin #define SH_XARGS	34
1004887Schin #define SH_RC		35
1014887Schin #define SH_SHOWME	36
1024887Schin 
1034887Schin /*
1044887Schin  * passed as flags to builtins in Nambltin_t struct when BLT_OPTIM is on
1054887Schin  */
1064887Schin #define SH_BEGIN_OPTIM	0x1
1074887Schin #define SH_END_OPTIM	0x2
1084887Schin 
1094887Schin /* The following type is used for error messages */
1104887Schin 
1114887Schin /* error messages */
1124887Schin extern __MANGLE__ const char	e_defpath[];
1134887Schin extern __MANGLE__ const char	e_found[];
1144887Schin extern __MANGLE__ const char	e_nospace[];
1154887Schin extern __MANGLE__ const char	e_format[];
1164887Schin extern __MANGLE__ const char 	e_number[];
1174887Schin extern __MANGLE__ const char	e_restricted[];
1184887Schin extern __MANGLE__ const char	e_recursive[];
1194887Schin extern __MANGLE__ char		e_version[];
1204887Schin 
1214887Schin typedef struct sh_scope
1224887Schin {
1234887Schin 	struct sh_scope	*par_scope;
1244887Schin 	int		argc;
1254887Schin 	char		**argv;
1264887Schin 	char		*cmdname;
1274887Schin 	char		*filename;
1288462SApril.Chin@Sun.COM 	char		*funname;
1294887Schin 	int		lineno;
1304887Schin 	Dt_t		*var_tree;
1314887Schin 	struct sh_scope	*self;
1324887Schin } Shscope_t;
1334887Schin 
1344887Schin /*
1354887Schin  * Saves the state of the shell
1364887Schin  */
1374887Schin 
1388462SApril.Chin@Sun.COM struct Shell_s
1394887Schin {
1404887Schin 	Shopt_t		options;	/* set -o options */
1414887Schin 	Dt_t		*var_tree;	/* for shell variables */
1424887Schin 	Dt_t		*fun_tree;	/* for shell functions */
1434887Schin 	Dt_t		*alias_tree;	/* for alias names */
1444887Schin 	Dt_t		*bltin_tree;    /* for builtin commands */
1454887Schin 	Shscope_t	*topscope;	/* pointer to top-level scope */
1464887Schin 	int		inlineno;	/* line number of current input file */
1474887Schin 	int		exitval;	/* most recent exit value */
1484887Schin 	unsigned char	trapnote;	/* set when trap/signal is pending */
1498462SApril.Chin@Sun.COM 	char		shcomp;		/* set when runing shcomp */
15010898Sroland.mainz@nrubsig.org 	short		subshell;	/* set for virtual subshell */
1514887Schin #ifdef _SH_PRIVATE
1524887Schin 	_SH_PRIVATE
1534887Schin #endif /* _SH_PRIVATE */
1548462SApril.Chin@Sun.COM };
1554887Schin 
1564887Schin /* flags for sh_parse */
1574887Schin #define SH_NL		1	/* Treat new-lines as ; */
1584887Schin #define SH_EOF		2	/* EOF causes syntax error */
1594887Schin 
1604887Schin /* symbolic values for sh_iogetiop */
1614887Schin #define SH_IOCOPROCESS	(-2)
1624887Schin #define SH_IOHISTFILE	(-3)
1634887Schin 
1648462SApril.Chin@Sun.COM #include	<cmd.h>
1658462SApril.Chin@Sun.COM 
1664887Schin /* symbolic value for sh_fdnotify */
1674887Schin #define SH_FDCLOSE	(-1)
1684887Schin 
1698462SApril.Chin@Sun.COM #undef getenv			/* -lshell provides its own */
1708462SApril.Chin@Sun.COM 
1714887Schin #if defined(__EXPORT__) && defined(_DLL)
1724887Schin #   ifdef _BLD_shell
1734887Schin #undef __MANGLE__
1744887Schin #define __MANGLE__ __LINKAGE__ __EXPORT__
1754887Schin #   endif /* _BLD_shell */
1764887Schin #endif /* _DLL */
1774887Schin 
1784887Schin extern __MANGLE__ Dt_t		*sh_bltin_tree __PROTO__((void));
1794887Schin extern __MANGLE__ void		sh_subfork __PROTO__((void));
1804887Schin extern __MANGLE__ Shell_t		*sh_init __PROTO__((int,char*[],Shinit_f));
1814887Schin extern __MANGLE__ int		sh_reinit __PROTO__((char*[]));
1824887Schin extern __MANGLE__ int 		sh_eval __PROTO__((Sfio_t*,int));
1834887Schin extern __MANGLE__ void 		sh_delay __PROTO__((double));
1844887Schin extern __MANGLE__ __V_		*sh_parse __PROTO__((Shell_t*, Sfio_t*,int));
1854887Schin extern __MANGLE__ int 		sh_trap __PROTO__((const char*,int));
1864887Schin extern __MANGLE__ int 		sh_fun __PROTO__((Namval_t*,Namval_t*, char*[]));
1874887Schin extern __MANGLE__ int 		sh_funscope __PROTO__((int,char*[],int(*)(__V_*),__V_*,int));
1884887Schin extern __MANGLE__ Sfio_t		*sh_iogetiop __PROTO__((int,int));
1898462SApril.Chin@Sun.COM extern __MANGLE__ int		sh_main __PROTO__((int, char*[], Shinit_f));
1908462SApril.Chin@Sun.COM extern __MANGLE__ int		sh_run __PROTO__((int, char*[]));
1914887Schin extern __MANGLE__ void		sh_menu __PROTO__((Sfio_t*, int, char*[]));
1924887Schin extern __MANGLE__ Namval_t		*sh_addbuiltin __PROTO__((const char*, int(*)(int, char*[],__V_*), __V_*));
1934887Schin extern __MANGLE__ char		*sh_fmtq __PROTO__((const char*));
1944887Schin extern __MANGLE__ char		*sh_fmtqf __PROTO__((const char*, int, int));
1954887Schin extern __MANGLE__ Sfdouble_t	sh_strnum __PROTO__((const char*, char**, int));
1964887Schin extern __MANGLE__ int		sh_access __PROTO__((const char*,int));
1974887Schin extern __MANGLE__ int 		sh_close __PROTO__((int));
1984887Schin extern __MANGLE__ int 		sh_dup __PROTO__((int));
1994887Schin extern __MANGLE__ void 		sh_exit __PROTO__((int));
2004887Schin extern __MANGLE__ int		sh_fcntl __PROTO__((int, int, ...));
2014887Schin extern __MANGLE__ Sfio_t		*sh_fd2sfio __PROTO__((int));
2024887Schin extern __MANGLE__ int		(*sh_fdnotify __PROTO__((int(*)(int,int)))) __PROTO__((int,int));
2034887Schin extern __MANGLE__ Shell_t		*sh_getinterp __PROTO__((void));
2044887Schin extern __MANGLE__ int		sh_open __PROTO__((const char*, int, ...));
2054887Schin extern __MANGLE__ int		sh_openmax __PROTO__((void));
2064887Schin extern __MANGLE__ Sfio_t		*sh_pathopen __PROTO__((const char*));
2074887Schin extern __MANGLE__ ssize_t 		sh_read __PROTO__((int, __V_*, size_t));
2084887Schin extern __MANGLE__ ssize_t 		sh_write __PROTO__((int, const __V_*, size_t));
2094887Schin extern __MANGLE__ off_t		sh_seek __PROTO__((int, off_t, int));
2104887Schin extern __MANGLE__ int 		sh_pipe __PROTO__((int[]));
2114887Schin extern __MANGLE__ mode_t 		sh_umask __PROTO__((mode_t));
2124887Schin extern __MANGLE__ __V_		*sh_waitnotify __PROTO__((Shwait_f));
2134887Schin extern __MANGLE__ Shscope_t	*sh_getscope __PROTO__((int,int));
2144887Schin extern __MANGLE__ Shscope_t	*sh_setscope __PROTO__((Shscope_t*));
2154887Schin extern __MANGLE__ void		sh_sigcheck __PROTO__((void));
2164887Schin extern __MANGLE__ unsigned long	sh_isoption __PROTO__((int));
2174887Schin extern __MANGLE__ unsigned long	sh_onoption __PROTO__((int));
2184887Schin extern __MANGLE__ unsigned long	sh_offoption __PROTO__((int));
2194887Schin extern __MANGLE__ int 		sh_waitsafe __PROTO__((void));
2204887Schin extern __MANGLE__ int		sh_exec __PROTO__((const Shnode_t*,int));
2214887Schin 
2224887Schin #if SHOPT_DYNAMIC
2234887Schin     extern __MANGLE__ __V_		**sh_getliblist __PROTO__((void));
2244887Schin #endif /* SHOPT_DYNAMIC */
2254887Schin 
2264887Schin /*
2274887Schin  * direct access to sh is obsolete, use sh_getinterp() instead
2284887Schin  */
2294887Schin #if !defined(_SH_PRIVATE) && defined(__IMPORT__) && !defined(_BLD_shell)
2304887Schin 	extern __MANGLE__ __IMPORT__  Shell_t sh;
2314887Schin #else
2324887Schin 	extern __MANGLE__ Shell_t sh;
2334887Schin #endif
2344887Schin 
2354887Schin #ifdef _DLL
2364887Schin #undef __MANGLE__
2374887Schin #define __MANGLE__ __LINKAGE__
2384887Schin #endif /* _DLL */
2394887Schin 
2404887Schin #ifndef _SH_PRIVATE
2414887Schin #   define access(a,b)	sh_access(a,b)
2424887Schin #   define close(a)	sh_close(a)
2434887Schin #   define exit(a)	sh_exit(a)
2444887Schin #   define fcntl(a,b,c)	sh_fcntl(a,b,c)
2454887Schin #   define pipe(a)	sh_pipe(a)
2464887Schin #   define read(a,b,c)	sh_read(a,b,c)
2474887Schin #   define write(a,b,c)	sh_write(a,b,c)
2484887Schin #   define umask(a)	sh_umask(a)
2494887Schin #   define dup		sh_dup
2504887Schin #   if _lib_lseek64
2514887Schin #	define open64	sh_open
2524887Schin #	define lseek64	sh_seek
2534887Schin #   else
2544887Schin #	define open	sh_open
2554887Schin #	define lseek	sh_seek
2564887Schin #   endif
2574887Schin #endif /* !_SH_PRIVATE */
2584887Schin 
2594887Schin #define SH_SIGSET	4
2604887Schin #define SH_EXITSIG	0400	/* signal exit bit */
2614887Schin #define SH_EXITMASK	(SH_EXITSIG-1)	/* normal exit status bits */
2624887Schin #define SH_RUNPROG	-1022	/* needs to be negative and < 256 */
2634887Schin 
2644887Schin #endif /* SH_INTERACTIVE */
265