home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s3.arc / READCTRL.MOD < prev    next >
Text File  |  1987-12-07  |  3KB  |  77 lines

  1. (*----------------------------------------------------------------------*)
  2. (*         Read_Ctrls --- Fix up ctrl key definitions in string         *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. FUNCTION Read_Ctrls( S : AnyStr ) : AnyStr;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Function:   Read_Ctrls                                           *)
  10. (*                                                                      *)
  11. (*     Purpose:    Convert control sequences in strings.                *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Fixed_S := Read_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 a character sequence of the form        *)
  23. (*        '^G' -- ascii 94 + ascii 71 -- with the single control        *)
  24. (*        character ctrl-G -- ascii 07.  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.    L      : INTEGER;
  35.  
  36. BEGIN (* Read_Ctrls *)
  37.                                    (* Scan for ctrl markers *)
  38.    T    := '';
  39.    I    := 1;
  40.    J    := 0;
  41.    L    := LENGTH( S );
  42.  
  43.    WHILE( I <= L ) DO
  44.       BEGIN                        (* Ctrl marker -- convert next char *)
  45.                                    (* to control character             *)
  46.  
  47.          IF ( S[I] = FK_Ctrl_Mark ) THEN
  48.             IF ( S[I+1] <> '''' ) THEN
  49.                BEGIN               (* Process control character *)
  50.                   INC( I );
  51.                   INC( J );
  52.                   T[J] := CHR( ORD( S[I] ) - 64 );
  53.                   INC( I );
  54.                END
  55.             ELSE
  56.                BEGIN
  57.                   INC( J );
  58.                   T[J]   := S[I];
  59.                   T[J+1] := S[I+1];
  60.                   T[J+2] := S[I+2];
  61.                   INC( I , 3 );
  62.                   INC( J , 2 );
  63.                END
  64.          ELSE
  65.             BEGIN                  (* Regular character -- just copy *)
  66.                INC( J );
  67.                T[J] := S[I];
  68.                INC( I );
  69.             END;
  70.  
  71.       END;
  72.  
  73.    T[0]       := CHR( J );
  74.    Read_Ctrls := T;
  75.  
  76. END   (* Read_Ctrls *);
  77.