summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cgi-lib.rb2
-rw-r--r--lib/debug.rb178
-rw-r--r--lib/mkmf.rb13
-rw-r--r--lib/telnet.rb245
4 files changed, 274 insertions, 164 deletions
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb
index 35b766ece0..3692b655c1 100644
--- a/lib/cgi-lib.rb
+++ b/lib/cgi-lib.rb
@@ -157,7 +157,7 @@ class CGI < SimpleDelegator
when "GET"
ENV['QUERY_STRING'] or ""
when "POST"
- input.read Integer(ENV['CONTENT_LENGTH'])
+ input.read(Integer(ENV['CONTENT_LENGTH'])) or ""
else
read_from_cmdline
end.split(/&/).each do |x|
diff --git a/lib/debug.rb b/lib/debug.rb
index e5c305db77..4c3ad2f099 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -1,12 +1,21 @@
class DEBUGGER__
+
+ def max(a,b)
+ if (a<b); b; else a; end
+ end
+
+ def min(a,b)
+ if (a<=b); a; else b; end
+ end
+
trap("INT") { DEBUGGER__::CONTEXT.interrupt }
$DEBUG = TRUE
def initialize
@break_points = []
@stop_next = 1
@frames = [nil]
- @frame_pos = nil
+ @frame_pos = nil # nil means not '0' but `unknown'.
@last_file = nil
@scripts = {}
end
@@ -23,19 +32,23 @@ class DEBUGGER__
val
rescue
at = caller(0)
- printf "%s:%s\n", at.shift, $!
+ STDOUT.printf "%s:%s\n", at.shift, $!
for i in at
break if i =~ /`debug_(eval|command)'$/ #`
- printf "\tfrom %s\n", i
+ STDOUT.printf "\tfrom %s\n", i
end
end
end
def debug_command(file, line, id, binding)
+ binding_file = file
+ binding_line = line
+ debug_line = {}
if (ENV['EMACS'] == 't')
- printf "\032\032%s:%d:\n", file, line
+ STDOUT.printf "\032\032%s:%d:\n", binding_file, binding_line
else
- printf "%s:%d:%s", file, line, line_at(file, line)
+ STDOUT.printf "%s:%d:%s", binding_file, binding_line,
+ line_at(binding_file, binding_line)
end
@frames[-1] = binding
STDOUT.print "(rdb:-) "
@@ -48,6 +61,7 @@ class DEBUGGER__
DEBUG_LAST_CMD[0] = input
end
case input
+
when /^b(reak)?\s+(([^:\n]+:)?.+)/
pos = $2
if pos.index ":"
@@ -60,14 +74,17 @@ class DEBUGGER__
else
pname = pos = pos.intern.id2name
end
- printf "Set breakpoint %d at %s:%s\n", @break_points.size, file, pname
+ STDOUT.printf "Set breakpoint %d at %s:%s\n", @break_points.size, file,
+ pname
@break_points.push [file, pos]
- when /^b(reak)?$/, /^info b(reak)?$/
+
+ when /^b(reak)?$/
n = 0
for f, p in @break_points
- printf "%d %s:%s\n", n, f, p
+ STDOUT.printf "%d %s:%s\n", n, f, p
n += 1
end
+
when /^del(ete)?(\s+(\d+))?$/
pos = $3
unless pos
@@ -83,14 +100,16 @@ class DEBUGGER__
pos = Integer(pos)
if @break_points[pos]
bp = @break_points[pos]
- printf "Clear breakpoint %d at %s:%s\n", pos, bp[0], bp[1]
+ STDOUT.printf "Clear breakpoint %d at %s:%s\n", pos, bp[0], bp[1]
@break_points[pos] = nil
else
- printf "Breakpoint %d is not defined\n", pos
+ STDOUT.printf "Breakpoint %d is not defined\n", pos
end
end
+
when /^c(ont)?$/
return
+
when /^s(tep)?\s*(\d+)?$/
if $2
lev = Integer($2)
@@ -99,6 +118,7 @@ class DEBUGGER__
end
@stop_next = lev
return
+
when /^n(ext)?\s*(\d+)?$/
if $2
lev = Integer($2)
@@ -108,78 +128,86 @@ class DEBUGGER__
@stop_next = lev
@no_step = @frames.size
return
- when /^up\s*(\d+)?$/
- if $1
- lev = Integer($1)
+
+ when /^i(?:nfo)?/, /^w(?:here)?/
+ fs = @frames.size
+ tb = caller(0)[-fs..-1].reverse
+ unless @frame_pos; @frame_pos = fs - 1; end
+
+ (fs-1).downto(0){ |i|
+ if (@frame_pos == i)
+ STDOUT.printf "--> frame %d:%s\n", i, tb[i]
+ else
+ STDOUT.printf " frame %d:%s\n", i, tb[i]
+ end
+ }
+
+ when /^l(ist)?$/
+ fs = @frames.size
+ tb = caller(0)[-fs..-1].reverse
+ unless @frame_pos; @frame_pos = fs - 1; end
+
+ file, line, func = tb[@frame_pos].split(":")
+ line = line.to_i
+ b = line - 1
+ e = line + 9
+ line_at(file, line)
+ if lines = @scripts[file] and lines != TRUE
+ lines = [0] + lines # Simple offset adjust
+ b = max(0, b); e = min(lines.size-1, e)
+ for l in b..e
+ if (l == line)
+ STDOUT.printf "--> %5d %s", l, lines[l]
+ else
+ STDOUT.printf " %5d %s", l, lines[l]
+ end
+ end
else
- lev = 1
- end
- unless @frame_pos
- @frame_pos = @frames.size - 1
+ STDOUT.printf "no sourcefile available for %s\n", file
end
+
+ when /^d(?:own)?\s*(\d+)??$/
+ if $1; lev = Integer($1); else lev = 1; end
+ unless @frame_pos; @frame_pos = 0; end
@frame_pos -= lev
if @frame_pos < 0
- STDOUT.print "at toplevel\n"
+ STDOUT.print "at stack bottom\n"
@frame_pos = 0
else
- binding = @frames[@frame_pos]
- end
- when /^down\s*(\d+)??$/
- if $1
- lev = Integer($1)
- else
- lev = 1
- end
- unless @frame_pos
- @frame_pos = @frames.size - 1
+ STDOUT.printf "at level %d\n", @frame_pos
end
- if lev >= @frames.size or @frame_pos and @frame_pos+lev >= @frames.size
- STDOUT.print "at stack bottom\n"
+ binding = @frames[@frame_pos]
+
+ when /^u(?:p)?\s*(\d+)?$/
+ if $1; lev = Integer($1); else lev = 1; end
+ unless @frame_pos; @frame_pos = @frames.size - 1; end
+ @frame_pos += lev
+ p @frame_pos
+ if @frame_pos >= @frames.size
+ STDOUT.print "at toplevel\n"
@frame_pos = nil
else
- @frame_pos += lev
+ binding = @frames[@frame_pos]
+ frame_info = caller(4)[-(@frame_pos+1)]
+ STDOUT.print "at #{frame_info}\n"
+ frame_info.sub( /:in `.*'$/, '' ) =~ /^(.*):(\d+)$/ #`
+ binding_file, binding_line = $1, $2.to_i
binding = @frames[@frame_pos]
end
- when /^fin(ish)?$/
+
+ when /^f(inish)?/
@finish_pos = @frames.size
return
+
when /^q(uit)?$/
STDOUT.print "really quit? (y/n) "
STDOUT.flush
input = STDIN.gets.chop!
exit if input == "y"
- when /^where$/
- at = caller(4)
- for i in at
- printf " %s\n", i
- end
- when /^l(ist)?(\s+(.*))?$/
- if $3
- b, e = $3.split(/[-,]/)
- b = Integer(b)-1
- if e
- e = Integer(e)-1
- else
- e = b + 10
- end
- end
- unless b
- b = line - 1
- e = line + 9
- end
- p [b,e]
- line_at(file, line)
- if lines = @scripts[file] and lines != TRUE
- n = b+1
- for l in lines[b..e]
- printf "%4d %s", n, l
- n += 1
- end
- else
- printf "no sourcefile available for %s\n", file
- end
+
when /^p\s+/
- p debug_eval($', binding) #'
+ p debug_eval($', binding)
+
else
v = debug_eval(input, binding)
p v unless v == nil
@@ -224,13 +252,26 @@ class DEBUGGER__
file = File.basename(file)
if @break_points.include? [file, pos]
index = @break_points.index([file, pos])
- printf "Breakpoint %d, %s at %s:%s\n",
+ STDOUT.printf "Breakpoint %d, %s at %s:%s\n",
index, debug_funcname(id), file, pos
return TRUE
end
return FALSE
end
+ def excn_handle(file, line, id, binding)
+ fs = @frames.size
+ tb = caller(0)[-fs..-1]
+ unless @frame_pos; @frame_pos = fs - 1; end
+
+ STDOUT.printf "%s\n", $!
+ for i in tb
+ STDOUT.printf "\tfrom %s\n", i
+ end
+ debug_command(file, line, id, binding)
+ end
+
+
def trace_func(event, file, line, id, binding)
if event == 'line'
if @no_step == nil or @no_step >= @frames.size
@@ -249,21 +290,30 @@ class DEBUGGER__
debug_command(file, line, id, binding)
end
end
+
if event == 'call'
@frames.push binding
if check_break_points(file, id.id2name, binding, id)
debug_command(file, line, id, binding)
end
end
+
if event == 'class'
@frames.push binding
end
+
if event == 'return' or event == 'end'
if @finish_pos == @frames.size
@stop_next = 1
end
@frames.pop
end
+
+ if event == 'raise'
+ # @frames.push binding
+ excn_handle(file, line, id, binding)
+ end
+
@last_file = file
end
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 82beea6b4f..d2cde95912 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -54,6 +54,8 @@ end
CFLAGS = CONFIG["CFLAGS"]
if PLATFORM == "m68k-human"
CFLAGS.gsub!(/-c..-stack=[0-9]+ */, '')
+elsif PLATFORM =~ /-nextstep|-rhapsody/
+ CFLAGS.gsub!( /-arch\s\w*/, '' );
end
if /win32|djgpp|mingw32|m68k-human|i386-os2_emx/i =~ PLATFORM
$null = open("nul", "w")
@@ -98,6 +100,7 @@ def try_cpp(src, opt="")
cfile.print src
cfile.close
begin
+
xsystem(format(CPP, $CFLAGS, opt))
ensure
system "rm -f conftest*"
@@ -335,9 +338,9 @@ def create_makefile(target)
end
unless $objs then
- $objs = Dir["*.{c,cc}"]
+ $objs = Dir["*.{c,cc,m}"]
for f in $objs
- f.sub!(/\.(c|cc)$/, ".o")
+ f.sub!(/\.(c|cc|m)$/, ".o")
end
end
$objs = $objs.join(" ")
@@ -402,13 +405,11 @@ EOMF
$(DLLIB): $(OBJS)
$(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS)
EOMF
- elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc") or
+ elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc")
mfile.print "$(DLLIB): $(OBJS)\n"
case PLATFORM
when "m68k-human"
mfile.printf "ar cru $(DLLIB) $(OBJS)\n"
- when /-nextstep/
- mfile.printf "cc -r $(CFLAGS) -o $(DLLIB) $(OBJS)\n"
else
mfile.printf "ld $(DLDFLAGS) -r -o $(DLLIB) $(OBJS)\n"
end
@@ -459,7 +460,7 @@ EOMF
end
end
-$libs = PLATFORM =~ /cygwin32|beos/ ? nil : "-lc"
+$libs = PLATFORM =~ /cygwin32|beos|rhapsody|nextstep/ ? nil : "-lc"
$objs = nil
$LOCAL_LIBS = ""
$CFLAGS = ""
diff --git a/lib/telnet.rb b/lib/telnet.rb
index 4251de1ee9..ac624fd257 100644
--- a/lib/telnet.rb
+++ b/lib/telnet.rb
@@ -1,11 +1,11 @@
=begin
-$Date: 1999/06/04 06:24:58 $
+$Date: 1999/06/29 09:08:51 $
== SIMPLE TELNET CLIANT LIBRARY
telnet.rb
-Version 0.20
+Version 0.22
Wakou Aoyama <wakou@fsinet.or.jp>
@@ -20,6 +20,7 @@ Wakou Aoyama <wakou@fsinet.or.jp>
"Prompt" => /[$%#>] \z/n, # default: /[$%#>] \z/n
"Telnetmode" => TRUE, # default: TRUE
"Timeout" => 10, # default: 10
+ # if ignore timeout then set "Timeout" to FALSE.
"Waittime" => 0, # default: 0
"Proxy" => proxy}) # default: nil
# proxy is Telnet or TCPsocket object
@@ -49,6 +50,7 @@ example
line = host.waitfor({"Match" => /match/,
"String" => "string",
"Timeout" => secs})
+ # if ignore timeout then set "Timeout" to FALSE.
if set "String" option. Match = Regexp.new(quote(string))
@@ -145,76 +147,128 @@ of cource, set sync=TRUE or flush is necessary.
== HISTORY
+=== Version 0.22
+
+1999/06/29 09:08:51
+
+- new, waitfor, cmd: {"Timeout" => FALSE} # ignore timeout
+
+=== Version 0.21
+
+1999/06/28 18:18:55
+
+- waitfor: not rescue (EOFError)
+
=== Version 0.20
-waitfor: support for divided telnet command
-=== Version 0.181 1999/05/22
-bug fix: print method
+1999/06/04 06:24:58
+
+- waitfor: support for divided telnet command
+
+=== Version 0.181
+
+1999/05/22
+
+- bug fix: print method
+
+=== Version 0.18
+
+1999/05/14
+
+- respond to "IAC WON'T SGA" with "IAC DON'T SGA"
+- DON'T SGA : end of line --> CR + LF
+- bug fix: preprocess method
+
+=== Version 0.17
+
+1999/04/30
+
+- bug fix: $! + "\n" --> $!.to_s + "\n"
+
+=== Version 0.163
+
+1999/04/11
-=== Version 0.18 1999/05/14
-respond to "IAC WON'T SGA" with "IAC DON'T SGA"
+- STDOUT.write(message) --> yield(message) if iterator?
-DON'T SGA : end of line --> CR + LF
+=== Version 0.162
-bug fix: preprocess method
+1999/03/17
-=== Version 0.17 1999/04/30
-bug fix: $! + "\n" --> $!.to_s + "\n"
+- add "Proxy" option
+- required timeout.rb
-=== Version 0.163 1999/04/11
-STDOUT.write(message) --> yield(message) if iterator?
+=== Version 0.161
-=== Version 0.162 1999/03/17
-add "Proxy" option
+1999/02/03
-required timeout.rb
+- select --> IO::select
-=== Version 0.161 1999/02/03
-select --> IO::select
+=== Version 0.16
-=== Version 0.16 1998/10/09
-preprocess method change for the better
+1998/10/09
-add binmode method.
+- preprocess method change for the better
+- add binmode method.
+- change default Binmode. TRUE --> FALSE
-change default Binmode
-TRUE --> FALSE
+=== Version 0.15
-=== Version 0.15 1998/10/04
-add telnetmode method.
+1998/10/04
-=== Version 0.141 1998/09/22
-change default prompt
- /[$%#>] $/ --> /[$%#>] \Z/
+- add telnetmode method.
-=== Version 0.14 1998/09/01
-IAC WILL SGA send EOL --> CR+NULL
+=== Version 0.141
-IAC WILL SGA IAC DO BIN send EOL --> CR
+1998/09/22
-NONE send EOL --> LF
+- change default prompt. /[$%#>] $/ --> /[$%#>] \Z/
-add Dump_log option.
+=== Version 0.14
-=== Version 0.13 1998/08/25
-add print method.
+1998/09/01
-=== Version 0.122 1998/08/05
-support for HP-UX 10.20 thanks to WATANABE Tetsuya <tetsu@jpn.hp.com>
+- IAC WILL SGA send EOL --> CR+NULL
+- IAC WILL SGA IAC DO BIN send EOL --> CR
+- NONE send EOL --> LF
+- add Dump_log option.
-socket.<< --> socket.write
+=== Version 0.13
-=== Version 0.121 1998/07/15
-string.+= --> string.concat
+1998/08/25
-=== Version 0.12 1998/06/01
-add timeout, waittime.
+- add print method.
-=== Version 0.11 1998/04/21
-add realtime output.
+=== Version 0.122
-=== Version 0.10 1998/04/13
-first release.
+1998/08/05
+
+- support for HP-UX 10.20 thanks to WATANABE Tetsuya <tetsu@jpn.hp.com>
+- socket.<< --> socket.write
+
+=== Version 0.121
+
+1998/07/15
+
+- string.+= --> string.concat
+
+=== Version 0.12
+
+1998/06/01
+
+- add timeout, waittime.
+
+=== Version 0.11
+
+1998/04/21
+
+- add realtime output.
+
+=== Version 0.10
+
+1998/04/13
+
+- first release.
=end
@@ -296,35 +350,35 @@ class Telnet < SimpleDelegator
EOL = CR + LF
v = $-v
$-v = false
- VERSION = "0.20"
- RELEASE_DATE = "$Date: 1999/06/04 06:24:58 $"
+ VERSION = "0.22"
+ RELEASE_DATE = "$Date: 1999/06/29 09:08:51 $"
$-v = v
def initialize(options)
@options = options
- @options["Binmode"] = FALSE if not @options.include?("Binmode")
- @options["Host"] = "localhost" if not @options.include?("Host")
- @options["Port"] = 23 if not @options.include?("Port")
- @options["Prompt"] = /[$%#>] \z/n if not @options.include?("Prompt")
- @options["Telnetmode"] = TRUE if not @options.include?("Telnetmode")
- @options["Timeout"] = 10 if not @options.include?("Timeout")
- @options["Waittime"] = 0 if not @options.include?("Waittime")
+ @options["Binmode"] = FALSE unless @options.key?("Binmode")
+ @options["Host"] = "localhost" unless @options.key?("Host")
+ @options["Port"] = 23 unless @options.key?("Port")
+ @options["Prompt"] = /[$%#>] \z/n unless @options.key?("Prompt")
+ @options["Telnetmode"] = TRUE unless @options.key?("Telnetmode")
+ @options["Timeout"] = 10 unless @options.key?("Timeout")
+ @options["Waittime"] = 0 unless @options.key?("Waittime")
@telnet_option = { "SGA" => FALSE, "BINARY" => FALSE }
- if @options.include?("Output_log")
+ if @options.key?("Output_log")
@log = File.open(@options["Output_log"], 'a+')
@log.sync = TRUE
@log.binmode
end
- if @options.include?("Dump_log")
+ if @options.key?("Dump_log")
@dumplog = File.open(@options["Dump_log"], 'a+')
@dumplog.sync = TRUE
@dumplog.binmode
end
- if @options.include?("Proxy")
+ if @options.key?("Proxy")
if @options["Proxy"].kind_of?(Telnet)
@sock = @options["Proxy"].sock
elsif @options["Proxy"].kind_of?(TCPsocket)
@@ -335,18 +389,22 @@ $-v = v
else
message = "Trying " + @options["Host"] + "...\n"
yield(message) if iterator?
- @log.write(message) if @options.include?("Output_log")
- @dumplog.write(message) if @options.include?("Dump_log")
+ @log.write(message) if @options.key?("Output_log")
+ @dumplog.write(message) if @options.key?("Dump_log")
begin
- timeout(@options["Timeout"]){
+ if @options["Timeout"] == FALSE
@sock = TCPsocket.open(@options["Host"], @options["Port"])
- }
+ else
+ timeout(@options["Timeout"]){
+ @sock = TCPsocket.open(@options["Host"], @options["Port"])
+ }
+ end
rescue TimeoutError
raise TimeOut, "timed-out; opening of the host"
rescue
- @log.write($!.to_s + "\n") if @options.include?("Output_log")
- @dumplog.write($!.to_s + "\n") if @options.include?("Dump_log")
+ @log.write($!.to_s + "\n") if @options.key?("Output_log")
+ @dumplog.write($!.to_s + "\n") if @options.key?("Dump_log")
raise
end
@sock.sync = TRUE
@@ -354,8 +412,8 @@ $-v = v
message = "Connected to " + @options["Host"] + ".\n"
yield(message) if iterator?
- @log.write(message) if @options.include?("Output_log")
- @dumplog.write(message) if @options.include?("Dump_log")
+ @log.write(message) if @options.key?("Output_log")
+ @dumplog.write(message) if @options.key?("Dump_log")
end
super(@sock)
@@ -386,7 +444,7 @@ $-v = v
str.gsub!(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"]
# combine EOL into "\n"
- str.gsub!(/#{EOL}/no, "\n") if not @options["Binmode"]
+ str.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
# respond to "IAC DO x"
str.gsub!(/([^#{IAC}]?)#{IAC}#{DO}([#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}])/no){
@@ -443,41 +501,42 @@ $-v = v
waittime = @options["Waittime"]
if options.kind_of?(Hash)
- prompt = if options.include?("Match")
+ prompt = if options.key?("Match")
options["Match"]
- elsif options.include?("Prompt")
+ elsif options.key?("Prompt")
options["Prompt"]
- elsif options.include?("String")
+ elsif options.key?("String")
Regexp.new( Regexp.quote(options["String"]) )
end
- time_out = options["Timeout"] if options.include?("Timeout")
- waittime = options["Waittime"] if options.include?("Waittime")
+ time_out = options["Timeout"] if options.key?("Timeout")
+ waittime = options["Waittime"] if options.key?("Waittime")
else
prompt = options
end
+ if time_out == FALSE
+ time_out = nil
+ end
+
line = ''
buf = ''
until(not IO::select([@sock], nil, nil, waittime) and prompt === line)
- raise TimeOut, "timed-out; wait for the next data" if
- not IO::select([@sock], nil, nil, time_out)
- begin
- c = @sock.sysread(1024 * 1024)
- @dumplog.print(c) if @options.include?("Dump_log")
- buf.concat c
- if @options["Telnetmode"]
- buf = preprocess(buf)
- if /#{IAC}.?\z/no === buf
- next
- end
- end
- @log.print(buf) if @options.include?("Output_log")
- yield buf if iterator?
- line.concat(buf)
- buf = ''
- rescue EOFError # End of file reached
- break
+ unless IO::select([@sock], nil, nil, time_out)
+ raise TimeOut, "timed-out; wait for the next data"
end
+ 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
+ @log.print(buf) if @options.key?("Output_log")
+ yield buf if iterator?
+ line.concat(buf)
+ buf = ''
end
line
end
@@ -487,7 +546,7 @@ $-v = v
str.gsub!(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
- if not @options["Binmode"]
+ unless @options["Binmode"]
if @telnet_option["BINARY"] and @telnet_option["SGA"]
# IAC WILL SGA IAC DO BIN send EOL --> CR
str.gsub!(/\n/n, CR)
@@ -509,8 +568,8 @@ $-v = v
if options.kind_of?(Hash)
string = options["String"]
- match = options["Match"] if options.include?("Match")
- time_out = options["Timeout"] if options.include?("Timeout")
+ match = options["Match"] if options.key?("Match")
+ time_out = options["Timeout"] if options.key?("Timeout")
else
string = options
end