diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cgi-lib.rb | 19 | ||||
-rw-r--r-- | lib/matrix.rb | 100 | ||||
-rw-r--r-- | lib/telnet.rb | 54 |
3 files changed, 110 insertions, 63 deletions
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb index f599f772ce..bf04601238 100644 --- a/lib/cgi-lib.rb +++ b/lib/cgi-lib.rb @@ -117,6 +117,17 @@ class CGI < SimpleDelegator LF = "\012" EOL = CR + LF + RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ] + RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ] + + # make rfc1123 date string + def rfc1123_date(time) + t = time.clone.gmtime + return format("%s, %.2d %s %d %.2d:%.2d:%.2d GMT", + RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year, + t.hour, t.min, t.sec) + end + # escape url encode def escape(str) str.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) } @@ -132,7 +143,7 @@ class CGI < SimpleDelegator str.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<") end - module_function :escape, :unescape, :escapeHTML + module_function :escape, :unescape, :escapeHTML, :rfc1123_date # offline mode. read name=value pairs on standard input. def read_from_cmdline @@ -160,7 +171,7 @@ class CGI < SimpleDelegator input.read(Integer(ENV['CONTENT_LENGTH'])) or "" else read_from_cmdline - end.split(/&/).each do |x| + end.split(/[&;]/).each do |x| key, val = x.split(/=/,2).collect{|x|unescape(x)} if @inputs.include?(key) @inputs[key] += "\0" + (val or "") @@ -201,7 +212,7 @@ class CGI < SimpleDelegator "Set-Cookie: " + options['name'] + '=' + escape(options['value']) + (options['domain'] ? '; domain=' + options['domain'] : '') + (options['path'] ? '; path=' + options['path'] : '') + - (options['expires'] ? '; expires=' + options['expires'].strftime("%a, %d %b %Y %X %Z") : '') + + (options['expires'] ? '; expires=' + rfc1123_date(options['expires']) : '') + (options['secure'] ? '; secure' : '') end @@ -218,7 +229,7 @@ class CGI < SimpleDelegator else if options.delete("nph") or (ENV['SERVER_SOFTWARE'] =~ /IIS/) [(ENV['SERVER_PROTOCOL'] or "HTTP/1.0") + " 200 OK", - "Date: " + Time.now.gmtime.strftime("%a, %d %b %Y %X %Z"), + "Date: " + rfc1123_date(Time.now), "Server: " + (ENV['SERVER_SOFTWARE'] or ""), "Connection: close"] + (options.empty? ? ["Content-Type: text/html"] : options) diff --git a/lib/matrix.rb b/lib/matrix.rb index a408f4be91..f31da643ff 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1,8 +1,9 @@ +#!/usr/local/bin/ruby # # matrix.rb - # $Release Version: 1.0$ -# $Revision: 1.9 $ -# $Date: 1999/08/24 10:25:00 $ +# $Revision: 1.11 $ +# $Date: 1999/10/06 11:01:53 $ # Original Version from Smalltalk-80 version # on July 23, 1985 at 8:37:17 am # by Keiju ISHITSUKA @@ -38,7 +39,7 @@ # creates a matrix where `rows' indicates rows. # `rows' is an array of arrays, # e.g, Matrix[[11, 12], [21, 22]] -# Matrix.rows(rows, copy = true) +# Matrix.rows(rows, copy = TRUE) # creates a matrix where `rows' indicates rows. # if optional argument `copy' is false, use the array as # internal structure of the metrix without copying. @@ -144,7 +145,7 @@ # # INSTANCE CREATION: # Vector.[](*array) -# Vector.elements(array, copy = true) +# Vector.elements(array, copy = TRUE) # ACCSESSING: # [](i) # size @@ -185,7 +186,7 @@ module ExceptionForMatrix end class Matrix - @RCS_ID='-$Id: matrix.rb,v 1.8 1999/02/17 12:34:19 keiju Exp keiju $-' + @RCS_ID='-$Id: matrix.rb,v 1.11 1999/10/06 11:01:53 keiju Exp keiju $-' # extend Exception2MessageMapper include ExceptionForMatrix @@ -194,10 +195,10 @@ class Matrix private_class_method :new def Matrix.[](*rows) - new(:init_rows, rows, false) + new(:init_rows, rows, FALSE) end - def Matrix.rows(rows, copy = true) + def Matrix.rows(rows, copy = TRUE) new(:init_rows, rows, copy) end @@ -209,7 +210,7 @@ class Matrix columns[j][i] } } - Matrix.rows(rows, false) + Matrix.rows(rows, FALSE) end def Matrix.diagonal(*values) @@ -220,7 +221,8 @@ class Matrix row[j] = values[j] row } - rows(rows, false) + self + rows(rows, FALSE) end def Matrix.scalar(n, value) @@ -242,11 +244,11 @@ class Matrix def Matrix.row_vector(row) case row when Vector - Matrix.rows([row.to_a], false) + Matrix.rows([row.to_a], FALSE) when Array - Matrix.rows([row.dup], false) + Matrix.rows([row.dup], FALSE) else - Matrix.row([[row]], false) + Matrix.row([[row]], FALSE) end end @@ -311,13 +313,13 @@ class Matrix |i| @rows[i][j] } - Vector.elements(col, false) + Vector.elements(col, FALSE) end end def collect rows = @rows.collect{|row| row.collect{|e| yield e}} - Matrix.rows(rows, false) + Matrix.rows(rows, FALSE) end alias map collect @@ -345,7 +347,7 @@ class Matrix |row| row[from_col, size_col] } - Matrix.rows(rows, false) + Matrix.rows(rows, FALSE) end # TESTING @@ -363,20 +365,20 @@ class Matrix # COMPARING def ==(other) - return false unless Matrix === other + return FALSE unless Matrix === other other.compare_by_row_vectors(@rows) end alias eql? == def compare_by_row_vectors(rows) - return false unless @rows.size == rows.size + return FALSE unless @rows.size == rows.size 0.upto(@rows.size - 1) do |i| - return false unless @rows[i] == rows[i] + return FALSE unless @rows[i] == rows[i] end - true + TRUE end def clone @@ -405,7 +407,7 @@ class Matrix e * m } } - return Matrix.rows(rows, false) + return Matrix.rows(rows, FALSE) when Vector m = Matrix.column_vector(m) r = self * m @@ -425,7 +427,7 @@ class Matrix vij } } - return Matrix.rows(rows, false) + return Matrix.rows(rows, FALSE) else x, y = m.coerce(self) return x * y @@ -453,7 +455,7 @@ class Matrix self[i, j] + m[i, j] } } - Matrix.rows(rows, false) + Matrix.rows(rows, FALSE) end def -(m) @@ -477,7 +479,7 @@ class Matrix self[i, j] - m[i, j] } } - Matrix.rows(rows, false) + Matrix.rows(rows, FALSE) end def /(other) @@ -490,7 +492,7 @@ class Matrix e / other } } - return Matrix.rows(rows, false) + return Matrix.rows(rows, FALSE) when Matrix return self * other.inverse else @@ -619,17 +621,36 @@ class Matrix k = 0 begin if (akk = a[k][k]) == 0 - i = -1 - nothing = false + i = k + exists = true begin if (i += 1) > column_size - 1 - nothing = true + exists = false break end end while a[i][k] == 0 - next if nothing - a[i], a[k] = a[k], a[i] - akk = a[k][k] + if exists + a[i], a[k] = a[k], a[i] + akk = a[k][k] + else + i = k + exists = true + begin + if (i += 1) > row_size - 1 + exists = false + break + end + end while a[k][i] == 0 + if exists + k.upto(column_size - 1) do + |j| + a[j][k], a[j][i] = a[j][i], a[j][k] + end + akk = a[k][k] + else + next + end + end end (k + 1).upto(row_size - 1) do |i| @@ -806,10 +827,10 @@ class Vector private_class_method :new def Vector.[](*array) - new(:init_elements, array, copy = false) + new(:init_elements, array, copy = FALSE) end - def Vector.elements(array, copy = true) + def Vector.elements(array, copy = TRUE) new(:init_elements, array, copy) end @@ -854,7 +875,7 @@ class Vector # COMPARING def ==(other) - return false unless Vector === other + return FALSE unless Vector === other other.compare_by(@elements) end @@ -874,11 +895,11 @@ class Vector # ARITHMETIC - def *(x) # is matrix or number + def *(x) "is matrix or number" case x when Numeric els = @elements.collect{|e| e * x} - Vector.elements(els, false) + Vector.elements(els, FALSE) when Matrix self.covector * x else @@ -895,7 +916,7 @@ class Vector |v1, v2| v1 + v2 } - Vector.elements(els, false) + Vector.elements(els, FALSE) when Matrix Matrix.column_vector(self) + v else @@ -912,7 +933,7 @@ class Vector |v1, v2| v1 - v2 } - Vector.elements(els, false) + Vector.elements(els, FALSE) when Matrix Matrix.column_vector(self) - v else @@ -939,7 +960,7 @@ class Vector |v| yield v } - Vector.elements(els, false) + Vector.elements(els, FALSE) end alias map collect @@ -948,7 +969,7 @@ class Vector |v1, v2| yield v1, v2 } - Vector.elements(els, false) + Vector.elements(els, FALSE) end def r @@ -999,4 +1020,3 @@ class Vector str = "Vector"+@elements.inspect end end - diff --git a/lib/telnet.rb b/lib/telnet.rb index b161ae8c6c..b6623513e0 100644 --- a/lib/telnet.rb +++ b/lib/telnet.rb @@ -1,11 +1,11 @@ =begin -$Date: 1999/09/21 21:24:07 $ +$Date: 1999/10/04 22:51:26 $ == SIMPLE TELNET CLIANT LIBRARY telnet.rb -Version 0.50 +Version 1.00 Wakou Aoyama <wakou@fsinet.or.jp> @@ -155,6 +155,15 @@ of cource, set sync=true or flush is necessary. == HISTORY +=== Version 1.00 + +1999/10/04 22:51:26 + +- bug fix: waitfor(preprocess) method + thanks to Shin-ichiro Hara <sinara@blade.nagaokaut.ac.jp> +- add simple support for AO, DM, IP, NOP, SB, SE +- COUTION! TimeOut --> TimeoutError + === Version 0.50 1999/09/21 21:24:07 @@ -331,7 +340,6 @@ require "socket" require "delegate" require "thread" require "timeout" -TimeOut = TimeoutError class Telnet < SimpleDelegator @@ -405,8 +413,8 @@ class Telnet < SimpleDelegator EOL = CR + LF v = $-v $-v = false - VERSION = "0.50" - RELEASE_DATE = "$Date: 1999/09/21 21:24:07 $" + VERSION = "1.00" + RELEASE_DATE = "$Date: 1999/10/04 22:51:26 $" $-v = v def initialize(options) @@ -456,7 +464,7 @@ $-v = v } end rescue TimeoutError - raise TimeOut, "timed-out; opening of the host" + raise TimeoutError, "timed-out; opening of the host" rescue @log.write($!.to_s + "\n") if @options.key?("Output_log") @dumplog.write($!.to_s + "\n") if @options.key?("Dump_log") @@ -502,10 +510,10 @@ $-v = v str.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"] str.gsub!(/#{IAC}( - #{IAC}| - #{AYT}| + [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]| [#{DO}#{DONT}#{WILL}#{WONT}] - [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}] + [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]| + #{SB}[^#{IAC}]*#{IAC}#{SE} )/xno){ if IAC == $1 # handle escaped IAC characters IAC @@ -539,6 +547,8 @@ $-v = v self.write(IAC + DONT + OPT_SGA) end '' + else + '' end } @@ -551,7 +561,7 @@ $-v = v if options.kind_of?(Hash) prompt = if options.key?("Match") - options["Match"] + options["Match"] elsif options.key?("Prompt") options["Prompt"] elsif options.key?("String") @@ -569,24 +579,30 @@ $-v = v line = '' buf = '' + rest = '' until(prompt === line and not IO::select([@sock], nil, nil, waittime)) unless IO::select([@sock], nil, nil, time_out) - raise TimeOut, "timed-out; wait for the next data" + raise TimeoutError, "timed-out; wait for the next data" end begin c = @sock.sysread(1024 * 1024) @dumplog.print(c) if @options.key?("Dump_log") - buf.concat c if @options["Telnetmode"] - buf = preprocess(buf) - if /#{IAC}.?\z/no === buf - next - end - end + if Integer(c.rindex(/#{IAC}#{SE}/no)) < + Integer(c.rindex(/#{IAC}#{SB}/no)) + buf = preprocess(rest + c[0 ... c.rindex(/#{IAC}#{SB}/no)]) + rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1] + elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) + buf = preprocess(rest + c[0 ... pt]) + rest = c[pt .. -1] + else + buf = preprocess(c) + rest = '' + end + end @log.print(buf) if @options.key?("Output_log") - yield buf if iterator? line.concat(buf) - buf = '' + yield buf if iterator? rescue EOFError # End of file reached if line == '' line = nil |