summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sample')
-rw-r--r--sample/biorhythm.rb227
-rw-r--r--sample/dbmtest.rb (renamed from sample/dbm.rb)0
-rw-r--r--sample/dir.rb2
-rw-r--r--sample/eval.rb7
-rw-r--r--sample/freq.rb4
-rwxr-xr-xsample/from.rb93
-rw-r--r--sample/mrshtest.rb (renamed from sample/marshal.rb)11
-rw-r--r--sample/philos.rb2
-rw-r--r--sample/regx.rb2
-rw-r--r--sample/ruby-mode.el225
-rw-r--r--sample/rubydb2x.el104
-rw-r--r--sample/rubydb3x.el104
-rw-r--r--sample/svr.rb2
-rw-r--r--sample/test.rb115
-rw-r--r--sample/tkbiff.rb2
-rw-r--r--sample/tkfrom.rb18
16 files changed, 617 insertions, 301 deletions
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
index 5a452e0078..b97ee85e16 100644
--- a/sample/biorhythm.rb
+++ b/sample/biorhythm.rb
@@ -1,74 +1,45 @@
-#!/mp/free/bin/ruby
+#!/usr/local/bin/ruby
#
-# biorhythm.rb -
-# $Release Version: $
-# $Revision: 1.6 $
-# $Date: 1994/02/24 10:23:34 $
-# by Yasuo OHBA(STAFS Development Room)
+# biorhythm.rb -
+# $Release Version: $
+# $Revision: 1.3 $
+# $Date: 1997/02/14 11:07:08 $
+# 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]
+require "date.rb"
+require "parsearg.rb"
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")
+ print "Usage:\n"
+ print "biorhythm.rb [options]\n"
+ print " options...\n"
+ print " -D YYYYMMDD(birthday) : すべて default 値を使う. \n"
+ print " --sdate | --date YYYYMMDD : system date もしくは指定した日付を使う.\n"
+ print " --birthday YYYYMMDD : 誕生日の指定をする. \n"
+ print " -v | -g : Values or Graph の指定. \n"
+ print " --days DAYS : 期間の指定をする(Graph の時のみ有効). \n"
+ print " --help : help\n"
end
$USAGE = 'usage'
-def leapyear(y)
- ta = 0
- if ((y % 4.0) == 0); ta = 1; end
- if ((y % 100.0) == 0); ta = 0; end
- if ((y % 400.0) == 0); ta = 1; end
- return ta
-end
-
-def bcalc(tt, m, j)
- ta = 0
- if (m <= 2)
- ta = (m - 1) * 31
- else
- ta = leapyear(j)
- ta = ta + ((306 * m - 324) / 10.0).to_i
- end
- ta = ta + (j - 1) * 365 + ((j - 1) / 4.0).to_i
- ta = ta - ((j - 1) / 100) + ((j - 1) / 400.0).to_i
- ta = ta + tt
- return ta
-end
-
-def printHeader(tg, mg, jg, gtag, tage)
- print("\n")
- print(" Biorhythm\n")
- print(" =========\n")
- print("\n")
- printf("The birthday %04d.%02d.%02d is a %s\n", jg, mg, tg, $wochentag[gtag])
- printf("Age in days: [%d]\n", tage)
+def printHeader(y, m, d, p, w)
+ print "\n>>> Biorhythm <<<\n"
+ printf "The birthday %04d.%02d.%02d is a %s\n", y, m, d, w
+ printf "Age in days: [%d]\n\n", p
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
+ 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
+ return phys, emot, geist
end
#
@@ -76,55 +47,41 @@ 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")
-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
+if $OPT_D
+ dd = Date.new(Time.now.strftime("%Y%m%d"))
+ bd = Date.new($OPT_D)
ausgabeart = "g"
else
- if ($OPT_birthday)
- dtmp = $OPT_birthday
+ if $OPT_birthday
+ bd = Date.new($OPT_birthday)
else
- printf(STDERR, "Birthday (YYYYMMDD) : ")
- dtmp = STDIN.gets.chop
+ printf(STDERR, "Birthday (YYYYMMDD) : ")
+ if (si = STDIN.gets.chop) != ""
+ bd = Date.new(si)
+ end
end
- if (dtmp.length != 8)
- printf(STDERR, "BAD Input Birthday!!\n")
+ if !bd
+ 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
+ if $OPT_sdate
+ dd = Date.new(Time.now.strftime("%Y%m%d"))
+ elsif $OPT_date
+ dd = Date.new($OPT_date)
else
- printf(STDERR, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
- dtmp = STDIN.gets.chop
+ printf(STDERR, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
+ if (si = STDIN.gets.chop) != ""
+ dd = Date.new(si)
+ end
end
- if (dtmp.length != 8)
- dtmp = Time.now.strftime("%Y%m%d")
+ if !dd
+ dd = Date.new(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)
+
+ if $OPT_v
ausgabeart = "v"
- elsif ($OPT_g)
+ elsif $OPT_g
ausgabeart = "g"
else
printf(STDERR, "Values for today or Graph (v/g) [default g] : ")
@@ -132,70 +89,50 @@ else
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")
+ printHeader(bd.year, bd.month, bd.day, dd.period - bd.period, bd.name_of_week)
+ 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")
+ phys, emot, geist = getPosition(dd.period - bd.period)
+ printf "Biorhythm: %04d.%02d.%02d\n", dd.year, dd.month, dd.day
+ 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
+ if $OPT_days
+ display_period = $OPT_days.to_i
+ elsif $OPT_D
+ display_period = 9
else
- if ($OPT_D)
- ktage = 9
+ printf(STDERR, "Graph for how many days [default 10] : ")
+ display_period = STDIN.gets.chop
+ if (display_period == "")
+ display_period = 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
+ display_period = display_period.to_i - 1
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")
+
+ printHeader(bd.year, bd.month, bd.day, dd.period - bd.period, bd.name_of_week)
+ 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)
+ for z in (dd.period - bd.period)..(dd.period - bd.period + display_period)
+ phys, emot, geist = 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
+ printf "%04d.%02d.%02d : ", dd.year, dd.month, dd.day
+ 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
+ print graph, "\n"
+ dd = dd + 1
end
- print(" -------------------------+-------------------------\n\n")
+ print " -------------------------+-------------------------\n\n"
end
diff --git a/sample/dbm.rb b/sample/dbmtest.rb
index c77cc2065b..c77cc2065b 100644
--- a/sample/dbm.rb
+++ b/sample/dbmtest.rb
diff --git a/sample/dir.rb b/sample/dir.rb
index 1fc0bb2aa8..2465c4d68e 100644
--- a/sample/dir.rb
+++ b/sample/dir.rb
@@ -3,7 +3,7 @@
dirp = Dir.open(".")
for f in dirp
$_ = f
- if (~/^\./ || ~/~$/ || ~/\.o/)
+ unless (~/^\./ || ~/~$/ || ~/\.o/)
print f, "\n"
end
end
diff --git a/sample/eval.rb b/sample/eval.rb
index da31b77153..216bf8ca39 100644
--- a/sample/eval.rb
+++ b/sample/eval.rb
@@ -1,9 +1,10 @@
line = ''
indent=0
+$stdout.sync = TRUE
print "ruby> "
while TRUE
l = gets
- if not l
+ unless l
break if line == ''
else
line = line + l
@@ -17,7 +18,7 @@ while TRUE
if l =~ /^\s*end\b[^_]/
indent -= 1
end
- if l =~ /{\s*(\|.*\|)?\s*$/
+ if l =~ /\{\s*(\|.*\|)?\s*$/
indent += 1
end
if l =~ /^\s*\}/
@@ -31,7 +32,7 @@ while TRUE
begin
print eval(line).inspect, "\n"
rescue
- $! = 'exception raised' if not $!
+ $! = 'exception raised' unless $!
print "ERR: ", $!, "\n"
end
break if not l
diff --git a/sample/freq.rb b/sample/freq.rb
index 0c433ae25a..d951591735 100644
--- a/sample/freq.rb
+++ b/sample/freq.rb
@@ -1,8 +1,8 @@
# word occurrence listing
# usege: ruby freq.rb file..
freq = {}
-while gets()
- while sub(/\w+/, '')
+while gets
+ while sub!(/\w+/, '')
word = $&
freq[word] +=1
end
diff --git a/sample/from.rb b/sample/from.rb
index 2ef000face..d39bb70084 100755
--- a/sample/from.rb
+++ b/sample/from.rb
@@ -1,81 +1,76 @@
#! /usr/local/bin/ruby
require "parsedate"
-require "base64"
+require "kconv"
+require "mailread"
include ParseDate
+include Kconv
-if ARGV[0] == '-w'
- wait = TRUE
- ARGV.shift
-end
+class String
-class Mail
+ public :kconv
- def Mail.new(f)
- if !f.kind_of?(IO)
- f = open(f, "r")
- me = super
- f.close
- else
- me = super
- end
- return me
+ def kconv(code = Kconv::EUC)
+ Kconv.kconv(self, code, Kconv::AUTO)
end
- def initialize(f)
- @header = {}
- @body = []
- while f.gets()
- $_.chop!
- next if /^From / # skip From-line
- break if /^$/ # end of header
- if /^(\S+):\s*(.*)/
- @header[attr = $1.capitalize] = $2
- elsif attr
- sub(/^\s*/, '')
- @header[attr] += "\n" + $_
- end
- end
-
- return if ! $_
-
- while f.gets()
- break if /^From /
- @body.push($_)
+ def kjust(len)
+ len += 1
+ me = self[0, len].ljust(len)
+ if me =~ /.$/ and $&.size == 2
+ me[-2, 2] = ' '
end
+ me.chop!
end
- def header
- return @header
- end
+end
- def body
- return @body
- end
+if ARGV[0] == '-w'
+ wait = TRUE
+ ARGV.shift
+end
+if ARGV.length == 0
+ user = ENV['USER']
+else
+ user = ARGV[0]
end
-ARGV[0] = '/usr/spool/mail/' + ENV['USER'] if ARGV.length == 0
+[ENV['SPOOLDIR'], '/usr/spool', '/var/spool', '/usr', '/var'].each do |m|
+ break if File.exist? ARGV[0] = "#{m}/mail/#{user}"
+end
$outcount = 0;
def fromout(date, from, subj)
return if !date
y = m = d = 0
- esc = "\033\(B"
y, m, d = parsedate(date) if date
- from = "sombody@somewhere" if ! from
- subj = "(nil)" if ! subj
- from = decode_b(from)
- subj = decode_b(subj)
- printf "%-02d/%02d/%02d [%-28.28s%s] %-40.40s%s\n",y,m,d,from,esc,subj,esc
+ if from
+ from.gsub! /\n/, ""
+ else
+ from = "sombody@somewhere"
+ end
+ if subj
+ subj.gsub! /\n/, ""
+ else
+ subj = "(nil)"
+ end
+ if ENV['LANG'] =~ /sjis/i
+ lang = Kconv::SJIS
+ else
+ lang = Kconv::EUC
+ end
+ from = from.kconv(lang).kjust(28)
+ subj = subj.kconv(lang).kjust(40)
+ printf "%02d/%02d/%02d [%s] %s\n",y,m,d,from,subj
$outcount += 1
end
for file in ARGV
next if !File.exist?(file)
f = open(file, "r")
- while !f.eof
+ while !f.eof?
mail = Mail.new(f)
fromout mail.header['Date'], mail.header['From'], mail.header['Subject']
end
diff --git a/sample/marshal.rb b/sample/mrshtest.rb
index 3d399ffe68..402b35ad55 100644
--- a/sample/marshal.rb
+++ b/sample/mrshtest.rb
@@ -1,13 +1,14 @@
require "marshal"
include Marshal
a = 25.6;
-pt = Struct.new('point', :x,:y);
+pt = Struct.new('Point', :x,:y);
x = pt.new(10, 10)
y = pt.new(20, 20)
-rt = Struct.new('rectangle', :origin,:corner);
+rt = Struct.new('Rectangle', :origin,:corner);
z = rt.new(x, y)
c = Object.new
s = [a, x, z, c, c, "fff"];
-print s.inspect;
-d = dumps(s);
-print load(d).inspect
+p s
+d = dump(s);
+p d
+p load(d)
diff --git a/sample/philos.rb b/sample/philos.rb
index ee0a8cd5fc..3ccb052532 100644
--- a/sample/philos.rb
+++ b/sample/philos.rb
@@ -30,7 +30,7 @@ def philosopher(n)
$forks[n].lock
if not $forks[(n+1)%N].try_lock
$forks[n].unlock # avoid deadlock
- continue
+ next
end
$state[n*2] = ?|;
$state[(n+1)%N*2] = ?|;
diff --git a/sample/regx.rb b/sample/regx.rb
index b9d8ca6e14..aaf4b5f1ee 100644
--- a/sample/regx.rb
+++ b/sample/regx.rb
@@ -17,7 +17,7 @@ while TRUE
re = gets
break if not re
re.chop!
- str.gsub! re, "#{st}&#{en}"
+ str.gsub! re, "#{st}\\&#{en}"
print str, "\n"
end
print "\n"
diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el
index 9dfde8588c..678a43ba77 100644
--- a/sample/ruby-mode.el
+++ b/sample/ruby-mode.el
@@ -1,13 +1,12 @@
;;;
;;; ruby-mode.el -
;;;
-;;; $Author$
-;;; $Revision$
-;;; $Date$
+;;; $Author: matz$
+;;; Time-stamp: <97/03/21 01:16:05 matz>
;;; created at: Fri Feb 4 14:49:13 JST 1994
;;;
-(defconst ruby-mode-version "1.0.2")
+(defconst ruby-mode-version "1.0.7")
(defconst ruby-block-beg-re
"class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do"
@@ -25,15 +24,21 @@
"then\\|else\\|elsif\\|when\\|rescue\\|ensure"
)
+(defconst ruby-block-op-re
+ "and\\|or\\|not"
+ )
+
(defconst ruby-block-end-re "end")
(defconst ruby-delimiter
(concat "[?$/%(){}#\"'`]\\|\\[\\|\\]\\|\\<\\("
- ruby-block-beg-re "\\|" ruby-block-end-re "\\)\\>")
+ ruby-block-beg-re
+ "\\|" ruby-block-end-re
+ "\\)\\>\\|^=begin")
)
(defconst ruby-negative
- (concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\|\\("
+ (concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\>\\|\\("
ruby-block-end-re "\\)\\>\\|\\}\\|\\]\\)")
)
@@ -59,8 +64,9 @@
(define-key ruby-mode-map "\e\C-p" 'ruby-beginning-of-block)
(define-key ruby-mode-map "\e\C-n" 'ruby-end-of-block)
(define-key ruby-mode-map "\t" 'ruby-indent-command)
- (define-key ruby-mode-map "\C-m" 'ruby-reindent-then-newline-and-indent)
- (define-key ruby-mode-map "\C-j" 'newline))
+ (define-key ruby-mode-map "\C-c\C-e" 'ruby-insert-end)
+ (define-key ruby-mode-map "\C-j" 'ruby-reindent-then-newline-and-indent)
+ (define-key ruby-mode-map "\C-m" 'newline))
(defvar ruby-mode-syntax-table nil
"Syntax table in use in ruby-mode buffers.")
@@ -70,6 +76,7 @@
(setq ruby-mode-syntax-table (make-syntax-table))
(modify-syntax-entry ?\' "\"" ruby-mode-syntax-table)
(modify-syntax-entry ?\" "\"" ruby-mode-syntax-table)
+ (modify-syntax-entry ?\` "\"" ruby-mode-syntax-table)
(modify-syntax-entry ?# "<" ruby-mode-syntax-table)
(modify-syntax-entry ?\n ">" ruby-mode-syntax-table)
(modify-syntax-entry ?\\ "'" ruby-mode-syntax-table)
@@ -184,7 +191,10 @@ The variable ruby-indent-level controls the amount of indentation.
(forward-word -1)
(or
(looking-at ruby-block-beg-re)
- (looking-at ruby-block-mid-re)))))))
+ (looking-at ruby-block-op-re)
+ (looking-at ruby-block-mid-re))
+ (goto-char (match-end 0))
+ (looking-at "[^_]"))))))
(defun ruby-parse-region (start end)
(let ((indent-point end)
@@ -228,7 +238,7 @@ The variable ruby-indent-level controls the amount of indentation.
((looking-at "%")
(cond
((and (not (eobp)) (ruby-expr-beg)
- (looking-at "%[Qq\"'Rr/Xx`]\\(.\\)"))
+ (looking-at "%[Qqrx]?\\(.\\)"))
(setq w (buffer-substring (match-beginning 1)
(match-end 1)))
(cond
@@ -278,13 +288,16 @@ The variable ruby-indent-level controls the amount of indentation.
(setq depth (1- depth))
(goto-char pnt))
((looking-at ruby-block-end-re)
- (if (and (not (bolp))
- (progn
- (forward-char -1)
- (eq ?_ (char-after (point))))
- (progn
- (goto-char pnt)
- (eq ?_ (char-after (point)))))
+ (if (or (and (not (bolp))
+ (progn
+ (forward-char -1)
+ (eq ?_ (char-after (point)))))
+ (progn
+ (goto-char pnt)
+ (setq w (char-after (point)))
+ (or (eq ?_ w)
+ (eq ?! w)
+ (eq ?? w))))
nil
(setq nest (cdr nest))
(setq depth (1- depth)))
@@ -295,7 +308,7 @@ The variable ruby-indent-level controls the amount of indentation.
(progn
(forward-char -1)
(not (eq ?_ (char-after (point))))))
- (save-excursion
+ (progn
(goto-char pnt)
(setq w (char-after (point)))
(and (not (eq ?_ w))
@@ -312,6 +325,11 @@ The variable ruby-indent-level controls the amount of indentation.
(if (looking-at "def\\s *[/`]")
(goto-char (match-end 0))
(goto-char pnt)))
+ ((looking-at "^=begin")
+ (if (re-search-forward "^=end" indent-point t)
+ (forward-line 1)
+ (setq in-string (match-end 0))
+ (goto-char indent-point)))
(t
(error (format "bad string %s"
(buffer-substring (point) pnt)
@@ -342,7 +360,7 @@ The variable ruby-indent-level controls the amount of indentation.
(let ((column (current-column))
(s (ruby-parse-region (point) indent-point)))
(cond
- ((> (nth 2 s) 0)
+ ((and (nth 2 s) (> (nth 2 s) 0))
(goto-char (cdr (nth 1 s)))
(forward-word -1)
(setq indent (+ (current-column) ruby-indent-level)))
@@ -358,7 +376,7 @@ The variable ruby-indent-level controls the amount of indentation.
(setq indent (+ (current-column) (* (nth 2 state) ruby-indent-level)))))
))
- ((> (nth 2 state) 0) ; in nest
+ ((and (nth 2 state)(> (nth 2 state) 0)) ; in nest
(goto-char (cdr (nth 1 state)))
(forward-word -1) ; skip back a keyword
(cond
@@ -374,7 +392,7 @@ The variable ruby-indent-level controls the amount of indentation.
(t
(setq indent (+ (current-column) ruby-indent-level)))))
- ((< (nth 2 state) 0) ; in negative nest
+ ((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest
(setq indent (+ (current-column) (* (nth 2 state) ruby-indent-level)))))
(cond
@@ -385,7 +403,8 @@ The variable ruby-indent-level controls the amount of indentation.
(beginning-of-line)
(cond
((re-search-forward ruby-negative eol t)
- (setq indent (- indent ruby-indent-level)))
+ (and (not (eq ?_ (char-after (match-end 0))))
+ (setq indent (- indent ruby-indent-level))))
;;operator terminated lines
((and
(save-excursion
@@ -396,33 +415,41 @@ The variable ruby-indent-level controls the amount of indentation.
(save-excursion ;except non-block braces
(goto-char (cdr (nth 1 state)))
(or (bobp) (forward-char -1))
- (not (ruby-expr-beg))))))
- (beginning-of-line)
- (skip-chars-backward " \t\n")
- (beginning-of-line) ; goto beginning of non-empty line
+ (not (ruby-expr-beg))))))
+ ;; goto beginning of non-empty no-comment line
+ (let (end done)
+ (while (not done)
+ (skip-chars-backward " \t\n")
+ (setq end (point))
+ (beginning-of-line)
+ (if (re-search-forward "^\\s *#" end t)
+ (beginning-of-line)
+ (setq done t))))
(setq bol (point))
(end-of-line)
(skip-chars-backward " \t")
(or (bobp) (forward-char -1))
- (and (looking-at ruby-operator-chars)
- (or (not (or (eq ?/ (char-after (point)))))
- (null (nth 0 (ruby-parse-region parse-start (point)))))
- (save-excursion
- (goto-char parse-start))
- (not (eq (char-after (1- (point))) ?$))
- (or (not (eq ?| (char-after (point))))
- (save-excursion
- (or (eolp) (forward-char -1))
- (and (search-backward "|")
- (skip-chars-backward " \t\n")
- (and (not (eolp))
- (progn
- (forward-char -1)
- (not (looking-at "\\{")))
- (progn
- (forward-word -1)
- (not (looking-at "do\\>[^_]")))))))
- (setq indent (+ indent ruby-indent-level)))))))
+ (and
+ (or (and (looking-at ruby-symbol-chars)
+ (skip-chars-backward ruby-symbol-chars)
+ (looking-at ruby-block-op-re))
+ (and (looking-at ruby-operator-chars)
+ (or (not (or (eq ?/ (char-after (point)))))
+ (null (nth 0 (ruby-parse-region parse-start (point)))))
+ (not (eq (char-after (1- (point))) ?$))
+ (or (not (eq ?| (char-after (point))))
+ (save-excursion
+ (or (eolp) (forward-char -1))
+ (and (search-backward "|")
+ (skip-chars-backward " \t\n")
+ (and (not (eolp))
+ (progn
+ (forward-char -1)
+ (not (looking-at "\\{")))
+ (progn
+ (forward-word -1)
+ (not (looking-at "do\\>[^_]")))))))))
+ (setq indent (+ indent ruby-indent-level)))))))
indent)))
(defun ruby-electric-brace (arg)
@@ -450,7 +477,7 @@ Returns t unless search stops due to end of buffer."
"Move forward to next end of defun.
An end of a defun is found by moving forward from the beginning of one."
(interactive "p")
- (and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)\\b")
+ (and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)\\b[^_]")
nil 'move (or arg 1))
(progn (beginning-of-line) t))
(forward-line 1))
@@ -512,21 +539,91 @@ An end of a defun is found by moving forward from the beginning of one."
(save-excursion
(ruby-indent-line)))))
-(if (featurep 'hilit19)
- (hilit-set-mode-patterns
- 'ruby-mode
- '(("[^$\\?]\\(\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"\\)" 1 string)
- ("[^$\\?]\\('[^\\']*\\(\\\\\\(.\\|\n\\)[^\\']*\\)*'\\)" 1 string)
- ("[^$\\?]\\(`[^\\`]*\\(\\\\\\(.\\|\n\\)[^\\`]*\\)*`\\)" 1 string)
- ("^\\s *#.*$" nil comment)
- ("[^$@?\\]\\(#[^$@{].*$\\)" 1 comment)
- ("[^a-zA-Z_]\\(\\?\\(\\\\[CM]-\\)*.\\)" 1 string)
- ("^\\s *\\(require\\|load\\).*$" nil include)
- ("^\\s *\\(include\\|alias\\|undef\\).*$" nil decl)
- ("^\\s *\\<\\(class\\|def\\|module\\)\\>" "[)\n;]" defun)
- ("[^_]\\<\\(begin\\|case\\|else\\|elsif\\|end\\|ensure\\|for\\|if\\|unless\\|rescue\\|then\\|when\\|while\\|until\\|do\\)\\>[^_]" 1 defun)
- ("[^_]\\<\\(and\\|break\\|next\\|raise\\|fail\\|in\\|not\\|or\\|redo\\|retry\\|return\\|super\\|yield\\)\\>[^_]" 1 keyword)
- ("[^_]\\<\\(self\\|nil\\|[A-Z][a-zA-Z_0-9]*\\)\\>[^_]" 1 define)
- ("\\$\\(.\\|\\sw+\\)" nil type)
- ("[$@].[a-zA-Z_0-9]*" nil struct)
- ("^__END__" nil label))))
+(defun ruby-insert-end ()
+ (interactive)
+ (insert "end")
+ (ruby-indent-line t)
+ (end-of-line))
+
+(cond
+ ((featurep 'hilit19)
+ (hilit-set-mode-patterns
+ 'ruby-mode
+ '(("[^$\\?]\\(\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"\\)" 1 string)
+ ("[^$\\?]\\('[^\\']*\\(\\\\\\(.\\|\n\\)[^\\']*\\)*'\\)" 1 string)
+ ("[^$\\?]\\(`[^\\`]*\\(\\\\\\(.\\|\n\\)[^\\`]*\\)*`\\)" 1 string)
+ ("^\\s *#.*$" nil comment)
+ ("[^$@?\\]\\(#[^$@{].*$\\)" 1 comment)
+ ("[^a-zA-Z_]\\(\\?\\(\\\\[CM]-\\)*.\\)" 1 string)
+ ("^\\s *\\(require\\|load\\).*$" nil include)
+ ("^\\s *\\(include\\|alias\\|undef\\).*$" nil decl)
+ ("^\\s *\\<\\(class\\|def\\|module\\)\\>" "[)\n;]" defun)
+ ("[^_]\\<\\(begin\\|case\\|else\\|elsif\\|end\\|ensure\\|for\\|if\\|unless\\|rescue\\|then\\|when\\|while\\|until\\|do\\)\\>[^_]" 1 defun)
+ ("[^_]\\<\\(and\\|break\\|next\\|raise\\|fail\\|in\\|not\\|or\\|redo\\|retry\\|return\\|super\\|yield\\|self\\|nil\\)\\>[^_]" 1 keyword)
+ ("\\$\\(.\\|\\sw+\\)" nil type)
+ ("[$@].[a-zA-Z_0-9]*" nil struct)
+ ("^__END__" nil label))))
+
+ ((featurep 'font-lock)
+ (or (boundp 'font-lock-variable-name-face)
+ (setq font-lock-variable-name-face font-lock-type-face))
+ (defvar ruby-font-lock-keywords
+ (list
+ (cons (concat
+ "\\(^\\|[^_]\\)\\b\\("
+ (mapconcat
+ 'identity
+ '("alias"
+ "and"
+ "begin"
+ "break"
+ "case"
+ "class"
+ "do"
+ "elsif"
+ "else"
+ "fail"
+ "ensure"
+ "for"
+ "end"
+ "if"
+ "in"
+ "module"
+ "next"
+ "nil"
+ "not"
+ "or"
+ "raise"
+ "redo"
+ "rescue"
+ "retry"
+ "return"
+ "then"
+ "self"
+ "super"
+ "unless"
+ "undef"
+ "until"
+ "when"
+ "while"
+ )
+ "\\|")
+ "\\)[ \n\t()]")
+ 2)
+ ;; variables
+ '("nil\\|self\\|TRUE\\|FALSE"
+ 0 font-lock-variable-name-face)
+ ;; variables
+ '("\\[$@].\\([a-zA-Z0-9_]\\)"
+ 0 font-lock-variable-name-face)
+ ;; constants
+ '("\\b[A-Z]+[a-zA-Z0-9_]*"
+ 0 font-lock-type-face)
+ ;; functions
+ '("\\bdef[ \t]+[a-zA-Z_]+[a-zA-Z0-9_]*[?!]?"
+ 0 font-lock-function-name-face))
+ "*Additional expressions to highlight in ruby mode.")
+ (add-hook 'ruby-mode-hook
+ (lambda ()
+ (setq font-lock-keywords ruby-font-lock-keywords)
+ (font-lock-mode 1)))))
diff --git a/sample/rubydb2x.el b/sample/rubydb2x.el
new file mode 100644
index 0000000000..a74265fb0e
--- /dev/null
+++ b/sample/rubydb2x.el
@@ -0,0 +1,104 @@
+(require 'gud)
+(provide 'rubydb)
+
+;; ======================================================================
+;; rubydb functions
+
+;;; History of argument lists passed to rubydb.
+(defvar gud-rubydb-history nil)
+
+(defun gud-rubydb-massage-args (file args)
+ (cons "-I" (cons "." (cons "-r" (cons "debug" (cons file args))))))
+
+;; There's no guarantee that Emacs will hand the filter the entire
+;; marker at once; it could be broken up across several strings. We
+;; might even receive a big chunk with several markers in it. If we
+;; receive a chunk of text which looks like it might contain the
+;; beginning of a marker, we save it here between calls to the
+;; filter.
+(defvar gud-rubydb-marker-acc "")
+
+(defun gud-rubydb-marker-filter (string)
+ (save-match-data
+ (setq gud-marker-acc (concat gud-marker-acc string))
+ (let ((output ""))
+
+ ;; Process all the complete markers in this chunk.
+ (while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
+ gud-marker-acc)
+ (setq
+
+ ;; Extract the frame position from the marker.
+ gud-last-frame
+ (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
+ (string-to-int (substring gud-marker-acc
+ (match-beginning 2)
+ (match-end 2))))
+
+ ;; Append any text before the marker to the output we're going
+ ;; to return - we don't include the marker in this text.
+ output (concat output
+ (substring gud-marker-acc 0 (match-beginning 0)))
+
+ ;; Set the accumulator to the remaining text.
+ gud-marker-acc (substring gud-marker-acc (match-end 0))))
+
+ ;; Does the remaining text look like it might end with the
+ ;; beginning of another marker? If it does, then keep it in
+ ;; gud-marker-acc until we receive the rest of it. Since we
+ ;; know the full marker regexp above failed, it's pretty simple to
+ ;; test for marker starts.
+ (if (string-match "\032.*\\'" gud-marker-acc)
+ (progn
+ ;; Everything before the potential marker start can be output.
+ (setq output (concat output (substring gud-marker-acc
+ 0 (match-beginning 0))))
+
+ ;; Everything after, we save, to combine with later input.
+ (setq gud-marker-acc
+ (substring gud-marker-acc (match-beginning 0))))
+
+ (setq output (concat output gud-marker-acc)
+ gud-marker-acc ""))
+
+ output)))
+
+(defun gud-rubydb-find-file (f)
+ (find-file-noselect f))
+
+(defvar rubydb-command-name "ruby"
+ "File name for executing ruby.")
+
+;;;###autoload
+(defun rubydb (command-line)
+ "Run rubydb on program FILE in buffer *gud-FILE*.
+The directory containing FILE becomes the initial working directory
+and source-file directory for your debugger."
+ (interactive
+ (list (read-from-minibuffer "Run rubydb (like this): "
+ (if (consp gud-rubydb-history)
+ (car gud-rubydb-history)
+ (concat rubydb-command-name " "))
+ nil nil
+ '(gud-rubydb-history . 1))))
+
+ (gud-overload-functions '((gud-massage-args . gud-rubydb-massage-args)
+ (gud-marker-filter . gud-rubydb-marker-filter)
+ (gud-find-file . gud-rubydb-find-file)
+ ))
+ (gud-common-init command-line)
+
+ (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
+; (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
+ (gud-def gud-step "s" "\C-s" "Step one source line with display.")
+ (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
+ (gud-def gud-cont "c" "\C-r" "Continue with display.")
+ (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
+ (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
+ (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
+ (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.")
+
+ (setq comint-prompt-regexp "^(rdb:-) ")
+ (setq paragraph-start comint-prompt-regexp)
+ (run-hooks 'rubydb-mode-hook)
+ )
diff --git a/sample/rubydb3x.el b/sample/rubydb3x.el
new file mode 100644
index 0000000000..9d4e31f90e
--- /dev/null
+++ b/sample/rubydb3x.el
@@ -0,0 +1,104 @@
+(require 'gud)
+(provide 'rubydb)
+
+;; ======================================================================
+;; rubydb functions
+
+;;; History of argument lists passed to rubydb.
+(defvar gud-rubydb-history nil)
+
+(defun gud-rubydb-massage-args (file args)
+ (cons "-r" (cons "debug" args)))
+
+;; There's no guarantee that Emacs will hand the filter the entire
+;; marker at once; it could be broken up across several strings. We
+;; might even receive a big chunk with several markers in it. If we
+;; receive a chunk of text which looks like it might contain the
+;; beginning of a marker, we save it here between calls to the
+;; filter.
+(defvar gud-rubydb-marker-acc "")
+
+(defun gud-rubydb-marker-filter (string)
+ (setq gud-marker-acc (concat gud-marker-acc string))
+ (let ((output ""))
+
+ ;; Process all the complete markers in this chunk.
+ (while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
+ gud-marker-acc)
+ (setq
+
+ ;; Extract the frame position from the marker.
+ gud-last-frame
+ (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
+ (string-to-int (substring gud-marker-acc
+ (match-beginning 2)
+ (match-end 2))))
+
+ ;; Append any text before the marker to the output we're going
+ ;; to return - we don't include the marker in this text.
+ output (concat output
+ (substring gud-marker-acc 0 (match-beginning 0)))
+
+ ;; Set the accumulator to the remaining text.
+ gud-marker-acc (substring gud-marker-acc (match-end 0))))
+
+ ;; Does the remaining text look like it might end with the
+ ;; beginning of another marker? If it does, then keep it in
+ ;; gud-marker-acc until we receive the rest of it. Since we
+ ;; know the full marker regexp above failed, it's pretty simple to
+ ;; test for marker starts.
+ (if (string-match "\032.*\\'" gud-marker-acc)
+ (progn
+ ;; Everything before the potential marker start can be output.
+ (setq output (concat output (substring gud-marker-acc
+ 0 (match-beginning 0))))
+
+ ;; Everything after, we save, to combine with later input.
+ (setq gud-marker-acc
+ (substring gud-marker-acc (match-beginning 0))))
+
+ (setq output (concat output gud-marker-acc)
+ gud-marker-acc ""))
+
+ output))
+
+(defun gud-rubydb-find-file (f)
+ (save-excursion
+ (let ((buf (find-file-noselect f)))
+ (set-buffer buf)
+ (gud-make-debug-menu)
+ buf)))
+
+(defvar rubydb-command-name "ruby"
+ "File name for executing ruby.")
+
+;;;###autoload
+(defun rubydb (command-line)
+ "Run rubydb on program FILE in buffer *gud-FILE*.
+The directory containing FILE becomes the initial working directory
+and source-file directory for your debugger."
+ (interactive
+ (list (read-from-minibuffer "Run rubydb (like this): "
+ (if (consp gud-rubydb-history)
+ (car gud-rubydb-history)
+ (concat rubydb-command-name " "))
+ nil nil
+ '(gud-rubydb-history . 1))))
+
+ (gud-common-init command-line 'gud-rubydb-massage-args
+ 'gud-rubydb-marker-filter 'gud-rubydb-find-file)
+
+ (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
+; (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
+ (gud-def gud-step "s" "\C-s" "Step one source line with display.")
+ (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
+ (gud-def gud-cont "c" "\C-r" "Continue with display.")
+ (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
+ (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
+ (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
+ (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.")
+
+ (setq comint-prompt-regexp "^(rdb:-) ")
+ (setq paragraph-start comint-prompt-regexp)
+ (run-hooks 'rubydb-mode-hook)
+ )
diff --git a/sample/svr.rb b/sample/svr.rb
index 14aded8c3f..c866407eb0 100644
--- a/sample/svr.rb
+++ b/sample/svr.rb
@@ -18,7 +18,7 @@ while TRUE
socks.push(ns)
print(s, " is accepted\n")
else
- if s.eof
+ if s.eof?
print(s, " is gone\n")
s.close
socks.delete(s)
diff --git a/sample/test.rb b/sample/test.rb
index aacddbc56a..c940f0023f 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -96,13 +96,13 @@ tmp.close
# test break
tmp = open("while_tmp", "r")
-ok(tmp.type == "File")
+ok(tmp.kind_of?(File))
while tmp.gets()
break if /vt100/
end
-ok(!tmp.eof && /vt100/)
+ok(!tmp.eof? && /vt100/)
tmp.close
# test next
@@ -112,7 +112,7 @@ while tmp.gets()
next if /vt100/;
$bad = 1 if /vt100/;
end
-ok(!(!tmp.eof || /vt100/ || $bad))
+ok(!(!tmp.eof? || /vt100/ || $bad))
tmp.close
# test redo
@@ -126,9 +126,19 @@ while tmp.gets()
$bad = 1 if /vt100/;
$bad = 1 if /VT100/;
end
-ok(tmp.eof && !$bad)
+ok(tmp.eof? && !$bad)
tmp.close
+sum=0
+for i in 1..10
+ sum += i
+ i -= 1
+ if i > 0
+ redo
+ end
+end
+ok(sum == 220)
+
# test interval
$bad = FALSE
tmp = open("while_tmp", "r")
@@ -173,33 +183,23 @@ rescue
end
ok(TRUE)
-$bad = TRUE
-$string = "this must be handled no.3"
-begin
- fail $string
-rescue
-ensure
- $bad = FALSE
- ok(TRUE)
-end
-ok(FALSE) if $bad || $! != $string
-
# exception in rescue clause
+$string = "this must be handled no.3"
begin
begin
- fail "this must be handled no.4"
- rescue
fail "exception in rescue clause"
+ rescue
+ fail $string
end
ok(FALSE)
rescue
- ok(TRUE)
+ ok(TRUE) if $! == $string
end
# exception in ensure clause
begin
begin
- fail "this must be handled no.5"
+ fail "this must be handled no.4"
ensure
fail "exception in ensure clause"
end
@@ -222,7 +222,7 @@ ok(!$bad)
$bad = TRUE
begin
begin
- fail "this must be handled no.5"
+ fail "this must be handled no.6"
ensure
$bad = FALSE
end
@@ -429,8 +429,15 @@ ok($x == [1, 2, 3, 1, 2, 3, 4, 5, 6, 7])
check "bignum"
def fact(n)
return 1 if n == 0
- return n*fact(n-1)
+ f = 1
+ while n>0
+ f *= n
+ n -= 1
+ end
+ p f
+ return f
end
+fact(3)
$x = fact(40)
ok($x == $x)
ok($x == fact(40))
@@ -445,11 +452,48 @@ ok($x == -815915283247897734345611269596115894272000000000)
ok(2-(2**32) == -(2**32-2))
ok(2**32 - 5 == (2**32-3)-2)
+$good = TRUE;
+for i in 1000..3000
+ $good = FALSE if ((1<<i) != (2**i))
+end
+ok($good)
+
+$good = TRUE;
+n1=1
+for i in 0..3000
+ $good = FALSE if ((1<<i) != n1)
+ n1 *= 2
+end
+ok($good)
+
+$good = TRUE;
+n2=n1
+for i in 3000..-1
+ n1 = n1 / 2
+ n2 = n2 >> 1
+ $good = FALSE if (n1 != n2)
+end
+ok($good)
+
+$good = TRUE;
+for i in 3500..4000
+ n1 = 1 << i;
+ $good = FALSE if ((n1**2-1) / (n1+1) != (n1-1))
+end
+ok($good)
+
check "string & char"
ok("abcd" == "abcd")
ok("abcd" =~ "abcd")
ok("abcd" === "abcd")
+ok(("abc" =~ /^$/) == FALSE)
+ok(("abc\n" =~ /^$/) == FALSE)
+ok(("abc" =~ /^d*$/) == FALSE)
+ok(("abc" =~ /d*$/) == 3)
+ok("" =~ /^$/)
+ok("\n" =~ /^$/)
+ok("a\n\n" =~ /^$/)
$foo = "abc"
ok("#$foo = abc" == "abc = abc")
@@ -467,6 +511,13 @@ ok(foo * 5 == '-----')
ok(foo * 1 == '-')
ok(foo * 0 == '')
+$x = "a.gif"
+ok($x.sub(/.*\.([^\.]+)$/, '\1') == "gif")
+ok($x.sub(/.*\.([^\.]+)$/, 'b.\1') == "b.gif")
+ok($x.sub(/.*\.([^\.]+)$/, '\2') == "")
+ok($x.sub(/.*\.([^\.]+)$/, 'a\2b') == "ab")
+ok($x.sub(/.*\.([^\.]+)$/, '<\&>') == "<a.gif>")
+
# character constants(assumes ASCII)
ok("a"[0] == ?a)
ok(?a == ?a)
@@ -582,7 +633,7 @@ if defined? Process.kill
check "signal"
$x = 0
- trap "SIGINT", proc{|sig| $x = sig}
+ trap "SIGINT", proc{|sig| $x = 2}
Process.kill "SIGINT", $$
sleep 0.1
ok($x == 2)
@@ -596,12 +647,13 @@ if defined? Process.kill
rescue
x = $!
end
- ok(x =~ /Interrupt/)
+ ok(x && x =~ /Interrupt/)
else
ok(FALSE)
end
check "eval"
+ok(eval("") == nil)
$bad=FALSE
eval 'while FALSE; $bad = TRUE; print "foo\n" end'
ok(!$bad)
@@ -696,7 +748,6 @@ tmp.close
done = TRUE
tmp = open("script_tmp", "r")
while tmp.gets
- print "c: ", $_
if $_.to_i % 5 != 0
done = FALSE
break
@@ -859,6 +910,22 @@ ok(x.baz == "foo+foo")
# check for cache
ok(x.baz == "foo+foo")
+class Alias3<Alias2
+ def foo
+ defined? super
+ end
+ def bar
+ defined? super
+ end
+ def quux
+ defined? super
+ end
+end
+x = Alias3.new
+ok(!x.foo)
+ok(x.bar)
+ok(!x.quux)
+
check "gc"
begin
1.upto(10000) {
diff --git a/sample/tkbiff.rb b/sample/tkbiff.rb
index 24860c11a6..d2d7bf7beb 100644
--- a/sample/tkbiff.rb
+++ b/sample/tkbiff.rb
@@ -116,7 +116,7 @@ def pop_up
outcount = 0;
$list.delete 0, 'end'
f = open($spool, "r")
- while !f.eof
+ while !f.eof?
mail = Mail.new(f)
date, from, subj = mail.header['Date'], mail.header['From'], mail.header['Subject']
next if !date
diff --git a/sample/tkfrom.rb b/sample/tkfrom.rb
index 9a53ea2d72..b0ef8995ca 100644
--- a/sample/tkfrom.rb
+++ b/sample/tkfrom.rb
@@ -9,7 +9,7 @@ class Mail
def Mail.new(f)
if !f.kind_of?(IO)
f = open(f, "r")
- me = super
+ me = super(f)
f.close
else
me = super
@@ -22,7 +22,7 @@ class Mail
@body = []
while f.gets()
$_.chop!
- next if /^From / # skip From-line
+ next if /^From / # skip From-line
break if /^$/ # end of header
if /^(\S+):\s*(.*)/
@header[attr = $1.capitalize] = $2
@@ -50,7 +50,15 @@ class Mail
end
-ARGV[0] = '/usr/spool/mail/' + ENV['USER'] if ARGV.length == 0
+if ARGV.length == 0
+ if ENV['MAIL']
+ ARGV[0] = ENV['MAIL']
+ elsif ENV['USER']
+ ARGV[0] = '/usr/spool/mail/' + ENV['USER']
+ elsif ENV['LOGNAME']
+ ARGV[0] = '/usr/spool/mail/' + ENV['LOGNAME']
+ end
+end
require "tk"
list = scroll = nil
@@ -90,8 +98,10 @@ for file in ARGV
f = open(file, "r")
while !f.eof
mail = Mail.new(f)
- date, from, subj = mail.header['Date'], mail.header['From'], mail.header['Subject']
+ date = mail.header['Date']
next if !date
+ from = mail.header['From']
+ subj = mail.header['Subject']
y = m = d = 0
y, m, d = parsedate(date) if date
from = "sombody@somewhere" if ! from