mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/readline/readline.c: supported libedit. fixed: [ruby-core:4858]
* ext/readline/extconf.rb: added new option --enable-libedit. * test/readline/test_readline.rb: added assertions for Readline::HISTORY. * lib/irb/input-method.rb: do not use Readline::HISTORY.pop. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ddec3de32a
commit
3fd16970f3
5 changed files with 173 additions and 124 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Thu May 19 23:33:09 2005 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/readline/readline.c: supported libedit. fixed: [ruby-core:4858]
|
||||||
|
|
||||||
|
* ext/readline/extconf.rb: added new option --enable-libedit.
|
||||||
|
|
||||||
|
* test/readline/test_readline.rb: added assertions for
|
||||||
|
Readline::HISTORY.
|
||||||
|
|
||||||
|
* lib/irb/input-method.rb: do not use Readline::HISTORY.pop.
|
||||||
|
|
||||||
Wed May 18 23:42:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed May 18 23:42:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* error.c (exc_exception): reverted to call Exception#initialize
|
* error.c (exc_exception): reverted to call Exception#initialize
|
||||||
|
|
|
@ -1,30 +1,60 @@
|
||||||
require "mkmf"
|
require "mkmf"
|
||||||
|
|
||||||
|
$readline_headers = ["stdio.h"]
|
||||||
|
|
||||||
|
def have_readline_header(header)
|
||||||
|
if have_header(header)
|
||||||
|
$readline_headers.push(header)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def have_readline_var(var)
|
||||||
|
return have_var(var, $readline_headers)
|
||||||
|
end
|
||||||
|
|
||||||
dir_config('curses')
|
dir_config('curses')
|
||||||
dir_config('ncurses')
|
dir_config('ncurses')
|
||||||
dir_config('termcap')
|
dir_config('termcap')
|
||||||
dir_config("readline")
|
dir_config("readline")
|
||||||
|
enable_libedit = enable_config("libedit")
|
||||||
have_library("user32", nil) if /cygwin/ === RUBY_PLATFORM
|
have_library("user32", nil) if /cygwin/ === RUBY_PLATFORM
|
||||||
have_library("ncurses", "tgetnum") or
|
have_library("ncurses", "tgetnum") ||
|
||||||
have_library("termcap", "tgetnum") or
|
have_library("termcap", "tgetnum") ||
|
||||||
have_library("curses", "tgetnum")
|
have_library("curses", "tgetnum")
|
||||||
|
|
||||||
if have_header("readline/readline.h") and
|
if enable_libedit
|
||||||
have_header("readline/history.h") and
|
unless (have_readline_header("editline/readline.h") ||
|
||||||
have_library("readline", "readline")
|
have_readline_header("readline/readline.h")) &&
|
||||||
if have_func("rl_filename_completion_function")
|
have_library("edit", "readline")
|
||||||
$CFLAGS += " -DREADLINE_42_OR_LATER"
|
exit
|
||||||
end
|
end
|
||||||
if have_func("rl_cleanup_after_signal")
|
else
|
||||||
$CFLAGS += " -DREADLINE_40_OR_LATER"
|
unless ((have_readline_header("readline/readline.h") &&
|
||||||
|
have_readline_header("readline/history.h")) &&
|
||||||
|
(have_library("readline", "readline") ||
|
||||||
|
have_library("edit", "readline"))) ||
|
||||||
|
(have_readline_header("editline/readline.h") &&
|
||||||
|
have_library("edit", "readline"))
|
||||||
|
exit
|
||||||
end
|
end
|
||||||
if try_link(<<EOF, $libs)
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <readline/readline.h>
|
|
||||||
main() {rl_completion_append_character = 1;}
|
|
||||||
EOF
|
|
||||||
# this feature is implemented in readline-2.1 or later.
|
|
||||||
$CFLAGS += " -DREADLINE_21_OR_LATER"
|
|
||||||
end
|
|
||||||
create_makefile("readline")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
have_readline_var("rl_filename_completion_function")
|
||||||
|
have_readline_var("rl_deprep_term_function")
|
||||||
|
have_readline_var("rl_completion_append_character")
|
||||||
|
have_readline_var("rl_basic_word_break_characters")
|
||||||
|
have_readline_var("rl_completer_word_break_characters")
|
||||||
|
have_readline_var("rl_basic_quote_characters")
|
||||||
|
have_readline_var("rl_completer_quote_characters")
|
||||||
|
have_readline_var("rl_filename_quote_characters")
|
||||||
|
have_readline_var("rl_attempted_completion_over")
|
||||||
|
have_readline_var("rl_library_version")
|
||||||
|
have_readline_var("rl_event_hook")
|
||||||
|
have_func("rl_cleanup_after_signal")
|
||||||
|
have_func("rl_clear_signals")
|
||||||
|
have_func("replace_history_entry")
|
||||||
|
have_func("remove_history")
|
||||||
|
create_makefile("readline")
|
||||||
|
|
|
@ -3,8 +3,16 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#ifdef HAVE_READLINE_READLINE_H
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_READLINE_HISTORY_H
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_EDITLINE_READLINE_H
|
||||||
|
#include <editline/readline.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "rubyio.h"
|
#include "rubyio.h"
|
||||||
|
@ -22,12 +30,16 @@ static VALUE mReadline;
|
||||||
#define COMPLETION_CASE_FOLD "completion_case_fold"
|
#define COMPLETION_CASE_FOLD "completion_case_fold"
|
||||||
static ID completion_proc, completion_case_fold;
|
static ID completion_proc, completion_case_fold;
|
||||||
|
|
||||||
#ifndef READLINE_42_OR_LATER
|
#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION
|
||||||
# define rl_filename_completion_function filename_completion_function
|
# define rl_filename_completion_function filename_completion_function
|
||||||
# define rl_username_completion_function username_completion_function
|
# define rl_username_completion_function username_completion_function
|
||||||
# define rl_completion_matches completion_matches
|
# define rl_completion_matches completion_matches
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int readline_event(void);
|
||||||
|
static char **readline_attempted_completion_function(const char *text,
|
||||||
|
int start, int end);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
readline_event()
|
readline_event()
|
||||||
{
|
{
|
||||||
|
@ -63,10 +75,10 @@ readline_readline(argc, argv, self)
|
||||||
buff = (char*)rb_protect((VALUE(*)_((VALUE)))readline, (VALUE)prompt,
|
buff = (char*)rb_protect((VALUE(*)_((VALUE)))readline, (VALUE)prompt,
|
||||||
&status);
|
&status);
|
||||||
if (status) {
|
if (status) {
|
||||||
#if defined READLINE_40_OR_LATER
|
#if defined HAVE_RL_CLEANUP_AFTER_SIGNAL
|
||||||
/* restore terminal mode and signal handler*/
|
/* restore terminal mode and signal handler*/
|
||||||
rl_cleanup_after_signal();
|
rl_cleanup_after_signal();
|
||||||
#elif defined READLINE_21_OR_LATER
|
#elif defined HAVE_RL_DEPREP_TERM_FUNCTION
|
||||||
/* restore terminal mode */
|
/* restore terminal mode */
|
||||||
(*rl_deprep_term_function)();
|
(*rl_deprep_term_function)();
|
||||||
#else
|
#else
|
||||||
|
@ -124,7 +136,7 @@ readline_s_get_completion_case_fold(self)
|
||||||
|
|
||||||
static char **
|
static char **
|
||||||
readline_attempted_completion_function(text, start, end)
|
readline_attempted_completion_function(text, start, end)
|
||||||
char *text;
|
const char *text;
|
||||||
int start;
|
int start;
|
||||||
int end;
|
int end;
|
||||||
{
|
{
|
||||||
|
@ -136,7 +148,9 @@ readline_attempted_completion_function(text, start, end)
|
||||||
proc = rb_attr_get(mReadline, completion_proc);
|
proc = rb_attr_get(mReadline, completion_proc);
|
||||||
if (NIL_P(proc))
|
if (NIL_P(proc))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#ifdef HAVE_RL_ATTEMPTED_COMPLETION_OVER
|
||||||
rl_attempted_completion_over = 1;
|
rl_attempted_completion_over = 1;
|
||||||
|
#endif
|
||||||
case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold));
|
case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold));
|
||||||
ary = rb_funcall(proc, rb_intern("call"), 1, rb_tainted_str_new2(text));
|
ary = rb_funcall(proc, rb_intern("call"), 1, rb_tainted_str_new2(text));
|
||||||
if (TYPE(ary) != T_ARRAY)
|
if (TYPE(ary) != T_ARRAY)
|
||||||
|
@ -209,7 +223,7 @@ static VALUE
|
||||||
readline_s_set_completion_append_character(self, str)
|
readline_s_set_completion_append_character(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (NIL_P(str)) {
|
if (NIL_P(str)) {
|
||||||
rl_completion_append_character = '\0';
|
rl_completion_append_character = '\0';
|
||||||
|
@ -226,14 +240,14 @@ readline_s_set_completion_append_character(self, str)
|
||||||
return self;
|
return self;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_COMPLETION_APPEND_CHARACTER */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_get_completion_append_character(self)
|
readline_s_get_completion_append_character(self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -246,14 +260,14 @@ readline_s_get_completion_append_character(self)
|
||||||
return str;
|
return str;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_COMPLETION_APPEND_CHARACTER */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_set_basic_word_break_characters(self, str)
|
readline_s_set_basic_word_break_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
|
||||||
static char *basic_word_break_characters = NULL;
|
static char *basic_word_break_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -273,28 +287,28 @@ readline_s_set_basic_word_break_characters(self, str)
|
||||||
return self;
|
return self;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_BASIC_WORD_BREAK_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_get_basic_word_break_characters(self, str)
|
readline_s_get_basic_word_break_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_basic_word_break_characters == NULL)
|
if (rl_basic_word_break_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_basic_word_break_characters);
|
return rb_tainted_str_new2(rl_basic_word_break_characters);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_BASIC_WORD_BREAK_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_set_completer_word_break_characters(self, str)
|
readline_s_set_completer_word_break_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
|
||||||
static char *completer_word_break_characters = NULL;
|
static char *completer_word_break_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -314,28 +328,28 @@ readline_s_set_completer_word_break_characters(self, str)
|
||||||
return self;
|
return self;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_get_completer_word_break_characters(self, str)
|
readline_s_get_completer_word_break_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_completer_word_break_characters == NULL)
|
if (rl_completer_word_break_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_completer_word_break_characters);
|
return rb_tainted_str_new2(rl_completer_word_break_characters);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_set_basic_quote_characters(self, str)
|
readline_s_set_basic_quote_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
|
||||||
static char *basic_quote_characters = NULL;
|
static char *basic_quote_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -355,28 +369,28 @@ readline_s_set_basic_quote_characters(self, str)
|
||||||
return self;
|
return self;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_BASIC_QUOTE_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_get_basic_quote_characters(self, str)
|
readline_s_get_basic_quote_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_basic_quote_characters == NULL)
|
if (rl_basic_quote_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_basic_quote_characters);
|
return rb_tainted_str_new2(rl_basic_quote_characters);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_BASIC_QUOTE_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_set_completer_quote_characters(self, str)
|
readline_s_set_completer_quote_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
|
||||||
static char *completer_quote_characters = NULL;
|
static char *completer_quote_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -396,28 +410,28 @@ readline_s_set_completer_quote_characters(self, str)
|
||||||
return self;
|
return self;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_COMPLETER_QUOTE_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_get_completer_quote_characters(self, str)
|
readline_s_get_completer_quote_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_completer_quote_characters == NULL)
|
if (rl_completer_quote_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_completer_quote_characters);
|
return rb_tainted_str_new2(rl_completer_quote_characters);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_COMPLETER_QUOTE_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_set_filename_quote_characters(self, str)
|
readline_s_set_filename_quote_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
|
||||||
static char *filename_quote_characters = NULL;
|
static char *filename_quote_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
@ -437,39 +451,21 @@ readline_s_set_filename_quote_characters(self, str)
|
||||||
return self;
|
return self;
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_FILENAME_QUOTE_CHARACTERS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_get_filename_quote_characters(self, str)
|
readline_s_get_filename_quote_characters(self, str)
|
||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
#ifdef READLINE_21_OR_LATER
|
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_filename_quote_characters == NULL)
|
if (rl_filename_quote_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_filename_quote_characters);
|
return rb_tainted_str_new2(rl_filename_quote_characters);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif /* READLINE_21_OR_LATER */
|
#endif /* HAVE_RL_FILENAME_QUOTE_CHARACTERS */
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_remove_history(index)
|
|
||||||
int index;
|
|
||||||
{
|
|
||||||
HIST_ENTRY *entry;
|
|
||||||
VALUE val;
|
|
||||||
|
|
||||||
rb_secure(4);
|
|
||||||
entry = remove_history(index);
|
|
||||||
if (entry) {
|
|
||||||
val = rb_tainted_str_new2(entry->line);
|
|
||||||
free(entry->line);
|
|
||||||
free(entry);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return Qnil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -484,19 +480,19 @@ hist_get(self, index)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
VALUE index;
|
VALUE index;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
HIST_ENTRY *entry;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
|
||||||
i = NUM2INT(index);
|
i = NUM2INT(index);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
i += state->length;
|
i += history_length;
|
||||||
}
|
}
|
||||||
if (i < 0 || i > state->length - 1) {
|
entry = history_get(history_base + i);
|
||||||
|
if (entry == NULL) {
|
||||||
rb_raise(rb_eIndexError, "invalid index");
|
rb_raise(rb_eIndexError, "invalid index");
|
||||||
}
|
}
|
||||||
return rb_tainted_str_new2(state->entries[i]->line);
|
return rb_tainted_str_new2(entry->line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -505,21 +501,23 @@ hist_set(self, index, str)
|
||||||
VALUE index;
|
VALUE index;
|
||||||
VALUE str;
|
VALUE str;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
#ifdef HAVE_REPLACE_HISTORY_ENTRY
|
||||||
VALUE s = str;
|
HIST_ENTRY *entry;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
|
||||||
i = NUM2INT(index);
|
i = NUM2INT(index);
|
||||||
|
SafeStringValue(str);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
i += state->length;
|
i += history_length;
|
||||||
}
|
}
|
||||||
if (i < 0 || i > state->length - 1) {
|
entry = replace_history_entry(i, RSTRING(str)->ptr, NULL);
|
||||||
|
if (entry == NULL) {
|
||||||
rb_raise(rb_eIndexError, "invalid index");
|
rb_raise(rb_eIndexError, "invalid index");
|
||||||
}
|
}
|
||||||
SafeStringValue(str);
|
#else
|
||||||
replace_history_entry(i, RSTRING(str)->ptr, NULL);
|
rb_notimplement();
|
||||||
|
#endif
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,16 +549,35 @@ hist_push_method(argc, argv, self)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_remove_history(index)
|
||||||
|
int index;
|
||||||
|
{
|
||||||
|
#ifdef HAVE_REMOVE_HISTORY
|
||||||
|
HIST_ENTRY *entry;
|
||||||
|
VALUE val;
|
||||||
|
|
||||||
|
rb_secure(4);
|
||||||
|
entry = remove_history(index);
|
||||||
|
if (entry) {
|
||||||
|
val = rb_tainted_str_new2(entry->line);
|
||||||
|
free(entry->line);
|
||||||
|
free(entry);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
rb_notimplement();
|
||||||
|
#endif
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
hist_pop(self)
|
hist_pop(self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
if (history_length > 0) {
|
||||||
if (state->length > 0) {
|
return rb_remove_history(history_length - 1);
|
||||||
return rb_remove_history(state->length - 1);
|
|
||||||
} else {
|
} else {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -570,11 +587,8 @@ static VALUE
|
||||||
hist_shift(self)
|
hist_shift(self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
if (history_length > 0) {
|
||||||
if (state->length > 0) {
|
|
||||||
return rb_remove_history(0);
|
return rb_remove_history(0);
|
||||||
} else {
|
} else {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
@ -585,13 +599,15 @@ static VALUE
|
||||||
hist_each(self)
|
hist_each(self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
HIST_ENTRY *entry;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
for (i = 0; i < history_length; i++) {
|
||||||
for (i = 0; i < state->length; i++) {
|
entry = history_get(history_base + i);
|
||||||
rb_yield(rb_tainted_str_new2(state->entries[i]->line));
|
if (entry == NULL)
|
||||||
|
break;
|
||||||
|
rb_yield(rb_tainted_str_new2(entry->line));
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -600,25 +616,16 @@ static VALUE
|
||||||
hist_length(self)
|
hist_length(self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
return INT2NUM(history_length);
|
||||||
return INT2NUM(state->length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
hist_empty_p(self)
|
hist_empty_p(self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
return history_length == 0 ? Qtrue : Qfalse;
|
||||||
if (state->length == 0)
|
|
||||||
return Qtrue;
|
|
||||||
else
|
|
||||||
return Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -626,15 +633,13 @@ hist_delete_at(self, index)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
VALUE index;
|
VALUE index;
|
||||||
{
|
{
|
||||||
HISTORY_STATE *state;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
state = history_get_history_state();
|
|
||||||
i = NUM2INT(index);
|
i = NUM2INT(index);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
i += state->length;
|
i += history_length;
|
||||||
if (i < 0 || i > state->length - 1) {
|
if (i < 0 || i > history_length - 1) {
|
||||||
rb_raise(rb_eIndexError, "invalid index");
|
rb_raise(rb_eIndexError, "invalid index");
|
||||||
}
|
}
|
||||||
return rb_remove_history(i);
|
return rb_remove_history(i);
|
||||||
|
@ -759,7 +764,6 @@ Init_readline()
|
||||||
rb_define_singleton_method(history,"each", hist_each, 0);
|
rb_define_singleton_method(history,"each", hist_each, 0);
|
||||||
rb_define_singleton_method(history,"length", hist_length, 0);
|
rb_define_singleton_method(history,"length", hist_length, 0);
|
||||||
rb_define_singleton_method(history,"size", hist_length, 0);
|
rb_define_singleton_method(history,"size", hist_length, 0);
|
||||||
|
|
||||||
rb_define_singleton_method(history,"empty?", hist_empty_p, 0);
|
rb_define_singleton_method(history,"empty?", hist_empty_p, 0);
|
||||||
rb_define_singleton_method(history,"delete_at", hist_delete_at, 1);
|
rb_define_singleton_method(history,"delete_at", hist_delete_at, 1);
|
||||||
rb_define_const(mReadline, "HISTORY", history);
|
rb_define_const(mReadline, "HISTORY", history);
|
||||||
|
@ -773,21 +777,18 @@ Init_readline()
|
||||||
rb_define_singleton_method(ucomp, "call",
|
rb_define_singleton_method(ucomp, "call",
|
||||||
username_completion_proc_call, 1);
|
username_completion_proc_call, 1);
|
||||||
rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
|
rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
|
||||||
#if defined READLINE_21_OR_LATER
|
#if defined HAVE_RL_LIBRARY_VERSION
|
||||||
rb_define_const(mReadline, "VERSION", rb_str_new2(rl_library_version));
|
rb_define_const(mReadline, "VERSION", rb_str_new2(rl_library_version));
|
||||||
#else
|
#else
|
||||||
rb_define_const(mReadline, "VERSION",
|
rb_define_const(mReadline, "VERSION",
|
||||||
rb_str_new2("2.0 or before version"));
|
rb_str_new2("2.0 or before version"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined READLINE_42_OR_LATER
|
rl_attempted_completion_function = readline_attempted_completion_function;
|
||||||
rl_attempted_completion_function
|
#ifdef HAVE_RL_EVENT_HOOK
|
||||||
= (rl_completion_func_t *)readline_attempted_completion_function;
|
|
||||||
rl_event_hook = (rl_hook_func_t *)readline_event;
|
|
||||||
#else
|
|
||||||
rl_attempted_completion_function
|
|
||||||
= (CPPFunction *) readline_attempted_completion_function;
|
|
||||||
rl_event_hook = readline_event;
|
rl_event_hook = readline_event;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_RL_CLEAR_SIGNALS
|
||||||
rl_clear_signals();
|
rl_clear_signals();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,8 +94,8 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def gets
|
def gets
|
||||||
if l = readline(@prompt, true)
|
if l = readline(@prompt, false)
|
||||||
HISTORY.pop if l.empty?
|
HISTORY.push(l) if !l.empty?
|
||||||
@line[@line_no += 1] = l + "\n"
|
@line[@line_no += 1] = l + "\n"
|
||||||
else
|
else
|
||||||
@eof = true
|
@eof = true
|
||||||
|
|
|
@ -16,11 +16,15 @@ class TestReadline < Test::Unit::TestCase
|
||||||
stdin.write("hello\n")
|
stdin.write("hello\n")
|
||||||
stdin.close
|
stdin.close
|
||||||
stdout.close
|
stdout.close
|
||||||
line = replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
|
line = replace_stdio(stdin.path, stdout.path) {
|
||||||
|
Readline.readline("> ", true)
|
||||||
|
}
|
||||||
assert_equal("hello", line)
|
assert_equal("hello", line)
|
||||||
assert_equal(true, line.tainted?)
|
assert_equal(true, line.tainted?)
|
||||||
stdout.open
|
stdout.open
|
||||||
assert_equal("> ", stdout.read(2))
|
assert_equal("> ", stdout.read(2))
|
||||||
|
assert_equal(1, Readline::HISTORY.length)
|
||||||
|
assert_equal("hello", Readline::HISTORY[0])
|
||||||
assert_raises(SecurityError) do
|
assert_raises(SecurityError) do
|
||||||
Thread.start {
|
Thread.start {
|
||||||
$SAFE = 1
|
$SAFE = 1
|
||||||
|
@ -42,6 +46,7 @@ class TestReadline < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_completion_append_character
|
def test_completion_append_character
|
||||||
|
begin
|
||||||
Readline.completion_append_character = "x"
|
Readline.completion_append_character = "x"
|
||||||
assert_equal("x", Readline.completion_append_character)
|
assert_equal("x", Readline.completion_append_character)
|
||||||
Readline.completion_append_character = "xyz"
|
Readline.completion_append_character = "xyz"
|
||||||
|
@ -50,6 +55,8 @@ class TestReadline < Test::Unit::TestCase
|
||||||
assert_equal(nil, Readline.completion_append_character)
|
assert_equal(nil, Readline.completion_append_character)
|
||||||
Readline.completion_append_character = ""
|
Readline.completion_append_character = ""
|
||||||
assert_equal(nil, Readline.completion_append_character)
|
assert_equal(nil, Readline.completion_append_character)
|
||||||
|
rescue NotImplementedError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue