diff options
author | April Chin <April.Chin@Sun.COM> | 2008-12-27 14:59:38 -0800 |
---|---|---|
committer | April Chin <April.Chin@Sun.COM> | 2008-12-27 14:59:38 -0800 |
commit | 7c2fbfb345896881c631598ee3852ce9ce33fb07 (patch) | |
tree | 4b173b5657508562dfc0aa05f7d056d1e9add505 /usr/src/lib/libshell/common/sh/trestore.c | |
parent | 6071ac1de68fed78e1e10052045bbb5f1732a263 (diff) | |
download | illumos-gate-7c2fbfb345896881c631598ee3852ce9ce33fb07.tar.gz |
PSARC/2008/094 ksh93 Update 1
PSARC/2008/344 ksh93 Integration Update 1 Amendments 1
PSARC/2008/589 Remove /usr/bin/printf from PSARC case 2008 094
6619428 *ksh93* RFE: Update ksh93 in Solaris to ast-ksh.2008-11-04
6788659 RFE: Update libpp in Solaris to ast-open.2008-07-25
6561901 RFE: Add "shcomp" (shell script compiler) + kernel module to exec binary sh code
6599668 RFE: Move consumers of alias.sh over to ksh93
6595183 *ksh93* RFE: Update ksh93-integration demo code
6775901 *ksh93* no C message catalogs are generated for ksh93
6451262 *sleep* RFE: /usr/bin/sleep should support floating-point values
6687139 *ksh93* command substitution, exec, and stdout redirection cause allocation loop
6703761 *ksh93* crashes in script containing uncommon output redirections
6715496 *ksh93* SEGVs on array reinitialization
6713682 *ksh93* Creating a compound variable in a subshell "bleeds through" to the calling subshell
6672350 *ksh93* causes parent shell to die when child shell is suspended
6745015 *ksh93* VARIABLE=`command substitution` assignment is not reliable on OpenSolaris
6710205 *ksh93* problem with command substitution (within back quotes) containing \$'
6737600 *ksh93* exits debugger when user presses ctrl-c
6748645 *ksh93* fc -l -e - is mis-parsed, outputs wrong error message "-e - requires single argument"
6754020 *ksh93* does weird '[' expansion
6753538 *ksh93* umask modification leaks out of a ksh93 subshell
6766246 *ksh93* bug in pattern matching
6763594 *ksh93* executes command after "command" builtin twice on failure
6762665 *ksh93* Difficult-to-reproduce SIGSEGV in ksh93
Diffstat (limited to 'usr/src/lib/libshell/common/sh/trestore.c')
-rw-r--r-- | usr/src/lib/libshell/common/sh/trestore.c | 177 |
1 files changed, 89 insertions, 88 deletions
diff --git a/usr/src/lib/libshell/common/sh/trestore.c b/usr/src/lib/libshell/common/sh/trestore.c index d866ca712f..b9fc63d82f 100644 --- a/usr/src/lib/libshell/common/sh/trestore.c +++ b/usr/src/lib/libshell/common/sh/trestore.c @@ -1,10 +1,10 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 1982-2007 AT&T Knowledge Ventures * +* Copyright (c) 1982-2008 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * -* by AT&T Knowledge Ventures * +* by AT&T Intellectual Property * * * * A copy of the License is available at * * http://www.opensource.org/licenses/cpl1.0.txt * @@ -32,29 +32,29 @@ #include "path.h" #include "io.h" -static struct dolnod *r_comlist(void); -static struct argnod *r_arg(void); -static struct ionod *r_redirect(void); -static struct regnod *r_switch(void); -static Shnode_t *r_tree(void); -static char *r_string(void); -static void r_comarg(struct comnod*); +static struct dolnod *r_comlist(Shell_t*); +static struct argnod *r_arg(Shell_t*); +static struct ionod *r_redirect(Shell_t*); +static struct regnod *r_switch(Shell_t*); +static Shnode_t *r_tree(Shell_t*); +static char *r_string(Stk_t*); +static void r_comarg(Shell_t*,struct comnod*); static Sfio_t *infile; -#define getnode(type) ((Shnode_t*)stakalloc(sizeof(struct type))) +#define getnode(s,type) ((Shnode_t*)stkalloc((s),sizeof(struct type))) -Shnode_t *sh_trestore(Sfio_t *in) +Shnode_t *sh_trestore(Shell_t *shp,Sfio_t *in) { Shnode_t *t; infile = in; - t = r_tree(); + t = r_tree(shp); return(t); } /* * read in a shell tree */ -static Shnode_t *r_tree() +static Shnode_t *r_tree(Shell_t *shp) { long l = sfgetl(infile); register int type; @@ -66,101 +66,101 @@ static Shnode_t *r_tree() { case TTIME: case TPAR: - t = getnode(parnod); - t->par.partre = r_tree(); + t = getnode(shp->stk,parnod); + t->par.partre = r_tree(shp); break; case TCOM: - t = getnode(comnod); + t = getnode(shp->stk,comnod); t->tre.tretyp = type; - r_comarg((struct comnod*)t); + r_comarg(shp,(struct comnod*)t); break; case TSETIO: case TFORK: - t = getnode(forknod); + t = getnode(shp->stk,forknod); t->fork.forkline = sfgetu(infile); - t->fork.forktre = r_tree(); - t->fork.forkio = r_redirect(); + t->fork.forktre = r_tree(shp); + t->fork.forkio = r_redirect(shp); break; case TIF: - t = getnode(ifnod); - t->if_.iftre = r_tree(); - t->if_.thtre = r_tree(); - t->if_.eltre = r_tree(); + t = getnode(shp->stk,ifnod); + t->if_.iftre = r_tree(shp); + t->if_.thtre = r_tree(shp); + t->if_.eltre = r_tree(shp); break; case TWH: - t = getnode(whnod); - t->wh.whinc = (struct arithnod*)r_tree(); - t->wh.whtre = r_tree(); - t->wh.dotre = r_tree(); + t = getnode(shp->stk,whnod); + t->wh.whinc = (struct arithnod*)r_tree(shp); + t->wh.whtre = r_tree(shp); + t->wh.dotre = r_tree(shp); break; case TLST: case TAND: case TORF: case TFIL: - t = getnode(lstnod); - t->lst.lstlef = r_tree(); - t->lst.lstrit = r_tree(); + t = getnode(shp->stk,lstnod); + t->lst.lstlef = r_tree(shp); + t->lst.lstrit = r_tree(shp); break; case TARITH: - t = getnode(arithnod); + t = getnode(shp->stk,arithnod); t->ar.arline = sfgetu(infile); - t->ar.arexpr = r_arg(); + t->ar.arexpr = r_arg(shp); t->ar.arcomp = 0; if((t->ar.arexpr)->argflag&ARG_RAW) t->ar.arcomp = sh_arithcomp((t->ar.arexpr)->argval); break; case TFOR: - t = getnode(fornod); + t = getnode(shp->stk,fornod); t->for_.forline = 0; if(type&FLINENO) t->for_.forline = sfgetu(infile); - t->for_.fortre = r_tree(); - t->for_.fornam = r_string(); - t->for_.forlst = (struct comnod*)r_tree(); + t->for_.fortre = r_tree(shp); + t->for_.fornam = r_string(shp->stk); + t->for_.forlst = (struct comnod*)r_tree(shp); break; case TSW: - t = getnode(swnod); + t = getnode(shp->stk,swnod); t->sw.swline = 0; if(type&FLINENO) t->sw.swline = sfgetu(infile); - t->sw.swarg = r_arg(); + t->sw.swarg = r_arg(shp); if(type&COMSCAN) - t->sw.swio = r_redirect(); + t->sw.swio = r_redirect(shp); else t->sw.swio = 0; - t->sw.swlst = r_switch(); + t->sw.swlst = r_switch(shp); break; case TFUN: { Stak_t *savstak; struct slnod *slp; - t = getnode(functnod); + t = getnode(shp->stk,functnod); t->funct.functloc = -1; t->funct.functline = sfgetu(infile); - t->funct.functnam = r_string(); + t->funct.functnam = r_string(shp->stk); savstak = stakcreate(STAK_SMALL); savstak = stakinstall(savstak, 0); - slp = (struct slnod*)stakalloc(sizeof(struct slnod)); + slp = (struct slnod*)stkalloc(shp->stk,sizeof(struct slnod)); slp->slchild = 0; - slp->slnext = sh.st.staklist; - sh.st.staklist = 0; - t->funct.functtre = r_tree(); + slp->slnext = shp->st.staklist; + shp->st.staklist = 0; + t->funct.functtre = r_tree(shp); t->funct.functstak = slp; slp->slptr = stakinstall(savstak,0); - slp->slchild = sh.st.staklist; - t->funct.functargs = (struct comnod*)r_tree(); + slp->slchild = shp->st.staklist; + t->funct.functargs = (struct comnod*)r_tree(shp); break; } case TTST: - t = getnode(tstnod); + t = getnode(shp->stk,tstnod); t->tst.tstline = sfgetu(infile); if((type&TPAREN)==TPAREN) - t->lst.lstlef = r_tree(); + t->lst.lstlef = r_tree(shp); else { - t->lst.lstlef = (Shnode_t*)r_arg(); + t->lst.lstlef = (Shnode_t*)r_arg(shp); if((type&TBINARY)) - t->lst.lstrit = (Shnode_t*)r_arg(); + t->lst.lstrit = (Shnode_t*)r_arg(shp); } } if(t) @@ -168,13 +168,14 @@ static Shnode_t *r_tree() return(t); } -static struct argnod *r_arg(void) +static struct argnod *r_arg(Shell_t *shp) { register struct argnod *ap=0, *apold, *aptop=0; register long l; + Stk_t *stkp=shp->stk; while((l=sfgetu(infile))>0) { - ap = (struct argnod*)stakseek((unsigned)l+ARGVAL); + ap = (struct argnod*)stkseek(stkp,(unsigned)l+ARGVAL); if(!aptop) aptop = ap; else @@ -187,27 +188,27 @@ static struct argnod *r_arg(void) ap->argval[l] = 0; ap->argchn.cp = 0; ap->argflag = sfgetc(infile); - if(ap->argflag&ARG_MESSAGE) + if((ap->argflag&ARG_MESSAGE) && *ap->argval) { /* replace international messages */ - ap = sh_endword(1); + ap = sh_endword(shp,1); ap->argflag &= ~ARG_MESSAGE; if(!(ap->argflag&(ARG_MAC|ARG_EXP))) - ap = sh_endword(0); + ap = sh_endword(shp,0); else { - ap = (struct argnod*)stakfreeze(0); + ap = (struct argnod*)stkfreeze(stkp,0); if(ap->argflag==0) ap->argflag = ARG_RAW; } } else - ap = (struct argnod*)stakfreeze(0); - if(*ap->argval==0 && (ap->argflag&~ARG_APPEND)==0) + ap = (struct argnod*)stkfreeze(stkp,0); + if(*ap->argval==0 && (ap->argflag&~(ARG_APPEND|ARG_MESSAGE|ARG_QUOTED))==0) { - struct fornod *fp = (struct fornod*)getnode(fornod); + struct fornod *fp = (struct fornod*)getnode(shp->stk,fornod); fp->fortyp = sfgetu(infile); - fp->fortre = r_tree(); + fp->fortre = r_tree(shp); fp->fornam = ap->argval+1; ap->argchn.ap = (struct argnod*)fp; } @@ -218,34 +219,34 @@ static struct argnod *r_arg(void) return(aptop); } -static struct ionod *r_redirect(void) +static struct ionod *r_redirect(Shell_t* shp) { register long l; register struct ionod *iop=0, *iopold, *ioptop=0; while((l=sfgetl(infile))>=0) { - iop = (struct ionod*)getnode(ionod); + iop = (struct ionod*)getnode(shp->stk,ionod); if(!ioptop) ioptop = iop; else iopold->ionxt = iop; iop->iofile = l; - iop->ioname = r_string(); - if(iop->iodelim = r_string()) + iop->ioname = r_string(shp->stk); + if(iop->iodelim = r_string(shp->stk)) { iop->iosize = sfgetl(infile); - if(sh.heredocs) - iop->iooffset = sfseek(sh.heredocs,(off_t)0,SEEK_END); + if(shp->heredocs) + iop->iooffset = sfseek(shp->heredocs,(off_t)0,SEEK_END); else { - sh.heredocs = sftmp(512); + shp->heredocs = sftmp(512); iop->iooffset = 0; } - sfmove(infile,sh.heredocs, iop->iosize, -1); + sfmove(infile,shp->heredocs, iop->iosize, -1); } iopold = iop; if(iop->iofile&IOVNM) - iop->iovname = r_string(); + iop->iovname = r_string(shp->stk); else iop->iovname = 0; iop->iofile &= ~IOVNM; @@ -255,30 +256,30 @@ static struct ionod *r_redirect(void) return(ioptop); } -static void r_comarg(struct comnod *com) +static void r_comarg(Shell_t *shp,struct comnod *com) { char *cmdname=0; - com->comio = r_redirect(); - com->comset = r_arg(); + com->comio = r_redirect(shp); + com->comset = r_arg(shp); com->comstate = 0; if(com->comtyp&COMSCAN) { - com->comarg = r_arg(); + com->comarg = r_arg(shp); if(com->comarg->argflag==ARG_RAW) cmdname = com->comarg->argval; } - else if(com->comarg = (struct argnod*)r_comlist()) + else if(com->comarg = (struct argnod*)r_comlist(shp)) cmdname = ((struct dolnod*)(com->comarg))->dolval[ARG_SPARE]; com->comline = sfgetu(infile); com->comnamq = 0; if(cmdname) { char *cp; - com->comnamp = (void*)nv_search(cmdname,sh.fun_tree,0); + com->comnamp = (void*)nv_search(cmdname,shp->fun_tree,0); if(com->comnamp && (cp =strrchr(cmdname+1,'.'))) { *cp = 0; - com->comnamp = (void*)nv_open(cmdname,sh.var_tree,NV_VARNAME|NV_NOADD|NV_NOARRAY); + com->comnamp = (void*)nv_open(cmdname,shp->var_tree,NV_VARNAME|NV_NOADD|NV_NOARRAY); *cp = '.'; } } @@ -286,36 +287,36 @@ static void r_comarg(struct comnod *com) com->comnamp = 0; } -static struct dolnod *r_comlist(void) +static struct dolnod *r_comlist(Shell_t *shp) { register struct dolnod *dol=0; register long l; register char **argv; if((l=sfgetl(infile))>0) { - dol = (struct dolnod*)stakalloc(sizeof(struct dolnod) + sizeof(char*)*(l+ARG_SPARE)); + dol = (struct dolnod*)stkalloc(shp->stk,sizeof(struct dolnod) + sizeof(char*)*(l+ARG_SPARE)); dol->dolnum = l; dol->dolbot = ARG_SPARE; argv = dol->dolval+ARG_SPARE; - while(*argv++ = r_string()); + while(*argv++ = r_string(shp->stk)); } return(dol); } -static struct regnod *r_switch(void) +static struct regnod *r_switch(Shell_t *shp) { register long l; struct regnod *reg=0,*regold,*regtop=0; while((l=sfgetl(infile))>=0) { - reg = (struct regnod*)getnode(regnod); + reg = (struct regnod*)getnode(shp->stk,regnod); if(!regtop) regtop = reg; else regold->regnxt = reg; reg->regflag = l; - reg->regptr = r_arg(); - reg->regcom = r_tree(); + reg->regptr = r_arg(shp); + reg->regcom = r_tree(shp); regold = reg; } if(reg) @@ -323,14 +324,14 @@ static struct regnod *r_switch(void) return(regtop); } -static char *r_string(void) +static char *r_string(Stk_t *stkp) { register Sfio_t *in = infile; register unsigned long l = sfgetu(in); register char *ptr; if(l == 0) return(NIL(char*)); - ptr = stakalloc((unsigned)l); + ptr = stkalloc(stkp,(unsigned)l); if(--l > 0) { if(sfread(in,ptr,(size_t)l)!=(size_t)l) |