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/xemacs-21.4.11/i686-pc-linux/char-db'){
51 $DB_HOME='/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db';
52 }elsif(-e '/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'){
53 $DB_HOME='/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db';
54 }elsif(-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'){
55 $DB_HOME='/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db';
56 }elsif(-e '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db'){
57 $DB_HOME='/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db';
58 }elsif(-e '/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'){
59 $DB_HOME='/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db';
60 }elsif(-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'){
61 $DB_HOME='/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/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";
70 $idc="\x{2ff0}-\x{2fff}";
73 ('C1','chinese-cns11643-1',
74 'C2','chinese-cns11643-2',
75 'C3','chinese-cns11643-3',
76 'C4','chinese-cns11643-4',
77 'C5','chinese-cns11643-5',
78 'C6','chinese-cns11643-6',
79 'C7','chinese-cns11643-7',
80 'CB','ideograph-cbeta',
81 'CDP','chinese-big5-cdp',
83 'GT-K','ideograph-gt',
84 'HZK1','ideograph-hanziku-1',
85 'HZK2','ideograph-hanziku-2',
86 'HZK3','ideograph-hanziku-3',
87 'HZK4','ideograph-hanziku-4',
88 'HZK5','ideograph-hanziku-5',
89 'HZK6','ideograph-hanziku-6',
90 'HZK7','ideograph-hanziku-7',
91 'HZK8','ideograph-hanziku-8',
92 'HZK9','ideograph-hanziku-9',
93 'HZK10','ideograph-hanziku-10',
94 'HZK11','ideograph-hanziku-11',
95 'HZK12','ideograph-hanziku-12',
96 'J78','japanese-jisx0208-1978',
97 'J83','japanese-jisx0208',
98 'J90','japanese-jisx0208-1990',
99 'JSP','japanese-jisx0212',
100 'JX1','japanese-jisx0213-1',
101 'JX2','japanese-jisx0213-2',
102 'K0','korean-ksc5601',
103 'M','ideograph-daikanwa',
106 for (glob "$DB_HOME/system-char-id/*"){
109 $atr=~s!$DB_HOME/system-char-id/!!;
113 for (glob "$DB_HOME/*"){
114 next if(/\.txt$/ or /system-char-id/);
117 $reverse_db{$atr}=$_."/system-char-id";
122 return 1 if(defined(%{$chardb{$atr}}));
123 if(defined($db{$atr}) and -f $db{$atr}){
124 tie %{$chardb{$atr}}, "BerkeleyDB::Hash",
125 -Filename => $db{$atr};
133 return 1 if(defined(%{$reverse_chardb{$atr}}));
134 if(defined($reverse_db{$atr}) and -f $reverse_db{$atr}){
135 tie %{$reverse_chardb{$atr}}, "BerkeleyDB::Hash",
136 -Filename => $reverse_db{$atr};
143 sub get_char_attribute{
145 &get_db($atr) or return "";
146 if($chardb{$atr}->{"?$char"}){
147 return $chardb{$atr}->{"?$char"};
153 sub get_chars_containing{
157 foreach $char (keys %{$chardb{$atr}}){
158 if($chardb{$atr}->{$char}=~/$value/){
167 sub get_chars_matching{
170 if(defined($reverse_db{$atr})){
171 if(&get_reverse_db($atr)){
172 if($char=$reverse_chardb{$atr}->{$value}){
179 # fall back if DB inconsistency exists.
182 foreach $char (keys %{$chardb{$atr}}){
183 if($chardb{$atr}->{$char} eq $value){
195 my @q=split(",",$query);
196 my(%res,@res,$atr,$value);
200 ($atr,$value)=split("=~",$query,2);
202 foreach (&get_chars_containing($atr,$value)){
205 }elsif($query=~/==/){
206 ($atr,$value)=split(/==/,$query,2);
208 foreach (&get_chars_matching($atr,$value)){
223 my($output_char,$atr,$value);
224 my $keys = join '|', keys %er_alias;
226 $output_char=pack("U",$er);
227 }elsif($er=~/^U[\+\-]([a-fA-F\d]+)/){
228 $output_char=pack("U",hex($1));
229 }elsif($er=~/(?:I\-)?($keys)\-?([0-9a-fA-F]+)/){
230 ($atr,$value)=($1,$2);
231 unless($er_alias{$atr}=~/daikanwa|gt/){
234 ($output_char)=&get_chars_matching($er_alias{$atr},$value);
245 my $char_id=unpack("U",$char);
246 if($char_id==0x2ff2 or $char_id==0x2ff3){
248 }elsif($char_id>=0x2ff0 and $char_id<=0x2fff){
255 # Autoload methods go after =cut, and are processed by the autosplit program.
259 # Below is stub documentation for your module. You better edit it!
263 Chise_utils - Perl extension for blah blah blah
272 Stub documentation for Chise_utils, created by h2xs. It looks like the
273 author of the extension was negligent enough to leave the stub
285 A. U. Thor, a.u.thor@a.galaxy.far.far.away