From 9c415b19aaaf0497e9cc074f3df56f16fe414e82 Mon Sep 17 00:00:00 2001 From: minima Date: Tue, 15 Oct 2002 00:37:14 +0000 Subject: [PATCH] fix missing callsigns add back compressed handling --- Changes | 6 ++++++ cmd/load/usdb.pl | 7 ++----- perl/USDB.pm | 25 +++++++++++++++++++++++-- perl/create_usdb.pl | 2 +- perl/gen_usdb_data.pl | 24 ++++++++++++------------ 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/Changes b/Changes index 524b2ade..111fe642 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +15Oct02======================================================================= +1. made some detail changes to the raw USDB data and the routines that +generate and operate on them. There were some bugs involving a few 'missing' +callsigns which been fixed. Also there were some, for our purposes, invalid +callsigns in the database which have been removed (down to about 820,000 +entries now). You should really update your database. 14Oct02======================================================================= 1. added show/usdb command as a simple, direct interface to the information available in the USDB stuff. diff --git a/cmd/load/usdb.pl b/cmd/load/usdb.pl index bd45547d..b06f7c51 100644 --- a/cmd/load/usdb.pl +++ b/cmd/load/usdb.pl @@ -15,9 +15,6 @@ my ($self, $line) = @_; my @out; return (1, $self->msg('e5')) if $self->priv < 9; -return (1, $self->msg('e3', "load/usdb", $line)) if $line && !-r $line; -$line = "$main::data/usdbraw" unless $line; -push @out, (USDB::load($line)); -USDB::init() unless @OUT; -@out = ($self->msg('ok')) unless @out; +my $r = USDB::load($line) if $line; +USDB::init() if undef $r || $r =~ /^\d+ rec/; return (1, @out); diff --git a/perl/USDB.pm b/perl/USDB.pm index 14f9fc2e..69e1ead0 100644 --- a/perl/USDB.pm +++ b/perl/USDB.pm @@ -101,8 +101,28 @@ sub load tie %dbn, 'DB_File', "$dbfn.new", O_RDWR|O_CREAT, 0664, $a or return "cannot tie $dbfn.new $!"; # now write away all the files + my $count = 0; for (@_) { my $ofn = shift; + + # conditionally handle compressed files (don't cha just lurv live code, this is + # a rave from the grave and is "in memoriam Flossie" the ICT 1301G I learnt on. + # {for pedant computer historians a 1301G is an ICT 1301A that has been + # Galdorised[tm] (for instance had decent IOs and a 24 pre-modify instruction)} + my $nfn = $ofn; + if ($nfn =~ /.gz$/i) { + my $gz; + eval qq{use Compress::Zlib; \$gz = gzopen(\$ofn, "rb")}; + return "Cannot read compressed files $@" if $@; + $nfn =~ s/.gz$//i; + my $of = new IO::File ">$nfn" or return "Cannot write to $nfn $!"; + my ($l, $buf); + $of->write($buf, $l) while ($l = $gz->gzread($buf)); + $gz->gzclose; + $of->close; + $ofn = $nfn; + } + my $of = new IO::File "$ofn" or return "Cannot read $ofn $!"; while (<$of>) { @@ -122,14 +142,15 @@ sub load $dbn{'##'} = "$no"; } $dbn{$call} = $ctyn; + $count++; } $of->close; - unlink $ofn; + unlink $nfn; } untie %dbn; rename "$dbfn.new", $dbfn; - return (); + return "$count records"; } 1; diff --git a/perl/create_usdb.pl b/perl/create_usdb.pl index a0da7ff4..575babc7 100755 --- a/perl/create_usdb.pl +++ b/perl/create_usdb.pl @@ -30,7 +30,7 @@ use USDB; die "no input (usdbraw?) files specified\n" unless @ARGV; -USDB::load(@ARGV); +print "\n", USDB::load(@ARGV), "\n"; exit(0); diff --git a/perl/gen_usdb_data.pl b/perl/gen_usdb_data.pl index cc2850cf..71101bec 100755 --- a/perl/gen_usdb_data.pl +++ b/perl/gen_usdb_data.pl @@ -73,7 +73,6 @@ foreach my $argv (@ARGV) { } $gzfh->gzclose; -print "$ctycount Cities found\n"; exit(0); @@ -96,19 +95,20 @@ sub handleEN $l =~ s/[\r\n]+$//; my ($rt,$usi,$ulsfn,$ebfno,$call,$type,$lid,$name,$first,$middle,$last,$suffix, $phone,$fax,$email,$street,$city,$state,$zip,$pobox,$attl,$sgin,$frn) = split /\|/, $l; - - my $rec = uc join '|', $call,$city,$state if $city && $state; - $buf .= "$rec\n"; - if (length $buf > $blksize) { - $gzfh->gzwrite($buf); - undef $buf; + +# print "ERR: $l\n" unless $call && $city && $state; + + if ($call && $city && $state) { + my $rec = uc join '|', $call,$city,$state if $city && $state; + $buf .= "$rec\n"; + if (length $buf > $blksize) { + $gzfh->gzwrite($buf); + undef $buf; + } + $count++; } - my $c = uc "$city|$state"; - $count++; - } - if (length $buf > $blksize) { - $gzfh->gzwrite($buf); } + $gzfh->gzwrite($buf) if length $buf; print ", $count records\n"; $fh->close; } -- 2.34.1