static char rcsid[] = "$Header:temp.c 12.0$";
#include "defs"

ptr gentemp(t)
ptr t;
{
register ptr oldp;
register ptr p;
register ptr q;
int ttype;
ptr ttypep, tdim;

/* search the temporary list for a matching type */

ttype = ((struct varblock *)t)->vtype;
ttypep = ((struct varblock *)t)->vtypep;
tdim = ((struct varblock *)t)->vdim;

for(oldp = (ptr)&tempvarlist ; p = ((struct dimblock *)oldp)->nextp ; oldp = p)
	if( (q = ((struct chain *)p)->datap) && (((struct varblock *)q)->vtype == ttype) &&
	  (((struct varblock *)q)->vtypep == ttypep) && eqdim(((struct varblock *)q)->vdim,tdim) )
		{
		((struct dimblock *)oldp)->nextp = ((struct dimblock *)p)->nextp;
		break;
		}

if(p == PNULL)
	{
	q = allexpblock();
	((struct headbits *)q)->tag = TTEMP;
	((struct headbits *)q)->subtype = ((struct headbits *)t)->subtype;
	((struct varblock *)q)->vtype = ttype;
	((struct varblock *)q)->vclass = ((struct varblock *)t)->vclass;
	((struct varblock *)q)->vtypep = ( ttypep ? cpexpr(ttypep) : PNULL);
	((struct varblock *)q)->vdim = tdim;
	mkftnp(q);	/* assign fortran types */

	p = (ptr)mkchain(q, CHNULL);
	((struct chain *)p)->datap = q;
	}

((struct dimblock *)p)->nextp = ((struct execblock *)thisexec)->temps;
((struct execblock *)thisexec)->temps = p;

return( cpexpr(q) );
/* need a copy of the block for the temporary list and another for use */
}


ptr gent(t,tp)  /* make a temporary of type t, typepointer tp */
int t;
ptr tp;
{
static struct varblock model;

model.vtype = t;
model.vtypep = tp;

return( gentemp(&model) );
}
