put dx.pl into an explicit handle sub
[spider.git] / perl / showdx
1 #!/usr/bin/perl
2 #
3 # Implement an external "show/dx" command
4 #
5 # Copyright (c) 1998-2000 Dirk Koopman G1TLH
6 #
7
8
9 # search local then perl directories
10 BEGIN {
11         # root of directory tree for this system
12         $root = "/spider"; 
13         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
14         
15         unshift @INC, "$root/perl";     # this IS the right way round!
16         unshift @INC, "$root/local";
17 }
18
19 use IO::Handle;
20 use DXUtil;
21 use Bands;
22 use Spot;
23 use VE7CC;
24
25 $dxdir = "/spider/cmd/show";
26 $dxcmd = "dx.pl";
27 $s = readfilestr($dxdir, $dxcmd);
28 $dxproc = eval "sub { $s }";
29 die $@ if $@;
30
31 STDOUT->autoflush(1);
32 Spot::init();
33 Bands::load();
34
35 $expr = join ' ', @ARGV if @ARGV;
36
37 for (;;) {
38         if ($expr) {
39                 $myexpr = $expr;
40         } else {
41                 print "show/dx: ";
42                 $myexpr = <STDIN>;
43                 last unless defined $myexpr;
44                 chomp $myexpr;
45                 last if $myexpr =~ /^q$/i;
46         }
47         my @out = map {"$_\n"} &$dxproc(undef, $myexpr);
48         shift @out;   # remove return code
49         print @out;
50         last if $expr;
51 }
52 exit(0);
53