diff options
Diffstat (limited to 'sample')
-rw-r--r-- | sample/MANIFEST | 1 | ||||
-rw-r--r-- | sample/biorhythm.rb | 24 | ||||
-rw-r--r-- | sample/cbreak.rb | 4 | ||||
-rw-r--r-- | sample/clnt.rb | 2 | ||||
-rw-r--r-- | sample/from.rb | 100 | ||||
-rw-r--r-- | sample/io.rb | 2 | ||||
-rw-r--r-- | sample/ruby-mode.el | 6 | ||||
-rw-r--r-- | sample/svr.rb | 8 | ||||
-rwxr-xr-x | sample/time.rb | 2 | ||||
-rw-r--r-- | sample/trojan.rb | 2 |
10 files changed, 128 insertions, 23 deletions
diff --git a/sample/MANIFEST b/sample/MANIFEST index c91c078e39..93c971b114 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 eb14ca7365..5a452e0078 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 5d2d849512..cbb15d2f41 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 a687d12211..d2c71ec563 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 0000000000..f6602943af --- /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 c3c1a47b28..c12e4f4498 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 20e1abebc9..aa91be330d 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 91faa56dd8..23b2bf71f6 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 b0ef065ce3..715d98ac9e 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 b42fd166a8..2024da0908 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) |