From fca49a8a69a0f6bb4feae74c6cd0e93d7fac8b36 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 21 Dec 1995 00:56:57 +0900 Subject: version 0.95 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.95.tar.gz Thu Dec 21 00:56:57 1995 Yukihiro Matsumoto * version 0.95 - fj.sourcesに * eval.c (rb_eval): rescueのロジックをrb_rescue()に一元化. Wed Dec 20 19:30:58 1995 Yukihiro Matsumoto * Makefile.in: 不要なコンパイルの回避(より完全に). * class.c (singleton_class_new): `single'->`singleton' Tue Dec 19 07:14:33 1995 Yukihiro Matsumoto * io.c (closed?): IOがcloseされているかどうかを知る述語. * parse.y (primary): 特異メソッドの引数のlex_stateが不適切. * lib/tk.rb: tcl->rubyの変換関数の用意. * ext/extmk.rb.in (install): installの2重コンパイルの回避. * array.c (range_beg_len): range指定の不適切なエラーを訂正. * string.c (str_aref): range指定のバグを削除. * lib/tk.rb (tk_split_list): Tclのリストに対応. Mon Dec 18 09:58:12 1995 Yukihiro Matsumoto * version 0.94 * dln.c (dln_load): HP対応(未確認) * eval.c (Init_Proc): BlockをProcに改名. Sat Dec 16 13:46:14 1995 Yukihiro Matsumoto * eval.c (rb_eval): retryでイテレータの再実行ができるように. Fri Dec 15 17:14:30 1995 Yukihiro Matsumoto * eval.c: proc:lambdaの親しみやすい別名 Thu Dec 14 17:21:55 1995 Yukihiro Matsumoto * eval.c (dyna_var_asgn): イテレータブロック内で最初に初期化された ローカル変数の有効範囲をそのブロック内に限定.これでlambdaと呼べ ないことはない. Wed Dec 13 02:30:58 1995 Yukihiro Matsumoto * gc.c: autoloadのマークミス. * lib/tk.rb: wishからの複数行の戻り値に対応 * lib/tkcomposite.rb: 複合widget * variable.c (rb_class2path): ICLASSに対応してなかった. * eval.c (ruby_run): exit(0)のバグ Sat Dec 9 01:21:24 1995 Yukihiro Matsumoto * ext/marshal/marshal.c (dumps|load): 文字列に対する入出力を可能に した(ただし実はファイル経由なのだ). Fri Dec 8 18:29:11 1995 Yukihiro Matsumoto * ext/marshal/marshal.c: シンボルを一度だけ初期化する. Thu Dec 7 07:58:50 1995 Yukihiro Matsumoto * parse.y (yylex): 第1引数の正規表現の認識にエラーがあった.同時に 状態数を減らした. * string.c (str_sub): 置換でスキップ幅が大きすぎた. Wed Dec 6 15:14:23 1995 Yukihiro Matsumoto * string.c (str_sub_method): sub/gsub(!なし)は置換が行なわれなかっ た時,置換前の文字列を返す. Tue Dec 5 00:55:15 1995 Yukihiro Matsumoto * parse.y (yylex): 括弧を省略した時の引数展開の`*'に対応. * eval.c (ruby_run): EXITハンドラ内での例外に対応. * bignum.c (big_cmp): BignumとFixnumの比較で落ちる. Mon Dec 4 14:21:18 1995 Yukihiro Matsumoto * parse.y (call_op): コンパイル時の定数式の展開をやめた.労多くし て益少ないと判断したので. Thu Nov 30 01:35:15 1995 Yukihiro Matsumoto * lib/tk.rb: {Radio,Check}Buttonのvariableの実装. * eval.c (rb_yield_0): Block.callがネストした時のバグ. * io.c (f_select): 常に配列3つをふくむ配列を返すように * lib/tk.rb: fileeventをruby側で実装. Wed Nov 29 17:53:23 1995 Yukihiro Matsumoto * variable.c (rb_ivar_get): selfを常に指定するように. Tue Nov 14 00:07:29 1995 Yukihiro Matsumoto * lib/tk.rb: Tk4.0対応 Mon Nov 13 16:23:32 1995 Yukihiro Matsumoto * version 0.93 Thu Nov 9 23:26:01 1995 Yukihiro Matsumoto * gc.c (gc_mark): モジュールのMixinのマーク忘れ. * parse.y (f_arglist): メソッド定義の引数を括弧で括らなくても良い ようにした. Wed Nov 8 00:17:51 1995 Yukihiro Matsumoto * eval.c (rb_yield_0): 未初期化のローカル変数があった. * eval.c (rb_eval): pendig signalのチェックをeval実行後に行うよう にした.でないとシグナルの発生と検出が遠く離れてしまう事がある. * parse.y: class文のsuperclass部を定数から式に拡張した. * lib/tk.rb: Tkのほぼ全ウィンドウクラスに対応.キャンバスとテキス ト上のオブジェクトが残っている. Tue Nov 7 08:18:37 1995 Yukihiro Matsumoto * signal.c (trap): ブロックを指定できるように. Mon Nov 6 16:44:00 1995 Yukihiro Matsumoto * eval.c (f_caller): 呼出元の情報を得る. * ext/tkutil/tkutil.c: wishのstderr出力を監視することで,エラー処 理を行う. * ext/tkutil/tkutil.c: wishとの通信部をCで記述. Sat Nov 4 01:12:59 1995 Yukihiro Matsumoto * sample/ruby-mode.el (ruby-calculate-indent): インデントの計算を もう少しスマートにした(正規表現のチェック,継続行のチェック). * eval.c (rb_call): 無限再帰を避けるため,関数のネストレベルの制限 を行なう. * lib/tk.rb: Tkインターフェース.まだ不完全だが. * eval.c (rb_yield_0): 空のBlockのバグ. * sample/ruby-mode.el (ruby-calculate-indent): 行末の演算子による 行継続に対応. Fri Nov 3 12:56:21 1995 Yukihiro Matsumoto * eval.c (rb_call): 本体が空の関数の実行にバグ. * parse.y (var_extend): 文字列の末尾の変数展開のバグ. * variable.c (rb_gvar_set): traceの評価時にに変数値を与えるように. * eval.c (f_require): ruby scriptのrequireにbug. * variable.c (rb_const_get): モジュールのinclude対策. Thu Oct 19 13:56:06 1995 Yukihiro Matsumoto * dln.c (dln_load): HP対応でのtypo. Wed Oct 18 17:39:39 1995 Yukihiro Matsumoto * version 0.92 * object.c (krn_type): オブジェクトの動的な型を返すメソッド. Tue Oct 17 00:48:18 1995 Yukihiro Matsumoto * ruby.c (proc_options): -X オプション.chdirだけを行う. * re.c (reg_search): 漢字コードを途中で変更できるように.コンパイ ル時のコードが変更された時にはマッチの直前に正規表現の再コンパイ ルを行う.定数KCODEから変数$KCODEへ. * parse.y: ()のなかにcompexprを許す. * re.c (reg_search): メモリリークを直した. Fri Oct 13 13:19:19 1995 Yukihiro Matsumoto * string.c (str_sub): 文字列置換にバグ. * string.c (str_strip_bang): 文字列の後ろの長さの調整が行われてい なかった. * re.c (reg_search): $&, $1...のはローカルに束縛するようになった. 呼び出したメソッドでのマッチは現スコープの$&などの値に影響しない. マッチの情報をスコープ外で得たいときには$~を使って束縛情報を持ち 出す必要がある. Thu Oct 12 00:33:33 1995 Yukihiro Matsumoto * re.c (reg_search): String:split, String:indexでは$&, $1...が変化 しないようにした. * io.c (rb_str_setter): setterの仕様が変更になっていた. * variable.c (f_trace_var): 第2引数を省略してイテレータとして呼べ るように. Wed Oct 11 11:50:59 1995 Yukihiro Matsumoto * version 0.91 * variable.c (var_setter): 引数が間違っていた.致命的バグ. * io.c (pipe_open): $stderrの値が変更されている時にはそちらを 子プロセスのstderrに設定する. Mon Oct 9 13:06:33 1995 Yukihiro Matsumoto * object.c (mod_to_s): モジュール内のモジュールは`::'を使った表現 で表示されるように. * variable.c (rb_gvar_set): 代入によるループが発生しないように, trace内での代入ではtraceを評価しない. * struct.c (struct_equal): structのequal判定にクラスの一致を含めた. Sat Oct 7 00:18:32 1995 Yukihiro Matsumoto * eval.c (rb_eval): defined?の機能を拡張(yieldのチェック,superの 存在など). Fri Oct 6 12:06:47 1995 Yukihiro Matsumoto * version 0.90 * st.c (st_foreach): 要素を削除した時に要素数が変化していなかった. * hash.c (hash_values): バグ修正.keysを返していた…. * parse.y (call_op): defined? の引数では定数の畳み込みを行わない (チェックする前にコンパイルエラーになっては困る). * スコープ生成の一部見直し. Thu Oct 5 00:29:43 1995 Yukihiro Matsumoto * 関数とクラスの命名規則を変更した.関数名,変数名の全面書き換え. * gc.c (looks_pointerp): ヒープチェックの高速化. * struct.c (Fstruct_aset): 構造体に対する`[]='. (struct_set): 構造体メンバに対する代入. Wed Oct 4 09:54:07 1995 Yukihiro Matsumoto * version 0.89 * eval.c (Frequire): ダイナミックロードのエラーチェックを厳しく. * struct.c: structの構造を完全に書き換えた.以前は順序付きの id->valueの連想配列であったが,今度は構造体毎に新しいクラスを生 成するようにした. * parse.y: `::'の意味をAssocの生成からクラス(モジュール)内の定数ア クセスへ変更. * assoc.c: なくす. Tue Oct 3 13:31:08 1995 Yukihiro Matsumoto * variable.c (Ftrace_var): trace_var, 大域変数への書き込みhookを設 定する. * variable.c: global_entryの構成を書き換えた.これでtrace_varを実 装できる. * file.c (Ffile_stat): "&"で直前のfstatの結果も参照できるように. Fri Sep 29 14:15:13 1995 Yukihiro Matsumoto * version 0.88 * dln.c (dln_load): AIXとHPに対応したコードを入れた(動作は未確認). * ext/extmk.rb.in: 必要に応じて,定数EXTLIBを定義するように. * dln.c (dln_load): dln独立に書き換える.将来の拡張用. (load_1): dln_a_outにおいてソースコードでライブラリを明示的にロー ドする必要がないように変更した. Thu Sep 28 13:31:37 1995 Yukihiro Matsumoto * sample/ruby-mode.el: もっとましなhilit19対応(正規表現). Wed Sep 27 04:12:44 1995 Takahasi Mamoru * sample/test.rb: echoで-nを使わないように(SysV対策). * ext/extmk.rb.in: sub -> sub! Tue Sep 26 19:12:42 1995 Yasuo OHBA * dln.c (dln_find_1): `.', `..'から始まるパスに対応した. Mon Sep 25 12:33:03 1995 Yukihiro Matsumoto * version 0.87 Sat Sep 23 10:00:18 1995 Yukihiro Matsumoto * eval.c (Fmod_modfunc): メソッドをprivateにし,同時に特異メソッド も定義するメソッド.パッケージ的使い方のモジュール用. Fri Sep 22 11:02:44 1995 Yukihiro Matsumoto * lib/find.rb: findを提供するライブラリ * variable.c (rb_define_variable): hookの設定を分離. (add_hook): 1変数に対して複数のhookを設定できるように. Thu Sep 21 00:22:11 1995 Yukihiro Matsumoto * string.c (Fstr_frozen): 文字列が更新不可かどうかをチェックする述 語メソッド. * hash.c (Fhash_aset): keyが文字列の時,キーの内容が変化しないよう に,dupしてfreezeする. Wed Sep 20 16:12:44 1995 Yukihiro Matsumoto * version 0.86 * ext/extmk.rb.in (have_header): キャッシュにバグ. * ext/extmk.rb.in (have_library): 引数の順序が変わった. Thu Sep 14 18:00:59 1995 Yukihiro Matsumoto * object.c (obj_is_instance_of): is_member_ofから名称変更. Wed Sep 13 15:44:35 1995 Yukihiro Matsumoto * string.c (Fstr_tr_bang): 範囲外の文字に対する変換バグ. Tue Sep 12 14:27:58 1995 Yukihiro Matsumoto * file.c (Sfile_expand_path): expand_file_name -> expand_pathに名 称変更. * enum.c (Fenum_member): includes? -> member? に名称変更. * string.c (Fstr_each_byte): StringはByteArrayであるという基本に戻っ て,eachの定義をeach_byteに変更した.今までのeachはeach_lineでア クセスできる. Mon Sep 11 18:31:17 1995 Yukihiro Matsumoto * file.c (cache_stat): ファイル名として"&"を指定すると直前の stat(2)の結果を再利用するように. Fri Sep 8 14:18:51 1995 Yukihiro Matsumoto * ruby.texi: `!', `?'に対応してアップデート. * parse.y: defined -> defined? * file.c: FileOpの一文字メソッドをなくす.一文字テストはtestメソッ ドにまかせる. * parse.y (yylex): 変数名の後ろに`?'も許す.述語メソッドの後ろに `?'を追加する. Thu Sep 7 20:01:33 1995 Yukihiro Matsumoto * string.c: 文字列の中身を更新するメソッドの名前の終りに`!'を付加. `!'の無いバージョンも用意した. * parse.y: 変数名の後ろに`!'を許す. Wed Sep 6 14:12:19 1995 Yukihiro Matsumoto * version 0.85 * string.c (Fstr_dup): 文字列の複製を作る (Fstr_freeze): 文字列の更新不可属性を設定できるように. (Fsub/Fgsub): $_の内容をdupしてから置換を行うように. * ruby.h (CLONESETUP): flagsの状態もコピー Tue Sep 5 01:27:50 1995 Yukihiro Matsumoto * sample/test.rb: 失敗の検出を厳しく. Fri Aug 25 14:31:02 1995 Yukihiro Matsumoto * process.c (Ffork): イテレータとしても動作するように. * version 0.84 * signal.c (sig_beg): ハンドラが設定されている時には再設定しない. * ext/extmk.rb.in (create_makefile): shared objectのリンクの際に `-l'オプションを指定するように. * signal.c (trap): `EXIT'で終了処理を行う設定が出来る. Wed Aug 16 00:13:22 1995 Yukihiro Matsumoto * signal.c (sig_beg): デフォルトではbegin節の中でだけSIGINTを捕捉 するように変更. * io.c (io_ctl): fcntlを持たないシステムにも対応. * 各ディレクトリに分散していたMANIFESTをまとめた.拡張モジュール毎 には必要. * string.c (Sstr_new,str_sub,Fstr_crypt): 引数を自動的に文字列に変 換するように. Sat Aug 12 00:44:02 1995 Yukihiro Matsumoto * string.c (Fstr_crypt): PD cryptを用意した. Fri Aug 11 14:37:03 1995 Yukihiro Matsumoto * assoc.c (Fassoc_clone): assocもcloneできるように. * io.c: マクロREAD_DATA_PENDINGの定義を変更(Linux対応) * io.c (io_fptr_finalize): ftprの開放時の処理を指定できるように. Wed Aug 9 16:52:41 1995 Yukihiro Matsumoto * eval.c (rb_provided): 複数のfeatureをロードすると無限ループに落 ちるという単純な(しかし凶悪な)ミス. * ext/extmk.rb.in (install): dlopen対応を行った.今までdlnにしか十 分に対応していなかった. Tue Aug 8 14:17:06 1995 Yukihiro Matsumoto * version 0.83 Mon Aug 7 12:47:41 1995 Yukihiro Matsumoto * parse.y: resque -> rescue.恥ずかしいがtypoを残しておくわけには いかないよなあ.なんで今まで気がつかなかったのか…. Thu Aug 3 18:18:05 1995 Yukihiro Matsumoto * missing/nt.c: NT移植用の関数群をまとめた. * variable.c (rb_const_get): また例外を発生するようにした.defined がある以上例外を発生させない理由がないので(例外が発生した方がタ イプミスの検出などの点で有利). * variable.c (Fautoload): autoloadを実装.今度は使えるか. Mon Jul 31 15:44:21 1995 Yukihiro Matsumoto * parse.y (arg_ambiguous): 第1引数のあいまいさを警告(-vオプション で有効). * eval.c (rb_eval): `-v'オプションをつけて`def'が呼ばれると不必要 なエラーメッセージが出た. * parse.y (yylex): メソッドの第1引数の判定をもうちょっと賢くした. Fri Jul 28 19:04:43 1995 Yukihiro Matsumoto * parse.y (yylex): `+/-/['の直前に空白が来るかどうかで動作を変更し た(混乱のもとか?) Wed Jul 26 09:21:23 1995 Yukihiro Matsumoto * version 0.82a * sprintf.c (Fsprintf): `%s'で'\0'を含む文字列に対応. * pack.c (Fpck_pack): packの要素確保のバグ. * eval.c (Floop): 無限ループのイテレータ. * io.c (next_argv): 存在しないファイル名が指定された時のエラー処理 が行われていなかった. Mon Jul 24 17:37:34 1995 Yukihiro Matsumoto * version 0.82 * ext/extmk.rb.in (install): 拡張モジュールをstatic linkする場合は そのモジュールが既にrequireされたのと同じようにfeatureを設定する. これで拡張モジュールの機能が必要な時には(static linkされているか どうかにかかわらず)requireすればよくなる. * eval.c (Frequire): `$"'に格納する文字列をフルパスでなくフィーチャ 名とする.rubyスクリプトをロードした時には`.rb',オブジェクトを ロードした時には`.o'をフィーチャ名に付加する.lispのrequireと provideの働きに(少し)近い. Thu Jul 20 12:50:05 1995 Yukihiro Matsumoto * Makefile.in (test): make testができるように. * struct.c (struct_new): typo. * eval.c (rb_eval): `defined'を追加.メソッド/変数/定数の定義状態 を知る事が出来る. Wed Jul 19 18:04:01 1995 Yukihiro Matsumoto * version 0.81 Mon Jul 17 14:53:51 1995 Yukihiro Matsumoto * variable.c (rb_const_get): 未初期化のCONSTANTの値をnilにした.し かし,今後また例外に戻す可能性はある.要はoptionalなクラス/モジュー ルが存在するかチェックしたいだけなんだな. * st.c (int): grow_factorを固定にした(大嶋さんのマシンに対応). Fri Jul 14 00:48:40 1995 Yukihiro Matsumoto * ext/extmk.rb.in: キャッシュのバグを修正. * parse.y (var_extend): #{$数字}に対応した. * dln.c (dln_load_1): `Init_FILENAME'だけを有効に.`init_*'は今後 実行しない. * ext/etc/etc.c : Etcモジュールを拡張モジュールとして分離.実はNT 対応への布石だったりするかもしれない. Tue Jul 11 17:12:48 1995 Yukihiro Matsumoto * gcc -Wallで出たwarningを元にソースを変更. * signal.c (trap): typo. Fri Jul 7 10:08:51 1995 Yukihiro Matsumoto * version 0.80 * ruby.texi: texinfo documentを提供.specとruby.1は無くなった. * signal.c (Ftrap): 割込み禁止中の例外発生に対応. * eval.c (Flambda): Blockオブジェクトを返す.Block.newと同義. Thu Jul 6 00:35:03 1995 Yukihiro Matsumoto * signal.c (Ftrap): SIG_DFLの処理を変更.SIGINTへのデフォルトハン ドラを用意(例外を発生する). * file.c (Sfile_expand_fname): パス名を絶対パスに展開するメソッド. (Sfile_basename): basenameを得るメソッド.拡張子も外せる. (Sfile_dirname): basenameの反対. * eval.c (rb_call): argument評価中の例外発生に対応. * file.c (Ftest): `M', `A', `C'を追加. Tue Jul 4 12:36:33 1995 Yukihiro Matsumoto * file.c (Ftest): ファイルテスト用メソッド. * ruby.c (proc_options): `-r'オプションを追加. * parse.y (f_args): デフォルト引数を追加. * eval.c (rb_call): 該当する引数が無い時,rest引数の値をnilに. * numeric.c (num_equal): 数値以外との比較で例外が発生していた. FALSEを返すように. * eval.c (masign): 多重代入のrest部の動作がおかしかった. Sat Jun 17 01:03:16 1995 Yukihiro Matsumoto * parse.y (gettable): 未初期化のローカル変数の参照(独立した識別子) は正式にメソッド呼び出しとした. * parse.y (read_escape): tokenbufを使わないように修正.それにとも ない,`\C-x',`\M-x'などのエスケープ表現を復活.これでドキュメン トと実際の処理系が一致した. Thu Jun 15 15:42:00 1995 Yukihiro Matsumoto * re.c (re_regcomp): cacheのチェックを改善. Mon Jun 12 18:50:51 1995 Yukihiro Matsumoto * version 0.79 Sat Jun 10 00:25:01 1995 Yukihiro Matsumoto * re.c (re_regcomp): cache判定に`$='の値も反映させた. * sample/test.rb: test suite作成. Fri Jun 9 15:58:34 1995 Yukihiro Matsumoto * re.c (re_regcomp): cacheの判定が間違っていた. Fri Jun 9 00:01:35 1995 Yukihiro Matsumoto (matz@dyna) * eval.c (rb_yield): block構造体に初期化していないメンバ(iter)があっ たのでイテレータのネストが正しく動作しなかった. Thu Jun 8 00:59:03 1995 Yukihiro Matsumoto (matz@dyna) * re.c (=~): String以外との比較がFALSEを返すように(例外を発生して いた). * extmk.rb.in: 判定した値をファイルにキャッシュするようにした. * assoc.c (to_a): to_aメソッドが再定義されていなかった. * eval.c (rb_eval): 初期化されていないローカル変数へのアクセスを引 数の無いメソッド呼び出しと解釈する.ただし,(現状では)メソッドが 定義されていない場合,エラーにせず変数未初期化のwaringを出して nilを返している.「ruby -pe print」などが実行できるという意味で はありがたいこの仕様は,しかし今後の検討が必要である.-- メソッ ド呼び出しとするのを止めるか(以前の仕様),いつもメソッド呼び出し とする(未定義ならばエラー)か,今の仕様で行くか. * eval.c (rb_eval): 初期化されていないローカル変数へのアクセスで (evalなどで)初期化された事が分かった時には以後初期化されたローカ ル変数とみなす. Wed Jun 7 11:58:12 1995 Yukihiro Matsumoto * eval.c (rb_fail): 例外処理後も`$!'をクリアしないように. (rb_fail): `$!'変数に最後に改行を追加しない. * io.c (Fprint): privateメソッドに変更.引数を取らない時の動作を変 更(`$_'を出力する). (Fio_print): 出力先指定のprintメソッド. (Fio_printf): 出力先指定のprintfメソッド. * parse.y: not演算子の追加.優先順位の低い`!'演算子. Mon Jun 5 19:00:55 1995 Yukihiro Matsumoto * version 0.78 Fri Jun 2 17:52:03 1995 Yukihiro Matsumoto * ruby.c (proc_options): -Iオプションで`$:'への追加される順番を修 正した. Fri Jun 2 00:36:34 1995 Yukihiro Matsumoto (matz@dyna) * parse.y: while修飾子の動作を通常のwhileと同じにした.ただし, begin式へのwhile修飾子だけはdo..while型のループとなる. Wed May 31 18:36:30 1995 Yukihiro Matsumoto * version 0.77 Mon May 29 18:39:37 1995 Yukihiro Matsumoto * ext/extmk.rb.in (install): 拡張モジュールもインストールできるよ うに. Fri May 26 14:43:01 1995 Yukihiro Matsumoto * process.c (Fsystem): 戻り値をサブプロセスの失敗/成功を表す真偽値 にした.終了ステータスは`$?'で得る. Tue May 23 10:58:11 1995 Yukihiro Matsumoto * string.c (Fstr_upto): 無限ループに陥らないように. * parse.y (cond): `||'などの右辺に制御式が書けるように,条件式がか ならずしも値を持たなくても良いようにした. * ext/marshal/marshal.c: オブジェクトの読み書きをメソッドの再定義 でコントロールできるように.インスタンスが`_dump_to'というメソッ ドを定義している時はそちらを使うように. * ext/extmk.rb.in: static linkも設定できるような仕様にした. ext/Setupというファイルにディレクトリ名を記述するとそのディレク トリに存在するモジュールはstatic linkされる(はず). * eval.c (rb_eval): `..'を文法に組み込み,`..'と`...'の動作をperl に合わせた. Sat May 20 01:22:48 1995 Yukihiro Matsumoto (matz@dyna) * io.c (select): timeout時と割込み時の動作の明確化. Co-authored-by: Takahasi Mamoru Co-authored-by: Yasuo OHBA --- file.c | 782 +++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 574 insertions(+), 208 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index e09ec7b21c..0691545c6a 100644 --- a/file.c +++ b/file.c @@ -10,24 +10,49 @@ ************************************************/ -#include -#include #include "ruby.h" #include "io.h" + #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_SYS_PARAM_H +# include +#else +# define MAXPATHLEN 1024 +#endif + +#ifdef HAVE_SYS_TIME_H +# include +#else +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ +}; +#endif + #ifdef HAVE_UTIME_H #include #endif +#ifdef HAVE_PWD_H +#include +#endif + +#ifdef HAVE_STRING_H +# include +#else +char *strrchr(); +#endif char *strdup(); +char *getenv(); -extern VALUE C_IO; -VALUE C_File; -VALUE M_FileTest; +extern VALUE cIO; +VALUE cFile; +VALUE mFileTest; +static VALUE sStat; VALUE time_new(); @@ -38,7 +63,7 @@ file_open(fname, mode) VALUE port; OpenFile *fptr; - port = obj_alloc(C_File); + port = obj_alloc(cFile); MakeOpenFile(port, fptr); fptr->mode = io_mode_flags(mode); @@ -79,7 +104,7 @@ apply2files(func, args, arg) } static VALUE -Ffile_tell(obj) +file_tell(obj) VALUE obj; { OpenFile *fptr; @@ -94,7 +119,7 @@ Ffile_tell(obj) } static VALUE -Ffile_seek(obj, offset, ptrname) +file_seek(obj, offset, ptrname) VALUE obj, offset, ptrname; { OpenFile *fptr; @@ -110,7 +135,7 @@ Ffile_seek(obj, offset, ptrname) } static VALUE -Ffile_set_pos(obj, offset) +file_set_pos(obj, offset) VALUE obj, offset; { OpenFile *fptr; @@ -125,7 +150,7 @@ Ffile_set_pos(obj, offset) } static VALUE -Ffile_rewind(obj) +file_rewind(obj) VALUE obj; { OpenFile *fptr; @@ -138,7 +163,7 @@ Ffile_rewind(obj) } static VALUE -Ffile_eof(obj) +file_eof(obj) VALUE obj; { OpenFile *fptr; @@ -149,7 +174,7 @@ Ffile_eof(obj) } static VALUE -Ffile_path(obj) +file_path(obj) VALUE obj; { OpenFile *fptr; @@ -159,7 +184,7 @@ Ffile_path(obj) } static VALUE -Ffile_isatty(obj) +file_isatty(obj) VALUE obj; { return FALSE; @@ -174,56 +199,55 @@ stat_new(st) struct stat *st; { if (st == Qnil) Bug("stat_new() called with nil"); - return struct_new("stat", - "dev", INT2FIX((int)st->st_dev), - "ino", INT2FIX((int)st->st_ino), - "mode", INT2FIX((int)st->st_mode), - "nlink", INT2FIX((int)st->st_nlink), - "uid", INT2FIX((int)st->st_uid), - "gid", INT2FIX((int)st->st_gid), + return struct_new(sStat, + INT2FIX((int)st->st_dev), + INT2FIX((int)st->st_ino), + INT2FIX((int)st->st_mode), + INT2FIX((int)st->st_nlink), + INT2FIX((int)st->st_uid), + INT2FIX((int)st->st_gid), #ifdef HAVE_ST_RDEV - "rdev", INT2FIX((int)st->st_rdev), + INT2FIX((int)st->st_rdev), #else - "rdev", INT2FIX(0), + INT2FIX(0), #endif - "size", INT2FIX((int)st->st_size), + INT2FIX((int)st->st_size), #ifdef HAVE_ST_BLKSIZE - "blksize", INT2FIX((int)st->st_blksize), + INT2FIX((int)st->st_blksize), #else - "blksize", INT2FIX(0), + INT2FIX(0), #endif #ifdef HAVE_ST_BLOCKS - "blocks", INT2FIX((int)st->st_blocks), + INT2FIX((int)st->st_blocks), #else - "blocks", INT2FIX(0), + INT2FIX(0), #endif - "atime", time_new(st->st_atime, 0), - "mtime", time_new(st->st_mtime, 0), - "ctime", time_new(st->st_ctime, 0), + time_new(st->st_atime, 0), + time_new(st->st_mtime, 0), + time_new(st->st_ctime, 0), Qnil); } -static char lastpath[MAXPATHLEN]; static struct stat laststat; +int cache_stat(path, st) char *path; struct stat *st; { - if (strcmp(lastpath, path) == 0) { + if (strcmp("&", path) == 0) { *st = laststat; return 0; } if (stat(path, st) == -1) return -1; - strcpy(lastpath, path); - laststat = *st; + laststat = *st; return 0; } static VALUE -Sfile_stat(obj, fname) +file_s_stat(obj, fname) VALUE obj; struct RString *fname; { @@ -237,21 +261,20 @@ Sfile_stat(obj, fname) } static VALUE -Ffile_stat(obj) +file_stat(obj) VALUE obj; { OpenFile *fptr; - struct stat st; GetOpenFile(obj, fptr); - if (fstat(fileno(fptr->f), &st) == -1) { + if (fstat(fileno(fptr->f), &laststat) == -1) { rb_sys_fail(fptr->path); } - return stat_new(&st); + return stat_new(&laststat); } static VALUE -Sfile_lstat(obj, fname) +file_s_lstat(obj, fname) VALUE obj; struct RString *fname; { @@ -265,7 +288,7 @@ Sfile_lstat(obj, fname) } static VALUE -Ffile_lstat(obj) +file_lstat(obj) VALUE obj; { OpenFile *fptr; @@ -278,21 +301,18 @@ Ffile_lstat(obj) return stat_new(&st); } -#define HAS_GETGROUPS - static int group_member(gid) GETGROUPS_T gid; { - GETGROUPS_T egid; - +#ifndef NT if (getgid() == gid || getegid() == gid) return TRUE; -#ifdef HAS_GETGROUPS -#ifndef NGROUPS -#define NGROUPS 32 -#endif +# ifdef HAVE_GETGROUPS +# ifndef NGROUPS +# define NGROUPS 32 +# endif { GETGROUPS_T gary[NGROUPS]; int anum; @@ -302,6 +322,7 @@ group_member(gid) if (gary[anum] == gid) return TRUE; } +# endif #endif return FALSE; } @@ -315,7 +336,6 @@ eaccess(path, mode) char *path; int mode; { - extern int group_member (); struct stat st; static int euid = -1; @@ -347,7 +367,7 @@ eaccess(path, mode) } static VALUE -Ftest_d(obj, fname) +test_d(obj, fname) VALUE obj; struct RString *fname; { @@ -364,7 +384,7 @@ Ftest_d(obj, fname) } static VALUE -Ftest_p(obj, fname) +test_p(obj, fname) VALUE obj; struct RString *fname; { @@ -384,7 +404,7 @@ Ftest_p(obj, fname) } static VALUE -Ftest_l(obj, fname) +test_l(obj, fname) VALUE obj; struct RString *fname; { @@ -413,7 +433,8 @@ Ftest_l(obj, fname) return FALSE; } -Ftest_S(obj, fname) +VALUE +test_S(obj, fname) VALUE obj; struct RString *fname; { @@ -443,7 +464,7 @@ Ftest_S(obj, fname) } static VALUE -Ftest_b(obj, fname) +test_b(obj, fname) VALUE obj; struct RString *fname; { @@ -465,7 +486,7 @@ Ftest_b(obj, fname) } static VALUE -Ftest_c(obj, fname) +test_c(obj, fname) VALUE obj; struct RString *fname; { @@ -483,7 +504,7 @@ Ftest_c(obj, fname) } static VALUE -Ftest_e(obj, fname) +test_e(obj, fname) VALUE obj; struct RString *fname; { @@ -495,7 +516,7 @@ Ftest_e(obj, fname) } static VALUE -Ftest_r(obj, fname) +test_r(obj, fname) VALUE obj; struct RString *fname; { @@ -505,7 +526,7 @@ Ftest_r(obj, fname) } static VALUE -Ftest_R(obj, fname) +test_R(obj, fname) VALUE obj; struct RString *fname; { @@ -515,7 +536,7 @@ Ftest_R(obj, fname) } static VALUE -Ftest_w(obj, fname) +test_w(obj, fname) VALUE obj; struct RString *fname; { @@ -525,7 +546,7 @@ Ftest_w(obj, fname) } static VALUE -Ftest_W(obj, fname) +test_W(obj, fname) VALUE obj; struct RString *fname; { @@ -535,7 +556,7 @@ Ftest_W(obj, fname) } static VALUE -Ftest_x(obj, fname) +test_x(obj, fname) VALUE obj; struct RString *fname; { @@ -545,7 +566,7 @@ Ftest_x(obj, fname) } static VALUE -Ftest_X(obj, fname) +test_X(obj, fname) VALUE obj; struct RString *fname; { @@ -555,7 +576,7 @@ Ftest_X(obj, fname) } static VALUE -Ftest_f(obj, fname) +test_f(obj, fname) VALUE obj; struct RString *fname; { @@ -568,7 +589,7 @@ Ftest_f(obj, fname) } static VALUE -Ftest_z(obj, fname) +test_z(obj, fname) VALUE obj; struct RString *fname; { @@ -581,7 +602,7 @@ Ftest_z(obj, fname) } static VALUE -Ftest_s(obj, fname) +test_s(obj, fname) VALUE obj; struct RString *fname; { @@ -594,7 +615,7 @@ Ftest_s(obj, fname) } static VALUE -Ftest_owned(obj, fname) +test_owned(obj, fname) VALUE obj; struct RString *fname; { @@ -607,15 +628,32 @@ Ftest_owned(obj, fname) } static VALUE -Ftest_grpowned(obj, fname) +test_rowned(obj, fname) VALUE obj; struct RString *fname; { struct stat st; + Check_Type(fname, T_STRING); + if (cache_stat(fname->ptr, &st) < 0) return FALSE; + if (st.st_uid == getuid()) return TRUE; + return FALSE; +} + +static VALUE +test_grpowned(obj, fname) + VALUE obj; + struct RString *fname; +{ +#ifndef NT + struct stat st; + Check_Type(fname, T_STRING); if (cache_stat(fname->ptr, &st) < 0) return FALSE; if (st.st_gid == getegid()) return TRUE; +#else + Check_Type(fname, T_STRING); +#endif return FALSE; } @@ -634,7 +672,7 @@ check3rdbyte(file, mode) #endif static VALUE -Ftest_suid(obj, fname) +test_suid(obj, fname) VALUE obj; struct RString *fname; { @@ -647,12 +685,12 @@ Ftest_suid(obj, fname) } static VALUE -Ftest_sgid(obj, fname) +test_sgid(obj, fname) VALUE obj; struct RString *fname; { Check_Type(fname, T_STRING); -#ifdef S_ISGID +#ifndef NT return check3rdbyte(fname->ptr, S_ISGID); #else return FALSE; @@ -660,7 +698,7 @@ Ftest_sgid(obj, fname) } static VALUE -Ftest_sticky(obj, fname) +test_sticky(obj, fname) VALUE obj; struct RString *fname; { @@ -673,7 +711,7 @@ Ftest_sticky(obj, fname) } static VALUE -Sfile_type(obj, fname) +file_s_type(obj, fname) VALUE obj; struct RString *fname; { @@ -718,7 +756,7 @@ Sfile_type(obj, fname) } static VALUE -Sfile_atime(obj, fname) +file_s_atime(obj, fname) VALUE obj; struct RString *fname; { @@ -730,7 +768,7 @@ Sfile_atime(obj, fname) } static VALUE -Ffile_atime(obj) +file_atime(obj) VALUE obj; { OpenFile *fptr; @@ -744,7 +782,7 @@ Ffile_atime(obj) } static VALUE -Sfile_mtime(obj, fname) +file_s_mtime(obj, fname) VALUE obj; struct RString *fname; { @@ -756,7 +794,7 @@ Sfile_mtime(obj, fname) } static VALUE -Ffile_mtime(obj) +file_mtime(obj) VALUE obj; { OpenFile *fptr; @@ -770,7 +808,7 @@ Ffile_mtime(obj) } static VALUE -Sfile_ctime(obj, fname) +file_s_ctime(obj, fname) VALUE obj; struct RString *fname; { @@ -782,7 +820,7 @@ Sfile_ctime(obj, fname) } static VALUE -Ffile_ctime(obj) +file_ctime(obj) VALUE obj; { OpenFile *fptr; @@ -805,15 +843,13 @@ chmod_internal(path, mode) } static VALUE -Sfile_chmod(argc, argv, obj) +file_s_chmod(argc, argv) int argc; VALUE *argv; - VALUE obj; { VALUE vmode; VALUE rest; int mode, n; - VALUE path; rb_scan_args(argc, argv, "1*", &vmode, &rest); mode = NUM2INT(vmode); @@ -823,7 +859,7 @@ Sfile_chmod(argc, argv, obj) } static VALUE -Ffile_chmod(obj, vmode) +file_chmod(obj, vmode) VALUE obj, vmode; { OpenFile *fptr; @@ -852,10 +888,9 @@ chown_internal(path, args) } static VALUE -Sfile_chown(argc, argv, obj) +file_s_chown(argc, argv) int argc; VALUE *argv; - VALUE obj; { VALUE o, g, rest; struct chown_args arg; @@ -879,11 +914,11 @@ Sfile_chown(argc, argv, obj) return INT2FIX(n); } -Ffile_chown(obj, owner, group) +VALUE +file_chown(obj, owner, group) VALUE obj, owner, group; { OpenFile *fptr; - int mode; GetOpenFile(obj, fptr); if (fchown(fileno(fptr->f), NUM2INT(owner), NUM2INT(group)) == -1) @@ -894,7 +929,7 @@ Ffile_chown(obj, owner, group) struct timeval *time_timeval(); -#ifdef HAVE_UTIME +#ifdef HAVE_UTIMES static void utime_internal(path, tvp) @@ -906,10 +941,9 @@ utime_internal(path, tvp) } static VALUE -Sfile_utime(argc, argv, obj) +file_s_utime(argc, argv) int argc; VALUE *argv; - VALUE obj; { VALUE atime, mtime, rest; struct timeval tvp[2]; @@ -926,39 +960,35 @@ Sfile_utime(argc, argv, obj) #else +#ifndef HAVE_UTIME_H +# ifdef NT +# include +# else +struct utimbuf { + long actime; + long modtime; +}; +# endif +#endif + static void utime_internal(path, utp) char *path; -#ifdef HAVE_UTIME_H struct utimbuf *utp; -#else - struct { - long actime; - long modtime; - } *utp; -#endif { if (utime(path, utp) < 0) rb_sys_fail(path); } static VALUE -Sfile_utime(argc, argv, obj) +file_s_utime(argc, argv) int argc; VALUE *argv; - VALUE obj; { VALUE atime, mtime, rest; int n; struct timeval *tv; -#ifdef HAVE_UTIME_H struct utimbuf utbuf; -#else - struct { - long actime; - long modtime; - } utbuf; -#endif rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest); @@ -974,7 +1004,7 @@ Sfile_utime(argc, argv, obj) #endif static VALUE -Sfile_link(obj, from, to) +file_s_link(obj, from, to) VALUE obj; struct RString *from, *to; { @@ -987,7 +1017,7 @@ Sfile_link(obj, from, to) } static VALUE -Sfile_symlink(obj, from, to) +file_s_symlink(obj, from, to) VALUE obj; struct RString *from, *to; { @@ -1000,7 +1030,7 @@ Sfile_symlink(obj, from, to) } static VALUE -Sfile_readlink(obj, path) +file_s_readlink(obj, path) VALUE obj; struct RString *path; { @@ -1024,7 +1054,7 @@ unlink_internal(path) } static VALUE -Sfile_unlink(obj, args) +file_s_unlink(obj, args) VALUE obj; struct RArray *args; { @@ -1035,7 +1065,7 @@ Sfile_unlink(obj, args) } static VALUE -Sfile_rename(obj, from, to) +file_s_rename(obj, from, to) VALUE obj; struct RString *from, *to; { @@ -1049,12 +1079,11 @@ Sfile_rename(obj, from, to) } static VALUE -Sfile_umask(argc, argv) +file_s_umask(argc, argv) int argc; VALUE *argv; { - VALUE mask; - int omask; + int omask = 0; if (argc == 0) { int omask = umask(0); @@ -1069,20 +1098,44 @@ Sfile_umask(argc, argv) return INT2FIX(omask); } +#if defined(HAVE_TRUNCATE) || defined(HAVE_CHSIZE) static VALUE -Sfile_truncate(obj, path, len) +file_s_truncate(obj, path, len) VALUE obj, len; struct RString *path; { Check_Type(path, T_STRING); +#ifdef HAVE_TRUNCATE if (truncate(path->ptr, NUM2INT(len)) < 0) rb_sys_fail(path->ptr); +#else +# ifdef HAVE_CHSIZE + { + int tmpfd; + +#if defined(NT) + if ((tmpfd = open(path->ptr, O_RDWR)) < 0) { + rb_sys_fail(path->ptr); + } +#else + if ((tmpfd = open(path->ptr, 0)) < 0) { + rb_sys_fail(path->ptr); + } +#endif + if (chsize(tmpfd, NUM2INT(len)) < 0) { + close(tmpfd); + rb_sys_fail(path->ptr); + } + close(tmpfd); + } +# endif +#endif return TRUE; } static VALUE -Ffile_truncate(obj, len) +file_truncate(obj, len) VALUE obj, len; { OpenFile *fptr; @@ -1092,111 +1145,424 @@ Ffile_truncate(obj, len) if (!(fptr->mode & FMODE_WRITABLE)) { Fail("not opened for writing"); } +#ifdef HAVE_TRUNCATE if (ftruncate(fileno(fptr->f), NUM2INT(len)) < 0) rb_sys_fail(fptr->path); +#else +# ifdef HAVE_CHSIZE + if (chsize(fileno(fptr->f), NUM2INT(len)) < 0) + rb_sys_fail(fptr->path); +# endif +#endif return TRUE; } +#endif +#ifdef HAVE_FCNTL static VALUE -Ffile_fcntl(obj, req, arg) +file_fcntl(obj, req, arg) VALUE obj, req; struct RString *arg; { io_ctl(obj, req, arg, 0); return obj; } +#endif + +static VALUE +file_s_expand_path(obj, fname) + VALUE obj; + struct RString *fname; +{ + char *s, *p; + char buf[MAXPATHLEN]; + + Check_Type(fname, T_STRING); + s = fname->ptr; + + p = buf; + if (s[0] == '~') { + if (s[1] == '/' || s[1] == '\0') { + char *dir = getenv("HOME"); + + if (!dir) { + Fail("couldn't find HOME environment -- expanding `%s'", s); + } + strcpy(buf, dir); + p = &buf[strlen(buf)]; + s++; + } + else { +#ifdef HAVE_PWD_H + struct passwd *pwPtr; + s++; +#endif + + while (*s && *s != '/') { + *p++ = *s++; + } + *p = '\0'; +#ifdef HAVE_PWD_H + pwPtr = getpwnam(buf); + if (!pwPtr) { + endpwent(); + Fail("user %s doesn't exist", buf); + } + strcpy(buf, pwPtr->pw_dir); + p = &buf[strlen(buf)]; + endpwent(); +#endif + } + } + else if (s[0] != '/') { +#ifdef HAVE_GETCWD + getcwd(buf, MAXPATHLEN); +#else + getwd(buf)l +#endif + p = &buf[strlen(buf)]; + } + *p = '/'; + + for ( ; *s; s++) { + switch (*s) { + case '.': + if (*(s+1)) { + switch (*++s) { + case '.': + if (*(s+1) == '\0' || *(s+1) == '/') { + /* We must go back to the parent */ + if (*p == '/' && p > buf) p--; + while (p > buf && *p != '/') p--; + } + else { + *++p = '.'; + *++p = '.'; + } + break; + case '/': + if (*p != '/') *++p = '/'; + break; + default: + *++p = '.'; *++p = *s; break; + } + } + break; + case '/': + if (*p != '/') *++p = '/'; break; + default: + *++p = *s; + } + } + + /* Place a \0 at end. If path ends with a "/", delete it */ + if (p == buf || *p != '/') p++; + *p = '\0'; + + return str_new2(buf); +} + +static int +rmext(p, e) + char *p, *e; +{ + int l1, l2; + + l1 = strlen(p); + if (!e) return 0; + + l2 = strlen(e); + if (l1 < l2) return l1; + + if (strcmp(p+l1-l2, e) == 0) { + return l1-l2; + } + return 0; +} + +static VALUE +file_s_basename(argc, argv) + int argc; + VALUE *argv; +{ + struct RString *fname; + struct RString *ext; + char *p; + int f; + + rb_scan_args(argc, argv, "11", &fname, &ext); + Check_Type(fname, T_STRING); + if (ext) Check_Type(ext, T_STRING); + p = strrchr(fname->ptr, '/'); + if (p == Qnil) { + if (ext) { + f = rmext(fname->ptr, ext->ptr); + if (f) return str_new(fname->ptr, f); + } + return (VALUE)fname; + } + p++; /* skip last `/' */ + if (ext) { + f = rmext(p, ext->ptr); + if (f) return str_new(p, f); + } + return str_new2(p); +} + +static VALUE +file_s_dirname(obj, fname) + VALUE obj; + struct RString *fname; +{ + char *p; + Check_Type(fname, T_STRING); + p = strrchr(fname->ptr, '/'); + if (p == Qnil) return (VALUE)fname; + return str_new(fname->ptr, p - fname->ptr); +} + +static void +test_check(n, argc, argv) + int n, argc; + VALUE *argv; +{ + int i; + + n+=1; + if (n < argc) Fail("Wrong # of arguments(%d for %d)", argc, n); + for (i=1; iptr, &st) == -1) { + rb_sys_fail(RSTRING(argv[1])->ptr); + } + + switch (cmd) { + case 'A': + return time_new(st.st_atime, 0); + case 'M': + return time_new(st.st_mtime, 0); + case 'C': + return time_new(st.st_ctime, 0); + } + } + + if (strchr("-=<>", cmd)) { + struct stat st1, st2; + + CHECK(2); + if (stat(RSTRING(argv[1])->ptr, &st1) < 0) return FALSE; + if (stat(RSTRING(argv[2])->ptr, &st2) < 0) return FALSE; + + switch (cmd) { + case '-': + if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) + return TRUE; + break; + + case '=': + if (st1.st_mtime == st2.st_mtime) return TRUE; + break; + + case '>': + if (st1.st_mtime > st2.st_mtime) return TRUE; + break; + + case '<': + if (st1.st_mtime < st2.st_mtime) return TRUE; + break; + } + } + return FALSE; +} + +extern VALUE cKernel; + +void Init_File() { - M_FileTest = rb_define_module("FileTest"); - - rb_define_method(M_FileTest, "d", Ftest_d, 1); - rb_define_method(M_FileTest, "isdirectory", Ftest_d, 1); - rb_define_method(M_FileTest, "a", Ftest_e, 1); - rb_define_method(M_FileTest, "e", Ftest_e, 1); - rb_define_method(M_FileTest, "exists", Ftest_e, 1); - rb_define_method(M_FileTest, "r", Ftest_r, 1); - rb_define_method(M_FileTest, "readable", Ftest_r, 1); - rb_define_method(M_FileTest, "R", Ftest_R, 1); - rb_define_method(M_FileTest, "w", Ftest_w, 1); - rb_define_method(M_FileTest, "writable", Ftest_w, 1); - rb_define_method(M_FileTest, "W", Ftest_W, 1); - rb_define_method(M_FileTest, "x", Ftest_x, 1); - rb_define_method(M_FileTest, "executable", Ftest_x, 1); - rb_define_method(M_FileTest, "X", Ftest_X, 1); - rb_define_method(M_FileTest, "f", Ftest_f, 1); - rb_define_method(M_FileTest, "isfile", Ftest_f, 1); - rb_define_method(M_FileTest, "z", Ftest_z, 1); - rb_define_method(M_FileTest, "s", Ftest_s, 1); - rb_define_method(M_FileTest, "size", Ftest_s, 1); - rb_define_method(M_FileTest, "O", Ftest_owned, 1); - rb_define_method(M_FileTest, "owned", Ftest_owned, 1); - rb_define_method(M_FileTest, "G", Ftest_grpowned, 1); - - rb_define_method(M_FileTest, "p", Ftest_p, 1); - rb_define_method(M_FileTest, "ispipe", Ftest_p, 1); - rb_define_method(M_FileTest, "l", Ftest_l, 1); - rb_define_method(M_FileTest, "issymlink", Ftest_l, 1); - rb_define_method(M_FileTest, "S", Ftest_S, 1); - rb_define_method(M_FileTest, "issocket", Ftest_S, 1); - - rb_define_method(M_FileTest, "b", Ftest_b, 1); - rb_define_method(M_FileTest, "c", Ftest_c, 1); - - rb_define_method(M_FileTest, "u", Ftest_suid, 1); - rb_define_method(M_FileTest, "setuid", Ftest_suid, 1); - rb_define_method(M_FileTest, "g", Ftest_sgid, 1); - rb_define_method(M_FileTest, "setgid", Ftest_sgid, 1); - rb_define_method(M_FileTest, "k", Ftest_sticky, 1); - - C_File = rb_define_class("File", C_IO); - rb_extend_object(C_File, M_FileTest); - - 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", 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", Sfile_utime, -1); - rb_define_single_method(C_File, "chmod", Sfile_chmod, -1); - rb_define_single_method(C_File, "chown", Sfile_chown, -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", 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_define_method(C_File, "stat", Ffile_stat, 0); - rb_define_method(C_File, "lstat", Ffile_lstat, 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_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); - - - rb_define_method(C_File, "pos", Ffile_tell, 0); - rb_define_method(C_File, "pos=", Ffile_set_pos, 1); - - rb_define_method(C_File, "rewind", Ffile_rewind, 0); - rb_define_method(C_File, "isatty", Ffile_isatty, 0); - rb_define_method(C_File, "eof", Ffile_eof, 0); - - rb_define_method(C_IO, "fcntl", Ffile_fcntl, 2); - - rb_define_method(C_File, "path", Ffile_path, 0); + mFileTest = rb_define_module("FileTest"); + + rb_define_module_function(mFileTest, "directory?", test_d, 1); + rb_define_module_function(mFileTest, "exists?", test_e, 1); + rb_define_module_function(mFileTest, "readable?", test_r, 1); + rb_define_module_function(mFileTest, "readable_real?", test_R, 1); + rb_define_module_function(mFileTest, "writable?", test_w, 1); + rb_define_module_function(mFileTest, "writable_real?", test_W, 1); + rb_define_module_function(mFileTest, "executable?", test_x, 1); + rb_define_module_function(mFileTest, "executable_real?", test_X, 1); + rb_define_module_function(mFileTest, "file?", test_f, 1); + rb_define_module_function(mFileTest, "zero?", test_z, 1); + rb_define_module_function(mFileTest, "size", test_s, 1); + rb_define_module_function(mFileTest, "owned?", test_owned, 1); + rb_define_module_function(mFileTest, "grpowned?", test_grpowned, 1); + + rb_define_module_function(mFileTest, "pipe?", test_p, 1); + rb_define_module_function(mFileTest, "symlink?", test_l, 1); + rb_define_module_function(mFileTest, "socket?", test_S, 1); + + rb_define_module_function(mFileTest, "blockdev?", test_b, 1); + rb_define_module_function(mFileTest, "chardev?", test_c, 1); + + rb_define_module_function(mFileTest, "setuid?", test_suid, 1); + rb_define_module_function(mFileTest, "setgid?", test_sgid, 1); + rb_define_module_function(mFileTest, "sticky?", test_sticky, 1); + + cFile = rb_define_class("File", cIO); + rb_extend_object(cFile, CLASS_OF(mFileTest)); + + rb_define_singleton_method(cFile, "stat", file_s_stat, 1); + rb_define_singleton_method(cFile, "lstat", file_s_lstat, 1); + rb_define_singleton_method(cFile, "type", file_s_type, 1); + + rb_define_singleton_method(cFile, "atime", file_s_atime, 1); + rb_define_singleton_method(cFile, "mtime", file_s_mtime, 1); + rb_define_singleton_method(cFile, "ctime", file_s_ctime, 1); + + rb_define_singleton_method(cFile, "utime", file_s_utime, -1); + rb_define_singleton_method(cFile, "chmod", file_s_chmod, -1); + rb_define_singleton_method(cFile, "chown", file_s_chown, -1); + + rb_define_singleton_method(cFile, "link", file_s_link, 2); + rb_define_singleton_method(cFile, "symlink", file_s_symlink, 2); + rb_define_singleton_method(cFile, "readlink", file_s_readlink, 1); + + rb_define_singleton_method(cFile, "unlink", file_s_unlink, -2); + rb_define_singleton_method(cFile, "delete", file_s_unlink, -2); + rb_define_singleton_method(cFile, "rename", file_s_rename, 2); + rb_define_singleton_method(cFile, "umask", file_s_umask, -1); +#if defined(HAVE_TRUNCATE) || defined(HAVE_CHSIZE) + rb_define_singleton_method(cFile, "truncate", file_s_truncate, 2); +#endif + rb_define_singleton_method(cFile, "expand_path", file_s_expand_path, 1); + rb_define_singleton_method(cFile, "basename", file_s_basename, -1); + rb_define_singleton_method(cFile, "dirname", file_s_dirname, 1); + + rb_define_method(cFile, "stat", file_stat, 0); + rb_define_method(cFile, "lstat", file_lstat, 0); + + rb_define_method(cFile, "atime", file_atime, 0); + rb_define_method(cFile, "mtime", file_mtime, 0); + rb_define_method(cFile, "ctime", file_ctime, 0); + + rb_define_method(cFile, "chmod", file_chmod, 1); + rb_define_method(cFile, "chown", file_chown, 2); +#if defined(HAVE_TRUNCATE) || defined(HAVE_CHSIZE) + rb_define_method(cFile, "truncate", file_truncate, 1); +#endif + + rb_define_method(cFile, "tell", file_tell, 0); + rb_define_method(cFile, "seek", file_seek, 2); + + rb_define_method(cFile, "pos", file_tell, 0); + rb_define_method(cFile, "pos=", file_set_pos, 1); + + rb_define_method(cFile, "rewind", file_rewind, 0); + rb_define_method(cFile, "isatty", file_isatty, 0); + rb_define_method(cFile, "tty?", file_isatty, 0); + rb_define_method(cFile, "eof", file_eof, 0); + rb_define_method(cFile, "eof?", file_eof, 0); + +#ifdef HAVE_FCNTL + rb_define_method(cIO, "fcntl", file_fcntl, 2); +#endif + + rb_define_method(cFile, "path", file_path, 0); + + rb_define_method(cKernel, "test", f_test, -1); + + sStat = struct_define("Stat", "dev", "ino", "mode", + "nlink", "uid", "gid", "rdev", + "size", "blksize", "blocks", + "atime", "mtime", "ctime", Qnil); } -- cgit v1.2.3