add import_cmd and other tidyups
[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         sub main::mkver {}
20 }
21
22 use IO::Handle;
23 use DXUtil;
24 use Bands;
25 use Spot;
26
27 $dxdir = "/spider/cmd/show";
28 $dxcmd = "dx.pl";
29 $s = readfilestr($dxdir, $dxcmd);
30 $dxproc = eval "sub { $s }";
31 die $@ if $@;
32
33 STDOUT->autoflush(1);
34 Spot::init();
35 Bands::load();
36
37 $expr = join ' ', @ARGV if @ARGV;
38
39 for (;;) {
40         if ($expr) {
41                 $myexpr = $expr;
42         } else {
43                 print "show/dx: ";
44                 $myexpr = <STDIN>;
45                 last unless defined $myexpr;
46                 chomp $myexpr;
47                 last if $myexpr =~ /^q$/i;
48         }
49         my @out = map {"$_\n"} &$dxproc({priv=>0,call=>'GDX'}, $myexpr);
50         shift @out;   # remove return code
51         print @out;
52         last if $expr;
53 }
54 exit(0);
55