home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s1.arc / HANDLEKB.MOD < prev    next >
Text File  |  1988-03-23  |  7KB  |  174 lines

  1. (*----------------------------------------------------------------------*)
  2. (*     Handle_Keyboard_Input ---  Read keyboard input in terminal mode  *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Handle_Keyboard_Input( VAR Done                  : BOOLEAN;
  6.                                  VAR Reset_Requested       : BOOLEAN;
  7.                                  VAR ClearScreen_Requested : BOOLEAN );
  8.  
  9. (*----------------------------------------------------------------------*)
  10. (*                                                                      *)
  11. (*     Procedure:  Handle_Keyboard_Input                                *)
  12. (*                                                                      *)
  13. (*     Purpose:    Reads keyboard input in terminal modes               *)
  14. (*                                                                      *)
  15. (*     Calling Sequence:                                                *)
  16. (*                                                                      *)
  17. (*        Handle_Keyboard_Input                                         *)
  18. (*                                                                      *)
  19. (*----------------------------------------------------------------------*)
  20.  
  21. VAR
  22.    Ch               : CHAR;
  23.    Save_Screen_Line : INTEGER;
  24.    Save_Screen_Col  : INTEGER;
  25.    I                : INTEGER;
  26.  
  27. BEGIN (* Handle_Keyboard_Input *)
  28.  
  29.                                    (* Read input character *)
  30.    Read_Kbd( Ch );
  31.                                    (* Assume not reset     *)
  32.    Reset_Requested := FALSE;
  33.                                    (* Assume not clear screen *)
  34.    ClearScreen_Requested := FALSE;
  35.                                    (* Process it           *)
  36.    IF ( Ch = CHR( ESC ) ) THEN
  37.       IF PibTerm_KeyPressed THEN
  38.          BEGIN  (* Escape AND PibTerm_KeyPressed *)
  39.  
  40.                                    (* Get character following escape *)
  41.             Read_Kbd( Ch );
  42.  
  43.             IF ( Ch = CHR( SI ) ) THEN
  44.                Reset_Requested := TRUE
  45.             ELSE
  46.                BEGIN  (* Not terminal reset *)
  47.  
  48.                   Save_Screen_Line := Max_Screen_Line;
  49.                   Save_Screen_Col  := Max_Screen_Col;
  50.  
  51.                   Process_Command( Ch, TRUE, PibTerm_Command );
  52.  
  53.                   CASE PibTerm_Command OF
  54.                      Null_Command: ;
  55.                      ClearSy     : ClearScreen_Requested := TRUE;
  56.                      ELSE
  57.                                    Execute_Command( PibTerm_Command, Done, FALSE );
  58.                   END (* CASE *);
  59.  
  60.                   Reset_Requested := ( Max_Screen_Line <> Save_Screen_Line ) OR
  61.                                      ( Max_Screen_Col  <> Save_Screen_Col  );
  62.  
  63.                END   (* Not terminal reset *);
  64.  
  65.             EXIT;
  66.  
  67.          END  (* Escape AND PibTerm_KeyPressed *)
  68.       ELSE  (* Escape only *)
  69.          IF Async_XOff_Received THEN
  70.             BEGIN
  71.                Clear_XOFF_Received;
  72.                EXIT;
  73.             END;
  74.                                    (* Convert characters to upper case *)
  75.    IF Send_Upper_Case_Only THEN
  76.       Ch := UpCase( Ch );
  77.                                    (* Learn this character if doing a *)
  78.                                    (* learn script.                   *)
  79.    IF Script_Learn_Mode THEN
  80.       Learn_A_Character( Ch );
  81.                                    (* We must handle the BS and Ctrl_BS  *)
  82.                                    (* requests specially, since they can *)
  83.                                    (* be strings.                        *)
  84.    CASE ORD( Ch ) OF
  85.  
  86.       DEL  : BEGIN
  87.                                    (* Send ctrl-backspace.  If local    *)
  88.                                    (* echo, store characters in receive *)
  89.                                    (* buffer.                           *)
  90.  
  91.                 FOR I := 1 TO LENGTH( Ctrl_BS_String ) DO
  92.                    BEGIN
  93.                       Async_Send ( Ctrl_BS_String[ I ] );
  94.                       IF Gossip_Mode_On THEN
  95.                          Display_Character( Ctrl_BS_String[I] )
  96.                       ELSE IF Local_Echo THEN
  97.                          Async_Stuff( Ctrl_BS_String[ I ] );
  98.                    END;
  99.                                    (* Move back in saved input line *)
  100.  
  101.                 IF ( Keyboard_Line_Pos > 0 ) THEN
  102.                    DEC( Keyboard_Line_Pos );
  103.  
  104.              END;
  105.  
  106.       BS   : BEGIN
  107.                                    (* Send backspace.  Also, if local   *)
  108.                                    (* echo, store characters in receive *)
  109.                                    (* buffer.                           *)
  110.  
  111.                 FOR I := 1 TO LENGTH( BS_String ) DO
  112.                    BEGIN
  113.                       Async_Send ( BS_String[ I ] );
  114.                       IF Gossip_Mode_On THEN
  115.                          Display_Character( BS_String[I] )
  116.                       ELSE IF Local_Echo THEN
  117.                          Async_Stuff( BS_String[ I ] );
  118.                    END;
  119.                                    (* Move back in saved input line *)
  120.  
  121.                 IF ( Keyboard_Line_Pos > 0 ) THEN
  122.                    DEC( Keyboard_Line_Pos );
  123.  
  124.              END;
  125.  
  126.       ELSE   BEGIN (* Other characters *)
  127.  
  128.                                    (* Put char in received buffer if *)
  129.                                    (* local echo on so we display it *)
  130.                                    (* later on, except XOFF.         *)
  131.  
  132.                 IF ( Ch <> CHR( XOFF ) ) THEN
  133.                    IF Gossip_Mode_On THEN
  134.                       Display_Character( Ch )
  135.                    ELSE IF Local_Echo THEN
  136.                       Async_Stuff( Ch );
  137.  
  138.                                    (* Send this character to remote.  *)
  139.                 Async_Send( Ch );
  140.                                    (* If Ch = CR and New_Line mode, send  *)
  141.                                    (* a LF as well.                       *)
  142.  
  143.                 IF ( Ch = CHR( CR ) ) THEN
  144.                    BEGIN
  145.                       IF New_Line THEN
  146.                          Async_Send( CHR( LF ) );
  147.                       IF Gossip_Mode_On THEN
  148.                          Display_Character( CHR( LF ) );
  149.                    END;
  150.  
  151.                                    (* Stuff character into keyboard line  *)
  152.  
  153.                 IF ( Keyboard_Line_Pos = 255 ) THEN
  154.                    BEGIN
  155.                       MOVE( Keyboard_Line[2], Keyboard_Line[1], 254 );
  156.                       Keyboard_Line[255] := Ch;
  157.                    END
  158.                 ELSE
  159.                    BEGIN
  160.                       INC( Keyboard_Line_Pos );
  161.                       Keyboard_Line[Keyboard_Line_Pos] := Ch;
  162.                    END;
  163.  
  164.                 Keyboard_Line[0] := CHR( Keyboard_Line_Pos );
  165.  
  166.                 IF ( Ch = CHR( CR ) ) THEN
  167.                    Keyboard_Line_Pos := 0;
  168.  
  169.              END   (* Other characters *);
  170.  
  171.    END (* CASE *);
  172.  
  173. END   (* Handle_Keyboard_Input *);
  174.