summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-09-08 07:09:52 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-09-08 07:09:52 +0000
commit5d71c8d89c6bd7af934e7a8de5882cda2991711b (patch)
tree8788e2b9a2db8bf605c8a38752192cc7eee66fc4 /io.c
parent1c193e5ffecdd8b7949206f9bbd24514974441f7 (diff)
1.1d series
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1dev@298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c921
1 files changed, 461 insertions, 460 deletions
diff --git a/io.c b/io.c
index c86409d0ea..7794c6785d 100644
--- a/io.c
+++ b/io.c
@@ -61,23 +61,25 @@ struct timeval {
#include <net/socket.h>
#endif
-VALUE cIO;
-VALUE eEOFError;
-VALUE eIOError;
+VALUE rb_cIO;
+VALUE rb_eEOFError;
+VALUE rb_eIOError;
VALUE rb_stdin, rb_stdout, rb_stderr, rb_defout;
-VALUE FS, OFS;
-VALUE RS, ORS;
-VALUE RS_default;
+VALUE rb_fs;
+VALUE rb_output_fs;
+VALUE rb_rs;
+VALUE rb_output_rs;
+VALUE rb_default_rs;
static VALUE argf;
-ID id_write;
+static ID id_write;
-extern char *inplace;
+extern char *ruby_inplace_mode;
-struct timeval time_timeval _((VALUE));
+struct timeval rb_time_timeval _((VALUE));
static VALUE filename, file;
static int gets_lineno;
@@ -90,65 +92,61 @@ static VALUE lineno;
# else
# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
# endif
+#elif defined(FILE_COUNT)
+# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
+#elif defined(__BEOS__)
+# define ReadDataPending(fp) (fp->_state._eof == 0)
+#elif defined(USE_CWGUSI)
+# define ReadDataPending(fp) (fp->state.eof == 0)
#else
-# ifdef FILE_COUNT
-# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
-# else
-# if defined(__BEOS__)
-# define ReadDataPending(fp) (fp->_state._eof == 0)
-# elif defined(USE_CWGUSI)
-# define ReadDataPending(fp) (fp->state.eof == 0)
-# else
/* requires systems own version of the ReadDataPending() */
extern int ReadDataPending();
-# endif
-# define READ_DATA_PENDING(fp) ReadDataPending(fp)
-# endif
+# define READ_DATA_PENDING(fp) ReadDataPending(fp)
#endif
#ifndef THREAD
# define READ_CHECK(fp) 0
#else
# define READ_CHECK(fp) do {\
- if (!READ_DATA_PENDING(fp)) thread_wait_fd(fileno(fp));\
+ if (!READ_DATA_PENDING(fp)) rb_thread_wait_fd(fileno(fp));\
} while(0)
#endif
void
-eof_error()
+rb_eof_error()
{
- Raise(eEOFError, "End of file reached");
+ rb_raise(rb_eEOFError, "End of file reached");
}
void
-io_check_closed(fptr)
+rb_io_check_closed(fptr)
OpenFile *fptr;
{
if (fptr->f == NULL && fptr->f2 == NULL)
- Raise(eIOError, "closed stream");
+ rb_raise(rb_eIOError, "closed stream");
}
void
-io_readable(fptr)
+rb_io_check_readable(fptr)
OpenFile *fptr;
{
if (!(fptr->mode & FMODE_READABLE)) {
- Raise(eIOError, "not opened for reading");
+ rb_raise(rb_eIOError, "not opened for reading");
}
}
void
-io_writable(fptr)
+rb_io_check_writable(fptr)
OpenFile *fptr;
{
if (!(fptr->mode & FMODE_WRITABLE)) {
- Raise(eIOError, "not opened for writing");
+ rb_raise(rb_eIOError, "not opened for writing");
}
}
/* writing functions */
VALUE
-io_write(io, str)
+rb_io_write(io, str)
VALUE io, str;
{
OpenFile *fptr;
@@ -156,7 +154,7 @@ io_write(io, str)
int n;
if (TYPE(str) != T_STRING)
- str = obj_as_string(str);
+ str = rb_obj_as_string(str);
if (RSTRING(str)->len == 0) return INT2FIX(0);
if (BUILTIN_TYPE(io) != T_FILE) {
@@ -166,7 +164,7 @@ io_write(io, str)
rb_secure(4);
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
@@ -195,22 +193,22 @@ io_write(io, str)
}
static VALUE
-io_addstr(io, str)
+rb_io_addstr(io, str)
VALUE io, str;
{
- io_write(io, str);
+ rb_io_write(io, str);
return io;
}
static VALUE
-io_flush(io)
+rb_io_flush(io)
VALUE io;
{
OpenFile *fptr;
FILE *f;
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
if (fflush(f) == EOF) rb_sys_fail(0);
@@ -219,7 +217,7 @@ io_flush(io)
}
static VALUE
-io_tell(io)
+rb_io_tell(io)
VALUE io;
{
OpenFile *fptr;
@@ -229,11 +227,11 @@ io_tell(io)
pos = ftell(fptr->f);
if (ferror(fptr->f) != 0) rb_sys_fail(fptr->path);
- return int2inum(pos);
+ return rb_int2inum(pos);
}
static VALUE
-io_seek(io, offset, ptrname)
+rb_io_seek(io, offset, ptrname)
VALUE io, offset, ptrname;
{
OpenFile *fptr;
@@ -248,7 +246,7 @@ io_seek(io, offset, ptrname)
}
static VALUE
-io_set_pos(io, offset)
+rb_io_set_pos(io, offset)
VALUE io, offset;
{
OpenFile *fptr;
@@ -263,7 +261,7 @@ io_set_pos(io, offset)
}
static VALUE
-io_rewind(io)
+rb_io_rewind(io)
VALUE io;
{
OpenFile *fptr;
@@ -276,19 +274,19 @@ io_rewind(io)
}
static VALUE
-io_eof(io)
+rb_io_eof(io)
VALUE io;
{
OpenFile *fptr;
int ch;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
- if (READ_DATA_PENDING(fptr->f)) return FALSE;
+ if (READ_DATA_PENDING(fptr->f)) return Qfalse;
#if 0
- if (feof(fptr->f)) return TRUE;
- return FALSE;
+ if (feof(fptr->f)) return Qtrue;
+ return Qfalse;
#else
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -297,24 +295,24 @@ io_eof(io)
if (ch != EOF) {
(void)ungetc(ch, fptr->f);
- return FALSE;
+ return Qfalse;
}
- return TRUE;
+ return Qtrue;
#endif
}
static VALUE
-io_sync(io)
+rb_io_sync(io)
VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- return (fptr->mode & FMODE_SYNC) ? TRUE : FALSE;
+ return (fptr->mode & FMODE_SYNC) ? Qtrue : Qfalse;
}
static VALUE
-io_set_sync(io, mode)
+rb_io_set_sync(io, mode)
VALUE io, mode;
{
OpenFile *fptr;
@@ -330,7 +328,7 @@ io_set_sync(io, mode)
}
static VALUE
-io_fileno(io)
+rb_io_fileno(io)
VALUE io;
{
OpenFile *fptr;
@@ -342,7 +340,7 @@ io_fileno(io)
}
static VALUE
-io_to_io(io)
+rb_io_to_io(io)
VALUE io;
{
return io;
@@ -368,7 +366,7 @@ read_all(port)
int n;
GetOpenFile(port, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
#ifdef __BEOS__
if (fstat(fileno(fptr->f), &st) == 0 && S_ISREG(st.st_mode)
@@ -384,7 +382,7 @@ read_all(port)
}
}
}
- str = str_new(0, siz);
+ str = rb_str_new(0, siz);
for (;;) {
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -397,15 +395,15 @@ read_all(port)
bytes += n;
if (bytes < siz) break;
siz += BUFSIZ;
- str_resize(str, siz);
+ rb_str_resize(str, siz);
}
if (bytes == 0) return Qnil;
- if (bytes != siz) str_resize(str, bytes);
- return str_taint(str);
+ if (bytes != siz) rb_str_resize(str, bytes);
+ return rb_str_taint(str);
}
static VALUE
-io_read(argc, argv, io)
+rb_io_read(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -420,9 +418,9 @@ io_read(argc, argv, io)
len = NUM2INT(length);
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
- str = str_new(0, len);
+ str = rb_str_new(0, len);
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -435,11 +433,11 @@ io_read(argc, argv, io)
RSTRING(str)->len = n;
RSTRING(str)->ptr[n] = '\0';
- return str_taint(str);
+ return rb_str_taint(str);
}
VALUE
-io_gets_method(argc, argv, io)
+rb_io_gets_method(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -453,7 +451,7 @@ io_gets_method(argc, argv, io)
VALUE rs;
if (argc == 0) {
- rs = RS;
+ rs = rb_rs;
}
else {
rb_scan_args(argc, argv, "1", &rs);
@@ -472,7 +470,7 @@ io_gets_method(argc, argv, io)
rspara = 1;
}
else if (rslen == 1 && RSTRING(rs)->ptr[0] == '\n') {
- return io_gets(io);
+ return rb_io_gets(io);
}
else {
rsptr = RSTRING(rs)->ptr;
@@ -480,7 +478,7 @@ io_gets_method(argc, argv, io)
}
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
if (rspara) {
@@ -541,9 +539,9 @@ io_gets_method(argc, argv, io)
}
if (append)
- str_cat(str, buf, cnt);
+ rb_str_cat(str, buf, cnt);
else
- str = str_new(buf, cnt);
+ str = rb_str_new(buf, cnt);
if (c != EOF &&
(!rslen ||
@@ -571,15 +569,15 @@ io_gets_method(argc, argv, io)
if (!NIL_P(str)) {
fptr->lineno++;
lineno = INT2FIX(fptr->lineno);
- str_taint(str);
+ rb_str_taint(str);
}
- lastline_set(str);
+ rb_lastline_set(str);
return str;
}
VALUE
-io_gets(io)
+rb_io_gets(io)
VALUE io;
{
OpenFile *fptr;
@@ -592,7 +590,7 @@ io_gets(io)
int append = 0;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
again:
@@ -617,9 +615,9 @@ io_gets(io)
}
if (append)
- str_cat(str, buf, cnt);
+ rb_str_cat(str, buf, cnt);
else
- str = str_new(buf, cnt);
+ str = rb_str_new(buf, cnt);
if (c != EOF && RSTRING(str)->ptr[RSTRING(str)->len-1] != '\n') {
append = 1;
@@ -630,32 +628,32 @@ io_gets(io)
if (!NIL_P(str)) {
fptr->lineno++;
lineno = INT2FIX(fptr->lineno);
- str_taint(str);
+ rb_str_taint(str);
}
- lastline_set(str);
+ rb_lastline_set(str);
return str;
}
static VALUE
-io_lineno(io)
+rb_io_lineno(io)
VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
return INT2NUM(fptr->lineno);
}
static VALUE
-io_set_lineno(io, lineno)
+rb_io_set_lineno(io, lineno)
VALUE io, lineno;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
fptr->lineno = NUM2INT(lineno);
}
@@ -670,50 +668,50 @@ lineno_setter(val, id, var)
}
static VALUE
-io_readline(argc, argv, io)
+rb_io_readline(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
- VALUE line = io_gets_method(argc, argv, io);
+ VALUE line = rb_io_gets_method(argc, argv, io);
if (NIL_P(line)) {
- eof_error();
+ rb_eof_error();
}
return line;
}
static VALUE
-io_readlines(argc, argv, io)
+rb_io_readlines(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
VALUE line, ary;
- ary = ary_new();
- while (!NIL_P(line = io_gets_method(argc, argv, io))) {
- ary_push(ary, line);
+ ary = rb_ary_new();
+ while (!NIL_P(line = rb_io_gets_method(argc, argv, io))) {
+ rb_ary_push(ary, line);
}
return ary;
}
static VALUE
-io_each_line(argc, argv, io)
+rb_io_each_line(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
VALUE str;
- while (!NIL_P(str = io_gets_method(argc, argv, io))) {
+ while (!NIL_P(str = rb_io_gets_method(argc, argv, io))) {
rb_yield(str);
}
return Qnil;
}
static VALUE
-io_each_byte(io)
+rb_io_each_byte(io)
VALUE io;
{
OpenFile *fptr;
@@ -721,7 +719,7 @@ io_each_byte(io)
int c;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
for (;;) {
@@ -737,7 +735,7 @@ io_each_byte(io)
}
VALUE
-io_getc(io)
+rb_io_getc(io)
VALUE io;
{
OpenFile *fptr;
@@ -745,7 +743,7 @@ io_getc(io)
int c;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
READ_CHECK(f);
@@ -761,26 +759,26 @@ io_getc(io)
}
static VALUE
-io_readchar(io)
+rb_io_readchar(io)
VALUE io;
{
- VALUE c = io_getc(io);
+ VALUE c = rb_io_getc(io);
if (NIL_P(c)) {
- eof_error();
+ rb_eof_error();
}
return c;
}
VALUE
-io_ungetc(io, c)
+rb_io_ungetc(io, c)
VALUE io, c;
{
OpenFile *fptr;
Check_Type(c, T_FIXNUM);
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
if (ungetc(FIX2INT(c), fptr->f) == EOF)
rb_sys_fail(fptr->path);
@@ -788,15 +786,15 @@ io_ungetc(io, c)
}
static VALUE
-io_isatty(io)
+rb_io_isatty(io)
VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
if (isatty(fileno(fptr->f)) == 0)
- return FALSE;
- return TRUE;
+ return Qfalse;
+ return Qtrue;
}
static void
@@ -816,7 +814,7 @@ fptr_finalize(fptr)
}
static void
-io_fptr_close(fptr)
+rb_io_fptr_close(fptr)
OpenFile *fptr;
{
if (fptr->f == NULL && fptr->f2 == NULL) return;
@@ -831,10 +829,10 @@ io_fptr_close(fptr)
}
void
-io_fptr_finalize(fptr)
+rb_io_fptr_finalize(fptr)
OpenFile *fptr;
{
- io_fptr_close(fptr);
+ rb_io_fptr_close(fptr);
if (fptr->path) {
free(fptr->path);
fptr->path = NULL;
@@ -842,37 +840,30 @@ io_fptr_finalize(fptr)
}
VALUE
-io_close(io)
+rb_io_close(io)
VALUE io;
{
OpenFile *fptr;
+ rb_secure(4);
GetOpenFile(io, fptr);
- io_fptr_close(fptr);
+ rb_io_fptr_close(fptr);
return Qnil;
}
-VALUE
-io_close_method(io)
- VALUE io;
-{
- rb_secure(4);
- return io_close(io);
-}
-
static VALUE
-io_closed(io)
+rb_io_closed(io)
VALUE io;
{
OpenFile *fptr;
fptr = RFILE(io)->fptr;
- return (fptr->f || fptr->f2)?FALSE:TRUE;
+ return (fptr->f || fptr->f2)?Qfalse:Qtrue;
}
static VALUE
-io_syswrite(io, str)
+rb_io_syswrite(io, str)
VALUE io, str;
{
OpenFile *fptr;
@@ -881,14 +872,14 @@ io_syswrite(io, str)
rb_secure(4);
if (TYPE(str) != T_STRING)
- str = obj_as_string(str);
+ str = rb_obj_as_string(str);
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
#ifdef THREAD
- thread_fd_writable(fileno(f));
+ rb_thread_fd_writable(fileno(f));
#endif
n = write(fileno(f), RSTRING(str)->ptr, RSTRING(str)->len);
@@ -898,7 +889,7 @@ io_syswrite(io, str)
}
static VALUE
-io_sysread(io, len)
+rb_io_sysread(io, len)
VALUE io, len;
{
OpenFile *fptr;
@@ -907,27 +898,27 @@ io_sysread(io, len)
ilen = NUM2INT(len);
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
- str = str_new(0, ilen);
+ str = rb_str_new(0, ilen);
#ifdef THREAD
- thread_wait_fd(fileno(fptr->f));
+ rb_thread_wait_fd(fileno(fptr->f));
#endif
TRAP_BEG;
n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len);
TRAP_END;
if (n == -1) rb_sys_fail(fptr->path);
- if (n == 0) eof_error();
+ if (n == 0) rb_eof_error();
RSTRING(str)->len = n;
RSTRING(str)->ptr[n] = '\0';
- return str_taint(str);
+ return rb_str_taint(str);
}
VALUE
-io_binmode(io)
+rb_io_binmode(io)
VALUE io;
{
#if defined(NT) || defined(DJGPP) || defined(__CYGWIN32__) || defined(__human68k__) || defined(USE_CWGUSI)
@@ -947,9 +938,9 @@ io_binmode(io)
rb_sys_fail(fptr->path);
# else /* USE_CWGUSI */
if (fptr->f)
- fptr->f->mode.binary_io = 1;
+ fptr->f->mode.binrb_ary_io = 1;
if (fptr->f2)
- fptr->f2->mode.binary_io = 1;
+ fptr->f2->mode.binrb_ary_io = 1;
# endif /* USE_CWGUSI */
#endif
@@ -959,7 +950,7 @@ io_binmode(io)
}
int
-io_mode_flags(mode)
+rb_io_mode_flags(mode)
char *mode;
{
int flags = 0;
@@ -975,7 +966,7 @@ io_mode_flags(mode)
flags |= FMODE_WRITABLE;
break;
default:
- ArgError("illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode");
}
if (mode[1] == 'b') {
@@ -1000,7 +991,7 @@ rb_fopen(fname, mode)
f = fopen(fname, mode);
if (f == NULL) {
if (errno == EMFILE || errno == ENFILE) {
- gc_gc();
+ rb_gc();
f = fopen(fname, mode);
}
if (f == NULL) {
@@ -1079,7 +1070,7 @@ pipe_atexit()
while (list) {
tmp = list->next;
- io_fptr_finalize(list->fptr);
+ rb_io_fptr_finalize(list->fptr);
list = tmp;
}
}
@@ -1104,10 +1095,10 @@ pipe_finalize(fptr)
#endif
void
-io_unbuffered(fptr)
+rb_io_unbuffered(fptr)
OpenFile *fptr;
{
- if (fptr->f2 == 0) TypeError("non-writable fptr");
+ if (fptr->f2 == 0) rb_raise(rb_eTypeError, "non-writable fptr");
if (fptr->f != 0) setbuf(fptr->f, NULL);
setbuf(fptr->f2, NULL);
fptr->mode |= FMODE_SYNC;
@@ -1118,7 +1109,7 @@ pipe_open(pname, mode)
char *pname, *mode;
{
#ifndef USE_CWGUSI
- int modef = io_mode_flags(mode);
+ int modef = rb_io_mode_flags(mode);
OpenFile *fptr;
#if defined(NT) || defined(DJGPP) || defined(__human68k__)
@@ -1127,7 +1118,7 @@ pipe_open(pname, mode)
if (f == NULL) rb_sys_fail(pname);
else {
NEWOBJ(port, struct RFile);
- OBJSETUP(port, cIO, T_FILE);
+ OBJSETUP(port, rb_cIO, T_FILE);
MakeOpenFile(port, fptr);
fptr->finalize = pipe_finalize;
fptr->mode = modef;
@@ -1136,9 +1127,9 @@ pipe_open(pname, mode)
if (modef & FMODE_READABLE) fptr->f = f;
if (modef & FMODE_WRITABLE) {
fptr->f2 = f;
- io_unbuffered(fptr);
+ rb_io_unbuffered(fptr);
}
- obj_call_init((VALUE)port);
+ rb_obj_call_init((VALUE)port);
return (VALUE)port;
}
#else
@@ -1175,15 +1166,15 @@ pipe_open(pname, mode)
}
if (doexec) {
- extern char *sourcefile;
- extern int sourceline;
+ extern char *ruby_sourcefile;
+ extern int ruby_sourceline;
int fd;
for (fd = 3; fd < NOFILE; fd++)
close(fd);
rb_proc_exec(pname);
fprintf(stderr, "%s:%d: command not found: %s\n",
- sourcefile, sourceline, pname);
+ ruby_sourcefile, ruby_sourceline, pname);
_exit(127);
}
return Qnil;
@@ -1191,7 +1182,7 @@ pipe_open(pname, mode)
case -1: /* fork failed */
if (errno == EAGAIN) {
#ifdef THREAD
- thread_sleep(1);
+ rb_thread_sleep(1);
#else
sleep(1);
#endif
@@ -1205,7 +1196,7 @@ pipe_open(pname, mode)
if (pid < 0) rb_sys_fail(pname);
else {
NEWOBJ(port, struct RFile);
- OBJSETUP(port, cIO, T_FILE);
+ OBJSETUP(port, rb_cIO, T_FILE);
MakeOpenFile(port, fptr);
fptr->mode = modef;
fptr->mode |= FMODE_SYNC;
@@ -1226,7 +1217,7 @@ pipe_open(pname, mode)
fptr->finalize = pipe_finalize;
pipe_add_fptr(fptr);
#endif
- obj_call_init((VALUE)port);
+ rb_obj_call_init((VALUE)port);
return (VALUE)port;
}
}
@@ -1237,7 +1228,7 @@ pipe_open(pname, mode)
}
static VALUE
-io_s_popen(argc, argv, self)
+rb_io_s_popen(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
@@ -1254,26 +1245,26 @@ io_s_popen(argc, argv, self)
mode = STR2CSTR(pmode);
len = strlen(mode);
if (len == 0 || len > 3)
- ArgError("illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode");
}
Check_SafeStr(pname);
return pipe_open(RSTRING(pname)->ptr, mode);
}
static VALUE
-io_open(fname, mode)
+rb_io_open(fname, mode)
char *fname, *mode;
{
if (fname[0] == '|') {
return pipe_open(fname+1, mode);
}
else {
- return file_open(fname, mode);
+ return rb_file_open(fname, mode);
}
}
static VALUE
-f_open(argc, argv)
+rb_f_open(argc, argv)
int argc;
VALUE *argv;
{
@@ -1292,30 +1283,26 @@ f_open(argc, argv)
mode = STR2CSTR(pmode);
len = strlen(mode);
if (len == 0 || len > 3)
- ArgError("illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode");
}
- port = io_open(RSTRING(pname)->ptr, mode);
- if (iterator_p()) {
- return rb_ensure(rb_yield, port, io_close, port);
+ port = rb_io_open(RSTRING(pname)->ptr, mode);
+ if (rb_iterator_p()) {
+ return rb_ensure(rb_yield, port, rb_io_close, port);
}
return port;
}
static VALUE
-io_get_io(io)
+rb_io_get_io(io)
VALUE io;
{
return rb_convert_type(io, T_FILE, "IO", "to_io");
}
-#ifndef NT
-extern char *strdup();
-#endif
-
static char*
-io_mode_string(fptr)
+rb_io_mode_string(fptr)
OpenFile *fptr;
{
switch (fptr->mode & FMODE_READWRITE) {
@@ -1330,7 +1317,7 @@ io_mode_string(fptr)
}
VALUE
-io_reopen(io, nfile)
+rb_io_reopen(io, nfile)
VALUE io, nfile;
{
OpenFile *fptr, *orig;
@@ -1338,7 +1325,7 @@ io_reopen(io, nfile)
int fd;
GetOpenFile(io, fptr);
- nfile = io_get_io(nfile);
+ nfile = rb_io_get_io(nfile);
GetOpenFile(nfile, orig);
if (orig->f2) {
@@ -1357,7 +1344,7 @@ io_reopen(io, nfile)
else fptr->path = 0;
fptr->finalize = orig->finalize;
- mode = io_mode_string(fptr);
+ mode = rb_io_mode_string(fptr);
fd = fileno(fptr->f);
if (fileno(fptr->f) < 3) {
/* need to keep stdio */
@@ -1381,7 +1368,7 @@ io_reopen(io, nfile)
}
if (fptr->mode & FMODE_BINMODE) {
- io_binmode(io);
+ rb_io_binmode(io);
}
RBASIC(io)->klass = RBASIC(nfile)->klass;
@@ -1389,7 +1376,7 @@ io_reopen(io, nfile)
}
static VALUE
-io_clone(io)
+rb_io_clone(io)
VALUE io;
{
OpenFile *fptr, *orig;
@@ -1434,25 +1421,25 @@ io_clone(io)
fptr->f = rb_fdopen(fd, "w");
}
if (fptr->mode & FMODE_BINMODE) {
- io_binmode((VALUE)obj);
+ rb_io_binmode((VALUE)obj);
}
return (VALUE)obj;
}
static VALUE
-io_printf(argc, argv, out)
+rb_io_printf(argc, argv, out)
int argc;
VALUE argv[];
VALUE out;
{
- rb_funcall(out, id_write, 1, f_sprintf(argc, argv));
+ rb_funcall(out, id_write, 1, rb_f_sprintf(argc, argv));
return Qnil;
}
static VALUE
-f_printf(argc, argv)
+rb_rb_f_printf(argc, argv)
int argc;
VALUE argv[];
{
@@ -1468,15 +1455,15 @@ f_printf(argc, argv)
argc--;
}
else {
- NameError("output must responds to `write'");
+ rb_raise(rb_eNameError, "output must responds to `write'");
}
- rb_funcall(out, id_write, 1, f_sprintf(argc, argv));
+ rb_funcall(out, id_write, 1, rb_f_sprintf(argc, argv));
return Qnil;
}
static VALUE
-io_print(argc, argv, out)
+rb_io_print(argc, argv, out)
int argc;
VALUE *argv;
VALUE out;
@@ -1487,48 +1474,48 @@ io_print(argc, argv, out)
/* if no argument given, print `$_' */
if (argc == 0) {
argc = 1;
- line = lastline_get();
+ line = rb_lastline_get();
argv = &line;
}
for (i=0; i<argc; i++) {
- if (!NIL_P(OFS) && i>0) {
- io_write(out, OFS);
+ if (!NIL_P(rb_output_fs) && i>0) {
+ rb_io_write(out, rb_output_fs);
}
switch (TYPE(argv[i])) {
case T_NIL:
- io_write(out, str_new2("nil"));
+ rb_io_write(out, rb_str_new2("nil"));
break;
case T_ARRAY:
for (j=0; j<RARRAY(argv[i])->len; j++) {
- if (!NIL_P(OFS) && j>0) {
- io_write(out, OFS);
+ if (!NIL_P(rb_output_fs) && j>0) {
+ rb_io_write(out, rb_output_fs);
}
- io_write(out, RARRAY(argv[i])->ptr[j]);
+ rb_io_write(out, RARRAY(argv[i])->ptr[j]);
}
break;
default:
- io_write(out, argv[i]);
+ rb_io_write(out, argv[i]);
break;
}
}
- if (!NIL_P(ORS)) {
- io_write(out, ORS);
+ if (!NIL_P(rb_output_rs)) {
+ rb_io_write(out, rb_output_rs);
}
return Qnil;
}
static VALUE
-f_print(argc, argv)
+rb_f_print(argc, argv)
int argc;
VALUE *argv;
{
- io_print(argc, argv, rb_defout);
+ rb_io_print(argc, argv, rb_defout);
return Qnil;
}
static VALUE
-io_putc(io, ch)
+rb_io_putc(io, ch)
VALUE io, ch;
{
OpenFile *fptr;
@@ -1537,7 +1524,7 @@ io_putc(io, ch)
rb_secure(4);
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
@@ -1550,14 +1537,14 @@ io_putc(io, ch)
}
static VALUE
-f_putc(recv, ch)
+rb_f_putc(recv, ch)
VALUE recv, ch;
{
- return io_putc(rb_defout, ch);
+ return rb_io_putc(rb_defout, ch);
}
static VALUE
-io_puts(argc, argv, out)
+rb_io_puts(argc, argv, out)
int argc;
VALUE *argv;
VALUE out;
@@ -1567,27 +1554,27 @@ io_puts(argc, argv, out)
/* if no argument given, print newline. */
if (argc == 0) {
- io_write(out, RS_default);
+ rb_io_write(out, rb_default_rs);
return Qnil;
}
for (i=0; i<argc; i++) {
switch (TYPE(argv[i])) {
case T_NIL:
- line = str_new2("nil");
+ line = rb_str_new2("nil");
break;
case T_ARRAY:
for (j=0; j<RARRAY(argv[i])->len; j++) {
- io_puts(1, &RARRAY(argv[i])->ptr[j], out);
+ rb_io_puts(1, &RARRAY(argv[i])->ptr[j], out);
}
continue;
default:
line = argv[i];
break;
}
- line = obj_as_string(line);
- io_write(out, line);
+ line = rb_obj_as_string(line);
+ rb_io_write(out, line);
if (RSTRING(line)->ptr[RSTRING(line)->len-1] != '\n') {
- io_write(out, RS_default);
+ rb_io_write(out, rb_default_rs);
}
}
@@ -1595,11 +1582,11 @@ io_puts(argc, argv, out)
}
static VALUE
-f_puts(argc, argv)
+rb_f_puts(argc, argv)
int argc;
VALUE *argv;
{
- io_puts(argc, argv, rb_defout);
+ rb_io_puts(argc, argv, rb_defout);
return Qnil;
}
@@ -1607,12 +1594,12 @@ void
rb_p(obj) /* for debug print within C code */
VALUE obj;
{
- io_write(rb_defout, rb_inspect(obj));
- io_write(rb_defout, RS_default);
+ rb_io_write(rb_defout, rb_inspect(obj));
+ rb_io_write(rb_defout, rb_default_rs);
}
static VALUE
-f_p(argc, argv)
+rb_f_p(argc, argv)
int argc;
VALUE *argv;
{
@@ -1625,7 +1612,7 @@ f_p(argc, argv)
}
static VALUE
-obj_display(argc, argv, self)
+rb_obj_display(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
@@ -1636,28 +1623,28 @@ obj_display(argc, argv, self)
out = rb_defout;
}
- io_write(out, self);
+ rb_io_write(out, self);
return Qnil;
}
static void
-io_defset(val, id)
+rb_io_defset(val, id)
VALUE val;
ID id;
{
if (TYPE(val) == T_STRING) {
- val = io_open(RSTRING(val)->ptr, "w");
+ val = rb_io_open(RSTRING(val)->ptr, "w");
}
if (!rb_respond_to(val, id_write)) {
- TypeError("$< must have write method, %s given",
- rb_class2name(CLASS_OF(val)));
+ rb_raise(rb_eTypeError, "$< must have write method, %s given",
+ rb_class2name(CLASS_OF(val)));
}
rb_defout = val;
}
static void
-io_stdio_set(val, id, var)
+rb_io_stdio_set(val, id, var)
VALUE val;
ID id;
VALUE *var;
@@ -1666,18 +1653,18 @@ io_stdio_set(val, id, var)
int fd;
if (TYPE(val) != T_FILE) {
- TypeError("%s must be IO object", rb_id2name(id));
+ rb_raise(rb_eTypeError, "%s must be IO object", rb_id2name(id));
}
GetOpenFile(*var, fptr);
fd = fileno(fptr->f);
GetOpenFile(val, fptr);
if (fd == 0) {
- io_readable(fptr);
+ rb_io_check_readable(fptr);
}
else {
- io_writable(fptr);
+ rb_io_check_writable(fptr);
}
- io_reopen(*var, val);
+ rb_io_reopen(*var, val);
}
static VALUE
@@ -1693,13 +1680,13 @@ prep_stdio(f, mode, klass)
MakeOpenFile(io, fp);
fp->f = f;
fp->mode = mode;
- obj_call_init((VALUE)io);
+ rb_obj_call_init((VALUE)io);
return (VALUE)io;
}
static VALUE
-io_s_new(argc, argv, klass)
+rb_io_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -1711,7 +1698,7 @@ io_s_new(argc, argv, klass)
Check_SafeStr(mode);
m = RSTRING(mode)->ptr;
}
- return prep_stdio(rb_fdopen(NUM2INT(fnum), m), io_mode_flags(m), klass);
+ return prep_stdio(rb_fdopen(NUM2INT(fnum), m), rb_io_mode_flags(m), klass);
}
static int
@@ -1736,32 +1723,33 @@ next_argv()
if (next_p == 1) {
next_p = 0;
if (RARRAY(rb_argv)->len > 0) {
- filename = ary_shift(rb_argv);
+ filename = rb_ary_shift(rb_argv);
fn = RSTRING(filename)->ptr;
if (RSTRING(filename)->len == 1 && fn[0] == '-') {
file = rb_stdin;
- if (inplace) {
+ if (ruby_inplace_mode) {
rb_defout = rb_stdout;
}
}
else {
FILE *fr = rb_fopen(fn, "r");
- if (inplace) {
+ if (ruby_inplace_mode) {
struct stat st, st2;
VALUE str;
FILE *fw;
if (TYPE(rb_defout) == T_FILE && rb_defout != rb_stdout) {
- io_close(rb_defout);
+ rb_io_close(rb_defout);
}
fstat(fileno(fr), &st);
- if (*inplace) {
- str = str_new2(fn);
+ if (*ruby_inplace_mode) {
+ str = rb_str_new2(fn);
#if defined(MSDOS) || defined(__CYGWIN32__) || defined(NT)
- add_suffix(str, inplace);
+ add_suffix(str, ruby_inplace_mode);
#else
- str_cat(str, inplace, strlen(inplace));
+ rb_str_cat(str, ruby_inplace_mode,
+ strlen(ruby_inplace_mode));
#endif
#if defined(MSDOS) || defined(__BOW__) || defined(__CYGWIN32__) || defined(NT) || defined(__human68k__)
(void)fclose(fr);
@@ -1770,8 +1758,8 @@ next_argv()
fr = rb_fopen(RSTRING(str)->ptr, "r");
#else
if (rename(fn, RSTRING(str)->ptr) < 0) {
- Warn("Can't rename %s to %s: %s, skipping file",
- fn, RSTRING(str)->ptr, strerror(errno));
+ rb_warn("Can't rename %s to %s: %s, skipping file",
+ fn, RSTRING(str)->ptr, strerror(errno));
fclose(fr);
goto retry;
}
@@ -1780,13 +1768,13 @@ next_argv()
else {
#if !defined(MSDOS) && !defined(__BOW__) && !defined(__CYGWIN32__) && !defined(NT) && !defined(__human68k__)
if (unlink(fn) < 0) {
- Warn("Can't remove %s: %s, skipping file",
- fn, strerror(errno));
+ rb_warn("Can't remove %s: %s, skipping file",
+ fn, strerror(errno));
fclose(fr);
goto retry;
}
#else
- Fatal("Can't do inplace edit without backup");
+ rb_fatal("Can't do inplace edit without backup");
#endif
}
fw = rb_fopen(fn, "w");
@@ -1798,21 +1786,21 @@ next_argv()
fchown(fileno(fw), st.st_uid, st.st_gid);
}
#endif
- rb_defout = prep_stdio(fw, FMODE_WRITABLE, cFile);
+ rb_defout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile);
}
- file = prep_stdio(fr, FMODE_READABLE, cFile);
+ file = prep_stdio(fr, FMODE_READABLE, rb_cFile);
}
}
else {
init_p = 0;
- return FALSE;
+ return Qfalse;
}
}
- return TRUE;
+ return Qtrue;
}
static VALUE
-f_gets_method(argc, argv)
+rb_f_gets_method(argc, argv)
int argc;
VALUE *argv;
{
@@ -1820,9 +1808,9 @@ f_gets_method(argc, argv)
retry:
if (!next_argv()) return Qnil;
- line = io_gets_method(argc, argv, file);
+ line = rb_io_gets_method(argc, argv, file);
if (NIL_P(line) && next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
goto retry;
}
@@ -1833,109 +1821,122 @@ f_gets_method(argc, argv)
}
VALUE
-f_gets()
+rb_f_gets()
{
- return f_gets_method(0,0);
+ VALUE line;
+
+ retry:
+ if (!next_argv()) return Qnil;
+ line = rb_io_gets(file);
+ if (NIL_P(line) && next_p != -1) {
+ rb_io_close(file);
+ next_p = 1;
+ goto retry;
+ }
+ gets_lineno++;
+ lineno = INT2FIX(gets_lineno);
+
+ return line;
}
static VALUE
-f_readline(argc, argv)
+rb_f_readline(argc, argv)
int argc;
VALUE *argv;
{
- VALUE line = f_gets_method(argc, argv);
+ VALUE line = rb_f_gets_method(argc, argv);
if (NIL_P(line)) {
- eof_error();
+ rb_eof_error();
}
return line;
}
static VALUE
-f_tell()
+rb_f_tell()
{
- return io_tell(file);
+ return rb_io_tell(file);
}
static VALUE
-f_seek(self, offset, ptrname)
+rb_f_seek(self, offset, ptrname)
VALUE self, offset, ptrname;
{
if (!next_argv()) {
- ArgError("no stream to seek");
+ rb_raise(rb_eArgError, "no stream to seek");
}
- return io_seek(file, offset, ptrname);
+ return rb_io_seek(file, offset, ptrname);
}
static VALUE
-f_set_pos(self, offset)
+rb_f_set_pos(self, offset)
VALUE self, offset;
{
if (!next_argv()) {
- ArgError("no stream to pos");
+ rb_raise(rb_eArgError, "no stream to pos");
}
- return io_set_pos(file, offset);
+ return rb_io_set_pos(file, offset);
}
static VALUE
-f_rewind()
+rb_f_rewind()
{
- return io_rewind(file);
+ return rb_io_rewind(file);
}
static VALUE
-f_eof()
+rb_f_eof()
{
if (init_p == 0 && !next_argv())
- return TRUE;
- if (io_eof(file)) {
+ return Qtrue;
+ if (rb_io_eof(file)) {
next_p = 1;
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
-f_getc()
+rb_f_getc()
{
- return io_getc(rb_stdin);
+ return rb_io_getc(rb_stdin);
}
static VALUE
-f_ungetc(self, c)
+rb_f_ungetc(self, c)
VALUE self, c;
{
if (!next_argv()) {
- ArgError("no stream to ungetc");
+ rb_raise(rb_eArgError, "no stream to ungetc");
}
- return io_ungetc(file, c);
+ return rb_io_ungetc(file, c);
}
static VALUE
-f_readchar()
+rb_f_readchar()
{
- VALUE c = f_getc();
+ VALUE c = rb_f_getc();
if (NIL_P(c)) {
- eof_error();
+ rb_eof_error();
}
return c;
}
static VALUE
-f_readlines(argc, argv)
+rb_f_readlines(argc, argv)
int argc;
VALUE *argv;
{
VALUE line, ary;
- ary = ary_new();
- while (!NIL_P(line = f_gets_method(argc, argv))) {
- ary_push(ary, line);
+ ary = rb_ary_new();
+ while (!NIL_P(line = rb_f_gets_method(argc, argv))) {
+ rb_ary_push(ary, line);
}
return ary;
@@ -1948,13 +1949,13 @@ rb_str_setter(val, id, var)
VALUE *var;
{
if (!NIL_P(val) && TYPE(val) != T_STRING) {
- TypeError("value of %s must be String", rb_id2name(id));
+ rb_raise(rb_eTypeError, "value of %s must be String", rb_id2name(id));
}
*var = val;
}
static VALUE
-f_backquote(obj, str)
+rb_f_backquote(obj, str)
VALUE obj, str;
{
VALUE port, result;
@@ -1963,9 +1964,9 @@ f_backquote(obj, str)
port = pipe_open(RSTRING(str)->ptr, "r");
result = read_all(port);
- io_close(port);
+ rb_io_close(port);
- if (NIL_P(result)) return str_new(0,0);
+ if (NIL_P(result)) return rb_str_new(0,0);
return result;
}
@@ -1977,7 +1978,7 @@ f_backquote(obj, str)
#endif
static VALUE
-f_select(argc, argv, obj)
+rb_f_select(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -1996,7 +1997,7 @@ f_select(argc, argv, obj)
tp = NULL;
}
else {
- timerec = time_timeval(timeout);
+ timerec = rb_time_timeval(timeout);
tp = &timerec;
}
@@ -2006,7 +2007,7 @@ f_select(argc, argv, obj)
rp = &rset;
FD_ZERO(rp);
for (i=0; i<RARRAY(read)->len; i++) {
- VALUE io = io_get_io(RARRAY(read)->ptr[i]);
+ VALUE io = rb_io_get_io(RARRAY(read)->ptr[i]);
GetOpenFile(io, fptr);
FD_SET(fileno(fptr->f), rp);
@@ -2029,7 +2030,7 @@ f_select(argc, argv, obj)
wp = &wset;
FD_ZERO(wp);
for (i=0; i<RARRAY(write)->len; i++) {
- VALUE io = io_get_io(RARRAY(write)->ptr[i]);
+ VALUE io = rb_io_get_io(RARRAY(write)->ptr[i]);
GetOpenFile(io, fptr);
FD_SET(fileno(fptr->f), wp);
@@ -2048,7 +2049,7 @@ f_select(argc, argv, obj)
ep = &eset;
FD_ZERO(ep);
for (i=0; i<RARRAY(except)->len; i++) {
- VALUE io = io_get_io(RARRAY(except)->ptr[i]);
+ VALUE io = rb_io_get_io(RARRAY(except)->ptr[i]);
GetOpenFile(io, fptr);
FD_SET(fileno(fptr->f), ep);
@@ -2065,7 +2066,7 @@ f_select(argc, argv, obj)
max++;
#ifdef THREAD
- n = thread_select(max, rp, wp, ep, tp);
+ n = rb_thread_select(max, rp, wp, ep, tp);
if (n < 0) {
rb_sys_fail(0);
}
@@ -2084,10 +2085,10 @@ f_select(argc, argv, obj)
#endif
if (!pending && n == 0) return Qnil; /* returns nil on timeout */
- res = ary_new2(3);
- ary_push(res, rp?ary_new():ary_new2(0));
- ary_push(res, wp?ary_new():ary_new2(0));
- ary_push(res, ep?ary_new():ary_new2(0));
+ res = rb_ary_new2(3);
+ rb_ary_push(res, rp?rb_ary_new():rb_ary_new2(0));
+ rb_ary_push(res, wp?rb_ary_new():rb_ary_new2(0));
+ rb_ary_push(res, ep?rb_ary_new():rb_ary_new2(0));
if (interrupt_flag == 0) {
if (rp) {
@@ -2096,7 +2097,7 @@ f_select(argc, argv, obj)
GetOpenFile(RARRAY(read)->ptr[i], fptr);
if (FD_ISSET(fileno(fptr->f), rp)
|| FD_ISSET(fileno(fptr->f), &pset)) {
- ary_push(list, RARRAY(read)->ptr[i]);
+ rb_ary_push(list, RARRAY(read)->ptr[i]);
}
}
}
@@ -2106,10 +2107,10 @@ f_select(argc, argv, obj)
for (i=0; i< RARRAY(write)->len; i++) {
GetOpenFile(RARRAY(write)->ptr[i], fptr);
if (FD_ISSET(fileno(fptr->f), wp)) {
- ary_push(list, RARRAY(write)->ptr[i]);
+ rb_ary_push(list, RARRAY(write)->ptr[i]);
}
else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), wp)) {
- ary_push(list, RARRAY(write)->ptr[i]);
+ rb_ary_push(list, RARRAY(write)->ptr[i]);
}
}
}
@@ -2119,10 +2120,10 @@ f_select(argc, argv, obj)
for (i=0; i< RARRAY(except)->len; i++) {
GetOpenFile(RARRAY(except)->ptr[i], fptr);
if (FD_ISSET(fileno(fptr->f), ep)) {
- ary_push(list, RARRAY(except)->ptr[i]);
+ rb_ary_push(list, RARRAY(except)->ptr[i]);
}
else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), ep)) {
- ary_push(list, RARRAY(except)->ptr[i]);
+ rb_ary_push(list, RARRAY(except)->ptr[i]);
}
}
}
@@ -2132,7 +2133,7 @@ f_select(argc, argv, obj)
}
static VALUE
-io_ctl(io, req, arg, io_p)
+rb_io_ctl(io, req, arg, io_p)
VALUE io, req, arg;
int io_p;
{
@@ -2147,13 +2148,13 @@ io_ctl(io, req, arg, io_p)
rb_secure(2);
GetOpenFile(io, fptr);
- if (NIL_P(arg) || arg == FALSE) {
+ if (NIL_P(arg) || arg == Qfalse) {
narg = 0;
}
else if (FIXNUM_P(arg)) {
narg = FIX2INT(arg);
}
- else if (arg == TRUE) {
+ else if (arg == Qtrue) {
narg = 1;
}
else {
@@ -2169,13 +2170,13 @@ io_ctl(io, req, arg, io_p)
#else
len = 256; /* otherwise guess at what's safe */
#endif
- str_modify(arg);
+ rb_str_modify(arg);
if (len <= RSTRING(arg)->len) {
len = RSTRING(arg)->len;
}
if (RSTRING(arg)->len < len) {
- str_resize(arg, len+1);
+ rb_str_resize(arg, len+1);
}
RSTRING(arg)->ptr[len] = 17; /* a little sanity check here */
narg = (long)RSTRING(arg)->ptr;
@@ -2190,7 +2191,7 @@ io_ctl(io, req, arg, io_p)
# endif
TRAP_END;
#else
- if (!io_p) {
+ if (!rb_io_p) {
rb_notimplement();
}
TRAP_BEG;
@@ -2199,7 +2200,7 @@ io_ctl(io, req, arg, io_p)
#endif
if (retval < 0) rb_sys_fail(fptr->path);
if (TYPE(arg) == T_STRING && RSTRING(arg)->ptr[len] != 17) {
- ArgError("return value overflowed string");
+ rb_raise(rb_eArgError, "return value overflowed string");
}
return INT2NUM(retval);
#else
@@ -2208,7 +2209,7 @@ io_ctl(io, req, arg, io_p)
}
static VALUE
-io_ioctl(argc, argv, io)
+rb_io_ioctl(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2216,11 +2217,11 @@ io_ioctl(argc, argv, io)
VALUE req, arg;
rb_scan_args(argc, argv, "11", &req, &arg);
- return io_ctl(io, req, arg, 1);
+ return rb_io_ctl(io, req, arg, 1);
}
static VALUE
-io_fcntl(argc, argv, io)
+rb_io_fcntl(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2229,14 +2230,14 @@ io_fcntl(argc, argv, io)
VALUE req, arg;
rb_scan_args(argc, argv, "11", &req, &arg);
- return io_ctl(io, req, arg, 0);
+ return rb_io_ctl(io, req, arg, 0);
#else
rb_notimplement();
#endif
}
static VALUE
-f_syscall(argc, argv)
+rb_f_syscall(argc, argv)
int argc;
VALUE *argv;
{
@@ -2257,7 +2258,7 @@ f_syscall(argc, argv)
rb_secure(2);
if (argc == 0)
- ArgError("too few arguments for syscall");
+ rb_raise(rb_eArgError, "too few arguments for syscall");
arg[0] = NUM2INT(argv[0]); argv++;
while (items--) {
if (FIXNUM_P(*argv)) {
@@ -2265,7 +2266,7 @@ f_syscall(argc, argv)
}
else {
Check_Type(*argv, T_STRING);
- str_modify(*argv);
+ rb_str_modify(*argv);
arg[i] = (unsigned long)RSTRING(*argv)->ptr; argv++;
}
i++;
@@ -2333,7 +2334,7 @@ f_syscall(argc, argv)
}
static VALUE
-io_s_pipe()
+rb_io_s_pipe()
{
#ifndef __human68k__
int pipes[2];
@@ -2346,12 +2347,12 @@ io_s_pipe()
#endif
rb_sys_fail(0);
- r = prep_stdio(fdopen(pipes[0], "r"), FMODE_READABLE, cIO);
- w = prep_stdio(fdopen(pipes[1], "w"), FMODE_WRITABLE, cIO);
+ r = prep_stdio(fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO);
+ w = prep_stdio(fdopen(pipes[1], "w"), FMODE_WRITABLE, rb_cIO);
- ary = ary_new2(2);
- ary_push(ary, r);
- ary_push(ary, w);
+ ary = rb_ary_new2(2);
+ rb_ary_push(ary, r);
+ rb_ary_push(ary, w);
return ary;
#else
@@ -2366,19 +2367,19 @@ struct foreach_arg {
};
static VALUE
-io_foreach_line(arg)
+rb_io_foreach_line(arg)
struct foreach_arg *arg;
{
VALUE str;
- while (!NIL_P(str = io_gets_method(arg->argc, &arg->sep, arg->io))) {
+ while (!NIL_P(str = rb_io_gets_method(arg->argc, &arg->sep, arg->io))) {
rb_yield(str);
}
return Qnil;
}
static VALUE
-io_s_foreach(argc, argv, io)
+rb_io_s_foreach(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2390,26 +2391,26 @@ io_s_foreach(argc, argv, io)
Check_SafeStr(fname);
arg.argc = argc - 1;
- arg.io = io_open(RSTRING(fname)->ptr, "r");
- return rb_ensure(io_foreach_line, (VALUE)&arg, io_close, arg.io);
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ return rb_ensure(rb_io_foreach_line, (VALUE)&arg, rb_io_close, arg.io);
}
static VALUE
-io_readline_line(arg)
+rb_io_readline_line(arg)
struct foreach_arg *arg;
{
VALUE line, ary;
- ary = ary_new();
- while (!NIL_P(line = io_gets_method(arg->argc, &arg->sep, arg->io))) {
- ary_push(ary, line);
+ ary = rb_ary_new();
+ while (!NIL_P(line = rb_io_gets_method(arg->argc, &arg->sep, arg->io))) {
+ rb_ary_push(ary, line);
}
return ary;
}
static VALUE
-io_s_readlines(argc, argv, io)
+rb_io_s_readlines(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2421,14 +2422,14 @@ io_s_readlines(argc, argv, io)
Check_SafeStr(fname);
arg.argc = argc - 1;
- arg.io = io_open(RSTRING(fname)->ptr, "r");
- return rb_ensure(io_readline_line, (VALUE)&arg, io_close, arg.io);
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ return rb_ensure(rb_io_readline_line, (VALUE)&arg, rb_io_close, arg.io);
}
static VALUE
arg_fileno()
{
- return io_fileno(file);
+ return rb_io_fileno(file);
}
static VALUE
@@ -2450,15 +2451,15 @@ arg_read(argc, argv)
retry:
if (!next_argv()) return str;
- tmp = io_read(argc, argv, file);
+ tmp = rb_io_read(argc, argv, file);
if (NIL_P(tmp) && next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
goto retry;
}
if (NIL_P(tmp)) return str;
else if (NIL_P(str)) str = tmp;
- else str_cat(str, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
+ else rb_str_cat(str, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
if (argc == 0) {
goto retry;
}
@@ -2478,9 +2479,9 @@ arg_getc()
retry:
if (!next_argv()) return Qnil;
- byte = io_getc(file);
+ byte = rb_io_getc(file);
if (NIL_P(byte) && next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
goto retry;
}
@@ -2491,10 +2492,10 @@ arg_getc()
static VALUE
arg_readchar()
{
- VALUE c = io_getc(file);
+ VALUE c = rb_io_getc(file);
if (NIL_P(c)) {
- eof_error();
+ rb_eof_error();
}
return c;
}
@@ -2506,7 +2507,7 @@ arg_each_line(argc, argv)
{
VALUE str;
- while (RTEST(str = f_gets_method(argc, argv))) {
+ while (RTEST(str = rb_f_gets_method(argc, argv))) {
rb_yield(str);
}
return Qnil;
@@ -2539,7 +2540,7 @@ static VALUE
arg_skip()
{
if (next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
}
return argf;
@@ -2548,7 +2549,7 @@ arg_skip()
static VALUE
arg_close()
{
- io_close(file);
+ rb_io_close(file);
if (next_p != -1) {
next_p = 1;
}
@@ -2559,14 +2560,14 @@ arg_close()
static VALUE
arg_closed()
{
- return io_closed(file);
+ return rb_io_closed(file);
}
static VALUE
opt_i_get()
{
- if (!inplace) return Qnil;
- return str_new2(inplace);
+ if (!ruby_inplace_mode) return Qnil;
+ return rb_str_new2(ruby_inplace_mode);
}
static void
@@ -2574,140 +2575,140 @@ opt_i_set(val)
VALUE val;
{
if (!RTEST(val)) {
- inplace = 0;
+ ruby_inplace_mode = 0;
return;
}
- inplace = STR2CSTR(val);
+ ruby_inplace_mode = STR2CSTR(val);
}
void
Init_IO()
{
- eIOError = rb_define_class("IOError", eStandardError);
- eEOFError = rb_define_class("EOFError", eIOError);
+ rb_eIOError = rb_define_class("IOError", rb_eStandardError);
+ rb_eEOFError = rb_define_class("EOFError", rb_eIOError);
id_write = rb_intern("write");
- rb_define_global_function("syscall", f_syscall, -1);
-
- rb_define_global_function("open", f_open, -1);
- rb_define_global_function("printf", f_printf, -1);
- rb_define_global_function("print", f_print, -1);
- rb_define_global_function("putc", f_putc, 1);
- rb_define_global_function("puts", f_puts, -1);
- rb_define_global_function("gets", f_gets_method, -1);
- rb_define_global_function("readline", f_readline, -1);
- rb_define_global_function("tell", f_tell, 0);
- rb_define_global_function("seek", f_seek, 2);
- rb_define_global_function("rewind", f_rewind, 0);
- rb_define_global_function("eof", f_eof, 0);
- rb_define_global_function("eof?", f_eof, 0);
- rb_define_global_function("getc", f_getc, 0);
- rb_define_global_function("readchar", f_readchar, 0);
- rb_define_global_function("select", f_select, -1);
- rb_define_global_function("ungetc", f_ungetc, 1);
-
- rb_define_global_function("readlines", f_readlines, -1);
-
- rb_define_global_function("`", f_backquote, 1);
- rb_define_global_function("pipe", io_s_pipe, 0);
-
- rb_define_global_function("p", f_p, -1);
- rb_define_method(mKernel, "display", obj_display, -1);
-
- cIO = rb_define_class("IO", cObject);
- rb_include_module(cIO, mEnumerable);
-
- rb_define_singleton_method(cIO, "new", io_s_new, -1);
- rb_define_singleton_method(cIO, "popen", io_s_popen, -1);
- rb_define_singleton_method(cIO, "foreach", io_s_foreach, -1);
- rb_define_singleton_method(cIO, "readlines", io_s_readlines, -1);
- rb_define_singleton_method(cIO, "select", f_select, -1);
-
- FS = OFS = Qnil;
- rb_define_hooked_variable("$;", &FS, 0, rb_str_setter);
- rb_define_hooked_variable("$-F", &FS, 0, rb_str_setter);
- rb_define_hooked_variable("$,", &OFS, 0, rb_str_setter);
-
- RS = RS_default = str_new2("\n"); ORS = Qnil;
- rb_global_variable(&RS_default);
- str_freeze(RS_default); /* avoid modifying RS_default */
- rb_define_hooked_variable("$/", &RS, 0, rb_str_setter);
- rb_define_hooked_variable("$-0", &RS, 0, rb_str_setter);
- rb_define_hooked_variable("$\\", &ORS, 0, rb_str_setter);
+ rb_define_global_function("syscall", rb_f_syscall, -1);
+
+ rb_define_global_function("open", rb_f_open, -1);
+ rb_define_global_function("printf", rb_rb_f_printf, -1);
+ rb_define_global_function("print", rb_f_print, -1);
+ rb_define_global_function("putc", rb_f_putc, 1);
+ rb_define_global_function("puts", rb_f_puts, -1);
+ rb_define_global_function("gets", rb_f_gets_method, -1);
+ rb_define_global_function("readline", rb_f_readline, -1);
+ rb_define_global_function("tell", rb_f_tell, 0);
+ rb_define_global_function("seek", rb_f_seek, 2);
+ rb_define_global_function("rewind", rb_f_rewind, 0);
+ rb_define_global_function("eof", rb_f_eof, 0);
+ rb_define_global_function("eof?", rb_f_eof, 0);
+ rb_define_global_function("getc", rb_f_getc, 0);
+ rb_define_global_function("readchar", rb_f_readchar, 0);
+ rb_define_global_function("select", rb_f_select, -1);
+ rb_define_global_function("ungetc", rb_f_ungetc, 1);
+
+ rb_define_global_function("readlines", rb_f_readlines, -1);
+
+ rb_define_global_function("`", rb_f_backquote, 1);
+ rb_define_global_function("pipe", rb_io_s_pipe, 0);
+
+ rb_define_global_function("p", rb_f_p, -1);
+ rb_define_method(rb_mKernel, "display", rb_obj_display, -1);
+
+ rb_cIO = rb_define_class("IO", rb_cObject);
+ rb_include_module(rb_cIO, rb_mEnumerable);
+
+ rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
+ rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
+ rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
+ rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1);
+ rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
+
+ rb_fs = rb_output_fs = Qnil;
+ rb_define_hooked_variable("$;", &rb_fs, 0, rb_str_setter);
+ rb_define_hooked_variable("$-F", &rb_fs, 0, rb_str_setter);
+ rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_str_setter);
+
+ rb_rs = rb_default_rs = rb_str_new2("\n"); rb_output_rs = Qnil;
+ rb_global_variable(&rb_default_rs);
+ rb_str_freeze(rb_default_rs); /* avoid modifying RS_default */
+ rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
+ rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
+ rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);
rb_define_hooked_variable("$.", &lineno, 0, lineno_setter);
- rb_define_virtual_variable("$_", lastline_get, lastline_set);
-
- rb_define_method(cIO, "clone", io_clone, 0);
- rb_define_method(cIO, "reopen", io_reopen, 1);
-
- rb_define_method(cIO, "print", io_print, -1);
- rb_define_method(cIO, "putc", io_putc, 1);
- rb_define_method(cIO, "puts", io_puts, -1);
- rb_define_method(cIO, "printf", io_printf, -1);
-
- rb_define_method(cIO, "each", io_each_line, -1);
- rb_define_method(cIO, "each_line", io_each_line, -1);
- rb_define_method(cIO, "each_byte", io_each_byte, 0);
-
- rb_define_method(cIO, "syswrite", io_syswrite, 1);
- rb_define_method(cIO, "sysread", io_sysread, 1);
-
- rb_define_method(cIO, "fileno", io_fileno, 0);
- rb_define_alias(cIO, "to_i", "fileno");
- rb_define_method(cIO, "to_io", io_to_io, 0);
-
- rb_define_method(cIO, "sync", io_sync, 0);
- rb_define_method(cIO, "sync=", io_set_sync, 1);
-
- rb_define_method(cIO, "lineno", io_lineno, 0);
- rb_define_method(cIO, "lineno=", io_set_lineno, 1);
-
- rb_define_method(cIO, "readlines", io_readlines, -1);
-
- rb_define_method(cIO, "read", io_read, -1);
- rb_define_method(cIO, "write", io_write, 1);
- rb_define_method(cIO, "gets", io_gets_method, -1);
- rb_define_method(cIO, "readline", io_readline, -1);
- rb_define_method(cIO, "getc", io_getc, 0);
- rb_define_method(cIO, "readchar", io_readchar, 0);
- rb_define_method(cIO, "ungetc",io_ungetc, 1);
- rb_define_method(cIO, "<<", io_addstr, 1);
- rb_define_method(cIO, "flush", io_flush, 0);
- rb_define_method(cIO, "tell", io_tell, 0);
- rb_define_method(cIO, "seek", io_seek, 2);
- rb_define_method(cIO, "rewind", io_rewind, 0);
- rb_define_method(cIO, "pos", io_tell, 0);
- rb_define_method(cIO, "pos=", io_set_pos, 1);
- rb_define_method(cIO, "eof", io_eof, 0);
- rb_define_method(cIO, "eof?", io_eof, 0);
-
- rb_define_method(cIO, "close", io_close_method, 0);
- rb_define_method(cIO, "closed?", io_closed, 0);
-
- rb_define_method(cIO, "isatty", io_isatty, 0);
- rb_define_method(cIO, "tty?", io_isatty, 0);
- rb_define_method(cIO, "binmode", io_binmode, 0);
-
- rb_define_method(cIO, "ioctl", io_ioctl, -1);
- rb_define_method(cIO, "fcntl", io_fcntl, -1);
-
- rb_stdin = prep_stdio(stdin, FMODE_READABLE, cIO);
- rb_define_hooked_variable("$stdin", &rb_stdin, 0, io_stdio_set);
- rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, cIO);
- rb_define_hooked_variable("$stdout", &rb_stdout, 0, io_stdio_set);
- rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, cIO);
- rb_define_hooked_variable("$stderr", &rb_stderr, 0, io_stdio_set);
+ rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
+
+ rb_define_method(rb_cIO, "clone", rb_io_clone, 0);
+ rb_define_method(rb_cIO, "reopen", rb_io_reopen, 1);
+
+ rb_define_method(rb_cIO, "print", rb_io_print, -1);
+ rb_define_method(rb_cIO, "putc", rb_io_putc, 1);
+ rb_define_method(rb_cIO, "puts", rb_io_puts, -1);
+ rb_define_method(rb_cIO, "printf", rb_io_printf, -1);
+
+ rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
+ rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
+ rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
+
+ rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
+ rb_define_method(rb_cIO, "sysread", rb_io_sysread, 1);
+
+ rb_define_method(rb_cIO, "fileno", rb_io_fileno, 0);
+ rb_define_alias(rb_cIO, "to_i", "fileno");
+ rb_define_method(rb_cIO, "to_io", rb_io_to_io, 0);
+
+ rb_define_method(rb_cIO, "sync", rb_io_sync, 0);
+ rb_define_method(rb_cIO, "sync=", rb_io_set_sync, 1);
+
+ rb_define_method(rb_cIO, "lineno", rb_io_lineno, 0);
+ rb_define_method(rb_cIO, "lineno=", rb_io_set_lineno, 1);
+
+ rb_define_method(rb_cIO, "readlines", rb_io_readlines, -1);
+
+ rb_define_method(rb_cIO, "read", rb_io_read, -1);
+ rb_define_method(rb_cIO, "write", rb_io_write, 1);
+ rb_define_method(rb_cIO, "gets", rb_io_gets_method, -1);
+ rb_define_method(rb_cIO, "readline", rb_io_readline, -1);
+ rb_define_method(rb_cIO, "getc", rb_io_getc, 0);
+ rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0);
+ rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
+ rb_define_method(rb_cIO, "<<", rb_io_addstr, 1);
+ rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
+ rb_define_method(rb_cIO, "tell", rb_io_tell, 0);
+ rb_define_method(rb_cIO, "seek", rb_io_seek, 2);
+ rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
+ rb_define_method(rb_cIO, "pos", rb_io_tell, 0);
+ rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
+ rb_define_method(rb_cIO, "eof", rb_io_eof, 0);
+ rb_define_method(rb_cIO, "eof?", rb_io_eof, 0);
+
+ rb_define_method(rb_cIO, "close", rb_io_close, 0);
+ rb_define_method(rb_cIO, "closed?", rb_io_closed, 0);
+
+ rb_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
+ rb_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
+ rb_define_method(rb_cIO, "binmode", rb_io_binmode, 0);
+
+ rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
+ rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
+
+ rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
+ rb_define_hooked_variable("$stdin", &rb_stdin, 0, rb_io_stdio_set);
+ rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO);
+ rb_define_hooked_variable("$stdout", &rb_stdout, 0, rb_io_stdio_set);
+ rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO);
+ rb_define_hooked_variable("$stderr", &rb_stderr, 0, rb_io_stdio_set);
rb_defout = rb_stdout;
- rb_define_hooked_variable("$>", &rb_defout, 0, io_defset);
+ rb_define_hooked_variable("$>", &rb_defout, 0, rb_io_defset);
rb_define_global_const("STDIN", rb_stdin);
rb_define_global_const("STDOUT", rb_stdout);
rb_define_global_const("STDERR", rb_stderr);
- argf = obj_alloc(cObject);
- rb_extend_object(argf, mEnumerable);
+ argf = rb_obj_alloc(rb_cObject);
+ rb_extend_object(argf, rb_mEnumerable);
rb_define_readonly_variable("$<", &argf);
rb_define_global_const("ARGF", argf);
@@ -2720,20 +2721,20 @@ Init_IO()
rb_define_singleton_method(argf, "each_byte", arg_each_byte, 0);
rb_define_singleton_method(argf, "read", arg_read, -1);
- rb_define_singleton_method(argf, "readlines", f_readlines, -1);
- rb_define_singleton_method(argf, "to_a", f_readlines, -1);
- rb_define_singleton_method(argf, "gets", f_gets_method, -1);
- rb_define_singleton_method(argf, "readline", f_readline, -1);
+ rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
+ rb_define_singleton_method(argf, "to_a", rb_f_readlines, -1);
+ rb_define_singleton_method(argf, "gets", rb_f_gets_method, -1);
+ rb_define_singleton_method(argf, "readline", rb_f_readline, -1);
rb_define_singleton_method(argf, "getc", arg_getc, 0);
rb_define_singleton_method(argf, "readchar", arg_readchar, 0);
- rb_define_singleton_method(argf, "tell", f_tell, 0);
- rb_define_singleton_method(argf, "seek", f_seek, 2);
- rb_define_singleton_method(argf, "rewind", f_rewind, 0);
- rb_define_singleton_method(argf, "pos", f_tell, 0);
- rb_define_singleton_method(argf, "pos=", f_set_pos, 1);
- rb_define_singleton_method(argf, "eof", f_eof, 0);
- rb_define_singleton_method(argf, "eof?", f_eof, 0);
- rb_define_singleton_method(argf, "ungetc", f_ungetc, 1);
+ rb_define_singleton_method(argf, "tell", rb_f_tell, 0);
+ rb_define_singleton_method(argf, "seek", rb_f_seek, 2);
+ rb_define_singleton_method(argf, "rewind", rb_f_rewind, 0);
+ rb_define_singleton_method(argf, "pos", rb_f_tell, 0);
+ rb_define_singleton_method(argf, "pos=", rb_f_set_pos, 1);
+ rb_define_singleton_method(argf, "eof", rb_f_eof, 0);
+ rb_define_singleton_method(argf, "eof?", rb_f_eof, 0);
+ rb_define_singleton_method(argf, "ungetc", rb_f_ungetc, 1);
rb_define_singleton_method(argf, "to_s", arg_filename, 0);
rb_define_singleton_method(argf, "filename", arg_filename, 0);
@@ -2742,7 +2743,7 @@ Init_IO()
rb_define_singleton_method(argf, "close", arg_close, 0);
rb_define_singleton_method(argf, "closed?", arg_closed, 0);
- filename = str_new2("-");
+ filename = rb_str_new2("-");
rb_define_readonly_variable("$FILENAME", &filename);
file = rb_stdin;
rb_global_variable(&file);