/**********************************************************************
 
	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	"xl.h"


XLISP_ENV *
get_root_env(XLISP_ENV * env)
{
	for ( ; ; ) {
		if ( env == 0 )
			return env;
		switch ( env->type ) {
		case GBET_PAIR:
			env = env->p.env[1];
			continue;
		case GBET_ENV:
			if ( env->e.work )
				return env;
			if ( env->e.parent == 0 )
				return env;
			env = env->e.parent;
			continue;
		default:
			er_panic("get_root_env(1)");
		}
	}
	return env;
}
