7 my ($self, $line) = @_;
8 my @list = split /\s+/, $line; # split the line up
14 my ($fromday, $today);
34 my ($doqsl, $doiota, $doqra, $dofilter);
36 my $usesql = $main::dbh && $Spot::use_db_for_search;
38 while ($f = shift @list) { # next field
39 dbg "arg: $f list: " . join(',', @list) if isdbg('shdx');
41 ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$|; # is it a from -> to count?
42 next if $from && $to > $from;
45 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
48 if (lc $f eq 'exact') {
52 if (lc $f eq 'dxcc') {
56 if (lc $f eq 'rt' || $f =~ /^real/i) {
60 if (lc $f eq 'on' && $list[0]) { # is it freq range?
61 dbg "freq $list[0]" if isdbg('shdx');
62 if (my ($from, $to) = $list[0] =~ m|^(\d+)(?:\.\d+)?(?:[-/](\d+)(?:\.\d+)?)?$|) {
63 $to = $from unless defined $to;
64 dbg "freq '$from' '$to'" if isdbg('shdx');
65 push @freq, $from, $to;
69 my @r = split '/', lc $list[0];
70 dbg "r0: $r[0] r1: $r[1]" if isdbg('shdx');
71 my @fr = Bands::get_freq($r[0], $r[1]);
72 if (@fr) { # yup, get rid of extranous param
73 dbg "freq: " . join(',', @fr) if isdbg('shdx');
74 push @freq, @fr; # add these to the list
80 if (lc $f eq 'day' && $list[0]) {
81 ($fromday, $today) = split m|[-/]|, shift(@list);
82 dbg "got day $fromday/$today" if isdbg('shdx');
85 if (lc $f eq 'info' && $list[0]) {
87 dbg "got info $info" if isdbg('shdx');
90 if (lc $f eq 'origin' && $list[0]) {
91 $origin = uc shift @list;
92 dbg "got origin $origin" if isdbg('shdx');
95 if (lc $f eq 'ip' && $list[0]) {
97 dbg "got ip $ip" if isdbg('shdx');
101 if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
102 $spotter = uc shift @list;
103 if ($list[0] && lc $list[0] eq 'dxcc') {
107 dbg "got spotter $spotter fromdxcc $fromdxcc" if isdbg('shdx');
110 if (lc $f =~ /^filt/) {
111 $dofilter = 1 if $self && $self->spotsfilter;
114 if (lc $f eq 'qsl') {
118 if (lc $f eq 'iota') {
122 if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
124 $doiota = "\\b$a\[\-\ \]\?$b\\b";
127 $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
130 if (lc $f eq 'qra') {
131 $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/oi;
132 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
135 if (lc $f eq 'zone') {
136 $zone = shift @list if @list;
139 if (lc $f =~ /^by_?zone/) {
140 $byzone = shift @list if @list;
143 if (lc $f eq 'itu') {
144 $itu = shift @list if @list;
147 if (lc $f =~ /^by_?itu/) {
148 $byitu = shift @list if @list;
151 if (lc $f eq 'state') {
152 $state = uc shift @list if @list;
155 if (lc $f =~ /^by_?state/) {
156 $bystate = uc shift @list if @list;
168 $expr .= ' && ' if $expr;
169 $expr .= "\$f7 eq '$origin'";
170 $hint .= ' && ' if $hint;
171 $hint .= "m{$origin}";
174 # check (any) ip address
176 $expr .= ' && ' if $expr;
177 $expr .= "\$f14 && \$f14 =~ m{^$ip}";
178 $hint .= ' && ' if $hint;
179 $ip =~ s/\./\\./g; # IPV4
183 # deal with the prefix
188 @ans = Prefix::extract($pre); # is it a callsign/prefix?
192 # first deal with the prefix
193 my $pre = shift @ans;
195 my $str = "Prefix: $pre";
200 # build up a search string for this dxcc country/countries
203 push @expr, "\$f5 == $n";
205 my $name = $a->name();
206 $str .= " Dxcc: $n ($name)";
210 $expr = @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
211 $hint = @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
215 $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
216 $pre = shellregex($pre);
222 $pre .= '$' if $exact;
223 $expr = "\$f1 =~ m{$pre}";
229 # now deal with any frequencies specified
231 $expr .= ($expr) ? ' && (' : "(";
232 # $hint .= ($hint) ? ' && ' : "(";
233 # $hint .= ' && ' if $hint;
235 for ($i = 0; $i < @freq; $i += 2) {
236 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
237 my $r = Spot::ftor($freq[$i], $freq[$i+1]);
238 # $hint .= "m{$r\\.} ||" if $r;
239 # $hint .= "m{\d+\.} ||";
242 chop $expr; chop $expr;
243 # chop $hint; chop $hint;
250 $expr .= ' && ' if $expr;
251 # $info =~ s{(.)}{"\Q$1"}ge;
252 $expr .= "\$f3 =~ m{$info}i";
253 $hint .= ' && ' if $hint;
254 $hint .= "m{$info}i";
261 @ans = Prefix::extract($spotter); # is it a callsign/prefix?
265 # first deal with the prefix
266 my $pre = shift @ans;
268 $expr .= ' && ' if $expr;
269 $hint .= ' && ' if $hint;
270 my $str = "Spotter: $pre";
275 # build up a search string for this dxcc country/countries
278 push @expr, "\$f6 == $n";
280 my $name = $a->name();
281 $str .= " Dxcc: $n ($name)";
285 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
286 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
290 $expr .= ' && ' if $expr;
291 $spotter .= '*' unless $spotter =~ /[\*\?\[]/o;
292 $spotter = shellregex($spotter);
294 $spotter =~ s/\.\*/%/g;
296 $spotter =~ s/\.\*\$$//;
298 $expr .= "\$f4 =~ m{\U$spotter}";
299 $hint .= ' && ' if $hint;
300 $spotter =~ s/[\^\$]//g;
301 $hint .= "m{\U$spotter}";
309 $expr .= ' && ' if $expr;
310 $hint .= ' && ' if $hint;
311 for (split /[:,]/, $zone) {
312 push @expr, "\$f9==$_";
315 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
316 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
321 $expr .= ' && ' if $expr;
322 $hint .= ' && ' if $hint;
323 for (split /[:,]/, $byzone) {
324 push @expr, "\$f11==$_";
327 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
328 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
335 $expr .= ' && ' if $expr;
336 $hint .= ' && ' if $hint;
337 for (split /[:,]/, $itu) {
338 push @expr, "\$f8==$_";
341 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
342 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
347 $expr .= ' && ' if $expr;
348 $hint .= ' && ' if $hint;
349 for (split /[:,]/, $byitu) {
350 push @expr, "\$f10==$_";
353 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
354 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
361 $expr .= ' && ' if $expr;
362 $hint .= ' && ' if $hint;
363 for (split /[:,]/, $state) {
364 push @expr, "\$f12 eq '$_'";
368 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
370 $expr .= @expr > 1 ? '(\$f12 && (' . join(' || ', @expr) . '))' : "(\$f12 && $expr[0])";
372 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
377 $expr .= ' && ' if $expr;
378 $hint .= ' && ' if $hint;
379 for (split /[:,]/, $bystate) {
380 push @expr, "\$f13 eq '$_'";
384 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
386 $expr .= @expr > 1 ? '(\$f13 && (' . join(' || ', @expr) . '))' : "(\$f13 && $expr[0])";
388 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
393 $expr .= ' && ' if $expr;
394 $expr .= "\$f3 =~ m{QSL|VIA}i";
395 $hint .= ' && ' if $hint;
396 $hint .= "m{QSL|VIA}i";
401 $expr .= ' && ' if $expr;
402 $expr .= "\$f3 =~ m{$doiota}i";
403 $hint .= ' && ' if $hint;
404 $hint .= "m{$doiota}i";
409 $expr .= ' && ' if $expr;
410 $expr .= "\$f3 =~ m{$doqra}i";
411 $hint .= ' && ' if $hint;
412 $hint .= "m{$doqra}io";
420 dbg "expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('sh/dx');
423 my @res = Spot::search($expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef);
426 foreach $ref (@res) {
427 if ($self && $self->ve7cc) {
428 push @out, VE7CC::dx_spot($self, @$ref);
430 if ($self && $real) {
431 push @out, DXCommandmode::format_dx_spot($self, @$ref);
433 push @out, Spot::formatl(@$ref);