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.rb233
-rw-r--r--lib/finalize.rb2
-rw-r--r--lib/ftools.rb2
-rw-r--r--lib/getopts.rb18
-rw-r--r--lib/jcode.rb14
-rw-r--r--lib/mathn.rb4
-rw-r--r--lib/matrix.rb62
-rw-r--r--lib/mkmf.rb143
-rw-r--r--lib/mutex_m.rb24
-rw-r--r--lib/observer.rb4
-rw-r--r--lib/shellwords.rb2
-rw-r--r--lib/telnet.rb116
-rw-r--r--lib/thread.rb12
14 files changed, 326 insertions, 312 deletions
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb
index 3692b655c1..f599f772ce 100644
--- a/lib/cgi-lib.rb
+++ b/lib/cgi-lib.rb
@@ -246,7 +246,7 @@ class CGI < SimpleDelegator
CGI::tag("BODY"){ message }
}
}
- TRUE
+ true
end
# print error message to $> and exit
diff --git a/lib/debug.rb b/lib/debug.rb
index 4c3ad2f099..45ec05ff01 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -1,22 +1,12 @@
-
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
+ $DEBUG = true
def initialize
@break_points = []
@stop_next = 1
@frames = [nil]
- @frame_pos = nil # nil means not '0' but `unknown'.
@last_file = nil
+ @last = [nil, nil]
@scripts = {}
end
@@ -41,16 +31,17 @@ class DEBUGGER__
end
def debug_command(file, line, id, binding)
+ frame_pos = 0
binding_file = file
binding_line = line
- debug_line = {}
+ previus_line = nil
if (ENV['EMACS'] == 't')
STDOUT.printf "\032\032%s:%d:\n", binding_file, binding_line
else
STDOUT.printf "%s:%d:%s", binding_file, binding_line,
line_at(binding_file, binding_line)
end
- @frames[-1] = binding
+ @frames[0] = binding
STDOUT.print "(rdb:-) "
STDOUT.flush
while input = STDIN.gets
@@ -60,10 +51,10 @@ class DEBUGGER__
else
DEBUG_LAST_CMD[0] = input
end
- case input
- when /^b(reak)?\s+(([^:\n]+:)?.+)/
- pos = $2
+ case input
+ when /^b(?:reak)?\s+((?:[^:\n]+:)?.+)/
+ pos = $1
if pos.index ":"
file, pos = pos.split(":")
end
@@ -78,15 +69,15 @@ class DEBUGGER__
pname
@break_points.push [file, pos]
- when /^b(reak)?$/
+ when /^b(?:reak)?$/, /^i(?:nfo) b(?:reak)?$/
n = 0
for f, p in @break_points
STDOUT.printf "%d %s:%s\n", n, f, p
n += 1
end
- when /^del(ete)?(\s+(\d+))?$/
- pos = $3
+ when /^del(?:ete)?(?:\s+(\d+))?$/
+ pos = $1
unless pos
STDOUT.print "clear all breakpoints? (y/n) "
STDOUT.flush
@@ -107,99 +98,111 @@ class DEBUGGER__
end
end
- when /^c(ont)?$/
+ when /^c(?:ont)?$/
return
- when /^s(tep)?\s*(\d+)?$/
- if $2
- lev = Integer($2)
+ when /^s(?:tep)?\s*(\d+)?$/
+ if $1
+ lev = Integer($1)
else
lev = 1
end
@stop_next = lev
return
- when /^n(ext)?\s*(\d+)?$/
- if $2
- lev = Integer($2)
+ when /^n(?:ext)?\s*(\d+)?$/
+ if $1
+ lev = Integer($1)
else
lev = 1
end
@stop_next = lev
- @no_step = @frames.size
+ @no_step = @frames.size - frame_pos
return
- 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]
+ when /^w(?:here)?$/, /^f(?:rame)?$/
+ at = caller(0)
+ 0.upto( @frames.size - 1 ) do |n|
+ if ( frame_pos == n )
+ STDOUT.printf "--> #%d %s\n", n, at[-(@frames.size - n)]
else
- STDOUT.printf " frame %d:%s\n", i, tb[i]
+ STDOUT.printf " #%d %s\n", n, at[-(@frames.size - n)]
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
- 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 stack bottom\n"
- @frame_pos = 0
- else
- STDOUT.printf "at level %d\n", @frame_pos
+ when /^l(?:ist)?(?:\s+(.+))?$/
+ if !$1
+ b = previus_line ? previus_line + 10 : binding_line - 5
+ e = b + 9
+ elsif $1 == '-'
+ b = previus_line ? previus_line - 10 : binding_line - 5
+ e = b + 9
+ else
+ b, e = $1.split(/[-,]/)
+ if e
+ b = Integer(b)
+ e = Integer(e)
+ else
+ b = Integer(b) - 5
+ e = b + 9
+ end
+ end
+ previus_line = b
+ STDOUT.printf "[%d, %d] in %s\n", b, e, binding_file
+ line_at(binding_file, binding_line)
+ if lines = @scripts[binding_file] and lines != true
+ n = 0
+ b.upto(e) do |n|
+ if n > 0 && lines[n-1]
+ if ( n == binding_line )
+ STDOUT.printf "=> %d %s\n", n, lines[n-1].chomp
+ else
+ STDOUT.printf " %d %s\n", n, lines[n-1].chomp
+ end
+ end
+ end
+ else
+ STDOUT.printf "no sourcefile available for %s\n", binding_file
+ end
+
+ when /^up\s*(\d+)?$/
+ previus_line = nil
+ if $1
+ lev = Integer($1)
+ else
+ lev = 1
+ end
+ frame_pos += lev
+ if frame_pos >= @frames.size
+ frame_pos = @frames.size - 1
+ STDOUT.print "at toplevel\n"
end
- 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
- 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]
+ binding = @frames[frame_pos]
+ info, binding_file, binding_line = frame_info(frame_pos)
+ STDOUT.printf "#%d %s\n", frame_pos, info
+
+ when /^down\s*(\d+)?$/
+ previus_line = nil
+ if $1
+ lev = Integer($1)
+ else
+ lev = 1
+ end
+ frame_pos -= lev
+ if frame_pos < 0
+ frame_pos = 0
+ STDOUT.print "at stack bottom\n"
end
+ binding = @frames[frame_pos]
+ info, binding_file, binding_line = frame_info(frame_pos)
+ STDOUT.printf "#%d %s\n", frame_pos, info
- when /^f(inish)?/
- @finish_pos = @frames.size
+ when /^fi(?:nish)?$/
+ @finish_pos = @frames.size - frame_pos
+ frame_pos = 0
return
- when /^q(uit)?$/
+ when /^q(?:uit)?$/
STDOUT.print "really quit? (y/n) "
STDOUT.flush
input = STDIN.gets.chop!
@@ -217,22 +220,28 @@ class DEBUGGER__
end
end
+ def frame_info(pos = 0)
+ info = caller(0)[-(@frames.size - pos)]
+ info.sub( /:in `.*'$/, '' ) =~ /^(.*):(\d+)$/ #`
+ [info, $1, $2.to_i]
+ end
+
def line_at(file, line)
lines = @scripts[file]
if lines
- return "\n" if lines == TRUE
+ return "\n" if lines == true
line = lines[line-1]
return "\n" unless line
return line
end
save = $DEBUG
begin
- $DEBUG = FALSE
+ $DEBUG = false
f = open(file)
lines = @scripts[file] = f.readlines
rescue
$DEBUG = save
- @scripts[file] = TRUE
+ @scripts[file] = true
return "\n"
end
line = lines[line-1]
@@ -254,15 +263,14 @@ class DEBUGGER__
index = @break_points.index([file, pos])
STDOUT.printf "Breakpoint %d, %s at %s:%s\n",
index, debug_funcname(id), file, pos
- return TRUE
+ return true
end
- return FALSE
+ 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
@@ -271,11 +279,15 @@ class DEBUGGER__
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
+ case event
+ when 'line'
+ if !@no_step or @frames.size == @no_step
@stop_next -= 1
+ elsif @frames.size < @no_step
+ @stop_next = 0 # break here before leaving...
+ else
+ # nothing to do. skipped.
end
if @stop_next == 0
if [file, line] == @last
@@ -289,31 +301,26 @@ class DEBUGGER__
if check_break_points(file, line, binding, id)
debug_command(file, line, id, binding)
end
- end
- if event == 'call'
- @frames.push binding
+ when 'call'
+ @frames.unshift 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
+ when 'class'
+ @frames.unshift binding
- if event == 'return' or event == 'end'
- if @finish_pos == @frames.size
+ when 'return', 'end'
+ if @frames.size == @finish_pos
@stop_next = 1
end
- @frames.pop
- end
+ @frames.shift
- if event == 'raise'
- # @frames.push binding
+ when 'raise'
excn_handle(file, line, id, binding)
- end
+ end
@last_file = file
end
diff --git a/lib/finalize.rb b/lib/finalize.rb
index a07e67d093..3cf79ff92f 100644
--- a/lib/finalize.rb
+++ b/lib/finalize.rb
@@ -157,7 +157,7 @@ module Finalizer
# method to call finalize_* safely.
def safe
old_status = Thread.critical
- Thread.critical = TRUE
+ Thread.critical = true
ObjectSpace.remove_finalizer(@proc)
yield
ObjectSpace.add_finalizer(@proc)
diff --git a/lib/ftools.rb b/lib/ftools.rb
index 7bba07e9f1..301bff6cee 100644
--- a/lib/ftools.rb
+++ b/lib/ftools.rb
@@ -67,7 +67,7 @@ class << File
to = catname(from, to)
$stderr.print from, " -> ", to, "\n" if verbose
- if PLATFORM =~ /djgpp|cygwin|mswin32/ and FileTest.file? to
+ if RUBY_PLATFORM =~ /djgpp|cygwin|mswin32/ and FileTest.file? to
unlink to
end
fstat = stat(from)
diff --git a/lib/getopts.rb b/lib/getopts.rb
index 9e1e8a2cf6..5b9562d5b2 100644
--- a/lib/getopts.rb
+++ b/lib/getopts.rb
@@ -15,7 +15,7 @@ $RCS_ID=%q$Header$
def isSingle(lopt)
if lopt.index(":")
if lopt.split(":")[0].length == 1
- return TRUE
+ return true
end
end
return nil
@@ -87,13 +87,13 @@ def getopts(single_opts, *options)
return nil
end
setOption(compare, ARGV[1])
- opts[compare] = TRUE
+ opts[compare] = true
ARGV.shift
count += 1
break
elsif lo == compare
- setOption(compare, TRUE)
- opts[compare] = TRUE
+ setOption(compare, true)
+ opts[compare] = true
count += 1
break
end
@@ -106,19 +106,19 @@ def getopts(single_opts, *options)
for idx in 1..(ARGV[0].length - 1)
compare = ARGV[0][idx, 1]
if single_opts && compare =~ "[" + single_opts + "]"
- setOption(compare, TRUE)
- opts[compare] = TRUE
+ setOption(compare, true)
+ opts[compare] = true
count += 1
elsif single_colon != "" && compare =~ "[" + single_colon + "]"
if ARGV[0][idx..-1].length > 1
setOption(compare, ARGV[0][(idx + 1)..-1])
- opts[compare] = TRUE
+ opts[compare] = true
count += 1
elsif ARGV.length <= 1
return nil
else
setOption(compare, ARGV[1])
- opts[compare] = TRUE
+ opts[compare] = true
ARGV.shift
count += 1
end
@@ -127,7 +127,7 @@ def getopts(single_opts, *options)
end
else
compare = ARGV[0]
- opts[compare] = TRUE
+ opts[compare] = true
newargv << ARGV[0]
end
diff --git a/lib/jcode.rb b/lib/jcode.rb
index 1ed82327b8..5b5b80d797 100644
--- a/lib/jcode.rb
+++ b/lib/jcode.rb
@@ -1,6 +1,6 @@
# jcode.rb - ruby code to handle japanese (EUC/SJIS) string
-$vsave, $VERBOSE = $VERBOSE, FALSE
+$vsave, $VERBOSE = $VERBOSE, false
class String
printf STDERR, "feel free for some warnings:\n" if $VERBOSE
@@ -58,7 +58,10 @@ class String
return nil
end
+ ExpandChCache = {}
+
def _expand_ch
+ return ExpandChCache[self] if ExpandChCache.key? self
a = []
self.scan(/(.|\n)-(.|\n)|(.|\n)/) do |r|
if $3
@@ -71,6 +74,7 @@ class String
$1.upto($2) { |c| a.push c }
end
end
+ ExpandChCache[self] = a
a
end
@@ -78,7 +82,7 @@ class String
return self.delete!(from) if to.length == 0
if from =~ /^\^/
- comp=TRUE
+ comp=true
from = $'
end
afrom = from._expand_ch
@@ -109,7 +113,7 @@ class String
def delete!(del)
if del =~ /^\^/
- comp=TRUE
+ comp=true
del = $'
end
adel = del._expand_ch
@@ -133,7 +137,7 @@ class String
def squeeze!(del=nil)
if del
if del =~ /^\^/
- comp=TRUE
+ comp=true
del = $'
end
adel = del._expand_ch
@@ -161,7 +165,7 @@ class String
def tr_s!(from, to)
return self.delete!(from) if to.length == 0
if from =~ /^\^/
- comp=TRUE
+ comp=true
from = $'
end
afrom = from._expand_ch
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 265ef1337f..8d92272159 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -121,7 +121,7 @@ class Bignum
end
class Rational
- Unify = TRUE
+ Unify = true
alias power! **
@@ -304,6 +304,6 @@ module Math
end
class Complex
- Unify = TRUE
+ Unify = true
end
diff --git a/lib/matrix.rb b/lib/matrix.rb
index bca6c40c95..f5c8491146 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -39,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.
@@ -145,7 +145,7 @@
#
# INSTANCE CREATION:
# Vector.[](*array)
-# Vector.elements(array, copy = TRUE)
+# Vector.elements(array, copy = true)
# ACCSESSING:
# [](i)
# size
@@ -195,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
@@ -210,7 +210,7 @@ class Matrix
columns[j][i]
}
}
- Matrix.rows(rows, FALSE)
+ Matrix.rows(rows, false)
end
def Matrix.diagonal(*values)
@@ -221,7 +221,7 @@ class Matrix
row[j] = values[j]
row
}
- rows(rows, FALSE)
+ rows(rows, false)
end
def Matrix.scalar(n, value)
@@ -243,11 +243,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
@@ -312,13 +312,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
@@ -346,7 +346,7 @@ class Matrix
|row|
row[from_col, size_col]
}
- Matrix.rows(rows, FALSE)
+ Matrix.rows(rows, false)
end
# TESTING
@@ -364,20 +364,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
@@ -406,7 +406,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
@@ -426,7 +426,7 @@ class Matrix
vij
}
}
- return Matrix.rows(rows, FALSE)
+ return Matrix.rows(rows, false)
else
x, y = m.coerce(self)
return x * y
@@ -454,7 +454,7 @@ class Matrix
self[i, j] + m[i, j]
}
}
- Matrix.rows(rows, FALSE)
+ Matrix.rows(rows, false)
end
def -(m)
@@ -478,7 +478,7 @@ class Matrix
self[i, j] - m[i, j]
}
}
- Matrix.rows(rows, FALSE)
+ Matrix.rows(rows, false)
end
def /(other)
@@ -491,7 +491,7 @@ class Matrix
e / other
}
}
- return Matrix.rows(rows, FALSE)
+ return Matrix.rows(rows, false)
when Matrix
return self * other.inverse
else
@@ -620,10 +620,10 @@ class Matrix
begin
if (akk = a[k][k]) == 0
i = -1
- nothing = FALSE
+ nothing = false
begin
if (i += 1) > column_size - 1
- nothing = TRUE
+ nothing = true
break
end
end while a[i][k] == 0
@@ -806,10 +806,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 +854,7 @@ class Vector
# COMPARING
def ==(other)
- return FALSE unless Vector === other
+ return false unless Vector === other
other.compare_by(@elements)
end
@@ -878,7 +878,7 @@ class Vector
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 +895,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 +912,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 +939,7 @@ class Vector
|v|
yield v
}
- Vector.elements(els, FALSE)
+ Vector.elements(els, false)
end
alias map collect
@@ -948,7 +948,7 @@ class Vector
|v1, v2|
yield v1, v2
}
- Vector.elements(els, FALSE)
+ Vector.elements(els, false)
end
def r
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index d2cde95912..e35f17b772 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -6,7 +6,7 @@ require 'find'
include Config
-$found = false;
+$cache_mod = false
$lib_cache = {}
$lib_found = {}
$func_cache = {}
@@ -33,14 +33,6 @@ end
$srcdir = CONFIG["srcdir"]
$libdir = CONFIG["libdir"]+"/ruby/"+CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
$archdir = $libdir+"/"+CONFIG["arch"]
-$install = CONFIG["INSTALL_PROGRAM"]
-$install_dllib = CONFIG["INSTALL_DLLIB"]
-$install_data = CONFIG["INSTALL_DATA"]
-if $install =~ %r!^[^\s/]+/! then
- $install = CONFIG["compile_dir"]+"/"+$install
- $install_dllib = CONFIG["compile_dir"]+"/"+$install_dllib
- $install_data = CONFIG["compile_dir"]+"/"+$install_data
-end
if File.exist? $archdir + "/ruby.h"
$hdrdir = $archdir
@@ -52,12 +44,12 @@ else
end
CFLAGS = CONFIG["CFLAGS"]
-if PLATFORM == "m68k-human"
+if RUBY_PLATFORM == "m68k-human"
CFLAGS.gsub!(/-c..-stack=[0-9]+ */, '')
-elsif PLATFORM =~ /-nextstep|-rhapsody/
- CFLAGS.gsub!( /-arch\s\w*/, '' );
+elsif RUBY_PLATFORM =~ /-nextstep|-rhapsody/
+ CFLAGS.gsub!( /-arch\s\w*/, '' )
end
-if /win32|djgpp|mingw32|m68k-human|i386-os2_emx/i =~ PLATFORM
+if /win32|djgpp|mingw32|m68k-human|i386-os2_emx/i =~ RUBY_PLATFORM
$null = open("nul", "w")
else
$null = open("/dev/null", "w")
@@ -100,7 +92,6 @@ def try_cpp(src, opt="")
cfile.print src
cfile.close
begin
-
xsystem(format(CPP, $CFLAGS, opt))
ensure
system "rm -f conftest*"
@@ -134,21 +125,23 @@ def try_run(src, opt="")
end
end
-def install_rb(mfile)
+def install_rb(mfile, srcdir = nil)
+ libdir = "lib"
+ libdir = srcdir + "/" + libdir if srcdir
path = []
dir = []
- Find.find("lib") do |f|
+ Find.find(libdir) do |f|
next unless /\.rb$/ =~ f
- f = f[4..-1]
+ f = f[libdir.length+1..-1]
path.push f
dir |= File.dirname(f)
end
for f in dir
next if f == "."
- mfile.printf "\t@test -d $(libdir)/%s || mkdir $(libdir)/%s\n", f, f
+ mfile.printf "\t@$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' $(libdir)/%s\n", f
end
for f in path
- mfile.printf "\t$(INSTALL_DATA) lib/%s $(libdir)/%s\n", f, f
+ mfile.printf "\t@$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)' lib/%s $(libdir)/%s\n", f, f
end
end
@@ -157,54 +150,35 @@ def have_library(lib, func="main")
STDOUT.flush
if $lib_cache[lib]
if $lib_cache[lib] == "yes"
- if $libs
- $libs = "-l" + lib + " " + $libs
- else
- $libs = "-l" + lib
- end
+ $libs = "-l" + lib + " " + $libs
print "(cached) yes\n"
- return TRUE
+ return true
else
print "(cached) no\n"
- return FALSE
+ return false
end
end
if func && func != ""
- cfile = open("conftest.c", "w")
- cfile.printf "\
-int main() { return 0; }
-int t() { %s(); return 0; }
-", func
- cfile.close
-
- if $libs
- libs = "-l" + lib + " " + $libs
- else
- libs = "-l" + lib
- end
+ libs = "-l" + lib + " " + $libs
unless try_link(<<"SRC", libs)
int main() { return 0; }
int t() { #{func}(); return 0; }
SRC
$lib_cache[lib] = 'no'
- $cache_mod = TRUE
+ $cache_mod = true
print "no\n"
- return FALSE
+ return false
end
else
- if $libs
- libs = "-l" + lib + " " + $libs
- else
- libs = "-l" + lib
- end
+ libs = "-l" + lib + " " + $libs
end
$libs = libs
$lib_cache[lib] = 'yes'
- $cache_mod = TRUE
+ $cache_mod = true
print "yes\n"
- return TRUE
+ return true
end
def have_func(func)
@@ -214,15 +188,14 @@ def have_func(func)
if $func_cache[func] == "yes"
$defs.push(format("-DHAVE_%s", func.upcase))
print "(cached) yes\n"
- return TRUE
+ return true
else
print "(cached) no\n"
- return FALSE
+ return false
end
end
libs = $libs
- libs = "" if libs == nil
unless try_link(<<"SRC", libs)
char #{func}();
@@ -230,15 +203,15 @@ int main() { return 0; }
int t() { #{func}(); return 0; }
SRC
$func_found[func] = 'no'
- $found = TRUE
+ $cache_mod = true
print "no\n"
- return FALSE
+ return false
end
$defs.push(format("-DHAVE_%s", func.upcase))
$func_found[func] = 'yes'
- $found = TRUE
+ $cache_mod = true
print "yes\n"
- return TRUE
+ return true
end
def have_header(header)
@@ -249,10 +222,10 @@ def have_header(header)
header.tr!("a-z./\055", "A-Z___")
$defs.push(format("-DHAVE_%s", header))
print "(cached) yes\n"
- return TRUE
+ return true
else
print "(cached) no\n"
- return FALSE
+ return false
end
end
@@ -260,20 +233,20 @@ def have_header(header)
#include <#{header}>
SRC
$hdr_found[header] = 'no'
- $found = TRUE
+ $cache_mod = true
print "no\n"
- return FALSE
+ return false
end
$hdr_found[header] = 'yes'
header.tr!("a-z./\055", "A-Z___")
$defs.push(format("-DHAVE_%s", header))
- $found = TRUE
+ $cache_mod = true
print "yes\n"
- return TRUE
+ return true
end
def arg_config(config, default=nil)
- return default if /mswin32/i =~ PLATFORM
+ return default if /mswin32/i =~ RUBY_PLATFORM
unless defined? $configure_args
$configure_args = {}
for arg in CONFIG["configure_args"].split + ARGV
@@ -318,25 +291,33 @@ def create_header()
end
end
-def create_makefile(target)
+def create_makefile(target, installpos = "")
print "creating Makefile\n"
system "rm -f conftest*"
STDOUT.flush
- if $libs and CONFIG["DLEXT"] == "o"
+ if CONFIG["DLEXT"] == "o"
libs = $libs.split
for lib in libs
lib.sub!(/-l(.*)/, '"lib\1.a"')
end
$defs.push(format("-DEXTLIB='%s'", libs.join(",")))
end
- $libs = "" unless $libs
$DLDFLAGS = CONFIG["DLDFLAGS"]
- if PLATFORM =~ /beos/
+ if RUBY_PLATFORM =~ /beos/
$libs = $libs + " -lruby"
$DLDFLAGS = $DLDFLAGS + " -L" + CONFIG["prefix"] + "/lib"
end
+ defflag = ''
+ if RUBY_PLATFORM =~ /cygwin/
+ if File.exist? target + ".def"
+ defflag = "--def=" + target + ".def"
+ end
+ $libs = $libs + " " + CONFIG["LIBRUBYARG"]
+ $DLDFLAGS = $DLDFLAGS + " -L$(topdir)"
+ end
+
unless $objs then
$objs = Dir["*.{c,cc,m}"]
for f in $objs
@@ -360,7 +341,7 @@ CC = #{CONFIG["CC"]}
CFLAGS = #{CONFIG["CCDLFLAGS"]} -I$(hdrdir) -I#{CONFIG["includedir"]} #{CFLAGS} #{$CFLAGS} #{$defs.join(" ")}
CXXFLAGS = $(CFLAGS)
DLDFLAGS = #{$DLDFLAGS} #{$LDFLAGS}
-LDSHARED = #{CONFIG["LDSHARED"]}
+LDSHARED = #{CONFIG["LDSHARED"]} #{defflag}
prefix = #{CONFIG["prefix"]}
exec_prefix = #{CONFIG["exec_prefix"]}
@@ -376,15 +357,13 @@ OBJS = #{$objs}
TARGET = #{target}
DLLIB = $(TARGET).#{CONFIG["DLEXT"]}
-INSTALL = #{$install}
-INSTALL_DLLIB = #{$install_dllib}
-INSTALL_DATA = #{$install_data}
+RUBY = #{CONFIG["ruby_install_name"]}
binsuffix = #{CONFIG["binsuffix"]}
all: $(DLLIB)
-clean:; @rm -f *.o *.so *.sl *.a
+clean:; @rm -f *.o *.so *.sl *.a $(DLLIB)
@rm -f Makefile extconf.h conftest.*
@rm -f core ruby$(binsuffix) *~
@@ -393,9 +372,8 @@ realclean: clean
install: $(archdir)/$(DLLIB)
$(archdir)/$(DLLIB): $(DLLIB)
- @test -d $(libdir) || mkdir $(libdir)
- @test -d $(archdir) || mkdir $(archdir)
- $(INSTALL_DLLIB) $(DLLIB) $(archdir)/$(DLLIB)
+ @$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' $(libdir) $(archdir)
+ @$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' $(DLLIB) $(archdir)/$(DLLIB)
EOMF
install_rb(mfile)
mfile.printf "\n"
@@ -407,7 +385,7 @@ $(DLLIB): $(OBJS)
EOMF
elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc")
mfile.print "$(DLLIB): $(OBJS)\n"
- case PLATFORM
+ case RUBY_PLATFORM
when "m68k-human"
mfile.printf "ar cru $(DLLIB) $(OBJS)\n"
else
@@ -425,7 +403,7 @@ EOMF
end
mfile.close
- if $found
+ if $cache_mod
begin
f = open($config_cache, "w")
for k,v in $lib_cache
@@ -451,16 +429,21 @@ EOMF
end
end
- if PLATFORM =~ /beos/
- print "creating ruby.def\n"
- open("ruby.def", "w") do |file|
- file.print("EXPORTS\n") if PLATFORM =~ /^i/
+ if RUBY_PLATFORM =~ /beos/
+ if RUBY_PLATFORM =~ /^powerpc/ then
+ deffilename = "ruby.exp"
+ else
+ deffilename = "ruby.def"
+ end
+ print "creating #{deffilename}\n"
+ open(deffilename, "w") do |file|
+ file.print("EXPORTS\n") if RUBY_PLATFORM =~ /^i/
file.print("Init_#{target}\n")
end
end
end
-$libs = PLATFORM =~ /cygwin32|beos|rhapsody|nextstep/ ? nil : "-lc"
+$libs = RUBY_PLATFORM =~ /cygwin|beos|openstep|nextstep|rhapsody/ ? "" : "-lc"
$objs = nil
$LOCAL_LIBS = ""
$CFLAGS = ""
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
index ed773b78d2..e0fcf0f209 100644
--- a/lib/mutex_m.rb
+++ b/lib/mutex_m.rb
@@ -67,33 +67,33 @@ module Mutex_m
end
def mu_try_lock
- result = FALSE
- Thread.critical = TRUE
+ result = false
+ Thread.critical = true
unless @mu_locked
- @mu_locked = TRUE
- result = TRUE
+ @mu_locked = true
+ result = true
end
- Thread.critical = FALSE
+ Thread.critical = false
result
end
def mu_lock
- while (Thread.critical = TRUE; @mu_locked)
+ while (Thread.critical = true; @mu_locked)
@mu_waiting.push Thread.current
Thread.stop
end
- @mu_locked = TRUE
- Thread.critical = FALSE
+ @mu_locked = true
+ Thread.critical = false
self
end
def mu_unlock
return unless @mu_locked
- Thread.critical = TRUE
+ Thread.critical = true
wait = @mu_waiting
@mu_waiting = []
- @mu_locked = FALSE
- Thread.critical = FALSE
+ @mu_locked = false
+ Thread.critical = false
for w in wait
w.run
end
@@ -105,7 +105,7 @@ module Mutex_m
def initialize(*args)
ret = super
@mu_waiting = []
- @mu_locked = FALSE;
+ @mu_locked = false;
return ret
end
end
diff --git a/lib/observer.rb b/lib/observer.rb
index 5928367a7d..0c74b49750 100644
--- a/lib/observer.rb
+++ b/lib/observer.rb
@@ -23,7 +23,7 @@ module Observable
0
end
end
- def changed(state=TRUE)
+ def changed(state=true)
@observer_state = state
end
def changed?
@@ -36,7 +36,7 @@ module Observable
i.update(*arg)
end
end
- @observer_state = FALSE
+ @observer_state = false
end
end
end
diff --git a/lib/shellwords.rb b/lib/shellwords.rb
index 9154cd84c1..60996be17c 100644
--- a/lib/shellwords.rb
+++ b/lib/shellwords.rb
@@ -17,7 +17,7 @@ module Shellwords
words = []
while line != ''
field = ''
- while TRUE
+ while true
if line.sub! /^"(([^"\\]|\\.)*)"/, '' then #"
snippet = $1
snippet.gsub! /\\(.)/, '\1'
diff --git a/lib/telnet.rb b/lib/telnet.rb
index ac624fd257..5a0ae40443 100644
--- a/lib/telnet.rb
+++ b/lib/telnet.rb
@@ -1,33 +1,33 @@
=begin
-$Date: 1999/06/29 09:08:51 $
+$Date: 1999/07/16 13:39:42 $
== SIMPLE TELNET CLIANT LIBRARY
telnet.rb
-Version 0.22
+Version 0.231
Wakou Aoyama <wakou@fsinet.or.jp>
=== MAKE NEW TELNET OBJECT
- host = Telnet.new({"Binmode" => FALSE, # default: FALSE
+ host = Telnet.new({"Binmode" => false, # default: false
"Host" => "localhost", # default: "localhost"
"Output_log" => "output_log", # default: not output
"Dump_log" => "dump_log", # default: not output
"Port" => 23, # default: 23
"Prompt" => /[$%#>] \z/n, # default: /[$%#>] \z/n
- "Telnetmode" => TRUE, # default: TRUE
+ "Telnetmode" => true, # default: true
"Timeout" => 10, # default: 10
- # if ignore timeout then set "Timeout" to FALSE.
+ # if ignore timeout then set "Timeout" to false.
"Waittime" => 0, # default: 0
"Proxy" => proxy}) # default: nil
# proxy is Telnet or TCPsocket object
Telnet object has socket class methods.
-if set "Telnetmode" option FALSE. not TELNET command interpretation.
+if set "Telnetmode" option to false. not telnet command interpretation.
"Waittime" is time to confirm "Prompt". There is a possibility that
the same character as "Prompt" is included in the data, and, when
the network or the host is very heavy, the value is enlarged.
@@ -50,9 +50,9 @@ example
line = host.waitfor({"Match" => /match/,
"String" => "string",
"Timeout" => secs})
- # if ignore timeout then set "Timeout" to FALSE.
+ # if ignore timeout then set "Timeout" to false.
-if set "String" option. Match = Regexp.new(quote(string))
+if set "String" option, then Match == Regexp.new(quote("string"))
==== REALTIME OUTPUT
@@ -62,7 +62,7 @@ if set "String" option. Match = Regexp.new(quote(string))
"String" => "string",
"Timeout" => secs}){|c| print c}
-of cource, set sync=TRUE or flush is necessary.
+of cource, set sync=true or flush is necessary.
=== SEND STRING AND WAIT PROMPT
@@ -80,7 +80,7 @@ of cource, set sync=TRUE or flush is necessary.
"Prompt" => /[$%#>] \z/n,
"Timeout" => 10}){|c| print c }
-of cource, set sync=TRUE or flush is necessary.
+of cource, set sync=true or flush is necessary.
=== SEND STRING
@@ -91,15 +91,15 @@ of cource, set sync=TRUE or flush is necessary.
=== TURN TELNET COMMAND INTERPRETATION
host.telnetmode # turn on/off
- host.telnetmode(TRUE) # on
- host.telnetmode(FALSE) # off
+ host.telnetmode(true) # on
+ host.telnetmode(false) # off
=== TOGGLE NEWLINE TRANSLATION
- host.binmode # turn TRUE/FALSE
- host.binmode(TRUE) # no translate newline
- host.binmode(FALSE) # translate newline
+ host.binmode # turn true/false
+ host.binmode(true) # no translate newline
+ host.binmode(false) # translate newline
=== LOGIN
@@ -119,7 +119,7 @@ of cource, set sync=TRUE or flush is necessary.
"Prompt" => /[$%#>] \z/n,
"Timeout" => 10}){|c| print c }
-of cource, set sync=TRUE or flush is necessary.
+of cource, set sync=true or flush is necessary.
== EXAMPLE
@@ -138,7 +138,7 @@ of cource, set sync=TRUE or flush is necessary.
pop = Telnet.new({"Host" => "your_destination_host_here",
"Port" => 110,
- "Telnetmode" => FALSE,
+ "Telnetmode" => false,
"Prompt" => /^\+OK/n})
pop.cmd("user " + "your_username_here"){|c| print c}
pop.cmd("pass " + "your_password_here"){|c| print c}
@@ -147,11 +147,23 @@ of cource, set sync=TRUE or flush is necessary.
== HISTORY
+=== Version 0.231
+
+1999/07/16 13:39:42
+
+- TRUE --> true, FALSE --> false
+
+=== Version 0.23
+
+1999/07/15 22:32:09
+
+- waitfor: if end of file reached, then return nil.
+
=== Version 0.22
1999/06/29 09:08:51
-- new, waitfor, cmd: {"Timeout" => FALSE} # ignore timeout
+- new, waitfor, cmd: {"Timeout" => false} # ignore timeout
=== Version 0.21
@@ -350,31 +362,31 @@ class Telnet < SimpleDelegator
EOL = CR + LF
v = $-v
$-v = false
- VERSION = "0.22"
- RELEASE_DATE = "$Date: 1999/06/29 09:08:51 $"
+ VERSION = "0.231"
+ RELEASE_DATE = "$Date: 1999/07/16 13:39:42 $"
$-v = v
def initialize(options)
@options = options
- @options["Binmode"] = FALSE unless @options.key?("Binmode")
+ @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["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 }
+ @telnet_option = { "SGA" => false, "BINARY" => false }
if @options.key?("Output_log")
@log = File.open(@options["Output_log"], 'a+')
- @log.sync = TRUE
+ @log.sync = true
@log.binmode
end
if @options.key?("Dump_log")
@dumplog = File.open(@options["Dump_log"], 'a+')
- @dumplog.sync = TRUE
+ @dumplog.sync = true
@dumplog.binmode
end
@@ -393,7 +405,7 @@ $-v = v
@dumplog.write(message) if @options.key?("Dump_log")
begin
- if @options["Timeout"] == FALSE
+ if @options["Timeout"] == false
@sock = TCPsocket.open(@options["Host"], @options["Port"])
else
timeout(@options["Timeout"]){
@@ -407,7 +419,7 @@ $-v = v
@dumplog.write($!.to_s + "\n") if @options.key?("Dump_log")
raise
end
- @sock.sync = TRUE
+ @sock.sync = true
@sock.binmode
message = "Connected to " + @options["Host"] + ".\n"
@@ -423,17 +435,17 @@ $-v = v
def telnetmode(mode = 'turn')
if 'turn' == mode
- @options["Telnetmode"] = @options["Telnetmode"] ? FALSE : TRUE
+ @options["Telnetmode"] = @options["Telnetmode"] ? false : true
else
- @options["Telnetmode"] = mode ? TRUE : FALSE
+ @options["Telnetmode"] = mode ? true : false
end
end
def binmode(mode = 'turn')
if 'turn' == mode
- @options["Binmode"] = @options["Binmode"] ? FALSE : TRUE
+ @options["Binmode"] = @options["Binmode"] ? false : true
else
- @options["Binmode"] = mode ? TRUE : FALSE
+ @options["Binmode"] = mode ? true : false
end
end
@@ -449,7 +461,7 @@ $-v = v
# respond to "IAC DO x"
str.gsub!(/([^#{IAC}]?)#{IAC}#{DO}([#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}])/no){
if OPT_BINARY == $2
- @telnet_option["BINARY"] = TRUE
+ @telnet_option["BINARY"] = true
@sock.write(IAC + WILL + OPT_BINARY)
else
@sock.write(IAC + WONT + $2)
@@ -468,7 +480,7 @@ $-v = v
if OPT_ECHO == $2
@sock.write(IAC + DO + OPT_ECHO)
elsif OPT_SGA == $2
- @telnet_option["SGA"] = TRUE
+ @telnet_option["SGA"] = true
@sock.write(IAC + DO + OPT_SGA)
end
$1
@@ -479,7 +491,7 @@ $-v = v
if OPT_ECHO == $2
@sock.write(IAC + DONT + OPT_ECHO)
elsif OPT_SGA == $2
- @telnet_option["SGA"] = FALSE
+ @telnet_option["SGA"] = false
@sock.write(IAC + DONT + OPT_SGA)
end
$1
@@ -514,7 +526,7 @@ $-v = v
prompt = options
end
- if time_out == FALSE
+ if time_out == false
time_out = nil
end
@@ -524,19 +536,27 @@ $-v = v
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
+ 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
- end
- @log.print(buf) if @options.key?("Output_log")
- yield buf if iterator?
- line.concat(buf)
- buf = ''
+ @log.print(buf) if @options.key?("Output_log")
+ yield buf if iterator?
+ line.concat(buf)
+ buf = ''
+ rescue EOFError # End of file reached
+ if line == ''
+ line = nil
+ yield nil if iterator?
+ end
+ break
+ end
end
line
end
@@ -575,7 +595,7 @@ $-v = v
end
IO::select(nil, [@sock])
- print(string)
+ self.print(string)
if iterator?
waitfor({"Prompt" => match, "Timeout" => time_out}){|c| yield c }
else
diff --git a/lib/thread.rb b/lib/thread.rb
index 39c3e025f3..22610f2992 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -62,10 +62,10 @@ class Mutex
def unlock
return unless @locked
- Thread.critical = TRUE
+ Thread.critical = true
t = @waiting.shift
- @locked = FALSE
- Thread.critical = FALSE
+ @locked = false
+ Thread.critical = false
t.run if t
self
end
@@ -192,14 +192,14 @@ class SizedQueue<Queue
end
def max=(max)
- Thread.critical = TRUE
+ Thread.critical = true
if @max >= max
@max = max
- Thread.critical = FALSE
+ Thread.critical = false
else
diff = max - @max
@max = max
- Thread.critical = FALSE
+ Thread.critical = false
diff.times do
t = @queue_wait.shift
t.run if t