Example #1
0
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(shp->stk,ionod);
		if(!ioptop)
			ioptop = iop;
		else
			iopold->ionxt = iop;
		iop->iofile = l;
		iop->ioname = r_string(shp->stk);
		if(iop->iodelim = r_string(shp->stk))
		{
			iop->iosize = sfgetl(infile);
			if(shp->heredocs)
				iop->iooffset = sfseek(shp->heredocs,(off_t)0,SEEK_END);
			else
			{
				shp->heredocs = sftmp(512);
				iop->iooffset = 0;
			}
			sfmove(infile,shp->heredocs, iop->iosize, -1);
		}
		iopold = iop;
		if(iop->iofile&IOVNM)
			iop->iovname = r_string(shp->stk);
		else
			iop->iovname = 0;
		iop->iofile &= ~IOVNM;
	}
	if(iop)
		iop->ionxt = 0;
	return(ioptop);
}
Example #2
0
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*)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(shp->stk));
	}
	return(dol);
}
Example #3
0
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(shp->stk,regnod);
		if(!regtop)
			regtop = reg;
		else
			regold->regnxt = reg;
		reg->regflag = l;
		reg->regptr = r_arg(shp);
		reg->regcom = r_tree(shp);
		regold = reg;
	}
	if(reg)
		reg->regnxt = 0;
	return(regtop);
}
Example #4
0
tmain()
{
	int	i, r;
	Sfio_t	*fp;

	if(!(fp = sftmp(8)))
		terror("Can't open temp file");

	for(i = -5448; i <= 5448; i += 101)
		if(sfputl(fp,(long)i) < 0)
			terror("Writing %d",i);

	sfseek(fp,(Sfoff_t)0,0);

	for(i = -5448; i <= 5448; i += 101)
		if((r = (int)sfgetl(fp)) != i)
			terror("Input=%d, Expect=%d",r,i);

	texit(0);
}
Example #5
0
/*
 * read in a shell tree
 */
static Shnode_t *r_tree(Shell_t *shp)
{
	long l = sfgetl(infile); 
	register int type;
	register Shnode_t *t=0;
	if(l<0)
		return(t);
	type = l;
	switch(type&COMMSK)
	{
		case TTIME:
		case TPAR:
			t = getnode(shp->stk,parnod);
			t->par.partre = r_tree(shp);
			break;
		case TCOM:
			t = getnode(shp->stk,comnod);
			t->tre.tretyp = type;
			r_comarg(shp,(struct comnod*)t);
			break;
		case TSETIO:
		case TFORK:
			t = getnode(shp->stk,forknod);
			t->fork.forkline = sfgetu(infile);
			t->fork.forktre = r_tree(shp);
			t->fork.forkio = r_redirect(shp);
			break;
		case TIF:
			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(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(shp->stk,lstnod);
			t->lst.lstlef = r_tree(shp);
			t->lst.lstrit = r_tree(shp);
			break;
		case TARITH:
			t = getnode(shp->stk,arithnod);
			t->ar.arline = sfgetu(infile);
			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(shp->stk,fornod);
			t->for_.forline = 0;
			if(type&FLINENO)
				t->for_.forline = sfgetu(infile);
			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(shp->stk,swnod);
			t->sw.swline = 0;
			if(type&FLINENO)
				t->sw.swline = sfgetu(infile);
			t->sw.swarg = r_arg(shp);
			if(type&COMSCAN)
				t->sw.swio = r_redirect(shp);
			else
				t->sw.swio = 0;
			t->sw.swlst = r_switch(shp);
			break;
		case TFUN:
		{
			Stak_t *savstak;
			struct slnod *slp;
			struct functnod *fp;
			t = getnode(shp->stk,functnod);
			t->funct.functloc = -1;
			t->funct.functline = sfgetu(infile);
			t->funct.functnam = r_string(shp->stk);
			savstak = stakcreate(STAK_SMALL);
			savstak = stakinstall(savstak, 0);
			slp = (struct slnod*)stkalloc(shp->stk,sizeof(struct slnod)+sizeof(struct functnod));
			slp->slchild = 0;
			slp->slnext = shp->st.staklist;
			shp->st.staklist = 0;
			fp = (struct functnod*)(slp+1);
			memset(fp, 0, sizeof(*fp));
			fp->functtyp = TFUN|FAMP;
			if(shp->st.filename)
				fp->functnam = stkcopy(shp->stk,shp->st.filename);
			t->funct.functtre = r_tree(shp); 
			t->funct.functstak = slp;
			slp->slptr =  stakinstall(savstak,0);
			slp->slchild = shp->st.staklist;
			t->funct.functargs = (struct comnod*)r_tree(shp);
			break;
		}
		case TTST:
			t = getnode(shp->stk,tstnod);
			t->tst.tstline = sfgetu(infile);
			if((type&TPAREN)==TPAREN)
				t->lst.lstlef = r_tree(shp); 
			else
			{
				t->lst.lstlef = (Shnode_t*)r_arg(shp);
				if((type&TBINARY))
					t->lst.lstrit = (Shnode_t*)r_arg(shp);
			}
	}
	if(t)
		t->tre.tretyp = type;
	return(t);
}