Fix help
[spider.git] / perl / Spot.pm
index 9f5c8645511711919943fc6564b239f59918bbda..3f5db145ee53c69494ee83852a46726b4f27c659 100644 (file)
@@ -17,6 +17,7 @@ use Julian;
 use Prefix;
 use DXDupe;
 use Data::Dumper;
+use QSL;
 
 use strict;
 
@@ -26,7 +27,7 @@ $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0))
 $main::build += $VERSION;
 $main::branch += $BRANCH;
 
-use vars qw($fp $statp $maxspots $defaultspots $maxdays $dirprefix $duplth $dupage $filterdef $totalspots $hfspots $vhfspots);
+use vars qw($fp $statp $maxspots $defaultspots $maxdays $dirprefix $duplth $dupage $filterdef $totalspots $hfspots $vhfspots );
 
 $fp = undef;
 $statp = undef;
@@ -101,8 +102,9 @@ sub init
        mkdir "$dirprefix", 0777 if !-e "$dirprefix";
        $fp = DXLog::new($dirprefix, "dat", 'd');
        $statp = DXLog::new($dirprefix, "dys", 'd');
-       system("rm -f $main::data/$dirprefix/200?/*.bys");
-       system("rm -f $main::data/$dirprefix/200?/*.cys");
+       my $rm = $main::is_win ? 'del' : 'rm -f';
+       system("$rm $main::data/$dirprefix/*/*.bys");
+       system("$rm $main::data/$dirprefix/*/*.cys");
 }
 
 sub prefix
@@ -151,7 +153,7 @@ sub prepare
 
 sub add
 {
-       my $buf = join("\^", @_[0..7]);
+       my $buf = join("\^", @_);
        $fp->writeunix($_[2], $buf);
        $totalspots++;
        if ($_[0] <= 30000) {
@@ -159,6 +161,10 @@ sub add
        } else {
                $vhfspots++;
        }
+       if ($_[3] =~ /(?:QSL|VIA)/i) {
+               my $q = QSL::get($_[1]) || new QSL $_[1];
+               $q->update($_[3], $_[2], $_[4]);
+       }
 }
 
 # search the spot database for records based on the field no and an expression
@@ -188,7 +194,7 @@ sub add
 
 sub search
 {
-       my ($expr, $dayfrom, $dayto, $from, $to, $hint) = @_;
+       my ($expr, $dayfrom, $dayto, $from, $to, $hint, $dxchan) = @_;
        my $eval;
        my @out;
        my $ref;
@@ -227,6 +233,22 @@ sub search
                           for (\$c = \$#spots; \$c >= 0; \$c--) {
                                        \$ref = \$spots[\$c];
                                        if ($expr) {
+                           if (\$dxchan && \$dxchan->{spotsfilter}) {
+                            if (\@\$ref < 9) {
+                                my \@dxcc = Prefix::cty_data(\$ref->[1]);
+                                if (\@dxcc) {
+                                    pop \@dxcc;
+                                    push \@\$ref, \@dxcc;
+                                }
+                                \@dxcc = Prefix::cty_data(\$ref->[4]);
+                                if (\@dxcc) {
+                                    pop \@dxcc;
+                                    push \@\$ref, \@dxcc;
+                                }
+                            }
+                                   my (\$filter, \$hops) = \$dxchan->{inspotsfilter}->it(\@\$ref);
+                                   next unless (\$filter);
+                        }
                                                \$count++;
                                                next if \$count < \$from; # wait until from 
                                                push(\@out, \$ref);
@@ -234,6 +256,9 @@ sub search
                                        }
                                }
                          );
+    
+       dbg("Spot eval: $eval") if isdbg('searcheval');
+       
 
        $fp->close;                                     # close any open files
 
@@ -369,6 +394,7 @@ sub genstats($)
                        my ($freq, $by, $dxcc) = (split /\^/)[0,4,6];
                        my $ref = $list{$by} || [0, $dxcc];
                        for (@freq) {
+                               next unless defined $_;
                                if ($freq >= $_->[1] && $freq <= $_->[2]) {
                                        $$ref[$_->[0]+2]++;
                                        $tot[$_->[0]+2]++;