9 my ($self, $line) = @_;
10 my @list = split /\s+/, $line; # split the line up
14 my $call = $self->call;
16 my ($fromday, $today);
36 my ($doqsl, $doiota, $doqra, $dofilter);
38 my $usesql = $main::dbh && $Spot::use_db_for_search;
40 while ($f = shift @list) { # next field
41 dbg "arg: $f list: " . join(',', @list) if isdbg('sh/dx');
43 ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$|; # is it a from -> to count?
44 next if $from && $to > $from;
47 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
50 if (lc $f eq 'exact') {
54 if (lc $f eq 'dxcc') {
58 if (lc $f eq 'rt' || $f =~ /^real/i) {
62 if (lc $f eq 'on' && $list[0]) { # is it freq range?
63 dbg "freq $list[0]" if isdbg('sh/dx');
64 if (my ($from, $to) = $list[0] =~ m|^(\d+)(?:\.\d+)?(?:[-/](\d+)(?:\.\d+)?)?$|) {
65 $to = $from unless defined $to;
66 dbg "freq '$from' '$to'" if isdbg('sh/dx');
67 push @freq, $from, $to;
71 my @r = split '/', lc $list[0];
72 dbg "r0: $r[0] r1: $r[1]" if isdbg('sh/dx');
73 my @fr = Bands::get_freq($r[0], $r[1]);
74 if (@fr) { # yup, get rid of extranous param
75 dbg "freq: " . join(',', @fr) if isdbg('sh/dx');
76 push @freq, @fr; # add these to the list
82 if (lc $f eq 'day' && $list[0]) {
83 ($fromday, $today) = split m|[-/]|, shift(@list);
84 dbg "got day $fromday/$today" if isdbg('sh/dx');
87 if (lc $f eq 'info' && $list[0]) {
89 dbg "got info $info" if isdbg('sh/dx');
92 if (lc $f eq 'origin' && $list[0]) {
93 $origin = uc shift @list;
94 dbg "got origin $origin" if isdbg('sh/dx');
97 if (lc $f eq 'ip' && $list[0]) {
99 dbg "got ip $ip" if isdbg('sh/dx');
103 if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
104 $spotter = uc shift @list;
105 if ($list[0] && lc $list[0] eq 'dxcc') {
109 dbg "got spotter $spotter fromdxcc $fromdxcc" if isdbg('sh/dx');
112 if (lc $f =~ /^filt/) {
113 $dofilter = 1 if $self && $self->spotsfilter;
116 if (lc $f eq 'qsl') {
120 if (lc $f eq 'iota') {
124 if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
126 $doiota = "\\b$a\[\-\ \]\?$b\\b";
129 $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
132 if (lc $f eq 'qra') {
133 $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/oi;
134 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
137 if (lc $f eq 'zone') {
138 $zone = shift @list if @list;
141 if (lc $f =~ /^by_?zone/) {
142 $byzone = shift @list if @list;
145 if (lc $f eq 'itu') {
146 $itu = shift @list if @list;
149 if (lc $f =~ /^by_?itu/) {
150 $byitu = shift @list if @list;
153 if (lc $f eq 'state') {
154 $state = uc shift @list if @list;
157 if (lc $f =~ /^by_?state/) {
158 $bystate = uc shift @list if @list;
170 $expr .= ' && ' if $expr;
171 $expr .= "\$f7 eq '$origin'";
172 $hint .= ' && ' if $hint;
173 $hint .= "m{$origin}";
176 # check (any) ip address
178 $expr .= ' && ' if $expr;
179 $expr .= "\$f14 && \$f14 =~ m{^$ip}";
180 $hint .= ' && ' if $hint;
181 $ip =~ s/\./\\./g; # IPV4
185 # deal with the prefix
190 @ans = Prefix::extract($pre); # is it a callsign/prefix?
194 # first deal with the prefix
195 my $pre = shift @ans;
197 my $str = "Prefix: $pre";
202 # build up a search string for this dxcc country/countries
205 push @expr, "\$f5 == $n";
207 my $name = $a->name();
208 $str .= " Dxcc: $n ($name)";
212 $expr = @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
213 $hint = @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
217 $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
218 $pre = shellregex($pre);
224 $pre .= '$' if $exact;
225 $expr = "\$f1 =~ m{$pre}";
231 # now deal with any frequencies specified
233 $expr .= ($expr) ? ' && (' : "(";
234 # $hint .= ($hint) ? ' && ' : "(";
235 # $hint .= ' && ' if $hint;
237 for ($i = 0; $i < @freq; $i += 2) {
238 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
239 my $r = Spot::ftor($freq[$i], $freq[$i+1]);
240 # $hint .= "m{$r\\.} ||" if $r;
241 # $hint .= "m{\d+\.} ||";
244 chop $expr; chop $expr;
245 # chop $hint; chop $hint;
252 $expr .= ' && ' if $expr;
253 # $info =~ s{(.)}{"\Q$1"}ge;
254 $expr .= "\$f3 =~ m{$info}i";
255 $hint .= ' && ' if $hint;
256 $hint .= "m{$info}i";
263 @ans = Prefix::extract($spotter); # is it a callsign/prefix?
267 # first deal with the prefix
268 my $pre = shift @ans;
270 $expr .= ' && ' if $expr;
271 $hint .= ' && ' if $hint;
272 my $str = "Spotter: $pre";
277 # build up a search string for this dxcc country/countries
280 push @expr, "\$f6 == $n";
282 my $name = $a->name();
283 $str .= " Dxcc: $n ($name)";
287 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
288 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
292 $expr .= ' && ' if $expr;
293 $spotter .= '*' unless $spotter =~ /[\*\?\[]/o;
294 $spotter = shellregex($spotter);
296 $spotter =~ s/\.\*/%/g;
298 $spotter =~ s/\.\*\$$//;
300 $expr .= "\$f4 =~ m{\U$spotter}";
301 $hint .= ' && ' if $hint;
302 $spotter =~ s/[\^\$]//g;
303 $hint .= "m{\U$spotter}";
311 $expr .= ' && ' if $expr;
312 $hint .= ' && ' if $hint;
313 for (split /[:,]/, $zone) {
314 push @expr, "\$f9==$_";
317 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
318 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
323 $expr .= ' && ' if $expr;
324 $hint .= ' && ' if $hint;
325 for (split /[:,]/, $byzone) {
326 push @expr, "\$f11==$_";
329 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
330 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
337 $expr .= ' && ' if $expr;
338 $hint .= ' && ' if $hint;
339 for (split /[:,]/, $itu) {
340 push @expr, "\$f8==$_";
343 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
344 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
349 $expr .= ' && ' if $expr;
350 $hint .= ' && ' if $hint;
351 for (split /[:,]/, $byitu) {
352 push @expr, "\$f10==$_";
355 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
356 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
363 $expr .= ' && ' if $expr;
364 $hint .= ' && ' if $hint;
365 for (split /[:,]/, $state) {
366 push @expr, "\$f12 eq '$_'";
370 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
372 $expr .= @expr > 1 ? '(\$f12 && (' . join(' || ', @expr) . '))' : "(\$f12 && $expr[0])";
374 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
379 $expr .= ' && ' if $expr;
380 $hint .= ' && ' if $hint;
381 for (split /[:,]/, $bystate) {
382 push @expr, "\$f13 eq '$_'";
386 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
388 $expr .= @expr > 1 ? '(\$f13 && (' . join(' || ', @expr) . '))' : "(\$f13 && $expr[0])";
390 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
395 $expr .= ' && ' if $expr;
396 $expr .= "\$f3 =~ m{QSL|VIA}i";
397 $hint .= ' && ' if $hint;
398 $hint .= "m{QSL|VIA}i";
403 $expr .= ' && ' if $expr;
404 $expr .= "\$f3 =~ m{$doiota}i";
405 $hint .= ' && ' if $hint;
406 $hint .= "m{$doiota}i";
411 $expr .= ' && ' if $expr;
412 $expr .= "\$f3 =~ m{$doqra}i";
413 $hint .= ' && ' if $hint;
414 $hint .= "m{$doqra}io";
423 dbg "expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('sh/dx');
427 push @out, $self->spawn_cmd("sh/dx $line", \&Spot::search,
428 args => [$expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef],
430 my ($dxchan, @res) = @_;
434 foreach $ref (@res) {
436 push @out, VE7CC::dx_spot($self, @$ref);
439 push @out, DXCommandmode::format_dx_spot($self, @$ref);
441 push @out, Spot::formatl(@$ref);
445 push @out, $self->msg('e3', "sh/dx", "'$line'") unless @out;
449 #my @res = Spot::search($expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef);
452 #foreach $ref (@res) {
453 # if ($self && $self->ve7cc) {
454 # push @out, VE7CC::dx_spot($self, @$ref);
456 # if ($self && $real) {
457 # push @out, DXCommandmode::format_dx_spot($self, @$ref);
459 # push @out, Spot::formatl(@$ref);