xref: /titanic_44/usr/src/lib/libshell/sparc/include/ast/shell.h (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1da2e3ebdSchin 
2da2e3ebdSchin /* : : generated by proto : : */
3da2e3ebdSchin /***********************************************************************
4da2e3ebdSchin *                                                                      *
5da2e3ebdSchin *               This software is part of the ast package               *
6*3e14f97fSRoger A. Faulkner *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
7da2e3ebdSchin *                      and is licensed under the                       *
8da2e3ebdSchin *                  Common Public License, Version 1.0                  *
97c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
10da2e3ebdSchin *                                                                      *
11da2e3ebdSchin *                A copy of the License is available at                 *
12da2e3ebdSchin *            http://www.opensource.org/licenses/cpl1.0.txt             *
13da2e3ebdSchin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
14da2e3ebdSchin *                                                                      *
15da2e3ebdSchin *              Information and Software Systems Research               *
16da2e3ebdSchin *                            AT&T Research                             *
17da2e3ebdSchin *                           Florham Park NJ                            *
18da2e3ebdSchin *                                                                      *
19da2e3ebdSchin *                  David Korn <dgk@research.att.com>                   *
20da2e3ebdSchin *                                                                      *
21da2e3ebdSchin ***********************************************************************/
22da2e3ebdSchin 
23da2e3ebdSchin #ifndef SH_INTERACTIVE
24da2e3ebdSchin #if !defined(__PROTO__)
25da2e3ebdSchin #include <prototyped.h>
26da2e3ebdSchin #endif
27da2e3ebdSchin #if !defined(__LINKAGE__)
28da2e3ebdSchin #define __LINKAGE__		/* 2004-08-11 transition */
29da2e3ebdSchin #endif
30da2e3ebdSchin 
31da2e3ebdSchin /*
32da2e3ebdSchin  * David Korn
33da2e3ebdSchin  * AT&T Labs
34da2e3ebdSchin  *
35da2e3ebdSchin  * Interface definitions for shell command language
36da2e3ebdSchin  *
37da2e3ebdSchin  */
38da2e3ebdSchin 
397c2fbfb3SApril Chin #include	<ast.h>
40da2e3ebdSchin #include	<cdt.h>
41da2e3ebdSchin #ifdef _SH_PRIVATE
42da2e3ebdSchin #   include	"name.h"
43da2e3ebdSchin #else
44da2e3ebdSchin #   include	<nval.h>
45da2e3ebdSchin #endif /* _SH_PRIVATE */
46da2e3ebdSchin 
477c2fbfb3SApril Chin #define SH_VERSION	20071012
48da2e3ebdSchin 
49da2e3ebdSchin #undef NOT_USED
50da2e3ebdSchin #define NOT_USED(x)	(&x,1)
51da2e3ebdSchin 
52da2e3ebdSchin /* options */
53da2e3ebdSchin typedef struct
54da2e3ebdSchin {
55da2e3ebdSchin 	unsigned long v[4];
56da2e3ebdSchin }
57da2e3ebdSchin Shopt_t;
58da2e3ebdSchin 
597c2fbfb3SApril Chin typedef struct Shell_s Shell_t;
607c2fbfb3SApril Chin 
617c2fbfb3SApril Chin typedef void	(*Shinit_f) __PROTO__((Shell_t*, int));
62da2e3ebdSchin typedef int	(*Shwait_f) __PROTO__((int, long, int));
63da2e3ebdSchin 
64da2e3ebdSchin union Shnode_u;
65da2e3ebdSchin typedef union Shnode_u Shnode_t;
66da2e3ebdSchin 
67da2e3ebdSchin #define SH_CFLAG	0
68da2e3ebdSchin #define SH_HISTORY	1	/* used also as a state */
69da2e3ebdSchin #define	SH_ERREXIT	2	/* used also as a state */
70da2e3ebdSchin #define	SH_VERBOSE	3	/* used also as a state */
71da2e3ebdSchin #define SH_MONITOR	4	/* used also as a state */
72da2e3ebdSchin #define	SH_INTERACTIVE	5	/* used also as a state */
73da2e3ebdSchin #define	SH_RESTRICTED	6
74da2e3ebdSchin #define	SH_XTRACE	7
75da2e3ebdSchin #define	SH_KEYWORD	8
76da2e3ebdSchin #define SH_NOUNSET	9
77da2e3ebdSchin #define SH_NOGLOB	10
78da2e3ebdSchin #define SH_ALLEXPORT	11
79da2e3ebdSchin #define SH_PFSH		12
80da2e3ebdSchin #define SH_IGNOREEOF	13
81da2e3ebdSchin #define SH_NOCLOBBER	14
82da2e3ebdSchin #define SH_MARKDIRS	15
83da2e3ebdSchin #define SH_BGNICE	16
84da2e3ebdSchin #define SH_VI		17
85da2e3ebdSchin #define SH_VIRAW	18
86da2e3ebdSchin #define	SH_TFLAG	19
87da2e3ebdSchin #define SH_TRACKALL	20
88da2e3ebdSchin #define	SH_SFLAG	21
89da2e3ebdSchin #define	SH_NOEXEC	22
90da2e3ebdSchin #define SH_GMACS	24
91da2e3ebdSchin #define SH_EMACS	25
92da2e3ebdSchin #define SH_PRIVILEGED	26
93da2e3ebdSchin #define SH_SUBSHARE	27	/* subshell shares state with parent */
94da2e3ebdSchin #define SH_NOLOG	28
95da2e3ebdSchin #define SH_NOTIFY	29
96da2e3ebdSchin #define SH_DICTIONARY	30
97da2e3ebdSchin #define SH_PIPEFAIL	32
98da2e3ebdSchin #define SH_GLOBSTARS	33
99da2e3ebdSchin #define SH_XARGS	34
100da2e3ebdSchin #define SH_RC		35
101da2e3ebdSchin #define SH_SHOWME	36
102da2e3ebdSchin 
103da2e3ebdSchin /*
104da2e3ebdSchin  * passed as flags to builtins in Nambltin_t struct when BLT_OPTIM is on
105da2e3ebdSchin  */
106da2e3ebdSchin #define SH_BEGIN_OPTIM	0x1
107da2e3ebdSchin #define SH_END_OPTIM	0x2
108da2e3ebdSchin 
109da2e3ebdSchin /* The following type is used for error messages */
110da2e3ebdSchin 
111da2e3ebdSchin /* error messages */
112da2e3ebdSchin extern __MANGLE__ const char	e_defpath[];
113da2e3ebdSchin extern __MANGLE__ const char	e_found[];
114da2e3ebdSchin extern __MANGLE__ const char	e_nospace[];
115da2e3ebdSchin extern __MANGLE__ const char	e_format[];
116da2e3ebdSchin extern __MANGLE__ const char 	e_number[];
117da2e3ebdSchin extern __MANGLE__ const char	e_restricted[];
118da2e3ebdSchin extern __MANGLE__ const char	e_recursive[];
119da2e3ebdSchin extern __MANGLE__ char		e_version[];
120da2e3ebdSchin 
121da2e3ebdSchin typedef struct sh_scope
122da2e3ebdSchin {
123da2e3ebdSchin 	struct sh_scope	*par_scope;
124da2e3ebdSchin 	int		argc;
125da2e3ebdSchin 	char		**argv;
126da2e3ebdSchin 	char		*cmdname;
127da2e3ebdSchin 	char		*filename;
1287c2fbfb3SApril Chin 	char		*funname;
129da2e3ebdSchin 	int		lineno;
130da2e3ebdSchin 	Dt_t		*var_tree;
131da2e3ebdSchin 	struct sh_scope	*self;
132da2e3ebdSchin } Shscope_t;
133da2e3ebdSchin 
134da2e3ebdSchin /*
135da2e3ebdSchin  * Saves the state of the shell
136da2e3ebdSchin  */
137da2e3ebdSchin 
1387c2fbfb3SApril Chin struct Shell_s
139da2e3ebdSchin {
140da2e3ebdSchin 	Shopt_t		options;	/* set -o options */
141da2e3ebdSchin 	Dt_t		*var_tree;	/* for shell variables */
142da2e3ebdSchin 	Dt_t		*fun_tree;	/* for shell functions */
143da2e3ebdSchin 	Dt_t		*alias_tree;	/* for alias names */
144da2e3ebdSchin 	Dt_t		*bltin_tree;    /* for builtin commands */
145da2e3ebdSchin 	Shscope_t	*topscope;	/* pointer to top-level scope */
146da2e3ebdSchin 	int		inlineno;	/* line number of current input file */
147da2e3ebdSchin 	int		exitval;	/* most recent exit value */
148da2e3ebdSchin 	unsigned char	trapnote;	/* set when trap/signal is pending */
1497c2fbfb3SApril Chin 	char		shcomp;		/* set when runing shcomp */
15034f9b3eeSRoland Mainz 	short		subshell;	/* set for virtual subshell */
151da2e3ebdSchin #ifdef _SH_PRIVATE
152da2e3ebdSchin 	_SH_PRIVATE
153da2e3ebdSchin #endif /* _SH_PRIVATE */
1547c2fbfb3SApril Chin };
155da2e3ebdSchin 
156da2e3ebdSchin /* flags for sh_parse */
157da2e3ebdSchin #define SH_NL		1	/* Treat new-lines as ; */
158da2e3ebdSchin #define SH_EOF		2	/* EOF causes syntax error */
159da2e3ebdSchin 
160da2e3ebdSchin /* symbolic values for sh_iogetiop */
161da2e3ebdSchin #define SH_IOCOPROCESS	(-2)
162da2e3ebdSchin #define SH_IOHISTFILE	(-3)
163da2e3ebdSchin 
1647c2fbfb3SApril Chin #include	<cmd.h>
1657c2fbfb3SApril Chin 
166da2e3ebdSchin /* symbolic value for sh_fdnotify */
167da2e3ebdSchin #define SH_FDCLOSE	(-1)
168da2e3ebdSchin 
1697c2fbfb3SApril Chin #undef getenv			/* -lshell provides its own */
1707c2fbfb3SApril Chin 
171da2e3ebdSchin #if defined(__EXPORT__) && defined(_DLL)
172da2e3ebdSchin #   ifdef _BLD_shell
173da2e3ebdSchin #undef __MANGLE__
174da2e3ebdSchin #define __MANGLE__ __LINKAGE__ __EXPORT__
175da2e3ebdSchin #   endif /* _BLD_shell */
176da2e3ebdSchin #endif /* _DLL */
177da2e3ebdSchin 
178da2e3ebdSchin extern __MANGLE__ Dt_t		*sh_bltin_tree __PROTO__((void));
179da2e3ebdSchin extern __MANGLE__ void		sh_subfork __PROTO__((void));
180da2e3ebdSchin extern __MANGLE__ Shell_t		*sh_init __PROTO__((int,char*[],Shinit_f));
181da2e3ebdSchin extern __MANGLE__ int		sh_reinit __PROTO__((char*[]));
182da2e3ebdSchin extern __MANGLE__ int 		sh_eval __PROTO__((Sfio_t*,int));
183da2e3ebdSchin extern __MANGLE__ void 		sh_delay __PROTO__((double));
184da2e3ebdSchin extern __MANGLE__ __V_		*sh_parse __PROTO__((Shell_t*, Sfio_t*,int));
185da2e3ebdSchin extern __MANGLE__ int 		sh_trap __PROTO__((const char*,int));
186da2e3ebdSchin extern __MANGLE__ int 		sh_fun __PROTO__((Namval_t*,Namval_t*, char*[]));
187da2e3ebdSchin extern __MANGLE__ int 		sh_funscope __PROTO__((int,char*[],int(*)(__V_*),__V_*,int));
188da2e3ebdSchin extern __MANGLE__ Sfio_t		*sh_iogetiop __PROTO__((int,int));
1897c2fbfb3SApril Chin extern __MANGLE__ int		sh_main __PROTO__((int, char*[], Shinit_f));
1907c2fbfb3SApril Chin extern __MANGLE__ int		sh_run __PROTO__((int, char*[]));
191da2e3ebdSchin extern __MANGLE__ void		sh_menu __PROTO__((Sfio_t*, int, char*[]));
192da2e3ebdSchin extern __MANGLE__ Namval_t		*sh_addbuiltin __PROTO__((const char*, int(*)(int, char*[],__V_*), __V_*));
193da2e3ebdSchin extern __MANGLE__ char		*sh_fmtq __PROTO__((const char*));
194da2e3ebdSchin extern __MANGLE__ char		*sh_fmtqf __PROTO__((const char*, int, int));
195da2e3ebdSchin extern __MANGLE__ Sfdouble_t	sh_strnum __PROTO__((const char*, char**, int));
196da2e3ebdSchin extern __MANGLE__ int		sh_access __PROTO__((const char*,int));
197da2e3ebdSchin extern __MANGLE__ int 		sh_close __PROTO__((int));
198da2e3ebdSchin extern __MANGLE__ int 		sh_dup __PROTO__((int));
199da2e3ebdSchin extern __MANGLE__ void 		sh_exit __PROTO__((int));
200da2e3ebdSchin extern __MANGLE__ int		sh_fcntl __PROTO__((int, int, ...));
201da2e3ebdSchin extern __MANGLE__ Sfio_t		*sh_fd2sfio __PROTO__((int));
202da2e3ebdSchin extern __MANGLE__ int		(*sh_fdnotify __PROTO__((int(*)(int,int)))) __PROTO__((int,int));
203da2e3ebdSchin extern __MANGLE__ Shell_t		*sh_getinterp __PROTO__((void));
204da2e3ebdSchin extern __MANGLE__ int		sh_open __PROTO__((const char*, int, ...));
205da2e3ebdSchin extern __MANGLE__ int		sh_openmax __PROTO__((void));
206da2e3ebdSchin extern __MANGLE__ Sfio_t		*sh_pathopen __PROTO__((const char*));
207da2e3ebdSchin extern __MANGLE__ ssize_t 		sh_read __PROTO__((int, __V_*, size_t));
208da2e3ebdSchin extern __MANGLE__ ssize_t 		sh_write __PROTO__((int, const __V_*, size_t));
209da2e3ebdSchin extern __MANGLE__ off_t		sh_seek __PROTO__((int, off_t, int));
210da2e3ebdSchin extern __MANGLE__ int 		sh_pipe __PROTO__((int[]));
211da2e3ebdSchin extern __MANGLE__ mode_t 		sh_umask __PROTO__((mode_t));
212da2e3ebdSchin extern __MANGLE__ __V_		*sh_waitnotify __PROTO__((Shwait_f));
213da2e3ebdSchin extern __MANGLE__ Shscope_t	*sh_getscope __PROTO__((int,int));
214da2e3ebdSchin extern __MANGLE__ Shscope_t	*sh_setscope __PROTO__((Shscope_t*));
215da2e3ebdSchin extern __MANGLE__ void		sh_sigcheck __PROTO__((void));
216da2e3ebdSchin extern __MANGLE__ unsigned long	sh_isoption __PROTO__((int));
217da2e3ebdSchin extern __MANGLE__ unsigned long	sh_onoption __PROTO__((int));
218da2e3ebdSchin extern __MANGLE__ unsigned long	sh_offoption __PROTO__((int));
219da2e3ebdSchin extern __MANGLE__ int 		sh_waitsafe __PROTO__((void));
220da2e3ebdSchin extern __MANGLE__ int		sh_exec __PROTO__((const Shnode_t*,int));
221da2e3ebdSchin 
222da2e3ebdSchin #if SHOPT_DYNAMIC
223da2e3ebdSchin     extern __MANGLE__ __V_		**sh_getliblist __PROTO__((void));
224da2e3ebdSchin #endif /* SHOPT_DYNAMIC */
225da2e3ebdSchin 
226da2e3ebdSchin /*
227da2e3ebdSchin  * direct access to sh is obsolete, use sh_getinterp() instead
228da2e3ebdSchin  */
229da2e3ebdSchin #if !defined(_SH_PRIVATE) && defined(__IMPORT__) && !defined(_BLD_shell)
230da2e3ebdSchin 	extern __MANGLE__ __IMPORT__  Shell_t sh;
231da2e3ebdSchin #else
232da2e3ebdSchin 	extern __MANGLE__ Shell_t sh;
233da2e3ebdSchin #endif
234da2e3ebdSchin 
235da2e3ebdSchin #ifdef _DLL
236da2e3ebdSchin #undef __MANGLE__
237da2e3ebdSchin #define __MANGLE__ __LINKAGE__
238da2e3ebdSchin #endif /* _DLL */
239da2e3ebdSchin 
240da2e3ebdSchin #ifndef _SH_PRIVATE
241da2e3ebdSchin #   define access(a,b)	sh_access(a,b)
242da2e3ebdSchin #   define close(a)	sh_close(a)
243da2e3ebdSchin #   define exit(a)	sh_exit(a)
244da2e3ebdSchin #   define fcntl(a,b,c)	sh_fcntl(a,b,c)
245da2e3ebdSchin #   define pipe(a)	sh_pipe(a)
246da2e3ebdSchin #   define read(a,b,c)	sh_read(a,b,c)
247da2e3ebdSchin #   define write(a,b,c)	sh_write(a,b,c)
248da2e3ebdSchin #   define umask(a)	sh_umask(a)
249da2e3ebdSchin #   define dup		sh_dup
250da2e3ebdSchin #   if _lib_lseek64
251da2e3ebdSchin #	define open64	sh_open
252da2e3ebdSchin #	define lseek64	sh_seek
253da2e3ebdSchin #   else
254da2e3ebdSchin #	define open	sh_open
255da2e3ebdSchin #	define lseek	sh_seek
256da2e3ebdSchin #   endif
257da2e3ebdSchin #endif /* !_SH_PRIVATE */
258da2e3ebdSchin 
259da2e3ebdSchin #define SH_SIGSET	4
260da2e3ebdSchin #define SH_EXITSIG	0400	/* signal exit bit */
261da2e3ebdSchin #define SH_EXITMASK	(SH_EXITSIG-1)	/* normal exit status bits */
262da2e3ebdSchin #define SH_RUNPROG	-1022	/* needs to be negative and < 256 */
263da2e3ebdSchin 
264da2e3ebdSchin #endif /* SH_INTERACTIVE */
265