7 my ($self, $line) = @_;
8 my @list = split /\s+/, $line; # split the line up
14 my ($fromday, $today);
32 my ($doqsl, $doiota, $doqra, $dofilter);
34 my $usesql = $main::dbh && $Spot::use_db_for_search;
36 while ($f = shift @list) { # next field
37 dbg "arg: $f list: " . join(',', @list) if isdbg('shdx');
39 ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$|; # is it a from -> to count?
40 next if $from && $to > $from;
43 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
46 if (lc $f eq 'exact') {
50 if (lc $f eq 'dxcc') {
54 if (lc $f eq 'rt' || $f =~ /^real/i) {
58 if (lc $f eq 'on' && $list[0]) { # is it freq range?
59 dbg "freq $list[0]" if isdbg('shdx');
60 if (my ($from, $to) = $list[0] =~ m|^(\d+)(?:\.\d+)?(?:[-/](\d+)(?:\.\d+)?)?$|) {
61 $to = $from unless defined $to;
62 dbg "freq '$from' '$to'" if isdbg('shdx');
63 push @freq, $from, $to;
67 my @r = split '/', lc $list[0];
68 dbg "r0: $r[0] r1: $r[1]" if isdbg('shdx');
69 my @fr = Bands::get_freq($r[0], $r[1]);
70 if (@fr) { # yup, get rid of extranous param
71 dbg "freq: " . join(',', @fr) if isdbg('shdx');
72 push @freq, @fr; # add these to the list
78 if (lc $f eq 'day' && $list[0]) {
79 ($fromday, $today) = split m|[-/]|, shift(@list);
80 dbg "got day $fromday/$today" if isdbg('shdx');
83 if (lc $f eq 'info' && $list[0]) {
85 dbg "got info $info" if isdbg('shdx');
88 if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
89 $spotter = uc shift @list;
90 if ($list[0] && lc $list[0] eq 'dxcc') {
94 dbg "got spotter $spotter fromdxcc $fromdxcc" if isdbg('shdx');
97 if (lc $f =~ /^filt/) {
98 $dofilter = 1 if $self && $self->spotsfilter;
101 if (lc $f eq 'qsl') {
105 if (lc $f eq 'iota') {
109 if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
111 $doiota = "\\b$a\[\-\ \]\?$b\\b";
114 $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
117 if (lc $f eq 'qra') {
118 $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/oi;
119 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
122 if (lc $f eq 'zone') {
123 $zone = shift @list if @list;
126 if (lc $f =~ /^by_?zone/) {
127 $byzone = shift @list if @list;
130 if (lc $f eq 'itu') {
131 $itu = shift @list if @list;
134 if (lc $f =~ /^by_?itu/) {
135 $byitu = shift @list if @list;
138 if (lc $f eq 'state') {
139 $state = uc shift @list if @list;
142 if (lc $f =~ /^by_?state/) {
143 $bystate = uc shift @list if @list;
153 # first deal with the prefix
158 @ans = Prefix::extract($pre); # is it a callsign/prefix?
162 # first deal with the prefix
163 my $pre = shift @ans;
165 my $str = "Prefix: $pre";
170 # build up a search string for this dxcc country/countries
173 push @expr, "\$f5 == $n";
175 my $name = $a->name();
176 $str .= " Dxcc: $n ($name)";
180 $expr = @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
181 $hint = @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
185 $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
186 $pre = shellregex($pre);
192 $pre .= '$' if $exact;
193 $expr = "\$f1 =~ m{$pre}";
199 # now deal with any frequencies specified
201 $expr .= ($expr) ? ' && (' : "(";
202 # $hint .= ($hint) ? ' && ' : "(";
203 # $hint .= ' && ' if $hint;
205 for ($i = 0; $i < @freq; $i += 2) {
206 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
207 my $r = Spot::ftor($freq[$i], $freq[$i+1]);
208 # $hint .= "m{$r\\.} ||" if $r;
209 # $hint .= "m{\d+\.} ||";
212 chop $expr; chop $expr;
213 # chop $hint; chop $hint;
220 $expr .= ' && ' if $expr;
221 $info =~ s{(.)}{"\Q$1"}ge;
222 $expr .= "\$f3 =~ m{$info}i";
223 $hint .= ' && ' if $hint;
224 $hint .= "m{$info}i";
231 @ans = Prefix::extract($spotter); # is it a callsign/prefix?
235 # first deal with the prefix
236 my $pre = shift @ans;
238 $expr .= ' && ' if $expr;
239 $hint .= ' && ' if $hint;
240 my $str = "Spotter: $pre";
245 # build up a search string for this dxcc country/countries
248 push @expr, "\$f6 == $n";
250 my $name = $a->name();
251 $str .= " Dxcc: $n ($name)";
255 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
256 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
260 $expr .= ' && ' if $expr;
261 $spotter .= '*' unless $spotter =~ /[\*\?\[]/o;
262 $spotter = shellregex($spotter);
264 $spotter =~ s/\.\*/%/g;
266 $spotter =~ s/\.\*\$$//;
268 $expr .= "\$f4 =~ m{\U$spotter}";
269 $hint .= ' && ' if $hint;
270 $spotter =~ s/[\^\$]//g;
271 $hint .= "m{\U$spotter}";
279 $expr .= ' && ' if $expr;
280 $hint .= ' && ' if $hint;
281 for (split /[:,]/, $zone) {
282 push @expr, "\$f9==$_";
285 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
286 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
291 $expr .= ' && ' if $expr;
292 $hint .= ' && ' if $hint;
293 for (split /[:,]/, $byzone) {
294 push @expr, "\$f11==$_";
297 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
298 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
305 $expr .= ' && ' if $expr;
306 $hint .= ' && ' if $hint;
307 for (split /[:,]/, $itu) {
308 push @expr, "\$f8==$_";
311 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
312 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
317 $expr .= ' && ' if $expr;
318 $hint .= ' && ' if $hint;
319 for (split /[:,]/, $byitu) {
320 push @expr, "\$f10==$_";
323 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : $expr[0];
324 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
331 $expr .= ' && ' if $expr;
332 $hint .= ' && ' if $hint;
333 for (split /[:,]/, $state) {
334 push @expr, "\$f12 eq '$_'";
338 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
340 $expr .= @expr > 1 ? '(\$f12 && (' . join(' || ', @expr) . '))' : "(\$f12 && $expr[0])";
342 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
347 $expr .= ' && ' if $expr;
348 $hint .= ' && ' if $hint;
349 for (split /[:,]/, $bystate) {
350 push @expr, "\$f13 eq '$_'";
354 $expr .= @expr > 1 ? '(' . join(' || ', @expr) . ')' : "$expr[0]";
356 $expr .= @expr > 1 ? '(\$f13 && (' . join(' || ', @expr) . '))' : "(\$f13 && $expr[0])";
358 $hint .= @hint > 1 ? '(' . join(' || ', @hint) . ')' : $hint[0];
363 $expr .= ' && ' if $expr;
364 $expr .= "\$f3 =~ m{QSL|VIA}i";
365 $hint .= ' && ' if $hint;
366 $hint .= "m{QSL|VIA}i";
371 $expr .= ' && ' if $expr;
372 $expr .= "\$f3 =~ m{$doiota}i";
373 $hint .= ' && ' if $hint;
374 $hint .= "m{$doiota}i";
379 $expr .= ' && ' if $expr;
380 $expr .= "\$f3 =~ m{$doqra}i";
381 $hint .= ' && ' if $hint;
382 $hint .= "m{$doqra}io";
385 dbg "expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('sh/dx');
388 my @res = Spot::search($expr, $fromday, $today, $from, $to, $hint, $dofilter ? $self : undef);
391 foreach $ref (@res) {
392 if ($self && $self->ve7cc) {
393 push @out, VE7CC::dx_spot($self, @$ref);
395 if ($self && $real) {
396 push @out, DXCommandmode::format_dx_spot($self, @$ref);
398 push @out, Spot::formatl(@$ref);