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