mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/readline/readline.c (readline_getc): use rl_getc_function if
possible, to get rid of hang up at EOF without a newline. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c362380d9f
commit
2b08fc1947
3 changed files with 40 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Apr 27 01:25:11 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/readline/readline.c (readline_getc): use rl_getc_function if
|
||||||
|
possible, to get rid of hang up at EOF without a newline.
|
||||||
|
|
||||||
Sun Apr 26 23:19:32 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
Sun Apr 26 23:19:32 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* enc/trans/utf8_mac.trans: Add converter for UTF8-MAC.
|
* enc/trans/utf8_mac.trans: Add converter for UTF8-MAC.
|
||||||
|
|
|
@ -46,6 +46,7 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
have_readline_func("rl_getc_function")
|
||||||
have_readline_func("rl_filename_completion_function")
|
have_readline_func("rl_filename_completion_function")
|
||||||
have_readline_func("rl_username_completion_function")
|
have_readline_func("rl_username_completion_function")
|
||||||
have_readline_func("rl_completion_matches")
|
have_readline_func("rl_completion_matches")
|
||||||
|
|
|
@ -68,8 +68,6 @@ static char **readline_attempted_completion_function(const char *text,
|
||||||
str = rb_str_conv_enc(str, rb_enc_get(str), rb_locale_encoding());\
|
str = rb_str_conv_enc(str, rb_enc_get(str), rb_locale_encoding());\
|
||||||
} while (0)\
|
} while (0)\
|
||||||
|
|
||||||
#ifdef HAVE_RL_EVENT_HOOK
|
|
||||||
#define BUSY_WAIT 0
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Document-class: Readline
|
* Document-class: Readline
|
||||||
|
@ -106,6 +104,26 @@ static char **readline_attempted_completion_function(const char *text,
|
||||||
* Documented by TAKAO Kouji <kouji at takao7 dot net>.
|
* Documented by TAKAO Kouji <kouji at takao7 dot net>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined HAVE_RL_GETC_FUNCTION
|
||||||
|
static VALUE readline_instream;
|
||||||
|
static ID id_getc;
|
||||||
|
|
||||||
|
static int readline_getc(FILE *);
|
||||||
|
static int
|
||||||
|
readline_getc(FILE *input)
|
||||||
|
{
|
||||||
|
rb_io_t *ifp = 0;
|
||||||
|
VALUE c;
|
||||||
|
if (!readline_instream) return rl_getc(input);
|
||||||
|
GetOpenFile(readline_instream, ifp);
|
||||||
|
if (rl_instream != ifp->stdio_file) return rl_getc(input);
|
||||||
|
c = rb_funcall(readline_instream, id_getc, 0, 0);
|
||||||
|
if (NIL_P(c)) return EOF;
|
||||||
|
return NUM2CHR(c);
|
||||||
|
}
|
||||||
|
#elif defined HAVE_RL_EVENT_HOOK
|
||||||
|
#define BUSY_WAIT 0
|
||||||
|
|
||||||
static int readline_event(void);
|
static int readline_event(void);
|
||||||
static int
|
static int
|
||||||
readline_event(void)
|
readline_event(void)
|
||||||
|
@ -123,6 +141,12 @@ readline_event(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
readline_get(VALUE prompt)
|
||||||
|
{
|
||||||
|
return (VALUE)readline((char *)prompt);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* Readline.readline(prompt = "", add_hist = false) -> string or nil
|
* Readline.readline(prompt = "", add_hist = false) -> string or nil
|
||||||
|
@ -225,8 +249,7 @@ readline_readline(int argc, VALUE *argv, VALUE self)
|
||||||
|
|
||||||
if (!isatty(0) && errno == EBADF) rb_raise(rb_eIOError, "closed stdin");
|
if (!isatty(0) && errno == EBADF) rb_raise(rb_eIOError, "closed stdin");
|
||||||
|
|
||||||
buff = (char*)rb_protect((VALUE(*)_((VALUE)))readline, (VALUE)prompt,
|
buff = (char*)rb_protect(readline_get, (VALUE)prompt, &status);
|
||||||
&status);
|
|
||||||
if (status) {
|
if (status) {
|
||||||
#if defined HAVE_RL_CLEANUP_AFTER_SIGNAL
|
#if defined HAVE_RL_CLEANUP_AFTER_SIGNAL
|
||||||
/* restore terminal mode and signal handler*/
|
/* restore terminal mode and signal handler*/
|
||||||
|
@ -272,6 +295,9 @@ readline_s_set_input(VALUE self, VALUE input)
|
||||||
Check_Type(input, T_FILE);
|
Check_Type(input, T_FILE);
|
||||||
GetOpenFile(input, ifp);
|
GetOpenFile(input, ifp);
|
||||||
rl_instream = rb_io_stdio_file(ifp);
|
rl_instream = rb_io_stdio_file(ifp);
|
||||||
|
#ifdef HAVE_RL_GETC_FUNCTION
|
||||||
|
readline_instream = input;
|
||||||
|
#endif
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1344,7 +1370,10 @@ Init_readline()
|
||||||
rb_define_const(mReadline, "VERSION", version);
|
rb_define_const(mReadline, "VERSION", version);
|
||||||
|
|
||||||
rl_attempted_completion_function = readline_attempted_completion_function;
|
rl_attempted_completion_function = readline_attempted_completion_function;
|
||||||
#ifdef HAVE_RL_EVENT_HOOK
|
#if defined HAVE_RL_GETC_FUNCTION
|
||||||
|
rl_getc_function = readline_getc;
|
||||||
|
id_getc = rb_intern_const("getc");
|
||||||
|
#elif defined HAVE_RL_EVENT_HOOK
|
||||||
rl_event_hook = readline_event;
|
rl_event_hook = readline_event;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_RL_CLEAR_SIGNALS
|
#ifdef HAVE_RL_CLEAR_SIGNALS
|
||||||
|
|
Loading…
Reference in a new issue