started the command processor code.
[spider.git] / perl / client.pl
index a5caec450e67b922eeeb7b9807fa8d56d92448da..b2dcfa3a7223d4cebba279b334de3e66a7525d64 100755 (executable)
@@ -25,7 +25,6 @@ $call = "";                     # the callsign being used
 @stdoutq = ();                  # the queue of stuff to send out to the user
 $conn = 0;                      # the connection object for the cluster
 $lastbit = "";                  # the last bit of an incomplete input line
-$nl = "\r";
 
 # cease communications
 sub cease
@@ -43,6 +42,21 @@ sub sig_term
   cease(1);
 }
 
+sub setmode
+{
+  if ($mode == 1) {
+    $nl = "\r";
+  } else {
+       $nl = "\n";
+  }
+  $/ = $nl;
+  if ($mode == 0) {
+    $\ = undef;
+  } else {
+    $\ = $nl;
+  }
+}
+
 # handle incoming messages
 sub rec_socket
 {
@@ -59,7 +73,8 @@ sub rec_socket
           print $line;
        } elsif ($sort eq 'M') {
          $mode = $line;               # set new mode from cluster
-       } elsif ($sort eq 'Z') {       # end, disconnect, go, away .....
+      setmode();
+    } elsif ($sort eq 'Z') {       # end, disconnect, go, away .....
          cease(0);
     }    
   } 
@@ -103,13 +118,11 @@ sub rec_stdin
 $call = uc $ARGV[0];
 die "client.pl <call> [<mode>]\r\n" if (!$call);
 $mode = $ARGV[1] if (@ARGV > 1);
+setmode();
 
-if ($mode != 1) {
-  $nl = "\n";
-  $\ = $nl;
-}
 
-select STDOUT; $| = 1;
+#select STDOUT; $| = 1;
+STDOUT->autoflush(1);
 
 $SIG{'INT'} = \&sig_term;
 $SIG{'TERM'} = \&sig_term;