home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s4.arc / WRITCTRL.MOD < prev    next >
Text File  |  1988-02-07  |  3KB  |  64 lines

  1. (*----------------------------------------------------------------------*)
  2. (*             Write_Ctrls --- Convert ctrl key defs in string          *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. FUNCTION Write_Ctrls( S : AnyStr ) : AnyStr;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Function:   Write_Ctrls                                          *)
  10. (*                                                                      *)
  11. (*     Purpose:    Convert ctrl key defs to ascii sequences             *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Fixed_S := Write_Ctrls( S: AnyStr ) : AnyStr;                 *)
  16. (*                                                                      *)
  17. (*           S       --- the string with potential ctrl seqs to convert *)
  18. (*           Fixed_S --- fixed up string                                *)
  19. (*                                                                      *)
  20. (*     Remarks:                                                         *)
  21. (*                                                                      *)
  22. (*        This routine replaces control sequences like ^G (ascii 07)    *)
  23. (*        with a two-character sequence like '^G' -- ascii 94 +         *)
  24. (*        ascii 71. The actual '^' character                            *)
  25. (*        is the global parameter FK_Ctrl_Mark and can be set with      *)
  26. (*        a configuration file.                                         *)
  27. (*                                                                      *)
  28. (*----------------------------------------------------------------------*)
  29.  
  30. VAR
  31.    T: AnyStr;
  32.    I: INTEGER;
  33.    J: INTEGER;
  34.  
  35. BEGIN (* Write_Ctrls *)
  36.                                    (* Scan for ctrl characters *)
  37.    T    := '';
  38.    J    := 0;
  39.  
  40.    FOR I := 1 TO LENGTH( S ) DO
  41.       BEGIN                        (* Ctrl char --- convert to marker  *)
  42.                                    (* plus ascii character             *)
  43.  
  44.          IF ( S[I] IN [^@..^_] ) THEN
  45.             BEGIN
  46.                INC( J );
  47.                T[J] := FK_Ctrl_Mark;
  48.                INC( J );
  49.                T[J] := CHR( ORD( S[I] ) + 64 );
  50.             END
  51.  
  52.                                    (* Regular character -- just copy *)
  53.          ELSE
  54.             BEGIN
  55.                INC( J );
  56.                T[J] := S[I];
  57.             END;
  58.       END;
  59.  
  60.    T[0]        := CHR( J );
  61.    Write_Ctrls := T;
  62.  
  63. END   (* Write_Ctrls *);
  64.