i
authoreto <eto>
Thu, 10 Jun 2004 11:20:26 +0000 (11:20 +0000)
committereto <eto>
Thu, 10 Jun 2004 11:20:26 +0000 (11:20 +0000)
18 files changed:
chise/char.rb
chise/character.rb
chise/codeviewer.rb
chise/config.rb
chise/csf.rb
chise/db.rb
chise/kageserver.rb
chise/management.rb [deleted file]
chise/parser.rb
chise/rbchise.rb
chise/uconv.rb [deleted file]
test/common.rb
test/test-rbchise.rb
tools/Makefile
tools/cp-chisedb [new file with mode: 0755]
tools/make-chisedb-tarball.rb
tools/move-obsolete-files.rb [new file with mode: 0755]
tools/move_obsolete_files.rb [deleted file]

index f8687e6..2d685be 100755 (executable)
@@ -4,11 +4,5 @@ require "chise/db"
 require "chise/config"
 require "chise/iconv"
 require "chise/uconv"
-
 require "chise/string"
 require "chise/character"
-
-$debug = false #これはテスト用
-$debug = true #これはテスト用
-$stdout.binmode if $debug
-$stdout.sync = true if $debug
index b2d0972..753089a 100755 (executable)
@@ -20,29 +20,29 @@ module CHISE
 
     def get(char_id)
       check_max
-      n = @parser.parse(char_id)
-      @chars[n] = Character.new(n) if @chars[n].nil?
-      @chars[n]
+      mcs = @parser.parse(char_id)
+      @chars[mcs] = Character.new(mcs) if @chars[mcs].nil?
+      @chars[mcs]
     end
 
     def check_max
       clear if MAX_CACHE_CHARACTER < @chars.length # clear all caches.
     end
-
-    def nu_length
-      @chars.length
-    end
   end
 
   class Character
     def initialize(char_id=nil)
-      @parser = CharacterParser.new
-      @char_id = @parser.parse(char_id)
-      @attributes = Hash.new
+      @char_id = char_id
+      @attributes = {}
       @check_all_database = false
     end
     attr_reader :char_id
 
+
+
+
+
+
     def to_i() @char_id end
     def mcs_utf8() Character.u4itou8(@char_id) end
     def mcs_hex() sprintf("%x", @char_id) end
@@ -61,7 +61,7 @@ module CHISE
       a
     end
 
-    def get_char_attribute(b) # XEmacs UTF-2000\8cÝ\8a·API\8cQ
+    def get_char_attribute(b) # XEmacs CHISE compatible API
       a = normalize_attribute_name(b)
       #p [a, b]
       atr = @attributes[a]
@@ -71,7 +71,8 @@ module CHISE
        @attributes[a] = atr
        return atr
       end
-      return get_char_attribute("="+a) unless a =~ /^=/ #\93ª\82É=\82ª\82Â\82¢\82Ä\82È\82¢\8fê\8d\87\82Í\82»\82ê\82ª\8fÈ\97ª\82³\82ê\82Ä\82¢\82é\82±\82Æ\82ð\89¼\92è\82µ\82Ä\81A\8dÄ\8bA\82·\82é
+      return get_char_attribute("="+a) unless a =~ /^=/
+      #\93ª\82É=\82ª\82Â\82¢\82Ä\82È\82¢\8fê\8d\87\82Í\82»\82ê\82ª\8fÈ\97ª\82³\82ê\82Ä\82¢\82é\82±\82Æ\82ð\89¼\92è\82µ\82Ä\81A\8dÄ\8bA\82·\82é
       nil
     end
 
index 0c70df4..3e8fc57 100755 (executable)
@@ -1,11 +1,12 @@
 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
 
-require "stroke"
+require "chise/stroke"
 
 module StrokeFont
   class CodeViewer
     WIDTH, HEIGHT = 256, 256
     SCALE = 2
+
     def initialize(cx=0, cy=0)
       @cx, @cy = cx, cy
       @s = SCALE
@@ -19,6 +20,7 @@ module StrokeFont
       calc_code
     end
     attr_reader :code
+
     def draw
       colorHSV(0, 0, 100, 10) #まずは下敷きになる枠を書きます。
       rect(@x1, @y1, @x2, @y2)
@@ -34,6 +36,7 @@ module StrokeFont
       line(@px-@pw/2, @py, @px+@pw/2, @py)
       line(@px, @py-@ph/2, @px, @py+@ph/2)
     end
+
     def onMouse(x, y)
       if @onkeydown
        x, y = @px, @py
@@ -50,6 +53,7 @@ module StrokeFont
        return false
       end
     end
+
     def calc_code()
       x = ((@px - @x1)/@s).to_i
       y = HEIGHT-1 - ((@py - @y1)/@s).to_i
@@ -63,6 +67,7 @@ module StrokeFont
        return false
       end
     end
+
     def show_list(list)
       colorHSV(0, 100, 100, 100)
       list.each {|code|
@@ -70,6 +75,7 @@ module StrokeFont
        rect(x, y, x+2, y-2)
       }
     end
+
     def code_to_xy(code)
       cx = code % WIDTH
       cy = HEIGHT - (code / WIDTH) #intになる?
@@ -77,13 +83,17 @@ module StrokeFont
       y = cy * SCALE + @y1
       return x, y
     end
+
     def length(x, y)    Math.sqrt(x*x + y*y)  end
+
     def onMouseDown(x, y)
       if length(@px-x, @py-y) < @pr
        @dragging = true
       end
     end
+
     def onMouseUp(x, y)    @dragging = false  end
+
     def onKeyDown(key)
       @onkeydown = true
       case key
index 52663ee..8944476 100755 (executable)
@@ -17,11 +17,11 @@ module CHISE
       @csf_dir = @base_dir+"/csf"
 
       if CHISE.windows?()
-       @db_dir  = @base_dir+"/char-db" # /sysmtem-char-id/ucs
+       @db_dir  = @base_dir+"/chise-db" # /sysmtem-char-id/=ucs
        @ids_dir = @base_dir+"/ids" # /IDS-JIS-X0208-1990.txt
       else
-       @db_dir  = "/usr/local/lib/xemacs-21.4.12/i686-pc-linux/char-db"
-       @ids_dir = "/home/eto/chise/ids"
+       @db_dir  = "/usr/local/lib/xemacs-21.4.14/i686-pc-linux/chise-db"
+       @ids_dir = "/home/eto/work/chise/ids"
       end
 
       instance_variables.each {|name|
index fd8bf1f..593b495 100755 (executable)
@@ -1,8 +1,6 @@
 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
 
 require "sgl"
-#require "kconv"
-#require "uconv"
 require "chise/iconv"
 require "chise/config"
 
@@ -19,14 +17,17 @@ module StrokeFont
       @strokes = Strokes.new
     end
     attr_reader :strokes
+
     def move_to_x(x) @x = x; @nx = x; end
     def draw_to_x(x) @nx = x; drawline; @x = @nx; @y = @ny; end
     def next_x_to(x) @nx = x; end
     def move_to_y(y) @y = y; @ny = y; end
     def draw_to_y(y) @ny = y; drawline; @x = @nx; @y = @ny; end
+
     def drawline()
       @strokes.add_line(t(@x), t(@y), t(@nx), t(@ny))
     end
+
     def t(a) a*DEST_WIDTH/ORG_WIDTH; end
   end
 
index 9785ae2..e5707d4 100755 (executable)
@@ -4,7 +4,6 @@ require "singleton"
 require "bdb"
 require "chise/config"
 require "chise/rbchise"
-require "chise/management"
 require "chise/util"
 
 module CHISE
index e01f530..f0ea01d 100755 (executable)
@@ -5,8 +5,7 @@ require "net/http"
 require "uri"
 require "chise"
 require "chise/network" #漢字間接続のネットワークを計算する
-#require "chise/kanjilist"
-#include CHISE
+require "chise/kanjilist"
 
 class KageServer
   include Singleton
diff --git a/chise/management.rb b/chise/management.rb
deleted file mode 100755 (executable)
index 38fcfde..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-
-module CHISE
-  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" #\92¼\91Å\82¿\82µ\82Ä\82¢\82é\81B
-    end
-
-    def move_obsolete_files # move obsolete BDB files
-      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
index 9b7083c..812b77c 100755 (executable)
@@ -63,7 +63,7 @@ module CHISE
     PRIVATE_USE_AREA = 0xe000
 
     def parse_er(s) # parse a Entity Reference and return a number (MCS)
-      raise "wrong ER." unless ALL_RE =~ s # I don't use is_er? for getting $1.
+      raise "wrong ER." unless ALL_RE =~ s # don't use is_er? for getting $1.
 
       s = $1 # extract the part of ER
 
index 99d14d3..789dbe9 100755 (executable)
@@ -12,17 +12,27 @@ module CHISE
     def initialize(type = Berkeley_DB, location = nil)
       @type, @location = type, location
       @location = Config.instance.db_dir if @location.nil?
-      @dbs = {}
+      @fnames = {}
+      @cnames_names = {}
       at_exit {
-       @dbs.each {|k, db|
-         db.close
-       }
+       @fnames.each {|k, db| db.close }
+       @cnames.each {|k, db| db.close }
       }
     end
 
-    def open_decoding_table(ccs)
-      db = open(ccs, "system-char-id")
-      DecodingTable.new(ccs, db)
+    def get_feature(feature)
+      @fnames[feature] = open_feature(feature) if @fnames[feature].nil?
+      @fnames[feature] 
+    end
+
+    def decode_char(name, code_point)
+      ccs = get_ccs(name)
+      ccs.decode(code_point)
+    end
+
+    def get_ccs(name)
+      db = open(name, "system-char-id")
+      CCSTable.new(name, db)
     end
 
     def open_feature_table(feature)
@@ -41,7 +51,7 @@ module CHISE
   class AttributeTable # abstract class
   end
   
-  class DecodingTable < AttributeTable
+  class CCSTable < AttributeTable
     def initialize(ccs, db)
       @ccs, @db = ccs, db
     end
diff --git a/chise/uconv.rb b/chise/uconv.rb
deleted file mode 100755 (executable)
index e69de29..0000000
index d5bdc43..b06096b 100755 (executable)
@@ -2,6 +2,11 @@
 
 $VERBOSE = true
 
+$debug = false # for test
+$debug = true  # for test
+$stdout.binmode if $debug
+$stdout.sync = true if $debug
+
 $LOAD_PATH.unshift("..")
 require "test/unit"
 require "chise/char"
index a3d18e3..457a3bb 100755 (executable)
@@ -3,8 +3,12 @@
 
 require "common"
 
-class TestRubyChise < Test::Unit::TestCase
+class TestRbChise < Test::Unit::TestCase
   def test_rbchise
+
+  end
+
+  def test_rbchise0
     @ds = CHISE::DataSource.new
     assert_instance_of(CHISE::DataSource, @ds)
     @dt = @ds.open_decoding_table("=daikanwa")
index 4b2696a..40919c6 100755 (executable)
@@ -1,16 +1,16 @@
 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
 
 #test: ids_db
-test:  
+test:
 
-tarball:       
-       ./mkdbtarball.rb  /usr/local/lib/xemacs-21.4.10/i686-pc-linux/
+tarball:
+       ruby -I make-chisedb-tarball.rb  /usr/local/lib/xemacs-21.4.14/i686-pc-linux
 
-dump:  
+dump:
        ./dbdumpall.rb
 
-ids_db:        
+ids_db:
        ./idsdbdumpall.rb
 
-check: 
+check:
        ./idscheckintegrity.rb
diff --git a/tools/cp-chisedb b/tools/cp-chisedb
new file mode 100755 (executable)
index 0000000..923fe2e
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/csh -f
+# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+
+scp aqua.eto.com:work/chise/ruby/tools/chise-db.tar.gz .
index cf95cf1..1fc57cc 100755 (executable)
@@ -11,28 +11,31 @@ def usage()
   exit
 end
 
-usage if ARGV.length < 1
-dir = ARGV[0]
-unless FileTest.directory?(dir+"/chise-db")
-  print "no chise-db here. #{dir}\n"
-  usage
-end
-tmpdir = ARGV[1]
-tmpdir = "/var/tmp" if tmpdir.nil?
+def main(argv)
+  usage if argv.length < 1
+  dir = argv.shift
+  unless FileTest.directory?(dir+"/chise-db")
+    print "no chise-db here. #{dir}\n"
+    usage
+  end
+  tmpdir = argv.shift
+  tmpdir = "/var/tmp" if tmpdir.nil?
 
-orgdir = Dir.pwd
-Dir.chdir(tmpdir) # \93K\93\96\82Èdir\82É\88Ú\93®\82µ\82Ä\82©\82ç
-system "cp -a #{dir}/chise-db ." # \82Ü\82¸\82»\82Ìdirectory\82É\96â\93\9a\96³\97p\82Å\91S\95\94\83R\83s\81[\82·\82é\81B
+  orgdir = Dir.pwd
+  Dir.chdir(tmpdir) # \93K\93\96\82Èdir\82É\88Ú\93®\82µ\82Ä\82©\82ç
+  system "cp -a #{dir}/chise-db ." # \82Ü\82¸\82»\82Ìdirectory\82É\96â\93\9a\96³\97p\82Å\91S\95\94\83R\83s\81[\82·\82é\81B
 
-Find.find("."){|f|
-  if f =~ /([*?<>])/ # Windows\82É\82¨\82¯\82é\8bÖ\8e~\95\8e\9a\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82ç\81A\92u\8a·\82·\82é
-    nf = CHISE.unix_to_win(f)
-    cmd = "mv '#{f}' '#{nf}'"
-    #print cmd, "\n"
-    system cmd
-  end
-}
+  Find.find("."){|f|
+    if f =~ /([*?<>])/ # Windows\82É\82¨\82¯\82é\8bÖ\8e~\95\8e\9a\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82ç\81A\92u\8a·\82·\82é
+      nf = CHISE.unix_to_win(f)
+      cmd = "mv '#{f}' '#{nf}'"
+      #print cmd, "\n"
+      system cmd
+    end
+  }
 
-system "tar czf chise-db.tar.gz chise-db"
-system "mv chise-db.tar.gz #{orgdir}"
-system "rm -rf #{tmpdir}/chise-db"
+  system "tar czf chise-db.tar.gz chise-db"
+  system "mv chise-db.tar.gz #{orgdir}"
+  system "rm -rf #{tmpdir}/chise-db"
+end
+main(ARGV)
diff --git a/tools/move-obsolete-files.rb b/tools/move-obsolete-files.rb
new file mode 100755 (executable)
index 0000000..9692632
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/env ruby
+# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+# move obsolete BDB files.
+
+$LOAD_PATH.unshift("..")
+require "chise/config"
+require "chise/util"
+
+module CHISE
+  class DBS_Management # DataBase file management
+    # from specs/char-atr.ja.txt
+    OBSOLETE_ATTRIBUTES = "
+cns-radical
+cns-radical?
+kangxi-radical
+daikanwa-radical
+
+cns-strokes
+kangxi-strokes
+daikanwa-strokes
+shinjigen-1-radical
+gb-original-radical
+japanese-strokes
+jis-strokes-a
+jisx0208-strokes
+unicode-strokes
+
+cns-total-strokes
+
+non-morohashi
+
+=>ucs*
+#=>mojikyo
+#=mojikyo
+->identical
+
+ancient-ideograph-of
+ancient-char-of-shinjigen-1
+original-ideograph-of
+original-char-of-shinjigen-1
+vulgar-ideograph-of
+vulgar-char-of-shinjigen-1
+ideographic-variants
+variant-of-shinjigen-1
+
+iso-10646-comment
+".split
+
+    def initialize
+    end
+
+    def move_obsolete_files
+      fdir = Config.instance.db_dir+"/system-char-id"
+      Dir.chdir(fdir){
+       odir = "obsolete"
+       Dir.mkdir(odir) unless FileTest.directory? odir
+
+       OBSOLETE_ATTRIBUTES.each {|attr|
+         next if attr =~ /^#/
+         f = get_filename(attr)
+         move(f, odir) if FileTest.exist?(f)
+         f = f+".txt"
+         move(f, odir) if FileTest.exist?(f)
+       }
+      }
+    end
+
+    def get_filename(t)
+      t = CHISE.unix_to_win(t) if CHISE.windows?
+      t
+    end
+
+    def move(file, dir)
+      cmd = "mv './#{file}' #{dir}"
+      p cmd
+      system cmd
+    end
+  end
+end
+
+man = CHISE::DBS_Management.new
+man.move_obsolete_files
diff --git a/tools/move_obsolete_files.rb b/tools/move_obsolete_files.rb
deleted file mode 100755 (executable)
index 4b52a8b..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env ruby
-# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-# obsoleteである属性のBDBファイルを移動する
-
-$LOAD_PATH.unshift("..")
-require "chise/char"
-
-man = DBS_Management.new
-man.move_obsolete_files