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