home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s4.arc / SENDMDM7.MOD < prev    next >
Text File  |  1987-12-02  |  13KB  |  354 lines

  1. (*----------------------------------------------------------------------*)
  2. (*        Send_Modem7_File --- Upload file with Modem7/Telink           *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Send_Modem7_File( Use_CRC: BOOLEAN );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Send_Modem7_File                                     *)
  10. (*                                                                      *)
  11. (*     Purpose:    Uploads file using Modem7/Telink batch               *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Send_Modem7_File( Use_CRC: BOOLEAN);                          *)
  16. (*                                                                      *)
  17. (*           Use_CRC --- TRUE to use CRC checking;                      *)
  18. (*                       FALSE to use Checksum checking.                *)
  19. (*                                                                      *)
  20. (*     Calls:   PibTerm_KeyPressed                                      *)
  21. (*              Async_Send                                              *)
  22. (*              Async_Receive_With_TimeOut                              *)
  23. (*              Get_Modem7_File_Name                                    *)
  24. (*              Check_The_KeyBoard                                      *)
  25. (*              RvsVideoOn                                              *)
  26. (*              RvsVideoOff                                             *)
  27. (*              Wait_For_Nak                                            *)
  28. (*              Send_File_Name                                          *)
  29. (*              Perform_Upload                                          *)
  30. (*                                                                      *)
  31. (*      Remarks:                                                        *)
  32. (*                                                                      *)
  33. (*         This routine performs wildcard directory searches and        *)
  34. (*         implements the Modem7 and Telink batch file transfer         *)
  35. (*         protocols.                                                   *)
  36. (*                                                                      *)
  37. (*----------------------------------------------------------------------*)
  38.  
  39. VAR
  40.    File_Pattern : AnyStr;
  41.    SFileName    : PACKED ARRAY[1..11] OF CHAR;
  42.    Int_Ch       : INTEGER;
  43.    Ch           : CHAR;
  44.    CheckSum     : INTEGER;
  45.    EndFName     : BOOLEAN;
  46.    I            : INTEGER;
  47.    J            : INTEGER;
  48.    File_Entry   : SearchRec;
  49.    Ack_OK       : BOOLEAN;
  50.    OK_File      : BOOLEAN;
  51.  
  52. (*----------------------------------------------------------------------*)
  53. (*          Check_The_KeyBoard --- Check for keyboard input             *)
  54. (*----------------------------------------------------------------------*)
  55.  
  56. PROCEDURE Check_The_KeyBoard;
  57.  
  58. BEGIN (* Check_The_KeyBoard *)
  59.  
  60.    Check_KeyBoard;
  61.  
  62.    IF Stop_Send THEN
  63.       BEGIN
  64.          IF ( NOT Display_Status ) THEN
  65.             Display_Batch_Window;
  66.          WRITELN('  Alt_S pressed, transfer cancelled.');
  67.       END;
  68.  
  69. END   (* Check_The_KeyBoard *);
  70.  
  71. (*----------------------------------------------------------------------*)
  72. (*       Get_Modem7_File_Name --- Construct file name to MODEM7 form    *)
  73. (*----------------------------------------------------------------------*)
  74.  
  75. PROCEDURE Get_Modem7_File_Name( VAR OK_File : BOOLEAN );
  76.  
  77. (*----------------------------------------------------------------------*)
  78. (*                                                                      *)
  79. (*     Remarks:                                                         *)
  80. (*                                                                      *)
  81. (*        The filename for Modem7 is 11 characters long.  The filename  *)
  82. (*        is left-justified and blank-filled in the first 8 characters. *)
  83. (*        The extension appears left-justified and blank-filled in      *)
  84. (*        positions 9 through 11.                                       *)
  85. (*                                                                      *)
  86. (*        Examples:                                                     *)
  87. (*                                 12345678901                          *)
  88. (*           'root.dat'  becomes:  root    dat                          *)
  89. (*           'root'      becomes:  root                                 *)
  90. (*                                                                      *)
  91. (*        Note that the checksum INCLUDES the terminating Ctrl-z (SUB)  *)
  92. (*        character of the file name.                                   *)
  93. (*                                                                      *)
  94. (*        In host mode, a check is made to ensure that the file to be   *)
  95. (*        sent is on the transfer list.  If not, it is not sent.        *)
  96. (*                                                                      *)
  97. (*----------------------------------------------------------------------*)
  98.  
  99. VAR
  100.    I: INTEGER;
  101.    J: INTEGER;
  102.  
  103. BEGIN (* Get_Modem7_File_Name *)
  104.  
  105.    I             := 1;
  106.    J             := 0;
  107.    SFileName     := '           ';
  108.    FileName      := '';
  109.  
  110.    WHILE( I <= LENGTH( File_Entry.Name ) ) DO
  111.       BEGIN
  112.  
  113.          Ch := File_Entry.Name[I];
  114.  
  115.          IF Ch = '.' THEN
  116.             J := 8
  117.          ELSE
  118.             BEGIN
  119.                J            := J + 1;
  120.                SFileName[J] := Ch;
  121.             END;
  122.  
  123.          FileName := FileName + Ch;
  124.  
  125.          I  := I + 1;
  126.  
  127.       END;
  128.                                    (* Get checksum *)
  129.    CheckSum := 0;
  130.  
  131.    FOR I := 1 TO 11 DO
  132.       CheckSum := ( CheckSum + ORD( SFileName[I] ) ) AND 255;
  133.  
  134.    CheckSum := ( CheckSum + SUB ) AND 255;
  135.  
  136.    OK_File := ( File_Entry.Attr AND
  137.                 ( VolumeID + Directory ) = 0 );
  138.  
  139.                                    (* If host mode, make sure file *)
  140.                                    (* is on xferlist!              *)
  141.    IF Host_Mode THEN
  142.       IF ( Privilege <> 'S' ) THEN
  143.          OK_File := OK_File AND ( Scan_Xfer_List( FileName ) > 0 );
  144.  
  145. END   (* Get_Modem7_File_Name *);
  146.  
  147. (*----------------------------------------------------------------------*)
  148. (*             Wait_For_Nak --- Wait for NAK at start of file name      *)
  149. (*----------------------------------------------------------------------*)
  150.  
  151. PROCEDURE Wait_For_Nak;
  152.  
  153. BEGIN (* Wait_For_Nak *)
  154.  
  155.    I := 0;
  156.                                    (* Wait up to minute for NAK *)
  157.    REPEAT
  158.       Async_Receive_With_Timeout( One_Second , Int_Ch );
  159.       Check_The_KeyBoard;
  160.       I := I + 1;
  161.    UNTIL ( Int_Ch  = NAK ) OR
  162.          ( I      >= 60  ) OR
  163.          Stop_Send;
  164.  
  165.    IF ( Int_Ch <> NAK ) THEN
  166.       BEGIN
  167.          Stop_Send := TRUE;
  168.          WRITELN('   NAK for start of file name not received;');
  169.          WRITELN('   Received Ascii ',Int_Ch,' instead.');
  170.       END
  171.    ELSE                            (* If NAK found, ACK it *)
  172.       BEGIN
  173.          Async_Send( CHR( ACK ) );
  174.       END;
  175.                                    (* Wait for com line to clear *)
  176.    Async_Purge_Buffer;
  177.  
  178. END   (* Wait_For_Nak *);
  179.  
  180. (*----------------------------------------------------------------------*)
  181. (*             Send_File_Name --- Send file name characters             *)
  182. (*----------------------------------------------------------------------*)
  183.  
  184. PROCEDURE Send_File_Name;
  185.  
  186. (*----------------------------------------------------------------------*)
  187. (*                                                                      *)
  188. (*     Remarks:                                                         *)
  189. (*                                                                      *)
  190. (*        The file name characters are sent one at a time.  After       *)
  191. (*        each is sent, we wait for an ACK.  To end the file name       *)
  192. (*        we send an SUB (ctrl-z) character.                            *)
  193. (*                                                                      *)
  194. (*----------------------------------------------------------------------*)
  195.  
  196. VAR
  197.    I: INTEGER;
  198.    J: INTEGER;
  199.  
  200. BEGIN (* Send_File_Name *)
  201.  
  202.    I := 0;
  203.  
  204.    WHILE( NOT Stop_Send ) AND ( I < 11 ) DO
  205.       BEGIN
  206.  
  207.          I := I + 1;
  208.  
  209.          Async_Send( SFileName[I] );
  210.  
  211.          J := 0;
  212.  
  213.          REPEAT
  214.             Async_Receive_With_Timeout( One_Second , Int_Ch );
  215.             Check_The_KeyBoard;
  216.             J := J + 1;
  217.          UNTIL ( Int_Ch  = ACK ) OR
  218.                ( J      >= 10  );
  219.  
  220.          Ack_OK := ( Int_Ch = ACK );
  221.  
  222.          Stop_Send := Stop_Send OR ( NOT Ack_OK );
  223.  
  224.       END;
  225.                                    (* Send End of file name character *)
  226.                                    (* and await receiver to send      *)
  227.                                    (* checksum.                       *)
  228.    IF NOT Stop_Send THEN
  229.       BEGIN
  230.  
  231.          Async_Send( CHR( SUB ) );
  232.  
  233.          J := 0;
  234.  
  235.          REPEAT
  236.             Async_Receive_With_Timeout( One_Second , Int_Ch );
  237.             Check_The_KeyBoard;
  238.             J := J + 1;
  239.          UNTIL ( Int_Ch  = CheckSum ) OR
  240.                ( J      >= 10  );
  241.  
  242.          IF ( Int_Ch <> CheckSum ) THEN
  243.             BEGIN
  244.                Stop_Send := TRUE;
  245.                WRITELN('   Received checksum for filename not correct;');
  246.                WRITELN('   Correct checksum = ',CheckSum,', received ',Int_Ch);
  247.             END
  248.          ELSE
  249.             Async_Send( CHR( ACK ) );
  250.  
  251.       END;
  252.  
  253. END   (* Send_File_Name *);
  254.  
  255. (*----------------------------------------------------------------------*)
  256. (*                Perform_Upload --- Do the upload                      *)
  257. (*----------------------------------------------------------------------*)
  258.  
  259. PROCEDURE Perform_Upload;
  260.  
  261. BEGIN (* Perform_Upload *)
  262.  
  263.    IF Display_Status THEN
  264.       WRITELN('  Uploading: ' + FileName );
  265.    Write_Log('Uploading: ' + FileName , FALSE, FALSE );
  266.  
  267.    IF Transfer_Protocol = Telink THEN
  268.       Make_Telink_Header( File_Entry );
  269.  
  270.    IF ( NOT Stop_Send ) THEN
  271.       Send_Xmodem_File( Use_CRC );
  272.  
  273.    TextColor( Menu_Text_Color );
  274.    TextBackGround( BLACK );
  275.  
  276. END   (* Perform_Upload *);
  277.  
  278. (*----------------------------------------------------------------------*)
  279.  
  280. BEGIN (* Send_Modem7_File *)
  281.                                    (* Open batch transfer window    *)
  282.    Display_Batch_Window;
  283.                                    (* CRC except Modem7 Checksum *)
  284.  
  285.    Use_CRC     := Use_CRC AND ( Transfer_Protocol <> Modem7_Chk );
  286.  
  287.                                    (* Get file name pattern to send *)
  288.    File_Pattern  := FileName;
  289.                                    (* Pick up drive and path name    *)
  290.    IF ( NOT Host_Mode ) THEN
  291.       Extract_Upload_Path_Name( File_Pattern , Upload_Dir_Path );
  292.  
  293.                                    (* See if we can find anything to *)
  294.                                    (* be sent.                       *)
  295.  
  296.    FindFirst( File_Pattern, AnyFile, File_Entry );
  297.  
  298.    Stop_Send    := ( DosError <> 0 );
  299.  
  300.    IF Stop_Send THEN
  301.       WRITELN('  No files found to send.');
  302.  
  303.                                    (* Loop over file names         *)
  304.    WHILE( NOT Stop_Send ) DO
  305.       BEGIN
  306.                                    (* Get file name *)
  307.  
  308.          Get_Modem7_File_Name( OK_File );
  309.  
  310.                                    (* If file can be sent, do it   *)
  311.          IF OK_File THEN
  312.             BEGIN
  313.                                    (* Wait for NAK indicating host *)
  314.                                    (* is ready for the file name.  *)
  315.                IF NOT Stop_Send THEN
  316.                   Wait_For_Nak;
  317.                                    (* Send file name characters     *)
  318.                IF NOT Stop_Send THEN
  319.                   Send_File_Name;
  320.                                    (* Send the file itself          *)
  321.                IF NOT Stop_Send THEN
  322.                   Perform_Upload;
  323.  
  324.             END;
  325.                                    (* See if more files to transfer *)
  326.  
  327.          FindNext( File_Entry );
  328.  
  329.          Stop_Send := Stop_Send OR ( DosError <> 0 );
  330.  
  331.       END (* WHILE *);
  332.                                    (* Send EOT to indicate no more files *)
  333.    Async_Send( CHR( EOT ) );
  334.                                    (* Wait for ACK                       *)
  335.  
  336.    Async_Receive_With_TimeOut( Five_Seconds , Int_Ch );
  337.  
  338.    TextColor( Menu_Text_Color );
  339.    TextBackGround( BLACK );
  340.  
  341.    IF ( NOT Display_Status ) THEN
  342.       Display_Batch_Window;
  343.  
  344.    IF ( Int_Ch = ACK ) THEN
  345.       BEGIN
  346.          WRITELN(' ');
  347.          WRITELN('  Host system ACKnowledged EOT.');
  348.          Write_Log('  Host system ACKnowledged EOT.', FALSE, FALSE);
  349.       END;
  350.  
  351.    End_Batch_Transfer;
  352.  
  353. END   (* Send_Modem7_File *);
  354.