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