/****************************************************************************
 * KONOHA COPYRIGHT, LICENSE NOTICE, AND DISCRIMER  
 * 
 * Copyright (c) 2005-2008, Kimio Kuramitsu <kimio at ynu.ac.jp>
 *           (c) 2008-      Konoha Software Foundation  
 * All rights reserved.
 * 
 * You may choose one of the following two licenses when you use konoha. 
 * See www.konohaware.org/license.html for further information.
 * 
 * (1) GNU General Public License 2.0      (with    KONOHA_UNDER_GPL2)
 * (2) Konoha Software Foundation License 1.0
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *  
 ****************************************************************************/

#include<konoha/konoha_t.h>


#ifdef __cplusplus 
extern "C" {
#endif

/* ======================================================================== */

#ifdef __cplusplus
}
#endif

#define KONOHA_UNEXPORTED
#include<konoha/lib/readline.h>

#ifdef __cplusplus 
extern "C" {
#endif


#ifdef  KONOHA_USING_READLINE
#ifdef  KONOHA_PRELINK_READLINE
//static int konohab_readline = 1;
//static int konohab_readline_loaded = 1;
f_lib_readline lib_readline = readline;
f_lib_add_history lib_add_history = add_history;
/* ------------------------------------------------------------------------ */

knh_bool_t konoha_using_readline(void)
{
	return 1;
}

#else /*KONOHA_PRELINK_READLINE*/

void *knh_loader_loaddll(Ctx*, char*, char*, char*);

static int konohab_readline = 0;
static int konohab_readline_loaded = 0;
f_lib_readline lib_readline = NULL;
f_lib_add_history lib_add_history = NULL;
/* ------------------------------------------------------------------------ */

#ifndef F_PREFIX
#define F_PREFIX  ""
#endif

#ifndef F_POSTFIX
#define F_POSTFIX  ""
#endif

knh_bool_t konoha_using_readline(void)
{
	if(konohab_readline_loaded) return konohab_readline;
	konohab_readline_loaded = 1;
	lib_readline = knh_loader_loaddll(NULL, NULL, "readline", F_PREFIX "readline" F_POSTFIX);
	if(lib_readline == NULL) {
		return 0;
	}
	lib_add_history = knh_loader_loaddll(NULL, NULL, "readline", F_PREFIX "add_history" F_POSTFIX);
	if(lib_add_history == NULL) {
		return 0;
	}
	konohab_readline = 1;
	return 1;
}

#endif/*KONOHA_PRELINK_READLINE*/

#else /*KONOHA_USING_READLINE*/

knh_bool_t konoha_using_readline(void)
{
	return 0;
}

#endif/*KONOHA_USING_READLINE*/

#ifdef __cplusplus
}
#endif
