home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c / qk3msc.pas < prev    next >
Pascal/Delphi Source File  |  2020-01-01  |  5KB  |  122 lines

  1. Unit MiscComm ;
  2. Interface
  3.   Uses Dos,          (* Standard Turbo Pascal Unit *)
  4.        KGlobals,     (* Kermit Globals *)
  5.        ModemPro,
  6.        Packets,
  7.        Setshow,
  8.        Vt100 ;
  9.      Procedure Logit  (filename : String);
  10.      Procedure Takeit  (filename : String);
  11.      Procedure QuitExit  (QuitOption : String);
  12. Implementation
  13. (* ================================================================== *)
  14. (* LOGIT - creates a Log file to record all incoming data from the    *)
  15. (*       remote line.                                                 *)
  16. (*           The file name is specified in the Parameter .            *)
  17. (*               if no parameter specified logging is turned off.     *)
  18. (* ================================================================== *)
  19. Procedure Logit  (filename : String);
  20. Begin (* Logit Procedure *)
  21. If (length(filename) < 3) or (filename='OFF') then
  22.     Begin (* Turn off Logging *)
  23.     Logging := false ;
  24.     {$I-} Close (Logfile); {$I+}
  25.     If IoResult = 0 then
  26.          Writeln (' Logging is turned off ');
  27.     End   (* Turn off Logging *)
  28.                         else
  29.     Begin (* Turn on Logging *)
  30.     If Logging then Close (Logfile);
  31.     Logging := True ;
  32.     Assign(Logfile,Filename);
  33.     {$I-} Rewrite(Logfile); {$I+}
  34.     If IoResult = 0 then
  35.         Writeln(' Logging data to file ',filename)
  36.                     else
  37.         Writeln(' Unable to open file',filename,' for Logging') ;
  38.     LogName := filename ;
  39.     End ; (* Turn on Logging *)
  40. End ; (* Logit Procedure)
  41.  
  42. (* ================================================================== *)
  43. (* Takeit - read commands from a file and executes them.              *)
  44. (*          if no file specified or file is not there if does nothing *)
  45. (* ================================================================== *)
  46. Procedure Takeit  (filename : String);
  47. Var FileInfo : SearchRec ;
  48. Begin (* Takeit Procedure *)
  49. If length(filename) > 1 then
  50.     FindFirst(filename,anyfile,FileInfo) ;
  51.      If DosError = 0 then
  52.          Begin (* Active file *)
  53.          Writeln ('Activating Command file ',filename);
  54.          TakeActive := true ;
  55.          Assign(Commandfile,filename);
  56.          Reset(Commandfile);
  57.          End  (* Active file *)
  58.                                 else
  59.          Writeln('No file ',filename) ;
  60. End ; (* Takeit Procedure)
  61.  
  62. (* ================================================================== *)
  63. (* QuitExit    - Terminates the KERMIT.                               *)
  64. (*             the QuitOptions are:                                   *)
  65. (*                  LOCAL,REMOTE,DISCONnect,ALL                       *)
  66. (*               if LOCAL or noparms only the local kermit terminates.*)
  67. (*               if REMOTE then  only the remote kermit terminates.   *)
  68. (*               if DISCONect then the remote kermit is terminated    *)
  69. (*                       and the remote is logged off.                *)
  70. (*               if ALL  then both kermits are terminated and remote  *)
  71. (*                        is logged off.                              *)
  72. (*                                                                    *)
  73. (* ================================================================== *)
  74. Procedure QuitExit  (QuitOption : String);
  75. Const
  76.     QuitTable : String[35] = '       LOCAL  REMOTE DISCON ALL    ' ;
  77. Type QuitType = (zero,local,remote,discon,all);
  78. Var
  79.     Qix : integer  ;
  80. Begin (* QuitExit Procedure *)
  81. QuitOption := Uppercase(Concat(' ',QuitOption));
  82. Qix := Pos(QuitOption,QuitTable) div 7 ;
  83. Case QuitType(Qix) of    (* Quit Type *)
  84.  zero,
  85.  local:  Running := false ;
  86.  remote :
  87.          Begin (* terminate remote kermit *)
  88.         (* Send a Finish packet *)
  89.          OutDataCount := 1 ;
  90.          OutSeq := OutSeq + 1 ;
  91.          If OutSeq > 64 then OutSeq := 0 ;
  92.          OutPacketType := Ord('G');
  93.          SendData[1] := Ord('F');
  94.          WaitXon := False ;
  95.          SendPacket ;
  96.          If RecvPacket and (InPacketType = Ord('Y')) then
  97.                Writeln (' Remote Kermit terminated. ')
  98.                                                      else
  99.                Writeln(' Unable to terminate Remote Kermit. ');
  100.          End ; (* terminate remote kermit *)
  101. discon,
  102. all:
  103.          Begin (* logoff Remote  *)
  104.          (* Send a Logoff packet *)
  105.          OutDataCount := 1 ;
  106.          OutSeq := OutSeq + 1 ;
  107.          If OutSeq > 64 then OutSeq := 0 ;
  108.          OutPacketType := Ord('G');
  109.          SendData[1] := Ord('L');
  110.          WaitXon := false ;
  111.          SendPacket ;
  112.          If RecvPacket and (InPacketType = Ord('Y')) then
  113.               Writeln (' Remote host is logging off ')
  114.                                                      else
  115.               Writeln(' Remote host unable to execute a log off ');
  116.          If (Qix = Ord(all))  then Running := False ;
  117.          End;  (* Logoff Remote *)
  118.     End ; (* Case Quit Type *)
  119. End; (* QuitExit Procedure *)
  120. Begin (* MiscComm Unit *)
  121. End.  (* MiscComm Unit *)
  122.