1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

The following change makes it possible for applications to have

their own version of scm_readline.
* readline.c, readline.h (rl_cleanup_after_signal,
rl_free_line_state): Made global.
(scm_readline_init_ports): New function.
(scm_readline): Use scm_readline_init_ports.
(Thanks to Anders Holst.)
This commit is contained in:
Mikael Djurfeldt 1999-08-29 18:02:19 +00:00
parent ae9e7aac5f
commit 2e3d59875a
2 changed files with 53 additions and 26 deletions

View file

@ -82,7 +82,7 @@ extern void _rl_clean_up_for_exit ();
extern void _rl_kill_kbd_macro (); extern void _rl_kill_kbd_macro ();
extern int _rl_init_argument (); extern int _rl_init_argument ();
static void void
rl_cleanup_after_signal () rl_cleanup_after_signal ()
{ {
#ifdef HAVE_RL_CLEAR_SIGNALS #ifdef HAVE_RL_CLEAR_SIGNALS
@ -95,7 +95,7 @@ rl_cleanup_after_signal ()
rl_pending_input = 0; rl_pending_input = 0;
} }
static void void
rl_free_line_state () rl_free_line_state ()
{ {
register HIST_ENTRY *entry; register HIST_ENTRY *entry;
@ -218,6 +218,32 @@ stream_from_fport (SCM port, char *mode, const char *subr)
return f; return f;
} }
void
scm_readline_init_ports (SCM inp, SCM outp)
{
if (SCM_UNBNDP (inp))
inp = scm_cur_inp;
if (SCM_UNBNDP (outp))
outp = scm_cur_outp;
if (!(SCM_NIMP (inp) && SCM_OPINFPORTP (inp))) {
scm_misc_error (0,
"Input port is not open or not a file port",
SCM_EOL);
}
if (!(SCM_NIMP (outp) && SCM_OPOUTFPORTP (outp))) {
scm_misc_error (0,
"Output port is not open or not a file port",
SCM_EOL);
}
input_port = inp;
rl_instream = stream_from_fport (inp, "r", s_readline);
rl_outstream = stream_from_fport (outp, "w", s_readline);
}
SCM SCM
scm_readline (SCM text, SCM inp, SCM outp, SCM read_hook) scm_readline (SCM text, SCM inp, SCM outp, SCM read_hook)
{ {
@ -237,11 +263,23 @@ scm_readline (SCM text, SCM inp, SCM outp, SCM read_hook)
SCM_COERCE_SUBSTR (text); SCM_COERCE_SUBSTR (text);
} }
if (SCM_UNBNDP (inp)) if (!((SCM_UNBNDP (inp) && SCM_NIMP (scm_cur_inp) && SCM_OPINFPORTP (inp))
inp = scm_cur_inp; || SCM_NIMP (inp) && SCM_OPINFPORTP (inp)))
{
--in_readline;
scm_misc_error (s_readline,
"Input port is not open or not a file port",
SCM_EOL);
}
if (SCM_UNBNDP (outp)) if (!((SCM_UNBNDP (outp) && SCM_NIMP (scm_cur_outp) && SCM_OPINFPORTP (outp))
outp = scm_cur_outp; || (SCM_NIMP (outp) && SCM_OPOUTFPORTP (outp))))
{
--in_readline;
scm_misc_error (s_readline,
"Output port is not open or not a file port",
SCM_EOL);
}
if (!(SCM_UNBNDP (read_hook) || SCM_FALSEP (read_hook))) if (!(SCM_UNBNDP (read_hook) || SCM_FALSEP (read_hook)))
{ {
@ -253,24 +291,7 @@ scm_readline (SCM text, SCM inp, SCM outp, SCM read_hook)
before_read = read_hook; before_read = read_hook;
} }
if (!(SCM_NIMP (inp) && SCM_OPINFPORTP (inp))) scm_readline_init_ports (inp, outp);
{
--in_readline;
scm_misc_error (s_readline,
"Input port is not open or not a file port",
SCM_EOL);
}
if (!(SCM_NIMP (outp) && SCM_OPOUTFPORTP (outp)))
{
--in_readline;
scm_misc_error (s_readline,
"Output port is not open or not a file port",
SCM_EOL);
}
input_port = inp;
rl_instream = stream_from_fport (inp, "r", s_readline);
rl_outstream = stream_from_fport (outp, "w", s_readline);
ans = scm_internal_catch (SCM_BOOL_T, ans = scm_internal_catch (SCM_BOOL_T,
(scm_catch_body_t) internal_readline, (scm_catch_body_t) internal_readline,
@ -474,7 +495,7 @@ scm_init_readline ()
rl_completion_entry_function = (Function*) completion_function; rl_completion_entry_function = (Function*) completion_function;
rl_basic_word_break_characters = "\t\n\"'`;()"; rl_basic_word_break_characters = "\t\n\"'`;()";
#ifdef USE_THREADS #ifdef USE_THREADS
scm_mutex_init (&reentry_barrier_mutex); scm_mutex_init (&reentry_barrier_mutex, NULL);
#endif #endif
scm_init_opts (scm_readline_options, scm_init_opts (scm_readline_options,
scm_readline_opts, scm_readline_opts,

View file

@ -30,6 +30,7 @@ extern scm_option scm_readline_opts[];
#define SCM_N_READLINE_OPTIONS 3 #define SCM_N_READLINE_OPTIONS 3
extern SCM scm_readline_options (SCM setting); extern SCM scm_readline_options (SCM setting);
extern void scm_readline_init_ports (SCM inp, SCM outp);
extern SCM scm_readline (SCM txt, SCM inp, SCM outp, SCM read_hook); extern SCM scm_readline (SCM txt, SCM inp, SCM outp, SCM read_hook);
extern SCM scm_add_history (SCM txt); extern SCM scm_add_history (SCM txt);
extern SCM scm_read_history (SCM file); extern SCM scm_read_history (SCM file);
@ -37,4 +38,9 @@ extern SCM scm_write_history (SCM file);
extern SCM scm_filename_completion_function (SCM text, SCM continuep); extern SCM scm_filename_completion_function (SCM text, SCM continuep);
extern void scm_init_readline (void); extern void scm_init_readline (void);
#ifndef HAVE_RL_CLEANUP_AFTER_SIGNAL
void rl_cleanup_after_signal ();
void rl_free_line_state ();
#endif
#endif #endif