home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / PRTESC.PRG < prev    next >
Text File  |  1991-08-16  |  3KB  |  107 lines

  1. /*
  2.  * File......: PRTESC.PRG
  3.  * Author....: Steven Tyrakowski
  4.  * Date......: $Date:   15 Aug 1991 23:04:26  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/prtesc.prv  $
  7.  * 
  8.  * This is an original work by Steven Tyrakowski and is placed
  9.  * in the public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/prtesc.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:04:26   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:52:42   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:02:02   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27. #ifdef FT_TEST
  28.   FUNCTION MAIN( cParm1 )
  29.      *-------------------------------------------------------
  30.      * Sample routine to test function from command line
  31.      *-------------------------------------------------------
  32.  
  33.     IF PCount() > 0
  34.       ? FT_ESCCODE( cParm1 )
  35.     ELSE
  36.       ? "Usage: PRT_ESC  'escape code sequence' "
  37.       ? "            outputs converted code to  standard output"
  38.       ?
  39.     ENDIF
  40.   RETURN (nil)
  41. #endif
  42.  
  43. /*  $DOC$
  44.  *  $FUNCNAME$
  45.  *     FT_ESCCODE()
  46.  *  $CATEGORY$
  47.  *     Conversion
  48.  *  $ONELINER$
  49.  *     Convert Lotus style escape codes
  50.  *  $SYNTAX$
  51.  *     FT_ESCCODE( <cASCII> )  -> <cPrinterFormat>
  52.  *  $ARGUMENTS$
  53.  *     <cASCII> is the ASCII representation of the printer control
  54.  *        codes in Lotus 123 format (e.g. "\027E" for Chr(27)+"E")
  55.  *
  56.  *        "\nnn" will be converted to Chr(nnn)
  57.  *        "\\" will be converted to "\"
  58.  *  $RETURNS$
  59.  *     The binary version of an ASCII coded printer setup string.
  60.  *  $DESCRIPTION$
  61.  *     This function is useful for allowing the user to enter printer
  62.  *     control codes in Lotus-style ASCII format, and then having
  63.  *     this function convert that code to the format that the printer
  64.  *     needs to receive.
  65.  *  $EXAMPLES$
  66.  *     cSetup = "\015"          // default = Epson compressed print
  67.  *     UserInput( @cSetup )     // Let user modify setup code
  68.  *     SET DEVICE TO PRINT      // get ready to print
  69.  *     ?? FT_ESCCODE( cSetup )  // Output the converted code
  70.  *  $END$
  71.  */
  72.  
  73.  
  74. FUNCTION FT_ESCCODE( cInput )
  75.  
  76. LOCAL cOutput  := ""             ,;
  77.       cCurrent                     ,;
  78.       nPointer := 1              ,;
  79.       nLen       := Len( cInput )
  80.  
  81.   DO WHILE nPointer <= nLen
  82.  
  83.     cCurrent := Substr( cInput, nPointer, 1 )
  84.  
  85.     DO CASE
  86.  
  87.        CASE cCurrent == "\" .AND. ;
  88.         IsDigit(Substr(cInput, nPointer+1, 1) ) .AND. ;
  89.         IsDigit(Substr(cInput, nPointer+2, 1) ) .AND. ;
  90.         IsDigit(Substr(cInput, nPointer+3, 1) )
  91.        cOutput  += Chr(Val(Substr(cInput, nPointer+1,3)))
  92.        nPointer += 4
  93.  
  94.        CASE cCurrent == "\" .AND. ;
  95.          Substr(cInput, nPointer+1, 1) == "\"
  96.        cOutput += "\"
  97.        nPointer += 2
  98.  
  99.        OTHERWISE
  100.        cOutput += cCurrent
  101.        nPointer++
  102.  
  103.     ENDCASE
  104.   ENDDO
  105.  
  106. RETURN cOutput
  107.