[macruby-changes] [4911] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 15 19:06:12 PST 2010


Revision: 4911
          http://trac.macosforge.org/projects/ruby/changeset/4911
Author:   watson1978 at gmail.com
Date:     2010-11-15 19:06:10 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.readchar will be passed the multiple file path.

Test Script:
{{{
require 'tempfile'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

t1 = Tempfile.new("foo")
t1.puts "1"
t1.puts "2"
t1.close
t2 = Tempfile.new("bar")
t2.puts "3"
t2.puts "4"
t2.close

def ruby(*args)
  args = ['-e', '$>.write($<.read)'] if args.empty?
  ruby = ARGV[0] || "/usr/local/bin/macruby"
  f = IO.popen([ruby] + args, 'r+')
  yield(f)
ensure
  f.close unless !f || f.closed?
end

ruby('-e', <<-SRC, t1.path, t2.path) do |f|
  s = ""
  begin
    while c = ARGF.readchar
      s << c
    end
  rescue EOFError
    puts s
  end
SRC
  assert_equal("1\n2\n3\n4\n", f.read)
end

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2010-11-16 03:06:07 UTC (rev 4910)
+++ MacRuby/trunk/io.c	2010-11-16 03:06:10 UTC (rev 4911)
@@ -4441,9 +4441,25 @@
 static VALUE
 argf_readchar(VALUE argf, SEL sel)
 {
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_readchar(ARGF.current_file, 0);
+    VALUE ch;
+
+  retry:
+    if (!next_argv()) {
+	rb_eof_error();
+    }
+    if (TYPE(ARGF.current_file) != T_FILE) {
+	ch = rb_funcall3(ARGF.current_file, rb_intern("getc"), 0, 0);
+    }
+    else {
+	ch = rb_io_getc(ARGF.current_file, sel);
+    }
+    if (NIL_P(ch) && ARGF.next_p != -1) {
+	argf_close(ARGF.current_file, sel);
+	ARGF.next_p = 1;
+	goto retry;
+    }
+
+    return ch;
 }
 
 static VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/0eb8fa30/attachment-0001.html>


More information about the macruby-changes mailing list