/**********************************************************************
 
	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	"xlerror.h"
#include	"xl.h"
#include	"netmapper.h"

extern void gc_gb_sexp();
XL_SEXP * xl_DoMapping();

void
init_DoMapping(XLISP_ENV * env)
{
	set_env(env,l_string(std_cm,"DoMapping"),
		get_func_prim(xl_DoMapping,FO_APPLICATIVE,0,1,1));
}


XL_SEXP *
xl_DoMapping(XLISP_ENV * env,XL_SEXP * s,
	XLISP_ENV * a,XL_SYM_FIELD * sf)
{
int maxloop;
int im;
	maxloop = 5;
	im = 1;
	for ( ; sf ; sf = sf->next ) {
		if ( l_strcmp(sf->name,l_string(std_cm,"maxloop")) == 0 ) {
			maxloop = atoi(n_string(std_cm,sf->data));
		}
		else if ( l_strcmp(sf->name,l_string(std_cm,"immidiate"))
				== 0 ) {
			im = 0;
		}
	}
	if ( im )
		do_mapping(maxloop);
	return output_mapping();
	
invalid_param:
	return get_error(
		s->h.file,
		s->h.line,
		XLE_PROTO_INV_PARAM,
		l_string(std_cm,"DoMapping"),
		0);
}


