/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/



#include	"gbview.h"
#include	"xl.h"

XL_SEXP * 
root_tag_func(XLISP_ENV * env,XL_SEXP * s,
	XLISP_ENV * a_env,XL_SYM_FIELD * sf,
	XLISP_ENV * sp)
{
XLISP_ENV * e;
XL_SEXP * r, * ret, * rret;
RESOURCE * rr;

	e = new_env_pair(sp,env);
	e = new_env(e);
	s = cdr(s);
	rret = 0;
	for ( ; get_type(s) ; s = cdr(s) ) {
		r = car(s);
		if ( get_type(r) == XLT_ERROR ) {
			ret = r;
			goto err;
		}
		ret = eval(e,r);
		if ( get_type(ret) != XLT_ERROR )
			rret = ret;
	}
	return rret;
err:
	rr = get_resource_ptr(&r,e,s->h.file,s->h.line);
	if ( rr == 0 )
		return ret;
	set_init_status_error(rr,ret);
	return ret;
}


void
root_tag(XLISP_ENV * env,L_CHAR * name,XLISP_ENV * sp_env)
{
	set_env(env,name,
		get_func_prim_sp(root_tag_func,
			FO_NORMAL,0,sp_env,1,-1));
}
