home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / getindex.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  103 lines

  1. /*
  2.  * File......: GETINDEX.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_GETINDEXKEY()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      Get the key of a Clipper index
  28.  *  $SYNTAX$
  29.  *      GT_GetIndexKey( cIndex, cKey )
  30.  *  $ARGUMENTS$
  31.  *      cIndex - Index file to get from
  32.  *      cKey   - Key to be returned (passed by reference)
  33.  *  $RETURNS$
  34.  *      File error code - 0 if OK
  35.  *  $DESCRIPTION$
  36.  *      Opens the given index file as a binary file, and retrieves the key
  37.  *  $EXAMPLES$
  38.  *
  39.  *  $SEEALSO$
  40.  *
  41.  *  $INCLUDE$
  42.  *      GT_LIB.CH
  43.  *  $END$
  44.  */
  45.  
  46. *
  47. #include "gt_lib.ch"
  48.  
  49. FUNCTION GT_GetIndexKey( cIndex, cKey )
  50.  
  51. /*****************************************************************************
  52.  Purpose - Read the key from an index file
  53.  Returns - File error code - 0 if OK
  54.  Author  - Martin Colloby
  55.  Created - 05/06/92
  56.  Edited  - 21/07/92 by MKC - Modified to return FERROR() code
  57. ******************************************************************************
  58.  Parameters - cIndex - Index file to get from
  59.               cKey   - Key to be returned (passed by reference)
  60.  Privates   - None
  61.  Locals     - cString - Temporary storage string
  62.               cBuffer - Buffer containing index file header
  63.               nHandle - File handle of index file
  64.               nPos    - Position of key in header
  65.  Externals  - None
  66. ******************************************************************************
  67.  N.B. This function assumes a valid index file
  68.  
  69.  nPos = 23 for Clipper NTX files
  70.  nPos = 25 for dBase NDX files
  71. *****************************************************************************/
  72.  
  73. LOCAL cBuffer := SPACE( 512 )
  74. LOCAL cString := ""
  75. LOCAL nHandle := ""
  76. LOCAL nPos    := 23
  77.  
  78. * See if the file exists
  79. IF FILE( cIndex )
  80.     * Open the file and get handle
  81.     nHandle := FOPEN( cIndex , FO_READ )
  82.  
  83.     IF FERROR() == 0
  84.         * Allocate 512 byte buffer
  85.  
  86.         * Read the index file header into memory
  87.         FREAD( nHandle , @cBuffer , 512 )
  88.  
  89.         * Discard all bytes before the key expression
  90.         cString := SUBSTR( cBuffer , nPos )
  91.  
  92.         * The expression is terminated with a zero byte (chr(0))
  93.         cKey := TRIM( SUBSTR( cString , 1 , AT( CHR(0) , cString ) - 1 ) )
  94.     ENDIF
  95.  
  96.     * Close the file and release the handle
  97.     FCLOSE( nHandle )
  98.  
  99. ENDIF
  100.  
  101. RETURN( FERROR() )
  102. *
  103.