]> www.dxcluster.org Git - spider.git/blob - cmd/show/dx.pl
94fbb7d84f97dfe4eaab5db3de78072fc86415d9
[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         while ($f = shift @list) {      # next field
46                 dbg "sh/dx arg: $f list: " . join(',', @list) if isdbg('sh/dx');
47                 if ($f && !$from && !$to) {
48                         ($from, $to) = $f =~ m|^(\d+)[-/](\d+)$| || (0,0); # is it a from -> to count?
49                         dbg("sh/dx from: $from to: $to") if isdbg('sh/dx');
50                         next if $from && $to > $from;
51                 }
52                 if ($f && !$to) {
53                         ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
54                         $to ||= 0;
55                         dbg("sh/dx to: $to") if isdbg('sh/dx');
56                         next if $to;
57                 }
58                 if (lc $f eq 'day' && $list[0]) {
59                         ($fromday, $today) = split m|[-/]|, shift(@list);
60                         dbg "sh/dx got day $fromday/$today" if isdbg('sh/dx');
61                         next;
62                 }
63                 if (lc $f eq 'exact') {
64                         dbg("sh/dx exact") if isdbg('sh/dx');
65                         $exact = 1;
66                         next;
67                 }
68                 if (lc $f eq 'rt' || $f =~ /^real/i) {
69                         dbg("sh/dx real") if isdbg('sh/dx');
70                         $real = 1;
71                         next;
72                 }
73                 if (lc $f =~ /^filt/) {
74                         dbg("sh/dx run spotfilter") if isdbg('sh/dx');
75                         $dofilter = 1 if $self && $self->spotsfilter;
76                         next;
77                 }
78                 if (lc $f eq 'qsl') {
79                         dbg("sh/dx qsl") if isdbg('sh/dx');
80                         push @flist, "info {QSL|VIA}";
81                         next;
82                 }
83                 if (lc $f eq '<es>') {
84                         dbg("sh/dx <es>") if isdbg('sh/dx');
85                         push @flist, "info {<ES>}";
86                         next;
87                 }
88                 if (lc $f eq '<tr>') {
89                         dbg("sh/dx <es>") if isdbg('sh/dx');
90                         push @flist, "info {<TR>}";
91                         next;
92                 }
93                 if (lc $f eq '<ms>') {
94                         dbg("sh/dx <ms>") if isdbg('sh/dx');
95                         push @flist, "info {<ms>}";
96                         next;
97                 }
98
99                 if (lc $f eq 'iota') {
100                         my $doiota;
101                         if (@list && $list[0] && (($a, $b) = $list[0] =~ /(AF|AN|NA|SA|EU|AS|OC)[-\s]?(\d\d?\d?)/i)) {
102                                 $a = uc $a;
103                                 $doiota = "\\b$a\[\-\ \]\?$b\\b";
104                                 shift @list;
105                         }
106                         $doiota = '\b(IOTA|(AF|AN|NA|SA|EU|AS|OC)[-\s]?\d?\d\d)\b' unless $doiota;
107                         push @flist, 'info', "{$doiota}";
108                         dbg("sh/dx iota info {$doiota}") if isdbg('sh/dx');
109                         next;
110                 }
111                 if (lc $f eq 'qra') {
112                         my $doqra = uc shift @list if @list && $list[0] =~ /[A-Z][A-Z]\d\d/i;
113                         $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
114                         push @flist, 'info',  "{$doqra}";
115                         dbg("sh/dx qra info {$doqra}") if isdbg('sh/dx');
116                         next;
117                 }
118                 if (grep {lc $f eq $_} qw { ( or and not ) }) {
119                         push @flist, $f;
120                         dbg("sh/dx operator $f") if isdbg('sh/dx');
121                         next;
122                 }
123                 if (grep {lc $f eq $_} qw(on freq call info spotter by call_dxcc by_dxcc bydxcc origin call_itu itu call_zone zone  byitu by_itu by_zone byzone call_state state bystate by_state ip) ) {
124                         push @flist, $f;
125                         push @flist, shift @list if @list;
126                         dbg("sh/dx function $flist[-2] $flist[-1]") if isdbg('sh/dx');
127                         next;
128                 }
129                 unless ($pre) {
130                         $pre = $f;
131                         next;
132                 }
133                 push @flist, $f;
134         }
135
136         
137         if ($pre) {
138                 # someone (probably me) has forgotten the 'info' keyword
139                 if ($pre =~ /^{.*}$/) {
140                         push @flist, 'info', $pre;
141                 } else {
142                         $pre .= '*' unless $pre =~ /[\*\?\[]$/o;
143                         $pre = shellregex($pre);
144                         if ($usesql) {
145                                 $pre =~ s/\.\*/%/g;
146                         } else {
147                                 $pre =~ s/\.\*\$$//;
148                         }
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         dbg "sh/dx user: $user expr: $expr from: $from to: $to fromday: $fromday today: $today" if isdbg('sh/dx');
163   
164         # now do the search
165
166         if ($self->{_nospawn}) {
167                 my @res = Spot::search($expr, $fromday, $today, $from, $to, $user, $dofilter ? $self : undef);
168                 my $ref;
169                 my @dx;
170                 foreach $ref (@res) {
171                         if ($self && $self->ve7cc) {
172                                 push @out, VE7CC::dx_spot($self, @$ref);
173                         }
174                         else {
175                                 if ($self && $real) {
176                                         push @out, DXCommandmode::format_dx_spot($self, @$ref);
177                                 }
178                                 else {
179                                         push @out, Spot::formatl(@$ref);
180                                 }
181                         }
182                 }
183         }
184         else {
185                 push @out, $self->spawn_cmd("sh/dx $line", \&Spot::search, 
186                                                                         args => [$expr, $fromday, $today, $from, $to, $filter, $dofilter ? $self : undef],
187                                                                         cb => sub {
188                                                                                 my ($dxchan, @res) = @_; 
189                                                                                 my $ref;
190                                                                                 my @out;
191
192                                                                                 foreach $ref (@res) {
193                                                                                         if ($self->ve7cc) {
194                                                                                                 push @out, VE7CC::dx_spot($self, @$ref);
195                                                                                         }
196                                                                                         else {
197                                                                                                 if ($real) {
198                                                                                                         push @out, DXCommandmode::format_dx_spot($self, @$ref);
199                                                                                                 }
200                                                                                                 else {
201                                                                                                         push @out, Spot::formatl(@$ref);
202                                                                                                 }
203                                                                                         }
204                                                                                 }
205                                                                                 push @out, $self->msg('e3', "sh/dx", "'$line'") unless @out;
206                                                                                 return @out;
207                                                                         });
208         }
209
210
211         return (1, @out);
212 }
213
214