summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
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 0000000..fbf7989
--- /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 0000000..cfec649
--- /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 0000000..2db79f1
--- /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 0000000..3261c43
--- /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 0000000..8988733
--- /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 0000000..f456f02
--- /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 0000000..93f0289
--- /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 0000000..4b4cb1d
--- /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 0000000..639e2a0
--- /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 0000000..6a752e8
--- /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 0000000..d7629fe
--- /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 0000000..1f2886e
--- /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 0000000..f4c3d17
--- /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 0000000..c261b53
--- /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 0000000..7ebe893
--- /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 0000000..c559376
--- /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 0000000..c72f91f
--- /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 0000000..7417e0b
--- /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 0000000..a07b90e
--- /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 0000000..b1d4b9c
--- /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 0000000..6067393
--- /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 0000000..57a7db4
--- /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.
+# wIvVw nil .
+# I, ZbgIvV.
+#
+# 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) lIvVw.
+# nil wKv.
+# ~:
+# Ol[IvV, IvVw.
+# --version , --geometry 300x400 , -d host:0.0 .
+# w ":" Kt.
+#
+# IvVw, $OPT_?? non-nil , I
+# vVZbg.
+# -f -> $OPT_f = %TRUE
+# --geometry 300x400 -> $OPT_geometry = 300x400
+#
+# - -- , ~, SIvV.
+#
+
+$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 0000000..16f1bb0
--- /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 0000000..126b17d
--- /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 0000000..45d50d6
--- /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 0000000..e818e7a
--- /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 0000000..e0b5b38
--- /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 0000000..c2e9bca
--- /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 0000000..83be1b9
--- /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 0000000..c0f705e
--- /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 0000000..bbf03ae
--- /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 0000000..1f5fcf2
--- /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 0000000..12e469d
--- /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 0000000..6e05137
--- /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 0000000..4981119
--- /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 0000000..4fc9a25
--- /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 0000000..e7e2b7a
--- /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, ZbgIvV.
+#
+# 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:")
+#
+# :
+# IvVO
+# :
+# IvVKvcKKv %TRUE %FALSE.
+# O:
+# -f -x (= -fx) lIvVw.
+# nil wKv.
+# l~:
+# Ol[IvV, IvVw.
+# --version , --geometry 300x400 , -d host:0.0 .
+# w ":" Kt.
+#
+# IvVw, $OPT_?? non-nil , I
+# vVZbg.
+# -f -> $OPT_f = %TRUE
+# --geometry 300x400 -> $OPT_geometry = 300x400
+#
+# usage g, $USAGE usage() w.
+# def usage()
+# c
+# end
+# $USAGE = 'usage'
+# usage , --help w, w\ヲ.
+#
+# - -- , ~, SIvV.
+#
+
+$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 0000000..9196525
--- /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 0000000..0897928
--- /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 0000000..61c88bf
--- /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 0000000..b147429
--- /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 0000000..25b3408
--- /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 0000000..84516b4
--- /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 0000000..b4d818f
--- /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 0000000..73717363
--- /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 0000000..7c0690b
--- /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 0000000..c00a03c
--- /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 0000000..c51626d
--- /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 0000000..98d3b52
--- /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 0000000..7f5b9df
--- /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 0000000..9c422cc
--- /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 0000000..ce022d4
--- /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 0000000..e552a0f
--- /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 0000000..cb863e3
--- /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(":"))