fix sh/dx by call and missing files
[spider.git] / cmd / show / dx.pl
1 #
2 # show dx (normal)
3 #
4 #
5 #
6
7 require 5.10.1;
8
9 sub handle
10 {
11         my ($self, $line) = @_;
12         my @list = split /\s+/, $line; # split the line up
13
14         my @out;
15         my $f;
16         my $call = $self->call;
17         my $usesql = $main::dbh && $Spot::use_db_for_search;
18         my ($from, $to);
19         my ($fromday, $today);
20         my $exact;
21         my $real;
22         my $user;
23         my $expr;
24         my $dofilter;
25         my $pre;
26         my $dxcc;
27
28         my @flist;
29
30         while ($f = shift @list) {      # next field
31                 dbg "sh/dx arg: $f list: " . join(',', @list) if isdbg('sh/dx');
32                 if (!$from && !$to) {
33                         ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$|; # is it a from -> to count?
34                         dbg("sh/dx from: $from to: $to") if isdbg('sh/dx');
35                         next if $from && $to > $from;
36                 }
37                 if (!$to) {
38                         ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
39                         dbg("sh/dx to: $to") if isdbg('sh/dx');
40                         next if $to;
41                 }
42                 if (lc $f eq 'day' && $list[0]) {
43                         ($fromday, $today) = split m|[-/]|, shift(@list);
44                         dbg "sh/dx got day $fromday/$today" if isdbg('sh/dx');
45                         next;
46                 }
47                 if (lc $f eq 'exact') {
48                         dbg("sh/dx exact") if isdbg('sh/dx');
49                         $exact = 1;
50                         next;
51                 }
52                 if (lc $f eq 'rt' || $f =~ /^real/i) {
53                         dbg("sh/dx real") if isdbg('sh/dx');
54                         $real = 1;
55                         next;
56                 }
57                 if (lc $f =~ /^filt/) {
58                         dbg("sh/dx run spotfilter") if isdbg('sh/dx');
59                         $dofilter = 1 if $self && $self->spotsfilter;
60                         next;
61                 }
62                 if (lc $f eq 'qsl') {
63                         dbg("sh/dx qsl") if isdbg('sh/dx');
64                         push @flist, "info {QSL|VIA}";
65                         next;
66                 }
67                 if (lc $f eq 'iota') {
68                         my $doiota;
69                         if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)-?(\d?\d\d)/oi)) {
70                                 $a = uc $a;
71                                 $doiota = "\\b$a\[\-\ \]\?$b\\b";
72                                 shift @list;
73                         }
74                         $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[- ]?\d?\d\d)\b' unless $doiota;
75                         push @flist, "info {$doiota}";
76                         dbg("sh/dx iota") if isdbg('sh/dx');
77                         next;
78                 }
79                 if (lc $f eq 'qra') {
80                         my $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/oi;
81                         $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
82                         push @flist, "info {$doqra}";
83                         dbg("sh/dx qra") if isdbg('sh/dx');
84                         next;
85                 }
86                 if (grep {lc $f eq $_} qw(zone byzone by_zone itu byitu by_itu state bystate by_state info on spotter by) ) {
87                         $f =~ s/^by(\w)/by_$1/;
88                         push @flist, $f;
89                         push @flist, shift @list if @list;
90                         next;
91                 }
92                 unless ($pre) {
93                         $pre = $f;
94                         next;
95                 }
96                 push @flist, $f;
97         }
98
99         
100         if ($pre) {
101                 $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
102                 $pre = shellregex($pre);
103                 if ($usesql) {
104                         $pre =~ s/\.\*/%/g;
105                 } else {
106                         $pre =~ s/\.\*\$$//;
107                 }
108                 $pre .= '$' if $exact;
109                 $pre =~ s/\^//;
110                 
111                 push @flist, 'call', $pre;
112         }
113         
114     my $newline = join(' ', @flist);
115         dbg("sh/dx newline: $newline") if isdbg('sh/dx');
116         my ($r, $filter, $fno, $user, $expr) = $Spot::filterdef->parse($self, 'spots', $newline, 1);
117
118         return (0, "sh/dx parse error '$r' " . $filter) if $r;
119         
120         dbg "sh/dx user: $user expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('sh/dx');
121   
122         # now do the search
123
124         if ($self->{_nospawn}) {
125                 my @res = Spot::search($expr, $fromday, $today, $from, $to, $user, $dofilter ? $self : undef);
126                 my $ref;
127                 my @dx;
128                 foreach $ref (@res) {
129                         if ($self && $self->ve7cc) {
130                                 push @out, VE7CC::dx_spot($self, @$ref);
131                         }
132                         else {
133                                 if ($self && $real) {
134                                         push @out, DXCommandmode::format_dx_spot($self, @$ref);
135                                 }
136                                 else {
137                                         push @out, Spot::formatl(@$ref);
138                                 }
139                         }
140                 }
141         }
142         else {
143                 push @out, $self->spawn_cmd("sh/dx $line", \&Spot::search, 
144                                                                         args => [$expr, $fromday, $today, $from, $to, $filter, $dofilter ? $self : undef],
145                                                                         cb => sub {
146                                                                                 my ($dxchan, @res) = @_; 
147                                                                                 my $ref;
148                                                                                 my @out;
149
150                                                                                 foreach $ref (@res) {
151                                                                                         if ($self->ve7cc) {
152                                                                                                 push @out, VE7CC::dx_spot($self, @$ref);
153                                                                                         }
154                                                                                         else {
155                                                                                                 if ($real) {
156                                                                                                         push @out, DXCommandmode::format_dx_spot($self, @$ref);
157                                                                                                 }
158                                                                                                 else {
159                                                                                                         push @out, Spot::formatl(@$ref);
160                                                                                                 }
161                                                                                         }
162                                                                                 }
163                                                                                 push @out, $self->msg('e3', "sh/dx", "'$line'") unless @out;
164                                                                                 return @out;
165                                                                         });
166         }
167
168
169         return (1, @out);
170 }
171
172