home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / pibsoft / terminal / source / receivea.mod < prev    next >
Encoding:
Text File  |  1988-02-18  |  10.6 KB  |  345 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                Receive_Ascii_File --- Download ASCII file            *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Receive_Ascii_File;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Receive_Ascii_File                                   *)
  10. (*                                                                      *)
  11. (*     Purpose:    Downloads ASCII file to PC                           *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Receive_Ascii_File;                                           *)
  16. (*                                                                      *)
  17. (*     Calls:   PibTerm_KeyPressed                                      *)
  18. (*              Async_Send                                              *)
  19. (*              Async_Receive                                           *)
  20. (*                                                                      *)
  21. (*----------------------------------------------------------------------*)
  22.  
  23. VAR
  24.    Ch            : CHAR;
  25.    Fin           : BOOLEAN;
  26.    X             : INTEGER;
  27.    Y             : INTEGER;
  28.    Line_Count    : LONGINT;
  29.    Byte_Count    : LONGINT;
  30.    Full_Name     : AnyStr;
  31.    Ascii_Display : BOOLEAN;
  32.    Use_Ch        : BOOLEAN;
  33.    I             : INTEGER;
  34.    Max_DLine     : INTEGER;
  35.    R_Error       : BOOLEAN;
  36.    AFile         : TEXT;
  37.    Divider_Line  : INTEGER;
  38.    Mess_Text     : AnyStr;
  39.    Ascii_Title   : AnyStr;
  40.    Alt_R_Hit     : BOOLEAN;
  41.  
  42. (*----------------------------------------------------------------------*)
  43. (* Initialize_Ascii_Receive_Display --- Start up transfer status window *)
  44. (*----------------------------------------------------------------------*)
  45.  
  46. PROCEDURE Initialize_Ascii_Receive_Display;
  47.  
  48. VAR
  49.    I: INTEGER;
  50.  
  51. BEGIN (* Initialize_Ascii_Receive_Display *)
  52.  
  53.                                    (* Figure display size              *)
  54.    IF Do_Status_Line THEN
  55.       Max_DLine := PRED( Max_Screen_Line )
  56.    ELSE
  57.       Max_DLine := Max_Screen_Line;
  58.  
  59.    Divider_Line := 13;
  60.  
  61.                                    (* Save current screen contents     *)
  62.    Save_Screen( Saved_Screen );
  63.                                    (* Open display window for received *)
  64.                                    (* text lines.                      *)
  65.    IF Ascii_Display THEN
  66.       BEGIN
  67.  
  68.          TextColor( Menu_Text_Color );
  69.  
  70.          PibTerm_Window( 1, 1, Max_Screen_Col, Max_DLine );
  71.          GoToXY( 1 , Divider_Line );
  72.  
  73.          FOR I := 1 TO 25 DO WRITE('=');
  74.  
  75.          TextColor( Menu_Text_Color_2 );
  76.          WRITE('Received text displayed below');
  77.  
  78.          TextColor( Menu_Text_Color );
  79.          FOR I := 1 TO 25 DO WRITE('=');
  80.  
  81.       END;
  82.                                    (* Open display window for transfer  *)
  83.  
  84.    Draw_Menu_Frame( 15, 4, 78, 11, Menu_Frame_Color, Menu_Title_Color,
  85.                     Menu_Text_Color, Ascii_Title );
  86.  
  87.                                    (* Headings for status information *)
  88.    TextColor( Menu_Text_Color_2 );
  89.    PibTerm_Window( 16, 5, 77, 10 );
  90.    GoToXY( 1 , 1 );
  91.    WRITELN(' Lines received: ');
  92.    WRITELN(' Bytes received: ');
  93.    WRITELN(' ');
  94.  
  95.    IF Ascii_Display THEN
  96.       BEGIN
  97.          PibTerm_Window( 1, SUCC( Divider_Line ), Max_Screen_Col, Max_DLine );
  98.          GoToXY( 1 , 1 );
  99.          Clear_Window;
  100.       END;
  101.  
  102. END   (* Initialize_Ascii_Receive_Display *);
  103.  
  104. (*----------------------------------------------------------------------*)
  105. (*        Flip_Display_Status --- turn status display on/off            *)
  106. (*----------------------------------------------------------------------*)
  107.  
  108. PROCEDURE Flip_Display_Status;
  109.  
  110. BEGIN (* Flip_Display_Status *)
  111.  
  112.    CASE Display_Status OF
  113.  
  114.       TRUE:   BEGIN
  115.                                    (* Indicate no display   *)
  116.  
  117.                  Display_Status := FALSE;
  118.  
  119.                                    (* Remove Ascii window  *)
  120.  
  121.                  Restore_Screen_And_Colors( Saved_Screen );
  122.  
  123.               END;
  124.  
  125.       FALSE:  BEGIN
  126.                                    (* Indicate display will be done *)
  127.  
  128.                  Display_Status := TRUE;
  129.                  Ascii_Display  := Ascii_Show_Text;
  130.  
  131.                                    (* Set up transfer status window *)
  132.  
  133.                  Initialize_Ascii_Receive_Display;
  134.  
  135.               END;
  136.  
  137.    END (* CASE *);
  138.  
  139. END   (* Flip_Display_Status *);
  140.  
  141. (*----------------------------------------------------------------------*)
  142. (*      Activate_Status_Window --- switch to status display window      *)
  143. (*----------------------------------------------------------------------*)
  144.  
  145. PROCEDURE Activate_Status_Window;
  146.  
  147. BEGIN (* Activate_Status_Window *)
  148.  
  149.    IF Ascii_Display THEN
  150.       BEGIN
  151.          X := WhereX;
  152.          Y := WhereY;
  153.          PibTerm_Window( 16, 5, 77, 10 );
  154.       END;
  155.  
  156. END   (* Activate_Status_Window *);
  157.  
  158. (*----------------------------------------------------------------------*)
  159. (*         Activate_Text_Window --- switch to text display window       *)
  160. (*----------------------------------------------------------------------*)
  161.  
  162. PROCEDURE Activate_Text_Window;
  163.  
  164. BEGIN (* Activate_Text_Window *)
  165.  
  166.    IF Ascii_Display THEN
  167.       BEGIN
  168.          PibTerm_Window( 1, SUCC( Divider_Line ), Max_Screen_Col, Max_DLine );
  169.          GoToXY( X , Y );
  170.       END;
  171.  
  172. END   (* Activate_Text_Window *);
  173.  
  174. (*----------------------------------------------------------------------*)
  175. (*  Update_Ascii_Receive_Display --- Update display of Xmodem reception *)
  176. (*----------------------------------------------------------------------*)
  177.  
  178. PROCEDURE  Update_Ascii_Receive_Display;
  179.  
  180. BEGIN (* Update_Ascii_Receive_Display *)
  181.  
  182.    Activate_Status_Window;
  183.  
  184.    TextColor( Menu_Text_Color );
  185.  
  186.    GoToXY( 17 , 1 );
  187.    WRITE( Line_Count:8 );
  188.    GoToXY( 17 , 2 );
  189.    WRITE( Byte_Count:8 );
  190.  
  191.    Activate_Text_Window;
  192.  
  193.    TextColor( Menu_Text_Color_2 );
  194.  
  195. END   (* Update_Ascii_Receive_Display *);
  196.  
  197. (*----------------------------------------------------------------------*)
  198.  
  199. BEGIN (* Receive_Ascii_File *)
  200.                                    (* Initialize *)
  201.    Fin           := FALSE;
  202.    Line_Count    := 0;
  203.    Byte_Count    := 0;
  204.    X             := 1;
  205.    Y             := 1;
  206.    Ascii_Display := Ascii_Show_Text;
  207.    Use_Ch        := TRUE;
  208.    R_Error       := FALSE;
  209.    Alt_R_Hit     := FALSE;
  210.                                    (* Remove cursor                    *)
  211.    CursorOff;
  212.                                    (* Initialize transfer display      *)
  213.  
  214.    Ascii_Title := 'Receive file ' + FileName + ' using ASCII';
  215.  
  216.    Initialize_Ascii_Receive_Display;
  217.  
  218.    Write_Log( Ascii_Title, FALSE, FALSE );
  219.  
  220.                                    (* Open reception file *)
  221.  
  222.    Add_Path( FileName, Download_Dir_Path, Full_Name );
  223.  
  224.    ASSIGN    ( Afile, Full_Name );
  225.    SetTextBuf( AFile , Sector_Data );
  226.    REWRITE   ( AFile );
  227.  
  228.    R_Error := ( INT24Result <> 0 );
  229.  
  230.    REPEAT
  231.                                    (* Check for Alt_R -- ends transfer; *)
  232.                                    (* Shift_Tab flips display status    *)
  233.       WHILE PibTerm_KeyPressed DO
  234.          BEGIN
  235.             Read_Kbd( Ch );
  236.             IF ( Ch = CHR( ESC ) ) AND PibTerm_KeyPressed THEN
  237.                BEGIN
  238.                   Read_Kbd( Ch );
  239.                   IF ORD( Ch ) = Alt_R THEN
  240.                      BEGIN
  241.                         Fin       := TRUE;
  242.                         Alt_R_Hit := TRUE;
  243.                      END
  244.                   ELSE IF ORD( Ch ) = Shift_Tab THEN
  245.                      Flip_Display_Status
  246.                   ELSE
  247.                      Handle_Function_Key( Ch );
  248.                END
  249.             ELSE
  250.                Async_Send( Ch );
  251.          END;
  252.  
  253.       IF Async_Receive( Ch ) THEN
  254.          BEGIN
  255.  
  256.             IF Auto_Strip_High_Bit THEN
  257.                Ch := CHR( ORD( Ch ) AND $7F );
  258.  
  259.             IF Ascii_Translate THEN
  260.                BEGIN
  261.                   Ch     := TrTab[ Ch ];
  262.                   Use_Ch := ( ORD( Ch ) <> NUL );
  263.                END;
  264.  
  265.             IF Use_Ch THEN
  266.                BEGIN
  267.  
  268.                   WRITE( AFile , Ch );
  269.                   R_Error := R_Error OR ( INT24Result <> 0 );
  270.  
  271.                   IF Ascii_Display THEN
  272.                      WRITE( Ch );
  273.  
  274.                   INC( Byte_Count );
  275.  
  276.                   IF ( Ch = CHR( CR ) ) THEN
  277.                      BEGIN
  278.  
  279.                         INC( Line_Count );
  280.  
  281.                         IF Display_Status THEN
  282.                            Update_Ascii_Receive_Display;
  283.  
  284.                         IF Add_LF THEN
  285.                            BEGIN
  286.  
  287.                               WRITE( AFile , CHR( LF ) );
  288.                               R_Error := R_Error OR ( INT24Result <> 0 );
  289.  
  290.                               IF Ascii_Display THEN
  291.                                  WRITE( CHR( LF ) );
  292.  
  293.                               INC( Byte_Count );
  294.  
  295.                            END;
  296.  
  297.                      END
  298.                   ELSE IF Ascii_Use_CtrlZ THEN
  299.                      IF ( Ch = ^Z ) THEN
  300.                         Fin := TRUE;
  301.  
  302.                END;
  303.  
  304.          END;
  305.  
  306.       Fin := Fin OR Async_Carrier_Drop OR R_Error;
  307.  
  308.                                    (* Print character from spooled file *)
  309.       IF Print_Spooling THEN
  310.          Print_Spooled_File;
  311.  
  312.    UNTIL ( Fin );
  313.                                    (* Ensure status window is up *)
  314.    IF ( NOT Display_Status ) THEN
  315.       Flip_Display_Status;
  316.  
  317.    Activate_Status_Window;
  318.                                    (* Get termination status message *)
  319.    IF Async_Carrier_Drop THEN
  320.       Mess_Text := 'Carrier dropped, receive cancelled.'
  321.    ELSE IF Alt_R_Hit THEN
  322.       Mess_Text := 'Alt-R hit, receive stopped.'
  323.    ELSE IF ( NOT R_Error ) THEN
  324.       Mess_Text := 'Receive completed.'
  325.    ELSE
  326.       Mess_Text := 'Error in receive.';
  327.  
  328.                                    (* Display termination status message *)
  329.    GoToXY( 1 , 4 );
  330.    Write_Log( Mess_Text , TRUE , TRUE );
  331.  
  332.    Window_Delay;
  333.  
  334.    CLOSE( AFile );
  335.  
  336.    R_Error := ( INT24Result <> 0 );
  337.  
  338.                                    (* Remove this window            *)
  339.  
  340.    Restore_Screen_And_Colors( Saved_Screen );
  341.                                    (* Reset cursor                  *)
  342.    CursorOn;
  343.  
  344. END   (* Receive_Ascii_File *);
  345.