[#8484] strptime fails to properly parse certain inputs — <noreply@...>

Bugs item #5263, was opened at 2006-08-01 23:14

13 messages 2006/08/02
[#8485] Re: [ ruby-Bugs-5263 ] strptime fails to properly parse certain inputs — Yukihiro Matsumoto <matz@...> 2006/08/02

Hi,

[#8538] Re: [ ruby-Bugs-5263 ] strptime fails to properly parse certain inputs — nobu@... 2006/08/06

Hi,

[#8561] sandbox timers & block scopes — why the lucky stiff <ruby-core@...>

Two puzzles I am trying to solve:

28 messages 2006/08/08
[#8624] Re: sandbox timers & block scopes — why the lucky stiff <ruby-core@...> 2006/08/15

raise ThisDecayingInquisition, "anyone? anyone at all?"

[#8627] Re: sandbox timers & block scopes — MenTaLguY <mental@...> 2006/08/15

On Wed, 2006-08-16 at 00:35 +0900, why the lucky stiff wrote:

[#8628] Re: sandbox timers & block scopes — why the lucky stiff <ruby-core@...> 2006/08/15

On Wed, Aug 16, 2006 at 02:46:30AM +0900, MenTaLguY wrote:

[#8629] Re: sandbox timers & block scopes — "Charles O Nutter" <headius@...> 2006/08/15

On 8/15/06, why the lucky stiff <ruby-core@whytheluckystiff.net> wrote:

[#8690] a ruby-core primer — why the lucky stiff <ruby-core@...>

Hello, all. I've been working on the ruby-core page for the new Ruby site.

21 messages 2006/08/22

[PATCH] readline

From: Ondrej Bilka <neleai@...>
Date: 2006-08-04 12:38:18 UTC
List: ruby-core #8524
Added bindings to some readline functions
                   keyseq   
                           -because readline uses callback which doesnt give information what sequence did you typed 
                             you can have most 4096 seqs and  typing record separator  can lead to unspecified behaviour
                   line_buffer,point  
                             variables rl_line_buffer and rl_point,
                             -to use readline with (n)curses
                   getc_proc
                              binding for  variable rl_getc_proc

Attachments (1)

rline (4.39 KB, text/x-diff)
Index: readline.c
===================================================================
RCS file: /src/ruby/ext/readline/readline.c,v
retrieving revision 1.30
diff -u -r1.30 readline.c
--- readline.c	24 Jul 2006 06:54:58 -0000	1.30
+++ readline.c	4 Aug 2006 12:15:29 -0000
@@ -120,6 +120,79 @@
     rl_outstream = rb_io_stdio_file(ofp);
     return output;
 }
+extern Keymap _rl_keymap;
+static VALUE readline_bindings;
+static int __readline_keyno_part;
+int readline_funa(int a,int b){
+	__readline_keyno_part=b-64;
+	return 0;
+}
+int readline_funb(int a,int b){
+	rb_funcall(*(RARRAY(readline_bindings)->ptr+64*__readline_keyno_part+b-64), 		rb_intern("call"),0);
+	return 0;
+}
+
+/*
+ * call-seq
+ *        Readline.keyseq(keyseq,proc) 
+ *        
+ *        when keyseq is typed proc is executed
+ *
+ */
+static VALUE readline_s_set_keyseq(VALUE self,VALUE seq,VALUE proc){
+	char *ptr=RSTRING(seq)->ptr;
+	char *macro=malloc(5);/*macro that results 2 func calls*/
+    if (!rb_respond_to(proc, rb_intern("call")))
+	rb_raise(rb_eArgError, "argument must respond to `call'");
+	rb_ary_push(readline_bindings,proc);
+	int n=RARRAY(readline_bindings)->len-1;
+	if (n>=4096)	rb_raise(rb_eArgError, "cannot define more than 4096 keybindings");
+
+    //30- record separator hope that nobody uses it 
+	macro[0]=30;	macro[1]=64+(n/64); macro[2]=0;
+	rl_generic_bind(ISFUNC,macro,(char *)readline_funa,_rl_keymap);
+	macro[2]=30;	macro[3]=64+(n%64); macro[4]=0;
+	rl_generic_bind(ISFUNC,macro+2,(char *)readline_funb,_rl_keymap);
+	rl_generic_bind(ISMACR,ptr,macro,_rl_keymap);/*macro is used by rl do not delete it*/
+}
+static VALUE
+readline_s_get_getc(VALUE self)
+{
+    rb_secure(4);
+    return rb_iv_get(mReadline, "@getc_proc");
+}
+int mygetc(FILE *in){
+	int r=NUM2INT(rb_funcall(readline_s_get_getc(mReadline),rb_intern("call"),0));
+	return r;
+}
+
+
+/*
+ *
+ * call-seq getc=proc
+ * 
+ *proc becomes custom getc used by readline 
+ *use when you cant stdin directly(remote connection)
+ *otherwise use input= to redirect input
+ *
+ */
+
+static VALUE
+readline_s_set_getc(VALUE self, VALUE proc)
+{	 
+	rl_getc_function=mygetc;
+	rb_secure(4);
+	if (NIL_P(proc)){
+	    return rb_iv_set(mReadline, "@getc_proc", proc);
+	}
+		
+
+    if (!rb_respond_to(proc, rb_intern("call")))
+	rb_raise(rb_eArgError, "argument must respond to `call'");
+    return rb_iv_set(mReadline, "@getc_proc", proc);
+}
+
+
 
 static VALUE
 readline_s_set_completion_proc(VALUE self, VALUE proc)
@@ -695,7 +768,20 @@
     }
     return result;
 }
-
+/*static VALUE readline_s_set_line_buffer(VALUE self,VALUE num){
+return (rl_line_buffer);
+}*/
+static VALUE readline_s_get_line_buffer(VALUE self){
+return rb_str_new(rl_line_buffer,rl_end);
+}
+static VALUE readline_s_set_point(VALUE self,VALUE num){
+ 	rl_point=NUM2INT(num);
+	return num;
+}
+static VALUE readline_s_get_point(VALUE self){
+return INT2NUM(rl_point);
+}
+	
 void
 Init_readline()
 {
@@ -710,12 +796,24 @@
     completion_case_fold = rb_intern(COMPLETION_CASE_FOLD);
 
     mReadline = rb_define_module("Readline");
+    rb_define_singleton_method(mReadline, "line_buffer",
+			       readline_s_get_line_buffer, 0);
+    rb_define_singleton_method(mReadline, "point=",
+			       readline_s_set_point, 1);
+    rb_define_singleton_method(mReadline, "point",
+			       readline_s_get_point, 0);
     rb_define_module_function(mReadline, "readline",
 			      readline_readline, -1);
     rb_define_singleton_method(mReadline, "input=",
 			       readline_s_set_input, 1);
     rb_define_singleton_method(mReadline, "output=",
 			       readline_s_set_output, 1);
+    rb_define_singleton_method(mReadline, "getc_proc=",
+			       readline_s_set_getc, 1);
+    rb_define_singleton_method(mReadline, "getc_proc",
+			       readline_s_get_getc, 0);
+    rb_define_singleton_method(mReadline, "keyseq",
+			       readline_s_set_keyseq, 2);
     rb_define_singleton_method(mReadline, "completion_proc=",
 			       readline_s_set_completion_proc, 1);
     rb_define_singleton_method(mReadline, "completion_proc",
@@ -767,6 +865,8 @@
     rb_define_singleton_method(history,"size", hist_length, 0);
     rb_define_singleton_method(history,"empty?", hist_empty_p, 0);
     rb_define_singleton_method(history,"delete_at", hist_delete_at, 1);
+ 	readline_bindings=rb_ary_new();
+    rb_iv_set(mReadline,"@bindings",readline_bindings)	;
     rb_define_const(mReadline, "HISTORY", history);
 
     fcomp = rb_obj_alloc(rb_cObject);

In This Thread