diff options
Diffstat (limited to 'sample')
-rw-r--r-- | sample/fib.scm | 4 | ||||
-rw-r--r-- | sample/from.rb | 29 | ||||
-rw-r--r-- | sample/io.rb | 44 | ||||
-rw-r--r-- | sample/rbc.rb | 46 | ||||
-rw-r--r-- | sample/ruby-mode.el | 20 | ||||
-rw-r--r-- | sample/test.rb | 10 | ||||
-rw-r--r-- | sample/tkfrom.rb | 40 |
7 files changed, 88 insertions, 105 deletions
diff --git a/sample/fib.scm b/sample/fib.scm index 8eba75bb9e..5c2b86e656 100644 --- a/sample/fib.scm +++ b/sample/fib.scm @@ -3,4 +3,6 @@ n (+ (fib (- n 2)) (fib (- n 1))))) -(fib 20) +(display (fib 20)) +(newline) + diff --git a/sample/from.rb b/sample/from.rb index d39bb70084..0a83f081f1 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 @@ -34,11 +32,15 @@ end if ARGV.length == 0 user = ENV['USER'] else - user = ARGV[0] + file = 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}" + if File.exist? f = "#{m}/mail/#{user}" + file = f + break + end end $outcount = 0; @@ -63,18 +65,23 @@ def fromout(date, from, subj) 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 + printf "%02d/%02d/%02d [%s] %s\n",y%100,m,d,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/io.rb b/sample/io.rb deleted file mode 100644 index 0b38d2112d..0000000000 --- a/sample/io.rb +++ /dev/null @@ -1,44 +0,0 @@ -# IO test -# usage: ruby io.rb file.. - -home = ENV["HOME"] -home.sub("m", "&&") -print(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", passwd.find{i|i =~ /\*/}) - -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/rbc.rb b/sample/rbc.rb index 88a5b2d069..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" @@ -120,9 +120,9 @@ module BC_APPLICATION__ if line != "\n" begin if CONFIG[:INSPECT] - print (cont._=eval(line, bind)).inspect, "\n" + print((cont._=eval(line, bind)).inspect, "\n") else - print (cont._=eval(line, bind)), "\n" + print((cont._=eval(line, bind)), "\n") end rescue # $! = 'exception raised' unless $! @@ -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/ruby-mode.el b/sample/ruby-mode.el index 0f56477ea0..d31b2d196e 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -2,11 +2,16 @@ ;;; ruby-mode.el - ;;; ;;; $Author$ -;;; Time-stamp: <97/03/21 01:16:05 matz> +;;; $Date$ ;;; created at: Fri Feb 4 14:49:13 JST 1994 ;;; -(defconst ruby-mode-version "1.0.7") +(defconst ruby-mode-revision "$Revision$") + +(defconst ruby-mode-version + (progn + (string-match "[0-9.]+" ruby-mode-revision) + (substring ruby-mode-revision (match-beginning 0) (match-end 0)))) (defconst ruby-block-beg-re "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do" @@ -79,7 +84,7 @@ (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) + (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) @@ -632,10 +637,10 @@ An end of a defun is found by moving forward from the beginning of one." '("\\(^\\|[^_]\\)\\b\\([A-Z]+[a-zA-Z0-9_]*\\)" 2 font-lock-type-face) ;; functions - '("^\\s *def[ \t]+.*$" - 0 font-lock-function-name-face)) + '("^\\s *def[ \t]+[^ \t(]*" + 0 font-lock-function-name-face t)) "*Additional expressions to highlight in ruby mode.") - (if (and (>= (string-to-int emacs-version) 20) + (if (and (>= (string-to-int emacs-version) 19) (not (featurep 'xemacs))) (add-hook 'ruby-mode-hook @@ -645,5 +650,4 @@ An end of a defun is found by moving forward from the beginning of one." '((ruby-font-lock-keywords) nil nil ((?\_ . "w")))))) (add-hook 'ruby-mode-hook (lambda () - (setq font-lock-keywords ruby-font-lock-keywords) - (font-lock-mode 1)))))) + (setq font-lock-keywords ruby-font-lock-keywords)))))) diff --git a/sample/test.rb b/sample/test.rb index 0a9d41c2ed..e413ada27a 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/; @@ -766,6 +766,14 @@ ok(done) File.unlink "script_tmp" or `/bin/rm -f "script_tmp"` File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"` +$bad = false +for script in Dir["{lib,sample}/*.rb"] + unless `./ruby -c #{script}` == "Syntax OK\n" + $bad = true + end +end +ok(!$bad) + check "const" TEST1 = 1 TEST2 = 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 |