home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / pibsoft / terminal / source / handlekb.mod < prev    next >
Encoding:
Text File  |  1988-01-24  |  6.5 KB  |  164 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 Local_Echo THEN
  95.                          Async_Stuff( Ctrl_BS_String[ I ] );
  96.                    END;
  97.                                    (* Move back in saved input line *)
  98.  
  99.                 IF ( Keyboard_Line_Pos > 0 ) THEN
  100.                    DEC( Keyboard_Line_Pos );
  101.  
  102.              END;
  103.  
  104.       BS   : BEGIN
  105.                                    (* Send backspace.  Also, if local   *)
  106.                                    (* echo, store characters in receive *)
  107.                                    (* buffer.                           *)
  108.  
  109.                 FOR I := 1 TO LENGTH( BS_String ) DO
  110.                    BEGIN
  111.                       Async_Send ( BS_String[ I ] );
  112.                       IF Local_Echo THEN
  113.                          Async_Stuff( BS_String[ I ] );
  114.                    END;
  115.                                    (* Move back in saved input line *)
  116.  
  117.                 IF ( Keyboard_Line_Pos > 0 ) THEN
  118.                    DEC( Keyboard_Line_Pos );
  119.  
  120.              END;
  121.  
  122.       ELSE   BEGIN (* Other characters *)
  123.  
  124.                                    (* Put char in received buffer if *)
  125.                                    (* local echo on so we display it *)
  126.                                    (* later on, except XOFF.         *)
  127.  
  128.                 IF Local_Echo THEN
  129.                    IF ( Ch <> CHR( XOFF ) ) THEN
  130.                       Async_Stuff( Ch );
  131.  
  132.                                    (* Send this character to remote.  *)
  133.                 Async_Send( Ch );
  134.                                    (* If Ch = CR and New_Line mode, send  *)
  135.                                    (* a LF as well.                       *)
  136.  
  137.                 IF ( Ch = CHR( CR ) ) THEN
  138.                    IF New_Line THEN
  139.                       Async_Send( CHR( LF ) );
  140.  
  141.                                    (* Stuff character into keyboard line  *)
  142.  
  143.                 IF ( Keyboard_Line_Pos = 255 ) THEN
  144.                    BEGIN
  145.                       MOVE( Keyboard_Line[2], Keyboard_Line[1], 254 );
  146.                       Keyboard_Line[255] := Ch;
  147.                    END
  148.                 ELSE
  149.                    BEGIN
  150.                       INC( Keyboard_Line_Pos );
  151.                       Keyboard_Line[Keyboard_Line_Pos] := Ch;
  152.                    END;
  153.  
  154.                 Keyboard_Line[0] := CHR( Keyboard_Line_Pos );
  155.  
  156.                 IF ( Ch = CHR( CR ) ) THEN
  157.                    Keyboard_Line_Pos := 0;
  158.  
  159.              END   (* Other characters *);
  160.  
  161.    END (* CASE *);
  162.  
  163. END   (* Handle_Keyboard_Input *);
  164.