summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1994-07-18 10:19:15 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:29 +0900
commit200e0ee2fd3c1c006c528874a88f684447215524 (patch)
treedf2252585f3000878a15123d98ccb08124306b90 /sample
version 0.49v0_49
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.49.tar.gz 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()で落ちていた. Thu Jul 14 11:18:07 1994 Yukihiro Matsumoto (matz@ix-02) * eval.c: メソッドが存在しない時にはKernel:_undefined(id)が呼ばれ るように. しかし, rubyでは個々のメソッド毎の処理よりも, クラス 単位の処理が必要な気もするなあ. * 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で<sys/types.h>もインクルードするようにした. * 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.
Diffstat (limited to 'sample')
-rw-r--r--sample/Artistic117
-rw-r--r--sample/aset.rb3
-rw-r--r--sample/attr.rb9
-rw-r--r--sample/biorhythm.rb201
-rw-r--r--sample/caller.rb15
-rw-r--r--sample/case.rb12
-rw-r--r--sample/cat.rb4
-rw-r--r--sample/cbreak.rb34
-rw-r--r--sample/clnt.rb12
-rw-r--r--sample/clone.rb12
-rw-r--r--sample/const.rb20
-rw-r--r--sample/dbm.rb6
-rw-r--r--sample/dir.rb9
-rw-r--r--sample/evaldef.rb21
-rw-r--r--sample/fib.awk5
-rw-r--r--sample/fib.pl10
-rw-r--r--sample/fib.rb8
-rw-r--r--sample/freq.rb13
-rw-r--r--sample/fullpath.pl22
-rw-r--r--sample/fullpath.rb24
-rw-r--r--sample/gctest.rb69
-rw-r--r--sample/getopts.rb111
-rwxr-xr-xsample/getopts.test31
-rw-r--r--sample/hash.rb4
-rw-r--r--sample/io.rb40
-rwxr-xr-xsample/less.rb30
-rw-r--r--sample/list.rb81
-rw-r--r--sample/list2.rb20
-rw-r--r--sample/math.rb4
-rwxr-xr-xsample/mpart.rb42
-rw-r--r--sample/newver.rb13
-rw-r--r--sample/occur.pl9
-rw-r--r--sample/occur.rb10
-rw-r--r--sample/occur2.rb14
-rw-r--r--sample/opt_s.rb8
-rw-r--r--sample/opt_x.rb8
-rw-r--r--sample/parsearg.rb69
-rw-r--r--sample/perror.rb7
-rw-r--r--sample/rcs.awk33
-rw-r--r--sample/rcs.dat17
-rw-r--r--sample/rcs.rb42
-rw-r--r--sample/reach.rb5
-rw-r--r--sample/resp.rb2
-rw-r--r--sample/samp.rb12
-rw-r--r--sample/split.rb12
-rw-r--r--sample/struct.rb4
-rw-r--r--sample/svr.rb23
-rw-r--r--sample/system.rb1
-rw-r--r--sample/t1.rb20
-rw-r--r--sample/t2.rb24
-rw-r--r--sample/test.rb5
-rw-r--r--sample/trap.pl6
-rw-r--r--sample/trap.rb3
-rw-r--r--sample/tt.rb103
54 files changed, 1439 insertions, 0 deletions
diff --git a/sample/Artistic b/sample/Artistic
new file mode 100644
index 0000000000..fbf7989775
--- /dev/null
+++ b/sample/Artistic
@@ -0,0 +1,117 @@
+
+
+
+
+ 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
new file mode 100644
index 0000000000..cfec649ac3
--- /dev/null
+++ b/sample/aset.rb
@@ -0,0 +1,3 @@
+ary = [0, 0, 4, 5]
+ary[1, 0] = [7]
+print(ary, "\n")
diff --git a/sample/attr.rb b/sample/attr.rb
new file mode 100644
index 0000000000..2db79f1ae5
--- /dev/null
+++ b/sample/attr.rb
@@ -0,0 +1,9 @@
+class Foo
+ attr("test", %TRUE)
+end
+
+foo = Foo.new
+foo.test = 10
+print(foo.test, "\n")
+foo._inspect.print
+print("\n")
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
new file mode 100644
index 0000000000..3261c4377f
--- /dev/null
+++ b/sample/biorhythm.rb
@@ -0,0 +1,201 @@
+#!/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(t, 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 + t
+ 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 [<RETURN> 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/caller.rb b/sample/caller.rb
new file mode 100644
index 0000000000..8988733377
--- /dev/null
+++ b/sample/caller.rb
@@ -0,0 +1,15 @@
+def test
+ for i in 1..2
+ for j in 1..5
+ print(j, ": ", caller(j).join(':'), "\n")
+ end
+ end
+end
+
+def test2
+ print(1, ": ", caller(1).join(':'), "\n")
+ test()
+end
+
+test2()
+caller()
diff --git a/sample/case.rb b/sample/case.rb
new file mode 100644
index 0000000000..f456f023d3
--- /dev/null
+++ b/sample/case.rb
@@ -0,0 +1,12 @@
+
+case "t"
+when /1/
+ print(1, "\n")
+when /t/
+ print(3..5, "\n")
+when /./
+ print(2, "\n")
+else
+ print("else\n")
+end
+
diff --git a/sample/cat.rb b/sample/cat.rb
new file mode 100644
index 0000000000..93f028906a
--- /dev/null
+++ b/sample/cat.rb
@@ -0,0 +1,4 @@
+while gets()
+ if $. == 1 ... ~ /^\*/; print("--") end
+ printf("%5d: %s", $., $_)
+end
diff --git a/sample/cbreak.rb b/sample/cbreak.rb
new file mode 100644
index 0000000000..4b4cb1d3e6
--- /dev/null
+++ b/sample/cbreak.rb
@@ -0,0 +1,34 @@
+%CBREAK = 0x00000002
+%ECHO = 0x00000008
+%TIOCGETP = 0x40067408
+%TIOCSETP = 0x80067409
+
+def cbreak ()
+ set_cbreak(%TRUE)
+end
+
+def cooked ()
+ set_cbreak(%FALSE)
+end
+
+def set_cbreak (on)
+ tty = "\0" * 256
+ $stdin.ioctl(%TIOCGETP, tty)
+ ttys = tty.unpack("C4 S")
+ if on
+ ttys[4] |= %CBREAK
+ ttys[4] &= ~%ECHO
+ else
+ ttys[4] &= ~%CBREAK
+ ttys[4] |= %ECHO
+ end
+ tty = ttys.pack("C4 S")
+ $stdin.ioctl(%TIOCSETP, tty)
+end
+cbreak();
+
+print("this is echo line: ");
+readline().print
+cooked();
+print("this is non echo line: ");
+readline().print
diff --git a/sample/clnt.rb b/sample/clnt.rb
new file mode 100644
index 0000000000..639e2a0daf
--- /dev/null
+++ b/sample/clnt.rb
@@ -0,0 +1,12 @@
+host=(if $ARGV.length == 2; $ARGV.shift; else "localhost"; end)
+print("Trying ", host, " ...")
+$stdout.flush
+s = TCPsocket.open(host, $ARGV.shift)
+print(" done\n")
+print("addr: ", s.addr.join(":"), "\n")
+print("peer: ", s.peeraddr.join(":"), "\n")
+while gets()
+ s.write($_)
+ print(s.gets)
+end
+s.close
diff --git a/sample/clone.rb b/sample/clone.rb
new file mode 100644
index 0000000000..6a752e8ab5
--- /dev/null
+++ b/sample/clone.rb
@@ -0,0 +1,12 @@
+foo = Object.new
+def foo.test
+ print("test\n")
+end
+bar = foo.clone
+def bar.test2
+ print("test2\n")
+end
+bar.test2
+bar.test
+foo.test
+foo.test2
diff --git a/sample/const.rb b/sample/const.rb
new file mode 100644
index 0000000000..d7629fe8e1
--- /dev/null
+++ b/sample/const.rb
@@ -0,0 +1,20 @@
+%test1 = 1
+%test2 = 2
+
+module Const
+ %test3 = 3
+ %test4 = 4
+end
+
+module Const2
+ %test3 = 6
+ %test4 = 8
+end
+
+include Const
+
+print(%test1,%test2,%test3,%test4,"\n")
+
+include Const2
+
+print(%test1,%test2,%test3,%test4,"\n")
diff --git a/sample/dbm.rb b/sample/dbm.rb
new file mode 100644
index 0000000000..1f2886e026
--- /dev/null
+++ b/sample/dbm.rb
@@ -0,0 +1,6 @@
+# ruby
+#
+
+d = Dbm.open("test")
+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
new file mode 100644
index 0000000000..f4c3d17c11
--- /dev/null
+++ b/sample/dir.rb
@@ -0,0 +1,9 @@
+dirp = Dir.open(".")
+dirp.rewind
+for f in dirp
+ if (~/^\./ || ~/~$/ || ~/\.o/)
+ else
+ print(f, "\n")
+ end
+end
+dirp.close
diff --git a/sample/evaldef.rb b/sample/evaldef.rb
new file mode 100644
index 0000000000..c261b53068
--- /dev/null
+++ b/sample/evaldef.rb
@@ -0,0 +1,21 @@
+class foo
+ def foo
+ eval("
+def baz
+ print(\"bar\n\")
+end")
+ end
+end
+
+class bar:foo
+ def bar
+ baz()
+ end
+end
+
+f = foo.new
+b = bar.new
+
+b.foo
+b.bar
+f.baz
diff --git a/sample/fib.awk b/sample/fib.awk
new file mode 100644
index 0000000000..7ebe8930f5
--- /dev/null
+++ b/sample/fib.awk
@@ -0,0 +1,5 @@
+ function fib(n) {
+ if ( n<2 ) return n; else return fib(n-2) + fib(n-1)
+ }
+
+ BEGIN { print fib(20); }
diff --git a/sample/fib.pl b/sample/fib.pl
new file mode 100644
index 0000000000..c5593764aa
--- /dev/null
+++ b/sample/fib.pl
@@ -0,0 +1,10 @@
+ sub fib {
+ local($n)=@_;
+ if( $n<2 ){
+ return $n;
+ } {
+ return &fib($n-2)+&fib($n-1)
+ }
+ }
+
+ print &fib(20), "\n";
diff --git a/sample/fib.rb b/sample/fib.rb
new file mode 100644
index 0000000000..c72f91f2f2
--- /dev/null
+++ b/sample/fib.rb
@@ -0,0 +1,8 @@
+def fib (n)
+ if n<2
+ n
+ else
+ fib(n-2)+fib(n-1)
+ end
+end
+print(fib(20), "\n");
diff --git a/sample/freq.rb b/sample/freq.rb
new file mode 100644
index 0000000000..7417e0b5a4
--- /dev/null
+++ b/sample/freq.rb
@@ -0,0 +1,13 @@
+#
+
+freq = {}
+while gets()
+ while sub(/\w+/, '')
+ word = $&
+ freq[word] +=1
+ end
+end
+
+for word in freq.keys.sort
+ printf("%s -- %d\n", word, freq[word])
+end
diff --git a/sample/fullpath.pl b/sample/fullpath.pl
new file mode 100644
index 0000000000..a07b90edd4
--- /dev/null
+++ b/sample/fullpath.pl
@@ -0,0 +1,22 @@
+#! /usr/local/bin/perl
+# convert ls-lR filename into fullpath.
+
+$path = shift;
+if (!defined $path) {
+ $path = "";
+}
+elsif ($path !~ /\/$/) {
+ $path .= "/"
+}
+
+while (<>) {
+ if (/:$/) {
+ chop; chop;
+ $path = $_ . "/";
+ } elsif (/^total/ || /^d/) {
+ next;
+ } elsif (/^(.*\d )(.+)$/) {
+ print $1, $path, $2, "\n";
+ }
+}
+
diff --git a/sample/fullpath.rb b/sample/fullpath.rb
new file mode 100644
index 0000000000..b1d4b9c332
--- /dev/null
+++ b/sample/fullpath.rb
@@ -0,0 +1,24 @@
+#! /usr/local/bin/ruby
+# convert ls-lR filename into fullpath.
+
+if $ARGV[0] =~ /-p/
+ $ARGV.shift
+ path = $ARGV.shift
+end
+
+if path == nil
+ path = ""
+elsif path !~ /\/$/
+ print(path, "/\n")
+ path += "/"
+end
+
+while gets()
+ if /:$/
+ path = $_.chop.chop + "/"
+ elsif /^total/ || /^d/
+ elsif /^(.*\d )(.+)$/
+ print($1, path, $2, "\n")
+ end
+end
+
diff --git a/sample/gctest.rb b/sample/gctest.rb
new file mode 100644
index 0000000000..6067393bbb
--- /dev/null
+++ b/sample/gctest.rb
@@ -0,0 +1,69 @@
+def cons(car, cdr)
+ [car, cdr]
+end
+
+def car(x)
+ if x == nil ; nil else x[0] end
+end
+
+def cdr(x)
+ if x == nil ; nil else x[1] end
+end
+
+def reverse1(x, y)
+ if x == nil ; y else reverse1(cdr(x), cons(car(x), y)) end
+end
+
+def reverse(x)
+ reverse1(x, nil)
+end
+
+def ints(low, up)
+ if low > up
+ nil
+ else
+ cons(low, ints(low+1, up))
+ end
+end
+
+def print_int_list(x)
+ if x == nil
+ print("NIL\n")
+ else
+ print(car(x))
+ if nil != cdr(x)
+ print(", ")
+ print_int_list(cdr(x))
+ else
+ print("\n")
+ end
+ end
+end
+
+GC.threshold = 1000000
+
+print("start\n")
+print("threshold: ", GC.threshold, "\n");
+
+a = ints(1, 100)
+print_int_list(a)
+b = ints(1, 50)
+print_int_list(b)
+print_int_list(reverse(a))
+print_int_list(reverse(b))
+for i in 1 .. 100
+ b = reverse(reverse(b))
+# print(i, ": ")
+# print_int_list(b)
+end
+print("a: ")
+print_int_list(a)
+print("b: ")
+print_int_list(b)
+print("reverse(a): ")
+print_int_list(reverse(a))
+print("reverse(b): ")
+print_int_list(reverse(b))
+a = b = nil
+print("finish\n")
+GC.start()
diff --git a/sample/getopts.rb b/sample/getopts.rb
new file mode 100644
index 0000000000..57a7db424f
--- /dev/null
+++ b/sample/getopts.rb
@@ -0,0 +1,111 @@
+#
+# getopts.rb - get options
+# $Release Version: $
+# $Revision: 1.2 $
+# $Date: 1994/02/15 05:17:15 $
+# by Yasuo OHBA(STAFS Development Room)
+#
+# --
+# IvV̉͂, $OPT_?? ɒlZbg܂.
+# ŵȂIvVw肳ꂽ nil Ԃ܂.
+# Iꍇ, ZbgꂽIvV̐Ԃ܂.
+#
+# getopts(single_opts, *opts)
+#
+# ex. sample [options] filename
+# options ...
+# -f -x --version --geometry 100x200 -d unix:0.0
+#
+# getopts("fx", "version", "geometry:", "d:")
+#
+# :
+# -f -x (= -fx) ̗lȈꕶ̃IvV̎w܂.
+# ňȂƂ nil ̎w肪Kvł.
+# ȍ~:
+# Ol[̃IvV, ̔IvV̎w܂.
+# --version , --geometry 300x400 , -d host:0.0 ł.
+# 𔺂w ":" KtĂ.
+#
+# IvV̎w肪ꍇ, ϐ $OPT_?? non-nil , ̃I
+# vV̈Zbg܂.
+# -f -> $OPT_f = %TRUE
+# --geometry 300x400 -> $OPT_geometry = 300x400
+#
+# - -- , ȍ~, SăIvV̉͂܂.
+#
+
+$RCS_ID="$Header: /var/ohba/RCS/getopts.rb,v 1.2 1994/02/15 05:17:15 ohba Exp ohba $"
+
+def getopts(single_opts, *opts)
+ if (opts)
+ single_colon = ""
+ long_opts = []
+ sc = 0
+ for option in opts
+ if (option.length <= 2)
+ single_colon[sc, 0] = option[0, 1]
+ sc += 1
+ else
+ long_opts.push(option)
+ end
+ end
+ end
+
+ count = 0
+ while ($ARGV.length != 0)
+ compare = nil
+ case $ARGV[0]
+ when /^-*$/
+ $ARGV.shift
+ break
+ when /^--.*/
+ compare = $ARGV[0][2, ($ARGV[0].length - 2)]
+ if (long_opts != "")
+ for option in long_opts
+ if (option[(option.length - 1), 1] == ":" &&
+ option[0, (option.length - 1)] == compare)
+ if ($ARGV.length <= 1)
+ return nil
+ end
+ eval("$OPT_" + compare + " = " + '$ARGV[1]')
+ $ARGV.shift
+ count += 1
+ break
+ elsif (option == compare)
+ eval("$OPT_" + compare + " = %TRUE")
+ count += 1
+ break
+ end
+ end
+ end
+ when /^-.*/
+ for index in 1..($ARGV[0].length - 1)
+ compare = $ARGV[0][index, 1]
+ if (single_opts && compare =~ "[" + single_opts + "]")
+ eval("$OPT_" + compare + " = %TRUE")
+ count += 1
+ elsif (single_colon != "" && compare =~ "[" + single_colon + "]")
+ if ($ARGV[0][index..-1].length > 1)
+ eval("$OPT_" + compare + " = " + '$ARGV[0][(index + 1)..-1]')
+ count += 1
+ elsif ($ARGV.length <= 1)
+ return nil
+ else
+ eval("$OPT_" + compare + " = " + '$ARGV[1]')
+ $ARGV.shift
+ count = count + 1
+ end
+ break
+ end
+ end
+ else
+ break
+ end
+
+ $ARGV.shift
+ if (!defined("$OPT_" + compare))
+ return nil
+ end
+ end
+ return count
+end
diff --git a/sample/getopts.test b/sample/getopts.test
new file mode 100755
index 0000000000..16f1bb06c7
--- /dev/null
+++ b/sample/getopts.test
@@ -0,0 +1,31 @@
+#! /mp/free/bin/ruby -- -*- ruby -*-
+
+load("parsearg.rb")
+
+def usage()
+ printf("Usage:\n")
+ printf("This is Getopt test program \n")
+end
+
+$USAGE = 'usage'
+parseArgs(0, !nil, "d", "x:", "y:", "version", "geometry:")
+if ($OPT_d)
+ if ($OPT_x)
+ printf("x = %d\n", $OPT_x.atoi)
+ end
+ if ($OPT_y)
+ printf("y = %d\n", $OPT_y.atoi)
+ end
+ if ($OPT_geometry)
+ printf("geometry = %s\n", $OPT_geometry)
+ end
+end
+
+if ($OPT_version)
+ printf("version 1.00\n")
+end
+
+while ($ARGV.length != 0)
+ print ("other = ", $ARGV[0], "\n")
+ $ARGV.shift
+end
diff --git a/sample/hash.rb b/sample/hash.rb
new file mode 100644
index 0000000000..126b17dfe4
--- /dev/null
+++ b/sample/hash.rb
@@ -0,0 +1,4 @@
+print(+-1.0.hash,"\n")
+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
new file mode 100644
index 0000000000..45d50d653a
--- /dev/null
+++ b/sample/io.rb
@@ -0,0 +1,40 @@
+home = getenv("HOME")
+print(home.sub("m", "&&"), home, "\n")
+print(home.reverse, "\n")
+
+if File.s("io.rb")
+ print(File.s("io.rb"), ": io.rb\n")
+end
+
+$/="f\n"
+for i in "abc\n\ndef\nghi\n"
+ print("tt: ", i)
+end
+
+printf("%s:(%d)%s\n", $0, $ARGV.length, $ARGV[0])
+passwd = open($ARGV[0], "r")
+#printf("%s", do passwd.find using i; i =~ /\*/ end)
+
+n = 1
+for i in passwd #.grep(/^\*/)
+ printf("%6d: %s", n, i)
+ n = n + 1;
+end
+
+fp = open("|-", "r")
+
+if fp == nil
+ for i in 1..5
+ print(i, "\n")
+ end
+else
+ for line in fp
+ print(line)
+ end
+end
+
+def printUsage()
+ if $USAGE
+ apply($USAGE);
+ end
+end
diff --git a/sample/less.rb b/sample/less.rb
new file mode 100755
index 0000000000..e818e7a2ba
--- /dev/null
+++ b/sample/less.rb
@@ -0,0 +1,30 @@
+#! /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 $"
+
+ZCAT = "/usr/local/bin/zcat"
+LESS = "/usr/local/bin/less"
+
+FILE = $ARGV.pop
+OPTION = (if $ARGV.length == 0; "" else $ARGV.join(" "); end)
+
+if FILE =~ /\.(Z|gz)$/
+ exec(format("%s %s | %s %s", ZCAT, FILE, LESS, OPTION))
+elsif FILE == nil
+ exec(format("%s %s", LESS, OPTION))
+else
+ print(format("%s %s %s", LESS, OPTION, FILE), "\n")
+ exec(format("%s %s %s", LESS, OPTION, FILE))
+end
+exit()
diff --git a/sample/list.rb b/sample/list.rb
new file mode 100644
index 0000000000..e0b5b383b0
--- /dev/null
+++ b/sample/list.rb
@@ -0,0 +1,81 @@
+# Linked list program
+class MyElem
+ def MyElem.new(item)
+ super.init(item)
+ end
+
+ def init(item)
+ @data = item
+ @next = nil
+ self
+ end
+
+ def data
+ @data
+ end
+
+ def next
+ @next
+ end
+
+ def next=(new)
+ @next = new
+ end
+end
+
+class MyList
+ def add_to_list(obj)
+ elt = MyElem.new(obj)
+ if @head
+ @tail.next = elt
+ else
+ @head = elt
+ end
+ @tail = elt
+ end
+
+ def each
+ elt = @head
+ while elt
+ yield elt
+ elt = elt.next
+ end
+ end
+
+ def to_s
+ str = "<MyList:\n";
+ for elt in self
+ str += elt.data.to_s + "\n"
+ end
+ str += ">"
+ str
+ end
+end
+
+class Point
+ def Point.new(x, y)
+ super.init(x, y)
+ end
+
+ def init(x, y)
+ @x = x; @y = y
+ self
+ end
+
+ def to_s
+ sprintf("%d@%d", @x, @y)
+ end
+end
+
+list1 = MyList.new
+list1.add_to_list(10)
+list1.add_to_list(20)
+list1.add_to_list(Point.new(2, 3))
+list1.add_to_list(Point.new(4, 5))
+list2 = MyList.new
+list2.add_to_list(20)
+list2.add_to_list(Point.new(4, 5))
+list2.add_to_list(list1)
+
+print("list1:\n", list1, "\n")
+print("list2:\n", list2, "\n")
diff --git a/sample/list2.rb b/sample/list2.rb
new file mode 100644
index 0000000000..c2e9bca753
--- /dev/null
+++ b/sample/list2.rb
@@ -0,0 +1,20 @@
+# Linked list program -- short version
+class Point
+ def Point.new(x, y)
+ super.init(x, y)
+ end
+
+ def init(x, y)
+ @x = x; @y = y
+ self
+ end
+
+ def to_s
+ sprintf("%d@%d", @x, @y)
+ end
+end
+
+list1 = [10, 20, Point.new(2, 3), Point.new(4, 5)]
+list2 = [20, Point.new(4, 5), list1]
+print("list1:\n", list1.join("\n"), "\n")
+print("list2:\n", list2.join("\n"), "\n")
diff --git a/sample/math.rb b/sample/math.rb
new file mode 100644
index 0000000000..83be1b9048
--- /dev/null
+++ b/sample/math.rb
@@ -0,0 +1,4 @@
+#load("lib/math.o")
+include Math
+sqrt(4)
+print(Math.sqrt(257), "\n")
diff --git a/sample/mpart.rb b/sample/mpart.rb
new file mode 100755
index 0000000000..c0f705ef8e
--- /dev/null
+++ b/sample/mpart.rb
@@ -0,0 +1,42 @@
+#! ./ruby
+
+lines = 1000
+
+if ($ARGV[0] =~ /^-(\d+)$/ )
+ lines = $1.to_i;
+ $ARGV.shift;
+end
+
+basename = $ARGV[0]
+extname = "part"
+
+part = 1
+line = 0
+
+fline = 0
+for i in ifp = open(basename)
+ fline = fline + 1
+end
+ifp.close
+
+parts = fline / lines + 1
+
+for i in ifp = open(basename)
+ if line == 0
+ ofp = open(sprintf("%s.%s%02d", basename, extname, part), "w")
+ printf(ofp, "%s part%02d/%02d\n", basename, part, parts)
+ ofp.write("BEGIN--cut here--cut here\n")
+ end
+ ofp.write(i)
+ line = line + 1
+ if line >= lines
+ ofp.write("END--cut here--cut here\n")
+ ofp.close
+ part = part + 1
+ line = 0
+ end
+end
+ofp.write("END--cut here--cut here\n")
+ofp.close
+
+ifp.close
diff --git a/sample/newver.rb b/sample/newver.rb
new file mode 100644
index 0000000000..bbf03aebc2
--- /dev/null
+++ b/sample/newver.rb
@@ -0,0 +1,13 @@
+#! /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 + 1
+ printf("ruby version %d.%0d\n", $1, i)
+ printf(f, "#define RUBY_VERSION \"%d.%0d\"\n", $1, i)
+ f.close
+end
diff --git a/sample/occur.pl b/sample/occur.pl
new file mode 100644
index 0000000000..1f5fcf27a4
--- /dev/null
+++ b/sample/occur.pl
@@ -0,0 +1,9 @@
+while (<>) {
+ for (split(/\W+/)) {
+ $freq{$_}++;
+ }
+}
+
+for (sort keys %freq) {
+ print "$_ -- $freq{$_}\n";
+}
diff --git a/sample/occur.rb b/sample/occur.rb
new file mode 100644
index 0000000000..12e469d20a
--- /dev/null
+++ b/sample/occur.rb
@@ -0,0 +1,10 @@
+freq = {}
+while gets()
+ for word in $_.split(/\W+/)
+ freq[word] +=1
+ end
+end
+
+for word in freq.keys.sort
+ printf("%s -- %d\n", word, freq[word])
+end
diff --git a/sample/occur2.rb b/sample/occur2.rb
new file mode 100644
index 0000000000..6e0513707c
--- /dev/null
+++ b/sample/occur2.rb
@@ -0,0 +1,14 @@
+freq = {}
+while gets()
+ for word in $_.split(/\W+/)
+ protect
+ freq[word] = freq[word] + 1
+ resque
+ freq[word] = 1
+ end
+ end
+end
+
+for word in freq.keys.sort
+ printf("%s -- %d\n", word, freq[word])
+end
diff --git a/sample/opt_s.rb b/sample/opt_s.rb
new file mode 100644
index 0000000000..4981119012
--- /dev/null
+++ b/sample/opt_s.rb
@@ -0,0 +1,8 @@
+#! ruby -s
+if ($xyz)
+ print("xyz = TRUE\n")
+end
+if ($zzz)
+ print("zzz = ", $zzz, "\n")
+end
+print($ARGV.join(", "), "\n")
diff --git a/sample/opt_x.rb b/sample/opt_x.rb
new file mode 100644
index 0000000000..4fc9a25276
--- /dev/null
+++ b/sample/opt_x.rb
@@ -0,0 +1,8 @@
+this is a forwarding header
+this is a header too.
+ #! ruby
+this is a trailing
+#! ./ruby -v
+print("tt\n")
+__END__
+this is a trailer
diff --git a/sample/parsearg.rb b/sample/parsearg.rb
new file mode 100644
index 0000000000..e7e2b7a7f3
--- /dev/null
+++ b/sample/parsearg.rb
@@ -0,0 +1,69 @@
+#
+# parseargs.rb - parse arguments
+# $Release Version: $
+# $Revision: 1.3 $
+# $Date: 1994/02/15 05:16:21 $
+# by Yasuo OHBA(STAFS Development Room)
+#
+# --
+# ̉͂, $OPT_?? ɒlZbg܂.
+# Iꍇ, ZbgꂽIvV̐Ԃ܂.
+#
+# parseArgs(argc, single_opts, *opts)
+#
+# ex. sample [options] filename
+# options ...
+# -f -x --version --geometry 100x200 -d unix:0.0
+#
+# parseArgs(1, nil, "fx", "version", "geometry:", "d:")
+#
+# :
+# IvVȊO̍Œ̐
+# :
+# IvV̕KvcKKvȂ %TRUE łȂ %FALSE.
+# O:
+# -f -x (= -fx) ̗lȈꕶ̃IvV̎w܂.
+# ňȂƂ nil ̎w肪Kvł.
+# lȍ~:
+# Ol[̃IvV, ̔IvV̎w܂.
+# --version , --geometry 300x400 , -d host:0.0 ł.
+# 𔺂w ":" KtĂ.
+#
+# IvV̎w肪ꍇ, ϐ $OPT_?? non-nil , ̃I
+# vV̈Zbg܂.
+# -f -> $OPT_f = %TRUE
+# --geometry 300x400 -> $OPT_geometry = 300x400
+#
+# usage gꍇ, $USAGE usage() w肵܂.
+# def usage()
+# c
+# end
+# $USAGE = 'usage'
+# usage , --help w肳ꂽ, Ԉwɕ\܂.
+#
+# - -- , ȍ~, SăIvV̉͂܂.
+#
+
+$RCS_ID="$Header: /var/ohba/RCS/parseargs.rb,v 1.3 1994/02/15 05:16:21 ohba Exp ohba $"
+
+load("getopts.rb")
+
+def printUsageAndExit()
+ if $USAGE
+ apply($USAGE)
+ end
+ exit()
+end
+
+def parseArgs(argc, nopt, single_opts, *opts)
+ if ((noOptions = getopts(single_opts, *opts)) == nil)
+ printUsageAndExit()
+ end
+ if (nopt && noOptions == 0)
+ printUsageAndExit()
+ end
+ if ($ARGV.length < argc)
+ printUsageAndExit()
+ end
+ return noOptions
+end
diff --git a/sample/perror.rb b/sample/perror.rb
new file mode 100644
index 0000000000..9196525ee3
--- /dev/null
+++ b/sample/perror.rb
@@ -0,0 +1,7 @@
+if File._s("io.rb")
+ print(File._z("io.rb", "io.rb\n")
+# print(File._s("io.rb"), ": io.rb\n")
+end
+
+for i in 1..5
+end
diff --git a/sample/rcs.awk b/sample/rcs.awk
new file mode 100644
index 0000000000..08979285c9
--- /dev/null
+++ b/sample/rcs.awk
@@ -0,0 +1,33 @@
+BEGIN {
+ sw = 40.0;
+ dw = 78.0;
+ hdw = dw / 2.0;
+ w = 20.0;
+ h =1.0;
+ d = 0.2;
+ ss="abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()-=\\[];'`,./";
+ rnd = srand();
+}
+
+{
+ 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);
+ c = (0 < i && i < length($0)) ? substr($0, i, 1) : "0";
+ y = h - d * c;
+ xl = xr - w * y / (1 + y);
+ if (xl < -hdw || xl >= 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
new file mode 100644
index 0000000000..61c88bff89
--- /dev/null
+++ b/sample/rcs.dat
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 0000000000..b14742981d
--- /dev/null
+++ b/sample/rcs.rb
@@ -0,0 +1,42 @@
+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)
+ c = if (0 < i < $_.length); $_[i, 1].to_i else 0 end
+ y = h - d * c
+ xl = xr - w * y / (1 + y);
+ if xl < -hdw || xl >= hdw || xl <= maxxl
+ t = rand(ss.length)
+ c = ss[t, 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
new file mode 100644
index 0000000000..25b340887d
--- /dev/null
+++ b/sample/reach.rb
@@ -0,0 +1,5 @@
+for i in 1..10
+ print("test\n")
+ break
+ print("test2\n")
+end
diff --git a/sample/resp.rb b/sample/resp.rb
new file mode 100644
index 0000000000..84516b4c78
--- /dev/null
+++ b/sample/resp.rb
@@ -0,0 +1,2 @@
+undef kill
+print(responds_to("kill"), "\n")
diff --git a/sample/samp.rb b/sample/samp.rb
new file mode 100644
index 0000000000..b4d818faba
--- /dev/null
+++ b/sample/samp.rb
@@ -0,0 +1,12 @@
+P = 0
+while gets()
+ printf("%3d: %s", $., $_)
+ while sub(/\w+/, '')
+ if $& != "";
+ P += 1
+ end
+ end
+ if ($. >= 10); break; end
+end
+printf("line: %d\n", $.)
+printf("word: %d\n", P)
diff --git a/sample/split.rb b/sample/split.rb
new file mode 100644
index 0000000000..737173635e
--- /dev/null
+++ b/sample/split.rb
@@ -0,0 +1,12 @@
+print("1 byte string", "\n")
+print("1 byte string".reverse, "\n")
+
+print("ʸ", "\n")
+print("ʸ".reverse, "\n")
+
+print("1 byte string", "\n")
+print("1 byte string".split(//).reverse.join(":"), "\n")
+print("ʸ", "\n")
+print("ʸ".split(//).reverse.join(":"), "\n")
+print("Ѥ1byteκ", "\n")
+print("Ѥ1byteκ".split(//).reverse.join(":"), "\n")
diff --git a/sample/struct.rb b/sample/struct.rb
new file mode 100644
index 0000000000..7c0690b627
--- /dev/null
+++ b/sample/struct.rb
@@ -0,0 +1,4 @@
+foo = Struct.new("test", "a1"::1, "a2"::2)
+print(foo, "\n")
+bar = foo.clone
+print(bar.a1, "\n")
diff --git a/sample/svr.rb b/sample/svr.rb
new file mode 100644
index 0000000000..c00a03c8cf
--- /dev/null
+++ b/sample/svr.rb
@@ -0,0 +1,23 @@
+gs = TCPserver.open(0)
+printf("server port is on %d\n", gs.port)
+socks = [gs]
+
+while %TRUE
+ nsock = select(socks);
+ if nsock == nil; continue end
+ for s in nsock[0]
+ if s == gs
+ socks.push(s.accept)
+ else
+ if s.eof
+ print(s, " is gone\n")
+ s.close
+ socks.delete(s)
+ else
+ if str = s.gets;
+ s.write(str)
+ end
+ end
+ end
+ end
+end
diff --git a/sample/system.rb b/sample/system.rb
new file mode 100644
index 0000000000..c51626d2dc
--- /dev/null
+++ b/sample/system.rb
@@ -0,0 +1 @@
+print(system2("echo foobar"))
diff --git a/sample/t1.rb b/sample/t1.rb
new file mode 100644
index 0000000000..98d3b529e9
--- /dev/null
+++ b/sample/t1.rb
@@ -0,0 +1,20 @@
+def test(a1, *a2)
+ while 1
+ switch gets()
+ case nil
+ break
+ case /^-$/
+ print("-\n")
+ return
+ case /^-help/
+ print("-help\n")
+ break
+ end
+ end
+ print(a1, a2, "\n")
+end
+
+print($ARGV, "\n")
+print("in: ")
+test(1)
+print("end\n")
diff --git a/sample/t2.rb b/sample/t2.rb
new file mode 100644
index 0000000000..7f5b9df480
--- /dev/null
+++ b/sample/t2.rb
@@ -0,0 +1,24 @@
+#print("in Print\n")
+def t2() end
+
+def println(*args)
+ for a in args
+ t2()
+ print(a)
+ end
+ print("\n")
+end def
+
+def tt
+ for i in 1..10
+ println("i:", i);
+ yield(i);
+ end
+end
+
+test =
+do tt() using i
+ if i == 3; break end
+ println("ttt: ", i);
+end
+#exit()
diff --git a/sample/test.rb b/sample/test.rb
new file mode 100644
index 0000000000..9c422cc94a
--- /dev/null
+++ b/sample/test.rb
@@ -0,0 +1,5 @@
+index = 1
+for argument in $ARGV
+ printf("%d:%s\n", index, argument)
+ index = index + 1
+end
diff --git a/sample/trap.pl b/sample/trap.pl
new file mode 100644
index 0000000000..ce022d4062
--- /dev/null
+++ b/sample/trap.pl
@@ -0,0 +1,6 @@
+$SIG{'INT'} = 'test';
+
+while (<>) {
+ print;
+}
+sub test { print "C-c handled\n"; }
diff --git a/sample/trap.rb b/sample/trap.rb
new file mode 100644
index 0000000000..e552a0fddc
--- /dev/null
+++ b/sample/trap.rb
@@ -0,0 +1,3 @@
+trap('print("C-c handled\n")', 'INT', 'HUP')
+print("---\n")
+while gets(); print($_) end
diff --git a/sample/tt.rb b/sample/tt.rb
new file mode 100644
index 0000000000..cb863e3527
--- /dev/null
+++ b/sample/tt.rb
@@ -0,0 +1,103 @@
+module Print
+ print("in Print\n")
+ def println(*args)
+ for a in args
+ print(a)
+ end
+ print("\n")
+ end def
+
+ def println2(*args)
+ print(*args)
+ print("\n")
+ end def
+end module
+
+module Print2
+ def println(*args)
+ print("pr2: ");
+ super
+ end
+end
+
+module Print3
+ include Print2
+ def println(*args)
+ print("pr3: ");
+ super
+ end
+end
+
+include Print, Print2, Print3
+
+println2("in TopLevel")
+
+print("a: ", $OPT_test, "\n")
+printf("%10.5g: %*s -> 0x%x\n", 123345, -10, Print, Print.id);
+
+println("a+ matches aaa at ", "bccAAaaa" =~ /a+/)
+ttt = "this is a "
+if offset = (ttt =~ /this ([^ ]*) (.*)/)
+ println("0 = ", $&);
+ println("1 = ", $1);
+ println("2 = ", $2);
+end
+
+class Fib:Object
+ print("in Fib:Object\n")
+
+ def Fib.test(*args)
+ println("in Fib.test")
+
+ if args; println(*args) end
+ args = args.grep(/^c/)
+ super(*args)
+ end def
+
+ def init
+ println("in Fib.init");
+ end def
+
+ def fib(n)
+ a =0; b = 1
+
+ while b <= n
+ c = a; a = b; b = c+b
+ end while
+ return b
+ end def
+end
+
+def Object.test(*args)
+ println("in Object.test")
+ if args; println(*args) end
+end
+
+Fib.test("abc", "def", "aaa", "ccc")
+println("1:", 0x3fffffffa)
+println("2:", 0x3ffffffa)
+#println("3:", 0x40000000+0x40000000)
+
+fib = Fib.new
+
+fib.init
+print(Fib, ":")
+
+#for i in 1 .. 100
+# fib.fib(90000)
+#end
+
+println(fib.fib(9000))
+
+def tt
+ for i in 1..10
+ println("i:", i);
+ yield(i);
+ end
+end
+
+test = do tt() using i
+ if i == 2; break end
+end
+
+println([1,2,3,4].join(":"))