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
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
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
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
setup_db(true)
raise "@db is nil." if @db.nil?
@db.put(format_char_id(cid), value)
+ true
end
def each_char
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?
@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