diff -ur rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/net.lib.rb rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/net.lib.rb
--- rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/net.lib.rb 2004-05-05 23:40:17.000000000 +0200
+++ rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/net.lib.rb 2004-05-15 11:16:23.000000000 +0200
@@ -25,6 +25,53 @@
s
end
+class TCPServer
+ def self.freeport(from, to)
+ res = nil
+ port = from
+
+ while res.nil? and port <= to
+ begin
+ #evtimeout(0.1) do
+ io = TCPSocket.new("localhost", port)
+ io.close
+ #end
+
+ port += 1
+ rescue
+ res = port
+ end
+ end
+
+ return res
+ end
+
+ def self.usedports(from, to)
+ threads = []
+ res = []
+
+ from.upto(to) do |port|
+ threads << Thread.new do
+ begin
+ io = TCPSocket.new("localhost", port)
+ io.close
+
+ port
+ rescue
+ nil
+ end
+ end
+ end
+
+ threads.each do |thread|
+ port = thread.value
+ res << port unless port.nil?
+ end
+
+ return res
+ end
+end
+
class EVURI
attr_reader :protocol
attr_writer :protocol
@@ -472,40 +519,41 @@
if not server.nil?
loop do
- io = nil
-
- begin
- io = server.accept
+ io = server.accept
- req = Request.new(io)
- resp = Response.new(io)
- rescue NameError, StandardError => e
- puts "Getting request from browser failed. (%s)" % e.class.to_s
- io = nil
- end
+ catch :rwd_io_error do
+ begin
+ req = Request.new(io)
+ resp = Response.new(io)
+ rescue
+ throw :rwd_io_error
+ end
- if not io.nil? and not req.peeraddr.nil?
- #Thread.new(req, resp) do |req, resp|
- com = req.request.to_s.strip + req.peeraddr[3]
+ begin
+ ip = req.peeraddr[3]
+ com = req.request.to_s.strip + ip
+ rescue NameError
+ throw :rwd_io_error
+ end
+ if (not remote) or (remote and (auth.nil? or auth.empty? or authenticate(auth, realm, req, resp)))
@@times[com]=Time.new.to_f if not @@times.include?(com)
- if (not remote) or (remote and (auth.nil? or auth.empty? or authenticate(auth, realm, req, resp)))
- #puts "#{Time.new.strftime("%H:%M:%S")}: #{req.peeraddr[3]}: #{((Time.new.to_f - @@times[com]).to_s + "0"*4)[0..4]}: > #{req.request}"
+ #puts "#{Time.new.strftime("%H:%M:%S")}: #{ip}: #{((Time.new.to_f - @@times[com]).to_s + "0"*4)[0..4]}: > #{req.request}"
+
+ yield(req, resp)
- yield(req, resp)
+ puts "#{Time.new.strftime("%H:%M:%S")}: #{ip}: #{((Time.new.to_f - @@times[com]).to_s + "0"*4)[0..4]}: < #{req.request}"
- puts "#{Time.new.strftime("%H:%M:%S")}: #{req.peeraddr[3]}: #{((Time.new.to_f - @@times[com]).to_s + "0"*4)[0..4]}: < #{req.request}"
+ @@times.delete(com)
+ end
- @@times.delete(com)
- end
-
- begin
- resp.flush
- rescue NameError, StandardError
- end
- #end
- end
+ begin
+ resp.flush
+ rescue
+ throw :rwd_io_error
+ end
+ end
end
end
end
diff -ur rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/ruby.lib.rb rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/ruby.lib.rb
--- rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/ruby.lib.rb 2004-05-05 23:40:17.000000000 +0200
+++ rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/ruby.lib.rb 2004-05-15 11:16:23.000000000 +0200
@@ -95,9 +95,17 @@
DRbObject.new(nil, "druby://localhost:3100").speak(self)
end
- def splitblocks(begindelimiters, enddelimiter)
- bd = begindelimiters.collect {|s| Regexp.escape(s)}
- ed = enddelimiter.collect {|s| Regexp.escape(s)}
+ def splitblocks(*delimiters)
+ begindelimiters = []
+ enddelimiters = []
+
+ delimiters.each do |k, v|
+ begindelimiters << k
+ enddelimiters << v
+ end
+
+ bd = begindelimiters.collect {|s| Regexp.escape(s)}
+ ed = enddelimiters.collect {|s| Regexp.escape(s)}
be = bd.join("|")
ee = ed.join("|")
@@ -106,14 +114,14 @@
type = 0
tmp = ""
es = ""
+
self.split(/(#{be}|#{ee})/).each do |s|
if type == 0
if begindelimiters.include?(s)
type = begindelimiters.index(s)+1
tmp = s
- es = enddelimiter[begindelimiters.index(s)]
+ es = enddelimiters[begindelimiters.index(s)]
else
- #res << [0, s] if not s.compress.empty?
res << [0, s] if not s.empty?
end
else
@@ -127,13 +135,17 @@
end
end
end
- res
+
+ res << [0, tmp] if not tmp.empty?
+
+ return res
end
- def splitwords(tokens=[], begindelimiters=["´", ´"´], enddelimiter=["´", ´"´])
+ def splitwords(tokens=[])
tokens = [tokens] if not tokens.kind_of?(Array)
res = []
- self.splitblocks(begindelimiters, enddelimiter).each do |type, s|
+
+ self.splitblocks(["´", "´"], [´"´, ´"´]).each do |type, s|
case type
when 0
tokens.each do |token|
@@ -148,18 +160,20 @@
res << s[1..-2]
end
end
- res
+
+ return res
end
def uncomment
res = []
- self.splitblocks( ["´" , ´"´ , "/*" , "<!--" , "#" , ";" ],
- ["´" , ´"´ , "*/" , "-->" , "\n", "\n"]).each do |type, s|
+
+ self.splitblocks(["´", "´"], [´"´, ´"´], ["/*", "*/"], ["<!--", "-->"], ["#", "\n"]).each do |type, s|
case type
when 0, 1, 2 then res << s
when 3, 4, 5
end
end
+
res.join("")
end
diff -ur rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/rwd.lib.rb rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/rwd.lib.rb
--- rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/rwd.lib.rb 2004-05-05 23:40:17.000000000 +0200
+++ rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/rwd.lib.rb 2004-05-15 11:16:23.000000000 +0200
@@ -12,8 +12,7 @@
$".push "win32/registry.rb"
end
-exit if ARGV.include?("--rwd-exit") # Hack ???
-
+$rwd_exit = ARGV.include?("--rwd-exit") # Hack ???
$rwd_debug = ($rwd_debug or false)
$rwd_border = ($rwd_border or 0)
@@ -31,68 +30,29 @@
Format = "\n<!-- %-10s %-10s -->\t"
-if not rcfile.nil?
+unless rcfile.nil?
puts "Reading #{rcfile} ..."
Hash.file(rcfile).each do |k, v|
ENV[k] = v
end
-else
- if not ENV.include?("RWDBROWSER")
- begin
- puts "Looking for default browser..."
- Win32::Registry::HKEY_CLASSES_ROOT.open(´htmlfile\shell\open\command´) do |reg|
- ENV["RWDBROWSER"] = reg[""]
- end
- rescue NameError
- puts "Not found."
- end
- end
-
- if not ENV.include?("RWDBROWSER") and false # ???
- s = ENV["HOME"] ; s = s + "/.rwdrc" if not s.nil? ; rcfile = s if (not s.nil? and rcfile.nil?)
- s = ENV["USERPROFILE"] ; s = s + "/rwd.cfg" if not s.nil? ; rcfile = s if (not s.nil? and rcfile.nil?)
- s = ENV["windir"] ; s = s + "/rwd.cfg" if not s.nil? ; rcfile = s if (not s.nil? and rcfile.nil?)
-
- if not rcfile.nil?
- puts "Creating #{rcfile} ..."
- puts ""
- puts "# This is the first time you start a RubyWebDialog application."
- puts "# I have to know your favorite browser."
- puts "# "
- puts "# Put the full path to your favorite browser between the quotes"
- puts "# (\"...\") after RWDBROWSER= and remove the hash (#) at the"
- puts "# beginning of the line."
- puts "# "
- puts "# Restart your application."
- puts ""
-
- File.open(rcfile, "a") do |f|
- f.puts "# This is the first time you start a RubyWebDialog application."
- f.puts "# I have to know your favorite browser."
- f.puts "# "
- f.puts "# Put the full path to your favorite browser between the quotes"
- f.puts "# (\"...\") after RWDBROWSER= and remove the hash (#) at the"
- f.puts "# beginning of the line."
- f.puts "# "
- f.puts "# Restart your application."
- f.puts ""
- f.puts "#RWDBROWSER=\"...\""
- end
- end
-
- if windows?
- system("notepad #{rcfile}")
+end
- sleep 1
- else
- puts "Please edit #{rcfile}."
+unless ENV.include?("RWDBROWSER")
+ begin
+ puts "Looking for default browser..."
+ Win32::Registry::HKEY_CLASSES_ROOT.open(´htmlfile\shell\open\command´) do |reg|
+ ENV["RWDBROWSER"] = reg[""]
end
-
- exit
+ rescue NameError
+ puts "Not found."
end
end
+unless ENV.include?("RWDPORTS")
+ ENV["RWDPORTS"] = "7701-7709"
+end
+
trap("INT") {puts "Terminating..." ; exit}
$SAFE = 2
@@ -155,7 +115,7 @@
res = ""
res = res + "<row valign=´top´>"
- res = res + "<radio name=´#{key.to_html}´ value=´#{value.to_html}´/>" if not key.nil?
+ res = res + "<radio name=´#{key.to_html}´ value=´#{value.to_html}´/>" unless key.nil?
res = res + self.collect{|s| "<p align=´left´>#{s.to_html}</p>"}.join("")
res = res + "</row>"
@@ -212,11 +172,11 @@
end
class Hash
- def rwd_table(field, joinwith=@sep, headers=nil)
+ def rwd_table(field=nil, joinwith=nil, headers=nil)
res = []
res << "<table>"
- res << headers.rwd_headers(true) if not headers.nil?
+ res << headers.rwd_headers((not field.nil?)) if not headers.nil?
self.keys.numsort.each do |key|
key2 = key
value2 = self[key]
@@ -233,8 +193,8 @@
end
class EVTable
- def rwd_table(key, joinwith)
- super(key, joinwith, @headers)
+ def rwd_table(field=nil, joinwith=@sep)
+ super(field, joinwith, @headers)
end
def rwd_form(prefix="", key=nil, twoparts=false)
@@ -685,9 +645,19 @@
new(File.new(rwdfile).readlines, *args)
end
- def serve(port=1234, auth=nil, realm=self.class.to_s)
+ def serve(port=nil, auth=nil, realm=self.class.to_s)
+ exit if $rwd_exit
+
raise "RWD is not initialized." if @rwd_xml.nil?
+ low, high = ENV["RWDPORTS"].split(/[^\d+]/)
+ high = low if high.nil?
+ low, high = low.to_i, high.to_i
+
+ port = TCPServer.freeport(low, high) if port.nil?
+ raise "No free TCP port." if port.nil?
+ port = port.to_i
+
@rwd_server = RWDServer.new(self, port, auth, realm)
end
@@ -950,11 +920,11 @@
#@ie = IE.new("http://localhost:#{port}/")
#else
if windows?
- system("#{ENV["RWDBROWSER"]} \"http://localhost:#{port}/\"")
+ system("#{ENV["RWDBROWSER"]} \"http://localhost:#{port}/\"".gsub(/%port%/, port.to_s))
elsif cygwin?
- system("#{ENV["RWDBROWSER"].gsub(/\\/, "/").gsub(/ /, "\ ")} \"http://localhost:#{port}/\"")
+ system("#{ENV["RWDBROWSER"].gsub(/\\/, "/").gsub(/ /, "\ ")} \"http://localhost:#{port}/\"".gsub(/%port%/, port.to_s))
else
- system("#{ENV["RWDBROWSER"]} \"http://localhost:#{port}/\"")
+ system("#{ENV["RWDBROWSER"]} \"http://localhost:#{port}/\"".gsub(/%port%/, port.to_s))
end
#end
diff -ur rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/sgml.lib.rb rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/sgml.lib.rb
--- rubywebdialogs-0.0.8.tar.gz/rubywebdialogs/lib/sgml.lib.rb 2004-05-05 23:40:17.000000000 +0200
+++ rubywebdialogs-0.0.9.tar.gz/rubywebdialogs/lib/sgml.lib.rb 2004-05-15 11:16:23.000000000 +0200
@@ -122,7 +122,7 @@
def buildobjects(string)
@objects = []
- string.splitblocks(["<!--", "<!", "<?", "<"], ["-->", ">", "?>", ">"]).each do |type, s|
+ string.splitblocks(["<!--", "-->"], ["<!", ">"], ["<?", "?>"], ["<", ">"]).each do |type, s|
case type
when 0 then @objects << Text.new(s)
when 1 then @objects << Comment.new(s)
@@ -156,7 +156,7 @@
def verwerktag2(string)
a = []
- string.splitblocks(["´", ´"´], ["´", ´"´]).collect do |type, s|
+ string.splitblocks(["´", "´"], [´"´, ´"´]).collect do |type, s|
case type
when 0
if self.class.to_s == "HTML"