2 # Package to handle US Callsign -> City, State translations
4 # Copyright (c) 2002 Dirk Koopman G1TLH
16 use vars qw($VERSION $BRANCH);
17 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
18 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
19 $main::build += $VERSION;
20 $main::branch += $BRANCH;
22 use vars qw(%db $present);
24 my $dbfn = "$main::data/usdb.v1";
29 tie %db, 'DB_File', $dbfn and $present = 1;
34 return unless $present;
41 return () unless $present;
42 my $ctyn = $db{$_[0]};
43 my @s = split /\|/, $db{$ctyn} if $ctyn;
49 return () unless $present;
51 return @s ? $s[1] : undef;
56 return () unless $present;
58 return @s ? $s[0] : undef;
62 # load in / update an existing DB with a standard format (GZIPPED)
65 # Note that this removes and overwrites the existing DB file
66 # You will need to init again after doing this
71 # create the new output file
72 my $a = new DB_File::BTREEINFO;
73 $a->{psize} = 4096 * 2;
75 if ($s = -s $dbfn && $s > 1024 * 1024) {
76 $a->{cachesize} = int(($s / (1024*1024)) / 2) * 1024 * 1024;
80 syscopy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!";
83 tie %dbn, 'DB_File', "$dbfn.new", O_RDWR|O_CREAT, 0664, $a or return "cannot tie $dbfn.new $!";
85 # now write away all the files
88 my $f = gzopen($fn, "r") or return "Cannot open $fn $!";
89 while ($f->gzreadline) {
91 my ($call, $city, $state) = split /\|/;
94 my $s = "$city|$state";
97 my $no = $dbn{'##'} || 1;
110 rename "$dbfn.new", $dbfn;