home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gethead.prg < prev    next >
Text File  |  1994-08-29  |  4KB  |  108 lines

  1. /*
  2.  * File......: GETHEAD.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.1
  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.  * 1.1 - 19/10/93 - Changed calls from CTOD to GT_STOD
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_GETHEADERSTRUCTURE()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      Get the header structure of a DBF file
  28.  *  $SYNTAX$
  29.  *      GT_GetHeaderStructure( cDbf , lMemoExists , dUpdated , nRecords , ;
  30.  *                             nOffset , nRecSize )
  31.  *  $ARGUMENTS$
  32.  *      cDbf        - DBF File to get header from
  33.  *      lMemoExists - Is there a memo file (passed by reference)
  34.  *      dUpdated    - Date file updated    (passed by reference)
  35.  *      nRecords    - Number of records    (passed by reference)
  36.  *      nOffset     - Data offset          (passed by reference)
  37.  *      nRecSize    - Record size          (passed by reference)
  38.  *  $RETURNS$
  39.  *      File error code when accessing table. 0 if OK
  40.  *  $DESCRIPTION$
  41.  *      Opens the given table as a binary file and gets the header info.
  42.  *  $EXAMPLES$
  43.  *
  44.  *  $SEEALSO$
  45.  *
  46.  *  $INCLUDE$
  47.  *      GT_LIB.CH
  48.  *  $END$
  49.  */
  50.  
  51. *
  52. #include "fileio.ch"
  53.  
  54. FUNCTION GT_GetHeaderStructure( cDbf , lMemoExists , dUpdated , nRecords , ;
  55.                                 nOffset , nRecSize )
  56.  
  57. /*****************************************************************************
  58.  Purpose - Get the header of the given file
  59.  Returns - File error code - 0 if OK
  60.  Author  - Martin Colloby
  61.  Created - 05/06/92
  62.  Edited  - 21/07/92 by MKC - Modified to return FERROR() code
  63. ******************************************************************************
  64.  Parameters - cDbf        - DBF File to get header from
  65.               lMemoExists - Is there a memo file (passed by reference)
  66.               dUpdated    - Date file updated    (passed by reference)
  67.               nRecords    - Number of records    (passed by reference)
  68.               nOffset     - Data offset          (passed by reference)
  69.               nRecSize    - Record size          (passed by reference)
  70.  Privates   - None
  71.  Locals     - cBuffer     - Input buffer
  72.               nHandle     - File handle of DBF
  73.  Externals  - None
  74. *****************************************************************************/
  75.  
  76. LOCAL cBuffer := SPACE( 12 )
  77. LOCAL nHandle := 0
  78.  
  79. * See if the file exists
  80. IF FILE( cDbf )
  81.     * Open the file and get handle
  82.     nHandle := FOPEN( cDbf , FO_READ )
  83.  
  84.     IF FERROR() == 0
  85.  
  86.         * Read the header into memory
  87.         FREAD( nHandle , @cBuffer , 12 )
  88.  
  89.         IF ASC( LEFT( cBuffer , 1 ) ) == 131 .OR. ;
  90.            ASC( LEFT( cBuffer , 1 ) ) == 3
  91.             lMemoExists := ( ASC( LEFT( cBuffer , 1 ) ) == 131 )
  92.             dUpdated    := GT_STOD( ALLTRIM( STR( ASC( SUBSTR( cBuffer , 2 , 1 ) ) ) ) + ;
  93.                                     ALLTRIM( STR( ASC( SUBSTR( cBuffer , 3 , 1 ) ) ) ) + ;
  94.                                     ALLTRIM( STR( ASC( SUBSTR( cBuffer , 4 , 1 ) ) ) ) )
  95.             nRecords    := BIN2L( SUBSTR( cBuffer , 5  , 4 ) )
  96.             nOffset     := BIN2W( SUBSTR( cBuffer , 9  , 2 ) )
  97.             nRecSize    := BIN2W( SUBSTR( cBuffer , 11 , 2 ) )
  98.         ENDIF
  99.     ENDIF
  100.  
  101.     * Close the file and release the handle
  102.     FCLOSE( nHandle )
  103.  
  104. ENDIF
  105.  
  106. RETURN( FERROR() )
  107. *
  108.