From 00e36aa09f54925c2f9c30524b48f4f54a9adb23 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 8 Dec 1994 14:17:29 +0900 Subject: version 0.60 https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.60.tar.gz Thu Dec 8 14:17:29 1994 Yukihiro Matsumoto (matz@ix-02) * 0.60 released - alpha test baseline. --- io.c | 69 ++++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 979af6aa68..27563c2c6d 100644 --- a/io.c +++ b/io.c @@ -3,7 +3,7 @@ io.c - $Author: matz $ - $Date: 1994/11/22 01:22:36 $ + $Date: 1994/12/06 09:30:03 $ created at: Fri Oct 15 18:08:59 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -37,7 +37,7 @@ extern char *inplace; /* writing functions */ VALUE -Fio_write(obj, str) +io_write(obj, str) VALUE obj; struct RString *str; { @@ -74,7 +74,7 @@ static VALUE Fio_puts(obj, str) VALUE obj, str; { - Fio_write(obj, str); + io_write(obj, str); return obj; } @@ -691,13 +691,23 @@ Fprint(argc, argv) else { for (i=0; i0) { - Fio_write(rb_defout, OFS); + io_write(rb_defout, OFS); + } + switch (TYPE(argv[i])) { + case T_STRING: + io_write(rb_defout, argv[i]); + break; + case T_ARRAY: + Fary_print_on(argv[i], rb_defout); + break; + default: + rb_funcall(argv[i], id_print_on, 1, rb_defout); + break; } - rb_funcall(argv[i], id_print_on, 1, rb_defout); } } if (ORS) { - Fio_write(rb_defout, ORS); + io_write(rb_defout, ORS); } return Qnil; @@ -720,7 +730,7 @@ static VALUE Fprint_on(obj, port) VALUE obj, port; { - return Fio_write(port, obj); + return io_write(port, obj); } static VALUE @@ -738,7 +748,7 @@ prep_stdio(f, mode) return obj; } -static VALUE filename = Qnil, file = Qnil; +static VALUE filename, file; static int gets_lineno; static int init_p = 0, next_p = 0; @@ -764,7 +774,7 @@ next_argv() if (next_p == 1) { next_p = 0; if (RARRAY(Argv)->len > 0) { - filename = Fary_shift(Argv); + filename = ary_shift(Argv); fn = RSTRING(filename)->ptr; if (RSTRING(filename)->len == 1 && fn[0] == '-') { file = rb_stdin; @@ -795,7 +805,6 @@ next_argv() fclose(fr); goto retry; } - obj_free(str); fw = fopen(fn, "w"); fstat(fileno(fw), &st2); fchmod(fileno(fw), st.st_mode); @@ -861,7 +870,7 @@ Freadlines(obj) ary = ary_new(); while (line = Fgets(obj)) { - Fary_push(ary, line); + ary_push(ary, line); } return ary; @@ -895,8 +904,6 @@ rb_xstring(str) rb_syswait(fptr->pid); fptr->pid = 0; - obj_free(port); - return result; } @@ -1026,7 +1033,7 @@ Fselect(obj, args) GetOpenFile(RARRAY(read)->ptr[i], fptr); if (FD_ISSET(fileno(fptr->f), rp) || FD_ISSET(fileno(fptr->f), &pset)) { - Fary_push(list, RARRAY(read)->ptr[i]); + ary_push(list, RARRAY(read)->ptr[i]); } } } @@ -1036,10 +1043,10 @@ Fselect(obj, args) for (i=0; i< RARRAY(write)->len; i++) { GetOpenFile(RARRAY(write)->ptr[i], fptr); if (FD_ISSET(fileno(fptr->f), rp)) { - Fary_push(list, RARRAY(write)->ptr[i]); + ary_push(list, RARRAY(write)->ptr[i]); } else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), rp)) { - Fary_push(list, RARRAY(write)->ptr[i]); + ary_push(list, RARRAY(write)->ptr[i]); } } } @@ -1049,10 +1056,10 @@ Fselect(obj, args) for (i=0; i< RARRAY(except)->len; i++) { GetOpenFile(RARRAY(except)->ptr[i], fptr); if (FD_ISSET(fileno(fptr->f), rp)) { - Fary_push(list, RARRAY(except)->ptr[i]); + ary_push(list, RARRAY(except)->ptr[i]); } else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), rp)) { - Fary_push(list, RARRAY(except)->ptr[i]); + ary_push(list, RARRAY(except)->ptr[i]); } } } @@ -1266,9 +1273,15 @@ Farg_each_byte() } static VALUE -Farg_to_s() +Farg_filename() { - return str_new2("$ARGF"); + return filename; +} + +static VALUE +Farg_file() +{ + return file; } extern VALUE M_Enumerable; @@ -1307,10 +1320,6 @@ Init_IO() rb_define_variable("$/", &RS, Qnil, rb_check_str); rb_define_variable("$\\", &ORS, Qnil, rb_check_str); - rb_define_variable("$<", &filename, Qnil, rb_readonly_hook); - rb_define_variable("$FILENAME", &filename, Qnil, rb_readonly_hook); - rb_global_variable(&file); - rb_define_variable("$.", &lineno, Qnil, Qnil); rb_define_variable("$_", &rb_lastline, Qnil, Qnil); @@ -1329,7 +1338,7 @@ Init_IO() rb_define_alias(C_IO, "readlines", "to_a"); rb_define_method(C_IO, "read", Fio_read, -2); - rb_define_method(C_IO, "write", Fio_write, 1); + rb_define_method(C_IO, "write", io_write, 1); rb_define_method(C_IO, "gets", Fio_gets, 0); rb_define_alias(C_IO, "readline", "gets"); rb_define_method(C_IO, "getc", Fio_getc, 0); @@ -1355,6 +1364,7 @@ Init_IO() rb_define_variable("$>", &rb_defout, Qnil, io_defset); argf = obj_alloc(C_Object); + rb_define_variable("$<", &argf, Qnil, rb_readonly_hook); rb_define_variable("$ARGF", &argf, Qnil, rb_readonly_hook); rb_define_single_method(argf, "each", Farg_each, 0); @@ -1367,8 +1377,15 @@ Init_IO() rb_define_single_method(argf, "getc", Farg_getc, 0); rb_define_single_method(argf, "eof", Feof, 0); - rb_define_single_method(argf, "to_s", Farg_to_s, 0); + rb_define_single_method(argf, "to_s", Farg_filename, 0); + rb_define_single_method(argf, "filename", Farg_filename, 0); + rb_define_single_method(argf, "file", Farg_file, 0); rb_include_module(CLASS_OF(argf), M_Enumerable); + filename = str_new2("-"); + rb_define_variable("$FILENAME", &filename, Qnil, rb_readonly_hook); + file = rb_stdin; + rb_global_variable(&file); + Init_File(); } -- cgit v1.2.3