i
[chise/ruby.git] / tools / dump-database.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3
4 $LOAD_PATH.unshift("..")
5 require "chise/char"
6 require "chise/qp"
7
8 module CHISE
9   class DataBaseManagement
10     def dump_all
11       #CharDB.instance.dump_all()
12       #CodesysDB.instance.dump_all()
13
14       cd = ChiseDB.instance
15       path = cd.location+"character/feature"
16
17       cd.each_feature {|f|
18         ft = cd.get_feature(f)
19         h = {}
20         ft.each {|k, v|
21           h[k] = v
22         }
23
24         f = f.path
25         f = f.escape
26         f = f.escape_win_filename
27         txt = f.to_s+".txt"
28         qp f, txt
29         t = path+txt
30
31         t.open("wb"){|out|
32           h.sort.each {|k, v|
33             out.printf("%s\t%s\n", k, v)
34           }
35         }
36
37         ft.close
38       }
39     end
40
41     def dump_db(t)
42       db = get(t)
43       return nil unless db
44       file = get_filename(t)
45       open("#{file}.txt", "w"){|out|
46         #        out.binmode.sync = true
47         ar = db.to_a
48         ar.map! {|k, v| [to_num(k), to_num(v)] }
49         ar.sort.each {|k, v|
50           out.printf("%s\t%s\n", k, v)
51         }
52       }
53       true
54     end
55
56
57   end
58 end
59
60 man = CHISE::DataBaseManagement.new
61 man.dump_all