1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * David Korn <dgk@research.att.com> *
19 ***********************************************************************/
21 #ifndef SH_INTERACTIVE
26 * Interface definitions for shell command language
36 #endif /* _SH_PRIVATE */
38 #define SH_VERSION 20071012
41 #define NOT_USED(x) (&x,1)
50 typedef struct Shell_s Shell_t
;
52 typedef void (*Shinit_f
)(Shell_t
*, int);
53 typedef int (*Shwait_f
)(int, long, int);
56 typedef union Shnode_u Shnode_t
;
59 #define SH_HISTORY 1 /* used also as a state */
60 #define SH_ERREXIT 2 /* used also as a state */
61 #define SH_VERBOSE 3 /* used also as a state */
62 #define SH_MONITOR 4 /* used also as a state */
63 #define SH_INTERACTIVE 5 /* used also as a state */
64 #define SH_RESTRICTED 6
69 #define SH_ALLEXPORT 11
71 #define SH_IGNOREEOF 13
72 #define SH_NOCLOBBER 14
73 #define SH_MARKDIRS 15
78 #define SH_TRACKALL 20
83 #define SH_PRIVILEGED 26
84 #define SH_SUBSHARE 27 /* subshell shares state with parent */
87 #define SH_DICTIONARY 30
88 #define SH_PIPEFAIL 32
89 #define SH_GLOBSTARS 33
95 * passed as flags to builtins in Nambltin_t struct when BLT_OPTIM is on
97 #define SH_BEGIN_OPTIM 0x1
98 #define SH_END_OPTIM 0x2
100 /* The following type is used for error messages */
103 extern const char e_defpath
[];
104 extern const char e_found
[];
105 extern const char e_nospace
[];
106 extern const char e_format
[];
107 extern const char e_number
[];
108 extern const char e_restricted
[];
109 extern const char e_recursive
[];
110 extern char e_version
[];
112 typedef struct sh_scope
114 struct sh_scope
*par_scope
;
122 struct sh_scope
*self
;
126 * Saves the state of the shell
131 Shopt_t options
; /* set -o options */
132 Dt_t
*var_tree
; /* for shell variables */
133 Dt_t
*fun_tree
; /* for shell functions */
134 Dt_t
*alias_tree
; /* for alias names */
135 Dt_t
*bltin_tree
; /* for builtin commands */
136 Shscope_t
*topscope
; /* pointer to top-level scope */
137 int inlineno
; /* line number of current input file */
138 int exitval
; /* most recent exit value */
139 unsigned char trapnote
; /* set when trap/signal is pending */
140 char shcomp
; /* set when runing shcomp */
141 short subshell
; /* set for virtual subshell */
144 #endif /* _SH_PRIVATE */
147 /* flags for sh_parse */
148 #define SH_NL 1 /* Treat new-lines as ; */
149 #define SH_EOF 2 /* EOF causes syntax error */
151 /* symbolic values for sh_iogetiop */
152 #define SH_IOCOPROCESS (-2)
153 #define SH_IOHISTFILE (-3)
157 /* symbolic value for sh_fdnotify */
158 #define SH_FDCLOSE (-1)
160 #undef getenv /* -lshell provides its own */
162 #if defined(__EXPORT__) && defined(_DLL)
164 # define extern __EXPORT__
165 # endif /* _BLD_shell */
168 extern Dt_t
*sh_bltin_tree(void);
169 extern void sh_subfork(void);
170 extern Shell_t
*sh_init(int,char*[],Shinit_f
);
171 extern int sh_reinit(char*[]);
172 extern int sh_eval(Sfio_t
*,int);
173 extern void sh_delay(double);
174 extern void *sh_parse(Shell_t
*, Sfio_t
*,int);
175 extern int sh_trap(const char*,int);
176 extern int sh_fun(Namval_t
*,Namval_t
*, char*[]);
177 extern int sh_funscope(int,char*[],int(*)(void*),void*,int);
178 extern Sfio_t
*sh_iogetiop(int,int);
179 extern int sh_main(int, char*[], Shinit_f
);
180 extern int sh_run(int, char*[]);
181 extern void sh_menu(Sfio_t
*, int, char*[]);
182 extern Namval_t
*sh_addbuiltin(const char*, int(*)(int, char*[],void*), void*);
183 extern char *sh_fmtq(const char*);
184 extern char *sh_fmtqf(const char*, int, int);
185 extern Sfdouble_t
sh_strnum(const char*, char**, int);
186 extern int sh_access(const char*,int);
187 extern int sh_close(int);
188 extern int sh_dup(int);
189 extern void sh_exit(int);
190 extern int sh_fcntl(int, int, ...);
191 extern Sfio_t
*sh_fd2sfio(int);
192 extern int (*sh_fdnotify(int(*)(int,int)))(int,int);
193 extern Shell_t
*sh_getinterp(void);
194 extern int sh_open(const char*, int, ...);
195 extern int sh_openmax(void);
196 extern Sfio_t
*sh_pathopen(const char*);
197 extern ssize_t
sh_read(int, void*, size_t);
198 extern ssize_t
sh_write(int, const void*, size_t);
199 extern off_t
sh_seek(int, off_t
, int);
200 extern int sh_pipe(int[]);
201 extern mode_t
sh_umask(mode_t
);
202 extern void *sh_waitnotify(Shwait_f
);
203 extern Shscope_t
*sh_getscope(int,int);
204 extern Shscope_t
*sh_setscope(Shscope_t
*);
205 extern void sh_sigcheck(void);
206 extern unsigned long sh_isoption(int);
207 extern unsigned long sh_onoption(int);
208 extern unsigned long sh_offoption(int);
209 extern int sh_waitsafe(void);
210 extern int sh_exec(const Shnode_t
*,int);
213 extern void **sh_getliblist(void);
214 #endif /* SHOPT_DYNAMIC */
217 * direct access to sh is obsolete, use sh_getinterp() instead
219 #if !defined(_SH_PRIVATE) && defined(__IMPORT__) && !defined(_BLD_shell)
220 extern __IMPORT__ Shell_t sh
;
230 # define access(a,b) sh_access(a,b)
231 # define close(a) sh_close(a)
232 # define exit(a) sh_exit(a)
233 # define fcntl(a,b,c) sh_fcntl(a,b,c)
234 # define pipe(a) sh_pipe(a)
235 # define read(a,b,c) sh_read(a,b,c)
236 # define write(a,b,c) sh_write(a,b,c)
237 # define umask(a) sh_umask(a)
240 # define open64 sh_open
241 # define lseek64 sh_seek
243 # define open sh_open
244 # define lseek sh_seek
246 #endif /* !_SH_PRIVATE */
249 #define SH_EXITSIG 0400 /* signal exit bit */
250 #define SH_EXITMASK (SH_EXITSIG-1) /* normal exit status bits */
251 #define SH_RUNPROG -1022 /* needs to be negative and < 256 */
253 #endif /* SH_INTERACTIVE */