*** empty log message ***
[spider.git] / cmd / show / dx.pl
1 #
2 # show dx (normal)
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 my $pre;
18 my $spotter;
19 my $info;
20 my $expr;
21 my $doqsl;
22
23 while ($f = shift @list) {              # next field
24         #  print "f: $f list: ", join(',', @list), "\n";
25         if (!$from && !$to) {
26                 ($from, $to) = $f =~ /^(\d+)-(\d+)$/o; # is it a from -> to count?
27                 next if $from && $to > $from;
28         }
29         if (!$to) {
30                 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
31                 next if $to;
32         }
33         if (lc $f eq 'on' && $list[0]) { # is it freq range?
34                 #    print "yup freq\n";
35                 my @r = split '/', $list[0];
36                         # print "r0: $r[0] r1: $r[1]\n";
37                 my @fr = Bands::get_freq($r[0], $r[1]);
38                 if (@fr) {                      # yup, get rid of extranous param
39                         #         print "freq: ", join(',', @fr), "\n";
40                         shift @list;
41                         push @freq, @fr;    # add these to the list
42                         next;
43                 }
44         }
45         if (lc $f eq 'day' && $list[0]) {
46                 #   print "got day\n";
47                 ($fromday, $today) = split '-', shift(@list);
48                 next;
49         }
50         if (lc $f eq 'info' && $list[0]) {
51                 #   print "got info\n";
52                 $info = shift @list;
53                 next;
54         }
55         if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
56                 #    print "got spotter\n";
57                 $spotter = uc shift @list;
58                 next;
59         }
60         if (lc $f eq 'qsl') {
61                 $doqsl = 1;
62                 next;
63         }
64         if (!$pre) {
65                 $pre = uc $f;
66         }
67 }
68
69 # first deal with the prefix
70 if ($pre) {
71         $pre .= '*' unless $pre =~ /[\*\?\[]/o;
72         $pre = shellregex($pre);
73         $expr = "\$f1 =~ m{$pre}o";
74 } else {
75         $expr = "1";                            # match anything
76 }
77   
78 # now deal with any frequencies specified
79 if (@freq) {
80         $expr .= ($expr) ? " && (" : "(";
81         my $i;
82         for ($i = 0; $i < @freq; $i += 2) {
83                 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
84         }
85         chop $expr;
86         chop $expr;
87         $expr .= ")";
88 }
89
90 # any info
91 if ($info) {
92         $expr .= " && " if $expr;
93         $info =~ s{(.)}{"\Q$1"}ge;
94         $expr .= "\$f3 =~ m{$info}io";
95 }
96
97 # any spotter
98 if ($spotter) {
99         $expr .= " && " if $expr;
100         $spotter = shellregex($spotter);
101         $expr .= "\$f4 =~ m{$spotter}o";
102 }
103
104 # qsl requests
105 if ($doqsl) {
106         $expr .= " && " if $expr;
107         $expr .= "\$f3 =~ m{(QSL|VIA)}io";
108 }
109
110 #print "expr: $expr from: $from to: $to fromday: $fromday today: $today\n";
111   
112 # now do the search
113 my @res = Spot::search($expr, $fromday, $today, $from, $to);
114 my $ref;
115 my @dx;
116 foreach $ref (@res) {
117         @dx = @$ref;
118         push @out, Spot::formatl(@dx);
119 }
120
121 return (1, @out);