11 my ($self, $line) = @_;
12 my @list = split /\s+/, $line; # split the line up
16 my $call = $self->call;
18 my ($fromday, $today);
38 my ($doqsl, $doiota, $doqra, $dofilter);
40 my $usesql = $main::dbh && $Spot::use_db_for_search;
42 while ($f = shift @list) { # next field
43 dbg "arg: $f list: " . join(',', @list) if isdbg('sh/dx');
45 ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$|; # is it a from -> to count?
46 next if $from && $to > $from;
49 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
52 if (lc $f eq 'exact') {
56 if (lc $f eq 'dxcc') {
60 if (lc $f eq 'rt' || $f =~ /^real/i) {
64 if (lc $f eq 'on' && $list[0]) { # is it freq range?
65 dbg "freq $list[0]" if isdbg('sh/dx');
66 if (my ($from, $to) = $list[0] =~ m|^(\d+)(?:\.\d+)?(?:[-/](\d+)(?:\.\d+)?)?$|) {
67 $to = $from unless defined $to;
68 dbg "freq '$from' '$to'" if isdbg('sh/dx');
69 push @freq, $from, $to;
74 my @r = split '/', lc $list[0];
75 dbg "r0: $r[0] r1: $r[1]" if isdbg('sh/dx');
76 my @fr = Bands::get_freq($r[0], $r[1]);
77 if (@fr) { # yup, get rid of extranous param
78 dbg "freq: " . join(',', @fr) if isdbg('sh/dx');
79 push @freq, @fr; # add these to the list
85 if (lc $f eq 'day' && $list[0]) {
86 ($fromday, $today) = split m|[-/]|, shift(@list);
87 dbg "got day $fromday/$today" if isdbg('sh/dx');
90 if (lc $f eq 'info' && $list[0]) {
92 dbg "got info $info" if isdbg('sh/dx');
95 if (lc $f eq 'origin' && $list[0]) {
96 $origin = uc shift @list;
97 dbg "got origin $origin" if isdbg('sh/dx');
100 if (lc $f eq 'ip' && $list[0]) {
102 dbg "got ip $ip" if isdbg('sh/dx');
106 if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
107 $spotter = uc shift @list;
108 if ($list[0] && lc $list[0] eq 'dxcc') {
112 dbg "got spotter $spotter fromdxcc $fromdxcc" if isdbg('sh/dx');
115 if (lc $f =~ /^filt/) {
116 $dofilter = 1 if $self && $self->spotsfilter;
119 if (lc $f eq 'qsl') {
123 if (lc $f eq 'iota') {
127 if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
129 $doiota = "\\b$a\[\-\ \]\?$b\\b";
132 $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
135 if (lc $f eq 'qra') {
136 $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/oi;
137 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
140 if (lc $f eq 'zone') {
141 $zone = shift @list if @list;
144 if (lc $f =~ /^by_?zone/) {
145 $byzone = shift @list if @list;
148 if (lc $f eq 'itu') {
149 $itu = shift @list if @list;
152 if (lc $f =~ /^by_?itu/) {
153 $byitu = shift @list if @list;
156 if (lc $f eq 'state') {
157 $state = uc shift @list if @list;
160 if (lc $f =~ /^by_?state/) {
161 $bystate = uc shift @list if @list;
173 $expr .= ' && ' if $expr;
174 $expr .= "\$f7 eq '$origin'";
175 $hint .= ' && ' if $hint;
176 $hint .= "m{$origin}";
179 # check (any) ip address
181 $expr .= ' && ' if $expr;
182 $expr .= "\$f14 && \$f14 =~ m{^$ip}";
183 $hint .= ' && ' if $hint;
184 $ip =~ s/\./\\./g; # IPV4
188 # deal with the prefix
193 @ans = Prefix::extract($pre); # is it a callsign/prefix?
197 # first deal with the prefix
198 my $pre = shift @ans;
200 my $str = "Prefix: $pre";
205 # build up a search string for this dxcc country/countries
208 push @expr, "\$f5 == $n";
210 my $name = $a->name();
211 $str .= " Dxcc: $n ($name)";
215 $expr = @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
216 $hint = @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
220 $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
221 $pre = shellregex($pre);
228 $pre .= '$' if $exact;
229 $expr = "\$f1 =~ m{$pre}";
235 # now deal with any frequencies specified
237 $expr .= ($expr) ? ' && (' : "(";
238 # $hint .= ($hint) ? ' && ' : "(";
239 # $hint .= ' && ' if $hint;
241 for ($i = 0; $i < @freq; $i += 2) {
242 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
243 my $r = Spot::ftor($freq[$i], $freq[$i+1]);
244 # $hint .= "m{$r\\.} ||" if $r;
245 # $hint .= "m{\d+\.} ||";
248 chop $expr; chop $expr;
249 # chop $hint; chop $hint;
256 $expr .= ' && ' if $expr;
257 # $info =~ s{(.)}{"\Q$1"}ge;
258 $expr .= "\$f3 =~ m{$info}i";
259 $hint .= ' && ' if $hint;
260 $hint .= "m{$info}i";
267 @ans = Prefix::extract($spotter); # is it a callsign/prefix?
271 # first deal with the prefix
272 my $pre = shift @ans;
274 $expr .= ' && ' if $expr;
275 $hint .= ' && ' if $hint;
276 my $str = "Spotter: $pre";
281 # build up a search string for this dxcc country/countries
284 push @expr, "\$f6 == $n";
286 my $name = $a->name();
287 $str .= " Dxcc: $n ($name)";
291 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
292 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
296 $expr .= ' && ' if $expr;
297 $spotter .= '*' unless $spotter =~ /[\*\?\[]/o;
298 $spotter = shellregex($spotter);
300 $spotter =~ s/\.\*/%/g;
303 $spotter =~ s/\.\*\$$//;
305 $expr .= "\$f4 =~ m{\U$spotter}";
306 $hint .= ' && ' if $hint;
307 $spotter =~ s/[\^\$]//g;
308 $hint .= "m{\U$spotter}";
316 $expr .= ' && ' if $expr;
317 $hint .= ' && ' if $hint;
318 for (split /[:,]/, $zone) {
319 push @expr, "\$f9==$_";
322 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
323 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
328 $expr .= ' && ' if $expr;
329 $hint .= ' && ' if $hint;
330 for (split /[:,]/, $byzone) {
331 push @expr, "\$f11==$_";
334 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
335 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
342 $expr .= ' && ' if $expr;
343 $hint .= ' && ' if $hint;
344 for (split /[:,]/, $itu) {
345 push @expr, "\$f8==$_";
348 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
349 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
354 $expr .= ' && ' if $expr;
355 $hint .= ' && ' if $hint;
356 for (split /[:,]/, $byitu) {
357 push @expr, "\$f10==$_";
360 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
361 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
368 $expr .= ' && ' if $expr;
369 $hint .= ' && ' if $hint;
370 for (split /[:,]/, $state) {
371 push @expr, "\$f12 eq '$_'";
375 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
378 $expr .= @expr > 1 ? '(\$f12 && (' . join(' || ', @expr) . '))' : "(\$f12 && $expr[0])";
380 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
385 $expr .= ' && ' if $expr;
386 $hint .= ' && ' if $hint;
387 for (split /[:,]/, $bystate) {
388 push @expr, "\$f13 eq '$_'";
392 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
395 $expr .= @expr > 1 ? '(\$f13 && (' . join(' || ', @expr) . '))' : "(\$f13 && $expr[0])";
397 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
402 $expr .= ' && ' if $expr;
403 $expr .= "\$f3 =~ m{QSL|VIA}i";
404 $hint .= ' && ' if $hint;
405 $hint .= "m{QSL|VIA}i";
410 $expr .= ' && ' if $expr;
411 $expr .= "\$f3 =~ m{$doiota}i";
412 $hint .= ' && ' if $hint;
413 $hint .= "m{$doiota}i";
418 $expr .= ' && ' if $expr;
419 $expr .= "\$f3 =~ m{$doqra}i";
420 $hint .= ' && ' if $hint;
421 $hint .= "m{$doqra}io";
430 dbg "expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('sh/dx');
434 if ($self->{_nospawn}) {
435 my @res = Spot::search($expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef);
438 foreach $ref (@res) {
439 if ($self && $self->ve7cc) {
440 push @out, VE7CC::dx_spot($self, @$ref);
443 if ($self && $real) {
444 push @out, DXCommandmode::format_dx_spot($self, @$ref);
447 push @out, Spot::formatl(@$ref);
453 push @out, $self->spawn_cmd("sh/dx $line", \&Spot::search,
454 args => [$expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef],
456 my ($dxchan, @res) = @_;
460 foreach $ref (@res) {
462 push @out, VE7CC::dx_spot($self, @$ref);
466 push @out, DXCommandmode::format_dx_spot($self, @$ref);
469 push @out, Spot::formatl(@$ref);
473 push @out, $self->msg('e3', "sh/dx", "'$line'") unless @out;