615aac04569d22e14552d876fb0edb3f08955c82
[spider.git] / cmd / show / dxcc.pl
1 #
2 # show dx using the dxcc number as the basis for searchs for each callsign or prefix entered
3 #
4 # $Id$
5 #
6
7 my ($self, $line) = @_;
8 my @list = split /\s+/, $line;                # split the line up
9
10 my @out;
11 my $f;
12 my $call;
13 my ($from, $to);
14 my ($fromday, $today);
15 my @freq;
16 my @ans;
17
18 while ($f = shift @list) {                 # next field
19   print "f: $f list: ", join(',', @list), "\n";
20   if (!$from && !$to) {
21     ($from, $to) = $f =~ /^(\d+)-(\d+)$/o;         # is it a from -> to count?
22     next if $from && $to > $from;
23   }
24   if (!$to) {
25     ($to) = $f =~ /^(\d+)$/o if !$to;              # is it a to count?
26     next if $to;
27   }
28   if (lc $f eq 'on' && $list[0]) {                  # is it freq range?
29     print "yup freq\n";
30     my @r = split '/', $list[0];
31         print "r0: $r[0] r1: $r[1]\n";
32         @freq = Bands::get_freq($r[0], $r[1]);
33         if (@freq) {                 # yup, get rid of extranous param
34           print "freq: ", join(',', @freq), "\n";
35           shift @list;
36           next;
37         }
38   }
39   if (lc $f eq 'day' && $list[0]) {
40     print "got day\n";
41     ($fromday, $today) = split '-', $list[0];
42         shift @list;
43         next;
44   }
45   if (!@ans) {
46     @ans = Prefix::extract($f);                       # is it a callsign/prefix?
47   }
48 }
49
50 # no dxcc country, no answer!
51 if (@ans) {                               # we have a valid prefix!
52   
53   # first deal with the prefix
54   my $pre = shift @ans;
55   my $a;
56   my $expr = "(";
57   my $str = "Prefix: $pre";
58   my $l = length $str;
59
60   # build up a search string for this dxcc country/countries
61   foreach $a (@ans) {
62     $expr .= " || " if $expr ne "(";
63         my $n = $a->dxcc();
64     $expr .= "\$f5 == $n";
65         my $name = $a->name();
66         $str .= " Dxcc: $n ($name)";
67         push @out, $str;
68         $str = pack "A$l", " ";
69   }
70   $expr .= ")";
71   push @out, $str;
72   
73   # now deal with any frequencies specified
74   if (@freq) {
75     $expr .= " && (";
76         my $i;
77         for ($i; $i < @freq; $i += 2) {
78           $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
79         }
80         chop $expr;
81         chop $expr;
82         $expr .= ")";
83   }
84
85   print "expr: $expr from: $from to: $to fromday: $fromday today: $today\n";
86   
87   # now do the search
88   my @res = Spot::search($expr, $fromday, $today, $from, $to);
89   my $ref;
90   my @dx;
91   foreach $ref (@res) {
92     @dx = @$ref;
93         my $t = ztime($dx[2]);
94         my $d = cldate($dx[2]);
95         push @out, sprintf "%9s %-12s %s %s %-28s <%s>", $dx[0], $dx[1], $d, $t, $dx[3], $dx[4];
96   }
97 } else {
98   @out = DXM::msg('e4');
99 }
100
101 return (1, @out);