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