9af8f41bcfba489681c86419da5a12e819bf964f
[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 # $Id$
8 #
9
10 # search local then perl directories
11 BEGIN {
12         # root of directory tree for this system
13         $root = "/spider"; 
14         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
15         
16         unshift @INC, "$root/perl";     # this IS the right way round!
17         unshift @INC, "$root/local";
18 }
19
20 use IO::Handle;
21 use DXUtil;
22 use Bands;
23 use Spot;
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({priv=>0,call=>'GDX'}, $myexpr);
48         shift @out;   # remove return code
49         print @out;
50         last if $expr;
51 }
52 exit(0);
53