From 4dfd93c72a9a221c5575c5888483f2fb55c82117 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 22 Nov 1994 01:22:30 +0900 Subject: version 0.56 https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.55-0.56.diff.gz --- array.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- defines.h | 2 +- dln.c | 2 +- error.c | 6 ++--- eval.c | 10 +++++---- file.c | 46 +++++++++++++++++++++++--------------- glob.c | 17 +++++++++----- gnuglob.c | 20 ++++++++--------- io.c | 62 +++++++++++++++++++++++++++------------------------ parse.y | 6 ++++- ruby.1 | 6 ++--- spec | 57 +++++++++++++++++++++++++++++++++-------------- string.c | 2 +- version.h | 4 ++-- 14 files changed, 220 insertions(+), 96 deletions(-) diff --git a/array.c b/array.c index 1c5e3b5b27..78de801bab 100644 --- a/array.c +++ b/array.c @@ -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 @@ Fary_hash(ary) 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; @@ -901,6 +971,10 @@ Init_Array() 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 --git a/defines.h b/defines.h index 0d600066eb..60e72b89ec 100644 --- a/defines.h +++ b/defines.h @@ -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 --git a/dln.c b/dln.c index ccf74b5a63..861ebfb634 100644 --- a/dln.c +++ b/dln.c @@ -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 --git a/error.c b/error.c index 747fa68623..05463504f8 100644 --- a/error.c +++ b/error.c @@ -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 @@ rb_sys_fail(mesg) 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 --git a/eval.c b/eval.c index 85bc3897f3..84356cf1a0 100644 --- a/eval.c +++ b/eval.c @@ -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 @@ extern VALUE C_Kernel; 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 --git a/file.c b/file.c index 8d4a1e13bf..463965547c 100644 --- a/file.c +++ b/file.c @@ -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 @@ apply2files0(func, args, arg, gl) 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 @@ Ffile_ctime2(obj) 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 @@ struct chown_args { 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 @@ struct timeval *time_timeval(); 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 @@ Ffile_readlink(obj, path) 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 --git a/glob.c b/glob.c index d74aa1ffce..bc4ad8aad0 100644 --- a/glob.c +++ b/glob.c @@ -131,11 +131,18 @@ Fglob_each(glob) 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 --git a/gnuglob.c b/gnuglob.c index 32068e42d9..d3159bbabd 100644 --- a/gnuglob.c +++ b/gnuglob.c @@ -105,8 +105,8 @@ char *alloca (); # 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 @@ glob_vector (pat, dir) { 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 @@ glob_vector (pat, dir) { 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 @@ glob_vector (pat, dir) 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 @@ glob_dir_to_array (dir, array) 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 @@ glob_filename (pathname) 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 @@ glob_filename (pathname) ++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 @@ glob_filename (pathname) /* 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 --git a/io.c b/io.c index 75bc3848e1..979af6aa68 100644 --- a/io.c +++ b/io.c @@ -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 @@ -615,6 +615,20 @@ pipe_open(pname, mode) return port; } +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 @@ Fopen(self, args) 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 @@ -697,6 +703,19 @@ Fprint(argc, argv) return Qnil; } +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 @@ io_ctl(obj, req, arg, io_p) } 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) { @@ -1090,20 +1109,6 @@ Fio_ioctl(obj, req, arg) return obj; } -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; @@ -1302,6 +1307,7 @@ 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); @@ -1346,9 +1352,7 @@ Init_IO() 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 @@ Init_IO() 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); diff --git a/parse.y b/parse.y index 10002fca92..1e3e3a9d5b 100644 --- a/parse.y +++ b/parse.y @@ -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 @@ retry: 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 --git a/ruby.1 b/ruby.1 index d0d8671ef1..5c3df055f0 100644 --- a/ruby.1 +++ b/ruby.1 @@ -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 @@ ruby \- 例: .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 @@ $VERBOSE 表示例: .ne 2 - ruby - version 0.51 (05 Sep 94) + ruby - version 0.56 (94/11/19) .fi .TP 5 diff --git a/spec b/spec index ba592a06fe..6432fc6090 100644 --- a/spec +++ b/spec @@ -1082,6 +1082,12 @@ Ruby $& 最後に成功したパターンマッチ + $` 最後のパターンマッチでマッチした文字列の前の文字列 + + $' 最後のパターンマッチでマッチした文字列の後に続く文字列 + + $+ 最後の検索パターンでマッチした最後の括弧 + $1..$9 最後に成功したパターンマッチでn番目の括弧にマッチした 値が格納される. 該当する括弧がなければnilが入っている. @@ -1109,6 +1115,12 @@ Ruby $. 最後に読んだ入力ファイルの行番号. + $< 仮想ファイル$ARGFで現在読み込み中の(メソッドgets()が今 + 読んでいる)ファイル名.(覚え方: `<'はシェルの入力指定) + + $> printやprintfのデフォルトの出力先. 初期値は$stdout. + (覚え方: `>'はシェルの出力先指定) + $_ 最後にgets()などで読み込んだ文字列. $0 rubyスクリプトの名前. この変数に代入するとps(1)の出力 @@ -1121,19 +1133,25 @@ Ruby $? 最後に実行した子プロセスの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 @@ Methods: 配列の繰り返し. + self - other + + 集合の差演算.selfからotherの要素を取り除いた内容の新しい配列 + を返す.重複する要素は1度だけ現れる. + + self * other + + 集合の積演算.両方の配列に含まれる要素からなる新しい配列を返す. + 重複する要素は1度だけ現れる. + + self | other + + 集合の和演算.両方の配列にいずれかに含まれる要素を全て含む新し + い配列を返す.重複する要素は1度だけ現れる. + self << obj objを配列の末尾に追加する. selfを返すのでC++的に連鎖できる. @@ -2362,16 +2395,6 @@ Methods: strを出力する. 出力したバイト数を返す. -Single Methods: - - default - - printやprintfのデフォルトの出力先を返す. 初期値は$stdout. - - default=(io) - - デフォルトの出力先を指定する. - *** Kernel(クラス) 全てのクラスの基底クラス. Ruby組み込みの全ての関数メソッドはこのクラス diff --git a/string.c b/string.c index 98f1d8efb4..f5b1a64f68 100644 --- a/string.c +++ b/string.c @@ -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 --git a/version.h b/version.h index 8ff9d4fc2b..ee2baeaac9 100644 --- a/version.h +++ b/version.h @@ -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" -- cgit v1.2.3