11 use vars qw(%db %chardb
12 %reverse_db %reverse_chardb
16 our @ISA = qw(Exporter);
18 # Items to export into callers namespace by default. Note: do not export
19 # names by default without a very good reason. Use EXPORT_OK instead.
20 # Do not simply export all your public functions/methods/constants.
22 # This allows declaration use Chise_utils ':all';
23 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
25 our %EXPORT_TAGS = ( 'all' => [ qw(
27 %reverse_db %reverse_chardb
40 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
44 our $VERSION = '0.01';
47 # Preloaded methods go here.
50 if(-e '/usr/local/lib/chise/char-db'){
51 $DB_HOME='/usr/local/lib/chise/char-db';
52 }elsif(-e '/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db'){
53 $DB_HOME='/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db';
54 }elsif(-e '/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'){
55 $DB_HOME='/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db';
56 }elsif(-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'){
57 $DB_HOME='/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db';
58 }elsif(-e '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db'){
59 $DB_HOME='/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db';
60 }elsif(-e '/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'){
61 $DB_HOME='/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db';
62 }elsif(-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'){
63 $DB_HOME='/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db';
64 }elsif(-e 'd:/work/chise/char-db'){
65 $DB_HOME='d:/work/chise/char-db';
67 print STDERR "No database found.\n";
68 print STDERR "Pleas set \$DB_HOME to Chise_utils.pm.\n";
72 $idc="\x{2ff0}-\x{2fff}";
75 ('C1','chinese-cns11643-1',
76 'C2','chinese-cns11643-2',
77 'C3','chinese-cns11643-3',
78 'C4','chinese-cns11643-4',
79 'C5','chinese-cns11643-5',
80 'C6','chinese-cns11643-6',
81 'C7','chinese-cns11643-7',
82 'CB','ideograph-cbeta',
83 'CDP','chinese-big5-cdp',
85 'GT-K','ideograph-gt',
86 'HZK1','ideograph-hanziku-1',
87 'HZK2','ideograph-hanziku-2',
88 'HZK3','ideograph-hanziku-3',
89 'HZK4','ideograph-hanziku-4',
90 'HZK5','ideograph-hanziku-5',
91 'HZK6','ideograph-hanziku-6',
92 'HZK7','ideograph-hanziku-7',
93 'HZK8','ideograph-hanziku-8',
94 'HZK9','ideograph-hanziku-9',
95 'HZK10','ideograph-hanziku-10',
96 'HZK11','ideograph-hanziku-11',
97 'HZK12','ideograph-hanziku-12',
98 'J78','japanese-jisx0208-1978',
99 'J83','japanese-jisx0208',
100 'J90','japanese-jisx0208-1990',
101 'JSP','japanese-jisx0212',
102 'JX1','japanese-jisx0213-1',
103 'JX2','japanese-jisx0213-2',
104 'K0','korean-ksc5601',
105 'M','ideograph-daikanwa',
108 for (glob "$DB_HOME/system-char-id/*"){
111 $atr=~s!$DB_HOME/system-char-id/!!;
115 for (glob "$DB_HOME/*"){
116 next if(/\.txt$/ or /system-char-id/);
119 $reverse_db{$atr}=$_."/system-char-id";
124 return 1 if(defined(%{$chardb{$atr}}));
125 if(defined($db{$atr}) and -f $db{$atr}){
126 tie %{$chardb{$atr}}, "BerkeleyDB::Hash",
127 -Filename => $db{$atr};
135 return 1 if(defined(%{$reverse_chardb{$atr}}));
136 if(defined($reverse_db{$atr}) and -f $reverse_db{$atr}){
137 tie %{$reverse_chardb{$atr}}, "BerkeleyDB::Hash",
138 -Filename => $reverse_db{$atr};
145 sub get_char_attribute{
147 &get_db($atr) or return "";
148 if($chardb{$atr}->{"?$char"}){
149 return $chardb{$atr}->{"?$char"};
155 sub get_chars_containing{
159 foreach $char (keys %{$chardb{$atr}}){
160 if($chardb{$atr}->{$char}=~/$value/){
169 sub get_chars_matching{
172 if(defined($reverse_db{$atr})){
173 if(&get_reverse_db($atr)){
174 if($char=$reverse_chardb{$atr}->{$value}){
181 # # fall back if DB inconsistency exists.
184 foreach $char (keys %{$chardb{$atr}}){
185 if($chardb{$atr}->{$char} eq $value){
197 my @q=split(",",$query);
198 my(%res,@res,$atr,$value);
202 ($atr,$value)=split("=~",$query,2);
204 foreach (&get_chars_containing($atr,$value)){
207 }elsif($query=~/==/){
208 ($atr,$value)=split(/==/,$query,2);
210 foreach (&get_chars_matching($atr,$value)){
225 my($output_char,$atr,$value);
226 my $keys = join '|', keys %er_alias;
228 $output_char=pack("U",$er);
229 }elsif($er=~/^U[\+\-]([a-fA-F\d]+)/){
230 $output_char=pack("U",hex($1));
231 }elsif($er=~/(?:I\-)?($keys)\-?([0-9a-fA-F]+)/){
232 ($atr,$value)=($1,$2);
233 unless($er_alias{$atr}=~/daikanwa|gt/){
236 ($output_char)=&get_chars_matching($er_alias{$atr},$value);
247 my $char_id=unpack("U",$char);
248 if($char_id==0x2ff2 or $char_id==0x2ff3){
250 }elsif($char_id>=0x2ff0 and $char_id<=0x2fff){
257 # Autoload methods go after =cut, and are processed by the autosplit program.
261 # Below is stub documentation for your module. You better edit it!
265 Chise_utils - Perl extension for blah blah blah
274 Stub documentation for Chise_utils, created by h2xs. It looks like the
275 author of the extension was negligent enough to leave the stub
287 A. U. Thor, a.u.thor@a.galaxy.far.far.away