process.c : unify indentation
configure.in : add --enable-setreuid option tcltklib.c : TclTkIp.new accepts 'ip-name' and 'options' ( e.g. TclTkIp.new('FOO', '-geometry 500x200 -use 0x2200009') ) tk.rb : support arguments of TclTkIp.new ( see TkCore::IP_NAME, TkCore::IP_OPTS ) tk*.rb : preparations for multi-Tk interpreter support git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
528b6c3f64
commit
fd46a1da0a
@ -374,6 +374,13 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync\
|
|||||||
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
|
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
|
||||||
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
|
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
|
||||||
setsid telldir seekdir fchmod mktime timegm cosh sinh tanh)
|
setsid telldir seekdir fchmod mktime timegm cosh sinh tanh)
|
||||||
|
AC_ARG_ENABLE(setreuid,
|
||||||
|
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
|
||||||
|
[use_setreuid=$enableval])
|
||||||
|
if test "$use_setreuid" = yes; then
|
||||||
|
AC_DEFINE(USE_SETREUID)
|
||||||
|
AC_DEFINE(USE_SETREGID)
|
||||||
|
fi
|
||||||
AC_STRUCT_TIMEZONE
|
AC_STRUCT_TIMEZONE
|
||||||
AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
|
AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
|
||||||
[AC_TRY_COMPILE([#include <time.h>],
|
[AC_TRY_COMPILE([#include <time.h>],
|
||||||
|
@ -530,7 +530,7 @@ ip_ruby(clientData, interp, argc, argv)
|
|||||||
DUMP2("rb_eval_string(%s)", arg);
|
DUMP2("rb_eval_string(%s)", arg);
|
||||||
old_trapflg = rb_trap_immediate;
|
old_trapflg = rb_trap_immediate;
|
||||||
rb_trap_immediate = 0;
|
rb_trap_immediate = 0;
|
||||||
res = rb_rescue2(rb_eval_string, (VALUE)arg,
|
res = rb_rescue2(rb_eval_string, (VALUE)arg,
|
||||||
ip_eval_rescue, (VALUE)&failed,
|
ip_eval_rescue, (VALUE)&failed,
|
||||||
rb_eStandardError, rb_eScriptError, 0);
|
rb_eStandardError, rb_eScriptError, 0);
|
||||||
rb_trap_immediate = old_trapflg;
|
rb_trap_immediate = old_trapflg;
|
||||||
@ -584,10 +584,14 @@ ip_alloc(self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ip_init(self)
|
ip_init(argc, argv, self)
|
||||||
|
int argc;
|
||||||
|
VALUE *argv;
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
struct tcltkip *ptr; /* tcltkip data struct */
|
struct tcltkip *ptr; /* tcltkip data struct */
|
||||||
|
VALUE argv0, opts, opt_n;
|
||||||
|
int cnt;
|
||||||
|
|
||||||
/* create object */
|
/* create object */
|
||||||
Data_Get_Struct(self, struct tcltkip, ptr);
|
Data_Get_Struct(self, struct tcltkip, ptr);
|
||||||
@ -605,6 +609,23 @@ ip_init(self)
|
|||||||
if (Tcl_Init(ptr->ip) == TCL_ERROR) {
|
if (Tcl_Init(ptr->ip) == TCL_ERROR) {
|
||||||
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set variables */
|
||||||
|
cnt = rb_scan_args(argc, argv, "02", &argv0, &opts);
|
||||||
|
switch(cnt) {
|
||||||
|
case 2:
|
||||||
|
/* options */
|
||||||
|
Tcl_SetVar(ptr->ip, "argv", StringValuePtr(opts), 0);
|
||||||
|
case 1:
|
||||||
|
/* argv0 */
|
||||||
|
if (argv0 != Qnil) {
|
||||||
|
Tcl_SetVar(ptr->ip, "argv0", StringValuePtr(argv0), 0);
|
||||||
|
}
|
||||||
|
case 0:
|
||||||
|
/* no args */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* from Tcl_AppInit() */
|
||||||
DUMP1("Tk_Init");
|
DUMP1("Tk_Init");
|
||||||
if (Tk_Init(ptr->ip) == TCL_ERROR) {
|
if (Tk_Init(ptr->ip) == TCL_ERROR) {
|
||||||
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
||||||
@ -989,7 +1010,7 @@ Init_tcltklib()
|
|||||||
get_eventloop_weight, 0);
|
get_eventloop_weight, 0);
|
||||||
|
|
||||||
rb_define_alloc_func(ip, ip_alloc);
|
rb_define_alloc_func(ip, ip_alloc);
|
||||||
rb_define_method(ip, "initialize", ip_init, 0);
|
rb_define_method(ip, "initialize", ip_init, -1);
|
||||||
rb_define_method(ip, "_eval", ip_eval, 1);
|
rb_define_method(ip, "_eval", ip_eval, 1);
|
||||||
rb_define_method(ip, "_toUTF8",ip_toUTF8,2);
|
rb_define_method(ip, "_toUTF8",ip_toUTF8,2);
|
||||||
rb_define_method(ip, "_fromUTF8",ip_fromUTF8,2);
|
rb_define_method(ip, "_fromUTF8",ip_fromUTF8,2);
|
||||||
|
353
ext/tk/lib/tk.rb
353
ext/tk/lib/tk.rb
@ -15,32 +15,18 @@ module TkComm
|
|||||||
'None'
|
'None'
|
||||||
end
|
end
|
||||||
|
|
||||||
Tk_CMDTBL = {}
|
#Tk_CMDTBL = {}
|
||||||
Tk_WINDOWS = {}
|
#Tk_WINDOWS = {}
|
||||||
Tk_IDs = [0, 0] # [0]-cmdid, [1]-winid
|
Tk_IDs = ["00000", "00000"] # [0]-cmdid, [1]-winid
|
||||||
|
|
||||||
INITIALIZE_TARGETS = [self]
|
# for backward compatibility
|
||||||
|
Tk_CMDTBL = Object.new
|
||||||
def self.__init_tables__
|
def Tk_CMDTBL.method_missing(id, *args)
|
||||||
Tk_WINDOWS.clear
|
TkCore::INTERP.tk_cmd_tbl.send(id, *args)
|
||||||
end
|
end
|
||||||
|
Tk_WINDOWS = Object.new
|
||||||
def self.__add_target_for_init__(target)
|
def Tk_WINDOWS.method_missing(id, *args)
|
||||||
INITIALIZE_TARGETS << target
|
TkCore::INTERP.tk_windows.send(id, *args)
|
||||||
|
|
||||||
if target.const_defined? :TkINTERP_SETUP_SCRIPTS
|
|
||||||
target::TkINTERP_SETUP_SCRIPTS.collect{|script|
|
|
||||||
if script.kind_of? Proc
|
|
||||||
script.call
|
|
||||||
elsif script.kind_of? Array
|
|
||||||
Tk.ip_invoke(*script)
|
|
||||||
else
|
|
||||||
Tk.ip_eval(script)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_at
|
def error_at
|
||||||
@ -80,7 +66,8 @@ module TkComm
|
|||||||
#{classname_def}
|
#{classname_def}
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@path=path
|
@path=path
|
||||||
Tk_WINDOWS[@path] = self
|
#Tk_WINDOWS[@path] = self
|
||||||
|
TkCore::INTERP.tk_windows[@path] = self
|
||||||
end
|
end
|
||||||
end"
|
end"
|
||||||
end
|
end
|
||||||
@ -91,7 +78,8 @@ module TkComm
|
|||||||
|
|
||||||
def tk_tcl2ruby(val)
|
def tk_tcl2ruby(val)
|
||||||
if val =~ /^rb_out (c\d+)/
|
if val =~ /^rb_out (c\d+)/
|
||||||
return Tk_CMDTBL[$1]
|
#return Tk_CMDTBL[$1]
|
||||||
|
return TkCore::INTERP.tk_cmd_tbl[$1]
|
||||||
end
|
end
|
||||||
if val.include? ?\s
|
if val.include? ?\s
|
||||||
return val.split.collect{|v| tk_tcl2ruby(v)}
|
return val.split.collect{|v| tk_tcl2ruby(v)}
|
||||||
@ -102,7 +90,9 @@ module TkComm
|
|||||||
when /^-?\d+$/
|
when /^-?\d+$/
|
||||||
val.to_i
|
val.to_i
|
||||||
when /^\./
|
when /^\./
|
||||||
Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
|
#Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
|
||||||
|
TkCore::INTERP.tk_windows[val]?
|
||||||
|
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
|
||||||
when /^i\d+$/
|
when /^i\d+$/
|
||||||
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
|
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
|
||||||
when / /
|
when / /
|
||||||
@ -251,14 +241,17 @@ module TkComm
|
|||||||
end
|
end
|
||||||
def window(val)
|
def window(val)
|
||||||
if val =~ /^\./
|
if val =~ /^\./
|
||||||
Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
|
#Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
|
||||||
|
TkCore::INTERP.tk_windows[val]?
|
||||||
|
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def procedure(val)
|
def procedure(val)
|
||||||
if val =~ /^rb_out (c\d+)/
|
if val =~ /^rb_out (c\d+)/
|
||||||
Tk_CMDTBL[$1]
|
#Tk_CMDTBL[$1]
|
||||||
|
TkCore::INTERP.tk_cmd_tbl[$1]
|
||||||
else
|
else
|
||||||
#nil
|
#nil
|
||||||
val
|
val
|
||||||
@ -311,11 +304,13 @@ module TkComm
|
|||||||
private :ruby2tcl
|
private :ruby2tcl
|
||||||
|
|
||||||
def _curr_cmd_id
|
def _curr_cmd_id
|
||||||
id = format("c%.4d", Tk_IDs[0])
|
#id = format("c%.4d", Tk_IDs[0])
|
||||||
|
id = "c" + Tk_IDs[0]
|
||||||
end
|
end
|
||||||
def _next_cmd_id
|
def _next_cmd_id
|
||||||
id = _curr_cmd_id
|
id = _curr_cmd_id
|
||||||
Tk_IDs[0] += 1
|
#Tk_IDs[0] += 1
|
||||||
|
Tk_IDs[0].succ!
|
||||||
id
|
id
|
||||||
end
|
end
|
||||||
private :_curr_cmd_id, :_next_cmd_id
|
private :_curr_cmd_id, :_next_cmd_id
|
||||||
@ -323,21 +318,25 @@ module TkComm
|
|||||||
def install_cmd(cmd)
|
def install_cmd(cmd)
|
||||||
return '' if cmd == ''
|
return '' if cmd == ''
|
||||||
id = _next_cmd_id
|
id = _next_cmd_id
|
||||||
Tk_CMDTBL[id] = cmd
|
#Tk_CMDTBL[id] = cmd
|
||||||
|
TkCore::INTERP.tk_cmd_tbl[id] = cmd
|
||||||
@cmdtbl = [] unless defined? @cmdtbl
|
@cmdtbl = [] unless defined? @cmdtbl
|
||||||
@cmdtbl.push id
|
@cmdtbl.push id
|
||||||
return format("rb_out %s", id);
|
return format("rb_out %s", id);
|
||||||
end
|
end
|
||||||
def uninstall_cmd(id)
|
def uninstall_cmd(id)
|
||||||
id = $1 if /rb_out (c\d+)/ =~ id
|
id = $1 if /rb_out (c\d+)/ =~ id
|
||||||
Tk_CMDTBL.delete(id)
|
#Tk_CMDTBL.delete(id)
|
||||||
|
TkCore::INTERP.tk_cmd_tbl.delete(id)
|
||||||
end
|
end
|
||||||
private :install_cmd, :uninstall_cmd
|
private :install_cmd, :uninstall_cmd
|
||||||
|
|
||||||
def install_win(ppath,name=nil)
|
def install_win(ppath,name=nil)
|
||||||
if !name or name == ''
|
if !name or name == ''
|
||||||
name = format("w%.4d", Tk_IDs[1])
|
#name = format("w%.4d", Tk_IDs[1])
|
||||||
Tk_IDs[1] += 1
|
#Tk_IDs[1] += 1
|
||||||
|
name = "w" + Tk_IDs[1]
|
||||||
|
Tk_IDs[1].succ!
|
||||||
end
|
end
|
||||||
if name[0] == ?.
|
if name[0] == ?.
|
||||||
@path = name.dup
|
@path = name.dup
|
||||||
@ -346,11 +345,13 @@ module TkComm
|
|||||||
else
|
else
|
||||||
@path = format("%s.%s", ppath, name)
|
@path = format("%s.%s", ppath, name)
|
||||||
end
|
end
|
||||||
Tk_WINDOWS[@path] = self
|
#Tk_WINDOWS[@path] = self
|
||||||
|
TkCore::INTERP.tk_windows[@path] = self
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninstall_win()
|
def uninstall_win()
|
||||||
Tk_WINDOWS.delete(@path)
|
#Tk_WINDOWS.delete(@path)
|
||||||
|
TkCore::INTERP.tk_windows.delete(@path)
|
||||||
end
|
end
|
||||||
private :install_win, :uninstall_win
|
private :install_win, :uninstall_win
|
||||||
|
|
||||||
@ -552,7 +553,8 @@ module TkComm
|
|||||||
if context
|
if context
|
||||||
tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline|
|
tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline|
|
||||||
if cmdline =~ /^rb_out (c\d+)\s+(.*)$/
|
if cmdline =~ /^rb_out (c\d+)\s+(.*)$/
|
||||||
[Tk_CMDTBL[$1], $2]
|
#[Tk_CMDTBL[$1], $2]
|
||||||
|
[TkCore::INTERP.tk_cmd_tbl[$1], $2]
|
||||||
else
|
else
|
||||||
cmdline
|
cmdline
|
||||||
end
|
end
|
||||||
@ -636,9 +638,75 @@ module TkCore
|
|||||||
include TkComm
|
include TkComm
|
||||||
extend TkComm
|
extend TkComm
|
||||||
|
|
||||||
INTERP = TclTkIp.new unless self.const_defined? :INTERP
|
unless self.const_defined? :INTERP
|
||||||
|
if self.const_defined? :IP_NAME
|
||||||
|
name = IP_NAME.to_s
|
||||||
|
else
|
||||||
|
name = nil
|
||||||
|
end
|
||||||
|
if self.const_defined? :IP_OPTS
|
||||||
|
if IP_OPTS.kind_of?(Hash)
|
||||||
|
opts = hash_kv(IP_OPTS).join(' ')
|
||||||
|
else
|
||||||
|
opts = IP_OPTS.to_s
|
||||||
|
end
|
||||||
|
else
|
||||||
|
opts = ''
|
||||||
|
end
|
||||||
|
|
||||||
INTERP._invoke("proc", "rb_out", "args", <<-'EOL')
|
INTERP = TclTkIp.new(name, opts)
|
||||||
|
|
||||||
|
def INTERP.__ip_id
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
INTERP.instance_eval{
|
||||||
|
@tk_cmd_tbl = {}
|
||||||
|
@tk_windows = {}
|
||||||
|
|
||||||
|
@tk_table_list = []
|
||||||
|
|
||||||
|
@init_ip_env = [] # table of Procs
|
||||||
|
@add_tk_procs = [] # table of [name, body]
|
||||||
|
}
|
||||||
|
def INTERP.tk_cmd_tbl
|
||||||
|
@tk_cmd_tbl
|
||||||
|
end
|
||||||
|
def INTERP.tk_windows
|
||||||
|
@tk_windows
|
||||||
|
end
|
||||||
|
|
||||||
|
def INTERP.tk_object_table(id)
|
||||||
|
@tk_table_list[id]
|
||||||
|
end
|
||||||
|
def INTERP.create_table
|
||||||
|
id = @tk_table_list.size
|
||||||
|
@tk_table_list << {}
|
||||||
|
obj = Object.new
|
||||||
|
obj.instance_eval <<-EOD
|
||||||
|
def self.method_missing(m, *args)
|
||||||
|
TkCore::INTERP.tk_object_table(#{id}).send(m, *args)
|
||||||
|
end
|
||||||
|
EOD
|
||||||
|
return obj
|
||||||
|
end
|
||||||
|
|
||||||
|
def INTERP.init_ip_env(script = Proc.new)
|
||||||
|
@init_ip_env << script
|
||||||
|
script.call(self)
|
||||||
|
end
|
||||||
|
def INTERP.add_tk_procs(name, args, body)
|
||||||
|
@add_tk_procs << [name, args, body]
|
||||||
|
self._invoke('proc', name, args, body)
|
||||||
|
end
|
||||||
|
def INTERP.init_ip_internal
|
||||||
|
ip = self
|
||||||
|
@init_ip_env.each{|script| script.call(ip)}
|
||||||
|
@add_tk_procs.each{|name,args,body| ip._invoke('proc',name,args,body)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
INTERP.add_tk_procs('rb_out', 'args', <<-'EOL')
|
||||||
regsub -all {!} $args {\\!} args
|
regsub -all {!} $args {\\!} args
|
||||||
regsub -all "{" $args "\\{" args
|
regsub -all "{" $args "\\{" args
|
||||||
if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} {
|
if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} {
|
||||||
@ -729,7 +797,9 @@ module TkCore
|
|||||||
def TkCore.callback(arg)
|
def TkCore.callback(arg)
|
||||||
# arg = tk_split_list(arg)
|
# arg = tk_split_list(arg)
|
||||||
arg = tk_split_simplelist(arg)
|
arg = tk_split_simplelist(arg)
|
||||||
_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
|
#_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
|
||||||
|
_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift],
|
||||||
|
*arg))
|
||||||
end
|
end
|
||||||
|
|
||||||
def windowingsystem
|
def windowingsystem
|
||||||
@ -824,13 +894,13 @@ module TkCore
|
|||||||
TclTkLib.get_eventloop_weight
|
TclTkLib.get_eventloop_weight
|
||||||
end
|
end
|
||||||
|
|
||||||
def restart(app_name = nil, use = nil)
|
def restart(app_name = nil, keys = {})
|
||||||
TkComm::INITIALIZE_TARGETS.each{|m| m.__init_tables__ }
|
TkCore::INTERP.init_ip_internal
|
||||||
|
|
||||||
tk_call('set', 'argv0', app_name) if app_name
|
tk_call('set', 'argv0', app_name) if app_name
|
||||||
if use
|
if keys.kind_of?(Hash) && keys.size > 0
|
||||||
tk_call('set', 'argc', 2)
|
# tk_call('set', 'argc', keys.size * 2)
|
||||||
tk_call('set', 'argv', "-use #{use}")
|
tk_call('set', 'argv', hash_kv(keys).join(' '))
|
||||||
end
|
end
|
||||||
|
|
||||||
INTERP.restart
|
INTERP.restart
|
||||||
@ -919,6 +989,8 @@ module TkPackage
|
|||||||
include TkCore
|
include TkCore
|
||||||
extend TkPackage
|
extend TkPackage
|
||||||
|
|
||||||
|
TkCommandNames = ['package'.freeze].freeze
|
||||||
|
|
||||||
def add_path(path)
|
def add_path(path)
|
||||||
Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path
|
Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path
|
||||||
end
|
end
|
||||||
@ -1136,6 +1208,9 @@ module Tk
|
|||||||
|
|
||||||
module Wm
|
module Wm
|
||||||
include TkComm
|
include TkComm
|
||||||
|
|
||||||
|
TkCommandNames = ['wm'.freeze].freeze
|
||||||
|
|
||||||
def aspect(*args)
|
def aspect(*args)
|
||||||
w = tk_call('wm', 'aspect', path, *args)
|
w = tk_call('wm', 'aspect', path, *args)
|
||||||
if args.length == 0
|
if args.length == 0
|
||||||
@ -1403,25 +1478,33 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Tk
|
module Tk
|
||||||
def encoding=(name)
|
module Encoding
|
||||||
INTERP.encoding = name
|
extend Encoding
|
||||||
|
|
||||||
|
TkCommandNames = ['encoding'.freeze].freeze
|
||||||
|
|
||||||
|
def encoding=(name)
|
||||||
|
INTERP.encoding = name
|
||||||
|
end
|
||||||
|
|
||||||
|
def encoding
|
||||||
|
INTERP.encoding
|
||||||
|
end
|
||||||
|
|
||||||
|
def encoding_names
|
||||||
|
tk_split_simplelist(tk_call('encoding', 'names'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def encoding_system
|
||||||
|
tk_call('encoding', 'system')
|
||||||
|
end
|
||||||
|
|
||||||
|
def encoding_system=(enc)
|
||||||
|
tk_call('encoding', 'system', enc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def encoding
|
extend Encoding
|
||||||
INTERP.encoding
|
|
||||||
end
|
|
||||||
|
|
||||||
def encoding_names
|
|
||||||
tk_split_simplelist(tk_call('encoding', 'names'))
|
|
||||||
end
|
|
||||||
|
|
||||||
def encoding_system
|
|
||||||
tk_call('encoding', 'system')
|
|
||||||
end
|
|
||||||
|
|
||||||
def encoding_system=(enc)
|
|
||||||
tk_call('encoding', 'system', enc)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# estimate encoding
|
# estimate encoding
|
||||||
@ -1443,21 +1526,27 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
|
|||||||
else
|
else
|
||||||
# dummy methods
|
# dummy methods
|
||||||
module Tk
|
module Tk
|
||||||
def encoding=(name)
|
module Encoding
|
||||||
nil
|
extend Encoding
|
||||||
end
|
|
||||||
def encoding
|
def encoding=(name)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
def encoding_names
|
def encoding
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
def encoding_system
|
def encoding_names
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
def encoding_system=(enc)
|
def encoding_system
|
||||||
nil
|
nil
|
||||||
|
end
|
||||||
|
def encoding_system=(enc)
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
extend Encoding
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1482,15 +1571,11 @@ end
|
|||||||
class TkBindTag
|
class TkBindTag
|
||||||
include TkBindCore
|
include TkBindCore
|
||||||
|
|
||||||
BTagID_TBL = {}
|
#BTagID_TBL = {}
|
||||||
Tk_BINDTAG_ID = ["btag00000"]
|
BTagID_TBL = TkCore::INTERP.create_table
|
||||||
|
Tk_BINDTAG_ID = ["btag".freeze, "00000"]
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.init_ip_env{ BTagID_TBL.clear }
|
||||||
|
|
||||||
def self.__init_tables__
|
|
||||||
BTagID_TBL.clear
|
|
||||||
Tk_BINDTAG_ID[0] = "btag00000"
|
|
||||||
end
|
|
||||||
|
|
||||||
def TkBindTag.id2obj(id)
|
def TkBindTag.id2obj(id)
|
||||||
BTagID_TBL[id]? BTagID_TBL[id]: id
|
BTagID_TBL[id]? BTagID_TBL[id]: id
|
||||||
@ -1506,8 +1591,8 @@ class TkBindTag
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*args, &b)
|
def initialize(*args, &b)
|
||||||
@id = Tk_BINDTAG_ID[0]
|
@id = Tk_BINDTAG_ID.join
|
||||||
Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ
|
Tk_BINDTAG_ID[1].succ!
|
||||||
BTagID_TBL[@id] = self
|
BTagID_TBL[@id] = self
|
||||||
bind(*args, &b) if args != []
|
bind(*args, &b) if args != []
|
||||||
end
|
end
|
||||||
@ -1557,22 +1642,16 @@ class TkVariable
|
|||||||
include Tk
|
include Tk
|
||||||
extend TkCore
|
extend TkCore
|
||||||
|
|
||||||
TkVar_CB_TBL = {}
|
TkCommandNames = ['tkwait'.freeze].freeze
|
||||||
TkVar_ID_TBL = {}
|
|
||||||
Tk_VARIABLE_ID = ["v00000"]
|
|
||||||
|
|
||||||
# this constant must be defined befor calling __add_target_for_init__
|
#TkVar_CB_TBL = {}
|
||||||
TkINTERP_SETUP_SCRIPTS = [
|
#TkVar_ID_TBL = {}
|
||||||
["proc", "rb_var", "args",
|
TkVar_CB_TBL = TkCore::INTERP.create_table
|
||||||
"ruby [format \"TkVariable.callback %%Q!%s!\" $args]"]
|
TkVar_ID_TBL = TkCore::INTERP.create_table
|
||||||
]
|
Tk_VARIABLE_ID = ["v".freeze, "00000"]
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.add_tk_procs('rb_var', 'args',
|
||||||
|
"ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
|
||||||
def self.__init_tables__
|
|
||||||
# cannot clear
|
|
||||||
# Tcl interpreter may keeps callbacks
|
|
||||||
end
|
|
||||||
|
|
||||||
def TkVariable.callback(args)
|
def TkVariable.callback(args)
|
||||||
name1,name2,op = tk_split_list(args)
|
name1,name2,op = tk_split_list(args)
|
||||||
@ -1584,8 +1663,8 @@ class TkVariable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(val="")
|
def initialize(val="")
|
||||||
@id = Tk_VARIABLE_ID[0]
|
@id = Tk_VARIABLE_ID.join
|
||||||
Tk_VARIABLE_ID[0] = Tk_VARIABLE_ID[0].succ
|
Tk_VARIABLE_ID[1].succ!
|
||||||
TkVar_ID_TBL[@id] = self
|
TkVar_ID_TBL[@id] = self
|
||||||
if val == []
|
if val == []
|
||||||
INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)',
|
INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)',
|
||||||
@ -1885,6 +1964,8 @@ module TkSelection
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['selection'.freeze].freeze
|
||||||
|
|
||||||
def self.clear(sel=nil)
|
def self.clear(sel=nil)
|
||||||
if sel
|
if sel
|
||||||
tk_call 'selection', 'clear', '-selection', sel
|
tk_call 'selection', 'clear', '-selection', sel
|
||||||
@ -1960,6 +2041,12 @@ module TkKinput
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = [
|
||||||
|
'kinput_start'.freeze,
|
||||||
|
'kinput_send_spot'.freeze,
|
||||||
|
'kanjiInput'.freeze
|
||||||
|
].freeze
|
||||||
|
|
||||||
def TkKinput.start(window, style=None)
|
def TkKinput.start(window, style=None)
|
||||||
tk_call 'kinput_start', window.path, style
|
tk_call 'kinput_start', window.path, style
|
||||||
end
|
end
|
||||||
@ -2022,6 +2109,8 @@ module TkXIM
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['imconfigure'.freeze].freeze
|
||||||
|
|
||||||
def TkXIM.useinputmethods(window=nil, value=nil)
|
def TkXIM.useinputmethods(window=nil, value=nil)
|
||||||
if window
|
if window
|
||||||
if value
|
if value
|
||||||
@ -2107,6 +2196,8 @@ module TkWinfo
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['winfo'.freeze].freeze
|
||||||
|
|
||||||
def TkWinfo.atom(name, win=nil)
|
def TkWinfo.atom(name, win=nil)
|
||||||
if win
|
if win
|
||||||
number(tk_call('winfo', 'atom', '-displayof', win, name))
|
number(tk_call('winfo', 'atom', '-displayof', win, name))
|
||||||
@ -2481,6 +2572,9 @@ end
|
|||||||
module TkPack
|
module TkPack
|
||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['pack'.freeze].freeze
|
||||||
|
|
||||||
def configure(win, *args)
|
def configure(win, *args)
|
||||||
if args[-1].kind_of?(Hash)
|
if args[-1].kind_of?(Hash)
|
||||||
keys = args.pop
|
keys = args.pop
|
||||||
@ -2524,6 +2618,8 @@ module TkGrid
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['grid'.freeze].freeze
|
||||||
|
|
||||||
def bbox(*args)
|
def bbox(*args)
|
||||||
list(tk_call('grid', 'bbox', *args))
|
list(tk_call('grid', 'bbox', *args))
|
||||||
end
|
end
|
||||||
@ -2619,6 +2715,8 @@ module TkPlace
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['place'.freeze].freeze
|
||||||
|
|
||||||
def configure(win, slot, value=None)
|
def configure(win, slot, value=None)
|
||||||
if slot.kind_of? Hash
|
if slot.kind_of? Hash
|
||||||
tk_call 'place', 'configure', win.epath, *hash_kv(slot)
|
tk_call 'place', 'configure', win.epath, *hash_kv(slot)
|
||||||
@ -2668,6 +2766,8 @@ module TkOptionDB
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['option'.freeze].freeze
|
||||||
|
|
||||||
module Priority
|
module Priority
|
||||||
WidgetDefault = 20
|
WidgetDefault = 20
|
||||||
StartupFile = 40
|
StartupFile = 40
|
||||||
@ -2695,7 +2795,7 @@ module TkOptionDB
|
|||||||
private :new
|
private :new
|
||||||
|
|
||||||
CARRIER = '.'.freeze
|
CARRIER = '.'.freeze
|
||||||
METHOD_TBL = {}
|
METHOD_TBL = TkCore::INTERP.create_table
|
||||||
ADD_METHOD = false
|
ADD_METHOD = false
|
||||||
SAFE_MODE = 4
|
SAFE_MODE = 4
|
||||||
|
|
||||||
@ -2765,7 +2865,7 @@ module TkOptionDB
|
|||||||
body = <<-"EOD"
|
body = <<-"EOD"
|
||||||
class #{klass} < TkOptionDB.module_eval('@@resource_proc_class')
|
class #{klass} < TkOptionDB.module_eval('@@resource_proc_class')
|
||||||
CARRIER = '#{carrier}'.freeze
|
CARRIER = '#{carrier}'.freeze
|
||||||
METHOD_TBL = {}
|
METHOD_TBL = TkCore::INTERP.create_table
|
||||||
ADD_METHOD = #{add}
|
ADD_METHOD = #{add}
|
||||||
SAFE_MODE = #{safe}
|
SAFE_MODE = #{safe}
|
||||||
%w(#{func_str}).each{|f| METHOD_TBL[f.intern] = nil }
|
%w(#{func_str}).each{|f| METHOD_TBL[f.intern] = nil }
|
||||||
@ -3654,6 +3754,8 @@ end
|
|||||||
|
|
||||||
class TkRoot<TkWindow
|
class TkRoot<TkWindow
|
||||||
include Wm
|
include Wm
|
||||||
|
|
||||||
|
=begin
|
||||||
ROOT = []
|
ROOT = []
|
||||||
def TkRoot.new(keys=nil)
|
def TkRoot.new(keys=nil)
|
||||||
if ROOT[0]
|
if ROOT[0]
|
||||||
@ -3673,6 +3775,24 @@ class TkRoot<TkWindow
|
|||||||
ROOT[0] = new
|
ROOT[0] = new
|
||||||
Tk_WINDOWS["."] = new
|
Tk_WINDOWS["."] = new
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
def TkRoot.new(keys=nil)
|
||||||
|
unless TkCore::INTERP.tk_windows['.']
|
||||||
|
TkCore::INTERP.tk_windows['.'] =
|
||||||
|
super(:without_creating=>true, :widgetname=>'.')
|
||||||
|
end
|
||||||
|
root = TkCore::INTERP.tk_windows['.']
|
||||||
|
if keys # wm commands
|
||||||
|
keys.each{|k,v|
|
||||||
|
if v.kind_of? Array
|
||||||
|
root.send(k,*v)
|
||||||
|
else
|
||||||
|
root.send(k,v)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return root
|
||||||
|
end
|
||||||
|
|
||||||
WidgetClassName = 'Tk'.freeze
|
WidgetClassName = 'Tk'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
@ -3688,6 +3808,7 @@ end
|
|||||||
class TkToplevel<TkWindow
|
class TkToplevel<TkWindow
|
||||||
include Wm
|
include Wm
|
||||||
|
|
||||||
|
TkCommandNames = ['toplevel'.freeze].freeze
|
||||||
WidgetClassName = 'Toplevel'.freeze
|
WidgetClassName = 'Toplevel'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -3890,6 +4011,7 @@ class TkToplevel<TkWindow
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkFrame<TkWindow
|
class TkFrame<TkWindow
|
||||||
|
TkCommandNames = ['frame'.freeze].freeze
|
||||||
WidgetClassName = 'Frame'.freeze
|
WidgetClassName = 'Frame'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -4017,6 +4139,7 @@ class TkLabelFrame<TkFrame
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkPanedWindow<TkWindow
|
class TkPanedWindow<TkWindow
|
||||||
|
TkCommandNames = ['panedwindow'.freeze].freeze
|
||||||
WidgetClassName = 'Panedwindow'.freeze
|
WidgetClassName = 'Panedwindow'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4128,6 +4251,7 @@ end
|
|||||||
TkPanedwindow = TkPanedWindow
|
TkPanedwindow = TkPanedWindow
|
||||||
|
|
||||||
class TkLabel<TkWindow
|
class TkLabel<TkWindow
|
||||||
|
TkCommandNames = ['label'.freeze].freeze
|
||||||
WidgetClassName = 'Label'.freeze
|
WidgetClassName = 'Label'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4143,6 +4267,7 @@ class TkLabel<TkWindow
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkButton<TkLabel
|
class TkButton<TkLabel
|
||||||
|
TkCommandNames = ['button'.freeze].freeze
|
||||||
WidgetClassName = 'Button'.freeze
|
WidgetClassName = 'Button'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4162,6 +4287,7 @@ class TkButton<TkLabel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkRadioButton<TkButton
|
class TkRadioButton<TkButton
|
||||||
|
TkCommandNames = ['radiobutton'.freeze].freeze
|
||||||
WidgetClassName = 'Radiobutton'.freeze
|
WidgetClassName = 'Radiobutton'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4186,6 +4312,7 @@ end
|
|||||||
TkRadiobutton = TkRadioButton
|
TkRadiobutton = TkRadioButton
|
||||||
|
|
||||||
class TkCheckButton<TkRadioButton
|
class TkCheckButton<TkRadioButton
|
||||||
|
TkCommandNames = ['checkbutton'.freeze].freeze
|
||||||
WidgetClassName = 'Checkbutton'.freeze
|
WidgetClassName = 'Checkbutton'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4203,6 +4330,7 @@ end
|
|||||||
TkCheckbutton = TkCheckButton
|
TkCheckbutton = TkCheckButton
|
||||||
|
|
||||||
class TkMessage<TkLabel
|
class TkMessage<TkLabel
|
||||||
|
TkCommandNames = ['message'.freeze].freeze
|
||||||
WidgetClassName = 'Message'.freeze
|
WidgetClassName = 'Message'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4215,6 +4343,7 @@ class TkMessage<TkLabel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkScale<TkWindow
|
class TkScale<TkWindow
|
||||||
|
TkCommandNames = ['scale'.freeze].freeze
|
||||||
WidgetClassName = 'Scale'.freeze
|
WidgetClassName = 'Scale'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -4252,6 +4381,7 @@ class TkScale<TkWindow
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkScrollbar<TkWindow
|
class TkScrollbar<TkWindow
|
||||||
|
TkCommandNames = ['scrollbar'.freeze].freeze
|
||||||
WidgetClassName = 'Scrollbar'.freeze
|
WidgetClassName = 'Scrollbar'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -4344,6 +4474,7 @@ class TkListbox<TkTextWin
|
|||||||
include TkTreatListItemFont
|
include TkTreatListItemFont
|
||||||
include Scrollable
|
include Scrollable
|
||||||
|
|
||||||
|
TkCommandNames = ['listbox'.freeze].freeze
|
||||||
WidgetClassName = 'Listbox'.freeze
|
WidgetClassName = 'Listbox'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -4482,6 +4613,7 @@ end
|
|||||||
class TkMenu<TkWindow
|
class TkMenu<TkWindow
|
||||||
include TkTreatMenuEntryFont
|
include TkTreatMenuEntryFont
|
||||||
|
|
||||||
|
TkCommandNames = ['menu'.freeze].freeze
|
||||||
WidgetClassName = 'Menu'.freeze
|
WidgetClassName = 'Menu'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -4657,7 +4789,8 @@ module TkSystemMenu
|
|||||||
fail ArgumentError, "parent must be a TkMenu object"
|
fail ArgumentError, "parent must be a TkMenu object"
|
||||||
end
|
end
|
||||||
@path = format("%s.%s", parent.path, self.class::SYSMENU_NAME)
|
@path = format("%s.%s", parent.path, self.class::SYSMENU_NAME)
|
||||||
TkComm::Tk_WINDOWS[@path] = self
|
#TkComm::Tk_WINDOWS[@path] = self
|
||||||
|
TkCore::INTERP.tk_windows[@path] = self
|
||||||
if self.method(:create_self).arity == 0
|
if self.method(:create_self).arity == 0
|
||||||
p 'create_self has no arg' if $DEBUG
|
p 'create_self has no arg' if $DEBUG
|
||||||
create_self
|
create_self
|
||||||
@ -4688,6 +4821,7 @@ class TkSysMenu_Apple<TkMenu
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkMenubutton<TkLabel
|
class TkMenubutton<TkLabel
|
||||||
|
TkCommandNames = ['menubutton'.freeze].freeze
|
||||||
WidgetClassName = 'Menubutton'.freeze
|
WidgetClassName = 'Menubutton'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
def create_self(keys)
|
def create_self(keys)
|
||||||
@ -4700,10 +4834,13 @@ class TkMenubutton<TkLabel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkOptionMenubutton<TkMenubutton
|
class TkOptionMenubutton<TkMenubutton
|
||||||
|
TkCommandNames = ['tk_optionMenu'.freeze].freeze
|
||||||
|
|
||||||
class OptionMenu<TkMenu
|
class OptionMenu<TkMenu
|
||||||
def initialize(path) #==> return value of tk_optionMenu
|
def initialize(path) #==> return value of tk_optionMenu
|
||||||
@path = path
|
@path = path
|
||||||
TkComm::Tk_WINDOWS[@path] = self
|
#TkComm::Tk_WINDOWS[@path] = self
|
||||||
|
TkCore::INTERP.tk_windows[@path] = self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -4843,6 +4980,8 @@ module TkClipboard
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['clipboard'.freeze].freeze
|
||||||
|
|
||||||
def self.clear(win=nil)
|
def self.clear(win=nil)
|
||||||
if win
|
if win
|
||||||
tk_call 'clipboard', 'clear', '-displayof', win
|
tk_call 'clipboard', 'clear', '-displayof', win
|
||||||
|
@ -9,21 +9,13 @@ class TkTimer
|
|||||||
include TkCore
|
include TkCore
|
||||||
extend TkCore
|
extend TkCore
|
||||||
|
|
||||||
Tk_CBID = [0]
|
TkCommandNames = ['after'.freeze].freeze
|
||||||
Tk_CBTBL = {}
|
|
||||||
|
|
||||||
# this constant must be defined befor calling __add_target_for_init__
|
Tk_CBID = ['a'.freeze, '00000']
|
||||||
TkINTERP_SETUP_SCRIPTS = [
|
Tk_CBTBL = TkCore::INTERP.create_table
|
||||||
["proc", "rb_after", "id",
|
|
||||||
"ruby [format \"#{self.name}.callback %%Q!%s!\" $id]"]
|
|
||||||
]
|
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.add_tk_procs('rb_after', 'id',
|
||||||
|
"ruby [format \"#{self.name}.callback %%Q!%s!\" $id]")
|
||||||
def self.__init_tables__
|
|
||||||
# cannot clear
|
|
||||||
# Tcl interpreter may keep callbacks
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
@ -108,8 +100,8 @@ class TkTimer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@id = format("a%.4d", Tk_CBID[0])
|
@id = Tk_CBID.join
|
||||||
Tk_CBID[0] += 1
|
Tk_CBID[1].succ!
|
||||||
|
|
||||||
@set_next = true
|
@set_next = true
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ require 'tk'
|
|||||||
module TkBgError
|
module TkBgError
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['bgerror'.freeze].freeze
|
||||||
|
|
||||||
def bgerror(message)
|
def bgerror(message)
|
||||||
tk_call 'bgerror', message
|
tk_call 'bgerror', message
|
||||||
end
|
end
|
||||||
|
@ -29,6 +29,7 @@ class TkCanvas<TkWindow
|
|||||||
include TkTreatCItemFont
|
include TkTreatCItemFont
|
||||||
include Scrollable
|
include Scrollable
|
||||||
|
|
||||||
|
TkCommandNames = ['canvas'.freeze].freeze
|
||||||
WidgetClassName = 'Canvas'.freeze
|
WidgetClassName = 'Canvas'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -527,15 +528,10 @@ end
|
|||||||
class TkcTag<TkObject
|
class TkcTag<TkObject
|
||||||
include TkcTagAccess
|
include TkcTagAccess
|
||||||
|
|
||||||
CTagID_TBL = {}
|
CTagID_TBL = TkCore::INTERP.create_table
|
||||||
Tk_CanvasTag_ID = ['ctag0000']
|
Tk_CanvasTag_ID = ['ctag', '00000']
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.init_ip_env{ CTagID_TBL.clear }
|
||||||
|
|
||||||
def self.__init_tables__
|
|
||||||
CTagID_TBL.clear
|
|
||||||
Tk_CanvasTag_ID[0] = 'ctag0000'
|
|
||||||
end
|
|
||||||
|
|
||||||
def TkcTag.id2obj(canvas, id)
|
def TkcTag.id2obj(canvas, id)
|
||||||
cpath = canvas.path
|
cpath = canvas.path
|
||||||
@ -549,10 +545,10 @@ class TkcTag<TkObject
|
|||||||
end
|
end
|
||||||
@c = parent
|
@c = parent
|
||||||
@cpath = parent.path
|
@cpath = parent.path
|
||||||
@path = @id = Tk_CanvasTag_ID[0]
|
@path = @id = Tk_CanvasTag_ID.join
|
||||||
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
|
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
|
||||||
CTagID_TBL[@cpath][@id] = self
|
CTagID_TBL[@cpath][@id] = self
|
||||||
Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ
|
Tk_CanvasTag_ID[1] = Tk_CanvasTag_ID[1].succ
|
||||||
if mode
|
if mode
|
||||||
tk_call @c.path, "addtag", @id, mode, *args
|
tk_call @c.path, "addtag", @id, mode, *args
|
||||||
end
|
end
|
||||||
@ -664,17 +660,17 @@ class TkcTagCurrent<TkcTag
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkcGroup<TkcTag
|
class TkcGroup<TkcTag
|
||||||
Tk_cGroup_ID = ['tkcg00000']
|
Tk_cGroup_ID = ['tkcg', '00000']
|
||||||
def create_self(parent, *args)
|
def create_self(parent, *args)
|
||||||
if not parent.kind_of?(TkCanvas)
|
if not parent.kind_of?(TkCanvas)
|
||||||
fail format("%s need to be TkCanvas", parent.inspect)
|
fail format("%s need to be TkCanvas", parent.inspect)
|
||||||
end
|
end
|
||||||
@c = parent
|
@c = parent
|
||||||
@cpath = parent.path
|
@cpath = parent.path
|
||||||
@path = @id = Tk_cGroup_ID[0]
|
@path = @id = Tk_cGroup_ID.join
|
||||||
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
|
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
|
||||||
CTagID_TBL[@cpath][@id] = self
|
CTagID_TBL[@cpath][@id] = self
|
||||||
Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ
|
Tk_cGroup_ID[1] = Tk_cGroup_ID[1].succ
|
||||||
add(*args) if args != []
|
add(*args) if args != []
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -697,13 +693,9 @@ class TkcItem<TkObject
|
|||||||
include TkcTagAccess
|
include TkcTagAccess
|
||||||
|
|
||||||
CItemTypeToClass = {}
|
CItemTypeToClass = {}
|
||||||
CItemID_TBL = {}
|
CItemID_TBL = TkCore::INTERP.create_table
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.init_ip_env{ CItemID_TBL.clear }
|
||||||
|
|
||||||
def self.__init_tables__
|
|
||||||
CItemID_TBL.clear
|
|
||||||
end
|
|
||||||
|
|
||||||
def TkcItem.type2class(type)
|
def TkcItem.type2class(type)
|
||||||
CItemTypeToClass[type]
|
CItemTypeToClass[type]
|
||||||
@ -828,19 +820,16 @@ end
|
|||||||
class TkImage<TkObject
|
class TkImage<TkObject
|
||||||
include Tk
|
include Tk
|
||||||
|
|
||||||
Tk_IMGTBL = {}
|
TkCommandNames = ['image'.freeze].freeze
|
||||||
Tk_Image_ID = ['i00000']
|
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
Tk_IMGTBL = TkCore::INTERP.create_table
|
||||||
|
Tk_Image_ID = ['i', '00000']
|
||||||
|
|
||||||
def self.__init_tables__
|
TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }
|
||||||
Tk_IMGTBL.clear
|
|
||||||
Tk_Image_ID[0] = 'i00000'
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(keys=nil)
|
def initialize(keys=nil)
|
||||||
@path = Tk_Image_ID[0]
|
@path = Tk_Image_ID.join
|
||||||
Tk_Image_ID[0] = Tk_Image_ID[0].succ
|
Tk_Image_ID[1] = Tk_Image_ID[1].succ
|
||||||
tk_call 'image', 'create', @type, @path, *hash_kv(keys)
|
tk_call 'image', 'create', @type, @path, *hash_kv(keys)
|
||||||
Tk_IMGTBL[@path] = self
|
Tk_IMGTBL[@path] = self
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,8 @@ module TkConsole
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['console'.freeze].freeze
|
||||||
|
|
||||||
def self.title(str=None)
|
def self.title(str=None)
|
||||||
tk_call 'console', str
|
tk_call 'console', str
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,8 @@ require "tk"
|
|||||||
class TkDialog2 < TkWindow
|
class TkDialog2 < TkWindow
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = ['tk_dialog'.freeze].freeze
|
||||||
|
|
||||||
def self.show(*args)
|
def self.show(*args)
|
||||||
dlog = self.new(*args)
|
dlog = self.new(*args)
|
||||||
dlog.show
|
dlog.show
|
||||||
|
@ -8,6 +8,7 @@ require 'tk.rb'
|
|||||||
class TkEntry<TkLabel
|
class TkEntry<TkLabel
|
||||||
include Scrollable
|
include Scrollable
|
||||||
|
|
||||||
|
TkCommandNames = ['entry'.freeze].freeze
|
||||||
WidgetClassName = 'Entry'.freeze
|
WidgetClassName = 'Entry'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -221,6 +222,7 @@ class TkEntry<TkLabel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkSpinbox<TkEntry
|
class TkSpinbox<TkEntry
|
||||||
|
TkCommandNames = ['spinbox'.freeze].freeze
|
||||||
WidgetClassName = 'Spinbox'.freeze
|
WidgetClassName = 'Spinbox'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
|
@ -9,17 +9,16 @@ class TkFont
|
|||||||
include Tk
|
include Tk
|
||||||
extend TkCore
|
extend TkCore
|
||||||
|
|
||||||
Tk_FontID = [0]
|
TkCommandNames = ['font'.freeze].freeze
|
||||||
Tk_FontNameTBL = {}
|
|
||||||
Tk_FontUseTBL = {}
|
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
Tk_FontID = ["@font".freeze, "00000"]
|
||||||
|
Tk_FontNameTBL = TkCore::INTERP.create_table
|
||||||
|
Tk_FontUseTBL = TkCore::INTERP.create_table
|
||||||
|
|
||||||
def self.__init_tables__
|
TkCore::INTERP.init_ip_env{
|
||||||
Tk_FontNameTBL.clear
|
Tk_FontNameTBL.clear
|
||||||
Tk_FontUseTBL.clear
|
Tk_FontUseTBL.clear
|
||||||
Tk_FontID[0] = 0
|
}
|
||||||
end
|
|
||||||
|
|
||||||
# set default font
|
# set default font
|
||||||
case Tk::TK_VERSION
|
case Tk::TK_VERSION
|
||||||
@ -222,8 +221,8 @@ class TkFont
|
|||||||
private
|
private
|
||||||
###################################
|
###################################
|
||||||
def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=nil, keys=nil)
|
def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=nil, keys=nil)
|
||||||
@id = format("@font%.4d", Tk_FontID[0])
|
@id = Tk_FontID.join
|
||||||
Tk_FontID[0] += 1
|
Tk_FontID[1].succ!
|
||||||
Tk_FontNameTBL[@id] = self
|
Tk_FontNameTBL[@id] = self
|
||||||
knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj
|
knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj
|
||||||
create_compoundfont(ltn, knj, keys)
|
create_compoundfont(ltn, knj, keys)
|
||||||
|
@ -12,6 +12,8 @@ module TkMacResource
|
|||||||
extend Tk
|
extend Tk
|
||||||
extend TkMacResource
|
extend TkMacResource
|
||||||
|
|
||||||
|
TkCommandNames = ['resource'.freeze].freeze
|
||||||
|
|
||||||
tk_call('package', 'require', 'resource')
|
tk_call('package', 'require', 'resource')
|
||||||
|
|
||||||
def close(rsrcRef)
|
def close(rsrcRef)
|
||||||
|
@ -7,6 +7,12 @@ require 'tk'
|
|||||||
module TkManageFocus
|
module TkManageFocus
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = [
|
||||||
|
'tk_focusFollowMouse'.freeze,
|
||||||
|
'tk_focusNext'.freeze,
|
||||||
|
'tk_focusPrev'.freeze
|
||||||
|
].freeze
|
||||||
|
|
||||||
def TkManageFocus.followsMouse
|
def TkManageFocus.followsMouse
|
||||||
tk_call 'tk_focusFollowsMouse'
|
tk_call 'tk_focusFollowsMouse'
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,12 @@ module TkPalette
|
|||||||
include Tk
|
include Tk
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
|
TkCommandNames = [
|
||||||
|
'tk_setPalette'.freeze,
|
||||||
|
'tk_bisque'.freeze,
|
||||||
|
'tkDarken'.freeze
|
||||||
|
].freeze
|
||||||
|
|
||||||
def TkPalette.set(*args)
|
def TkPalette.set(*args)
|
||||||
args = args.to_a.flatten if args.kind_of? Hash
|
args = args.to_a.flatten if args.kind_of? Hash
|
||||||
tk_call 'tk_setPalette', *args
|
tk_call 'tk_setPalette', *args
|
||||||
|
@ -28,6 +28,7 @@ class TkText<TkTextWin
|
|||||||
include TkTreatTextTagFont
|
include TkTreatTextTagFont
|
||||||
include Scrollable
|
include Scrollable
|
||||||
|
|
||||||
|
TkCommandNames = ['text'.freeze].freeze
|
||||||
WidgetClassName = 'Text'.freeze
|
WidgetClassName = 'Text'.freeze
|
||||||
WidgetClassNames[WidgetClassName] = self
|
WidgetClassNames[WidgetClassName] = self
|
||||||
|
|
||||||
@ -765,15 +766,10 @@ end
|
|||||||
class TkTextTag<TkObject
|
class TkTextTag<TkObject
|
||||||
include TkTreatTagFont
|
include TkTreatTagFont
|
||||||
|
|
||||||
TTagID_TBL = {}
|
TTagID_TBL = TkCore::INTERP.create_table
|
||||||
Tk_TextTag_ID = ['tag0000']
|
Tk_TextTag_ID = ['tag', '00000']
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.init_ip_env{ TTagID_TBL.clear }
|
||||||
|
|
||||||
def self.__init_tables__
|
|
||||||
TTagID_TBL.clear
|
|
||||||
Tk_TextTag_ID[0] = 'tag0000'
|
|
||||||
end
|
|
||||||
|
|
||||||
def TkTextTag.id2obj(text, id)
|
def TkTextTag.id2obj(text, id)
|
||||||
tpath = text.path
|
tpath = text.path
|
||||||
@ -787,11 +783,11 @@ class TkTextTag<TkObject
|
|||||||
end
|
end
|
||||||
@parent = @t = parent
|
@parent = @t = parent
|
||||||
@tpath = parent.path
|
@tpath = parent.path
|
||||||
@path = @id = Tk_TextTag_ID[0]
|
@path = @id = Tk_TextTag_ID.join
|
||||||
TTagID_TBL[@id] = self
|
TTagID_TBL[@id] = self
|
||||||
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
|
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
|
||||||
TTagID_TBL[@tpath][@id] = self
|
TTagID_TBL[@tpath][@id] = self
|
||||||
Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ
|
Tk_TextTag_ID[1].succ!
|
||||||
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
|
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
|
||||||
if args != [] then
|
if args != [] then
|
||||||
keys = args.pop
|
keys = args.pop
|
||||||
@ -974,15 +970,10 @@ class TkTextTagSel<TkTextNamedTag
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TkTextMark<TkObject
|
class TkTextMark<TkObject
|
||||||
TMarkID_TBL = {}
|
TMarkID_TBL = TkCore::INTERP.create_table
|
||||||
Tk_TextMark_ID = ['mark0000']
|
Tk_TextMark_ID = ['mark', '00000']
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear }
|
||||||
|
|
||||||
def self.__init_tables__
|
|
||||||
TMarkID_TBL.clear
|
|
||||||
Tk_TextMark_ID[0] = 'mark0000'
|
|
||||||
end
|
|
||||||
|
|
||||||
def TkTextMark.id2obj(text, id)
|
def TkTextMark.id2obj(text, id)
|
||||||
tpath = text.path
|
tpath = text.path
|
||||||
@ -996,7 +987,7 @@ class TkTextMark<TkObject
|
|||||||
end
|
end
|
||||||
@parent = @t = parent
|
@parent = @t = parent
|
||||||
@tpath = parent.path
|
@tpath = parent.path
|
||||||
@path = @id = Tk_TextMark_ID[0]
|
@path = @id = Tk_TextMark_ID.join
|
||||||
TMarkID_TBL[@id] = self
|
TMarkID_TBL[@id] = self
|
||||||
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
|
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
|
||||||
TMarkID_TBL[@tpath][@id] = self
|
TMarkID_TBL[@tpath][@id] = self
|
||||||
|
@ -7,15 +7,12 @@ require 'tk'
|
|||||||
class TkVirtualEvent<TkObject
|
class TkVirtualEvent<TkObject
|
||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
TkVirtualEventID = [0]
|
TkCommandNames = ['event'.freeze].freeze
|
||||||
TkVirtualEventTBL = {}
|
|
||||||
|
|
||||||
TkComm.__add_target_for_init__(self)
|
TkVirtualEventID = ["<VirtEvent".freeze, "00000", ">".freeze]
|
||||||
|
TkVirtualEventTBL = TkCore::INTERP.create_table
|
||||||
|
|
||||||
def self.__init_tables__
|
TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }
|
||||||
TkVirtualEventTBL.clear
|
|
||||||
TkVirtualEventID[0] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
class PreDefVirtEvent<self
|
class PreDefVirtEvent<self
|
||||||
def initialize(event)
|
def initialize(event)
|
||||||
@ -44,8 +41,8 @@ class TkVirtualEvent<TkObject
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*sequences)
|
def initialize(*sequences)
|
||||||
@path = @id = format("<VirtEvent%.4d>", TkVirtualEventID[0])
|
@path = @id = TkVirtualEventID.join
|
||||||
TkVirtualEventID[0] += 1
|
TkVirtualEventID[1].succ!
|
||||||
add(*sequences)
|
add(*sequences)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ module TkWinDDE
|
|||||||
extend Tk
|
extend Tk
|
||||||
extend TkWinDDE
|
extend TkWinDDE
|
||||||
|
|
||||||
|
TkCommandNames = ['dde'.freeze].freeze
|
||||||
|
|
||||||
tk_call('package', 'require', 'dde')
|
tk_call('package', 'require', 'dde')
|
||||||
|
|
||||||
def servername(topic=nil)
|
def servername(topic=nil)
|
||||||
@ -50,6 +52,8 @@ module TkWinRegistry
|
|||||||
extend Tk
|
extend Tk
|
||||||
extend TkWinRegistry
|
extend TkWinRegistry
|
||||||
|
|
||||||
|
TkCommandNames = ['registry'.freeze].freeze
|
||||||
|
|
||||||
tk_call('package', 'require', 'registry')
|
tk_call('package', 'require', 'registry')
|
||||||
|
|
||||||
def delete(keynam, valnam=nil)
|
def delete(keynam, valnam=nil)
|
||||||
|
558
process.c
558
process.c
@ -1288,128 +1288,128 @@ p_uid_change_privilege(obj, id)
|
|||||||
|
|
||||||
if (geteuid() == 0) { /* root-user */
|
if (geteuid() == 0) { /* root-user */
|
||||||
#if defined(HAVE_SETRESUID)
|
#if defined(HAVE_SETRESUID)
|
||||||
if (setresuid(uid, uid, uid) < 0) rb_sys_fail(0);
|
if (setresuid(uid, uid, uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
|
||||||
#elif defined(HAVE_SETUID)
|
|
||||||
if (setuid(uid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = uid;
|
|
||||||
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
|
||||||
if (getuid() == uid) {
|
|
||||||
if (SAVED_USER_ID == uid) {
|
|
||||||
if (setreuid(-1, uid) < 0) rb_sys_fail(0);
|
|
||||||
} else {
|
|
||||||
if (uid == 0) { /* (r,e,s) == (root, root, x) */
|
|
||||||
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
|
|
||||||
if (setreuid(SAVED_USER_ID, 0) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = 0; /* (r,e,s) == (x, root, root) */
|
|
||||||
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = uid;
|
|
||||||
} else {
|
|
||||||
if (setreuid(0, -1) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = 0;
|
|
||||||
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = uid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
}
|
#elif defined(HAVE_SETUID)
|
||||||
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
|
if (setuid(uid) < 0) rb_sys_fail(0);
|
||||||
if (getuid() == uid) {
|
SAVED_USER_ID = uid;
|
||||||
if (SAVED_USER_ID == uid) {
|
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
||||||
if (seteuid(uid) < 0) rb_sys_fail(0);
|
if (getuid() == uid) {
|
||||||
|
if (SAVED_USER_ID == uid) {
|
||||||
|
if (setreuid(-1, uid) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
if (uid == 0) { /* (r,e,s) == (root, root, x) */
|
||||||
|
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
|
||||||
|
if (setreuid(SAVED_USER_ID, 0) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = 0; /* (r,e,s) == (x, root, root) */
|
||||||
|
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = uid;
|
||||||
|
} else {
|
||||||
|
if (setreuid(0, -1) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = 0;
|
||||||
|
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = uid;
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
|
||||||
|
if (getuid() == uid) {
|
||||||
|
if (SAVED_USER_ID == uid) {
|
||||||
|
if (seteuid(uid) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
if (uid == 0) {
|
||||||
|
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = 0;
|
||||||
|
if (setruid(0) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
if (setruid(0) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = 0;
|
||||||
|
if (seteuid(uid) < 0) rb_sys_fail(0);
|
||||||
|
if (setruid(uid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (uid == 0) {
|
|
||||||
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = 0;
|
|
||||||
if (setruid(0) < 0) rb_sys_fail(0);
|
|
||||||
} else {
|
|
||||||
if (setruid(0) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = 0;
|
|
||||||
if (seteuid(uid) < 0) rb_sys_fail(0);
|
if (seteuid(uid) < 0) rb_sys_fail(0);
|
||||||
if (setruid(uid) < 0) rb_sys_fail(0);
|
if (setruid(uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (seteuid(uid) < 0) rb_sys_fail(0);
|
|
||||||
if (setruid(uid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = uid;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif
|
#endif
|
||||||
} else { /* unprivileged user */
|
} else { /* unprivileged user */
|
||||||
#if defined(HAVE_SETRESUID)
|
#if defined(HAVE_SETRESUID)
|
||||||
if (setresuid((getuid() == uid)? -1: uid,
|
if (setresuid((getuid() == uid)? -1: uid,
|
||||||
(geteuid() == uid)? -1: uid,
|
(geteuid() == uid)? -1: uid,
|
||||||
(SAVED_USER_ID == uid)? -1: uid) < 0) rb_sys_fail(0);
|
(SAVED_USER_ID == uid)? -1: uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
||||||
if (SAVED_USER_ID == uid) {
|
if (SAVED_USER_ID == uid) {
|
||||||
if (setreuid((getuid() == uid)? -1: uid,
|
if (setreuid((getuid() == uid)? -1: uid,
|
||||||
(geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
|
(geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
|
||||||
} else if (getuid() != uid) {
|
} else if (getuid() != uid) {
|
||||||
if (setreuid(uid, (geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
|
if (setreuid(uid, (geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
} else if (/* getuid() == uid && */ geteuid() != uid) {
|
} else if (/* getuid() == uid && */ geteuid() != uid) {
|
||||||
if (setreuid(geteuid(), uid) < 0) rb_sys_fail(0);
|
if (setreuid(geteuid(), uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
|
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
|
||||||
} else { /* getuid() == uid && geteuid() == uid */
|
} else { /* getuid() == uid && geteuid() == uid */
|
||||||
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
|
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
|
||||||
if (setreuid(SAVED_USER_ID, uid) < 0) rb_sys_fail(0);
|
if (setreuid(SAVED_USER_ID, uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
|
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
|
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
|
||||||
if (SAVED_USER_ID == uid) {
|
if (SAVED_USER_ID == uid) {
|
||||||
if (geteuid() != uid && seteuid(uid) < 0) rb_sys_fail(0);
|
if (geteuid() != uid && seteuid(uid) < 0) rb_sys_fail(0);
|
||||||
if (getuid() != uid && setruid(uid) < 0) rb_sys_fail(0);
|
if (getuid() != uid && setruid(uid) < 0) rb_sys_fail(0);
|
||||||
} else if (/* SAVED_USER_ID != uid && */ geteuid() == uid) {
|
} else if (/* SAVED_USER_ID != uid && */ geteuid() == uid) {
|
||||||
if (getuid() != uid) {
|
if (getuid() != uid) {
|
||||||
if (setruid(uid) < 0) rb_sys_fail(0);
|
if (setruid(uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
} else {
|
} else {
|
||||||
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
|
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
if (setruid(uid) < 0) rb_sys_fail(0);
|
if (setruid(uid) < 0) rb_sys_fail(0);
|
||||||
|
}
|
||||||
|
} else if (/* geteuid() != uid && */ getuid() == uid) {
|
||||||
|
if (seteuid(uid) < 0) rb_sys_fail(0);
|
||||||
|
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_USER_ID = uid;
|
||||||
|
if (setruid(uid) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
errno = EPERM;
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
} else if (/* geteuid() != uid && */ getuid() == uid) {
|
|
||||||
if (seteuid(uid) < 0) rb_sys_fail(0);
|
|
||||||
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_USER_ID = uid;
|
|
||||||
if (setruid(uid) < 0) rb_sys_fail(0);
|
|
||||||
} else {
|
|
||||||
errno = EPERM;
|
|
||||||
rb_sys_fail(0);
|
|
||||||
}
|
|
||||||
#elif defined HAVE_44BSD_SETUID
|
#elif defined HAVE_44BSD_SETUID
|
||||||
if (getuid() == uid) {
|
if (getuid() == uid) {
|
||||||
/* (r,e,s)==(uid,?,?) ==> (uid,uid,uid) */
|
/* (r,e,s)==(uid,?,?) ==> (uid,uid,uid) */
|
||||||
if (setuid(uid) < 0) rb_sys_fail(0);
|
if (setuid(uid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = uid;
|
SAVED_USER_ID = uid;
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined HAVE_SETEUID
|
#elif defined HAVE_SETEUID
|
||||||
if (getuid() == uid && SAVED_USER_ID == uid) {
|
if (getuid() == uid && SAVED_USER_ID == uid) {
|
||||||
if (seteuid(uid) < 0) rb_sys_fail(0);
|
if (seteuid(uid) < 0) rb_sys_fail(0);
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined HAVE_SETUID
|
#elif defined HAVE_SETUID
|
||||||
if (getuid() == uid && SAVED_USER_ID == uid) {
|
if (getuid() == uid && SAVED_USER_ID == uid) {
|
||||||
if (setuid(uid) < 0) rb_sys_fail(0);
|
if (setuid(uid) < 0) rb_sys_fail(0);
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return INT2FIX(uid);
|
return INT2FIX(uid);
|
||||||
@ -1481,9 +1481,9 @@ p_sys_issetugid(obj)
|
|||||||
{
|
{
|
||||||
#if defined HAVE_ISSETUGID
|
#if defined HAVE_ISSETUGID
|
||||||
if (issetugid()) {
|
if (issetugid()) {
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
} else {
|
} else {
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
@ -1586,7 +1586,8 @@ proc_setgroups(VALUE obj, VALUE ary)
|
|||||||
else {
|
else {
|
||||||
gr = getgrnam(RSTRING(g)->ptr);
|
gr = getgrnam(RSTRING(g)->ptr);
|
||||||
if (gr == NULL)
|
if (gr == NULL)
|
||||||
rb_raise(rb_eArgError, "can't find group for %s", RSTRING(g)->ptr);
|
rb_raise(rb_eArgError,
|
||||||
|
"can't find group for %s", RSTRING(g)->ptr);
|
||||||
groups[i] = gr->gr_gid;
|
groups[i] = gr->gr_gid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1605,7 +1606,7 @@ proc_setgroups(VALUE obj, VALUE ary)
|
|||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
proc_initgroups(obj, uname, base_grp)
|
proc_initgroups(obj, uname, base_grp)
|
||||||
VALUE obj, uname, base_grp;
|
VALUE obj, uname, base_grp;
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INITGROUPS
|
#ifdef HAVE_INITGROUPS
|
||||||
if (initgroups(StringValuePtr(uname), (gid_t)NUM2INT(base_grp)) != 0) {
|
if (initgroups(StringValuePtr(uname), (gid_t)NUM2INT(base_grp)) != 0) {
|
||||||
@ -1632,7 +1633,7 @@ proc_setmaxgroups(obj, val)
|
|||||||
size_t ngroups = FIX2INT(val);
|
size_t ngroups = FIX2INT(val);
|
||||||
|
|
||||||
if (ngroups > 4096)
|
if (ngroups > 4096)
|
||||||
ngroups = 4096;
|
ngroups = 4096;
|
||||||
|
|
||||||
maxgroups = ngroups;
|
maxgroups = ngroups;
|
||||||
|
|
||||||
@ -1652,129 +1653,129 @@ p_gid_change_privilege(obj, id)
|
|||||||
|
|
||||||
if (geteuid() == 0) { /* root-user */
|
if (geteuid() == 0) { /* root-user */
|
||||||
#if defined(HAVE_SETRESGID)
|
#if defined(HAVE_SETRESGID)
|
||||||
if (setresgid(gid, gid, gid) < 0) rb_sys_fail(0);
|
if (setresgid(gid, gid, gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
|
||||||
#elif defined HAVE_SETGID
|
|
||||||
if (setgid(gid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = gid;
|
|
||||||
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
|
||||||
if (getgid() == gid) {
|
|
||||||
if (SAVED_GROUP_ID == gid) {
|
|
||||||
if (setregid(-1, gid) < 0) rb_sys_fail(0);
|
|
||||||
} else {
|
|
||||||
if (gid == 0) { /* (r,e,s) == (root, y, x) */
|
|
||||||
if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
|
||||||
if (setregid(SAVED_GROUP_ID, 0) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = 0; /* (r,e,s) == (x, root, root) */
|
|
||||||
if (setregid(gid, gid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = gid;
|
|
||||||
} else { /* (r,e,s) == (z, y, x) */
|
|
||||||
if (setregid(0, 0) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = 0;
|
|
||||||
if (setregid(gid, gid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = gid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (setregid(gid, gid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
}
|
#elif defined HAVE_SETGID
|
||||||
#elif defined(HAVE_SETRGID) && defined (HAVE_SETEGID)
|
if (setgid(gid) < 0) rb_sys_fail(0);
|
||||||
if (getgid() == gid) {
|
SAVED_GROUP_ID = gid;
|
||||||
if (SAVED_GROUP_ID == gid) {
|
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
||||||
if (setegid(gid) < 0) rb_sys_fail(0);
|
if (getgid() == gid) {
|
||||||
|
if (SAVED_GROUP_ID == gid) {
|
||||||
|
if (setregid(-1, gid) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
if (gid == 0) { /* (r,e,s) == (root, y, x) */
|
||||||
|
if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
||||||
|
if (setregid(SAVED_GROUP_ID, 0) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = 0; /* (r,e,s) == (x, root, root) */
|
||||||
|
if (setregid(gid, gid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = gid;
|
||||||
|
} else { /* (r,e,s) == (z, y, x) */
|
||||||
|
if (setregid(0, 0) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = 0;
|
||||||
|
if (setregid(gid, gid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (setregid(gid, gid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = gid;
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_SETRGID) && defined (HAVE_SETEGID)
|
||||||
|
if (getgid() == gid) {
|
||||||
|
if (SAVED_GROUP_ID == gid) {
|
||||||
|
if (setegid(gid) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
if (gid == 0) {
|
||||||
|
if (setegid(gid) < 0) rb_sys_fail(0);
|
||||||
|
if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = 0;
|
||||||
|
if (setrgid(0) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
if (setrgid(0) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = 0;
|
||||||
|
if (setegid(gid) < 0) rb_sys_fail(0);
|
||||||
|
if (setrgid(gid) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gid == 0) {
|
|
||||||
if (setegid(gid) < 0) rb_sys_fail(0);
|
|
||||||
if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = 0;
|
|
||||||
if (setrgid(0) < 0) rb_sys_fail(0);
|
|
||||||
} else {
|
|
||||||
if (setrgid(0) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = 0;
|
|
||||||
if (setegid(gid) < 0) rb_sys_fail(0);
|
if (setegid(gid) < 0) rb_sys_fail(0);
|
||||||
if (setrgid(gid) < 0) rb_sys_fail(0);
|
if (setrgid(gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (setegid(gid) < 0) rb_sys_fail(0);
|
|
||||||
if (setrgid(gid) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = gid;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif
|
#endif
|
||||||
} else { /* unprivileged user */
|
} else { /* unprivileged user */
|
||||||
#if defined(HAVE_SETRESGID)
|
#if defined(HAVE_SETRESGID)
|
||||||
if (setresgid((getgid() == gid)? -1: gid,
|
if (setresgid((getgid() == gid)? -1: gid,
|
||||||
(getegid() == gid)? -1: gid,
|
(getegid() == gid)? -1: gid,
|
||||||
(SAVED_GROUP_ID == gid)? -1: gid) < 0) rb_sys_fail(0);
|
(SAVED_GROUP_ID == gid)? -1: gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
||||||
if (SAVED_GROUP_ID == gid) {
|
if (SAVED_GROUP_ID == gid) {
|
||||||
if (setregid((getgid() == gid)? -1: gid,
|
if (setregid((getgid() == gid)? -1: gid,
|
||||||
(getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
|
(getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
|
||||||
} else if (getgid() != gid) {
|
} else if (getgid() != gid) {
|
||||||
if (setregid(gid, (getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
|
if (setregid(gid, (getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
} else if (/* getgid() == gid && */ getegid() != gid) {
|
} else if (/* getgid() == gid && */ getegid() != gid) {
|
||||||
if (setregid(getegid(), gid) < 0) rb_sys_fail(0);
|
if (setregid(getegid(), gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
if (setregid(gid, -1) < 0) rb_sys_fail(0);
|
if (setregid(gid, -1) < 0) rb_sys_fail(0);
|
||||||
} else { /* getgid() == gid && getegid() == gid */
|
} else { /* getgid() == gid && getegid() == gid */
|
||||||
if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
||||||
if (setregid(SAVED_GROUP_ID, gid) < 0) rb_sys_fail(0);
|
if (setregid(SAVED_GROUP_ID, gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
if (setregid(gid, -1) < 0) rb_sys_fail(0);
|
if (setregid(gid, -1) < 0) rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined(HAVE_SETRGID) && defined(HAVE_SETEGID)
|
#elif defined(HAVE_SETRGID) && defined(HAVE_SETEGID)
|
||||||
if (SAVED_GROUP_ID == gid) {
|
if (SAVED_GROUP_ID == gid) {
|
||||||
if (getegid() != gid && setegid(gid) < 0) rb_sys_fail(0);
|
if (getegid() != gid && setegid(gid) < 0) rb_sys_fail(0);
|
||||||
if (getgid() != gid && setrgid(gid) < 0) rb_sys_fail(0);
|
if (getgid() != gid && setrgid(gid) < 0) rb_sys_fail(0);
|
||||||
} else if (/* SAVED_GROUP_ID != gid && */ getegid() == gid) {
|
} else if (/* SAVED_GROUP_ID != gid && */ getegid() == gid) {
|
||||||
if (getgid() != gid) {
|
if (getgid() != gid) {
|
||||||
if (setrgid(gid) < 0) rb_sys_fail(0);
|
if (setrgid(gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
} else {
|
} else {
|
||||||
if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
if (setrgid(gid) < 0) rb_sys_fail(0);
|
if (setrgid(gid) < 0) rb_sys_fail(0);
|
||||||
|
}
|
||||||
|
} else if (/* getegid() != gid && */ getgid() == gid) {
|
||||||
|
if (setegid(gid) < 0) rb_sys_fail(0);
|
||||||
|
if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
||||||
|
SAVED_GROUP_ID = gid;
|
||||||
|
if (setrgid(gid) < 0) rb_sys_fail(0);
|
||||||
|
} else {
|
||||||
|
errno = EPERM;
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
} else if (/* getegid() != gid && */ getgid() == gid) {
|
|
||||||
if (setegid(gid) < 0) rb_sys_fail(0);
|
|
||||||
if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
|
|
||||||
SAVED_GROUP_ID = gid;
|
|
||||||
if (setrgid(gid) < 0) rb_sys_fail(0);
|
|
||||||
} else {
|
|
||||||
errno = EPERM;
|
|
||||||
rb_sys_fail(0);
|
|
||||||
}
|
|
||||||
#elif defined HAVE_44BSD_SETGID
|
#elif defined HAVE_44BSD_SETGID
|
||||||
if (getgid() == gid) {
|
if (getgid() == gid) {
|
||||||
/* (r,e,s)==(gid,?,?) ==> (gid,gid,gid) */
|
/* (r,e,s)==(gid,?,?) ==> (gid,gid,gid) */
|
||||||
if (setgid(gid) < 0) rb_sys_fail(0);
|
if (setgid(gid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = gid;
|
SAVED_GROUP_ID = gid;
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined HAVE_SETEGID
|
#elif defined HAVE_SETEGID
|
||||||
if (getgid() == gid && SAVED_GROUP_ID == gid) {
|
if (getgid() == gid && SAVED_GROUP_ID == gid) {
|
||||||
if (setegid(gid) < 0) rb_sys_fail(0);
|
if (setegid(gid) < 0) rb_sys_fail(0);
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined HAVE_SETGID
|
#elif defined HAVE_SETGID
|
||||||
if (getgid() == gid && SAVED_GROUP_ID == gid) {
|
if (getgid() == gid && SAVED_GROUP_ID == gid) {
|
||||||
if (setgid(gid) < 0) rb_sys_fail(0);
|
if (setgid(gid) < 0) rb_sys_fail(0);
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return INT2FIX(gid);
|
return INT2FIX(gid);
|
||||||
@ -1822,17 +1823,17 @@ rb_seteuid_core(euid)
|
|||||||
|
|
||||||
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
|
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
|
||||||
if (uid != euid) {
|
if (uid != euid) {
|
||||||
if (setresuid(-1,euid,euid) < 0) rb_sys_fail(0);
|
if (setresuid(-1,euid,euid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = euid;
|
SAVED_USER_ID = euid;
|
||||||
} else {
|
} else {
|
||||||
if (setresuid(-1,euid,-1) < 0) rb_sys_fail(0);
|
if (setresuid(-1,euid,-1) < 0) rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
||||||
if (setreuid(-1, euid) < 0) rb_sys_fail(0);
|
if (setreuid(-1, euid) < 0) rb_sys_fail(0);
|
||||||
if (uid != euid) {
|
if (uid != euid) {
|
||||||
if (setreuid(euid,uid) < 0) rb_sys_fail(0);
|
if (setreuid(euid,uid) < 0) rb_sys_fail(0);
|
||||||
if (setreuid(uid,euid) < 0) rb_sys_fail(0);
|
if (setreuid(uid,euid) < 0) rb_sys_fail(0);
|
||||||
SAVED_USER_ID = euid;
|
SAVED_USER_ID = euid;
|
||||||
}
|
}
|
||||||
#elif defined HAVE_SETEUID
|
#elif defined HAVE_SETEUID
|
||||||
if (seteuid(euid) < 0) rb_sys_fail(0);
|
if (seteuid(euid) < 0) rb_sys_fail(0);
|
||||||
@ -1849,7 +1850,7 @@ static VALUE
|
|||||||
p_uid_grant_privilege(obj, id)
|
p_uid_grant_privilege(obj, id)
|
||||||
VALUE obj, id;
|
VALUE obj, id;
|
||||||
{
|
{
|
||||||
return rb_seteuid_core(NUM2INT(id));
|
return rb_seteuid_core(NUM2INT(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -1896,17 +1897,17 @@ rb_setegid_core(egid)
|
|||||||
|
|
||||||
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
|
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
|
||||||
if (gid != egid) {
|
if (gid != egid) {
|
||||||
if (setresgid(-1,egid,egid) < 0) rb_sys_fail(0);
|
if (setresgid(-1,egid,egid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = egid;
|
SAVED_GROUP_ID = egid;
|
||||||
} else {
|
} else {
|
||||||
if (setresgid(-1,egid,-1) < 0) rb_sys_fail(0);
|
if (setresgid(-1,egid,-1) < 0) rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
||||||
if (setregid(-1, egid) < 0) rb_sys_fail(0);
|
if (setregid(-1, egid) < 0) rb_sys_fail(0);
|
||||||
if (gid != egid) {
|
if (gid != egid) {
|
||||||
if (setregid(egid,gid) < 0) rb_sys_fail(0);
|
if (setregid(egid,gid) < 0) rb_sys_fail(0);
|
||||||
if (setregid(gid,egid) < 0) rb_sys_fail(0);
|
if (setregid(gid,egid) < 0) rb_sys_fail(0);
|
||||||
SAVED_GROUP_ID = egid;
|
SAVED_GROUP_ID = egid;
|
||||||
}
|
}
|
||||||
#elif defined HAVE_SETEGID
|
#elif defined HAVE_SETEGID
|
||||||
if (setegid(egid) < 0) rb_sys_fail(0);
|
if (setegid(egid) < 0) rb_sys_fail(0);
|
||||||
@ -1923,18 +1924,18 @@ static VALUE
|
|||||||
p_gid_grant_privilege(obj, id)
|
p_gid_grant_privilege(obj, id)
|
||||||
VALUE obj, id;
|
VALUE obj, id;
|
||||||
{
|
{
|
||||||
return rb_setegid_core(NUM2INT(id));
|
return rb_setegid_core(NUM2INT(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
p_uid_exchangeable()
|
p_uid_exchangeable()
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
|
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
#else
|
#else
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1963,11 +1964,11 @@ static VALUE
|
|||||||
p_gid_exchangeable()
|
p_gid_exchangeable()
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
|
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
#else
|
#else
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1996,9 +1997,9 @@ static VALUE
|
|||||||
p_uid_have_saved_id()
|
p_uid_have_saved_id()
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || _POSIX_SAVED_IDS
|
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || _POSIX_SAVED_IDS
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
#else
|
#else
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2014,33 +2015,33 @@ p_uid_switch(obj)
|
|||||||
|
|
||||||
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || _POSIX_SAVED_IDS
|
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || _POSIX_SAVED_IDS
|
||||||
if (uid != euid) {
|
if (uid != euid) {
|
||||||
proc_seteuid(obj, INT2FIX(uid));
|
proc_seteuid(obj, INT2FIX(uid));
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
return rb_ensure(rb_yield, Qnil, rb_seteuid_core, SAVED_USER_ID);
|
return rb_ensure(rb_yield, Qnil, rb_seteuid_core, SAVED_USER_ID);
|
||||||
} else {
|
} else {
|
||||||
return INT2FIX(euid);
|
return INT2FIX(euid);
|
||||||
}
|
}
|
||||||
} else if (euid != SAVED_USER_ID) {
|
} else if (euid != SAVED_USER_ID) {
|
||||||
proc_seteuid(obj, INT2FIX(SAVED_USER_ID));
|
proc_seteuid(obj, INT2FIX(SAVED_USER_ID));
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
return rb_ensure(rb_yield, Qnil, rb_seteuid_core, euid);
|
return rb_ensure(rb_yield, Qnil, rb_seteuid_core, euid);
|
||||||
} else {
|
} else {
|
||||||
return INT2FIX(uid);
|
return INT2FIX(uid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (uid == euid) {
|
if (uid == euid) {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
p_uid_switch(obj);
|
p_uid_switch(obj);
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
return rb_ensure(rb_yield, Qnil, p_uid_switch, obj);
|
return rb_ensure(rb_yield, Qnil, p_uid_switch, obj);
|
||||||
} else {
|
} else {
|
||||||
return INT2FIX(euid);
|
return INT2FIX(euid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2049,9 +2050,9 @@ static VALUE
|
|||||||
p_gid_have_saved_id()
|
p_gid_have_saved_id()
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || _POSIX_SAVED_IDS
|
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || _POSIX_SAVED_IDS
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
#else
|
#else
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2067,33 +2068,34 @@ p_gid_switch(obj)
|
|||||||
|
|
||||||
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || _POSIX_SAVED_IDS
|
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || _POSIX_SAVED_IDS
|
||||||
if (gid != egid) {
|
if (gid != egid) {
|
||||||
proc_setegid(obj, INT2FIX(gid));
|
proc_setegid(obj, INT2FIX(gid));
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
return rb_ensure(rb_yield, Qnil, proc_setegid, INT2FIX(SAVED_GROUP_ID));
|
return rb_ensure(rb_yield, Qnil, proc_setegid,
|
||||||
} else {
|
INT2FIX(SAVED_GROUP_ID));
|
||||||
return INT2FIX(egid);
|
} else {
|
||||||
}
|
return INT2FIX(egid);
|
||||||
|
}
|
||||||
} else if (egid != SAVED_GROUP_ID) {
|
} else if (egid != SAVED_GROUP_ID) {
|
||||||
proc_setegid(obj, INT2FIX(SAVED_GROUP_ID));
|
proc_setegid(obj, INT2FIX(SAVED_GROUP_ID));
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
return rb_ensure(rb_yield, Qnil, proc_setegid, INT2FIX(egid));
|
return rb_ensure(rb_yield, Qnil, proc_setegid, INT2FIX(egid));
|
||||||
} else {
|
} else {
|
||||||
return INT2FIX(gid);
|
return INT2FIX(gid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (gid == egid) {
|
if (gid == egid) {
|
||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
p_gid_switch(obj);
|
p_gid_switch(obj);
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
return rb_ensure(rb_yield, Qnil, p_gid_switch, obj);
|
return rb_ensure(rb_yield, Qnil, p_gid_switch, obj);
|
||||||
} else {
|
} else {
|
||||||
return INT2FIX(egid);
|
return INT2FIX(egid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user