
/*
 *
 *  Material Modeling Platform Package
 *  
 *  Copyright(c) 2000, The Japan Research Institute, Ltd.
 *  All rights reserved.
 *
 */

/*
 *		$Author: nishimoto $
 *		$Date: 2004/11/29 12:19:13 $
 */

#include <stdio.h>
#include <string.h>
#include "yut_system.h"
#include "yut_object.h"


void		yut_initobj(Objectdef* obj)
{
	obj->lookup	= 0 ;
	obj->area	= 0 ;
	obj->start	= 0 ;
	obj->end	= 0 ;
	obj->name[0]	= '\0' ;
	obj->olist	= NULL ;
	obj->startlist	= NULL ;
	obj->endlist	= NULL ;
}

void		yut_freeobj(Objectdef* obj)
{
	Objectlist	*sp ;
	Objectlist	*nsp ;
	for(sp = obj->endlist; sp != NULL ; sp = sp->prev){
		if((nsp = sp->next) != NULL){
			if(nsp->name != NULL){
				free((char *)nsp->name) ;
			}
			free((char *)nsp) ;
		}
	}

	sp = obj->startlist ;
	if(sp != NULL){
		if(sp->name != NULL){
			free((char *)sp->name) ;
		}
		free((char *)sp) ;
	}
}

Objectlist	*yut_getnextobj(Objectdef* obj)
{
	Objectlist	*sp;
	for(sp = obj->startlist ; sp != NULL ; sp = sp->next){
		if(sp->depth == obj->lookup){
			obj->lookup++ ;
			break ;
		}
	}

	return sp ;
}

Objectlist	*yut_constobj(Objectdef* obj)		/* install s in symbol table */
{
	Objectlist	*sp;

	sp = (Objectlist *)malloc(sizeof(Objectlist));
	if(sp == NULL){
		return NULL ;
	}

	if(obj->olist == NULL){
		obj->olist = sp ;
		obj->startlist = sp ;
		obj->endlist = sp ;
		obj->olist->depth = 0 ;
		obj->olist->area = obj->area ;
		obj->olist->start = obj->start ;
		obj->olist->end = obj->end ;
		obj->olist->name = strdup(obj->name) ;
		obj->olist->next = NULL ;
		obj->olist->prev = NULL ;
	}
	else{
		obj->olist->next = sp ;
		obj->endlist = sp ;
		obj->olist->next->depth = obj->olist->depth + 1 ;
		obj->olist->next->prev = obj->olist ;
		obj->olist = obj->olist->next ;
		obj->olist->area = obj->area ;
		obj->olist->start = obj->start ;
		obj->olist->end = obj->end ;
		obj->olist->name = strdup(obj->name) ;
		obj->olist->next = NULL ;
	}
	return sp;
}

