From 00e36aa09f54925c2f9c30524b48f4f54a9adb23 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 8 Dec 1994 14:17:29 +0900 Subject: version 0.60 https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.60.tar.gz Thu Dec 8 14:17:29 1994 Yukihiro Matsumoto (matz@ix-02) * 0.60 released - alpha test baseline. --- CVS/Entries | 51 -- CVS/Repository | 1 - ChangeLog | 1147 +---------------------- Makefile | 6 - Makefile.in | 175 ++-- ToDo | 5 +- array.c | 77 +- bignum.c | 38 +- bring | 57 -- config.status | 72 -- configure.in | 34 +- dbm.c | 14 +- defines.h | 2 +- dict.c | 27 +- dir.c | 32 +- dln.c | 1 + enum.c | 12 +- etc.c | 4 +- eval.c | 21 +- file.c | 101 ++- fnmatch.c | 1 + gc.c | 30 +- getopt.c | 660 ++++++++++++++ getopt.h | 128 +++ getopt1.c | 162 ++++ gnuglob.c | 2 + io.c | 69 +- missing.c | 67 -- missing/CVS/Entries | 9 - missing/CVS/Repository | 1 - missing/alloca.c | 189 ++++ missing/getopt.c | 662 -------------- missing/getopt.h | 128 --- missing/getopt1.c | 162 ---- missing/strdup.c | 25 + missing/strftime.c | 6 +- newver.rb | 19 - numeric.c | 10 +- object.c | 4 +- pack.c | 42 +- parse.y | 18 +- process.c | 81 +- range.c | 14 +- re.c | 56 +- regex.c | 1 + ruby.c | 12 +- ruby.h | 35 +- sample/Artistic | 117 --- sample/aset.rb | 6 +- sample/attr.rb | 11 +- sample/biorhythm.rb | 201 ----- sample/case.rb | 12 +- sample/cat.rb | 1 + sample/cat2.rb | 1 + sample/cbreak.rb | 2 + sample/clnt.rb | 2 + sample/clone.rb | 6 + sample/const.rb | 4 + sample/dbm.rb | 8 +- sample/dir.rb | 7 +- sample/evaldef.rb | 5 + sample/export.rb | 5 + sample/fib.rb | 2 + sample/freq.rb | 4 +- sample/gctest.rb | 1 + sample/hash.rb | 7 + sample/io.rb | 3 + sample/less.rb | 15 +- sample/list.rb | 42 +- sample/list2.rb | 2 +- sample/list3.rb | 4 +- sample/math.rb | 2 +- sample/mpart.rb | 2 + sample/newver.rb | 13 - sample/occur.rb | 2 + sample/occur2.rb | 2 + sample/opt_s.rb | 4 +- sample/opt_x.rb | 6 +- sample/perror.rb | 7 - sample/rcs.awk | 33 - sample/rcs.dat | 17 - sample/rcs.rb | 46 - sample/reach.rb | 5 - sample/resp.rb | 2 - sample/samp.rb | 3 + sample/sieve.rb | 1 + sample/split.rb | 1 + sample/struct.rb | 4 + sample/svr.rb | 3 + sample/system.rb | 1 + socket.c | 40 +- spec | 2361 ++++++++++++++++++++++++------------------------ sprintf.c | 5 +- st.c | 1 + string.c | 33 +- struct.c | 10 +- time.c | 16 +- version.h | 4 +- 98 files changed, 3057 insertions(+), 4505 deletions(-) delete mode 100644 CVS/Entries delete mode 100644 CVS/Repository delete mode 100644 Makefile delete mode 100644 bring delete mode 100755 config.status create mode 100644 getopt.c create mode 100644 getopt.h create mode 100644 getopt1.c delete mode 100644 missing.c delete mode 100644 missing/CVS/Entries delete mode 100644 missing/CVS/Repository create mode 100644 missing/alloca.c delete mode 100644 missing/getopt.c delete mode 100644 missing/getopt.h delete mode 100644 missing/getopt1.c create mode 100644 missing/strdup.c delete mode 100755 newver.rb delete mode 100644 sample/Artistic delete mode 100644 sample/biorhythm.rb delete mode 100644 sample/newver.rb delete mode 100644 sample/perror.rb delete mode 100644 sample/rcs.awk delete mode 100644 sample/rcs.dat delete mode 100644 sample/rcs.rb delete mode 100644 sample/reach.rb delete mode 100644 sample/resp.rb diff --git a/CVS/Entries b/CVS/Entries deleted file mode 100644 index 067e16dd65..0000000000 --- a/CVS/Entries +++ /dev/null @@ -1,51 +0,0 @@ -/autoexec.c/0.15/Wed Jun 1 23:40:54 1994 Thu Mar 17 18:49:43 1994// -/class.c/0.22/Wed Jun 1 23:40:54 1994 Fri Mar 25 13:12:36 1994// -/compar.c/0.15/Wed Jun 1 23:40:54 1994 Thu Mar 17 18:49:43 1994// -/dln.h/0.14/Wed Jun 1 23:40:57 1994 Thu Mar 17 15:55:00 1994// -/error.c/0.15/Wed Jun 1 23:40:57 1994 Thu Mar 17 18:49:43 1994// -/etc.c/0.22/Wed Jun 1 23:40:58 1994 Fri Mar 25 13:12:36 1994// -/ident.h/0.17/Wed Jun 1 23:41:00 1994 Wed May 25 00:56:16 1994// -/inits.c/0.27/Wed Jun 1 23:41:00 1994 Mon Apr 25 23:30:29 1994// -/io.h/0.14/Wed Jun 1 23:41:01 1994 Thu Mar 17 15:55:00 1994// -/methods.c/0.20/Wed Jun 1 23:41:01 1994 Tue Mar 22 16:58:31 1994// -/missing.c/0.29/Wed Jun 1 23:41:01 1994 Wed Jun 1 23:36:26 1994// -/parse.y/0.35/Wed Jun 1 23:41:08 1994 Wed Jun 1 23:36:30 1994// -/random.c/0.15/Wed Jun 1 23:41:09 1994 Thu Mar 17 18:49:43 1994// -/range.c/0.15/Wed Jun 1 23:41:09 1994 Thu Mar 17 18:49:43 1994// -/re.h/0.15/Wed Jun 1 23:41:10 1994 Thu May 26 00:41:30 1994// -/regex.c/0.15/Wed Jun 1 23:41:12 1994 Wed Jun 1 23:36:35 1994// -/regex.h/0.14/Wed Jun 1 23:41:12 1994 Thu Mar 17 15:55:00 1994// -/st.h/0.14/Wed Jun 1 23:41:14 1994 Thu Mar 17 15:55:00 1994// -/variable.c/0.29/Wed Jun 1 23:41:16 1994 Wed May 25 00:56:35 1994// -/version.c/0.27/Wed Jun 1 23:41:16 1994 Mon Apr 25 23:30:35 1994// -/Makefile/0.32/Fri Jun 3 00:15:00 1994 Fri Jun 3 00:15:00 1994// -/Makefile.in/1.3/Fri Jun 3 00:15:01 1994 Fri Jun 3 00:15:01 1994// -/array.c/0.29/Fri Jun 3 00:15:02 1994 Fri Jun 3 00:15:02 1994// -/configure/1.3/Fri Jun 3 00:15:04 1994 Fri Jun 3 00:15:03 1994// -/configure.in/1.3/Fri Jun 3 00:15:04 1994 Fri Jun 3 00:15:04 1994// -/dbm.c/0.28/Fri Jun 3 00:15:05 1994 Fri Jun 3 00:15:05 1994// -/defines.h/1.4/Fri Jun 3 00:15:06 1994 Fri Jun 3 00:15:06 1994// -/dict.c/0.28/Fri Jun 3 00:15:06 1994 Fri Jun 3 00:15:06 1994// -/dir.c/0.18/Fri Jun 3 00:15:07 1994 Fri Jun 3 00:15:07 1994// -/dln.c/0.29/Fri Jun 3 00:15:08 1994 Fri Jun 3 00:15:08 1994// -/enum.c/0.16/Fri Jun 3 00:15:09 1994 Fri Jun 3 00:15:08 1994// -/eval.c/0.35/Fri Jun 3 00:15:10 1994 Fri Jun 3 00:15:09 1994// -/file.c/0.29/Fri Jun 3 00:15:11 1994 Fri Jun 3 00:15:11 1994// -/gc.c/0.30/Fri Jun 3 00:15:12 1994 Fri Jun 3 00:15:12 1994// -/io.c/0.29/Fri Jun 3 00:15:13 1994 Fri Jun 3 00:15:13 1994// -/math.c/0.28/Fri Jun 3 00:15:14 1994 Fri Jun 3 00:15:14 1994// -/node.h/0.32/Fri Jun 3 00:15:15 1994 Fri Jun 3 00:15:14 1994// -/numeric.c/0.19/Fri Jun 3 00:15:15 1994 Fri Jun 3 00:15:15 1994// -/object.c/0.32/Fri Jun 3 00:15:16 1994 Fri Jun 3 00:15:16 1994// -/pack.c/0.18/Fri Jun 3 00:15:17 1994 Fri Jun 3 00:15:17 1994// -/process.c/0.30/Fri Jun 3 00:15:18 1994 Fri Jun 3 00:15:17 1994// -/re.c/0.32/Fri Jun 3 00:15:19 1994 Fri Jun 3 00:15:18 1994// -/ruby.c/0.34/Fri Jun 3 00:15:19 1994 Fri Jun 3 00:15:19 1994// -/ruby.h/0.30/Fri Jun 3 00:15:20 1994 Fri Jun 3 00:15:20 1994// -/socket.c/0.27/Fri Jun 3 00:15:21 1994 Fri Jun 3 00:15:21 1994// -/sprintf.c/0.23/Fri Jun 3 00:15:22 1994 Fri Jun 3 00:15:21 1994// -/st.c/0.15/Fri Jun 3 00:15:22 1994 Fri Jun 3 00:15:22 1994// -/string.c/0.29/Fri Jun 3 00:15:23 1994 Fri Jun 3 00:15:23 1994// -/struct.c/0.26/Fri Jun 3 00:15:25 1994 Fri Jun 3 00:15:24 1994// -/time.c/0.29/Fri Jun 3 00:15:26 1994 Fri Jun 3 00:15:26 1994// -/version.h/1.7/Fri Jun 3 00:15:27 1994 Fri Jun 3 00:15:27 1994// diff --git a/CVS/Repository b/CVS/Repository deleted file mode 100644 index b98482fac9..0000000000 --- a/CVS/Repository +++ /dev/null @@ -1 +0,0 @@ -/work/cvsroot/ruby diff --git a/ChangeLog b/ChangeLog index 11f5773358..52af56fba7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,1147 +1,4 @@ -Fri Oct 14 13:22:18 1994 Yukihiro Matsumoto (matz@ix-02) +Thu Dec 8 14:17:29 1994 Yukihiro Matsumoto (matz@ix-02) - * version 0.52: ……なんてこったい. + * 0.60 released - alpha test baseline. - * eval.c(rb_call): returnの処理が間違っていたので, マシンによって - はreturnで関数を終了するだけでなくtoplevelまでつき抜けていた. - - * object.c: Builtinクラスを新設. 組み込み関数をKernelから移した. - nilが組み込み関数を理解するとトラブルの元である. - - * dbm.c: Dictと同様にeachが[key,value]を返すように. - - * version 0.51 - -Thu Oct 13 12:13:48 1994 Yukihiro Matsumoto (matz@ix-02) - - * eval.c(SETUP_ARGS): 付加演算子が配列でない時には配列に変換する. - - * parse.y: 括弧なしのメソッド呼び出しでも`*'による付加引数が使える - ようにした. ただし, 通常引数が一つもない場合は乗算演算子と区別が - つかないので, 必ず括弧が必要. - -Wed Oct 12 10:09:07 1994 Yukihiro Matsumoto (matz@ix-02) - - * eval.c(rb_call): キャッシュの計算をinline化. キャッシュミスがあ - れば関数呼び出しでメソッドを検索する. methods.cはなくなった. - - * eval.c(rb_eval): ローカル変数用の領域をalloca()するように変更. - サイズの変更が必要になれば改めてmalloc()するように. - - * parse.y: error recoveryの際にlex_stateを更新しておくように. - -Tue Oct 11 17:10:46 1994 Yukihiro Matsumoto (matz@ix-02) - - * socket.c(for_fd): ファイル記述子(Fixnum)からソケットインスタンス - を得るメソッド. たとえばinetdから起動されたサーバで標準入出力に - ソケット操作を行なうために使う. つまりSocket.for_fd($stdin)で標 - 準入力に対応するソケットオブジェクトが得られる. - - * io.c(to_i): IOクラスのインスタンスを整数に変換するとそのファイル - 記述子を返すように. - - * numeric.c(num2int): to_iメソッドを使ってできる限り整数に変換する. - 以前はnum2fixだけが全てのオブジェクトに対してto_iメソッドを適用 - していた. - - * sprintf.c(Fsprintf): 整数表示の際, オブジェクトをできる限り整数 - に変換するように(to_iメソッドを使う). - -Fri Oct 7 14:06:32 1994 Yukihiro Matsumoto (matz@ix-02) - - * eval.c(Fcaller): 必要性がよく分からないのでドキュメントから削除. - 将来デバッガを作る時に復活させよう. - - * eval.c(rb_call): Cで記述されたメソッド呼び出しでは環境をスタック - にセーブしないことによって高速化. - -Wed Oct 5 15:00:58 1994 Yukihiro Matsumoto (matz@ix-02) - - * ruby.h: 一時env.hに移動してたQselfの定義を復活. ただし今回は関数 - として実現(env.hでは変数として再定義してある). - - * ruby.h: TRUEでsyntax errorにならないよう#undefを追加. - - * eval.c(rb_eval): thread化に挑戦したが, 失敗(速くならなかった). - が, Scopingなどの無駄なコードの削除とメソッド呼び出しの引数セッ - トのinline化で若干の高速化を実現した. 副作用として, argc, argv形 - 式の関数呼び出しの仕様が変化した(argvにselfを含まなくなった). - - * eval.c(rb_call): メソッド呼び出しの高速化. - -Tue Oct 4 11:40:53 1994 Yukihiro Matsumoto (matz@ix-02) - - * ruby-mode.el: 修飾子に対応した. - - * parse.y: 多重代入にrestをつけた. この機能を使えばoptional引数の - 解析が簡単にできる(はず). - - * pack.c(unpack): uuencode形式のdecodeの際に文字列の長さが間違って - いた. - -Mon Oct 3 15:58:41 1994 Yukihiro Matsumoto (matz@ix-02) - - * file.c(type): ファイルタイプを文字列で返すメソッド. - -Fri Sep 30 11:36:07 1994 Yukihiro Matsumoto (matz@ix-02) - - * object.c: デフォルトの真の値である%TRUEの値を1(Fixnum)からtに変 - 更した. to_sで文字列に変換した時にも`t'と表示される. 更に踏み込 - んで`t'を予約語にしてlispのようにしようかとも思ったが, そこまで - は決心できなかった. 一文字のローカル変数はかなり使いそうな気がす - るので…. - - * array.c,dict.c: equalを再定義しているクラスで, hashを正しく定義 - した. - -Wed Sep 28 23:30:28 1994 Yukihiro Matsumoto (matz@dyna) - - * eval.c(Ffail): 今までfailはカーネルクラスのメソッドであったが, - 構文に組み込んだ. この変更によって, 1)`fail'は予約語となり, ロー - カル変数に用いることができなくなった. 2)`fail'単体で例外を発生す - るようになった. 3)failはメソッドではなくなったので再定義される可 - 能性がなくなった. - - * dic.c, dbm.c(indexes): Arrayのindexesと同様の機能を持つメソッド - を追加. - - * array.c(indexes): 引数をインデックスとする要素の配列を返す. 整数 - の配列を引数とする時には引数の要素をインデックスとする要素の配列 - を返す. - -Mon Sep 19 13:42:31 1994 Yukihiro Matsumoto (matz@ix-02) - - * array.c(aset): 部分配列に対する代入で配列以外のオブジェクトが指 - 定された場合に多重代入と同じルールで配列化するようにした. - - * io.c(print): 引数として与えられた各オブジェクトにprint_onメッセー - ジを与えるように. 実行速度は落ちるが柔軟性は増す. - -Fri Sep 16 14:59:18 1994 Yukihiro Matsumoto (matz@ix-02) - - * glob.c: ワイルドカードの導入. bashに使われているGNUのglobルーチ - ンを流用した. - -Mon Sep 12 18:36:58 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y(value_expr): 式がnilの時に対応. - - * class.c: ICLASSのclassが必ずClass/Moduleを指すように. - -Tue Sep 6 16:23:28 1994 Yukihiro Matsumoto (matz@ix-02) - - * re.c: 正規表現内で「\数字」形式が指定できるように. - - * parse.y:「do expr using var ... end」形式はなくなった. 寂しい気 - もする. *BACKWARD INCOMPATIBILITY* - -Mon Sep 5 10:59:01 1994 Yukihiro Matsumoto (matz@ix-02) - - * numeric.c(next): Numericクラスにもnextを提供. - - * string.c(upto): uptoを提供. - - * range.c(each): nextを使ったインタフェースからuptoを使うように変 - 更した. この方が一つのメソッドで処理をまとめで行なうことができる. - -Fri Sep 2 15:25:39 1994 Yukihiro Matsumoto (matz@ix-02) - - * dict.c(each): 戻り値を[key, value]のペアに変更. 今までのeachは - each_valueとして残る. *BACKWARD INCOMPATIBILITY* - -Thu Sep 1 10:49:04 1994 Yukihiro Matsumoto (matz@ix-02) - - * 成功した(特別な戻り値を持たない)システムコールは`0'を返すように. - -Wed Aug 31 00:26:51 1994 Yukihiro Matsumoto (matz@dyna) - - * string.c: チェックサムを得るメソッド`sum'を作った. - - * class.c(include_class_new): ICLASSのclassをもとのクラスにした. - gcの際に元クラスをマークする必要があるのが, フィールドを増やす余 - 地が無いので, classフィールドを流用した. 私の見積りが間違ってい - て, ICLASSのインスタンスにメッセージを送る事があれば, おかしな動 - 作をするだろう. - - * eval.c(masign): 式(a,b = nil)の値を[nil]からnilに変更した. - -Mon Aug 29 11:56:09 1994 Yukihiro Matsumoto (matz@ix-02) - - * class.c: rb_define_mfuncを無くして, メタクラスにモジュールをイン - クルードするようにした. - - * error.c(yyerror): 同じ行で複数のsyntax errorをリポートしないよう - にした. - - * file.c: FileTestモジュールにファイルテストメソッドを分離した. - - * parse.y: 演算子を指定する時のlex_stateを正しく設定した. - -Sat Aug 27 01:23:34 1994 Yukihiro Matsumoto (matz@dyna) - - * parse.y: if/whileなどの複合式をprimaryに移動した. これによって例 - えば「if cond then a else b end.message()」のような式が書けるよ - うになった. - -Fri Aug 26 10:46:30 1994 Yukihiro Matsumoto (matz@ix-02) - - * spec: 整理された文法にしたがって書き直した. - - * parse.y: ここ数日で混乱していた文法を整理した. 括弧を省略したメ - ソッド呼び出しができるようになったこと, modifierが付けられるよう - になったこと, returnにリストが渡せるようになったことが主な変更点 - である. - - * process周りが怪しいがとにかくSolaris 2.3で動くように. - - * parse.y: 曖昧性がない場合にはメソッド呼び出しの引数の括弧を省略 - できるように. 省略できるメソッド呼び出しの条件は, 1)かならず1個 - 以上の引数を必要とすること, 2)第1引数が`+', `-', `(', `[', `{', - `/'など, 式の始まりに置かれた時と途中に現れた時とで解釈が違う記 - 号で始まらないこと, である. - -Thu Aug 25 13:54:58 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y(cond): 条件式の展開部にbugがあった. - -Wed Aug 24 00:01:15 1994 Yukihiro Matsumoto (matz@dyna) - - * parse.y: returnはコンマで区切ったリストも受け取るように. つまり, - return a, b, cはreturn [a, b, c]と同じ意味になる. - - * parse.y: yield以外の大域脱出制御式をexprからexpr0に移した. よっ - てメソッドの引数に制御式を使えなくなる(これで困る人はいないはず). - - * parse.y: `+'の定数展開の際に演算子の優先順位を忘れていた. - - * eval.c: untilの戻り値はnilになった. - - * parse.y: modifierとしてのif/unless/while/untilを追加. - - * parse.y: 文法からendの後ろにつけるキーワードを削除. ほとんど使わ - なかった上に, emacsではruby-modeがあれば対応のチェックが機械的に - 出来るため. - -Tue Aug 23 18:08:33 1994 Yukihiro Matsumoto (matz@ix-02) - - * eval.c: スクリプト実行開始前に例外が発生した時にcore dumpした. - 組み込み用にコードを変更した時にenbugしてしまった. - -Tue Aug 23 00:07:17 1994 Yukihiro Matsumoto (matz@dyna) - - * eval.c: doの戻り値がいつもnilになっていた. - - * parse.y: loop制御変数の多重代入化にbugがあった. - - * parse.y(expand_op): 文字列も畳み込みの対象に. - -Mon Aug 22 10:50:01 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y(expand_op): `+'に関しては結合則を使って, より多く定数畳 - み込みを行なうように. - - * ruby.c(proc_options): argcが0の時にも対応. - - * parse.y: forなどの制御変数に多重代入も使えるように. - -Sat Aug 20 00:59:40 1994 Yukihiro Matsumoto (matz@dyna) - - * parse.y(call_op): 演算子`~'の取り扱いをルール部へ移動. - -Fri Aug 19 11:44:13 1994 Yukihiro Matsumoto (matz@ix-02) - - * main.c: rubyをほかのプログラムに組み込めるようにmain()を分割した. - それにともない, プログラムの呼び出し構造を修正した. - - * parse.y: 条件式の定義を変更. ifなどの条件式の中でだけ`&&'や`||' - および`!'の引数が条件式になるように. この変更により条件式以外の - 場所での `&&', `||', `!'演算子の動作が直観に一致する. - - * parse.y: 実引数の`*'の後に続く引数はexprに制限した. 今までは全て - の文が有効であったが, ここで定義文があってもしょうがない. - -Thu Aug 18 10:21:45 1994 Yukihiro Matsumoto (matz@ix-02) - - * re.c: 正規表現ルーチンの初期化部分を削除してしまっていた. これで - はemacsの正規表現になってしまう. - - * version.c: copyright表示を追加. - - * version.c: バージョン表示をstderrに. - - * configure.in: gccがない場合testに失敗していた. - -Fri Aug 12 14:12:23 1994 Yukihiro Matsumoto (matz@ix-02) - - * array.c(astore): 配列の拡大する時にある程度の大きさをまとめて拡 - 大するように. - - * io.c(Fprint): 配列に対しては一度文字列に変換することなく, 直接内 - 容を出力するように. - - * string.c(str_new): memmoveからmemcpyへ置き換えた. これでもかなり - 速度が違う. - - * ruby.h: データメンバの取り出しで名前を文字列からIDで指定するよう - にした. かなりの高速化になる. - - * io.c: $ARGFという変数で引数列からなる仮想ファイルをオブジェクト - として扱えるようにした. 今まではトップレベルのgets()などを使って - アクセスしていたが, どうもオブジェクト指向的ではなかった. - -Thu Aug 11 11:43:15 1994 Yukihiro Matsumoto (matz@ix-02) - - * gc.c: mark_location()の間違った呼び出し方の行が残っていた. - - * method.c: プロトタイプ宣言が足りなかった. - -Wed Aug 10 15:54:46 1994 Yukihiro Matsumoto (matz@ix-02) - - * variable.c: -vオプションが指定されている時は初期化されていない, - 大域変数, インスタンス変数, ローカル変数を参照した時点でwarning - を出すようにした. - -Tue Aug 9 11:50:48 1994 Yukihiro Matsumoto (matz@ix-02) - - * bignum.c: 冪乗に関しても多倍長演算を行なうように. 特に浮動小数点 - 数の範囲を越えた時の処理を的確に行なうように. - - * eval.c: メソッド定義後は構文木から, メソッド定義部分を外す. 無駄 - な再定義が起こらないようにするためと2重にfree()されないため. - - * array.c(Fary_aref): 引数が1つでFixnumの時, Range checkを行なわな - いように修正. - - * eval.c: メソッドの引数の数をコンパイル時に計算して若干の高速化. - -Mon Aug 8 13:06:24 1994 Yukihiro Matsumoto (matz@ix-02) - - * object.c: nilによる比較連鎖をなくした. - - * parse.y: bit演算子の優先順位を比較演算子よりも強くした. Cとは異 - なることになるが, 直観には合致する. - - * gc.c: クラスを解放する時, 個々のメソッド毎にキャッシュをクリアす - るのではなく, クラス単位でクリアするように. - -Thu Aug 4 18:45:09 1994 Yukihiro Matsumoto (matz@ix-02) - - * methods.c(method_free): 解放されたメソッドに関してキャッシュをク - リアしておく必要があった. - - * gc.c: Dataクラスのデータ部分をfree()し忘れていた. - -Wed Aug 3 09:58:14 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y: def func .. end形式による関数メソッドの定義はなくなった. - - * methods.c: func形式のメソッドをなくした. あっても, あまり意味が - ないので. - - * eval.c: $0への代入でps(1)の出力が変化するように. - - * io.c(Fsyscall): syscall()を実現. - -Mon Aug 1 13:41:11 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y: ダブルクォートで囲まれた文字列や正規表現中で"#{変数名}" - または"#変数名"という形式で変数の内容を埋め込むことができるよう - になった. - - * io.c: 関数メソッドsystem2()はなくなった. 今はバッククォートがあ - るからね. - - * parse.y: `cmd`によってコマンドを文字列に展開することができるよう - になった. - - * parse.y: __FILE__, __LINE__を追加. それぞれファイル名(文字列), - 行番号(整数)を値とする疑似変数. - -Fri Jul 29 13:16:07 1994 Yukihiro Matsumoto (matz@ix-02) - - * methods.h: メソッドをオブジェクトとして扱うのをやめる. メソッド - のメモリ管理にはリファレンスカウントを使うことにした. これでオブ - ジェクトの数が減ってほんの少しだけGCが速くなる(かな). - - * purifyによってメモリ関係のバグを検査した(見つかる,見つかる…). - - * gc.c: GCをプログラマが変数をマークする形式から, スタックとレジス - タからマークする方法に変更. 移植性が下がるような気もするが, siod - やscmでも採用されているから多分大丈夫だろう. Linux on i486でも動 - 作を確認した. - -Wed Jul 27 16:13:13 1994 Yukihiro Matsumoto (matz@ix-02) - - * eval.c(Eval): トップレベルでは構造木をfreeしないように. どうせ解 - 放されるから時間の無駄である. - - * array.c, dict.c: "=="を構造一致に変更. - -Fri Jul 22 10:14:09 1994 Yukihiro Matsumoto (matz@ix-02) - - * error.c: 組み込みタイプの名前を登録し忘れていた. - -Thu Jul 21 14:06:48 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y(freenode),eval.c(Eval): 解析木を解放し忘れていた. - -Mon Jul 18 10:19:15 1994 Yukihiro Matsumoto (matz@ix-02) - - * parse.y: 多重代入を処理するルールにバグがあって, 3要素以上の多重 - 代入に失敗していた. - - * eval.c(rb_eval): 多重代入で, 右辺が配列でない時には`to_a'メソッ - ドで配列に変換して代入するようにした. 今までの仕様だと右辺値が第 - 1要素にそのまま代入されていたが, structなど配列に変換できるもの - は変換した方が嬉しい気がする. - - * dbm.c,dict.c(delete_if): メソッド追加. - - * process.c(wait,waitpid): システムコールwaitpidまたはwait4がある - 時はそちらを使うように. configureもそれらをチェックするように変更. - - * dbm.c, dict.c(clear): メソッド追加. - -Fri Jul 15 10:54:45 1994 Yukihiro Matsumoto (matz@ix-02) - - * array.c(Fary_fill,Fary_clear): メソッドを追加. - - * string.c(Fstr_split): $;の値が長さ1の文字列である時, これを正規 - 表現化しないで, 単なる文字として分割する. - - * string.c(Fstr_aset/Fstr_aref): インデックスが文字列の範囲外だっ - た時の動作をArrayを参考に修正した. - - * array.c(astore,Fary_aset): 領域をreallocした後, ゼロでクリアする - ように. 今まで配列にゴミが入っていた. - - * array.c: []/[]=でのインデックス関係を整理. 基本的に負のインデッ - クスに代入しない限り例外は起きないように変更した. 必要に応じて適 - 当に解釈して, 必要ならば領域を拡張するように. - -Thu Jul 14 11:18:07 1994 Yukihiro Matsumoto (matz@ix-02) - - * autoexec.c: 削除. autoload関係の機能は今後検討しよう. - - * dict.c: 辞書クラスの正式名称をDictに変更した. 別名としてHashを用 - 意した. 今までDictionaryなどと長い名前にしていたが誰も使っていな - かったしね. *BACKWARD INCOMPATIBILITY* - - * parse.y: Dictを生成する構文を追加. こちらを{..}にした. - - * parse.y: 配列を生成する構文を[..]に変更した. 過去のRubyスクリプ - トとの互換性が保てないが, Dictを生成する構文を導入するに当たり, - perl5に合わせて(意識して), 変更する時期は今しかないと考えた. - *BACKWARD INCOMPATIBILITY* - - * eval.c(Feval): eval()でメソッドを定義する時, 定義されるクラスを - メソッドの所属するクラスにした. 今まではObjectクラスに定義されて - いた. - - * parse.y: ローカル引数がない時のeval()で落ちていた. - -Tue Jul 12 09:41:28 1994 Yukihiro Matsumoto (matz@ix-02) - - * pack.c: uuencode形式のサポート. - - * `-0'を`-R'に. 出力レコードセパレータをコマンドラインから指定する - 方法はなくなった. どうも, 仕様がゆれるなあ. - -Mon Jul 11 09:51:24 1994 Yukihiro Matsumoto (matz@ix-02) - - * ruby.c: `-r'オプションは`-0'オプションになった. 当面は`-r'も有効 - だが変更される可能性がある. `-R'は当面はそのまま. - - * version.c: version表示に日付を含めた. - - * parse.y: private methodの復活. RubyのprivateメソッドはC++におけ - るprotected methodに該当するもので, `@'で始まる名前を持つ. - - * env.h: struct ENVIRONの定義を分離. - - * parse.y: `\$var', `\@var', `%var'も許すように. - - * variable.c(Fdefined): idも引数として受け付けるように. - - * parse.y: if文/unless文にキーワードthenを追加. thenなしというのは, - 意外と間違いが多いので. もちろん省略できる. - -Sat Jul 9 02:16:04 1994 Yukihiro Matsumoto (matz@dyna) - - * eval.c(rb_eval): class/moduleの評価で新しいスコープを割り当てて - いなかった. スコープ割り当て部分をrb_call()からrb_eval()に移した. - - * eval.c(rb_call): realloc()に渡される事のある, ローカル変数用の領 - 域をalloca()していた. たまに落ちるわけだ. - - * string.c(Fstr_times): 割り当てた領域を越えた部分を変更していた. - -Wed Jul 6 15:52:42 1994 Yukihiro Matsumoto (matz@ix-02) - - * socket.c: Socket -> BasicSocket, RawSocket -> Socket に改名. - - * string.c(ucfirst,lcfirst): 最初の1文字だけの大文字/小文字変換. - - * numeric.c(chr): 整数の文字列化メソッド. - - * inits.c, dbm.c: DBMが使えない時はクラスそのものを定義しないよう - にした. 利用できないクラスはnilとすることを今後のポリシーとしよ - う(いままではアクセスした時点でエラーが発生していた). autoexec() - のあり方も検討が必要になりそうだ. - - * bignum.c(bigadd): バグ修正. - -Thu Jul 7 11:12:18 1994 Yukihiro Matsumoto (matz@ix-02) - - * eval.c(Fload,Feval): eval_treeをクリアし忘れていた. - - * _inspect: オブジェクトを可読形式の文字列に変換する(主にデバッグ - 出力用). - -Wed Jul 6 00:57:18 1994 Yukihiro Matsumoto (matz@dyna) - - * numeric.c, bignum.c: 整数に対する`[]'演算子. nビット目がセットさ - れているかどうかを返す. - -Tue Jul 5 12:48:39 1994 Yukihiro Matsumoto (matz@ix-02) - - * io.c(Feof): 追加. コマンドラインからなる仮想ファイルについても - EOFが検出できるように. - - * ruby.c: -l/-r/-R/-Xオプションの追加. - - * ruby.c: -n/-pオプションのloopの付加などをメインルーチンに移動し - た. これで, オプションの解析途中で(`-c'オプションのせいで)終了な - どといったことはない. - - * io.c(Fgets): 高速化. 凝ったことをしない方が速かった. 虚しい. - -Mon Jul 4 15:55:48 1994 Yukihiro Matsumoto (matz@ix-02) - - * Socket:getsockname/getpeername - ようやく仕様が安定した. - - * io.c(Fgets): eachでgetsを記述するのではなく, getsでeachを記述す - るようにした. - -Fri Jul 1 10:35:49 1994 Yukihiro Matsumoto (matz@ix-02) - - * $ENV[env] = nil/$ENV.delete(env)で環境変数を削除できるようになっ - た. $ENV.deleteは環境変数の以前の値を返す. - - * !~の定義が間違っていた. - - * Dict,DBM:[]= - nilの代入によって要素を削除できるようになった. こ - れにともないnilはDictの要素になれなくなった. - - * ソースの整理. 盲腸のような使われていないコードをなくしたり, 変数 - 名を付け変えたりした. - -Fri Jul 1 00:21:29 1994 Yukihiro Matsumoto (matz@dyna) - - * Array:join() - 要素数0の配列に対して空文字列を返す. - - * RawSocket:open(),socketpair() - 文字列で指定できるドメインとタイ - プをいくつか追加した. - -Thu Jun 30 13:51:29 1994 Yukihiro Matsumoto (matz@ix-02) - - * -fオプションをなくした. 昔(loadのなかった頃)の名残なので, 今となっ - ては必要ないだろう. - - * -sオプションを追加. perlの-sオプションと同じ動きをする. - - * RawSocketクラスを提供する. Socketに対するシステムコールレベルの - アクセスが可能になった. - -Thu Jun 30 00:27:19 1994 Yukihiro Matsumoto (matz@dyna) - - * Socket - bug fixes. - - * linuxではsyscall(SYS_select)が正常に動作しない. - - * Socket:addr,peeraddr - 配列としてsockaddrの情報を返す. - -Wed Jun 29 00:14:20 1994 Yukihiro Matsumoto (matz@dyna) - - * Socket:setopt,getopt - setsockopt(2), getsockopt(2)へのアクセス - を実現. - - * sprintf() - rubyにはunsignedは無いので, %uを取り除いた. - - * sprintf() - %b, %x, %oでは2の補数表現, %B, %X, %Oでは符号付き表 - 現で出力するように. ここ数日でsprintf()の仕様がゆらいでいたが, - これで落ち着きそうだ. - -Tue Jun 28 14:42:03 1994 Yukihiro Matsumoto (matz@ix-02) - - * Bignum:<<,>> - 2の補数をとる処理を除いた. シフト演算には関係ない - 処理だった. - - * Bignum:^ - bug fix. 符合が反対だった. - - * sprintf() - 2進出力子"%b"を追加. - - * sprintf() - %x, %oでFixnumを出力する時, 2の補数表示を行なわない. - - * sprintf() - %x, %oはやはり負の数の時は`-'を出力するように. - -Mon Jun 27 14:56:13 1994 Yukihiro Matsumoto (matz@ix-02) - - * sprintf() - Bignumについても%d, %oは(2の補数表現に変換して)正の - 整数を表示するようにした. - - * Bignumに対する論理演算の定義を修正した. 負の数は2の補数表現であ - るとみなし, かつ仮想的に左側に無限に1が連続しているような演算結 - 果を得る. - - * Fixnum:<<,>> - 符合付シフトに変更. - - * Bignum:>> - 負の整数のシフトに対応した. - - * __END__, ^D, ^Zでスクリプトを終了できる. - - * -xオプションを追加. #! ..rubyなる行まで読み飛ばす. - - * -cオプションを追加. コンパイルのみを行う. - -Sat Jun 25 01:37:21 1994 Yukihiro Matsumoto (matz@dyna) - - * Fixnum:<< - 必要に応じてBignumに拡張して左シフトするように. よっ - て, シフト幅が32を越えるとCやPerlとは違った値を返す. - -Fri Jun 24 10:01:28 1994 Yukihiro Matsumoto (matz@ix-02) - - * ioctl()/fcntl() - システムコールを呼び出す前にバッファの大きさを - 調節するようにした. - - * String:toupper/tolower - 文字列を置き換えたコピーを作るのではな - く, 元の文字列の内容を変更するようにした. - - * inplace editを実現した. perlと同じように`-i'オプションで指定する. - もっとも, こちらはMS-DOSのこととか考えてないけど. - - * デフォルトの出力先を追加した. 今までは$stdoutに代入するしか方法 - はなかった. - -Fri Jun 17 10:55:08 1994 Yukihiro Matsumoto (matz@ix-02) - - * 環境変数にアクセスする方法としてgetenv()/setenv()以外に$ENVを用 - 意した. $ENVは文字列-文字列の辞書であるかのように動作するEnvDict - オブジェクトが代入されている(eachはassocを与える). - - * nilに代入するとcore dumpした. コンパイル時のチェックを強化. - - * Struct: struct_new()の引数をGCプロテクトする必要がある. せめてス - タック領域だけでもスキャンできるようにしなければいけないんだろう - か? でも, 移植性がなあ. - -Fri Jun 17 01:01:46 1994 Yukihiro Matsumoto (matz@dyna) - - * Time::asctime() - 日付のフォーマットで日が落ちていた. - - * Stat: StatはEtcなどと同様にStructで実現したので, Statクラスは無 - くなった. - -Thu Jun 16 10:32:23 1994 Yukihiro Matsumoto (matz@ix-02) - - * bignum.c: いくつかのバグを修正した. Fixnumを渡すべきところで普通 - のintを渡していた. 失敗. - - * big2str() - 1桁ずつbaseで割る代わりに, 4桁ずつ割算を行なうように - した. これで多倍長割算の回数が1/4になる. さらに整数->数(文字)へ - の変換をテーブルを用いるようにした. - - * rb_ivar_get_1() - すでに何らかのインスタンス変数を持つオブジェク - トでは, 未定義のインスタンス変数の値が不定値になっていた. - - * yylex() - インスタンス変数の認識に失敗していた. attr()は正しく動 - 作していたので, 混用すると動作しなかった. 全部違っていたから動い - ていたのね. - - * Object:attr() - すでにアクセスメソッドが定義されている時にはデフォ - ルトのアクセスメソッドを定義しないようにした. もっともアクセスメ - ソッドと同名のメソッドの区別はRubyには存在しないけど, それは仕方 - がないよね. - - * pack.c: エンディアンをautoconfで判定するようにしたので, v/Vが使 - えるようになった. またntoh?()/hton?()も自前で用意した. - - * Stat: st_rdevをアクセスするメソッドを追加. さらにシステムがstat - 構造体にst_blksize, st_blockを持っているかをautoconfでチェックす - るようにした. - - * ドキュメントを少し整備した. - - * INT2FIX()のうち, 31bit幅が保証できないものは, int2inum()に置き換 - えた. - -Wed Jun 15 10:18:27 1994 Yukihiro Matsumoto (matz@ix-02) - - * sprintf() - bignumの出力の時, 出力幅を正しく計算するようにした. - - * str2inum() - baseが0の時, baseを自動判定するように(0xで始まる時 - 16 進, 0で始まる時8進). - -Tue Jun 14 16:08:42 1994 Yukihiro Matsumoto (matz@ix-02) - - * gc.c: Bignum型を追加するのを忘れていた. 組み込み型を追加した時に - は必ずmark()とsweep()にその型に関する処理を追加する必要がある. - - * bignum: 割算も動いたような気がする. アルゴリズムを理解していない - ので, 自信がない. - -Mon Jun 13 14:36:55 1994 Yukihiro Matsumoto (matz@ix-02) - - * まだサポートしていないメソッドなどがあるが, 曲がりなりにもBignum - が使えるようになる. これでioctlも使える. - -Fri Jun 10 17:26:42 1994 Yukihiro Matsumoto (matz@ix-02) - - * Comparable: 基礎となるメソッドを`=='と`>'から`<=>'に変更した. 今 - 後Comparableのサブクラスは`<=>'だけを再定義する必要がある. - -Wed Jun 8 13:12:18 1994 Yukihiro Matsumoto (matz@ix-02) - - * Need_Fixnum()をほとんどなくして, NUM2INT()で直接intに変換するこ - とにした. これで31bitに丸めて桁落ちをおこす問題がなくなる. - -Tue Jun 7 09:45:31 1994 Yukihiro Matsumoto (matz@ix-02) - - * ruby.h: マクロFIXABLE(n)を追加. ついでにFIXNUM周りの定義を変更し - て, 移植性を高めた(つもり). - - * C++の予約語であるnewを削除した. しかし, もうひとつの予約語である - classに関しては, 置き換える単語が思いつかないこともあってそのま - まになっている. - - * 31bitを越えそうなINT2FIX()を関数呼び出しに変えた. 将来bignumが導 - 入された時には自動的にbignumを返すようにする. - - * readline() - 引数の`-'は標準入力を意味するようになった. - - * ruby.h: 右シフトが論理シフトか算術シフトかは処理系依存のようなの - で, ruby.hでcppを使ってチェックするようにした. これでうまくいく - と思うのだが, 手元に符合付intを論理シフトする処理系がないので確 - 認できない. NEWS-OSのCCは確か右シフトはいつも論理シフトだったよ - うな気がするんだけど…. - -Mon Jun 6 10:10:22 1994 Yukihiro Matsumoto (matz@ix-02) - - * FIX2INT()の定義を変更した. どうして昔はうまく動かなかったんだろ - うか? もしかして, 右シフトの符号拡張は処理系依存? - - * FIX2INT()とFIX2UINT()を使い分けるようにした. もっともfixnumは31 - ビットしかないので, 本質的な解決にはならないのだが(ioctlが組み込 - みたかった). - - * printを関数的メソッドから通常メソッドに変更. 引数が与えられない - 時にはレシーバをプリントするようにした. これでprintをメッセージ - 形式でも実行できるようになった. 例: - - ruby -e 'readlines().sort.print' - - 上のスクリプトは, 引数として与えられた(あるいは標準入力から読み - 込まれた)文字列を各行毎にソートして表示する. - - * eval.c: argc,argvパターンで引数を受けるメソッドに引数が一つも与 - えられない時, argvがnilになっていた(argv[0]にアクセスすると落ち - てしまう). - - * _exit()を追加. こちらは例外処理など行なわない. - - * dbmクラス: クラス名称をDBM(大文字)に統一した. - -Sat Jun 4 00:51:04 1994 Yukihiro Matsumoto (matz@dyna) - - * ループ変数にも属性や配列要素を指定できるようにした. - -Fri Jun 3 09:49:48 1994 Yukihiro Matsumoto (matz@ix-02) - - * 多重代入において, 属性代入, 配列要素への代入も行なえるようにした. - - * Need_Fixnum(): nilを0に変換するように. - - * Enumerable:min, max, index, includes - 追加. min, maxは要素が - `<=>'メソッドを持つことを仮定している. - - * Dict/Dbm:length - 要素数を返すメソッド. - - * Dbmクラスにto_aメソッドを追加. - - * Sunにおけるsortの誤動作の件, 昨日の修正でfixされた. しかし, それ - でなぜ動かなかったのかは明らかではないが…. 比較関数がどんな値を - 返しても指定した領域外をアクセスするのはバグではないか. - - * ファイルの全内容を読んで, 各行を配列として返すメソッドはpythonを - 参考にして`readlines'という名前にした. それにともないgetsに対し - てreadlineという別名を用意した. - -Fri Jun 3 00:08:38 1994 Yukihiro Matsumoto (matz@dyna) - - * Array:sort - 判別関数の戻り値はFixnumではなく, Intであるべきだっ - た. 間違い. Sunで動作がおかしかったのはこのせいかも知れない. - -Thu Jun 2 11:48:37 1994 Yukihiro Matsumoto (matz@ix-02) - - * IO:read_all() - ストリームの最後まで入力して, 各行を要素とする配 - 列を返すメソッドを追加. また関数メソッド read_all()も追加した. - これは引数のファイルから読み込んで各行を要素とする配列を返す. 意 - 味的には - - def read_all() - ary = {} - while gets() - ary.push($_) - end - end - - とほぼ等価である. - - * String:atoiメソッドを削除. to_aメソッドからaが配列であるとの連想 - を呼んで, 混乱を招かないため. 代わりにto_iメソッドを使うこと. - - * 配列への変換メソッドto_aを導入した. 通常のオブジェクトは自分自身 - を唯一の要素とする長さ1の配列を返す. 配列は自分自身を, 辞書はキー - と値のペアの配列を返す. Enumeratedをincludeしたクラスは, eachが - 返す各要素を含む配列を返す. - - * file.c: 不定個の引数を受けとるメソッド(chmod,chown,utimes)を書き - 換えて, 整理した. それに伴い, 最初に全ての引数の型チェックを行な - うようにした. 型チェックに失敗すると処理を行なわずに例外を発生さ - せる. - - * configure.in: 不必要なテストを行なわないように修正した. - -Tue May 31 10:41:08 1994 Yukihiro Matsumoto (matz@ix-02) - - * String:pack(): 2進数の文字列変換(B,b)で0と1が逆だった. - - * Math.c: 実数系のメソッドに引数として整数が渡された時に自動的に変 - 換するようにした. - - * toupper(), tolower(): 文字列の判定ミスで変換されていなかった. - - * getopt_long()の仕様によって, スクリプトへの引数がインタプリタの - 引数だと解釈されていた. 引数パターン文字列の先頭に`+'を追加. - - * config.hを削除した. DEFINEはMakefileで与えられる. - - * sprintf(): "%d"に文字列が与えられた時にはアドレスではなく内容を - 整数に変換するようにした. ついでに浮動小数点数も変換するように変 - 更した. - - * regexp.c: rubyの拡張正規表現(\d, \D, \s, \S)の処理で割り当てた領 - 域を越えてバッファに書き込んでいた. 処理前にバッファをきちんと拡 - 張するようにした. これで昨日問題にしていたメモリの問題は解決でき - たと思う. - - * yylex(): ダブルクォート文字列中でダブルクォートを表現するため - のバックスラッシュ表現ができなかった. - -Mon May 30 10:07:42 1994 Yukihiro Matsumoto (matz@ix-02) - - * 演算子`!'の右辺も条件式であるとした. これによって, この演算子を - 再定義する人は混乱するかも知れないが, 大多数のこの演算子を使う人 - は混乱を避けることができると思う. - - * autoconfを使って, 自動的にMakefile, config.hを生成するようにした. - これで, 多くのマシンでは`configure'を実行した後, `make'一発でコ - ンパイルできると思う. - - * clone: サブクラスに対して用いられた場合, 元のオブジェクトと同じ - クラスのインスタンスを返すように(以前はビルトインクラスの場合を - 考えてなかった). - - * ビルトインクラスのサブクラスも作れるように, リテラルのあるクラス - にもnewメソッドを追加した. - - * malloc()で落ちる. purifyが必要かも知れない. - - * re.c: rb_global_variable()の呼びだし形式の間違い. 変数へのポイン - タを渡さなければいけない. - - * parse.y: ローカル変数の扱いに引数の評価順に依存する移植性のない - 部分があった. - - * attr(): 属性設定のバグを直した. いつ内部仕様が変わったんだろう…? - -Sat May 28 23:08:18 1994 Yukihiro Matsumoto (matz@dyna) - - * 正規表現キャッシュの文字列一致判定をポインタ一致から内容一致に変 - 更した. そういえば文字列リテラルは一回毎に新しくオブジェクトが生 - 成されるのだった. - -Fri May 27 11:42:00 1994 Yukihiro Matsumoto (matz@ix-02) - - * trから文字削除(delete), 文字圧縮(squeeze)を分離した. それにとも - ないtrのオプション引数はなくなった. - -Thu May 26 10:32:55 1994 Yukihiro Matsumoto (matz@ix-02) - - * スクリプト読み込みルーチンを書き直して, 通常ファイル以外のファイ - ル名や空文字列がスクリプトとして与えられた場合に対応した. また, - 標準入力からスクリプトを読み込む時に, 一時ファイルが/tmpに残らな - いようにした. - - * Fixnum:id2name - IDから文字列に戻す関数. String:internの逆. - - * Array: 配列の範囲外の要素をアクセスした時に例外を発生させずに, - nilを返すようにした. 配列は自動的に拡張される. - - * string:stripを追加. - - * -nオプションが-eオプションを複数指定した時も動作するように. - - * parse.yでもインクルードするようにした. - - * fname周りの細かいbugを修正. - -Wed May 26 11:45:10 1994 Yukihiro Matsumoto (matz@dyna) - - * 定数をキャッシュするようにした. 繰り返しが多い場合には有効のはず - だが, 一度しかアクセスしない場合は遅くなるなあ. - -Wed May 25 00:42:24 1994 Yukihiro Matsumoto (matz@dyna) - - * 多重代入文(foo, bar = 1, 2)の採用. - - * 条件式部に文字列あるいは正規表現リテラルをおくと`=~'演算子によっ - て`$_'と比較される. 更に`...'の両辺では整数リテラルが`$.'と比較 - される. - -Mon May 23 23:27:03 1994 Yukihiro Matsumoto (matz@dyna) - - * &式 形式はなくなった. 代わりにkernel:apply(id, args..)を導入. - - * def op () ..形式の導入. opは再定義可能な演算子. - - * constantの代入時チェック. 既に初期化されている定数に代入した場合 - は例外が発生する. - - * 多重代入文. - -Thu May 19 22:57:07 1994 Yukihiro Matsumoto (matz@dyna) - - * 複合文でもvoid valueのチェックを行うようにした. - - * untilの動作の修正(do..until型だった). - -Wed May 18 01:06:25 1994 Yukihiro Matsumoto (matz@dyna) - - * 移植に関する若干の問題を修正. - - * 別名の構文を「def a b」にした. - - * until/unless: 演算子から制御文へ. 例外を捕捉する機能はそのまま. - - * 選択可能な機能をconfig.hからdefines.hに移動. - -Fri May 13 23:20:21 1994 Yukihiro Matsumoto (matz@dyna) - - * -yオプションを新設. -dオプションからコンパイラのデバッグ部分を分 - 離した. - -Tue Apr 25 20:17:33 1994 Yukihiro Matsumoto (matz@dyna) - - * マルチバイト文字列を識別子に使えるように. 個人的には使いたくは無 - いけどなあ. - - * `-v'フラグの状態を$verboseでアクセスできるように. - - * CVSの導入に伴い, バージョン管理の方法を変更. - - * 真面目にChangeLogをつける事にした. - -Tue Mar 8 10:09:25 1994 Yukihiro Matsumoto (matz at nws119) - - * %変数名 によるクラス定数を導入. - - * undef メソッド によるメソッド定義の取り消しを導入. - - * rb_get_method_bodyではthe_envを変更せず, rb_call()で明示的に変更 - するように. これでresponds_toなどで環境が破壊されない. - -Mon Mar 7 17:46:15 1994 Yukihiro Matsumoto (matz at nws119) - - * 「&文字列」形式. 「式.文字列」型のメッセージセンドはなくなった. - - * 自己代入形式(+=. -=, ...) - - * obj.attr = expr形式の採用. - -Thu Feb 24 16:23:28 1994 Yukihiro Matsumoto (matz at nws119) - - * toint, tofloat, print_stringをそれぞれto_i, to_f, to_sに変更. - - * String:clone - Copy on Writeの実現. - -Tue Feb 22 11:11:44 1994 Yukihiro Matsumoto (matz at nws119) - - * re.c: マッチした文字列の保存に失敗していた. - - * trap: 可能ならば処理に時間のかかるシステムコール(read, wait, - sigpause, select)をフックして割り込み処理の即答性を高める(DOSな - どでは無理だなあ). - - * trap: 割り込みをその場で処理するか(迅速だが危険), 安全なタイミン - グで処理するかを選択できるように. - -Tue Feb 17 11:11:12 1994 Yukihiro Matsumoto (matz at nws119) - - * trap: 割り込みハンドラ. - -Wed Feb 16 12:29:12 1994 Yukihiro Matsumoto (matz at nws119) - - * String:crypt: 暗号化ルーチン - - * "::"演算子の追加. a::b は {a, b}と同義. a::b::c は {a, {b, c}}と - 同義(右結合). 同義とはいうものの, "::"演算子を使った方が少しだけ - メモリ効率が良い. - - * Dir.rmdir(), File.unlink(), File.utime() -- 各システムコールへの - インタフェース. - - * kill -- kill(2) I/F - - * select(): readのチェックではstdioにバッファリングされているかど - うかをチェックするように. - -Tue Feb 15 15:08:31 1994 Yukihiro Matsumoto (matz at nws119) - - * file.c: statをキャッシュするように. - - * File:utime()を追加. - - * unliteralize(): フラグを破壊していた. - - * Bug(): coreを吐くように. - - * String:tr -- tr(1)互換. 引数パターンがちょっと違うけど…. - -Mon Feb 14 18:24:13 1994 Yukihiro Matsumoto (matz at nws119) - - * unless, untilが例外も偽と見なすように. - - * select() -- select(2) I/F - - * Array:pack, String:unpack: perlのpack/unpackの同等品 - -Tue Feb 8 17:11:10 1994 Yukihiro Matsumoto (matz at nws119) - - * setenv()のないシステムのためにputenv()を使ったコードも用意した. - -Mon Feb 7 09:52:44 1994 Yukihiro Matsumoto (matz at nws119) - - * 引数の一番最後に`*'を置けるようにした. これでrest引数のリストを - 操作する必要が少なくなる. - -Fri Feb 4 18:23:26 1994 Yukihiro Matsumoto (matz at nws119) - - * ruby-mode.elを書き直す. ずいぶんましになったと思う. - - * 文字列リテラルのCopy on Writeを実現. これで文字列がリテラルであ - るからといっていちいちcloneしなくても済む. - -Tue Feb 1 09:21:09 1994 Yukihiro Matsumoto (matz at nws119) - - * sub(), gsub()で, マッチした文字列を$&, $1..$9でアクセスできるよ - うにした. 同時にマッチした部分文字列をコピーしておくように(元の - 文字列が変更されても状態を保存するため). - -Mon Jan 31 15:16:58 1994 Yukihiro Matsumoto (matz at nws119) - - * プライベートメソッドの仕様を変更. 今までは同じクラスのメソッドか - らしかアクセスできなかったが, サブクラスのメソッドからもアクセス - できるようにした(C++におけるprotected メンバ関数). - - * メソッドサーチのアルゴリズムを改善し, 10%程度の高速化を行なった. - - * 高速化. Cで記述されたメソッドを呼び出す時にはsetjmpを呼ばないよ - うにした. これでCメソッドを多用する場合には3倍程度高速になった. - -Fri Jan 28 15:44:04 1994 Yukihiro Matsumoto (matz at nws119) - - * sh-modeを元にruby-mode.elを作る. 演算子で終る, 2行に渡る文には対 - 応していないけど…. - -Thu Jan 27 11:35:19 1994 Yukihiro Matsumoto (matz at nws119) - - * freenode(): NODE_NILの解放忘れ. - - * 字句解析部のバグ修正(コメントの後の状態を戻し忘れ). - - * protect .. endのバグ修正. GC_LINKのネストが不正だった. - - * joinのバグ修正(使っているオブジェクトをfreeしていた). - - * splitのバグ修正(アルゴリズムがおかしかった). - - * fork()を追加. - -Wed Jan 26 17:09:56 1994 Yukihiro Matsumoto (matz at nws119) - - * ファイルテストメソッドの追加. - - * rb_autoexec(): クラスを初めてアクセスした時の挙動を制御できるよ - うにした. これでautoloadも実現できる. これにともないメソッド - unknownはなくなった. - -Tue Jan 25 15:51:36 1994 Yukihiro Matsumoto (matz at nws119) - - * Dbmクラス, Mathモジュールを作成. - - * -Iオプションでサーチパスに追加できるように. - - * サーチパスを変数$load_pathに設定できるように. - - * load(): ダイナミックロードを使えるようにした. - -Tue Jan 18 14:14:01 1994 Yukihiro Matsumoto (matz at nws119) - - * Comparable:"<=>" - - * Float,Fixnum:"**" - - * Array:sort - -Fri Jan 14 16:53:37 1994 Yukihiro Matsumoto (matz at nws119) - - * version 0.07 - - * メソッドに関するドキュメントを充実させた. - - * String:index(): 引数positionを増やした. - -Thu Jan 13 15:13:52 1994 Yukihiro Matsumoto (matz at nws119) - - * 未初期化の変数アクセスをなくした. - - * 無駄なhash tableのアロケーションを削除. - - * Purify'd(on Sun) - - * ~RE と ~STRのコンパイル時展開の抑制. - - * Sunへ移植. signal()の戻り値. RDataのbug修正. - - * parse.y: nlsルールを削除. - - * yylex(): 改行と符合の解析部分を変更. - - * missing/strftime.c: 移植用. - - * Time:strftime: その他のメソッドもstrftimeを利用するように. - - * メソッド再定義時にメソッドキャッシュをクリアする. - -Fri Jan 7 15:23:20 1994 Yukihiro Matsumoto (matz at nws119) - - * Float:coerce(): FixnumとFloat以外の引数を与えられるた時には例外 - を発生するように. - - * Stat: stat構造体の全てのメンバに対するアクセスメソッドを用意. - - * 未定義のクラス/モジュールへの参照がunknownメソッドを呼び出すよう - にした. - - * baseline - version 0.06. diff --git a/Makefile b/Makefile deleted file mode 100644 index 0908d49776..0000000000 --- a/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# -# Makefile - -# -# created at: Wed Aug 10 15:21:29 JST 1994 - -all:; @echo "You must run configure first." diff --git a/Makefile.in b/Makefile.in index 6296a5e650..3a88a991be 100644 --- a/Makefile.in +++ b/Makefile.in @@ -6,31 +6,28 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -DBM = @DBM@ +DBMCC = cc YACC = @YACC@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ -MAKEINFO = makeinfo CFLAGS = -g LDFLAGS = @STATIC@ $(CFLAGS) LIBS = @LIBS@ DEFS = @DEFS@ +MISSING = @LIBOBJS@ prefix = /usr/local binprefix = exec_prefix = $(prefix) bindir = $(exec_prefix)/bin -infodir = $(prefix)/info #### End of system configuration section. #### -.c.o: - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(DEFS) -I$(srcdir) -I$(srcdir)/lib $< - HDRS = defines.h \ dln.h \ + getopt.h \ ident.h \ io.h \ node.h \ @@ -40,47 +37,6 @@ HDRS = defines.h \ st.h \ version.h -SRCS = array.c \ - bignum.c \ - class.c \ - compar.c \ - dbm.c \ - dict.c \ - dir.c \ - dln.c \ - enum.c \ - error.c \ - etc.c \ - eval.c \ - file.c \ - fnmatch.c \ - gc.c \ - glob.c \ - gnuglob.c \ - inits.c \ - io.c \ - main.c \ - math.c \ - missing.c \ - numeric.c \ - object.c \ - pack.c \ - parse.y \ - process.c \ - random.c \ - range.c \ - re.c \ - regex.c \ - ruby.c \ - socket.c \ - sprintf.c \ - st.c \ - string.c \ - struct.c \ - time.c \ - variable.c \ - version.c - OBJS = array.o \ bignum.o \ class.o \ @@ -96,13 +52,14 @@ OBJS = array.o \ file.o \ fnmatch.o \ gc.o \ + getopt.o \ + getopt1.o \ glob.o \ gnuglob.o \ inits.o \ io.o \ main.o \ math.o \ - missing.o \ numeric.o \ object.o \ pack.o \ @@ -120,11 +77,9 @@ OBJS = array.o \ struct.o \ time.o \ variable.o \ - version.o - -DISTFILES = README NEWS TODO THANKS COPYING INSTALL \ -ChangeLog Makefile.in configure.in \ -$(HDRS) $(SRCS) configure + version.o \ + $(MISSING) \ + @ALLOCA@ PROGRAM = ruby @@ -140,56 +95,80 @@ $(bindir)/$(PROGRAM): $(PROGRAM) install: $(bindir)/$(PROGRAM) clean:; @rm -f $(OBJS) - -realclean:; @rm -f $(OBJS) @rm -f core ruby *~ config.status Makefile +.c.o: + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< dbm.o:dbm.c - $(CC) -c $(DBM) $(CFLAGS) $(CPPFLAGS) $(DEFS) -I$(srcdir) -I$(srcdir)/lib dbm.c + $(DBMCC) $(CFLAGS) $(CPPFLAGS) -c dbm.c + +alloca.o: missing/alloca.c + $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/alloca.c + +memmove.o: missing/memmove.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/memmove.c + +mkdir.o: missing/mkdir.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/mkdir.c + +strerror.o: missing/strerror.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/strerror.c + +strdup.o: missing/strdup.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/strdup.c + +strftime.o: missing/strftime.c + $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/strftime.c + +strstr.o: missing/strstr.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/strstr.c + +strtol.o: missing/strtol.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/strtol.c + +strtoul.o: missing/strtoul.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/strtoul.c # Prevent GNU make v3 from overflowing arg limit on SysV. .NOEXPORT: ### -parse.o : parse.y ruby.h defines.h env.h node.h st.h ident.h regex.h +parse.o : parse.y ruby.h defines.h config.h env.h node.h st.h ident.h regex.h ### -array.o : array.c ruby.h defines.h -bignum.o : bignum.c ruby.h defines.h -class.o : class.c ruby.h defines.h env.h node.h st.h -compar.o : compar.c ruby.h defines.h -dbm.o : dbm.c ruby.h defines.h -dict.o : dict.c ruby.h defines.h st.h -dir.o : dir.c ruby.h defines.h -dln.o : dln.c defines.h dln.h -enum.o : enum.c ruby.h defines.h -error.o : error.c ruby.h defines.h env.h -etc.o : etc.c ruby.h defines.h -eval.o : eval.c ruby.h defines.h ident.h env.h node.h st.h -file.o : file.c ruby.h defines.h io.h -fnmatch.o : fnmatch.c fnmatch.h -gc.o : gc.c ruby.h defines.h env.h st.h -glob.o : glob.c ruby.h defines.h fnmatch.h -gnuglob.o : gnuglob.c fnmatch.h -inits.o : inits.c ruby.h defines.h -io.o : io.c ruby.h defines.h io.h -main.o : main.c -math.o : math.c ruby.h defines.h -missing.o : missing.c ruby.h defines.h missing/memmove.c missing/strerror.c \ - missing/strtoul.c missing/strftime.c missing/strstr.c missing/getopt.h missing/getopt.c \ - missing/getopt1.c missing/mkdir.c -numeric.o : numeric.c ruby.h defines.h -object.o : object.c ruby.h defines.h env.h node.h st.h -pack.o : pack.c ruby.h defines.h -process.o : process.c ruby.h defines.h st.h -random.o : random.c ruby.h defines.h -range.o : range.c ruby.h defines.h -re.o : re.c ruby.h defines.h re.h regex.h -regex.o : regex.c defines.h regex.h -ruby.o : ruby.c ruby.h defines.h re.h regex.h missing/getopt.h -socket.o : socket.c ruby.h defines.h -sprintf.o : sprintf.c ruby.h defines.h -st.o : st.c st.h -string.o : string.c ruby.h defines.h re.h regex.h -struct.o : struct.c ruby.h defines.h env.h -time.o : time.c ruby.h defines.h -variable.o : variable.c ruby.h defines.h env.h node.h ident.h st.h -version.o : version.c ruby.h defines.h version.h +array.o: array.c ruby.h config.h defines.h +bignum.o: bignum.c ruby.h config.h defines.h +class.o: class.c ruby.h config.h defines.h env.h node.h st.h +compar.o: compar.c ruby.h config.h defines.h +dbm.o: dbm.c ruby.h config.h defines.h +dict.o: dict.c ruby.h config.h defines.h st.h +dir.o: dir.c ruby.h config.h defines.h +dln.o: dln.c defines.h dln.h +enum.o: enum.c ruby.h config.h defines.h +error.o: error.c ruby.h config.h defines.h env.h +etc.o: etc.c ruby.h config.h defines.h +eval.o: eval.c ruby.h config.h defines.h ident.h env.h node.h st.h +file.o: file.c ruby.h config.h defines.h io.h +fnmatch.o: fnmatch.c fnmatch.h +gc.o: gc.c ruby.h config.h defines.h env.h st.h +glob.o: glob.c ruby.h config.h defines.h fnmatch.h +gnuglob.o: gnuglob.c fnmatch.h +inits.o: inits.c ruby.h config.h defines.h +io.o: io.c ruby.h config.h defines.h io.h +main.o: main.c +math.o: math.c ruby.h config.h defines.h +numeric.o: numeric.c ruby.h config.h defines.h env.h +object.o: object.c ruby.h config.h defines.h env.h node.h st.h +pack.o: pack.c ruby.h config.h defines.h +process.o: process.c ruby.h config.h defines.h st.h +random.o: random.c ruby.h config.h defines.h +range.o: range.c ruby.h config.h defines.h +re.o: re.c ruby.h config.h defines.h re.h regex.h +regex.o: regex.c defines.h regex.h +ruby.o: ruby.c ruby.h config.h defines.h re.h regex.h getopt.h +socket.o: socket.c ruby.h config.h defines.h io.h +sprintf.o: sprintf.c ruby.h config.h defines.h +st.o: st.c st.h +string.o: string.c ruby.h config.h defines.h re.h regex.h +struct.o: struct.c ruby.h config.h defines.h env.h +time.o: time.c ruby.h config.h defines.h +variable.o: variable.c ruby.h config.h defines.h env.h node.h ident.h st.h +version.o: version.c ruby.h config.h defines.h version.h diff --git a/ToDo b/ToDo index cd572cf40a..5422040f45 100644 --- a/ToDo +++ b/ToDo @@ -1,4 +1,7 @@ -* trからBSDコードを取り除く +* format機能 +* here document +* perlのようなsetuid check +* trからBSDコードを取り除く(またはcopyrightをはっきりさせる) * 適切なsignal handling * dlnのCOFF対応 * rubyで定義する変数hookの実現 diff --git a/array.c b/array.c index 78de801bab..6ecadb50cc 100644 --- a/array.c +++ b/array.c @@ -3,7 +3,7 @@ array.c - $Author: matz $ - $Date: 1994/11/22 01:22:30 $ + $Date: 1994/12/06 09:29:47 $ created at: Fri Aug 6 09:46:12 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -94,7 +94,7 @@ assoc_new(elm1, elm2) } static VALUE -Fary_new(class) +Sary_new(class) VALUE class; { NEWOBJ(ary, struct RArray); @@ -132,7 +132,7 @@ astore(ary, idx, val) } VALUE -Fary_push(ary, item) +ary_push(ary, item) struct RArray *ary; VALUE item; { @@ -150,7 +150,7 @@ Fary_append(ary, item) } VALUE -Fary_pop(ary) +ary_pop(ary) struct RArray *ary; { if (ary->len == 0) return Qnil; @@ -158,7 +158,7 @@ Fary_pop(ary) } VALUE -Fary_shift(ary) +ary_shift(ary) struct RArray *ary; { VALUE top; @@ -175,7 +175,7 @@ Fary_shift(ary) } VALUE -Fary_unshift(ary, item) +ary_unshift(ary, item) struct RArray *ary; { VALUE top; @@ -474,7 +474,7 @@ Fary_length(ary) } static VALUE -Fary_clone(ary) +ary_clone(ary) struct RArray *ary; { VALUE ary2 = ary_new2(ary->len); @@ -497,16 +497,14 @@ ary_join(ary, sep) if (ary->len == 0) return str_new(0, 0); if (TYPE(ary->ptr[0]) == T_STRING) - result = Fstr_clone(ary->ptr[0]); + result = str_clone(ary->ptr[0]); else result = obj_as_string(ary->ptr[0]); for (i=1; ilen; i++) { - int need_free = 1; tmp = ary->ptr[i]; switch (TYPE(tmp)) { case T_STRING: - need_free = 0; break; case T_ARRAY: tmp = ary_join(tmp, sep); @@ -516,7 +514,6 @@ ary_join(ary, sep) } if (sep) str_cat(result, sep->ptr, sep->len); str_cat(result, RSTRING(tmp)->ptr, RSTRING(tmp)->len); - if (need_free == 1) obj_free(tmp); } return result; @@ -547,7 +544,7 @@ Fary_to_s(ary) return str; } -static VALUE +VALUE Fary_print_on(ary, port) struct RArray *ary; VALUE port; @@ -556,9 +553,9 @@ Fary_print_on(ary, port) for (i=0; ilen; i++) { if (OFS && i>1) { - Fio_write(port, OFS); + io_write(port, OFS); } - Fio_write(port, ary->ptr[i]); + io_write(port, ary->ptr[i]); } return port; } @@ -573,7 +570,7 @@ Fary_inspect(ary) VALUE str; char *p; - ary = (struct RArray*)Fary_clone(ary); + ary = (struct RArray*)ary_clone(ary); len = ary->len; for (i=0; ilen; i++) { if (rb_funcall(ary->ptr[i], eq, 1, item)) { - return 1; + return TRUE; } } - return 0; + return FALSE; } static VALUE @@ -880,9 +877,9 @@ Fary_diff(ary1, ary2) 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]); + if (Fary_includes(ary2, ary1->ptr[i])) continue; + if (Fary_includes(ary3, ary1->ptr[i])) continue; + ary_push(ary3, ary1->ptr[i]); } return ary3; } @@ -897,9 +894,9 @@ Fary_and(ary1, ary2) 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]); + if (Fary_includes(ary2, ary1->ptr[i]) + && !Fary_includes(ary3, ary1->ptr[i])) { + ary_push(ary3, ary1->ptr[i]); } } return ary3; @@ -912,16 +909,19 @@ Fary_or(ary1, ary2) VALUE ary3; int i; - if (TYPE(ary2) != T_ARRAY) return Fary_plus(ary1, ary2); + if (TYPE(ary2) != T_ARRAY) { + if (Fary_includes(ary1, ary2)) return (VALUE)ary1; + else 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]); + if (!Fary_includes(ary3, ary1->ptr[i])) + ary_push(ary3, ary1->ptr[i]); } for (i=0; ilen; i++) { - if (!ary_contains(ary3, ary2->ptr[i])) - Fary_push(ary3, ary2->ptr[i]); + if (!Fary_includes(ary3, ary2->ptr[i])) + ary_push(ary3, ary2->ptr[i]); } return ary3; } @@ -934,7 +934,7 @@ Init_Array() C_Array = rb_define_class("Array", C_Object); rb_include_module(C_Array, M_Enumerable); - rb_define_single_method(C_Array, "new", Fary_new, 0); + rb_define_single_method(C_Array, "new", Sary_new, 0); rb_define_method(C_Array, "to_s", Fary_to_s, 0); rb_define_method(C_Array, "_inspect", Fary_inspect, 0); rb_define_method(C_Array, "to_a", Fary_to_a, 0); @@ -946,17 +946,17 @@ Init_Array() rb_define_method(C_Array, "[]", Fary_aref, -2); rb_define_method(C_Array, "[]=", Fary_aset, -2); rb_define_method(C_Array, "<<", Fary_append, 1); - rb_define_method(C_Array, "push", Fary_push, 1); - rb_define_method(C_Array, "pop", Fary_pop, 0); - rb_define_method(C_Array, "shift", Fary_shift, 0); - rb_define_method(C_Array, "unshift", Fary_unshift, 1); + rb_define_method(C_Array, "push", ary_push, 1); + rb_define_method(C_Array, "pop", ary_pop, 0); + rb_define_method(C_Array, "shift", ary_shift, 0); + rb_define_method(C_Array, "unshift", ary_unshift, 1); rb_define_method(C_Array, "each", Fary_each, 0); rb_define_method(C_Array, "each_index", Fary_each_index, 0); rb_define_method(C_Array, "length", Fary_length, 0); rb_define_alias(C_Array, "size", "length"); rb_define_method(C_Array, "index", Fary_index, 1); rb_define_method(C_Array, "indexes", Fary_indexes, -2); - rb_define_method(C_Array, "clone", Fary_clone, 0); + rb_define_method(C_Array, "clone", ary_clone, 0); rb_define_method(C_Array, "join", Fary_join, -2); rb_define_method(C_Array, "reverse", Fary_reverse, 0); rb_define_method(C_Array, "sort", Fary_sort, 0); @@ -964,6 +964,7 @@ Init_Array() rb_define_method(C_Array, "delete_if", Fary_delete_if, 0); rb_define_method(C_Array, "clear", Fary_clear, 0); rb_define_method(C_Array, "fill", Fary_fill, -2); + rb_define_method(C_Array, "includes", Fary_includes, 1); rb_define_method(C_Array, "assoc", Fary_assoc, 1); rb_define_method(C_Array, "rassoc", Fary_rassoc, 1); diff --git a/bignum.c b/bignum.c index ce18befc92..9490b36672 100644 --- a/bignum.c +++ b/bignum.c @@ -3,7 +3,7 @@ bignum.c - $Author: matz $ - $Date: 1994/11/01 08:27:46 $ + $Date: 1994/12/06 09:29:49 $ created at: Fri Jun 10 00:48:55 JST 1994 ************************************************/ @@ -44,7 +44,7 @@ bignew_1(class, len, sign) #define bignew(len,sign) bignew_1(C_Bignum,len,sign) static VALUE -Fbig_new(class, y) +Sbig_new(class, y) VALUE class; struct RBignum *y; { @@ -53,7 +53,7 @@ Fbig_new(class, y) } VALUE -Fbig_clone(x) +big_clone(x) struct RBignum *x; { VALUE z = bignew_1(CLASS_OF(x), x->len, x->sign); @@ -286,7 +286,7 @@ big2str(x, base) Fail("bignum cannot treat base %d", base); } - t = Fbig_clone(x); + t = big_clone(x); ds = BDIGITS(t); ss = str_new(0, j); s = RSTRING(ss)->ptr; @@ -406,7 +406,7 @@ static VALUE Fbig_uminus(x) struct RBignum *x; { - VALUE z = Fbig_clone(x); + VALUE z = big_clone(x); RBIGNUM(z)->sign = !x->sign; @@ -572,7 +572,7 @@ bigdivmod(x, y, div, mod) xds = BDIGITS(x); if (ny == 1) { dd = yds[0]; - z = Fbig_clone(x); + z = big_clone(x); zds = BDIGITS(z); t2 = 0; i = nx; while(i--) { @@ -592,7 +592,7 @@ bigdivmod(x, y, div, mod) if (nx==ny) zds[nx+1] = 0; while (!yds[ny-1]) ny--; if ((dd = BIGRAD/(yds[ny-1]+1)) != 1) { - y = (struct RBignum*)Fbig_clone(y); + y = (struct RBignum*)big_clone(y); tds = BDIGITS(y); j = 0; num = 0; @@ -649,7 +649,7 @@ bigdivmod(x, y, div, mod) zds[j] = q; } while (--j >= ny); if (div) { /* move quotient down in z */ - *div = Fbig_clone(z); + *div = big_clone(z); zds = BDIGITS(*div); j = (nx==ny ? nx+2 : nx+1) - ny; for (i = 0;i < j;i++) zds[i] = zds[i+ny]; @@ -657,7 +657,7 @@ bigdivmod(x, y, div, mod) *div = bignorm(*div); } if (mod) { /* just normalize remainder */ - *mod = Fbig_clone(z); + *mod = big_clone(z); if (dd) { zds = BDIGITS(*mod); t2 = 0; i = ny; @@ -763,11 +763,11 @@ Fbig_and(x, y) } if (!y->sign) { - y = (struct RBignum*)Fbig_clone(y); + y = (struct RBignum*)big_clone(y); big_2comp(y); } if (!x->sign) { - x = (struct RBignum*)Fbig_clone(x); + x = (struct RBignum*)big_clone(x); big_2comp(x); } if (x->len > y->len) { @@ -814,11 +814,11 @@ Fbig_or(x, y) } if (!y->sign) { - y = (struct RBignum*)Fbig_clone(y); + y = (struct RBignum*)big_clone(y); big_2comp(y); } if (!x->sign) { - x = (struct RBignum*)Fbig_clone(x); + x = (struct RBignum*)big_clone(x); big_2comp(x); } if (x->len > y->len) { @@ -866,11 +866,11 @@ Fbig_xor(x, y) } if (!y->sign) { - y = (struct RBignum*)Fbig_clone(y); + y = (struct RBignum*)big_clone(y); big_2comp(y); } if (!x->sign) { - x = (struct RBignum*)Fbig_clone(x); + x = (struct RBignum*)big_clone(x); big_2comp(x); } if (x->len > y->len) { @@ -907,7 +907,7 @@ static VALUE Fbig_neg(x) struct RBignum *x; { - VALUE z = Fbig_clone(x); + VALUE z = big_clone(x); UINT i = x->len; USHORT *ds = BDIGITS(z); @@ -998,7 +998,7 @@ Fbig_aref(x, y) if (!x->sign) { if (s1 >= x->len) return INT2FIX(1); - x = (struct RBignum*)Fbig_clone(x); + x = (struct RBignum*)big_clone(x); big_2comp(x); } else { @@ -1065,7 +1065,7 @@ Fbig_abs(x) struct RBignum *x; { if (!x->sign) { - x = (struct RBignum*)Fbig_clone(x); + x = (struct RBignum*)big_clone(x); x->sign = 1; } return (VALUE)x; @@ -1074,7 +1074,7 @@ Fbig_abs(x) Init_Bignum() { C_Bignum = rb_define_class("Bignum", C_Integer); - rb_define_single_method(C_Bignum, "new", Fbig_new, 1); + rb_define_single_method(C_Bignum, "new", Sbig_new, 1); rb_define_method(C_Bignum, "to_s", Fbig_to_s, 0); rb_define_method(C_Bignum, "coerce", Fbig_coerce, 1); diff --git a/bring b/bring deleted file mode 100644 index 771cd04542..0000000000 --- a/bring +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/bash - -function fdeject() { - if type eject > /dev/null 2>&1; then - eject - fi -} - -function copyfiles() { - for d in . missing sample; do - if [ ! -d $1/$d ];then mkdir $1/$d; fi - for i in $d/*;do - case $i in - */ruby|*.o|*~|*.sav|*.bak|*.orig|*/core|"#"*);; - */Change*|*/config.status|*/Makefile);; - *) - if [ -f $i ]; then - if [ $i -nt $1/$i -o ! -f $1/$i ];then - echo copying $i - cp -p $i $1/$i - fi - fi;; - esac - done - done -} - -if [ ! -d exchange ]; then mkdir exchange; fi - -if [ "$1" = "in" ]; then - - cd exchange - - mread ruby.tgz ruby.tgz - fdeject - tar zxf ruby.tgz - rm -f ruby.tgz - cd ruby - - cp ChangeLog ../../Changes - copyfiles ../.. - -else -# bring out - if [ ! -d exchange/ruby ]; then mkdir exchange/ruby; fi - - cp -p ChangeLog exchange/ruby - copyfiles exchange/ruby - - cd exchange - (cd ruby; make realclean) - - tar zcf ruby.tgz ruby - mwrite ruby.tgz ruby.tgz - fdeject - rm -f ruby.tgz -fi diff --git a/config.status b/config.status deleted file mode 100755 index 7bdc7b26ed..0000000000 --- a/config.status +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# Generated automatically by configure. -# Run this file to recreate the current configuration. -# This directory was configured as follows, -# on host dyna: -# -# ./configure - -for arg -do - case "$arg" in - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo running ${CONFIG_SHELL-/bin/sh} ./configure - exec ${CONFIG_SHELL-/bin/sh} ./configure ;; - *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;; - esac -done - -trap 'rm -f Makefile; exit 1' 1 3 15 -PROGS='ruby' -CC='gcc' -CPP='gcc -E' -DBM='-fpcc-struct-return' -STATIC='' -YACC='bison -y' -INSTALL='/usr/bin/install -c' -INSTALL_PROGRAM='$(INSTALL)' -INSTALL_DATA='$(INSTALL) -m 644' -ALLOCA='' -LIBS=' -lm -ldbm' -srcdir='.' -DEFS=' -DHAVE_UNISTD_H=1 -DHAVE_SYSCALL_H=1 -DHAVE_A_OUT_H=1 -DDIRENT=1 -DGETGROUPS_T=gid_t -DRETSIGTYPE=void -DHAVE_GETOPT_LONG=1 -DHAVE_MEMMOVE=1 -DHAVE_STRERROR=1 -DHAVE_STRTOL=1 -DHAVE_STRTOUL=1 -DHAVE_STRDUP=1 -DHAVE_SETENV=1 -DHAVE_KILLPG=1 -DHAVE_MKDIR=1 -DHAVE_STRFTIME=1 -DHAVE_ALLOCA_H=1' -prefix='' -exec_prefix='' -prsub='' -extrasub='' - -top_srcdir=$srcdir - -CONFIG_FILES=${CONFIG_FILES-"Makefile"} -for file in .. ${CONFIG_FILES}; do if test "x$file" != x..; then - srcdir=$top_srcdir - # Remove last slash and all that follows it. Not all systems have dirname. - dir=`echo $file|sed 's%/[^/][^/]*$%%'` - if test "$dir" != "$file"; then - test "$top_srcdir" != . && srcdir=$top_srcdir/$dir - test ! -d $dir && mkdir $dir - fi - echo creating $file - rm -f $file - echo "# Generated automatically from `echo $file|sed 's|.*/||'`.in by configure." > $file - sed -e " -$prsub -$extrasub -s%@PROGS@%$PROGS%g -s%@CC@%$CC%g -s%@CPP@%$CPP%g -s%@DBM@%$DBM%g -s%@STATIC@%$STATIC%g -s%@YACC@%$YACC%g -s%@INSTALL@%$INSTALL%g -s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_DATA@%$INSTALL_DATA%g -s%@ALLOCA@%$ALLOCA%g -s%@LIBS@%$LIBS%g -s%@srcdir@%$srcdir%g -s%@DEFS@%$DEFS% -" $top_srcdir/${file}.in >> $file -fi; done - - -exit 0 diff --git a/configure.in b/configure.in index bd841c434c..9eec8ad999 100644 --- a/configure.in +++ b/configure.in @@ -4,10 +4,6 @@ PROGS="ruby" AC_SUBST(PROGS)dnl AC_PROG_CC AC_GCC_TRADITIONAL -if test "$GCC" = 1 ; then - DBM=-fpcc-struct-return -fi -AC_SUBST(DBM)dnl if test "$HOSTTYPE" = sparc; then if test "$GCC" = 1 ; then STATIC=-static @@ -24,22 +20,23 @@ AC_HAVE_HEADERS(unistd.h syscall.h a.out.h) AC_DIR_HEADER AC_GETGROUPS_T AC_RETSIGTYPE -AC_HAVE_FUNCS(getopt_long memmove strerror strtoul strdup strstr) -AC_HAVE_FUNCS(setenv fmod killpg mkdir strftime socket random) +AC_REPLACE_FUNCS(memmove mkdir strerror strftime) +AC_REPLACE_FUNCS(strstr strtol strtoul strdup) +AC_HAVE_FUNCS(fmod killpg socket random) AC_HAVE_FUNCS(wait4 waitpid syscall getcwd) +AC_HAVE_FUNCS(setruid seteuid setreuid) +AC_HAVE_FUNCS(setrgid setegid setregid) AC_HAVE_FUNCS(getpriority sigprocmask) -if echo $DEFS | grep "HAVE_SETENV" 2>&1 > /dev/null; then - : -else - AC_HAVE_FUNCS(putenv) -fi -if echo $DEFS | grep "HAVE_STRFTIME" 2>&1 > /dev/null; then - : -else - AC_TIMEZONE - AC_COMPILE_CHECK([daylight], [], - [extern int daylight; int i = daylight;], AC_DEFINE(HAVE_DAYLIGHT)) -fi +AC_FUNC_CHECK(setenv, [], AC_HAVE_FUNCS(putenv)) + +case "$LIBOBJS" in + *) ;; + *strftime*) + AC_TIMEZONE + AC_COMPILE_CHECK([daylight], [], + [extern int daylight; int i = daylight;], AC_DEFINE(HAVE_DAYLIGHT));; +esac + AC_ALLOCA AC_WORDS_BIGENDIAN AC_ST_BLKSIZE @@ -63,3 +60,4 @@ AC_HAVE_LIBRARY(m, [LIBS="$LIBS -lm"]) AC_HAVE_LIBRARY(dbm, [LIBS="$LIBS -ldbm"]) AC_HAVE_LIBRARY(socket, [LIBS="$LIBS -lsocket"]) AC_OUTPUT(Makefile) +mv confdefs.h config.h diff --git a/dbm.c b/dbm.c index 0e310f64d3..16ca0880f7 100644 --- a/dbm.c +++ b/dbm.c @@ -3,7 +3,7 @@ dbm.c - $Author: matz $ - $Date: 1994/10/14 10:00:51 $ + $Date: 1994/12/06 09:29:52 $ created at: Mon Jan 24 15:59:52 JST 1994 Copyright (C) 1994 Yukihiro Matsumoto @@ -50,7 +50,7 @@ free_dbm(dbmp) } static VALUE -Fdbm_open(class, args) +Sdbm_open(class, args) VALUE class, args; { VALUE file, vmode; @@ -302,7 +302,7 @@ Fdbm_keys(obj) ary = ary_new(); GetDBM(obj, dbm); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - Fary_push(ary, str_new(key.dptr, key.dsize)); + ary_push(ary, str_new(key.dptr, key.dsize)); } return ary; @@ -320,7 +320,7 @@ Fdbm_values(obj) GetDBM(obj, dbm); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - Fary_push(ary, str_new(val.dptr, val.dsize)); + ary_push(ary, str_new(val.dptr, val.dsize)); } return ary; @@ -377,8 +377,8 @@ Fdbm_to_a(obj) ary = ary_new(); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - Fary_push(ary, assoc_new(str_new(key.dptr, key.dsize), - str_new(val.dptr, val.dsize))); + ary_push(ary, assoc_new(str_new(key.dptr, key.dsize), + str_new(val.dptr, val.dsize))); } return ary; @@ -389,7 +389,7 @@ Init_DBM() C_DBM = rb_define_class("DBM", C_Object); rb_include_module(C_DBM, M_Enumerable); - rb_define_single_method(C_DBM, "open", Fdbm_open, -2); + rb_define_single_method(C_DBM, "open", Sdbm_open, -2); rb_define_method(C_DBM, "close", Fdbm_close, 0); rb_define_method(C_DBM, "[]", Fdbm_fetch, 1); rb_define_method(C_DBM, "[]=", Fdbm_store, 2); diff --git a/defines.h b/defines.h index 60e72b89ec..d5e86072af 100644 --- a/defines.h +++ b/defines.h @@ -16,9 +16,9 @@ #define EUC #undef SJIS -/* define USE_DLN to load object file(.o). */ #ifdef HAVE_A_OUT_H +/* define USE_DLN to load object file(.o). */ #define USE_DLN #ifdef USE_DLN #define LIBC_NAME "libc.a" diff --git a/dict.c b/dict.c index 4dab1a8947..74bfc22e03 100644 --- a/dict.c +++ b/dict.c @@ -3,7 +3,7 @@ dict.c - $Author: matz $ - $Date: 1994/11/01 08:27:49 $ + $Date: 1994/12/06 09:29:53 $ created at: Mon Nov 22 18:51:18 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -37,8 +37,8 @@ rb_hash(a, mod) #define ASSOC_KEY(a) RARRAY(a)->ptr[0] #define ASSOC_VAL(a) RARRAY(a)->ptr[1] -VALUE -Fdic_new(class) +static VALUE +Sdic_new(class) VALUE class; { int i, max; @@ -50,6 +50,12 @@ Fdic_new(class) return (VALUE)dic; } +VALUE +dic_new() +{ + return Sdic_new(C_Dict); +} + static VALUE Fdic_clone(dic) struct RDict *dic; @@ -216,7 +222,7 @@ static dic_to_a(key, value, ary) VALUE key, value, ary; { - Fary_push(ary, assoc_new(key, value)); + ary_push(ary, assoc_new(key, value)); return ST_CONTINUE; } @@ -269,19 +275,14 @@ static VALUE Fdic_to_s(dic) VALUE dic; { - VALUE str; - - dic = Fdic_to_a(dic); - str = Fary_to_s(dic); - - return str; + return Fary_to_s(Fdic_to_a(dic)); } static dic_keys(key, value, ary) VALUE key, value, ary; { - Fary_push(ary, key); + ary_push(ary, key); return ST_CONTINUE; } @@ -301,7 +302,7 @@ static dic_values(key, value, ary) VALUE key, value, ary; { - Fary_push(ary, key); + ary_push(ary, key); return ST_CONTINUE; } @@ -542,7 +543,7 @@ Init_Dict() rb_include_module(C_Dict, M_Enumerable); - rb_define_single_method(C_Dict, "new", Fdic_new, 0); + rb_define_single_method(C_Dict, "new", Sdic_new, 0); rb_define_method(C_Dict,"clone", Fdic_clone, 0); diff --git a/dir.c b/dir.c index 0e9b3b44ba..f139c40554 100644 --- a/dir.c +++ b/dir.c @@ -3,7 +3,7 @@ dir.c - $Author: matz $ - $Date: 1994/10/14 06:19:12 $ + $Date: 1994/12/06 09:29:55 $ created at: Wed Jan 5 09:51:01 JST 1994 Copyright (C) 1994 Yukihiro Matsumoto @@ -47,7 +47,7 @@ free_dir(dir) } static VALUE -Fdir_open(dir_class, dirname) +Sdir_open(dir_class, dirname) VALUE dir_class; struct RString *dirname; { @@ -146,7 +146,7 @@ Fdir_close(dir) char *getenv(); static VALUE -Fdir_chdir(obj, args) +Sdir_chdir(obj, args) VALUE obj, args; { VALUE path; @@ -171,7 +171,7 @@ Fdir_chdir(obj, args) } static VALUE -Fdir_getwd(dir) +Sdir_getwd(dir) VALUE dir; { extern char *getwd(); @@ -187,7 +187,7 @@ Fdir_getwd(dir) } static VALUE -Fdir_chroot(dir, path) +Sdir_chroot(dir, path) VALUE dir, path; { Check_Type(path, T_STRING); @@ -199,7 +199,7 @@ Fdir_chroot(dir, path) } static VALUE -Fdir_mkdir(obj, args) +Sdir_mkdir(obj, args) VALUE obj, args; { VALUE path, vmode; @@ -220,7 +220,7 @@ Fdir_mkdir(obj, args) } static VALUE -Fdir_rmdir(obj, dir) +Sdir_rmdir(obj, dir) VALUE obj; struct RString *dir; { @@ -240,7 +240,7 @@ Init_Dir() rb_include_module(C_Dir, M_Enumerable); - rb_define_single_method(C_Dir, "open", Fdir_open, 1); + rb_define_single_method(C_Dir, "open", Sdir_open, 1); rb_define_method(C_Dir,"each", Fdir_each, 0); rb_define_method(C_Dir,"rewind", Fdir_rewind, 0); @@ -248,14 +248,14 @@ Init_Dir() rb_define_method(C_Dir,"seek", Fdir_seek, 1); rb_define_method(C_Dir,"close", Fdir_close, 0); - rb_define_single_method(C_Dir,"chdir", Fdir_chdir, -2); - rb_define_single_method(C_Dir,"getwd", Fdir_getwd, 0); - rb_define_single_method(C_Dir,"pwd", Fdir_getwd, 0); - rb_define_single_method(C_Dir,"chroot", Fdir_chroot, 1); - rb_define_single_method(C_Dir,"mkdir", Fdir_mkdir, -2); - rb_define_single_method(C_Dir,"rmdir", Fdir_rmdir, 1); - rb_define_single_method(C_Dir,"delete", Fdir_rmdir, 1); - rb_define_single_method(C_Dir,"unlink", Fdir_rmdir, 1); + rb_define_single_method(C_Dir,"chdir", Sdir_chdir, -2); + rb_define_single_method(C_Dir,"getwd", Sdir_getwd, 0); + rb_define_single_method(C_Dir,"pwd", Sdir_getwd, 0); + rb_define_single_method(C_Dir,"chroot", Sdir_chroot, 1); + rb_define_single_method(C_Dir,"mkdir", Sdir_mkdir, -2); + rb_define_single_method(C_Dir,"rmdir", Sdir_rmdir, 1); + rb_define_single_method(C_Dir,"delete", Sdir_rmdir, 1); + rb_define_single_method(C_Dir,"unlink", Sdir_rmdir, 1); id_dir = rb_intern("dir"); } diff --git a/dln.c b/dln.c index 861ebfb634..b15c01bce1 100644 --- a/dln.c +++ b/dln.c @@ -13,6 +13,7 @@ #include #include #include +#include "config.h" #include "defines.h" #include "dln.h" #include diff --git a/enum.c b/enum.c index 1a52a20c67..c6866b425f 100644 --- a/enum.c +++ b/enum.c @@ -3,7 +3,7 @@ enum.c - $Author: matz $ - $Date: 1994/08/12 04:47:18 $ + $Date: 1994/12/06 09:29:56 $ created at: Fri Oct 1 15:15:19 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -27,7 +27,7 @@ enum_grep(i, arg) VALUE i, *arg; { if (rb_funcall(arg[0], id_match, 1, i)) { - Fary_push(arg[1], i); + ary_push(arg[1], i); } } @@ -85,7 +85,7 @@ enum_find_all(i, tmp) VALUE i; { if (rb_yield(i)) { - Fary_push(tmp, i); + ary_push(tmp, i); } } @@ -109,7 +109,7 @@ enum_collect(i, tmp) retval = rb_yield(i); if (retval) { - Fary_push(tmp, retval); + ary_push(tmp, retval); } } @@ -129,7 +129,7 @@ static void enum_reverse(i, tmp) VALUE i, tmp; { - Fary_unshift(tmp, i); + ary_unshift(tmp, i); } static VALUE @@ -148,7 +148,7 @@ static void enum_all(i, ary) VALUE i, ary; { - Fary_push(ary, i); + ary_push(ary, i); } static VALUE diff --git a/etc.c b/etc.c index 7fd4dd39aa..501c9106d3 100644 --- a/etc.c +++ b/etc.c @@ -3,7 +3,7 @@ etc.c - $Author: matz $ - $Date: 1994/11/01 08:27:53 $ + $Date: 1994/12/06 09:29:57 $ created at: Tue Mar 22 18:39:19 JST 1994 ************************************************/ @@ -119,7 +119,7 @@ setup_group(grp) mem = ary_new(); tbl = grp->gr_mem; while (*tbl) { - Fary_push(mem, str_new2(*tbl)); + ary_push(mem, str_new2(*tbl)); tbl++; } return struct_new("group", diff --git a/eval.c b/eval.c index 84356cf1a0..fac68662c9 100644 --- a/eval.c +++ b/eval.c @@ -3,7 +3,7 @@ eval.c - $Author: matz $ - $Date: 1994/11/22 01:22:33 $ + $Date: 1994/12/06 09:29:59 $ created at: Thu Jun 10 14:22:17 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -999,11 +999,8 @@ rb_eval(node) case NODE_HASH: { - extern VALUE C_Dict; - extern VALUE Fdic_new(); NODE *list; - - VALUE hash = Fdic_new(C_Dict); + VALUE hash = dic_new(); VALUE key, val; list = node->nd_head; @@ -1321,7 +1318,7 @@ rb_fail(mesg) errstr = mesg; } else { - errstr = Fstr_clone(mesg); + errstr = str_clone(mesg); str_cat(errstr, "\n", 1); } } @@ -1965,7 +1962,6 @@ find_file(file) sep = str_new2(":"); vpath = ary_join(rb_load_path, sep); path = RSTRING(vpath)->ptr; - obj_free(sep); sep = Qnil; } else { @@ -1975,8 +1971,6 @@ find_file(file) found = dln_find_file(file, path); if (found == Qnil) Fail("No such file to load -- %s", file); - if (vpath) obj_free(vpath); - return found; } @@ -2010,7 +2004,6 @@ Fload(obj, fname) } } #endif - PUSH_TAG(); DUP_ENV(); PUSH_CLASS(); @@ -2051,12 +2044,12 @@ Frequire(obj, fname) file = find_file(fname->ptr); p = RARRAY(rb_loadfiles)->ptr; - pend = p+ RARRAY(rb_loadfiles)->len; + pend = p + RARRAY(rb_loadfiles)->len; while (p < pend) { Check_Type(*p, T_STRING); if (strcmp(RSTRING(*p)->ptr, file) == 0) return FALSE; } - Fary_push(rb_loadfiles, str_new2(file)); + ary_push(rb_loadfiles, str_new2(file)); Fload(obj, fname); return TRUE; @@ -2083,11 +2076,11 @@ addpath(path) while (*p) { while (*p == RUBY_LIB_SEP) p++; if (s = strchr(p, RUBY_LIB_SEP)) { - Fary_push(rb_load_path, str_new(p, (int)(s-p))); + ary_push(rb_load_path, str_new(p, (int)(s-p))); p = s + 1; } else { - Fary_push(rb_load_path, str_new2(p)); + ary_push(rb_load_path, str_new2(p)); break; } } diff --git a/file.c b/file.c index 463965547c..1fc344778e 100644 --- a/file.c +++ b/file.c @@ -4,7 +4,7 @@ file.c - $Author: matz $ - $Date: 1994/11/22 01:22:34 $ + $Date: 1994/12/06 09:30:00 $ created at: Mon Nov 15 12:24:34 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -255,7 +255,7 @@ cache_stat(path, st) } static VALUE -Ffile_stat(obj, fname) +Sfile_stat(obj, fname) VALUE obj; struct RString *fname; { @@ -269,7 +269,7 @@ Ffile_stat(obj, fname) } static VALUE -Ffile_stat2(obj) +Ffile_stat(obj) VALUE obj; { OpenFile *fptr; @@ -283,7 +283,7 @@ Ffile_stat2(obj) } static VALUE -Ffile_lstat(obj, fname) +Sfile_lstat(obj, fname) VALUE obj; struct RString *fname; { @@ -297,7 +297,7 @@ Ffile_lstat(obj, fname) } static VALUE -Ffile_lstat2(obj) +Ffile_lstat(obj) VALUE obj; { OpenFile *fptr; @@ -705,7 +705,7 @@ Ftest_sticky(obj, fname) } static VALUE -Ffile_type(obj, fname) +Sfile_type(obj, fname) VALUE obj; struct RString *fname; { @@ -750,7 +750,7 @@ Ffile_type(obj, fname) } static VALUE -Ffile_atime(obj, fname) +Sfile_atime(obj, fname) VALUE obj; struct RString *fname; { @@ -762,7 +762,7 @@ Ffile_atime(obj, fname) } static VALUE -Ffile_atime2(obj) +Ffile_atime(obj) VALUE obj; { OpenFile *fptr; @@ -776,7 +776,7 @@ Ffile_atime2(obj) } static VALUE -Ffile_mtime(obj, fname) +Sfile_mtime(obj, fname) VALUE obj; struct RString *fname; { @@ -788,7 +788,7 @@ Ffile_mtime(obj, fname) } static VALUE -Ffile_mtime2(obj) +Ffile_mtime(obj) VALUE obj; { OpenFile *fptr; @@ -802,7 +802,7 @@ Ffile_mtime2(obj) } static VALUE -Ffile_ctime(obj, fname) +Sfile_ctime(obj, fname) VALUE obj; struct RString *fname; { @@ -814,7 +814,7 @@ Ffile_ctime(obj, fname) } static VALUE -Ffile_ctime2(obj) +Ffile_ctime(obj) VALUE obj; { OpenFile *fptr; @@ -837,7 +837,7 @@ chmod_internal(path, mode) } static VALUE -Ffile_chmod(obj, args) +Sfile_chmod(obj, args) VALUE obj, args; { VALUE vmode; @@ -853,7 +853,7 @@ Ffile_chmod(obj, args) } static VALUE -Ffile_chmod2(obj, vmode) +Ffile_chmod(obj, vmode) VALUE obj, vmode; { OpenFile *fptr; @@ -882,7 +882,7 @@ chown_internal(path, args) } static VALUE -Ffile_chown(obj, args) +Sfile_chown(obj, args) VALUE obj, args; { VALUE o, g, rest; @@ -907,7 +907,7 @@ Ffile_chown(obj, args) return INT2FIX(n); } -Ffile_chown2(obj, owner, group) +Ffile_chown(obj, owner, group) VALUE obj, owner, group; { OpenFile *fptr; @@ -932,7 +932,7 @@ utime_internal(path, tvp) } static VALUE -Ffile_utime(obj, args) +Sfile_utime(obj, args) VALUE obj, args; { VALUE atime, mtime, rest; @@ -949,7 +949,7 @@ Ffile_utime(obj, args) } static VALUE -Ffile_link(obj, from, to) +Sfile_link(obj, from, to) VALUE obj; struct RString *from, *to; { @@ -962,7 +962,7 @@ Ffile_link(obj, from, to) } static VALUE -Ffile_symlink(obj, from, to) +Sfile_symlink(obj, from, to) VALUE obj; struct RString *from, *to; { @@ -974,7 +974,8 @@ Ffile_symlink(obj, from, to) return TRUE; } -Ffile_readlink(obj, path) +static VALUE +Sfile_readlink(obj, path) VALUE obj; struct RString *path; { @@ -998,7 +999,7 @@ unlink_internal(path) } static VALUE -Ffile_unlink(obj, args) +Sfile_unlink(obj, args) VALUE obj; struct RArray *args; { @@ -1009,7 +1010,7 @@ Ffile_unlink(obj, args) } static VALUE -Ffile_rename(obj, from, to) +Sfile_rename(obj, from, to) VALUE obj; struct RString *from, *to; { @@ -1023,7 +1024,7 @@ Ffile_rename(obj, from, to) } static VALUE -Ffile_umask(argc, argv) +Sfile_umask(argc, argv) int argc; VALUE *argv; { @@ -1044,7 +1045,7 @@ Ffile_umask(argc, argv) } static VALUE -Ffile_truncate(obj, path, len) +Sfile_truncate(obj, path, len) VALUE obj, len; struct RString *path; { @@ -1056,7 +1057,7 @@ Ffile_truncate(obj, path, len) } static VALUE -Ffile_truncate2(obj, len) +Ffile_truncate(obj, len) VALUE obj, len; { OpenFile *fptr; @@ -1125,40 +1126,40 @@ Init_File() C_File = rb_define_class("File", C_IO); - rb_define_single_method(C_File, "stat", Ffile_stat, 1); - rb_define_single_method(C_File, "lstat", Ffile_lstat, 1); - rb_define_single_method(C_File, "type", Ffile_type, 1); + rb_define_single_method(C_File, "stat", Sfile_stat, 1); + rb_define_single_method(C_File, "lstat", Sfile_lstat, 1); + rb_define_single_method(C_File, "type", Sfile_type, 1); - rb_define_single_method(C_File, "atime", Ffile_atime, 1); - rb_define_single_method(C_File, "mtime", Ffile_mtime, 1); - rb_define_single_method(C_File, "ctime", Ffile_ctime, 1); + rb_define_single_method(C_File, "atime", Sfile_atime, 1); + rb_define_single_method(C_File, "mtime", Sfile_mtime, 1); + rb_define_single_method(C_File, "ctime", Sfile_ctime, 1); - rb_define_single_method(C_File, "utime", Ffile_utime, -2); - rb_define_single_method(C_File, "chmod", Ffile_chmod, -2); - rb_define_single_method(C_File, "chown", Ffile_chown, -2); + rb_define_single_method(C_File, "utime", Sfile_utime, -2); + rb_define_single_method(C_File, "chmod", Sfile_chmod, -2); + rb_define_single_method(C_File, "chown", Sfile_chown, -2); - rb_define_single_method(C_File, "link", Ffile_link, 2); - rb_define_single_method(C_File, "symlink", Ffile_symlink, 2); - rb_define_single_method(C_File, "readlink", Ffile_readlink, 1); + rb_define_single_method(C_File, "link", Sfile_link, 2); + rb_define_single_method(C_File, "symlink", Sfile_symlink, 2); + rb_define_single_method(C_File, "readlink", Sfile_readlink, 1); - rb_define_single_method(C_File, "unlink", Ffile_unlink, -2); - rb_define_single_method(C_File, "delete", Ffile_unlink, -2); - rb_define_single_method(C_File, "rename", Ffile_rename, 2); - rb_define_single_method(C_File, "umask", Ffile_umask, -1); - rb_define_single_method(C_File, "truncate", Ffile_truncate, 2); + rb_define_single_method(C_File, "unlink", Sfile_unlink, -2); + rb_define_single_method(C_File, "delete", Sfile_unlink, -2); + rb_define_single_method(C_File, "rename", Sfile_rename, 2); + rb_define_single_method(C_File, "umask", Sfile_umask, -1); + rb_define_single_method(C_File, "truncate", Sfile_truncate, 2); rb_include_module(CLASS_OF(C_File), M_FileTest); - rb_define_method(C_File, "stat", Ffile_stat2, 0); - rb_define_method(C_File, "lstat", Ffile_lstat2, 0); + rb_define_method(C_File, "stat", Ffile_stat, 0); + rb_define_method(C_File, "lstat", Ffile_lstat, 0); - rb_define_method(C_File, "atime", Ffile_atime2, 0); - rb_define_method(C_File, "mtime", Ffile_mtime2, 0); - rb_define_method(C_File, "ctime", Ffile_ctime2, 0); + rb_define_method(C_File, "atime", Ffile_atime, 0); + rb_define_method(C_File, "mtime", Ffile_mtime, 0); + rb_define_method(C_File, "ctime", Ffile_ctime, 0); - rb_define_method(C_File, "chmod", Ffile_chmod2, 1); - rb_define_method(C_File, "chown", Ffile_chown2, 2); - rb_define_method(C_File, "truncate", Ffile_truncate2, 1); + rb_define_method(C_File, "chmod", Ffile_chmod, 1); + rb_define_method(C_File, "chown", Ffile_chown, 2); + rb_define_method(C_File, "truncate", Ffile_truncate, 1); rb_define_method(C_File, "tell", Ffile_tell, 0); rb_define_method(C_File, "seek", Ffile_seek, 2); diff --git a/fnmatch.c b/fnmatch.c index 6a8b574902..0847f5cafb 100644 --- a/fnmatch.c +++ b/fnmatch.c @@ -16,6 +16,7 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "config.h" #include #include "fnmatch.h" diff --git a/gc.c b/gc.c index 0dcaae74d6..5c1d27e553 100644 --- a/gc.c +++ b/gc.c @@ -3,7 +3,7 @@ gc.c - $Author: matz $ - $Date: 1994/11/01 08:27:58 $ + $Date: 1994/12/06 09:30:02 $ created at: Tue Oct 5 09:44:46 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -110,7 +110,7 @@ Cambridge, MA 02138 static int dont_gc; VALUE -Fgc_enable() +Sgc_enable() { int old = dont_gc; @@ -119,7 +119,7 @@ Fgc_enable() } VALUE -Fgc_disable() +Sgc_disable() { int old = dont_gc; @@ -130,12 +130,14 @@ Fgc_disable() #include #include -static Fgc_begin() +static +Fgc_begin() { return Qnil; } -static Fgc_end() +static +Fgc_end() { return Qnil; } @@ -234,14 +236,19 @@ newobj() } VALUE -newdata(size) - UINT size; +data_new(datap, dfree, dmark) + VALUE *datap; + void (*dfree)(); + void (*dmark)(); { extern VALUE C_Data; struct RData *data = (struct RData*)newobj(); OBJSETUP(data, C_Data, T_DATA); - data->data = xmalloc(size); + data->data = datap; + data->dfree = dfree; + data->dmark = dmark; + return (VALUE)data; } @@ -445,6 +452,8 @@ gc_mark(obj) #define MIN_FREE_OBJ 512 +static void obj_free(); + static void gc_sweep() { @@ -509,6 +518,7 @@ freemethod(key, body) return ST_CONTINUE; } +static void obj_free(obj) struct RBasic *obj; { @@ -632,7 +642,7 @@ Init_GC() { M_GC = rb_define_module("GC"); rb_define_single_method(M_GC, "start", gc, 0); - rb_define_single_method(M_GC, "enable", Fgc_enable, 0); - rb_define_single_method(M_GC, "disable", Fgc_disable, 0); + rb_define_single_method(M_GC, "enable", Sgc_enable, 0); + rb_define_single_method(M_GC, "disable", Sgc_disable, 0); rb_define_method(M_GC, "garbage_collect", gc, 0); } diff --git a/getopt.c b/getopt.c new file mode 100644 index 0000000000..bfc4013b29 --- /dev/null +++ b/getopt.c @@ -0,0 +1,660 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu + before changing it! + + Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "config.h" + +#include + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +#include +#include +#endif /* GNU C library. */ + + +#ifndef __STDC__ +#define const +#endif + +/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a + long-named option. Because this is not POSIX.2 compliant, it is + being phased out. */ +#define GETOPT_COMPAT + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg = 0; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +int optind = 0; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return EOF with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +#ifdef __GNU_LIBRARY__ +#include +#define my_index strchr +#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n)) +#else + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +char *getenv (); + +static char * +my_index (string, chr) + char *string; + int chr; +{ + while (*string) + { + if (*string == chr) + return string; + string++; + } + return 0; +} + +static void +my_bcopy (from, to, size) + char *from, *to; + int size; +{ + int i; + for (i = 0; i < size; i++) + to[i] = from[i]; +} +#endif /* GNU C library. */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +static void +exchange (argv) + char **argv; +{ + int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *); + char **temp = (char **) malloc (nonopts_size); + + /* Interchange the two blocks of data in ARGV. */ + + my_bcopy (&argv[first_nonopt], temp, nonopts_size); + my_bcopy (&argv[last_nonopt], &argv[first_nonopt], + (optind - last_nonopt) * sizeof (char *)); + my_bcopy (temp, &argv[first_nonopt + optind - last_nonopt], nonopts_size); + + free(temp); + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns `EOF'. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (argc, argv, optstring, longopts, longind, long_only) + int argc; + char *const *argv; + const char *optstring; + const struct option *longopts; + int *longind; + int long_only; +{ + int option_index; + + optarg = 0; + + /* Initialize the internal data when the first call is made. + Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + if (optind == 0) + { + first_nonopt = last_nonopt = optind = 1; + + nextchar = NULL; + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (getenv ("POSIXLY_CORRECT") != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + } + + if (nextchar == NULL || *nextchar == '\0') + { + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Now skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc + && (argv[optind][0] != '-' || argv[optind][1] == '\0') +#ifdef GETOPT_COMPAT + && (longopts == NULL + || argv[optind][0] != '+' || argv[optind][1] == '\0') +#endif /* GETOPT_COMPAT */ + ) + optind++; + last_nonopt = optind; + } + + /* Special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if ((argv[optind][0] != '-' || argv[optind][1] == '\0') +#ifdef GETOPT_COMPAT + && (longopts == NULL + || argv[optind][0] != '+' || argv[optind][1] == '\0') +#endif /* GETOPT_COMPAT */ + ) + { + if (ordering == REQUIRE_ORDER) + return EOF; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Start decoding its characters. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + if (longopts != NULL + && ((argv[optind][0] == '-' + && (argv[optind][1] == '-' || long_only)) +#ifdef GETOPT_COMPAT + || argv[optind][0] == '+' +#endif /* GETOPT_COMPAT */ + )) + { + const struct option *p; + char *s = nextchar; + int exact = 0; + int ambig = 0; + const struct option *pfound = NULL; + int indfound = 0; + extern int strncmp(); + + while (*s && *s != '=') + s++; + + /* Test all options for either exact match or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; + p++, option_index++) + if (!strncmp (p->name, nextchar, s - nextchar)) + { + if (s - nextchar == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous\n", + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*s) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = s + 1; + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + "%s: option `--%s' doesn't allow an argument\n", + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + "%s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, "%s: option `%s' requires an argument\n", + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' +#ifdef GETOPT_COMPAT + || argv[optind][0] == '+' +#endif /* GETOPT_COMPAT */ + || my_index (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, "%s: unrecognized option `--%s'\n", + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, "%s: unrecognized option `%c%s'\n", + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + return '?'; + } + } + + /* Look at and handle the next option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (opterr) + { + if (c < 040 || c >= 0177) + fprintf (stderr, "%s: unrecognized option, character code 0%o\n", + argv[0], c); + else + fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c); + } + return '?'; + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = 0; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + fprintf (stderr, "%s: option `-%c' requires an argument\n", + argv[0], c); + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (argc, argv, optstring) + int argc; + char *const *argv; + const char *optstring; +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == EOF) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/getopt.h b/getopt.h new file mode 100644 index 0000000000..de027434f7 --- /dev/null +++ b/getopt.h @@ -0,0 +1,128 @@ +/* Declarations for getopt. + Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef _GETOPT_H +#define _GETOPT_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ +#if __STDC__ + const char *name; +#else + char *name; +#endif + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +enum _argtype +{ + no_argument, + required_argument, + optional_argument +}; + +#if __STDC__ +#if defined(__GNU_LIBRARY__) +/* Many other libraries have conflicting prototypes for getopt, with + differences in the consts, in stdlib.h. To avoid compilation + errors, only prototype getopt for the GNU C library. */ +extern int getopt (int argc, char *const *argv, const char *shortopts); +#else /* not __GNU_LIBRARY__ */ +extern int getopt (); +#endif /* not __GNU_LIBRARY__ */ +extern int getopt_long (int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind); +extern int getopt_long_only (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind); + +/* Internal only. Users should not call this directly. */ +extern int _getopt_internal (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind, + int long_only); +#else /* not __STDC__ */ +extern int getopt (); +extern int getopt_long (); +extern int getopt_long_only (); + +extern int _getopt_internal (); +#endif /* not __STDC__ */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GETOPT_H */ diff --git a/getopt1.c b/getopt1.c new file mode 100644 index 0000000000..7f824232d7 --- /dev/null +++ b/getopt1.c @@ -0,0 +1,162 @@ +/* Getopt for GNU. + Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include "config.h" + +#ifdef LIBC +/* For when compiled as part of the GNU C library. */ +#include +#endif + +#include "getopt.h" + +#ifndef __STDC__ +#define const +#endif + +#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC) +#include +#else /* STDC_HEADERS or __GNU_LIBRARY__ */ +char *getenv (); +#endif /* STDC_HEADERS or __GNU_LIBRARY__ */ + +#if !defined (NULL) +#define NULL 0 +#endif + +int +getopt_long (argc, argv, options, long_options, opt_index) + int argc; + char *const *argv; + const char *options; + const struct option *long_options; + int *opt_index; +{ + return _getopt_internal (argc, argv, options, long_options, opt_index, 0); +} + +/* Like getopt_long, but '-' as well as '--' can indicate a long option. + If an option that starts with '-' (not '--') doesn't match a long option, + but does match a short option, it is parsed as a short option + instead. */ + +int +getopt_long_only (argc, argv, options, long_options, opt_index) + int argc; + char *const *argv; + const char *options; + const struct option *long_options; + int *opt_index; +{ + return _getopt_internal (argc, argv, options, long_options, opt_index, 1); +} + +#ifdef TEST + +#include + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static struct option long_options[] = + { + {"add", 1, 0, 0}, + {"append", 0, 0, 0}, + {"delete", 1, 0, 0}, + {"verbose", 0, 0, 0}, + {"create", 0, 0, 0}, + {"file", 1, 0, 0}, + {0, 0, 0, 0} + }; + + c = getopt_long (argc, argv, "abc:d:0123456789", + long_options, &option_index); + if (c == EOF) + break; + + switch (c) + { + case 0: + printf ("option %s", long_options[option_index].name); + if (optarg) + printf (" with arg %s", optarg); + printf ("\n"); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case 'd': + printf ("option d with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/gnuglob.c b/gnuglob.c index d3159bbabd..69af7b1618 100644 --- a/gnuglob.c +++ b/gnuglob.c @@ -19,6 +19,8 @@ Unix programs use to perform this function. I wrote this from scratch based on specifications for the pattern matching. --RMS. */ +#include "config.h" + #if defined (SHELL) # if defined (HAVE_STDLIB_H) # include diff --git a/io.c b/io.c index 979af6aa68..27563c2c6d 100644 --- a/io.c +++ b/io.c @@ -3,7 +3,7 @@ io.c - $Author: matz $ - $Date: 1994/11/22 01:22:36 $ + $Date: 1994/12/06 09:30:03 $ created at: Fri Oct 15 18:08:59 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -37,7 +37,7 @@ extern char *inplace; /* writing functions */ VALUE -Fio_write(obj, str) +io_write(obj, str) VALUE obj; struct RString *str; { @@ -74,7 +74,7 @@ static VALUE Fio_puts(obj, str) VALUE obj, str; { - Fio_write(obj, str); + io_write(obj, str); return obj; } @@ -691,13 +691,23 @@ Fprint(argc, argv) else { for (i=0; i0) { - Fio_write(rb_defout, OFS); + io_write(rb_defout, OFS); + } + switch (TYPE(argv[i])) { + case T_STRING: + io_write(rb_defout, argv[i]); + break; + case T_ARRAY: + Fary_print_on(argv[i], rb_defout); + break; + default: + rb_funcall(argv[i], id_print_on, 1, rb_defout); + break; } - rb_funcall(argv[i], id_print_on, 1, rb_defout); } } if (ORS) { - Fio_write(rb_defout, ORS); + io_write(rb_defout, ORS); } return Qnil; @@ -720,7 +730,7 @@ static VALUE Fprint_on(obj, port) VALUE obj, port; { - return Fio_write(port, obj); + return io_write(port, obj); } static VALUE @@ -738,7 +748,7 @@ prep_stdio(f, mode) return obj; } -static VALUE filename = Qnil, file = Qnil; +static VALUE filename, file; static int gets_lineno; static int init_p = 0, next_p = 0; @@ -764,7 +774,7 @@ next_argv() if (next_p == 1) { next_p = 0; if (RARRAY(Argv)->len > 0) { - filename = Fary_shift(Argv); + filename = ary_shift(Argv); fn = RSTRING(filename)->ptr; if (RSTRING(filename)->len == 1 && fn[0] == '-') { file = rb_stdin; @@ -795,7 +805,6 @@ next_argv() fclose(fr); goto retry; } - obj_free(str); fw = fopen(fn, "w"); fstat(fileno(fw), &st2); fchmod(fileno(fw), st.st_mode); @@ -861,7 +870,7 @@ Freadlines(obj) ary = ary_new(); while (line = Fgets(obj)) { - Fary_push(ary, line); + ary_push(ary, line); } return ary; @@ -895,8 +904,6 @@ rb_xstring(str) rb_syswait(fptr->pid); fptr->pid = 0; - obj_free(port); - return result; } @@ -1026,7 +1033,7 @@ Fselect(obj, args) GetOpenFile(RARRAY(read)->ptr[i], fptr); if (FD_ISSET(fileno(fptr->f), rp) || FD_ISSET(fileno(fptr->f), &pset)) { - Fary_push(list, RARRAY(read)->ptr[i]); + ary_push(list, RARRAY(read)->ptr[i]); } } } @@ -1036,10 +1043,10 @@ Fselect(obj, args) for (i=0; i< RARRAY(write)->len; i++) { GetOpenFile(RARRAY(write)->ptr[i], fptr); if (FD_ISSET(fileno(fptr->f), rp)) { - Fary_push(list, RARRAY(write)->ptr[i]); + ary_push(list, RARRAY(write)->ptr[i]); } else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), rp)) { - Fary_push(list, RARRAY(write)->ptr[i]); + ary_push(list, RARRAY(write)->ptr[i]); } } } @@ -1049,10 +1056,10 @@ Fselect(obj, args) for (i=0; i< RARRAY(except)->len; i++) { GetOpenFile(RARRAY(except)->ptr[i], fptr); if (FD_ISSET(fileno(fptr->f), rp)) { - Fary_push(list, RARRAY(except)->ptr[i]); + ary_push(list, RARRAY(except)->ptr[i]); } else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), rp)) { - Fary_push(list, RARRAY(except)->ptr[i]); + ary_push(list, RARRAY(except)->ptr[i]); } } } @@ -1266,9 +1273,15 @@ Farg_each_byte() } static VALUE -Farg_to_s() +Farg_filename() { - return str_new2("$ARGF"); + return filename; +} + +static VALUE +Farg_file() +{ + return file; } extern VALUE M_Enumerable; @@ -1307,10 +1320,6 @@ Init_IO() rb_define_variable("$/", &RS, Qnil, rb_check_str); rb_define_variable("$\\", &ORS, Qnil, rb_check_str); - rb_define_variable("$<", &filename, Qnil, rb_readonly_hook); - rb_define_variable("$FILENAME", &filename, Qnil, rb_readonly_hook); - rb_global_variable(&file); - rb_define_variable("$.", &lineno, Qnil, Qnil); rb_define_variable("$_", &rb_lastline, Qnil, Qnil); @@ -1329,7 +1338,7 @@ Init_IO() rb_define_alias(C_IO, "readlines", "to_a"); rb_define_method(C_IO, "read", Fio_read, -2); - rb_define_method(C_IO, "write", Fio_write, 1); + rb_define_method(C_IO, "write", io_write, 1); rb_define_method(C_IO, "gets", Fio_gets, 0); rb_define_alias(C_IO, "readline", "gets"); rb_define_method(C_IO, "getc", Fio_getc, 0); @@ -1355,6 +1364,7 @@ Init_IO() rb_define_variable("$>", &rb_defout, Qnil, io_defset); argf = obj_alloc(C_Object); + rb_define_variable("$<", &argf, Qnil, rb_readonly_hook); rb_define_variable("$ARGF", &argf, Qnil, rb_readonly_hook); rb_define_single_method(argf, "each", Farg_each, 0); @@ -1367,8 +1377,15 @@ Init_IO() rb_define_single_method(argf, "getc", Farg_getc, 0); rb_define_single_method(argf, "eof", Feof, 0); - rb_define_single_method(argf, "to_s", Farg_to_s, 0); + rb_define_single_method(argf, "to_s", Farg_filename, 0); + rb_define_single_method(argf, "filename", Farg_filename, 0); + rb_define_single_method(argf, "file", Farg_file, 0); rb_include_module(CLASS_OF(argf), M_Enumerable); + filename = str_new2("-"); + rb_define_variable("$FILENAME", &filename, Qnil, rb_readonly_hook); + file = rb_stdin; + rb_global_variable(&file); + Init_File(); } diff --git a/missing.c b/missing.c deleted file mode 100644 index cccadb494f..0000000000 --- a/missing.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Do all necessary includes here, so that we don't have to worry about - * overlapping includes in the files in missing.d. - */ - -#include -#include -#include -#include -#include - -#include "ruby.h" - -#ifndef __STDC__ -#define const -#endif /* !__STDC__ */ - -#ifdef STDC_HEADERS -#include -#endif - -#ifndef HAVE_MEMMOVE -#include "missing/memmove.c" -#endif - -#ifndef HAVE_STRERROR -#include "missing/strerror.c" -#endif - -#ifndef HAVE_STRTOUL -#include "missing/strtoul.c" -#endif - -#ifndef HAVE_STRFTIME -#include "missing/strftime.c" -#endif - -#ifndef HAVE_STRSTR -#include "missing/strstr.c" -#endif - -#ifndef HAVE_GETOPT_LONG -#include "missing/getopt.h" -#include "missing/getopt.c" -#include "missing/getopt1.c" -#endif - -#ifndef HAVE_MKDIR -#include "missing/mkdir.c" -#endif - -#ifndef HAVE_STRDUP -char * -strdup(str) - char *str; -{ - extern char *xmalloc(); - char *tmp; - int len = strlen(str) + 1; - - tmp = xmalloc(len); - if (tmp == NULL) return NULL; - memcpy(tmp, str, len); - - return tmp; -} -#endif diff --git a/missing/CVS/Entries b/missing/CVS/Entries deleted file mode 100644 index 2c02d6e353..0000000000 --- a/missing/CVS/Entries +++ /dev/null @@ -1,9 +0,0 @@ -/getopt.c/0.26/Wed Jun 1 23:41:18 1994 Mon Apr 18 12:30:25 1994// -/getopt.h/0.26/Wed Jun 1 23:41:18 1994 Mon Apr 18 12:30:25 1994// -/getopt1.c/0.26/Wed Jun 1 23:41:18 1994 Mon Apr 18 12:30:25 1994// -/memmove.c/0.26/Wed Jun 1 23:41:18 1994 Mon Apr 18 12:30:25 1994// -/mkdir.c/1.1/Wed Jun 1 23:41:18 1994 Wed Jun 1 23:38:35 1994// -/strerror.c/0.26/Wed Jun 1 23:41:18 1994 Mon Apr 18 12:30:25 1994// -/strftime.c/0.26/Wed Jun 1 23:41:19 1994 Mon Apr 18 12:30:25 1994// -/strtol.c/0.26/Wed Jun 1 23:41:19 1994 Mon Apr 18 12:30:25 1994// -/strtoul.c/0.26/Wed Jun 1 23:41:19 1994 Mon Apr 18 12:30:25 1994// diff --git a/missing/CVS/Repository b/missing/CVS/Repository deleted file mode 100644 index a7ac69cf13..0000000000 --- a/missing/CVS/Repository +++ /dev/null @@ -1 +0,0 @@ -/work/cvsroot/ruby/missing diff --git a/missing/alloca.c b/missing/alloca.c new file mode 100644 index 0000000000..6879618c8a --- /dev/null +++ b/missing/alloca.c @@ -0,0 +1,189 @@ +/* alloca -- (mostly) portable public-domain implementation -- D A Gwyn + + last edit: 86/05/30 rms + include config.h, since on VMS it renames some symbols. + Use xmalloc instead of malloc. + + This implementation of the PWB library alloca() function, + which is used to allocate space off the run-time stack so + that it is automatically reclaimed upon procedure exit, + was inspired by discussions with J. Q. Johnson of Cornell. + + It should work under any C implementation that uses an + actual procedure stack (as opposed to a linked list of + frames). There are some preprocessor constants that can + be defined when compiling for your specific system, for + improved efficiency; however, the defaults should be okay. + + The general concept of this implementation is to keep + track of all alloca()-allocated blocks, and reclaim any + that are found to be deeper in the stack than the current + invocation. This heuristic does not reclaim storage as + soon as it becomes invalid, but it will do so eventually. + + As a special case, alloca(0) reclaims storage without + allocating any. It is a good idea to use alloca(0) in + your main control loop, etc. to force garbage collection. +*/ +#ifndef lint +static char SCCSid[] = "@(#)alloca.c 1.1"; /* for the "what" utility */ +#endif + +#include "config.h" +#ifdef emacs +#ifdef static +/* actually, only want this if static is defined as "" + -- this is for usg, in which emacs must undefine static + in order to make unexec workable + */ +#ifndef STACK_DIRECTION +you +lose +-- must know STACK_DIRECTION at compile-time +#endif /* STACK_DIRECTION undefined */ +#endif /* static */ +#endif /* emacs */ + +#ifdef X3J11 +typedef void *pointer; /* generic pointer type */ +#else +typedef char *pointer; /* generic pointer type */ +#endif /* X3J11 */ + +#define NULL 0 /* null pointer constant */ + +extern void free(); +extern pointer xmalloc(); + +/* + Define STACK_DIRECTION if you know the direction of stack + growth for your system; otherwise it will be automatically + deduced at run-time. + + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown +*/ + +#ifndef STACK_DIRECTION +#define STACK_DIRECTION 0 /* direction unknown */ +#endif + +#if STACK_DIRECTION != 0 + +#define STACK_DIR STACK_DIRECTION /* known at compile-time */ + +#else /* STACK_DIRECTION == 0; need run-time code */ + +static int stack_dir; /* 1 or -1 once known */ +#define STACK_DIR stack_dir + +static void +find_stack_direction (/* void */) +{ + static char *addr = NULL; /* address of first + `dummy', once known */ + auto char dummy; /* to get stack address */ + + if (addr == NULL) + { /* initial entry */ + addr = &dummy; + + find_stack_direction (); /* recurse once */ + } + else /* second entry */ + if (&dummy > addr) + stack_dir = 1; /* stack grew upward */ + else + stack_dir = -1; /* stack grew downward */ +} + +#endif /* STACK_DIRECTION == 0 */ + +/* + An "alloca header" is used to: + (a) chain together all alloca()ed blocks; + (b) keep track of stack depth. + + It is very important that sizeof(header) agree with malloc() + alignment chunk size. The following default should work okay. +*/ + +#ifndef ALIGN_SIZE +#define ALIGN_SIZE sizeof(double) +#endif + +typedef union hdr +{ + char align[ALIGN_SIZE]; /* to force sizeof(header) */ + struct + { + union hdr *next; /* for chaining headers */ + char *deep; /* for stack depth measure */ + } h; +} header; + +/* + alloca( size ) returns a pointer to at least `size' bytes of + storage which will be automatically reclaimed upon exit from + the procedure that called alloca(). Originally, this space + was supposed to be taken from the current stack frame of the + caller, but that method cannot be made to work for some + implementations of C, for example under Gould's UTX/32. +*/ + +static header *last_alloca_header = NULL; /* -> last alloca header */ + +pointer +alloca (size) /* returns pointer to storage */ + unsigned size; /* # bytes to allocate */ +{ + auto char probe; /* probes stack depth: */ + register char *depth = &probe; + +#if STACK_DIRECTION == 0 + if (STACK_DIR == 0) /* unknown growth direction */ + find_stack_direction (); +#endif + + /* Reclaim garbage, defined as all alloca()ed storage that + was allocated from deeper in the stack than currently. */ + { + register header *hp; /* traverses linked list */ + + for (hp = last_alloca_header; hp != NULL;) + if (STACK_DIR > 0 && hp->h.deep > depth + || STACK_DIR < 0 && hp->h.deep < depth) + { + register header *np = hp->h.next; + + free ((pointer) hp); /* collect garbage */ + + hp = np; /* -> next header */ + } + else + break; /* rest are not deeper */ + + last_alloca_header = hp; /* -> last valid storage */ + } + + if (size == 0) + return NULL; /* no allocation required */ + + /* Allocate combined header + user data storage. */ + + { + register pointer new = xmalloc (sizeof (header) + size); + /* address of header */ + + ((header *)new)->h.next = last_alloca_header; + ((header *)new)->h.deep = depth; + + last_alloca_header = (header *)new; + + /* User storage begins just after header. */ + + return (pointer)((char *)new + sizeof(header)); + } +} + diff --git a/missing/getopt.c b/missing/getopt.c deleted file mode 100644 index bbf345c33c..0000000000 --- a/missing/getopt.c +++ /dev/null @@ -1,662 +0,0 @@ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published - by the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifdef GAWK -#include "config.h" -#endif - -#include - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include -#include -#endif /* GNU C library. */ - - -#ifndef __STDC__ -#define const -#endif - -/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a - long-named option. Because this is not POSIX.2 compliant, it is - being phased out. */ -#define GETOPT_COMPAT - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "getopt.h" - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *optarg = 0; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns EOF, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -int optind = 0; - -/* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - -static char *nextchar; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int opterr = 1; - -/* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return EOF with `optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER -} ordering; - -#ifdef __GNU_LIBRARY__ -#include -#define my_index strchr -#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n)) -#else - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -char *getenv (); - -static char * -my_index (string, chr) - char *string; - int chr; -{ - while (*string) - { - if (*string == chr) - return string; - string++; - } - return 0; -} - -static void -my_bcopy (from, to, size) - char *from, *to; - int size; -{ - int i; - for (i = 0; i < size; i++) - to[i] = from[i]; -} -#endif /* GNU C library. */ - -/* Handle permutation of arguments. */ - -/* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - -static int first_nonopt; -static int last_nonopt; - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -static void -exchange (argv) - char **argv; -{ - int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *); - char **temp = (char **) malloc (nonopts_size); - - /* Interchange the two blocks of data in ARGV. */ - - my_bcopy (&argv[first_nonopt], temp, nonopts_size); - my_bcopy (&argv[last_nonopt], &argv[first_nonopt], - (optind - last_nonopt) * sizeof (char *)); - my_bcopy (temp, &argv[first_nonopt + optind - last_nonopt], nonopts_size); - - free(temp); - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns `EOF'. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - -int -_getopt_internal (argc, argv, optstring, longopts, longind, long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; -{ - int option_index; - - optarg = 0; - - /* Initialize the internal data when the first call is made. - Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - if (optind == 0) - { - first_nonopt = last_nonopt = optind = 1; - - nextchar = NULL; - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (getenv ("POSIXLY_CORRECT") != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - } - - if (nextchar == NULL || *nextchar == '\0') - { - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; - - /* Now skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (optind < argc - && (argv[optind][0] != '-' || argv[optind][1] == '\0') -#ifdef GETOPT_COMPAT - && (longopts == NULL - || argv[optind][0] != '+' || argv[optind][1] == '\0') -#endif /* GETOPT_COMPAT */ - ) - optind++; - last_nonopt = optind; - } - - /* Special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; - - optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return EOF; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if ((argv[optind][0] != '-' || argv[optind][1] == '\0') -#ifdef GETOPT_COMPAT - && (longopts == NULL - || argv[optind][0] != '+' || argv[optind][1] == '\0') -#endif /* GETOPT_COMPAT */ - ) - { - if (ordering == REQUIRE_ORDER) - return EOF; - optarg = argv[optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Start decoding its characters. */ - - nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); - } - - if (longopts != NULL - && ((argv[optind][0] == '-' - && (argv[optind][1] == '-' || long_only)) -#ifdef GETOPT_COMPAT - || argv[optind][0] == '+' -#endif /* GETOPT_COMPAT */ - )) - { - const struct option *p; - char *s = nextchar; - int exact = 0; - int ambig = 0; - const struct option *pfound = NULL; - int indfound = 0; - extern int strncmp(); - - while (*s && *s != '=') - s++; - - /* Test all options for either exact match or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; - p++, option_index++) - if (!strncmp (p->name, nextchar, s - nextchar)) - { - if (s - nextchar == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, "%s: option `%s' is ambiguous\n", - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*s) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = s + 1; - else - { - if (opterr) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[optind - 1][0], pfound->name); - } - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, "%s: option `%s' requires an argument\n", - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-' -#ifdef GETOPT_COMPAT - || argv[optind][0] == '+' -#endif /* GETOPT_COMPAT */ - || my_index (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, "%s: unrecognized option `--%s'\n", - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, "%s: unrecognized option `%c%s'\n", - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - return '?'; - } - } - - /* Look at and handle the next option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++optind; - - if (temp == NULL || c == ':') - { - if (opterr) - { - if (c < 040 || c >= 0177) - fprintf (stderr, "%s: unrecognized option, character code 0%o\n", - argv[0], c); - else - fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c); - } - return '?'; - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = 0; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - fprintf (stderr, "%s: option `-%c' requires an argument\n", - argv[0], c); - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } - } - return c; - } -} - -int -getopt (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; -{ - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); -} - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == EOF) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/missing/getopt.h b/missing/getopt.h deleted file mode 100644 index de027434f7..0000000000 --- a/missing/getopt.h +++ /dev/null @@ -1,128 +0,0 @@ -/* Declarations for getopt. - Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published - by the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef _GETOPT_H -#define _GETOPT_H 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns EOF, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -extern int opterr; - -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -struct option -{ -#if __STDC__ - const char *name; -#else - char *name; -#endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct option'. */ - -enum _argtype -{ - no_argument, - required_argument, - optional_argument -}; - -#if __STDC__ -#if defined(__GNU_LIBRARY__) -/* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int getopt (int argc, char *const *argv, const char *shortopts); -#else /* not __GNU_LIBRARY__ */ -extern int getopt (); -#endif /* not __GNU_LIBRARY__ */ -extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); -extern int getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind); - -/* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind, - int long_only); -#else /* not __STDC__ */ -extern int getopt (); -extern int getopt_long (); -extern int getopt_long_only (); - -extern int _getopt_internal (); -#endif /* not __STDC__ */ - -#ifdef __cplusplus -} -#endif - -#endif /* _GETOPT_H */ diff --git a/missing/getopt1.c b/missing/getopt1.c deleted file mode 100644 index eb06338ab3..0000000000 --- a/missing/getopt1.c +++ /dev/null @@ -1,162 +0,0 @@ -/* Getopt for GNU. - Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc. - -This file is part of the libiberty library. -Libiberty is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -Libiberty is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifdef LIBC -/* For when compiled as part of the GNU C library. */ -#include -#endif - -#ifndef RUBY -#include "getopt.h" -#endif - -#ifndef __STDC__ -#define const -#endif - -#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC) -#include -#else /* STDC_HEADERS or __GNU_LIBRARY__ */ -char *getenv (); -#endif /* STDC_HEADERS or __GNU_LIBRARY__ */ - -#if !defined (NULL) -#define NULL 0 -#endif - -int -getopt_long (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - -#ifdef TEST - -#include - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == EOF) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/missing/strdup.c b/missing/strdup.c new file mode 100644 index 0000000000..2e1fe90bbd --- /dev/null +++ b/missing/strdup.c @@ -0,0 +1,25 @@ +/************************************************ + + strdup.c - + + $Author$ + $Date$ + created at: Wed Dec 7 15:34:01 JST 1994 + +************************************************/ +#include + +char * +strdup(str) + char *str; +{ + extern char *xmalloc(); + char *tmp; + int len = strlen(str) + 1; + + tmp = xmalloc(len); + if (tmp == NULL) return NULL; + memcpy(tmp, str, len); + + return tmp; +} diff --git a/missing/strftime.c b/missing/strftime.c index 4d3561c78c..313b9d00a1 100644 --- a/missing/strftime.c +++ b/missing/strftime.c @@ -35,16 +35,14 @@ * February 1994 */ -#ifndef RUBY +#include "config.h" + #include #include #include #include -#endif -#if defined(TM_IN_SYS_TIME) || ! defined(RUBY) #include #include -#endif /* defaults: season to taste */ #define SYSV_EXT 1 /* stuff in System V ascftime routine */ diff --git a/newver.rb b/newver.rb deleted file mode 100755 index 884e873ba4..0000000000 --- a/newver.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/local/bin/ruby -f = open("version.h", "r") -f.gets() -f.close - -if $_ =~ /"(\d+)\.(\d+)"/; - f = open("version.h", "w") - i = $2.to_i - if $ARGV[0] == "-f" - i += 1 - end - date = Time.now.strftime("%y/%m/%d") - printf("ruby - version %d.%0d (%s)\n", $1, i, date) - printf(f, "#define RUBY_VERSION \"%d.%0d\"\n", $1, i) - printf(f, "#define VERSION_DATE \"%s\"\n", date) - f.close -else - printf("match error - %s\n", $_) -end diff --git a/numeric.c b/numeric.c index 2c9ed8bc59..97037b8c99 100644 --- a/numeric.c +++ b/numeric.c @@ -3,7 +3,7 @@ numeric.c - $Author: matz $ - $Date: 1994/11/01 08:28:06 $ + $Date: 1994/12/06 09:30:05 $ created at: Fri Aug 13 18:33:09 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -22,7 +22,6 @@ VALUE C_Float; VALUE C_Integer; VALUE C_Fixnum; -extern VALUE C_Range; double big2dbl(); VALUE @@ -64,7 +63,7 @@ Fnum_dot2(left, right) { Need_Fixnum(left); Need_Fixnum(right); - return range_new(C_Range, left, right); + return range_new(left, right); } static VALUE @@ -768,7 +767,7 @@ Ffix_dot2(left, right) VALUE left, right; { Need_Fixnum(right); - return range_new(C_Range, left, right); + return range_new(left, right); } static VALUE @@ -885,7 +884,8 @@ Ffix_class(fix) return C_Fixnum; } -static Ffix_abs(fix) +static +Ffix_abs(fix) VALUE fix; { int i = FIX2INT(fix); diff --git a/object.c b/object.c index 19eab4a1bd..decb070dca 100644 --- a/object.c +++ b/object.c @@ -3,7 +3,7 @@ object.c - $Author: matz $ - $Date: 1994/11/01 08:28:07 $ + $Date: 1994/12/06 09:30:06 $ created at: Thu Jul 15 12:01:24 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -325,6 +325,7 @@ Fcls_export(argc, argv) VALUE *argv; { Fcls_export_internal(argc, argv, 0); + return Qnil; } static VALUE @@ -333,6 +334,7 @@ Fcls_unexport(argc, argv) VALUE *argv; { Fcls_export_internal(argc, argv, 1); + return Qnil; } static VALUE diff --git a/pack.c b/pack.c index fbedc6759d..af7f8c274d 100644 --- a/pack.c +++ b/pack.c @@ -3,7 +3,7 @@ pack.c - $Author: matz $ - $Date: 1994/10/14 06:19:34 $ + $Date: 1994/12/06 09:30:08 $ created at: Thu Feb 10 15:17:05 JST 1994 Copyright (C) 1994 Yukihiro Matsumoto @@ -529,7 +529,7 @@ Fpck_unpack(str, fmt) } case 'a': if (len > send - s) len = send - s; - Fary_push(ary, str_new(s, len)); + ary_push(ary, str_new(s, len)); s += len; break; @@ -541,7 +541,7 @@ Fpck_unpack(str, fmt) if (p[-1] == '*' || len > (send - s) * 8) len = (send - s) * 8; - Fary_push(ary, bitstr = str_new(0, len + 1)); + ary_push(ary, bitstr = str_new(0, len + 1)); t = RSTRING(bitstr)->ptr; for (i=0; i>= 1; @@ -560,7 +560,7 @@ Fpck_unpack(str, fmt) if (p[-1] == '*' || len > (send - s) * 8) len = (send - s) * 8; - Fary_push(ary, bitstr = str_new(0, len + 1)); + ary_push(ary, bitstr = str_new(0, len + 1)); t = RSTRING(bitstr)->ptr; for (i=0; i (send - s) * 2) len = (send - s) * 2; - Fary_push(ary, bitstr = str_new(0, len + 1)); + ary_push(ary, bitstr = str_new(0, len + 1)); t = RSTRING(bitstr)->ptr; for (i=0; i (send - s) * 2) len = (send - s) * 2; - Fary_push(ary, bitstr = str_new(0, len + 1)); + ary_push(ary, bitstr = str_new(0, len + 1)); t = RSTRING(bitstr)->ptr; for (i=0; i 0) { char c = *s++; - Fary_push(ary, INT2FIX(c)); + ary_push(ary, INT2FIX(c)); } break; @@ -627,7 +627,7 @@ Fpck_unpack(str, fmt) len = send - s; while (len-- > 0) { unsigned char c = *s++; - Fary_push(ary, INT2FIX(c)); + ary_push(ary, INT2FIX(c)); } break; @@ -638,7 +638,7 @@ Fpck_unpack(str, fmt) short tmp; memcpy(&tmp, s, sizeof(short)); s += sizeof(short); - Fary_push(ary, INT2FIX(tmp)); + ary_push(ary, INT2FIX(tmp)); } break; @@ -649,7 +649,7 @@ Fpck_unpack(str, fmt) unsigned short tmp; memcpy(&tmp, s, sizeof(unsigned short)); s += sizeof(unsigned short); - Fary_push(ary, INT2FIX(tmp)); + ary_push(ary, INT2FIX(tmp)); } break; @@ -660,7 +660,7 @@ Fpck_unpack(str, fmt) int tmp; memcpy(&tmp, s, sizeof(int)); s += sizeof(int); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -671,7 +671,7 @@ Fpck_unpack(str, fmt) unsigned int tmp; memcpy(&tmp, s, sizeof(unsigned int)); s += sizeof(unsigned int); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -682,7 +682,7 @@ Fpck_unpack(str, fmt) long tmp; memcpy(&tmp, s, sizeof(long)); s += sizeof(long); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -693,7 +693,7 @@ Fpck_unpack(str, fmt) unsigned long tmp; memcpy(&tmp, s, sizeof(unsigned long)); s += sizeof(unsigned long); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -705,7 +705,7 @@ Fpck_unpack(str, fmt) memcpy(&tmp, s, sizeof(short)); s += sizeof(short); tmp = ntohs(tmp); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -717,7 +717,7 @@ Fpck_unpack(str, fmt) memcpy(&tmp, s, sizeof(long)); s += sizeof(long); tmp = ntohl(tmp); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -729,7 +729,7 @@ Fpck_unpack(str, fmt) float tmp; memcpy(&tmp, s, sizeof(float)); s += sizeof(float); - Fary_push(ary, float_new((double)tmp)); + ary_push(ary, float_new((double)tmp)); } break; @@ -741,7 +741,7 @@ Fpck_unpack(str, fmt) double tmp; memcpy(&tmp, s, sizeof(double)); s += sizeof(double); - Fary_push(ary, float_new(tmp)); + ary_push(ary, float_new(tmp)); } break; @@ -753,7 +753,7 @@ Fpck_unpack(str, fmt) memcpy(&tmp, s, sizeof(short)); s += sizeof(short); tmp = vtohs(tmp); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -765,7 +765,7 @@ Fpck_unpack(str, fmt) memcpy(&tmp, s, sizeof(long)); s += sizeof(long); tmp = vtohl(tmp); - Fary_push(ary, int2inum(tmp)); + ary_push(ary, int2inum(tmp)); } break; @@ -812,7 +812,7 @@ Fpck_unpack(str, fmt) s += 2; } RSTRING(str)->len = total; - Fary_push(ary, str); + ary_push(ary, str); } break; diff --git a/parse.y b/parse.y index 1e3e3a9d5b..5fc35a5041 100644 --- a/parse.y +++ b/parse.y @@ -3,7 +3,7 @@ parse.y - $Author: matz $ - $Date: 1994/11/22 01:22:38 $ + $Date: 1994/12/06 09:30:09 $ created at: Fri May 28 18:02:42 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -1283,8 +1283,10 @@ parse_string(term) tokadd(c); } else { + int flags = EXPAND_B; + if (term != '"') flags |= LEAVE_BS; pushback(); - read_escape(LEAVE_BS | EXPAND_B); + read_escape(flags); } continue; } @@ -1364,9 +1366,9 @@ yylex() retry: switch (c = nextc()) { - case '\0': - case '\004': - case '\032': + case '\0': /* NUL */ + case '\004': /* ^D */ + case '\032': /* ^Z */ case -1: /* end of script. */ return 0; @@ -2983,10 +2985,14 @@ rb_class2name(class) Fail("0x%x is not a class/module", class); } - while (FL_TEST(class, FL_SINGLE)) { + if (FL_TEST(class, FL_SINGLE)) { class = (struct RClass*)class->super; } + while (TYPE(class) == T_ICLASS) { + class = (struct RClass*)class->super; + } + st_foreach(rb_class_tbl, id_find, class); if (find_ok) { return rb_id2name((ID)find_ok); diff --git a/process.c b/process.c index 32ef856e97..c4e46e0521 100644 --- a/process.c +++ b/process.c @@ -3,7 +3,7 @@ process.c - $Author: matz $ - $Date: 1994/11/01 08:28:14 $ + $Date: 1994/12/06 09:30:11 $ created at: Tue Aug 10 14:30:50 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -810,6 +810,38 @@ Fproc_setuid(obj, id) return INT2FIX(uid); } +static VALUE +Fproc_getgid(obj) + VALUE obj; +{ + int gid = getgid(); + return INT2FIX(gid); +} + +static VALUE +Fproc_setgid(obj, id) + VALUE obj, id; +{ + int gid; + + gid = NUM2INT(id); +#ifdef HAS_SETRGID + setrgid((GIDTYPE)gid); +#else +#ifdef HAVE_SETREGID + setregid(gid, -1); +#else + { + if (getegid() == gid) + setgid(gid); + else + Fail("getrgid not implemented"); + } +#endif +#endif + return INT2FIX(gid); +} + static VALUE Fproc_geteuid(obj) VALUE obj; @@ -822,11 +854,50 @@ static VALUE Fproc_seteuid(obj, euid) VALUE obj, euid; { - if (seteuid(NUM2INT(euid)) == -1) - rb_sys_fail(Qnil); +#ifdef HAVE_SETEUID + if (seteuid(NUM2INT(euid)) == -1) rb_sys_fail(Qnil); +#else +#ifdef HAVE_SETREUID + if (setreuid(-1, NUM2INT(euid)) == -1) rb_sys_fail(Qnil); +#else + euid = NUM2INT(euid); + if (euid == getuid()) + setuid(euid); + else + Fail("seteuid() not implemented"); +#endif +#endif return euid; } +static VALUE +Fproc_getegid(obj) + VALUE obj; +{ + int egid = getegid(); + return INT2FIX(egid); +} + +static VALUE +Fproc_setegid(obj, egid) + VALUE obj, egid; +{ +#ifdef HAVE_SETEGID + if (setegid(NUM2INT(egid)) == -1) rb_sys_fail(Qnil); +#else +#ifdef HAVE_SETREGID + if (setregid(-1, NUM2INT(egid)) == -1) rb_sys_fail(Qnil); +#else + egid = NUM2INT(egid); + if (egid == getgid()) + setgid(egid); + else + Fail("setegid() not implemented"); +#endif +#endif + return egid; +} + VALUE rb_readonly_hook(); VALUE M_Process; @@ -869,6 +940,10 @@ Init_process() rb_define_module_function(M_Process, "uid", Fproc_getuid, 0); rb_define_module_function(M_Process, "uid=", Fproc_setuid, 1); + rb_define_module_function(M_Process, "gid", Fproc_getgid, 0); + rb_define_module_function(M_Process, "gid=", Fproc_setgid, 1); rb_define_module_function(M_Process, "euid", Fproc_geteuid, 0); rb_define_module_function(M_Process, "euid=", Fproc_seteuid, 1); + rb_define_module_function(M_Process, "egid", Fproc_getegid, 0); + rb_define_module_function(M_Process, "egid=", Fproc_setegid, 1); } diff --git a/range.c b/range.c index 42a18c30ff..6274170522 100644 --- a/range.c +++ b/range.c @@ -3,7 +3,7 @@ range.c - $Author: matz $ - $Date: 1994/10/14 06:19:39 $ + $Date: 1994/12/06 09:30:12 $ created at: Thu Aug 19 17:46:47 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -17,8 +17,8 @@ VALUE C_Range; static ID next, eq; -VALUE -range_new(class, start, end) +static VALUE +Srng_new(class, start, end) VALUE class, start, end; { VALUE obj; @@ -35,6 +35,13 @@ range_new(class, start, end) return obj; } +VALUE +range_new(start, end) + VALUE start, end; +{ + return Srng_new(C_Range, start, end); +} + static VALUE Frng_match(rng, obj) VALUE rng, obj; @@ -142,6 +149,7 @@ Init_Range() { C_Range = rb_define_class("Range", C_Object); rb_include_module(C_Range, M_Enumerable); + rb_define_single_method(C_Range, "new", Srng_new, 2); rb_define_method(C_Range, "=~", Frng_match, 1); rb_define_method(C_Range, "each", Frng_each, 0); rb_define_method(C_Range, "start", Frng_start, 0); diff --git a/re.c b/re.c index 164f24b242..ce79c9093c 100644 --- a/re.c +++ b/re.c @@ -3,7 +3,7 @@ re.c - $Author: matz $ - $Date: 1994/11/01 08:28:21 $ + $Date: 1994/12/06 09:30:14 $ created at: Mon Aug 9 18:24:49 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -135,6 +135,9 @@ research(reg, str, start, ignorecase) { int result; + if (FL_TEST(reg, FL_USER0)) { /* case-flag set for the object */ + ignorecase = FL_TEST(reg, FL_USER1); /* case-flag */ + } if (ignorecase) reg->ptr->pat.translate = casetable; else @@ -149,10 +152,8 @@ research(reg, str, start, ignorecase) struct match *data; int beg, i; - obj = (struct RData*)newdata(sizeof(struct match)); - OBJSETUP(obj, C_Data, T_DATA); - obj->dfree = free_match; - data = (struct match*)DATA_PTR(obj); + data = ALLOC(struct match); + obj = (struct RData*)data_new(data, free_match, Qnil); data->len = str->len; data->ptr = ALLOC_N(char, str->len+1); @@ -350,29 +351,38 @@ Freg_match2(re) } static VALUE -Freg_compile(re, str) - VALUE re; - struct RString *str; +Sreg_new(argc, argv) + int argc; + VALUE *argv; { - Check_Type(str, T_STRING); - return regexp_new_1(re, str->ptr, str->ptr); -} + VALUE src, reg; -static VALUE -Freg_new(re, src) - VALUE re, src; -{ + if (argc == 0 || argc > 2) { + Fail("wrong # of argument"); + } + + src = argv[0]; switch (TYPE(src)) { case T_STRING: - return regexp_new_1(re, RREGEXP(src)->ptr, RREGEXP(src)->len); + reg = regexp_new_1(Qself, RREGEXP(src)->ptr, RREGEXP(src)->len); case T_REGEXP: - return regexp_new_1(re, RREGEXP(src)->str, RREGEXP(src)->len); + reg = regexp_new_1(Qself, RREGEXP(src)->str, RREGEXP(src)->len); default: - Check_Type(src, T_REGEXP); + Check_Type(src, T_STRING); } - /* not reached */ + + if (argc == 2) { + FL_SET(reg, FL_USER0); + if (argv[1]) { + FL_SET(reg, FL_USER1); + } + else { + FL_UNSET(reg, FL_USER1); + } + } + return Qnil; } @@ -431,8 +441,10 @@ re_regsub(str) } if (val == Qnil) return (VALUE)str; + if (p < e) { + str_cat(val, p, e-p); + } if (RSTRING(val)->len == 0) { - obj_free(val); /* free for cost */ return (VALUE)str; } return val; @@ -517,8 +529,8 @@ Init_Regexp() rb_define_variable("$=", &ignorecase, Qnil, Qnil); C_Regexp = rb_define_class("Regexp", C_Object); - rb_define_single_method(C_Regexp, "new", Freg_new, 1); - rb_define_single_method(C_Regexp, "compile", Freg_compile, 1); + rb_define_single_method(C_Regexp, "new", Sreg_new, -1); + rb_define_single_method(C_Regexp, "compile", Sreg_new, -1); rb_define_method(C_Regexp, "=~", Freg_match, 1); rb_define_method(C_Regexp, "~", Freg_match2, 0); diff --git a/regex.c b/regex.c index 58ef7f5d3c..e23d33eb11 100644 --- a/regex.c +++ b/regex.c @@ -25,6 +25,7 @@ On the other hand, if you compile with both -Dtest and -Dcanned you can run some tests we've already thought of. */ +#include "config.h" /* We write fatal error messages on standard error. */ #include diff --git a/ruby.c b/ruby.c index 0d53a7b1a9..cb5f8c68b6 100644 --- a/ruby.c +++ b/ruby.c @@ -3,7 +3,7 @@ ruby.c - $Author: matz $ - $Date: 1994/11/01 08:28:24 $ + $Date: 1994/12/06 09:30:15 $ created at: Tue Aug 10 12:47:31 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -18,11 +18,7 @@ #include #include -#ifdef HAVE_GETOPT_LONG -#include -#else -#include "missing/getopt.h" -#endif +#include "getopt.h" static int version, copyright; @@ -184,7 +180,7 @@ proc_options(argcp, argvp) break; case 'I': - Fary_unshift(rb_load_path, str_new2(optarg)); + ary_unshift(rb_load_path, str_new2(optarg)); break; default: @@ -427,6 +423,6 @@ ruby_init0(argc, argv, envp) rb_define_variable("$*", &Argv, Qnil, Qnil); Argv = ary_new2(argc); for (i=0; i < argc; i++) { - Fary_push(Argv, str_new2(argv[i])); + ary_push(Argv, str_new2(argv[i])); } } diff --git a/ruby.h b/ruby.h index 8e3b4c0c63..f513557b97 100644 --- a/ruby.h +++ b/ruby.h @@ -3,7 +3,7 @@ ruby.h - $Author: matz $ - $Date: 1994/10/14 06:19:44 $ + $Date: 1994/12/06 09:30:16 $ created at: Thu Jun 10 14:26:32 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -13,6 +13,7 @@ #ifndef RUBY_H #define RUBY_H +#include "config.h" #include "defines.h" #ifdef __STDC__ @@ -82,15 +83,6 @@ extern VALUE C_Data; #define CLASS_OF(obj) (FIXNUM_P(obj)?C_Fixnum: NIL_P(obj)?C_Nil:\ RBASIC(obj)->class) -#define FL_SINGLE 0x10 -#define FL_MARK 0x20 -#define FL_LITERAL 0x40 - -#define FL_ABLE(x) (!(FIXNUM_P(x)||NIL_P(x))) -#define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0) -#define FL_SET(x,f) if (FL_ABLE(x)) {RBASIC(x)->flags |= (f);} -#define FL_UNSET(x,f) if(FL_ABLE(x)){RBASIC(x)->flags &= ~(f);} - #define T_NIL 0x0 #define T_OBJECT 0x1 #define T_CLASS 0x2 @@ -180,6 +172,7 @@ struct RData { #define DATA_PTR(dta) (RDATA(dta)->data) +VALUE data_new(); VALUE rb_ivar_get_1(); VALUE rb_ivar_set_1(); @@ -191,11 +184,9 @@ VALUE rb_ivar_set_1(); } #define Make_Data_Struct(obj, iv, type, mark, free, sval) {\ - struct RData *_new_;\ - _new_ = (struct RData*)newdata(sizeof(type));\ - _new_->dmark = (void (*)())(mark);\ - _new_->dfree = (void (*)())(free);\ - sval = (type*)DATA_PTR(_new_);\ + VALUE _new_;\ + sval = ALLOC(type);\ + _new_ = data_new(sval,free,mark);\ memset(sval, 0, sizeof(type));\ rb_ivar_set_1(obj, iv, _new_);\ } @@ -230,6 +221,20 @@ struct RBignum { #define RSTRUCT(obj) (R_CAST(RStruct)(obj)) #define RBIGNUM(obj) (R_CAST(RBignum)(obj)) +#define FL_SINGLE (1<<4) +#define FL_MARK (1<<5) +#define FL_LITERAL (1<<6) + +#define FL_USER0 (1<<7) +#define FL_USER1 (1<<8) +#define FL_USER2 (1<<9) +#define FL_USER3 (1<<10) + +#define FL_ABLE(x) (!(FIXNUM_P(x)||NIL_P(x))) +#define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0) +#define FL_SET(x,f) if (FL_ABLE(x)) {RBASIC(x)->flags |= (f);} +#define FL_UNSET(x,f) if(FL_ABLE(x)){RBASIC(x)->flags &= ~(f);} + extern VALUE rb_self(); #define Qself rb_self() #define Qnil (VALUE)0 diff --git a/sample/Artistic b/sample/Artistic deleted file mode 100644 index fbf7989775..0000000000 --- a/sample/Artistic +++ /dev/null @@ -1,117 +0,0 @@ - - - - - The "Artistic License" - - Preamble - -The intent of this document is to state the conditions under which a -Package may be copied, such that the Copyright Holder maintains some -semblance of artistic control over the development of the package, -while giving the users of the package the right to use and distribute -the Package in a more-or-less customary fashion, plus the right to make -reasonable modifications. - -Definitions: - - "Package" refers to the collection of files distributed by the - Copyright Holder, and derivatives of that collection of files - created through textual modification. - - "Standard Version" refers to such a Package if it has not been - modified, or has been modified in accordance with the wishes - of the Copyright Holder. - - "Copyright Holder" is whoever is named in the copyright or - copyrights for the package. - - "You" is you, if you're thinking about copying or distributing - this Package. - - "Reasonable copying fee" is whatever you can justify on the - basis of media cost, duplication charges, time of people involved, - and so on. (You will not be required to justify it to the - Copyright Holder, but only to the computing community at large - as a market that must bear the fee.) - - "Freely Available" means that no fee is charged for the item - itself, though there may be fees involved in handling the item. - It also means that recipients of the item may redistribute it - under the same conditions they received it. - -1. You may make and give away verbatim copies of the source form of the -Standard Version of this Package without restriction, provided that you -duplicate all of the original copyright notices and associated disclaimers. - -2. You may apply bug fixes, portability fixes and other modifications -derived from the Public Domain or from the Copyright Holder. A Package -modified in such a way shall still be considered the Standard Version. - -3. You may otherwise modify your copy of this Package in any way, provided -that you insert a prominent notice in each changed file stating how and -when you changed that file, and provided that you do at least ONE of the -following: - - a) place your modifications in the Public Domain or otherwise make them - Freely Available, such as by posting said modifications to Usenet or - an equivalent medium, or placing the modifications on a major archive - site such as uunet.uu.net, or by allowing the Copyright Holder to include - your modifications in the Standard Version of the Package. - - b) use the modified Package only within your corporation or organization. - - c) rename any non-standard executables so the names do not conflict - with standard executables, which must also be provided, and provide - a separate manual page for each non-standard executable that clearly - documents how it differs from the Standard Version. - - d) make other distribution arrangements with the Copyright Holder. - -4. You may distribute the programs of this Package in object code or -executable form, provided that you do at least ONE of the following: - - a) distribute a Standard Version of the executables and library files, - together with instructions (in the manual page or equivalent) on where - to get the Standard Version. - - b) accompany the distribution with the machine-readable source of - the Package with your modifications. - - c) accompany any non-standard executables with their corresponding - Standard Version executables, giving the non-standard executables - non-standard names, and clearly documenting the differences in manual - pages (or equivalent), together with instructions on where to get - the Standard Version. - - d) make other distribution arrangements with the Copyright Holder. - -5. You may charge a reasonable copying fee for any distribution of this -Package. You may charge any fee you choose for support of this Package. -You may not charge a fee for this Package itself. However, -you may distribute this Package in aggregate with other (possibly -commercial) programs as part of a larger (possibly commercial) software -distribution provided that you do not advertise this Package as a -product of your own. - -6. The scripts and library files supplied as input to or produced as -output from the programs of this Package do not automatically fall -under the copyright of this Package, but belong to whomever generated -them, and may be sold commercially, and may be aggregated with this -Package. - -7. C subroutines supplied by you and linked into this Package in order -to emulate subroutines and variables of the language defined by this -Package shall not be considered part of this Package, but are the -equivalent of input as in Paragraph 6, provided these subroutines do -not change the language in any way that would cause it to fail the -regression tests for the language. - -8. The name of the Copyright Holder may not be used to endorse or promote -products derived from this software without specific prior written permission. - -9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - - The End diff --git a/sample/aset.rb b/sample/aset.rb index cfec649ac3..414c13ba70 100644 --- a/sample/aset.rb +++ b/sample/aset.rb @@ -1,3 +1,7 @@ +# array set example +# output: +# 07045 + ary = [0, 0, 4, 5] ary[1, 0] = [7] -print(ary, "\n") +print ary, "\n" diff --git a/sample/attr.rb b/sample/attr.rb index 2db79f1ae5..83265295f3 100644 --- a/sample/attr.rb +++ b/sample/attr.rb @@ -1,9 +1,14 @@ +# attribute access example +# output: +# 10 +# # + class Foo - attr("test", %TRUE) + attr "test", %TRUE end foo = Foo.new foo.test = 10 -print(foo.test, "\n") +print foo.test, "\n" foo._inspect.print -print("\n") +print "\n" diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb deleted file mode 100644 index eb14ca7365..0000000000 --- a/sample/biorhythm.rb +++ /dev/null @@ -1,201 +0,0 @@ -#!/mp/free/bin/ruby -# -# biorhythm.rb - -# $Release Version: $ -# $Revision: 1.6 $ -# $Date: 1994/02/24 10:23:34 $ -# by Yasuo OHBA(STAFS Development Room) -# -# -- -# -# -# - -$RCS_ID="$Header: /var/ohba/RCS/biorhythm.rb,v 1.6 1994/02/24 10:23:34 ohba Exp ohba $" - -include Math -load("parsearg.rb") - -$wochentag = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] -monatstag1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] -monatstag2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] - -def usage() - print("Usage:\n") - print("biorhythm.rb [options]\n") - print(" options...\n") - print(" -D YYYYMMDD(birthday) : すべて default 値を使う. \n") - print(" --sdate | --date YYYYMMDD : system date もしくは指定した日付を使う.\n") - print(" --birthday YYYYMMDD : 誕生日の指定をする. \n") - print(" -v | -g : Values or Graph の指定. \n") - print(" --days DAYS : 期間の指定をする(Graph の時のみ有効). \n") - print(" --help : help\n") -end -$USAGE = 'usage' - -def leapyear(y) - ta = 0 - if ((y % 4.0) == 0); ta = 1; end - if ((y % 100.0) == 0); ta = 0; end - if ((y % 400.0) == 0); ta = 1; end - return ta -end - -def bcalc(tt, m, j) - ta = 0 - if (m <= 2) - ta = (m - 1) * 31 - else - ta = leapyear(j) - ta = ta + ((306 * m - 324) / 10.0).to_i - end - ta = ta + (j - 1) * 365 + ((j - 1) / 4.0).to_i - ta = ta - ((j - 1) / 100) + ((j - 1) / 400.0).to_i - ta = ta + tt - return ta -end - -def printHeader(tg, mg, jg, gtag, tage) - print("\n") - print(" Biorhythm\n") - print(" =========\n") - print("\n") - printf("The birthday %04d.%02d.%02d is a %s\n", jg, mg, tg, $wochentag[gtag]) - printf("Age in days: [%d]\n", tage) -end - -def getPosition(z) - pi = 3.14159265 - $phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * pi / 180.0))).to_i - $emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * pi / 180.0))).to_i - $geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * pi / 180.0))).to_i -end - -# -# main program -# -parseArgs(0, nil, "vg", "D:", "sdate", "date:", "birthday:", "days:") - -printf($stderr, "\n") -printf($stderr, "Biorhythm (c) 1987-1994 V3.0\n") -printf($stderr, "\n") -if ($OPT_D) - dtmp = Time.now.strftime("%Y%m%d") - jh = dtmp[0,4].to_i - mh = dtmp[4,2].to_i - th = dtmp[6,2].to_i - dtmp = $OPT_D - jg = dtmp[0,4].to_i - mg = dtmp[4,2].to_i - tg = dtmp[6,2].to_i - gtag = bcalc(tg, mg, jg) % 7 - ausgabeart = "g" -else - if ($OPT_birthday) - dtmp = $OPT_birthday - else - printf($stderr, "Birthday (YYYYMMDD) : ") - dtmp = $stdin.gets.chop - end - if (dtmp.length != 8) - printf($stderr, "BAD Input Birthday!!\n") - exit() - end - jg = dtmp[0,4].to_i - mg = dtmp[4,2].to_i - tg = dtmp[6,2].to_i - - gtag = bcalc(tg, mg, jg) % 7 - - if ($OPT_sdate) - dtmp = Time.now.strftime("%Y%m%d") - elsif ($OPT_date) - dtmp = $OPT_date - else - printf($stderr, "Date [ for Systemdate] (YYYYMMDD) : ") - dtmp = $stdin.gets.chop - end - if (dtmp.length != 8) - dtmp = Time.now.strftime("%Y%m%d") - end - jh = dtmp[0,4].to_i - mh = dtmp[4,2].to_i - th = dtmp[6,2].to_i - - if ($OPT_v) - ausgabeart = "v" - elsif ($OPT_g) - ausgabeart = "g" - else - printf($stderr, "Values for today or Graph (v/g) [default g] : ") - ausgabeart = $stdin.gets.chop - end -end -if (ausgabeart == "v") - tag = bcalc(tg, mg, jg) - tah = bcalc(th, mh, jh) - tage = tah - tag - printHeader(tg, mg, jg, gtag, tage) - print("\n") - - getPosition(tage) - printf("Biorhythm: %04d.%02d.%02d\n", jh, mh, th) - printf("Physical: %d%%\n", $phys) - printf("Emotional: %d%%\n", $emot) - printf("Mental: %d%%\n", $geist) - print("\n") -else - if ($OPT_days) - ktage = $OPT_days.to_i - else - if ($OPT_D) - ktage = 9 - else - printf($stderr, "Graph for how many days [default 10] : ") - ktage = $stdin.gets.chop - if (ktage == "") - ktage = 9 - else - ktage = ktage.to_i - 1 - end - end - end - tag = bcalc(tg, mg, jg) - tah = bcalc(th, mh, jh) - tage = tah - tag - printHeader(tg, mg, jg, gtag, tage) - print(" P=physical, E=emotional, M=mental\n") - print(" -------------------------+-------------------------\n") - print(" Bad Condition | Good Condition\n") - print(" -------------------------+-------------------------\n") - - for z in tage..(tage + ktage) - getPosition(z) - - printf("%04d.%02d.%02d : ", jh, mh, th) - p = ($phys / 2.0 + 0.5).to_i - e = ($emot / 2.0 + 0.5).to_i - g = ($geist / 2.0 + 0.5).to_i - graph = "." * 51 - graph[25] = ?| - graph[p] = ?P - graph[e] = ?E - graph[g] = ?M - print(graph, "\n") - th = th + 1 - if (leapyear(jh) == 0) - $MONATSTAG = monatstag1 - else - $MONATSTAG = monatstag2 - end - if (th > $MONATSTAG[mh - 1]) - mh = mh + 1 - th = 1 - end - if (mh > 12) - jh = jh + 1 - mh = 1 - end - end - print(" -------------------------+-------------------------\n\n") -end diff --git a/sample/case.rb b/sample/case.rb index f456f023d3..e844cddfd6 100644 --- a/sample/case.rb +++ b/sample/case.rb @@ -1,12 +1,14 @@ +# case statement example +# output: +# 3..5 case "t" when /1/ - print(1, "\n") + print 1, "\n" when /t/ - print(3..5, "\n") + print 3..5, "\n" when /./ - print(2, "\n") + print 2, "\n" else - print("else\n") + print "else\n" end - diff --git a/sample/cat.rb b/sample/cat.rb index 93f028906a..a3243d308d 100644 --- a/sample/cat.rb +++ b/sample/cat.rb @@ -1,3 +1,4 @@ +# cat -n & `...' operator test while gets() if $. == 1 ... ~ /^\*/; print("--") end printf("%5d: %s", $., $_) diff --git a/sample/cat2.rb b/sample/cat2.rb index f979dc53cb..bbc1ebb0ff 100644 --- a/sample/cat2.rb +++ b/sample/cat2.rb @@ -1,3 +1,4 @@ +# cat -n & `...' operator test while gets() if 1 ... /^\*/; print("--") end printf("%5d: %s", $., $_) diff --git a/sample/cbreak.rb b/sample/cbreak.rb index 5befd5066a..6d3d551569 100644 --- a/sample/cbreak.rb +++ b/sample/cbreak.rb @@ -1,3 +1,5 @@ +# ioctl example works on Sun + %CBREAK = 0x00000002 %ECHO = 0x00000008 %TIOCGETP = 0x40067408 diff --git a/sample/clnt.rb b/sample/clnt.rb index 639e2a0daf..a687d12211 100644 --- a/sample/clnt.rb +++ b/sample/clnt.rb @@ -1,3 +1,5 @@ +# socket example - client side +# usage: ruby clnt.rb [host] port host=(if $ARGV.length == 2; $ARGV.shift; else "localhost"; end) print("Trying ", host, " ...") $stdout.flush diff --git a/sample/clone.rb b/sample/clone.rb index 6a752e8ab5..69d2f1d52b 100644 --- a/sample/clone.rb +++ b/sample/clone.rb @@ -1,3 +1,9 @@ +# object cloning & single method test +# output: +# test2 +# test +# test +# clone.rb:13: undefined method `test2' for "#"(Object) foo = Object.new def foo.test print("test\n") diff --git a/sample/const.rb b/sample/const.rb index d7629fe8e1..783965cfd5 100644 --- a/sample/const.rb +++ b/sample/const.rb @@ -1,3 +1,7 @@ +# constant access test +# output: +# 1234 +# 1268 %test1 = 1 %test2 = 2 diff --git a/sample/dbm.rb b/sample/dbm.rb index 128391faec..cdec665a79 100644 --- a/sample/dbm.rb +++ b/sample/dbm.rb @@ -1,6 +1,4 @@ -# ruby -# - +# ruby dbm acess d = DBM.open("test") -for k in d.keys; print(k, "\n"); end -for v in d.values; print(v, "\n"); end +for k in d.keys; print k, "\n"; end +for v in d.values; print v, "\n"; end diff --git a/sample/dir.rb b/sample/dir.rb index f4c3d17c11..f269c568ba 100644 --- a/sample/dir.rb +++ b/sample/dir.rb @@ -1,9 +1,10 @@ +# directory access +# list all files but .*/*~/*.o dirp = Dir.open(".") dirp.rewind for f in dirp - if (~/^\./ || ~/~$/ || ~/\.o/) - else - print(f, "\n") + unless (~/^\./ || ~/~$/ || ~/\.o/) + print f, "\n" end end dirp.close diff --git a/sample/evaldef.rb b/sample/evaldef.rb index c261b53068..021f65800a 100644 --- a/sample/evaldef.rb +++ b/sample/evaldef.rb @@ -1,3 +1,8 @@ +# method definition by eval() +# output: +# bar +# (eval):21: method `baz' not available for "#"(foo) + class foo def foo eval(" diff --git a/sample/export.rb b/sample/export.rb index 3a6a8198df..ea6c5aeaeb 100644 --- a/sample/export.rb +++ b/sample/export.rb @@ -1,3 +1,8 @@ +# methos access permission +# output: +# foobar +# foo + class foo export(\printf) end diff --git a/sample/fib.rb b/sample/fib.rb index 9fb8b24697..cde4fba082 100644 --- a/sample/fib.rb +++ b/sample/fib.rb @@ -1,3 +1,5 @@ +# calculate Fibonacci(20) +# for benchmark def fib(n) if n<2 n diff --git a/sample/freq.rb b/sample/freq.rb index 7417e0b5a4..0c433ae25a 100644 --- a/sample/freq.rb +++ b/sample/freq.rb @@ -1,5 +1,5 @@ -# - +# word occurrence listing +# usege: ruby freq.rb file.. freq = {} while gets() while sub(/\w+/, '') diff --git a/sample/gctest.rb b/sample/gctest.rb index 23476d2b78..6810b95481 100644 --- a/sample/gctest.rb +++ b/sample/gctest.rb @@ -1,3 +1,4 @@ +# GC stress test def cons(car, cdr) [car, cdr] end diff --git a/sample/hash.rb b/sample/hash.rb index 126b17dfe4..85f719e7eb 100644 --- a/sample/hash.rb +++ b/sample/hash.rb @@ -1,3 +1,10 @@ +# hash value +# output: +# 78651 +# 78651 +# 78651 +# -45637 + print(+-1.0.hash,"\n") print(-1.0.hash,"\n") print((-1.0).hash,"\n") diff --git a/sample/io.rb b/sample/io.rb index 0b8a537ef4..c3c1a47b28 100644 --- a/sample/io.rb +++ b/sample/io.rb @@ -1,3 +1,6 @@ +# IO test +# usage: ruby io.rb file.. + home = getenv("HOME") home.sub("m", "&&") print(home, "\n") diff --git a/sample/less.rb b/sample/less.rb index e818e7a2ba..6960b9c03d 100755 --- a/sample/less.rb +++ b/sample/less.rb @@ -1,17 +1,4 @@ -#! /mp/free/bin/ruby -- -*- ruby -*- -# -# less - -# $Release Version: $ -# $Revision: 1.1 $ -# $Date: 90/09/29 15:17:59 $ -# by Yasuo OHBA(STAFS Development Room) -# -# -- -# -# -# - -$RCS_ID="$Header: less,v 1.1 90/09/29 15:17:59 ohba Locked $" +#! /usr/local/bin/ruby -- -*- ruby -*- ZCAT = "/usr/local/bin/zcat" LESS = "/usr/local/bin/less" diff --git a/sample/list.rb b/sample/list.rb index e0b5b383b0..1a20c954d0 100644 --- a/sample/list.rb +++ b/sample/list.rb @@ -1,10 +1,16 @@ -# Linked list program +# Linked list example class MyElem + #クラスメソッド(相当)の定義 def MyElem.new(item) - super.init(item) + # スーパークラスのメソッドの呼び出し(この場合はクラスClass) + elm = super # 変数宣言は要らない + #elmに対するメソッドの呼び出し + elm.init(item) end - + + # 通常のメソッド定義 def init(item) + # @変数はインスタンス変数(宣言は要らない) @data = item @next = nil self @@ -18,6 +24,7 @@ class MyElem @next end + # 「obj.data = val」としたときに暗黙に呼ばれるメソッド def next=(new) @next = new end @@ -42,9 +49,12 @@ class MyList end end + # オブジェクトを文字列に変換するメソッド + # これを再定義するとprintでの表現が変わる def to_s str = "= hdw || xl <= maxxl) { - t = rand() * length(ss); - c = substr(ss, t, 1); - } - else { - c = substr(s, xl + hdw, 1); - maxxl = xl; - } - s = s c; - xr = xr + 1; - } - print s; -} diff --git a/sample/rcs.dat b/sample/rcs.dat deleted file mode 100644 index 61c88bff89..0000000000 --- a/sample/rcs.dat +++ /dev/null @@ -1,17 +0,0 @@ -0000000000000000220000000000000000 -0000000000000111221110000000000000 -0000000000111112222111110000000000 -0000000111111112222111111110000000 -0000111111111122222211111111110000 -0111111111111222222221111111111110 -2222222222222222222222222222222222 -1122222222222222222222222222222211 -0111122222222222222222222222211110 -0011111122222222222222222211111100 -0001111111222222222222221111111000 -0000111112222222222222222111110000 -0000011122222222112222222211100000 -0000001122222221111222222211000000 -0000000122221111111111222210000000 -0000000221111111111111111220000000 -0000000000000000000000000000000000 diff --git a/sample/rcs.rb b/sample/rcs.rb deleted file mode 100644 index 0ed4a36c1e..0000000000 --- a/sample/rcs.rb +++ /dev/null @@ -1,46 +0,0 @@ -sw = 40.0 # p^[ -dw = 78.0 # Random Character Streogram -hdw = dw / 2.0 -w = 20.0 # -h =1.0 # -d = 0.2 # P -ss="abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()-=\\[];'`,./" -rnd = srand() - -while gets() -# print($_) - xr = -hdw; y = h * 1.0; maxxl = -999 - s = ""; - while xr < hdw - x = xr * (1 + y) - y * w / 2 - i = (x / (1 + h) + sw /2) - if (1 < i && i < $_.length); - c = $_[i, 1].to_i - else - c = 0 - end - y = h - d * c - xl = xr - w * y / (1 + y); - if xl < -hdw || xl >= hdw || xl <= maxxl - tt = rand(ss.length) - c = ss[tt, 1] - else - c = s[xl + hdw, 1] - maxxl = xl - end - s = s + c - xr = xr + 1 - end - print(s, "\n") -end - - - - - - - - - - - diff --git a/sample/reach.rb b/sample/reach.rb deleted file mode 100644 index 25b340887d..0000000000 --- a/sample/reach.rb +++ /dev/null @@ -1,5 +0,0 @@ -for i in 1..10 - print("test\n") - break - print("test2\n") -end diff --git a/sample/resp.rb b/sample/resp.rb deleted file mode 100644 index 84516b4c78..0000000000 --- a/sample/resp.rb +++ /dev/null @@ -1,2 +0,0 @@ -undef kill -print(responds_to("kill"), "\n") diff --git a/sample/samp.rb b/sample/samp.rb index b4d818faba..4052a308c1 100644 --- a/sample/samp.rb +++ b/sample/samp.rb @@ -1,3 +1,6 @@ +# SpXNvg +# g: samp.rb file.. + P = 0 while gets() printf("%3d: %s", $., $_) diff --git a/sample/sieve.rb b/sample/sieve.rb index 0228243fda..192a5865d8 100644 --- a/sample/sieve.rb +++ b/sample/sieve.rb @@ -1,3 +1,4 @@ +# sieve of Eratosthenes sieve = [] unless max = $ARGV.shift; max = 100; end max = max.to_i diff --git a/sample/split.rb b/sample/split.rb index 737173635e..2b6f3921ce 100644 --- a/sample/split.rb +++ b/sample/split.rb @@ -1,3 +1,4 @@ +# split test print("1 byte string", "\n") print("1 byte string".reverse, "\n") diff --git a/sample/struct.rb b/sample/struct.rb index 7c0690b627..322764d02f 100644 --- a/sample/struct.rb +++ b/sample/struct.rb @@ -1,3 +1,7 @@ +#output: +# struct test +# 1 + foo = Struct.new("test", "a1"::1, "a2"::2) print(foo, "\n") bar = foo.clone diff --git a/sample/svr.rb b/sample/svr.rb index c00a03c8cf..1c0104cc40 100644 --- a/sample/svr.rb +++ b/sample/svr.rb @@ -1,3 +1,6 @@ +# socket example - server side +# usage: ruby svr.rb + gs = TCPserver.open(0) printf("server port is on %d\n", gs.port) socks = [gs] diff --git a/sample/system.rb b/sample/system.rb index 1693d905b4..02f3782b39 100644 --- a/sample/system.rb +++ b/sample/system.rb @@ -1 +1,2 @@ +# command string print(`echo foobar`) diff --git a/socket.c b/socket.c index b65c6b7e6f..098545cae9 100644 --- a/socket.c +++ b/socket.c @@ -3,7 +3,7 @@ socket.c - $Author: matz $ - $Date: 1994/11/01 08:28:26 $ + $Date: 1994/12/06 09:30:18 $ created at: Thu Mar 31 12:21:29 JST 1994 ************************************************/ @@ -227,7 +227,7 @@ open_inet(class, h, serv, server) } static VALUE -Ftcp_sock_open(class, host, serv) +Stcp_sock_open(class, host, serv) VALUE class, host, serv; { Check_Type(host, T_STRING); @@ -235,7 +235,7 @@ Ftcp_sock_open(class, host, serv) } static VALUE -Ftcp_svr_open(class, args) +Stcp_svr_open(class, args) VALUE class, args; { VALUE arg1, arg2; @@ -379,7 +379,7 @@ Ftcp_peeraddr(sock) } static VALUE -Funix_sock_open(sock, path) +Sunix_sock_open(sock, path) VALUE sock, path; { return open_unix(sock, path, 0); @@ -403,7 +403,7 @@ Funix_path(sock) } static VALUE -Funix_svr_open(class, path) +Sunix_svr_open(class, path) VALUE class, path; { return open_unix(class, path, 1); @@ -522,7 +522,7 @@ setup_domain_and_type(domain, dv, type, tv) } static VALUE -Fsock_open(class, domain, type, protocol) +Ssock_open(class, domain, type, protocol) VALUE class, domain, type, protocol; { int fd; @@ -535,14 +535,14 @@ Fsock_open(class, domain, type, protocol) } static VALUE -Fsock_for_fd(class, fd) +Ssock_for_fd(class, fd) VALUE class, fd; { return sock_new(class, NUM2INT(fd)); } static VALUE -Fsock_socketpair(class, domain, type, protocol) +Ssock_socketpair(class, domain, type, protocol) VALUE class, domain, type, protocol; { int fd; @@ -706,32 +706,32 @@ Init_Socket () rb_define_method(C_BasicSocket, "getpeername", Fbsock_getpeername, 0); C_TCPsocket = rb_define_class("TCPsocket", C_BasicSocket); - rb_define_single_method(C_TCPsocket, "open", Ftcp_sock_open, 2); - rb_define_single_method(C_TCPsocket, "new", Ftcp_sock_open, 2); + rb_define_single_method(C_TCPsocket, "open", Stcp_sock_open, 2); + rb_define_single_method(C_TCPsocket, "new", Stcp_sock_open, 2); rb_define_method(C_TCPsocket, "addr", Ftcp_addr, 0); rb_define_method(C_TCPsocket, "peeraddr", Ftcp_peeraddr, 0); C_TCPserver = rb_define_class("TCPserver", C_TCPsocket); - rb_define_single_method(C_TCPserver, "open", Ftcp_svr_open, -2); - rb_define_single_method(C_TCPserver, "new", Ftcp_svr_open, -2); + rb_define_single_method(C_TCPserver, "open", Stcp_svr_open, -2); + rb_define_single_method(C_TCPserver, "new", Stcp_svr_open, -2); rb_define_method(C_TCPserver, "accept", Ftcp_accept, 0); C_UNIXsocket = rb_define_class("UNIXsocket", C_BasicSocket); - rb_define_single_method(C_UNIXsocket, "open", Funix_sock_open, 1); - rb_define_single_method(C_UNIXsocket, "new", Funix_sock_open, 1); + rb_define_single_method(C_UNIXsocket, "open", Sunix_sock_open, 1); + rb_define_single_method(C_UNIXsocket, "new", Sunix_sock_open, 1); rb_define_method(C_UNIXsocket, "path", Funix_path, 0); rb_define_method(C_UNIXsocket, "addr", Funix_addr, 0); rb_define_method(C_UNIXsocket, "peeraddr", Funix_peeraddr, 0); C_UNIXserver = rb_define_class("UNIXserver", C_UNIXsocket); - rb_define_single_method(C_UNIXserver, "open", Funix_svr_open, 1); - rb_define_single_method(C_UNIXserver, "new", Funix_svr_open, 1); + rb_define_single_method(C_UNIXserver, "open", Sunix_svr_open, 1); + rb_define_single_method(C_UNIXserver, "new", Sunix_svr_open, 1); rb_define_method(C_UNIXserver, "accept", Funix_accept, 0); C_Socket = rb_define_class("Socket", C_BasicSocket); - rb_define_single_method(C_Socket, "open", Fsock_open, 3); - rb_define_single_method(C_Socket, "new", Fsock_open, 3); - rb_define_single_method(C_Socket, "for_fd", Fsock_for_fd, 1); + rb_define_single_method(C_Socket, "open", Ssock_open, 3); + rb_define_single_method(C_Socket, "new", Ssock_open, 3); + rb_define_single_method(C_Socket, "for_fd", Ssock_for_fd, 1); rb_define_method(C_Socket, "connect", Fsock_connect, 1); rb_define_method(C_Socket, "bind", Fsock_bind, 1); @@ -742,6 +742,6 @@ Init_Socket () rb_define_method(C_Socket, "recv", Fsock_recv, -2); rb_define_method(C_Socket, "recvfrom", Fsock_recv, -2); - rb_define_single_method(C_Socket, "socketpair", Fsock_socketpair, 3); + rb_define_single_method(C_Socket, "socketpair", Ssock_socketpair, 3); } #endif /* HAVE_SOCKET */ diff --git a/spec b/spec index 6432fc6090..ee23c704cd 100644 --- a/spec +++ b/spec @@ -3,65 +3,64 @@ * はじめに(なぜRubyか?) Rubyは「UNIXで手軽にオブジェクト指向プログラミング」をしたいという望み -を実現するために生まれた. そのために必要だと思われた性質は: +を実現するために生まれた.そのために必要だと思われた性質は: - * 文法や機能が単純である. + * 文法や機能が単純である. * オブジェクト指向プログラミングをサポートする機能を - 持つ言語として設計されている. - * ターンアラウンドタイムが短い(インタプリタである). - * OS(UNIX)の機能が簡単に利用できる. - * スクリプト言語として使える. - * 処理系がfreeである. - -などである. オブジェクト指向言語として一般的であるSmalltalkやC++などは -上の条件の一部を満たしてはいるが, 特に手軽なプログラミングという点に欠 -けており, 以上の条件の全てを満たすものではなかった. 一方スクリプト言語 -であるPerlや Tclにオブジェクト指向機能を追加したシステムも存在するが, -これらは「手軽にプログラミング」という性質は満たしてはいても, 逆にオブ -ジェクト指向機能に不備や不満があった. よって, これらの条件を満たす言語 -を新たに設計する必要があると考えられた. これらを踏まえて設計されたRuby -の特徴は: - - * インタプリタである. - * 単純で例外の少ない文法. - * 十分なオブジェクト指向機能を持つ. - * できるだけ書きやすい(演算子形式など). - * ガーベージコレクタがある. - * 例外処理機能がある. - * 十分に強力なクラスが組み込まれている. - * OSをアクセスする機能が提供される. - * 拡張しやすい. - -などがある. RubyはshやPerlを知っている人にとっての常識になるたけ従った -ので, それらの言語からの自然な移行が可能であると思われる. プログラマが -Rubyのオブジェクト指向機能について学べば, より強力なこともできるように -なるだろう. - -更にC言語でクラスやメソッドを記述し, 追加することでRubyを更に強力にす -ることができる. 一部のプラットフォームではRubyは動的にオブジェクトファ -イルをリンクできるし, そうでなくてもRubyを再コンパイルして組み込みクラ -スを追加するのは容易である(Perlなどよりもはるかに容易である). + 持つ言語として設計されている. + * ターンアラウンドタイムが短い(インタプリタである). + * OS(UNIX)の機能が簡単に利用できる. + * スクリプト言語として使える. + * 処理系がfreeである. + +などである.オブジェクト指向言語として一般的であるSmalltalkやC++などは +上の条件の一部を満たしてはいるが,特に手軽なプログラミングという点に欠 +けており,以上の条件の全てを満たすものではなかった.一方スクリプト言語 +であるPerlや Tclにオブジェクト指向機能を追加したシステムも存在するが, +これらは「手軽にプログラミング」という性質は満たしてはいても,逆にオブ +ジェクト指向機能に不備や不満があった.よって,これらの条件を満たすため +に設計されたRubyの特徴は: + + * インタプリタである. + * 単純で例外の少ない文法. + * 十分なオブジェクト指向機能を持つ. + * できるだけ書きやすい(演算子形式など). + * ガーベージコレクタがある. + * 例外処理機能がある. + * 十分に強力なクラスが組み込まれている. + * OSをアクセスする機能が提供される. + * 拡張しやすい. + +などである.RubyはshやPerlを知っている人にとっての常識になるたけ従った +ので,それらの言語からの自然な移行が可能であると思われる.プログラマが +Rubyのオブジェクト指向機能について学べば,より強力なこともできるように +なるだろう. + +更にC言語でクラスやメソッドを記述し,追加することでRubyを更に強力にす +ることができる.一部のプラットフォームではRubyは動的にオブジェクトファ +イルをリンクできるし,そうでなくてもRubyを再コンパイルして組み込みクラ +スを追加するのは容易である(Perlなどよりもはるかに容易である). * Rubyの文法 -ここではRuby言語の文法を解説する. Rubyの基本的な部分は非常に小さく, 文 -法に例外が少ないので身につけるのはさほど難しくないだろう. +ここではRuby言語の文法を解説する.Rubyの基本的な部分は小さく,文法に例 +外が少ないので身につけるのはさほど難しくないだろう. ** コメント -スクリプト言語の習慣にならい, 文字列中以外の'#'から行末まではコメント -と見なす. +スクリプト言語の習慣にならい,文字列中以外の'#'から行末まではコメント +と見なす. ** 区切り記号 -空白文字(タブとスペース)および改行(\n)が区切り記号となる. 更に +空白文字(タブとスペース)および改行(\n)が区切り記号となる.更に 改行は a + b -のように行が式(文)の途中で終り, 次の行に続くことが明白な場合以外は文の -区切りとしても認識される. +のように行が式(文)の途中で終り,次の行に続くことが明白な場合以外は文の +区切りとしても認識される. ** 予約語 @@ -75,16 +74,16 @@ Ruby else in retry until elsif include return when -予約語はクラス名, メソッド名, 変数名などに用いることはできない. +予約語はクラス名,メソッド名,変数名などに用いることはできない. ** 式 -Rubyプログラムを構成する要素は式と文である. まず, 式から解説する. +Rubyプログラムを構成する要素は式と文である.まず,式から解説する. *** リテラル -プログラム中に直接記述できるオブジェクトをリテラルと呼ぶ. Rubyのリテラ -ルには文字列, 正規表現, 数値というリテラルがある. +プログラム中に直接記述できるオブジェクトをリテラルと呼ぶ.Rubyのリテラ +ルには文字列,正規表現,数値というリテラルがある. **** 文字列リテラル @@ -100,19 +99,20 @@ Ruby \b バックスペース(0x08) \a ベル(0x07) \e エスケープ(0x1b) - \# 文字`#'そのもの + \# 文字`#'そのもの \nnn 8進数表記(nは0-7) \xnn 16進数表記(nは0-9,a-f) \^c コントロール文字(cはASCII文字) \C-c コントロール文字(同上) \M-c メタ文字(c|0x80) + \それ以外 文字そのもの **** 変数展開 ダブルクォート(`"')で囲まれた文字列と正規表現の中では `#{変数名}'とい -う形式で変数の内容を展開することができる. 変数が変数記号(`$',`@',`%') -を持つ場合には`#変数名'という形式でも展開できる. 文字`#'に続く文字が -`{',`$',`@',`%'でなければ, そのまま`#'として解釈される. +う形式で変数の内容を展開することができる.変数が変数記号(`$',`@',`%') + で始まる場合には`#変数名'という形式でも展開できる.文字`#'に続く文字 +が `{',`$',`@',`%'でなければ,そのまま`#'として解釈される. **** 正規表現リテラル @@ -121,11 +121,11 @@ Ruby ^ 行頭 $ 行末 . 任意の1文字 - \w 英数字. [0-9A-Za-z_]と同じ + \w 英数字.[0-9A-Za-z_]と同じ \W 非英数字 - \s 空白文字. [ \t\n\r\f]と同じ + \s 空白文字.[ \t\n\r\f]と同じ \S 非空白文字 - \d 数字. [0-9] と同じ + \d 数字.[0-9] と同じ \D 非数字 \b 語境界文字(文字クラス外) \B 非語境界文字 @@ -138,7 +138,7 @@ Ruby | 選択 ( ) 正規表現をまとめる -その他に文字列と同じバックスラッシュ記法も有効である. +その他に文字列と同じバックスラッシュ記法も有効である. **** ワイルドカードリテラル @@ -163,188 +163,188 @@ Ruby ?\M-a メタaのコード(225) ?\M-\C-a メタ-コントロールaのコード(129) - \シンボル 識別子/変数名と一対一対応する整数. applyなどでメソッ - ドを指定するのに使う. + \シンボル 識別子/変数名と一対一対応する整数.applyなどでメソッ + ドを指定するのに使う. -?表現では全てのバックスラッシュ記法が有効である. +?表現では全てのバックスラッシュ記法が有効である. *** コマンドの出力 Rubyではshのようにコマンドの実行結果を文字列リテラルのように使うことが -できる. ``で囲まれた文字列は, ダブルクォートと同様にバックスラッシュ記 -法の解釈と変数展開が行なわれた後, コマンドとして実行され, その実行結果 -が文字列として与えられる. コマンドは評価されるたびに実行される. +できる.``で囲まれた文字列は,ダブルクォートと同様にバックスラッシュ記 +法の解釈と変数展開が行なわれた後,コマンドとして実行され,その実行結果 +が文字列として与えられる.コマンドは評価されるたびに実行される. *** 変数参照 -Rubyの変数はスコープ(有効範囲)と寿命(有効期限)によって4種類に分類され, -その種類は変数名の最初の一文字で決定される. 通常の変数の2文字目以降は -英数時または`_'であるが, システム変数の一部は「`$'+1文字の記号」という -変数がある. 変数名の長さに関して特別な制限はない. +Rubyの変数はスコープ(有効範囲)と寿命(有効期限)によって4種類に分類され, +その種類は変数名の最初の一文字で決定される.通常の変数の2文字目以降は +英数時または`_'であるが,システム変数の一部は「`$'+1文字の記号」という +変数がある.変数名の長さに関して特別な制限はない. -変数のスコープに関わらず, 初期化されていない変数を参照した時の値はnil -である. +変数のスコープに関わらず,初期化されていない変数を参照した時の値はnil +である. **** グローバル変数 -`$'で始まる変数のスコープはグローバルであり, プログラムのどこからでも -参照できる. その寿命はプログラムの寿命と等しい. +`$'で始まる変数のスコープはグローバルであり,プログラムのどこからでも +参照できる.その寿命はプログラムの寿命と等しい. **** インスタンス変数 -`@'で始まる変数はインスタンス変数であり, そのクラスまたはサブクラスの -メソッドから参照できる. スコープはメソッド内であり, その寿命はオブジェ -クトの寿命に等しい. +`@'で始まる変数はインスタンス変数であり,そのクラスまたはサブクラスの +メソッドから参照できる.スコープはメソッド内であり,その寿命はオブジェ +クトの寿命に等しい. **** クラス名/モジュール名/ローカル変数 -アルファベットまたは`_'で始まる変数は識別子とも呼ばれ, ローカル変数, -クラス名またはモジュール名である. +アルファベットまたは`_'で始まる変数は識別子とも呼ばれ,ローカル変数, +クラス名またはモジュール名である. 初期状態では識別子はクラス/モジュール名とみなされるが(該当するクラスが -存在しない場合の値はnil), 代入式の左辺に現れた識別子は,そのスコープ内 -ではローカル変数として見なされ, 同名のクラスやモジュールは隠される. こ -の意味で識別子への代入は宣言としての働きも持つ. +存在しない場合の値はnil),代入式の左辺に現れた識別子は,そのスコープ内 +ではローカル変数として見なされ,同名のクラスやモジュールは隠される.こ +の意味で識別子への代入は宣言としての働きも持つ. Array # 配列クラス Array - Array = 15 # 代入. 以後Arrayはローカル変数 + Array = 15 # 代入.以後Arrayはローカル変数 print Array, "\n" # `15'が出力される -この宣言としての代入の解釈はコンパイル時に行なわれるため, 識別子への代 -入式が実際に実行されてもされなくても, 以降のスコープ内ではその識別子は -ローカル変数とみなされる. +この宣言としての代入の解釈はコンパイル時に行なわれるため,識別子への代 +入式が実際に実行されてもされなくても,以降のスコープ内ではその識別子は +ローカル変数とみなされる. Array # 配列クラス Array if %FALSE - Array = 15 # このコードは実行されないが, - # 以降Arrayはローカル変数とみなされる. + Array = 15 # このコードは実行されないが, + # 以降Arrayはローカル変数とみなされる. end print Array, "\n" # `nil'が出力される -このルールは一見複雑だが, クラス/モジュール名とローカル変数名が重複し -ない限り, 未初期化のローカル変数の値はnilであると考えても差し支えはな -い. Rubyの組み込みクラスは大文字のアルファベットで始まる名前がついて -おり, ユーザもクラス/モジュール名には大文字で始まる識別子を, ローカル -変数名には小文字または`_'で始まる識別子を使うことを強く推奨する. +このルールは一見複雑だが,クラス/モジュール名とローカル変数名が重複し +ない限り,未初期化のローカル変数の値はnilであると考えても差し支えはな +い.Rubyの組み込みクラスは大文字のアルファベットで始まる名前がついて +おり,ユーザもクラス/モジュール名には大文字で始まる識別子を,ローカル +変数名には小文字または`_'で始まる識別子を使うことを強く推奨する. ローカル変数のスコープも寿命もそのブロックの終りまで(トップレベルのロー -カル変数はプログラムの終了まで)である. +カル変数はプログラムの終了まで)である. **** クラス変数(定数) -`%'で始まる変数はクラス変数であり, そのクラスと全てのサブクラスのイン -スタンスから参照できる. この変数への代入はトップレベル, すなわちメソッ -ドが定義できるレベルでのみ可能である. この変数はクラス間で値が共有され, -一度代入するとメソッドからは値を変更することができないので,定数として -用いられる. +`%'で始まる変数はクラス変数であり,そのクラスと全てのサブクラスのイン +スタンスから参照できる.この変数への代入はトップレベル,すなわちメソッ +ドが定義できるレベルでのみ可能である.この変数はクラス間で値が共有され, +一度代入するとメソッドからは値を変更することができないので,定数として +用いられる. **** 疑似変数 -通常の変数以外に疑似変数と呼ばれる特殊な変数が4つある. +通常の変数以外に疑似変数と呼ばれる特殊な変数が4つある. self | 現在のメソッドの実行主体 nil | Nilクラスの唯一のインスタンス(偽を表す) __FILE__ | スクリプトのファイル名(文字列) - __LINE__ | 現在の行番号 + __LINE__ | 現在の行番号(整数) -これらの疑似変数は代入によってその値を変更することはできない. これらの -変数への代入は例外を発生させる. +これらの疑似変数は代入によってその値を変更することはできない.これらの +変数への代入は例外を発生させる. *** メッセージ式 -オブジェクトにメッセージを送る基本的な構文がメッセージ式であり, その基 -本形式は以下の通りである. +オブジェクトにメッセージを送る基本的な構文がメッセージ式であり,その基 +本形式は以下の通りである. 式1 '.' メソッド名 '(' 引数1... [',' '*' 引数n ]')' -式1を評価して得られるオブジェクトの, 識別子で指定されるメソッドを呼び -出す. 一番最後の引数が'*'に続く(単一の)式である場合, その式を評価した -結果(配列である必要がある)を展開して, 引数として追加する. +式1を評価して得られるオブジェクトの,識別子で指定されるメソッドを呼び +出す.一番最後の引数が'*'に続く(単一の)式である場合,その式を評価した +結果(配列である必要がある)を展開して,引数として追加する. -引数が一つもない時には括弧を省略できる. +引数が一つもない時には括弧を省略できる. -メソッド名としては任意の識別子を用いることができる. 変数名とは識別子の -名前空間が違うので重複しても構わない. +メソッド名としては任意の識別子を用いることができる.変数名とは識別子の +名前空間が違うので重複しても構わない. -メッセージ式で, レシーバがselfの場合, レシーバを省略して通常のプログラ -ミング言語における関数のような形式でメソッドを呼び出すことができる. こ -の場合引数が1つもない時でも括弧の省略はできない. +メッセージ式で,レシーバがselfの場合,レシーバを省略して通常のプログラ +ミング言語における関数のような形式でメソッドを呼び出すことができる.こ +の場合引数が1つもない時でも括弧の省略はできない. クラス定義文の外で指定されたメソッドとクラスModuleのnoexportメソッドで -指定されたメソッドは関数的メソッドと呼ばれ, 関数形式でしか呼び出すこと -ができない. +指定されたメソッドは関数的メソッドと呼ばれ,関数形式でしか呼び出すこと +ができない. *** スーパークラスのメソッド呼び出し メッセージ式の特殊なケースとしてスーパークラスのメソッドの呼び出しがあ -る. この形式はメソッドを再定義した時にスーパークラスの定義を利用するた -めに使う. +る.この形式はメソッドを再定義した時にスーパークラスの定義を利用するた +めに使う. super 現在のメソッドに与えられた引数のままスーパクラスの同名のメソッドを呼び -出す. +出す. super'(' 引数... ')' -引数とともにスーパークラスの同名のメソッドを呼び出す. 一番最後の引数が -`*'に続く場合は通常のメソッド呼び出しと同様に渡される. +引数とともにスーパークラスの同名のメソッドを呼び出す.一番最後の引数が +`*'に続く場合は通常のメソッド呼び出しと同様に渡される. *** 配列式/連想配列式 -配列のオブジェクトを生成する式の形式は以下の形式である. +配列のオブジェクトを生成する式の形式は以下の形式である. '[' 式, ... ']' -それぞれの式を評価した結果を含む配列を返す. 要素数が0の空配列を生成す +それぞれの式を評価した結果を含む配列を返す.要素数が0の空配列を生成す るためには空の配列式 '[' ']' -を用いる. +を用いる. ** 連想配列式 -連想配列とは任意のオブジェクトをキー(添字)として持てる配列である. Ruby -では連想配列はSmalltalkの用語を借りてDict(辞書)とも呼ばれる. 詳細はク -ラスDictの項を参照されたい. 連想配列を生成する連想配列式は以下の形式で -ある. +連想配列とは任意のオブジェクトをキー(添字)として持てる配列である.Ruby +では連想配列はSmalltalkの用語を借りてDict(辞書)とも呼ばれる.詳細はク +ラスDictの項を参照されたい.連想配列を生成する連想配列式は以下の形式で +ある. '{' 式 '=>' 式... '}' -それぞれの式を評価した結果をキーと値とする連想配列オブジェクトを返す. +それぞれの式を評価した結果をキーと値とする連想配列オブジェクトを返す. 要素数が0の連想配列を生成するためには空の連想配列式 '{' '}' -を用いる. +を用いる. -*** 配列参照, 配列代入 +*** 配列参照,配列代入 -配列(連想配列を含む)の要素の参照は以下の形式で行なう. +配列(連想配列を含む)の要素の参照は以下の形式で行なう. 式1 '[' 式2... ']' -この形式は内部的に, 式1に"[]"というメッセージを送ると解釈される. この -動作を疑似的なコードで記述すれば以下のようになる. +この形式は内部的に,式1に"[]"というメッセージを送ると解釈される.この +動作を疑似的なコードで記述すれば以下のようになる. - 式1"[]="(式2) + 式1"[]"(式2...) -一方, 配列要素の代入は +一方,配列要素の代入は 式1 '[' 式2... ']' '=' 式n -という形式で行なわれ, +という形式で行なわれ, - 式1."[]="(式2..) + 式1."[]="(式2...) -という形式として解釈される. +という形式として解釈される. *** 演算子形式 プログラミングの利便のために一部のメソッド呼び出しと制御構造は演算子形 -式をとる. Rubyには以下にあげる演算子がある. 上のものほど結合順位が強く, -同じ列の演算子の結合順位は同じである. +式をとる.Rubyには以下にあげる演算子がある.上のものほど結合順位が強く, +同じ列の演算子の結合順位は同じである. 強 -(unary) +(unary) ! ~ ** @@ -357,76 +357,76 @@ Ruby <=> == != =~ !~ && || - .. ... + .. ... :: 弱 =(代入) 自己代入(+=, -=, ..) ほとんどの演算式にはメソッド呼び出しとして解釈される(クラス毎に再定義 -できる)が, 一部再定義できない特殊なものがある. 再定義できない特殊演算 +できる)が,一部再定義できない特殊なものがある.再定義できない特殊演算 子は - &&(論理積), ||(論理和), =(代入), ...(範囲指定), + &&(論理積), ||(論理和), =(代入), ...(範囲指定) -の4つである. +の4つである. -上であげた特殊演算子以外の演算子形式はメソッド呼び出しと見なされる. +上であげた特殊演算子以外の演算子形式はメソッド呼び出しと見なされる. 単項演算子(+, -, !, ~)は 式1."演算子"() -という形式に, それ以外の2項演算子は +という形式に,それ以外の2項演算子は 式1."演算子"(式2) -に解釈される. +に解釈される. ** 代入 -代入には変数に対する代入(真の代入)と, プログラムを簡単にするためのシン -タックスシュガーとしての代入がある. 真の代入は以下の形式である. +代入には変数に対する代入(真の代入)と,プログラムを簡単にするためのシン +タックスシュガーとしての代入がある.真の代入は以下の形式である. 変数 '=' 式 -これは式を評価し, 変数の値として代入する. クラスやモジュールや疑似変数 -には代入できない. クラスやモジュールの定義を変更するためにはclass文, -module文を用いる. 代入式は演算子形式をとっているが, メソッドではないの -で再定義することはできない. +これは式を評価し,変数の値として代入する.クラスやモジュールや疑似変数 +には代入できない.クラスやモジュールの定義を変更するためにはclass文, +module文を用いる.代入式は演算子形式をとっているが,メソッドではないの +で再定義することはできない. -シンタックスシュガーとしての代入式は以下のものがある. +シンタックスシュガーとしての代入式は以下のものがある. 配列要素への代入 式1'[' 式2... ' ]' '=' 式n -式1を評価して得られるオブジェクトに, 式2から式nまでを引数として, "[]=" -というメソッドを呼び出す. +式1を評価して得られるオブジェクトに,式2から式nまでを引数として,"[]=" +というメソッドを呼び出す. 属性代入 式1 '.' 識別子 '=' 式2 -式1を評価して得られるオブジェクトに対して"識別子="というメソッドを, 式 -2を引数として呼び出す. +式1を評価して得られるオブジェクトに対して"識別子="というメソッドを,式 +2を引数として呼び出す. 自己代入 - 式1 op= 式2 # 式1は代入可能でなければならない. + 式1 op= 式2 # 式1は代入可能でなければならない. -この形式は内部的に「式1 = 式1 op 式2」と展開され, 実行される. そのため -式1は2回評価されるので, 副作用がある場合は予想しない結果を呼ぶ可能性が -ある. 自己代入形式はプログラマのタイプ数を減らす目的のために存在する形 -式である. opとして使える演算子は +この形式は内部的に「式1 = 式1 op 式2」と展開され,実行される.そのため +式1は2回評価されるので,副作用がある場合は予想しない結果を呼ぶ可能性が +ある.自己代入形式はプログラマのタイプ数を減らす目的のためだけに存在す +る形式である.opとして使える演算子は +, -, *, /, %, **, &, |, ^, <<, >> -の11種類である. 演算子と`='の間にスペースを空けてはいけない. +の11種類である.演算子と`='の間にスペースを空けてはいけない. *** 条件分岐式 -式の値によって分岐する式は以下に示すif式, unless式, case式の複合文型が -3種類と演算子型が3種類ある. Rubyではnilが偽, それ以外が真と評価される. -CやPerlなどとは異なり, 0や ""(空文字列)は偽とは評価されないので気をつ -けること. +式の値によって分岐する式は以下に示すif式,unless式,case式の複合文型が +3種類と演算子型が3種類ある.Rubyではnilが偽,それ以外が真と評価される. +CやPerlなどとは異なり,0や ""(空文字列)は偽とは評価されないので気をつ +けること. if式 @@ -438,9 +438,9 @@ if 文n ] end -条件判断式. 式1が真の場合に文1を評価する. それ以外の場合は文2を評価す -る. Rubyのif式はelse ifでもelifでもなくelsifでifの連続を行なうことに注 -意すること. +条件判断式.式1が真の場合に文1を評価する.それ以外の場合は文2を評価す +る.Rubyのif式はelse ifでもelifでもなくelsifでifの連続を行なうことに注 +意すること. unless式 @@ -450,22 +450,22 @@ unless 文2 ] end -式1が偽(nil)を返すか, 式2の評価中に例外が発生した場合に文1を評価する. -それ以外の場合は文2を評価する. +式1が偽(nil)を返すか,式2の評価中に例外が発生した場合に文1を評価する. +それ以外の場合は文2を評価する. case式 case 式0 [when 式1 [, 式2]... [then] - 文1 ]... + 文1 ]... [else 文n ] end -条件分岐, CのswitchよりもPascalのcaseに似ている. breakで脱出することも -後ろの文に継続することもないので注意. +条件分岐,CのswitchよりもPascalのcaseに似ている.breakで脱出することも +後ろの文に継続することもないので注意. -条件の一致は「式n =~ 式0]で行なわれる. つまり, +条件の一致は「式n =~ 式0]で行なわれる.つまり, case expr0 when expr1, expr2 @@ -476,7 +476,7 @@ case stmt3 end -は以下のif文と等価である. +は以下のif文とほぼ等価である. _tmp = expr0 if expr1 =~ _tmp || expr2 =~ _tmp @@ -491,21 +491,21 @@ case 式1 '&&' 式2 -式1を評価し, その値が真(nil以外)であれば, 式2を評価する. +式1を評価し,その値が真(nil以外)であれば,式2を評価する. 式1 '||' 式2 -式1を評価し, その値が偽であれば, 式2を評価する. +式1を評価し,その値が偽であれば,式2を評価する. 式1 '...' 式2 -式1が真になるまでは偽を返し, その後は式2が真を返すまでは真を返す. 式2 +式1が真になるまでは偽を返し,その後は式2が真を返すまでは真を返す.式2 が真になれば状態は偽に戻る *** 繰り返し式(単純型) -ループを構成する式. これらの式の値は常にnilである. オブジェクトに合わ -せたループを行なうためには次に述べるイテレータを用いる. +ループを構成する式.これらの式の値は常にnilである.オブジェクトに合わ +せたループを行なうためには次に述べるイテレータを用いる. while式 @@ -513,7 +513,7 @@ while 文 end -条件が真の間, 文を繰り返し実行する. +条件が真の間,文を繰り返し実行する. until式 @@ -522,82 +522,80 @@ until end 式1 until 式2 -式が偽(nil)を返すか, 式の評価中に例外が発生する間, 文を繰り返し実行す -る. +式が偽(nil)を返すか,式の評価中に例外が発生する間,文を繰り返し実行す +る. *** 条件式について -if, unless, while, untilの条件判断部の式, および特殊演算子`...'の両辺 -の式は条件式と呼ばれる. 条件式では文字列と正規表現リテラルは式「$_=~リ -テラル」の省略であるとみなされる. 更に演算子`...'の両辺では整数定数が -「$.==定数」の省略と解釈される. 条件式に現れる演算子 `&&', `||', `!'の -右辺の式も条件式とみなされる. +if,unless,while,untilの条件判断部の式,および特殊演算子`...'の両辺 +の式は条件式と呼ばれる.条件式では文字列と正規表現リテラルは式「$_=~リ +テラル」の省略であるとみなされる.更に演算子`...'の両辺では整数定数が +「$.==定数」の省略と解釈される.条件式に現れる演算子 `&&', `||', `!'の +右辺の式も条件式とみなされる. -注意: 演算子`!'は特殊演算子ではないので, 再定義を行なう場合に気をつけ -ること. 条件式の中で +注意: 演算子`!'は特殊演算子ではないので,再定義を行なう場合に気をつけ +ること.条件式の中で ! 文字列リテラル ! 正規表現リテラル -の形で呼び出されるメソッドの引数は, リテラルの表すオブジェクトではなく, -上記の比較の結果が与えられる. このため, 原則的に`!'メソッドは再定義し -ない方が良い. +の形で呼び出されるメソッドの引数は,リテラルの表すオブジェクトではなく, +上記の比較の結果が与えられる.このため,原則的に`!'メソッドは再定義し +ない方が良い. *** イテレータ(繰り返し子) -** イテレータ - イテレータとは制御構造(特にループ)の抽象化のために用いられるメソッドの -一種である. コードの断片(ブロックと呼ばれる)を指定してイテレータを呼び -出すと, イテレータは適当な値をセットしてブロックを評価する(おそらくは -複数回). イテレータからのブロックの呼び出しはyield式を用いる(後述). +一種である.コードの断片(ブロックと呼ばれる)を指定してイテレータを呼び +出すと,イテレータは適当な値をセットしてブロックを評価する(おそらくは +複数回).イテレータからのブロックの呼び出しはyield式を用いる(後述). -イテレータの呼び出しは以下の構文で行なわれる. +イテレータの呼び出しは以下の構文で行なわれる. イテレータとは制御構造(特にループ)の抽象化のために用いられるメソッドの -一種である. イテレータの呼び出しは以下の構文で行なわれる. +一種である.イテレータの呼び出しは以下の構文で行なわれる. 式 '{' 変数... '|' 文 '}' -「文」をブロックとして設定し, 「式」のメソッドをイテレータとして評価す -る. 「式」のトップレベルのメソッドだけがイテレータとして呼び出され, -レシーバを表す式や, 引数の式はイテレータとしては呼び出されない. 「式」 -が複数の式を含む時, 各々がイテレータとして順に呼ばれる. +「文」をブロックとして設定し,「式」のメソッドをイテレータとして評価す +る.「式」のトップレベルのメソッドだけがイテレータとして呼び出され, +レシーバを表す式や,引数の式はイテレータとしては呼び出されない.「式」 +が複数の式を含む時,各々がイテレータとして順に呼ばれる. -イテレータ内でyield文が実行されると, そこで指定された値がdo文で指定さ -れた変数に代入され, ブロックが実行される. ブロックの実行が終了するとそ -の値は yield文の値として返される. あるメソッドがイテレータとして呼び出 -されたかどうかはメソッドiterator_p()の戻り値で知ることができる. 中には +イテレータ内でyield文が実行されると,そこで指定された値がdo文で指定さ +れた変数に代入され,ブロックが実行される.ブロックの実行が終了するとそ +の値は yield文の値として返される.あるメソッドがイテレータとして呼び出 +されたかどうかはメソッドiterator_p()の戻り値で知ることができる.中には Enumerableモジュールのgrepメソッドのようにイテレータとして呼ばれた時と -普通のメソッドとして呼ばれた時とで動作が異なるメソッドもある. +普通のメソッドとして呼ばれた時とで動作が異なるメソッドもある. -オブジェクトの各要素に対して操作を行なうための形式も提供されている. 形 -式は以下の通り. +オブジェクトの各要素に対して操作を行なうための形式も提供されている.形 +式は以下の通り. for 変数.. in 式 文 end -式の各要素に対し文を実行する. これは以下の式と等価である. +式の各要素に対し文を実行する.これは以下の式と等価である. 式 '{' 変数 '|' 文 '}' -よって式の値のオブジェクトがメソッドeachを持たない場合, forを実行する -と例外が発生する. +よって式の値のオブジェクトがメソッドeachを持たない場合,forを実行する +と例外が発生する. *** イテレータの中でのブロック呼び出し yield '(' [式 [',' 式...]]) yield -イテレータの中でブロックの呼び出しを行なう. yieldを実行したメソッドが -イテレータとして呼び出されていない時には例外が発生する. yield の値はブ -ロックの戻り値である. +イテレータの中でブロックの呼び出しを行なう.yieldを実行したメソッドが +イテレータとして呼び出されていない時には例外が発生する.yield の値はブ +ロックの戻り値である. *** 例外処理 -処理中に予期しない事態が発生した時には例外が発生する. Rubyでは例外を途 -中で捕捉して, 再試行したり, 後処理を行なったりすることができる. +処理中に予期しない事態が発生した時には例外が発生する.Rubyでは例外を途 +中で捕捉して,再試行したり,後処理を行なったりすることができる. protect 文1 @@ -607,49 +605,49 @@ Enumerable 文3] end -文1を実行し, その実行中に例外が発生すればresque節で指定された文2を実行 -する. 更にensure節が存在する時はprotect文を終了する前に必ず(正常終了時 -だけでなく, 例外, return, break, continue, redoなどによる脱出でも)文3 -を実行する. +文1を実行し,その実行中に例外が発生すればresque節で指定された文2を実行 +する.更にensure節が存在する時はprotect文を終了する前に必ず(正常終了時 +だけでなく,例外, return, break, continue, redoなどによる脱出でも)文3 +を実行する. -unless文, until文は条件を評価する時に例外が発生した場合, 評価結果が偽 -であると見なすので, 暗黙の例外処理を行なっていることになる. +unless文,until文は条件を評価する時に例外が発生した場合,評価結果が偽 +であると見なすので,暗黙の例外処理を行なっていることになる. *** グルーピング -式は括弧によってグルーピングすることができる. +式は括弧によってグルーピングすることができる. '(' 式 ')' -更に括弧を用いて, 文(または文の並び)を式にすることもできる. +更に括弧を用いて,文(または文の並び)を式にすることもできる. '(' 文 ';' 文... ')' -文の並びの値は最後に評価した式の値である. つまりの値は最後に評価した文 -の値になる. +文の並びの値は最後に評価した式の値である.つまりの値は最後に評価した文 +の値になる. ** 文 -Rubyプログラムを構成するもう一つの要素は文である. 文には単純文, 制御文, -宣言文がある. 一般に文の値を用いることはないが, 式として用いられる場合 -もあるので, 値を持つ. 通常は文の値はnilである. +Rubyプログラムを構成するもう一つの要素は文である.文には単純文,制御文, +宣言文がある.一般に文の値を用いることはないが,式として用いられる場合 +もあるので,値を持つ.通常は文の値はnilである. *** 式 -式は単純文である. +式は単純文である. *** 多重代入 -同時に複数の変数に代入を行なうことができる. その形式は以下の通りである. +同時に複数の変数に代入を行なうことができる.その形式は以下の通りである. 変数 ',' [変数 ',' ...] ['*' 変数]= 式 [, 式...] -右辺の式が一つしかない場合は, その値を配列として(必要ならばto_aメソッ -ドで配列に変換して), 要素をそれぞれ変数に代入する. それ以外の場合には, -それぞれの式の値が変数に代入される. 左辺の変数の数と右辺の要素の数が合 -わない時には足りない変数には nilが代入され, 余った要素は無視される. 多 -重代入の最後の要素の前に`*'がある場合, 残りの全て引数が配列として代入 -される. +右辺の式が一つしかない場合は,その値を配列として(必要ならばto_aメソッ +ドで配列に変換して),要素をそれぞれ変数に代入する.それ以外の場合には, +それぞれの式の値が変数に代入される.左辺の変数の数と右辺の要素の数が合 +わない時には足りない変数には nilが代入され,余った要素は無視される.多 +重代入の最後の要素の前に`*'がある場合,残りの全て引数が配列として代入 +される. foo, bar = [1, 2] # foo = 1; bar = 2 foo, bar = 1, 2 # foo = 1; bar = 2 @@ -659,19 +657,19 @@ Ruby foo, bar = 1, 2, 3 # foo = 1; bar = 2 foo,*bar = 1, 2, 3 # foo = 1; bar = [2, 3] -多重代入は単純文である. その値は(配列に変換された)右辺である. +多重代入は単純文である.その値は(配列に変換された)右辺である. *** 制御文 -制御の流れを変更する以下の文がある. これらは単純文である. +制御の流れを変更する以下の文がある.これらは単純文である. return文 - return [式[, 式...]] + return [式[',' 式...]] -式の値を戻り値としてメソッドの実行を終了する. 式が2つ以上与えられた時 -には, それらを要素とする配列をメソッドの戻り値とする. 式が一つもない場 -合には nil が戻り値となる. +式の値を戻り値としてメソッドの実行を終了する.式が2つ以上与えられた時 +には,それらを要素とする配列をメソッドの戻り値とする.式が一つもない場 +合には nil が戻り値となる. ループ制御文 @@ -679,406 +677,406 @@ return文 redo break -上記3つはループ中で使う. +上記3つはループ中で使う. -continueはもっとも内側のループの次の繰り返しを始める. redoはループ条件 -のチェックを行なわず, 現在の繰り返しをやり直す. break はループを脱出す -る. Cと違い, breakはもっとも内側のループを脱出する作用だけを持ち, case -を抜ける作用は持たない. +continueはもっとも内側のループの次の繰り返しを始める.redoはループ条件 +のチェックを行なわず,現在の繰り返しをやり直す.break はループを脱出す +る.Cと違い,breakはもっとも内側のループを脱出する作用だけを持ち,case +を抜ける作用は持たない. retry文 retry -protect文のresque節で使い, protect文を始めから実行する. 例外処理を行なっ -てから再試行するのに使う. resque節以外でretryが用いられた場合例外が発 -生する. +protect文のresque節で使い,protect文を始めから実行する.例外処理を行なっ +てから再試行するのに使う.resque節以外でretryが用いられた場合例外が発 +生する. fail文 fail '(' [メッセージ] ')' fail [メッセージ] -例外を発生させる. メッセージが与えられた場合には発生したソースファイル -名, 行番号をシステム変数`$@'に, メッセージを`$!'にセットする. +例外を発生させる.メッセージが与えられた場合には発生したソースファイル +名,行番号をシステム変数`$@'に,メッセージを`$!'にセットする. yield文 yield 式 [',' 式...] -文としてyieldを用いることもできる. この場合は式を括弧で括る必要はない. +文としてyieldを用いることもできる.この場合は式を括弧で括る必要はない. *** メソッド呼び出し文 -1つ以上の引数を持つメソッド呼び出す場合には曖昧さがなければ, 引数を括 -弧で括る必要はない. その形式は以下の通りである. +1つ以上の引数を持つメソッド呼び出す場合には曖昧さがなければ,引数を括 +弧で括る必要はない.その形式は以下の通りである. 式 '.' メソッド名 引数1 ',' [引数2...]['*' 引数n] メソッド名 引数1 ',' [引数2...]['*' 引数n] super 引数1 ',' [引数2... ]['*' 引数n] -構文解析時に, 式のように解釈できる場合は式としての解釈が優先される. +構文解析時に,式のように解釈できる場合は式としての解釈が優先される. foo bar+baz # メソッド呼び出しfoo(bar+baz) foo (bar)+baz # メソッド呼び出しfoo(bar) + bar foo 1 # メソッド呼び出しfoo(1) foo -1 # ローカル変数foo - 1 -括弧のないメソッド呼び出し文は単純文である. +括弧のないメソッド呼び出し文は単純文である. *** 制御修飾子 -単純文に制御修飾子を付加したものは文である(単純文ではない). 修飾子は以 -下の4種類である. +単純文に制御修飾子を付加したものは文である(単純文ではない).修飾子は以 +下の4種類である. 単純文 if 式 単純文 unless 式 単純文 while 式 単純文 until 式 -条件修飾子(if/unless)の式は先行する文に先だって評価される. 動作も対応 -する条件分岐式と同様である. +条件修飾子(if/unless)の式は先行する文に先だって評価される.動作も対応 +する条件分岐式と同様である. 繰り返し修飾子(while/until)はまず先行する文を評価してから条件式を評価 -するので, 最低一度は文を実行することになる. +するので,最低一度は文を実行することになる. *** クラス宣言文 -クラスを定義する構文は以下の通りである. +クラスを定義する構文は以下の通りである. class クラス名 [':' スーパークラス名 ] 定義実体 end -クラス名は任意の識別子である(大文字で始めることを推奨する). クラス定義 -のネストはできないので他の定義文内ではクラスを定義できない. +クラス名は任意の識別子である(大文字で始めることを推奨する).クラス定義 +のネストはできないので他の定義文内ではクラスを定義できない. *** モジュール定義文 -モジュールを定義する構文は以下の通りである. +モジュールを定義する構文は以下の通りである. module クラス名 定義実体 end -モジュール名は大文字で始まる識別子である. クラス同様, モジュール定義も -ネストできない. +モジュール名は大文字で始まる識別子である.クラス同様,モジュール定義も +ネストできない. *** インクルード文 -モジュールをインクルードすることによって, クラスまたはモジュールに機能 -を追加できる. モジュールをインクルードした場合, そのモジュール(および +モジュールをインクルードすることによって,クラスまたはモジュールに機能 +を追加できる.モジュールをインクルードした場合,そのモジュール(および そのモジュールが更にインクルードしているモジュール)の全てのメソッドを -受け継ぐ. 別のいい方をすればインクルードは限定された多重継承といえる. +受け継ぐ.別のいい方をすればインクルードは限定された多重継承といえる. -他のモジュールをインクルードする構文は以下の通りである. +他のモジュールをインクルードする構文は以下の通りである. include モジュール名 [',' モジュール名...] 現在の定義中のクラスまたはモジュール(トップレベルではObjectクラス)に指 -定したモジュールをインクルードする. +定したモジュールをインクルードする. *** メソッド定義文 -通常(特異メソッドでない)メソッド定義の形式は以下の通りである. 通常メソッ -ド定義はネストできないので, メソッド定義文中ではメソッド定義文を再び呼 -び出せない. +通常(特異メソッドでない)メソッド定義の形式は以下の通りである.通常メソッ +ド定義はネストできないので,メソッド定義文中ではメソッド定義文を再び呼 +び出せない. def メソッド名 ['(' 引数 [',' 引数...][',' '*'引数 ] ')'] 定義実体 end -メソッド名は識別子または文字列である. 演算子の再定義をする時には文字列 -で指定する. 仮引数並びの最後に`*'がある場合, 仮引数より多く与えられた -実引数は, 最後の引数に配列として与えられる(足りない時にはエラー). +メソッド名は識別子または文字列である.演算子の再定義をする時には文字列 +で指定する.仮引数並びの最後に`*'がある場合,仮引数より多く与えられた +実引数は,最後の引数に配列として与えられる(足りない時にはエラー). -メソッドには関数的メソッドと通常メソッドがある. 関数的メソッドは関数形 -式でしか呼び出すことができず, よって該当するクラスとそのサブクラスのメ -ソッドからしか呼び出すことができない. クラス定義文の外にあるdef文は関 -数的メソッドを定義し, クラス定義文の中にあるdef文は通常のメソッドを定 -義する. メソッドの可視性はModuleクラスのexport/noexportメソッドを使っ -て変更する. +メソッドには関数的メソッドと通常メソッドがある.関数的メソッドは関数形 +式でしか呼び出すことができず,よって該当するクラスとそのサブクラスのメ +ソッドからしか呼び出すことができない.クラス定義文の外にあるdef文は関 +数的メソッドを定義し,クラス定義文の中にあるdef文は通常のメソッドを定 +義する.メソッドの可視性はModuleクラスのexport/noexportメソッドを使っ +て変更する. ** 特異メソッド定義文 -メソッド定義にはもう一つ特異メソッドの定義がある. 特異メソッドとはある -特定のオブジェクトに固有のメソッドである. 形式は以下の通りである. +メソッド定義にはもう一つ特異メソッドの定義がある.特異メソッドとはある +特定のオブジェクトに固有のメソッドである.形式は以下の通りである. def 式 '.' メソッド名 ['(' 引数 [',' 引数...][',' '*'引数 ] ')'] 定義実体 end -この形式は式の値であるオブジェクトに特異メソッドを定義する. 式の値は -(ビルトインクラスでない)通常オブジェクトか, クラスまたはモジュールであ -る必要がある. 通常メソッド定義とは異なり, 特異メソッドはメソッド本体内 -でもネストして定義することができる. +この形式は式の値であるオブジェクトに特異メソッドを定義する.式の値は +(ビルトインクラスでない)通常オブジェクトか,クラスまたはモジュールであ +る必要がある.通常メソッド定義とは異なり,特異メソッドはメソッド本体内 +でもネストして定義することができる. -特異メソッドは通常は継承しえないが, 例外としてクラスの特異メソッドはそ -のサブクラスにも継承される. 言い替えればクラスの特異メソッドは他のオブ -ジェクト指向システムにおけるクラスメソッドの働きをする. +特異メソッドは通常は継承しえないが,例外としてクラスの特異メソッドはそ +のサブクラスにも継承される.言い替えればクラスの特異メソッドは他のオブ +ジェクト指向システムにおけるクラスメソッドの働きをする. *** メソッドの別名定義文 -以下の形式でメソッドに別名をつけることができる. +以下の形式でメソッドに別名をつけることができる. def メソッド名1 メソッド名2 -別名を付けられたメソッドは, その時点でのメソッド定義を引き継ぎ, 元のメ -ソッドが再定義されても, 古いメソッドが呼び出されたのと全く同じ働きをす -る. +別名を付けられたメソッドは,その時点でのメソッド定義を引き継ぎ,元のメ +ソッドが再定義されても,古いメソッドが呼び出されたのと全く同じ働きをす +る. *** メソッド定義取り消し文 -メソッドの定義を取り消すためにはundefを用いる. +メソッドの定義を取り消すためにはundefを用いる. undef メソッド名 -識別子または文字列で指定したメソッドの定義を取り消す. +識別子または文字列で指定したメソッドの定義を取り消す. defによる別名定義とundefによる定義取り消しを使うとクラスのインタフェー -スをスーパークラスと独立に変更することができる. ただし, メソッドがself +スをスーパークラスと独立に変更することができる.ただし,メソッドがself にメッセージを送っている場合にはよく注意しないと既存のメソッドが動作し -なくなる可能性がある. +なくなる可能性がある. ------------------------------------------------------- * Rubyの組み込み機能 -Rubyプログラミングの基本はクラス, モジュールとそのメソッドの習得である. -Rubyには処理系そのものに以下の機能が組み込まれている. ライブラリをロー -ドすることによって機能は増えるが, それらに関してはそれぞれのライブラリ -のドキュメントを参照してもらいたい. +Rubyプログラミングの基本はクラス,モジュールとそのメソッドの習得である. +Rubyには処理系そのものに以下の機能が組み込まれている.ライブラリをロー +ドすることによって機能は増えるが,それらに関してはそれぞれのライブラリ +のドキュメントを参照してもらいたい. ** 関数 Rubyには厳密な意味では関数はないがKernelクラスの関数メソッドは(全ての -通常クラスから関数形式で呼び出せるので), 関数的に用いられる. 関数的に -用いられるメソッドを以下にあげる. これらのメソッドを再定義する際には互 -換性を考えて行なうべきである. +通常クラスから関数形式で呼び出せるので),関数的に用いられる.関数的に +用いられるメソッドを以下にあげる.これらのメソッドを再定義する際には互 +換性を考えて行なうべきである. _exit(status) - プログラムの実行を終了する. 整数statusを終了ステータスとする. - exit()とは違って, 例外処理などは一切行なわない. fork()の後, 子 - プロセスを終了させる時などに用いる. + プログラムの実行を終了する.整数statusを終了ステータスとする. + exit()とは違って,例外処理などは一切行なわない.fork()の後,子 + プロセスを終了させる時などに用いる. eof() - コマンドラインからの入力がEOFに到達している場合, 真を返す. + コマンドラインからの入力がEOFに到達している場合,真を返す. eval(expr) - exprとして与えられた文字列をrubyプログラムとして解釈,実行する. + exprとして与えられた文字列をrubyプログラムとして解釈,実行する. exec(command) - 現在実行しているプロセスを終了して, command文字列で指定される - 別プロセスを起動する. + 現在実行しているプロセスを終了して,command文字列で指定される + 別プロセスを起動する. exit([status]) - プログラムの実行を終了する. statusとして整数が与えられた場合, - その値をRubyコマンドの終了ステータスとする. デフォルトは0. + プログラムの実行を終了する.statusとして整数が与えられた場合, + その値をRubyコマンドの終了ステータスとする.デフォルトは0. fork() - forkシステムコールを実行し, 子プロセスを生成する. 詳細は - fork(2)を参照のこと. 親プロセス側では子プロセスのプロセスidを - 返し, 子プロセス側ではnilを返す. 何らかの原因で子プロセスの生 - 成に失敗した時には例外が発生する. + forkシステムコールを実行し,子プロセスを生成する.詳細は + fork(2)を参照のこと.親プロセス側では子プロセスのプロセスidを + 返し,子プロセス側ではnilを返す.何らかの原因で子プロセスの生 + 成に失敗した時には例外が発生する. format(format, ...) フォーマットとして与えられた文字列をC言語のsprintfと同じように - 解釈し, 引数を展開した文字列を返す. メソッドsprintf()の別名. + 解釈し,引数を展開した文字列を返す.メソッドsprintf()の別名. Rubyにおけるformat指定子の拡張についてはsprintf()の項を参照の - こと. + こと. getc() - 標準入力から一文字取り出す. 戻り値は読み込んだ文字の文字コード - (ASCII)を表すFixnumである. + 標準入力から一文字取り出す.戻り値は読み込んだ文字の文字コード + (ASCII)を表すFixnumである. getenv(name) - nameに該当する環境変数を取り出す. $ENV[name]と同義. + nameに該当する環境変数を取り出す.$ENV[name]と同義. gets() 引数として与えられたファイル(なければ標準入力)で構成される仮想 - 的なファイル($ARGFでアクセスできる)から一行読み込んで, 読み込 - みに成功した時にはその文字列を返す. ファイルの終りに到達した時 - にはnilを返す. 行の区切りはシステム変数`$/'によって変更できる. - 読み込んだ文字列はシステム変数`$_'にもセットされる. + 的なファイル(システム変数`$<'でアクセスできる)から一行読み込ん + で,読み込みに成功した時にはその文字列を返す.ファイルの終りに + 到達した時にはnilを返す.行の区切りはシステム変数`$/'によって + 変更できる.読み込んだ文字列はシステム変数`$_'にもセットされる. gsub(pattern, replace) - システム変数`$_'の指す文字列に対して置換を行なう. 文字列内で - patternにマッチする部分を全てreplaceに置き換える. Stringクラス - のgsubメソッドの解説を参照のこと. gsubメソッドは`$_'の値を更新 - する. + システム変数`$_'の指す文字列に対して置換を行なう.文字列内で + patternにマッチする部分を全てreplaceに置き換える.Stringクラス + のgsubメソッドの解説を参照のこと.gsubメソッドは`$_'の値を更新 + する. iterator_p() - メソッドがイテレータとして呼び出された時に真, そうでない時に偽 - を返す述語. + メソッドがイテレータとして呼び出された時に真,そうでない時に偽 + を返す述語. kill(signal, pid...) - pidで指定されたプロセスにシグナルを送る. シグナルはシグナル番 - 号か名前で指定する. 負の値を持つシグナル(あるいはシグナル名の + pidで指定されたプロセスにシグナルを送る.シグナルはシグナル番 + 号か名前で指定する.負の値を持つシグナル(あるいはシグナル名の 前に`-')を与えるとプロセスではなくプロセスグループにシグナルを - 送る. + 送る. load(file) - fileをロードする. fileをロードするパスはシステム変数$LOAD_PATH - で決定される. + fileをロードする.fileをロードするパスはシステム変数$LOAD_PATH + で決定される. open(file[, mode]) - fileをオープンして, Fileオブジェクトを返す. ファイル名はオープ - ンするファイルを示す. ファイル名が`|'で始まる時には続く文字列 - をコマンドとして起動し, パイプラインを生成する. + fileをオープンして,Fileオブジェクトを返す.ファイル名はオープ + ンするファイルを示す.ファイル名が`|'で始まる時には続く文字列 + をコマンドとして起動し,パイプラインを生成する. - コマンド名が"-"である時, open()はRubyの子プロセスを生成し, そ - の子プロセスとのパイプを返す. + コマンド名が"-"である時,open()はRubyの子プロセスを生成し,そ + の子プロセスとのパイプを返す. - modeはファイルのアクセスモードを指定する. これは以下のうちのい - ずれかの文字列である. + modeはファイルのアクセスモードを指定する.これは以下のうちのい + ずれかの文字列である. - r 読み込み専用. openするファイルはあらかじめ存在している - 必要がある. + r 読み込み専用.openするファイルはあらかじめ存在している + 必要がある. - r+ 読み書き両用. openするファイルはあらかじめ存在している - 必要がある. + r+ 読み書き両用.openするファイルはあらかじめ存在している + 必要がある. - w 書き込み専用. ファイルが存在していた場合, 長さを0にす - る. 存在していなければ新たにファイルを作成する. + w 書き込み専用.ファイルが存在していた場合,長さを0にす + る.存在していなければ新たにファイルを作成する. - w+ 読み書き両用. 読み込みが行なえること以外は"w"と同じ働き - をする. + w+ 読み書き両用.読み込みが行なえること以外は"w"と同じ働き + をする. - a 追加書き込み専用. ファイルはあらかじめ存在している必要 - がある. 書き込みはファイルの最後に追加される. + a 追加書き込み専用.ファイルはあらかじめ存在している必要 + がある.書き込みはファイルの最後に追加される. - a+ 読み書き両用. ファイルが存在していなければ新たに作成す - る. アクセス位置はファイルの最後に初期化される. + a+ 読み書き両用.ファイルが存在していなければ新たに作成す + る.アクセス位置はファイルの最後に初期化される. - モードが省略された場合のデフォルトは"r"である. + モードが省略された場合のデフォルトは"r"である. print(arg1, ..., argn) - 引数を順に出力する. 引数が与えられない時にはレシーバを出力する. - 文字列以外のオブジェクトが引数として与えられた場合には, 当該オ - ブジェクトのto_sメソッドによって文字列に変換してから出力される. + 引数を順に出力する.引数が与えられない時にはレシーバを出力する. + 文字列以外のオブジェクトが引数として与えられた場合には,当該オ + ブジェクトのto_sメソッドによって文字列に変換してから出力される. システム変数`$;'(出力フィールドセパレータ)にnilでない値がセッ - トされている時には, 各引数の間にその文字列を出力する. システム + トされている時には,各引数の間にその文字列を出力する.システム 変数`$\'(出力フィールドセパレータ)にnil でない値がセットされて - いる時には, 最後にそれを出力する. + いる時には,最後にそれを出力する. printf([port, ]format, arg1, ..., argn) - C言語のprintf()と同じformatに従い引数を文字列に変換し, 出力す - る. 第1引数がIOのサブクラスのインスタンスであった場合はそのオ - ブジェクトに対して出力を行なう. デフォルトは$stdoutに出力する. + C言語のprintf()と同じformatに従い引数を文字列に変換し,出力す + る.第1引数がIOのサブクラスのインスタンスであった場合はそのオ + ブジェクトに対して出力を行なう.デフォルトは$stdoutに出力する. Rubyにおけるformat指定子の拡張についてはsprintf()の項を参照の - こと. + こと. rand(max) - 0からmaxを越えない範囲の整数の乱数を発生する. 戻り値はFixnum. + 0からmaxを越えない範囲の整数の乱数を発生する.戻り値はFixnum. require(file) - fileをロードする. loadとの動作の違いはrequireはロードしたファ - イルのフルパスを変数$LOAD_FILESに覚えていて, 既にロードしたファ - イルは再ロードしない点である. 実際にロードした時には%TRUE, 既 - にロードされている時には%FALSEを返す. + fileをロードする.loadとの動作の違いはrequireはロードしたファ + イルのフルパスを変数`$"'に覚えていて,既にロードしたファイルは + 再ロードしない点である.実際にロードした時には%TRUE,既にロー + ドされている時には%FALSEを返す. select(reads[, writes[, execpts[, timeout]]]) - select(2)を実行する. reads/writes/execptsにはIO(またはそのサブ - クラス)のインスタンスの配列を与える. timeoutはFixnum / Float - / Timeのいずれかで指定する. 戻り値はtimeoutが成立した場合には - nil, そうでないときは3要素の配列を返し, その各要素が入力/出力/ - 例外待ちのオブジェクトを要素として持つ. + select(2)を実行する.reads/writes/execptsにはIO(またはそのサブ + クラス)のインスタンスの配列を与える.timeoutはFixnum / Float + / Timeのいずれかで指定する.戻り値はtimeoutが成立した場合には + nil,そうでないときは3要素の配列を返し,その各要素が入力/出力/ + 例外待ちのオブジェクトを要素として持つ. setenv(name, value) - nameで指定される環境変数をvalueにセットする. $ENV[name]=value - と同じ働きをする. + nameで指定される環境変数をvalueにセットする.$ENV[name]=value + と同じ働きをする. sleep([sec]) - sec秒だけプログラムの実行を停止する. secが省略された場合, プロ - セスにSIGALRMが送られない限り, 永久にスリープする. 実際にスリー - プした秒数を返す. + sec秒だけプログラムの実行を停止する.secが省略された場合,プロ + セスにSIGALRMが送られない限り,永久にスリープする.実際にスリー + プした秒数を返す. sprintf(format, ...) - format文字列をC言語のsprintfと同じように解釈し, 引数を展開した - 文字列を返す. メソッドformat()の別名. + format文字列をC言語のsprintfと同じように解釈し,引数を展開した + 文字列を返す.メソッドformat()の別名. - format指定子はC言語のsprintf()が受け付けるもの(ただし, Rubyに - は unsignedがないので, %uは除く)に加えて, %b, %B, %O, %Xを使う - ことができる. %bは数値の2進表示, %B, %O, %Xは, それぞれ, 2進, - 8 進, 16進数の表示を行なうが, 負の数の処理の際に2の補数表現で - はなく, その絶対値表記の先頭に`-'をつけたものを表示する. + format指定子はC言語のsprintf()が受け付けるもの(ただし,Rubyに + は unsignedがないので,%uは除く)に加えて, %b, %B, %O, %Xを使う + ことができる.%bは数値の2進表示,%B, %O, %Xはそれぞれ2進,8進, + 16進数の表示を行なうが,負の数の処理の際に2の補数表現ではなく, + その絶対値表記の先頭に`-'をつけたものを表示する. srand([初期値]) - 乱数の初期値を設定し, 古い初期値を返す. 初期値が省略された時に - はtime(3)の返す値をデフォルトとする. + 乱数の初期値を設定し,古い初期値を返す.初期値が省略された時に + はtime(3)の返す値をデフォルトとする. sub(pattern, replace) - システム変数`$_'の指す文字列に対して置換を行なう. 文字列内で最 - 初にpatternにマッチする部分をreplaceに置き換える. subメソッド - は`$_'の値を更新する. その他の詳細に関してはStringクラスのsub - メソッドの解説を参照のこと. + システム変数`$_'の指す文字列に対して置換を行なう.文字列内で最 + 初にpatternにマッチする部分をreplaceに置き換える.subメソッド + は`$_'の値を更新する.その他の詳細に関してはStringクラスのsub + メソッドの解説を参照のこと. syscall(num, arg...) - numで指定された番号のシステムコールを実行する. 第2引数以降をシ - ステムコールの引数として渡す. 引数は文字列または整数でなければ - ならない. + numで指定された番号のシステムコールを実行する.第2引数以降をシ + ステムコールの引数として渡す.引数は文字列または整数でなければ + ならない. system(command) - コマンドを実行し, その終了ステータスを返す. + コマンドを実行し,その終了ステータスを返す. trap(command, signal...) - signalの割り込みがかかった時にcommandを実行する. signalはシグ - ナル名かシグナルの番号. commandとして"SIG_IGN"または"IGNORE"を - 指定した時にはそのシグナルを無視する(可能ならば). "SIG_DFL"ま - たは"DEFAULT"を指定した時はデフォルトの動作を行なう. + signalの割り込みがかかった時にcommandを実行する.signalはシグ + ナル名かシグナルの番号.commandとして"SIG_IGN"または"IGNORE"を + 指定した時にはそのシグナルを無視する(可能ならば)."SIG_DFL"ま + たは"DEFAULT"を指定した時はデフォルトの動作を行なう. wait() - 子プロセスが終了するのを待ち, 終了した子プロセスのpidを返す. - 子プロセスが一つもなければnilを返す. + 子プロセスが終了するのを待ち,終了した子プロセスのpidを返す. + 子プロセスが一つもなければnilを返す. waitpid(pid, flags) - 特定の子プロセスの終了を待ち, そのプロセスが終了した時に真を返 - す. 子プロセスが存在しないか, ノンブロッキングモードで子プロセ - スがまだ終了していない時にはnilを返す. waitpid(2)かwait4(2)の + 特定の子プロセスの終了を待ち,そのプロセスが終了した時に真を返 + す.子プロセスが存在しないか,ノンブロッキングモードで子プロセ + スがまだ終了していない時にはnilを返す.waitpid(2)かwait4(2)の 実装されていないマシンではflagsはいつもnilまたは0でなければな - らない. + らない. ** システム変数 - $! エラーメッセージ. failで設定する. + $! エラーメッセージ.failで設定する. $@ エラーが発生した時点のファイル名と行番号が "ファイル:行番号[:メソッド名(あれば)]" - の形式で格納される. + の形式で格納される. $& 最後に成功したパターンマッチ @@ -1089,77 +1087,82 @@ Ruby $+ 最後の検索パターンでマッチした最後の括弧 $1..$9 最後に成功したパターンマッチでn番目の括弧にマッチした - 値が格納される. 該当する括弧がなければnilが入っている. + 値が格納される.該当する括弧がなければnilが入っている. - $~ 最後のマッチに関する情報. これをセットすると$&や$1..$9 - の値が変化する. + $~ 最後のマッチに関する情報.これをセットすると$&や$1..$9 + の値が変化する. - $= この変数の値がnilでない時, パターンマッチや文字列の比 - 較でアルファベットの大文字小文字を区別しない. デフォル - トはnil(区別する). + $= この変数の値がnilでない時,パターンマッチや文字列の比 + 較でアルファベットの大文字小文字を区別しない.デフォル + トはnil(区別する). - $/ 入力レコードセパレータ. ファイルや文字列に対してeachを - 行なう時の分割文字を指定する. $/に空文字列("")を指定す - ると段落単位で入力を行ない, nilを指定すると全体を一度 - に読み込む. $/には正規表現は使えない. デフォルトは - "\n". + $/ 入力レコードセパレータ.ファイルや文字列に対してeachを + 行なう時の分割文字を指定する.$/に空文字列("")を指定す + ると段落単位で入力を行ない,nilを指定すると全体を一度 + に読み込む.$/には正規表現は使えない.デフォルトは + "\n". - $\ 出力レコードセパレータ. この変数に文字列を指定すると + $\ 出力レコードセパレータ.この変数に文字列を指定すると write()やprint()の度に最後にこの文字列を付加して出力す - る. デフォルトはnil(なにも追加しない). + る.デフォルトはnil(なにも追加しない). - $, Array:join()のデフォルトの区切り文字列. print()の各引 - 数の間に出力される文字列. + $, Array:join()のデフォルトの区切り文字列.print()の各引 + 数の間に出力される文字列. - $; String:split()のデフォルトの区切り文字. + $; String:split()のデフォルトの区切り文字. - $. 最後に読んだ入力ファイルの行番号. + $. 最後に読んだ入力ファイルの行番号. - $< 仮想ファイル$ARGFで現在読み込み中の(メソッドgets()が今 - 読んでいる)ファイル名.(覚え方: `<'はシェルの入力指定) + $< 引数(なければ標準入力)で構成される仮想ファイル.つまり + gets()は$<.gets()と同じ意味である.$<.fileで現在読み込 + み中のファイルオブジェクトが,$<.filenameでそのファイ + ル名が得られる.(覚え方: `<'はシェルの入力元指定) - $> printやprintfのデフォルトの出力先. 初期値は$stdout. - (覚え方: `>'はシェルの出力先指定) + $> printやprintfのデフォルトの出力先.初期値は$stdout.-i + オプションを指定した場合には読み込み元と同じ名前のファ + イル.(覚え方: `>'はシェルの出力先指定) - $_ 最後にgets()などで読み込んだ文字列. + $_ 最後にgets()などで読み込んだ文字列. - $0 rubyスクリプトの名前. この変数に代入するとps(1)の出力 - が変化する. + $0 rubyスクリプトの名前.この変数に代入するとps(1)の出力 + が変化する. - $* rubyスクリプトに与えられた引数. ruby自身に対する引数は - 取り除かれている. + $* rubyスクリプトに与えられた引数.ruby自身に対する引数は + 取り除かれている. - $$ 現在実行中のrubyプロセスのpid. + $$ 現在実行中のrubyプロセスのpid. - $? 最後に実行した子プロセスのstatus. + $? 最後に実行した子プロセスのstatus. $: ファイルをロードする時に検索するディレクトリへのパスを - 含む配列. 起動時にはデフォルト値(コンパイル時に指定す - る)に加えて, 環境変数RUBYLIBの値とruby起動時の-Iオプショ + 含む配列.起動時にはデフォルト値(コンパイル時に指定す + る)に加えて,環境変数RUBYLIBの値とruby起動時の-Iオプショ ンで指定された値が追加される.(覚え方: コロンは環境変 数PATHの区切り文字である) - $" ロードされたファイル名を含む配列.同じファイルを2回ロー - ドしないために用いられる.(覚え方: prevent files to be - doubly quoted(loaded)) - - $ARGV $*と同じ. + $" 既にロードされたファイル名を含む配列.require()で同じ + ファイルを2回ロードしないために用いられる.(覚え方: + prevent files to be doubly quoted(loaded)) - $ENV 環境変数にアクセスする連想配列. + $ARGF $<の別名. - $FILENAME $<と同じ. + $ARGV $*の別名. $DEBUG `-d'フラグの状態(真偽値). - $LOAD_PATH $:と同じ. + $ENV 環境変数にアクセスする連想配列.文字列をキーとして与え + ると対応する環境変数の値が得られる.環境変数が存在しな + い場合はnilが返る. + + $FILENAME 仮想ファイル`$<'で現在読み込み中の(メソッドgets()が今 + 読んでいる)ファイル名.$<.filenameと同じ. + + $LOAD_PATH $:の別名. $stdin 標準入力 $stdout 標準出力 $stderr 標準エラー出力 - $ARGF 引数(なければ標準入力)で構成される仮想ファイル. つまり - gets()は$ARGF.gets()と同じ意味である. - $VERBOSE `-v'フラグの状態(真偽値) $VERSION rubyのバージョンを示す文字列 @@ -1169,12 +1172,12 @@ Ruby %TRUE t %FALSE nil - それぞれ真偽値を表す. 条件判断はnilを偽, それ以外の全ての値を - 真として判断するため, %TRUEの値は代表的な真の値という以上の意 - 味を持たない. よって, あるメソッドの返値が真であるということと, + それぞれ真偽値を表す.条件判断はnilを偽,それ以外の全ての値を + 真として判断するため,%TRUEの値は代表的な真の値という以上の意 + 味を持たない.よって,あるメソッドの返値が真であるということと, それが%TRUEを返すということは厳密には同じではない(述語的に用い られるメソッドは大抵真の値として%TRUEを返すようにはなっている - が). つまり + が).つまり if some.method() then .. else .. end @@ -1182,15 +1185,15 @@ Ruby if some.method() == %TRUE then .. else .. end - は完全には同義ではない. %FALSEに関しては, このような問題は生じ - ない. + は完全には同義ではない.%FALSEに関しては,このような問題は生じ + ない. ** クラス/モジュール *** Array(クラス) -数字を添字とした配列のクラスである. 生成は一般的には配列式``[...]''で -行なわれる. +数字を添字とした配列のクラスである.生成は一般的には配列式``[...]''で +行なわれる. SuperClass: Object @@ -1202,21 +1205,21 @@ Methods: self[start..end] self[start, length] - 配列の要素にアクセスする. 最初の形式では配列のnth番目の要素を - 返し, 2番目の形式ではstart番目の要素からend番目の要素を含む部 - 分配列を返す. 3番目の形式ではstart番目からlength個の要素を含む - 部分配列を返す. + 配列の要素にアクセスする.最初の形式では配列のnth番目の要素を + 返し,2番目の形式ではstart番目の要素からend番目の要素を含む部 + 分配列を返す.3番目の形式ではstart番目からlength個の要素を含む + 部分配列を返す. self[nth] = val self[start..end] = val self[start, length] = val - 配列の要素を変更する. 最初の形式では配列のnth番目の要素をvalに - 変更する. 2番目の形式はstart番目の要素からend番目の要素までを - valに変更する. 3番目の形式ではstart番目からlength個の要素をval - に変更する. + 配列の要素を変更する.最初の形式では配列のnth番目の要素をvalに + 変更する.2番目の形式はstart番目の要素からend番目の要素までを + valに変更する.3番目の形式ではstart番目からlength個の要素をval + に変更する. - 2番目, 3番目の形式ではvalは配列でなければならない. + 2番目,3番目の形式ではvalは配列でなければならない. 例: @@ -1226,12 +1229,12 @@ Methods: self + other - 配列の連結. selfとotherの両方の配列の内容を繋げた新しい配列を - 返す. + 配列の連結.selfとotherの両方の配列の内容を繋げた新しい配列を + 返す. self * times - 配列の繰り返し. + 配列の繰り返し. self - other @@ -1250,73 +1253,73 @@ Methods: self << obj - objを配列の末尾に追加する. selfを返すのでC++的に連鎖できる. + objを配列の末尾に追加する.selfを返すのでC++的に連鎖できる. assoc(key) - 連想リスト(2要素の配列を要素とする配列)を検索し, 第1要素がkey - と等しい("=="で比較する)配列を返す. + 連想リスト(2要素の配列を要素とする配列)を検索し,第1要素がkey + と等しい("=="で比較する)配列を返す. clear - 配列の大きさを0にする. + 配列の大きさを0にする. delete(val) - valと一致する要素を削除する. + valと一致する要素を削除する. delete_if - 要素を削除するイテレータ. ブロックを評価した値が真の時, 対応す - る要素を配列から削除する. + 要素を削除するイテレータ.ブロックを評価した値が真の時,対応す + る要素を配列から削除する. each - 配列の各要素を順に与えるイテレータ. + 配列の各要素を順に与えるイテレータ. fill(val) fill(val, start[, length]) fill(val, start..end) - 配列(の指定された部分)の要素の値をvalに設定する. 2番めの形式で - lengthが省略された時は配列の終りまでの長さをとる. 指定された部 - 分配列が元の配列の範囲を越える時は自動的に拡張される. + 配列(の指定された部分)の要素の値をvalに設定する.2番めの形式で + lengthが省略された時は配列の終りまでの長さをとる.指定された部 + 分配列が元の配列の範囲を越える時は自動的に拡張される. index(val) - valと等しい最初の要素のインデックスを返す. 該当する要素が存在 - しない場合はnilを返す. + valと等しい最初の要素のインデックスを返す.該当する要素が存在 + しない場合はnilを返す. indexes(ary) indexes(index-1, ..., index-n) - 1番目の形式では整数の配列を引数として受けて, その要素をインデッ - クスとする要素を含む配列を返す. 2番目の形式では各引数の値をイ - ンデックスとする要素を含む配列を返す. + 1番目の形式では整数の配列を引数として受けて,その要素をインデッ + クスとする要素を含む配列を返す.2番目の形式では各引数の値をイ + ンデックスとする要素を含む配列を返す. join([sep]) - 配列の要素を連結した文字列を返す. 各要素は文字列に変換され, 間 - にsepを挟んで連結される. sepが省略された時にはシステム変数`$,' - の値が用いられる. + 配列の要素を連結した文字列を返す.各要素は文字列に変換され,間 + にsepを挟んで連結される.sepが省略された時にはシステム変数`$,' + の値が用いられる. length size - 配列の長さ(要素数)を返す. + 配列の長さ(要素数)を返す. push(obj) - objを配列の末尾に追加する. + objを配列の末尾に追加する. pack(template) - 配列の内容をtemplate文字列にしたがって, 1つの文字列にパックす - る. パックした文字列を返す. テンプレートは型指定文字列とその長 - さ(省略時は1)を並べたものである. 長さとして`*'が指定された時は - 「残りのデータ全て」の長さを表す. + 配列の内容をtemplate文字列にしたがって,1つの文字列にパックす + る.パックした文字列を返す.テンプレートは型指定文字列とその長 + さ(省略時は1)を並べたものである.長さとして`*'が指定された時は + 「残りのデータ全て」の長さを表す. - 型指定文字は以下のものがある. + 型指定文字は以下のものがある. a ASCII文字列(null文字を詰める) A ASCII文字列(スペースを詰める) @@ -1342,41 +1345,41 @@ Methods: pop - 配列の末尾の要素を取り除いて, それを返す. + 配列の末尾の要素を取り除いて,それを返す. rassoc(value) - 連想リスト(2要素の配列を要素とする配列)を検索し, 第2要素が - valueと等しい("=="で比較する)配列を返す. + 連想リスト(2要素の配列を要素とする配列)を検索し,第2要素が + valueと等しい("=="で比較する)配列を返す. shift - 配列の先頭の要素を取り除いて, それを返す. + 配列の先頭の要素を取り除いて,それを返す. sort - 配列の内容をソートする. イテレータとして呼び出された場合はブロッ - クを評価した値で要素の大小を決定する. 大きい時に正, 等しい時に - 0, 小さき時に負. 通常のメソッドとして呼び出された場合は各要素 - を`<=>'で比較する. + 配列の内容をソートする.イテレータとして呼び出された場合はブロッ + クを評価した値で要素の大小を決定する.大きい時に正,等しい時に + 0,小さき時に負.通常のメソッドとして呼び出された場合は各要素 + を`<=>'で比較する. to_a - 自分自身を返す. 対称性のために用意されているメソッドであまり面 - 白くない. + 自分自身を返す.対称性のために用意されているメソッドであまり面 + 白くない. unshift(obj) - objを配列の先頭に追加する. + objを配列の先頭に追加する. *** Bignum(クラス) -無限多倍長整数のクラス. 演算の結果がこのFixnumの範囲内である場合には自 -動的にクラスはFixnumに変換される. 一般的にRubyプログラムではFixnumと -Bignumの変換は暗黙のうちに行われるので, 意識する必要は無い. Floatとの -混合に関しては, Bignumより Floatの方がgenericityが高いのにも関わらず, -Bignumの方が, 大きな値を表現できるので, 変換時に桁落ちが生じる可能性が -ある. +無限多倍長整数のクラス.演算の結果がこのFixnumの範囲内である場合には自 +動的にクラスはFixnumに変換される.一般的にRubyプログラムではFixnumと +Bignumの変換は暗黙のうちに行われるので,意識する必要は無い.Floatとの +混合に関しては,Bignumより Floatの方がgenericityが高いのにも関わらず, +Bignumの方が,大きな値を表現できるので,変換時に桁落ちが生じる可能性が +ある. SuperClass: Integer @@ -1390,33 +1393,33 @@ Methods: self % other self ** other - 算術演算. それぞれ和, 差, 積, 商, 剰余, 冪乗を返す. + 算術演算.それぞれ和,差,積,商,剰余,冪乗を返す. ~ self self | other self & other self ^ other - ビット演算. それぞれビット反転, 論理和, 論理積, 排他的論理和を - 返す. + ビット演算.それぞれビット反転,論理和,論理積,排他的論理和を + 返す. self << bits self >> bits - シフト演算. それぞれbitsビットだけ左右にビットシフトを行なう. + シフト演算.それぞれbitsビットだけ左右にビットシフトを行なう. divmod(other) - 商と剰余の2要素の配列を返す. + 商と剰余の2要素の配列を返す. *** Class(クラス) -クラスのクラス. より厳密に説明するとクラスは特異メソッドを継承するため -に, それぞれメタクラスと呼ばれる名前のないクラスをクラスとして持ち, -Classはそのメタクラスのクラスである(分かったかな?). が, この解説が理解 -できなくても, Rubyを使うことに何の支障もない. クラスには特異メソッドを -定義できる事と, スーパークラスで定義された特異メソッドはそのサブクラス -でも有効である事を知れば十分である. +クラスのクラス.より厳密に説明するとクラスは特異メソッドを継承するため +に,それぞれメタクラスと呼ばれる名前のないクラスをクラスとして持ち, +Classはそのメタクラスのクラスである(分かったかな?).が,この解説が理解 +できなくても,Rubyを使うことに何の支障もない.クラスには特異メソッドを +定義できる事と,スーパークラスで定義された特異メソッドはそのサブクラス +でも有効である事を知れば十分である. SuperClass: Module @@ -1424,55 +1427,55 @@ Private Methods: attr(name[, public]) - そのクラスのインスタンスに対してnameで指定される属性を定義する. - 詳しくはModuleのattrメソッドの項を参照のこと. + そのクラスのインスタンスに対してnameで指定される属性を定義する. + 詳しくはModuleのattrメソッドの項を参照のこと. Methods: new(...) - クラスのインスタンスを生成する. 多くの場合このメソッドはサブク - ラスの特異メソッドによってオーバーライドされ, クラスによって引 - 数が異なる. + クラスのインスタンスを生成する.多くの場合このメソッドはサブク + ラスの特異メソッドによってオーバーライドされ,クラスによって引 + 数が異なる. *** Comparable(モジュール) -比較演算を許すクラスのためのMixin. このモジュールをインクルードするこ -とによって, `<=>'演算子を定義するだけで他の演算子はその定義を利用して -派生できる. +比較演算を許すクラスのためのMixin.このモジュールをインクルードするこ +とによって,`<=>'演算子を定義するだけで他の演算子はその定義を利用して +派生できる. Methods: self == other - selfがotherと等しい時真を返す. + selfがotherと等しい時真を返す. self > other - selfがotherより大きい時真を返す. + selfがotherより大きい時真を返す. self >= other - selfがotherより大きいか等しい時真を返す. + selfがotherより大きいか等しい時真を返す. self < other - selfがotherより小さい時真を返す. + selfがotherより小さい時真を返す. self <= other - selfがotherより小さいか等しい時真を返す. + selfがotherより小さいか等しい時真を返す. between(min, max) - selfがminとmaxの範囲内にある時真を返す. + selfがminとmaxの範囲内にある時真を返す. *** DBM(クラス) -NDBMファイルをアクセスするクラス. キー, データともに文字列でなければな -らないという制限と, データがファイルに保存されるという点を除いては -Dictクラスと全く同様に扱うことができる. NDBMを備えていないシステムでは -このクラスは定義されない. +NDBMファイルをアクセスするクラス.キー,データともに文字列でなければな +らないという制限と,データがファイルに保存されるという点を除いては +Dictクラスと全く同様に扱うことができる.NDBMを備えていないシステムでは +このクラスは定義されない. SuperClass: Object @@ -1482,92 +1485,92 @@ Methods: self [key] - keyをキーとする値を返す. + keyをキーとする値を返す. self [key]= value - keyをキーとして, valueを格納する. valueとしてnilを指定すると, - keyに対する項目の削除となる. + keyをキーとして,valueを格納する.valueとしてnilを指定すると, + keyに対する項目の削除となる. clear - DBMファイルの中身を空にする. + DBMファイルの中身を空にする. close - DBMファイルをクローズする. 以後の操作は例外を発生させる. + DBMファイルをクローズする.以後の操作は例外を発生させる. delete(key) - keyをキーとする組を削除する. + keyをキーとする組を削除する. delete_if - 要素を削除するイテレータ. [key, value]という配列を与えて, ブロッ - クを評価した値が真の時, 該当する項目を削除する. + 要素を削除するイテレータ.[key, value]という配列を与えて,ブロッ + クを評価した値が真の時,該当する項目を削除する. each each_pair - [key, value]なる配列を与えるイテレータ. + [key, value]なる配列を与えるイテレータ. each_value - 全てのvalueに対して繰り返すイテレータ. + 全てのvalueに対して繰り返すイテレータ. each_key - 全てのkeyに対して繰り返すイテレータ. + 全てのkeyに対して繰り返すイテレータ. has_key(key) includes(key) - keyがデータベース中に存在する時, 真を返す + keyがデータベース中に存在する時,真を返す has_value(value) - valueを値とする組がデータベース中に存在する時, 真を + valueを値とする組がデータベース中に存在する時,真を 返す indexes(ary) indexes(key-1, ..., key-n) - 1番目の形式では文字列の配列を引数として受けて, その要素をキー - とする要素を含む配列を返す. 2番目の形式では各引数の値をキーと + 1番目の形式では文字列の配列を引数として受けて,その要素をキー + とする要素を含む配列を返す.2番目の形式では各引数の値をキーと する要素を含む配列を返す. keys - データベース中に存在するキー全てを含む配列を返す. + データベース中に存在するキー全てを含む配列を返す. length size - データベース中の要素の数を返す. (注意:現在の実現では要素数を数 - えるためにデータベースを全部検索するので, 結構コストが高い. 気 + データベース中の要素の数を返す.(注意:現在の実現では要素数を数 + えるためにデータベースを全部検索するので,結構コストが高い.気 をつけて使うこと.) to_a - データベース中のkey-valueペアを要素とする配列を返す. + データベース中のkey-valueペアを要素とする配列を返す. values - データベース中に存在する値全てを含む配列を返す. + データベース中に存在する値全てを含む配列を返す. Single Methods: open(dbname[, mode]) dbnameで指定したデータベースをモードをmodeに設定してオープンす - る. modeの省略値は0666である. modeとしてnilを指定するとデータ - ベースが既に存在しない時には新たにオープンせず, nilを返す. + る.modeの省略値は0666である.modeとしてnilを指定するとデータ + ベースが既に存在しない時には新たにオープンせず,nilを返す. *** Dict(クラス) -辞書あるいは連想配列. 任意のオブジェクトを添字とできる配列のクラスであ -る. Hashという名前でもアクセスできる. 連想配列オブジェクトの生成は一般 -的には連想配列式``{a=>b,..}'' で行なわれる. +辞書あるいは連想配列.任意のオブジェクトを添字とできる配列のクラスであ +る.Hashという名前でもアクセスできる.連想配列オブジェクトの生成は一般 +的には連想配列式``{a=>b,..}'' で行なわれる. SuperClass: Object @@ -1577,83 +1580,83 @@ Methods: self [key] - keyをキーとする値を返す. + keyをキーとする値を返す. self [key]= value - keyをキーとして, valueを格納する. valueとしてnilを指定するとそ - のkeyに対する項目の削除となる. つまり, Dictは値としてnilを持つ - ことはできない. + keyをキーとして,valueを格納する.valueとしてnilを指定するとそ + のkeyに対する項目の削除となる.つまり,Dictは値としてnilを持つ + ことはできない. clear - 連想配列を空にする. + 連想配列を空にする. delete(key) - keyをキーとする組を削除する. + keyをキーとする組を削除する. delete_if - 要素を削除するイテレータ. [key, value]という配列を与えて, ブロッ - クを評価した値が真の時, 該当する項目を削除する. + 要素を削除するイテレータ.[key, value]という配列を与えて,ブロッ + クを評価した値が真の時,該当する項目を削除する. each each_value - 全てのvalueに対して繰り返すイテレータ. + 全てのvalueに対して繰り返すイテレータ. each_key - 全てのkeyに対して繰り返すイテレータ. + 全てのkeyに対して繰り返すイテレータ. each_pair - [key, value]なる配列を与えるイテレータ. + [key, value]なる配列を与えるイテレータ. has_key(key) includes(key) - keyが辞書中に存在する時, 真を返す + keyが辞書中に存在する時,真を返す has_value(value) - valueを値とする組が辞書中に存在する時, 真を返す + valueを値とする組が辞書中に存在する時,真を返す indexes(ary) indexes(key-1, ..., key-n) - 1番目の形式では配列を引数として受けて, その要素をキーとする要 - 素を含む配列を返す. 2番目の形式では各引数の値をキーとする要素 - を含む配列を返す. + 1番目の形式では配列を引数として受けて,その要素をキーとする要 + 素を含む配列を返す.2番目の形式では各引数の値をキーとする要素 + を含む配列を返す. keys - 辞書中に存在するキー全てを含む配列を返す. + 辞書中に存在するキー全てを含む配列を返す. length size - 辞書中の要素の数を返す. + 辞書中の要素の数を返す. to_a - 辞書中のkey-valueペアを要素とする配列を返す. + 辞書中のkey-valueペアを要素とする配列を返す. values - 辞書中に存在する値全てを含む配列を返す. + 辞書中に存在する値全てを含む配列を返す. Single Methods: new - 新しい(空の)辞書オブジェクトを返す. + 新しい(空の)辞書オブジェクトを返す. *** Directory(クラス) -ディレクトリ内の要素を順に返すディレクトリストリーム操作のためのクラス. -Dirという名前でもアクセスできる. +ディレクトリ内の要素を順に返すディレクトリストリーム操作のためのクラス. +Dirという名前でもアクセスできる. SuperClass: Object @@ -1663,61 +1666,61 @@ Methods: close - ディレクトリストリームをクローズする. 以後の操作は例外を発生さ - せる. + ディレクトリストリームをクローズする.以後の操作は例外を発生さ + せる. each - ディレクトリ内の各要素を順に与えるイテレータ. + ディレクトリ内の各要素を順に与えるイテレータ. getwd pwd - カレントディレクトリを返す. + カレントディレクトリを返す. rewind - ディレクトリストリームを先頭にリセットする. + ディレクトリストリームを先頭にリセットする. seek(pos) - ディレクトリストリームの位置をposに設定する. + ディレクトリストリームの位置をposに設定する. tell - ディレクトリストリームの現在の位置を返す. + ディレクトリストリームの現在の位置を返す. Single Methods: chdir(path) - カレントディレクトリをpathに変更する. + カレントディレクトリをpathに変更する. chroot(path) - プロセスのルートディレクトリを変更する, 同名のシステムコールと - 同じ働きをする. この操作は実効uidがスーパユーザである時だけに - 制限されている. ルートディレクトリを元に戻す(ルートディレクト - リを上方に変更する)方法は提供されていない. + プロセスのルートディレクトリを変更する,同名のシステムコールと + 同じ働きをする.この操作は実効uidがスーパユーザである時だけに + 制限されている.ルートディレクトリを元に戻す(ルートディレクト + リを上方に変更する)方法は提供されていない. mkdir(path[, mode]) - modeで指定されたモードを持つディレクトリpathを作成する. モード - はumaskによって修正される. modeのデフォルト値は0777. + modeで指定されたモードを持つディレクトリpathを作成する.モード + はumaskによって修正される.modeのデフォルト値は0777. open(path) - pathに対するディレクトリストリームをオープンする. + pathに対するディレクトリストリームをオープンする. rmdir(path) - pathで指定されたディレクトリを削除する. ディレクトリは空である - 必要がある. + pathで指定されたディレクトリを削除する.ディレクトリは空である + 必要がある. *** Enumerable(モジュール) -要素に対する繰り返しを行なうクラスのためのMixin. このモジュールをイン -クルードするためには, メソッド`each'を定義する必要がある. +要素に対する繰り返しを行なうクラスのためのMixin.このモジュールをイン +クルードするためには,メソッド`each'を定義する必要がある. Methods: @@ -1727,65 +1730,65 @@ Methods: find - 要素の対してブロックを評価した値が真になった最初の要素を返す. + 要素の対してブロックを評価した値が真になった最初の要素を返す. find_all 各要素に対してブロックを評価した値が真であった要素を全て含む配 - 列を返す. + 列を返す. grep(pattern) - 「要素 =~ pattern」が成立する全ての要素を含む配列を返す. イテ + 「要素 =~ pattern」が成立する全ての要素を含む配列を返す.イテ レータとして用いられた時は上記の条件の成立した要素に対してブロッ - クを実行する. + クを実行する. includes(val) - valと`=='の関係にある要素を持つ時, 真を返す. + valと`=='の関係にある要素を持つ時,真を返す. index(val) - valと`=='の関係にあるオブジェクトが何番目に現れたかを返す. 一 - 番最初の要素が0になる. 要素が存在しない時にはnilを返す. 順序の - ないクラスに対してはあまり意味がない. + valと`=='の関係にあるオブジェクトが何番目に現れたかを返す.一 + 番最初の要素が0になる.要素が存在しない時にはnilを返す.順序の + ないクラスに対してはあまり意味がない. min - 最小の要素を返す. 全ての要素がお互いに`<=>'メソッドで比較でき - ることを仮定している. + 最小の要素を返す.全ての要素がお互いに`<=>'メソッドで比較でき + ることを仮定している. max - 最大の要素を返す. 各要素が`<=>'メソッドで比較できることを仮定 - している. + 最大の要素を返す.各要素が`<=>'メソッドで比較できることを仮定 + している. reverse - 全ての要素を逆順に並べた配列を返す. + 全ての要素を逆順に並べた配列を返す. sort - 全ての要素をソートした配列を返す. + 全ての要素をソートした配列を返す. *** Etc(モジュール) -/etcディレクトリ以下の情報を得るためのモジュール. クラスにインクルード -して使うこともできる. +/etcディレクトリ以下の情報を得るためのモジュール.クラスにインクルード +して使うこともできる. Methods: Single Methods: getlogin - 自分のlogin名を返す. これが失敗した場合はgetpwuid()を用いると - 良い. + 自分のlogin名を返す.これが失敗した場合はgetpwuid()を用いると + 良い. getpwnam(name) /etc/passwdファイル(あるいはDBMファイルやNISデータベース)を検 - 索し, nameの名前を持つpasswdエントリを返す. 戻り値はpasswd構造 - 体で以下のメンバを持つ. + 索し,nameの名前を持つpasswdエントリを返す.戻り値はpasswd構造 + 体で以下のメンバを持つ. struct passwd name # ユーザ名(文字列) @@ -1795,7 +1798,7 @@ Single Methods: gecos # gecosフィールド(文字列) dir # ホームディレクトリ(文字列) shell # ログインシェル(文字列) - # 以降のメンバはシステムによっては提供されない. + # 以降のメンバはシステムによっては提供されない. change # パスワード変更時間(整数) quota # クォータ(整数) age # エージ(整数) @@ -1804,19 +1807,19 @@ Single Methods: expire # アカウント有効期限(整数) end - 詳細はgetpwnam(3)を参照のこと. + 詳細はgetpwnam(3)を参照のこと. getpwuid([uid]) - uidをユーザIDとするpasswdエントリを返す. 戻り値はgetpwnam()と - 同様である. 引数を省略した場合にはgetuid()の値を用いる. 詳細は - getpwuid(3)を参照のこと. + uidをユーザIDとするpasswdエントリを返す.戻り値はgetpwnam()と + 同様である.引数を省略した場合にはgetuid()の値を用いる.詳細は + getpwuid(3)を参照のこと. getgrgid(gid) - /etc/groupファイル(あるいは…getpwnam参照)を検索し, gidをグルー - プIDとするグループエントリを返す. 戻り値はgroup構造体で以下の - メンバを持つ. + /etc/groupファイル(あるいは…getpwnam参照)を検索し,gidをグルー + プIDとするグループエントリを返す.戻り値はgroup構造体で以下の + メンバを持つ. struct group name # グループ名(文字列) @@ -1825,26 +1828,26 @@ Single Methods: mem # グループメンバ名の配列 end - 詳細はgetgrgid(3)を参照のこと. + 詳細はgetgrgid(3)を参照のこと. getgrnam(name) - nameという名前のグループエントリを返す. 戻り値はgetgrgid()と同 - 様である. 詳細はgetgrnam(3)を参照. + nameという名前のグループエントリを返す.戻り値はgetgrgid()と同 + 様である.詳細はgetgrnam(3)を参照. group - 全てのグループエントリを順にアクセスするためのイテレータ. + 全てのグループエントリを順にアクセスするためのイテレータ. passwd - 全てのpasswdエントリを順にアクセスするためのイテレータ. + 全てのpasswdエントリを順にアクセスするためのイテレータ. *** File(クラス) -ファイルアクセスのためのクラス. メソッドopen()で生成される. また, この +ファイルアクセスのためのクラス.メソッドopen()で生成される.また,この クラスの特異メソッドとしてtestのファイルテスト演算子相当のメソッドが定 -義されている(FileTestモジュールのメソッド郡). +義されている(FileTestモジュールのメソッド郡). SuperClass: IO @@ -1852,53 +1855,53 @@ Methods: atime - ファイルの最終アクセス時刻を返す. + ファイルの最終アクセス時刻を返す. ctime - ファイルの最終ステータス変更時刻を返す. + ファイルの最終ステータス変更時刻を返す. chmod(mode) - ファイルのパーミッションを変更する(cf chmod(2)). + ファイルのパーミッションを変更する(cf chmod(2)). chown(owner, group) - ファイルの所有者とグループを変更する(cf chown(2)). nilか-1を + ファイルの所有者とグループを変更する(cf chown(2)).nilか-1を 指定することによって所有者やグループを現在のまま変えないでおく - ことができる. + ことができる. eof - ファイルの終端に到達した時に真を返す. + ファイルの終端に到達した時に真を返す. lstat - ファイルに関するStat構造体を返す. lstatはファイルがシンボリッ - クリンクであればリンクそのものに関するStat構造体を返す. 構造体 - の内容についてはstatを参照のこと. + ファイルに関するStat構造体を返す.lstatはファイルがシンボリッ + クリンクであればリンクそのものに関するStat構造体を返す.構造体 + の内容についてはstatを参照のこと. mtime - ファイルの最終修正時刻を返す. + ファイルの最終修正時刻を返す. rewind - ファイルのファイルポインタの位置を先頭に移動する. + ファイルのファイルポインタの位置を先頭に移動する. path - ファイルのパス名を返す. + ファイルのパス名を返す. seek(offset, ptrname) - ファイルのファイルポインタの位置をoffsetに移動する. ptrnameは - 0, 1, 2のいずれかであって, それぞれファイルの先頭, 現在位置, - ファイルの終端のうちのいずれかからの相対を示す. + ファイルのファイルポインタの位置をoffsetに移動する.ptrnameは + 0,1,2のいずれかであって,それぞれファイルの先頭,現在位置, + ファイルの終端のうちのいずれかからの相対を示す. stat - ファイルに関するStat構造体を返す(Struct を参照). + ファイルに関するStat構造体を返す(Struct を参照). struct stat dev # ファイルの存在するデバイス @@ -1916,204 +1919,204 @@ Methods: ctime # 最終状態変更時間 end - 詳細な説明はfstat(2)を参照のこと. システム上で定義されている - stat構造体に該当するメンバがない場合は0が設定されている. + 詳細な説明はfstat(2)を参照のこと.システム上で定義されている + stat構造体に該当するメンバがない場合は0が設定されている. tell - ファイルの現在のファイルポインタの位置を返す. + ファイルの現在のファイルポインタの位置を返す. truncate(length) - ファイルを切り捨てて最大lengthバイトにする. ファイルはwriteモー - ドでオープンされていなければならない. + ファイルを切り捨てて最大lengthバイトにする.ファイルはwriteモー + ドでオープンされていなければならない. Single Methods: atime(filename) - filenameの最終アクセス時刻を返す. + filenameの最終アクセス時刻を返す. ctime(filename) - filenameの最終ステータス変更時刻を返す. + filenameの最終ステータス変更時刻を返す. chmod(mode, path, file...) - ファイルのパーミッションを変更する(cf chmod(2)). 変更したファ - イル数を返す. fileにはワイルドカードも許す. + ファイルのパーミッションを変更する(cf chmod(2)).変更したファ + イル数を返す.fileにはワイルドカードも許す. chown(owner, group, file...) - ファイルの所有者とグループを変更する(cf chown(2)). nilか-1を指 + ファイルの所有者とグループを変更する(cf chown(2)).nilか-1を指 定することによって所有者やグループを現在のまま変えないでおくこ - とができる. 変更したファイル数を返す. fileにはワイルドカードも - 許す. + とができる.変更したファイル数を返す.fileにはワイルドカードも + 許す. link(old, new) - oldへのハードリンクnewを生成する. link(2)と同じ制限がある. + oldへのハードリンクnewを生成する.link(2)と同じ制限がある. mtime(filename) - filenameの最終修正時刻を返す. + filenameの最終修正時刻を返す. readlink(path) - シンボリックリンクpathの内容を文字列として返す. + シンボリックリンクpathの内容を文字列として返す. rename(from, to) - ファイル名fromをtoに変更する. rename(2)参照. 既にtoという名前 - のファイルが存在する時にはまずそのファイルが削除される. + ファイル名fromをtoに変更する.rename(2)参照.既にtoという名前 + のファイルが存在する時にはまずそのファイルが削除される. stat(filename) - filenameのファイルのStat構造体を返す. + filenameのファイルのStat構造体を返す. symlink(old, new) - oldへのシンボリックリンクnewを生成する. + oldへのシンボリックリンクnewを生成する. truncate(path, length) - pathで指定されたファイルを切り捨てて最大lengthバイトにする. + pathで指定されたファイルを切り捨てて最大lengthバイトにする. type(filename) - filenameのファイルのタイプを表す文字列を返す. 文字列は"file", - "directory", "characterSpecial", "blockSpecial", "fifo", - "link", "socket"のうちのいずれか一つである. + filenameのファイルのタイプを表す文字列を返す.文字列は"file", + "directory","characterSpecial","blockSpecial","fifo", + "link","socket"のうちのいずれか一つである. unlink(file...) - ファイルを削除する. ディレクトリの削除にはDir.rmdirを使うこと. - fileにはワイルドカードも許す. + ファイルを削除する.ディレクトリの削除にはDir.rmdirを使うこと. + fileにはワイルドカードも許す. utime(atime, mtime, file...) - ファイルのアクセス時刻をatimeに, 修正時刻をmtimeに設定する. - atime, mtimeは数またはTimeクラスのインスタンスでなければならな - い. fileにはワイルドカードも許す. + ファイルのアクセス時刻をatimeに,修正時刻をmtimeに設定する. + atime,mtimeは数またはTimeクラスのインスタンスでなければならな + い.fileにはワイルドカードも許す. - これ以外にFileTestモジュールのメソッドも特異メソッドとして持つ. + これ以外にFileTestモジュールのメソッドも特異メソッドとして持つ. *** FileTest(モジュール) -ファイルテスト用メソッドを集めたモジュール. インクルードして用いること -もできる. +ファイルテスト用メソッドを集めたモジュール.インクルードして用いること +もできる. Methods: Single Methods: b(filename) - filenameのファイルがブロックスペシャルファイルである時, 真を返 - す. + filenameのファイルがブロックスペシャルファイルである時,真を返 + す. c(filename) - filenameのファイルがキャラクタスペシャルファイルである時, 真を - 返す. + filenameのファイルがキャラクタスペシャルファイルである時,真を + 返す. executable(filename) x(filename) - filenameのファイルが実行可能の時, 真を返す. + filenameのファイルが実行可能の時,真を返す. exists(filename) e(filename) a(filename) - filenameのファイルが存在する時, 真を返す. + filenameのファイルが存在する時,真を返す. G(filename) - filenameのファイルのgidが実効グループのgidと同じ時, 真を返す. + filenameのファイルのgidが実効グループのgidと同じ時,真を返す. isdirectory(filename) d(filename) - filenameがディレクトリの時, 真を返す. + filenameがディレクトリの時,真を返す. isfile(filename) f(filename) - filenameのファイルが通常ファイルの時, 真を返す. + filenameのファイルが通常ファイルの時,真を返す. islink(filename) l(filename) - filenameのファイルがシンボリックリンクである時, 真を返す. + filenameのファイルがシンボリックリンクである時,真を返す. ispipe(filename) p(filename) - filenameのファイルが名前つきパイプ(FIFO)である時, 真を返す. + filenameのファイルが名前つきパイプ(FIFO)である時,真を返す. issocket(filename) S(filename) - filenameのファイルがソケットである時, 真を返す. + filenameのファイルがソケットである時,真を返す. owned(filename) O(filename) - filenameのファイルを実効ユーザが所有している時, 真を返す. + filenameのファイルを実効ユーザが所有している時,真を返す. readable(filename) r(filename) - filenameのファイルを読みとり可能の時, 真を返す. + filenameのファイルを読みとり可能の時,真を返す. R(filename) - filenameのファイルを実uid/gidで読みとり可能の時, 真を返す. + filenameのファイルを実uid/gidで読みとり可能の時,真を返す. setuid(filename) u(filename) - filenameのファイルのsetuidビットがセットされている時, 真を返す. + filenameのファイルのsetuidビットがセットされている時,真を返す. setuid(filename) g(filename) - filenameのファイルのsetuidビットがセットされている時, 真を返す. + filenameのファイルのsetuidビットがセットされている時,真を返す. size(filename) s(filename) - filenameのファイルが存在する時, ファイルの大きさを返す. 存在し - ない時はnilを返す. + filenameのファイルが存在する時,ファイルの大きさを返す.存在し + ない時はnilを返す. sticky(filename) g(filename) - filenameのファイルのstickyビットがセットされている時, 真を返す. + filenameのファイルのstickyビットがセットされている時,真を返す. writable(filename) w(filename) - filenameのファイルが実uid/gidで書き込み可能の時, 真を返す. + filenameのファイルが実uid/gidで書き込み可能の時,真を返す. W(filename) - filenameのファイルが書き込み可能の時, 真を返す. + filenameのファイルが書き込み可能の時,真を返す. z(filename) - filenameのファイルが存在し, 大きさが0である時, 真を返す. + filenameのファイルが存在し,大きさが0である時,真を返す. *** Fixnum(クラス) -31bit整数のクラス. builtin classである. このクラスはpointer内の即値で +31bit整数のクラス.builtin classである.このクラスはpointer内の即値で あるためcall by valueで呼び出される点が特徴的である(他のクラスはcall -by reference). 演算の結果が31bitを越える場合には自動的にBignum(無限多 -倍長整数)に拡張される. +by reference).演算の結果が31bitを越える場合には自動的にBignum(無限多 +倍長整数)に拡張される. -イテレータupto(), downto(), step()は繰り返しのために用いられ, 一般に -Rangeクラスを用いるより高速である. +イテレータupto(),downto(),step()は繰り返しのために用いられ,一般に +Rangeクラスを用いるより高速である. SuperClass: Integer @@ -2126,53 +2129,53 @@ Methods: self % other self ** other - 算術演算. それぞれ和, 差, 積, 商, 剰余, 冪乗を返す. + 算術演算.それぞれ和,差,積,商,剰余,冪乗を返す. ~ self self | other self & other self ^ other - ビット演算. それぞれビット反転, 論理和, 論理積, 排他的論理和を - 返す. + ビット演算.それぞれビット反転,論理和,論理積,排他的論理和を + 返す. self << bits self >> bits - シフト演算. それぞれbitsビットだけ左右にビットシフトを行なう. + シフト演算.それぞれbitsビットだけ左右にビットシフトを行なう. self .. max - 範囲指定. self から maxまでの範囲オブジェクトを返す. + 範囲指定.self から maxまでの範囲オブジェクトを返す. downto(min) - イテレータ. selfからminまで下向きに繰り返す. + イテレータ.selfからminまで下向きに繰り返す. id2name - 整数値をIDだとみなして, 相当する文字列を返す. 相当する文字列が - 存在しない場合はnilを返す. + 整数値をIDだとみなして,相当する文字列を返す.相当する文字列が + 存在しない場合はnilを返す. step(max, step) - イテレータ. selfからmaxまでstepずつ変化しながら, 繰り返す. + イテレータ.selfからmaxまでstepずつ変化しながら,繰り返す. to_f - selfをFloatに変換したものを返す. + selfをFloatに変換したものを返す. to_i - selfをそのまま返す. + selfをそのまま返す. upto(max) - イテレータ. selfからmaxまで繰り返す. + イテレータ.selfからmaxまで繰り返す. *** Float(クラス) - 浮動小数点数のクラス. + 浮動小数点数のクラス. SuperClass: Numeric @@ -2185,63 +2188,63 @@ Methods: self % other self ** other - 算術演算. それぞれ和, 差, 積, 商, 剰余, 冪乗を返す. + 算術演算.それぞれ和,差,積,商,剰余,冪乗を返す. self == other self > other - 比較演算. + 比較演算. coerce(num) - numをfloatに変換する. ただし現時点でFloatが理解できる他の数は - FixnumとBignumだけである. + numをfloatに変換する.ただし現時点でFloatが理解できる他の数は + FixnumとBignumだけである. to_f - selfをそのまま返す. + selfをそのまま返す. to_i - selfを整数に変換した結果を返す. + selfを整数に変換した結果を返す. Single Methods: new(float) - floatと同じ値を持つ新しいFloatオブジェクトを返す. + floatと同じ値を持つ新しいFloatオブジェクトを返す. *** GC(モジュール) -Ruby組み込みのgarbage collectorの制御を行なうためのモジュール. このモ -ジュールのメソッドをを用いることによって, 一時的にGCを止めたり, GCの起 -きるタイミングを制御したりできる. +Ruby組み込みのgarbage collectorの制御を行なうためのモジュール.このモ +ジュールのメソッドをを用いることによって,一時的にGCを止めたり,GCの起 +きるタイミングを制御したりできる. Methods: garbage_collect - GCを開始する. 「GC.start」と同義. + GCを開始する.「GC.start」と同義. Single Methods: disable - GCを禁止する. + GCを禁止する. enable - GCを許可する. + GCを許可する. start - GCを開始する. + GCを開始する. *** Glob(クラス) -ワイルドカードのクラス. ワイルドカードのリテラルは<...>という形式であ -る. 正規表現とほぼ同じように使えるが, こちらは機能が少ない. ただし, ワ -イルドカードの展開機能がある. +ワイルドカードのクラス.ワイルドカードのリテラルは<...>という形式であ +る.正規表現とほぼ同じように使えるが,こちらは機能が少ない.ただし,ワ +イルドカードの展開機能がある. SuperClass: Object @@ -2251,26 +2254,26 @@ Methods: self =~ string - ワイルドカードが文字列にマッチした場合には真を, しない場合は - nilを返す. + ワイルドカードが文字列にマッチした場合には真を,しない場合は + nilを返す. each - ワイルドカードにマッチするファイル名を返すイテレータ. + ワイルドカードにマッチするファイル名を返すイテレータ. Single Methods: new(string) - 文字列をワイルドカードに変換したオブジェクトを返す. + 文字列をワイルドカードに変換したオブジェクトを返す. *** Integer(クラス) -整数クラス. 実際はその大きさによってFixnumとBignumいう二つのサブクラス -で実現されている. Integerはそれらのスーパークラスとなる抽象クラスであ -る. Rubyではほとんどの場合, FixnumとBignumの区別は必要なく, 相互の変換 -は自動的に行なわれる. 整数をビット列だとみなす場合には, 無限の長さをも -つビット列と考えて構わない. +整数クラス.実際はその大きさによってFixnumとBignumいう二つのサブクラス +で実現されている.Integerはそれらのスーパークラスとなる抽象クラスであ +る.Rubyではほとんどの場合,FixnumとBignumの区別は必要なく,相互の変換 +は自動的に行なわれる.整数をビット列だとみなす場合には,無限の長さをも +つビット列と考えて構わない. SuperClass: Numeric @@ -2278,25 +2281,25 @@ Methods: self[idx] - 整数のidxビット目がセットされていれば1, セットされていなければ - 0を返す. + 整数のidxビット目がセットされていれば1,セットされていなければ + 0を返す. chr - その数をコードとする文字だけを含む1文字の文字列を返す. 一般に - 長さ1以上の文字列について, 次の関係が常に成立する. + その数をコードとする文字だけを含む1文字の文字列を返す.一般に + 長さ1以上の文字列について,次の関係が常に成立する. str[0].chr == str[0,1] - 整数が文字の範囲内(0..255)になければ例外が発生する. + 整数が文字の範囲内(0..255)になければ例外が発生する. is_integer - いつも真を返す. + いつも真を返す. *** IO(クラス) -入出力のための基本クラス. +入出力のための基本クラス. SuperClass: Object @@ -2306,9 +2309,9 @@ Methods: self << object - objectを出力する. objectが文字列でない時にはメソッドto_sを用い - て文字列に変換する. selfを戻り値とするので, C++のような`<<'の - 連鎖を使える. + objectを出力する.objectが文字列でない時にはメソッドto_sを用い + て文字列に変換する.selfを戻り値とするので,C++のような`<<'の + 連鎖を使える. 例: @@ -2316,89 +2319,89 @@ Methods: close - 入出力ポートをクローズする. 以後のこのオブジェクトに対する入出 - 力操作はエラーになる. + 入出力ポートをクローズする.以後のこのオブジェクトに対する入出 + 力操作はエラーになる. each - 一行ずつ読み込んでくるためのイテレータ. 行の区切りはシステム変 - 数`$/'によって変更できる. 読み込んだ文字列はシステム変数`$_'に - もセットされる. + 一行ずつ読み込んでくるためのイテレータ.行の区切りはシステム変 + 数`$/'によって変更できる.読み込んだ文字列はシステム変数`$_'に + もセットされる. each_byte() - 一文字ずつ読み込んでくるためのイテレータ. 文字は文字コードを表 - すFixnumである. + 一文字ずつ読み込んでくるためのイテレータ.文字は文字コードを表 + すFixnumである. fileno to_i - IOオブジェクトが使っているファイルディスクリプタ(Fixnum)を返す. + IOオブジェクトが使っているファイルディスクリプタ(Fixnum)を返す. flush - バッファをフラッシュする. + バッファをフラッシュする. getc - 一行読み込んで, 読み込みに成功した時にはその文字列を返す. ファ - イルの終りに到達した時にはnilを返す. カーネルメソッドgetc()は - $stdin.getcと同じ意味である. + 一行読み込んで,読み込みに成功した時にはその文字列を返す.ファ + イルの終りに到達した時にはnilを返す.カーネルメソッドgetc()は + $stdin.getcと同じ意味である. gets - 一行読み込んで, 読み込みに成功した時にはその文字列を返す. ファ - イルの終りに到達した時にはnilを返す. + 一行読み込んで,読み込みに成功した時にはその文字列を返す.ファ + イルの終りに到達した時にはnilを返す. isatty - 入出力ポートがttyである時, 真を返す. + 入出力ポートがttyである時,真を返す. puts(obj) - objを出力する. 「self << obj」と同じ意味である. + objを出力する.「self << obj」と同じ意味である. read([length]) - lengthバイト読み込んで, その文字列を返す. lengthが省略された時 - には, 全てのデータを読み込む. + lengthバイト読み込んで,その文字列を返す.lengthが省略された時 + には,全てのデータを読み込む. readlines - ファイルを全て読み込んで各行を要素としてもつ配列を返す. + ファイルを全て読み込んで各行を要素としてもつ配列を返す. sync - 現在の出力同期モードを真偽値で返す. 同期モードが真の時は出力関 - 数の呼出毎にバッファがフラッシュされる. + 現在の出力同期モードを真偽値で返す.同期モードが真の時は出力関 + 数の呼出毎にバッファがフラッシュされる. sync=(newstate) - 出力同期モードを設定する. + 出力同期モードを設定する. sysread(length) - stdioを経由せずにread(2)を用いて入力を行なう. 入力されたデータ - を含む文字列を返す. ファイルの終りに到達した時にはnilを返す. + stdioを経由せずにread(2)を用いて入力を行なう.入力されたデータ + を含む文字列を返す.ファイルの終りに到達した時にはnilを返す. read(2)の性質により必ずlengthバイトの文字列が読み込まれるわけ - ではない. gets()やgetc()などstdioを経由するメソッドと混用する - ことはバッファリングの不整合などで思わぬ動作をすることがある. + ではない.gets()やgetc()などstdioを経由するメソッドと混用する + ことはバッファリングの不整合などで思わぬ動作をすることがある. syswrite(str) - stdioを経由せずに, write(2)を用いて出力を行なう. このメソッド - はバッファリングなどstdioがしてくれることは一切行なわない. - syswriteは実際に書き込んだバイト数を返す. print()やprintf()と - syswrite()を混用するのは推奨できない. + stdioを経由せずに,write(2)を用いて出力を行なう.このメソッド + はバッファリングなどstdioがしてくれることは一切行なわない. + syswriteは実際に書き込んだバイト数を返す.print()やprintf()と + syswrite()を混用するのは推奨できない. write(str) - strを出力する. 出力したバイト数を返す. + strを出力する.出力したバイト数を返す. *** Kernel(クラス) -全てのクラスの基底クラス. Ruby組み込みの全ての関数メソッドはこのクラス -で定義されている. 関数メソッドについては「関数」の項目を参照のこと. +全てのクラスの基底クラス.Ruby組み込みの全ての関数メソッドはこのクラス +で定義されている.関数メソッドについては「関数」の項目を参照のこと. SuperClass: なし @@ -2406,74 +2409,74 @@ Methods: ! self - 否定. Non-nilのオブジェクトの場合常に偽(nil)を返す. このメソッ - ドはNilクラスでは再定義され真を返す. + 否定.Non-nilのオブジェクトの場合常に偽(nil)を返す.このメソッ + ドはNilクラスでは再定義され真を返す. self == other equal(other) - オブジェクトの一致判定. レシーバと引数の引数が一致する時, 真を - 返す. Kernelクラスの定義では双方のオブジェクトが同一の時真を返 - す. "=="メソッドは各オブジェクトの性質に応じて再定義する必要が - ある. "=="メソッドを再定義した時には, hashメソッドもそれに合わ - せて再定義する必要がある. + オブジェクトの一致判定.レシーバと引数の引数が一致する時,真を + 返す.Kernelクラスの定義では双方のオブジェクトが同一の時真を返 + す."=="メソッドは各オブジェクトの性質に応じて再定義する必要が + ある."=="メソッドを再定義した時には,hashメソッドもそれに合わ + せて再定義する必要がある. - equal()メソッドは"=="メソッドの別名で, "=="を再定義した後でも - オブジェクトの同一性判定を行なうために用いられる. よって - equal()メソッドはサブクラスで再定義するべきではない. + equal()メソッドは"=="メソッドの別名で,"=="を再定義した後でも + オブジェクトの同一性判定を行なうために用いられる.よって + equal()メソッドはサブクラスで再定義するべきではない. self != other - "=="の否定. 内部で"=="メソッドを呼び出しているので, こちらは再 - 定義する必要はない. + "=="の否定.内部で"=="メソッドを呼び出しているので,こちらは再 + 定義する必要はない. self =~ other - マッチ. デフォルトの動作は"=="と同じである. "=~"はcaseの比較に - も用いられる. + マッチ.デフォルトの動作は"=="と同じである."=~"はcaseの比較に + も用いられる. !~ - "=~"の否定. 内部で"=~"メソッドを呼び出しているので, こちらは再 - 定義する必要はない. + "=~"の否定.内部で"=~"メソッドを呼び出しているので,こちらは再 + 定義する必要はない. self :: other - selfとotherを要素とする長さ2の配列を返す. 配列を生成するという - 意味で [self, other]と同じ働きをするが, こちらの方がわずかに効 - 率が良い. この演算子は右結合であるので, a::b::c は (a::(b::c)) - と解釈される. + selfとotherを要素とする長さ2の配列を返す.配列を生成するという + 意味で [self, other]と同じ働きをするが,こちらの方がわずかに効 + 率が良い.この演算子は右結合であるので,a::b::c は (a::(b::c)) + と解釈される. is_nil - オブジェクトがnilであるかどうか. Kernelクラスの定義では真を返 - す. Nilクラスで再定義されている. + オブジェクトがnilであるかどうか.Kernelクラスの定義では真を返 + す.Nilクラスで再定義されている. id - 各オブジェクトに対して一意のFixnumを返す. が, Fixnumは自分自身を返 - すので, idが一致しても同じオブジェクトであることは保証されない. - つまり, + 各オブジェクトに対して一意のFixnumを返す.が,Fixnumは自分自身を返 + すので,idが一致しても同じオブジェクトであることは保証されない. + つまり, obj1.id == obj2.id - が成立しても, どちらかがFixnumであれば, obj1とobj2が同じである - とは限らない. ただし, 両方がFixnumでないことが保証できれば, 2 - つのオブジェクトが同一であることは確実である. + が成立しても,どちらかがFixnumであれば,obj1とobj2が同じである + とは限らない.ただし,両方がFixnumでないことが保証できれば,2 + つのオブジェクトが同一であることは確実である. hash - オブジェクトのハッシュ値(Fixnum)を返す. Dictクラスでキーとなる + オブジェクトのハッシュ値(Fixnum)を返す.Dictクラスでキーとなる オブジェクトを格納するのに用いられている.「A == B」が成立する - 時は必ず「A.hash == B.hash」が成立する必要があるので, "=="を再 - 定義した時には必ずこちらもそれに合わせて再定義すること. + 時は必ず「A.hash == B.hash」が成立する必要があるので,"=="を再 + 定義した時には必ずこちらもそれに合わせて再定義すること. *** Math(モジュール) -浮動小数点演算をサポートするクラス. Mathモジュールは同じ定義のメソッド -と特異メソッドとの両方が定義されているので, 特異メソッドを呼び出して使 -う使い方と, クラスにインクルードして使う使い方との両方ができる. +浮動小数点演算をサポートするクラス.Mathモジュールは同じ定義のメソッド +と特異メソッドとの両方が定義されているので,特異メソッドを呼び出して使 +う使い方と,クラスにインクルードして使う使い方との両方ができる. 例: @@ -2486,37 +2489,37 @@ Single Methods: atan2(x, y) - π〜-πの範囲でX/Yのアークタンジェントを返す. + π〜-πの範囲でX/Yのアークタンジェントを返す. cos(x) sin(x) tan(x) - ラジアンで表されたxの三角関数の値を返す. + ラジアンで表されたxの三角関数の値を返す. exp(x) - xの指数関数の値を返す. + xの指数関数の値を返す. log(x) - xの自然対数を返す. + xの自然対数を返す. log10(x) - xの常用対数を返す. + xの常用対数を返す. sqrt(x) - xの平方根を返す. xの値が負である時には例外を発生させる. + xの平方根を返す.xの値が負である時には例外を発生させる. cbrt(x) - xの立方根を返す. + xの立方根を返す. *** Module(クラス) -モジュールのクラス. +モジュールのクラス. SuperClass: Object @@ -2525,22 +2528,22 @@ Private Methods: attr(name[, public]) そのモジュールをインクルードしたクラスのインスタンスに対して - nameで指定される属性を付加し, 属性に対するアクセスメソッドを定 - 義する. attr("attr")はクラス定義に以下に示すコードを追加するの - とほぼ同義である. + nameで指定される属性を付加し,属性に対するアクセスメソッドを定 + 義する.attr("attr")はクラス定義に以下に示すコードを追加するの + とほぼ同義である. def attr; @attr; end - 省略可能な第2引数publicが与えられて, かつその値がnilでない時に - は, その属性には属性設定メソッドも用意され, 外部から代入可能に - なる. attr("attr", %TRUE)はクラス定義に以下のコードを追加する - のとほぼ同義である. + 省略可能な第2引数publicが与えられて,かつその値がnilでない時に + はその属性には属性設定メソッドも用意され,外部から代入可能にな + る.attr("attr", %TRUE)はクラス定義に以下のコードを追加するの + とほぼ同義である. def attr; @attr; end def attr=(val); @attr = val; end - 属性を構成するメソッドを再定義することによって, アクセス時の動 - 作を変更できる. 例えば + 属性を構成するメソッドを再定義することによって,アクセス時の動 + 作を変更できる.例えば attr("test", %TRUE) def test=(val) @@ -2548,31 +2551,31 @@ Private Methods: print("and now is ", @test = val, "\n") end - のように設定時に属性の値を表示するようなことが可能である. attr - はアクセスメソッドがすでに定義されている場合は, デフォルトのア - クセスメソッドを定義しない. + のように設定時に属性の値を表示するようなことが可能である.attr + はアクセスメソッドがすでに定義されている場合は,デフォルトのア + クセスメソッドを定義しない. Methods: export(name[, name..]) - nameで指定されたメソッドを通常形式で呼び出し可能にする. すでに - 通常メソッドである場合には何もしない. + nameで指定されたメソッドを通常形式で呼び出し可能にする.すでに + 通常メソッドである場合には何もしない. to_s - モジュールの文字列表現を返す. モジュールの場合の文字列表現はモ - ジュール名である. + モジュールの文字列表現を返す.モジュールの場合の文字列表現はモ + ジュール名である. unexport(name[, name..]) - nameで指定されたメソッドを関数形式でだけ呼び出し可能にする. す - でに関数メソッドである場合には何もしない. + nameで指定されたメソッドを関数形式でだけ呼び出し可能にする.す + でに関数メソッドである場合には何もしない. *** Nil(クラス) -偽を表すオブジェクトnilのクラス. 偽変数(の値)nilはNilクラスの唯一のイ -ンスタンスである. +偽を表すオブジェクトnilのクラス.偽変数(の値)nilはNilクラスの唯一のイ +ンスタンスである. SuperClass: Kernel @@ -2580,19 +2583,19 @@ Methods: self + other - otherが整数, 浮動小数点数, 文字列, 配列である時, otherを返す. + otherが整数,浮動小数点数,文字列,配列である時,otherを返す. ! self - 常に真を返す. + 常に真を返す. is_nil - 常に真を返す. + 常に真を返す. *** Numeric(クラス) -数一般の性質を表す抽象クラス. +数一般の性質を表す抽象クラス. SuperClass: Object @@ -2606,26 +2609,26 @@ Methods: - self - 「0 - self」の値を返す. サブクラスでより効率的に再定義されるこ - とが期待される. + 「0 - self」の値を返す.サブクラスでより効率的に再定義されるこ + とが期待される. abs - 絶対値を返す. + 絶対値を返す. divmod(other) - 商と剰余の2要素の配列を返す. + 商と剰余の2要素の配列を返す. next - 次の数を返す. 次の数とはその数を越える最小の整数である. + 次の数を返す.次の数とはその数を越える最小の整数である. *** Object(クラス) -全ての通常クラスのスーパクラス. 通常クラスのインスタンスの一般的な振舞 -いを定義している. このクラスのサブクラスでないクラスはKernelとNilと, -組み込み関数を定義しているBuiltinだけである. +全ての通常クラスのスーパクラス.通常クラスのインスタンスの一般的な振舞 +いを定義している.このクラスのサブクラスでないクラスはKernelとNilと, +組み込み関数を定義しているBuiltinだけである. SuperClass: Builtin @@ -2633,83 +2636,99 @@ Methods: is_member_of(class) - オブジェクトselfがクラスclassのインスタンスである時,真を返す. + オブジェクトselfがクラスclassのインスタンスである時,真を返す. is_kind_of(class) オブジェクトselfがクラスclassかそのサブクラスのインスタンスで - ある時, 真を返す. + ある時,真を返す. clone - オブジェクトの複製を作る. インスタンスが即値であるFixnumクラス - 以外のクラスの場合,「obj.equal(obj.clone)」は偽であるが, 多く - の場合「obj == obj.clone」は真である. + オブジェクトの複製を作る.インスタンスが即値であるFixnumクラス + 以外のクラスの場合,「obj.equal(obj.clone)」は偽であるが,多く + の場合「obj == obj.clone」は真である. to_s - オブジェクトの文字列表現を返す. このメソッドは内部的にprint() - やformat()メソッドで用いられている. + オブジェクトの文字列表現を返す.このメソッドは内部的にprint() + やformat()メソッドで用いられている. to_a - オブジェクトを配列に変換する. カーネルクラスで定義されているデ - フォルトは, そのオブジェクト自身を含む1要素の配列を返す. + オブジェクトを配列に変換する.カーネルクラスで定義されているデ + フォルトは,そのオブジェクト自身を含む1要素の配列を返す. *** Process(モジュール) -プロセスに関する操作を行なうためのモジュール. Mathモジュールと同様に全 -てのメソッドは特異メソッドとしても通常のメソッドとしても使える. -Processはプロセスオブジェクトのクラスではなくて, プロセス操作のメソッ -ドをまとめたものであることに注意すること. +プロセスに関する操作を行なうためのモジュール.Mathモジュールと同様に全 +てのメソッドは特異メソッドとしても通常のメソッドとしても使える. +Processはプロセスオブジェクトのクラスではなくて,プロセス操作のメソッ +ドをまとめたものであることに注意すること. Methods: Single Methods: + egid + + プロセスの現在の実効GIDを返す. + + egid=(gid) + + プロセスの現在の実効GIDをgidにセットする. + euid - プロセスの現在の実効UIDを返す. + プロセスの現在の実効UIDを返す. euid=(uid) - プロセスの現在の実効UIDをuidにセットする. + プロセスの現在の実効UIDをuidにセットする. getpgrp([pid]) pidで指定されたプロセスが現在所属しているプロセスグループのid - を返す. pidを省略した時とpidに0を与えた時は現在実行しているプ - ロセスを対象にする. + を返す.pidを省略した時とpidに0を与えた時は現在実行しているプ + ロセスを対象にする. getpriority(which, who) - whichとwhoで指定されるプロセス, プロセスグループ, ユーザの現在 - の優先順位を返す. 詳細はgetpriority(2)を参照. Processモジュー - ルではwhichとして指定できる定数%PRIO_PROCESS, %PRIO_PGRP, - %PRIO_USERが定義されている. + whichとwhoで指定されるプロセス,プロセスグループ,ユーザの現在 + の優先順位を返す.詳細はgetpriority(2)を参照.Processモジュー + ルではwhichとして指定できる定数%PRIO_PROCESS,%PRIO_PGRP, + %PRIO_USERが定義されている. + + gid + + プロセスの現在の実GIDを返す. + + gid= + + プロセスの現在の実GIDをgidにセットする. pid - プロセスのプロセスIDを返す. これはシステム変数`$$'の値と同じで - ある. + プロセスのプロセスIDを返す.これはシステム変数`$$'の値と同じで + ある. ppid - 親プロセスのプロセスのプロセスIDを返す. UNIXでは直接の親プロセ - スが終了した場合, 親プロセスのpidは1(initのpid)になる. + 親プロセスのプロセスのプロセスIDを返す.UNIXでは直接の親プロセ + スが終了した場合,親プロセスのpidは1(initのpid)になる. setpgrp(pid, pgrp) - pidで指定されたプロセスのプロセスグループをpgrpにする. pidに0 - を与えると現在実行中のプロセスを対象にする. + pidで指定されたプロセスのプロセスグループをpgrpにする.pidに0 + を与えると現在実行中のプロセスを対象にする. setpriority(which, who, prio) - whichとwhoで指定されるプロセス, プロセスグループ, ユーザの現在 - の優先順位をprioに設定する. 詳細はsetpriority(2)を参照のこと. + whichとwhoで指定されるプロセス,プロセスグループ,ユーザの現在 + の優先順位をprioに設定する.詳細はsetpriority(2)を参照のこと. uid - プロセスの現在の実UIDを返す. + プロセスの現在の実UIDを返す. uid= @@ -2717,21 +2736,21 @@ Single Methods: *** Range(クラス) -範囲オブジェクトのクラス. 範囲オブジェクトは`..'演算子によって生成され, +範囲オブジェクトのクラス.範囲オブジェクトは`..'演算子によって生成され, 一般的には以下のような使い方をする for i in 1..5 ... end -しかし, この場合は以下の方が速い. +しかし,この場合は以下の方が速い. do 1.upto(5) ... end 範囲オブジェクトを生成する`..'演算子の両辺はComparableを含むクラスのイ -ンスタンスであれば何でも構わない. 範囲は始点と終点を含むことに注意する +ンスタンスであれば何でも構わない.範囲は始点と終点を含むことに注意する こと. SuperClass: Object @@ -2742,21 +2761,21 @@ Methods: self =~ other - selfがotherと同じクラスに対する範囲オブジェクトで, その範囲内 - にotherがある時(start <= other <= end),真を返す. これはcase文 - で範囲指定する時に便利である. 例えば + selfがotherと同じクラスに対する範囲オブジェクトで,その範囲内 + にotherがある時(start <= other <= end),真を返す.これはcase文 + で範囲指定する時に便利である.例えば case i when 1, 3..5 ... end case - のようなコードを書くことができる. + のようなコードを書くことができる. each - 範囲内に存在するオブジェクトを与えるイテレータ. 主にfor文のた - めに用いられる. + 範囲内に存在するオブジェクトを与えるイテレータ.主にfor文のた + めに用いられる. end @@ -2764,48 +2783,48 @@ Methods: start - 範囲の始点を返す. + 範囲の始点を返す. *** Socket(クラス) SuperClass: BasicSocket -ソケットそのものに対するシステムコールレベルのアクセスを提供するクラス. -Perlのソケットに対するアクセスと同レベルの機能を提供している. このクラ -スではソケットアドレスはpackされた文字列で, 指定する. UDPソケットはこ -のクラスを使って利用する. +ソケットそのものに対するシステムコールレベルのアクセスを提供するクラス. +Perlのソケットに対するアクセスと同レベルの機能を提供している.このクラ +スではソケットアドレスはpackされた文字列で,指定する.UDPソケットはこ +のクラスを使って利用する. Methods: accept - 新しい接続を受け付けて, 新しい接続に対するソケットとアドレスの - ペアを返す. accept(2)を参照. + 新しい接続を受け付けて,新しい接続に対するソケットとアドレスの + ペアを返す.accept(2)を参照. bind(addr) - bind(2)と同じ働きをする. addrはpackされたソケットアドレス構造 - 体である. + bind(2)と同じ働きをする.addrはpackされたソケットアドレス構造 + 体である. connect(addr) - connect(2)と同じ働きをする. addrはpackされたソケットアドレス構 - 造体である. + connect(2)と同じ働きをする.addrはpackされたソケットアドレス構 + 造体である. listen(backlog) - listen(2)と同じ働きをする. + listen(2)と同じ働きをする. recv(len[, flags]) - ソケットからデータを受け取り, 文字列として返す. lenは受け取る - 最大の長さを指定する. flagsについてはrecv(2)を参照. flagsのデ - フォルト値は0である. + ソケットからデータを受け取り,文字列として返す.lenは受け取る + 最大の長さを指定する.flagsについてはrecv(2)を参照.flagsのデ + フォルト値は0である. recvfrom(len[, flags]) - recvと同様にソケットからデータを受け取るが, 戻り値は文字列と相 - 手ソケットのアドレスのペアである. 引数についてはrecvと同様. + recvと同様にソケットからデータを受け取るが,戻り値は文字列と相 + 手ソケットのアドレスのペアである.引数についてはrecvと同様. send(mesg, flags[, to]) @@ -2818,26 +2837,26 @@ Single Methods: open(domain, type, protocol) new(domain, type, protocol) - 新しいソケットを生成する. domain, type, protocolはインクルード - ファイルで定義されている定数値で指定する. domainとtypeに関して - は, 文字列で指定できるが, すべてをカバーしている保証はない. + 新しいソケットを生成する.domain,type,protocolはインクルード + ファイルで定義されている定数値で指定する.domainとtypeに関して + は,文字列で指定できるが,すべてをカバーしている保証はない. socketpair(domain, type, protocol) - ソケットのペアを生成し, 2要素の配列として返す. 引数の指定は - openと同じである. + ソケットのペアを生成し,2要素の配列として返す.引数の指定は + openと同じである. *** Regexp(クラス) -正規表現のクラス. 正規表現のリテラルは/.../という形式で表すが, 動的に +正規表現のクラス.正規表現のリテラルは/.../という形式で表すが,動的に 生成するためには Regexp.new(文字列) -とする. ただし, Stringクラスの`=~'を始めとして多くのメソッドは正規表現 -の替わりに文字列が与えられた時には内部的に正規表現を生成するので, 生成 -コストを節約したいと思う時以外は明示的に生成したいと思うことは少ないは -ずだ. +とする.ただし,Stringクラスの`=~'を始めとして多くのメソッドは正規表現 +の替わりに文字列が与えられた時には内部的に正規表現を生成するので,生成 +コストを節約したいと思う時や,正規表現の大文字小文字の区別を明示的に指 +定したい時など以外は明示的に生成したいと思うことは少ないはずだ. SuperClass: Object @@ -2845,24 +2864,28 @@ Methods: self =~ string - 正規表現が文字列にマッチした場合, マッチした位置を返す. マッチ - しない場合はnilを返す. + 正規表現が文字列にマッチした場合,マッチした位置を返す.マッチ + しない場合はnilを返す. ~ self - 「$_ =~ self」と同義. + 「$_ =~ self」と同義. Single Methods: - complie(string) - new(string) + complie(string[, casefold]) + new(string[, casefold]) - 文字列を正規表現に変換したオブジェクトを返す. + 文字列を正規表現に変換したオブジェクトを返す.省略可能な第2引 + 数が与えられた時には,生成される正規表現オブジェクトはシステム + 変数`$='の値に関わらず,真の時は大文字小文字を無視し,偽の時は + 区別する.設定されない場合はマッチを行なった時点のシステム変数 + `$='の値によって区別するかしないかが決定される. *** BasicSocket(クラス) -ソケットを表す抽象クラス. 具体的なソケット操作はサブクラスで定義される. -例えばインターネットドメインの場合はTCPsocketを用いる. +ソケットを表す抽象クラス.具体的なソケット操作はサブクラスで定義される. +例えばインターネットドメインの場合はTCPsocketを用いる. SuperClass: IO @@ -2870,36 +2893,36 @@ Methods: getopt(level, optname) - ソケットのオプションを取得する. getsockopt(2)を参照のこと. 取 - 得したオプションの内容を含む文字列を返す. + ソケットのオプションを取得する.getsockopt(2)を参照のこと.取 + 得したオプションの内容を含む文字列を返す. getpeername - 接続の相手先のソケットの情報を得る. パックされたsockaddr構造体 - をベタにダンプした文字列が返される. getpeername(2)を参照のこと. + 接続の相手先のソケットの情報を得る.パックされたsockaddr構造体 + をベタにダンプした文字列が返される.getpeername(2)を参照のこと. getsockname - ソケットの情報を得る. パックされたsockaddr構造体をベタにダンプ - した文字列が返される. getsockname(2)を参照のこと. + ソケットの情報を得る.パックされたsockaddr構造体をベタにダンプ + した文字列が返される.getsockname(2)を参照のこと. setopt(level, optname, optval) - ソケットのオプションを設定する. setsockopt(2)を参照のこと. + ソケットのオプションを設定する.setsockopt(2)を参照のこと. shutdown(how) - ソケットの以降の接続を終了させる. howが0である時, 以降の受信が, - howが1である時は, 以降の送信が拒否される. howが2の時には, それ - 以降の送信, 受信ともに拒否される. shutdown(2)を参照. + ソケットの以降の接続を終了させる.howが0である時,以降の受信が, + howが1である時は,以降の送信が拒否される.howが2の時には,それ + 以降の送信,受信ともに拒否される.shutdown(2)を参照. *** String(クラス) -文字列クラス. Rubyの文字列はヌルターミネートではないので, バイナリデー -タも扱える. 従ってどちらかというと単なる文字列というよりバイト列である. -その思想に基づいて, 正規表現に関するメソッド以外は2byte系の文字を意識 -していない. これは作者の手抜きではなく意図的にそうしているのである(信 -じてくれ). +文字列クラス.Rubyの文字列はヌルターミネートではないので,バイナリデー +タも扱える.従ってどちらかというと単なる文字列というよりバイト列である. +その思想に基づいて,正規表現に関するメソッド以外は2byte系の文字を意識 +していない.これは作者の手抜きではなく意図的にそうしているのである(信 +じてくれ). SuperClass: Object @@ -2909,123 +2932,123 @@ Methods: self + other - 文字列の連結. 連結された文字列を返す. + 文字列の連結.連結された文字列を返す. self * times - 文字列の繰り返し. 例えば + 文字列の繰り返し.例えば "x" * 4 == "xxxx" - である. + である. self == other self > other - 文字列の比較. システム変数$=がnilでない時には大文字小文字を区 - 別せずに比較を行なう. + 文字列の比較.システム変数$=がnilでない時には大文字小文字を区 + 別せずに比較を行なう. self =~ other - 文字列のマッチ. otherは正規表現か文字列. otherが文字列の場合に - は動的に正規表現に変換される. マッチした場合はマッチした位置, - しなかった場合はnilが返る. + 文字列のマッチ.otherは正規表現か文字列.otherが文字列の場合に + は動的に正規表現に変換される.マッチした場合はマッチした位置, + しなかった場合はnilが返る. ~ self - 「$_ =~ self」と同義. + 「$_ =~ self」と同義. self[nth] self[beg..end] self[beg,len] - 内容の取り出し. 1番目の形式ではnthバイト目のデータをFixnumとし - て返す. 2番目の形式ではbegバイト目からendバイト目までの部分文 - 字列を返す(両端を含む). 3番目の形式ではbegバイト目からlenバイ - ト分の部分文字列を返す. + 内容の取り出し.1番目の形式ではnthバイト目のデータをFixnumとし + て返す.2番目の形式ではbegバイト目からendバイト目までの部分文 + 字列を返す(両端を含む).3番目の形式ではbegバイト目からlenバイ + ト分の部分文字列を返す. self[nth] = val self[beg..end] = val self[beg,len] = val - 内容の更新. 1番目の形式ではnthバイト目のデータをval (整数)に変 - 更する. 2番目の形式はbegバイト目からendバイト目までの部分文字 - 列をvalとして与えられた文字列で置き換える. 3番目の形式はbegバ + 内容の更新.1番目の形式ではnthバイト目のデータをval (整数)に変 + 更する.2番目の形式はbegバイト目からendバイト目までの部分文字 + 列をvalとして与えられた文字列で置き換える.3番目の形式はbegバ イト目からlenバイト分の部分文字列をvalとして与えられた文字列で - 置き換える. + 置き換える. capitalize - 文字列中の最初の文字を(それがアルファベットであれば), 大文字に - 変換し, 残る文字列中のアルファベットを小文字に置き換える. + 文字列中の最初の文字を(それがアルファベットであれば),大文字に + 変換し,残る文字列中のアルファベットを小文字に置き換える. chop - 文字列の最後のバイトを切り落とす. 元の文字列を変更することに注 - 意すること. + 文字列の最後のバイトを切り落とす.元の文字列を変更することに注 + 意すること. crypt(salt) - crypt(3)を用いて暗号化した文字列を返す. saltは2バイト以上の長 - さの任意の文字列である. + crypt(3)を用いて暗号化した文字列を返す.saltは2バイト以上の長 + さの任意の文字列である. delete(str) - 文字列のうち, strに含まれる文字を削除する. 文字列の指定はtrと - 同様であり, a-bでaからbまでの範囲を, 先頭の^で文字列の否定(含 - まれてないものを指定)を意味する. 元の文字列を変更することに注 - 意すること. + 文字列のうち,strに含まれる文字を削除する.文字列の指定はtrと + 同様であり,a-bでaからbまでの範囲を,先頭の^で文字列の否定(含 + まれてないものを指定)を意味する.元の文字列を変更することに注 + 意すること. downcase - 文字列中のアルファベットを全て小文字に置き換えた文字列を返す. + 文字列中のアルファベットを全て小文字に置き換えた文字列を返す. each - 文字列から1行ずつ読み込んでくるイテレータ. + 文字列から1行ずつ読み込んでくるイテレータ. each_byte - 文字列のそれぞれのバイトについて繰り返すイテレータ. + 文字列のそれぞれのバイトについて繰り返すイテレータ. gsub(pattern, replace) - 文字列中でpatternにマッチする部分を全てreplaceに置き換える. - 置換文字列replace中の&と\0はマッチした文字列に, \1..\9はn番目 - の括弧の内容に置き換えられる. + 文字列中でpatternにマッチする部分を全てreplaceに置き換える. + 置換文字列replace中の&と\0はマッチした文字列に,\1..\9はn番目 + の括弧の内容に置き換えられる. hex - 文字列を16進数を表す文字列と解釈して, 整数に変換する. + 文字列を16進数を表す文字列と解釈して,整数に変換する. index(substr[, pos]) - substrが最初に出現する位置を返す. posを与えるとその位置から検 - 索を開始する. 見つからない時にはnilを返す. + substrが最初に出現する位置を返す.posを与えるとその位置から検 + 索を開始する.見つからない時にはnilを返す. intern - 文字列に一意に対応する整数を返す. 文字列はナル文字を含んではな - らない. + 文字列に一意に対応する整数を返す.文字列はナル文字を含んではな + らない. length size - 文字列の長さ(バイト数)を返す. + 文字列の長さ(バイト数)を返す. ljust(width) rjust(width) center(width) - 文字列をそれぞれ, 右詰め, 左詰め, 真中寄せした幅widthの文字列 - を返す. 文字列長がwidthより長い場合は元の文字列を返し, 切り詰 - めない. + 文字列をそれぞれ,右詰め,左詰め,真中寄せした幅widthの文字列 + を返す.文字列長がwidthより長い場合は元の文字列を返し,切り詰 + めない. next - selfからendまで「次の」文字列を返す. 次の文字列とは数字は数字 - として,英文字は英文字として増加し, 桁上がりの処理が行なわれた - ものである. + selfからendまで「次の」文字列を返す.次の文字列とは数字は数字 + として,英文字は英文字として増加し,桁上がりの処理が行なわれた + ものである. "aa".next => "ab" "99".next => "100" @@ -3033,62 +3056,62 @@ Methods: oct - 文字列を8進数を表す文字列と解釈して, 整数に変換する. 8進数の - 定義は/[0-7]+/であり, 文字列の先頭からこのパターンにマッチする - 部分を整数に変換する. この定義に全く当てはまらない文字列に対し - ては0を返す. perlとは違って文字列が0xから始まっているからといっ - て 16進数だと見なしてくれたりはしない. それらは先頭の0が8進数 - と認識され, 0を返す. + 文字列を8進数を表す文字列と解釈して,整数に変換する.8進数の + 定義は/[0-7]+/であり,文字列の先頭からこのパターンにマッチする + 部分を整数に変換する.この定義に全く当てはまらない文字列に対し + ては0を返す.perlとは違って文字列が0xから始まっているからといっ + て 16進数だと見なしてくれたりはしない.それらは先頭の0が8進数 + と認識され,0を返す. reverse - 文字列の各バイトを逆順に並べた文字列を返す. 文字列が2バイトで - 構成される文字を含んでいてもお構いなしにバイト単位で反転する. - splitは2バイト文字を理解するので, 2バイト文字を含む文字列を文 + 文字列の各バイトを逆順に並べた文字列を返す.文字列が2バイトで + 構成される文字を含んでいてもお構いなしにバイト単位で反転する. + splitは2バイト文字を理解するので,2バイト文字を含む文字列を文 字単位に反転するには "全角文字列".split(//).reverse.join("") - とすればよい. + とすればよい. rindex(substr[, pos]) - 文字列substrが最後に出現する位置を返す. posを与えるとその位置 - で検索を終了する. 見つからない時にはnilを返す. indexとの相違点 - は1)文字列の末尾から検索する. 2)substrとして正規表現を受け付け - ない. の2点である. + 文字列substrが最後に出現する位置を返す.posを与えるとその位置 + で検索を終了する.見つからない時にはnilを返す.indexとの相違点 + は1)文字列の末尾から検索する.2)substrとして正規表現を受け付け + ない.の2点である. split([sep[, limit]]) - 文字列をsepで指定されたパターンによって, フィールドに分割する. + 文字列をsepで指定されたパターンによって,フィールドに分割する. sepが省略された時のデフォルトはシステム変数`$;'の値が用いられ - る. limitが指定された時には最大limit個のフィールドに分割する. - split()は分割された文字列を含む配列を返す. sepで指定されたパター - ンが空文字列とマッチする場合は文字列が1文字ずつに分割される. + る.limitが指定された時には最大limit個のフィールドに分割する. + split()は分割された文字列を含む配列を返す.sepで指定されたパター + ンが空文字列とマッチする場合は文字列が1文字ずつに分割される. squeeze([str]) - 文字列のうち, strに含まれる文字が連続していた場合, 一文字に圧 - 縮する. strが省略された場合, すべての文字を対象とする. 文字列 - の指定はtrと同様であり, `a-b'でaからbまでの範囲を, 先頭の`^'で - 文字列の否定(含まれてないものを指定)を意味する. 元の文字列を変 - 更することに注意すること. + 文字列のうち,strに含まれる文字が連続していた場合,一文字に圧 + 縮する.strが省略された場合,すべての文字を対象とする.文字列 + の指定はtrと同様であり,`a-b'でaからbまでの範囲を,先頭の`^'で + 文字列の否定(含まれてないものを指定)を意味する.元の文字列を変 + 更することに注意すること. strip - 文字列の前後の空白を取り除く. + 文字列の前後の空白を取り除く. sub(pattern, replace) - 文字列中でpatternにマッチする部分をreplaceに置き換える. 置換文 - 字列replace中の&と\0はマッチした文字列に, \1..\9は n番目の括弧 - の内容に置き換えられる. sub()はgsub()と異なり, 最初のマッチだ - けを置換する. + 文字列中でpatternにマッチする部分をreplaceに置き換える.置換文 + 字列replace中の&と\0はマッチした文字列に,\1..\9は n番目の括弧 + の内容に置き換えられる.sub()はgsub()と異なり,最初のマッチだ + けを置換する. sum([bits]) - 文字列のbitsビットのチェックサムを得る. 省略値は16である. ruby - では以下のコードでSystem Vの`sum'プログラムと同じ値を得られる. + 文字列のbitsビットのチェックサムを得る.省略値は16である.ruby + では以下のコードでSystem Vの`sum'プログラムと同じ値を得られる. while gets() sum += $_.sum @@ -3097,53 +3120,53 @@ Methods: swapcase - 文字列中のアルファベットのうち大文字を小文字に, 小文字を大文字 - に置き換える. + 文字列中のアルファベットのうち大文字を小文字に,小文字を大文字 + に置き換える. to_f - 文字列をFloatに変換する. + 文字列をFloatに変換する. to_i - 文字列を10進数を表す文字列と解釈して, 整数に変換する. + 文字列を10進数を表す文字列と解釈して,整数に変換する. toupper - 文字列中のアルファベットを全て大文字に置き換えた文字列を返す. - tr("a-z", "A-Z")より少し速い. + 文字列中のアルファベットを全て大文字に置き換えた文字列を返す. + tr("a-z", "A-Z")より少し速い. tolower - 文字列中のアルファベットを全て小文字に置き換えた文字列を返す. - tr("A-Z", "a-z")より少し速い. + 文字列中のアルファベットを全て小文字に置き換えた文字列を返す. + tr("A-Z", "a-z")より少し速い. tr(search, replace) - 文字列の中にsearch文字列に含まれる文字が存在すれば, replace文 - 字列の対応する文字で置き換える. replace文字列が省略された場合 - は空文字列が与えられたと見なす. replace文字列がsearch文字列よ + 文字列の中にsearch文字列に含まれる文字が存在すれば,replace文 + 字列の対応する文字で置き換える.replace文字列が省略された場合 + は空文字列が与えられたと見なす.replace文字列がsearch文字列よ りも短い時はreplace文字列の最後の文字が繰り返されていると見な - す. search文字列の方が短い時には対応する文字のないreplace部は - 単に無視される(BSDのtrの動作). + す.search文字列の方が短い時には対応する文字のないreplace部は + 単に無視される(BSDのtrの動作). - search文字列, replace文字列中に`a-b'という形式が現れた場合, そ - のaからbまでの範囲の文字をASCIIの昇順で指定したことになる. ま - た, search文字列の最初の文字が`^'である場合, 続く文字列に*含ま - れない*文字列が置換の対象になる. + search文字列,replace文字列中に`a-b'という形式が現れた場合,そ + のaからbまでの範囲の文字をASCIIの昇順で指定したことになる.ま + た,search文字列の最初の文字が`^'である場合,続く文字列に*含ま + れない*文字列が置換の対象になる. - tr(1)の機能のうち, 文字を削除する機能, 連続する文字を圧縮する - 機能は別のメソッドに分割されている. それらの機能については - delete, squeezeを参照のこと. + tr(1)の機能のうち,文字を削除する機能,連続する文字を圧縮する + 機能は別のメソッドに分割されている.それらの機能については + delete,squeezeを参照のこと. - 簡便のため, str.tr(src,repl).squeeze(repl)に相当するメソッド - tr_s(src,repl) が提供されている. + 簡便のため,str.tr(src,repl).squeeze(repl)に相当するメソッド + tr_s(src,repl) が提供されている. unpack(template) - 文字列をtemplate文字列にしたがってアンパックし, それらの要素を - 含む配列を返す. template文字列はArrayクラスのpackメソッドとほ - ぼ同様である. + 文字列をtemplate文字列にしたがってアンパックし,それらの要素を + 含む配列を返す.template文字列はArrayクラスのpackメソッドとほ + ぼ同様である. a ASCII文字列(後続するnull文字やスペースを残す) A ASCII文字列(後続するnull文字やスペースを削除) @@ -3168,78 +3191,78 @@ Methods: @ 絶対位置への移動 rubyのunpackはperlと違ってチェックサムの計算機能がないことに注 - 意すること. + 意すること. upcase - 文字列中のアルファベットを全て大文字に置き換えた文字列を返す. + 文字列中のアルファベットを全て大文字に置き換えた文字列を返す. upto(end) - selfから始まって, endまで「次の」文字列を順に与えるイテレータ. - 次の文字列とはstr.nextで与えられる文字列である. + selfから始まって,endまで「次の」文字列を順に与えるイテレータ. + 次の文字列とはstr.nextで与えられる文字列である. - このメソッドはRange:eachで用いられているので, 以下のような処理 - が可能である. + このメソッドはRange:eachで用いられているので,以下のような処理 + が可能である. for i in "a" .. "ba" print(i, "\n"); end - これはa, b, c, .. aa, .. az, baまでを各行に出力する. + これはa, b, c, .. aa, .. az, baまでを各行に出力する. - 気を付けなければいけないのは, この終了判定は大小関係ではなく - `=='で判定されているため, `..'演算子の左辺の値に続く文字列に右 - 辺の文字列が含まれていない, 以下の例のような場合は無限ループに - 陥ってしまう. + 気を付けなければいけないのは,この終了判定は大小関係ではなく + `=='で判定されているため,`..'演算子の左辺の値に続く文字列に右 + 辺の文字列が含まれていない,以下の例のような場合は無限ループに + 陥ってしまう. for i in "0" .. "1a" print(i, "\n"); end 作者はこう書くことによって責任を逃れてようとしていると考える人 - もいるかもしれない. その推測は正しい. + もいるかもしれない.その推測は正しい. Single Methods: new(string) - stringと同じ内容を持つ新しい文字列を返す. + stringと同じ内容を持つ新しい文字列を返す. *** Struct(クラス) -構造体クラス. 複数のデータをまとめる時に用いられる(例: Time::times). -データをまとめる時には配列クラスが用いられることもあるが(例: select), -構造体を使うべき時は以下のような場合である. +構造体クラス.複数のデータをまとめる時に用いられる(例: Time::times). +データをまとめる時には配列クラスが用いられることもあるが(例: select), +構造体を使うべき時は以下のような場合である. (1) 要素の数が固定 - 要素の数が変動するものは構造体を使うのには向かない. + 要素の数が変動するものは構造体を使うのには向かない. (2) 要素の数が多い - 人間が一度に容易に扱える概念の数は7つまでであるという仮説がある. - この仮説に従えば, 要素が4つ以上あるデータの場合は配列を用いた場 - 合, 要素数*2(つまりオフセットとその意味)が7を越える. よって, そ - のような場合には構造体を使った方が理解しやすいと思われる. + 人間が一度に容易に扱える概念の数は7つまでであるという仮説がある. + この仮説に従えば,要素が4つ以上あるデータの場合は配列を用いた場 + 合,要素数*2(つまりオフセットとその意味)が7を越える.よって,そ + のような場合には構造体を使った方が理解しやすいと思われる. (3) 同時に大量に生成されない - 構造体は配列よりも若干生成コストが高いので, 速度が問題になる場合 + 構造体は配列よりも若干生成コストが高いので,速度が問題になる場合 (例えば同時に大量に生成される場合など)は構造体の使用が適切でない - 可能性がある. + 可能性がある. -各構造体にはメンバ名と同名の引数のないメソッドが定義される. +各構造体にはメンバ名と同名の引数のないメソッドが定義される. -本ドキュメント内で, 構造体を表現するためには以下の形式を使う. +本ドキュメント内で,構造体を表現するためには以下の形式を使う. struct 構造体名 - メンバ ... + メンバ ... end -しかし, プログラム中でこの形式で構造体を生成するわけではない. +しかし,プログラム中でこの形式で構造体を生成するわけではない. SuperClass: Object @@ -3249,33 +3272,33 @@ Methods: self[idx] - idxが数の時はidx番目の要素を返す. idxが文字列の時はidxと同じ名 - 前のメンバの要素を返す. + idxが数の時はidx番目の要素を返す.idxが文字列の時はidxと同じ名 + 前のメンバの要素を返す. values - 構造体のメンバの値を要素に持つ配列を返す. 例えば以下のコードで - 自分のpasswdエントリを出力することができる. + 構造体のメンバの値を要素に持つ配列を返す.例えば以下のコードで + 自分のpasswdエントリを出力することができる. print(Etc.getpwuid().values.join(":"), "\n") この出力は`grep "$USER" /etc/passwd'の出力と余分なフィールドい - くつか(システムによって異なる)がある以外は同じである. + くつか(システムによって異なる)がある以外は同じである. Single Methods: new(name, member::value...) - nameという名前を持つ構造体を生成する. memberは構造体のメンバを - 表す文字列であり, valueはその値である. 生成された構造体はメン - バで指定された名前の特異メソッドが定義されていて, そのメソッド - によってメンバの内容を得ることができる. + nameという名前を持つ構造体を生成する.memberは構造体のメンバを + 表す文字列であり,valueはその値である.生成された構造体はメン + バで指定された名前の特異メソッドが定義されていて,そのメソッド + によってメンバの内容を得ることができる. *** TCPserver(クラス) -TCP/IPストリーム型接続のサーバ側のソケットのクラス. このクラスによって -簡単にソケットを利用したサーバのプログラミングができる. 例えばechoサー -バは以下のようになる. +TCP/IPストリーム型接続のサーバ側のソケットのクラス.このクラスによって +簡単にソケットを利用したサーバのプログラミングができる.例えばechoサー +バは以下のようになる. gs = TCPserver.open(4444) socks = [gs] @@ -3304,8 +3327,8 @@ Methods: accept - クライアントからの接続要求を受け付け, 接続したTCPsocketのイン - スタンスを返す. + クライアントからの接続要求を受け付け,接続したTCPsocketのイン + スタンスを返す. Single Methods: @@ -3313,16 +3336,16 @@ Single Methods: open([host, ]service) serviceは/etc/services(またはNIS)に登録されているサービス名か - ポート番号で指定する. hostを指定した時は指定したホストからの接 - 続だけを受け付ける. 省略時は全てのホストからの接続要求を受け付 - ける. + ポート番号で指定する.hostを指定した時は指定したホストからの接 + 続だけを受け付ける.省略時は全てのホストからの接続要求を受け付 + ける. *** TCPsocket -インターネットドメインのストリーム型ソケットのクラス. 通常のIOクラスの -サブクラスと同様の入出力ができる. このクラスによってソケットを用いたク -ライアントを簡単に記述できる. ユーザの入力をそのままサーバに転送するプ -ログラムは以下のようになる. +インターネットドメインのストリーム型ソケットのクラス.通常のIOクラスの +サブクラスと同様の入出力ができる.このクラスによってソケットを用いたク +ライアントを簡単に記述できる.ユーザの入力をそのままサーバに転送するプ +ログラムは以下のようになる. s = TCPsocket("localhost", 4444) while gets() @@ -3336,14 +3359,14 @@ Methods: addr - ソケットの接続情報を表す配列を返す. その配列の各要素は第1要素 - が文字列 "AF_INET", 第2要素がport番号, 第3要素がホストを表す文 - 字列である. + ソケットの接続情報を表す配列を返す.その配列の各要素は第1要素 + が文字列 "AF_INET",第2要素がport番号,第3要素がホストを表す文 + 字列である. peeraddr - 接続相手先ソケットの情報を表す配列を返す. その配列の各要素は - addrメソッドが返す配列と同じである. + 接続相手先ソケットの情報を表す配列を返す.その配列の各要素は + addrメソッドが返す配列と同じである. Single Methods: @@ -3351,15 +3374,15 @@ Single Methods: new(host, service) hostで指定したホストのserviceで指定したポートと接続したソケッ - トを返す. hostはホスト名, またはインターネットアドレスを示す文 - 字列, serviceは/etc/services(またはNIS)に登録されているサービ - ス名かポート番号である. + トを返す.hostはホスト名,またはインターネットアドレスを示す文 + 字列,serviceは/etc/services(またはNIS)に登録されているサービ + ス名かポート番号である. *** Time(クラス) -時間を表すクラス. 大小比較などができる. Time.nowで現在の時間を得ること -ができる. またファイルのタイムスタンプを得るメソッドの戻り値もこのクラ -スのインスタンスである. +時間を表すクラス.大小比較などができる.Time.nowで現在の時間を得ること +ができる.またファイルのタイムスタンプを得るメソッドの戻り値もこのクラ +スのインスタンスである. SuperClass: Object @@ -3369,38 +3392,38 @@ Methods: self <=> other - otherはTimeのインスタンスか整数. 整数が与えられた場 + otherはTimeのインスタンスか整数.整数が与えられた場 合には1970年 1月 1日 00:00:00 GMTからの秒数であると - して時刻との比較を行なう. + して時刻との比較を行なう. asctime ctime to_s - 時刻をdate(1)形式の文字列に変換する. + 時刻をdate(1)形式の文字列に変換する. gmtime - タイムゾーンの修正を行なわないGMTでの時刻を得る. このメソッド - を受けとったTimeクラスのインスタンスは, 以後の時刻変換をGMTで - 行なう. gmtimeは自分自身を返す. + タイムゾーンの修正を行なわないGMTでの時刻を得る.このメソッド + を受けとったTimeクラスのインスタンスは,以後の時刻変換をGMTで + 行なう.gmtimeは自分自身を返す. ロンドンの時刻を表示するには print(Time.now.gmtime, "\n") - とすればよい. + とすればよい. localtime - タイムゾーンの修正を行なった時刻を得る(デフォルト). localtime - は自分自身を返す. + タイムゾーンの修正を行なった時刻を得る(デフォルト).localtime + は自分自身を返す. to_i tv_sec - 1970年 1月 1日 00:00:00 GMTから時刻までの秒数を整数で返す. 時 - 刻のsecondの部分でもある. + 1970年 1月 1日 00:00:00 GMTから時刻までの秒数を整数で返す.時 + 刻のsecondの部分でもある. sec min @@ -3412,13 +3435,13 @@ Methods: zone isdst - 内部的に保持しているtm構造体の内容を返す. zone以外は整数を返す. - zoneはタイムゾーンを表す文字列を返す. (cf localtime(3)) + 内部的に保持しているtm構造体の内容を返す.zone以外は整数を返す. + zoneはタイムゾーンを表す文字列を返す.(cf localtime(3)) strftime(format) - 時刻をformat文字列に従って文字列に変換した結果を返す. format - 文字列として指定できるものは 以下の通りである. + 時刻をformat文字列に従って文字列に変換した結果を返す.format + 文字列として指定できるものは 以下の通りである. %A 曜日の名称(Sunday, Monday,...) %a 曜日の省略名(Sun, Mon,...) @@ -3433,11 +3456,11 @@ Methods: %m 月を表す数字(01-12) %p 午前または午後(AM,PM) %S 秒(00-61) - %U 週を表す数字. 最初の日曜日が第1週の + %U 週を表す数字.最初の日曜日が第1週の 始まり(00-53) - %W 週を表す数字. 最初の月曜日が第1週の + %W 週を表す数字.最初の月曜日が第1週の 始まり(00-53) - %w 曜日を表す数字. 日曜日が0(0-6) + %w 曜日を表す数字.日曜日が0(0-6) %X 時刻(例: 15:01:06) %x 日付(例: Fri Jan 14 1994) %Y 西暦を表す数字 @@ -3448,25 +3471,25 @@ Methods: usec tv_usec - 時刻のmicro secondの部分を返す. + 時刻のmicro secondの部分を返す. Single Methods: now - 現在の時刻を表すTimeクラスのインスタンスを生成する. + 現在の時刻を表すTimeクラスのインスタンスを生成する. at(time) - timeと同じ時刻を表すTimeクラスのインスタンスを生成する. timeは - Timeクラスのインスタンスかあるいは数(整数/浮動小数点数)であり, + timeと同じ時刻を表すTimeクラスのインスタンスを生成する.timeは + Timeクラスのインスタンスかあるいは数(整数/浮動小数点数)であり, 数の場合は1970年 1月 1日 00:00:00 GMTからの秒数であるとして時 - 刻を計算する. + 刻を計算する. times 現在のプロセスとその子プロセスが消費したユーザ/システムCPUタイ - ムの積算を構造体として返す(Structを参照). + ムの積算を構造体として返す(Structを参照). struct tms utime # プロセスのユーザ時間 @@ -3475,12 +3498,12 @@ Single Methods: cstime # 子プロセスのシステム時間 end - 時間の単位は秒であり, 浮動小数点数で与えられる. 詳細は - times(3)を参照のこと. + 時間の単位は秒であり,浮動小数点数で与えられる.詳細は + times(3)を参照のこと. *** UNIXserver -UNIXストリーム型接続のサーバ側のソケットのクラス. +UNIXストリーム型接続のサーバ側のソケットのクラス. SuperClass: UNIXsocket @@ -3488,13 +3511,13 @@ Methods: accept - クライアントからの接続要求を受け付け, 接続したUNIXsocketのイン - スタンスを返す. + クライアントからの接続要求を受け付け,接続したUNIXsocketのイン + スタンスを返す. *** UNIXsocket -UNIXドメインのストリーム型ソケットのクラス. 通常のIOクラスのサブクラス -と同様の入出力ができる. +UNIXドメインのストリーム型ソケットのクラス.通常のIOクラスのサブクラス +と同様の入出力ができる. SuperClass: BasicSocket @@ -3502,24 +3525,24 @@ Methods: addr - ソケットの接続情報を表す配列を返す. その配列の各要素は第1要素 - が文字列 "AF_UNIX", 第2要素がpathである. + ソケットの接続情報を表す配列を返す.その配列の各要素は第1要素 + が文字列 "AF_UNIX",第2要素がpathである. path - UNIXソケットのパスを返す. + UNIXソケットのパスを返す. peeraddr - 接続相手先ソケットの情報を表す配列を返す. その配列の各要素は - addrメソッドが返す配列と同じである. + 接続相手先ソケットの情報を表す配列を返す.その配列の各要素は + addrメソッドが返す配列と同じである. Single Methods: open(path) new(path) - pathで指定したパス名を用いて接続したソケットを返す. + pathで指定したパス名を用いて接続したソケットを返す. ------------------------------------------------------- Local variables: diff --git a/sprintf.c b/sprintf.c index 6fef9c329d..507724f6b9 100644 --- a/sprintf.c +++ b/sprintf.c @@ -3,7 +3,7 @@ sprintf.c - $Author: matz $ - $Date: 1994/10/14 06:19:50 $ + $Date: 1994/12/06 09:30:23 $ created at: Fri Oct 15 10:39:26 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -220,7 +220,7 @@ Fsprintf(argc, argv) val = str2inum(RSTRING(val)->ptr, 0); goto bin_retry; case T_BIGNUM: - val = Fbig_clone(val); + val = big_clone(val); break; default: WrongType(val, T_FIXNUM); @@ -280,7 +280,6 @@ Fsprintf(argc, argv) } sprintf(&buf[blen], fbuf, s); blen += strlen(&buf[blen]); - obj_free(val); } break; diff --git a/st.c b/st.c index b44b51103f..e4e36380e6 100644 --- a/st.c +++ b/st.c @@ -5,6 +5,7 @@ static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; static char *rcsid = "$Header: /usr/ext/cvsroot/ruby/st.c,v 1.2 1994/08/12 04:47:59 matz Exp $"; #endif +#include "config.h" #include #include "st.h" diff --git a/string.c b/string.c index f5b1a64f68..12070809cc 100644 --- a/string.c +++ b/string.c @@ -3,7 +3,7 @@ string.c - $Author: matz $ - $Date: 1994/11/18 01:37:38 $ + $Date: 1994/12/06 09:30:24 $ created at: Mon Aug 9 17:12:58 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -61,7 +61,7 @@ str_new3(str) #define as_str(str) (struct RString*)obj_as_string(str) -static ID pr_str = Qnil; +static ID pr_str; VALUE obj_as_string(obj) @@ -79,7 +79,7 @@ obj_as_string(obj) } VALUE -Fstr_clone(str) +str_clone(str) struct RString *str; { VALUE obj; @@ -93,7 +93,7 @@ Fstr_clone(str) } static VALUE -Fstr_new(class, str) +Sstr_new(class, str) VALUE class; struct RString *str; { @@ -164,7 +164,7 @@ Fstr_dot2(left, right) VALUE str; Check_Type(right, T_STRING); - str = range_new(C_Range, left, right); + str = range_new(left, right); return str; } @@ -375,6 +375,7 @@ Fstr_match(x, y) switch (TYPE(y)) { case T_REGEXP: return Freg_match(y, x); + case T_STRING: reg = re_regcomp(y); start = research(reg, x, 0, ignorecase); @@ -382,6 +383,7 @@ Fstr_match(x, y) return FALSE; } return INT2FIX(start); + default: if (obj_is_kind_of(y, C_Glob)) { return Fglob_match(y, x); @@ -542,7 +544,6 @@ Fstr_next(orig) str2 = (struct RString*)str_new(0, str->len+1); str2->ptr[0] = c; memmove(str2->ptr+1, str->ptr, str->len); - obj_free(str); str = str2; } @@ -1310,7 +1311,7 @@ Fstr_split(str, args) } else { if (isspace(*ptr)) { - Fary_push(result, str_substr(str, beg, end-beg)); + ary_push(result, str_substr(str, beg, end-beg)); if (limit && lim <= ++i) break; skip = 1; beg = end + 1; @@ -1324,7 +1325,7 @@ Fstr_split(str, args) else { for (end = beg = 0; ptrptr[beg])) - Fary_push(result, str_substr(str, beg, 2)); + ary_push(result, str_substr(str, beg, 2)); else - Fary_push(result, str_substr(str, beg, 1)); + ary_push(result, str_substr(str, beg, 1)); beg = start; if (limit && lim <= ++i) break; } @@ -1357,7 +1358,7 @@ Fstr_split(str, args) } } else { - Fary_push(result, str_substr(str, beg, end-beg)); + ary_push(result, str_substr(str, beg, end-beg)); beg = start = RMATCH[0]; if (limit && lim <= ++i) break; } @@ -1369,17 +1370,17 @@ Fstr_split(str, args) tmp = str_new(0, 0); else tmp = str_subseq(str, LMATCH[idx], RMATCH[idx]-1); - Fary_push(result, tmp); + ary_push(result, tmp); if (limit && lim <= ++i) break; } } } if (str->len > beg) { - Fary_push(result, str_subseq(str, beg, -1)); + ary_push(result, str_subseq(str, beg, -1)); } else if (str->len == beg) { - Fary_push(result, str_new(0, 0)); + ary_push(result, str_new(0, 0)); } return result; @@ -1631,8 +1632,8 @@ Init_String() C_String = rb_define_class("String", C_Object); rb_include_module(C_String, M_Comparable); rb_include_module(C_String, M_Enumerable); - rb_define_single_method(C_String, "new", Fstr_new, 1); - rb_define_method(C_String, "clone", Fstr_clone, 0); + rb_define_single_method(C_String, "new", Sstr_new, 1); + rb_define_method(C_String, "clone", str_clone, 0); rb_define_method(C_String, "<=>", Fstr_cmp, 1); rb_define_method(C_String, "==", Fstr_equal, 1); rb_define_method(C_String, "hash", Fstr_hash, 0); diff --git a/struct.c b/struct.c index 3ecc265d32..6f69d0cf02 100644 --- a/struct.c +++ b/struct.c @@ -3,7 +3,7 @@ struct.c - $Author: matz $ - $Date: 1994/08/12 04:48:01 $ + $Date: 1994/12/06 09:30:26 $ created at: Tue Mar 22 18:44:30 JST 1994 ************************************************/ @@ -101,7 +101,7 @@ struct_new(name, va_alist) #define ASSOC_VAL(a) RARRAY(a)->ptr[1] static VALUE -Fstruct_new(class, args) +Sstruct_new(class, args) VALUE class, args; { VALUE name, st; @@ -151,7 +151,7 @@ Fstruct_values(s) t = s->tbl; tend = t + s->len; while (t < tend) { - Fary_push(ary, t->value); + ary_push(ary, t->value); t++; } @@ -223,7 +223,7 @@ Fstruct_to_a(s) ary = ary_new2(s->len); for (i=0; ilen; i++) { - Fary_push(ary, s->tbl[i].value); + ary_push(ary, s->tbl[i].value); } return ary; @@ -248,7 +248,7 @@ Init_Struct() C_Struct = rb_define_class("Struct", C_Object); rb_include_module(C_Struct, M_Enumerable); - rb_define_single_method(C_Struct, "new", Fstruct_new, -2); + rb_define_single_method(C_Struct, "new", Sstruct_new, -2); rb_define_method(C_Struct, "clone", Fstruct_clone, 0); rb_define_method(C_Struct, "to_s", Fstruct_to_s, 0); diff --git a/time.c b/time.c index b54cfcaddf..b6c1bd26cb 100644 --- a/time.c +++ b/time.c @@ -3,7 +3,7 @@ time.c - $Author: matz $ - $Date: 1994/11/01 08:28:40 $ + $Date: 1994/12/06 09:30:28 $ created at: Tue Dec 28 14:31:59 JST 1993 Copyright (C) 1994 Yukihiro Matsumoto @@ -38,7 +38,7 @@ static ID id_tv; } static VALUE -Ftime_now(class) +Stime_now(class) VALUE class; { VALUE obj = obj_alloc(class); @@ -116,7 +116,7 @@ time_timeval(time) } static VALUE -Ftime_at(class, time) +Stime_at(class, time) VALUE class, time; { VALUE obj; @@ -501,7 +501,7 @@ Ftime_strftime(time, format) } static VALUE -Ftime_times(obj) +Stime_times(obj) VALUE obj; { struct tms buf; @@ -520,11 +520,11 @@ Init_Time() C_Time = rb_define_class("Time", C_Object); rb_include_module(C_Time, M_Comparable); - rb_define_single_method(C_Time, "now", Ftime_now, 0); - rb_define_single_method(C_Time, "new", Ftime_now, 0); - rb_define_single_method(C_Time, "at", Ftime_at, 1); + rb_define_single_method(C_Time, "now", Stime_now, 0); + rb_define_single_method(C_Time, "new", Stime_now, 0); + rb_define_single_method(C_Time, "at", Stime_at, 1); - rb_define_single_method(C_Time, "times", Ftime_times, 0); + rb_define_single_method(C_Time, "times", Stime_times, 0); rb_define_method(C_Time, "to_i", Ftime_to_i, 0); rb_define_method(C_Time, "to_f", Ftime_to_f, 0); diff --git a/version.h b/version.h index ee2baeaac9..681475c953 100644 --- a/version.h +++ b/version.h @@ -1,2 +1,2 @@ -#define RUBY_VERSION "0.56" -#define VERSION_DATE "94/11/22" +#define RUBY_VERSION "0.60" +#define VERSION_DATE "94/12/08" -- cgit v1.2.3