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