summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1995-02-24 13:15:43 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:31 +0900
commit881c5a9c320c637ee0f6526b40cf70c1379ab656 (patch)
tree3c0327fc9bdef8f056563ceee400226ac572535b /sample
parent2f106ab85c4f4e171374aee261f5a12bdd923c41 (diff)
version 0.68v0_68
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.67-0.68.diff.gz Fri Feb 24 13:15:43 1995 Yukihiro Matsumoto (matz@ix-02) * version 0.68 Thu Feb 23 11:19:19 1995 Yukihiro Matsumoto (matz@ix-02) * eval.c: resque節のselfの値が間違っていた. * eval.c(rb_clear_cache): キャッシュのクリアし忘れがあった. * eval.c: 定数のスコープをクラス内の静的スコープに変更した.これに よって,特異メソッドからは参照される定数は,レシーバのクラスでは なく,定義されたスコープのクラスの定数となる. Wed Feb 22 00:51:38 1995 Yukihiro Matsumoto (matz@dyna) * regex.c: ignorecaseを正規表現のコンパイル前に指定しないと正しく 動作しない.修正. * string.c(toupper,tolower): bug fix. * ENV,VERSION: readonly変数から定数へ.
Diffstat (limited to 'sample')
-rw-r--r--sample/MANIFEST1
-rw-r--r--sample/biorhythm.rb24
-rw-r--r--sample/cbreak.rb4
-rw-r--r--sample/clnt.rb2
-rw-r--r--sample/from.rb100
-rw-r--r--sample/io.rb2
-rw-r--r--sample/ruby-mode.el6
-rw-r--r--sample/svr.rb8
-rwxr-xr-xsample/time.rb2
-rw-r--r--sample/trojan.rb2
10 files changed, 128 insertions, 23 deletions
diff --git a/sample/MANIFEST b/sample/MANIFEST
index c91c078..93c971b 100644
--- a/sample/MANIFEST
+++ b/sample/MANIFEST
@@ -20,6 +20,7 @@ fib.pl
fib.rb
fib.scm
freq.rb
+from.rb
fullpath.pl
fullpath.rb
gctest.rb
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
index eb14ca7..5a452e0 100644
--- a/sample/biorhythm.rb
+++ b/sample/biorhythm.rb
@@ -76,9 +76,9 @@ end
#
parseArgs(0, nil, "vg", "D:", "sdate", "date:", "birthday:", "days:")
-printf($stderr, "\n")
-printf($stderr, "Biorhythm (c) 1987-1994 V3.0\n")
-printf($stderr, "\n")
+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
@@ -94,11 +94,11 @@ else
if ($OPT_birthday)
dtmp = $OPT_birthday
else
- printf($stderr, "Birthday (YYYYMMDD) : ")
- dtmp = $stdin.gets.chop
+ printf(STDERR, "Birthday (YYYYMMDD) : ")
+ dtmp = STDIN.gets.chop
end
if (dtmp.length != 8)
- printf($stderr, "BAD Input Birthday!!\n")
+ printf(STDERR, "BAD Input Birthday!!\n")
exit()
end
jg = dtmp[0,4].to_i
@@ -112,8 +112,8 @@ else
elsif ($OPT_date)
dtmp = $OPT_date
else
- printf($stderr, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
- dtmp = $stdin.gets.chop
+ printf(STDERR, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
+ dtmp = STDIN.gets.chop
end
if (dtmp.length != 8)
dtmp = Time.now.strftime("%Y%m%d")
@@ -127,8 +127,8 @@ else
elsif ($OPT_g)
ausgabeart = "g"
else
- printf($stderr, "Values for today or Graph (v/g) [default g] : ")
- ausgabeart = $stdin.gets.chop
+ printf(STDERR, "Values for today or Graph (v/g) [default g] : ")
+ ausgabeart = STDIN.gets.chop
end
end
if (ausgabeart == "v")
@@ -151,8 +151,8 @@ else
if ($OPT_D)
ktage = 9
else
- printf($stderr, "Graph for how many days [default 10] : ")
- ktage = $stdin.gets.chop
+ printf(STDERR, "Graph for how many days [default 10] : ")
+ ktage = STDIN.gets.chop
if (ktage == "")
ktage = 9
else
diff --git a/sample/cbreak.rb b/sample/cbreak.rb
index 5d2d849..cbb15d2 100644
--- a/sample/cbreak.rb
+++ b/sample/cbreak.rb
@@ -15,7 +15,7 @@ end
def set_cbreak (on)
tty = "\0" * 256
- $stdin.ioctl(TIOCGETP, tty)
+ STDIN.ioctl(TIOCGETP, tty)
ttys = tty.unpack("C4 S")
if on
ttys[4] |= CBREAK
@@ -25,7 +25,7 @@ def set_cbreak (on)
ttys[4] |= ECHO
end
tty = ttys.pack("C4 S")
- $stdin.ioctl(TIOCSETP, tty)
+ STDIN.ioctl(TIOCSETP, tty)
end
cbreak();
diff --git a/sample/clnt.rb b/sample/clnt.rb
index a687d12..d2c71ec 100644
--- a/sample/clnt.rb
+++ b/sample/clnt.rb
@@ -2,7 +2,7 @@
# usage: ruby clnt.rb [host] port
host=(if $ARGV.length == 2; $ARGV.shift; else "localhost"; end)
print("Trying ", host, " ...")
-$stdout.flush
+STDOUT.flush
s = TCPsocket.open(host, $ARGV.shift)
print(" done\n")
print("addr: ", s.addr.join(":"), "\n")
diff --git a/sample/from.rb b/sample/from.rb
new file mode 100644
index 0000000..f660294
--- /dev/null
+++ b/sample/from.rb
@@ -0,0 +1,100 @@
+#! /usr/local/bin/ruby
+
+$= = TRUE
+
+module ParseDate
+ MONTHS = {
+ 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4,
+ 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8,
+ 'sep' => 9, 'oct' =>10, 'nov' =>11, 'dec' =>12 }
+ MONTHPAT = MONTHS.keys.join('|')
+ DAYPAT = 'mon|tue|wed|thu|fri|sat|sun'
+
+ def ParseDate.parsedate(date)
+ if date.sub(/(#{DAYPAT})/i, ' ')
+ dayofweek = $1
+ end
+ if date.sub(/\s+(\d+:\d+(:\d+)?)/, ' ')
+ time = $1
+ end
+ if date =~ /19\d\d/
+ year = $&
+ end
+ if date.sub(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/, ' ')
+ dayofmonth = $1
+ monthname = $2
+ elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/, ' ')
+ monthname = $1
+ dayofmonth = $2
+ elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/, ' ')
+ monthname = $1
+ dayofmonth = $2
+ elsif date.sub(/\s*(\d\d?)\/(\d\d?)/, ' ')
+ month = $1
+ dayofmonth = $2
+ end
+ if monthname
+ month = MONTHS[monthname.tolower]
+ end
+ if ! year && date =~ /\d\d/
+ year = $&
+ end
+ return year, month, dayofmonth
+ end
+
+end
+
+ def parsedate(date)
+ ParseDate.parsedate(date)
+ end
+
+# include ParseDate
+
+if $ARGV[0] == '-w'
+ wait = TRUE
+ $ARGV.shift
+end
+
+$ARGV[0] = '/usr/spool/mail/' + ENV['USER'] if $ARGV.length == 0
+
+$outcount = 0;
+def fromout(date, from, subj)
+ y, m, d = parsedate(date)
+ printf "%-2d/%02d/%02d [%.28s] %.40s\n", y, m, d, from, subj
+ $outcount += 1
+end
+
+while TRUE
+ fields = {}
+ while gets()
+ $_.chop
+ continue if /^From / # skip From-line
+ break if /^[ \t]*$/ # end of header
+ if /^(\S+):\s*(.*)/
+ fields[attr = $1] = $2
+ elsif attr
+ sub(/^\s*/, '')
+ fields[attr] += "\n" + $_
+ end
+ end
+
+ break if ! $_
+
+ fromout fields['Date'], fields['From'], fields['Subject']
+
+ while gets()
+# print $_
+ break if /^From /
+ end
+
+ break if ! $_
+end
+
+if $outcount == 0
+ print "You have no mail.\n"
+ sleep 2 if wait
+elsif wait
+ system "stty cbreak -echo"
+ getc()
+ system "stty cooked echo"
+end
diff --git a/sample/io.rb b/sample/io.rb
index c3c1a47..c12e4f4 100644
--- a/sample/io.rb
+++ b/sample/io.rb
@@ -1,7 +1,7 @@
# IO test
# usage: ruby io.rb file..
-home = getenv("HOME")
+home = ENV["HOME"]
home.sub("m", "&&")
print(home, "\n")
print(home.reverse, "\n")
diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el
index 20e1abe..aa91be3 100644
--- a/sample/ruby-mode.el
+++ b/sample/ruby-mode.el
@@ -321,12 +321,12 @@ An end of a defun is found by moving forward from the beginning of one."
(defun ruby-reindent-then-newline-and-indent ()
(interactive "*")
- (save-excursion
- (delete-region (point) (progn (skip-chars-backward " \t") (point))))
(insert ?\n)
(save-excursion
(forward-line -1)
- (indent-according-to-mode))
+ (indent-according-to-mode)
+ (end-of-line)
+ (delete-region (point) (progn (skip-chars-backward " \t") (point))))
(indent-according-to-mode))
(defun ruby-encomment-region (beg end)
diff --git a/sample/svr.rb b/sample/svr.rb
index 91faa56..23b2bf7 100644
--- a/sample/svr.rb
+++ b/sample/svr.rb
@@ -2,7 +2,9 @@
# usage: ruby svr.rb
gs = TCPserver.open(0)
-printf("server port is on %d\n", gs.port)
+addr = gs.addr
+addr.shift
+printf("server is on %d\n", addr.join(":"))
socks = [gs]
while TRUE
@@ -10,7 +12,9 @@ while TRUE
if nsock == nil; continue end
for s in nsock[0]
if s == gs
- socks.push(s.accept)
+ ns = s.accept
+ socks.push(ns)
+ print(s, " is accepted\n")
else
if s.eof
print(s, " is gone\n")
diff --git a/sample/time.rb b/sample/time.rb
index b0ef065..715d98a 100755
--- a/sample/time.rb
+++ b/sample/time.rb
@@ -5,4 +5,4 @@ system(cmd)
e = Time.now
ut, st, cut, cst = Time.times
total = (e - b).to_f
-printf $stderr, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
+printf STDERR, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
diff --git a/sample/trojan.rb b/sample/trojan.rb
index b42fd16..2024da0 100644
--- a/sample/trojan.rb
+++ b/sample/trojan.rb
@@ -1,5 +1,5 @@
#! /usr/local/bin/ruby
-path = $ENV['PATH'].split(/:/)
+path = ENV['PATH'].split(/:/)
for dir in path
if File.d(dir)