home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / pibcal11.zip / EDITSTRI.PAS < prev    next >
Pascal/Delphi Source File  |  1985-03-09  |  10KB  |  237 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*          Edit_String  -- Edit a string using Wordstar commands           *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. FUNCTION Edit_String( VAR In_Str      : AnyStr;
  6.                           Buffer_Len  : INTEGER;
  7.                           Start_X     : INTEGER;
  8.                           Y           : INTEGER;
  9.                           Force_Case  : BOOLEAN  ) : CHAR;
  10.  
  11. (*--------------------------------------------------------------------------*)
  12. (*                                                                          *)
  13. (*     Function:  Edit_String                                               *)
  14. (*                                                                          *)
  15. (*     Purpose:   Provides for editing a string using Wordstar commands.    *)
  16. (*                                                                          *)
  17. (*     Callling Sequence:                                                   *)
  18. (*                                                                          *)
  19. (*        Edited_String = Edit_String( VAR  In_Str     : AnyStr;            *)
  20. (*                                          Buffer_Len : INTEGER;           *)
  21. (*                                          Start_X    : INTEGER;           *)
  22. (*                                          Y          : INTEGER;           *)
  23. (*                                          Force_Case : BOOLEAN ) : CHAR;  *)
  24. (*                                                                          *)
  25. (*           In_Str      --- String to be edited                            *)
  26. (*           Buffer_Len  --- Maximum length allowed for In_Str              *)
  27. (*           Start_X     --- Column to display string                       *)
  28. (*           Y           --- Row to display string                          *)
  29. (*           Force_Case  --- TRUE to force input to upper case              *)
  30. (*                                                                          *)
  31. (*     Calls:    DUPL                                                       *)
  32. (*               GoToXY                                                     *)
  33. (*               UpCase                                                     *)
  34. (*               KeyPressed                                                 *)
  35. (*               COPY                                                       *)
  36. (*               INSERT                                                     *)
  37. (*               DELETE                                                     *)
  38. (*               Edit_Help                                                  *)
  39. (*                                                                          *)
  40. (*     Remarks:                                                             *)
  41. (*                                                                          *)
  42. (*        In addition to strict WordStar commands, the keys on the keypad   *)
  43. (*        can also be used.                                                 *)
  44. (*                                                                          *)
  45. (*        Insert mode is on by default.                                     *)
  46. (*                                                                          *)
  47. (*--------------------------------------------------------------------------*)
  48.  
  49. Var
  50.   Insert_Mode  : BOOLEAN           (* TRUE = insert mode, FALSE = overwrite *);
  51.   Done         : BOOLEAN           (* TRUE if editing finished              *);
  52.   Current_Char : CHAR              (* Current input editing character       *);
  53.   X            : BYTE              (* Current column being edited           *);
  54.   Escape       : BOOLEAN           (* TRUE if escape sequence read          *);
  55.   Current      : CHAR              (* Current input character               *);
  56.   In_string    : AnyStr            (* Working copy of string to be edited   *);
  57.  
  58. BEGIN (* Edit_String *)
  59.  
  60.                                    (* Initialize *)
  61.   Done         := FALSE;
  62.   Insert_Mode  := TRUE;
  63.   X            := Start_X;
  64.                                    (* Display the string to be edited *)
  65.   In_String := In_str;
  66.   GoToXY(X,Y);
  67.   WRITE(In_String);
  68.   GoToXY(X,Y);
  69.  
  70.   REPEAT                           (* Begin main edit/input loop *)
  71.  
  72.      IF (X - Start_X) = Buffer_Len THEN
  73.         Current_Char := ^M         (* Terminate input if buffer is full *)
  74.      ELSE
  75.         READ( Kbd , Current_Char );    (* Get a character *)
  76.  
  77.      IF Force_Case THEN            (* Force upper case if requested *)
  78.         Current_Char := UPCASE(Current_Char);
  79.  
  80.      REPEAT
  81.  
  82.         Escape := FALSE;
  83.  
  84.         CASE Current_Char of       (* Act on the current input *)
  85.  
  86.            ^[        : IF KeyPressed THEN
  87.                           BEGIN
  88.  
  89.                              READ( Kbd , Current_Char );
  90.  
  91.                              Escape := TRUE;
  92.  
  93.                                    (* Translate escape sequences to *)
  94.                                    (* WordStar commands             *)
  95.  
  96.                              CASE Current_Char OF
  97.  
  98.                                 'H' : Current_Char := ^E;
  99.                                 'P' : Current_Char := ^X;
  100.                                 'K' : Current_Char := ^S;
  101.                                 'M' : Current_Char := ^D;
  102.                                 'S' : Current_Char := ^G;
  103.                                 'R' : Current_Char := ^V;
  104.                                 'O' : Current_Char := ^F;
  105.                                 'G' : Current_Char := ^A;
  106.                                 '<' : Current_Char := ^R;
  107.                                 's' : Current_Char := ^A;
  108.                                 't' : Current_Char := ^F;
  109.  
  110.                                 ';' : BEGIN
  111.                                          Edit_Help;
  112.                                          Current_Char := ^@;
  113.                                       END;
  114.  
  115.                                 'D' : BEGIN
  116.                                          Done   := TRUE;
  117.                                          Escape := FALSE;
  118.                                       End;
  119.  
  120.                                 'I' : BEGIN
  121.                                          Done   := TRUE;
  122.                                          Escape := FALSE;
  123.                                       End;
  124.  
  125.                                 'Q' : BEGIN
  126.                                          Done   := TRUE;
  127.                                          Escape := FALSE;
  128.                                       End;
  129.  
  130.                              END (* CASE *);
  131.  
  132.                           END (* Escape found *);
  133.  
  134.            ^E        : Done := TRUE;
  135.  
  136.            ^X        : Done := TRUE;
  137.  
  138.                                    (* Move to end of string *)
  139.            ^F        : X := Start_x + LENGTH(In_string);
  140.  
  141.                                    (* Move to beginning of string *)
  142.            ^A        : X := Start_x;
  143.  
  144.            ^R        : BEGIN
  145.                           In_string := In_str;
  146.                           GoToXY( Start_X , Y );
  147.                           WRITE( In_string );
  148.                        END;
  149.  
  150.                                    (* Toggle Insert/Overwrite Mode *)
  151.            ^V        : Insert_Mode := NOT Insert_Mode;
  152.  
  153.                                    (* Non-destructive backspace *)
  154.            ^S        : IF X > Start_X THEN
  155.                           X := X - 1;
  156.  
  157.                                    (* Destructive backspace *)
  158.            ^H,#127   : IF X > Start_X THEN
  159.                           BEGIN
  160.                              DELETE( In_String, X - Start_X, 1);
  161.                              GoToXY( Start_X , Y );
  162.                              WRITE( In_String , ' ' );
  163.                              X := X - 1;
  164.                           END;
  165.  
  166.                                     (* Move 1 column to right *)
  167.            ^D        : IF (X - Start_X) < Buffer_Len THEN
  168.                           IF (X - Start_X) < LENGTH( In_String ) THEN
  169.                              X := X + 1;
  170.  
  171.                                     (* Delete character under cursor *)
  172.            ^G        : BEGIN
  173.                           DELETE( In_String, X - Start_X + 1, 1 );
  174.                           GoToXY( Start_X , Y );
  175.                           WRITE( In_String, ' ' );
  176.                        END;
  177.  
  178.            ^M        : Done := TRUE;
  179.  
  180.            ^J        : Done := TRUE;
  181.  
  182.            ' '..'~'  : IF ( X - Start_X ) >= LENGTH( In_String ) THEN
  183.                          BEGIN
  184.                             In_String := In_String + Current_Char;
  185.                             GoToXY( X , Y );
  186.                             WRITE( Current_Char );
  187.                             IF ( X - Start_X ) < Buffer_Len THEN
  188.                                X := X + 1;
  189.                          END
  190.  
  191.                        ELSE        (* Ordinary character *)
  192.  
  193.                                    (* If insert mode ... *)
  194.                          IF Insert_Mode THEN
  195.                             BEGIN
  196.  
  197.                                INSERT( Current_Char, In_String,
  198.                                        X - Start_X + 1 );
  199.  
  200.                                In_String := COPY( In_String, 1, Buffer_Len );
  201.  
  202.                                GoToXY( Start_X, Y );
  203.                                WRITE( In_String );
  204.  
  205.                                IF ( X - Start_X ) < Buffer_Len THEN
  206.                                   X := X + 1;
  207.  
  208.                                GoToXY( X , Y );
  209.  
  210.                             END
  211.                          ELSE
  212.                            BEGIN   (* If Overwrite mode ... *)
  213.  
  214.                               In_String[ X - Start_X + 1 ] := Current_Char;
  215.  
  216.                               GoToXY( X , Y );
  217.                               WRITE( Current_Char );
  218.  
  219.                               IF ( X - Start_X ) < Buffer_Len THEN
  220.                                  X := X + 1;
  221.  
  222.                            END;
  223.  
  224.             ELSE
  225.  
  226.          END (* CASE *);
  227.  
  228.     UNTIL ( NOT Escape );
  229.  
  230.     GoToXY( X , Y );
  231.  
  232.   UNTIL Done;
  233.  
  234.   Edit_String := Current_Char;     (* Return the terminator *)
  235.   In_str      := In_string;        (* Return updated string *)
  236.  
  237. END   (* Edit_String *);