added shellregex
[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         $pre .= '*' unless $pre =~ /[\*\?\[]/o;
67         $pre = shellregex($pre);
68         $expr = "\$f1 =~ m{$pre}o";
69 } else {
70         $expr = "1";                            # match anything
71 }
72   
73 # now deal with any frequencies specified
74 if (@freq) {
75         $expr .= ($expr) ? " && (" : "(";
76         my $i;
77         for ($i = 0; $i < @freq; $i += 2) {
78                 $expr .= "(\$f0 >= $freq[$i] && \$f0 <= $freq[$i+1]) ||";
79         }
80         chop $expr;
81         chop $expr;
82         $expr .= ")";
83 }
84
85 # any info
86 if ($info) {
87         $expr .= " && " if $expr;
88         $info = shellregex($info);
89         $expr .= "\$f3 =~ m{$info}io";
90 }
91
92 # any spotter
93 if ($spotter) {
94         $expr .= " && " if $expr;
95         $spotter = shellregex($spotter);
96         $expr .= "\$f4 =~ m{$spotter}o";
97 }
98
99 #print "expr: $expr from: $from to: $to fromday: $fromday today: $today\n";
100   
101 # now do the search
102 my @res = Spot::search($expr, $fromday, $today, $from, $to);
103 my $ref;
104 my @dx;
105 foreach $ref (@res) {
106         @dx = @$ref;
107         push @out, Spot::formatl(@dx);
108 }
109
110 return (1, @out);