2003-07-27 15:35:06 -04:00
|
|
|
#
|
|
|
|
# multi-tk.rb - supports multi Tk interpreters
|
|
|
|
# by Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
|
|
|
|
|
|
|
require 'tcltklib'
|
2004-05-01 12:09:54 -04:00
|
|
|
require 'tkutil'
|
2003-07-27 15:35:06 -04:00
|
|
|
require 'thread'
|
|
|
|
|
2003-07-31 03:59:18 -04:00
|
|
|
################################################
|
2003-08-29 04:34:14 -04:00
|
|
|
# ignore exception on the mainloop?
|
2003-07-31 03:59:18 -04:00
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
TclTkLib.mainloop_abort_on_exception = true
|
2003-07-31 03:59:18 -04:00
|
|
|
# TclTkLib.mainloop_abort_on_exception = false
|
2003-08-29 04:34:14 -04:00
|
|
|
# TclTkLib.mainloop_abort_on_exception = nil
|
|
|
|
|
2003-07-31 03:59:18 -04:00
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
################################################
|
|
|
|
# exceptiopn to treat the return value from IP
|
|
|
|
class MultiTkIp_OK < Exception
|
2004-01-02 11:21:26 -05:00
|
|
|
def self.send(thread, ret=nil)
|
2003-07-27 15:35:06 -04:00
|
|
|
thread.raise self.new(ret)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(ret=nil)
|
|
|
|
super('succeed')
|
|
|
|
@return_value = ret
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :return_value
|
|
|
|
alias value return_value
|
|
|
|
end
|
|
|
|
MultiTkIp_OK.freeze
|
|
|
|
|
2003-07-31 03:59:18 -04:00
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
################################################
|
|
|
|
# methods for construction
|
|
|
|
class MultiTkIp
|
2003-09-07 03:10:44 -04:00
|
|
|
SLAVE_IP_ID = ['slave'.freeze, '0'.taint].freeze
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@@IP_TABLE = {}.taint
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@@INIT_IP_ENV = [].taint # table of Procs
|
|
|
|
@@ADD_TK_PROCS = [].taint # table of [name, args, body]
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@@TK_TABLE_LIST = [].taint
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@@TK_CMD_TBL = {}.taint
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
######################################
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
@@CB_ENTRY_CLASS = Class.new(TkCallbackEntry){|c|
|
2003-07-27 15:35:06 -04:00
|
|
|
def initialize(ip, cmd)
|
|
|
|
@ip = ip
|
|
|
|
@cmd = cmd
|
|
|
|
end
|
|
|
|
attr_reader :ip, :cmd
|
2004-05-01 12:09:54 -04:00
|
|
|
def inspect
|
|
|
|
cmd.inspect
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
def call(*args)
|
|
|
|
begin
|
|
|
|
unless @ip.deleted?
|
|
|
|
@ip.cb_eval(@cmd, *args)
|
|
|
|
end
|
|
|
|
rescue TkCallbackBreak, TkCallbackContinue
|
|
|
|
fail
|
|
|
|
rescue Exception
|
|
|
|
end
|
|
|
|
end
|
2003-09-07 03:10:44 -04:00
|
|
|
}.freeze
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
######################################
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def _keys2opts(src_keys)
|
|
|
|
return nil if src_keys == nil
|
|
|
|
keys = {}; src_keys.each{|k, v| keys[k.to_s] = v}
|
|
|
|
#keys.collect{|k,v| "-#{k} #{v}"}.join(' ')
|
|
|
|
keys.collect{|k,v| "-#{k} #{TclTkLib._conv_listelement(TkComm::_get_eval_string(v))}"}.join(' ')
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
private :_keys2opts
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def _check_and_return(thread, exception, wait=0)
|
2003-07-27 15:35:06 -04:00
|
|
|
return nil unless thread
|
2003-08-29 04:34:14 -04:00
|
|
|
|
|
|
|
if wait == 0
|
|
|
|
# no wait
|
|
|
|
thread.raise exception
|
|
|
|
return thread
|
|
|
|
end
|
|
|
|
|
|
|
|
# wait to stop the caller thread
|
2003-07-27 15:35:06 -04:00
|
|
|
wait.times{
|
|
|
|
if thread.stop?
|
|
|
|
# ready to send exception
|
|
|
|
thread.raise exception
|
|
|
|
return thread
|
|
|
|
end
|
|
|
|
|
|
|
|
# wait
|
|
|
|
Thread.pass
|
|
|
|
}
|
|
|
|
|
|
|
|
# unexpected error
|
|
|
|
thread.raise RuntimeError, "the thread may not wait for the return value"
|
|
|
|
return thread
|
|
|
|
end
|
|
|
|
|
2003-07-28 02:10:13 -04:00
|
|
|
######################################
|
|
|
|
|
|
|
|
def set_safe_level(safe)
|
|
|
|
@cmd_queue.enq([@system, 'set_safe_level', safe])
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.set_safe_level(safe)
|
|
|
|
__getip.set_safe_level(safe)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _create_receiver_and_watchdog()
|
|
|
|
# command-procedures receiver
|
|
|
|
receiver = Thread.new{
|
2003-08-29 04:34:14 -04:00
|
|
|
safe_level = $SAFE
|
2003-07-27 15:35:06 -04:00
|
|
|
loop do
|
|
|
|
thread, cmd, *args = @cmd_queue.deq
|
2003-07-28 02:10:13 -04:00
|
|
|
if thread == @system
|
2003-08-29 04:34:14 -04:00
|
|
|
# control command
|
2003-07-28 02:10:13 -04:00
|
|
|
case cmd
|
|
|
|
when 'set_safe_level'
|
|
|
|
begin
|
2003-08-29 04:34:14 -04:00
|
|
|
safe_level = args[0] if safe_level < args[0]
|
2003-07-28 02:10:13 -04:00
|
|
|
rescue Exception
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# ignore
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
else
|
2003-08-29 04:34:14 -04:00
|
|
|
# procedure
|
2003-07-28 02:10:13 -04:00
|
|
|
begin
|
2003-08-29 04:34:14 -04:00
|
|
|
ret = proc{$SAFE = safe_level; cmd.call(*args)}.call
|
|
|
|
rescue SystemExit
|
|
|
|
# delete IP
|
|
|
|
unless @interp.deleted?
|
2004-05-01 12:09:54 -04:00
|
|
|
# if @interp._invoke('info', 'command', '.') != ""
|
|
|
|
# @interp._invoke('destroy', '.')
|
|
|
|
# end
|
|
|
|
# @interp.delete
|
|
|
|
@interp._eval_without_enc('exit')
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
|
|
|
_check_and_return(thread, MultiTkIp_OK.new(nil))
|
|
|
|
break
|
2003-07-28 02:10:13 -04:00
|
|
|
rescue Exception => e
|
|
|
|
# raise exception
|
|
|
|
_check_and_return(thread, e)
|
|
|
|
else
|
|
|
|
# no exception
|
|
|
|
_check_and_return(thread, MultiTkIp_OK.new(ret))
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# watchdog of receiver
|
|
|
|
watchdog = Thread.new{
|
|
|
|
begin
|
2003-08-29 04:34:14 -04:00
|
|
|
loop do
|
|
|
|
sleep 1
|
|
|
|
break unless receiver.alive?
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
rescue Exception
|
|
|
|
# ignore all kind of Exception
|
|
|
|
end
|
|
|
|
# receiver is dead
|
|
|
|
loop do
|
|
|
|
thread, cmd, *args = @cmd_queue.deq
|
|
|
|
next unless thread
|
|
|
|
if thread.alive?
|
|
|
|
if @interp.deleted?
|
|
|
|
thread.raise RuntimeError, 'the interpreter is already deleted'
|
|
|
|
else
|
|
|
|
thread.raise RuntimeError,
|
|
|
|
'the interpreter no longer receives command procedures'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# return threads
|
|
|
|
[receiver, watchdog]
|
|
|
|
end
|
|
|
|
private :_check_and_return, :_create_receiver_and_watchdog
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
if self.const_defined? :DEFAULT_MASTER_NAME
|
|
|
|
name = DEFAULT_MASTER_NAME.to_s
|
|
|
|
else
|
|
|
|
name = nil
|
|
|
|
end
|
|
|
|
if self.const_defined?(:DEFAULT_MASTER_OPTS) &&
|
|
|
|
DEFAULT_MASTER_OPTS.kind_of?(Hash)
|
|
|
|
keys = DEFAULT_MASTER_OPTS
|
|
|
|
else
|
|
|
|
keys = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
@@DEFAULT_MASTER = self.allocate
|
|
|
|
@@DEFAULT_MASTER.instance_eval{
|
2003-09-07 03:10:44 -04:00
|
|
|
@tk_windows = {}.taint
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@tk_table_list = [].taint
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@slave_ip_tbl = {}.taint
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
@slave_ip_top = {}.taint
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
unless keys.kind_of? Hash
|
|
|
|
fail ArgumentError, "expecting a Hash object for the 2nd argument"
|
|
|
|
end
|
|
|
|
|
|
|
|
@interp = TclTkIp.new(name, _keys2opts(keys))
|
|
|
|
@ip_name = nil
|
|
|
|
|
2003-07-28 02:10:13 -04:00
|
|
|
@system = Object.new
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
@threadgroup = Thread.current.group
|
|
|
|
|
|
|
|
@cmd_queue = Queue.new
|
|
|
|
|
|
|
|
@cmd_receiver, @receiver_watchdog = _create_receiver_and_watchdog()
|
|
|
|
|
|
|
|
@threadgroup.add @cmd_receiver
|
|
|
|
@threadgroup.add @receiver_watchdog
|
|
|
|
|
|
|
|
# NOT enclose @threadgroup for @@DEFAULT_MASTER
|
|
|
|
|
|
|
|
@@IP_TABLE[ThreadGroup::Default] = self
|
|
|
|
@@IP_TABLE[@threadgroup] = self
|
|
|
|
}
|
|
|
|
@@DEFAULT_MASTER.freeze # defend against modification
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
def self.inherited(subclass)
|
|
|
|
# trust if on ThreadGroup::Default or @@DEFAULT_MASTER's ThreadGroup
|
|
|
|
if @@IP_TABLE[Thread.current.group] == @@DEFAULT_MASTER
|
|
|
|
begin
|
|
|
|
class << subclass
|
|
|
|
self.methods.each{|m|
|
|
|
|
begin
|
|
|
|
unless m == '__id__' || m == '__send__' || m == 'freeze'
|
|
|
|
undef_method(m)
|
|
|
|
end
|
|
|
|
rescue Exception
|
|
|
|
# ignore all exceptions
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
subclass.freeze
|
|
|
|
fail SecurityError,
|
|
|
|
"cannot create subclass of MultiTkIp on a untrusted ThreadGroup"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
2003-08-02 01:04:30 -04:00
|
|
|
SAFE_OPT_LIST = [
|
|
|
|
'accessPath'.freeze,
|
|
|
|
'statics'.freeze,
|
|
|
|
'nested'.freeze,
|
|
|
|
'deleteHook'.freeze
|
|
|
|
].freeze
|
2003-09-07 03:10:44 -04:00
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _parse_slaveopts(keys)
|
|
|
|
name = nil
|
|
|
|
safe = false
|
|
|
|
safe_opts = {}
|
|
|
|
tk_opts = {}
|
|
|
|
|
|
|
|
keys.each{|k,v|
|
2004-05-01 12:09:54 -04:00
|
|
|
k_str = k.to_s
|
|
|
|
if k_str == 'name'
|
2003-07-27 15:35:06 -04:00
|
|
|
name = v
|
2004-05-01 12:09:54 -04:00
|
|
|
elsif k_str == 'safe'
|
2003-07-27 15:35:06 -04:00
|
|
|
safe = v
|
2004-05-01 12:09:54 -04:00
|
|
|
elsif SAFE_OPT_LIST.member?(k_str)
|
|
|
|
safe_opts[k_str] = v
|
2003-07-27 15:35:06 -04:00
|
|
|
else
|
2004-05-01 12:09:54 -04:00
|
|
|
tk_opts[k_str] = v
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
if keys['without_tk'] || keys[:without_tk]
|
|
|
|
[name, safe, safe_opts, nil]
|
|
|
|
else
|
|
|
|
[name, safe, safe_opts, tk_opts]
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
private :_parse_slaveopts
|
|
|
|
|
|
|
|
def _create_slave_ip_name
|
2004-05-01 12:09:54 -04:00
|
|
|
name = SLAVE_IP_ID.join('')
|
2003-07-27 15:35:06 -04:00
|
|
|
SLAVE_IP_ID[1].succ!
|
|
|
|
name
|
|
|
|
end
|
|
|
|
private :_create_slave_ip_name
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
def __check_safetk_optkeys(optkeys)
|
|
|
|
# based on 'safetk.tcl'
|
|
|
|
new_keys = {}
|
2003-07-28 21:24:32 -04:00
|
|
|
optkeys.each{|k,v| new_keys[k.to_s] = v}
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
# check 'display'
|
|
|
|
if !new_keys.key?('display')
|
|
|
|
begin
|
2003-10-14 11:25:45 -04:00
|
|
|
#new_keys['display'] = @interp._invoke('winfo screen .')
|
|
|
|
new_keys['display'] = @interp._invoke('winfo', 'screen', '.')
|
2003-07-27 15:35:06 -04:00
|
|
|
rescue
|
|
|
|
if ENV[DISPLAY]
|
|
|
|
new_keys['display'] = ENV[DISPLAY]
|
|
|
|
elsif !new_keys.key?('use')
|
|
|
|
warn "Warning: no screen info or ENV[DISPLAY], so use ':0.0'"
|
|
|
|
new_keys['display'] = ':0.0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# check 'use'
|
|
|
|
if new_keys.key?('use')
|
|
|
|
# given 'use'
|
|
|
|
case new_keys['use']
|
|
|
|
when TkWindow
|
|
|
|
new_keys['use'] = TkWinfo.id(new_keys['use'])
|
2003-10-14 11:25:45 -04:00
|
|
|
#assoc_display = @interp._eval('winfo screen .')
|
|
|
|
assoc_display = @interp._invoke('winfo', 'screen', '.')
|
2003-07-27 15:35:06 -04:00
|
|
|
when /^\..*/
|
|
|
|
new_keys['use'] = @interp._invoke('winfo', 'id', new_keys['use'])
|
|
|
|
assoc_display = @interp._invoke('winfo', 'screen', new_keys['use'])
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
pathname = @interp._invoke('winfo', 'pathname', new_keys['use'])
|
|
|
|
assco_display = @interp._invoke('winfo', 'screen', pathname)
|
|
|
|
rescue
|
|
|
|
assoc_display = new_keys['display']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# match display?
|
|
|
|
if assoc_display != new_keys['display']
|
|
|
|
if optkeys.keys?(:display) || optkeys.keys?('display')
|
|
|
|
fail RuntimeError,
|
|
|
|
"conflicting 'display'=>#{new_keys['display']} " +
|
|
|
|
"and display '#{assoc_display}' on 'use'=>#{new_keys['use']}"
|
|
|
|
else
|
|
|
|
new_keys['display'] = assoc_display
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# return
|
|
|
|
new_keys
|
|
|
|
end
|
|
|
|
private :__check_safetk_optkeys
|
|
|
|
|
|
|
|
def __create_safetk_frame(slave_ip, slave_name, app_name, keys)
|
2003-07-28 21:24:32 -04:00
|
|
|
# display option is used by ::safe::loadTk
|
|
|
|
loadTk_keys = {}
|
|
|
|
loadTk_keys['display'] = keys['display']
|
2003-07-27 15:35:06 -04:00
|
|
|
dup_keys = keys.dup
|
2003-07-28 21:24:32 -04:00
|
|
|
|
|
|
|
# keys for toplevel : allow followings
|
|
|
|
toplevel_keys = {}
|
|
|
|
['height', 'width', 'background', 'menu'].each{|k|
|
|
|
|
toplevel_keys[k] = dup_keys.delete(k) if dup_keys.key?(k)
|
|
|
|
}
|
|
|
|
toplevel_keys['classname'] = 'SafeTk'
|
|
|
|
toplevel_keys['screen'] = dup_keys.delete('display')
|
|
|
|
|
|
|
|
# other keys used by pack option of container frame
|
|
|
|
|
|
|
|
# create toplevel widget
|
2003-07-27 15:35:06 -04:00
|
|
|
begin
|
2003-07-28 21:24:32 -04:00
|
|
|
top = TkToplevel.new(toplevel_keys)
|
2003-07-27 15:35:06 -04:00
|
|
|
rescue NameError
|
|
|
|
fail unless @interp.safe?
|
|
|
|
fail SecurityError, "unable create toplevel on the safe interpreter"
|
|
|
|
end
|
|
|
|
msg = "Untrusted Ruby/Tk applet (#{slave_name})"
|
|
|
|
if app_name.kind_of?(String)
|
|
|
|
top.title "#{app_name} (#{slave_name})"
|
|
|
|
else
|
|
|
|
top.title msg
|
|
|
|
end
|
|
|
|
|
|
|
|
# procedure to delete slave interpreter
|
|
|
|
slave_delete_proc = proc{
|
|
|
|
unless slave_ip.deleted?
|
2004-05-01 12:09:54 -04:00
|
|
|
#if slave_ip._invoke('info', 'command', '.') != ""
|
|
|
|
# slave_ip._invoke('destroy', '.')
|
|
|
|
#end
|
|
|
|
#slave_ip.delete
|
|
|
|
slave_ip._eval_without_enc('exit')
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
top.destroy if top.winfo_exist?
|
2003-07-27 15:35:06 -04:00
|
|
|
}
|
|
|
|
tag = TkBindTag.new.bind('Destroy', slave_delete_proc)
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
top.bindtags = top.bindtags.unshift(tag)
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
# create control frame
|
|
|
|
TkFrame.new(top, :bg=>'red', :borderwidth=>3, :relief=>'ridge') {|fc|
|
|
|
|
fc.bindtags = fc.bindtags.unshift(tag)
|
|
|
|
|
|
|
|
TkFrame.new(fc, :bd=>0){|f|
|
|
|
|
TkButton.new(f,
|
|
|
|
:text=>'Delete', :bd=>1, :padx=>2, :pady=>0,
|
|
|
|
:highlightthickness=>0, :command=>slave_delete_proc
|
|
|
|
).pack(:side=>:right, :fill=>:both)
|
|
|
|
f.pack(:side=>:right, :fill=>:both, :expand=>true)
|
|
|
|
}
|
|
|
|
|
|
|
|
TkLabel.new(fc, :text=>msg, :padx=>2, :pady=>0,
|
|
|
|
:anchor=>:w).pack(:side=>:left, :fill=>:both, :expand=>true)
|
|
|
|
|
|
|
|
fc.pack(:side=>:bottom, :fill=>:x)
|
|
|
|
}
|
|
|
|
|
|
|
|
# container frame for slave interpreter
|
2003-07-28 21:24:32 -04:00
|
|
|
dup_keys['fill'] = :both unless dup_keys.key?('fill')
|
|
|
|
dup_keys['expand'] = true unless dup_keys.key?('expand')
|
|
|
|
c = TkFrame.new(top, :container=>true).pack(dup_keys)
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-07-28 21:24:32 -04:00
|
|
|
# return keys
|
|
|
|
loadTk_keys['use'] = TkWinfo.id(c)
|
2004-05-01 12:09:54 -04:00
|
|
|
[loadTk_keys, top.path]
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
private :__create_safetk_frame
|
|
|
|
|
|
|
|
def __create_safe_slave_obj(safe_opts, app_name, tk_opts)
|
|
|
|
# safe interpreter
|
|
|
|
ip_name = _create_slave_ip_name
|
|
|
|
slave_ip = @interp.create_slave(ip_name, true)
|
|
|
|
@slave_ip_tbl[ip_name] = slave_ip
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
@interp._eval("::safe::interpInit #{ip_name}")
|
|
|
|
|
|
|
|
slave_ip._invoke('set', 'argv0', app_name) if app_name.kind_of?(String)
|
|
|
|
|
|
|
|
if tk_opts
|
|
|
|
tk_opts = __check_safetk_optkeys(tk_opts)
|
|
|
|
if tk_opts.key?('use')
|
|
|
|
@slave_ip_top[ip_name] = ''
|
|
|
|
else
|
|
|
|
tk_opts, top_path = __create_safetk_frame(slave_ip, ip_name, app_name,
|
|
|
|
tk_opts)
|
|
|
|
@slave_ip_top[ip_name] = top_path
|
|
|
|
end
|
|
|
|
@interp._eval("::safe::loadTk #{ip_name} #{_keys2opts(tk_opts)}")
|
|
|
|
else
|
|
|
|
@slave_ip_top[ip_name] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if safe_opts.key?('deleteHook') || safe_opts.key?(:deleteHook)
|
|
|
|
@interp._eval("::safe::interpConfigure #{ip_name} " +
|
|
|
|
_keys2opts(safe_opts))
|
|
|
|
else
|
|
|
|
@interp._eval("::safe::interpConfigure #{ip_name} " +
|
|
|
|
_keys2opts(safe_opts) + '-deleteHook {' +
|
|
|
|
TkComm._get_eval_string(proc{|slave|
|
|
|
|
self._default_delete_hook(slave)
|
|
|
|
}) + '}')
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
[slave_ip, ip_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def __create_trusted_slave_obj(name, keys)
|
|
|
|
ip_name = _create_slave_ip_name
|
|
|
|
slave_ip = @interp.create_slave(ip_name, false)
|
|
|
|
slave_ip._invoke('set', 'argv0', name) if name.kind_of?(String)
|
|
|
|
slave_ip._invoke('set', 'argv', _keys2opts(keys))
|
|
|
|
@interp._invoke('load', '', 'Tk', ip_name)
|
|
|
|
@slave_ip_tbl[ip_name] = slave_ip
|
|
|
|
[slave_ip, ip_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
def _create_slave_object(keys={})
|
|
|
|
ip = MultiTkIp.new_slave(self, keys={})
|
|
|
|
@slave_ip_tbl[ip.name] = ip
|
|
|
|
end
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
def initialize(master, safeip=true, keys={})
|
2003-09-08 09:16:57 -04:00
|
|
|
if $SAFE >= 4
|
|
|
|
fail SecurityError, "cannot create a new interpreter at level #{$SAFE}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if safeip == nil && $SAFE >= 2
|
|
|
|
fail SecurityError, "cannot create a master-ip at level #{$SAFE}"
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
2003-09-08 09:16:57 -04:00
|
|
|
if !master.master? && master.safe?
|
|
|
|
fail SecurityError, "safe-slave-ip cannot create a new interpreter"
|
|
|
|
end
|
|
|
|
|
|
|
|
if safeip == nil && !master.master?
|
|
|
|
fail SecurityError, "slave-ip cannot create a master-ip"
|
2003-09-07 03:10:44 -04:00
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
unless keys.kind_of? Hash
|
|
|
|
fail ArgumentError, "expecting a Hash object for the 2nd argument"
|
|
|
|
end
|
|
|
|
|
|
|
|
@tk_windows = {}
|
|
|
|
@tk_table_list = []
|
|
|
|
@slave_ip_tbl = {}
|
2004-05-01 12:09:54 -04:00
|
|
|
@slave_ip_top = {}
|
2003-07-27 15:35:06 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@tk_windows.taint unless @tk_windows.tainted?
|
|
|
|
@tk_table_list.taint unless @tk_table_list.tainted?
|
|
|
|
@slave_ip_tbl.taint unless @slave_ip_tbl.tainted?
|
2004-05-01 12:09:54 -04:00
|
|
|
@slave_ip_top.taint unless @slave_ip_top.tainted?
|
2003-09-07 03:10:44 -04:00
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
name, safe, safe_opts, tk_opts = _parse_slaveopts(keys)
|
|
|
|
|
|
|
|
if safeip == nil
|
|
|
|
# create master-ip
|
|
|
|
@interp = TclTkIp.new(name, _keys2opts(tk_opts))
|
|
|
|
@ip_name = nil
|
|
|
|
else
|
|
|
|
# create slave-ip
|
|
|
|
if safeip || master.safe?
|
|
|
|
@interp, @ip_name = master.__create_safe_slave_obj(safe_opts,
|
|
|
|
name, tk_opts)
|
|
|
|
else
|
|
|
|
@interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
|
|
|
|
end
|
|
|
|
@set_alias_proc = proc{|name|
|
|
|
|
master._invoke('interp', 'alias', @ip_name, name, '', name)
|
|
|
|
}.freeze
|
|
|
|
end
|
|
|
|
|
2003-07-28 02:10:13 -04:00
|
|
|
@system = Object.new
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
@threadgroup = ThreadGroup.new
|
|
|
|
|
|
|
|
@cmd_queue = Queue.new
|
|
|
|
|
|
|
|
@cmd_receiver, @receiver_watchdog = _create_receiver_and_watchdog()
|
|
|
|
|
|
|
|
@threadgroup.add @cmd_receiver
|
|
|
|
@threadgroup.add @receiver_watchdog
|
|
|
|
|
|
|
|
@threadgroup.enclose
|
|
|
|
|
|
|
|
@@IP_TABLE[@threadgroup] = self
|
|
|
|
_init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
|
2003-09-07 03:10:44 -04:00
|
|
|
@@TK_TABLE_LIST.size.times{
|
|
|
|
(tbl = {}).tainted? || tbl.taint
|
|
|
|
@tk_table_list << tbl
|
|
|
|
}
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
self.freeze # defend against modification
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
def _default_delete_hook(slave)
|
|
|
|
if @slave_ip_top[slave].kind_of?(String)
|
|
|
|
# call default hook of safetk.tcl (ignore exceptions)
|
|
|
|
if @slave_ip_top[slave] == ''
|
|
|
|
begin
|
|
|
|
@interp._eval("::safe::disallowTk #{slave}")
|
|
|
|
rescue
|
|
|
|
warn("Waring: fail to call '::safe::disallowTk'") if $DEBUG
|
|
|
|
end
|
|
|
|
else # toplevel path
|
|
|
|
begin
|
|
|
|
@interp._eval("::safe::tkDelete {} #{@slave_ip_top[slave]} #{slave}")
|
|
|
|
rescue
|
|
|
|
warn("Waring: fail to call '::safe::tkDelete'") if $DEBUG
|
|
|
|
begin
|
|
|
|
@interp._eval("destroy #{@slave_ip_top[slave]}")
|
|
|
|
rescue
|
|
|
|
warn("Waring: fail to destroy toplevel") if $DEBUG
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@slave_ip_tbl.delete(slave)
|
|
|
|
@slave_ip_top.delete(slave)
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# get target IP
|
|
|
|
class MultiTkIp
|
|
|
|
def self.__getip
|
|
|
|
if Thread.current.group == ThreadGroup::Default
|
|
|
|
@@DEFAULT_MASTER
|
|
|
|
else
|
|
|
|
ip = @@IP_TABLE[Thread.current.group]
|
|
|
|
unless ip
|
|
|
|
fail SecurityError,
|
|
|
|
"cannot call Tk methods on #{Thread.current.inspect}"
|
|
|
|
end
|
|
|
|
ip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# aliases of constructor
|
|
|
|
class << MultiTkIp
|
|
|
|
alias __new new
|
|
|
|
private :__new
|
|
|
|
|
2003-07-30 03:23:14 -04:00
|
|
|
def new_master(keys={}, &b)
|
|
|
|
ip = __new(__getip, nil, keys)
|
|
|
|
ip.eval_proc(&b) if b
|
|
|
|
ip
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
alias new new_master
|
|
|
|
|
2003-07-30 03:23:14 -04:00
|
|
|
def new_slave(keys={}, &b)
|
|
|
|
ip = __new(__getip, false, keys)
|
|
|
|
ip.eval_proc(&b) if b
|
|
|
|
ip
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
alias new_trusted_slave new_master
|
|
|
|
|
2003-07-30 03:23:14 -04:00
|
|
|
def new_safe_slave(keys={},&b)
|
|
|
|
ip = __new(__getip, true, keys)
|
|
|
|
ip.eval_proc(&b) if b
|
|
|
|
ip
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
alias new_safeTk new_safe_slave
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# get info
|
|
|
|
class MultiTkIp
|
|
|
|
def inspect
|
|
|
|
s = self.to_s.chop!
|
|
|
|
if master?
|
|
|
|
s << ':master'
|
|
|
|
else
|
|
|
|
if @interp.safe?
|
|
|
|
s << ':safe-slave'
|
|
|
|
else
|
|
|
|
s << ':trusted-slave'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
s << '>'
|
|
|
|
end
|
|
|
|
|
|
|
|
def master?
|
|
|
|
if @ip_name
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2003-07-28 02:10:13 -04:00
|
|
|
def self.master?
|
|
|
|
__getip.master?
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
def slave?
|
|
|
|
not master?
|
|
|
|
end
|
2003-07-28 02:10:13 -04:00
|
|
|
def self.slave?
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
def alive?
|
2003-07-28 02:10:13 -04:00
|
|
|
begin
|
|
|
|
return false unless @cmd_receiver.alive?
|
|
|
|
return false if @interp.deleted?
|
|
|
|
return false if @interp._invoke('interp', 'exists', '') == '0'
|
|
|
|
rescue Exception
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
def self.alive?
|
|
|
|
__getip.alive?
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def path
|
2003-07-28 02:10:13 -04:00
|
|
|
@ip_name || ''
|
|
|
|
end
|
|
|
|
def self.path
|
|
|
|
__getip.path
|
|
|
|
end
|
|
|
|
def ip_name
|
|
|
|
@ip_name || ''
|
|
|
|
end
|
|
|
|
def self.ip_name
|
|
|
|
__getip.ip_name
|
|
|
|
end
|
|
|
|
def to_eval
|
|
|
|
@ip_name || ''
|
|
|
|
end
|
|
|
|
def self.to_eval
|
|
|
|
__getip.to_eval
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def slaves(all = false)
|
|
|
|
@interp._invoke('interp','slaves').split.map!{|name|
|
|
|
|
if @slave_ip_tbl.key?(name)
|
|
|
|
@slave_ip_tbl[name]
|
|
|
|
elsif all
|
|
|
|
name
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
}.compact!
|
|
|
|
end
|
2003-07-28 02:10:13 -04:00
|
|
|
def self.slaves(all = false)
|
|
|
|
__getip.slaves(all)
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# instance methods to treat tables
|
|
|
|
class MultiTkIp
|
|
|
|
def _tk_cmd_tbl
|
2003-08-29 04:34:14 -04:00
|
|
|
tbl = {}
|
|
|
|
MultiTkIp.tk_cmd_tbl.each{|id, ent| tbl[id] = ent if ent.ip == self }
|
|
|
|
tbl
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def _tk_windows
|
|
|
|
@tk_windows
|
|
|
|
end
|
|
|
|
|
|
|
|
def _tk_table_list
|
|
|
|
@tk_table_list
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def _add_new_tables
|
2003-09-07 03:10:44 -04:00
|
|
|
(@@TK_TABLE_LIST.size - @tk_table_list.size).times{
|
|
|
|
(tbl = {}).tainted? || tbl.taint
|
|
|
|
@tk_table_list << tbl
|
|
|
|
}
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _init_ip_env(script)
|
|
|
|
script.call(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _add_tk_procs(name, args, body)
|
|
|
|
return if slave?
|
|
|
|
@interp._invoke('proc', name, args, body) if args && body
|
|
|
|
@interp._invoke('interp', 'slaves').split.each{|slave|
|
|
|
|
@interp._invoke('interp', 'alias', slave, name, '', name)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def _init_ip_internal(init_ip_env, add_tk_procs)
|
|
|
|
init_ip_env.each{|script| script.call(self)}
|
|
|
|
add_tk_procs.each{|name, args, body|
|
|
|
|
if master?
|
|
|
|
@interp._invoke('proc', name, args, body) if args && body
|
|
|
|
else
|
|
|
|
@set_alias_proc.call(name)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# class methods to treat tables
|
|
|
|
class MultiTkIp
|
|
|
|
def self.tk_cmd_tbl
|
|
|
|
@@TK_CMD_TBL
|
|
|
|
end
|
|
|
|
def self.tk_windows
|
|
|
|
__getip._tk_windows
|
|
|
|
end
|
|
|
|
def self.tk_object_table(id)
|
|
|
|
__getip._tk_table_list[id]
|
|
|
|
end
|
|
|
|
def self.create_table
|
2003-09-07 03:10:44 -04:00
|
|
|
#if __getip.slave?
|
|
|
|
# raise SecurityError, "slave-IP has no permission creating a new table"
|
|
|
|
#end
|
2003-07-27 15:35:06 -04:00
|
|
|
id = @@TK_TABLE_LIST.size
|
|
|
|
obj = Object.new
|
|
|
|
@@TK_TABLE_LIST << obj
|
|
|
|
obj.instance_eval <<-EOD
|
|
|
|
def self.method_missing(m, *args)
|
|
|
|
MultiTkIp.tk_object_table(#{id}).send(m, *args)
|
|
|
|
end
|
|
|
|
EOD
|
|
|
|
obj.freeze
|
2003-08-29 04:34:14 -04:00
|
|
|
@@IP_TABLE.each{|tg, ip| ip._add_new_tables }
|
2003-07-27 15:35:06 -04:00
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.init_ip_env(script = Proc.new)
|
|
|
|
@@INIT_IP_ENV << script
|
|
|
|
@@IP_TABLE.each{|tg, ip|
|
|
|
|
ip._init_ip_env(script)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.add_tk_procs(name, args=nil, body=nil)
|
|
|
|
@@ADD_TK_PROCS << [name, args, body]
|
|
|
|
@@IP_TABLE.each{|tg, ip|
|
|
|
|
ip._add_tk_procs(name, args, body)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.init_ip_internal
|
|
|
|
__getip._init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# for callback operation
|
|
|
|
class MultiTkIp
|
|
|
|
def self.get_cb_entry(cmd)
|
|
|
|
@@CB_ENTRY_CLASS.new(__getip, cmd).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def cb_eval(cmd, *args)
|
|
|
|
self.eval_callback{ TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *args)) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# evaluate a procedure on the proper interpreter
|
|
|
|
class MultiTkIp
|
|
|
|
# instance method
|
2003-08-29 04:34:14 -04:00
|
|
|
def eval_proc_core(req_val, cmd, *args)
|
2003-07-27 15:35:06 -04:00
|
|
|
# cmd string ==> proc
|
|
|
|
if cmd.kind_of?(String)
|
2003-08-29 04:34:14 -04:00
|
|
|
xcmd = cmd
|
|
|
|
xargs = args
|
|
|
|
cmd = proc{ TkComm._get_eval_string(TkUtil.eval_cmd(xcmd, *xargs)) }
|
2003-07-27 15:35:06 -04:00
|
|
|
args = []
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# check
|
|
|
|
unless cmd.kind_of?(Proc)
|
|
|
|
raise RuntimeError, "A Proc object is expected for the 'cmd' argument"
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
# on IP thread
|
|
|
|
if (@cmd_receiver == Thread.current)
|
2003-08-29 04:34:14 -04:00
|
|
|
begin
|
|
|
|
ret = cmd.call(*args)
|
|
|
|
rescue SystemExit
|
|
|
|
# exit IP
|
|
|
|
warn("Warning: "+ $! + " on " + self.inspect) if $DEBUG
|
2004-05-01 12:09:54 -04:00
|
|
|
begin
|
|
|
|
self._eval_without_enc('exit')
|
|
|
|
rescue Exception
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
self.delete
|
|
|
|
ret = nil
|
|
|
|
rescue Exception => e
|
|
|
|
warn("Warning: " + e.class.inspect +
|
|
|
|
((e.message.length > 0)? ' "' + e.message + '"': '') +
|
|
|
|
" on " + self.inspect)
|
|
|
|
ret = nil
|
|
|
|
end
|
|
|
|
return ret
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# send cmd to the proc-queue
|
2003-08-29 04:34:14 -04:00
|
|
|
unless req_val
|
2003-07-27 15:35:06 -04:00
|
|
|
@cmd_queue.enq([nil, cmd, *args])
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# send and get return value by exception
|
2003-07-27 15:35:06 -04:00
|
|
|
begin
|
2003-08-29 04:34:14 -04:00
|
|
|
@cmd_queue.enq([Thread.current, cmd, *args])
|
2003-07-27 15:35:06 -04:00
|
|
|
Thread.stop
|
|
|
|
rescue MultiTkIp_OK => ret
|
|
|
|
# return value
|
|
|
|
return ret.value
|
2003-08-29 04:34:14 -04:00
|
|
|
rescue SystemExit
|
|
|
|
# exit IP
|
|
|
|
warn("Warning: " + $! + " on " + self.inspect) if $DEBUG
|
2004-05-01 12:09:54 -04:00
|
|
|
begin
|
|
|
|
self._eval_without_enc('exit')
|
|
|
|
rescue Exception
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
self.delete
|
|
|
|
rescue Exception => e
|
|
|
|
# others --> warning
|
|
|
|
warn("Warning: " + e.class.inspect +
|
|
|
|
((e.message.length > 0)? ' "' + e.message + '"': '') +
|
|
|
|
" on " + self.inspect)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
return nil
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
private :eval_proc_core
|
|
|
|
|
|
|
|
def eval_callback(cmd = Proc.new, *args)
|
|
|
|
eval_proc_core(false, cmd, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def eval_proc(cmd = Proc.new, *args)
|
|
|
|
eval_proc_core(true, cmd, *args)
|
|
|
|
end
|
|
|
|
alias call eval_proc
|
2003-08-29 04:34:14 -04:00
|
|
|
alias eval_string eval_proc
|
|
|
|
end
|
|
|
|
class << MultiTkIp
|
2003-07-27 15:35:06 -04:00
|
|
|
# class method
|
2003-08-29 04:34:14 -04:00
|
|
|
def eval_proc(cmd = Proc.new, *args)
|
2003-07-27 15:35:06 -04:00
|
|
|
# class ==> interp object
|
|
|
|
__getip.eval_proc(cmd, *args)
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
alias call eval_proc
|
|
|
|
alias eval_string eval_proc
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# event loop
|
2003-07-27 15:35:06 -04:00
|
|
|
# all master/slave IPs are controled by only one event-loop
|
|
|
|
class << MultiTkIp
|
|
|
|
def mainloop(check_root = true)
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.mainloop(check_root)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def mainloop_watchdog(check_root = true)
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.mainloop_watchdog(check_root)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def do_one_event(flag = TclTkLib::EventFlag::ALL)
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.do_one_event(flag)
|
|
|
|
end
|
|
|
|
def mainloop_abort_on_exception
|
2004-05-01 12:09:54 -04:00
|
|
|
# __getip.mainloop_abort_on_exception
|
|
|
|
TclTkLib.mainloop_abort_on_exception
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
|
|
|
def mainloop_abort_on_exception=(mode)
|
2004-05-01 12:09:54 -04:00
|
|
|
# __getip.mainloop_abort_on_exception=(mode)
|
|
|
|
TclTkLib.mainloop_abort_on_exception=(mode)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def set_eventloop_tick(tick)
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.set_eventloop_tick(tick)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def get_eventloop_tick
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.get_eventloop_tick
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def set_no_event_wait(tick)
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.set_no_event_wait(tick)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def get_no_event_wait
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.get_no_event_wait
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def set_eventloop_weight(loop_max, no_event_tick)
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.set_eventloop_weight(loop_max, no_event_tick)
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
def get_eventloop_weight
|
2003-08-29 04:34:14 -04:00
|
|
|
__getip.get_eventloop_weight
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# class methods to delegate to TclTkIp
|
|
|
|
class << MultiTkIp
|
2003-07-31 16:52:40 -04:00
|
|
|
def method_missing(id, *args)
|
|
|
|
__getip.send(id, *args)
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def make_safe
|
|
|
|
__getip.make_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def safe?
|
|
|
|
__getip.safe?
|
|
|
|
end
|
|
|
|
|
|
|
|
def restart
|
|
|
|
__getip.restart
|
|
|
|
end
|
|
|
|
|
|
|
|
def _eval(str)
|
|
|
|
__getip._eval(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _invoke(*args)
|
|
|
|
__getip._invoke(*args)
|
|
|
|
end
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def _eval_without_enc(str)
|
|
|
|
__getip._eval_without_enc(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _invoke_without_enc(*args)
|
|
|
|
__getip._invoke_without_enc(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _eval_with_enc(str)
|
|
|
|
__getip._eval_with_enc(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _invoke_with_enc(*args)
|
|
|
|
__getip._invoke_with_enc(*args)
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _toUTF8(str, encoding)
|
|
|
|
__getip._toUTF8(str, encoding)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _fromUTF8(str, encoding)
|
|
|
|
__getip._fromUTF8(str, encoding)
|
|
|
|
end
|
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
def _thread_vwait(var)
|
|
|
|
__getip._thread_vwait(var)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _thread_tkwait(mode, target)
|
|
|
|
__getip._thread_tkwait(mode, target)
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _return_value
|
|
|
|
__getip._return_value
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
def _get_variable(var, flag)
|
|
|
|
__getip._get_variable(var, flag)
|
|
|
|
end
|
|
|
|
def _get_variable2(var, idx, flag)
|
|
|
|
__getip._get_variable2(var, idx, flag)
|
|
|
|
end
|
|
|
|
def _set_variable(var, value, flag)
|
|
|
|
__getip._set_variable(var, value, flag)
|
|
|
|
end
|
|
|
|
def _set_variable2(var, idx, value, flag)
|
|
|
|
__getip._set_variable2(var, idx, value, flag)
|
|
|
|
end
|
|
|
|
def _unset_variable(var, flag)
|
|
|
|
__getip._unset_variable(var, flag)
|
|
|
|
end
|
|
|
|
def _unset_variable2(var, idx, flag)
|
|
|
|
__getip._unset_variable2(var, idx, flag)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _get_global_var(var)
|
|
|
|
__getip._get_global_var(var)
|
|
|
|
end
|
|
|
|
def _get_global_var2(var, idx)
|
|
|
|
__getip._get_global_var2(var, idx)
|
|
|
|
end
|
|
|
|
def _set_global_var(var, value)
|
|
|
|
__getip._set_global_var(var, value)
|
|
|
|
end
|
|
|
|
def _set_global_var2(var, idx, value)
|
|
|
|
__getip._set_global_var2(var, idx, value)
|
|
|
|
end
|
|
|
|
def _unset_global_var(var)
|
|
|
|
__getip._unset_global_var(var)
|
|
|
|
end
|
|
|
|
def _unset_global_var2(var, idx)
|
|
|
|
__getip._unset_global_var2(var, idx)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _split_tklist(str)
|
|
|
|
__getip._split_tklist(str)
|
|
|
|
end
|
|
|
|
def _merge_tklist(*args)
|
|
|
|
__getip._merge_tklist(*args)
|
|
|
|
end
|
|
|
|
def _conv_listelement(arg)
|
|
|
|
__getip._conv_listelement(arg)
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# wrap methods on TclTkLib : not permit calling TclTkLib module methods
|
|
|
|
class << TclTkLib
|
|
|
|
def mainloop(check_root = true)
|
|
|
|
MultiTkIp.mainloop(check_root)
|
|
|
|
end
|
|
|
|
def mainloop_watchdog(check_root = true)
|
|
|
|
MultiTkIp.mainloop_watchdog(check_root)
|
|
|
|
end
|
|
|
|
def do_one_event(flag = TclTkLib::EventFlag::ALL)
|
|
|
|
MultiTkIp.do_one_event(flag)
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
#def mainloop_abort_on_exception
|
|
|
|
# MultiTkIp.mainloop_abort_on_exception
|
|
|
|
#end
|
|
|
|
#def mainloop_abort_on_exception=(mode)
|
|
|
|
# MultiTkIp.mainloop_abort_on_exception=(mode)
|
|
|
|
#end
|
2003-08-29 04:34:14 -04:00
|
|
|
def set_eventloop_tick(tick)
|
|
|
|
MultiTkIp.set_eventloop_tick(tick)
|
|
|
|
end
|
|
|
|
def get_eventloop_tick
|
|
|
|
MultiTkIp.get_eventloop_tick
|
|
|
|
end
|
|
|
|
def set_no_event_wait(tick)
|
|
|
|
MultiTkIp.set_no_event_wait(tick)
|
|
|
|
end
|
|
|
|
def get_no_event_wait
|
|
|
|
MultiTkIp.get_no_event_wait
|
|
|
|
end
|
|
|
|
def set_eventloop_weight(loop_max, no_event_tick)
|
|
|
|
MultiTkIp.set_eventloop_weight(loop_max, no_event_tick)
|
|
|
|
end
|
|
|
|
def get_eventloop_weight
|
|
|
|
MultiTkIp.get_eventloop_weight
|
|
|
|
end
|
|
|
|
def restart
|
|
|
|
MultiTkIp.restart
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
def _merge_tklist(*args)
|
|
|
|
MultiTkIp._merge_tklist(*args)
|
|
|
|
end
|
|
|
|
def _conv_listelement(arg)
|
|
|
|
MultiTkIp._conv_listelement(arg)
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
# depend on TclTkIp
|
|
|
|
class MultiTkIp
|
2004-05-01 12:09:54 -04:00
|
|
|
def mainloop(check_root = true, restart_on_dead = false)
|
2003-08-29 04:34:14 -04:00
|
|
|
return self if self.slave?
|
2003-07-31 03:59:18 -04:00
|
|
|
unless restart_on_dead
|
|
|
|
@interp.mainloop(check_root)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
loop do
|
2003-08-29 04:34:14 -04:00
|
|
|
break unless self.alive?
|
2003-07-31 03:59:18 -04:00
|
|
|
if check_root
|
|
|
|
begin
|
2003-08-29 04:34:14 -04:00
|
|
|
break if TclTkLib.num_of_mainwindows == 0
|
2003-07-31 03:59:18 -04:00
|
|
|
rescue Exception
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
@interp.mainloop(check_root)
|
2003-07-31 03:59:18 -04:00
|
|
|
end
|
|
|
|
rescue StandardError
|
|
|
|
if TclTkLib.mainloop_abort_on_exception != nil
|
2003-08-29 04:34:14 -04:00
|
|
|
STDERR.print("Warning: Tk mainloop on ", @interp.inspect,
|
2003-07-31 03:59:18 -04:00
|
|
|
" receives ", $!.class.inspect,
|
|
|
|
" exception (ignore) : ", $!.message, "\n");
|
|
|
|
end
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
self
|
2003-07-31 03:59:18 -04:00
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def make_safe
|
|
|
|
@interp.make_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def safe?
|
|
|
|
@interp.safe?
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete
|
2004-05-01 12:09:54 -04:00
|
|
|
if safe?
|
|
|
|
# do 'exit' to call the delete_hook procedure
|
|
|
|
@interp._eval_without_enc('exit')
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
@interp.delete
|
|
|
|
end
|
|
|
|
|
|
|
|
def deleted?
|
|
|
|
@interp.deleted?
|
|
|
|
end
|
|
|
|
|
|
|
|
def restart
|
|
|
|
@interp.restart
|
|
|
|
end
|
|
|
|
|
|
|
|
def _eval(str)
|
|
|
|
@interp._eval(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _invoke(*args)
|
|
|
|
@interp._invoke(*args)
|
|
|
|
end
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def _eval_without_enc(str)
|
|
|
|
@interp._eval_without_enc(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _invoke_without_enc(*args)
|
|
|
|
@interp._invoke_without_enc(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _eval_with_enc(str)
|
|
|
|
@interp._eval_with_enc(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _invoke_with_enc(*args)
|
|
|
|
@interp._invoke_with_enc(*args)
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _toUTF8(str, encoding)
|
|
|
|
@interp._toUTF8(str, encoding)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _fromUTF8(str, encoding)
|
|
|
|
@interp._fromUTF8(str, encoding)
|
|
|
|
end
|
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
def _thread_vwait(var)
|
|
|
|
@interp._thread_vwait(var)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _thread_tkwait(mode, target)
|
|
|
|
@interp._thread_tkwait(mode, target)
|
|
|
|
end
|
|
|
|
|
2003-07-27 15:35:06 -04:00
|
|
|
def _return_value
|
|
|
|
@interp._return_value
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
def _get_variable(var, flag)
|
|
|
|
@interp._get_variable(var, flag)
|
|
|
|
end
|
|
|
|
def _get_variable2(var, idx, flag)
|
|
|
|
@interp._get_variable2(var, idx, flag)
|
|
|
|
end
|
|
|
|
def _set_variable(var, value, flag)
|
|
|
|
@interp._set_variable(var, value, flag)
|
|
|
|
end
|
|
|
|
def _set_variable2(var, idx, value, flag)
|
|
|
|
@interp._set_variable2(var, idx, value, flag)
|
|
|
|
end
|
|
|
|
def _unset_variable(var, flag)
|
|
|
|
@interp._unset_variable(var, flag)
|
|
|
|
end
|
|
|
|
def _unset_variable2(var, idx, flag)
|
|
|
|
@interp._unset_variable2(var, idx, flag)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _get_global_var(var)
|
|
|
|
@interp._get_global_var(var)
|
|
|
|
end
|
|
|
|
def _get_global_var2(var, idx)
|
|
|
|
@interp._get_global_var2(var, idx)
|
|
|
|
end
|
|
|
|
def _set_global_var(var, value)
|
|
|
|
@interp._set_global_var(var, value)
|
|
|
|
end
|
|
|
|
def _set_global_var2(var, idx, value)
|
|
|
|
@interp._set_global_var2(var, idx, value)
|
|
|
|
end
|
|
|
|
def _unset_global_var(var)
|
|
|
|
@interp._unset_global_var(var)
|
|
|
|
end
|
|
|
|
def _unset_global_var2(var, idx)
|
|
|
|
@interp._unset_global_var2(var, idx)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _split_tklist(str)
|
|
|
|
@interp._split_tklist(str)
|
|
|
|
end
|
|
|
|
def _merge_tklist(*args)
|
|
|
|
@interp._merge_tklist(*args)
|
|
|
|
end
|
|
|
|
def _conv_listelement(arg)
|
|
|
|
@interp._conv_listelement(arg)
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-07-28 02:10:13 -04:00
|
|
|
# interp command support
|
|
|
|
class MultiTkIp
|
|
|
|
def _lst2ary(str)
|
|
|
|
return [] if str == ""
|
|
|
|
idx = str.index('{')
|
|
|
|
while idx and idx > 0 and str[idx-1] == ?\\
|
|
|
|
idx = str.index('{', idx+1)
|
|
|
|
end
|
|
|
|
return str.split unless idx
|
|
|
|
|
|
|
|
list = str[0,idx].split
|
|
|
|
str = str[idx+1..-1]
|
|
|
|
i = -1
|
|
|
|
brace = 1
|
|
|
|
str.each_byte {|c|
|
|
|
|
i += 1
|
|
|
|
brace += 1 if c == ?{
|
|
|
|
brace -= 1 if c == ?}
|
|
|
|
break if brace == 0
|
|
|
|
}
|
|
|
|
if i == 0
|
|
|
|
list.push ''
|
|
|
|
elsif str[0, i] == ' '
|
|
|
|
list.push ' '
|
|
|
|
else
|
|
|
|
list.push str[0..i-1]
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
list += _lst2ary(str[i+1..-1])
|
2003-07-28 02:10:13 -04:00
|
|
|
list
|
|
|
|
end
|
|
|
|
private :_lst2ary
|
|
|
|
|
|
|
|
def _slavearg(slave)
|
|
|
|
if slave.kind_of?(MultiTkIp)
|
|
|
|
slave.path
|
|
|
|
elsif slave.kind_of?(String)
|
|
|
|
slave
|
|
|
|
else
|
|
|
|
cmd_name.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
private :_slavearg
|
|
|
|
|
|
|
|
def alias_info(slave, cmd_name)
|
|
|
|
_lst2ary(@interp._invoke('interp', 'alias', _slavearg(slave), cmd_name))
|
|
|
|
end
|
|
|
|
def self.alias_info(slave, cmd_name)
|
|
|
|
__getip.alias_info(slave, cmd_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def alias_delete(slave, cmd_name)
|
|
|
|
@interp._invoke('interp', 'alias', _slavearg(slave), cmd_name, '')
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.alias_delete(slave, cmd_name)
|
|
|
|
__getip.alias_delete(slave, cmd_name)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def def_alias(slave, new_cmd, org_cmd, *args)
|
|
|
|
ret = @interp._invoke('interp', 'alias', _slavearg(slave), new_cmd,
|
|
|
|
'', org_cmd, *args)
|
|
|
|
(ret == new_cmd)? self: nil
|
|
|
|
end
|
|
|
|
def self.def_alias(slave, new_cmd, org_cmd, *args)
|
|
|
|
ret = __getip.def_alias(slave, new_cmd, org_cmd, *args)
|
|
|
|
(ret == new_cmd)? self: nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def aliases(slave = '')
|
|
|
|
_lst2ary(@interp._invoke('interp', 'aliases', _slavearg(slave)))
|
|
|
|
end
|
|
|
|
def self.aliases(slave = '')
|
|
|
|
__getip.aliases(slave)
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_slaves(*args)
|
|
|
|
slaves = args.collect{|s| _slavearg(s)}
|
|
|
|
@interp._invoke('interp', 'delete', *slaves) if slaves.size > 0
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.delete_slaves(*args)
|
|
|
|
__getip.delete_slaves(*args)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def exist?(slave = '')
|
|
|
|
ret = @interp._invoke('interp', 'exists', _slavearg(slave))
|
|
|
|
(ret == '1')? true: false
|
|
|
|
end
|
|
|
|
def self.exist?(slave = '')
|
|
|
|
__getip.exist?(slave)
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_cmd(slave, cmd)
|
|
|
|
slave_invoke = @interp._invoke('list', 'rename', cmd, '')
|
|
|
|
@interp._invoke('interp', 'eval', _slavearg(slave), slave_invoke)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.delete_cmd(slave, cmd)
|
|
|
|
__getip.delete_cmd(slave, cmd)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def expose_cmd(slave, cmd, aliasname = nil)
|
|
|
|
if aliasname
|
|
|
|
@interp._invoke('interp', 'expose', _slavearg(slave), cmd, aliasname)
|
|
|
|
else
|
|
|
|
@interp._invoke('interp', 'expose', _slavearg(slave), cmd)
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.expose_cmd(slave, cmd, aliasname = nil)
|
|
|
|
__getip.expose_cmd(slave, cmd, aliasname)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def hide_cmd(slave, cmd, aliasname = nil)
|
|
|
|
if aliasname
|
|
|
|
@interp._invoke('interp', 'hide', _slavearg(slave), cmd, aliasname)
|
|
|
|
else
|
|
|
|
@interp._invoke('interp', 'hide', _slavearg(slave), cmd)
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.hide_cmd(slave, cmd, aliasname = nil)
|
|
|
|
__getip.hide_cmd(slave, cmd, aliasname)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidden_cmds(slave = '')
|
|
|
|
_lst2ary(@interp._invoke('interp', 'hidden', _slavearg(slave)))
|
|
|
|
end
|
|
|
|
def self.hidden_cmds(slave = '')
|
|
|
|
__getip.hidden_cmds(slave)
|
|
|
|
end
|
|
|
|
|
|
|
|
def invoke_hidden(slave, cmd, *args)
|
|
|
|
@interp._invoke('interp', 'invokehidden', _slavearg(slave), cmd, *args)
|
|
|
|
end
|
|
|
|
def self.invoke_hidden(slave, cmd, *args)
|
|
|
|
__getip.invoke_hidden(slave, cmd, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def invoke_hidden_on_global(slave, cmd, *args)
|
|
|
|
@interp._invoke('interp', 'invokehidden', _slavearg(slave),
|
|
|
|
'-global', cmd, *args)
|
|
|
|
end
|
|
|
|
def self.invoke_hidden_on_global(slave, cmd, *args)
|
|
|
|
__getip.invoke_hidden_on_global(slave, cmd, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def mark_trusted(slave = '')
|
|
|
|
@interp._invoke('interp', 'marktrusted', _slavearg(slave))
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.mark_trusted(slave = '')
|
|
|
|
__getip.mark_trusted(slave)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def recursion_limit(slave = '', limit = None)
|
|
|
|
number(@interp._invoke('interp', 'recursionlimit',
|
|
|
|
_slavearg(slave), limit))
|
|
|
|
end
|
|
|
|
def self.recursion_limit(slave = '', limit = None)
|
|
|
|
__getip.recursion_limit(slave)
|
|
|
|
end
|
|
|
|
|
2003-07-28 02:10:13 -04:00
|
|
|
def alias_target(aliascmd, slave = '')
|
|
|
|
@interp._invoke('interp', 'target', _slavearg(slave), aliascmd)
|
|
|
|
end
|
|
|
|
def self.alias_target(aliascmd, slave = '')
|
|
|
|
__getip.alias_target(aliascmd, slave)
|
|
|
|
end
|
|
|
|
|
|
|
|
def share_stdin(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'share', src, 'stdin', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.share_stdin(dist, src = '')
|
|
|
|
__getip.share_stdin(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def share_stdout(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'share', src, 'stdout', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.share_stdout(dist, src = '')
|
|
|
|
__getip.share_stdout(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def share_stderr(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'share', src, 'stderr', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.share_stderr(dist, src = '')
|
|
|
|
__getip.share_stderr(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def transfer_stdin(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'transfer', src, 'stdin', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.transfer_stdin(dist, src = '')
|
|
|
|
__getip.transfer_stdin(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def transfer_stdout(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'transfer', src, 'stdout', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.transfer_stdout(dist, src = '')
|
|
|
|
__getip.transfer_stdout(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def transfer_stderr(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'transfer', src, 'stderr', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.transfer_stderr(dist, src = '')
|
|
|
|
__getip.transfer_stderr(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def share_stdio(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'share', src, 'stdin', dist)
|
|
|
|
@interp._invoke('interp', 'share', src, 'stdout', dist)
|
|
|
|
@interp._invoke('interp', 'share', src, 'stderr', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.share_stdio(dist, src = '')
|
|
|
|
__getip.share_stdio(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def transfer_stdio(dist, src = '')
|
|
|
|
@interp._invoke('interp', 'transfer', src, 'stdin', dist)
|
|
|
|
@interp._invoke('interp', 'transfer', src, 'stdout', dist)
|
|
|
|
@interp._invoke('interp', 'transfer', src, 'stderr', dist)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def self.transfer_stdio(dist, src = '')
|
|
|
|
__getip.transfer_stdio(dist, src)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-07-31 16:52:40 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
# Safe Base :: manipulating safe interpreter
|
2003-07-31 16:52:40 -04:00
|
|
|
class MultiTkIp
|
2004-05-01 12:09:54 -04:00
|
|
|
def safeip_configure(slave, slot, value=None)
|
|
|
|
# use for '-noStatics' option ==> {statics=>false}
|
|
|
|
# for '-nestedLoadOk' option ==> {nested=>true}
|
|
|
|
if slot.kind_of?(Hash)
|
|
|
|
ip = MultiTkIp.__getip
|
|
|
|
ip._eval('::safe::interpConfigure ' + @ip_name + ' ' +
|
|
|
|
hash_kv(slot).join(' '))
|
|
|
|
else
|
|
|
|
ip._eval('::safe::interpConfigure ' + @ip_name + ' ' +
|
|
|
|
"-#{slot} #{_get_eval_string(value)}")
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def safeip_configinfo(slot = nil)
|
|
|
|
ip = MultiTkIp.__getip
|
|
|
|
ret = {}
|
|
|
|
if slot
|
|
|
|
conf = _lst2ary(ip._eval("::safe::interpConfigure " +
|
|
|
|
@ip_name + " -#{slot}"))
|
|
|
|
if conf[0] == '-deleteHook'
|
|
|
|
if conf[1] =~ /^rb_out (c\d+)/
|
|
|
|
ret[conf[0][1..-1]] = MultiTkIp._tk_cmd_tbl[$1]
|
|
|
|
else
|
|
|
|
ret[conf[0][1..-1]] = conf[1]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
ret[conf[0][1..-1]] = conf[1]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Hash[*_lst2ary(ip._eval("::safe::interpConfigure " +
|
|
|
|
@ip_name))].each{|k, v|
|
|
|
|
if k == '-deleteHook'
|
|
|
|
if v =~ /^rb_out (c\d+)/
|
|
|
|
ret[k[1..-1]] = MultiTkIp._tk_cmd_tbl[$1]
|
|
|
|
else
|
|
|
|
ret[k[1..-1]] = v
|
|
|
|
end
|
|
|
|
else
|
|
|
|
ret[k[1..-1]] = v
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
ret
|
|
|
|
end
|
2003-07-31 16:52:40 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def safeip_delete(slave)
|
|
|
|
ip = MultiTkIp.__getip
|
|
|
|
ip._eval("::safe::interpDelete " + @ip_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def safeip_add_to_access_path(slave, dir)
|
|
|
|
ip = MultiTkIp.__getip
|
|
|
|
ip._eval("::safe::interpAddToAccessPath #{@ip_name} #{dir}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def safeip_find_in_access_path(slave, dir)
|
|
|
|
ip = MultiTkIp.__getip
|
|
|
|
ip._eval("::safe::interpFindInAccessPath #{@ip_name} #{dir}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def safeip_set_log_cmd(slave, cmd = Proc.new)
|
|
|
|
ip = MultiTkIp.__getip
|
|
|
|
ip._eval("::safe::setLogCmd #{@ip_name} #{_get_eval_string(cmd)}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# encoding convert
|
|
|
|
class MultiTkIp
|
2003-07-31 16:52:40 -04:00
|
|
|
def encoding
|
2004-05-01 12:09:54 -04:00
|
|
|
@interp.encoding
|
2003-07-31 16:52:40 -04:00
|
|
|
end
|
|
|
|
def encoding=(enc)
|
2004-05-01 12:09:54 -04:00
|
|
|
@interp.encoding = enc
|
2003-07-31 16:52:40 -04:00
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
def encoding_convertfrom(str, enc=None)
|
|
|
|
@interp.encoding_convertfrom(str, enc)
|
2003-07-31 16:52:40 -04:00
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
alias encoding_convert_from encoding_convertfrom
|
2003-07-31 16:52:40 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def encoding_convertto(str, enc=None)
|
|
|
|
@interp.encoding_convertto(str, enc)
|
2003-07-31 16:52:40 -04:00
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
alias encoding_convert_to encoding_convertto
|
2003-07-31 16:52:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# remove methods for security
|
|
|
|
class MultiTkIp
|
|
|
|
undef_method :instance_eval
|
|
|
|
undef_method :instance_variable_get
|
|
|
|
undef_method :instance_variable_set
|
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# end of MultiTkIp definition
|
|
|
|
|
|
|
|
# defend against modification
|
2003-11-12 16:11:40 -05:00
|
|
|
#MultiTkIp.freeze
|
|
|
|
#TclTkLib.freeze
|
2003-07-27 15:35:06 -04:00
|
|
|
|
|
|
|
########################################
|
|
|
|
# start Tk which depends on MultiTkIp
|
|
|
|
module TkCore
|
|
|
|
INTERP = MultiTkIp
|
|
|
|
end
|
|
|
|
require 'tk'
|