From 9e48333190cb95ecd4d8a49eed103518457e8ace Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 27 Apr 1998 10:04:11 +0000 Subject: tcltklib/gtk git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/telnet.rb | 52 +++++++++++++++++++-------------------- lib/tk.rb | 79 ++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 72 insertions(+), 59 deletions(-) (limited to 'lib') diff --git a/lib/telnet.rb b/lib/telnet.rb index e93c2aaa8e..44fda9e41a 100644 --- a/lib/telnet.rb +++ b/lib/telnet.rb @@ -4,54 +4,54 @@ # Wakou Aoyama # # == make new Telnet object -# host = Telnet.new({"Binmode" => TRUE, default: TRUE -# "Host" => "localhost", default: "localhost" -# "Output_log"] => "output_log", default: not output -# "Port" => 23, default: 23 -# "Prompt" => /[$%#>] $/, default: /[$%#>] $/ -# "Telnetmode"] => TRUE, default: TRUE -# "Timeout"] => 10} default: 10 +# host = Telnet.new("Binmode" => TRUE, default: TRUE +# "Host" => "localhost", default: "localhost" +# "Output_log" => "output_log", default: not output +# "Port" => 23, default: 23 +# "Prompt" => /[$%#>] $/, default: /[$%#>] $/ +# "Telnetmode" => TRUE, default: TRUE +# "Timeout" => 10) default: 10 # # if set "Telnetmode" option FALSE. not TELNET command interpretation. # # == wait for match # print host.waitfor(/match/) -# print host.waitfor({"Match" => /match/, -# "String" => "string", -# "Timeout" => secs}) +# print host.waitfor("Match" => /match/, +# "String" => "string", +# "Timeout" => secs) # if set "String" option. Match = Regexp.new(quote(string)) # # realtime output. of cource, set sync=TRUE or flush is necessary. # host.waitfor(/match/){|c| print c } -# host.waitfor({"Match" => /match/, -# "String" => "string", -# "Timeout" => secs}){|c| print c} +# host.waitfor("Match" => /match/, +# "String" => "string", +# "Timeout" => secs){|c| print c} # # == send string and wait prompt # print host.cmd("string") -# print host.cmd({"String" => "string", -# "Prompt" => /[$%#>] $//, -# "Timeout" => 10}) +# print host.cmd("String" => "string", +# "Prompt" => /[$%#>] $//, +# "Timeout" => 10) # # realtime output. of cource, set sync=TRUE or flush is necessary. # host.cmd("string"){|c| print c } -# host.cmd({"String" => "string", -# "Prompt" => /[$%#>] $//, -# "Timeout" => 10}){|c| print c } +# host.cmd("String" => "string", +# "Prompt" => /[$%#>] $//, +# "Timeout" => 10){|c| print c } # # == login # host.login("username", "password") -# host.login({"Name" => "username", -# "Password" => "password", -# "Prompt" => /[$%#>] $/, -# "Timeout" => 10}) +# host.login("Name" => "username", +# "Password" => "password", +# "Prompt" => /[$%#>] $/, +# "Timeout" => 10) # # and Telnet object has socket class methods # # == sample -# localhost = Telnet.new({"Host" => "localhost", -# "Timeout" => 10, -# "Prompt" => /[$%#>] $/}) +# localhost = Telnet.new("Host" => "localhost", +# "Timeout" => 10, +# "Prompt" => /[$%#>] $/) # localhost.login("username", "password") # print localhost.cmd("command") # localhost.close diff --git a/lib/tk.rb b/lib/tk.rb index 08a146b8be..8c361c03e5 100644 --- a/lib/tk.rb +++ b/lib/tk.rb @@ -48,8 +48,9 @@ module TkComm end def tk_split_list(str) + return [] if str == "" idx = str.index('{') - return tk_tcl2ruby(str) if not idx + return tk_tcl2ruby(str) unless idx list = tk_tcl2ruby(str[0,idx]) str = str[idx+1..-1] @@ -112,7 +113,8 @@ module TkComm end end def list(val) - tk_split_list(val) + p val + tk_split_list(val).to_a end def window(val) Tk_WINDOWS[val] @@ -260,7 +262,7 @@ module TkCore extend TkComm INTERP = TclTkIp.new - INTERP._eval("proc rb_out {args} { ruby [format \"TkCore.callback %%Q!%s!\" $args] }") + INTERP._invoke("proc", "rb_out", "args", "ruby [format \"TkCore.callback %%Q!%s!\" $args]") def TkCore.callback(arg) arg = Array(tk_split_list(arg)) @@ -271,36 +273,35 @@ module TkCore TclTkLib.mainloop end - def _get_eval_string(*args) - argstr = "" - args.each{|arg| - next if arg == None - if arg.kind_of?(Hash) - str = hash_kv(arg).join(" ") - elsif arg == nil - str = "" - elsif arg == false - str = "0" - elsif arg == true - str = "1" - elsif (arg.respond_to?(:to_eval)) - str = arg.to_eval() - else - str = arg.to_s() - end - argstr += " " if argstr != "" - argstr += '"' + str.gsub(/[][$"]/, '\\\\\&') + '"' #' - } - return argstr + def _get_eval_string(str) + return str if str == None + if str.kind_of?(Hash) + str = hash_kv(str).join(" ") + elsif str == nil + str = "" + elsif str == false + str = "0" + elsif str == true + str = "1" + elsif (str.respond_to?(:to_eval)) + str = str.to_eval() + else + str = str.to_s() + end + return str end def tk_call(*args) - argstr = _get_eval_string(*args) - - res = INTERP._eval(argstr) + print args.join(" "), "\n" if $DEBUG + args.filter {|x|_get_eval_string(x)} + args.delete!(None) + args.flatten! + args.compact! + res = INTERP._invoke(*args) if INTERP._return_value() != 0 fail RuntimeError, res, error_at end + print "==> ", res, "\n" if $DEBUG return res end end @@ -376,7 +377,8 @@ module Tk list(w) if args.size == 0 end def iconwindow(*args) - tk_call 'wm', 'iconwindow', path, *args + w = tk_call('wm', 'iconwindow', path, *args) + window(w) if args.size == 0 end def maxsize(*args) w = tk_call('wm', 'maxsize', path, *args) @@ -431,7 +433,8 @@ class TkVariable def initialize(val="") @id = Tk_VARIABLE_ID[0] Tk_VARIABLE_ID[0] = Tk_VARIABLE_ID[0].succ - INTERP._eval(format('global %s; set %s %s', @id, @id, _get_eval_string(val))) + s = '"' + _get_eval_string(val).gsub(/[][$"]/, '\\\\\&') + '"' #' + INTERP._eval(format('global %s; set %s %s', @id, @id, s)) end def id @@ -816,6 +819,8 @@ class TkObject