c63e063f68f6352dd170ea1bfed15a00059bac11
[spider.git] / cmd / show / dx.pl
1 #
2 # show dx (normal)
3 #
4 # $Id$
5 #
6
7 my ($self, $line) = @_;
8 my @list = split /\s+/, $line;  # split the line up
9
10 my @out;
11 my $f;
12 my $call;
13 my ($from, $to);
14 my ($fromday, $today);
15 my @freq;
16 my @ans;
17 my $pre;
18 my $spotter;
19 my $info;
20 my $expr;
21 my $hint;
22 my ($doqsl, $doiota, $doqra);
23
24 while ($f = shift @list) {              # next field
25         #  print "f: $f list: ", join(',', @list), "\n";
26         if (!$from && !$to) {
27                 ($from, $to) = $f =~ /^(\d+)-(\d+)$/o; # is it a from -> to count?
28                 next if $from && $to > $from;
29         }
30         if (!$to) {
31                 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
32                 next if $to;
33         }
34         if (lc $f eq 'on' && $list[0]) { # is it freq range?
35                 #    print "yup freq\n";
36                 my @r = split '/', lc $list[0];
37                         # print "r0: $r[0] r1: $r[1]\n";
38                 my @fr = Bands::get_freq($r[0], $r[1]);
39                 if (@fr) {                      # yup, get rid of extranous param
40                         #         print "freq: ", join(',', @fr), "\n";
41                         shift @list;
42                         push @freq, @fr;    # add these to the list
43                         next;
44                 }
45         }
46         if (lc $f eq 'day' && $list[0]) {
47                 #   print "got day\n";
48                 ($fromday, $today) = split '-', shift(@list);
49                 next;
50         }
51         if (lc $f eq 'info' && $list[0]) {
52                 #   print "got info\n";
53                 $info = shift @list;
54                 next;
55         }
56         if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
57                 #    print "got spotter\n";
58                 $spotter = uc shift @list;
59                 next;
60         }
61         if (lc $f eq 'qsl') {
62                 $doqsl = 1;
63                 next;
64         }
65         if (lc $f eq 'iota') {
66                 my ($a, $b);
67 #               $DB::single =1;
68                 
69                 if ($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                 next;
76         }
77         if (lc $f eq 'qra') {
78                 $doqra = uc shift @list if $list[0] =~ /[A-Z][A-Z]\d\d/oi;
79                 $doqra = '\b([A-Z][A-Z]\d\d|[A-Z][A-Z]\d\d[A-Z][A-Z])\b' unless $doqra;
80                 next;
81         }
82         if (!$pre) {
83                 $pre = uc $f;
84         }
85 }
86
87 # first deal with the prefix
88 if ($pre) {
89         $pre .= '*' unless $pre =~ /[\*\?\[]/o;
90         $pre = shellregex($pre);
91         $expr = "\$f1 =~ m{$pre}";
92         $pre =~ s/[\^\$]//g;
93         $hint = "m{\U$pre}";
94 }
95   
96 # now deal with any frequencies specified
97 if (@freq) {
98         $expr .= ($expr) ? " && (" : "(";
99         $hint .= ($hint) ? " && (" : "(";
100         my $i;
101         for ($i = 0; $i < @freq; $i += 2) {
102                 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
103                 my $r = Spot::ftor($freq[$i], $freq[$i+1]);
104                 $hint .= "m{$r\\.} ||" if $r;
105         }
106         chop $expr;     chop $expr;
107         chop $hint;     chop $hint;
108         $expr .= ")";
109         $hint .= ")";
110 }
111
112 # any info
113 if ($info) {
114         $expr .= " && " if $expr;
115         $info =~ s{(.)}{"\Q$1"}ge;
116         $expr .= "\$f3 =~ m{$info}i";
117         $hint .= " && " if $hint;
118         $hint .= "m{$info}i";
119 }
120
121 # any spotter
122 if ($spotter) {
123         $expr .= " && " if $expr;
124         $spotter = shellregex($spotter);
125         $expr .= "\$f4 =~ m{\U$spotter}";
126         $hint .= " && " if $hint;
127         $spotter =~ s/[\^\$]//g;
128         $hint .= "m{\U$spotter}";
129 }
130
131 # qsl requests
132 if ($doqsl) {
133         $expr .= " && " if $expr;
134         $expr .= "\$f3 =~ m{QSL|VIA}i";
135         $hint .= " && " if $hint;
136         $hint .= "m{QSL|VIA}i";
137 }
138
139 # iota requests
140 if ($doiota) {
141         $expr .= " && " if $expr;
142         $expr .= "\$f3 =~ m{$doiota}i";
143         $hint .= " && " if $hint;
144         $hint .= "m{$doiota}i";
145 }
146
147 # iota requests
148 if ($doqra) {
149         $expr .= " && " if $expr;
150         $expr .= "\$f3 =~ m{$doqra}i";
151         $hint .= " && " if $hint;
152         $hint .= "m{$doqra}io";
153 }
154
155 #print "expr: $expr from: $from to: $to fromday: $fromday today: $today\n";
156   
157 # now do the search
158 my @res = Spot::search($expr, $fromday, $today, $from, $to, $hint);
159 my $ref;
160 my @dx;
161 foreach $ref (@res) {
162         push @out, Spot::formatl(@$ref);
163 }
164
165 return (1, @out);