From b814252d728cb08f159da1777feca4f8e9362327 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 9 Feb 1998 10:56:24 +0000 Subject: 1.1b7 pre git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@67 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/from.rb | 22 +++++++++++++--------- sample/rbc.rb | 42 +++++++++++++++++++++--------------------- sample/test.rb | 3 ++- sample/tkfrom.rb | 40 +++++++++++++++++++++++----------------- 4 files changed, 59 insertions(+), 48 deletions(-) (limited to 'sample') diff --git a/sample/from.rb b/sample/from.rb index d39bb70084..39aa4b7553 100644 --- a/sample/from.rb +++ b/sample/from.rb @@ -9,8 +9,6 @@ include Kconv class String - public :kconv - def kconv(code = Kconv::EUC) Kconv.kconv(self, code, Kconv::AUTO) end @@ -35,10 +33,11 @@ if ARGV.length == 0 user = ENV['USER'] else user = ARGV[0] + ARGV.clear end [ENV['SPOOLDIR'], '/usr/spool', '/var/spool', '/usr', '/var'].each do |m| - break if File.exist? ARGV[0] = "#{m}/mail/#{user}" + break if File.exist? file = "#{m}/mail/#{user}" end $outcount = 0; @@ -67,14 +66,19 @@ def fromout(date, from, subj) $outcount += 1 end -for file in ARGV - next if !File.exist?(file) +if File.exist?(file) + atime = File.atime(file) + mtime = File.mtime(file) f = open(file, "r") - while !f.eof? - mail = Mail.new(f) - fromout mail.header['Date'], mail.header['From'], mail.header['Subject'] + begin + until f.eof? + mail = Mail.new(f) + fromout mail.header['Date'],mail.header['From'],mail.header['Subject'] + end + ensure + f.close + File.utime(atime, mtime, file) end - f.close end if $outcount == 0 diff --git a/sample/rbc.rb b/sample/rbc.rb index b3a4851ef5..7ab0edba12 100644 --- a/sample/rbc.rb +++ b/sample/rbc.rb @@ -11,29 +11,29 @@ # # rbc.rb [options] file_name opts # options: -# -d デバッグモード(利用しない方が良いでしょう) -# -m bcモード(分数, 行列の計算ができます) -# -r load-module ruby -r と同じ -# --inspect 結果出力にinspectを用いる(bcモード以外はデ -# フォルト). -# --noinspect 結果出力にinspectを用いない. -# --noreadline readlineライブラリを利用しない(デフォルト -# ではreadlineライブラリを利用しようとする). +# -d debug mode(not encouraged) +# -m bc mode(calculate rational, matrix) +# -r load-module same as `ruby -r' +# --inspect use inspect for output. +# (default except in bc mode) +# --noinspect do not use inspect for output. +# --noreadline do not use readline library. +# (rbc tries to use readline as default). # -# 追加 private method: -# exit, quit 終了する. -# inspect(sw = nil) インスペクトモードのトグル -# trace_load(sw = nil) load/require時にrbcのfile読み込み機能を用 -# いるモードのスイッチ(デフォルトはトレース -# モード) +# additional private methods: +# exit, quit quit +# inspect(sw = nil) toggle inspect mode +# trace_load(sw = nil) toggle trace mode for load/require. +# (default is trace mode on) # require "e2mmap.rb" $stdout.sync = TRUE module BC_APPLICATION__ - RCS_ID='-$Header: /home/keiju/var/src/var.lib/ruby/ruby/RCS/rbc.rb,v 1.2 1997/11/27 13:46:06 keiju Exp keiju $-' - + + RCS_ID=%q$Id: rbc.rb,v 1.2 1997/11/27 13:46:06 keiju Exp keiju $ + extend Exception2MessageMapper def_exception :UnrecognizedSwitch, "Unrecognized switch: %s" @@ -186,7 +186,7 @@ module BC_APPLICATION__ PARCENT_LTYPE = { "q" => "\'", - "Q" => "\"", + "Q" => "\"", #" "x" => "\`", "r" => "\/" } @@ -332,7 +332,7 @@ module BC_APPLICATION__ @lex_state = EXPR_BEG end end - @OP.def_rule('$') do + @OP.def_rule('$') do #' |op, rests| identify_gvar(rests) end @@ -444,7 +444,7 @@ module BC_APPLICATION__ print token, "\n" if $DEBUG if state = CLAUSE_STATE_TRANS[token] if @lex_state != EXPR_BEG and token =~ /^(if|unless|while|until)/ - # 修飾子 + # $B=$>~;R(B else if ENINDENT_CLAUSE.include?(token) @indent += 1 @@ -472,7 +472,7 @@ module BC_APPLICATION__ if lt = PARCENT_LTYPE[ch] ch = chrs.shift else - lt = "\"" + lt = "\"" #" end if ch !~ /\W/ chrs.unshift ch @@ -618,7 +618,7 @@ module BC_APPLICATION__ def_exception :ErrNodeAlreadyExists, "node already exists" class Node - # postprocがなければ抽象ノード, nilじゃなければ具象ノード + # postproc$B$,$J$1$l$PCj>]%N!<%I(B, nil$B$8$c$J$1$l$P6q>]%N!<%I(B def initialize(preproc = nil, postproc = nil) @Tree = {} @preproc = preproc diff --git a/sample/test.rb b/sample/test.rb index 0a9d41c2ed..ce0822685a 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -120,7 +120,7 @@ $bad = false tmp = open("while_tmp", "r") while tmp.gets() if gsub!('vt100', 'VT100') - gsub!('VT100', 'Vt100') + p gsub!('VT100', 'Vt100') redo; end $bad = 1 if /vt100/; @@ -453,6 +453,7 @@ ok($x+1 == 815915283247897734345611269596115894272000000001) ok($x/fact(20) == 335367096786357081410764800000) $x = -$x ok($x == -815915283247897734345611269596115894272000000000) +p [2**32, 2-(2**32), -(2**32-2)] ok(2-(2**32) == -(2**32-2)) ok(2**32 - 5 == (2**32-3)-2) diff --git a/sample/tkfrom.rb b/sample/tkfrom.rb index b0ef8995ca..ba0e547799 100644 --- a/sample/tkfrom.rb +++ b/sample/tkfrom.rb @@ -94,25 +94,31 @@ root.bind "space", proc{exit} $outcount = 0; for file in ARGV - next if !File.exist?(file) + next if File.exist?(file) + atime = File.atime(file) + mtime = File.mtime(file) f = open(file, "r") - while !f.eof - mail = Mail.new(f) - 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 - subj = "(nil)" if ! subj - from = decode_b(from) - subj = decode_b(subj) - list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj) - $outcount += 1 + begin + until f.eof + mail = Mail.new(f) + date = mail.header['Date'] + next unless date + from = mail.header['From'] + subj = mail.header['Subject'] + y = m = d = 0 + y, m, d = parsedate(date) if date + from = "sombody@somewhere" unless from + subj = "(nil)" unless subj + from = decode_b(from) + subj = decode_b(subj) + list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj) + $outcount += 1 + end + ensure + f.close + File.utime(atime, mtime, file) + list.see 'end' end - f.close - list.see 'end' end limit = 10000 -- cgit v1.2.3