]> dxcluster.net Git - spider.git/blob - cmd/show/dx.pl
See Changes
[spider.git] / cmd / show / dx.pl
1 #
2 # show dx (normal)
3 #
4 #
5 #
6
7 require 5.10.1;
8 use warnings;
9
10 sub handle
11 {
12         my ($self, $line) = @_;
13
14         # disguise regexes
15         $line =~ s/\{(.*?)\}/'{'. unpack('H*', $1) . '}'/eg;
16         dbg("sh/dx disguise any regex: '$line'") if isdbg('sh/dx');
17
18         # now space out brackets and !
19         $line =~ s/([\(\!\)])/ $1 /g;
20         
21         my @list = split /\s+/, $line; # split the line up
22
23         # put back the regexes 
24         @list = map { my $l = $_; $l =~ s/\{([0-9a-fA-F]+)\}/'{' . pack('H*', $1) . '}'/eg; $l } @list;
25
26         dbg("sh/dx after regex return: '" . join(' ', @list) . "'") if isdbg('sh/dx');
27         
28         my @out;
29         my $f;
30         my $call = $self->call;
31         my $usesql = $main::dbh && $Spot::use_db_for_search;
32         my ($from, $to) = (0, 0);
33         my ($fromday, $today) = (0, 0);
34         my $exact;
35         my $real;
36         my $dofilter;
37         my $pre;
38         my $dxcc;
39
40         my @flist;
41
42         
43         dbg("sh/dx list: " . join(" ", @list)) if isdbg('sh/dx');
44
45 #       $DB::single=1;
46         
47         while (@list) { # next field
48                 $f = shift @list;
49                 dbg("sh/dx arg: $f list: '" . join(',', @list) . "'") if isdbg('sh/dx');
50                 if ($f && !$from && !$to) {
51                         ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$| || (0,0); # is it a from -> to count?
52                         dbg("sh/dx from: $from to: $to") if isdbg('sh/dx');
53                         next if $from && $to > $from;
54                 }
55                 if ($f && !$to) {
56                         ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
57                         $to ||= 0;
58                         dbg("sh/dx to: $to") if isdbg('sh/dx');
59                         next if $to;
60                 }
61                 if (lc $f eq 'day' && $list[0]) {
62                         ($fromday, $today) = split m|[-/]|, shift(@list);
63                         dbg("sh/dx got day $fromday/$today") if isdbg('sh/dx');
64                         next;
65                 }
66                 if (lc $f eq 'exact') {
67                         dbg("sh/dx exact") if isdbg('sh/dx');
68                         $exact = 1;
69                         next;
70                 }
71                 if (lc $f eq 'rt' || $f =~ /^real/i) {
72                         dbg("sh/dx real") if isdbg('sh/dx');
73                         $real = 1;
74                         next;
75                 }
76                 if (lc $f =~ /^filt/) {
77                         dbg("sh/dx run spotfilter") if isdbg('sh/dx');
78                         $dofilter = 1 if $self && $self->spotsfilter;
79                         next;
80                 }
81                 if (lc $f eq 'qsl') {
82                         dbg("sh/dx qsl") if isdbg('sh/dx');
83                         push @flist, "info {QSL|VIA}";
84                         next;
85                 }
86                 if (lc $f eq '<es>') {
87                         dbg("sh/dx <es>") if isdbg('sh/dx');
88                         push @flist, "info {<ES>}";
89                         next;
90                 }
91                 if (lc $f eq '<tr>') {
92                         dbg("sh/dx <es>") if isdbg('sh/dx');
93                         push @flist, "info {<TR>}";
94                         next;
95                 }
96                 if (lc $f eq '<ms>') {
97                         dbg("sh/dx <ms>") if isdbg('sh/dx');
98                         push @flist, "info {<ms>}";
99                         next;
100                 }
101
102                 if (lc $f eq 'iota') {
103                         my $doiota;
104                         if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)[-\s]?(\d\d?\d?)/i)) {
105                                 $a = uc $a;
106                                 $doiota = "\\b$a\[\-\ \]\?$b\\b";
107                                 shift @list;
108                         }
109                         $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[-\s]?\d?\d\d)\b' unless $doiota;
110                         push @flist, 'info', "{$doiota}";
111                         dbg("sh/dx iota info {$doiota}") if isdbg('sh/dx');
112                         next;
113                 }
114                 if (lc $f eq 'qra') {
115                         my $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/i;
116                         $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
117                         push @flist, 'info',  "{$doqra}";
118                         dbg("sh/dx qra info {$doqra}") if isdbg('sh/dx');
119                         next;
120                 }
121                 if (grep {lc $f eq $_} qw { ( or and not ) }) {
122                         push @flist, $f;
123                         dbg("sh/dx operator $f") if isdbg('sh/dx');
124                         next;
125                 }
126                 if (grep {lc $f eq $_} qw(on freq call info spotter by dxcc call_dxcc by_dxcc bydxcc origin call_itu itu call_zone zone cq bycq  byitu by_itu by_zone byzone call_state state bystate by_state ip) ) {
127                         push @flist, $f;
128                         push @flist, shift @list if @list;
129                         dbg("sh/dx function $flist[-2] $flist[-1]") if isdbg('sh/dx');
130                         next;
131                 }
132                 unless ($pre) {
133                         $pre = $f;
134                         next;
135                 }
136                 push @flist, $f;
137         }
138
139         dbg("sh/dx: flist = '" . join(',', @flist). "'") if isdbg('sh/dx');
140         
141         if ($pre) {
142                 # someone (probably me) has forgotten the 'info' keyword
143                 if ($pre =~ /^{.*}$/) {
144                         push @flist, 'info', $pre;
145                 } else {
146                         $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
147                         $pre = shellregex($pre);
148                         $pre =~ s/\.\*\$$//;
149                         $pre .= '$' if $exact;
150                         $pre =~ s/\^//;
151                         push @flist, 'call', $pre;
152                 }
153         }
154         
155     my $newline = join(' ', @flist);
156         dbg("sh/dx newline: '$newline'") if isdbg('sh/dx');
157         my ($r, $filter, $fno, $user, $expr) = $Spot::filterdef->parse($self, 'spots', $newline, 1);
158
159         return (0, "sh/dx parse error '$r' " . $filter) if $r;
160
161         $user ||= '';
162         $expr ||= '';
163         dbg("sh/dx user: $user expr: $expr from: $from to: $to fromday: $fromday today: $today") if isdbg('sh/dx');
164   
165         # now do the search
166
167         if (($self->{_nospawn} || $main::is_win == 1) || ($Spot::spotcachedays && !$expr && $from == 0 && $fromday == 0 && $today == 0)) {
168                 my @res = Spot::search($expr, $fromday, $today, $from, $to, $user, $dofilter, $self);
169                 my $ref;
170                 my @dx;
171                 foreach $ref (@res) {
172                         if ($self && $self->ve7cc) {
173                                 push @out, VE7CC::dx_spot($self, @$ref);
174                         }
175                         else {
176                                 if ($self && $real) {
177                                         push @out, DXCommandmode::format_dx_spot($self, @$ref);
178                                 }
179                                 else {
180                                         push @out, Spot::formatl($self->{width}, @$ref);
181                                 }
182                         }
183                 }
184         }
185         else {
186                 push @out, $self->spawn_cmd("sh/dx $line", \&Spot::search, 
187                                                                         args => [$expr, $fromday, $today, $from, $to, $filter, $dofilter, $self],
188                                                                         cb => sub {
189                                                                                 my ($dxchan, @res) = @_; 
190                                                                                 my $ref;
191                                                                                 my @out;
192
193                                                                                 foreach $ref (@res) {
194                                                                                         if ($self->ve7cc) {
195                                                                                                 push @out, VE7CC::dx_spot($self, @$ref);
196                                                                                         }
197                                                                                         else {
198                                                                                                 if ($real) {
199                                                                                                         push @out, DXCommandmode::format_dx_spot($self, @$ref);
200                                                                                                 }
201                                                                                                 else {
202                                                                                                         push @out, Spot::formatl($self->{width}, @$ref);
203                                                                                                 }
204                                                                                         }
205                                                                                 }
206                                                                                 push @out, $self->msg('e3', "sh/dx", "'$line'") unless @out;
207                                                                                 return @out;
208                                                                         });
209         }
210
211
212         return (1, @out);
213 }
214
215