Esempio n. 1
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);
}
Esempio n. 2
0
VOID
r_do_page()
{

	/* internal declarations */

	bool		no_write = FALSE;	/* true if St_no_write TRUE
						** on entry.  */
	DB_DATA_VALUE	ffdbv;
	DB_TEXT_STRING	*fftext;
	char 		ffbuf[20];


	/* start of routine */



	if (St_p_length <=0)
	{	/* never do page breaks on 0 length page */
		return;
	}

	St_in_pbreak = TRUE;

	if (St_no_write)
	{	/* nothing written yet */
		
		r_set_dflt();
		no_write = TRUE;		/* need to know later */
	}	/* note: r_set_dflt sets St_no_write to FALSE */

	/* temporarily save the current environment */

	r_switch();

	r_ln_clr(Ptr_pln_top);		/* clear out page buffers */
	r_x_tab(St_p_lm,B_ABSOLUTE);

	/* set up error flag switch */

	Cact_tname = NAM_FOOTER;

	if (!no_write)
	{


		r_x_tcmd((Ptr_pag_brk)->brk_footer);

		if ((St_c_cblk>0) || (St_c_lntop->ln_started!=LN_NONE))
		{	/* something left in the line buffers.  Write out */
			St_c_cblk = 0;
			r_x_newline(1);
		}
		/*  Bug #  3902  */
		if (St_ff_on && !St_to_term )
			r_wrt(En_rf_unit, ERx("\f"), 1);
		else if( St_to_term &&  St_ff_on) 
		{
			ffdbv.db_data     = (PTR) ffbuf;
			ffdbv.db_length   = 1;
			ffdbv.db_prec   = 0;
			ffdbv.db_datatype = DB_LTXT_TYPE;
			fftext = (DB_TEXT_STRING *) ffbuf;
			STcopy(ERx("\f"), (PTR)fftext->db_t_text);
			fftext->db_t_count = 1;
			r_x_print( &ffdbv, ffdbv.db_length, FALSE);
		}
	}


	/* determine the next page number */

	if (St_nxt_page >= 0)
	{
		St_p_number = St_nxt_page;
		St_nxt_page = -1;
	}
	else if (!no_write)
	{
		St_p_number++;
	}

	St_l_number = 1;
	St_pos_number = 1;

	/* if the St_do_phead is set to FALSE (at the very end of the
	** report, don't put out a header for the next page */

	if (St_do_phead == TRUE)
	{
		Cact_tname =NAM_HEADER;

		r_x_tcmd((Ptr_pag_brk)->brk_header);
	}

	St_in_pbreak = FALSE;

	if( St_adjusting)
	{
		r_stp_adjust();			/* in case anything is there */
	}

	if ((St_c_cblk>0) || (St_c_lntop->ln_started!=LN_NONE))
	{	/* something left in the line buffers.  Write out */
		St_c_cblk = 0;
		r_x_newline(1);
	}

	/* get back the old environment */

	r_switch();

	r_x_tab(St_left_margin,B_ABSOLUTE);	/* go to report margin */


	return;

}