* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.

* ext/stringio/stringio.c (strio_getline): should not set $_ here.

* io.c (argf_to_s): argf.to_s returns "ARGF".

* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
  obsolete.

* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
  $stderr not to be instance of IO.

* io.c (rb_f_readline): forward method to current_file. gets,
  readline, readlines, getc, readchar, tell, seek, pos=, rewind,
  fileno, to_io, eof, each_line, each_byte, binmode, and closed?
  as well.

* io.c (argf_forward): utility function to forward method to
  current_file.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-07-28 07:31:52 +00:00
Родитель 4158a73ee4
Коммит dea1baa169
7 изменённых файлов: 193 добавлений и 88 удалений

Просмотреть файл

@ -1,3 +1,25 @@
Mon Jul 28 15:32:04 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
Mon Jul 28 03:08:47 2003 Akinori MUSHA <knu@iDaemons.org> Mon Jul 28 03:08:47 2003 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb: each() should return self. * lib/set.rb: each() should return self.

Просмотреть файл

@ -783,7 +783,7 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;; rb_cv_dlopen=yes ;;
esix*|uxpds*) LDSHARED="ld -G" esix*|uxpds*) LDSHARED="ld -G"
rb_cv_dlopen=yes ;; rb_cv_dlopen=yes ;;
osf*) LDSHARED="$CC -shared" osf*) LDSHARED="ld -shared -expect_unresolved \"*\""
rb_cv_dlopen=yes ;; rb_cv_dlopen=yes ;;
linux*) LDSHARED="$CC -shared" linux*) LDSHARED="$CC -shared"
rb_cv_dlopen=yes ;; rb_cv_dlopen=yes ;;

16
error.c
Просмотреть файл

@ -113,8 +113,8 @@ warn_print(fmt, args)
char buf[BUFSIZ]; char buf[BUFSIZ];
err_snprintf(buf, BUFSIZ, fmt, args); err_snprintf(buf, BUFSIZ, fmt, args);
rb_write_deferr(buf); rb_write_error(buf);
rb_write_deferr("\n"); rb_write_error("\n");
} }
void void
@ -162,8 +162,8 @@ static VALUE
rb_warn_m(self, mesg) rb_warn_m(self, mesg)
VALUE self, mesg; VALUE self, mesg;
{ {
rb_io_write(rb_deferr, mesg); rb_io_write(rb_stderr, mesg);
rb_io_write(rb_deferr, rb_default_rs); rb_io_write(rb_stderr, rb_default_rs);
return mesg; return mesg;
} }
@ -186,8 +186,8 @@ rb_bug(fmt, va_alist)
warn_print(buf, args); warn_print(buf, args);
va_end(args); va_end(args);
snprintf(buf, BUFSIZ, "ruby %s (%s) [%s]\n", RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM); snprintf(buf, BUFSIZ, "ruby %s (%s) [%s]\n", RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM);
rb_write_deferr(buf); rb_write_error(buf);
rb_write_deferr("\n"); rb_write_error("\n");
abort(); abort();
} }
@ -1200,7 +1200,7 @@ err_append(s)
} }
} }
else { else {
rb_write_deferr(s); rb_write_error(s);
rb_write_deferr("\n"); rb_write_error("\n");
} }
} }

8
eval.c
Просмотреть файл

@ -992,11 +992,11 @@ warn_printf(fmt, va_alist)
va_init_list(args, fmt); va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args); vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args); va_end(args);
rb_write_deferr(buf); rb_write_error(buf);
} }
#define warn_print(x) rb_write_deferr(x) #define warn_print(x) rb_write_error(x)
#define warn_print2(x,l) rb_write_deferr2(x,l) #define warn_print2(x,l) rb_write_error2(x,l)
static void static void
error_pos() error_pos()
@ -3846,7 +3846,7 @@ rb_f_abort(argc, argv)
rb_scan_args(argc, argv, "1", &mesg); rb_scan_args(argc, argv, "1", &mesg);
StringValue(argv[0]); StringValue(argv[0]);
rb_io_puts(argc, argv, rb_deferr); rb_io_puts(argc, argv, rb_stderr);
terminate_process(1, RSTRING(argv[0])->ptr, RSTRING(argv[0])->len); terminate_process(1, RSTRING(argv[0])->ptr, RSTRING(argv[0])->len);
} }
return Qnil; /* not reached */ return Qnil; /* not reached */

Просмотреть файл

@ -161,7 +161,7 @@ static VALUE strio_each_byte _((VALUE));
static VALUE strio_getc _((VALUE)); static VALUE strio_getc _((VALUE));
static VALUE strio_ungetc _((VALUE, VALUE)); static VALUE strio_ungetc _((VALUE, VALUE));
static VALUE strio_readchar _((VALUE)); static VALUE strio_readchar _((VALUE));
static VALUE strio_gets_internal _((int, VALUE *, struct StringIO *)); static VALUE strio_getline _((int, VALUE *, struct StringIO *));
static VALUE strio_gets _((int, VALUE *, VALUE)); static VALUE strio_gets _((int, VALUE *, VALUE));
static VALUE strio_readline _((int, VALUE *, VALUE)); static VALUE strio_readline _((int, VALUE *, VALUE));
static VALUE strio_each _((int, VALUE *, VALUE)); static VALUE strio_each _((int, VALUE *, VALUE));
@ -633,7 +633,7 @@ bm_search(little, llen, big, blen, skip)
} }
static VALUE static VALUE
strio_gets_internal(argc, argv, ptr) strio_getline(argc, argv, ptr)
int argc; int argc;
VALUE *argv; VALUE *argv;
struct StringIO *ptr; struct StringIO *ptr;
@ -701,7 +701,6 @@ strio_gets_internal(argc, argv, ptr)
} }
ptr->pos = e - RSTRING(ptr->string)->ptr; ptr->pos = e - RSTRING(ptr->string)->ptr;
ptr->lineno++; ptr->lineno++;
rb_lastline_set(str);
return str; return str;
} }
@ -711,7 +710,10 @@ strio_gets(argc, argv, self)
VALUE *argv; VALUE *argv;
VALUE self; VALUE self;
{ {
return strio_gets_internal(argc, argv, readable(StringIO(self))); VALUE str = strio_getline(argc, argv, readable(StringIO(self)));
rb_lastline_set(str);
return str;
} }
static VALUE static VALUE
@ -720,7 +722,7 @@ strio_readline(argc, argv, self)
VALUE *argv; VALUE *argv;
VALUE self; VALUE self;
{ {
VALUE line = strio_gets_internal(argc, argv, readable(StringIO(self))); VALUE line = strio_getline(argc, argv, readable(StringIO(self)));
if (NIL_P(line)) rb_eof_error(); if (NIL_P(line)) rb_eof_error();
return line; return line;
} }
@ -734,7 +736,7 @@ strio_each(argc, argv, self)
struct StringIO *ptr = StringIO(self); struct StringIO *ptr = StringIO(self);
VALUE line; VALUE line;
while (!NIL_P(line = strio_gets_internal(argc, argv, readable(ptr)))) { while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
rb_yield(line); rb_yield(line);
} }
return self; return self;
@ -748,7 +750,7 @@ strio_readlines(argc, argv, self)
{ {
struct StringIO *ptr = StringIO(self); struct StringIO *ptr = StringIO(self);
VALUE ary = rb_ary_new(), line; VALUE ary = rb_ary_new(), line;
while (!NIL_P(line = strio_gets_internal(argc, argv, readable(ptr)))) { while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
rb_ary_push(ary, line); rb_ary_push(ary, line);
} }
return ary; return ary;

216
io.c
Просмотреть файл

@ -94,8 +94,8 @@ VALUE rb_cIO;
VALUE rb_eEOFError; VALUE rb_eEOFError;
VALUE rb_eIOError; VALUE rb_eIOError;
VALUE rb_stdin, rb_stdout, rb_stderr, rb_defout, rb_deferr; VALUE rb_stdin, rb_stdout, rb_stderr;
static VALUE orig_stdin, orig_stdout, orig_stderr; static VALUE orig_stdout, orig_stderr;
VALUE rb_output_fs; VALUE rb_output_fs;
VALUE rb_rs; VALUE rb_rs;
@ -2574,7 +2574,7 @@ rb_f_printf(argc, argv)
if (argc == 0) return Qnil; if (argc == 0) return Qnil;
if (TYPE(argv[0]) == T_STRING) { if (TYPE(argv[0]) == T_STRING) {
out = rb_defout; out = rb_stdout;
} }
else { else {
out = argv[0]; out = argv[0];
@ -2626,7 +2626,7 @@ rb_f_print(argc, argv)
int argc; int argc;
VALUE *argv; VALUE *argv;
{ {
rb_io_print(argc, argv, rb_defout); rb_io_print(argc, argv, rb_stdout);
return Qnil; return Qnil;
} }
@ -2644,7 +2644,7 @@ static VALUE
rb_f_putc(recv, ch) rb_f_putc(recv, ch)
VALUE recv, ch; VALUE recv, ch;
{ {
return rb_io_putc(rb_defout, ch); return rb_io_putc(rb_stdout, ch);
} }
static VALUE static VALUE
@ -2705,7 +2705,7 @@ rb_f_puts(argc, argv)
int argc; int argc;
VALUE *argv; VALUE *argv;
{ {
rb_io_puts(argc, argv, rb_defout); rb_io_puts(argc, argv, rb_stdout);
return Qnil; return Qnil;
} }
@ -2713,8 +2713,8 @@ void
rb_p(obj) /* for debug print within C code */ rb_p(obj) /* for debug print within C code */
VALUE obj; VALUE obj;
{ {
rb_io_write(rb_defout, rb_obj_as_string(rb_inspect(obj))); rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj)));
rb_io_write(rb_defout, rb_default_rs); rb_io_write(rb_stdout, rb_default_rs);
} }
static VALUE static VALUE
@ -2727,8 +2727,8 @@ rb_f_p(argc, argv)
for (i=0; i<argc; i++) { for (i=0; i<argc; i++) {
rb_p(argv[i]); rb_p(argv[i]);
} }
if (TYPE(rb_defout) == T_FILE) { if (TYPE(rb_stdout) == T_FILE) {
rb_io_flush(rb_defout); rb_io_flush(rb_stdout);
} }
return Qnil; return Qnil;
} }
@ -2742,7 +2742,7 @@ rb_obj_display(argc, argv, self)
VALUE out; VALUE out;
if (rb_scan_args(argc, argv, "01", &out) == 0) { if (rb_scan_args(argc, argv, "01", &out) == 0) {
out = rb_defout; out = rb_stdout;
} }
rb_io_write(out, self); rb_io_write(out, self);
@ -2751,18 +2751,18 @@ rb_obj_display(argc, argv, self)
} }
void void
rb_write_deferr2(mesg, len) rb_write_error2(mesg, len)
const char *mesg; const char *mesg;
long len; long len;
{ {
rb_io_write(rb_deferr, rb_str_new(mesg, len)); rb_io_write(rb_stderr, rb_str_new(mesg, len));
} }
void void
rb_write_deferr(mesg) rb_write_error(mesg)
const char *mesg; const char *mesg;
{ {
rb_write_deferr2(mesg, strlen(mesg)); rb_write_error2(mesg, strlen(mesg));
} }
static void static void
@ -2779,7 +2779,17 @@ must_respond_to(mid, val, id)
} }
static void static void
rb_io_defset(val, id, variable) set_input_var(val, id, variable)
VALUE val;
ID id;
VALUE *variable;
{
must_respond_to(id_read, val, id);
*variable = val;
}
static void
set_output_var(val, id, variable)
VALUE val; VALUE val;
ID id; ID id;
VALUE *variable; VALUE *variable;
@ -2789,26 +2799,23 @@ rb_io_defset(val, id, variable)
} }
static void static void
set_stdio(val, id, var) set_defout_var(val, id, variable)
VALUE val; VALUE val;
ID id; ID id;
VALUE *var; VALUE *variable;
{ {
char *vn = rb_id2name(id); set_output_var(val, id, variable);
char *cn = "IO#"; rb_warn("$defout is obslete; use $stdout instead");
}
if (strlen(vn) > 5) { static void
switch (vn[4]) { set_deferr_var(val, id, variable)
case 'i': VALUE val;
cn = "STDIN."; break; ID id;
case 'o': VALUE *variable;
cn = "STDOUT."; break; {
case 'e': set_output_var(val, id, variable);
cn = "STDERR."; break; rb_warn("$deferr is obslete; use $stderr instead");
}
}
rb_warn("assignment to %s is deprecated; use %sreopen() instead", vn, cn);
rb_name_error(id, "%s is a read-only variable", vn);
} }
static VALUE static VALUE
@ -2934,17 +2941,40 @@ rb_io_s_for_fd(argc, argv, klass)
static int binmode = 0; static int binmode = 0;
static VALUE
argf_forward()
{
return rb_funcall3(current_file, ruby_frame->last_func,
ruby_frame->argc, ruby_frame->argv);
}
#define ARGF_FORWARD() do { if (TYPE(current_file) != T_FILE) return argf_forward(); } while (0)
#define NEXT_ARGF_FORWARD() do {\
if (!next_argv()) return Qnil;\
ARGF_FORWARD();\
} while (0)
static void
argf_close(file)
VALUE file;
{
if (TYPE(file) == T_FILE)
rb_io_close(file);
else
rb_funcall3(file, rb_intern("close"), 0, 0);
}
static int static int
next_argv() next_argv()
{ {
extern VALUE rb_argv; extern VALUE rb_argv;
char *fn; char *fn;
OpenFile *fptr; OpenFile *fptr;
int defout_binmode = 0; int stdout_binmode = 0;
GetOpenFile(rb_defout, fptr); GetOpenFile(rb_stdout, fptr);
if (fptr->mode & FMODE_BINMODE) if (fptr->mode & FMODE_BINMODE)
defout_binmode = 1; stdout_binmode = 1;
if (init_p == 0) { if (init_p == 0) {
if (RARRAY(rb_argv)->len > 0) { if (RARRAY(rb_argv)->len > 0) {
@ -2969,7 +2999,6 @@ next_argv()
current_file = rb_stdin; current_file = rb_stdin;
if (ruby_inplace_mode) { if (ruby_inplace_mode) {
rb_warn("Can't do inplace edit for stdio"); rb_warn("Can't do inplace edit for stdio");
rb_defout = rb_stdout;
} }
} }
else { else {
@ -2980,8 +3009,8 @@ next_argv()
VALUE str; VALUE str;
FILE *fw; FILE *fw;
if (TYPE(rb_defout) == T_FILE && rb_defout != rb_stdout) { if (TYPE(rb_stdout) == T_FILE && rb_stdout != orig_stdout) {
rb_io_close(rb_defout); rb_io_close(rb_stdout);
} }
fstat(fileno(fr), &st); fstat(fileno(fr), &st);
if (*ruby_inplace_mode) { if (*ruby_inplace_mode) {
@ -3029,17 +3058,20 @@ next_argv()
fchown(fileno(fw), st.st_uid, st.st_gid); fchown(fileno(fw), st.st_uid, st.st_gid);
} }
#endif #endif
rb_defout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile); rb_stdout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile);
prep_path(rb_defout, fn); prep_path(rb_stdout, fn);
if (stdout_binmode) rb_io_binmode(rb_stdout);
} }
current_file = prep_stdio(fr, FMODE_READABLE, rb_cFile); current_file = prep_stdio(fr, FMODE_READABLE, rb_cFile);
prep_path(current_file, fn); prep_path(current_file, fn);
} }
if (binmode) rb_io_binmode(current_file); if (binmode) rb_io_binmode(current_file);
if (defout_binmode) rb_io_binmode(rb_defout);
} }
else { else {
init_p = 0; init_p = 0;
if (ruby_inplace_mode) {
rb_stdout = orig_stdout;
}
return Qfalse; return Qfalse;
} }
} }
@ -3073,7 +3105,7 @@ argf_getline(argc, argv)
line = rb_io_getline(rs, fptr); line = rb_io_getline(rs, fptr);
} }
if (NIL_P(line) && next_p != -1) { if (NIL_P(line) && next_p != -1) {
io_close(current_file); argf_close(current_file);
next_p = 1; next_p = 1;
goto retry; goto retry;
} }
@ -3089,8 +3121,15 @@ rb_f_gets(argc, argv)
int argc; int argc;
VALUE *argv; VALUE *argv;
{ {
VALUE line = argf_getline(argc, argv); VALUE line;
if (TYPE(current_file) != T_FILE) {
if (!next_argv()) return Qnil;
line = rb_funcall3(current_file, rb_intern("gets"), argc, argv);
}
else {
line = argf_getline(argc, argv);
}
rb_lastline_set(line); rb_lastline_set(line);
return line; return line;
} }
@ -3108,7 +3147,7 @@ rb_gets()
if (!next_argv()) return Qnil; if (!next_argv()) return Qnil;
line = rb_io_gets(current_file); line = rb_io_gets(current_file);
if (NIL_P(line) && next_p != -1) { if (NIL_P(line) && next_p != -1) {
io_close(current_file); argf_close(current_file);
next_p = 1; next_p = 1;
goto retry; goto retry;
} }
@ -3126,8 +3165,10 @@ rb_f_readline(argc, argv)
int argc; int argc;
VALUE *argv; VALUE *argv;
{ {
VALUE line = rb_f_gets(argc, argv); VALUE line;
NEXT_ARGF_FORWARD();
line = rb_f_gets(argc, argv);
if (NIL_P(line)) { if (NIL_P(line)) {
rb_eof_error(); rb_eof_error();
} }
@ -3149,6 +3190,7 @@ rb_f_readlines(argc, argv)
{ {
VALUE line, ary; VALUE line, ary;
NEXT_ARGF_FORWARD();
ary = rb_ary_new(); ary = rb_ary_new();
while (!NIL_P(line = argf_getline(argc, argv))) { while (!NIL_P(line = argf_getline(argc, argv))) {
rb_ary_push(ary, line); rb_ary_push(ary, line);
@ -3698,6 +3740,7 @@ argf_tell()
if (!next_argv()) { if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to tell"); rb_raise(rb_eArgError, "no stream to tell");
} }
ARGF_FORWARD();
return rb_io_tell(current_file); return rb_io_tell(current_file);
} }
@ -3710,6 +3753,7 @@ argf_seek_m(argc, argv, self)
if (!next_argv()) { if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to seek"); rb_raise(rb_eArgError, "no stream to seek");
} }
ARGF_FORWARD();
return rb_io_seek_m(argc, argv, current_file); return rb_io_seek_m(argc, argv, current_file);
} }
@ -3720,6 +3764,7 @@ argf_set_pos(self, offset)
if (!next_argv()) { if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to set position"); rb_raise(rb_eArgError, "no stream to set position");
} }
ARGF_FORWARD();
return rb_io_set_pos(current_file, offset); return rb_io_set_pos(current_file, offset);
} }
@ -3729,6 +3774,7 @@ argf_rewind()
if (!next_argv()) { if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to rewind"); rb_raise(rb_eArgError, "no stream to rewind");
} }
ARGF_FORWARD();
return rb_io_rewind(current_file); return rb_io_rewind(current_file);
} }
@ -3738,6 +3784,7 @@ argf_fileno()
if (!next_argv()) { if (!next_argv()) {
rb_raise(rb_eArgError, "no stream"); rb_raise(rb_eArgError, "no stream");
} }
ARGF_FORWARD();
return rb_io_fileno(current_file); return rb_io_fileno(current_file);
} }
@ -3745,6 +3792,7 @@ static VALUE
argf_to_io() argf_to_io()
{ {
next_argv(); next_argv();
ARGF_FORWARD();
return current_file; return current_file;
} }
@ -3761,9 +3809,14 @@ argf_read(argc, argv)
retry: retry:
if (!next_argv()) return str; if (!next_argv()) return str;
tmp = io_read(argc, argv, current_file); if (TYPE(current_file) != T_FILE) {
tmp = argf_forward();
}
else {
tmp = io_read(argc, argv, current_file);
}
if (NIL_P(tmp) && next_p != -1) { if (NIL_P(tmp) && next_p != -1) {
io_close(current_file); argf_close(current_file);
next_p = 1; next_p = 1;
if (argc == 0) goto retry; if (argc == 0) goto retry;
} }
@ -3782,9 +3835,14 @@ argf_getc()
retry: retry:
if (!next_argv()) return Qnil; if (!next_argv()) return Qnil;
byte = rb_io_getc(current_file); if (TYPE(current_file) != T_FILE) {
byte = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
}
else {
byte = rb_io_getc(current_file);
}
if (NIL_P(byte) && next_p != -1) { if (NIL_P(byte) && next_p != -1) {
io_close(current_file); argf_close(current_file);
next_p = 1; next_p = 1;
goto retry; goto retry;
} }
@ -3795,8 +3853,10 @@ argf_getc()
static VALUE static VALUE
argf_readchar() argf_readchar()
{ {
VALUE c = argf_getc(); VALUE c;
NEXT_ARGF_FORWARD();
c = argf_getc();
if (NIL_P(c)) { if (NIL_P(c)) {
rb_eof_error(); rb_eof_error();
} }
@ -3808,6 +3868,7 @@ argf_eof()
{ {
if (current_file) { if (current_file) {
if (init_p == 0) return Qtrue; if (init_p == 0) return Qtrue;
ARGF_FORWARD();
if (rb_io_eof(current_file)) { if (rb_io_eof(current_file)) {
next_p = 1; next_p = 1;
return Qtrue; return Qtrue;
@ -3823,7 +3884,15 @@ argf_each_line(argc, argv)
{ {
VALUE str; VALUE str;
while (RTEST(str = argf_getline(argc, argv))) { if (!next_argv()) return Qnil;
if (TYPE(current_file) != T_FILE) {
for (;;) {
if (!next_argv()) return argf;
rb_iterate(rb_each, current_file, rb_yield, 0);
next_p = 1;
}
}
while (!NIL_P(str = argf_getline(argc, argv))) {
rb_yield(str); rb_yield(str);
} }
return argf; return argf;
@ -3859,6 +3928,7 @@ argf_binmode()
{ {
binmode = 1; binmode = 1;
next_argv(); next_argv();
ARGF_FORWARD();
rb_io_binmode(current_file); rb_io_binmode(current_file);
return argf; return argf;
} }
@ -3867,16 +3937,17 @@ static VALUE
argf_skip() argf_skip()
{ {
if (next_p != -1) { if (next_p != -1) {
io_close(current_file); argf_close(current_file);
next_p = 1; next_p = 1;
} }
return argf; return argf;
} }
static VALUE static VALUE
argf_close() argf_close_m()
{ {
io_close(current_file); next_argv();
argf_close(current_file);
if (next_p != -1) { if (next_p != -1) {
next_p = 1; next_p = 1;
} }
@ -3887,9 +3958,17 @@ argf_close()
static VALUE static VALUE
argf_closed() argf_closed()
{ {
next_argv();
ARGF_FORWARD();
return rb_io_closed(current_file); return rb_io_closed(current_file);
} }
static VALUE
argf_to_s()
{
return rb_str_new2("ARGF");
}
static VALUE static VALUE
opt_i_get() opt_i_get()
{ {
@ -4048,19 +4127,21 @@ Init_IO()
rb_define_method(rb_cIO, "pid", rb_io_pid, 0); rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0); rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
rb_stdin = orig_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO); rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
rb_define_hooked_variable("$stdin", &rb_stdin, 0, set_stdio); rb_define_hooked_variable("$stdin", &rb_stdin, 0, set_input_var);
rb_stdout = orig_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO); rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO);
rb_define_hooked_variable("$stdout", &rb_stdout, 0, set_stdio); rb_define_hooked_variable("$stdout", &rb_stdout, 0, set_output_var);
rb_stderr = orig_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO); rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO);
rb_define_hooked_variable("$stderr", &rb_stderr, 0, set_stdio); rb_define_hooked_variable("$stderr", &rb_stderr, 0, set_output_var);
rb_define_hooked_variable("$>", &rb_stdout, 0, set_output_var);
orig_stdout = rb_stdout;
orig_stderr = rb_stderr;
rb_defout = rb_stdout; /* variables to be removed in 1.8.1 */
rb_define_hooked_variable("$>", &rb_defout, 0, rb_io_defset); rb_define_hooked_variable("$defout", &rb_stdout, 0, set_defout_var);
rb_define_hooked_variable("$defout", &rb_defout, 0, rb_io_defset); rb_define_hooked_variable("$deferr", &rb_stderr, 0, set_deferr_var);
rb_deferr = rb_stderr;
rb_define_hooked_variable("$deferr", &rb_deferr, 0, rb_io_defset);
/* constants to hold original stdin/stdout/stderr */
rb_define_global_const("STDIN", rb_stdin); rb_define_global_const("STDIN", rb_stdin);
rb_define_global_const("STDOUT", rb_stdout); rb_define_global_const("STDOUT", rb_stdout);
rb_define_global_const("STDERR", rb_stderr); rb_define_global_const("STDERR", rb_stderr);
@ -4071,6 +4152,8 @@ Init_IO()
rb_define_readonly_variable("$<", &argf); rb_define_readonly_variable("$<", &argf);
rb_define_global_const("ARGF", argf); rb_define_global_const("ARGF", argf);
rb_define_singleton_method(argf, "to_s", argf_to_s, 0);
rb_define_singleton_method(argf, "fileno", argf_fileno, 0); rb_define_singleton_method(argf, "fileno", argf_fileno, 0);
rb_define_singleton_method(argf, "to_i", argf_fileno, 0); rb_define_singleton_method(argf, "to_i", argf_fileno, 0);
rb_define_singleton_method(argf, "to_io", argf_to_io, 0); rb_define_singleton_method(argf, "to_io", argf_to_io, 0);
@ -4094,12 +4177,11 @@ Init_IO()
rb_define_singleton_method(argf, "eof?", argf_eof, 0); rb_define_singleton_method(argf, "eof?", argf_eof, 0);
rb_define_singleton_method(argf, "binmode", argf_binmode, 0); rb_define_singleton_method(argf, "binmode", argf_binmode, 0);
rb_define_singleton_method(argf, "to_s", argf_filename, 0);
rb_define_singleton_method(argf, "filename", argf_filename, 0); rb_define_singleton_method(argf, "filename", argf_filename, 0);
rb_define_singleton_method(argf, "path", argf_filename, 0); rb_define_singleton_method(argf, "path", argf_filename, 0);
rb_define_singleton_method(argf, "file", argf_file, 0); rb_define_singleton_method(argf, "file", argf_file, 0);
rb_define_singleton_method(argf, "skip", argf_skip, 0); rb_define_singleton_method(argf, "skip", argf_skip, 0);
rb_define_singleton_method(argf, "close", argf_close, 0); rb_define_singleton_method(argf, "close", argf_close_m, 0);
rb_define_singleton_method(argf, "closed?", argf_closed, 0); rb_define_singleton_method(argf, "closed?", argf_closed, 0);
rb_define_singleton_method(argf, "lineno", argf_lineno, 0); rb_define_singleton_method(argf, "lineno", argf_lineno, 0);

1
ruby.h
Просмотреть файл

@ -613,7 +613,6 @@ RUBY_EXTERN VALUE rb_eNameError;
RUBY_EXTERN VALUE rb_eSyntaxError; RUBY_EXTERN VALUE rb_eSyntaxError;
RUBY_EXTERN VALUE rb_eLoadError; RUBY_EXTERN VALUE rb_eLoadError;
RUBY_EXTERN VALUE rb_defout, rb_deferr;
RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr; RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
RUBY_EXTERN VALUE ruby_errinfo; RUBY_EXTERN VALUE ruby_errinfo;