summaryrefslogtreecommitdiff
path: root/usr/src/lib/libshell/common/include
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libshell/common/include')
-rw-r--r--usr/src/lib/libshell/common/include/argnod.h147
-rw-r--r--usr/src/lib/libshell/common/include/builtins.h200
-rw-r--r--usr/src/lib/libshell/common/include/defs.h377
-rw-r--r--usr/src/lib/libshell/common/include/edit.h257
-rw-r--r--usr/src/lib/libshell/common/include/env.h50
-rw-r--r--usr/src/lib/libshell/common/include/fault.h124
-rw-r--r--usr/src/lib/libshell/common/include/fcin.h62
-rw-r--r--usr/src/lib/libshell/common/include/history.h75
-rw-r--r--usr/src/lib/libshell/common/include/io.h123
-rw-r--r--usr/src/lib/libshell/common/include/jobs.h159
-rw-r--r--usr/src/lib/libshell/common/include/lexstates.h151
-rw-r--r--usr/src/lib/libshell/common/include/name.h208
-rw-r--r--usr/src/lib/libshell/common/include/national.h37
-rw-r--r--usr/src/lib/libshell/common/include/nval.h305
-rw-r--r--usr/src/lib/libshell/common/include/path.h140
-rw-r--r--usr/src/lib/libshell/common/include/shell.h245
-rw-r--r--usr/src/lib/libshell/common/include/shlex.h152
-rw-r--r--usr/src/lib/libshell/common/include/shnodes.h222
-rw-r--r--usr/src/lib/libshell/common/include/shtable.h65
-rw-r--r--usr/src/lib/libshell/common/include/streval.h195
-rw-r--r--usr/src/lib/libshell/common/include/terminal.h195
-rw-r--r--usr/src/lib/libshell/common/include/test.h71
-rw-r--r--usr/src/lib/libshell/common/include/timeout.h30
-rw-r--r--usr/src/lib/libshell/common/include/ulimit.h175
-rw-r--r--usr/src/lib/libshell/common/include/variables.h104
-rw-r--r--usr/src/lib/libshell/common/include/version.h20
26 files changed, 3889 insertions, 0 deletions
diff --git a/usr/src/lib/libshell/common/include/argnod.h b/usr/src/lib/libshell/common/include/argnod.h
new file mode 100644
index 0000000000..fd93e5b215
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/argnod.h
@@ -0,0 +1,147 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef ARG_RAW
+/*
+ * struct to hold a word argument
+ * Written by David Korn
+ *
+ */
+
+#include <stak.h>
+
+struct ionod
+{
+ unsigned iofile;
+ char *ioname;
+ struct ionod *ionxt;
+ struct ionod *iolst;
+ char *iodelim;
+ off_t iooffset;
+ long iosize;
+ char *iovname;
+};
+
+struct comnod
+{
+ int comtyp;
+ struct ionod *comio;
+ struct argnod *comarg;
+ struct argnod *comset;
+ void *comnamp;
+ void *comnamq;
+ void *comstate;
+ int comline;
+};
+
+#define COMBITS 4
+#define COMMSK ((1<<COMBITS)-1)
+#define COMSCAN (01<<COMBITS)
+#define COMFIXED (02<<COMBITS)
+
+struct slnod /* struct for link list of stacks */
+{
+ struct slnod *slnext;
+ struct slnod *slchild;
+ Stak_t *slptr;
+};
+
+/*
+ * This struct is use to hold $* lists and arrays
+ */
+
+struct dolnod
+{
+ short dolrefcnt; /* reference count */
+ short dolmax; /* size of dolval array */
+ short dolnum; /* number of elements */
+ short dolbot; /* current first element */
+ struct dolnod *dolnxt; /* used when list are chained */
+ char *dolval[1]; /* array of value pointers */
+};
+
+/*
+ * This struct is used to hold word arguments of variable size during
+ * parsing and during expansion. The flags indicate what processing
+ * is required on the argument.
+ */
+
+struct argnod
+{
+ union
+ {
+ struct argnod *ap;
+ char *cp;
+ } argnxt;
+ union
+ {
+ struct argnod *ap;
+ char *cp;
+ int len;
+ } argchn;
+ unsigned char argflag;
+ char argval[4];
+};
+
+
+
+/* The following should evaluate to the offset of argval in argnod */
+#define ARGVAL offsetof(struct argnod,argval[0])
+#define sh_argstr(ap) ((ap)->argflag&ARG_RAW?sh_fmtq((ap)->argval):(ap)->argval)
+#define ARG_SPARE 1
+
+
+/* legal argument flags */
+#define ARG_RAW 0x1 /* string needs no processing */
+#define ARG_MAKE 0x2 /* bit set during argument expansion */
+#define ARG_COMSUB 0x2 /* command sub */
+#define ARG_MAC 0x4 /* string needs macro expansion */
+#define ARG_EXP 0x8 /* string needs file expansion */
+#define ARG_ASSIGN 0x10 /* argument is an assignment */
+#define ARG_QUOTED 0x20 /* word contained quote characters */
+#define ARG_MESSAGE 0x40 /* contains international string */
+#define ARG_APPEND 0x80 /* for += assignment */
+/* The following can be passed as options to sh_macexpand() */
+#define ARG_ARITH 0x100 /* arithmetic expansion */
+#define ARG_OPTIMIZE 0x200 /* try to optimize */
+#define ARG_NOGLOB 0x400 /* no file name expansion */
+#define ARG_LET 0x800 /* processing let command arguments */
+
+extern char **sh_argbuild(int*,const struct comnod*,int);
+extern struct dolnod *sh_argcreate(char*[]);
+extern char *sh_argdolminus(void);
+extern struct dolnod *sh_argfree(struct dolnod*,int);
+extern struct dolnod *sh_argnew(char*[],struct dolnod**);
+extern int sh_argopts(int,char*[]);
+extern void sh_argreset(struct dolnod*,struct dolnod*);
+extern void sh_argset(char*[]);
+extern struct dolnod *sh_arguse(void);
+
+extern const char e_heading[];
+extern const char e_off[];
+extern const char e_on[];
+extern const char e_sptbnl[];
+extern const char e_subst[];
+extern const char e_option[];
+extern const char e_exec[];
+extern const char e_devfdNN[];
+extern const char e_devfdstd[];
+
+#endif /* ARG_RAW */
diff --git a/usr/src/lib/libshell/common/include/builtins.h b/usr/src/lib/libshell/common/include/builtins.h
new file mode 100644
index 0000000000..8c79075fce
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/builtins.h
@@ -0,0 +1,200 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+#ifndef SYSDECLARE
+
+#include <option.h>
+#include "FEATURE/options"
+#include "FEATURE/dynamic"
+#include "shtable.h"
+
+#define SYSLOGIN (sh.bltin_cmds)
+#define SYSEXEC (sh.bltin_cmds+1)
+#define SYSSET (sh.bltin_cmds+2)
+#define SYSTRUE (sh.bltin_cmds+4)
+#define SYSCOMMAND (sh.bltin_cmds+5)
+#define SYSCD (sh.bltin_cmds+6)
+#define SYSBREAK (sh.bltin_cmds+7)
+#define SYSCONT (sh.bltin_cmds+8)
+#define SYSTYPESET (sh.bltin_cmds+9)
+#define SYSTEST (sh.bltin_cmds+10)
+#define SYSBRACKET (sh.bltin_cmds+11)
+#define SYSLET (sh.bltin_cmds+12)
+#define SYSEXPORT (sh.bltin_cmds+13)
+#if SHOPT_BASH
+# define SYSLOCAL (sh.bltin_cmds+14)
+#else
+# define SYSLOCAL 0
+#endif
+
+/* entry point for shell special builtins */
+
+#if _BLD_shell && defined(__EXPORT__)
+# define extern __EXPORT__
+#endif
+
+extern int b_alias(int, char*[],void*);
+extern int b_break(int, char*[],void*);
+extern int b_dot_cmd(int, char*[],void*);
+extern int b_exec(int, char*[],void*);
+extern int b_eval(int, char*[],void*);
+extern int b_return(int, char*[],void*);
+extern int B_login(int, char*[],void*);
+extern int b_true(int, char*[],void*);
+extern int b_false(int, char*[],void*);
+extern int b_readonly(int, char*[],void*);
+extern int b_set(int, char*[],void*);
+extern int b_shift(int, char*[],void*);
+extern int b_trap(int, char*[],void*);
+extern int b_typeset(int, char*[],void*);
+extern int b_unset(int, char*[],void*);
+extern int b_unalias(int, char*[],void*);
+
+/* The following are for job control */
+#if defined(SIGCLD) || defined(SIGCHLD)
+ extern int b_jobs(int, char*[],void*);
+ extern int b_kill(int, char*[],void*);
+# ifdef SIGTSTP
+ extern int b_bg(int, char*[],void*);
+# endif /* SIGTSTP */
+#endif
+
+/* The following utilities are built-in because of side-effects */
+extern int b_builtin(int, char*[],void*);
+extern int b_cd(int, char*[],void*);
+extern int b_command(int, char*[],void*);
+extern int b_getopts(int, char*[],void*);
+extern int b_hist(int, char*[],void*);
+extern int b_let(int, char*[],void*);
+extern int b_read(int, char*[],void*);
+extern int b_ulimit(int, char*[],void*);
+extern int b_umask(int, char*[],void*);
+#ifdef _cmd_universe
+ extern int b_universe(int, char*[],void*);
+#endif /* _cmd_universe */
+#if SHOPT_FS_3D
+ extern int b_vpath(int, char*[],void*);
+#endif /* SHOPT_FS_3D */
+extern int b_wait(int, char*[],void*);
+extern int b_whence(int, char*[],void*);
+
+extern int b_alarm(int, char*[],void*);
+extern int b_print(int, char*[],void*);
+extern int b_printf(int, char*[],void*);
+extern int b_pwd(int, char*[],void*);
+extern int b_sleep(int, char*[],void*);
+extern int b_test(int, char*[],void*);
+#if !SHOPT_ECHOPRINT
+ extern int B_echo(int, char*[],void*);
+#endif /* SHOPT_ECHOPRINT */
+
+#undef extern
+
+extern const char e_alrm1[];
+extern const char e_alrm2[];
+extern const char e_badfun[];
+extern const char e_baddisc[];
+extern const char e_nofork[];
+extern const char e_nosignal[];
+extern const char e_nolabels[];
+extern const char e_notimp[];
+extern const char e_nosupport[];
+extern const char e_badbase[];
+extern const char e_overlimit[];
+
+extern const char e_eneedsarg[];
+extern const char e_toodeep[];
+extern const char e_badname[];
+extern const char e_badwrite[];
+extern const char e_badsyntax[];
+#ifdef _cmd_universe
+ extern const char e_nouniverse[];
+#endif /* _cmd_universe */
+extern const char e_histopen[];
+extern const char e_condition[];
+extern const char e_badrange[];
+extern const char e_numeric[];
+extern const char e_trap[];
+extern const char e_direct[];
+extern const char e_defedit[];
+extern const char e_cneedsarg[];
+extern const char e_defined[];
+#if SHOPT_FS_3D
+ extern const char e_cantset[];
+ extern const char e_cantget[];
+ extern const char e_mapping[];
+ extern const char e_versions[];
+#endif /* SHOPT_FS_3D */
+
+/* for option parsing */
+extern const char sh_set[];
+extern const char sh_optalarm[];
+extern const char sh_optalias[];
+extern const char sh_optbreak[];
+extern const char sh_optbuiltin[];
+extern const char sh_optcd[];
+extern const char sh_optcommand[];
+extern const char sh_optcont[];
+extern const char sh_optdot[];
+#ifndef ECHOPRINT
+ extern const char sh_optecho[];
+#endif /* !ECHOPRINT */
+extern const char sh_opteval[];
+extern const char sh_optexec[];
+extern const char sh_optexit[];
+extern const char sh_optexport[];
+extern const char sh_optgetopts[];
+extern const char sh_optbg[];
+extern const char sh_optdisown[];
+extern const char sh_optfg[];
+extern const char sh_opthist[];
+extern const char sh_optjobs[];
+extern const char sh_optkill[];
+extern const char sh_optksh[];
+extern const char sh_optlet[];
+extern const char sh_optprint[];
+extern const char sh_optprintf[];
+extern const char sh_optpwd[];
+extern const char sh_optread[];
+extern const char sh_optreadonly[];
+extern const char sh_optreturn[];
+extern const char sh_optset[];
+extern const char sh_optshift[];
+extern const char sh_optsleep[];
+extern const char sh_opttrap[];
+extern const char sh_opttypeset[];
+extern const char sh_optulimit[];
+extern const char sh_optumask[];
+extern const char sh_optunalias[];
+extern const char sh_optwait[];
+#ifdef _cmd_universe
+ extern const char sh_optuniverse[];
+#endif /* _cmd_universe */
+extern const char sh_optunset[];
+#if SHOPT_FS_3D
+ extern const char sh_optvpath[];
+ extern const char sh_optvmap[];
+#endif /* SHOPT_FS_3D */
+extern const char sh_optwhence[];
+#endif /* SYSDECLARE */
+
+extern const char e_dict[];
+
diff --git a/usr/src/lib/libshell/common/include/defs.h b/usr/src/lib/libshell/common/include/defs.h
new file mode 100644
index 0000000000..91a3d2c3e1
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/defs.h
@@ -0,0 +1,377 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * David Korn
+ * AT&T Labs
+ *
+ * Shell interface private definitions
+ *
+ */
+
+#include <ast.h>
+#include <sfio.h>
+#include <error.h>
+#include "FEATURE/options"
+#include <cdt.h>
+#include <history.h>
+#include "fault.h"
+#include "argnod.h"
+
+#ifndef pointerof
+#define pointerof(x) ((void*)((char*)0+(x)))
+#endif
+
+#define env_change() (++ast.env_serial)
+#if SHOPT_ENV
+# include <env.h>
+#else
+# define Env_t void
+# define sh_envput(e,p) env_change()
+# define env_delete(e,p) env_change()
+#endif
+
+/*
+ * note that the first few fields have to be the same as for
+ * Shscoped_t in <shell.h>
+ */
+struct sh_scoped
+{
+ struct sh_scoped *prevst; /* pointer to previous state */
+ int dolc;
+ char **dolv;
+ char *cmdname;
+ char *filename;
+ int lineno;
+ Dt_t *save_tree; /* var_tree for calling function */
+ struct sh_scoped *self; /* pointer to copy of this scope*/
+ Dt_t *var_local; /* local level variables for name() */
+ struct slnod *staklist; /* link list of function stacks */
+ int states;
+ int breakcnt;
+ int execbrk;
+ int loopcnt;
+ int firstline;
+ int32_t optindex;
+ int32_t optnum;
+ int32_t tmout; /* value for TMOUT */
+ short optchar;
+ short opterror;
+ int ioset;
+ unsigned short trapmax;
+ char *trap[SH_DEBUGTRAP+1];
+ char **trapcom;
+ char **otrapcom;
+ void *timetrap;
+};
+
+struct limits
+{
+ long arg_max; /* max arg+env exec() size */
+ int open_max; /* maximum number of file descriptors */
+ int clk_tck; /* number of ticks per second */
+ int child_max; /* maxumum number of children */
+ int ngroups_max; /* maximum number of process groups */
+ unsigned char posix_version; /* posix version number */
+ unsigned char posix_jobcontrol;/* non-zero for job control systems */
+ unsigned char fs3d; /* non-zero for 3-d file system */
+};
+
+#define _SH_PRIVATE \
+ struct sh_scoped st; /* scoped information */ \
+ struct limits lim; /* run time limits */ \
+ Sfio_t *heredocs; /* current here-doc temp file */ \
+ Sfio_t *funlog; /* for logging function definitions */ \
+ int **fdptrs; /* pointer to file numbers */ \
+ int savexit; \
+ char *lastarg; \
+ char *lastpath; /* last alsolute path found */ \
+ int path_err; /* last error on path search */ \
+ Dt_t *track_tree; /* for tracked aliases*/ \
+ Namval_t *bltin_nodes; /* pointer to built-in variables */ \
+ Dt_t *var_base; /* global level variables */ \
+ Namval_t *namespace; /* current active namespace*/ \
+ Namval_t *last_table; /* last table used in last nv_open */ \
+ Sfio_t *outpool; /* ouput stream pool */ \
+ long timeout; /* read timeout */ \
+ short curenv; /* current subshell number */ \
+ short jobenv; /* subshell number for jobs */ \
+ int nextprompt; /* next prompt is PS<nextprompt> */ \
+ Namval_t *bltin_cmds; /* pointer to built-in commands */ \
+ Namval_t *posix_fun; /* points to last name() function */ \
+ int infd; /* input file descriptor */ \
+ char *outbuff; /* pointer to output buffer */ \
+ char *errbuff; /* pointer to stderr buffer */ \
+ char *prompt; /* pointer to prompt string */ \
+ char *shname; /* shell name */ \
+ char *shpath; /* path name of shell */ \
+ char *user; /* name of real user for pfsh */ \
+ char *comdiv; /* points to sh -c argument */ \
+ char *prefix; /* prefix for compound assignment */ \
+ sigjmp_buf *jmplist; /* longjmp return stack */ \
+ char **sigmsg; /* points to signal messages */ \
+ int oldexit; \
+ uid_t userid,euserid; /* real and effective user id */ \
+ gid_t groupid,egroupid;/* real and effective group id */ \
+ pid_t pid; /* process id of shell */ \
+ pid_t bckpid; /* background process id */ \
+ pid_t cpid; \
+ int32_t ppid; /* parent process id of shell */ \
+ int topfd; \
+ int sigmax; /* maximum number of signals */ \
+ int savesig; \
+ unsigned char *sigflag; /* pointer to signal states */ \
+ char intrap; \
+ char login_sh; \
+ char lastbase; \
+ char forked; \
+ char binscript; \
+ char deftype; \
+ char used_pos; /* used postional parameter */\
+ unsigned char lastsig; /* last signal received */ \
+ char *readscript; /* set before reading a script */ \
+ int *inpipe; /* input pipe pointer */ \
+ int *outpipe; /* output pipe pointer */ \
+ int cpipe[2]; \
+ int coutpipe; \
+ int inuse_bits; \
+ struct argnod *envlist; \
+ struct dolnod *arglist; \
+ int fn_depth; \
+ int dot_depth; \
+ int hist_depth; \
+ int xargmin; \
+ int xargmax; \
+ int xargexit; \
+ mode_t mask; \
+ long nforks; \
+ Env_t *env; \
+ void *init_context; \
+ void *mac_context; \
+ void *lex_context; \
+ void *arg_context; \
+ void *ed_context; \
+ void *job_context; \
+ void *pathlist; \
+ void *defpathlist; \
+ void *cdpathlist; \
+ char **argaddr; \
+ void *optlist; \
+ int optcount ; \
+ struct sh_scoped global; \
+ struct checkpt checkbase; \
+ Shinit_f userinit; \
+ Shbltin_f bltinfun; \
+ Shwait_f waitevent; \
+ char *cur_line; \
+ char *rcfile; \
+ char **login_files; \
+ short offsets[10]; \
+ Sfio_t **sftable; \
+ unsigned char *fdstatus; \
+ const char *pwd; \
+ History_t *hist_ptr; \
+ char universe; \
+ void *jmpbuffer; \
+ void *mktype; \
+ Sfio_t *strbuf; \
+ Dt_t *last_root; \
+ char ifstable[256]; \
+ Shopt_t offoptions;
+
+#include <shell.h>
+
+
+/* error exits from various parts of shell */
+#define NIL(type) ((type)0)
+
+#define new_of(type,x) ((type*)malloc((unsigned)sizeof(type)+(x)))
+
+#define exitset() (sh.savexit=sh.exitval)
+
+#ifndef SH_DICT
+#define SH_DICT (void*)e_dict
+#endif
+
+#ifndef SH_CMDLIB_DIR
+#define SH_CMDLIB_DIR "/opt/ast/bin"
+#endif
+
+/* states */
+/* low numbered states are same as options */
+#define SH_NOFORK 0 /* set when fork not necessary, not a state */
+#define SH_COMPLETE 0 /* set for command completion */
+#define SH_FORKED 7 /* set when process has been forked */
+#define SH_PROFILE 8 /* set when processing profiles */
+#define SH_NOALIAS 9 /* do not expand non-exported aliases */
+#define SH_NOTRACK 10 /* set to disable sftrack() function */
+#define SH_STOPOK 11 /* set for stopable builtins */
+#define SH_GRACE 12 /* set for timeout grace period */
+#define SH_TIMING 13 /* set while timing pipelines */
+#define SH_DEFPATH 14 /* set when using default path */
+#define SH_INIT 15 /* set when initializing the shell */
+#define SH_TTYWAIT 16 /* waiting for keyboard input */
+#define SH_FCOMPLETE 17 /* set for filename completion */
+#define SH_PREINIT 18 /* set with SH_INIT before parsing options */
+
+#define SH_BASH 41
+#define SH_BRACEEXPAND 42
+#define SH_POSIX 46
+#define SH_MULTILINE 47
+
+#define SH_NOPROFILE 78
+#define SH_NOUSRPROFILE 79
+#define SH_LOGIN_SHELL 67
+#define SH_COMMANDLINE 0x100
+#define SH_BASHEXTRA 0x200
+#define SH_BASHOPT 0x400
+
+#define SH_ID "ksh" /* ksh id */
+#define SH_STD "sh" /* standard sh id */
+
+/* defines for sh_type() */
+
+#define SH_TYPE_SH 001
+#define SH_TYPE_KSH 002
+#define SH_TYPE_BASH 004
+#define SH_TYPE_LOGIN 010
+#define SH_TYPE_PROFILE 020
+#define SH_TYPE_RESTRICTED 040
+
+#if SHOPT_BASH
+# ifndef SHOPT_HISTEXPAND
+# define SHOPT_HISTEXPAND 1
+# endif
+/*
+ * define for all the bash options
+ */
+# define SH_CDABLE_VARS 51
+# define SH_CDSPELL 52
+# define SH_CHECKHASH 53
+# define SH_CHECKWINSIZE 54
+# define SH_CMDHIST 55
+# define SH_DOTGLOB 56
+# define SH_EXECFAIL 57
+# define SH_EXPAND_ALIASES 58
+# define SH_EXTGLOB 59
+# define SH_HOSTCOMPLETE 63
+# define SH_HUPONEXIT 64
+# define SH_INTERACTIVE_COMM 65
+# define SH_LITHIST 66
+# define SH_MAILWARN 68
+# define SH_NOEMPTYCMDCOMPL 69
+# define SH_NOCASEGLOB 70
+# define SH_NULLGLOB 71
+# define SH_PHYSICAL 45
+# define SH_PROGCOMP 72
+# define SH_PROMPTVARS 73
+# define SH_RESTRICTED2 74
+# define SH_SHIFT_VERBOSE 75
+# define SH_SOURCEPATH 76
+# define SH_XPG_ECHO 77
+#endif
+
+#if SHOPT_HISTEXPAND
+# define SH_HISTAPPEND 60
+# define SH_HISTEXPAND 43
+# define SH_HISTORY2 44
+# define SH_HISTREEDIT 61
+# define SH_HISTVERIFY 62
+#endif
+
+#ifndef PIPE_BUF
+# define PIPE_BUF 512
+#endif
+
+#define MATCH_MAX 64
+
+extern int sh_addlib(void*);
+extern void *sh_argopen(Shell_t*);
+extern Namval_t *sh_assignok(Namval_t*,int);
+extern char *sh_checkid(char*,char*);
+extern int sh_debug(const char*,const char*,const char*,char *const[],int);
+extern int sh_echolist(Sfio_t*, int, char**);
+extern struct argnod *sh_endword(int);
+extern char **sh_envgen(void);
+#if SHOPT_ENV
+extern void sh_envput(Env_t*, Namval_t*);
+#endif
+extern void sh_envnolocal(Namval_t*,void*);
+extern Sfdouble_t sh_arith(const char*);
+extern void *sh_arithcomp(char*);
+extern pid_t sh_fork(int,int*);
+extern pid_t _sh_fork(pid_t, int ,int*);
+extern char *sh_mactrim(char*,int);
+extern int sh_macexpand(struct argnod*,struct argnod**,int);
+extern void sh_machere(Sfio_t*, Sfio_t*, char*);
+extern void *sh_macopen(Shell_t*);
+extern char *sh_macpat(struct argnod*,int);
+extern char *sh_mactry(char*);
+extern void sh_printopts(Shopt_t,int,Shopt_t*);
+extern int sh_readline(Shell_t*,char**,int,int,long);
+extern Sfio_t *sh_sfeval(char*[]);
+extern void sh_setmatch(const char*,int,int,int[]);
+extern Dt_t *sh_subaliastree(int);
+extern Dt_t *sh_subfuntree(int);
+extern int sh_subsavefd(int);
+extern void sh_subtmpfile(void);
+extern char *sh_substitute(const char*,const char*,char*);
+extern const char *_sh_translate(const char*);
+extern int sh_trace(char*[],int);
+extern void sh_trim(char*);
+extern int sh_type(const char*);
+extern void sh_utol(const char*, char*);
+extern int sh_whence(char**,int);
+
+#ifndef ERROR_dictionary
+# define ERROR_dictionary(s) (s)
+#endif
+#define sh_translate(s) _sh_translate(ERROR_dictionary(s))
+
+#define WBITS (sizeof(long)*8)
+#define WMASK (0xff)
+
+#define is_option(s,x) ((s)->v[((x)&WMASK)/WBITS] & (1L << ((x) % WBITS)))
+#define on_option(s,x) ((s)->v[((x)&WMASK)/WBITS] |= (1L << ((x) % WBITS)))
+#define off_option(s,x) ((s)->v[((x)&WMASK)/WBITS] &= ~(1L << ((x) % WBITS)))
+#define sh_isoption(x) is_option(&sh.options,x)
+#define sh_onoption(x) on_option(&sh.options,x)
+#define sh_offoption(x) off_option(&sh.options,x)
+
+
+#define sh_state(x) ( 1<<(x))
+#define sh_isstate(x) (sh.st.states&sh_state(x))
+#define sh_onstate(x) (sh.st.states |= sh_state(x))
+#define sh_offstate(x) (sh.st.states &= ~sh_state(x))
+#define sh_getstate() (sh.st.states)
+#define sh_setstate(x) (sh.st.states = (x))
+
+#define sh_sigcheck() do{if(sh.trapnote&SH_SIGSET)sh_exit(SH_EXITSIG);} while(0)
+
+extern int32_t sh_mailchk;
+extern const char e_dict[];
+
+/* sh_printopts() mode flags -- set --[no]option by default */
+
+#define PRINT_VERBOSE 0x01 /* option on|off list */
+#define PRINT_ALL 0x02 /* list unset iptions too */
+#define PRINT_NO_HEADER 0x04 /* omit listing header */
+#define PRINT_SHOPT 0x08 /* shopt -s|-u */
+#define PRINT_TABLE 0x10 /* table of all options */
diff --git a/usr/src/lib/libshell/common/include/edit.h b/usr/src/lib/libshell/common/include/edit.h
new file mode 100644
index 0000000000..ddbd45c24b
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/edit.h
@@ -0,0 +1,257 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef SEARCHSIZE
+/*
+ * edit.h - common data structure for vi and emacs edit options
+ *
+ * David Korn
+ * AT&T Labs
+ *
+ */
+
+#define SEARCHSIZE 80
+
+#include "FEATURE/options"
+#include "FEATURE/locale"
+#if !SHOPT_VSH && !SHOPT_ESH
+# define ed_winsize() (SEARCHSIZE)
+#else
+
+#if !KSHELL
+# include <setjmp.h>
+# include <sig.h>
+# include <ctype.h>
+#endif /* KSHELL */
+
+#include "FEATURE/setjmp"
+#include "terminal.h"
+
+#define STRIP 0377
+#define LOOKAHEAD 80
+
+#if SHOPT_MULTIBYTE
+# ifndef ESS_MAXCHAR
+# include "national.h"
+# endif /* ESS_MAXCHAR */
+ typedef wchar_t genchar;
+# define CHARSIZE (sizeof(wchar_t)<=2?3:sizeof(wchar_t))
+#else
+ typedef char genchar;
+# define CHARSIZE 1
+#endif /* SHOPT_MULTIBYTE */
+
+#define TABSIZE 8
+#define PRSIZE 160
+#define MAXLINE 1024 /* longest edit line permitted */
+
+typedef struct _edit_pos
+{
+ unsigned short line;
+ unsigned short col;
+} Edpos_t;
+
+typedef struct edit
+{
+ sigjmp_buf e_env;
+ int e_kill;
+ int e_erase;
+ int e_werase;
+ int e_eof;
+ int e_lnext;
+ int e_fchar;
+ int e_plen; /* length of prompt string */
+ int e_crlf; /* zero if cannot return to beginning of line */
+ int e_llimit; /* line length limit */
+ int e_hline; /* current history line number */
+ int e_hloff; /* line number offset for command */
+ int e_hismin; /* minimum history line number */
+ int e_hismax; /* maximum history line number */
+ int e_raw; /* set when in raw mode or alt mode */
+ int e_cur; /* current line position */
+ int e_eol; /* end-of-line position */
+ int e_pcur; /* current physical line position */
+ int e_peol; /* end of physical line position */
+ int e_mode; /* edit mode */
+ int e_lookahead; /* index in look-ahead buffer */
+ int e_repeat;
+ int e_saved;
+ int e_fcol; /* first column */
+ int e_ucol; /* column for undo */
+ int e_wsize; /* width of display window */
+ char *e_outbase; /* pointer to start of output buffer */
+ char *e_outptr; /* pointer to position in output buffer */
+ char *e_outlast; /* pointer to end of output buffer */
+ genchar *e_inbuf; /* pointer to input buffer */
+ char *e_prompt; /* pointer to buffer containing the prompt */
+ genchar *e_ubuf; /* pointer to the undo buffer */
+ genchar *e_killbuf; /* pointer to delete buffer */
+ char e_search[SEARCHSIZE]; /* search string */
+ genchar *e_Ubuf; /* temporary workspace buffer */
+ genchar *e_physbuf; /* temporary workspace buffer */
+ int e_lbuf[LOOKAHEAD];/* pointer to look-ahead buffer */
+ int e_fd; /* file descriptor */
+ int e_ttyspeed; /* line speed, also indicates tty parms are valid */
+ int e_tabcount;
+#ifdef _hdr_utime
+ ino_t e_tty_ino;
+ dev_t e_tty_dev;
+ char *e_tty;
+#endif
+#if SHOPT_OLDTERMIO
+ char e_echoctl;
+ char e_tcgeta;
+ struct termio e_ott;
+#endif
+#if SHOPT_MULTIBYTE
+ int e_curchar;
+ int e_cursize;
+#endif
+ int *e_globals; /* global variables */
+ genchar *e_window; /* display window image */
+ char e_inmacro; /* processing macro expansion */
+#if KSHELL
+ char e_vi_insert[2]; /* for sh_keytrap */
+ int32_t e_col; /* for sh_keytrap */
+#else
+ char e_prbuff[PRSIZE]; /* prompt buffer */
+#endif /* KSHELL */
+ struct termios e_ttyparm; /* initial tty parameters */
+ struct termios e_nttyparm; /* raw tty parameters */
+ struct termios e_savetty; /* saved terminal state */
+ int e_savefd; /* file descriptor for saved terminal state */
+ char e_macro[4]; /* macro buffer */
+ void *e_vi; /* vi specific data */
+ void *e_emacs; /* emacs specific data */
+ Shell_t *sh; /* interpreter pointer */
+ char *e_stkptr; /* saved stack pointer */
+ int e_stkoff; /* saved stack offset */
+ char **e_clist; /* completion list after <ESC>= */
+ int e_nlist; /* number of elements on completion list */
+ int e_multiline; /* allow multiple lines for editing */
+ int e_winsz; /* columns in window */
+ Edpos_t e_curpos; /* cursor line and column */
+ Namval_t *e_default; /* variable containing default value */
+ Namval_t *e_term; /* TERM variable */
+ char e_termname[80]; /* terminal name */
+} Edit_t;
+
+#undef MAXWINDOW
+#define MAXWINDOW 300 /* maximum width window */
+#define FAST 2
+#define SLOW 1
+#define ESC cntl('[')
+#define UEOF -2 /* user eof char synonym */
+#define UINTR -3 /* user intr char synonym */
+#define UERASE -4 /* user erase char synonym */
+#define UKILL -5 /* user kill char synonym */
+#define UWERASE -6 /* user word erase char synonym */
+#define ULNEXT -7 /* user next literal char synonym */
+
+#if ( 'a' == 97) /* ASCII? */
+# define cntl(x) (x&037)
+#else
+# define cntl(c) (c=='D'?55:(c=='E'?45:(c=='F'?46:(c=='G'?'\a':(c=='H'?'\b': \
+ (c=='I'?'\t':(c=='J'?'\n':(c=='T'?60:(c=='U'?61:(c=='V'?50: \
+ (c=='W'?38:(c=='Z'?63:(c=='['?39:(c==']'?29: \
+ (c<'J'?c+1-'A':(c+10-'J'))))))))))))))))
+#endif
+
+#if !KSHELL
+# define STRIP 0377
+# define GMACS 1
+# define EMACS 2
+# define VIRAW 4
+# define EDITVI 8
+# define NOHIST 16
+# define EDITMASK 15
+# define is_option(m) (opt_flag&(m))
+ extern char opt_flag;
+# ifdef SYSCALL
+# define read(fd,buff,n) syscall(3,fd,buff,n)
+# else
+# define read(fd,buff,n) rEAd(fd,buff,n)
+# endif /* SYSCALL */
+#endif /* KSHELL */
+
+extern void ed_crlf(Edit_t*);
+extern void ed_putchar(Edit_t*, int);
+extern void ed_ringbell(void);
+extern void ed_setup(Edit_t*,int, int);
+extern void ed_flush(Edit_t*);
+extern int ed_getchar(Edit_t*,int);
+extern int ed_virt_to_phys(Edit_t*,genchar*,genchar*,int,int,int);
+extern int ed_window(void);
+extern void ed_ungetchar(Edit_t*,int);
+extern int ed_viread(void*, int, char*, int, int);
+extern int ed_read(void*, int, char*, int, int);
+extern int ed_emacsread(void*, int, char*, int, int);
+extern Edpos_t ed_curpos(Edit_t*, genchar*, int, int, Edpos_t);
+extern int ed_setcursor(Edit_t*, genchar*, int, int, int);
+#if KSHELL
+ extern int ed_macro(Edit_t*,int);
+ extern int ed_expand(Edit_t*, char[],int*,int*,int,int);
+ extern int ed_fulledit(Edit_t*);
+ extern void *ed_open(Shell_t*);
+#endif /* KSHELL */
+# if SHOPT_MULTIBYTE
+ extern int ed_internal(const char*, genchar*);
+ extern int ed_external(const genchar*, char*);
+ extern void ed_gencpy(genchar*,const genchar*);
+ extern void ed_genncpy(genchar*,const genchar*,int);
+ extern int ed_genlen(const genchar*);
+ extern int ed_setwidth(const char*);
+# endif /* SHOPT_MULTIBYTE */
+
+extern const char e_runvi[];
+#if !KSHELL
+ extern const char e_version[];
+#endif /* KSHELL */
+
+#if SHOPT_HISTEXPAND
+
+/* flags */
+
+#define HIST_EVENT 0x1 /* event designator seen */
+#define HIST_QUESTION 0x2 /* question mark event designator */
+#define HIST_HASH 0x4 /* hash event designator */
+#define HIST_WORDDSGN 0x8 /* word designator seen */
+#define HIST_QUICKSUBST 0x10 /* quick substition designator seen */
+#define HIST_SUBSTITUTE 0x20 /* for substition loop */
+#define HIST_NEWLINE 0x40 /* newline in squashed white space */
+
+/* modifier flags */
+
+#define HIST_PRINT 0x100 /* print new command */
+#define HIST_QUOTE 0x200 /* quote resulting history line */
+#define HIST_QUOTE_BR 0x400 /* quote every word on space break */
+#define HIST_GLOBALSUBST 0x800 /* apply substition globally */
+
+#define HIST_ERROR 0x1000 /* an error ocurred */
+
+/* flags to be returned */
+
+#define HIST_FLAG_RETURN_MASK (HIST_EVENT|HIST_PRINT|HIST_ERROR)
+
+extern int hist_expand(const char *, char **);
+#endif
+
+#endif
+#endif
diff --git a/usr/src/lib/libshell/common/include/env.h b/usr/src/lib/libshell/common/include/env.h
new file mode 100644
index 0000000000..f888913c34
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/env.h
@@ -0,0 +1,50 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef _ENV_H
+#define _ENV_H 1
+
+#ifdef _BLD_env
+# ifdef __EXPORT__
+# define export __EXPORT__
+# endif
+#else
+ typedef void *Env_t;
+#endif
+
+/* for use with env_open */
+#define ENV_STABLE (-1)
+
+/* for third agument to env_add */
+#define ENV_MALLOCED 1
+#define ENV_STRDUP 2
+
+extern void env_close(Env_t*);
+extern int env_add(Env_t*, const char*, int);
+extern int env_delete(Env_t*, const char*);
+extern char **env_get(Env_t*);
+extern Env_t *env_open(char**,int);
+extern Env_t *env_scope(Env_t*,int);
+
+#undef extern
+
+#endif
+
+
diff --git a/usr/src/lib/libshell/common/include/fault.h b/usr/src/lib/libshell/common/include/fault.h
new file mode 100644
index 0000000000..107b337f68
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/fault.h
@@ -0,0 +1,124 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef SH_SIGBITS
+/*
+ * UNIX shell
+ * S. R. Bourne
+ * Rewritten by David Korn
+ *
+ */
+
+#include <sig.h>
+#include <setjmp.h>
+#include <error.h>
+#include <sfio.h>
+#include "FEATURE/setjmp"
+#include "FEATURE/sigfeatures"
+
+#ifndef SIGWINCH
+# ifdef SIGWIND
+# define SIGWINCH SIGWIND
+# else
+# ifdef SIGWINDOW
+# define SIGWINCH SIGWINDOW
+# endif
+# endif
+#endif
+
+typedef void (*SH_SIGTYPE)(int,void(*)(int));
+
+#define SH_FORKLIM 16 /* fork timeout interval */
+
+#define SH_TRAP 0200 /* bit for internal traps */
+#define SH_ERRTRAP 0 /* trap for non-zero exit status */
+#define SH_KEYTRAP 1 /* trap for keyboard event */
+#define SH_DEBUGTRAP 4 /* must be last internal trap */
+
+#define SH_SIGBITS 8
+#define SH_SIGFAULT 1 /* signal handler is sh_fault */
+#define SH_SIGOFF 2 /* signal handler is SIG_IGN */
+#define SH_SIGSET 4 /* pending signal */
+#define SH_SIGTRAP 010 /* pending trap */
+#define SH_SIGDONE 020 /* default is exit */
+#define SH_SIGIGNORE 040 /* default is ingore signal */
+#define SH_SIGINTERACTIVE 0100 /* handle interactive specially */
+#define SH_SIGTSTP 0200 /* tstp signal received */
+#define SH_SIGALRM 0200 /* timer alarm received */
+#define SH_SIGTERM SH_SIGOFF /* term signal received */
+
+/*
+ * These are longjmp values
+ */
+
+#define SH_JMPDOT 2
+#define SH_JMPEVAL 3
+#define SH_JMPTRAP 4
+#define SH_JMPIO 5
+#define SH_JMPCMD 6
+#define SH_JMPFUN 7
+#define SH_JMPERRFN 8
+#define SH_JMPSUB 9
+#define SH_JMPERREXIT 10
+#define SH_JMPEXIT 11
+#define SH_JMPSCRIPT 12
+
+struct openlist
+{
+ Sfio_t *strm;
+ struct openlist *next;
+};
+
+struct checkpt
+{
+ sigjmp_buf buff;
+ sigjmp_buf *prev;
+ int topfd;
+ int mode;
+ struct openlist *olist;
+#if (ERROR_VERSION >= 20030214L)
+ Error_context_t err;
+#else
+ struct errorcontext err;
+#endif
+};
+
+#define sh_pushcontext(bp,n) ( (bp)->mode=(n) , (bp)->olist=0, \
+ (bp)->topfd=sh.topfd, (bp)->prev=sh.jmplist, \
+ (bp)->err = *ERROR_CONTEXT_BASE, \
+ sh.jmplist = (sigjmp_buf*)(&(bp)->buff) \
+ )
+#define sh_popcontext(bp) (sh.jmplist=(bp)->prev, errorpop(&((bp)->err)))
+
+extern void sh_fault(int);
+extern void sh_done(int);
+extern void sh_chktrap(void);
+extern void sh_sigclear(int);
+extern void sh_sigdone(void);
+extern void sh_siginit(void);
+extern void sh_sigtrap(int);
+extern void sh_sigreset(int);
+extern void sh_timetraps(void);
+extern void *sh_timeradd(unsigned long,int ,void (*)(void*),void*);
+extern void timerdel(void*);
+
+extern const char e_alarm[];
+
+#endif /* !SH_SIGBITS */
diff --git a/usr/src/lib/libshell/common/include/fcin.h b/usr/src/lib/libshell/common/include/fcin.h
new file mode 100644
index 0000000000..c147a8fdef
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/fcin.h
@@ -0,0 +1,62 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef fcgetc
+/*
+ * David Korn
+ * AT&T Labs
+ *
+ * Fast character input with sfio text streams and strings
+ *
+ */
+
+#include <sfio.h>
+
+typedef struct _fcin
+{
+ Sfio_t *_fcfile; /* input file pointer */
+ unsigned char *fcbuff; /* pointer to input buffer */
+ unsigned char *fclast; /* pointer to end of input buffer */
+ unsigned char *fcptr; /* pointer to next input char */
+ unsigned char fcchar; /* saved character */
+ void (*fcfun)(Sfio_t*,const char*,int); /* advance function */
+ int fcleft; /* for multibyte boundary */
+ Sfoff_t fcoff; /* offset for last read */
+} Fcin_t;
+
+#define fcfile() (_Fcin._fcfile)
+#define fcgetc(c) (((c=fcget()) || (c=fcfill())), c)
+#define fcget() ((int)(*_Fcin.fcptr++))
+#define fcpeek(n) ((int)_Fcin.fcptr[n])
+#define fcseek(n) ((char*)(_Fcin.fcptr+=(n)))
+#define fcfirst() ((char*)_Fcin.fcbuff)
+#define fcsopen(s) (_Fcin._fcfile=(Sfio_t*)0,_Fcin.fcbuff=_Fcin.fcptr=(unsigned char*)(s))
+#define fctell() (_Fcin.fcoff + (_Fcin.fcptr-_Fcin.fcbuff))
+#define fcsave(x) (*(x) = _Fcin)
+#define fcrestore(x) (_Fcin = *(x))
+extern int fcfill(void);
+extern int fcfopen(Sfio_t*);
+extern int fcclose(void);
+void fcnotify(void(*)(Sfio_t*,const char*,int));
+extern int fcmbstate(const char*,int*,int*);
+
+extern Fcin_t _Fcin; /* used by macros */
+
+#endif /* fcgetc */
diff --git a/usr/src/lib/libshell/common/include/history.h b/usr/src/lib/libshell/common/include/history.h
new file mode 100644
index 0000000000..f97cd8b4a4
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/history.h
@@ -0,0 +1,75 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef HIST_VERSION
+/*
+ * Interface for history mechanism
+ * written by David Korn
+ *
+ */
+
+#include <ast.h>
+
+#define HIST_CHAR '!'
+#define HIST_VERSION 1 /* history file format version no. */
+
+typedef struct
+{
+ Sfdisc_t histdisc; /* discipline for history */
+ Sfio_t *histfp; /* history file stream pointer */
+ char *histname; /* name of history file */
+ int32_t histind; /* current command number index */
+ int histsize; /* number of accessible history lines */
+#ifdef _HIST_PRIVATE
+ _HIST_PRIVATE
+#endif /* _HIST_PRIVATE */
+} History_t;
+
+typedef struct
+{
+ int hist_command;
+ int hist_line;
+ int hist_char;
+} Histloc_t;
+
+/* the following are readonly */
+extern const char hist_fname[];
+
+extern int _Hist;
+#define hist_min(hp) ((_Hist=((int)((hp)->histind-(hp)->histsize)))>=0?_Hist:0)
+#define hist_max(hp) ((int)((hp)->histind))
+/* these are the history interface routines */
+extern int sh_histinit(void);
+extern void hist_cancel(History_t*);
+extern void hist_close(History_t*);
+extern int hist_copy(char*, int, int, int);
+extern void hist_eof(History_t*);
+extern Histloc_t hist_find(History_t*,char*,int, int, int);
+extern void hist_flush(History_t*);
+extern void hist_list(History_t*,Sfio_t*, off_t, int, char*);
+extern int hist_match(History_t*,off_t, char*, int*);
+extern off_t hist_tell(History_t*,int);
+extern off_t hist_seek(History_t*,int);
+extern char *hist_word(char*, int, int);
+#if SHOPT_ESH
+ extern Histloc_t hist_locate(History_t*,int, int, int);
+#endif /* SHOPT_ESH */
+
+#endif /* HIST_VERSION */
diff --git a/usr/src/lib/libshell/common/include/io.h b/usr/src/lib/libshell/common/include/io.h
new file mode 100644
index 0000000000..b8881bee84
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/io.h
@@ -0,0 +1,123 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * UNIX shell
+ * David Korn
+ *
+ */
+
+#include <ast.h>
+#include <sfio.h>
+
+#ifndef IOBSIZE
+# define IOBSIZE SF_BUFSIZE
+#endif /* IOBSIZE */
+#define IOMAXTRY 20
+
+#ifndef SF_CLOSING
+#define SF_CLOSING SF_CLOSE
+#endif
+#ifndef SF_APPENDWR
+#define SF_APPENDWR SF_APPEND
+#endif
+
+/* used for output of shell errors */
+#define ERRIO 2
+
+#define IOREAD 001
+#define IOWRITE 002
+#define IODUP 004
+#define IOSEEK 010
+#define IONOSEEK 020
+#define IOTTY 040
+#define IOCLEX 0100
+#define IOCLOSE (IOSEEK|IONOSEEK)
+
+#define IOSUBSHELL 0x8000 /* must be larger than any file descriptor */
+
+/*
+ * The remainder of this file is only used when compiled with shell
+ */
+
+#if KSHELL
+
+#ifndef ARG_RAW
+ struct ionod;
+#endif /* !ARG_RAW */
+
+#define sh_inuse(f2) (sh.fdptrs[f2])
+
+extern int sh_iocheckfd(int);
+extern void sh_ioinit(void);
+extern int sh_iomovefd(int);
+extern int sh_iorenumber(int,int);
+extern void sh_pclose(int[]);
+extern void sh_iorestore(int,int);
+#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
+ __EXPORT__
+#endif
+extern Sfio_t *sh_iostream(int);
+extern int sh_redirect(struct ionod*,int);
+extern void sh_iosave(int,int);
+extern void sh_iounsave(void);
+extern int sh_chkopen(const char*);
+extern int sh_ioaccess(int,int);
+extern int sh_devtofd(const char*);
+extern int sh_source(Shell_t*, Sfio_t*, const char*);
+
+/* the following are readonly */
+extern const char e_pexists[];
+extern const char e_query[];
+extern const char e_history[];
+extern const char e_argtype[];
+extern const char e_create[];
+extern const char e_tmpcreate[];
+extern const char e_exists[];
+extern const char e_file[];
+extern const char e_formspec[];
+extern const char e_badregexp[];
+extern const char e_open[];
+extern const char e_notseek[];
+extern const char e_noread[];
+extern const char e_badseek[];
+extern const char e_badpattern[];
+extern const char e_toomany[];
+extern const char e_pipe[];
+extern const char e_unknown[];
+extern const char e_devnull[];
+extern const char e_profile[];
+extern const char e_sysprofile[];
+#if SHOPT_SYSRC
+extern const char e_sysrc[];
+#endif
+#if SHOPT_BASH
+#if SHOPT_SYSRC
+extern const char e_bash_sysrc[];
+#endif
+extern const char e_bash_rc[];
+extern const char e_bash_login[];
+extern const char e_bash_logout[];
+extern const char e_bash_profile[];
+#endif
+extern const char e_stdprompt[];
+extern const char e_supprompt[];
+extern const char e_ambiguous[];
+#endif /* KSHELL */
diff --git a/usr/src/lib/libshell/common/include/jobs.h b/usr/src/lib/libshell/common/include/jobs.h
new file mode 100644
index 0000000000..c4998eabca
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/jobs.h
@@ -0,0 +1,159 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef JOB_NFLAG
+/*
+ * Interface to job control for shell
+ * written by David Korn
+ *
+ */
+
+#define JOBTTY 2
+
+#include <ast.h>
+#include <sfio.h>
+#ifndef SIGINT
+# include <signal.h>
+#endif /* !SIGINT */
+#include "FEATURE/options"
+
+#undef JOBS
+#if defined(SIGCLD) && !defined(SIGCHLD)
+# define SIGCHLD SIGCLD
+#endif
+#ifdef SIGCHLD
+# define JOBS 1
+# include "terminal.h"
+# ifdef FIOLOOKLD
+ /* Ninth edition */
+ extern int tty_ld, ntty_ld;
+# define OTTYDISC tty_ld
+# define NTTYDISC ntty_ld
+# endif /* FIOLOOKLD */
+#else
+# undef SIGTSTP
+# undef SH_MONITOR
+# define SH_MONITOR 0
+# define job_set(x)
+# define job_reset(x)
+#endif
+
+struct process
+{
+ struct process *p_nxtjob; /* next job structure */
+ struct process *p_nxtproc; /* next process in current job */
+ pid_t p_pid; /* process id */
+ pid_t p_pgrp; /* process group */
+ pid_t p_fgrp; /* process group when stopped */
+ short p_job; /* job number of process */
+ unsigned short p_exit; /* exit value or signal number */
+ unsigned short p_flag; /* flags - see below */
+ int p_env; /* subshell environment number */
+#ifdef JOBS
+ off_t p_name; /* history file offset for command */
+ struct termios p_stty; /* terminal state for job */
+#endif /* JOBS */
+};
+
+struct jobs
+{
+ struct process *pwlist; /* head of process list */
+ pid_t curpgid; /* current process gid id */
+ pid_t parent; /* set by fork() */
+ pid_t mypid; /* process id of shell */
+ pid_t mypgid; /* process group id of shell */
+ pid_t mytgid; /* terminal group id of shell */
+ unsigned int in_critical; /* >0 => in critical region */
+ int savesig; /* active signal */
+ int numpost; /* number of posted jobs */
+ short fd; /* tty descriptor number */
+#ifdef JOBS
+ int suspend; /* suspend character */
+ int linedisc; /* line dicipline */
+#endif /* JOBS */
+ char jobcontrol; /* turned on for real job control */
+ char waitsafe; /* wait will not block */
+ char waitall; /* wait for all jobs in pipe */
+ char toclear; /* job table needs clearing */
+ unsigned char *freejobs; /* free jobs numbers */
+};
+
+/* flags for joblist */
+#define JOB_LFLAG 1
+#define JOB_NFLAG 2
+#define JOB_PFLAG 4
+#define JOB_NLFLAG 8
+
+extern struct jobs job;
+
+#ifdef JOBS
+
+#define job_lock() (job.in_critical++)
+#define job_unlock() do{if(!--job.in_critical&&job.savesig)job_reap(job.savesig);}while(0)
+
+extern const char e_jobusage[];
+extern const char e_done[];
+extern const char e_running[];
+extern const char e_coredump[];
+extern const char e_no_proc[];
+extern const char e_no_job[];
+extern const char e_jobsrunning[];
+extern const char e_nlspace[];
+extern const char e_access[];
+extern const char e_terminate[];
+extern const char e_no_jctl[];
+extern const char e_signo[];
+#ifdef SIGTSTP
+ extern const char e_no_start[];
+#endif /* SIGTSTP */
+#ifdef NTTYDISC
+ extern const char e_newtty[];
+ extern const char e_oldtty[];
+#endif /* NTTYDISC */
+#endif /* JOBS */
+
+/*
+ * The following are defined in jobs.c
+ */
+
+extern void job_clear(void);
+extern void job_bwait(char**);
+extern int job_walk(Sfio_t*,int(*)(struct process*,int),int,char*[]);
+extern int job_kill(struct process*,int);
+extern void job_wait(pid_t);
+extern int job_post(pid_t,pid_t);
+extern void *job_subsave(void);
+extern void job_subrestore(void*);
+#ifdef JOBS
+ extern void job_init(int);
+ extern int job_close(void);
+ extern int job_list(struct process*,int);
+ extern int job_terminate(struct process*,int);
+ extern int job_switch(struct process*,int);
+ extern void job_fork(pid_t);
+ extern int job_reap(int);
+#else
+# define job_init(flag)
+# define job_close() (0)
+# define job_fork(p)
+#endif /* JOBS */
+
+
+#endif /* !JOB_NFLAG */
diff --git a/usr/src/lib/libshell/common/include/lexstates.h b/usr/src/lib/libshell/common/include/lexstates.h
new file mode 100644
index 0000000000..8e3cdbfef6
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/lexstates.h
@@ -0,0 +1,151 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef S_BREAK
+#define S_BREAK 1 /* end of token */
+#define S_EOF 2 /* end of buffer */
+#define S_NL 3 /* new-line when not a token */
+#define S_RES 4 /* first character of reserved word */
+#define S_NAME 5 /* other identifier characters */
+#define S_REG 6 /* non-special characters */
+#define S_TILDE 7 /* first char is tilde */
+#define S_PUSH 8
+#define S_POP 9
+#define S_BRACT 10
+#define S_LIT 11 /* literal quote character */
+#define S_NLTOK 12 /* new-line token */
+#define S_OP 13 /* operator character */
+#define S_PAT 14 /* pattern characters * and ? */
+#define S_EPAT 15 /* pattern char when followed by ( */
+#define S_EQ 16 /* assignment character */
+#define S_COM 17 /* comment character */
+#define S_MOD1 18 /* ${...} modifier character - old quoting */
+#define S_MOD2 19 /* ${...} modifier character - new quoting */
+#define S_ERR 20 /* invalid character in ${...} */
+#define S_SPC1 21 /* special prefix characters after $ */
+#define S_SPC2 22 /* special characters after $ */
+#define S_DIG 23 /* digit character after $*/
+#define S_ALP 24 /* alpahbetic character after $ */
+#define S_LBRA 25 /* left brace after $ */
+#define S_RBRA 26 /* right brace after $ */
+#define S_PAR 27 /* set for $( */
+#define S_ENDCH 28 /* macro expansion terminator */
+#define S_SLASH 29 /* / character terminates ~ expansion */
+#define S_COLON 30 /* for character : */
+#define S_LABEL 31 /* for goto label */
+#define S_EDOL 32 /* ends $identifier */
+#define S_BRACE 33 /* left brace */
+#define S_DOT 34 /* . char */
+#define S_META 35 /* | & ; < > inside ${...} reserved for future use */
+#define S_SPACE S_BREAK /* IFS space characters */
+#define S_DELIM S_RES /* IFS delimter characters */
+#define S_MBYTE S_NAME /* IFS first byte of multi-byte char */
+#define S_BLNK 36 /* space or tab */
+/* The following must be the highest numbered states */
+#define S_QUOTE 37 /* double quote character */
+#define S_GRAVE 38 /* old comsub character */
+#define S_ESC 39 /* escape character */
+#define S_DOL 40 /* $ subsitution character */
+#define S_ESC2 41 /* escape character inside '...' */
+
+/* These are the lexical state table names */
+#define ST_BEGIN 0
+#define ST_NAME 1
+#define ST_NORM 2
+#define ST_LIT 3
+#define ST_QUOTE 4
+#define ST_NESTED 5
+#define ST_DOL 6
+#define ST_BRACE 7
+#define ST_DOLNAME 8
+#define ST_MACRO 9
+#define ST_QNEST 10
+#define ST_NONE 11
+
+#include "FEATURE/locale"
+
+#if _hdr_wchar
+# include <wchar.h>
+# if _hdr_wctype
+# include <wctype.h>
+# undef isalpha
+# define isalpha(x) iswalpha(x)
+# if defined(iswblank) || _lib_iswblank
+# undef isblank
+# define isblank(x) iswblank(x)
+# else
+# if _lib_wctype && _lib_iswctype
+# define _lib_iswblank -1
+# undef isblank
+# define isblank(x) local_iswblank(x)
+ extern int local_iswblank(wchar_t);
+# endif
+# endif
+# endif
+#endif
+#ifndef isblank
+# define isblank(x) ((x)==' '||(x)=='\t')
+#endif
+
+#undef LEN
+#if SHOPT_MULTIBYTE
+ static int NXT, LEN;
+# define isaname(c) ((c)>0xff?isalpha(c): sh_lexstates[ST_NAME][(c)]==0)
+# define isaletter(c) ((c)>0xff?isalpha(c): sh_lexstates[ST_DOL][(c)]==S_ALP && (c)!='.')
+#else
+# undef mbwide
+# define mbwide() (0)
+# define LEN 1
+# define isaname(c) (sh_lexstates[ST_NAME][c]==0)
+# define isaletter(c) (sh_lexstates[ST_DOL][c]==S_ALP && (c)!='.')
+#endif
+#define STATE(s,c) (mbwide()?(c=fcmbstate(s,&NXT,&LEN),NXT):s[c=fcget()])
+#define isadigit(c) (sh_lexstates[ST_DOL][c]==S_DIG)
+#define isastchar(c) ((c)=='@' || (c)=='*')
+#define isexp(c) (sh_lexstates[ST_MACRO][c]==S_PAT||(c)=='$'||(c)=='`')
+#define ismeta(c) (sh_lexstates[ST_NAME][c]==S_BREAK)
+
+extern char *sh_lexstates[ST_NONE];
+extern const char *sh_lexrstates[ST_NONE];
+extern const char e_lexversion[];
+extern const char e_lexspace[];
+extern const char e_lexslash[];
+extern const char e_lexlabignore[];
+extern const char e_lexlabunknown[];
+extern const char e_lexsyntax1[];
+extern const char e_lexsyntax2[];
+extern const char e_lexsyntax3[];
+extern const char e_lexobsolete1[];
+extern const char e_lexobsolete2[];
+extern const char e_lexobsolete3[];
+extern const char e_lexobsolete4[];
+extern const char e_lexobsolete5[];
+extern const char e_lexobsolete6[];
+extern const char e_lexusebrace[];
+extern const char e_lexusequote[];
+extern const char e_lexescape[];
+extern const char e_lexquote[];
+extern const char e_lexnested[];
+extern const char e_lexbadchar[];
+extern const char e_lexlongquote[];
+extern const char e_lexfuture[];
+extern const char e_lexzerobyte[];
+extern const char e_lexemptyfor[];
+#endif
diff --git a/usr/src/lib/libshell/common/include/name.h b/usr/src/lib/libshell/common/include/name.h
new file mode 100644
index 0000000000..04ed23e7d0
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/name.h
@@ -0,0 +1,208 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef _NV_PRIVATE
+/*
+ * This is the implementation header file for name-value pairs
+ */
+
+#define _NV_PRIVATE \
+ Namfun_t *nvfun; /* pointer to trap functions */ \
+ union Value nvalue; /* value field */ \
+ char *nvenv; /* pointer to environment name */
+
+#include <ast.h>
+#include <cdt.h>
+#include "shtable.h"
+
+/* Nodes can have all kinds of values */
+union Value
+{
+ const char *cp;
+ int *ip;
+ char c;
+ int i;
+ unsigned int u;
+ int32_t *lp;
+ Sflong_t *llp; /* for long long arithmetic */
+ int16_t s;
+ double *dp; /* for floating point arithmetic */
+ Sfdouble_t *ldp; /* for long floating point arithmetic */
+ struct Namarray *array; /* for array node */
+ struct Namval *np; /* for Namval_t node */
+ union Value *up; /* for indirect node */
+ struct Ufunction *rp; /* shell user defined functions */
+ struct Namfun *funp; /* discipline pointer */
+ struct Namref *nrp; /* name reference */
+ int (*bfp)(int,char*[],void*);/* builtin entry point function pointer */
+};
+
+#include "nval.h"
+
+/* used for arrays */
+
+#define ARRAY_MAX (1L<<ARRAY_BITS) /* maximum number of elements in an array */
+#define ARRAY_MASK (ARRAY_MAX-1) /* For index values */
+
+#define ARRAY_INCR 32 /* number of elements to grow when array
+ bound exceeded. Must be a power of 2 */
+#define ARRAY_FILL (8L<<ARRAY_BITS) /* used with nv_putsub() */
+#define ARRAY_NOCLONE (16L<<ARRAY_BITS) /* do not clone array disc */
+#define ARRAY_NOCHILD (32L<<ARRAY_BITS) /* skip compound arrays */
+#define ARRAY_SETSUB (64L<<ARRAY_BITS) /* set subscript */
+#define NV_ASETSUB 8 /* set subscript */
+
+/* These flags are used as options to array_get() */
+#define ARRAY_ASSIGN 0
+#define ARRAY_LOOKUP 1
+#define ARRAY_DELETE 2
+
+
+struct Namref
+{
+ Namval_t *np;
+ Namval_t *table;
+ Dt_t *root;
+ char *sub;
+};
+
+/* This describes a user shell function node */
+struct Ufunction
+{
+ int *ptree; /* address of parse tree */
+ int lineno; /* line number of function start */
+ off_t hoffset; /* offset into source or history file */
+ Namval_t *nspace; /* pointer to name space */
+ char *fname; /* file name where function defined */
+};
+
+#ifndef ARG_RAW
+ struct argnod;
+#endif /* !ARG_RAW */
+
+/* attributes of Namval_t items */
+
+/* The following attributes are for internal use */
+#define NV_NOCHANGE (NV_EXPORT|NV_IMPORT|NV_RDONLY|NV_TAGGED|NV_NOFREE)
+#define NV_ATTRIBUTES (~(NV_NOSCOPE|NV_ARRAY|NV_NOARRAY|NV_IDENT|NV_ASSIGN|NV_REF|NV_VARNAME))
+#define NV_PARAM NV_NODISC /* expansion use positional params */
+
+/* This following are for use with nodes which are not name-values */
+#define NV_TYPE 0x1000000
+#define NV_FUNCTION (NV_RJUST|NV_FUNCT) /* value is shell function */
+#define NV_FPOSIX NV_LJUST /* posix function semantics */
+#define NV_FTMP NV_ZFILL /* function source in tmpfile */
+
+#define NV_NOPRINT (NV_LTOU|NV_UTOL) /* do not print */
+#define NV_NOALIAS (NV_NOPRINT|NV_IMPORT)
+#define NV_NOEXPAND NV_RJUST /* do not expand alias */
+#define NV_BLTIN (NV_NOPRINT|NV_EXPORT)
+#define BLT_ENV (NV_RDONLY) /* non-stoppable,
+ * can modify enviornment */
+#define BLT_SPC (NV_LJUST) /* special built-ins */
+#define BLT_EXIT (NV_RJUST) /* exit value can be > 255 */
+#define BLT_DCL (NV_TAGGED) /* declaration command */
+#define nv_isref(n) (nv_isattr((n),NV_REF)==NV_REF)
+#define nv_istable(n) (nv_isattr((n),NV_TABLE|NV_LJUST|NV_RJUST)==NV_TABLE)
+#define is_abuiltin(n) (nv_isattr(n,NV_BLTIN)==NV_BLTIN)
+#define is_afunction(n) (nv_isattr(n,NV_FUNCTION)==NV_FUNCTION)
+#define nv_funtree(n) ((n)->nvalue.rp->ptree)
+#define funptr(n) ((n)->nvalue.bfp)
+
+#define NV_SUBQUOTE (NV_ADD<<1) /* used with nv_endsubscript */
+
+/* NAMNOD MACROS */
+/* ... for attributes */
+
+#define nv_setattr(n,f) ((n)->nvflag = (f))
+#define nv_context(n) ((void*)(n)->nvfun) /* for builtins */
+/* The following are for name references */
+#define nv_refnode(n) ((n)->nvalue.nrp->np)
+#define nv_reftree(n) ((n)->nvalue.nrp->root)
+#define nv_reftable(n) ((n)->nvalue.nrp->table)
+#define nv_refsub(n) ((n)->nvalue.nrp->sub)
+#if SHOPT_OO
+# define nv_class(np) (nv_isattr(np,NV_REF|NV_IMPORT)?0:(Namval_t*)((np)->nvenv))
+#endif /* SHOPT_OO */
+
+/* ... etc */
+
+#define nv_setsize(n,s) ((n)->nvsize = (s))
+#undef nv_size
+#define nv_size(np) ((np)->nvsize)
+#define nv_isnull(np) (!(np)->nvalue.cp && !(np)->nvfun && !nv_isattr(np,NV_SHORT))
+
+/* ... for arrays */
+
+#define array_elem(ap) ((ap)->nelem&ARRAY_MASK)
+#define array_assoc(ap) ((ap)->fun)
+
+extern int array_maxindex(Namval_t*);
+extern char *nv_endsubscript(Namval_t*, char*, int);
+extern Namfun_t *nv_cover(Namval_t*);
+extern Namarr_t *nv_arrayptr(Namval_t*);
+extern int nv_setnotify(Namval_t*,char **);
+extern int nv_unsetnotify(Namval_t*,char **);
+extern void nv_setlist(struct argnod*, int);
+extern void nv_optimize(Namval_t*);
+extern void nv_outname(Sfio_t*,char*, int);
+extern void nv_scope(struct argnod*);
+extern void nv_unref(Namval_t*);
+extern void _nv_unset(Namval_t*,int);
+extern int nv_clone(Namval_t*, Namval_t*, int);
+extern void *nv_diropen(const char*);
+extern char *nv_dirnext(void*);
+extern void nv_dirclose(void*);
+extern char *nv_getvtree(Namval_t*, Namfun_t*);
+extern void nv_attribute(Namval_t*, Sfio_t*, char*, int);
+extern Namval_t *nv_bfsearch(const char*, Dt_t*, Namval_t**, char**);
+extern Namval_t *nv_mkclone(Namval_t*);
+extern Namval_t *nv_mktype(Namval_t**, int);
+extern void nv_addnode(Namval_t*, int);
+extern Namval_t *nv_parent(Namval_t*);
+extern char *nv_getbuf(size_t);
+extern Namval_t *nv_mount(Namval_t*, const char *name, Dt_t*);
+extern Namval_t *nv_arraychild(Namval_t*, Namval_t*, int);
+extern int nv_compare(Dt_t*, Void_t*, Void_t*, Dtdisc_t*);
+
+extern const Namdisc_t RESTRICTED_disc;
+extern char nv_local;
+extern Dtdisc_t _Nvdisc;
+extern const char e_subscript[];
+extern const char e_nullset[];
+extern const char e_notset[];
+extern const char e_noparent[];
+extern const char e_readonly[];
+extern const char e_badfield[];
+extern const char e_restricted[];
+extern const char e_ident[];
+extern const char e_varname[];
+extern const char e_noalias[];
+extern const char e_noarray[];
+extern const char e_aliname[];
+extern const char e_badexport[];
+extern const char e_badref[];
+extern const char e_noref[];
+extern const char e_selfref[];
+extern const char e_envmarker[];
+extern const char e_badlocale[];
+extern const char e_loop[];
+extern const char e_redef[];
+#endif /* _NV_PRIVATE */
diff --git a/usr/src/lib/libshell/common/include/national.h b/usr/src/lib/libshell/common/include/national.h
new file mode 100644
index 0000000000..837015011a
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/national.h
@@ -0,0 +1,37 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * national.h - definitions for multibyte character sets
+ *
+ * David Korn
+ * AT&T Labs
+ *
+ */
+
+#if SHOPT_MULTIBYTE
+
+# ifndef MARKER
+# define MARKER 0xdfff /* Must be invalid character */
+# endif
+
+ extern int sh_strchr(const char*,const char*);
+
+#endif /* SHOPT_MULTIBYTE */
diff --git a/usr/src/lib/libshell/common/include/nval.h b/usr/src/lib/libshell/common/include/nval.h
new file mode 100644
index 0000000000..6d02dc0a3b
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/nval.h
@@ -0,0 +1,305 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef NV_DEFAULT
+/*
+ * David Korn
+ * AT&T Labs
+ *
+ * Interface definitions of structures for name-value pairs
+ * These structures are used for named variables, functions and aliases
+ *
+ */
+
+
+#include <ast.h>
+#include <cdt.h>
+
+/* for compatibility with old hash library */
+#define Hashtab_t Dt_t
+#define HASH_BUCKET 1
+#define HASH_NOSCOPE 2
+#define HASH_SCOPE 4
+#define hashscope(x) dtvnext(x)
+
+typedef struct Namval Namval_t;
+typedef struct Namfun Namfun_t;
+typedef struct Namdisc Namdisc_t;
+typedef struct Nambfun Nambfun_t;
+typedef struct Namarray Namarr_t;
+typedef struct Nambltin Nambltin_t;
+typedef struct Namtype Namtype_t;
+
+/*
+ * This defines the template for nodes that have their own assignment
+ * and or lookup functions
+ */
+struct Namdisc
+{
+ size_t dsize;
+ void (*putval)(Namval_t*, const char*, int, Namfun_t*);
+ char *(*getval)(Namval_t*, Namfun_t*);
+ Sfdouble_t (*getnum)(Namval_t*, Namfun_t*);
+ char *(*setdisc)(Namval_t*, const char*, Namval_t*, Namfun_t*);
+ Namval_t *(*createf)(Namval_t*, const char*, int, Namfun_t*);
+ Namfun_t *(*clonef)(Namval_t*, Namval_t*, int, Namfun_t*);
+ char *(*namef)(Namval_t*, Namfun_t*);
+ Namval_t *(*nextf)(Namval_t*, Dt_t*, Namfun_t*);
+ Namval_t *(*typef)(Namval_t*, Namfun_t*);
+ int (*readf)(Namval_t*, Sfio_t*, int, Namfun_t*);
+};
+
+struct Namfun
+{
+ const Namdisc_t *disc;
+ char nofree;
+ char funs;
+ unsigned short dsize;
+ Namfun_t *next;
+ char *last;
+ Namval_t *type;
+};
+
+struct Nambfun
+{
+ Namfun_t fun;
+ int num;
+ const char **bnames;
+ Namval_t *bltins[1];
+};
+
+/* This is an array template header */
+struct Namarray
+{
+ Namfun_t hdr;
+ long nelem; /* number of elements */
+ void *(*fun)(Namval_t*,const char*,int); /* associative arrays */
+ Namval_t *parent; /* for multi-dimensional */
+};
+
+/* Passed as third argument to a builtin when NV_BLTINOPT is set on node */
+struct Nambltin
+{
+ void *shp;
+ Namval_t *np;
+ void *ptr;
+ void *data;
+ int flags;
+};
+
+struct Namtype
+{
+ void *shp;
+ Namval_t *np;
+ const char *optstring;
+ void *optinfof;
+};
+
+/* attributes of name-value node attribute flags */
+
+#define NV_DEFAULT 0
+/* This defines the attributes for an attributed name-value pair node */
+struct Namval
+{
+ Dtlink_t nvlink; /* space for cdt links */
+ char *nvname; /* pointer to name of the node */
+ unsigned short nvflag; /* attributes */
+ unsigned short nvsize; /* size or base */
+#ifdef _NV_PRIVATE
+ _NV_PRIVATE
+#else
+ Namfun_t *nvfun;
+ char *nvalue;
+ char *nvprivate;
+#endif /* _NV_PRIVATE */
+};
+
+#define NV_CLASS ".sh.type"
+#define NV_MINSZ (sizeof(struct Namval)-sizeof(Dtlink_t)-sizeof(char*))
+#define nv_namptr(p,n) ((Namval_t*)((char*)(p)+(n)*NV_MINSZ-sizeof(Dtlink_t)))
+
+/* The following attributes are for internal use */
+#define NV_NOFREE 0x200 /* don't free the space when releasing value */
+#define NV_ARRAY 0x400 /* node is an array */
+#define NV_REF 0x4000 /* reference bit */
+#define NV_TABLE 0x800 /* node is a dictionary table */
+#define NV_IMPORT 0x1000 /* value imported from environment */
+#define NV_MINIMAL NV_IMPORT /* node does not contain all fields */
+
+#define NV_INTEGER 0x2 /* integer attribute */
+/* The following attributes are valid only when NV_INTEGER is off */
+#define NV_LTOU 0x4 /* convert to uppercase */
+#define NV_UTOL 0x8 /* convert to lowercase */
+#define NV_ZFILL 0x10 /* right justify and fill with leading zeros */
+#define NV_RJUST 0x20 /* right justify and blank fill */
+#define NV_LJUST 0x40 /* left justify and blank fill */
+#define NV_BINARY 0x100 /* fixed size data buffer */
+#define NV_RAW NV_LJUST /* used only with NV_BINARY */
+#define NV_HOST (NV_RJUST|NV_LJUST) /* map to host filename */
+
+/* The following attributes do not effect the value */
+#define NV_RDONLY 0x1 /* readonly bit */
+#define NV_EXPORT 0x2000 /* export bit */
+#define NV_TAGGED 0x8000 /* user define tag bit */
+
+/* The following are used with NV_INTEGER */
+#define NV_SHORT (NV_RJUST) /* when integers are not long */
+#define NV_LONG (NV_UTOL) /* for long long and long double */
+#define NV_UNSIGN (NV_LTOU) /* for unsigned quantities */
+#define NV_DOUBLE (NV_ZFILL) /* for floating point */
+#define NV_EXPNOTE (NV_LJUST) /* for scientific notation */
+
+/* options for nv_open */
+
+#define NV_APPEND 0x10000 /* append value */
+#define NV_MOVE 0x20000 /* for use with nv_clone */
+#define NV_ADD 8
+ /* add node if not found */
+#define NV_ASSIGN NV_NOFREE /* assignment is possible */
+#define NV_NOASSIGN 0 /* backward compatibility */
+#define NV_NOARRAY 0x200000 /* array name not possible */
+#define NV_IARRAY 0x400000 /* for indexed array */
+#define NV_NOREF NV_REF /* don't follow reference */
+#define NV_IDENT 0x80 /* name must be identifier */
+#define NV_VARNAME 0x20000 /* name must be ?(.)id*(.id) */
+#define NV_NOADD 0x40000 /* do not add node */
+#define NV_NOSCOPE 0x80000 /* look only in current scope */
+#define NV_NOFAIL 0x100000 /* return 0 on failure, no msg */
+#define NV_NODISC NV_IDENT /* ignore disciplines */
+
+#define NV_FUNCT NV_IDENT /* option for nv_create */
+#define NV_BLTINOPT NV_ZFILL /* save state for optimization*/
+
+#define NV_PUBLIC (~(NV_NOSCOPE|NV_ASSIGN|NV_IDENT|NV_VARNAME|NV_NOADD))
+
+/* numeric types */
+#define NV_INT16 (NV_SHORT|NV_INTEGER)
+#define NV_UINT16 (NV_UNSIGN|NV_SHORT|NV_INTEGER)
+#define NV_INT32 (NV_INTEGER)
+#define NV_UNT32 (NV_UNSIGN|NV_INTEGER)
+#define NV_INT64 (NV_LONG|NV_INTEGER)
+#define NV_UINT64 (NV_UNSIGN|NV_LONG|NV_INTEGER)
+#define NV_FLOAT (NV_SHORT|NV_DOUBLE|NV_INTEGER)
+#define NV_LDOUBLE (NV_LONG|NV_DOUBLE|NV_INTEGER)
+
+/* name-value pair macros */
+#define nv_isattr(np,f) ((np)->nvflag & (f))
+#define nv_onattr(n,f) ((n)->nvflag |= (f))
+#define nv_offattr(n,f) ((n)->nvflag &= ~(f))
+#define nv_isarray(np) (nv_isattr((np),NV_ARRAY))
+
+/* The following are operations for associative arrays */
+#define NV_AINIT 1 /* initialize */
+#define NV_AFREE 2 /* free array */
+#define NV_ANEXT 3 /* advance to next subscript */
+#define NV_ANAME 4 /* return subscript name */
+#define NV_ADELETE 5 /* delete current subscript */
+#define NV_AADD 6 /* add subscript if not found */
+#define NV_ACURRENT 7 /* return current subscript Namval_t* */
+
+/* The following are for nv_disc */
+#define NV_FIRST 1
+#define NV_LAST 2
+#define NV_POP 3
+#define NV_CLONE 4
+
+/* The following are operations for nv_putsub() */
+#define ARRAY_BITS 24
+#define ARRAY_ADD (1L<<ARRAY_BITS) /* add subscript if not found */
+#define ARRAY_SCAN (2L<<ARRAY_BITS) /* For ${array[@]} */
+#define ARRAY_UNDEF (4L<<ARRAY_BITS) /* For ${array} */
+
+
+/* These are disciplines provided by the library for use with nv_discfun */
+#define NV_DCADD 0 /* used to add named disciplines */
+#define NV_DCRESTRICT 1 /* variable that are restricted in rsh */
+
+#if defined(__EXPORT__) && defined(_DLL)
+# ifdef _BLD_shell
+# define extern __EXPORT__
+# else
+# define extern __IMPORT__
+# endif /* _BLD_shell */
+#endif /* _DLL */
+/* prototype for array interface*/
+extern Namarr_t *nv_setarray(Namval_t*,void*(*)(Namval_t*,const char*,int));
+extern void *nv_associative(Namval_t*,const char*,int);
+extern int nv_aindex(Namval_t*);
+extern int nv_nextsub(Namval_t*);
+extern char *nv_getsub(Namval_t*);
+extern Namval_t *nv_putsub(Namval_t*, char*, long);
+extern Namval_t *nv_opensub(Namval_t*);
+
+/* name-value pair function prototypes */
+extern int nv_adddisc(Namval_t*, const char**, Namval_t**);
+extern int nv_clone(Namval_t*, Namval_t*, int);
+extern void nv_close(Namval_t*);
+extern void *nv_context(Namval_t*);
+extern Namval_t *nv_create(const char*, Dt_t*, int,Namfun_t*);
+extern Dt_t *nv_dict(Namval_t*);
+extern Sfdouble_t nv_getn(Namval_t*, Namfun_t*);
+extern Sfdouble_t nv_getnum(Namval_t*);
+extern char *nv_getv(Namval_t*, Namfun_t*);
+extern char *nv_getval(Namval_t*);
+extern Namfun_t *nv_hasdisc(Namval_t*, const Namdisc_t*);
+extern int nv_isnull(Namval_t*);
+extern Namval_t *nv_lastdict(void);
+extern void nv_newattr(Namval_t*,unsigned,int);
+extern Namval_t *nv_open(const char*,Dt_t*,int);
+extern void nv_putval(Namval_t*,const char*,int);
+extern void nv_putv(Namval_t*,const char*,int,Namfun_t*);
+extern int nv_scan(Dt_t*,void(*)(Namval_t*,void*),void*,int,int);
+extern Namval_t *nv_scoped(Namval_t*);
+extern char *nv_setdisc(Namval_t*,const char*,Namval_t*,Namfun_t*);
+extern void nv_setref(Namval_t*, Dt_t*,int);
+extern int nv_settype(Namval_t*, Namval_t*, int);
+extern void nv_setvec(Namval_t*,int,int,char*[]);
+extern void nv_setvtree(Namval_t*);
+extern int nv_setsize(Namval_t*,int);
+extern Namfun_t *nv_disc(Namval_t*,Namfun_t*,int);
+extern void nv_unset(Namval_t*);
+extern Namval_t *nv_search(const char *, Dt_t*, int);
+extern void nv_unscope(void);
+extern char *nv_name(Namval_t*);
+extern Namval_t *nv_type(Namval_t*);
+extern const Namdisc_t *nv_discfun(int);
+
+#ifdef _DLL
+# undef extern
+#endif /* _DLL */
+
+#define nv_size(np) nv_setsize((np),-1)
+#define nv_stack(np,nf) nv_disc(np,nf,0)
+
+#if 0
+/*
+ * The names of many functions were changed in early '95
+ * Here is a mapping to the old names
+ */
+# define nv_istype(np) nv_isattr(np)
+# define nv_newtype(np) nv_newattr(np)
+# define nv_namset(np,a,b) nv_open(np,a,b)
+# define nv_free(np) nv_unset(np)
+# define nv_settype(np,a,b,c) nv_setdisc(np,a,b,c)
+# define nv_search(np,a,b) nv_open(np,a,((b)?0:NV_NOADD))
+# define settype setdisc
+#endif
+
+#endif /* NV_DEFAULT */
diff --git a/usr/src/lib/libshell/common/include/path.h b/usr/src/lib/libshell/common/include/path.h
new file mode 100644
index 0000000000..2460be3cbf
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/path.h
@@ -0,0 +1,140 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef PATH_OFFSET
+
+/*
+ * UNIX shell path handling interface
+ * Written by David Korn
+ * These are the definitions for the lexical analyzer
+ */
+
+#include "FEATURE/options"
+#include <nval.h>
+
+#if !defined(SHOPT_SPAWN)
+# if _UWIN || _use_spawnveg || !_lib_fork
+# define SHOPT_SPAWN 1
+# endif
+#endif /* !SHOPT_SPAWN */
+
+#define PATH_PATH 0001
+#define PATH_FPATH 0002
+#define PATH_CDPATH 0004
+#define PATH_BFPATH 0010
+#define PATH_SKIP 0020
+#define PATH_BUILTIN_LIB 0040
+#define PATH_STD_DIR 0100 /* directory is on $(getconf PATH) */
+
+#define PATH_OFFSET 2 /* path offset for path_join */
+#define MAXDEPTH (sizeof(char*)==2?64:4096) /* maximum recursion depth*/
+
+/*
+ * path component structure for path searching
+ */
+typedef struct pathcomp
+{
+ struct pathcomp *next;
+ int refcount;
+ dev_t dev;
+ ino_t ino;
+ char *name;
+ char *lib;
+ char *blib;
+ void *bltin_lib;
+ unsigned short len;
+ unsigned short flags;
+ Shell_t *shp;
+} Pathcomp_t;
+
+#ifndef ARG_RAW
+ struct argnod;
+#endif /* !ARG_RAW */
+
+/* pathname handling routines */
+extern void path_newdir(Pathcomp_t*);
+extern Pathcomp_t *path_dirfind(Pathcomp_t*,const char*,int);
+extern Pathcomp_t *path_unsetfpath(Pathcomp_t*);
+extern Pathcomp_t *path_addpath(Pathcomp_t*,const char*,int);
+extern Pathcomp_t *path_dup(Pathcomp_t*);
+extern void path_delete(Pathcomp_t*);
+extern void path_alias(Namval_t*,Pathcomp_t*);
+extern Pathcomp_t *path_absolute(const char*, Pathcomp_t*);
+extern char *path_basename(const char*);
+extern char *path_fullname(const char*);
+extern int path_expand(const char*, struct argnod**);
+extern void path_exec(const char*,char*[],struct argnod*);
+extern pid_t path_spawn(const char*,char*[],char*[],Pathcomp_t*,int);
+#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
+# define extern __EXPORT__
+#endif
+extern int path_open(const char*,Pathcomp_t*);
+extern Pathcomp_t *path_get(const char*);
+#undef extern
+extern char *path_pwd(int);
+extern Pathcomp_t *path_nextcomp(Pathcomp_t*,const char*,Pathcomp_t*);
+extern int path_search(const char*,Pathcomp_t*,int);
+extern char *path_relative(const char*);
+extern int path_complete(const char*, const char*,struct argnod**);
+#if SHOPT_BRACEPAT
+ extern int path_generate(struct argnod*,struct argnod**);
+#endif /* SHOPT_BRACEPAT */
+
+/* constant strings needed for whence */
+extern const char e_timeformat[];
+extern const char e_badtformat[];
+extern const char e_dot[];
+extern const char e_pfsh[];
+extern const char e_pwd[];
+extern const char e_logout[];
+extern const char e_alphanum[];
+extern const char e_mailmsg[];
+extern const char e_suidprofile[];
+extern const char e_sysprofile[];
+extern const char e_traceprompt[];
+extern const char e_crondir[];
+#if SHOPT_SUID_EXEC
+ extern const char e_suidexec[];
+#endif /* SHOPT_SUID_EXEC */
+extern const char is_alias[];
+extern const char is_builtin[];
+extern const char is_builtver[];
+extern const char is_reserved[];
+extern const char is_talias[];
+extern const char is_xalias[];
+extern const char is_function[];
+extern const char is_ufunction[];
+#ifdef SHELLMAGIC
+ extern const char e_prohibited[];
+#endif /* SHELLMAGIC */
+
+#if SHOPT_ACCT
+# include "FEATURE/acct"
+# ifdef _sys_acct
+ extern void sh_accinit(void);
+ extern void sh_accbegin(const char*);
+ extern void sh_accend(void);
+ extern void sh_accsusp(void);
+# else
+# undef SHOPT_ACCT
+# endif /* _sys_acct */
+#endif /* SHOPT_ACCT */
+
+#endif /*! PATH_OFFSET */
diff --git a/usr/src/lib/libshell/common/include/shell.h b/usr/src/lib/libshell/common/include/shell.h
new file mode 100644
index 0000000000..66ccd20436
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/shell.h
@@ -0,0 +1,245 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef SH_INTERACTIVE
+/*
+ * David Korn
+ * AT&T Labs
+ *
+ * Interface definitions for shell command language
+ *
+ */
+
+#include <cmd.h>
+#include <cdt.h>
+#ifdef _SH_PRIVATE
+# include "name.h"
+#else
+# include <nval.h>
+#endif /* _SH_PRIVATE */
+
+#define SH_VERSION 20060510
+
+#undef NOT_USED
+#define NOT_USED(x) (&x,1)
+
+/* options */
+typedef struct
+{
+ unsigned long v[4];
+}
+Shopt_t;
+
+typedef void (*Shinit_f)(int);
+typedef int (*Shbltin_f)(int, char*[], void*);
+typedef int (*Shwait_f)(int, long, int);
+
+union Shnode_u;
+typedef union Shnode_u Shnode_t;
+
+#define SH_CFLAG 0
+#define SH_HISTORY 1 /* used also as a state */
+#define SH_ERREXIT 2 /* used also as a state */
+#define SH_VERBOSE 3 /* used also as a state */
+#define SH_MONITOR 4 /* used also as a state */
+#define SH_INTERACTIVE 5 /* used also as a state */
+#define SH_RESTRICTED 6
+#define SH_XTRACE 7
+#define SH_KEYWORD 8
+#define SH_NOUNSET 9
+#define SH_NOGLOB 10
+#define SH_ALLEXPORT 11
+#define SH_PFSH 12
+#define SH_IGNOREEOF 13
+#define SH_NOCLOBBER 14
+#define SH_MARKDIRS 15
+#define SH_BGNICE 16
+#define SH_VI 17
+#define SH_VIRAW 18
+#define SH_TFLAG 19
+#define SH_TRACKALL 20
+#define SH_SFLAG 21
+#define SH_NOEXEC 22
+#define SH_GMACS 24
+#define SH_EMACS 25
+#define SH_PRIVILEGED 26
+#define SH_SUBSHARE 27 /* subshell shares state with parent */
+#define SH_NOLOG 28
+#define SH_NOTIFY 29
+#define SH_DICTIONARY 30
+#define SH_PIPEFAIL 32
+#define SH_GLOBSTARS 33
+#define SH_XARGS 34
+#define SH_RC 35
+#define SH_SHOWME 36
+
+/*
+ * passed as flags to builtins in Nambltin_t struct when BLT_OPTIM is on
+ */
+#define SH_BEGIN_OPTIM 0x1
+#define SH_END_OPTIM 0x2
+
+/* The following type is used for error messages */
+
+/* error messages */
+extern const char e_defpath[];
+extern const char e_found[];
+extern const char e_nospace[];
+extern const char e_format[];
+extern const char e_number[];
+extern const char e_restricted[];
+extern const char e_recursive[];
+extern char e_version[];
+
+typedef struct sh_scope
+{
+ struct sh_scope *par_scope;
+ int argc;
+ char **argv;
+ char *cmdname;
+ char *filename;
+ int lineno;
+ Dt_t *var_tree;
+ struct sh_scope *self;
+} Shscope_t;
+
+/*
+ * Saves the state of the shell
+ */
+
+typedef struct sh_static
+{
+ Shopt_t options; /* set -o options */
+ Dt_t *var_tree; /* for shell variables */
+ Dt_t *fun_tree; /* for shell functions */
+ Dt_t *alias_tree; /* for alias names */
+ Dt_t *bltin_tree; /* for builtin commands */
+ Shscope_t *topscope; /* pointer to top-level scope */
+ int inlineno; /* line number of current input file */
+ int exitval; /* most recent exit value */
+ unsigned char trapnote; /* set when trap/signal is pending */
+ char subshell; /* set for virtual subshell */
+#ifdef _SH_PRIVATE
+ _SH_PRIVATE
+#endif /* _SH_PRIVATE */
+} Shell_t;
+
+/* flags for sh_parse */
+#define SH_NL 1 /* Treat new-lines as ; */
+#define SH_EOF 2 /* EOF causes syntax error */
+
+/* symbolic values for sh_iogetiop */
+#define SH_IOCOPROCESS (-2)
+#define SH_IOHISTFILE (-3)
+
+/* symbolic value for sh_fdnotify */
+#define SH_FDCLOSE (-1)
+
+#if defined(__EXPORT__) && defined(_DLL)
+# ifdef _BLD_shell
+# define extern __EXPORT__
+# endif /* _BLD_shell */
+#endif /* _DLL */
+
+extern Dt_t *sh_bltin_tree(void);
+extern void sh_subfork(void);
+extern Shell_t *sh_init(int,char*[],Shinit_f);
+extern int sh_reinit(char*[]);
+extern int sh_eval(Sfio_t*,int);
+extern void sh_delay(double);
+extern void *sh_parse(Shell_t*, Sfio_t*,int);
+extern int sh_trap(const char*,int);
+extern int sh_fun(Namval_t*,Namval_t*, char*[]);
+extern int sh_funscope(int,char*[],int(*)(void*),void*,int);
+extern Sfio_t *sh_iogetiop(int,int);
+extern int sh_main(int, char*[], void(*)(int));
+extern void sh_menu(Sfio_t*, int, char*[]);
+extern Namval_t *sh_addbuiltin(const char*, int(*)(int, char*[],void*), void*);
+extern char *sh_fmtq(const char*);
+extern char *sh_fmtqf(const char*, int, int);
+extern Sfdouble_t sh_strnum(const char*, char**, int);
+extern int sh_access(const char*,int);
+extern int sh_close(int);
+extern int sh_dup(int);
+extern void sh_exit(int);
+extern int sh_fcntl(int, int, ...);
+extern Sfio_t *sh_fd2sfio(int);
+extern int (*sh_fdnotify(int(*)(int,int)))(int,int);
+extern Shell_t *sh_getinterp(void);
+extern int sh_open(const char*, int, ...);
+extern int sh_openmax(void);
+extern Sfio_t *sh_pathopen(const char*);
+extern ssize_t sh_read(int, void*, size_t);
+extern ssize_t sh_write(int, const void*, size_t);
+extern off_t sh_seek(int, off_t, int);
+extern int sh_pipe(int[]);
+extern mode_t sh_umask(mode_t);
+extern void *sh_waitnotify(Shwait_f);
+extern Shscope_t *sh_getscope(int,int);
+extern Shscope_t *sh_setscope(Shscope_t*);
+extern void sh_sigcheck(void);
+extern unsigned long sh_isoption(int);
+extern unsigned long sh_onoption(int);
+extern unsigned long sh_offoption(int);
+extern int sh_waitsafe(void);
+extern int sh_exec(const Shnode_t*,int);
+
+#if SHOPT_DYNAMIC
+ extern void **sh_getliblist(void);
+#endif /* SHOPT_DYNAMIC */
+
+/*
+ * direct access to sh is obsolete, use sh_getinterp() instead
+ */
+#if !defined(_SH_PRIVATE) && defined(__IMPORT__) && !defined(_BLD_shell)
+ extern __IMPORT__ Shell_t sh;
+#else
+ extern Shell_t sh;
+#endif
+
+#ifdef _DLL
+# undef extern
+#endif /* _DLL */
+
+#ifndef _SH_PRIVATE
+# define access(a,b) sh_access(a,b)
+# define close(a) sh_close(a)
+# define exit(a) sh_exit(a)
+# define fcntl(a,b,c) sh_fcntl(a,b,c)
+# define pipe(a) sh_pipe(a)
+# define read(a,b,c) sh_read(a,b,c)
+# define write(a,b,c) sh_write(a,b,c)
+# define umask(a) sh_umask(a)
+# define dup sh_dup
+# if _lib_lseek64
+# define open64 sh_open
+# define lseek64 sh_seek
+# else
+# define open sh_open
+# define lseek sh_seek
+# endif
+#endif /* !_SH_PRIVATE */
+
+#define SH_SIGSET 4
+#define SH_EXITSIG 0400 /* signal exit bit */
+#define SH_EXITMASK (SH_EXITSIG-1) /* normal exit status bits */
+#define SH_RUNPROG -1022 /* needs to be negative and < 256 */
+
+#endif /* SH_INTERACTIVE */
diff --git a/usr/src/lib/libshell/common/include/shlex.h b/usr/src/lib/libshell/common/include/shlex.h
new file mode 100644
index 0000000000..56de279d6c
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/shlex.h
@@ -0,0 +1,152 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef NOTSYM
+/*
+ * UNIX shell
+ * Written by David Korn
+ * These are the definitions for the lexical analyzer
+ */
+
+#include <cdt.h>
+#include "FEATURE/options"
+#include "shnodes.h"
+#include "shtable.h"
+#include "lexstates.h"
+
+struct shlex_t
+{
+ Shell_t *sh; /* pointer to the interpreter */
+ struct argnod *arg; /* current word */
+ struct ionod *heredoc; /* pending here document list */
+ int token; /* current token number */
+ int lastline; /* last line number */
+ int lasttok; /* previous token number */
+ int digits; /* numerical value with word token */
+ char aliasok; /* on when alias is legal */
+ char assignok; /* on when name=value is legal */
+ int inlineno; /* saved value of sh.inlineno */
+ int firstline; /* saved value of sh.st.firstline */
+ int comsub; /* parsing command substitution */
+#if SHOPT_KIA
+ Sfio_t *kiafile; /* kia output file */
+ Sfio_t *kiatmp; /* kia reference file */
+ unsigned long script; /* script entity number */
+ unsigned long fscript; /* script file entity number */
+ unsigned long current; /* current entity number */
+ unsigned long unknown; /* <unknown> entity number */
+ off_t kiabegin; /* offset of first entry */
+ char *scriptname; /* name of script file */
+ Dt_t *entity_tree; /* for entity ids */
+#endif /* SHOPT_KIA */
+};
+
+/* symbols for parsing */
+#define NL '\n'
+#define NOTSYM '!'
+#define SYMRES 0400 /* reserved word symbols */
+#define DOSYM (SYMRES|01)
+#define FISYM (SYMRES|02)
+#define ELIFSYM (SYMRES|03)
+#define ELSESYM (SYMRES|04)
+#define INSYM (SYMRES|05)
+#define THENSYM (SYMRES|06)
+#define DONESYM (SYMRES|07)
+#define ESACSYM (SYMRES|010)
+#define IFSYM (SYMRES|011)
+#define FORSYM (SYMRES|012)
+#define WHILESYM (SYMRES|013)
+#define UNTILSYM (SYMRES|014)
+#define CASESYM (SYMRES|015)
+#define FUNCTSYM (SYMRES|016)
+#define SELECTSYM (SYMRES|017)
+#define TIMESYM (SYMRES|020)
+#define NSPACESYM (SYMRES|021)
+
+#define SYMREP 01000 /* symbols for doubled characters */
+#define BREAKCASESYM (SYMREP|';')
+#define ANDFSYM (SYMREP|'&')
+#define ORFSYM (SYMREP|'|')
+#define IOAPPSYM (SYMREP|'>')
+#define IODOCSYM (SYMREP|'<')
+#define EXPRSYM (SYMREP|'(')
+#define BTESTSYM (SYMREP|'[')
+#define ETESTSYM (SYMREP|']')
+
+#define SYMMASK 0170000
+#define SYMPIPE 010000 /* trailing '|' */
+#define SYMLPAR 020000 /* trailing LPAREN */
+#define SYMAMP 040000 /* trailing '&' */
+#define SYMGT 0100000 /* trailing '>' */
+#define SYMSEMI 0110000 /* trailing ';' */
+#define SYMSHARP 0120000 /* trailing '#' */
+#define IOSEEKSYM (SYMSHARP|'<')
+#define IOMOV0SYM (SYMAMP|'<')
+#define IOMOV1SYM (SYMAMP|'>')
+#define FALLTHRUSYM (SYMAMP|';')
+#define COOPSYM (SYMAMP|'|')
+#define IORDWRSYM (SYMGT|'<')
+#define IOCLOBSYM (SYMPIPE|'>')
+#define IPROCSYM (SYMLPAR|'<')
+#define OPROCSYM (SYMLPAR|'>')
+#define EOFSYM 04000 /* end-of-file */
+#define TESTUNOP 04001
+#define TESTBINOP 04002
+#define LABLSYM 04003
+#define IOVNAME 04004
+
+/* additional parser flag, others in <shell.h> */
+#define SH_EMPTY 04
+#define SH_NOIO 010
+#define SH_ASSIGN 020
+#define SH_FUNDEF 040
+#define SH_ARRAY 0100
+#define SH_SEMI 0200 /* semi-colon after NL ok */
+
+#define SH_COMPASSIGN 010 /* allow compound assignments only */
+
+typedef struct _shlex_
+{
+ struct shlex_t _shlex;
+#ifdef _SHLEX_PRIVATE
+ _SHLEX_PRIVATE
+#endif
+} Lex_t;
+
+#define shlex (((Lex_t*)(sh.lex_context))->_shlex)
+extern const char e_unexpected[];
+extern const char e_unmatched[];
+extern const char e_endoffile[];
+extern const char e_newline[];
+
+/* odd chars */
+#define LBRACE '{'
+#define RBRACE '}'
+#define LPAREN '('
+#define RPAREN ')'
+#define LBRACT '['
+#define RBRACT ']'
+
+extern int sh_lex();
+extern Lex_t *sh_lexopen(Lex_t*, Shell_t*, int);
+extern void sh_lexskip(int,int,int);
+extern void sh_syntax(void);
+
+#endif /* !NOTSYM */
diff --git a/usr/src/lib/libshell/common/include/shnodes.h b/usr/src/lib/libshell/common/include/shnodes.h
new file mode 100644
index 0000000000..b688edb4c5
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/shnodes.h
@@ -0,0 +1,222 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef _SHNODES_H
+#define _SHNODES_H 1
+/*
+ * UNIX shell
+ * Written by David Korn
+ *
+ */
+
+
+#include <ast.h>
+#include "argnod.h"
+
+/* command tree for tretyp */
+#define FINT (02<<COMBITS) /* non-interruptable */
+#define FAMP (04<<COMBITS) /* background */
+#define FPIN (010<<COMBITS) /* input is a pipe */
+#define FPOU (040<<COMBITS) /* output is a pipe */
+#define FPCL (0100<<COMBITS) /* close the pipe */
+#define FCOOP (0200<<COMBITS) /* cooperating process */
+#define FSHOWME (0400<<COMBITS) /* set for showme commands */
+#define FPOSIX (02<<COMBITS) /* posix semantics function */
+#define FLINENO (04<<COMBITS) /* for/case has line number */
+
+#define TNEGATE (01<<COMBITS) /* ! inside [[...]] */
+#define TBINARY (02<<COMBITS) /* binary operator in [[...]] */
+#define TUNARY (04<<COMBITS) /* unary operator in [[...]] */
+#define TTEST (010<<COMBITS)
+#define TPAREN (TBINARY|TUNARY)
+#define TSHIFT (COMBITS+4)
+#define TNSPACE (TFUN|COMSCAN)
+
+#define TCOM 0
+#define TPAR 1
+#define TFIL 2
+#define TLST 3
+#define TIF 4
+#define TWH 5
+#define TUN (TWH|COMSCAN)
+#define TTST 6
+#define TSW 7
+#define TAND 8
+#define TORF 9
+#define TFORK 10
+#define TFOR 11
+#define TSELECT (TFOR|COMSCAN)
+#define TARITH 12
+#define TTIME 13
+#define TSETIO 14
+#define TFUN 15
+
+/* this node is a proforma for those that follow */
+
+struct trenod
+{
+ int tretyp;
+ struct ionod *treio;
+};
+
+
+struct forknod
+{
+ int forktyp;
+ struct ionod *forkio;
+ Shnode_t *forktre;
+ int forkline;
+};
+
+
+struct ifnod
+{
+ int iftyp;
+ Shnode_t *iftre;
+ Shnode_t *thtre;
+ Shnode_t *eltre;
+};
+
+struct whnod
+{
+ int whtyp;
+ Shnode_t *whtre;
+ Shnode_t *dotre;
+ struct arithnod *whinc;
+};
+
+struct fornod
+{
+ int fortyp;
+ char *fornam;
+ Shnode_t *fortre;
+ struct comnod *forlst;
+ int forline;
+};
+
+struct swnod
+{
+ int swtyp;
+ struct argnod *swarg;
+ struct regnod *swlst;
+ struct ionod *swio;
+ int swline;
+};
+
+struct regnod
+{
+ struct argnod *regptr;
+ Shnode_t *regcom;
+ struct regnod *regnxt;
+ char regflag;
+};
+
+struct parnod
+{
+ int partyp;
+ Shnode_t *partre;
+};
+
+struct lstnod
+{
+ int lsttyp;
+ Shnode_t *lstlef;
+ Shnode_t *lstrit;
+};
+
+/* tst is same as lst, but with extra field for line number */
+struct tstnod
+{
+ struct lstnod tstlst;
+ int tstline;
+};
+
+struct functnod
+{
+ int functtyp;
+ char *functnam;
+ Shnode_t *functtre;
+ int functline;
+ off_t functloc;
+ struct slnod *functstak;
+ struct comnod *functargs;
+};
+
+struct arithnod
+{
+ int artyp;
+ int arline;
+ struct argnod *arexpr;
+ void *arcomp;
+};
+
+
+/* types of ionodes stored in iofile */
+#define IOUFD 0x3f /* file descriptor number mask */
+#define IOPUT 0x40 /* > redirection operator */
+#define IOAPP 0x80 /* >> redirection operator */
+#define IODOC 0x100 /* << redirection operator */
+#define IOMOV 0x200 /* <& or >& operators */
+#define IOCLOB 0x400 /* noclobber bit */
+#define IORDW 0x800 /* <> redirection operator */
+#define IORAW 0x1000 /* no expansion needed for filename */
+#define IOSTRG 0x2000 /* here-document stored as incore string */
+#define IOSTRIP 0x4000 /* strip leading tabs for here-document */
+#define IOQUOTE 0x8000 /* here-document delimiter was quoted */
+#define IOVNM 0x10000 /* iovname field is non-zero */
+#define IOLSEEK 0x20000 /* seek operators <# or ># */
+#define IOARITH 0x40000 /* arithmetic seek <# ((expr)) */
+#define IOCOPY IOCLOB /* copy skipped lines onto standard output */
+
+union Shnode_u
+{
+ struct argnod arg;
+ struct ionod io;
+ struct whnod wh;
+ struct swnod sw;
+ struct ifnod if_;
+ struct dolnod dol;
+ struct comnod com;
+ struct trenod tre;
+ struct forknod fork;
+ struct fornod for_;
+ struct regnod reg;
+ struct parnod par;
+ struct lstnod lst;
+ struct tstnod tst;
+ struct functnod funct;
+ struct arithnod ar;
+};
+
+extern void sh_freeup(void);
+extern void sh_funstaks(struct slnod*,int);
+extern Sfio_t *sh_subshell(Shnode_t*, int, int);
+#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
+ __EXPORT__
+#endif
+extern int sh_tdump(Sfio_t*, const Shnode_t*);
+extern Shnode_t *sh_dolparen(void);
+extern Shnode_t *sh_trestore(Sfio_t*);
+#if SHOPT_KIA
+ extern int kiaclose(void);
+ extern unsigned long kiaentity(const char*,int,int,int,int,unsigned long,int,int,const char*);
+#endif /* SHOPT_KIA */
+
+#endif /* _SHNODES_H */
diff --git a/usr/src/lib/libshell/common/include/shtable.h b/usr/src/lib/libshell/common/include/shtable.h
new file mode 100644
index 0000000000..fc4e8e471f
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/shtable.h
@@ -0,0 +1,65 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef _SHTABLE_H
+
+/*
+ * David Korn
+ * AT&T Labs
+ *
+ * Interface definitions read-only data tables for shell
+ *
+ */
+
+#define _SHTABLE_H 1
+
+typedef struct shtable1
+{
+ const char *sh_name;
+ unsigned sh_number;
+} Shtable_t;
+
+struct shtable2
+{
+ const char *sh_name;
+ unsigned sh_number;
+ const char *sh_value;
+};
+
+struct shtable3
+{
+ const char *sh_name;
+ unsigned sh_number;
+ int (*sh_value)(int, char*[], void*);
+};
+
+#define sh_lookup(name,value) (sh_locate(name,(Shtable_t*)(value),sizeof(*(value)))->sh_number)
+extern const Shtable_t shtab_testops[];
+extern const Shtable_t shtab_options[];
+extern const Shtable_t shtab_attributes[];
+extern const struct shtable2 shtab_variables[];
+extern const struct shtable2 shtab_aliases[];
+extern const struct shtable2 shtab_signals[];
+extern const struct shtable3 shtab_builtins[];
+extern const Shtable_t shtab_reserved[];
+extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
+extern int sh_lookopt(const char*, int*);
+
+#endif /* SH_TABLE_H */
diff --git a/usr/src/lib/libshell/common/include/streval.h b/usr/src/lib/libshell/common/include/streval.h
new file mode 100644
index 0000000000..bbf51bd9d7
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/streval.h
@@ -0,0 +1,195 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef SEQPOINT
+/*
+ * D. G. Korn
+ *
+ * arithmetic expression evaluator
+ */
+
+/* The following only is needed for const */
+#include <ast.h>
+#include <math.h>
+#if _AST_VERSION >= 20030127L
+# include <ast_float.h>
+#endif
+
+#if _ast_fltmax_double
+#define LDBL_LLONG_MAX DBL_LLONG_MAX
+#define LDBL_ULLONG_MAX DBL_ULLONG_MAX
+#define LDBL_LLONG_MIN DBL_LLONG_MIN
+#endif
+
+#ifndef LDBL_LLONG_MAX
+# ifdef LLONG_MAX
+# define LDBL_LLONG_MAX ((Sfdouble_t)LLONG_MAX)
+# else
+# ifdef LLONG_MAX
+# define LDBL_LLONG_MAX ((Sfdouble_t)LLONG_MAX)
+# else
+# define LDBL_LLONG_MAX ((Sfdouble_t)((((Sflong_t)1) << (8*sizeof(Sflong_t)-1)) -1 ))
+# endif
+# endif
+#endif
+#ifndef LDBL_ULLONG_MAX
+# ifdef ULLONG_MAX
+# define LDBL_ULLONG_MAX ((Sfdouble_t)ULLONG_MAX)
+# else
+# define LDBL_ULLONG_MAX (2.*((Sfdouble_t)LDBL_LLONG_MAX))
+# endif
+#endif
+#ifndef LDBL_LLONG_MIN
+# ifdef LLONG_MIN
+# define LDBL_LLONG_MIN ((Sfdouble_t)LLONG_MIN)
+# else
+# define LDBL_LLONG_MIN (-LDBL_LLONG_MAX)
+# endif
+#endif
+#ifndef LDBL_DIG
+# define LDBL_DIG DBL_DIG
+#endif
+
+struct lval
+{
+ char *value;
+ Sfdouble_t (*fun)(Sfdouble_t,...);
+ const char *expr;
+ short flag;
+ char isfloat;
+ char nargs;
+ short emode;
+ short level;
+ short elen;
+};
+
+struct mathtab
+{
+ char fname[16];
+ Sfdouble_t (*fnptr)(Sfdouble_t,...);
+};
+
+typedef struct _arith_
+{
+ unsigned char *code;
+ const char *expr;
+ Sfdouble_t (*fun)(const char**,struct lval*,int,Sfdouble_t);
+ short size;
+ short staksize;
+ short emode;
+ short elen;
+} Arith_t;
+#define ARITH_COMP 04 /* set when compile separate from execute */
+
+#define MAXPREC 15 /* maximum precision level */
+#define SEQPOINT 0200 /* sequence point */
+#define NOASSIGN 0100 /* assignment legal with this operator */
+#define RASSOC 040 /* right associative */
+#define NOFLOAT 020 /* illegal with floating point */
+#define PRECMASK 017 /* precision bit mask */
+
+#define A_EOF 1
+#define A_NEQ 2
+#define A_NOT 3
+#define A_MOD 4
+#define A_ANDAND 5
+#define A_AND 6
+#define A_LPAR 7
+#define A_RPAR 8
+#define A_POW 9
+#define A_TIMES 10
+#define A_PLUSPLUS 11
+#define A_PLUS 12
+#define A_COMMA 13
+#define A_MINUSMINUS 14
+#define A_MINUS 15
+#define A_DIV 16
+#define A_LSHIFT 17
+#define A_LE 18
+#define A_LT 19
+#define A_EQ 20
+#define A_ASSIGN 21
+#define A_COLON 22
+#define A_RSHIFT 23
+#define A_GE 24
+#define A_GT 25
+#define A_QCOLON 26
+#define A_QUEST 27
+#define A_XOR 28
+#define A_OROR 29
+#define A_OR 30
+#define A_TILDE 31
+#define A_REG 32
+#define A_DIG 33
+#define A_INCR 34
+#define A_DECR 35
+#define A_PUSHV 36
+#define A_PUSHL 37
+#define A_PUSHN 38
+#define A_PUSHF 39
+#define A_STORE 40
+#define A_POP 41
+#define A_SWAP 42
+#define A_UMINUS 43
+#define A_JMPZ 44
+#define A_JMPNZ 45
+#define A_JMP 46
+#define A_CALL0 47
+#define A_CALL1 48
+#define A_CALL2 49
+#define A_CALL3 50
+#define A_DOT 51
+#define A_LIT 52
+#define A_NOTNOT 53
+
+
+/* define error messages */
+extern const unsigned char strval_precedence[35];
+extern const char strval_states[64];
+extern const char e_moretokens[];
+extern const char e_argcount[];
+extern const char e_paren[];
+extern const char e_badnum[];
+extern const char e_badcolon[];
+extern const char e_recursive[];
+extern const char e_divzero[];
+extern const char e_synbad[];
+extern const char e_notlvalue[];
+extern const char e_function[];
+extern const char e_questcolon[];
+extern const char e_incompatible[];
+extern const char e_domain[];
+extern const char e_overflow[];
+extern const char e_singularity[];
+extern const char e_dict[];
+extern const char e_charconst[];
+extern const struct mathtab shtab_math[];
+
+/* function code for the convert function */
+
+#define LOOKUP 0
+#define ASSIGN 1
+#define VALUE 2
+#define MESSAGE 3
+
+extern Sfdouble_t strval(const char*,char**,Sfdouble_t(*)(const char**,struct lval*,int,Sfdouble_t),int);
+extern Arith_t *arith_compile(const char*,char**,Sfdouble_t(*)(const char**,struct lval*,int,Sfdouble_t),int);
+extern Sfdouble_t arith_exec(Arith_t*);
+#endif /* !SEQPOINT */
diff --git a/usr/src/lib/libshell/common/include/terminal.h b/usr/src/lib/libshell/common/include/terminal.h
new file mode 100644
index 0000000000..1712c12bab
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/terminal.h
@@ -0,0 +1,195 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+#ifndef _terminal_
+#define _terminal_ 1
+
+#include "FEATURE/ttys"
+/*
+ * terminal interface
+ * complicated by the fact that there are so many variations
+ * This will use POSIX <termios.h> interface where available
+ */
+
+#ifdef _hdr_termios
+# include <termios.h>
+# if __sgi__ || sgi /* special hack to eliminate ^M problem */
+# ifndef ECHOCTL
+# define ECHOCTL ECHOE
+# endif /* ECHOCTL */
+# ifndef CNSUSP
+# define CNSUSP CNSWTCH
+# endif /* CNSUSP */
+# endif /* sgi */
+# ifdef _NEXT_SOURCE
+# define _lib_tcgetattr 1
+# define _lib_tcgetpgrp 1
+# endif /* _NEXT_SOURCE */
+#else
+# if defined(_sys_termios) && defined(_lib_tcgetattr)
+# include <sys/termios.h>
+# define _hdr_termios
+# else
+# undef _sys_termios
+# endif /* _sys_termios */
+#endif /* _hdr_termios */
+
+#ifdef _hdr_termios
+# undef _hdr_sgtty
+# undef tcgetattr
+# undef tcsetattr
+# undef tcgetpgrp
+# undef tcsetpgrp
+# undef cfgetospeed
+# ifndef TCSANOW
+# define TCSANOW TCSETS
+# define TCSADRAIN TCSETSW
+# define TCSAFLUSH TCSETSF
+# endif /* TCSANOW */
+ /* The following corrects bugs in some implementations */
+# if defined(TCSADFLUSH) && !defined(TCSAFLUSH)
+# define TCSAFLUSH TCSADFLUSH
+# endif /* TCSADFLUSH */
+# ifndef _lib_tcgetattr
+# undef tcgetattr
+# define tcgetattr(fd,tty) ioctl(fd, TCGETS, tty)
+# undef tcsetattr
+# define tcsetattr(fd,action,tty) ioctl(fd, action, tty)
+# undef cfgetospeed
+# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD)
+# endif /* _lib_tcgetattr */
+# undef TIOCGETC
+# if SHOPT_OLDTERMIO /* use both termios and termio */
+# ifdef _hdr_termio
+# include <termio.h>
+# else
+# ifdef _sys_termio
+# include <sys/termio.h>
+# define _hdr_termio 1
+# else
+# undef SHOPT_OLDTERMIO
+# endif /* _sys_termio */
+# endif /* _hdr_termio */
+# endif /* SHOPT_OLDTERMIO */
+#else
+# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD)
+# undef SHOPT_OLDTERMIO
+# ifdef _hdr_termio
+# include <termio.h>
+# else
+# ifdef _sys_termio
+# include <sys/termio.h>
+# define _hdr_termio 1
+# endif /* _sys_termio */
+# endif /* _hdr_termio */
+# ifdef _hdr_termio
+# define termios termio
+# undef TIOCGETC
+# define tcgetattr(fd,tty) ioctl(fd, TCGETA, tty)
+# define tcsetattr(fd,action,tty) ioctl(fd, action, tty)
+
+# ifdef _sys_bsdtty
+# include <sys/bsdtty.h>
+# endif /* _sys_bsdtty */
+# else
+# ifdef _hdr_sgtty
+# include <sgtty.h>
+# ifndef LPENDIN
+# ifdef _sys_nttyio
+# include <sys/nttyio.h>
+# endif /* _sys_nttyio */
+# endif /* LPENDIN */
+# define termios sgttyb
+# ifdef TIOCSETN
+# undef TCSETAW
+# endif /* TIOCSETN */
+# ifdef TIOCGETP
+# define tcgetattr(fd,tty) ioctl(fd, TIOCGETP, tty)
+# define tcsetattr(fd,action,tty) ioctl(fd, action, tty)
+# else
+# define tcgetattr(fd,tty) gtty(fd, tty)
+# define tcsetattr(fd,action,tty) stty(fd, tty)
+# endif /* TIOCGETP */
+# endif /* _hdr_sgtty */
+# endif /* hdr_termio */
+
+# ifndef TCSANOW
+# ifdef TCSETAW
+# define TCSANOW TCSETA
+# ifdef u370
+ /* delays are too long, don't wait for output to drain */
+# define TCSADRAIN TCSETA
+# else
+# define TCSADRAIN TCSETAW
+# endif /* u370 */
+# define TCSAFLUSH TCSETAF
+# else
+# ifdef TIOCSETN
+# define TCSANOW TIOCSETN
+# define TCSADRAIN TIOCSETN
+# define TCSAFLUSH TIOCSETP
+# endif /* TIOCSETN */
+# endif /* TCSETAW */
+# endif /* TCSANOW */
+#endif /* _hdr_termios */
+
+/* set ECHOCTL if driver can echo control charaters as ^c */
+#ifdef LCTLECH
+# ifndef ECHOCTL
+# define ECHOCTL LCTLECH
+# endif /* !ECHOCTL */
+#endif /* LCTLECH */
+#ifdef LNEW_CTLECH
+# ifndef ECHOCTL
+# define ECHOCTL LNEW_CTLECH
+# endif /* !ECHOCTL */
+#endif /* LNEW_CTLECH */
+#ifdef LNEW_PENDIN
+# ifndef PENDIN
+# define PENDIN LNEW_PENDIN
+# endif /* !PENDIN */
+#endif /* LNEW_PENDIN */
+#ifndef ECHOCTL
+# ifndef VEOL
+# define RAWONLY 1
+# endif /* !VEOL */
+#endif /* !ECHOCTL */
+
+#ifdef _sys_filio
+# ifndef FIONREAD
+# include <sys/filio.h>
+# endif /* FIONREAD */
+#endif /* _sys_filio */
+/* set FIORDCHK if you can check for characters in input queue */
+#ifdef FIONREAD
+# ifndef FIORDCHK
+# define FIORDCHK FIONREAD
+# endif /* !FIORDCHK */
+#endif /* FIONREAD */
+
+extern int tty_alt(int);
+extern void tty_cooked(int);
+extern int tty_get(int,struct termios*);
+extern int tty_raw(int,int);
+extern int tty_check(int);
+extern int tty_set(int, int, struct termios*);
+
+#endif /* _terminal_ */
diff --git a/usr/src/lib/libshell/common/include/test.h b/usr/src/lib/libshell/common/include/test.h
new file mode 100644
index 0000000000..b1ece6fcfa
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/test.h
@@ -0,0 +1,71 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef TEST_ARITH
+/*
+ * UNIX shell
+ * David Korn
+ * AT&T Labs
+ *
+ */
+
+#include "FEATURE/options"
+#include "shtable.h"
+/*
+ * These are the valid test operators
+ */
+
+#define TEST_ARITH 040 /* arithmetic operators */
+#define TEST_BINOP 0200 /* binary operator */
+#define TEST_PATTERN 0100 /* turn off bit for pattern compares */
+
+#define TEST_NE (TEST_ARITH|9)
+#define TEST_EQ (TEST_ARITH|4)
+#define TEST_GE (TEST_ARITH|5)
+#define TEST_GT (TEST_ARITH|6)
+#define TEST_LE (TEST_ARITH|7)
+#define TEST_LT (TEST_ARITH|8)
+#define TEST_OR (TEST_BINOP|1)
+#define TEST_AND (TEST_BINOP|2)
+#define TEST_SNE (TEST_PATTERN|1)
+#define TEST_SEQ (TEST_PATTERN|14)
+#define TEST_PNE 1
+#define TEST_PEQ 14
+#define TEST_EF 3
+#define TEST_NT 10
+#define TEST_OT 12
+#define TEST_SLT 15
+#define TEST_SGT 16
+#define TEST_END 8
+#define TEST_REP 20
+
+extern int test_unop(int, const char*);
+extern int test_inode(const char*, const char*);
+extern int test_binop(int, const char*, const char*);
+
+extern const char sh_opttest[];
+extern const char test_opchars[];
+extern const char e_argument[];
+extern const char e_missing[];
+extern const char e_badop[];
+extern const char e_tstbegin[];
+extern const char e_tstend[];
+
+#endif /* TEST_ARITH */
diff --git a/usr/src/lib/libshell/common/include/timeout.h b/usr/src/lib/libshell/common/include/timeout.h
new file mode 100644
index 0000000000..3248b562c1
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/timeout.h
@@ -0,0 +1,30 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+/*
+ * UNIX shell
+ *
+ * AT&T Labs
+ *
+ */
+
+#define TGRACE 60 /* grace period before termination */
+ /* The time_warn message contains this number */
+extern const char e_timeout[];
+extern const char e_timewarn[];
diff --git a/usr/src/lib/libshell/common/include/ulimit.h b/usr/src/lib/libshell/common/include/ulimit.h
new file mode 100644
index 0000000000..b31d12b494
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/ulimit.h
@@ -0,0 +1,175 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+#ifndef _ULIMIT_H
+#define _ULIMIT_H 1
+/*
+ * This is for the ulimit built-in command
+ */
+
+#include "FEATURE/time"
+#include "FEATURE/rlimits"
+#if defined(_sys_resource) && defined(_lib_getrlimit)
+# include <sys/resource.h>
+# if !defined(RLIMIT_FSIZE) && defined(_sys_vlimit)
+ /* This handles hp/ux problem */
+# include <sys/vlimit.h>
+# define RLIMIT_FSIZE (LIM_FSIZE-1)
+# define RLIMIT_DATA (LIM_DATA-1)
+# define RLIMIT_STACK (LIM_STACK-1)
+# define RLIMIT_CORE (LIM_CORE-1)
+# define RLIMIT_CPU (LIM_CPU-1)
+# ifdef LIM_MAXRSS
+# define RLIMIT_RSS (LIM_MAXRSS-1)
+# endif /* LIM_MAXRSS */
+# endif
+# undef _lib_ulimit
+#else
+# ifdef _sys_vlimit
+# include <sys/vlimit.h>
+# undef _lib_ulimit
+# define RLIMIT_FSIZE LIM_FSIZE
+# define RLIMIT_DATA LIM_DATA
+# define RLIMIT_STACK LIM_STACK
+# define RLIMIT_CORE LIM_CORE
+# define RLIMIT_CPU LIM_CPU
+# ifdef LIM_MAXRSS
+# define RLIMIT_RSS LIM_MAXRSS
+# endif /* LIM_MAXRSS */
+# else
+# ifdef _lib_ulimit
+# define vlimit ulimit
+# endif /* _lib_ulimit */
+# endif /* _lib_vlimit */
+#endif
+
+#ifdef RLIM_INFINITY
+# define INFINITY RLIM_INFINITY
+#else
+# ifndef INFINITY
+# define INFINITY ((rlim_t)-1L)
+# endif /* INFINITY */
+#endif /* RLIM_INFINITY */
+
+#if defined(_lib_getrlimit) || defined(_lib_vlimit) || defined(_lib_ulimit)
+# ifndef RLIMIT_CPU
+# define RLIMIT_CPU 0
+# endif /* !RLIMIT_CPU */
+# ifndef RLIMIT_DATA
+# define RLIMIT_DATA 0
+# endif /* !RLIMIT_DATA */
+# ifndef RLIMIT_RSS
+# define RLIMIT_RSS 0
+# endif /* !RLIMIT_RSS */
+# ifndef RLIMIT_STACK
+# define RLIMIT_STACK 0
+# endif /* !RLIMIT_STACK */
+# ifndef RLIMIT_CORE
+# define RLIMIT_CORE 0
+# endif /* !RLIMIT_CORE */
+# ifndef RLIMIT_VMEM
+# define RLIMIT_VMEM 0
+# endif /* !RLIMIT_VMEM */
+# ifndef RLIMIT_NOFILE
+# define RLIMIT_NOFILE 0
+# endif /* !RLIMIT_NOFILE */
+#else
+# define _no_ulimit
+#endif
+#ifndef _typ_rlim_t
+ typedef long rlim_t;
+#endif
+
+#if !defined(RLIMIT_NOFILE) && defined(RLIMIT_OFILE)
+#define RLIMIT_NOFILE RLIMIT_OFILE
+#endif
+
+#ifndef RLIMIT_UNKNOWN
+#define RLIMIT_UNKNOWN (-9999)
+#endif
+#ifndef RLIMIT_AS
+#define RLIMIT_AS RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_CORE
+#define RLIMIT_CORE RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_CPU
+#define RLIMIT_CPU RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_DATA
+#define RLIMIT_DATA RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_FSIZE
+#define RLIMIT_FSIZE RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_LOCKS
+#define RLIMIT_LOCKS RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_MEMLOCK
+#define RLIMIT_MEMLOCK RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_NOFILE
+#define RLIMIT_NOFILE RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_NPROC
+#define RLIMIT_NPROC RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_PIPE
+#define RLIMIT_PIPE RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_RSS
+#define RLIMIT_RSS RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_SBSIZE
+#define RLIMIT_SBSIZE RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_STACK
+#define RLIMIT_STACK RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_PTHREAD
+#define RLIMIT_PTHREAD RLIMIT_UNKNOWN
+#endif
+#ifndef RLIMIT_VMEM
+#define RLIMIT_VMEM RLIMIT_UNKNOWN
+#endif
+
+#define LIM_COUNT 0
+#define LIM_BLOCK 1
+#define LIM_BYTE 2
+#define LIM_KBYTE 3
+#define LIM_SECOND 4
+
+typedef struct Limit_s
+{
+ const char name[8];
+ const char* description;
+ int index;
+ const char* conf;
+ unsigned char option;
+ unsigned char type;
+} Limit_t;
+
+extern const Limit_t shtab_limits[];
+extern const int shtab_units[];
+
+extern const char e_unlimited[];
+extern const char* e_units[];
+
+#endif /* _ULIMIT_H */
diff --git a/usr/src/lib/libshell/common/include/variables.h b/usr/src/lib/libshell/common/include/variables.h
new file mode 100644
index 0000000000..2ceefcf9f7
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/variables.h
@@ -0,0 +1,104 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+#ifndef SH_VALNOD
+
+#include <option.h>
+#include "FEATURE/options"
+#include "FEATURE/dynamic"
+
+/* The following defines are coordinated with data in data/variables.c */
+
+#define PATHNOD (sh.bltin_nodes)
+#define PS1NOD (sh.bltin_nodes+1)
+#define PS2NOD (sh.bltin_nodes+2)
+#define IFSNOD (sh.bltin_nodes+3)
+#define PWDNOD (sh.bltin_nodes+4)
+#define HOME (sh.bltin_nodes+5)
+#define MAILNOD (sh.bltin_nodes+6)
+#define REPLYNOD (sh.bltin_nodes+7)
+#define SHELLNOD (sh.bltin_nodes+8)
+#define EDITNOD (sh.bltin_nodes+9)
+#define MCHKNOD (sh.bltin_nodes+10)
+#define RANDNOD (sh.bltin_nodes+11)
+#define ENVNOD (sh.bltin_nodes+12)
+#define HISTFILE (sh.bltin_nodes+13)
+#define HISTSIZE (sh.bltin_nodes+14)
+#define HISTEDIT (sh.bltin_nodes+15)
+#define HISTCUR (sh.bltin_nodes+16)
+#define FCEDNOD (sh.bltin_nodes+17)
+#define CDPNOD (sh.bltin_nodes+18)
+#define MAILPNOD (sh.bltin_nodes+19)
+#define PS3NOD (sh.bltin_nodes+20)
+#define OLDPWDNOD (sh.bltin_nodes+21)
+#define VISINOD (sh.bltin_nodes+22)
+#define COLUMNS (sh.bltin_nodes+23)
+#define LINES (sh.bltin_nodes+24)
+#define PPIDNOD (sh.bltin_nodes+25)
+#define L_ARGNOD (sh.bltin_nodes+26)
+#define TMOUTNOD (sh.bltin_nodes+27)
+#define SECONDS (sh.bltin_nodes+28)
+#define LINENO (sh.bltin_nodes+29)
+#define OPTARGNOD (sh.bltin_nodes+30)
+#define OPTINDNOD (sh.bltin_nodes+31)
+#define PS4NOD (sh.bltin_nodes+32)
+#define FPATHNOD (sh.bltin_nodes+33)
+#define LANGNOD (sh.bltin_nodes+34)
+#define LCALLNOD (sh.bltin_nodes+35)
+#define LCCOLLNOD (sh.bltin_nodes+36)
+#define LCTYPENOD (sh.bltin_nodes+37)
+#define LCMSGNOD (sh.bltin_nodes+38)
+#define LCNUMNOD (sh.bltin_nodes+39)
+#define FIGNORENOD (sh.bltin_nodes+40)
+#define DOTSHNOD (sh.bltin_nodes+41)
+#define ED_CHRNOD (sh.bltin_nodes+42)
+#define ED_COLNOD (sh.bltin_nodes+43)
+#define ED_TXTNOD (sh.bltin_nodes+44)
+#define ED_MODENOD (sh.bltin_nodes+45)
+#define SH_NAMENOD (sh.bltin_nodes+46)
+#define SH_SUBSCRNOD (sh.bltin_nodes+47)
+#define SH_VALNOD (sh.bltin_nodes+48)
+#define SH_VERSIONNOD (sh.bltin_nodes+49)
+#define SH_DOLLARNOD (sh.bltin_nodes+50)
+#define SH_MATCHNOD (sh.bltin_nodes+51)
+#define SH_COMMANDNOD (sh.bltin_nodes+52)
+#define SH_PATHNAMENOD (sh.bltin_nodes+53)
+#define SH_FUNNAMENOD (sh.bltin_nodes+54)
+#define SH_SUBSHELLNOD (sh.bltin_nodes+55)
+#define SH_LEVELNOD (sh.bltin_nodes+56)
+#if SHOPT_FS_3D
+# define VPATHNOD (sh.bltin_nodes+57)
+# define NFS_3D 1
+#else
+# define NFS_3D 0
+#endif /* SHOPT_FS_3D */
+#if SHOPT_VPIX
+# define DOSPATHNOD (sh.bltin_nodes+57+NFS_3D)
+# define VPIXNOD (sh.bltin_nodes+58+NFS_3D)
+# define NVPIX (NFS_3D+2)
+#else
+# define NVPIX NFS_3D
+#endif /* SHOPT_VPIX */
+#ifdef apollo
+# define SYSTYPENOD (sh.bltin_nodes+57+NVPIX)
+#endif /* apollo */
+
+#endif /* SH_VALNOD */
diff --git a/usr/src/lib/libshell/common/include/version.h b/usr/src/lib/libshell/common/include/version.h
new file mode 100644
index 0000000000..dafdfcbd68
--- /dev/null
+++ b/usr/src/lib/libshell/common/include/version.h
@@ -0,0 +1,20 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Knowledge Ventures *
+* *
+* A copy of the License is available at *
+* http://www.opensource.org/licenses/cpl1.0.txt *
+* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* David Korn <dgk@research.att.com> *
+* *
+***********************************************************************/
+#define SH_RELEASE "1993-12-28 s+"