various DXCluster->get alterations
[spider.git] / perl / DXCommandmode.pm
index ab8d9573dd4c4f8e446472cd71737f23bd889d67..4ad01392dede6d82b09df9775084a0bf197247cd 100644 (file)
@@ -18,6 +18,7 @@ use DXVars;
 use DXDebug;
 use DXM;
 use DXLog;
+use DXLogPrint;
 use CmdAlias;
 use FileHandle;
 use Carp;
@@ -51,13 +52,10 @@ sub start
   my $user = $self->{user};
   my $call = $self->{call};
   my $name = $user->{name};
-  my $info = DXCluster::cluster();
   
   $self->{name} = $name ? $name : $call;
   $self->send($self->msg('l2',$self->{name}));
   $self->send_file($main::motd) if (-e $main::motd);
-  $self->send("Cluster:$info");
-  $self->send($self->msg('pr', $call));
   $self->state('prompt');                  # a bit of room for further expansion, passwords etc
   $self->{priv} = $user->priv;
   $self->{lang} = $user->lang;
@@ -79,6 +77,11 @@ sub start
   my @pc16 = DXProt::pc16($nchan, $cuser);
   DXProt::broadcast_ak1a(@pc16);
   Log('DXCommand', "$call connected");
+
+  # send prompts and things
+  my $info = DXCluster::cluster();
+  $self->send("Cluster:$info");
+  $self->send($self->msg('pr', $call));
 }
 
 #
@@ -94,26 +97,7 @@ sub normal
        # remove leading and trailing spaces
        $cmdline =~ s/^\s*(.*)\s*$/$1/;
        
-       if ($self->{state} eq 'prompt') {
-               @ans = run_cmd($self, $cmdline) if length $cmdline;
-       
-               if ($self->{pagelth} && @ans > $self->{pagelth}) {
-                       my $i;
-                       for ($i = $self->{pagelth}; $i-- > 0; ) {
-                               my $line = shift @ans;
-                               $line =~ s/\s+$//o;            # why am having to do this? 
-                               $self->send($line);
-                       }
-                       $self->{pagedata} =  \@ans;
-                       $self->state('page');
-                       $self->send($self->msg('page', scalar @ans));
-               } else {
-                       for (@ans) {
-                               s/\s+$//o;                     # why ?????????
-                               $self->send($_);
-                       }
-               } 
-       } elsif ($self->{state} eq 'page') {
+       if ($self->{state} eq 'page') {
                my $i = $self->{pagelth};
                my $ref = $self->{pagedata};
                my $tot = @$ref;
@@ -138,7 +122,26 @@ sub normal
                } else {
                        $self->state('prompt');
                }
-       }
+       } else {
+               @ans = run_cmd($self, $cmdline) if length $cmdline;
+       
+               if ($self->{pagelth} && @ans > $self->{pagelth}) {
+                       my $i;
+                       for ($i = $self->{pagelth}; $i-- > 0; ) {
+                               my $line = shift @ans;
+                               $line =~ s/\s+$//o;            # why am having to do this? 
+                               $self->send($line);
+                       }
+                       $self->{pagedata} =  \@ans;
+                       $self->state('page');
+                       $self->send($self->msg('page', scalar @ans));
+               } else {
+                       for (@ans) {
+                               s/\s+$//o;                     # why ?????????
+                               $self->send($_);
+                       }
+               } 
+       } 
        
        # send a prompt only if we are in a prompt state
        $self->prompt() if $self->{state} =~ /^prompt/o;
@@ -151,73 +154,66 @@ sub normal
 
 sub run_cmd
 {
-  my $self = shift;
-  my $user = $self->{user};
-  my $call = $self->{call};
-  my $cmdline = shift;
-  my @ans;
-
-  # are we in stored state?
-  if ($self->{func}) {
-    my $c = qq{ \@ans = $self->{func}(\$self, \$cmdline) };
-    dbg('eval', "stored func cmd = $c\n");
-    eval  $c;
-    if ($@) {
-      return (1, "Syserr: Eval err $errstr on stored func $self->{func}");
-    }
-  } else {
-
-    # special case only \n input => " "
-#    if ($cmdline eq " ") {
-#        $self->prompt();
-#        return;
-#      }
+       my $self = shift;
+       my $user = $self->{user};
+       my $call = $self->{call};
+       my $cmdline = shift;
+       my @ans;
        
-    # strip out //
-    $cmdline =~ s|//|/|og;
-  
-    # split the command line up into parts, the first part is the command
-    my ($cmd, $args) = $cmdline =~ /^([\w\/]+)\s*(.*)/o;
-
-    if ($cmd) {
-    
-         my ($path, $fcmd);
-         
-         # alias it if possible
-         my $acmd = CmdAlias::get_cmd($cmd);
-         if ($acmd) {
-           ($cmd, $args) = "$acmd $args" =~ /^([\w\/]+)\s*(.*)/o;
-         }
-   
-      # first expand out the entry to a command
-         ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
-         ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd;
-
-      my $package = find_cmd_name($path, $fcmd);
-         @ans = (0) if !$package ;
-
-      if ($package) {
-           my $c = qq{ \@ans = $package(\$self, \$args) };
-           dbg('eval', "cluster cmd = $c\n");
-           eval  $c;
-           if ($@) {
-                 @ans = (0, "Syserr: Eval err cached $package\n$@");
-        }
-         }
+       if ($self->{func}) {
+               my $c = qq{ \@ans = $self->{func}(\$self, \$cmdline) };
+               dbg('eval', "stored func cmd = $c\n");
+               eval  $c;
+               if ($@) {
+                       return (1, "Syserr: Eval err $errstr on stored func $self->{func}");
+               }
+       } else {
+               
+               # strip out //
+               $cmdline =~ s|//|/|og;
+               
+               # split the command line up into parts, the first part is the command
+               my ($cmd, $args) = $cmdline =~ /^([\w\/]+)\s*(.*)/o;
+               
+               if ($cmd) {
+                       
+                       my ($path, $fcmd);
+                       
+                       # alias it if possible
+                       my $acmd = CmdAlias::get_cmd($cmd);
+                       if ($acmd) {
+                               ($cmd, $args) = "$acmd $args" =~ /^([\w\/]+)\s*(.*)/o;
+                       }
+                       
+                       # first expand out the entry to a command
+                       ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
+                       ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd;
+                       
+                       my $package = find_cmd_name($path, $fcmd);
+                       @ans = (0) if !$package ;
+                       
+                       if ($package) {
+                               my $c = qq{ \@ans = $package(\$self, \$args) };
+                               dbg('eval', "cluster cmd = $c\n");
+                               eval  $c;
+                               if ($@) {
+                                       @ans = (0, "Syserr: Eval err cached $package\n$@");
+                               }
+                       }
+               }
        }
-  }
-       
-  if ($ans[0]) {
-    shift @ans;
-  } else {
-    shift @ans;
-       if (@ans > 0) {
-               unshift @ans, $self->msg('e2');
+
+       if ($ans[0]) {
+               shift @ans;
        } else {
-               @ans = $self->msg('e1');
+               shift @ans;
+               if (@ans > 0) {
+                       unshift @ans, $self->msg('e2');
+               } else {
+                       @ans = $self->msg('e1');
+               }
        }
-  }
-  return (@ans);
+       return (@ans);
 }
 
 #