X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=CHISE.pm;h=3eec0ee1a7e41651bea059a47549ce32fd03dfbd;hb=132564cd4179de9403eab3d4585e8bca955cbfd7;hp=a0dd98890f397dd24d416ab96074bf2a3c359b7e;hpb=6090f9cbd96aba6891b105e7a6a70da64b95cd52;p=chise%2Fperl.git diff --git a/CHISE.pm b/CHISE.pm index a0dd988..3eec0ee 100644 --- a/CHISE.pm +++ b/CHISE.pm @@ -1,12 +1,13 @@ # # CHISE.pm by Shigeki Moro -# $Id: CHISE.pm,v 1.4 2003-08-10 09:11:56 moro Exp $ +# $Id: CHISE.pm,v 1.6 2003-10-08 13:30:28 moro Exp $ # package CHISE; use strict; use warnings; -use BerkeleyDB; +use utf8; +use DB_File; our ($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET); ($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET) @@ -16,26 +17,26 @@ our ($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET); # データベースの全ファイルをchownしないとø»‚¢³ãˆãªã„かも my $DB_HOME=''; if (-e '/usr/local/lib/chise/char-db') { - $DB_HOME='/usr/local/lib/chise/char-db'; + $DB_HOME = '/usr/local/lib/chise/char-db'; } elsif (-e '/sw/lib/xemacs-21.4.11/powerpc-apple-darwin6.6/char-db') { $DB_HOME = '/sw/lib/xemacs-21.4.11/powerpc-apple-darwin6.6/char-db'; } elsif (-e '/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db') { - $DB_HOME='/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db'; + $DB_HOME = '/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db'; } elsif (-e '/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db') { - $DB_HOME='/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'; + $DB_HOME = '/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'; } elsif (-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'){ - $DB_HOME='/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'; + $DB_HOME = '/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'; } elsif (-e '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db') { - $DB_HOME='/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db'; + $DB_HOME = '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db'; } elsif (-e '/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db') { - $DB_HOME='/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'; + $DB_HOME = '/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'; } elsif (-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'){ - $DB_HOME='/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'; + $DB_HOME = '/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'; } elsif (-e 'd:/work/chise/char-db'){ - $DB_HOME='d:/work/chise/char-db'; + $DB_HOME = 'd:/work/chise/char-db'; } else { - print STDERR "No database found.\n"; - print STDERR "Please set \$DB_HOME to CHISE.pm.\n"; + print STDERR "CHISE.pm: No database found.\n"; + print STDERR "CHISE.pm: Please set \$DB_HOME to CHISE.pm.\n"; exit 1; } @@ -154,6 +155,9 @@ sub compare { $aonly++ if (exists $a->{$i}); $bonly++ if (exists $b->{$i}); } + } else { + $aonly++ if (exists $a->{$i}); + $bonly++ if (exists $b->{$i}); } } if ($common == 0) { @@ -281,27 +285,30 @@ sub utf8 { sub getvalue ($$) { # キーから値をø½Šž­ã‚Šå‡ºã™ - my($dbname, $key) = @_; - tie my %h, "BerkeleyDB::Hash", - -Filename => $dbname; - my $value = $h{$key}; + my ($chise_dbname, $key) = @_; + my $value = ''; + tie (my %h, "DB_File", $chise_dbname, O_RDWR) + or die "Cannot open file $chise_dbname: $!\n"; + $value = $h{$key}; untie %h; return $value; } sub getkeys ($$) { # 値からキーの配列をø½Šž­ã‚Šå‡ºã™ - my($dbname, $value) = @_; - tie my %h, "BerkeleyDB::Hash", - -Filename => $dbname; + my ($chise_dbname, $value) = @_; + tie (my %h, "DB_File", $chise_dbname, O_RDWR, , $DB_BTREE) + or die "Cannot open file $chise_dbname: $!\n"; my @keys = (); for my $key (keys %h) { - push @keys, $key if ($h{$key} =~ /\b$value\b/); + next unless (exists $h{$key}); + push @keys, $key if ($h{$key} eq $value); } untie %h; return @keys; } + sub cap { # 2つの配列の積ø½ŠŸ›åˆã‚’求める my($a, $b) = @_;