c98699969ad095cc4518eab077ee5bf936009821
[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
22 while ($f = shift @list) {              # next field
23         #  print "f: $f list: ", join(',', @list), "\n";
24         if (!$from && !$to) {
25                 ($from, $to) = $f =~ /^(\d+)-(\d+)$/o; # is it a from -> to count?
26                 next if $from && $to > $from;
27         }
28         if (!$to) {
29                 ($to) = $f =~ /^(\d+)$/o if !$to; # is it a to count?
30                 next if $to;
31         }
32         if (lc $f eq 'on' && $list[0]) { # is it freq range?
33                 #    print "yup freq\n";
34                 my @r = split '/', $list[0];
35                         # print "r0: $r[0] r1: $r[1]\n";
36                 my @fr = Bands::get_freq($r[0], $r[1]);
37                 if (@fr) {                      # yup, get rid of extranous param
38                         #         print "freq: ", join(',', @fr), "\n";
39                         shift @list;
40                         push @freq, @fr;    # add these to the list
41                         next;
42                 }
43         }
44         if (lc $f eq 'day' && $list[0]) {
45                 #   print "got day\n";
46                 ($fromday, $today) = split '-', shift(@list);
47                 next;
48         }
49         if (lc $f eq 'info' && $list[0]) {
50                 #   print "got info\n";
51                 $info = shift @list;
52                 next;
53         }
54         if ((lc $f eq 'spotter' || lc $f eq 'by') && $list[0]) {
55                 #    print "got spotter\n";
56                 $spotter = uc shift @list;
57                 next;
58         }
59         if (!$pre) {
60                 $pre = uc $f;
61         }
62 }
63
64 # first deal with the prefix
65 if ($pre) {
66         $expr = "\$f1 =~ /";
67         $pre =~ s|/|\\/|;                       # change the slashes to \/ 
68         if ($pre =~ /^\*/o) {
69                 $pre =~ s/^\*//;;
70                 $expr .= "$pre\$/o";
71         } else {
72                 $expr .= "^$pre/o";
73         }
74 } else {
75         $expr = "1";                            # match anything
76 }
77   
78 # now deal with any frequencies specified
79 if (@freq) {
80         $expr .= ($expr) ? " && (" : "(";
81         my $i;
82         for ($i = 0; $i < @freq; $i += 2) {
83                 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
84         }
85         chop $expr;
86         chop $expr;
87         $expr .= ")";
88 }
89
90 # any info
91 if ($info) {
92         $expr .= " && " if $expr;
93         $info =~ s|/|\\/|;
94         $expr .= "\$f3 =~ /$info/io";
95 }
96
97 # any spotter
98 if ($spotter) {
99         $expr .= " && " if $expr;
100         $spotter =~ s|/|\\/|;
101         $expr .= "\$f4 =~ /$spotter/o";
102 }
103
104 #print "expr: $expr from: $from to: $to fromday: $fromday today: $today\n";
105   
106 # now do the search
107 my @res = Spot::search($expr, $fromday, $today, $from, $to);
108 my $ref;
109 my @dx;
110 foreach $ref (@res) {
111         @dx = @$ref;
112         push @out, Spot::formatl(@dx);
113 }
114
115 return (1, @out);