11 use vars qw(%db %chardb %db_opened
12 %reverse_db %reverse_chardb %rdb_opened
13 %er_alias $er_prefix_re
18 our @ISA = qw(Exporter);
20 # Items to export into callers namespace by default. Note: do not export
21 # names by default without a very good reason. Use EXPORT_OK instead.
22 # Do not simply export all your public functions/methods/constants.
24 # This allows declaration use Chise_utils ':all';
25 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
27 our %EXPORT_TAGS = ( 'all' => [ qw(
29 %reverse_db %reverse_chardb
31 %er_alias $er_prefix_re
43 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
47 our $VERSION = '0.02';
50 # Preloaded methods go here.
52 $omegadb_path="/usr/local/lib/chise/omega";
56 if(-e '/usr/local/lib/chise/chise-db'){
57 $DB_HOME='/usr/local/lib/chise/chise-db';
58 }elsif(-e '/usr/lib/chise/chise-db'){
59 $DB_HOME='/usr/lib/chise/chise-db';
60 }elsif(-e '/usr/local/lib/chise/char-db'){
61 $DB_HOME='/usr/local/lib/chise/char-db';
62 }elsif(-e 'd:/work/chise/char-db'){
63 $DB_HOME='d:/work/chise/char-db';
65 print STDERR "No database found.\n";
66 print STDERR "Pleas set \$DB_HOME to Chise_utils.pm.\n";
71 $idc="\x{2ff0}-\x{2fff}";
94 'HZK10','=hanziku-10',
95 'HZK11','=hanziku-11',
96 'HZK12','=hanziku-12',
97 'J78','=jisx0208-1978',
99 'J90','=jisx0208-1990',
107 $er_prefix_re=join '|', keys %er_alias;
109 if(-d "$DB_HOME/character"){
110 for (glob "$DB_HOME/character/feature/*"){
113 $atr=~s!$DB_HOME/character/feature/!!;
116 for (glob "$DB_HOME/character/by_feature/*"){
119 $atr=~s!$DB_HOME/character/by_feature/!!;
120 $reverse_db{$atr}=$_;
122 }elsif(-d "$DB_HOME/system-char-id"){
123 for (glob "$DB_HOME/system-char-id/*"){
126 $atr=~s!$DB_HOME/system-char-id/!!;
129 for (glob "$DB_HOME/*"){
130 next if(/\.txt$/ or /system-char-id/);
133 $reverse_db{$atr}=$_."/system-char-id";
136 print STDERR "No database found.\n";
137 print STDERR "Pleas set \$DB_HOME to Chise_utils.pm correctly.\n";
143 return 1 if($db_opened{$atr});
144 if(defined($db{$atr}) and -f $db{$atr}){
145 if(tie %{$chardb{$atr}}, 'BerkeleyDB::Hash',
146 -Filename => $db{$atr},
147 -Flags => DB_RDONLY){
159 return 1 if($rdb_opened{$atr});
160 if(defined($reverse_db{$atr}) and -f $reverse_db{$atr}){
161 if(tie %{$reverse_chardb{$atr}}, "BerkeleyDB::Hash",
162 -Filename => $reverse_db{$atr},
163 -Flags => DB_RDONLY){
174 sub get_char_attribute{
177 unless($db_opened{$atr}){
178 &get_db($atr) or return "";
180 if($res=$chardb{$atr}->{"?$char"}){
188 sub get_chars_containing{
191 unless($db_opened{$atr}){
192 &get_db($atr) or return ();
194 foreach $char (keys %{$chardb{$atr}}){
195 if($chardb{$atr}->{$char}=~/$value/){
204 sub get_chars_matching{
207 if(defined($reverse_db{$atr})){
208 unless($rdb_opened{$atr}){
209 &get_reverse_db($atr) or return ();
211 if($char=$reverse_chardb{$atr}->{$value}){
220 # # fall back if DB inconsistency exists.
221 unless($db_opened{$atr}){
222 &get_db($atr) or return ();
224 foreach $char (keys %{$chardb{$atr}}){
225 if($chardb{$atr}->{$char} eq $value){
237 my @q=split(",",$query);
238 my(%res,@res,$atr,$value);
242 ($atr,$value)=split("=~",$query,2);
244 foreach (&get_chars_containing($atr,$value)){
247 }elsif($query=~/==/){
248 ($atr,$value)=split(/==/,$query,2);
250 foreach (&get_chars_matching($atr,$value)){
255 return grep {defined($res{$_}) and $res{$_}==$i} (keys %res);
260 my($output_char,$atr,$value);
262 $er=~/^(amp|&)?(.+?)(;)?$/
263 and $prefix=$1,$er=$2,$suffix=$3;
264 $prefix or $prefix="",$suffix or $suffix="";
265 if($prefix eq 'amp'){$prefix="",$suffix="";}
267 $output_char=pack("U",$er);
268 }elsif($er=~/^U[\+\-]([a-fA-F\d]+)/){
269 $output_char=pack("U",hex($1));
270 }elsif($er=~/^(?:I\-)?($er_prefix_re)\-?([0-9a-fA-F]+)$/){
271 ($atr,$value)=($1,$2);
272 if($er_alias{$atr}=~/daikanwa|gt/){
277 ($output_char)=&get_chars_matching($er_alias{$atr},$value);
282 return $prefix.$er.$suffix;
288 my $char_id=unpack("U",$char);
289 if($char_id==0x2ff2 or $char_id==0x2ff3){
291 }elsif($char_id>=0x2ff0 and $char_id<=0x2fff){
298 # Autoload methods go after =cut, and are processed by the autosplit program.
302 # Below is stub documentation for your module. You better edit it!
306 Chise_utils - Perl extension for blah blah blah
315 Stub documentation for Chise_utils, created by h2xs. It looks like the
316 author of the extension was negligent enough to leave the stub
328 A. U. Thor, a.u.thor@a.galaxy.far.far.away