X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fruby.git;a=blobdiff_plain;f=chise%2Flibchise_r.rb;fp=chise%2Flibchise_r.rb;h=f0556f038d4f96b26ae59a403b229f9957b669a7;hp=dbc421d8de47a0d1275e8a91de60999db70d9ead;hb=98b534b0449bdeedcba40a1f692764569fe63ac7;hpb=9b4963acbdbc25c39a502d98a77e7de43d7d1c77 diff --git a/chise/libchise_r.rb b/chise/libchise_r.rb index dbc421d..f0556f0 100755 --- a/chise/libchise_r.rb +++ b/chise/libchise_r.rb @@ -11,6 +11,20 @@ module CHISE module ChiseValue; end module TableAccessModule; end + module EachEntryModule + def each_entry(subdir) + #dir = @location + subdir + dir = DataSource::DB_DIR.path + subdir + dir.each_entry {|f| + #p f + next if f.to_s == "." || f.to_s == ".." + #next if f.to_s =~ /\.txt\Z/ + #yield(f.unescape_win_filename.unescape.to_s) + yield(f.to_s) + } + end + end + class DataSource_R NONE = 0 Berkeley_DB = 1 @@ -18,14 +32,14 @@ module CHISE def initialize(type=Berkeley_DB, loc=DB_DIR, subtype=0, modemask=0755) @type = type - loc = Config.instance.db_dir if loc.nil? + #loc = Config.instance.db_dir if loc.nil? @location = loc.path @subtype = subtype @modemask = modemask @fdb = {} @cdb = {} end - attr_reader :type, :subtype, :modemask + attr_reader :type, :location, :subtype, :modemask def close() end @@ -43,39 +57,34 @@ module CHISE each_entry("character/feature") {|f| yield f } end - def load_feature(name, cid) - ft = get_feature(name) - return nil if ft.nil? - ft.get_value(cid) + def load_feature(cid, name) + feature = get_feature(name) + return nil if feature.nil? + feature.get_value(cid) end def decode_char(ccs, code_point) - ct = get_ccs(ccs) - return nil if ct.nil? - ct.decode(code_point) + ccst = get_ccs(ccs) + return nil if ccst.nil? + ccst.decode(code_point) end private - def each_entry(subdir) - dir = @location + subdir - dir.each_entry {|f| - next if f.to_s == "." || f.to_s == ".." - next if f.to_s =~ /\.txt\Z/ - yield(f.unescape_win_filename.unescape.to_s) - } - end + include EachEntryModule end class AttributeTable def initialize(dir, cat, keytype, name, amask, mmask) @name = name + #qp name dbdir = dir + cat + keytype path = dbdir + name.path.escape.escape_win_filename if amask == BDB::RDONLY raise unless FileTest.exist?(path.to_s) end + #qp path.to_s @db = BDB::Hash.open(path.to_s, nil, amask) at_exit { close @@ -106,28 +115,33 @@ module CHISE def sync @db.close if @db - @db = nil reset + true end alias close sync - private def setup_db(writable=nil) if writable sync if @access & BDB::CREATE == 0 - @access = BDB::CREATE + access = BDB::CREATE else - @access = BDB::RDONLY + access = BDB::RDONLY end - return if @db + return true if @db + #qp @ds.location, @category, @keyvalue, @name, @access, @ds.modemask begin @db = AttributeTable.new(@ds.location, @category, @keyvalue, - @name, @access, @ds.modemask) + @name, access, @ds.modemask) + return false if @db.nil? + @access = access rescue => e + #puts $!, $@ @db = nil + return false end + true end end @@ -151,6 +165,7 @@ module CHISE setup_db(true) raise "@db is nil." if @db.nil? @db.put(format_char_id(cid), value) + true end def each_char @@ -172,6 +187,14 @@ module CHISE reset end + def set(code_point, cid) + setup_db(true) + raise "@db is nil." if @db.nil? + parse_c_string(@db.get(code_point.to_s)) + @db.put(code_point.to_s, format_char_id(cid)) + true + end + def decode(code_point) setup_db return nil if @db.nil? @@ -184,11 +207,11 @@ module CHISE @db.put(code_point.to_s, format_char_id(cid)) end - def each + def each_char setup_db raise "@db is nil." if @db.nil? - @db.each {|k, v| - yield(k, parse_c_string(v)) + @db.each {|code_point, cid| + yield(code_point, parse_c_string(cid)) } end end