update.
[chise/ruby.git] / chise / db.rb
index e408969..2371a61 100755 (executable)
@@ -4,6 +4,7 @@ require "singleton"
 require "bdb"
 require "chise/config"
 require "chise/rbchise"
+require "chise/util"
 
 module CHISE
 
@@ -39,16 +40,6 @@ module CHISE
       return key
     end
 
-    def myvalue(v)
-      return v if v == nil
-      return v.to_i if v =~ /^\d+$/ #数字だったらここで変換しておく
-      return v.sub(/^\?/, "") if v =~ /^\?/ #冒頭の?は取り除く
-      return $1 if v =~ /^"(.+)"$/ #最初と最後に"がついていたら、取り除く
-      #p ["get", v, t, key, db]
-      #return parse_sexp(v) if v =~ /^\(.+\)$/ #最初と最後が()の時は、S式にparseする
-      return v #それ以外って何?
-    end
-
     def myget(key) #keyキーを引いて返す
       key = mykey(key)
       v = get(key) #存在しなかったらnilを返すことになる
@@ -63,29 +54,14 @@ module CHISE
   end
 
   class DB # abstract class for DataBase
-    # translate file name for deal with Windows file system.
-    def self.unix_to_win(unix_path)
-      win = unix_path.gsub(/</, "(")
-      win = win.gsub(/>/, ")")
-      win = win.gsub(/\*/, "+")
-      win = win.gsub(/\?/, "!")
-      win
-    end
-
-    def self.win_to_unix(win_path)
-      unix = win_path.gsub(/\)/, ">")
-      unix = unix.gsub(/\(/, "<")
-      unix = unix.gsub(/\!/, "?")
-      unix = unix.gsub(/\+/, "*")
-      unix
-    end
-
     def get_filename(t)
-      return @pre + DB.unix_to_win(t) + @post if CHISE.windows?
+      return @pre + CHISE.unix_to_win(t) + @post if CHISE.windows?
       return @pre + t + @post
     end
 
-    def get_dirname(t) File.dirname(get_filename(t)) end
+    def get_dirname(t)
+      File.dirname(get_filename(t))
+    end
 
     def open_dbs()
       @dbs = Hash.new
@@ -102,12 +78,12 @@ module CHISE
       }
       keys = []
       files.each {|f|
-       t = DB.win_to_unix(f)
+       t = CHISE.win_to_unix(f)
        t.sub!(%r|^#{@pre}|, "")
        t.sub!(%r|#{@post}$|, "") if @post != ""
        keys << t
       }
-      return keys
+      keys
     end
 
     def close_db(t)
@@ -351,6 +327,7 @@ module CHISE
       @common = db.get_codesys("=jis-x0208")
       @newest = db.get_codesys("japanese-jisx0208-1990")
     end
+
     def get_char(code)
       char = @common.get(code)
       return char unless char.nil?
@@ -358,76 +335,6 @@ module CHISE
       return char unless char.nil?
       return nil
     end
-  end
-
-  class DBS_Management # DataBase file management
-    OBSOLETE_ATTRIBUTES = "
-cns-radical
-cns-radical?
-kangxi-radical
-daikanwa-radical
-unicode-radical
-
-cns-strokes
-kangxi-strokes
-daikanwa-strokes
-shinjigen-1-radical
-gb-original-radical
-japanese-strokes
-jis-strokes-a
-jis-strokes-b
-jisx0208-strokes
-jis-x0213-strokes
-jisx0213-strokes
-unicode-strokes
-
-totalstrokes
-cns-total-strokes
-jis-total-strokes-b
-
-non-morohashi
-
-=>ucs*
-#=>mojikyo
-#=mojikyo
-->identical
-
-ancient-ideograph-of
-ancient-char-of-shinjigen-1
-original-ideograph-of
-original-char-of-shinjigen-1
-simplified-ideograph-of
-vulgar-ideograph-of
-vulgar-char-of-shinjigen-1
-ideograph=
-ideographic-variants
-variant-of-shinjigen-1
-
-iso-10646-comment
-".split
-
-    def initialize
-      dir = Config.instance.db_dir
-      @odir = dir+"/system-char-id/obsolete" #直打ちしている。
-    end
-
-    def move_obsolete_files # move obsolete BDB files to obsolete directory
-      db = CharDB.instance
-      db.close_all
-      Dir.mkdir(@odir) unless FileTest.directory? @odir
-      OBSOLETE_ATTRIBUTES.each {|attr|
-       next if attr =~ /^#/
-       filename = db.get_filename(attr)
-       move_to_obsolete(filename)
-       move_to_obsolete(filename+".txt")
-      }
-    end
-
-    def move_to_obsolete(file)
-      cmd = "mv \"#{file}\" #{@odir}"
-      #      p cmd
-      system cmd
-    end
 
   end
 end