sub get_db{
my($atr)=@_;
- return if(defined(%{$chardb{$atr}}));
+ return 1 if(defined(%{$chardb{$atr}}));
if(defined($db{$atr}) and -f $db{$atr}){
tie %{$chardb{$atr}}, "BerkeleyDB::Hash",
-Filename => $db{$atr};
sub get_reverse_db{
my($atr)=@_;
- return if(defined(%{$reverse_chardb{$atr}}));
+ return 1 if(defined(%{$reverse_chardb{$atr}}));
if(defined($reverse_db{$atr}) and -f $reverse_db{$atr}){
tie %{$reverse_chardb{$atr}}, "BerkeleyDB::Hash",
-Filename => $reverse_db{$atr};
sub get_char_attribute{
my($char,$atr)=@_;
- unless(defined($chardb{$atr})){
- &get_db($atr) or return "";
- }
+ &get_db($atr) or return "";
if($chardb{$atr}->{"?$char"}){
return $chardb{$atr}->{"?$char"};
}else{
sub get_chars_containing{
my($atr,$value)=@_;
my($char,@res);
- &get_db($atr);
- if(defined(%{$chardb{$atr}})){
+ if(&get_db($atr)){
foreach $char (keys %{$chardb{$atr}}){
if($chardb{$atr}->{$char}=~/$value/){
$char=~s/^\?//;
my($atr,$value)=@_;
my($char,@res);
if(defined($reverse_db{$atr})){
- &get_reverse_db($atr);
- if(defined(%{$reverse_chardb{$atr}})){
+ if(&get_reverse_db($atr)){
if($char=$reverse_chardb{$atr}->{$value}){
$char=~s/^\?//;
push @res,$char;
}
}
- }else{
- &get_db($atr);
- if(defined(%{$chardb{$atr}})){
+ }
+ # else{
+ # fall back if DB inconsistency exists.
+ unless(@res){
+ if(&get_db($atr)){
foreach $char (keys %{$chardb{$atr}}){
if($chardb{$atr}->{$char} eq $value){
$char=~s/^\?//;
}
if($opt_map){
- &get_db($opt_map);
- if(defined(%{$chardb{$opt_map}})){
+ if(&get_db($opt_map)){
foreach $char (sort keys %{$chardb{$opt_map}}){
if($chardb{$opt_map}->{$char}){
print $char,"\t",$chardb{$opt_map}->{$char},"\n";
print STDERR "No map for $opt_map.\n";
}
}elsif($opt_rev_map){
- &get_reverse_db($opt_rev_map);
- if(defined(%{$reverse_chardb{$opt_rev_map}})){
+ if(&get_reverse_db($opt_rev_map)){
foreach $char (sort keys %{$reverse_chardb{$opt_rev_map}}){
if($reverse_chardb{$opt_rev_map}->{$char}){
print $char,"\t",$reverse_chardb{$opt_rev_map}->{$char},"\n";