n.c.
[chise/ruby.git] / tools / management.rb
index 820a960..284ed6e 100755 (executable)
@@ -1,6 +1,7 @@
 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
 
 $LOAD_PATH.unshift("..")
+require "chise/char"
 require "pathname"
 require "fileutils"
 require "chise/config"
@@ -10,8 +11,44 @@ require "chise/qp"
 module CHISE
   class DataBaseManagement
     def dump_all
-#CharDB.instance.dump_all()
-#CodesysDB.instance.dump_all()
+      cd = ChiseDB.instance
+      path = cd.location+"character/feature"
+
+      cd.each_feature {|f|
+       ft = cd.get_feature(f)
+       h = {}
+       ft.each {|k, v|
+         h[k] = v
+       }
+
+       f = f.path.escape.escape_win_filename
+       txt = f.to_s+".txt"
+       #qp f.to_s, txt
+       t = path+txt
+
+       t.open("wb"){|out|
+         h.sort.each {|k, v|
+           out.printf("%s\t%s\n", k, v)
+         }
+       }
+
+       ft.close
+      }
+    end
+
+    def dump_db(t)
+      db = get(t)
+      return nil unless db
+      file = get_filename(t)
+      open("#{file}.txt", "w"){|out|
+       #        out.binmode.sync = true
+       ar = db.to_a
+       ar.map! {|k, v| [to_num(k), to_num(v)] }
+       ar.sort.each {|k, v|
+         out.printf("%s\t%s\n", k, v)
+       }
+      }
+      true
     end
   end