[#3747] constants (or class vriable?) — Wakou Aoyama <wakou@...>
青山です。
原です。
青山です。
まつもと ゆきひろです
In message <199812080034.JAA05946@picachu.netlab.co.jp>
立石です。
まつもと ゆきひろです
[#3773] pack("M")/unpack("M") — shugo@... (MAEDA Shugo)
前田です。
[#3794] port NetBSD/ alpha 1.3I — SHIROYAMA Takayuki <psi@...>
[#3826] ruby 1.1d0 released — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
渡辺哲也です。
ふなばです。
笠原です。
前田です。
[#3851] tkutil patch (for 1.1d0) — ttate@...
立石です。
[#3859] missing/setenv.c in 1.1d0 — Inaba Hiroto <inaba@...>
稲葉です。こんなにパッチがあると、みのがされてしまうかも。
[#3862] 1.1d0 new here document — Wakou Aoyama <wakou@...>
青山です。
まつもと ゆきひろです
青山です。
まつもと ゆきひろです
[#3873] (?: ) does not work? — shugo@... (MAEDA Shugo)
前田です。
まつもと ゆきひろです
前田です。
まつもと ゆきひろです
前田です。
白山@Stellarです。
[#3881] I want to catch all jump — shugo@... (Shugo Maeda)
前田です。
まつもと ゆきひろです
前田です。
まつもと ゆきひろです
[#3894] ruby 1.1d1 released — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
わたなべです.
[#3899] interpreter reinitialization — shugo@... (Shugo Maeda)
前田です。
まつもと ゆきひろです
前田です。
まつもと ゆきひろです
前田です。
まつもと ゆきひろです
前田です。
まつもと ゆきひろです
[#3962] ruby 1.3(!) released — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
[#3966] [BUG] exception in safe level 4 — shugo@... (Shugo Maeda)
前田です。
[#3997] [BUG] "#{}" while 1 — gotoken@... (GOTO Kentaro)
ごとけんです
まつもと ゆきひろです
[#4002] config.guess — Koji Arai <JCA02266@...>
新井です。
まつもと ゆきひろです
新井です。
まつもと ゆきひろです
新井です。
まつもと ゆきひろです
笠原です。
まつもと ゆきひろです
えぐち@エスアンドイー です。
[#4005] [BUG] ruby 1.3(98/12/24) [i686-linux] at rb_gc_mark() — Ryo HAYASAKA <hayasaka@...>
早坂@会津大学といいます。
In message "[ruby-dev:4005] [BUG] ruby 1.3(98/12/24) [i686-linux] at rb_gc_mark()"
早坂@会津大学です。
[#4015] Integer proper methods — gotoken@... (GOTO Kentaro)
ごとけんです
[#4030] module Precision — gotoken@... (GOTO Kentaro)
ごとけんです
ごとけんです
まつもと ゆきひろです
ごとけんです
けいじゅ@日本ラショナルソフトウェアです.
ごとけんです
まつもと ゆきひろです
まつもと ゆきひろです
ごとけんです
まつもと ゆきひろです
ごとけんです
ごとけんです
けいじゅ@日本ラショナルソフトウェアです.
ごとけんです
まつもと ゆきひろです
まつもと ゆきひろです
まつもと ゆきひろです
ごとけんです
ごとけんです
けいじゅ@日本ラショナルソフトウェアです.
ごとけんです
けいじゅ@日本ラショナルソフトウェアです.
ごとけんです
けいじゅ@日本ラショナルソフトウェアです.
ごとけんです
けいじゅ@日本ラショナルソフトウェアです.
最近あんまり建設的でないわたし.
けいじゅ@日本ラショナルソフトウェアです.
ごとけんです
原です。
[#4032] [Req] make-symbol? — shugo@... (Shugo Maeda)
前田です。
[ruby-dev:3991] [patch] ext/readline/readline.c (Re: readline)
前田です。
In message "[ruby-dev:3973] Re: readline (Re: ruby 1.1d0 released)"
Motoyuki Kasahara <m-kasahr@sra.co.jp> wrote:
> すみませんが、もう一つ二つ質問させて下さい。readline 組み込みの
>
> filename_completion_function()
> username_completion_function()
>
> といった補完関数に相当するものは指定できるのでしょうか。
現状ではできませんが、さっき実装しましたのでパッチをつけます。
Readline.completion_proc = Readline::USERNAME_COMPLETION_PROC
でユーザ名が補完されるようになります。
> あと、Proc オブジェクトに state が引数として渡されないようですが、渡し
> た方が良くありませんか?
Readlineモジュールではrl_completion_entry_functionではなく
rl_attempted_completion_functionを使っています。
ですので、渡すとしたらstateではなくstartとend(rl_line_buffer
内のtextの位置のindex)ですが、ほとんど使わない値を渡すために、
Readline.completion_proc = proc {|x,| ... }
のように|x,|で受けなければならなくなるのが嫌だったのでこのように
しています。
--
前田 修吾 (mailto:shugo@aianet.ne.jp)
Attachments (1)
--- readline.c.orig Fri Dec 25 13:12:25 1998
+++ readline.c Sat Dec 26 01:10:14 1998
@@ -8,15 +8,13 @@
#include "ruby.h"
#include "rubysig.h"
-VALUE mReadline;
-static VALUE histary;
-
-static ID id_completion_proc;
-static ID id_completion_case_fold;
-static ID id_call;
+static VALUE mReadline;
#define TOLOWER(c) (isupper(c) ? tolower(c) : c)
+#define COMPLETION_PROC "completion_proc"
+#define COMPLETION_CASE_FOLD "completion_case_fold"
+
static int
readline_event()
{
@@ -34,8 +32,7 @@
char *buff;
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
- Check_Type(tmp, T_STRING);
- prompt = RSTRING(tmp)->ptr;
+ prompt = STR2CSTR(tmp);
}
buff = readline(prompt);
if (RTEST(add_hist) && buff) {
@@ -52,27 +49,27 @@
static VALUE
readline_s_set_completion_proc(VALUE self, VALUE proc)
{
- if (proc != Qnil && !rb_obj_is_instance_of(proc, rb_cProc))
- rb_raise(rb_eArgError, "argument needs to be proc or nil");
- return rb_ivar_set(mReadline, id_completion_proc, proc);
+ if (!rb_respond_to(proc, rb_intern("call")))
+ rb_raise(rb_eArgError, "argument have to respond to `call'");
+ return rb_iv_set(mReadline, COMPLETION_PROC, proc);
}
static VALUE
readline_s_get_completion_proc(VALUE self)
{
- return rb_ivar_get(mReadline, id_completion_proc);
+ return rb_iv_get(mReadline, COMPLETION_PROC);
}
static VALUE
readline_s_set_completion_case_fold(VALUE self, VALUE val)
{
- return rb_ivar_set(mReadline, id_completion_case_fold, val);
+ return rb_iv_set(mReadline, COMPLETION_CASE_FOLD, val);
}
static VALUE
readline_s_get_completion_case_fold(VALUE self)
{
- return rb_ivar_get(mReadline, id_completion_case_fold);
+ return rb_iv_get(mReadline, COMPLETION_CASE_FOLD);
}
static char **
@@ -83,26 +80,19 @@
int case_fold;
int i, matches;
- proc = rb_ivar_get(mReadline, id_completion_proc);
- if (!rb_obj_is_instance_of(proc, rb_cProc))
- return NULL;
+ proc = rb_iv_get(mReadline, COMPLETION_PROC);
rl_attempted_completion_over = 1;
- case_fold = RTEST(rb_ivar_get(mReadline, id_completion_case_fold));
- ary = rb_funcall(proc, id_call, 1, rb_str_new2(text));
- if (!rb_obj_is_instance_of(ary, rb_cArray))
- return NULL;
+ case_fold = RTEST(rb_iv_get(mReadline, COMPLETION_CASE_FOLD));
+ ary = rb_funcall(proc, rb_intern("call"), 1, rb_str_new2(text));
+ if (TYPE(ary) != T_ARRAY)
+ ary = rb_Array(ary);
matches = RARRAY(ary)->len;
if (matches == 0)
return NULL;
- result = (char **) xmalloc(sizeof(char *) * (matches + 2));
+ result = ALLOC_N(char *, matches + 2);
for (i = 0; i < matches; i++) {
- temp = RARRAY(ary)->ptr[i];
- if (!rb_obj_is_instance_of(temp, rb_cString)) {
- if (result) free(result);
- return NULL;
- }
- result[i + 1]
- = (char *) xmalloc(sizeof(char) * (RSTRING(temp)->len + 1));
+ temp = rb_obj_as_string(RARRAY(ary)->ptr[i]);
+ result[i + 1] = ALLOC_N(char, RSTRING(temp)->len + 1);
strcpy(result[i + 1], RSTRING(temp)->ptr);
}
result[matches + 1] = NULL;
@@ -134,8 +124,8 @@
if (low > si) low = si;
i++;
}
- result[0] = xmalloc (low + 1);
- strncpy (result[0], result[1], low);
+ result[0] = ALLOC_N(char, low + 1);
+ strncpy(result[0], result[1], low);
result[0][low] = '\0';
}
@@ -187,16 +177,14 @@
if (i < 0 || i > state->length - 1) {
rb_raise(rb_eIndexError, "Invalid index");
}
- Check_Type(str, T_STRING);
- replace_history_entry(i, RSTRING(str)->ptr, NULL);
+ replace_history_entry(i, STR2CSTR(str), NULL);
return str;
}
static VALUE
hist_push(VALUE self, VALUE str)
{
- Check_Type(str, T_STRING);
- add_history(RSTRING(str)->ptr);
+ add_history(STR2CSTR(str));
return self;
}
@@ -208,8 +196,7 @@
while (argc--) {
str = *argv++;
- Check_Type(str, T_STRING);
- add_history(RSTRING(str)->ptr);
+ add_history(STR2CSTR(str));
}
return self;
}
@@ -294,14 +281,48 @@
return rb_str_new2(entry->line);
}
+static VALUE
+filename_completion_proc_call(VALUE self, VALUE str)
+{
+ VALUE result = rb_ary_new();
+ char **matches;
+ int i;
+
+ matches = completion_matches(STR2CSTR(str),
+ filename_completion_function);
+ for (i = 0; matches[i]; i++) {
+ rb_ary_push(result, rb_str_new2(matches[i]));
+ free(matches[i]);
+ }
+ free(matches);
+ if (RARRAY(result)->len >= 2)
+ rb_ary_shift(result);
+ return result;
+}
+
+static VALUE
+username_completion_proc_call(VALUE self, VALUE str)
+{
+ VALUE result = rb_ary_new();
+ char **matches;
+ int i;
+
+ matches = completion_matches(STR2CSTR(str),
+ username_completion_function);
+ for (i = 0; matches[i]; i++) {
+ rb_ary_push(result, rb_str_new2(matches[i]));
+ free(matches[i]);
+ }
+ free(matches);
+ if (RARRAY(result)->len >= 2)
+ rb_ary_shift(result);
+ return result;
+}
+
void
Init_readline(void)
{
- extern VALUE rb_mEnumerable;
-
- id_completion_proc = rb_intern("completion_proc");
- id_completion_case_fold = rb_intern("completion_case_fold");
- id_call = rb_intern("call");
+ VALUE histary, fcomp, ucomp;
using_history();
@@ -335,6 +356,16 @@
rb_define_singleton_method(histary,"empty?", hist_empty_p, 0);
rb_define_singleton_method(histary,"delete_at", hist_delete_at, 1);
rb_define_const(mReadline, "HISTORY", histary);
+
+ fcomp = rb_obj_alloc(rb_cObject);
+ rb_define_singleton_method(fcomp, "call",
+ filename_completion_proc_call, 1);
+ rb_define_const(mReadline, "FILENAME_COMPLETION_PROC", fcomp);
+
+ ucomp = rb_obj_alloc(rb_cObject);
+ rb_define_singleton_method(ucomp, "call",
+ username_completion_proc_call, 1);
+ rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
rl_attempted_completion_function
= (CPPFunction *) readline_attempted_completion_function;