home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / MISC / FNPEEK.PRG < prev    next >
Text File  |  1993-02-23  |  3KB  |  135 lines

  1. /*
  2.  * File......: FNPEEK.PRG
  3.  * Author....: Steve Larsen
  4.  * CIS ID....: 76370,1532
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  *
  9.  * This is an original work by Steve Larsen and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19. #include "netto.ch"
  20.  
  21.  
  22.  
  23. /*  $DOC$
  24.  *  $FUNCNAME$
  25.  *      fn_PeekStr()
  26.  *  $CATEGORY$
  27.  *      Miscellaneous
  28.  *  $ONELINER$
  29.  *      Read a string of bytes from memory
  30.  *  $SYNTAX$
  31.  *
  32.  *      fn_PeekStr( <nSegment>, <nOffset>, <nLength> ) -> cBinStr
  33.  *
  34.  *  $ARGUMENTS$
  35.  *
  36.  *      <nSegment> is the memory segment to read.
  37.  *
  38.  *      <nOffset> is the starting offset from <nSegment> to read from.
  39.  *
  40.  *      <nLength> is the number of bytes to read.
  41.  *
  42.  *  $RETURNS$
  43.  *
  44.  *      A string containing the characters found at <nSegment>:<nOffset>.
  45.  *
  46.  *  $DESCRIPTION$
  47.  *
  48.  *      Use this function to perform memory reads of a contiguous block of
  49.  *      memory.  The string returned contains one character for each byte
  50.  *      of memory read.
  51.  *
  52.  *      If you plan to perform consecutive memory reads from memory, for
  53.  *      instance in filling an array, pass <nOffset> by reference to keep
  54.  *      it updated in the calling routine.
  55.  *
  56.  *  $EXAMPLES$
  57.  *
  58.  *      /* fill an array with 8-bytes taken from a block in memory */
  59.  *
  60.  *      ARRAY( aMemValues, 10 )                 // create a Clipper array
  61.  *
  62.  *          nSeg := <...>                                    // initialize pointers to
  63.  *      nOff := <...>                           //  desired memory location
  64.  *
  65.  *      AEVAL( aMemValues, {|e| e = fn_PeekStr( nSeg, @nOff, 8 ) }
  66.  *
  67.  *  $SEEALSO$
  68.  *      fn_PokeStr()
  69.  *  $INCLUDE$
  70.  *
  71.  *  $END$
  72.  */
  73.  
  74. FUNCTION fn_PeekStr( nSeg, nOff, nLen )
  75.     LOCAL cRetVal := "", i
  76.     FOR i := 1 TO nLen
  77.         cRetVal += I2BYTE( ft_Peek( nSeg, nOff++ ) )
  78.     NEXT
  79. RETURN cRetVal
  80.  
  81. /*  $DOC$
  82.  *  $FUNCNAME$
  83.  *      fn_PokeStr()
  84.  *  $CATEGORY$
  85.  *      Miscellaneous
  86.  *  $ONELINER$
  87.  *      Write a string of bytes to memory
  88.  *  $SYNTAX$
  89.  *
  90.  *      fn_PokeStr( <nSegment>, <nOffset>, <cBinStr> ) -> NIL
  91.  *
  92.  *  $ARGUMENTS$
  93.  *
  94.  *      <nSegment> is the memory segment to write to.
  95.  *
  96.  *      <nOffset> is the starting offset from <nSegment> to write at.
  97.  *
  98.  *      <cBinStr> is a string of bytes to write.
  99.  *
  100.  *  $RETURNS$
  101.  *
  102.  *      Nothing.
  103.  *
  104.  *  $DESCRIPTION$
  105.  *
  106.  *      Use this function to perform memory write to a contiguous block of
  107.  *      memory.  
  108.  *
  109.  *      If you plan to perform consecutive memory write to memory, for
  110.  *      instance in copying an array of binary strings to memory, pass 
  111.  *      <nOffset> by reference to keep it updated in the calling routine.
  112.  *
  113.  *  $EXAMPLES$
  114.  *
  115.  *      /* write an array to a block in memory */
  116.  *
  117.  *          nSeg := <...>                                    // initialize pointers to
  118.  *      nOff := <...>                           //  desired memory location
  119.  *
  120.  *      AEVAL( aMemValues, {|e| fn_PokeStr( nSeg, @nOff, e ) }
  121.  *
  122.  *  $SEEALSO$
  123.  *      fn_PeekStr()
  124.  *  $INCLUDE$
  125.  *
  126.  *  $END$
  127.  */
  128.  
  129. FUNCTION fn_PokeStr( nSeg, nOff, cStr )
  130.     LOCAL i
  131.     FOR i := 1 TO LEN( cStr )
  132.         ft_Poke( nSeg, nOff++, BYTE2I( SUBST( cStr, i, 1 ) ) )
  133.     NEXT
  134. RETURN nil
  135.