added some extra cases for IOTA and QSL detection on sh/dx
[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, $doiota, $doqra);
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 (lc $f eq 'iota') {
65                 my ($a, $b);
66 #               $DB::single =1;
67                 
68                 if ($list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
69                         $a = uc $a;
70                         $doiota = "\\b$a\[\-\ \]\?$b\\b";
71                         shift @list;
72                 }
73                 $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
74                 next;
75         }
76         if (lc $f eq 'qra') {
77                 $doqra = uc shift @list if $list[0] =~ /[A-Z][A-Z]\d\d/oi;
78                 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
79                 next;
80         }
81         if (!$pre) {
82                 $pre = uc $f;
83         }
84 }
85
86 # first deal with the prefix
87 if ($pre) {
88         $pre .= '*' unless $pre =~ /[\*\?\[]/o;
89         $pre = shellregex($pre);
90         $expr = "\$f1 =~ m{$pre}o";
91 } else {
92         $expr = "1";                            # match anything
93 }
94   
95 # now deal with any frequencies specified
96 if (@freq) {
97         $expr .= ($expr) ? " && (" : "(";
98         my $i;
99         for ($i = 0; $i < @freq; $i += 2) {
100                 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
101         }
102         chop $expr;
103         chop $expr;
104         $expr .= ")";
105 }
106
107 # any info
108 if ($info) {
109         $expr .= " && " if $expr;
110         $info =~ s{(.)}{"\Q$1"}ge;
111         $expr .= "\$f3 =~ m{$info}io";
112 }
113
114 # any spotter
115 if ($spotter) {
116         $expr .= " && " if $expr;
117         $spotter = shellregex($spotter);
118         $expr .= "\$f4 =~ m{$spotter}o";
119 }
120
121 # qsl requests
122 if ($doqsl) {
123         $expr .= " && " if $expr;
124         $expr .= "\$f3 =~ m{(\@|>|QSL|VIA)}io";
125 }
126
127 # iota requests
128 if ($doiota) {
129         $expr .= " && " if $expr;
130         $expr .= "\$f3 =~ m{$doiota}io";
131 }
132
133 # iota requests
134 if ($doqra) {
135         $expr .= " && " if $expr;
136         $expr .= "\$f3 =~ m{$doqra}io";
137 }
138
139 #print "expr: $expr from: $from to: $to fromday: $fromday today: $today\n";
140   
141 # now do the search
142 my @res = Spot::search($expr, $fromday, $today, $from, $to);
143 my $ref;
144 my @dx;
145 foreach $ref (@res) {
146         @dx = @$ref;
147         push @out, Spot::formatl(@dx);
148 }
149
150 return (1, @out);