diff -au ruby-0.55/array.c ruby/array.c --- ruby-0.55/array.c Tue Nov 1 17:27:44 1994 +++ ruby/array.c Tue Nov 22 10:22:30 1994 @@ -3,7 +3,7 @@ array.c - $Author: matz $ - $Date: 1994/11/01 08:27:44 $ + $Date: 1994/11/22 01:22:30 $ created at: Fri Aug 6 09:46:12 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -856,6 +856,76 @@ return INT2FIX(h); } +static int +ary_contains(ary, item) + struct RArray *ary; + VALUE item; +{ + int i; + for (i=0; ilen; i++) { + if (rb_funcall(ary->ptr[i], eq, 1, item)) { + return 1; + } + } + return 0; +} + +static VALUE +Fary_diff(ary1, ary2) + struct RArray *ary1, *ary2; +{ + VALUE ary3; + int i, j; + + Check_Type(ary2, T_ARRAY); + ary3 = ary_new(); + for (i=0; ilen; i++) { + if (ary_contains(ary2, ary1->ptr[i])) continue; + if (ary_contains(ary3, ary1->ptr[i])) continue; + Fary_push(ary3, ary1->ptr[i]); + } + return ary3; +} + +static VALUE +Fary_and(ary1, ary2) + struct RArray *ary1, *ary2; +{ + VALUE ary3; + int i, j; + + Check_Type(ary2, T_ARRAY); + ary3 = ary_new(); + for (i=0; ilen; i++) { + if (ary_contains(ary2, ary1->ptr[i]) + && !ary_contains(ary3, ary1->ptr[i])) { + Fary_push(ary3, ary1->ptr[i]); + } + } + return ary3; +} + +static VALUE +Fary_or(ary1, ary2) + struct RArray *ary1, *ary2; +{ + VALUE ary3; + int i; + + if (TYPE(ary2) != T_ARRAY) return Fary_plus(ary1, ary2); + + ary3 = ary_new(); + for (i=0; ilen; i++) { + if (!ary_contains(ary3, ary1->ptr[i])) + Fary_push(ary3, ary1->ptr[i]); + } + for (i=0; ilen; i++) { + if (!ary_contains(ary3, ary2->ptr[i])) + Fary_push(ary3, ary2->ptr[i]); + } + return ary3; +} + extern VALUE C_Kernel; extern VALUE M_Enumerable; @@ -900,6 +970,10 @@ rb_define_method(C_Array, "+", Fary_plus, 1); rb_define_method(C_Array, "*", Fary_times, 1); + + rb_define_method(C_Array, "-", Fary_diff, 1); + rb_define_method(C_Array, "&", Fary_and, 1); + rb_define_method(C_Array, "|", Fary_or, 1); cmp = rb_intern("<=>"); eq = rb_intern("=="); diff -au ruby-0.55/defines.h ruby/defines.h --- ruby-0.55/defines.h Sat Nov 12 00:56:24 1994 +++ ruby/defines.h Fri Nov 18 10:37:26 1994 @@ -3,7 +3,7 @@ defines.h - $Author: matz $ - $Date: 1994/08/12 04:47:11 $ + $Date: 1994/11/18 01:37:26 $ created at: Wed May 18 00:21:44 JST 1994 ************************************************/ diff -au ruby-0.55/dln.c ruby/dln.c --- ruby-0.55/dln.c Mon Nov 14 11:34:58 1994 +++ ruby/dln.c Fri Nov 18 10:37:28 1994 @@ -3,7 +3,7 @@ dln.c - $Author: matz $ - $Date: 1994/10/14 06:19:13 $ + $Date: 1994/11/18 01:37:28 $ created at: Tue Jan 18 17:05:06 JST 1994 Copyright (C) 1994 Yukihiro Matsumoto diff -au ruby-0.55/error.c ruby/error.c --- ruby-0.55/error.c Tue Nov 1 17:27:52 1994 +++ ruby/error.c Tue Nov 22 10:22:31 1994 @@ -3,7 +3,7 @@ error.c - $Author: matz $ - $Date: 1994/11/01 08:27:52 $ + $Date: 1994/11/22 01:22:31 $ created at: Mon Aug 9 16:11:34 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -140,9 +140,9 @@ extern int errno; if (mesg == Qnil) - sprintf(buf, "%s.\n", strerror(errno)); + sprintf(buf, "%s\n", strerror(errno)); else - sprintf(buf, "%s - %s.\n", strerror(errno), mesg); + sprintf(buf, "%s - %s\n", strerror(errno), mesg); errno = 0; rb_fail(str_new2(buf)); diff -au ruby-0.55/eval.c ruby/eval.c --- ruby-0.55/eval.c Fri Nov 11 00:14:12 1994 +++ ruby/eval.c Tue Nov 22 10:22:33 1994 @@ -3,7 +3,7 @@ eval.c - $Author: matz $ - $Date: 1994/11/01 08:27:55 $ + $Date: 1994/11/22 01:22:33 $ created at: Thu Jun 10 14:22:17 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -2097,13 +2097,15 @@ Init_load() { - extern VALUE rb_check_str(); char *path; - rb_define_variable("$LOAD_PATH", &rb_load_path, Qnil, rb_check_str); rb_load_path = ary_new(); - rb_define_variable("$LOAD_FILES", &rb_load_path, Qnil, rb_readonly_hook); + rb_define_variable("$:", &rb_load_path, Qnil, rb_readonly_hook); + rb_define_variable("$LOAD_PATH", &rb_load_path, Qnil, rb_readonly_hook); + rb_loadfiles = ary_new(); + rb_define_variable("$\"", &rb_load_path, Qnil, rb_readonly_hook); + rb_define_variable("$LOAD_FILES", &rb_load_path, Qnil, rb_readonly_hook); addpath(getenv("RUBYLIB")); addpath(RUBY_LIB); diff -au ruby-0.55/file.c ruby/file.c --- ruby-0.55/file.c Fri Nov 18 00:20:00 1994 +++ ruby/file.c Tue Nov 22 10:22:34 1994 @@ -4,7 +4,7 @@ file.c - $Author: matz $ - $Date: 1994/11/01 08:27:57 $ + $Date: 1994/11/22 01:22:34 $ created at: Mon Nov 15 12:24:34 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -69,19 +69,29 @@ path = args->ptr[i]; if (TYPE(path) == T_STRING) { if (gl) { - char *p; + char buf[MAXPATHLEN]; + char *p, *s; + + s = buf; p = RSTRING(path)->ptr; while (*p) { - switch (*p++) { + switch (*s = *p++) { case '*': case '?': - case '[': case ']': - case '{': case '}': + case '[': case '{': path = glob_new(path); goto glob; + case '\\': + if (*p == '\0') break; + *s = *p++; } + s++; } + *s = '\0'; + (*func)(buf, arg); + } + else { + (*func)(RSTRING(path)->ptr, arg); } - (*func)(path, arg); n++; } else { @@ -819,11 +829,11 @@ static void chmod_internal(path, mode) - struct RString *path; + char *path; int mode; { - if (chmod(path->ptr, mode) == -1) - rb_sys_fail(RSTRING(path)->ptr); + if (chmod(path, mode) == -1) + rb_sys_fail(path); } static VALUE @@ -864,11 +874,11 @@ static void chown_internal(path, args) - struct RString *path; + char *path; struct chown_args *args; { - if (chown(path->ptr, args->owner, args->group) < 0) - rb_sys_fail(path->ptr); + if (chown(path, args->owner, args->group) < 0) + rb_sys_fail(path); } static VALUE @@ -914,11 +924,11 @@ static void utime_internal(path, tvp) - struct RString *path; + char *path; struct timeval tvp[]; { - if (utimes(path->ptr, tvp) < 0) - rb_sys_fail(path->ptr); + if (utimes(path, tvp) < 0) + rb_sys_fail(path); } static VALUE @@ -981,10 +991,10 @@ static void unlink_internal(path) - struct RString *path; + char *path; { - if (unlink(path->ptr) < 0) - rb_sys_fail(path->ptr); + if (unlink(path) < 0) + rb_sys_fail(path); } static VALUE diff -au ruby-0.55/glob.c ruby/glob.c --- ruby-0.55/glob.c Thu Nov 17 23:59:17 1994 +++ ruby/glob.c Sat Nov 19 12:13:44 1994 @@ -131,11 +131,18 @@ rb_yield(str_new2(*patv)); continue; } - fnames = ff = glob_filename(*patv); - while (*ff) { - rb_yield(str_new2(*ff)); - free(*ff); - ff++; + fnames = glob_filename(*patv); + if (fnames == (char**)-1) rb_sys_fail(*patv); + if (fnames[0] == Qnil) { + rb_yield(str_new2(*patv)); + } + else { + ff = fnames; + while (*ff) { + rb_yield(str_new2(*ff)); + free(*ff); + ff++; + } } free(fnames); } diff -au ruby-0.55/gnuglob.c ruby/gnuglob.c --- ruby-0.55/gnuglob.c Sat Nov 12 00:59:23 1994 +++ ruby/gnuglob.c Sat Nov 19 11:59:42 1994 @@ -105,8 +105,8 @@ # endif /* !SHELL */ #endif /* OPENDIR_NOT_ROBUST */ +extern void *xmalloc (), *xrealloc (); #if !defined (HAVE_STDLIB_H) -extern char *malloc (), *realloc (); extern void free (); #endif /* !HAVE_STDLIB_H */ @@ -243,7 +243,7 @@ { nextlink = (struct globval *)alloca (sizeof (struct globval)); nextlink->next = lastlink; - nextname = (char *) malloc (1); + nextname = (char *) xmalloc (1); if (!nextname) lose = 1; else @@ -291,7 +291,7 @@ { nextlink = (struct globval *) alloca (sizeof (struct globval)); nextlink->next = lastlink; - nextname = (char *) malloc (D_NAMLEN (dp) + 1); + nextname = (char *) xmalloc (D_NAMLEN (dp) + 1); if (nextname == NULL) { lose = 1; @@ -307,7 +307,7 @@ if (!lose) { - name_vector = (char **) malloc ((count + 1) * sizeof (char *)); + name_vector = (char **) xmalloc ((count + 1) * sizeof (char *)); lose |= name_vector == NULL; } @@ -361,13 +361,13 @@ while (array[i] != NULL) ++i; - result = (char **) malloc ((i + 1) * sizeof (char *)); + result = (char **) xmalloc ((i + 1) * sizeof (char *)); if (result == NULL) return (NULL); for (i = 0; array[i] != NULL; i++) { - result[i] = (char *) malloc (l + (add_slash ? 1 : 0) + result[i] = (char *) xmalloc (l + (add_slash ? 1 : 0) + strlen (array[i]) + 1); if (result[i] == NULL) return (NULL); @@ -399,7 +399,7 @@ char *directory_name, *filename; unsigned int directory_len; - result = (char **) malloc (sizeof (char *)); + result = (char **) xmalloc (sizeof (char *)); result_size = 1; if (result == NULL) return (NULL); @@ -475,7 +475,7 @@ ++l; result = - (char **)realloc (result, (result_size + l) * sizeof (char *)); + (char **)xrealloc(result, (result_size + l) * sizeof (char *)); if (result == NULL) goto memory_error; @@ -501,10 +501,10 @@ /* If there is only a directory name, return it. */ if (*filename == '\0') { - result = (char **) realloc ((char *) result, 2 * sizeof (char *)); + result = (char **) xrealloc ((char *) result, 2 * sizeof (char *)); if (result == NULL) return (NULL); - result[0] = (char *) malloc (directory_len + 1); + result[0] = (char *) xmalloc (directory_len + 1); if (result[0] == NULL) goto memory_error; bcopy (directory_name, result[0], directory_len + 1); diff -au ruby-0.55/io.c ruby/io.c --- ruby-0.55/io.c Thu Nov 17 23:32:24 1994 +++ ruby/io.c Tue Nov 22 10:22:36 1994 @@ -3,7 +3,7 @@ io.c - $Author: matz $ - $Date: 1994/11/01 08:28:01 $ + $Date: 1994/11/22 01:22:36 $ created at: Fri Oct 15 18:08:59 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -616,6 +616,20 @@ } static VALUE +io_open(fname, mode) + char *fname, *mode; +{ + int pipe = 0; + + if (fname[0] == '|') { + return pipe_open(fname+1, mode); + } + else { + return file_open(fname, mode); + } +} + +static VALUE Fopen(self, args) VALUE self, args; { @@ -635,15 +649,7 @@ Fail("illegal access mode"); mode = RSTRING(pmode)->ptr; } - - if (RSTRING(pname)->ptr[0] == '|') { - port = pipe_open(RSTRING(pname)->ptr+1, mode); - } - else { - port = file_open(RSTRING(pname)->ptr, mode); - } - - return port; + return io_open(RSTRING(pname)->ptr, mode); } static VALUE @@ -698,6 +704,19 @@ } static VALUE +io_defset(obj, val) + VALUE obj, val; +{ + if (TYPE(val) == T_STRING) { + val = io_open(RSTRING(val)->ptr, "w"); + } + if (!obj_is_kind_of(val, C_IO)) { + Fail("$< must be a file, %s given", rb_class2name(CLASS_OF(val))); + } + return rb_defout = val; +} + +static VALUE Fprint_on(obj, port) VALUE obj, port; { @@ -1073,7 +1092,7 @@ } arg->ptr[len] = 17; fd = fileno(fptr->f); - if (io_p?ioctl(fd, cmd, arg->ptr):fcntl(fd, cmd, arg->ptr)<0) { + if ((io_p?ioctl(fd, cmd, arg->ptr):fcntl(fd, cmd, arg->ptr))<0) { rb_sys_fail(fptr->path); } if (arg->ptr[len] != 17) { @@ -1091,20 +1110,6 @@ } static VALUE -Fio_defget(obj) - VALUE obj; -{ - return rb_defout; -} - -static VALUE -Fio_defset(obj, val) - VALUE obj, val; -{ - return rb_defout = val; -} - -static VALUE Fsyscall(argc, argv) int argc; VALUE *argv; @@ -1302,6 +1307,7 @@ 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); @@ -1346,9 +1352,7 @@ rb_stderr = prep_stdio(stderr, FMODE_WRITABLE); rb_define_variable("$stderr", &rb_stderr, Qnil, rb_readonly_hook); rb_defout = rb_stdout; - rb_global_variable(&rb_defout); - rb_define_single_method(C_IO, "default", Fio_defget, 0); - rb_define_single_method(C_IO, "default=", Fio_defset, 1); + rb_define_variable("$>", &rb_defout, Qnil, io_defset); argf = obj_alloc(C_Object); rb_define_variable("$ARGF", &argf, Qnil, rb_readonly_hook); @@ -1359,7 +1363,7 @@ rb_define_single_method(argf, "read", Farg_read, 0); rb_define_single_method(argf, "readlines", Freadlines, 0); rb_define_single_method(argf, "gets", Fgets, 0); - rb_define_single_method(argf, "realine", Fgets, 0); + rb_define_single_method(argf, "readline", Fgets, 0); rb_define_single_method(argf, "getc", Farg_getc, 0); rb_define_single_method(argf, "eof", Feof, 0); Common subdirectories: ruby-0.55/missing and ruby/missing diff -au ruby-0.55/parse.y ruby/parse.y --- ruby-0.55/parse.y Tue Nov 1 17:28:09 1994 +++ ruby/parse.y Tue Nov 22 10:22:38 1994 @@ -3,7 +3,7 @@ parse.y - $Author: matz $ - $Date: 1994/11/01 08:28:09 $ + $Date: 1994/11/22 01:22:38 $ created at: Fri May 28 18:02:42 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -1855,6 +1855,10 @@ case '+': /* $&: string matches last paren. */ case '~': /* $~: match-data */ case '=': /* $=: ignorecase */ + case ':': /* $:: load path */ + case '<': /* $<: reading filename */ + case '>': /* $>: default output handle */ + case '"': /* $": already loaded files */ tokadd(c); tokadd('\0'); goto id_fetch; diff -au ruby-0.55/ruby.1 ruby/ruby.1 --- ruby-0.55/ruby.1 Fri Nov 18 00:24:37 1994 +++ ruby/ruby.1 Tue Nov 22 10:22:40 1994 @@ -1,6 +1,6 @@ .\"ruby.1 - -*- Nroff -*- .\" $Author: matz $ -.\" $Date: 1994/10/14 06:19:42 $ +.\" $Date: 1994/11/22 01:22:40 $ .\" created at: Tue Apr 12 01:45:04 JST 1994 .TH RUBY 1 "\*(RP" .UC @@ -134,7 +134,7 @@ 例: .ne 2 - % echo matz | ruby \-p \-e '$_\.tr("a-z", "A-Z")' + % echo matz | ruby \-p \-e '$_\.tr "a-z", "A-Z"' MATZ .fi @@ -181,7 +181,7 @@ 表示例: .ne 2 - ruby - version 0.51 (05 Sep 94) + ruby - version 0.56 (94/11/19) .fi .TP 5 Common subdirectories: ruby-0.55/sample and ruby/sample diff -au ruby-0.55/spec ruby/spec --- ruby-0.55/spec Fri Nov 18 10:23:40 1994 +++ ruby/spec Tue Nov 22 10:22:41 1994 @@ -1082,6 +1082,12 @@ $& 最後に成功したパターンマッチ + $` 最後のパターンマッチでマッチした文字列の前の文字列 + + $' 最後のパターンマッチでマッチした文字列の後に続く文字列 + + $+ 最後の検索パターンでマッチした最後の括弧 + $1..$9 最後に成功したパターンマッチでn番目の括弧にマッチした 値が格納される. 該当する括弧がなければnilが入っている. @@ -1109,6 +1115,12 @@ $. 最後に読んだ入力ファイルの行番号. + $< 仮想ファイル$ARGFで現在読み込み中の(メソッドgets()が今 + 読んでいる)ファイル名.(覚え方: `<'はシェルの入力指定) + + $> printやprintfのデフォルトの出力先. 初期値は$stdout. + (覚え方: `>'はシェルの出力先指定) + $_ 最後にgets()などで読み込んだ文字列. $0 rubyスクリプトの名前. この変数に代入するとps(1)の出力 @@ -1121,19 +1133,25 @@ $? 最後に実行した子プロセスのstatus. + $: ファイルをロードする時に検索するディレクトリへのパスを + 含む配列. 起動時にはデフォルト値(コンパイル時に指定す + る)に加えて, 環境変数RUBYLIBの値とruby起動時の-Iオプショ + ンで指定された値が追加される.(覚え方: コロンは環境変 + 数PATHの区切り文字である) + + $" ロードされたファイル名を含む配列.同じファイルを2回ロー + ドしないために用いられる.(覚え方: prevent files to be + doubly quoted(loaded)) + $ARGV $*と同じ. $ENV 環境変数にアクセスする連想配列. - $FILENAME 仮想ファイル$ARGFで現在読み込み中のファイル名. メソッ - ドgets()が今読んでいるファイル名. + $FILENAME $<と同じ. - $DEBUG `-d'フラグの状態(真偽値) + $DEBUG `-d'フラグの状態(真偽値). - $LOAD_PATH ファイルをロードする時に検索するディレクトリへのパスを - 含む配列. 起動時にはデフォルト値(コンパイル時に指定す - る)に加えて, 環境変数RUBYLIBの値とruby起動時の-Iオプショ - ンで指定された値が追加される. + $LOAD_PATH $:と同じ. $stdin 標準入力 $stdout 標準出力 @@ -1215,6 +1233,21 @@ 配列の繰り返し. + self - other + + 集合の差演算.selfからotherの要素を取り除いた内容の新しい配列 + を返す.重複する要素は1度だけ現れる. + + self * other + + 集合の積演算.両方の配列に含まれる要素からなる新しい配列を返す. + 重複する要素は1度だけ現れる. + + self | other + + 集合の和演算.両方の配列にいずれかに含まれる要素を全て含む新し + い配列を返す.重複する要素は1度だけ現れる. + self << obj objを配列の末尾に追加する. selfを返すのでC++的に連鎖できる. @@ -2361,16 +2394,6 @@ write(str) strを出力する. 出力したバイト数を返す. - -Single Methods: - - default - - printやprintfのデフォルトの出力先を返す. 初期値は$stdout. - - default=(io) - - デフォルトの出力先を指定する. *** Kernel(クラス) diff -au ruby-0.55/string.c ruby/string.c --- ruby-0.55/string.c Fri Nov 11 10:10:30 1994 +++ ruby/string.c Fri Nov 18 10:37:38 1994 @@ -3,7 +3,7 @@ string.c - $Author: matz $ - $Date: 1994/11/01 08:28:38 $ + $Date: 1994/11/18 01:37:38 $ created at: Mon Aug 9 17:12:58 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto diff -au ruby-0.55/version.h ruby/version.h --- ruby-0.55/version.h Fri Nov 18 00:09:46 1994 +++ ruby/version.h Tue Nov 22 10:22:43 1994 @@ -1,2 +1,2 @@ -#define RUBY_VERSION "0.55" -#define VERSION_DATE "94/11/18" +#define RUBY_VERSION "0.56" +#define VERSION_DATE "94/11/22"