新井です。

前から気になってた、Readline モジュールで入力待ちのときに 
Ctrl-C すると末状態を復帰しない問題の対処です(なんとなくやる
気になった)。

rl_cleanup_after_signal() を呼ぶと、signal handler の復元ま
でやってるのですが、これでいいのか、ちゃんと検証しきれてませ
ん。(この辺がやる気になりきれてない - -;)

あと、completion_append_character が追加されてますが、以下に
示すように GNU readline 2.0 にはない機能なので extconf.rb で
判定するようにしてみました。

$ ruby extconf.rb --with-readline-include=$HOME/src/readline-2.0 --with-readline-lib=$HOME/src/readline-2.0
checking for tgetnum() in -lncurses... yes
checking for readline/readline.h... yes
checking for readline/history.h... yes
checking for readline() in -lreadline... yes
checking for rl_filename_completion_function()... no
creating Makefile

$ make
gcc -fPIC -g  -I/usr/local/lib/ruby/1.7/i586-linux -I/usr/local/include -DHAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H   -I/home/arai/src/readline-2.0 -c readline.c
gcc -shared  -L/home/arai/src/readline-2.0 -L/usr/local/lib/ruby/1.7/i586-linux -L/usr/local/lib  -o readline.so readline.o  -lreadline -lncurses -lc 

$ ldd readline.so 
        libncurses.so.5 => /lib/libncurses.so.5 (0x4002f000)
        libc.so.6 => /lib/libc.so.6 (0x4006f000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

$ ruby -r./readline.so -e ''
0: ./readline.so: undefined symbol: rl_completion_append_character - ./readline.so (LoadError)
[exit: 1]


Mon Aug 20 05:27:43 2001 Koji Arai <JCA02266 / nifty.ne.jp> * ext/readline/readline.c: restore terminal mode even if readline() interrupted. * ext/readline/extconf.rb: check whether the libreadline has the variable `rl_completion_append_character' (this feature was implemented from GNU readline 2.1). Index: readline/extconf.rb =================================================================== RCS file: /usr/local/cvsup/ruby/ruby/ext/readline/extconf.rb,v retrieving revision 1.6 diff -u -p -u -r1.6 extconf.rb --- readline/extconf.rb 2001/05/06 15:03:25 1.6 +++ readline/extconf.rb 2001/08/19 17:50:27 @@ -12,5 +12,13 @@ if have_header("readline/readline.h") an if have_func("rl_filename_completion_function") $CFLAGS += "-DREADLINE_42_OR_LATER" 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 += " -DHAVE_RL_COMPLETION_APPEND_CHARACTER=1" + end create_makefile("readline") end Index: readline/readline.c =================================================================== RCS file: /usr/local/cvsup/ruby/ruby/ext/readline/readline.c,v retrieving revision 1.6 diff -u -p -u -r1.6 readline.c --- readline/readline.c 2001/06/23 09:30:42 1.6 +++ readline/readline.c 2001/08/19 20:21:33 @@ -38,11 +38,17 @@ readline_readline(argc, argv, self) VALUE tmp, add_hist, result; char *prompt = NULL; char *buff; + int status; if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) { prompt = StringValuePtr(tmp); } - buff = readline(prompt); + buff = rb_protect(readline, prompt, &status); + if (status) { + rl_cleanup_after_signal(); /* restore terminal mode */ + /* (*rl_deprep_term_function)(); */ + rb_jump_tag(status); + } if (RTEST(add_hist) && buff) { add_history(buff); } @@ -167,6 +173,7 @@ readline_s_emacs_editing_mode(self) return Qnil; } +#if HAVE_RL_COMPLETION_APPEND_CHARACTER static VALUE readline_s_set_completion_append_character(self, str) VALUE self, str; @@ -196,6 +203,7 @@ readline_s_get_completion_append_charact return str; } +#endif /* HAVE_RL_COMPLETION_APPEND_CHARACTER */ static VALUE hist_to_s(self) @@ -426,10 +434,12 @@ Init_readline() readline_s_vi_editing_mode, 0); rb_define_singleton_method(mReadline, "emacs_editing_mode", readline_s_emacs_editing_mode, 0); +#if HAVE_RL_COMPLETION_APPEND_CHARACTER rb_define_singleton_method(mReadline, "completion_append_character=", readline_s_set_completion_append_character, 1); rb_define_singleton_method(mReadline, "completion_append_character", readline_s_get_completion_append_character, 0); +#endif /* HAVE_RL_COMPLETION_APPEND_CHARACTER */ histary = rb_obj_alloc(rb_cObject); rb_extend_object(histary, rb_mEnumerable); -- 新井康司 (Koji Arai)