2 # Package to handle US Callsign -> City, State translations
4 # Copyright (c) 2002 Dirk Koopman G1TLH
18 use vars qw($VERSION $BRANCH);
19 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
20 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
21 $main::build += $VERSION;
22 $main::branch += $BRANCH;
24 use vars qw(%db $present $dbfn);
26 $dbfn = "$main::data/usdb.v1";
31 tie %db, 'DB_File', $dbfn and $present = 1;
36 return unless $present;
43 return () unless $present;
44 my $ctyn = $db{$_[0]};
45 my @s = split /\|/, $db{$ctyn} if $ctyn;
51 return () unless $present;
53 return @s ? $s[1] : undef;
58 return () unless $present;
60 return @s ? $s[0] : undef;
64 # load in / update an existing DB with a standard format (GZIPPED)
67 # Note that this removes and overwrites the existing DB file
68 # You will need to init again after doing this
73 return "Need a filename" unless @_;
75 # create the new output file
76 my $a = new DB_File::BTREEINFO;
77 $a->{psize} = 4096 * 2;
85 if ($s > 1024 * 1024) {
86 $a->{cachesize} = int($s / (1024*1024)) * 3 * 1024 * 1024;
89 # print "cache size " . $a->{cachesize} . "\n";
93 syscopy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!";
96 tie %dbn, 'DB_File', "$dbfn.new", O_RDWR|O_CREAT, 0664, $a or return "cannot tie $dbfn.new $!";
98 # now write away all the files
101 my $f = gzopen($fn, "r") or return "Cannot open $fn $!";
103 while ($f->gzreadline($l)) {
105 my ($call, $city, $state) = split /\|/, $l;
108 my $s = "$city|$state";
111 my $no = $dbn{'##'} || 1;
124 rename "$dbfn.new", $dbfn;