9 my ($self, $line) = @_;
10 my @list = split /\s+/, $line; # split the line up
14 my $call = $self->call;
16 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 'spotter' || lc $f eq 'by') && $list[0]) {
91 $spotter = uc shift @list;
92 if ($list[0] && lc $list[0] eq 'dxcc') {
96 dbg "got spotter $spotter fromdxcc $fromdxcc" if isdbg('shdx');
99 if (lc $f =~ /^filt/) {
100 $dofilter = 1 if $self && $self->spotsfilter;
103 if (lc $f eq 'qsl') {
107 if (lc $f eq 'iota') {
111 if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
113 $doiota = "\\b$a\[\-\ \]\?$b\\b";
116 $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
119 if (lc $f eq 'qra') {
120 $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/oi;
121 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
124 if (lc $f eq 'zone') {
125 $zone = shift @list if @list;
128 if (lc $f =~ /^by_?zone/) {
129 $byzone = shift @list if @list;
132 if (lc $f eq 'itu') {
133 $itu = shift @list if @list;
136 if (lc $f =~ /^by_?itu/) {
137 $byitu = shift @list if @list;
140 if (lc $f eq 'state') {
141 $state = uc shift @list if @list;
144 if (lc $f =~ /^by_?state/) {
145 $bystate = uc shift @list if @list;
155 # first deal with the prefix
160 @ans = Prefix::extract($pre); # is it a callsign/prefix?
164 # first deal with the prefix
165 my $pre = shift @ans;
167 my $str = "Prefix: $pre";
172 # build up a search string for this dxcc country/countries
175 push @expr, "\$f5 == $n";
177 my $name = $a->name();
178 $str .= " Dxcc: $n ($name)";
182 $expr = @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
183 $hint = @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
187 $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
188 $pre = shellregex($pre);
194 $pre .= '$' if $exact;
195 $expr = "\$f1 =~ m{$pre}";
201 # now deal with any frequencies specified
203 $expr .= ($expr) ? ' && (' : "(";
204 # $hint .= ($hint) ? ' && ' : "(";
205 # $hint .= ' && ' if $hint;
207 for ($i = 0; $i < @freq; $i += 2) {
208 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
209 my $r = Spot::ftor($freq[$i], $freq[$i+1]);
210 # $hint .= "m{$r\\.} ||" if $r;
211 # $hint .= "m{\d+\.} ||";
214 chop $expr; chop $expr;
215 # chop $hint; chop $hint;
222 $expr .= ' && ' if $expr;
223 $info =~ s{(.)}{"\Q$1"}ge;
224 $expr .= "\$f3 =~ m{$info}i";
225 $hint .= ' && ' if $hint;
226 $hint .= "m{$info}i";
233 @ans = Prefix::extract($spotter); # is it a callsign/prefix?
237 # first deal with the prefix
238 my $pre = shift @ans;
240 $expr .= ' && ' if $expr;
241 $hint .= ' && ' if $hint;
242 my $str = "Spotter: $pre";
247 # build up a search string for this dxcc country/countries
250 push @expr, "\$f6 == $n";
252 my $name = $a->name();
253 $str .= " Dxcc: $n ($name)";
257 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
258 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
262 $expr .= ' && ' if $expr;
263 $spotter .= '*' unless $spotter =~ /[\*\?\[]/o;
264 $spotter = shellregex($spotter);
266 $spotter =~ s/\.\*/%/g;
268 $spotter =~ s/\.\*\$$//;
270 $expr .= "\$f4 =~ m{\U$spotter}";
271 $hint .= ' && ' if $hint;
272 $spotter =~ s/[\^\$]//g;
273 $hint .= "m{\U$spotter}";
281 $expr .= ' && ' if $expr;
282 $hint .= ' && ' if $hint;
283 for (split /[:,]/, $zone) {
284 push @expr, "\$f9==$_";
287 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
288 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
293 $expr .= ' && ' if $expr;
294 $hint .= ' && ' if $hint;
295 for (split /[:,]/, $byzone) {
296 push @expr, "\$f11==$_";
299 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
300 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
307 $expr .= ' && ' if $expr;
308 $hint .= ' && ' if $hint;
309 for (split /[:,]/, $itu) {
310 push @expr, "\$f8==$_";
313 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
314 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
319 $expr .= ' && ' if $expr;
320 $hint .= ' && ' if $hint;
321 for (split /[:,]/, $byitu) {
322 push @expr, "\$f10==$_";
325 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
326 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
333 $expr .= ' && ' if $expr;
334 $hint .= ' && ' if $hint;
335 for (split /[:,]/, $state) {
336 push @expr, "\$f12 eq '$_'";
340 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
342 $expr .= @expr > 1 ? '(\$f12 && (' . join(' || ', @expr) . '))' : "(\$f12 && $expr[0])";
344 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
349 $expr .= ' && ' if $expr;
350 $hint .= ' && ' if $hint;
351 for (split /[:,]/, $bystate) {
352 push @expr, "\$f13 eq '$_'";
356 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
358 $expr .= @expr > 1 ? '(\$f13 && (' . join(' || ', @expr) . '))' : "(\$f13 && $expr[0])";
360 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
365 $expr .= ' && ' if $expr;
366 $expr .= "\$f3 =~ m{QSL|VIA}i";
367 $hint .= ' && ' if $hint;
368 $hint .= "m{QSL|VIA}i";
373 $expr .= ' && ' if $expr;
374 $expr .= "\$f3 =~ m{$doiota}i";
375 $hint .= ' && ' if $hint;
376 $hint .= "m{$doiota}i";
381 $expr .= ' && ' if $expr;
382 $expr .= "\$f3 =~ m{$doqra}i";
383 $hint .= ' && ' if $hint;
384 $hint .= "m{$doqra}io";
387 dbg "expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('shdx');
391 push @out, $self->spawn_cmd("sh/dx $line", \&Spot::search,
392 args => [$expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef],
394 my ($dxchan, @res) = @_;
398 foreach $ref (@res) {
400 push @out, VE7CC::dx_spot($self, @$ref);
403 push @out, DXCommandmode::format_dx_spot($self, @$ref);
405 push @out, Spot::formatl(@$ref);
412 #my @res = Spot::search($expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef);
415 #foreach $ref (@res) {
416 # if ($self && $self->ve7cc) {
417 # push @out, VE7CC::dx_spot($self, @$ref);
419 # if ($self && $real) {
420 # push @out, DXCommandmode::format_dx_spot($self, @$ref);
422 # push @out, Spot::formatl(@$ref);