/* readline.c --- line editing support for Guile */
-/* Copyright (C) 1997,1999,2000,2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1999,2000,2001, 2002, 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
*
*/
\f
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
+/* Include private, configure generated header (i.e. config.h). */
+#include "guile-readline-config.h"
-#include "libguile/_scm.h"
#ifdef HAVE_RL_GETC_FUNCTION
#include "libguile.h"
#include "libguile/gh.h"
{ SCM_OPTION_INTEGER, "history-length", 200,
"History length." },
{ SCM_OPTION_INTEGER, "bounce-parens", 500,
- "Time (ms) to show matching opening parenthesis (0 = off)."}
+ "Time (ms) to show matching opening parenthesis (0 = off)."},
+ { 0 }
};
extern void stifle_history (int max);
{
SCM ans = scm_options (setting,
scm_readline_opts,
- SCM_N_READLINE_OPTIONS,
FUNC_NAME);
stifle_history (SCM_HISTORY_LENGTH);
return ans;
static int
current_input_getc (FILE *in SCM_UNUSED)
{
- if (promptp && !SCM_FALSEP (before_read))
+ if (promptp && scm_is_true (before_read))
{
scm_apply (before_read, SCM_EOL, SCM_EOL);
promptp = 0;
return scm_getc (input_port);
}
-static void
-redisplay ()
-{
- rl_redisplay ();
- /* promptp = 1; */
-}
-
static int in_readline = 0;
static SCM reentry_barrier_mutex;
if (!SCM_UNBNDP (text))
{
- if (!SCM_STRINGP (text))
+ if (!scm_is_string (text))
{
--in_readline;
scm_wrong_type_arg (s_scm_readline, SCM_ARG1, text);
}
}
- if (!((SCM_UNBNDP (inp) && SCM_OPINFPORTP (scm_cur_inp))
+ if (!((SCM_UNBNDP (inp) && SCM_OPINFPORTP (scm_current_input_port ()))
|| SCM_OPINFPORTP (inp)))
{
--in_readline;
SCM_EOL);
}
- if (!((SCM_UNBNDP (outp) && SCM_OPOUTFPORTP (scm_cur_outp))
+ if (!((SCM_UNBNDP (outp) && SCM_OPOUTFPORTP (scm_current_output_port ()))
|| SCM_OPOUTFPORTP (outp)))
{
--in_readline;
SCM_EOL);
}
- if (!(SCM_UNBNDP (read_hook) || SCM_FALSEP (read_hook)))
+ if (!(SCM_UNBNDP (read_hook) || scm_is_false (read_hook)))
{
- if (!(SCM_NFALSEP (scm_thunk_p (read_hook))))
+ if (scm_is_false (scm_thunk_p (read_hook)))
{
--in_readline;
scm_wrong_type_arg (s_scm_readline, SCM_ARG4, read_hook);
{
SCM ret;
char *s;
- char *prompt = SCM_UNBNDP (text) ? "" : SCM_STRING_CHARS (text);
+ char *prompt = SCM_UNBNDP (text) ? "" : scm_to_locale_string (text);
promptp = 1;
s = readline (prompt);
if (s)
- ret = scm_makfrom0str (s);
+ ret = scm_from_locale_string (s);
else
ret = SCM_EOF_VAL;
+ if (!SCM_UNBNDP (text))
+ free (prompt);
free (s);
return ret;
scm_readline_init_ports (SCM inp, SCM outp)
{
if (SCM_UNBNDP (inp))
- inp = scm_cur_inp;
+ inp = scm_current_input_port ();
if (SCM_UNBNDP (outp))
- outp = scm_cur_outp;
+ outp = scm_current_output_port ();
if (!SCM_OPINFPORTP (inp)) {
scm_misc_error (0,
#define FUNC_NAME s_scm_add_history
{
char* s;
- SCM_VALIDATE_STRING (1,text);
- s = SCM_STRING_CHARS (text);
- add_history (strdup (s));
+ s = scm_to_locale_string (text);
+ add_history (s);
+ free (s);
return SCM_UNSPECIFIED;
}
"")
#define FUNC_NAME s_scm_read_history
{
- SCM_VALIDATE_STRING (1,file);
- return SCM_NEGATE_BOOL (read_history (SCM_STRING_CHARS (file)));
+ char *filename;
+ SCM ret;
+
+ filename = scm_to_locale_string (file);
+ ret = scm_from_bool (!read_history (filename));
+ free (filename);
+ return ret;
}
#undef FUNC_NAME
"")
#define FUNC_NAME s_scm_write_history
{
- SCM_VALIDATE_STRING (1,file);
- return SCM_NEGATE_BOOL (write_history (SCM_STRING_CHARS (file)));
+ char *filename;
+ SCM ret;
+
+ filename = scm_to_locale_string (file);
+ ret = scm_from_bool (!write_history (filename));
+ free (filename);
+ return ret;
}
#undef FUNC_NAME
{
char *s;
SCM ans;
- SCM_VALIDATE_STRING (1,text);
+ char *c_text = scm_to_locale_string (text);
#ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION
- s = rl_filename_completion_function (SCM_STRING_CHARS (text), SCM_NFALSEP (continuep));
+ s = rl_filename_completion_function (c_text, scm_is_true (continuep));
#else
- s = filename_completion_function (SCM_STRING_CHARS (text), SCM_NFALSEP (continuep));
+ s = filename_completion_function (c_text, scm_is_true (continuep));
#endif
- ans = scm_makfrom0str (s);
- free (s);
+ ans = scm_take_locale_string (s);
+ free (c_text);
return ans;
}
#undef FUNC_NAME
SCM compfunc = SCM_VARIABLE_REF (scm_readline_completion_function_var);
SCM res;
- if (SCM_FALSEP (compfunc))
+ if (scm_is_false (compfunc))
return NULL; /* #f => completion disabled */
else
{
- SCM t = scm_makfrom0str (text);
- SCM c = continuep ? SCM_BOOL_T : SCM_BOOL_F;
+ SCM t = scm_from_locale_string (text);
+ SCM c = scm_from_bool (continuep);
res = scm_apply (compfunc, scm_list_2 (t, c), SCM_EOL);
- if (SCM_FALSEP (res))
+ if (scm_is_false (res))
return NULL;
- if (!SCM_STRINGP (res))
- scm_misc_error (s_scm_readline,
- "Completion function returned bogus value: %S",
- scm_list_1 (res));
- return strdup (SCM_STRING_CHARS (res));
+ return scm_to_locale_string (res);
}
}
+#if HAVE_RL_GET_KEYMAP
/*Bouncing parenthesis (reimplemented by GH, 11/23/98, since readline is strict gpl)*/
static int match_paren (int x, int k);
{
rl_redisplay ();
#ifndef __MINGW32__
- scm_internal_select (fno + 1, &readset, NULL, NULL, &timeout);
+ scm_std_select (fno + 1, &readset, NULL, NULL, &timeout);
#else
WaitForSingleObject (GetStdHandle(STD_INPUT_HANDLE),
SCM_READLINE_BOUNCE_PARENS);
}
return 0;
}
+#endif /* HAVE_RL_GET_KEYMAP */
#if defined (HAVE_RL_PRE_INPUT_HOOK) && defined (GUILE_SIGWINCH_SA_RESTART_CLEARED)
/* Readline disables SA_RESTART on SIGWINCH.
#ifndef __MINGW32__
rl_getc_function = current_input_getc;
#endif
- rl_redisplay_function = redisplay;
#if defined (_RL_FUNCTION_TYPEDEF)
rl_completion_entry_function = (rl_compentry_func_t*) completion_function;
#else
reentry_barrier_mutex = scm_permanent_object (scm_make_mutex ());
scm_init_opts (scm_readline_options,
- scm_readline_opts,
- SCM_N_READLINE_OPTIONS);
+ scm_readline_opts);
+#if HAVE_RL_GET_KEYMAP
init_bouncing_parens();
+#endif
scm_add_feature ("readline");
#endif /* HAVE_RL_GETC_FUNCTION */
}