make sure it's a row of 5 and not 4
[spider.git] / cmd / show / configuration.pl
index 62beea66a7334ffb27724ecfaa8fff7ba350bf63..7c4bbf27572cc5d9931f54605b6a2531e84d746d 100644 (file)
@@ -9,35 +9,82 @@
 my ($self, $line) = @_;
 my @list = map { uc } split /\s+/, $line;           # list of callsigns of nodes
 my @out;
-my @nodes = (DXNode::get_all());
+my @nodes = sort {$a->call cmp $b->call} (Route::Node::get_all());
 my $node;
+my @l;
+my @val;
 
-push @out, "Node         Callsigns";
-foreach $node (@nodes) {
-  if (@list) {
-    next if !grep $node->call eq $_, @list;
-  }
-  my $i = 0;
-  my @l;
-  my $call = $node->call;
-  $call = "($call)" if $node->here == 0;
-  push @l, $call;
-  my $nlist = $node->list;
-  my @val = values %{$nlist};
-  foreach $call (@val) {
-    if ($i >= 5) {
-         push @out, sprintf "%-12s %-12s %-12s %-12s %-12s %-12s", @l;
-         @l = ();
-         push @l, "";
-         $i = 0;
+push @out, $self->msg('showconf');
+if ($list[0] && $list[0] =~ /^NOD/) {
+       my @ch = sort {$a->call cmp $b->call} DXChannel::get_all_nodes();
+       my $dxchan;
+       
+       foreach $dxchan (@ch) {
+               @val = sort {$a->call cmp $b->call} grep { $_->dxchan == $dxchan } @nodes;
+               @l = ();
+               my $call = $dxchan->call;
+               $call ||= '???';
+               $call = "($call)" unless $dxchan->here;
+               push @l, $call;
+               
+               foreach my $ref (@val) {
+                       if (@l >= 5) {
+                               push @out, sprintf "%-12s %-12s %-12s %-12s %-12s %-12s", @l;
+                               @l = ();
+                               push @l, "";
+                       }
+                       my $s = $ref->call;
+                       $s ||= '???';
+                       $s = sprintf "(%s)", $s unless $ref->here;
+                       push @l, $s;
+               }
+               push @l, "" while @l < 5;
+               push @out, sprintf "%-12s %-12s %-12s %-12s %-12s %-12s", @l;
+       }
+} else {
+       my $printall;
+       
+       $printall = 1 if @list && $list[0] =~ /^ALL/i;
+       
+       # build up the screen from the Node table
+       foreach $node (@nodes) {
+               unless ($printall) {
+                       if (@list) {
+                               next unless grep $node->call =~ /^$_/, @list;
+                       } else {
+                               next unless grep $node->dxcc == $_, @main::my_cc;
+                       }
+               }
+               my $call = $node->call;
+               @l = ();
+               $call ||= '???';
+               $call = "($call)" unless $node->here;
+               push @l, $call;
+               @val = sort $node->users;
+
+               if (@val == 0 && $node->usercount) {
+                       push @l, sprintf "(%d users)", $node->usercount;
+               }
+               foreach $call (@val) {
+                       if (@l >= 6) {
+                               push @out, sprintf "%-12s %-12s %-12s %-12s %-12s %-12s", @l;
+                               @l = ();
+                               push @l, "";
+                       }
+                       my $uref = Route::User::get($call);
+                       my $s = $call;
+                       if ($uref) {
+                               $s = sprintf "(%s)", $call unless $uref->here;
+                       } else {
+                               $s = "$call?";
+                       }
+                       push @l, $s;
+               }
+               push @l, "" while @l < 6;
+               push @out, sprintf "%-12s %-12s %-12s %-12s %-12s %-12s", @l;
        }
-       my $s = $call->{call};
-       $s = sprintf "(%s)", $s if $call->{here} == 0;
-       push @l, $s;
-       $i++;
-  }
-  push @out, sprintf "%-12s %-12s %-12s %-12s %-12s %-12s", @l;
 }
 
 
+
 return (1, @out);