summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-31 23:04:45 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-31 23:04:45 +0000
commitbc8b42fc1eb3f1adf9d170dc353a33f53bdab92f (patch)
tree197128d19a69a4d98898914df795f35c2aa631bc /ext
parent75362fbd47cedf4b4906a361a6c54bc4ad8ea5ec (diff)
* bug fix : wrong resource file format (resource.{en,jp})
* add Tk::Encoding.{encoding_convertfrom, encoding_convertto} * add TkOptionDB.read_with_encoding to read non-utf8 resource file git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/tk/lib/multi-tk.rb2
-rw-r--r--ext/tk/lib/tk.rb66
-rw-r--r--ext/tk/sample/resource.en6
-rw-r--r--ext/tk/sample/resource.ja6
-rw-r--r--ext/tk/sample/tkoptdb.rb4
5 files changed, 72 insertions, 12 deletions
diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb
index af94204252..c74b5714b8 100644
--- a/ext/tk/lib/multi-tk.rb
+++ b/ext/tk/lib/multi-tk.rb
@@ -1155,8 +1155,6 @@ class MultiTkIp
# from tkencoding.rb by ttate@jaist.ac.jp
alias __eval _eval
alias __invoke _invoke
- private :__eval
- private :__invoke
def encoding
@encoding[0]
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 0a9aacaaa5..d22f7b43d7 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -1509,8 +1509,6 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
# from tkencoding.rb by ttate@jaist.ac.jp
alias __eval _eval
alias __invoke _invoke
- private :__eval
- private :__invoke
attr_accessor :encoding
@@ -1521,7 +1519,7 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
__eval(cmd)
end
end
-
+
def _invoke(*cmds)
if defined? @encoding
cmds = cmds.collect{|cmd| _toUTF8(cmd, @encoding)}
@@ -1557,6 +1555,16 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
def encoding_system=(enc)
tk_call('encoding', 'system', enc)
end
+
+ def encoding_convertfrom(str, enc=None)
+ TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
+ end
+ alias encoding_convert_from encoding_convertfrom
+
+ def encoding_convertto(str, enc=None)
+ TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
+ end
+ alias encoding_convert_to encoding_convertto
end
extend Encoding
@@ -1580,6 +1588,11 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
else
# dummy methods
+ class TclTkIp
+ alias __eval _eval
+ alias __invoke _invoke
+ end
+
module Tk
module Encoding
extend Encoding
@@ -1599,6 +1612,16 @@ else
def encoding_system=(enc)
nil
end
+
+ def encoding_convertfrom(str, enc=None)
+ str
+ end
+ alias encoding_convert_from encoding_convertfrom
+
+ def encoding_convertto(str, enc=None)
+ str
+ end
+ alias encoding_convert_to encoding_convertto
end
extend Encoding
@@ -2848,6 +2871,43 @@ module TkOptionDB
tk_call 'option', 'readfile', file, pri
end
module_function :add, :clear, :get, :readfile
+
+ def read_with_encoding(file, f_enc=nil, pri=None)
+ i_enc = Tk.encoding()
+
+ unless f_enc
+ f_enc = i_enc
+ end
+
+ cline = ''
+ open(file, 'r') {|f|
+ while line = f.gets
+ cline += line.chomp!
+ case cline
+ when /\\$/ # continue
+ cline.chop!
+ next
+ when /^!/ # coment
+ cline = ''
+ next
+ when /^([^:]+):\s(.*)$/
+ pat = $1
+ val = $2
+ p "ResourceDB: #{[pat, val].inspect}" if $DEBUG
+ pat = TkCore::INTERP._toUTF8(pat, f_enc)
+ pat = TkCore::INTERP._fromUTF8(pat, i_enc)
+ val = TkCore::INTERP._toUTF8(val, f_enc)
+ val = TkCore::INTERP._fromUTF8(val, i_enc)
+ add(pat, val, pri)
+ cline = ''
+ else # unknown --> ignore
+ cline = ''
+ next
+ end
+ end
+ }
+ end
+ module_function :read_with_encoding
# support procs on the resource database
@@resource_proc_class = Class.new
diff --git a/ext/tk/sample/resource.en b/ext/tk/sample/resource.en
index 29bd587ea2..bfdc809278 100644
--- a/ext/tk/sample/resource.en
+++ b/ext/tk/sample/resource.en
@@ -1,6 +1,6 @@
-#
-# see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
-#
+!
+! see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
+!
*BtnFrame.borderWidth: 5
*BtnFrame.relief: ridge
*BtnFrame.Button.background: wheat
diff --git a/ext/tk/sample/resource.ja b/ext/tk/sample/resource.ja
index 61098db4f8..8b715f36b0 100644
--- a/ext/tk/sample/resource.ja
+++ b/ext/tk/sample/resource.ja
@@ -1,6 +1,6 @@
-#
-# see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
-#
+!
+! see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
+!
*BtnFrame.borderWidth: 5
*BtnFrame.relief: ridge
*BtnFrame.Button.background: wheat
diff --git a/ext/tk/sample/tkoptdb.rb b/ext/tk/sample/tkoptdb.rb
index 066bd9501a..6cb3d17993 100644
--- a/ext/tk/sample/tkoptdb.rb
+++ b/ext/tk/sample/tkoptdb.rb
@@ -10,7 +10,9 @@ require "tk"
if ENV['LANG'] =~ /^ja/
# read Japanese resource
- TkOptionDB.readfile(File.expand_path('resource.ja', File.dirname(__FILE__)))
+ TkOptionDB.read_with_encoding(File.expand_path('resource.ja',
+ File.dirname(__FILE__)),
+ 'euc-jp')
else
# read English resource
TkOptionDB.readfile(File.expand_path('resource.en', File.dirname(__FILE__)))