home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / TPKERMIT / KERMIT.PAS < prev    next >
Pascal/Delphi Source File  |  1987-03-25  |  18KB  |  395 lines

  1. (* +FILE+ KERMIT.PASMSCPM *)
  2. {$C-}
  3. Program Kermit ;
  4. (* ***************************************************************** *)
  5. (*                                                                   *)
  6. (* Author - Victor Lee, Queen's University, Kingston, Ontario        *)
  7. (*          Comments and problem can be sent to VIC@QUCDN.BITNET     *)
  8. (*          Phone - 613-547-6115                                     *)
  9. (*          Contributions from Jeff Duncan                           *)
  10. (* Date -   1985 January                                             *)
  11. (*      -   1985 May  1    first official release                    *)
  12. (*      -        June 28   Add run command , fix logging             *)
  13. (*      -        July  5   Fix Asfile bug.                           *)
  14. (*               July 10   Fix Binary Transfer bug (no repeatchar)   *)
  15. (*               July 17   change write(ch) to ritechar to fix bug   *)
  16. (*                         with keyboard input.                      *)
  17. (*               July 23   Add I/O error handling,fix initparm bug,  *)
  18. (*                         restrict source to 80 columns.            *)
  19. (*               Aug 7     Use $C- option,  Eliminate the use of     *)
  20. (*                         ritechar procedure. Add VT100 terminal    *)
  21. (*                         simulation code                           *)
  22. (*               Sept 9    Minor cleanup of code. Retry for reading  *)
  23. (*                         Keytable file.                            *)
  24. (*               Sept 18   Set version number.                       *)
  25. (*               Sept 30   Check seqnum on recieved data packets.    *)
  26. (*               Nov. 01   Reenable auto remote command.             *)
  27. (*               Dec. 16   Insert Mode ( FatCursor indicator )       *)
  28. (*               Dec. 20   Sub Directory commands and features       *)
  29. (*               Dec. 23   Audio Toggle .                            *)
  30. (* Date -   1986 Jan.  7   Allow Packet Parameter specifications.    *)
  31. (*               Jan. 14   Apl character set selection.              *)
  32. (*               Jan. 20   8bit quote and repeat char. bug fixed.    *)
  33. (*               Jan. 22   Remove some of the system dependant code  *)
  34. (*                         from KERMIT.PAS.                          *)
  35. (*               Jan. 29   Break key - to us ALT F10 .               *)
  36. (*                                                                   *)
  37. (* ***************************************************************** *)
  38. (*  Utility Procedures                                               *)
  39. (*       HEX                                                         *)
  40. (*       UpperCase                                                   *)
  41. (*       GETTOKEN                                                    *)
  42. (*       NewAsFile                                                   *)
  43. (* SysFunc Procedures  - These are operating system dependent        *)
  44. (*       KeyChar                                                     *)
  45. (*       CursorPosition                                              *)
  46. (*       CursorUp,CursorDown,CursorRight,CursorLeft                  *)
  47. (*       LocalScreen,RemoteScreen                                    *)
  48. (*       FirstFile,Nextfile                                          *)
  49. (*       DefaultDrive                                                *)
  50. (*       SetDefaultDrive                                             *)
  51. (*       DisplayDiskStatus                                           *)
  52. (*       ExecFile                                                    *)
  53. (* Modem Procedures   -   These are Machine dependent procedures     *)
  54. (*       InitModem                                                   *)
  55. (*       SetModem                                                    *)
  56. (*       ResetModem                                                  *)
  57. (*       DialModem                                                   *)
  58. (*       RecvChar                                                    *)
  59. (*       SendChar                                                    *)
  60. (*                                                                   *)
  61. (* Define Word Procedures                                            *)
  62. (*       AssignDefWord                                               *)
  63. (*       DisplayDefWords                                             *)
  64. (*       CheckDefWords                                               *)
  65. (*       WriteDefWord                                                *)
  66. (*       DEFINEWORD                                                  *)
  67. (*       LoadDefWords                                                *)
  68. (*       SaveDefWords                                                *)
  69. (* Read Character Procedure                                          *)
  70. (*       ReadChar                                                    *)
  71. (* Packet Procedures                                                 *)
  72. (*       SENDPACKET                                                  *)
  73. (*       RECVPACKET                                                  *)
  74. (*       RESENDIT                                                    *)
  75. (*       SENDACK                                                     *)
  76. (*                                                                   *)
  77. (*  ------------------ COMMAND  PROCEDURES  --------------------     *)
  78. (*                                                                   *)
  79. (*       SENDFILE  - Sends a file to another computer.               *)
  80. (*       RECVFILE  - Receive a file from another computer.           *)
  81. (*       CONNECTION- Simulate a dumb terminal.                       *)
  82. (* SetShow Procedures                                                *)
  83. (*       SHOWIT    - Display the options .                           *)
  84. (*       SETIT     - Set the options.                                *)
  85. (*       DisplayCommands - Displays the commands available.          *)
  86. (*                                                                   *)
  87. (* Local Procedures                                                  *)
  88. (*      DisplayDir  - Display directory.                             *)
  89. (*      EraseFiles  - Erase files.                                   *)
  90. (*      RenameFiles - Rename files.                                  *)
  91. (*      DisplayFile - Display file (TYPE file ).                     *)
  92. (*     (RunFile     - Run a program  ( See SYSFUNC procedures ) )    *)
  93. (*                                                                   *)
  94. (*       REMOTEPRO  - Remote request procedures                      *)
  95. (* Misccomm Procedures                                               *)
  96. (*       Logit      - log the session to a file.                     *)
  97. (*       Takeit     - take commands from a file.                     *)
  98. (*       QuitExit   - terminate kermits and log out.                 *)
  99. (*                                                                   *)
  100. (* ***************************************************************** *)
  101. CONST
  102.     VERSION   = '2.5 ' ;  (* <<<<<<<<<<<< V E R S I O N <<<<<<<<<<< *)
  103.     Date      = '1986 January 29  ' ;
  104.  
  105.     LocalChar = $1C ;   (* control backslash       ^\  *)
  106.     BreakChar = $1D ;   (* control right bracket   ^]  *)
  107.  
  108.     SOH  = $01 ;        (* Start of Header *)
  109.     EOT  = $04 ;        (* End of transmission *)
  110.     BS   = $08 ;        (* Back Space *)
  111.     Xon  = $11 ;
  112.     Xoff = $13 ;
  113.     ESC  = $1B ;
  114.     DEL  = $7F ;
  115.  
  116. TYPE
  117.     layouts = (one,two,three,four,five,six,seven,eight,nine,ten) ;
  118.     Commandindex = (
  119.                   zero,
  120.                   connect,
  121.                   send,
  122.                   receive,
  123.                   setparm,
  124.                   status,
  125.                   directory,
  126.                   erase,
  127.                   rename,
  128.                   typefile,
  129.                   runfile,
  130.                   remote,
  131.                   log,
  132.                   take,
  133.                   define,
  134.                   help,
  135.                   mkdir,
  136.                   rmdir,
  137.                   chdir,
  138.                   audio,
  139.                   parms,
  140.                   quit,
  141.                   null );
  142.     comstring = string[80] ;
  143.     Wstring   = string[10] ;
  144.  
  145.     STATETYPE = (S,SF,SD,SZ,SB,C,A,R,RF,RD) ;
  146.     ABORTTYPE = (NOSOH,BADSF,NOT_S,NOT_SFBZ,NOT_DZ);
  147.     BREAKTYPE = (NOBREAK,BX,BZ,BC,BE);
  148.     PACKET = PACKED ARRAY[1..255] OF BYTE ;
  149.     ParityType = (OddP,EvenP,MarkP,NoneP);
  150.     DefPointer = ^DefineRec ;
  151.     DefineRec = Record
  152.                 Link : DefPointer ;
  153.                 DefWord : Wstring ;
  154.                 DefString : comstring ;
  155.                 End ;
  156.  
  157. VAR
  158.     STATE          : STATETYPE ;
  159.     ABORT          : ABORTTYPE ;
  160.     BREAKSTATE     : BREAKTYPE ;
  161.     RetryCount     : Integer ;
  162.  
  163.     (* Packet variables *)                           (* format   *)
  164.     (* Receive       Send     *)                     (* SOH      *)
  165.        InCount,      OutCount      : BYTE ;          (* COUNT    *)
  166.        INSEQ,        OUTSEQ        : BYTE ;          (* SEQNUM   *)
  167.        INPACKETTYPE, OUTPACKETTYPE : BYTE ;          (* TYPE     *)
  168.        RecvData,     SendData      : PACKET ;        (* DATA...  *)
  169.        CHECKSUM                    : INTEGER ;       (* CHECKSUM *)
  170.        CRC                         : INTEGER ;       (* CRC      *)
  171.  
  172.        InDataCount,  OutDataCount  : BYTE ;          (* dataCOUNT *)
  173.  
  174.     (* Initialization packet parameters *)
  175.     PacketSize,Timeout,NumPad,PadChar,EndChar,StartChar,
  176.     CntrlQuote,Bit8Quote,Checktype,RepChar     : Byte ;
  177.  
  178.     (* Operational Options Parameters *)
  179.     LocalEcho   : Boolean ;
  180.     Series1     : Boolean ;
  181.     XonXoff     : Boolean ;
  182.     BaudRate    : Integer ;
  183.     Parity      : ParityType ;
  184.     PrimaryPort : Boolean ;
  185.     AudioFlag,AplFlag,ParmFlag  : Boolean ;
  186.  
  187.     (* Execution control flags *)
  188.     WaitXon, Running, Logging, ForPrinter,
  189.     ActiveCommandFile, GotSOH,DTRcheck               : Boolean ;
  190.  
  191.     I                      : INTEGER ;
  192.     inputstring            : comstring ;
  193.     command                : Wstring ;
  194.     commandtable,parmtable : string[255];
  195.     LogName,dummy          : comstring ;
  196.     Logfile,CommandFile    : Text ;
  197.  
  198. {$I Utility.Pas }
  199. {$I SYSFUNC.PAS }
  200. {$I MODEMPRO.PAS }
  201. {$I ReadChar.Pas }
  202. {$I DefWords.pas }
  203. {$I packet.pas }
  204.  
  205. (* ----------------------------------------------------------------- *)
  206. (* SENDFILE - Procedure                                              *)
  207. (* ----------------------------------------------------------------- *)
  208. {$I SENDFILE }
  209.  
  210. (* ----------------------------------------------------------------- *)
  211. (* RECVFILE - Procedure                                              *)
  212. (* ----------------------------------------------------------------- *)
  213. {$I RECVFILE }
  214.  
  215. (* ----------------------------------------------------------------- *)
  216. (* Graphics - Procedures . This are only required for graphics.      *)
  217. (* ----------------------------------------------------------------- *)
  218. {$I TYPEDEF }
  219. {$I GRAPHIX }
  220. {$I KERNEL }
  221. {*I POLYGON }
  222. {*I HATCH }
  223.  
  224. (* ----------------------------------------------------------------- *)
  225. (* CONNECTION - Procedure                                            *)
  226. (* ----------------------------------------------------------------- *)
  227. {$I CONNECT }
  228.  
  229. (* ----------------------------------------------------------------- *)
  230. (* SHOWOPTIONS and SETOPTIONS and  DisplayCommand - Procedures       *)
  231. (* ----------------------------------------------------------------- *)
  232. {$I SETSHOW }
  233.  
  234. (* ----------------------------------------------------------------- *)
  235. (* Local Procedures - Directory, Erase, Rename, Typefile             *)
  236. (* ----------------------------------------------------------------- *)
  237. {$I LOCAL }
  238.  
  239. (* ----------------------------------------------------------------- *)
  240. (* Remote Procedures                                                 *)
  241. (* ----------------------------------------------------------------- *)
  242. {$I REMOTE }
  243.  
  244. (* ----------------------------------------------------------------- *)
  245. (* MiscCommands - LOG , Exit                      - Procedures       *)
  246. (* ----------------------------------------------------------------- *)
  247. {$I MISCCOMM }
  248.  
  249. (* ***************************************************************** *)
  250. (* ********    Outter Block of Kermit ****************************** *)
  251. (* ***************************************************************** *)
  252.  
  253.  
  254. BEGIN (* KERMIT *)
  255. commandtable := concat('bad       ',
  256.                        'CONNECT   ',
  257.                        'SEND      ',
  258.                        'RECEIVE   ',
  259.                        'SET       ',
  260.                        'STATUS    ',
  261.                        'DIRECTORY ',
  262.                        'ERASE     ',
  263.                        'RENAME    ',
  264.                        'TYPE      ',
  265.                        'RUN EXEC  ',
  266.                        'REMOTE    ',
  267.                        'LOG       ',
  268.                        'TAKE      ',
  269.                        'DEFINE    ',
  270.                        'HELP  ?   ',
  271.                        'MKDIR MD  ',
  272.                        'RMDIR RD  ',
  273.                        'CHDIR CD  ',
  274.                        'AUDIO     ',
  275.                        'PARMS     ',
  276.                        'QUIT      ',
  277.                        'DO LOCAL  ') ;
  278.  
  279.  (* Default Packet settings *)
  280.  PacketSize := 94 ;     (* PACKET size 94 maximum *)
  281.  Timeout    := 60 ;     (* Time out in seconds *)
  282.  NumPad     := 00 ;     (* Number of Pad characters *)
  283.  PadChar    := 00 ;     (* Padding Character *)
  284.  EndChar    := 13 ;     (* End of line char - CR *)
  285.  StartChar  := 01 ;     (* Start of Packet char - SOH *)
  286.  CntrlQuote := 35 ;     (* # *)
  287.  Bit8Quote  := 38 ;     (* & *)
  288.  CheckType  := 49 ;     (* 1 *)
  289.  RepChar    := 00 ;     (* ~ *)
  290.  
  291.  (* Default Settings *)
  292.  Baudrate    := DefaultBaud ;
  293.  Parity      := EvenP ;
  294.  XonXoff     := False ;
  295.  Series1     := True ;
  296.  LocalEcho   := False ;
  297.  PrimaryPort := True ;
  298.  AudioFlag   := False ;
  299.  AplFlag     := False ;
  300.  ParmFlag    := False ;
  301.  
  302. (* Set control flow flags *)
  303. connected         := false ;
  304. logging           := false ;
  305. ForPrinter        := false ;
  306. ActiveCommandfile := false ;
  307. GotSOH            := false ;
  308. DTRcheck          := true ;
  309. Running := true;
  310.  
  311. DefList := Nil ;
  312. LoadDefWords ; NewDefs := false ;
  313. InitModem ;
  314.  
  315. inputstring := commandline ;
  316. (* writeln(commandline); *)
  317.  
  318. ReadKeyTable;
  319.  
  320.    Writeln('          * ======================================== * ');
  321.    Writeln('          *  Queen''s University  -  KERMIT /',termtype,' * ');
  322.    Writeln('          *                                          * ');
  323.    Writeln('          *      Version ',version,Gversion,' - ',Date,'  * ');
  324.    Writeln('          *      Author   -  Victor Lee              * ');
  325.    Writeln('          *      Graphics ',Graph,'  * ');
  326.    Writeln('          * ======================================== * ');
  327.  
  328. While Running Do
  329.     Begin (* Command Loop *)
  330.     if audioflag then
  331.        Begin sound(1500);delay(50);sound(300);delay(50);nosound; end ;
  332.     if length(inputstring)<1 then
  333.          if ActiveCommandFile then
  334.               Begin (* Get command from file *)
  335.               Readln(Commandfile,inputstring);
  336.               ActiveCommandFile := not Eof(commandfile);
  337.               End
  338.                              else
  339.              Begin (* ask for input *)
  340.              Write('QK-Kermit>');              (* PROMPT for input *)
  341.              readln(inputstring);
  342.              End ; (* ask for input *)
  343.  
  344.     command := Uppercase(GETTOKEN(inputstring));
  345.     CheckDefWords(DefList,command,Inputstring);
  346.     command := ' ' + command ;
  347.     WaitXon := false ;
  348.  
  349.     case commandindex(POS(command,commandtable) div 10 ) of
  350.           zero    : If length(command)>1 then
  351.                         Begin (* bad command *)
  352.                         Writeln(' Invalid Command >>>>> ',Command,' <<<<<');
  353.                         Writeln('--- Type HELP to see valid Commands.--- ');
  354.                         End ; (* bad command *)
  355.           connect  : Begin
  356.                      If length(inputstring) > 1 then SetOptions(inputstring);
  357.                      CONNECTION ;
  358.                      End;
  359.           send     : SENDFILE (inputstring);
  360.           receive  : RECVFILE (inputstring );
  361.           setparm  : SetOptions(inputstring);
  362.           status   : ShowOptions ;
  363.           directory: DisplayDir (GetToken(inputstring));
  364.           erase    : EraseFiles (GetToken(inputstring));
  365.           rename   : RenameFile (inputstring);
  366.           typefile : DisplayFile (GetToken(inputstring));
  367.           runfile  : EXECFile (inputstring);
  368.           remote   : RemoteProc (inputstring);
  369.           log      : Logit  (GetToken(inputstring));
  370.           take     : Takeit (GetToken(inputstring));
  371.           define   : DefineWord(inputstring);
  372.           help     : DisplayCommands ;
  373.           mkdir    : MkdirFunc (GetToken(inputstring)) ;
  374.           rmdir    : RmdirFunc (GetToken(inputstring)) ;
  375.           chdir    : ChdirFunc (GetToken(inputstring)) ;
  376.           audio    : AudioFlag := AudioFlag xor True ;
  377.           parms    : ParmFlag := ParmFlag xor True ;
  378.           quit     : QuitExit (UpperCase(GetToken(inputstring)));
  379.           null     : ;
  380.        end ;  (*  Case commandindex *)
  381.     End ; (* Command Loop *)
  382.  
  383.  If Logging then Close(Logfile);
  384.  If NewDefs then SaveDefWords ;
  385.  If audioflag then
  386.     begin sound(1500);delay(200);sound(3000);delay(200);end ;
  387.  If connected then ResetModem;
  388.  If audioflag then
  389.     begin sound(2000);delay(200); nosound; end ;
  390.  ClrScr;
  391.  Gotoxy(20,10); Write( ' G O O D - B Y E ');
  392.  
  393. END.  (* KERMIT *)
  394.  
  395.