home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / bbs / pibterm / pibt3sp1 / editalin.pas < prev    next >
Pascal/Delphi Source File  |  1985-07-18  |  16KB  |  426 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*       Edit_A_Line --- Edit line on screen and resend to host             *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. OVERLAY PROCEDURE Edit_A_Line;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*    Function: Edit_A_Line                                                 *)
  10. (*                                                                          *)
  11. (*    Purpose:  Edit line on screen and resend to host                      *)
  12. (*                                                                          *)
  13. (*    Calling Sequence:                                                     *)
  14. (*                                                                          *)
  15. (*       Edit_A_Line;                                                       *)
  16. (*                                                                          *)
  17. (*    Calls:  EditString                                                    *)
  18. (*            Async_Send                                                    *)
  19. (*            Get_Screen_Text_Line                                          *)
  20. (*                                                                          *)
  21. (*--------------------------------------------------------------------------*)
  22.  
  23. VAR
  24.    I           : INTEGER;
  25.    S           : AnyStr;
  26.    Ch          : CHAR;
  27.    X           : INTEGER;
  28.    Y           : INTEGER;
  29.    Saved_Line  : AnyStr;
  30.    Status_Line : INTEGER;
  31.    Old_Status  : INTEGER;
  32.    Saved_X     : BYTE;
  33.    Saved_Y     : BYTE;
  34.    Saved_X_2   : BYTE;
  35.    Saved_Y_2   : BYTE;
  36.  
  37. (*--------------------------------------------------------------------------*)
  38. (*                  Edit_Help --- display help about editing                *)
  39. (*--------------------------------------------------------------------------*)
  40.  
  41. PROCEDURE Edit_Help;
  42.  
  43. (*--------------------------------------------------------------------------*)
  44. (*                       Dummy routine for the present                      *)
  45. (*--------------------------------------------------------------------------*)
  46.  
  47. BEGIN (* Edit_Help *)
  48.  
  49.    ;
  50.  
  51. END   (* Edit_Help *);
  52.  
  53. (*--------------------------------------------------------------------------*)
  54. (*          Edit_String  -- Edit a string using Wordstar commands           *)
  55. (*--------------------------------------------------------------------------*)
  56.  
  57. FUNCTION Edit_String( VAR In_Str      : AnyStr;
  58.                           Buffer_Len  : INTEGER;
  59.                           Start_X     : INTEGER;
  60.                           X           : INTEGER;
  61.                           Y           : INTEGER;
  62.                           Force_Case  : BOOLEAN;
  63.                           Status_Line : INTEGER  ) : CHAR;
  64.  
  65. (*--------------------------------------------------------------------------*)
  66. (*                                                                          *)
  67. (*     Function:  Edit_String                                               *)
  68. (*                                                                          *)
  69. (*     Purpose:   Provides for editing a string using Wordstar commands.    *)
  70. (*                                                                          *)
  71. (*     Callling Sequence:                                                   *)
  72. (*                                                                          *)
  73. (*        Edited_String = Edit_String( VAR  In_Str     : AnyStr;            *)
  74. (*                                          Buffer_Len : INTEGER;           *)
  75. (*                                          Start_X    : INTEGER;           *)
  76. (*                                          X          : INTEGER;           *)
  77. (*                                          Y          : INTEGER;           *)
  78. (*                                          Force_Case : BOOLEAN;           *)
  79. (*                                          Status_Line: INTEGER ) : CHAR;  *)
  80. (*                                                                          *)
  81. (*           In_Str      --- String to be edited                            *)
  82. (*           Buffer_Len  --- Maximum length allowed for In_Str              *)
  83. (*           Start_X     --- Column to display string                       *)
  84. (*           X           --- Initial edit column                            *)
  85. (*           Y           --- Row to display string                          *)
  86. (*           Force_Case  --- TRUE to force input to upper case              *)
  87. (*           Status_Line --- Display edit status on this line if > 0;       *)
  88. (*                           else no status line display.                   *)
  89. (*                                                                          *)
  90. (*     Calls:    DUPL                                                       *)
  91. (*               GoToXY                                                     *)
  92. (*               UpCase                                                     *)
  93. (*               KeyPressed                                                 *)
  94. (*               COPY                                                       *)
  95. (*               INSERT                                                     *)
  96. (*               DELETE                                                     *)
  97. (*               Edit_Help                                                  *)
  98. (*                                                                          *)
  99. (*     Remarks:                                                             *)
  100. (*                                                                          *)
  101. (*        In addition to strict WordStar commands, the keys on the keypad   *)
  102. (*        can also be used.                                                 *)
  103. (*                                                                          *)
  104. (*        Insert mode is on by default.                                     *)
  105. (*                                                                          *)
  106. (*--------------------------------------------------------------------------*)
  107.  
  108. Var
  109.   Insert_Mode  : BOOLEAN           (* TRUE = insert mode, FALSE = overwrite *);
  110.   Done         : BOOLEAN           (* TRUE if editing finished              *);
  111.   Current_Char : CHAR              (* Current input editing character       *);
  112.   Escape       : BOOLEAN           (* TRUE if escape sequence read          *);
  113.   Current      : CHAR              (* Current input character               *);
  114.   In_string    : AnyStr            (* Working copy of string to be edited   *);
  115.  
  116. (*--------------------------------------------------------------------------*)
  117.  
  118. PROCEDURE Update_Status_Line;
  119.  
  120. VAR
  121.    SaveX: INTEGER;
  122.    SaveY: INTEGER;
  123.  
  124. BEGIN (* Update_Status_Line *)
  125.  
  126.    TextColor     ( Global_BackGround_Color );
  127.    TextBackGround( Global_ForeGround_Color );
  128.  
  129.    SaveX := WhereX;
  130.    SaveY := WhereY;
  131.  
  132.    GoToXY( 1 , Status_Line );
  133.  
  134.    WRITE(' Line ',Y:3,'   Column ',X:3);
  135.  
  136.    IF Insert_Mode THEN
  137.       WRITE('  Insert   ')
  138.    ELSE
  139.       WRITE('  Overwrite');
  140.  
  141.    TextColor     ( Global_ForeGround_Color );
  142.    TextBackGround( Global_BackGround_Color );
  143.  
  144.    ClrEol;
  145.  
  146.    GoToXY( SaveX, SaveY );
  147.  
  148. END   (* Update_Status_Line *);
  149.  
  150. (*--------------------------------------------------------------------------*)
  151.  
  152. BEGIN (* Edit_String *)
  153.  
  154.                                    (* Initialize *)
  155.   Done         := FALSE;
  156.   Insert_Mode  := TRUE;
  157.                                    (* Display the string to be edited *)
  158.   In_String := In_str;
  159.  
  160.   GoToXY( Start_X , Y );
  161.  
  162.   WRITE( In_String );
  163.  
  164.   GoToXY( X , Y );
  165.                                    (* Display status line if requested *)
  166.   IF Status_Line > 0 THEN
  167.      Update_Status_Line;
  168.  
  169.   REPEAT                           (* Begin main edit/input loop *)
  170.  
  171.      IF ( X - Start_X ) = Buffer_Len THEN
  172.         Current_Char := ^M         (* Terminate input if buffer is full *)
  173.      ELSE
  174.         READ( Kbd , Current_Char );    (* Get a character *)
  175.  
  176.      IF Force_Case THEN            (* Force upper case if requested *)
  177.         Current_Char := UPCASE( Current_Char );
  178.  
  179.      REPEAT
  180.  
  181.         Escape := FALSE;
  182.  
  183.         CASE Current_Char of       (* Act on the current input *)
  184.  
  185.            ^[        : IF KeyPressed THEN
  186.                           BEGIN
  187.  
  188.                              READ( Kbd , Current_Char );
  189.  
  190.                              Escape := TRUE;
  191.  
  192.                                    (* Translate escape sequences to *)
  193.                                    (* WordStar commands             *)
  194.  
  195.                              CASE Current_Char OF
  196.  
  197.                                 'H' : BEGIN
  198.                                          Current_Char := ^W;
  199.                                          Done         := TRUE;
  200.                                          Escape       := FALSE;
  201.                                       END;
  202.  
  203.                                 'P' : BEGIN
  204.                                          Current_Char := ^X;
  205.                                          Done         := TRUE;
  206.                                          Escape       := FALSE;
  207.                                       END;
  208.  
  209.                                 'K' : Current_Char := ^S;
  210.                                 'M' : Current_Char := ^D;
  211.                                 'S' : Current_Char := ^G;
  212.                                 'R' : Current_Char := ^V;
  213.                                 'O' : Current_Char := ^F;
  214.                                 'G' : Current_Char := ^A;
  215.                                 '<' : Current_Char := ^R;
  216.                                 's' : Current_Char := ^A;
  217.                                 't' : Current_Char := ^F;
  218.  
  219.                                 ';' : BEGIN
  220.                                          Edit_Help;
  221.                                          Current_Char := ^@;
  222.                                       END;
  223.  
  224.                                 'D' : BEGIN
  225.                                          Done   := TRUE;
  226.                                          Escape := FALSE;
  227.                                       End;
  228.  
  229.                                 'I' : BEGIN
  230.                                          Done   := TRUE;
  231.                                          Escape := FALSE;
  232.                                       End;
  233.  
  234.                                 'Q' : BEGIN
  235.                                          Done   := TRUE;
  236.                                          Escape := FALSE;
  237.                                       End;
  238.  
  239.                              END (* CASE *);
  240.  
  241.                           END (* Escape found *);
  242.  
  243.            ^W        : BEGIN
  244.                           Done    := TRUE;
  245.                           Escape  := FALSE;
  246.                        END;
  247.  
  248.            ^X        : BEGIN
  249.                           Done    := TRUE;
  250.                           Escape  := FALSE;
  251.                        END;
  252.  
  253.                                    (* Move to end of string *)
  254.            ^F        : X := Start_X + LENGTH(In_string);
  255.  
  256.                                    (* Move to beginning of string *)
  257.            ^A        : X := Start_X;
  258.  
  259.            ^R        : BEGIN
  260.                           In_string := In_str;
  261.                           GoToXY( Start_X , Y );
  262.                           WRITE( In_string );
  263.                        END;
  264.  
  265.                                    (* Toggle Insert/Overwrite Mode *)
  266.            ^V        : Insert_Mode := NOT Insert_Mode;
  267.  
  268.                                    (* Non-destructive backspace *)
  269.            ^S        : IF X > Start_X THEN
  270.                           X := X - 1;
  271.  
  272.                                    (* Destructive backspace *)
  273.            ^H,#127   : IF X > Start_X THEN
  274.                           BEGIN
  275.                              DELETE( In_String, X - Start_X, 1 );
  276.                              GoToXY( Start_X , Y );
  277.                              WRITE( In_String , ' ' );
  278.                              X := X - 1;
  279.                           END;
  280.  
  281.                                     (* Move 1 column to right *)
  282.            ^D        : IF (X - Start_X) < Buffer_Len THEN
  283.                           IF (X - Start_X) < LENGTH( In_String ) THEN
  284.                              X := X + 1;
  285.  
  286.                                     (* Delete character under cursor *)
  287.            ^G        : BEGIN
  288.                           DELETE( In_String, X - Start_X + 1, 1 );
  289.                           GoToXY( Start_X , Y );
  290.                           WRITE( In_String, ' ' );
  291.                        END;
  292.  
  293.            ^M        : Done := TRUE;
  294.  
  295.            ^J        : Done := TRUE;
  296.  
  297.            ' '..'~'  : IF ( X - Start_X ) >= LENGTH( In_String ) THEN
  298.                           BEGIN
  299.                              In_String := In_String + Current_Char;
  300.                              GoToXY( X , Y );
  301.                              WRITE( Current_Char );
  302.                              IF ( X - Start_X ) < Buffer_Len THEN
  303.                                 X := X + 1;
  304.                           END
  305.  
  306.                        ELSE        (* Ordinary character *)
  307.  
  308.                                    (* If insert mode ... *)
  309.                          IF Insert_Mode THEN
  310.                             BEGIN
  311.  
  312.                                INSERT( Current_Char, In_String,
  313.                                        X - Start_X + 1 );
  314.  
  315.                                In_String := COPY( In_String, 1, Buffer_Len );
  316.  
  317.                                GoToXY( Start_X, Y );
  318.                                WRITE( In_String );
  319.  
  320.                                IF ( X - Start_X ) < Buffer_Len THEN
  321.                                   X := X + 1;
  322.  
  323.                                GoToXY( X , Y );
  324.  
  325.                             END
  326.                          ELSE
  327.                            BEGIN   (* If Overwrite mode ... *)
  328.  
  329.                               In_String[ X - Start_X + 1 ] := Current_Char;
  330.  
  331.                               GoToXY( X , Y );
  332.                               WRITE( Current_Char );
  333.  
  334.                               IF ( X - Start_X ) < Buffer_Len THEN
  335.                                  X := X + 1;
  336.  
  337.                            END;
  338.  
  339.             ELSE
  340.  
  341.          END (* CASE *);
  342.  
  343.     UNTIL ( NOT Escape );
  344.  
  345.     GoToXY( X , Y );
  346.  
  347.     IF Status_Line > 0 THEN
  348.        Update_Status_Line;
  349.  
  350.   UNTIL Done;
  351.  
  352.   Edit_String := Current_Char;     (* Return the terminator *)
  353.   In_str      := In_string;        (* Return updated string *)
  354.  
  355. END   (* Edit_String *);
  356.  
  357. (*--------------------------------------------------------------------------*)
  358.  
  359. BEGIN (* Edit_A_Line *)
  360.                                    (* Tell host to stop sending *)
  361.    Async_Send( CHR( XOFF ) );
  362.  
  363.    X       := 1;
  364.    Y       := WhereY;
  365.  
  366.    Saved_X := WhereX;
  367.    Saved_Y := Y;
  368.  
  369.    IF Y <> 1 THEN
  370.       Old_Status := 1
  371.    ELSE
  372.       Old_Status := 25;
  373.  
  374.    Get_Screen_Text_Line( Saved_Line, Old_Status, 1 );
  375.  
  376.    REPEAT
  377.  
  378.       IF Y <> 1 THEN
  379.          Status_Line := 1
  380.       ELSE
  381.          Status_Line := 25;
  382.  
  383.       IF Status_Line <> Old_Status THEN
  384.          BEGIN
  385.  
  386.             Saved_X_2 := WhereX;
  387.             Saved_Y_2 := WhereY;
  388.  
  389.             GoToXY( 1 , Old_Status );
  390.             WRITE( TRIM( Saved_Line ) );
  391.             ClrEol;
  392.  
  393.             Old_Status := Status_Line;
  394.  
  395.             Get_Screen_Text_Line( Saved_Line, Status_Line, 1 );
  396.  
  397.             GoToXY( Saved_X_2, Saved_Y_2 );
  398.  
  399.          END;
  400.  
  401.       Get_Screen_Text_Line( S, Y, 1 );
  402.  
  403.       S  := Trim( S );
  404.  
  405.       Ch := Edit_String( S, 255, 1, X, Y, FALSE, Status_Line );
  406.  
  407.       CASE Ch OF
  408.          ^W:  IF ( Y > 1  ) THEN Y := Y - 1;
  409.          ^X:  IF ( Y < 25 ) THEN Y := Y + 1;
  410.          ELSE ;
  411.       END (* CASE *);
  412.  
  413.    UNTIL ( Ch = CHR( CR ) );
  414.  
  415.    GoToXY( 1 , Status_Line );
  416.    WRITE( TRIM( Saved_Line ) );
  417.    ClrEol;
  418.  
  419.    GoToXY( Saved_X , Saved_Y );
  420.  
  421.    Async_Send( CHR( XON ) );
  422.  
  423.    Async_Send_String( Trim( S ) + CHR( CR ) );
  424.  
  425. END   (* Edit_A_Line *);
  426. ə