projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
complete unconpression
[spider.git]
/
perl
/
USDB.pm
diff --git
a/perl/USDB.pm
b/perl/USDB.pm
index 3b62fa5d59c5d995b5371a1e4c4a4e9460533b95..d5ac1d8a59cd2a5ea5fe90e77d60eea13965bd3f 100644
(file)
--- a/
perl/USDB.pm
+++ b/
perl/USDB.pm
@@
-5,6
+5,8
@@
#
#
#
#
+package USDB;
+
use strict;
use DXVars;
use strict;
use DXVars;
@@
-19,14
+21,19
@@
$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0))
$main::build += $VERSION;
$main::branch += $BRANCH;
$main::build += $VERSION;
$main::branch += $BRANCH;
-use vars qw(%db $present);
+use vars qw(%db $present
$dbfn
);
-
my
$dbfn = "$main::data/usdb.v1";
+$dbfn = "$main::data/usdb.v1";
sub init
{
end();
sub init
{
end();
- tie %db, 'DB_File', $dbfn and $present = 1;
+ if (tie %db, 'DB_File', $dbfn, O_RDONLY, 0664, $DB_BTREE) {
+ $present = 1;
+ dbg("US Database loaded");
+ } else {
+ dbg("US Database not loaded");
+ }
}
sub end
}
sub end
@@
-64,31
+71,44
@@
sub getcity
#
# Note that this removes and overwrites the existing DB file
# You will need to init again after doing this
#
# Note that this removes and overwrites the existing DB file
# You will need to init again after doing this
-#
+#
sub load
{
sub load
{
+ return "Need a filename" unless @_;
+
# create the new output file
my $a = new DB_File::BTREEINFO;
$a->{psize} = 4096 * 2;
# create the new output file
my $a = new DB_File::BTREEINFO;
$a->{psize} = 4096 * 2;
- my $s;
- if ($s = -s $dbfn && $s > 1024 * 1024) {
- $a->{cachesize} = int(($s / (1024*1024)) / 2) * 1024 * 1024;
+ my $s = 0;
+
+ # guess a cache size
+ for (@_) {
+ my $ts = -s;
+ $s = $ts if $ts > $s;
+ }
+ if ($s > 1024 * 1024) {
+ $a->{cachesize} = int($s / (1024*1024)) * 3 * 1024 * 1024;
}
}
+
+# print "cache size " . $a->{cachesize} . "\n";
+
my %dbn;
if (-e $dbfn ) {
my %dbn;
if (-e $dbfn ) {
-
sys
copy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!";
+ copy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!";
}
tie %dbn, 'DB_File', "$dbfn.new", O_RDWR|O_CREAT, 0664, $a or return "cannot tie $dbfn.new $!";
# now write away all the files
for (@_) {
}
tie %dbn, 'DB_File', "$dbfn.new", O_RDWR|O_CREAT, 0664, $a or return "cannot tie $dbfn.new $!";
# now write away all the files
for (@_) {
- my $fn = shift;
- my $f = gzopen($fn, "r") or return "Cannot open $fn $!";
- while ($f->gzreadline) {
- chomp;
- my ($call, $city, $state) = split /\|/;
+ my $ofn = shift;
+ my $of = new IO::File "$ofn" or return "Cannot read $ofn $!";
+
+ while (<$of>) {
+ my $l = $_;
+ $l =~ s/[\r\n]+$//;
+ my ($call, $city, $state) = split /\|/, $l;
# lookup the city
my $s = "$city|$state";
# lookup the city
my $s = "$city|$state";
@@
-103,11
+123,13
@@
sub load
}
$dbn{$call} = $ctyn;
}
}
$dbn{$call} = $ctyn;
}
- $f->gzclose;
+ $of->close;
+ unlink $ofn;
}
untie %dbn;
rename "$dbfn.new", $dbfn;
}
untie %dbn;
rename "$dbfn.new", $dbfn;
+ return ();
}
1;
}
1;