dbffpt

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  
c:\harbour\source\rdd\dbffpt
dbffpt1.c
TypeFunctionSourceLine
STATIC ERRCODEhb_memoErrorRT( FPTAREAP pArea, USHORT uiGenCode, USHORT uiSubCode, char * szFileName, USHORT uiOsCode, USHORT uiFlags )
static ERRCODE hb_memoErrorRT( FPTAREAP pArea, USHORT uiGenCode, USHORT uiSubCode, char * szFileName, USHORT uiOsCode, USHORT uiFlags )
{
   ERRCODE errCode = FAILURE;

   if( hb_vmRequestQuery() == 0 )
   {
      PHB_ITEM pError = hb_errNew();

      if( uiGenCode == 0 )
         uiGenCode = hb_dbfGetEGcode( uiSubCode );
      if( uiOsCode == 0 && uiSubCode != EDBF_DATATYPE && uiSubCode != EDBF_DATAWIDTH )
         uiOsCode = hb_fsError();

      hb_errPutGenCode( pError, uiGenCode );
      hb_errPutSubCode( pError, uiSubCode );
      if( uiOsCode )
         hb_errPutOsCode( pError, uiOsCode );
      hb_errPutDescription( pError, hb_langDGetErrorDesc( uiGenCode ) );
      if( szFileName )
         hb_errPutFileName( pError, szFileName );
      if( uiFlags )
         hb_errPutFlags( pError, uiFlags );
      errCode = SELF_ERROR( ( AREAP ) pArea, pError );
      hb_errRelease( pError );
   }
   return errCode;
}
dbffpt1.c235
STATIC CONST CHAR *hb_memoDefaultFileExt( int iType, USHORT uiRdd )
static const char * hb_memoDefaultFileExt( int iType, USHORT uiRdd )
{
   if( uiRdd == s_uiRddIdBLOB )
      return DBV_MEMOEXT;

   switch( iType )
   {
      case DB_MEMO_DBT:
         return DBT_MEMOEXT;
      case DB_MEMO_FPT:
         return FPT_MEMOEXT;
      case DB_MEMO_SMT:
         return SMT_MEMOEXT;
   }
   return NULL;
}
dbffpt1.c267
STATIC BOOLhb_fptFileLockEx( FPTAREAP pArea, BOOL fWait )
static BOOL hb_fptFileLockEx( FPTAREAP pArea, BOOL fWait )
{
   BOOL fRet;

   if( !pArea->fShared )
   {
      fRet = TRUE;
   }
   else
   {
      for( ;; )
      {
         fRet = hb_fileLock( pArea->pMemoFile, FPT_LOCKPOS, FPT_LOCKSIZE,
                             FL_LOCK | FLX_EXCLUSIVE | ( fWait ? FLX_WAIT : 0 ) );
         if( fRet || !fWait )
            break;
         hb_releaseCPU();
      }
   }
   return fRet;
}
dbffpt1.c284
STATIC BOOLhb_fptFileLockSh( FPTAREAP pArea, BOOL fWait )
static BOOL hb_fptFileLockSh( FPTAREAP pArea, BOOL fWait )
{
   BOOL fRet;

   if( !pArea->fShared )
   {
      fRet = TRUE;
   }
   else
   {
      for( ;; )
      {
         fRet = hb_fileLock( pArea->pMemoFile, FPT_LOCKPOS, FPT_LOCKSIZE,
                             FL_LOCK | FLX_SHARED | ( fWait ? FLX_WAIT : 0 ) );
         if( fRet || !fWait )
            break;
         hb_releaseCPU();
      }
   }
   return fRet;
}
dbffpt1.c314
STATIC BOOLhb_fptFileUnLock( FPTAREAP pArea )
static BOOL hb_fptFileUnLock( FPTAREAP pArea )
{
   return !pArea->fShared || hb_fileLock( pArea->pMemoFile, FPT_LOCKPOS, FPT_LOCKSIZE, FL_UNLOCK );
}
dbffpt1.c336
STATIC BOOLhb_fptHasDirectAccess( FPTAREAP pArea )
static BOOL hb_fptHasDirectAccess( FPTAREAP pArea )
{
   return pArea->bMemoType == DB_MEMO_FPT &&
          ( pArea->uiMemoVersion == DB_MEMOVER_FLEX ||
            pArea->uiMemoVersion == DB_MEMOVER_CLIP );
}
dbffpt1.c344
STATIC BOOLhb_fptRootBlockLock( FPTAREAP pArea )
static BOOL hb_fptRootBlockLock( FPTAREAP pArea )
{
   BOOL fRet;

   if( !pArea->fShared )
      fRet = TRUE;
   else
      fRet = hb_fileLock( pArea->pMemoFile, FPT_ROOTBLOCK_OFFSET, 4,
                          FL_LOCK | FLX_EXCLUSIVE );
   return fRet;
}
dbffpt1.c354
STATIC BOOLhb_fptRootBlockUnLock( FPTAREAP pArea )
static BOOL hb_fptRootBlockUnLock( FPTAREAP pArea )
{
   return !pArea->fShared ||
          hb_fileLock( pArea->pMemoFile, FPT_ROOTBLOCK_OFFSET, 4, FL_UNLOCK );
}
dbffpt1.c369
STATIC ERRCODEhb_fptGetRootBlock( FPTAREAP pArea, ULONG * pulBlock )
static ERRCODE hb_fptGetRootBlock( FPTAREAP pArea, ULONG * pulBlock )
{
   *pulBlock = 0;

   if( hb_fptHasDirectAccess( pArea ) )
   {
      BYTE buffer[ 4 ];

      if( hb_fileReadAt( pArea->pMemoFile, buffer, 4, FPT_ROOTBLOCK_OFFSET ) == 4 )
      {
         *pulBlock = HB_GET_LE_UINT32( buffer );
         return SUCCESS;
      }
      else
         return EDBF_READ;
   }
   return EDBF_UNSUPPORTED;
}
dbffpt1.c378
STATIC ERRCODEhb_fptPutRootBlock( FPTAREAP pArea, ULONG ulBlock )
static ERRCODE hb_fptPutRootBlock( FPTAREAP pArea, ULONG ulBlock )
{
   if( hb_fptHasDirectAccess( pArea ) )
   {
      BYTE buffer[ 4 ];

      HB_PUT_LE_UINT32( buffer, ulBlock );
      if( hb_fileWriteAt( pArea->pMemoFile, buffer, 4, FPT_ROOTBLOCK_OFFSET ) == 4 )
         return SUCCESS;
      else
         return EDBF_WRITE;
   }
   return EDBF_UNSUPPORTED;
}
dbffpt1.c400
STATIC VOIDhb_fptSortGCitems( LPMEMOGCTABLE pGCtable )
static void hb_fptSortGCitems( LPMEMOGCTABLE pGCtable )
{
   ULONG ulOffset, ulSize;
   BOOL fMoved = TRUE;
   int i, j, l;

   /* this table should be allready quite good sorted so this simple
      algorithms will be the most efficient one.
      It will need only one or two passes */
   l = pGCtable->usItems - 1;
   while( fMoved )
   {
      fMoved = FALSE;
      j = l;
      for( i = 0; i < j; i++ )
      {
         if( pGCtable->pGCitems[i].ulSize > pGCtable->pGCitems[i+1].ulSize )
         {
            ulOffset = pGCtable->pGCitems[i+1].ulOffset;
            ulSize = pGCtable->pGCitems[i+1].ulSize;
            pGCtable->pGCitems[i+1].ulSize   = pGCtable->pGCitems[i].ulSize;
            pGCtable->pGCitems[i+1].ulOffset = pGCtable->pGCitems[i].ulOffset;
            pGCtable->pGCitems[ i ].ulSize   = ulSize;
            pGCtable->pGCitems[ i ].ulOffset = ulOffset;
            fMoved = TRUE;
            pGCtable->bChanged |= 2;
            l = i;
         }
      }
   }
}
dbffpt1.c488
STATIC VOIDhb_fptPackGCitems( LPMEMOGCTABLE pGCtable )
static void hb_fptPackGCitems( LPMEMOGCTABLE pGCtable )
{
   ULONG ulEnd;
   int i, j;

   /* TODO: better alogrithm this primitve one can be too slow for big
      free block list table */
   for( i = 0; i < pGCtable->usItems; i++ )
   {
      if( pGCtable->pGCitems[i].ulOffset != 0 &&
          pGCtable->pGCitems[i].ulSize != 0 )
      {
         ulEnd = pGCtable->pGCitems[i].ulOffset + pGCtable->pGCitems[i].ulSize;
         if( ulEnd == pGCtable->ulNextBlock )
         {
            pGCtable->ulNextBlock -= pGCtable->pGCitems[i].ulSize;
            pGCtable->pGCitems[i].ulOffset = pGCtable->pGCitems[i].ulSize = 0;
            pGCtable->bChanged |= 2;
            i = -1;
         }
         else
         {
            for( j = i + 1; j < pGCtable->usItems; j++ )
            {
               if( ulEnd == pGCtable->pGCitems[j].ulOffset )
               {
                  pGCtable->pGCitems[i].ulSize += pGCtable->pGCitems[j].ulSize;
                  pGCtable->pGCitems[j].ulOffset = pGCtable->pGCitems[j].ulSize = 0;
                  pGCtable->bChanged |= 2;
                  i = -1;
                  break;
               }
            }
         }
      }
   }

   /* remove empty items */
   for( i = j = 0; i < pGCtable->usItems; i++ )
   {
      if( pGCtable->pGCitems[i].ulOffset != 0 &&
          pGCtable->pGCitems[i].ulSize != 0 )
      {
         if( i > j )
         {
            pGCtable->pGCitems[j].ulOffset = pGCtable->pGCitems[i].ulOffset;
            pGCtable->pGCitems[j].ulSize   = pGCtable->pGCitems[i].ulSize;
         }
         j++;
      }
   }
   pGCtable->usItems = j;
}
dbffpt1.c523
STATIC ERRCODEhb_fptWriteGCitems( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, USHORT usItem )
static ERRCODE hb_fptWriteGCitems( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, USHORT usItem )
{
   FPTBLOCK fptBlock;
   ERRCODE errCode = SUCCESS;
   int i /* ,iStart, iStop */;

   HB_SYMBOL_UNUSED( usItem );

/*
   if( usItem == 0 )
   {
      iStart = 0;
      iStop = pGCtable->usItems;
   }
   else
   {
      iStart = usItem;
      iStop = usItem + 1;
   }
*/

   for( i = 0; i < pGCtable->usItems; i++ )
   {
      if( pGCtable->pGCitems[i].fChanged )
      {
         if( pArea->uiMemoVersion == DB_MEMOVER_FLEX ||
             pArea->uiMemoVersion == DB_MEMOVER_CLIP )
         {
            HB_PUT_BE_UINT32( fptBlock.type, FPTIT_FLEX_UNUSED );
            HB_PUT_BE_UINT32( fptBlock.size, pArea->uiMemoBlockSize *
                              pGCtable->pGCitems[i].ulSize - sizeof( FPTBLOCK ) );
            if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                                sizeof( FPTBLOCK ),
                                FPT_BLOCK_OFFSET( pGCtable->pGCitems[i].ulOffset ) ) !=
                sizeof( FPTBLOCK ) )
            {
               errCode = EDBF_WRITE;
            }
            pArea->fMemoFlush = TRUE;
         }
         pGCtable->pGCitems[i].fChanged = FALSE;
      }
   }
   return errCode;
}
dbffpt1.c580
STATIC ERRCODEhb_fptGCfreeBlock( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, ULONG ulOffset, ULONG ulByteSize, BOOL fRaw )
static ERRCODE hb_fptGCfreeBlock( FPTAREAP pArea, LPMEMOGCTABLE pGCtable,
                                  ULONG ulOffset, ULONG ulByteSize, BOOL fRaw )
{
   ERRCODE errCode = SUCCESS;
   ULONG ulSize;

   if( pArea->bMemoType == DB_MEMO_DBT )
   {
      return SUCCESS;
   }
   else if( pArea->bMemoType == DB_MEMO_FPT && !fRaw )
   {
      if( ulByteSize == 0 )
      {
         FPTBLOCK fptBlock;

         if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                            sizeof( FPTBLOCK ), FPT_BLOCK_OFFSET( ulOffset ) ) ==
             sizeof( FPTBLOCK ) )
         {
            ulByteSize = HB_GET_BE_UINT32( fptBlock.size ) + sizeof( FPTBLOCK );
         }
      }
      else
      {
         ulByteSize += sizeof( FPTBLOCK );
      }
   }

   ulSize = ( ulByteSize + pArea->uiMemoBlockSize - 1 ) / pArea->uiMemoBlockSize;

   if( ulSize == 0 )
   {
      return EDBF_CORRUPT;
   }

   if( ulOffset + ulSize == pGCtable->ulNextBlock )
   {
      pGCtable->ulNextBlock -= ulSize;
      pGCtable->bChanged |= 1;
      hb_fptPackGCitems( pGCtable );
   }
   else
   {
      BOOL fChanged = FALSE;
      int i;

      for( i = 0; i < pGCtable->usItems; i++ )
      {
         if( pGCtable->pGCitems[i].ulOffset + pGCtable->pGCitems[i].ulSize == ulOffset )
         {
            ulOffset = pGCtable->pGCitems[i].ulOffset;
            ulSize   = pGCtable->pGCitems[i].ulSize += ulSize;
            fChanged = pGCtable->pGCitems[i].fChanged = TRUE;
            break;
         }
         if( pGCtable->pGCitems[i].ulOffset == ulOffset + ulSize )
         {
            pGCtable->pGCitems[i].ulOffset = ulOffset;
            ulSize   = pGCtable->pGCitems[i].ulSize += ulSize;
            fChanged = pGCtable->pGCitems[i].fChanged = TRUE;
            break;
         }
      }
      if( !fChanged )
      {
         if( pGCtable->usItems <= pGCtable->usMaxItem )
         {
            if( pGCtable->pGCitems == NULL )
            {
               pGCtable->pGCitems = ( LPMEMOGCITEM ) hb_xgrab( sizeof( MEMOGCITEM ) * ( pGCtable->usMaxItem + 1 ) );
            }
            pGCtable->pGCitems[ pGCtable->usItems ].ulOffset = ulOffset;
            pGCtable->pGCitems[ pGCtable->usItems ].ulSize = ulSize;
            pGCtable->pGCitems[ pGCtable->usItems ].fChanged = fChanged = TRUE;
            pGCtable->usItems++;
         }
         else if( pGCtable->pGCitems[ 0 ].ulSize < ulSize )
         {
            if( pGCtable->ulNextBlock == pGCtable->pGCitems[ 0 ].ulOffset +
                                         pGCtable->pGCitems[ 0 ].ulSize )
            {
               pGCtable->ulNextBlock -= pGCtable->pGCitems[ 0 ].ulSize;
            }
            else if( pGCtable->pGCitems[ 0 ].fChanged )
            {
               errCode = hb_fptWriteGCitems( pArea, pGCtable, 0 );
            }
            pGCtable->pGCitems[ 0 ].ulOffset = ulOffset;
            pGCtable->pGCitems[ 0 ].ulSize = ulSize;
            pGCtable->pGCitems[ 0 ].fChanged = fChanged = TRUE;
         }
      }

      if( fChanged )
      {
         pGCtable->bChanged |= 2;
         hb_fptPackGCitems( pGCtable );
         hb_fptSortGCitems( pGCtable );
      }
   }

   return errCode;
}
dbffpt1.c629
STATIC ERRCODEhb_fptGCgetFreeBlock( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, ULONG * ulOffset, ULONG ulByteSize, BOOL fRaw )
static ERRCODE hb_fptGCgetFreeBlock( FPTAREAP pArea, LPMEMOGCTABLE pGCtable,
                                     ULONG * ulOffset, ULONG ulByteSize,
                                     BOOL fRaw )
{
   BOOL fAlloc = FALSE;
   ULONG ulSize;
   int i;


   if( pArea->bMemoType == DB_MEMO_SMT || fRaw )
   {
      ulSize = ( ulByteSize + pArea->uiMemoBlockSize - 1 ) /
               pArea->uiMemoBlockSize;
   }
   else if( pArea->bMemoType == DB_MEMO_FPT )
   {
      ulSize = ( ulByteSize + sizeof( FPTBLOCK ) + pArea->uiMemoBlockSize - 1 ) /
               pArea->uiMemoBlockSize;
   }
   else if( pArea->bMemoType == DB_MEMO_DBT )
   {
      ulSize = ( ulByteSize + pArea->uiMemoBlockSize ) /
               pArea->uiMemoBlockSize;
   }
   else
   {
      ulSize = ( ulByteSize + pArea->uiMemoBlockSize - 1 ) /
               pArea->uiMemoBlockSize;
   }

   for( i = 0; i < pGCtable->usItems; i++ )
   {
      if( pGCtable->pGCitems[i].ulSize >= ulSize )
      {
         *ulOffset = pGCtable->pGCitems[i].ulOffset;
         pGCtable->pGCitems[i].ulOffset += ulSize;
         pGCtable->pGCitems[i].ulSize -= ulSize;
         if( pGCtable->pGCitems[i].ulSize == 0 )
         {
            while( ++i < pGCtable->usItems )
            {
               pGCtable->pGCitems[i-1].ulOffset = pGCtable->pGCitems[i].ulOffset;
               pGCtable->pGCitems[i-1].ulSize   = pGCtable->pGCitems[i].ulSize;
            }
            pGCtable->usItems--;
         }
         else
         {
            pGCtable->pGCitems[i].fChanged = TRUE;
            hb_fptSortGCitems( pGCtable );
         }
         pGCtable->bChanged |= 2;
         fAlloc = TRUE;
         break;
      }
   }
   if( !fAlloc )
   {
      *ulOffset = pGCtable->ulNextBlock;
      pGCtable->ulNextBlock += ulSize;
      pGCtable->bChanged |= 1;
   }
   return SUCCESS;
}
dbffpt1.c737
STATIC VOIDhb_fptInitGCdata( LPMEMOGCTABLE pGCtable )
static void hb_fptInitGCdata( LPMEMOGCTABLE pGCtable )
{
   memset( pGCtable, 0, sizeof(MEMOGCTABLE) );
}
dbffpt1.c805
STATIC VOIDhb_fptDestroyGCdata( LPMEMOGCTABLE pGCtable )
static void hb_fptDestroyGCdata( LPMEMOGCTABLE pGCtable )
{
   if( pGCtable->pGCitems != NULL )
   {
      hb_xfree( pGCtable->pGCitems );
      pGCtable->pGCitems = NULL;
      pGCtable->usItems = 0;
   }
   pGCtable->bChanged = 0;
}
dbffpt1.c813
STATIC ERRCODEhb_fptReadGCdata( FPTAREAP pArea, LPMEMOGCTABLE pGCtable )
static ERRCODE hb_fptReadGCdata( FPTAREAP pArea, LPMEMOGCTABLE pGCtable )
{
   int i;

   hb_fptDestroyGCdata( pGCtable );
   memset( &pGCtable->fptHeader, 0, sizeof( FPTHEADER ) );

   if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &pGCtable->fptHeader,
                      sizeof( FPTHEADER ), 0 ) >= 512 )
   {
      if( pArea->bMemoType == DB_MEMO_SMT || pArea->bMemoType == DB_MEMO_DBT )
         pGCtable->ulNextBlock = HB_GET_LE_UINT32( pGCtable->fptHeader.nextBlock );
      else
         pGCtable->ulNextBlock = HB_GET_BE_UINT32( pGCtable->fptHeader.nextBlock );
      pGCtable->ulPrevBlock = pGCtable->ulNextBlock;

      if( pArea->uiMemoVersion == DB_MEMOVER_SIX ||
           pArea->bMemoType == DB_MEMO_SMT )
      {
         pGCtable->bType = DB_MEMOVER_SIX;
         pGCtable->usMaxItem = MAX_SIXFREEBLOCKS;
         pGCtable->usItems = HB_GET_LE_UINT16( pGCtable->fptHeader.nGCitems );
         if( pGCtable->usItems > pGCtable->usMaxItem )
         {
            return EDBF_CORRUPT;
         }

         pGCtable->pGCitems = ( LPMEMOGCITEM ) hb_xgrab( sizeof( MEMOGCITEM ) * ( pGCtable->usMaxItem + 1 ) );

         for( i = 0; i < pGCtable->usItems; i++ )
         {
            pGCtable->pGCitems[i].ulSize = HB_GET_LE_UINT16( &pGCtable->fptHeader.reserved2[ i * 6 ] );
            pGCtable->pGCitems[i].ulOffset = HB_GET_LE_UINT32( &pGCtable->fptHeader.reserved2[ i * 6 + 2 ] );
            pGCtable->pGCitems[i].fChanged = FALSE;
         }
      }
      else if( pArea->bMemoType == DB_MEMO_FPT &&
               ( pArea->uiMemoVersion == DB_MEMOVER_FLEX ||
                 pArea->uiMemoVersion == DB_MEMOVER_CLIP ) )
      {
         FPTBLOCK fptBlock;
         BYTE *bPageBuf;

         pGCtable->bType = DB_MEMOVER_FLEX;
         pGCtable->usMaxItem = MAX_FLEXFREEBLOCKS;
         pGCtable->ulRevPage = HB_GET_LE_UINT32( pGCtable->fptHeader.flexRev );
         pGCtable->ulDirPage = HB_GET_LE_UINT32( pGCtable->fptHeader.flexDir );
         pGCtable->ulCounter = HB_GET_LE_UINT32( pGCtable->fptHeader.counter );
         if( pGCtable->ulDirPage )
         {
            if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                               sizeof( FPTBLOCK ), pGCtable->ulDirPage ) !=
                sizeof( FPTBLOCK ) ||
                HB_GET_BE_UINT32( fptBlock.type ) != FPTIT_FLEX_GC )
            {
               return EDBF_CORRUPT;
            }
            pGCtable->ulSize = HB_GET_BE_UINT32( fptBlock.size );
            bPageBuf = ( BYTE * ) hb_xgrab( pGCtable->ulSize );
            if( hb_fileReadAt( pArea->pMemoFile, bPageBuf,
                               pGCtable->ulSize,
                               pGCtable->ulDirPage + sizeof( FPTBLOCK ) ) !=
                pGCtable->ulSize )
            {
               hb_xfree( bPageBuf );
               return EDBF_CORRUPT;
            }
            pGCtable->usMaxItem = ( USHORT ) ( ( pGCtable->ulSize - 2 ) >> 3 );
            pGCtable->usItems = ( HB_GET_LE_UINT16( bPageBuf ) - 3 ) >> 2;

            pGCtable->pGCitems = ( LPMEMOGCITEM ) hb_xgrab( sizeof( MEMOGCITEM ) *
                     ( HB_MIN( pGCtable->usItems, pGCtable->usMaxItem ) + 1 ) );

            for( i = 0; i < pGCtable->usItems; i++ )
            {
               pGCtable->pGCitems[i].ulOffset = HB_GET_LE_UINT32( &bPageBuf[ i * 8 + 2 ] ) /
                                                      pArea->uiMemoBlockSize;
               pGCtable->pGCitems[i].ulSize = HB_GET_LE_UINT32( &bPageBuf[ i * 8 + 6 ] ) /
                                                      pArea->uiMemoBlockSize;
               pGCtable->pGCitems[i].fChanged = FALSE;
            }
            hb_xfree( bPageBuf );
         }
      }

      if( pGCtable->pGCitems )
      {
         hb_fptSortGCitems( pGCtable );
      }

      return SUCCESS;
   }
   return EDBF_READ;
}
dbffpt1.c827
STATIC ERRCODEhb_fptWriteGCdata( FPTAREAP pArea, LPMEMOGCTABLE pGCtable )
static ERRCODE hb_fptWriteGCdata( FPTAREAP pArea, LPMEMOGCTABLE pGCtable )
{
   ERRCODE errCode = SUCCESS;
   ULONG ulHdrSize = 512;
   int i, j;

   if( pGCtable->bChanged > 0 )
   {
      if( pGCtable->bType == DB_MEMOVER_SIX )
      {
         USHORT usItems = HB_MIN( pGCtable->usItems, pGCtable->usMaxItem );
         HB_PUT_LE_UINT16( pGCtable->fptHeader.nGCitems, usItems );
         memset( pGCtable->fptHeader.reserved2, 0, sizeof( pGCtable->fptHeader.reserved2 ) );
         j = pGCtable->usItems - usItems;
         for( i = j; i < pGCtable->usItems; i++ )
         {
            HB_PUT_LE_UINT16( &pGCtable->fptHeader.reserved2[ ( i - j ) * 6 ],
                              ( ( USHORT ) pGCtable->pGCitems[i].ulSize ) );
            HB_PUT_LE_UINT32( &pGCtable->fptHeader.reserved2[ ( i - j ) * 6 + 2 ],
                              pGCtable->pGCitems[i].ulOffset );
         }
      }
      else if( pGCtable->bType == DB_MEMOVER_FLEX )
      {
         ulHdrSize = sizeof( FPTHEADER );
         pGCtable->ulCounter++;
         if( pGCtable->usItems == 0 && pGCtable->ulDirPage )
         {
            ULONG ulOffset = pGCtable->ulDirPage;
            ULONG ulSize = ( pGCtable->ulSize + pArea->uiMemoBlockSize - 1 ) /
                           pArea->uiMemoBlockSize;
            if( pGCtable->ulRevPage )
            {
               ulSize <<= 1;
               if( pGCtable->ulDirPage > pGCtable->ulRevPage )
               {
                  ulOffset = pGCtable->ulRevPage;
               }
            }
            ulOffset /= pArea->uiMemoBlockSize;
            if( ulOffset + ulSize == pGCtable->ulNextBlock )
            {
               pGCtable->ulDirPage = pGCtable->ulRevPage = 0;
               pGCtable->ulNextBlock -= ulSize;
            }
         }
         else if( pGCtable->usItems > 0 && ! pGCtable->ulDirPage )
         {
            pGCtable->ulSize = FLEXGCPAGE_SIZE;
            errCode = hb_fptGCgetFreeBlock( pArea, pGCtable,
                                &pGCtable->ulDirPage, pGCtable->ulSize, FALSE );
            if( errCode == SUCCESS )
            {
               pGCtable->ulDirPage *= pArea->uiMemoBlockSize;
               errCode = hb_fptGCgetFreeBlock( pArea, pGCtable,
                                &pGCtable->ulRevPage, pGCtable->ulSize, FALSE );
               pGCtable->ulRevPage *= pArea->uiMemoBlockSize;
            }
            pGCtable->bChanged |= 2;
         }
         if( pGCtable->ulDirPage && pGCtable->bChanged > 1 )
         {
            FPTBLOCK fptBlock;
            BYTE *bPageBuf;
            USHORT usItems = HB_MIN( pGCtable->usItems, pGCtable->usMaxItem );

            HB_PUT_BE_UINT32( fptBlock.type, FPTIT_FLEX_GC );
            HB_PUT_BE_UINT32( fptBlock.size, pGCtable->ulSize );
            bPageBuf = ( BYTE * ) hb_xgrab( pGCtable->ulSize );
            memset( bPageBuf, 0xAD, pGCtable->ulSize );
            HB_PUT_LE_UINT16( bPageBuf, ( ( USHORT ) usItems << 2 ) + 3 );
            j = pGCtable->usItems - usItems;
            for( i = j; i < pGCtable->usItems; i++ )
            {
               HB_PUT_LE_UINT32( &bPageBuf[ ( i - j ) * 8 + 2 ],
                                pGCtable->pGCitems[i].ulOffset * pArea->uiMemoBlockSize );
               HB_PUT_LE_UINT32( &bPageBuf[ ( i - j ) * 8 + 6 ],
                                pGCtable->pGCitems[i].ulSize * pArea->uiMemoBlockSize );
            }
            if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                                sizeof( FPTBLOCK ), pGCtable->ulDirPage ) !=
                sizeof( FPTBLOCK ) ||
                hb_fileWriteAt( pArea->pMemoFile, bPageBuf, pGCtable->ulSize,
                                pGCtable->ulDirPage + sizeof( FPTBLOCK ) ) !=
                pGCtable->ulSize )
            {
               errCode = EDBF_WRITE;
            }
            else if( pGCtable->ulRevPage )
            {
               for( i = j; i < pGCtable->usItems; i++ )
               {
                  HB_PUT_LE_UINT32( &bPageBuf[ ( i - j ) * 8 + 2 ],
                                   ( ( USHORT ) pGCtable->pGCitems[i].ulSize * pArea->uiMemoBlockSize ) );
                  HB_PUT_LE_UINT32( &bPageBuf[ ( i - j ) * 8 + 6 ],
                                   pGCtable->pGCitems[i].ulOffset * pArea->uiMemoBlockSize );
               }
               if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                                   sizeof( FPTBLOCK ), pGCtable->ulRevPage ) !=
                   sizeof( FPTBLOCK ) ||
                   hb_fileWriteAt( pArea->pMemoFile, bPageBuf, pGCtable->ulSize,
                                   pGCtable->ulRevPage + sizeof( FPTBLOCK ) ) !=
                   pGCtable->ulSize )
               {
                  errCode = EDBF_WRITE;
               }
            }
            hb_xfree( bPageBuf );
         }
         HB_PUT_LE_UINT32( pGCtable->fptHeader.flexRev, pGCtable->ulRevPage );
         HB_PUT_LE_UINT32( pGCtable->fptHeader.flexDir, pGCtable->ulDirPage );
         HB_PUT_LE_UINT32( pGCtable->fptHeader.counter, pGCtable->ulCounter );
      }

      if( pGCtable->bChanged > 1 && errCode == SUCCESS )
      {
         errCode = hb_fptWriteGCitems( pArea, pGCtable, 0 );
      }
      if( errCode == SUCCESS )
      {
         if( pArea->bMemoType == DB_MEMO_SMT || pArea->bMemoType == DB_MEMO_DBT )
            HB_PUT_LE_UINT32( pGCtable->fptHeader.nextBlock, pGCtable->ulNextBlock );
         else
            HB_PUT_BE_UINT32( pGCtable->fptHeader.nextBlock, pGCtable->ulNextBlock );
         if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &pGCtable->fptHeader,
                             ulHdrSize, 0 ) != ulHdrSize )
         {
            errCode = EDBF_WRITE;
         }
         else if( pGCtable->ulNextBlock < pGCtable->ulPrevBlock )
         {
            /* trunc file */
            hb_fileTruncAt( pArea->pMemoFile, FPT_BLOCK_OFFSET( pGCtable->ulNextBlock ) );
         }
      }
      pArea->fMemoFlush = TRUE;
      pGCtable->bChanged = 0;
   }
   return errCode;
}
dbffpt1.c925
STATIC ULONGhb_fptGetMemoLen( FPTAREAP pArea, USHORT uiIndex )
static ULONG hb_fptGetMemoLen( FPTAREAP pArea, USHORT uiIndex )
{
   ULONG ulBlock, ulSize, ulType;
   FPTBLOCK fptBlock;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetMemoLen(%p, %hu)", pArea, uiIndex));

   if( hb_dbfGetMemoData( ( DBFAREAP ) pArea, uiIndex - 1, &ulBlock, &ulSize,
                          &ulType ) == SUCCESS )
   {
      if( ulBlock != 0 )
      {
         if( ulSize == 0 && ( pArea->bMemoType == DB_MEMO_DBT ||
                              pArea->bMemoType == DB_MEMO_FPT ) )
         {
            HB_FOFFSET fOffset = FPT_BLOCK_OFFSET( ulBlock );
            if( pArea->bMemoType == DB_MEMO_DBT )
            {
               BYTE pBlock[ DBT_DEFBLOCKSIZE ];
               ULONG ulLen, u;

               do
               {
                  ulLen = hb_fileReadAt( pArea->pMemoFile, pBlock, DBT_DEFBLOCKSIZE, fOffset );
                  fOffset += ulLen;
                  if( ulLen <= 0 )
                     break;
                  u = 0;
                  while( u < ulLen && pBlock[ u ] != 0x1A )
                     u++;
                  ulSize += u;
               } while( u == DBT_DEFBLOCKSIZE );
            }
            else if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                                    sizeof( FPTBLOCK ), fOffset ) ==
                     sizeof( FPTBLOCK ) )
               ulSize = HB_GET_BE_UINT32( fptBlock.size );
         }
         return ulSize;
      }
   }
   return 0;
}
dbffpt1.c1069
STATIC CONST CHAR *hb_fptGetMemoType( FPTAREAP pArea, USHORT uiIndex )
static const char * hb_fptGetMemoType( FPTAREAP pArea, USHORT uiIndex )
{
   ULONG ulBlock, ulSize, ulType;
   FPTBLOCK fptBlock;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetMemoType(%p, %hu)", pArea, uiIndex));

   if( hb_dbfGetMemoData( ( DBFAREAP ) pArea, uiIndex - 1, &ulBlock, &ulSize,
                          &ulType ) == SUCCESS )
   {
      if( ulBlock != 0 )
      {
         if( ulType == 0 && pArea->bMemoType == DB_MEMO_FPT )
         {
            if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                               sizeof( FPTBLOCK ), FPT_BLOCK_OFFSET( ulBlock ) ) !=
                sizeof( FPTBLOCK ) )
               return "U";
            ulType = HB_GET_BE_UINT32( fptBlock.type );
         }
      }

      if( ulType == 0 )
         return "M";

      if( pArea->bMemoType == DB_MEMO_FPT )
      {
         switch ( ulType )
         {
            case FPTIT_SIX_LNUM:
            case FPTIT_SIX_DNUM:
               return "N";
            case FPTIT_SIX_LDATE:
               return "D";
            case FPTIT_SIX_LOG:
               return "L";
            case FPTIT_SIX_CHAR:
               return "M";
            case FPTIT_SIX_ARRAY:
               return "A";
/*
            case FPTIT_SIX_BLOCK:
            case FPTIT_SIX_VREF:
            case FPTIT_SIX_MREF:
*/
            case FPTIT_FLEX_ARRAY:
            case FPTIT_FLEX_VOARR:
               return "A";
            case FPTIT_FLEX_OBJECT:
            case FPTIT_FLEX_VOOBJ:
               return "O";
            case FPTIT_FLEX_NIL:
               return "U";
            case FPTIT_FLEX_TRUE:
            case FPTIT_FLEX_FALSE:
               return "L";
            case FPTIT_FLEX_LDATE:
               return "D";
            case FPTIT_FLEX_CHAR:
            case FPTIT_FLEX_UCHAR:
            case FPTIT_FLEX_SHORT:
            case FPTIT_FLEX_USHORT:
            case FPTIT_FLEX_LONG:
            case FPTIT_FLEX_ULONG:
            case FPTIT_FLEX_DOUBLE:
            case FPTIT_FLEX_LDOUBLE:
               return "N";
            case FPTIT_TEXT:
               return "M";
            case FPTIT_PICT:
            case FPTIT_FLEX_COMPRCH:
               return "C";
         }
         return "U";
      }
      else if( pArea->bMemoType == DB_MEMO_SMT )
      {
         switch ( ulType )
         {
            case SMT_IT_NIL:
               return "U";
            case SMT_IT_CHAR:
               return "M";
            case SMT_IT_INT:
            case SMT_IT_DOUBLE:
               return "N";
            case SMT_IT_DATE:
               return "D";
            case SMT_IT_LOGICAL:
               return "L";
            case SMT_IT_ARRAY:
               return "A";
         }
         return "U";
      }
      return "M";
   }

   return "U";
}
dbffpt1.c1116
STATIC ULONGhb_fptCountSMTItemLength( FPTAREAP pArea, PHB_ITEM pItem, ULONG * pulArrayCount )
static ULONG hb_fptCountSMTItemLength( FPTAREAP pArea, PHB_ITEM pItem,
                                       ULONG * pulArrayCount )
{
   ULONG ulLen, i, ulSize;

   switch( hb_itemType( pItem ) )
   {
      case HB_IT_ARRAY: /* HB_IT_OBJECT == HB_IT_ARRAY */
         (*pulArrayCount)++;
         ulSize = 3;
         ulLen = hb_arrayLen( pItem );
         if( ulLen > 0xFFFF )
            ulLen = 0xFFFF;
         for( i = 1; i <= ulLen; i++ )
         {
            ulSize += hb_fptCountSMTItemLength( pArea, hb_arrayGetItemPtr( pItem, i ), pulArrayCount );
         }
         break;
      case HB_IT_MEMO:
      case HB_IT_STRING:
         ulLen = hb_itemGetCLen( pItem );
         if( ulLen > 0xFFFF )
            ulLen = 0xFFFF;
         ulSize = ulLen + 3;
         break;
      case HB_IT_LOGICAL:
         ulSize = 2;
         break;
      case HB_IT_DATE:
         ulSize = 5;
         break;
      case HB_IT_INTEGER:
      case HB_IT_LONG:
      {
         HB_LONG iVal;
         iVal = hb_itemGetNInt( pItem );
         if( HB_LIM_INT32( iVal ) )
         {
            ulSize = 5;
            break;
         }
      }
      case HB_IT_DOUBLE:
         ulSize = 11;
         break;
      case HB_IT_NIL:
      default:
         ulSize = 1;
   }
   return ulSize;
}
dbffpt1.c1220
STATIC ERRCODEhb_fptCountSMTDataLength( FPTAREAP pArea, HB_FOFFSET * pfOffset )
static ERRCODE hb_fptCountSMTDataLength( FPTAREAP pArea, HB_FOFFSET * pfOffset )
{
   USHORT i, uiSize;
   BYTE buffer[ 2 ];

   if( hb_fileReadAt( pArea->pMemoFile, buffer, 1, *pfOffset ) != 1 )
      return EDBF_READ;

   *pfOffset += 1;
   switch( buffer[ 0 ] )
   {
      case SMT_IT_ARRAY:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 2, *pfOffset ) != 2 )
            return EDBF_READ;
         *pfOffset += 2;
         uiSize = HB_GET_LE_UINT16( buffer );
         for( i = 0; i < uiSize; i++ )
         {
            ERRCODE errCode = hb_fptCountSMTDataLength( pArea, pfOffset );
            if( errCode != SUCCESS )
               return errCode;
         }
         break;

      case SMT_IT_CHAR:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 2, *pfOffset ) != 2 )
            return EDBF_READ;
         uiSize = HB_GET_LE_UINT16( buffer );
         *pfOffset += uiSize + 2;
         break;

      case SMT_IT_INT:
      case SMT_IT_DATE:
         *pfOffset += 4;
         break;

      case SMT_IT_DOUBLE:
         *pfOffset += 10;
         break;

      case SMT_IT_LOGICAL:
         *pfOffset += 1;
         break;

      case SMT_IT_NIL:
         break;

      default:
         return EDBF_CORRUPT;
   }

   return SUCCESS;
}
dbffpt1.c1275
STATIC ULONGhb_fptStoreSMTItem( FPTAREAP pArea, PHB_ITEM pItem, BYTE ** bBufPtr )
static ULONG hb_fptStoreSMTItem( FPTAREAP pArea, PHB_ITEM pItem, BYTE ** bBufPtr )
{
   ULONG ulLen, i, ulSize = 0;
   HB_LONG iVal;
   LONG lVal;
   double dVal;
   int iWidth, iDec;

   switch( hb_itemType( pItem ) )
   {
      case HB_IT_ARRAY:
         *(*bBufPtr)++ = SMT_IT_ARRAY;
         ulLen = hb_arrayLen( pItem );
         if( ulLen > 0xFFFF )
            ulLen = 0xFFFF;
         HB_PUT_LE_UINT16( *bBufPtr, ulLen );
         *bBufPtr += 2;
         for( i = 1; i <= ulLen; i++ )
         {
            ulSize += hb_fptStoreSMTItem( pArea, hb_arrayGetItemPtr( pItem, i ),
                                          bBufPtr );
         }
         break;

      case HB_IT_STRING:
      case HB_IT_MEMO:
         *(*bBufPtr)++ = SMT_IT_CHAR;
         ulLen = hb_itemGetCLen( pItem );
         if( ulLen > 0xFFFF )
            ulLen = 0xFFFF;
         HB_PUT_LE_UINT16( *bBufPtr, ulLen );
         *bBufPtr += 2;
         if( ulLen > 0 )
         {
            memcpy( *bBufPtr, hb_itemGetCPtr( pItem ), ulLen );
#ifndef HB_CDP_SUPPORT_OFF
            hb_cdpnTranslate( ( char *) *bBufPtr, hb_vmCDP(), pArea->cdPage, ulLen );
#endif
            *bBufPtr += ulLen;
         }
         break;

      case HB_IT_INTEGER:
      case HB_IT_LONG:
         iVal = hb_itemGetNInt( pItem );
         if( HB_LIM_INT32( iVal ) )
         {
            *(*bBufPtr)++ = SMT_IT_INT;
            HB_PUT_LE_UINT32( *bBufPtr, iVal );
            *bBufPtr += 4;
            break;
         }
      case HB_IT_DOUBLE:
         dVal = hb_itemGetND( pItem );
         hb_itemGetNLen( pItem, &iWidth, &iDec );
         if( iDec )
            iWidth += iDec + 1;
         *(*bBufPtr)++ = SMT_IT_DOUBLE;
         *(*bBufPtr)++ = ( BYTE ) iWidth;
         *(*bBufPtr)++ = ( BYTE ) iDec;
         HB_PUT_LE_DOUBLE( *bBufPtr, dVal );
         *bBufPtr += 8;
         break;

      case HB_IT_DATE:
         *(*bBufPtr)++ = SMT_IT_DATE;
         lVal = hb_itemGetDL( pItem );
         HB_PUT_LE_UINT32( *bBufPtr, lVal );
         *bBufPtr += 4;
         break;

      case HB_IT_LOGICAL:
         *(*bBufPtr)++ = SMT_IT_LOGICAL;
         *(*bBufPtr)++ = hb_itemGetL( pItem ) ? 1 : 0;
         break;

      case HB_IT_NIL:
      default:
         *(*bBufPtr)++ = SMT_IT_NIL;
         break;
   }
   return ulSize;
}
dbffpt1.c1332
STATIC ERRCODEhb_fptReadRawSMTItem( FPTAREAP pArea, PHB_ITEM pItem, HB_FOFFSET *pfOffset )
static ERRCODE hb_fptReadRawSMTItem( FPTAREAP pArea, PHB_ITEM pItem, HB_FOFFSET *pfOffset )
{
   ULONG ulLen, i;
   BYTE buffer[ 10 ], *pBuffer;
   int iWidth, iDec;

   if( hb_fileReadAt( pArea->pMemoFile, buffer, 1, *pfOffset ) != 1 )
      return EDBF_READ;

   *pfOffset += 1;
   switch( buffer[ 0 ] )
   {
      case SMT_IT_ARRAY:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 2, *pfOffset ) != 2 )
            return EDBF_READ;

         *pfOffset += 2;
         ulLen = HB_GET_LE_UINT16( buffer );
         hb_arrayNew( pItem, ulLen );
         for( i = 1; i <= ulLen; i++ )
         {
            ERRCODE errCode = hb_fptReadRawSMTItem( pArea,
                                    hb_arrayGetItemPtr( pItem, i ), pfOffset );
            if( errCode != SUCCESS )
               return errCode;
         }
         break;

      case SMT_IT_CHAR:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 2, *pfOffset ) != 2 )
            return EDBF_READ;
         *pfOffset += 2;
         ulLen = HB_GET_LE_UINT16( buffer );
         pBuffer = ( BYTE * ) hb_xgrab( ulLen + 1 );
         if( hb_fileReadAt( pArea->pMemoFile, pBuffer, ulLen, *pfOffset ) != ulLen )
         {
            hb_xfree( pBuffer );
            return EDBF_READ;
         }
         *pfOffset += ulLen;
#ifndef HB_CDP_SUPPORT_OFF
         hb_cdpnTranslate( ( char *) pBuffer, pArea->cdPage, hb_vmCDP(), ulLen );
#endif
         hb_itemPutCLPtr( pItem, ( char *) pBuffer, ulLen );
         break;

      case SMT_IT_INT:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 4, *pfOffset ) != 4 )
            return EDBF_READ;
         *pfOffset += 4;
         hb_itemPutNInt( pItem, ( LONG ) HB_GET_LE_UINT32( buffer ) );
         break;

      case SMT_IT_DOUBLE:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 10, *pfOffset ) != 10 )
            return EDBF_READ;
         *pfOffset += 10;
         iWidth = buffer[ 0 ];
         iDec = buffer[ 1 ];
         if( iDec )
            iWidth -= iDec + 1;
         hb_itemPutNDLen( pItem, HB_GET_LE_DOUBLE( &buffer[ 2 ] ), iWidth, iDec );
         break;

      case SMT_IT_DATE:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 4, *pfOffset ) != 4 )
            return EDBF_READ;
         *pfOffset += 4;
         hb_itemPutDL( pItem, ( LONG ) HB_GET_LE_UINT32( buffer ) );
         break;

      case SMT_IT_LOGICAL:
         if( hb_fileReadAt( pArea->pMemoFile, buffer, 1, *pfOffset ) != 1 )
            return EDBF_READ;
         *pfOffset += 1;
         hb_itemPutL( pItem, buffer[ 0 ] != 0 );
         break;

      case SMT_IT_NIL:
         hb_itemClear( pItem );
         break;

      default:
         hb_itemClear( pItem );
         return EDBF_CORRUPT;
   }

   return SUCCESS;
}
dbffpt1.c1419
STATIC ERRCODEhb_fptReadSMTItem( FPTAREAP pArea, BYTE ** pbMemoBuf, BYTE * bBufEnd, PHB_ITEM pItem )
static ERRCODE hb_fptReadSMTItem( FPTAREAP pArea, BYTE ** pbMemoBuf, BYTE * bBufEnd, PHB_ITEM pItem )
{
   ULONG ulLen, i;
   ERRCODE errCode = SUCCESS;
   int iWidth, iDec;

   if( bBufEnd - (*pbMemoBuf) >= 1 )
   {
      switch ( *(*pbMemoBuf)++ )
      {
         case SMT_IT_ARRAY:
            if( bBufEnd - (*pbMemoBuf) < 2 )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            ulLen = HB_GET_LE_UINT16( *pbMemoBuf );
            *pbMemoBuf += 2;
            if( bBufEnd - (*pbMemoBuf) < ( LONG ) ulLen )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            hb_arrayNew( pItem, ulLen );
            for( i = 1; i <= ulLen; i++ )
            {
               errCode = hb_fptReadSMTItem( pArea, pbMemoBuf, bBufEnd,
                                            hb_arrayGetItemPtr( pItem, i ) );
               if( errCode != SUCCESS )
                  break;
            }
            break;

         case SMT_IT_CHAR:
            if( bBufEnd - (*pbMemoBuf) < 2 )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            ulLen = HB_GET_LE_UINT16( *pbMemoBuf );
            *pbMemoBuf += 2;
            if( bBufEnd - (*pbMemoBuf) < ( LONG ) ulLen )
            {
               errCode = EDBF_CORRUPT;
            }
            else
            {
#ifndef HB_CDP_SUPPORT_OFF
               hb_cdpnTranslate( ( char *) (*pbMemoBuf), pArea->cdPage, hb_vmCDP(), ulLen );
#endif
               hb_itemPutCL( pItem, ( char *) (*pbMemoBuf), ulLen );
               *pbMemoBuf += ulLen;
            }
            break;

         case SMT_IT_INT:
            if( bBufEnd - (*pbMemoBuf) < 4 )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            hb_itemPutNInt( pItem, ( LONG ) HB_GET_LE_UINT32( *pbMemoBuf ) );
            *pbMemoBuf += 4;
            break;

         case SMT_IT_DOUBLE:
            if( bBufEnd - (*pbMemoBuf) < 10 )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            iWidth = *(*pbMemoBuf)++;
            iDec = *(*pbMemoBuf)++;
            if( iDec )
               iWidth -= iDec + 1;
            hb_itemPutNDLen( pItem, HB_GET_LE_DOUBLE( *pbMemoBuf ), iWidth, iDec );
            *pbMemoBuf += 8;
            break;

         case SMT_IT_DATE:
            if( bBufEnd - (*pbMemoBuf) < 4 )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            hb_itemPutDL( pItem, ( LONG ) HB_GET_LE_UINT32( *pbMemoBuf ) );
            *pbMemoBuf += 4;
            break;

         case SMT_IT_LOGICAL:
            if( bBufEnd - (*pbMemoBuf) < 1 )
            {
               errCode = EDBF_CORRUPT;
               break;
            }
            hb_itemPutL( pItem, *(*pbMemoBuf)++ != 0 );
            break;

         case SMT_IT_NIL:
            hb_itemClear( pItem );
            break;

         default:
            hb_itemClear( pItem );
            errCode = EDBF_CORRUPT;
            break;
      }
   }
   else
   {
      errCode = EDBF_CORRUPT;
   }

   return errCode;
}
dbffpt1.c1512
STATIC ULONGhb_fptCountSixItemLength( FPTAREAP pArea, PHB_ITEM pItem, ULONG * pulArrayCount )
static ULONG hb_fptCountSixItemLength( FPTAREAP pArea, PHB_ITEM pItem,
                                       ULONG * pulArrayCount )
{
   ULONG ulLen, i, ulSize;

   switch ( hb_itemType( pItem ) )
   {
      case HB_IT_ARRAY: /* HB_IT_OBJECT == HB_IT_ARRAY */
         (*pulArrayCount)++;
         ulSize = SIX_ITEM_BUFSIZE;
         ulLen = hb_arrayLen( pItem );
         if( pArea->uiMemoVersion == DB_MEMOVER_SIX )
         {
            /* only 2 bytes (SHORT) for SIX compatibility */
            ulLen = HB_MIN( ulLen, 0xFFFF );
         }
         for( i = 1; i <= ulLen; i++ )
         {
            ulSize += hb_fptCountSixItemLength( pArea, hb_arrayGetItemPtr( pItem, i ), pulArrayCount );
         }
         break;
      case HB_IT_MEMO:
      case HB_IT_STRING:
         ulSize = SIX_ITEM_BUFSIZE;
         ulLen = hb_itemGetCLen( pItem );
         if( pArea->uiMemoVersion == DB_MEMOVER_SIX && ulLen > 0xFFFF )
         {
            /* only 2 bytes (SHORT) for SIX compatibility */
            ulLen = 0xFFFF;
         }
         ulSize += ulLen;
         break;
      case HB_IT_INTEGER:
      case HB_IT_LONG:
      case HB_IT_DOUBLE:
      case HB_IT_DATE:
      case HB_IT_LOGICAL:
      default:
         ulSize = SIX_ITEM_BUFSIZE;
   }
   return ulSize;
}
dbffpt1.c1631
STATIC ULONGhb_fptStoreSixItem( FPTAREAP pArea, PHB_ITEM pItem, BYTE ** bBufPtr )
static ULONG hb_fptStoreSixItem( FPTAREAP pArea, PHB_ITEM pItem, BYTE ** bBufPtr )
{
   ULONG ulLen, i, ulSize;
   HB_LONG iVal;
   LONG lVal;
   double dVal;
   int iWidth, iDec;

   memset( *bBufPtr, '\0', SIX_ITEM_BUFSIZE );
   ulSize = SIX_ITEM_BUFSIZE;
   switch ( hb_itemType( pItem ) )
   {
      case HB_IT_ARRAY: /* HB_IT_OBJECT == HB_IT_ARRAY */
         HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_ARRAY );
         ulLen = hb_arrayLen( pItem );
         if( pArea->uiMemoVersion == DB_MEMOVER_SIX )
         {
            /* only 2 bytes (SHORT) for SIX compatibility */
            ulLen = HB_MIN( ulLen, 0xFFFF );
         }
         HB_PUT_LE_UINT32( &(*bBufPtr)[2], ulLen );
         *bBufPtr += SIX_ITEM_BUFSIZE;
         for( i = 1; i <= ulLen; i++ )
         {
            ulSize += hb_fptStoreSixItem( pArea, hb_arrayGetItemPtr( pItem, i ), bBufPtr );
         }
         break;

      case HB_IT_INTEGER:
      case HB_IT_LONG:
         iVal = hb_itemGetNInt( pItem );
         hb_itemGetNLen( pItem, &iWidth, &iDec );
         if( HB_LIM_INT32( iVal ) )
         {
            HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_LNUM );
            HB_PUT_LE_UINT16( &(*bBufPtr)[2], iWidth );
            HB_PUT_LE_UINT16( &(*bBufPtr)[4], iDec );
            HB_PUT_LE_UINT32( &(*bBufPtr)[6], iVal );
            *bBufPtr += SIX_ITEM_BUFSIZE;
         }
         else
         {
            HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_DNUM );
            HB_PUT_LE_UINT16( &(*bBufPtr)[2], iWidth );
            HB_PUT_LE_UINT16( &(*bBufPtr)[4], iDec );
            HB_PUT_LE_DOUBLE( &(*bBufPtr)[6], ( double ) iVal );
            *bBufPtr += SIX_ITEM_BUFSIZE;
         }
         break;

      case HB_IT_DOUBLE:
         dVal = hb_itemGetND( pItem );
         hb_itemGetNLen( pItem, &iWidth, &iDec );
         HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_DNUM );
         HB_PUT_LE_UINT16( &(*bBufPtr)[2], iWidth );
         HB_PUT_LE_UINT16( &(*bBufPtr)[4], iDec );
         HB_PUT_LE_DOUBLE( &(*bBufPtr)[6], dVal );
         *bBufPtr += SIX_ITEM_BUFSIZE;
         break;

      case HB_IT_DATE:
         lVal = hb_itemGetDL( pItem );
         HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_LDATE );
         HB_PUT_LE_UINT32( &(*bBufPtr)[6], lVal );
         *bBufPtr += SIX_ITEM_BUFSIZE;
         break;

      case HB_IT_LOGICAL:
         HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_LOG );
         (*bBufPtr)[6] = hb_itemGetL( pItem ) ? 1 : 0;
         *bBufPtr += SIX_ITEM_BUFSIZE;
         break;

      case HB_IT_STRING:
      case HB_IT_MEMO:
         HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_CHAR );
         ulLen = hb_itemGetCLen( pItem );
         if( pArea->uiMemoVersion == DB_MEMOVER_SIX && ulLen > 0xFFFF )
         {
            /* only 2 bytes (SHORT) for SIX compatibility */
            ulLen = 0xFFFF;
         }
         HB_PUT_LE_UINT32( &(*bBufPtr)[2], ulLen );
         *bBufPtr += SIX_ITEM_BUFSIZE;
         if( ulLen > 0 )
         {
            memcpy( *bBufPtr, hb_itemGetCPtr( pItem ), ulLen );
#ifndef HB_CDP_SUPPORT_OFF
            hb_cdpnTranslate( ( char *) *bBufPtr, hb_vmCDP(), pArea->cdPage, ulLen );
#endif
            *bBufPtr += ulLen;
         }
         break;
      default:
         HB_PUT_LE_UINT16( &(*bBufPtr)[0], FPTIT_SIX_NIL );
         *bBufPtr += SIX_ITEM_BUFSIZE;
         break;
   }
   return ulSize;
}
dbffpt1.c1677
STATIC ERRCODEhb_fptReadSixItem( FPTAREAP pArea, BYTE ** pbMemoBuf, BYTE * bBufEnd, PHB_ITEM pItem )
static ERRCODE hb_fptReadSixItem( FPTAREAP pArea, BYTE ** pbMemoBuf, BYTE * bBufEnd, PHB_ITEM pItem )
{
   USHORT usType;
   ULONG ulLen, i;
   ERRCODE errCode = SUCCESS;

   ulLen = SIX_ITEM_BUFSIZE;
   if( bBufEnd - (*pbMemoBuf) >= ( LONG ) ulLen )
   {
      usType = HB_GET_LE_UINT16( &(*pbMemoBuf)[0] );
      switch ( usType )
      {
         case FPTIT_SIX_LNUM:
            hb_itemPutNL( pItem, ( LONG ) HB_GET_LE_UINT32( &(*pbMemoBuf)[6] ) );
            break;

         case FPTIT_SIX_DNUM:
            hb_itemPutNDLen( pItem, HB_GET_LE_DOUBLE( &(*pbMemoBuf)[6] ),
                                    HB_GET_LE_UINT16( &(*pbMemoBuf)[2] ),
                                    HB_GET_LE_UINT16( &(*pbMemoBuf)[4] ) );
            break;

         case FPTIT_SIX_LDATE:
            hb_itemPutDL( pItem, ( LONG ) HB_GET_LE_UINT32( &(*pbMemoBuf)[6] ) );
            break;

         case FPTIT_SIX_LOG:
            hb_itemPutL( pItem, HB_GET_LE_UINT16( &(*pbMemoBuf)[6] ) != 0 );
            break;

         case FPTIT_SIX_CHAR:
            ulLen = HB_GET_LE_UINT32( &(*pbMemoBuf)[2] );
            if( pArea->uiMemoVersion == DB_MEMOVER_SIX )
            {
              ulLen &= 0xFFFF; /* only 2 bytes (SHORT) for SIX compatibility */
            }
            (*pbMemoBuf) += SIX_ITEM_BUFSIZE;
            if( bBufEnd - (*pbMemoBuf) >= ( LONG ) ulLen )
            {
#ifndef HB_CDP_SUPPORT_OFF
               hb_cdpnTranslate( ( char *) (*pbMemoBuf), pArea->cdPage, hb_vmCDP(), ulLen );
#endif
               hb_itemPutCL( pItem, ( char *) (*pbMemoBuf), ulLen );
            }
            else
            {
               errCode = EDBF_CORRUPT;
            }
            break;
/*
         case FPTIT_SIX_BLOCK:
         case FPTIT_SIX_VREF:
         case FPTIT_SIX_MREF:
*/
         case FPTIT_SIX_ARRAY:
            ulLen = HB_GET_LE_UINT32( &(*pbMemoBuf)[2] );
            if( pArea->uiMemoVersion == DB_MEMOVER_SIX )
            {
                 ulLen &= 0xFFFF; /* only 2 bytes (SHORT) for SIX compatibility */
            }
            (*pbMemoBuf) += SIX_ITEM_BUFSIZE;
            hb_arrayNew( pItem, ulLen );
            for( i = 1; i <= ulLen; i++ )
            {
               errCode = hb_fptReadSixItem( pArea, pbMemoBuf, bBufEnd,
                                            hb_arrayGetItemPtr( pItem, i ) );
               if( errCode != SUCCESS )
               {
                  break;
               }
            }
            ulLen = 0;
            break;

         case FPTIT_SIX_NIL:
            hb_itemClear( pItem );
            break;

         default:
            errCode = EDBF_CORRUPT;
            hb_itemClear( pItem );
            break;
      }
      *pbMemoBuf += ulLen;
   }
   else
   {
      errCode = EDBF_CORRUPT;
   }

   return errCode;
}
dbffpt1.c1781
STATIC ULONGhb_fptCountFlexItemLength( FPTAREAP pArea, PHB_ITEM pItem, ULONG * pulArrayCount )
static ULONG hb_fptCountFlexItemLength( FPTAREAP pArea, PHB_ITEM pItem,
                                        ULONG * pulArrayCount )
{
   ULONG ulLen, i, ulSize = 1;
   HB_LONG iVal;

   switch ( hb_itemType( pItem ) )
   {
      case HB_IT_ARRAY:
         (*pulArrayCount)++;
         ulSize += 2;
         ulLen = hb_arrayLen( pItem ) & 0xFFFF;
         for( i = 1; i <= ulLen; i++ )
         {
            ulSize += hb_fptCountFlexItemLength( pArea, hb_arrayGetItemPtr( pItem, i ), pulArrayCount );
         }
         break;
      case HB_IT_MEMO:
      case HB_IT_STRING:
         ulLen = hb_itemGetCLen( pItem );
         if( ulLen > 0xFFFF )
            ulLen = 0xFFFF;
         if( ulLen > 0 )
            ulSize += ulLen + 2;
         break;
      case HB_IT_DATE:
         ulSize += 4;
         break;
      case HB_IT_INTEGER:
      case HB_IT_LONG:
         iVal = hb_itemGetNInt( pItem );
         ulSize += ( HB_LIM_INT8( iVal ) ? 2 :
                   ( HB_LIM_INT16( iVal ) ? 3 :
                   ( HB_LIM_INT32( iVal ) ? 5 : 10 ) ) );
         break;
      case HB_IT_DOUBLE:
         ulSize += 10;
         break;
   }
   return ulSize;
}
dbffpt1.c1877
STATIC VOIDhb_fptStoreFlexItem( FPTAREAP pArea, PHB_ITEM pItem, BYTE ** bBufPtr )
static void hb_fptStoreFlexItem( FPTAREAP pArea, PHB_ITEM pItem, BYTE ** bBufPtr )
{
   ULONG ulLen, i;
   HB_LONG iVal;
   LONG lVal;
   double dVal;
   int iWidth, iDec;

   switch ( hb_itemType( pItem ) )
   {
      case HB_IT_ARRAY:
         ulLen = hb_arrayLen( pItem ) & 0xFFFF;
         *(*bBufPtr)++ = FPTIT_FLEXAR_ARAY;
         HB_PUT_LE_UINT16( *bBufPtr, ( USHORT ) ulLen );
         *bBufPtr += 2;
         for( i = 1; i <= ulLen; i++ )
         {
            hb_fptStoreFlexItem( pArea, hb_arrayGetItemPtr( pItem, i ), bBufPtr );
         }
         break;
      case HB_IT_MEMO:
      case HB_IT_STRING:
         ulLen = hb_itemGetCLen( pItem );
         if( ulLen > 0xFFFF )
            ulLen = 0xFFFF;
         if( ulLen == 0 )
         {
            *(*bBufPtr)++ = FPTIT_FLEXAR_NUL;
         }
         else
         {
            *(*bBufPtr)++ = FPTIT_FLEXAR_STR;
            HB_PUT_LE_UINT16( *bBufPtr, ( USHORT ) ulLen );
            *bBufPtr += 2;
            memcpy( *bBufPtr, hb_itemGetCPtr( pItem ), ulLen );
#ifndef HB_CDP_SUPPORT_OFF
            hb_cdpnTranslate( ( char *) *bBufPtr, hb_vmCDP(), pArea->cdPage, ulLen );
#endif
            *bBufPtr += ulLen;
         }
         break;
      case HB_IT_DATE:
         *(*bBufPtr)++ = FPTIT_FLEXAR_DATEJ;
         lVal = hb_itemGetDL( pItem );
         HB_PUT_LE_UINT32( *bBufPtr, lVal );
         *bBufPtr += 4;
         break;
      case HB_IT_INTEGER:
      case HB_IT_LONG:
         iVal = hb_itemGetNInt( pItem );
         hb_itemGetNLen( pItem, &iWidth, &iDec );
         if( HB_LIM_INT8( iVal ) )
         {
            *(*bBufPtr)++ = FPTIT_FLEXAR_CHAR1;
            *(*bBufPtr)++ = (BYTE) iVal;
            *(*bBufPtr)++ = (BYTE) iWidth;
         }
         else if( HB_LIM_INT16( iVal ) )
         {
            *(*bBufPtr)++ = FPTIT_FLEXAR_SHORT1;
            HB_PUT_LE_UINT16( *bBufPtr, iVal );
            *bBufPtr += 2;
            *(*bBufPtr)++ = (BYTE) iWidth;
         }
         else if( HB_LIM_INT32( iVal ) )
         {
            *(*bBufPtr)++ = FPTIT_FLEXAR_LONG1;
            HB_PUT_LE_UINT32( *bBufPtr, iVal );
            *bBufPtr += 4;
            *(*bBufPtr)++ = (BYTE) iWidth;
         }
         else
         {
            *(*bBufPtr)++ = FPTIT_FLEXAR_DOUBLE2;
            *(*bBufPtr)++ = (BYTE) iWidth;
            *(*bBufPtr)++ = (BYTE) iDec;
            HB_PUT_LE_DOUBLE( *bBufPtr, (double) iVal );
            *bBufPtr += 8;
         }
         break;
      case HB_IT_DOUBLE:
         dVal = hb_itemGetND( pItem );
         hb_itemGetNLen( pItem, &iWidth, &iDec );
         if( iDec )
            iWidth += iDec + 1;
         *(*bBufPtr)++ = FPTIT_FLEXAR_DOUBLE2;
         *(*bBufPtr)++ = (BYTE) iWidth;
         *(*bBufPtr)++ = (BYTE) iDec;
         HB_PUT_LE_DOUBLE( *bBufPtr, dVal );
         *bBufPtr += 8;
         break;
      case HB_IT_LOGICAL:
         *(*bBufPtr)++ = hb_itemGetL( pItem ) ?
                                   FPTIT_FLEXAR_TRUE : FPTIT_FLEXAR_FALSE;
         break;
      case HB_IT_NIL:
      default:
         *(*bBufPtr)++ = FPTIT_FLEXAR_NIL;
   }
}
dbffpt1.c1922
STATIC ERRCODEhb_fptReadFlexItem( FPTAREAP pArea, BYTE ** pbMemoBuf, BYTE * bBufEnd, PHB_ITEM pItem, BOOL bRoot )
static ERRCODE hb_fptReadFlexItem( FPTAREAP pArea, BYTE ** pbMemoBuf, BYTE * bBufEnd, PHB_ITEM pItem, BOOL bRoot )
{
   BYTE usType;
   ULONG ulLen, i;
   ERRCODE errCode = SUCCESS;

   if( bRoot )
   {
      usType = FPTIT_FLEXAR_ARAY;
   }
   else if( bBufEnd - (*pbMemoBuf) > 0 )
   {
      usType = *(*pbMemoBuf)++;
   }
   else
   {
      return EDBF_CORRUPT;
   }
   switch ( usType )
   {
      case FPTIT_FLEXAR_NIL:
         hb_itemClear( pItem );
         break;
      case FPTIT_FLEXAR_TRUE:
         hb_itemPutL( pItem, TRUE );
         break;
      case FPTIT_FLEXAR_FALSE:
         hb_itemPutL( pItem, FALSE );
         break;
      case FPTIT_FLEXAR_LOGIC:
         if( bBufEnd - (*pbMemoBuf) >= 1 )
         {
            hb_itemPutL( pItem, *(*pbMemoBuf)++ != 0 );
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_DATEJ:
      case FPTIT_FLEXAR_DATEX:
         if( bBufEnd - (*pbMemoBuf) >= 4 )
         {
            hb_itemPutDL( pItem, ( LONG ) HB_GET_LE_UINT32( *pbMemoBuf ) );
            *pbMemoBuf += 4;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_CHAR:
         if( bBufEnd - (*pbMemoBuf) >= 1 )
         {
            hb_itemPutNI( pItem, ( signed char ) *(*pbMemoBuf)++ );
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_CHAR1:
         if( bBufEnd - (*pbMemoBuf) >= 2 )
         {
            hb_itemPutNILen( pItem, ( signed char ) **pbMemoBuf, (*pbMemoBuf)[1] );
            *pbMemoBuf += 2;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_CHAR2:
         if( bBufEnd - (*pbMemoBuf) >= 3 )
         {
            int iLen = (*pbMemoBuf)[1], iDec = (*pbMemoBuf)[2];
            if( iDec )
            {
               iLen -= iDec + 1;
               hb_itemPutNDLen( pItem, ( signed char ) **pbMemoBuf, iLen, iDec );
            }
            else
            {
               hb_itemPutNILen( pItem, ( signed char ) **pbMemoBuf, iLen );
            }
            *pbMemoBuf += 3;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_UCHAR:
         if( bBufEnd - (*pbMemoBuf) >= 1 )
         {
            hb_itemPutNI( pItem, ( unsigned char ) *(*pbMemoBuf)++ );
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_UCHAR1:
         if( bBufEnd - (*pbMemoBuf) >= 2 )
         {
            hb_itemPutNILen( pItem, ( unsigned char ) **pbMemoBuf, (*pbMemoBuf)[1] );
            *pbMemoBuf += 2;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_UCHAR2:
         if( bBufEnd - (*pbMemoBuf) >= 3 )
         {
            int iLen = (*pbMemoBuf)[1], iDec = (*pbMemoBuf)[2];
            if( iDec )
            {
               iLen -= iDec + 1;
               hb_itemPutNDLen( pItem, ( unsigned char ) **pbMemoBuf, iLen, iDec );
            }
            else
            {
               hb_itemPutNILen( pItem, ( unsigned char ) **pbMemoBuf, iLen );
            }
            *pbMemoBuf += 3;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_SHORT:
         if( bBufEnd - (*pbMemoBuf) >= 2 )
         {
            hb_itemPutNI( pItem, ( SHORT ) HB_GET_LE_UINT16( *pbMemoBuf ) );
            *pbMemoBuf += 2;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_SHORT1:
         if( bBufEnd - (*pbMemoBuf) >= 3 )
         {
            hb_itemPutNILen( pItem, ( SHORT ) HB_GET_LE_UINT16( *pbMemoBuf ),
                             (*pbMemoBuf)[2] );
            *pbMemoBuf += 3;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_SHORT2:
         if( bBufEnd - (*pbMemoBuf) >= 4 )
         {
            int iLen = (*pbMemoBuf)[2], iDec = (*pbMemoBuf)[3];
            if( iDec )
            {
               iLen -= iDec + 1;
               hb_itemPutNDLen( pItem, ( SHORT ) HB_GET_LE_UINT16( *pbMemoBuf ), iLen, iDec );
            }
            else
            {
               hb_itemPutNILen( pItem, ( SHORT ) HB_GET_LE_UINT16( *pbMemoBuf ), iLen );
            }
            *pbMemoBuf += 4;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_USHORT:
         if( bBufEnd - (*pbMemoBuf) >= 2 )
         {
            hb_itemPutNInt( pItem, ( USHORT ) HB_GET_LE_UINT16( *pbMemoBuf ) );
            *pbMemoBuf += 2;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_USHORT1:
         if( bBufEnd - (*pbMemoBuf) >= 3 )
         {
            hb_itemPutNIntLen( pItem, ( USHORT ) HB_GET_LE_UINT16( *pbMemoBuf ),
                               (*pbMemoBuf)[2] );
            *pbMemoBuf += 3;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_USHORT2:
         if( bBufEnd - (*pbMemoBuf) >= 4 )
         {
            int iLen = (*pbMemoBuf)[2], iDec = (*pbMemoBuf)[3];
            if( iDec )
            {
               iLen -= iDec + 1;
               hb_itemPutNDLen( pItem, ( USHORT ) HB_GET_LE_UINT16( *pbMemoBuf ), iLen, iDec );
            }
            else
            {
               hb_itemPutNIntLen( pItem, ( USHORT ) HB_GET_LE_UINT16( *pbMemoBuf ), iLen );
            }
            *pbMemoBuf += 4;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_LONG:
         if( bBufEnd - (*pbMemoBuf) >= 4 )
         {
            hb_itemPutNL( pItem, ( LONG ) HB_GET_LE_UINT32( *pbMemoBuf ) );
            *pbMemoBuf += 4;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_LONG1:
         if( bBufEnd - (*pbMemoBuf) >= 5 )
         {
            hb_itemPutNLLen( pItem, ( LONG ) HB_GET_LE_UINT32( *pbMemoBuf ),
                                    (*pbMemoBuf)[4] );
            *pbMemoBuf += 5;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_LONG2:
         if( bBufEnd - (*pbMemoBuf) >= 6 )
         {
            int iLen = (*pbMemoBuf)[4], iDec = (*pbMemoBuf)[5];
            if( iDec )
            {
               iLen -= iDec + 1;
               hb_itemPutNDLen( pItem, (LONG) HB_GET_LE_UINT32( *pbMemoBuf ), iLen, iDec );
            }
            else
            {
               hb_itemPutNLLen( pItem, (LONG) HB_GET_LE_UINT32( *pbMemoBuf ), iLen );
            }
            *pbMemoBuf += 6;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_ULONG2:
         if( bBufEnd - (*pbMemoBuf) >= 6 )
         {
            int iLen = (*pbMemoBuf)[4], iDec = (*pbMemoBuf)[5];
            if( iDec )
            {
               iLen -= iDec + 1;
               hb_itemPutNDLen( pItem, (ULONG) HB_GET_LE_UINT32( *pbMemoBuf ), iLen, iDec );
            }
            else
            {
               hb_itemPutNIntLen( pItem, (ULONG) HB_GET_LE_UINT32( *pbMemoBuf ), iLen );
            }
            *pbMemoBuf += 6;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_DOUBLE:
         if( bBufEnd - (*pbMemoBuf) >= 8 )
         {
            hb_itemPutND( pItem, HB_GET_LE_DOUBLE( *pbMemoBuf ) );
            *pbMemoBuf += 8;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_DOUBLE2:
         if( bBufEnd - (*pbMemoBuf) >= 10 )
         {
            int iLen = (*pbMemoBuf)[0], iDec = (*pbMemoBuf)[1];
            if( iDec )
               iLen -= iDec + 1;
            hb_itemPutNDLen( pItem, HB_GET_LE_DOUBLE( *pbMemoBuf + 2 ), iLen, iDec );
            *pbMemoBuf += 10;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_LDOUBLE:
         if( bBufEnd - (*pbMemoBuf) >= 10 )
         {
            /* TODO: write a cross platform converter from
                     10 digit long double to double */
            hb_itemPutND( pItem, 0.0 /* HB_GET_LE_DOUBLE( *pbMemoBuf ) */ );
            *pbMemoBuf += 10;
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      case FPTIT_FLEXAR_NUL:
         hb_itemPutCL( pItem, NULL, 0);
         break;

      case FPTIT_FLEXAR_STR:
         if( bBufEnd - (*pbMemoBuf) >= 2 )
         {
            ulLen = HB_GET_LE_UINT16( *pbMemoBuf );
            *pbMemoBuf += 2;
            if( bBufEnd - (*pbMemoBuf) >= ( LONG ) ulLen )
            {
#ifndef HB_CDP_SUPPORT_OFF
               hb_cdpnTranslate( ( char *) *pbMemoBuf, pArea->cdPage, hb_vmCDP(), ulLen );
#endif
               hb_itemPutCL( pItem, ( char *) *pbMemoBuf, ulLen );
               *pbMemoBuf += ulLen;
            }
            else
            {
               errCode = EDBF_CORRUPT;
            }
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;

      case FPTIT_FLEXAR_ARAY:
         if( bBufEnd - (*pbMemoBuf) >= 2 )
         {
            ulLen = HB_GET_LE_UINT16( *pbMemoBuf );
            *pbMemoBuf += 2;
            if( bBufEnd - (*pbMemoBuf) >= ( LONG ) ulLen )
            {
               hb_arrayNew( pItem, ulLen );
               for( i = 1; i <= ulLen; i++ )
               {
                  errCode = hb_fptReadFlexItem( pArea, pbMemoBuf, bBufEnd,
                                    hb_arrayGetItemPtr( pItem, i ), FALSE );
                  if( errCode != SUCCESS )
                  {
                     break;
                  }
               }
            }
            else
            {
               errCode = EDBF_CORRUPT;
            }
         }
         else
         {
            errCode = EDBF_CORRUPT;
         }
         break;
      default:
         /* fprintf(stderr,"Uknown FLEX array item: 0x%x = %d\n", usType, usType); fflush(stderr); */
         errCode = EDBF_CORRUPT;
         hb_itemClear( pItem );
         break;
   }
   return errCode;
}
dbffpt1.c2026
STATIC ERRCODEhb_fptCopyToRawFile( PHB_FILE pSrc, HB_FOFFSET from, HB_FHANDLE hDst, HB_FOFFSET size )
static ERRCODE hb_fptCopyToRawFile( PHB_FILE pSrc, HB_FOFFSET from,
                                    HB_FHANDLE hDst,
                                    HB_FOFFSET size )
{
   ERRCODE errCode = SUCCESS;
   if( size )
   {
      HB_FOFFSET written = 0;
      ULONG ulBufSize, ulRead;
      BYTE * pBuffer;

      ulBufSize = ( ULONG ) HB_MIN( 0x10000, size );
      pBuffer = ( BYTE * ) hb_xgrab( ulBufSize );

      do
      {
         ulRead = hb_fileReadAt( pSrc, pBuffer, ( ULONG )
                     HB_MIN( ( HB_FOFFSET ) ulBufSize, size - written ),
                     from + written );
         if( ulRead <= 0 )
            errCode = EDBF_READ;
         else if( hb_fsWriteLarge( hDst, pBuffer, ulRead ) != ulRead )
            errCode = EDBF_WRITE;
         else
            written += ulRead;
      }
      while( errCode == SUCCESS && written < size );

      hb_xfree( pBuffer );
   }

   return errCode;
}
dbffpt1.c2414
STATIC ERRCODEhb_fptCopyToFile( PHB_FILE pSrc, HB_FOFFSET from, PHB_FILE pDst, HB_FOFFSET to, HB_FOFFSET size )
static ERRCODE hb_fptCopyToFile( PHB_FILE pSrc, HB_FOFFSET from,
                                 PHB_FILE pDst, HB_FOFFSET to,
                                 HB_FOFFSET size )
{
   ERRCODE errCode = SUCCESS;
   if( size )
   {
      HB_FOFFSET written = 0;
      ULONG ulBufSize, ulRead;
      BYTE * pBuffer;

      ulBufSize = ( ULONG ) HB_MIN( 0x10000, size );
      pBuffer = ( BYTE * ) hb_xgrab( ulBufSize );

      do
      {
         ulRead = hb_fileReadAt( pSrc, pBuffer, ( ULONG )
                     HB_MIN( ( HB_FOFFSET ) ulBufSize, size - written ),
                     from + written );
         if( ulRead <= 0 )
            errCode = EDBF_READ;
         else if( hb_fileWriteAt( pDst, pBuffer, ulRead,
                                  to + written ) != ulRead )
            errCode = EDBF_WRITE;
         else
            written += ulRead;
      }
      while( errCode == SUCCESS && written < size );

      hb_xfree( pBuffer );
   }

   return errCode;
}
dbffpt1.c2448
STATIC ERRCODEhb_fptReadRawBlock( FPTAREAP pArea, BYTE * bBuffer, HB_FHANDLE hFile, ULONG ulBlock, ULONG ulSize )
static ERRCODE hb_fptReadRawBlock( FPTAREAP pArea, BYTE * bBuffer, HB_FHANDLE hFile,
                                   ULONG ulBlock, ULONG ulSize )
{
   ERRCODE errCode = SUCCESS;

   if( ulBlock == 0 )
      return EDBF_CORRUPT;

   if( hFile != FS_ERROR )
   {
      errCode = hb_fptCopyToRawFile( pArea->pMemoFile, FPT_BLOCK_OFFSET( ulBlock ),
                                     hFile, ulSize );
   }
   else
   {
      if( hb_fileReadAt( pArea->pMemoFile, bBuffer, ulSize,
                         FPT_BLOCK_OFFSET( ulBlock ) ) != ulSize )
         errCode = EDBF_READ;
   }

   return errCode;
}
dbffpt1.c2483
STATIC ERRCODEhb_fptReadBlobBlock( FPTAREAP pArea, PHB_ITEM pItem, HB_FHANDLE hFile, ULONG ulBlock, USHORT uiMode )
static ERRCODE hb_fptReadBlobBlock( FPTAREAP pArea, PHB_ITEM pItem,
                                    HB_FHANDLE hFile, ULONG ulBlock,
                                    USHORT uiMode )
{
   ULONG ulSize;
   BYTE buffer[ 4 ];

   if( ulBlock == 0 )
      return EDBF_CORRUPT;

   /* TODO: uiMode => BLOB_IMPORT_COMPRESS, BLOB_IMPORT_ENCRYPT */
   HB_SYMBOL_UNUSED( uiMode );

   if( hb_fileReadAt( pArea->pMemoFile, buffer, 4, FPT_BLOCK_OFFSET( ulBlock ) ) != 4 )
      return EDBF_READ;

   ulSize = HB_GET_LE_UINT32( buffer );
   if( hFile != FS_ERROR )
      return hb_fptCopyToRawFile( pArea->pMemoFile, FPT_BLOCK_OFFSET( ulBlock ) + 4,
                                  hFile, ulSize );

   if( ulSize == 0 )
      hb_itemPutC( pItem, NULL );
   else
   {
      BYTE * bBuffer = ( BYTE * ) hb_xalloc( ulSize + 1 );

      if( !bBuffer )
      {
         /* in most cases this means that file is corrupted */
         return EDBF_CORRUPT;
      }
      if( hb_fileReadAt( pArea->pMemoFile, bBuffer, ulSize,
                         FPT_BLOCK_OFFSET( ulBlock ) + 4 ) != ulSize )
      {
         hb_xfree( bBuffer );
         return EDBF_READ;
      }
      hb_itemPutCLPtr( pItem, ( char * ) bBuffer, ulSize );
   }
   return SUCCESS;
}
dbffpt1.c2506
STATIC ERRCODEhb_fptReadSMTBlock( FPTAREAP pArea, PHB_ITEM pItem, ULONG ulBlock, ULONG ulSize )
static ERRCODE hb_fptReadSMTBlock( FPTAREAP pArea, PHB_ITEM pItem,
                                   ULONG ulBlock, ULONG ulSize )
{
   if( ulBlock == 0 )
      return EDBF_CORRUPT;

   if( ulSize == 0 )
   {
      HB_FOFFSET fOffset = FPT_BLOCK_OFFSET( ulBlock );
      return hb_fptReadRawSMTItem( pArea, pItem, &fOffset );
   }
   else
   {
      ERRCODE errCode;
      BYTE * bBuffer = ( BYTE * ) hb_xalloc( ulSize ), * bMemoBuf;

      if( !bBuffer )
      {
         /* in most cases this means that file is corrupted */
         return EDBF_CORRUPT;
      }

      if( hb_fileReadAt( pArea->pMemoFile, bBuffer, ulSize,
                         FPT_BLOCK_OFFSET( ulBlock ) ) != ulSize )
      {
         errCode = EDBF_READ;
      }
      else
      {
         bMemoBuf = bBuffer;
         errCode = hb_fptReadSMTItem( pArea, &bMemoBuf, bMemoBuf + ulSize, pItem );
      }
      hb_xfree( bBuffer );
      return errCode;
   }
}
dbffpt1.c2549
STATIC ERRCODEhb_fptGetMemo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem, HB_FHANDLE hFile, ULONG ulBlock, ULONG ulStart, ULONG ulCount )
static ERRCODE hb_fptGetMemo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem,
                              HB_FHANDLE hFile, ULONG ulBlock, ULONG ulStart,
                              ULONG ulCount )
{
   ERRCODE errCode;
   ULONG ulSize = 0, ulType = 0;
   BYTE * pBuffer, * bMemoBuf;
   FPTBLOCK fptBlock;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetMemo(%p, %hu, %p, %p, %lu, %lu)", pArea, uiIndex, pItem, hFile, ulStart, ulCount));

   if( uiIndex )
   {
      errCode = hb_dbfGetMemoData( ( DBFAREAP ) pArea, uiIndex - 1,
                                   &ulBlock, &ulSize, &ulType );
   }
   else if( ! hb_fptHasDirectAccess( pArea ) )
   {
      errCode = EDBF_UNSUPPORTED;
   }
   else
   {
      errCode = SUCCESS;
   }

   if( errCode != SUCCESS )
      return errCode;

   if( ulBlock > 0 )
   {
      HB_FOFFSET fOffset = FPT_BLOCK_OFFSET( ulBlock );
      if( pArea->bMemoType == DB_MEMO_FPT )
      {
         if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                            sizeof( FPTBLOCK ), fOffset ) != sizeof( FPTBLOCK ) )
         {
            return EDBF_READ;
         }
         fOffset += sizeof( FPTBLOCK );
         ulType = HB_GET_BE_UINT32( fptBlock.type );
         ulSize = HB_GET_BE_UINT32( fptBlock.size );
      }
      else
      {
         if( pArea->bMemoType == DB_MEMO_DBT )
         {
            ulSize = hb_fptGetMemoLen( pArea, uiIndex );
            ulType = FPTIT_BINARY;
         }
      }

      if( ulStart || ulCount )
      {
         if( pArea->bMemoType == DB_MEMO_FPT )
         {
            if( ulType != FPTIT_TEXT && ulType != FPTIT_PICT )
               ulStart = ulCount = 0;
         }
         else if( pArea->bMemoType == DB_MEMO_SMT )
         {
            if( ulType != SMT_IT_CHAR )
               ulStart = ulCount = 0;
         }
      }

      if( ulStart >= ulSize )
         ulSize = 0;
      else
         ulSize -= ulStart;
      if( ulCount && ulCount < ulSize )
         ulSize = ulCount;
      if( ulStart && ulSize )
         fOffset += ulStart;

      if( hFile != FS_ERROR )
      {
         return hb_fptCopyToRawFile( pArea->pMemoFile, fOffset, hFile, ulSize );
      }

      if( pArea->bMemoType == DB_MEMO_FPT )
      {
         pBuffer = ( BYTE * ) hb_xalloc( HB_MAX( ulSize + 1, 8 ) );
         if( pBuffer )
            memset( pBuffer, '\0', 8 );
      }
      else
      {
         pBuffer = ( BYTE * ) hb_xalloc( ulSize + 1 );
      }

      if( !pBuffer )
      {
         /* in most cases this means that file is corrupted */
         return EDBF_CORRUPT;
      }

      if( ulSize != 0 && hb_fileReadAt( pArea->pMemoFile, pBuffer, ulSize,
                                        fOffset ) != ulSize )
      {
         errCode = EDBF_READ;
      }
      else if( pArea->bMemoType == DB_MEMO_DBT )
      {
#ifndef HB_CDP_SUPPORT_OFF
         hb_cdpnTranslate( ( char *) pBuffer, pArea->cdPage, hb_vmCDP(), ulSize );
#endif
         pBuffer[ ulSize ] = '\0';
         hb_itemPutCLPtr( pItem, ( char * ) pBuffer, ulSize );
         hb_itemSetCMemo( pItem );
         pBuffer = NULL;
      }
      else if( pArea->bMemoType == DB_MEMO_SMT )
      {
         if( ulType == SMT_IT_CHAR )
         {
#ifndef HB_CDP_SUPPORT_OFF
            hb_cdpnTranslate( ( char *) pBuffer, pArea->cdPage, hb_vmCDP(), ulSize );
#endif
            pBuffer[ ulSize ] = '\0';
            hb_itemPutCLPtr( pItem, ( char * ) pBuffer, ulSize );
            hb_itemSetCMemo( pItem );
            pBuffer = NULL;
         }
         else if( !ulSize || pBuffer[ 0 ] != ( BYTE ) ulType )
         {
            errCode = EDBF_CORRUPT;
            hb_itemClear( pItem );
         }
         else
         {
            bMemoBuf = pBuffer;
            errCode = hb_fptReadSMTItem( pArea, &bMemoBuf, bMemoBuf + ulSize, pItem );
         }
      }
      else
      {
         switch( ulType )
         {
            case FPTIT_SIX_LNUM:
            case FPTIT_SIX_DNUM:
            case FPTIT_SIX_LDATE:
            case FPTIT_SIX_LOG:
            case FPTIT_SIX_CHAR:
            case FPTIT_SIX_ARRAY:
/*
            case FPTIT_SIX_BLOCK:
            case FPTIT_SIX_VREF:
            case FPTIT_SIX_MREF:
*/
               bMemoBuf = pBuffer;
               errCode = hb_fptReadSixItem( pArea, &bMemoBuf, bMemoBuf + ulSize, pItem );
               break;
            case FPTIT_FLEX_ARRAY:
               bMemoBuf = pBuffer;
               errCode = hb_fptReadFlexItem( pArea, &bMemoBuf, bMemoBuf + ulSize, pItem, TRUE );
               break;
            case FPTIT_FLEX_NIL:
               hb_itemClear( pItem );
               break;
            case FPTIT_FLEX_TRUE:
               hb_itemPutL( pItem, TRUE );
               break;
            case FPTIT_FLEX_FALSE:
               hb_itemPutL( pItem, FALSE );
               break;
            case FPTIT_FLEX_LDATE:
               hb_itemPutDL( pItem, (LONG) HB_GET_LE_UINT32( pBuffer ) );
               break;
            case FPTIT_FLEX_CHAR:
               hb_itemPutNI( pItem, (signed char) pBuffer[0] );
               break;
            case FPTIT_FLEX_UCHAR:
               hb_itemPutNI( pItem, (BYTE) pBuffer[0] );
               break;
            case FPTIT_FLEX_SHORT:
               hb_itemPutNI( pItem, (SHORT) HB_GET_LE_UINT16( pBuffer ) );
               break;
            case FPTIT_FLEX_USHORT:
               hb_itemPutNInt( pItem, HB_GET_LE_UINT16( pBuffer ) );
               break;
            case FPTIT_FLEX_LONG:
               hb_itemPutNL( pItem, (LONG) HB_GET_LE_UINT32( pBuffer ) );
               break;
            case FPTIT_FLEX_ULONG:
               hb_itemPutNInt( pItem, HB_GET_LE_UINT32( pBuffer ) );
               break;
            case FPTIT_FLEX_DOUBLE:
               hb_itemPutND( pItem, HB_GET_LE_DOUBLE( pBuffer ) );
               break;
            case FPTIT_FLEX_LDOUBLE:
               /* TODO: write a cross platform converter from
                        10 digit long double to double */
               hb_itemPutND( pItem, 0.0 /* HB_GET_LE_DOUBLE( pBuffer ) */ );
               break;
            case FPTIT_TEXT:
#ifndef HB_CDP_SUPPORT_OFF
               hb_cdpnTranslate( ( char *) pBuffer, pArea->cdPage, hb_vmCDP(), ulSize );
#endif
               pBuffer[ ulSize ] = '\0';
               hb_itemPutCLPtr( pItem, ( char * ) pBuffer, ulSize );
               hb_itemSetCMemo( pItem );
               pBuffer = NULL;
               break;
            case FPTIT_PICT:
               pBuffer[ ulSize ] = '\0';
               hb_itemPutCLPtr( pItem, ( char * ) pBuffer, ulSize );
               pBuffer = NULL;
               break;
            default:
               hb_itemClear( pItem );
               break;
         }
      }
      if( pBuffer )
         hb_xfree(pBuffer);
   }
   else
   {
      hb_itemPutC( pItem, NULL );
      hb_itemSetCMemo( pItem );
   }
   return errCode;
}
dbffpt1.c2586
STATIC ERRCODEhb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize, BYTE *bBufPtr, HB_FHANDLE hFile, ULONG ulType, ULONG ulLen, ULONG * ulStoredBlock )
static ERRCODE hb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize,
                                BYTE *bBufPtr, HB_FHANDLE hFile,
                                ULONG ulType, ULONG ulLen, ULONG * ulStoredBlock )
{
   MEMOGCTABLE fptGCtable;
   ERRCODE errCode;
   BOOL bWrite;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptWriteMemo(%p, %lu, %lu, %p, %p, %hu, %lu, %p)",
         pArea, ulBlock, ulSize, bBufPtr, hFile, ulType, ulLen, ulStoredBlock));

   bWrite = ( ulLen != 0 || ( pArea->bMemoType == DB_MEMO_FPT &&
              ulType != FPTIT_TEXT && ulType != FPTIT_BINARY &&
              ulType != FPTIT_DUMMY ) );

   if( ulBlock == 0 && !bWrite )
   {
      * ulStoredBlock = 0;
      return SUCCESS;
   }

   hb_fptInitGCdata( &fptGCtable );
   errCode = hb_fptReadGCdata( pArea, &fptGCtable );
   if( errCode != SUCCESS )
   {
      return errCode;
   }

   if( ulBlock > 0 )
   {
      errCode = hb_fptGCfreeBlock( pArea, &fptGCtable, ulBlock, ulSize,
                                   ulType == FPTIT_DUMMY );
      if( errCode != SUCCESS )
      {
         hb_fptDestroyGCdata( &fptGCtable );
         return errCode;
      }
   }

   /* Write memo header and data */
   if( bWrite )
   {
      HB_FOFFSET fOffset;

      errCode = hb_fptGCgetFreeBlock( pArea, &fptGCtable, ulStoredBlock, ulLen,
                                      ulType == FPTIT_DUMMY );
      if( errCode != SUCCESS )
      {
         hb_fptDestroyGCdata( &fptGCtable );
         return errCode;
      }

      fOffset = FPT_BLOCK_OFFSET( *ulStoredBlock );
      if( pArea->bMemoType == DB_MEMO_FPT && ulType != FPTIT_DUMMY )
      {
         FPTBLOCK fptBlock;
         HB_PUT_BE_UINT32( fptBlock.type, ulType );
         HB_PUT_BE_UINT32( fptBlock.size, ulLen );
         if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                             sizeof( FPTBLOCK ), fOffset ) != sizeof( FPTBLOCK ) )
            errCode = EDBF_WRITE;
         else
            fOffset +=sizeof( FPTBLOCK );
      }

      if( errCode == SUCCESS && ulLen > 0 )
      {
         /* TODO: uiMode => BLOB_IMPORT_COMPRESS, BLOB_IMPORT_ENCRYPT */
         if( hFile != FS_ERROR )
         {
            ULONG ulWritten = 0, ulRead, ulBufSize = HB_MIN( ( 1 << 16 ), ulLen );
            BYTE * bBuffer = ( BYTE * ) hb_xgrab( ulBufSize );

            do
            {
               ulRead = hb_fsReadLarge( hFile, bBuffer,
                                        HB_MIN( ulBufSize, ulLen - ulWritten ) );
               if( ulRead <= 0 )
                  errCode = EDBF_READ;
               else if( hb_fileWriteAt( pArea->pMemoFile, bBuffer,
                                        ulRead, fOffset ) != ulRead )
                  errCode = EDBF_WRITE;
               else
               {
                  ulWritten += ulRead;
                  fOffset += ulRead;
               }
            }
            while( errCode == SUCCESS && ulWritten < ulLen );

            hb_xfree(bBuffer);
         }
         else
         {
            if( hb_fileWriteAt( pArea->pMemoFile, bBufPtr,
                                ulLen, fOffset ) != ulLen )
               errCode = EDBF_WRITE;
            else
               fOffset += ulLen;
         }
      }
      /* if written block is smaller then block size we should write at last
         block byte 0xAF to be FLEX compatible */
      if( errCode == SUCCESS )
      {
         if( pArea->bMemoType == DB_MEMO_DBT )
         {
            hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) "\x1A\x1A", 2, fOffset );
         }
         else if( pArea->uiMemoVersion == DB_MEMOVER_FLEX &&
             ( ulLen + sizeof( FPTBLOCK ) ) % pArea->uiMemoBlockSize != 0 )
         {
            ULONG ulBlocks = ( ulLen + sizeof( FPTBLOCK ) + pArea->uiMemoBlockSize - 1 ) /
                              pArea->uiMemoBlockSize;
            hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) "\xAF", 1,
                            FPT_BLOCK_OFFSET( *ulStoredBlock + ulBlocks ) - 1 );
         }
      }
      pArea->fMemoFlush = TRUE;
   }
   else
   {
      * ulStoredBlock = 0;
   }

   if( errCode == SUCCESS )
   {
      errCode = hb_fptWriteGCdata( pArea, &fptGCtable );
   }
   hb_fptDestroyGCdata( &fptGCtable );

   return errCode;
}
dbffpt1.c2813
STATIC ERRCODEhb_fptPutMemo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem, ULONG * pulBlock )
static ERRCODE hb_fptPutMemo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem,
                              ULONG * pulBlock )
{
   ULONG ulBlock = 0, ulSize, ulType, ulOldSize = 0, ulOldType = 0, ulArrayCount = 0;
   BYTE itmBuffer[FLEX_ITEM_BUFSIZE];
   BYTE  *bBufPtr = NULL, *bBufAlloc = NULL;
   ERRCODE errCode;
   HB_LONG iVal;
   LONG lVal;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptPutMemo(%p, %hu, %p, %p)", pArea, uiIndex, pItem, pulBlock));

   if( HB_IS_STRING( pItem ) )
   {
      ulType = FPTIT_TEXT;
      ulSize = hb_itemGetCLen( pItem );
      bBufPtr = ( BYTE *) hb_itemGetCPtr( pItem );
#ifndef HB_CDP_SUPPORT_OFF
      if( ulSize > 0 && pArea->cdPage != hb_vmCDP() )
      {
         bBufAlloc = ( BYTE * ) hb_xgrab( ulSize );
         memcpy( bBufAlloc, bBufPtr, ulSize );
         hb_cdpnTranslate( ( char *) bBufAlloc, hb_vmCDP(), pArea->cdPage, ulSize );
         bBufPtr = bBufAlloc;
      }
      if( pArea->bMemoType == DB_MEMO_SMT )
      {
         ulType = SMT_IT_CHAR;
      }
#endif
   }
   else if( pArea->bMemoType == DB_MEMO_DBT )
   {
      return EDBF_DATATYPE;
   }
   else if( pArea->bMemoType == DB_MEMO_SMT )
   {
      ulSize = hb_fptCountSMTItemLength( pArea, pItem, &ulArrayCount );
      if( ulSize == 0 )
         return EDBF_DATATYPE;
      bBufPtr = bBufAlloc = ( BYTE * ) hb_xgrab( ulSize );
      hb_fptStoreSMTItem( pArea, pItem, &bBufPtr );
      ulType = ( ULONG ) bBufAlloc[ 0 ];
      bBufPtr = bBufAlloc;
   }
   else if( pArea->uiMemoVersion == DB_MEMOVER_SIX )
   {
      if( HB_IS_NIL( pItem ) )
      {
         ulType = FPTIT_SIX_NIL;
         ulSize = 0;
      }
      else
      {
         ulSize = hb_fptCountSixItemLength( pArea, pItem, &ulArrayCount );
         if( ulSize > 0 )
         {
            bBufPtr = bBufAlloc = ( BYTE * ) hb_xgrab( ulSize );
            hb_fptStoreSixItem( pArea, pItem, &bBufPtr );
            ulType = ( ULONG ) HB_GET_LE_UINT16( bBufAlloc );
            bBufPtr = bBufAlloc;
         }
         else
         {
            return EDBF_DATATYPE;
         }
      }
   }
   else if( pArea->uiMemoVersion == DB_MEMOVER_FLEX )
   {
      switch ( hb_itemType( pItem ) )
      {
         case HB_IT_ARRAY:
            ulType = FPTIT_FLEX_ARRAY;
            ulSize = hb_fptCountFlexItemLength( pArea, pItem, &ulArrayCount ) - 1;
            if( ulSize > 0 )
            {
               bBufPtr = bBufAlloc = (BYTE *) hb_xgrab( ulSize + 1 );
               hb_fptStoreFlexItem( pArea, pItem, &bBufPtr );
               bBufPtr = bBufAlloc + 1; /* FLEX doesn't store the first byte of array ID */
            }
            break;
         case HB_IT_NIL:
            ulType = FPTIT_FLEX_NIL;
            ulSize = 0;
            break;
         case HB_IT_LOGICAL:
            ulType = hb_itemGetL( pItem ) ? FPTIT_FLEX_TRUE : FPTIT_FLEX_FALSE;
            ulSize = 0;
            break;
         case HB_IT_DATE:
            ulType = FPTIT_FLEX_LDATE;
            ulSize = 4;
            lVal = hb_itemGetDL( pItem );
            HB_PUT_LE_UINT32( itmBuffer, lVal );
            bBufPtr = itmBuffer;
            break;
         case HB_IT_INTEGER:
         case HB_IT_LONG:
            iVal = hb_itemGetNInt( pItem );
            if( HB_LIM_INT8( iVal ) )
            {
               ulType = FPTIT_FLEX_CHAR;
               ulSize = 1;
               *itmBuffer = ( BYTE ) iVal;
               bBufPtr = itmBuffer;
            }
            else if( HB_LIM_INT16( iVal ) )
            {
               ulType = FPTIT_FLEX_SHORT;
               ulSize = 2;
               HB_PUT_LE_UINT16( itmBuffer, iVal );
               bBufPtr = itmBuffer;
            }
            else if( HB_LIM_INT32( iVal ) )
            {
               ulType = FPTIT_FLEX_LONG;
               ulSize = 4;
               HB_PUT_LE_UINT32( itmBuffer, iVal );
               bBufPtr = itmBuffer;
            }
            else
            {
               double d = (double) iVal;
               ulType = FPTIT_FLEX_DOUBLE;
               ulSize = 8;
               HB_PUT_LE_DOUBLE( itmBuffer, d );
               bBufPtr = itmBuffer;
            }
            break;
         case HB_IT_DOUBLE:
         {
            double d = hb_itemGetND( pItem );
            ulType = FPTIT_FLEX_DOUBLE;
            ulSize = 8;
            HB_PUT_LE_DOUBLE( itmBuffer, d );
            bBufPtr = itmBuffer;
            break;
         }
         default:
            ulType = FPTIT_BINARY;
            ulSize = 0;
            break;
      }
   }
   else
   {
      return EDBF_DATATYPE;
   }

   if( uiIndex )
   {
      errCode = hb_dbfGetMemoData( (DBFAREAP) pArea, uiIndex - 1,
                                   &ulBlock, &ulOldSize, &ulOldType );
   }
   else if( !pulBlock || ! hb_fptHasDirectAccess( pArea ) )
   {
      errCode = EDBF_UNSUPPORTED;
   }
   else
   {
      ulBlock = *pulBlock;
      errCode = SUCCESS;
   }

   if( errCode == SUCCESS )
      errCode = hb_fptWriteMemo( pArea, ulBlock, ulOldSize, bBufPtr, FS_ERROR,
                                 ulType, ulSize, &ulBlock );

   if( bBufAlloc != NULL )
   {
      hb_xfree( bBufAlloc );
   }

   if( errCode == SUCCESS )
   {
      if( uiIndex )
         hb_dbfSetMemoData( (DBFAREAP) pArea, uiIndex - 1, ulBlock, ulSize, ulType );
      else
         *pulBlock = ulBlock;
   }
   return errCode;
}
dbffpt1.c2950
STATIC BOOLhb_fptHasMemoData( FPTAREAP pArea, USHORT uiIndex )
static BOOL hb_fptHasMemoData( FPTAREAP pArea, USHORT uiIndex )
{
   if( --uiIndex < pArea->uiFieldCount )
   {
      LPFIELD pField = pArea->lpFields + uiIndex;

      if( pField->uiType == HB_FT_ANY )
      {
         if( pField->uiLen >= 6 )
         {
            BYTE * pFieldBuf = pArea->pRecord + pArea->pFieldOffset[ uiIndex ];
            USHORT uiType = HB_GET_LE_UINT16( pFieldBuf + pField->uiLen - 2 );

            switch( uiType )
            {
               case HB_VF_ARRAY:
               case HB_VF_BLOB:
               case HB_VF_BLOBCOMPRESS:
               case HB_VF_BLOBENCRYPT:
                  return TRUE;
               case HB_VF_DNUM:
                  return pField->uiLen <= 12;
               default:
                  return uiType <= HB_VF_CHAR && pField->uiLen - 2 < uiType;
            }
         }
      }
      else if( pField->uiType == HB_FT_MEMO ||
               pField->uiType == HB_FT_IMAGE ||
               pField->uiType == HB_FT_BLOB ||
               pField->uiType == HB_FT_OLE )
      {
         BYTE * pFieldBuf = pArea->pRecord + pArea->pFieldOffset[ uiIndex ];
         USHORT uiLen = pField->uiLen;

         if( uiLen == 4 )
            return HB_GET_LE_UINT32( pFieldBuf ) != 0;
         if( uiLen == 10 )
         {
            if( pArea->bMemoType == DB_MEMO_SMT )
               return HB_GET_LE_UINT32( ( ( LPSMTFIELD ) pFieldBuf )->block ) != 0;
            do
            {
               if( *pFieldBuf >= '1' && *pFieldBuf <= '9' )
                  return TRUE;
               ++pFieldBuf;
            }
            while( --uiLen );
         }
      }
   }
   return FALSE;
}
dbffpt1.c3138
STATIC ERRCODEhb_fptLockForRead( FPTAREAP pArea, USHORT uiIndex, BOOL *fUnLock )
static ERRCODE hb_fptLockForRead( FPTAREAP pArea, USHORT uiIndex, BOOL *fUnLock )
{
   ERRCODE uiError;
   BOOL fLocked;

   *fUnLock = FALSE;
#ifdef HB_MEMO_SAFELOCK
   if( pArea->lpdbPendingRel )
   {
      uiError = SELF_FORCEREL( ( AREAP ) pArea );
      if( uiError != SUCCESS )
         return uiError;
   }

   if( ( uiIndex > 0 && pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_ANY &&
         pArea->lpFields[ uiIndex - 1 ].uiLen < 6 ) ||
       !pArea->fPositioned || !pArea->fShared ||
       pArea->fFLocked || pArea->fRecordChanged )
   {
      fLocked = TRUE;
   }
   else
   {
      PHB_ITEM pRecNo = hb_itemNew( NULL ), pResult = hb_itemNew( NULL );

      uiError = SELF_RECINFO( ( AREAP ) pArea, pRecNo, DBRI_LOCKED, pResult );
      fLocked = hb_itemGetL( pResult );
      hb_itemRelease( pRecNo );
      hb_itemRelease( pResult );
      if( uiError != SUCCESS )
         return uiError;
   }

   if( !fLocked )
   {
      if( !pArea->fValidBuffer || uiIndex == 0 ||
          hb_fptHasMemoData( pArea, uiIndex ) )
      {
         if( !hb_fptFileLockSh( pArea, TRUE ) )
            return FAILURE;

         *fUnLock = TRUE;
         pArea->fValidBuffer = FALSE;
      }
   }
#else
   HB_SYMBOL_UNUSED( uiIndex );
#endif
   /* update any pending relations and reread record if necessary */
   uiError = SELF_DELETED( ( AREAP ) pArea, &fLocked );

   return uiError;
}
dbffpt1.c3196
STATIC ERRCODEhb_fptGetVarField( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem, HB_FHANDLE hFile )
static ERRCODE hb_fptGetVarField( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem, HB_FHANDLE hFile )
{
   LPFIELD pField;
   ERRCODE uiError;
   BYTE * pFieldBuf;
   BOOL fUnLock = FALSE;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetVarField(%p, %hu, %p, %p)", pArea, uiIndex, pItem, hFile));

   pField = pArea->lpFields + uiIndex - 1;

   if( pField->uiType == HB_FT_ANY )
   {
      USHORT uiType;

      uiError = hb_fptLockForRead( pArea, uiIndex, &fUnLock );
      if( uiError != SUCCESS )
         return uiError;

      pFieldBuf = pArea->pRecord + pArea->pFieldOffset[ uiIndex - 1 ];
      if( pField->uiLen >= 6 )
         uiType = HB_GET_LE_UINT16( pFieldBuf + pField->uiLen - 2 );
      else
         uiType = 0;

      if( pField->uiLen == 3 || uiType == HB_VF_DATE )
         hb_itemPutDL( pItem, hb_sxPtoD( ( char * ) pFieldBuf ) );
      else if( pField->uiLen == 4 || uiType == HB_VF_INT )
         hb_itemPutNIntLen( pItem, ( HB_LONG ) HB_GET_LE_INT32( pFieldBuf ), 10 );
      else if( pField->uiLen == 2 )
         hb_itemPutNIntLen( pItem, ( int ) HB_GET_LE_INT16( pFieldBuf ), 10 );
      else if( pField->uiLen == 1 )
         hb_itemPutNILen( pItem, ( signed char ) pFieldBuf[ 0 ], 4 );
      else if( pField->uiLen >= 6 )
      {
         ULONG ulBlock = HB_GET_LE_UINT32( pFieldBuf + pField->uiLen - 6 );

         if( uiType <= HB_VF_CHAR ) /* 64000 max string size */
         {
            char * pString = ( char * ) hb_xgrab( uiType + 1 ), * pBuf;

            pBuf = pString;
            if( uiType <= pField->uiLen - 2 )
               memcpy( pString, pFieldBuf, uiType );
            else
            {
               ULONG ulSize = uiType;

               if( pField->uiLen > 6 )
               {
                  USHORT uiVLen = pField->uiLen - 6;
                  memcpy( pBuf, pFieldBuf, uiVLen );
                  ulSize -= uiVLen;
                  pBuf += uiVLen;
               }
               uiError = hb_fptReadRawBlock( pArea, ( BYTE * ) pBuf, FS_ERROR, ulBlock, ulSize );
            }
            if( uiError == SUCCESS )
            {
               pString[ uiType ] = '\0';
#ifndef HB_CDP_SUPPORT_OFF
               hb_cdpnTranslate( pString, pArea->cdPage, hb_vmCDP(), uiType );
#endif
               if( hFile != FS_ERROR )
               {
                  if( hb_fsWrite( hFile, ( BYTE * ) pString, uiType ) != uiType )
                     uiError = EDBF_WRITE;
                  hb_xfree( pString );
               }
               else
               {
                  hb_itemPutCLPtr( pItem, pString, uiType );
               }
            }
            else
               hb_xfree( pString );
         }
         else if( uiType == HB_VF_LOG )
         {
            if( hFile != FS_ERROR )
               uiError = EDBF_DATATYPE;
            else
               hb_itemPutL( pItem, pFieldBuf[ 0 ] != 0 );
         }
         else if( uiType == HB_VF_DNUM ) /* n>12 VFIELD else MEMO (bLen[1],bDec[1],dVal[8]) */
         {
            if( hFile != FS_ERROR )
               uiError = EDBF_DATATYPE;
            else
            {
               BYTE pBuffer[ 11 ];
               int iWidth, iDec;

               /* should be <= 11 - it's SIX bug but I replicated it for
                  compatibility */
               if( pField->uiLen <= 12 )
               {
                  uiError = hb_fptReadRawBlock( pArea, pBuffer, FS_ERROR, ulBlock, 11 );
                  if( uiError == SUCCESS )
                  {
                     if( pBuffer[ 0 ] == SMT_IT_DOUBLE )
                        pFieldBuf = pBuffer + 1;
                     else
                        uiError = EDBF_CORRUPT;
                  }
               }
               if( uiError == SUCCESS )
               {
                  iWidth = *pFieldBuf++;
                  iDec = *pFieldBuf++;
                  if( iDec )
                     iWidth += iDec + 1;
                  hb_itemPutNDLen( pItem, HB_GET_LE_DOUBLE( pFieldBuf ), iWidth, iDec );
               }
            }
         }
         else if( uiType == HB_VF_ARRAY ) /* MEMO only as SMT ARRAY */
         {
            if( hFile != FS_ERROR )
               uiError = EDBF_DATATYPE;
            else
               uiError = hb_fptReadSMTBlock( pArea, pItem, ulBlock, 0 );
         }
         else if( uiType == HB_VF_BLOB )
            uiError = hb_fptReadBlobBlock( pArea, pItem, hFile, ulBlock, 0 );
         else if( uiType == HB_VF_BLOBCOMPRESS )
            uiError = hb_fptReadBlobBlock( pArea, pItem, hFile, ulBlock, BLOB_IMPORT_COMPRESS );
         else if( uiType == HB_VF_BLOBENCRYPT )
            uiError = hb_fptReadBlobBlock( pArea, pItem, hFile, ulBlock, BLOB_IMPORT_ENCRYPT );
         else
            uiError = EDBF_DATATYPE;
      }
   }
   else if( pField->uiType == HB_FT_MEMO ||
            pField->uiType == HB_FT_IMAGE ||
            pField->uiType == HB_FT_BLOB ||
            pField->uiType == HB_FT_OLE )
   {
      uiError = hb_fptLockForRead( pArea, uiIndex, &fUnLock );
      if( uiError != SUCCESS )
         return uiError;

      uiError = hb_fptGetMemo( pArea, uiIndex, pItem, hFile, 0, 0, 0 );
   }
   else if( hFile == FS_ERROR )
   {
      return SUPER_GETVALUE( ( AREAP ) pArea, uiIndex, pItem );
   }
   else
   {
      return FAILURE;
   }

   if( fUnLock )
      hb_fptFileUnLock( pArea );

   return uiError;
}
dbffpt1.c3250
STATIC ERRCODEhb_fptGetVarFile( FPTAREAP pArea, ULONG ulBlock, BYTE * szFile, USHORT uiMode )
static ERRCODE hb_fptGetVarFile( FPTAREAP pArea, ULONG ulBlock, BYTE * szFile, USHORT uiMode )
{
   USHORT uiError;
   HB_FHANDLE hFile;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetVarFile(%p, %lu, %s, %hu)", pArea, ulBlock, szFile, uiMode));

   hFile = hb_fsExtOpen( szFile, NULL, FO_WRITE | FO_EXCLUSIVE |
                         FXO_DEFAULTS | FXO_SHARELOCK |
                         ( uiMode == FILEGET_APPEND ?
                         FXO_APPEND : FXO_TRUNCATE ),
                         NULL, NULL );

   if( hFile == FS_ERROR )
   {
      uiError = uiMode != FILEGET_APPEND ? EDBF_CREATE : EDBF_OPEN_DBF;
   }
   else
   {
      hb_fsSeekLarge( hFile, 0, FS_END );
      uiError = hb_fptGetMemo( pArea, 0, NULL, hFile, ulBlock, 0, 0 );
      hb_fsClose( hFile );
   }

   /* Exit if any error */
   if( uiError != SUCCESS )
   {
      if( uiError != FAILURE )
      {
         hb_memoErrorRT( pArea, 0, uiError,
                         uiError == EDBF_OPEN_DBF || uiError == EDBF_CREATE ||
                         uiError == EDBF_WRITE ? ( char * ) szFile :
                         pArea->szMemoFileName, 0, 0 );
      }
      return FAILURE;
   }
   return SUCCESS;
}
dbffpt1.c3409
STATIC ULONGhb_fptPutVarFile( FPTAREAP pArea, ULONG ulBlock, BYTE * szFile )
static ULONG hb_fptPutVarFile( FPTAREAP pArea, ULONG ulBlock, BYTE * szFile )
{
   USHORT uiError;
   HB_FHANDLE hFile;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptPutVarFile(%p, %lu, %s)", pArea, ulBlock, szFile));

   hFile = hb_fsExtOpen( szFile, NULL, FO_READ | FO_DENYNONE |
                         FXO_DEFAULTS | FXO_SHARELOCK, NULL, NULL );
   if( hFile == FS_ERROR )
   {
      uiError = EDBF_OPEN_DBF;
   }
   else
   {
      ULONG ulSize;
      HB_FOFFSET size = hb_fsSeekLarge( hFile, 0, FS_END );
      hb_fsSeek( hFile, 0, FS_SET );
      if( ( HB_FOFFSET ) ( size & 0xFFFFFFFFUL ) == size )
         ulSize = HB_MIN( ( ULONG ) size, 0xFFFFFFFFUL - sizeof( FPTBLOCK ) );
      else
         ulSize = ( ULONG ) HB_MIN( size, ( HB_FOFFSET ) ( 0xFFFFFFFFUL - sizeof( FPTBLOCK ) ) );

      if( hb_fptFileLockEx( pArea, TRUE ) )
      {
         uiError = hb_fptWriteMemo( pArea, ulBlock, 0, NULL, hFile,
                                    0, ulSize, &ulBlock );
         hb_fptFileUnLock( pArea );
      }
      else
      {
         uiError = EDBF_LOCK;
      }
      hb_fsClose( hFile );
   }

   if( uiError != SUCCESS )
   {
      hb_memoErrorRT( pArea, 0, uiError,
                      uiError == EDBF_OPEN_DBF || uiError == EDBF_READ ?
                      ( char * ) szFile : pArea->szMemoFileName, 0, 0 );
      ulBlock = 0;
   }

   return ulBlock;
}
dbffpt1.c3448
STATIC ERRCODEhb_fptPutVarField( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
static ERRCODE hb_fptPutVarField( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
{
   LPFIELD pField;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptPutVarField(%p, %hu, %p)", pArea, uiIndex, pItem));

   pField = pArea->lpFields + uiIndex - 1;

   if( pField->uiType == HB_FT_ANY ||
       pField->uiType == HB_FT_MEMO ||
       pField->uiType == HB_FT_IMAGE ||
       pField->uiType == HB_FT_BLOB ||
       pField->uiType == HB_FT_OLE )
   {
      BYTE * pFieldBuf = pArea->pRecord + pArea->pFieldOffset[ uiIndex - 1 ];
      ERRCODE uiError;
      BOOL bDeleted;

      /* update any pending relations and reread record if necessary */
      uiError = SELF_DELETED( ( AREAP ) pArea, &bDeleted );
      if( uiError != SUCCESS )
         return uiError;

      if( !pArea->fPositioned )
         return SUCCESS;

      /* Buffer is hot? */
      if( !pArea->fRecordChanged )
      {
         uiError = SELF_GOHOT( ( AREAP ) pArea );
         if( uiError != SUCCESS )
            return uiError;
      }

      if( pField->uiType != HB_FT_ANY )
      {
         if( !hb_fptFileLockEx( pArea, TRUE ) )
            return EDBF_LOCK;
         uiError = hb_fptPutMemo( pArea, uiIndex, pItem, NULL );
#if defined( HB_MEMO_SAFELOCK )
         if( uiError == SUCCESS )
         {
            /* Force writer record to eliminate race condition */
            SELF_GOCOLD( ( AREAP ) pArea );
         }
#endif
         hb_fptFileUnLock( pArea );
      }
      else if( pField->uiLen == 3 )
      {
         if( ! HB_IS_DATE( pItem ) )
         {
            return EDBF_DATATYPE;
         }
         hb_sxDtoP( ( char * ) pFieldBuf, hb_itemGetDL( pItem ) );
      }
      else if( pField->uiLen == 4 )
      {
         HB_LONG lVal;

         if( ! HB_IS_NUMBER( pItem ) )
            return EDBF_DATATYPE;
         lVal = hb_itemGetNInt( pItem );
         if( HB_IS_DOUBLE( pItem ) ?
                        ! HB_DBL_LIM_INT32( hb_itemGetND( pItem ) ) :
                        ! HB_LIM_INT32( lVal ) )
         {
            return EDBF_DATAWIDTH;
         }
         HB_PUT_LE_UINT32( pFieldBuf, ( UINT32 ) lVal );
      }
      else if( pField->uiLen < 6 )
      {
         return EDBF_DATATYPE;
      }
      else
      {
         BYTE buffer[ 11 ], *pBlock = NULL, *pAlloc = NULL;
         ULONG ulOldBlock = 0, ulOldSize = 0, ulNewSize = 0;
         USHORT uiType = HB_GET_LE_UINT16( pFieldBuf + pField->uiLen - 2 );

         if( ( uiType <= HB_VF_CHAR && uiType > pField->uiLen - 2 ) ||
             ( uiType == HB_VF_DNUM && pField->uiLen <= 12 ) ||
             uiType == HB_VF_ARRAY || uiType == HB_VF_BLOB ||
             uiType == HB_VF_BLOBCOMPRESS || uiType == HB_VF_BLOBENCRYPT )
         {
            ulOldBlock = HB_GET_LE_UINT32( pFieldBuf + pField->uiLen - 6 );
            if( ulOldBlock )
            {
               if( uiType <= HB_VF_CHAR )
                  ulOldSize = uiType - ( pField->uiLen - 6 );
               else if( uiType == HB_VF_DNUM )
                  ulOldSize = 11;
               else if( uiType == HB_VF_ARRAY )
               {
                  HB_FOFFSET fOffset = FPT_BLOCK_OFFSET( ulOldBlock );
                  if( hb_fptCountSMTDataLength( pArea, &fOffset ) != SUCCESS )
                     ulOldSize = 0;
                  else
                     ulOldSize = fOffset - FPT_BLOCK_OFFSET( ulOldBlock );
               }
            }
         }

         if( HB_IS_DATE( pItem ) )
         {
            hb_sxDtoP( ( char * ) pFieldBuf, hb_itemGetDL( pItem ) );
            uiType = HB_VF_DATE;
         }
         else if( HB_IS_LOGICAL( pItem ) )
         {
            pFieldBuf[ 0 ] = hb_itemGetL( pItem ) ? 1 : 0;
            uiType = HB_VF_LOG;
         }
         else if( HB_IS_NIL( pItem ) )
         {
            uiType = 0;
         }
         else if( HB_IS_NUMBER( pItem ) )
         {
            HB_LONG lVal;
            lVal = hb_itemGetNInt( pItem );

            if( !HB_IS_DOUBLE( pItem ) && HB_LIM_INT32( lVal ) )
            {
               HB_PUT_LE_UINT32( pFieldBuf, ( UINT32 ) lVal );
               uiType = HB_VF_INT;
            }
            else
            {
               double dVal = hb_itemGetND( pItem );
               int iWidth, iDec;

               hb_itemGetNLen( pItem, &iWidth, &iDec );
               if( iDec )
                  iWidth += iDec + 1;
               buffer[ 0 ] = SMT_IT_DOUBLE;
               buffer[ 1 ] = ( BYTE ) iWidth;
               buffer[ 2 ] = ( BYTE ) iDec;
               HB_PUT_LE_DOUBLE( &buffer[ 3 ], dVal );
               uiType = HB_VF_DNUM;
               if( pField->uiLen > 12 )
                  memcpy( pFieldBuf, buffer + 1, 10 );
               else
               {
                  pBlock = buffer;
                  ulNewSize = 11;
               }
            }
         }
         else if( HB_IS_STRING( pItem ) )
         {
            ULONG ulLen = hb_itemGetCLen( pItem );

            if( ulLen > HB_VF_CHAR )
               ulLen = HB_VF_CHAR;
            uiType = ( USHORT ) ulLen;
            pAlloc = ( BYTE * ) hb_xgrab( uiType + 1 );
            memcpy( pAlloc, hb_itemGetCPtr( pItem ), uiType );
#ifndef HB_CDP_SUPPORT_OFF
            hb_cdpnTranslate( ( char * ) pAlloc, hb_vmCDP(), pArea->cdPage, uiType );
#endif
            if( uiType <= pField->uiLen - 2 )
            {
               memcpy( pFieldBuf, pAlloc, uiType );
            }
            else
            {
               pBlock = pAlloc;
               ulNewSize = uiType;
               if( pField->uiLen > 6 )
               {
                  memcpy( pFieldBuf, pBlock, pField->uiLen - 6 );
                  ulNewSize -= pField->uiLen - 6;
                  pBlock += pField->uiLen - 6;
               }
            }
         }
         else if( HB_IS_ARRAY( pItem ) )
         {
            ULONG ulArrayCount = 0;
            ulNewSize = hb_fptCountSMTItemLength( pArea, pItem, &ulArrayCount );
            pBlock = pAlloc = ( BYTE * ) hb_xgrab( ulNewSize );
            hb_fptStoreSMTItem( pArea, pItem, &pBlock );
            pBlock = pAlloc;
            uiType = HB_VF_ARRAY;
         }
         else
         {
            return EDBF_DATATYPE;
         }

         HB_PUT_LE_UINT16( pFieldBuf + pField->uiLen - 2, uiType );
         if( ulNewSize )
            HB_PUT_LE_UINT32( pFieldBuf + pField->uiLen - 6, 0 );
         if( ulOldBlock != 0 || ulNewSize != 0 )
         {
            if( !hb_fptFileLockEx( pArea, TRUE ) )
            {
               uiError = EDBF_LOCK;
            }
            else
            {
               uiError = hb_fptWriteMemo( pArea, ulOldBlock, ulOldSize,
                                          pBlock, FS_ERROR,
                                          FPTIT_DUMMY, ulNewSize, &ulOldBlock );
               if( uiError == SUCCESS )
               {
                  if( ulNewSize )
                     HB_PUT_LE_UINT32( pFieldBuf + pField->uiLen - 6, ulOldBlock );
#if defined( HB_MEMO_SAFELOCK )
                  /* Force writer record to eliminate race condition */
                  SELF_GOCOLD( ( AREAP ) pArea );
#endif
               }
               hb_fptFileUnLock( pArea );
            }
         }
         if( pAlloc )
            hb_xfree( pAlloc );
      }

      return uiError;
   }
   return SUPER_PUTVALUE( ( AREAP ) pArea, uiIndex, pItem );
}


dbffpt1.c3495
STATIC ERRCODEhb_fptStructSize( FPTAREAP pArea, USHORT * uiSize )
static ERRCODE hb_fptStructSize( FPTAREAP pArea, USHORT * uiSize )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_fptStrucSize(%p, %p)", pArea, uiSize));
   HB_SYMBOL_UNUSED( pArea );

   * uiSize = sizeof( FPTAREA );
   return SUCCESS;
}
dbffpt1.c3730
STATIC ERRCODEhb_fptGetVarLen( FPTAREAP pArea, USHORT uiIndex, ULONG * pLength )
static ERRCODE hb_fptGetVarLen( FPTAREAP pArea, USHORT uiIndex, ULONG * pLength )
{

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetVarLen(%p, %hu, %p)", pArea, uiIndex, pLength));

   if( pArea->fHasMemo && pArea->pMemoFile &&
       ( pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_MEMO ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_IMAGE ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_BLOB ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_OLE ) )
   {
      ERRCODE uiError;
      BOOL fUnLock;

      uiError = hb_fptLockForRead( pArea, uiIndex, &fUnLock );
      if( uiError == SUCCESS )
         *pLength = hb_fptGetMemoLen( pArea, uiIndex );
      else
         *pLength = 0;

      if( fUnLock )
         hb_fptFileUnLock( pArea );

      return uiError;
   }

   return SUPER_GETVARLEN( ( AREAP ) pArea, uiIndex, pLength );
}
dbffpt1.c3743
STATIC ERRCODEhb_fptGetValue( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
static ERRCODE hb_fptGetValue( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
{
   ERRCODE uiError;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetValue(%p, %hu, %p)", pArea, uiIndex, pItem));

   if( !uiIndex || uiIndex > pArea->uiFieldCount )
      return FAILURE;

   uiError = hb_fptGetVarField( pArea, uiIndex, pItem, FS_ERROR );

   if( uiError != SUCCESS )
   {
      if( uiError == FAILURE )
         return FAILURE;
      hb_memoErrorRT( pArea, 0, uiError, pArea->szMemoFileName, 0, 0 );
   }
   return SUCCESS;
}
dbffpt1.c3776
STATIC ERRCODEhb_fptPutValue( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
static ERRCODE hb_fptPutValue( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
{
   ERRCODE uiError;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptPutValue(%p, %hu, %p)", pArea, uiIndex, pItem));

   if( !uiIndex || uiIndex > pArea->uiFieldCount )
      return FAILURE;

   uiError = hb_fptPutVarField( pArea, uiIndex, pItem );
   if( uiError != SUCCESS )
   {
      if( uiError == FAILURE )
         return FAILURE;
      hb_memoErrorRT( pArea, 0, uiError, pArea->szMemoFileName, 0, EF_CANDEFAULT );
   }
   return SUCCESS;
}
dbffpt1.c3800
STATIC ERRCODEhb_fptCreateMemFile( FPTAREAP pArea, LPDBOPENINFO pCreateInfo )
static ERRCODE hb_fptCreateMemFile( FPTAREAP pArea, LPDBOPENINFO pCreateInfo )
{
   FPTHEADER fptHeader;
   ULONG ulNextBlock, ulSize, ulLen;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptCreateMemFile(%p, %p)", pArea, pCreateInfo));

   if( pCreateInfo )
   {
      BYTE szFileName[ _POSIX_PATH_MAX + 1 ];
      PHB_FNAME pFileName;
      PHB_ITEM pError = NULL, pItem = NULL;
      BOOL bRetry;

      if( !pArea->bMemoType )
      {
         pItem = hb_itemPutNI( pItem, 0 );
         if( SELF_INFO( ( AREAP ) pArea, DBI_MEMOTYPE, pItem ) != SUCCESS )
         {
            hb_itemRelease( pItem );
            return FAILURE;
         }
         pArea->bMemoType = hb_itemGetNI( pItem );
/*
         if( !pArea->bMemoType )
         {
            pArea->bMemoType = DB_MEMO_FPT;
            pArea->uiMemoVersion = DB_MEMOVER_FLEX;
         }
*/
         if( pArea->bMemoType != DB_MEMO_DBT &&
             pArea->bMemoType != DB_MEMO_FPT &&
             pArea->bMemoType != DB_MEMO_SMT )
         {
            hb_memoErrorRT( pArea, EG_CREATE, EDBF_MEMOTYPE,
                            ( char * ) pCreateInfo->abName, 0, 0 );
            hb_itemRelease( pItem );
            return FAILURE;
         }
      }
      if( !pArea->uiMemoVersion )
      {
         if( pArea->bMemoType == DB_MEMO_SMT )
            pArea->uiMemoVersion = DB_MEMOVER_SIX;
         else if( pArea->bMemoType == DB_MEMO_FPT )
         {
            pItem = hb_itemPutNI( pItem, 0 );
            if( SELF_INFO( ( AREAP ) pArea, DBI_MEMOVERSION, pItem ) != SUCCESS )
            {
               hb_itemRelease( pItem );
               return FAILURE;
            }
            pArea->uiMemoVersion = hb_itemGetNI( pItem );
         }
         else
            pArea->uiMemoVersion = DB_MEMOVER_STD;
      }
      if( !pArea->uiMemoBlockSize )
      {
         pItem = hb_itemPutNI( pItem, 0 );
         if( SELF_INFO( ( AREAP ) pArea, DBI_MEMOBLOCKSIZE, pItem ) != SUCCESS )
         {
            hb_itemRelease( pItem );
            return FAILURE;
         }
         pArea->uiMemoBlockSize = hb_itemGetNI( pItem );
      }

      /* create file name */
      pFileName = hb_fsFNameSplit( ( char * ) pCreateInfo->abName );
      if( ! pFileName->szExtension )
      {
         pItem = hb_itemPutC( pItem, NULL );
         SELF_INFO( ( AREAP ) pArea, DBI_MEMOEXT, pItem );
         pFileName->szExtension = hb_itemGetCPtr( pItem );
         hb_fsFNameMerge( ( char * ) szFileName, pFileName );
      }
      else
      {
         hb_strncpy( ( char * ) szFileName, ( char * ) pCreateInfo->abName, sizeof( szFileName ) - 1 );
      }
      hb_xfree( pFileName );


      if( pItem )
      {
         hb_itemRelease( pItem );
      }

      /* Try create */
      do
      {
         pArea->pMemoFile = hb_fileExtOpen( szFileName, NULL,
                                            FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
                                            FXO_DEFAULTS | FXO_SHARELOCK,
                                            NULL, pError );
         if( !pArea->pMemoFile )
         {
            if( !pError )
            {
               pError = hb_errNew();
               hb_errPutGenCode( pError, EG_CREATE );
               hb_errPutSubCode( pError, EDBF_CREATE_MEMO );
               hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CREATE ) );
               hb_errPutOsCode( pError, hb_fsError() );
               hb_errPutFileName( pError, ( char * ) szFileName );
               hb_errPutFlags( pError, EF_CANRETRY );
            }
            bRetry = ( SELF_ERROR( ( AREAP ) pArea, pError ) == E_RETRY );
         }
         else
            bRetry = FALSE;
      } while( bRetry );
      if( pError )
         hb_itemRelease( pError );

      if( !pArea->pMemoFile )
         return FAILURE;

      pArea->szMemoFileName = hb_strdup( ( char * ) szFileName );
   }
   /* else -> For zap file */

   memset( &fptHeader, 0, sizeof( FPTHEADER ) );
   ulSize = 512;
   if( pArea->uiMemoVersion == DB_MEMOVER_SIX )
   {
      memcpy( fptHeader.signature1, "SIxMemo", 8 );
   }
   else
   {
      memcpy( fptHeader.signature1, "Harbour", 8 );
      if( pArea->uiMemoVersion == DB_MEMOVER_FLEX ||
          pArea->uiMemoVersion == DB_MEMOVER_CLIP )
      {
         memcpy( fptHeader.signature2, "FlexFile3\003", 11 );
         ulSize = sizeof( FPTHEADER );
         if( pArea->rddID == s_uiRddIdBLOB )
         {
            HB_PUT_LE_UINT16( fptHeader.flexSize, pArea->uiMemoBlockSize );
         }
      }
   }
   ulNextBlock = ( ulSize + pArea->uiMemoBlockSize - 1 ) / pArea->uiMemoBlockSize;
   if( pArea->bMemoType == DB_MEMO_SMT || pArea->bMemoType == DB_MEMO_DBT )
   {
      HB_PUT_LE_UINT32( fptHeader.nextBlock, ulNextBlock );
      HB_PUT_LE_UINT32( fptHeader.blockSize, ( UINT32 ) pArea->uiMemoBlockSize );
   }
   else
   {
      HB_PUT_BE_UINT32( fptHeader.nextBlock, ulNextBlock );
      HB_PUT_BE_UINT32( fptHeader.blockSize, ( UINT32 ) pArea->uiMemoBlockSize );
   }
   if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &fptHeader, ulSize, 0 ) != ulSize )
      return FAILURE;

   ulLen = ulNextBlock * pArea->uiMemoBlockSize - ulSize;
   if( ulLen > ulSize )
   {
      memset( &fptHeader, 0, sizeof( FPTHEADER ) );
      do
      {
         ULONG ulWrite = HB_MIN( ulLen - ulSize, sizeof( FPTHEADER ) );
         if( hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) &fptHeader,
                             ulWrite, ulSize ) != ulWrite )
            return FAILURE;
         ulSize += ulWrite;
      }
      while( ulLen > ulSize );
   }
   /* trunc file */
   hb_fileTruncAt( pArea->pMemoFile, ulSize );
   pArea->fMemoFlush = TRUE;
   return SUCCESS;
}
dbffpt1.c3825
STATIC ERRCODEhb_fptGetValueFile( FPTAREAP pArea, USHORT uiIndex, BYTE * szFile, USHORT uiMode )
static ERRCODE hb_fptGetValueFile( FPTAREAP pArea, USHORT uiIndex, BYTE * szFile, USHORT uiMode )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_fptGetValueFile(%p, %hu, %s, %hu)", pArea, uiIndex, szFile, uiMode));

   if( !uiIndex || uiIndex > pArea->uiFieldCount )
      return FAILURE;

   if( pArea->fHasMemo && pArea->pMemoFile &&
       ( pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_MEMO ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_IMAGE ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_BLOB ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_OLE ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_ANY ) )
   {
      USHORT uiError;
      HB_FHANDLE hFile;

      hFile = hb_fsExtOpen( szFile, NULL, FO_WRITE | FO_EXCLUSIVE |
                            FXO_DEFAULTS | FXO_SHARELOCK |
                            ( uiMode == FILEGET_APPEND ?
                            FXO_APPEND : FXO_TRUNCATE ),
                            NULL, NULL );

      if( hFile == FS_ERROR )
      {
         uiError = uiMode != FILEGET_APPEND ? EDBF_CREATE : EDBF_OPEN_DBF;
      }
      else
      {
         hb_fsSeekLarge( hFile, 0, FS_END );
         uiError = hb_fptGetVarField( pArea, uiIndex, NULL, hFile );
         hb_fsClose( hFile );
      }

      /* Exit if any error */
      if( uiError != SUCCESS )
      {
         if( uiError != FAILURE )
         {
            hb_memoErrorRT( pArea, 0, uiError,
                            uiError == EDBF_OPEN_DBF || uiError == EDBF_CREATE ||
                            uiError == EDBF_WRITE ? ( char * ) szFile :
                            pArea->szMemoFileName, 0, 0 );
         }
         return FAILURE;
      }
      return SUCCESS;
   }
   return SUPER_GETVALUEFILE( ( AREAP ) pArea, uiIndex, szFile, uiMode );
}
dbffpt1.c4007
STATIC ERRCODEhb_fptOpenMemFile( FPTAREAP pArea, LPDBOPENINFO pOpenInfo )
static ERRCODE hb_fptOpenMemFile( FPTAREAP pArea, LPDBOPENINFO pOpenInfo )
{
   BYTE szFileName[ _POSIX_PATH_MAX + 1 ];
   PHB_FNAME pFileName;
   PHB_ITEM pError;
   USHORT uiFlags;
   BOOL bRetry;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptOpenMemFile(%p, %p)", pArea, pOpenInfo));

   if( pArea->rddID == s_uiRddIdBLOB )
   {
      pArea->bMemoType = DB_MEMO_FPT;
      pArea->uiMemoVersion = DB_MEMOVER_FLEX;
   }
   else if( pArea->bMemoType != DB_MEMO_DBT &&
            pArea->bMemoType != DB_MEMO_FPT &&
            pArea->bMemoType != DB_MEMO_SMT )
   {
      hb_memoErrorRT( pArea, EG_OPEN, EDBF_MEMOTYPE,
                      ( char * ) pOpenInfo->abName, 0, 0 );
      return FAILURE;
   }

   /* create file name */
   pFileName = hb_fsFNameSplit( ( char * ) pOpenInfo->abName );
   if( ! pFileName->szExtension )
   {
      PHB_ITEM pItem = hb_itemPutC( NULL, NULL );
      SELF_INFO( ( AREAP ) pArea, DBI_MEMOEXT, pItem );
      pFileName->szExtension = hb_itemGetCPtr( pItem );
      hb_fsFNameMerge( ( char * ) szFileName, pFileName );
      hb_itemRelease( pItem );
   }
   else
   {
      hb_strncpy( ( char * ) szFileName, ( char * ) pOpenInfo->abName, sizeof( szFileName ) - 1 );
   }
   hb_xfree( pFileName );

   uiFlags = (pOpenInfo->fReadonly ? FO_READ : FO_READWRITE) |
             (pOpenInfo->fShared ? FO_DENYNONE : FO_EXCLUSIVE);
   pError = NULL;

   /* Try open */
   do
   {
      pArea->pMemoFile = hb_fileExtOpen( szFileName, NULL, uiFlags |
                                         FXO_DEFAULTS | FXO_SHARELOCK,
                                         NULL, pError );
      if( !pArea->pMemoFile )
      {
         if( !pError )
         {
            pError = hb_errNew();
            hb_errPutGenCode( pError, EG_OPEN );
            hb_errPutSubCode( pError, EDBF_OPEN_MEMO );
            hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_OPEN ) );
            hb_errPutOsCode( pError, hb_fsError() );
            hb_errPutFileName( pError, ( char * ) szFileName );
            hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT );
         }
         bRetry = ( SELF_ERROR( ( AREAP ) pArea, pError ) == E_RETRY );
      }
      else
         bRetry = FALSE;
   } while( bRetry );

   if( pError )
      hb_itemRelease( pError );

   if( !pArea->pMemoFile )
      return FAILURE;

   pArea->szMemoFileName = hb_strdup( ( char * ) szFileName );

   if( pArea->bMemoType == DB_MEMO_DBT )
   {
      pArea->uiMemoBlockSize = DBT_DEFBLOCKSIZE;
   }
   else
   {
      FPTHEADER fptHeader;
      memset( &fptHeader, 0, sizeof( FPTHEADER ) );
      if( hb_fptFileLockSh( pArea, TRUE ) )
      {
         if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptHeader,
                            sizeof( FPTHEADER ), 0 ) >= 512 )
         {
            pArea->uiMemoVersion = DB_MEMOVER_STD;
            if( pArea->bMemoType == DB_MEMO_SMT )
               pArea->uiMemoBlockSize = ( USHORT ) HB_GET_LE_UINT32( fptHeader.blockSize );
            else
               pArea->uiMemoBlockSize = ( USHORT ) HB_GET_BE_UINT32( fptHeader.blockSize );
            /* Check for compatibility with SIX memo headers */
            if( memcmp( fptHeader.signature1, "SIxMemo", 7 ) == 0 )
            {
               pArea->uiMemoVersion = DB_MEMOVER_SIX;
            }
            /* Check for compatibility with CLIP (www.itk.ru) memo headers */
            else if( memcmp( fptHeader.signature1, "Made by CLIP", 12 ) == 0 )
            {
               pArea->uiMemoVersion = DB_MEMOVER_CLIP;
            }
            /* Check for compatibility with Clipper 5.3/FlexFile3 malformed memo headers */
            if( pArea->uiMemoVersion != DB_MEMOVER_SIX &&
                memcmp( fptHeader.signature2, "FlexFile3\003", 10) == 0 )
            {
               USHORT usSize = HB_GET_LE_UINT16( fptHeader.flexSize );
               pArea->uiMemoVersion = DB_MEMOVER_FLEX;
               if( usSize != 0 && ( pArea->uiMemoBlockSize == 0 ||
                                    pArea->rddID == s_uiRddIdBLOB ) )
               {
                  pArea->uiMemoBlockSize = usSize;
               }
            }
         }
         hb_fptFileUnLock( pArea );
      }
   }

   if( pArea->uiMemoBlockSize == 0 )
   {
      hb_memoErrorRT( pArea, EG_CORRUPTION, EDBF_CORRUPT,
                      ( char * ) pArea->szMemoFileName, 0, 0 );
      return FAILURE;
   }

   return SUCCESS;
}
dbffpt1.c4062
STATIC ERRCODEhb_fptPutValueFile( FPTAREAP pArea, USHORT uiIndex, BYTE * szFile, USHORT uiMode )
static ERRCODE hb_fptPutValueFile( FPTAREAP pArea, USHORT uiIndex, BYTE * szFile, USHORT uiMode )
{
   LPFIELD pField;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptPutValueFile(%p, %hu, %s, %hu)", pArea, uiIndex, szFile, uiMode));

   if( !uiIndex || uiIndex > pArea->uiFieldCount )
      return FAILURE;

   pField = pArea->lpFields + uiIndex - 1;

   if( pArea->fHasMemo && pArea->pMemoFile &&
       ( pField->uiType == HB_FT_MEMO ||
         pField->uiType == HB_FT_IMAGE ||
         pField->uiType == HB_FT_BLOB ||
         pField->uiType == HB_FT_OLE ||
         ( pField->uiType == HB_FT_ANY && pField->uiLen >= 6 ) ) )
   {
      USHORT uiError;
      BOOL bDeleted;
      HB_FHANDLE hFile;

      /* update any pending relations and reread record if necessary */
      uiError = SELF_DELETED( ( AREAP ) pArea, &bDeleted );
      if( uiError != SUCCESS )
         return uiError;

      if( !pArea->fPositioned )
         return FAILURE;

      /* Buffer is hot? */
      if( !pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == FAILURE )
         return FAILURE;

      hFile = hb_fsExtOpen( szFile, NULL, FO_READ | FO_DENYNONE |
                            FXO_DEFAULTS | FXO_SHARELOCK, NULL, NULL );
      if( hFile == FS_ERROR )
      {
         uiError = EDBF_OPEN_DBF;
      }
      else if( pField->uiType == HB_FT_ANY )
      {
         BYTE * pAlloc;
         ULONG ulSize;
         HB_FOFFSET size = hb_fsSeekLarge( hFile, 0, FS_END );

         ulSize = ( ULONG ) HB_MIN( size, HB_VF_CHAR );
         pAlloc = ( BYTE * ) hb_xgrab( ulSize + 1 );
         hb_fsSeek( hFile, 0, FS_SET );
         if( hb_fsRead( hFile, pAlloc, ( USHORT ) ulSize ) != ( USHORT ) ulSize )
         {
            uiError = EDBF_READ;
            hb_xfree( pAlloc );
         }
         else
         {
            pAlloc[ ulSize ] = '\0';
         }
         hb_fsClose( hFile );
         if( uiError == SUCCESS )
         {
            PHB_ITEM pItem = hb_itemPutCLPtr( NULL, ( char * ) pAlloc, ulSize );
            uiError = hb_fptPutVarField( pArea, uiIndex, pItem );
            hb_itemRelease( pItem );
         }
      }
      else if( !hb_fptFileLockEx( pArea, TRUE ) )
      {
         hb_fsClose( hFile );
         uiError = EDBF_LOCK;
      }
      else
      {
         ULONG ulSize, ulBlock, ulType, ulOldSize, ulOldType;
         HB_FOFFSET size = hb_fsSeekLarge( hFile, 0, FS_END );

         hb_fsSeek( hFile, 0, FS_SET );
         if( ( HB_FOFFSET ) ( size & 0xFFFFFFFFUL ) == size )
         {
            ulSize = HB_MIN( ( ULONG ) size, 0xFFFFFFFFUL - sizeof( FPTBLOCK ) );
         }
         else
         {
            ulSize = ( ULONG ) HB_MIN( size, ( HB_FOFFSET ) ( 0xFFFFFFFFUL - sizeof( FPTBLOCK ) ) );
         }

         if( pArea->bMemoType == DB_MEMO_SMT )
            ulType = SMT_IT_CHAR;
         else
            ulType = FPTIT_BINARY;


         uiError = hb_dbfGetMemoData( (DBFAREAP) pArea, uiIndex - 1,
                                      &ulBlock, &ulOldSize, &ulOldType );
         if( uiError == SUCCESS )
            uiError = hb_fptWriteMemo( pArea, ulBlock, ulOldSize, NULL, hFile,
                                       ulType, ulSize, &ulBlock );
         if( uiError == SUCCESS )
            uiError = hb_dbfSetMemoData( (DBFAREAP) pArea, uiIndex - 1, ulBlock, ulSize, ulType );
#if defined( HB_MEMO_SAFELOCK )
         if( uiError == SUCCESS )
         {
            /* Force writer record to eliminate race condition */
            SELF_GOCOLD( ( AREAP ) pArea );
         }
#endif
         hb_fptFileUnLock( pArea );
         hb_fsClose( hFile );
      }
      /* Exit if any error */
      if( uiError != SUCCESS )
      {
         hb_memoErrorRT( pArea, 0, uiError,
                         uiError == EDBF_OPEN_DBF || uiError == EDBF_READ ?
                         ( char * ) szFile : pArea->szMemoFileName, 0, 0 );
         return FAILURE;
      }
      return SUCCESS;
   }

   return SUPER_PUTVALUEFILE( ( AREAP ) pArea, uiIndex, szFile, uiMode );
}
dbffpt1.c4197
STATIC ERRCODEhb_fptDoPackRec( FPTAREAP pArea )
static ERRCODE hb_fptDoPackRec( FPTAREAP pArea )
{
   ERRCODE errCode = SUCCESS;
   ULONG ulBlock, ulSize, ulType;
   USHORT uiField;
   HB_FOFFSET pos, from;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptDoPackRec(%p)", pArea));

   /* TODO: implement memo pack operation */
   for( uiField = 0; uiField < pArea->uiFieldCount; ++uiField )
   {
      LPFIELD pField = pArea->lpFields + uiField;

      if( pField->uiType == HB_FT_MEMO ||
          pField->uiType == HB_FT_IMAGE ||
          pField->uiType == HB_FT_BLOB ||
          pField->uiType == HB_FT_OLE )
      {
         errCode = hb_dbfGetMemoData( ( DBFAREAP ) pArea, uiField,
                                      &ulBlock, &ulSize, &ulType );
         if( errCode == SUCCESS && ulBlock != 0 )
         {
            /* Buffer is hot? */
            if( !pArea->fRecordChanged )
               errCode = SELF_GOHOT( ( AREAP ) pArea );
            if( ulSize == 0 && errCode == SUCCESS )
            {
               if( pArea->bMemoType == DB_MEMO_DBT )
               {
                  ulSize = hb_fptGetMemoLen( pArea, uiField + 1 );
                  if( ulSize )
                     ++ulSize;
               }
               else if( pArea->bMemoType == DB_MEMO_FPT )
               {
                  FPTBLOCK fptBlock;
                  if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
                                     sizeof( FPTBLOCK ), FPT_BLOCK_OFFSET( ulBlock ) ) ==
                      sizeof( FPTBLOCK ) )
                     ulSize = HB_GET_BE_UINT32( fptBlock.size ) + sizeof( FPTBLOCK );
               }
            }
            if( ulSize && errCode == SUCCESS )
            {
               from = FPT_BLOCK_OFFSET( ulBlock );
               pos = hb_fileSize( pArea->pMemoTmpFile );
               ulBlock = ( ULONG ) ( ( pos + pArea->uiNewBlockSize - 1 ) /
                                     pArea->uiNewBlockSize );
               pos = ( HB_FOFFSET ) ulBlock *
                     ( HB_FOFFSET ) pArea->uiNewBlockSize;
               errCode = hb_fptCopyToFile( pArea->pMemoFile, from,
                                           pArea->pMemoTmpFile, pos, ulSize );
            }
            else
               ulBlock = ulType = 0;

            if( errCode == SUCCESS )
               errCode = hb_dbfSetMemoData( ( DBFAREAP ) pArea, uiField,
                                            ulBlock, ulSize, ulType );
         }
      }
      else if( pField->uiType == HB_FT_ANY && pField->uiLen >= 6 )
      {
         BYTE * pFieldBuf = pArea->pRecord + pArea->pFieldOffset[ uiField ];
         BYTE buffer[4];

         ulBlock = HB_GET_LE_UINT32( pFieldBuf + pField->uiLen - 6 );
         ulType = HB_GET_LE_UINT16( pFieldBuf + pField->uiLen - 2 );
         ulSize = 0;

         switch( ulType )
         {
            case HB_VF_BLOB:
            case HB_VF_BLOBCOMPRESS:
            case HB_VF_BLOBENCRYPT:
               if( hb_fileReadAt( pArea->pMemoFile, buffer, 4,
                                  FPT_BLOCK_OFFSET( ulBlock ) ) != 4 )
                  errCode = EDBF_READ;
               else
                  ulSize = HB_GET_LE_UINT32( buffer ) + 4;
               break;
            case HB_VF_ARRAY:
               from = FPT_BLOCK_OFFSET( ulBlock );
               errCode = hb_fptCountSMTDataLength( pArea, &from );
               ulSize = from - FPT_BLOCK_OFFSET( ulBlock );
               break;
            case HB_VF_DNUM:
               if( pField->uiLen <= 12 )
                  ulSize = 11;
               break;
            default:
               if( ulType <= HB_VF_CHAR && ( pField->uiLen - 2 ) < ( int ) ulType )
                  ulSize = ulType - ( pField->uiLen - 6 );
               break;
         }
         if( errCode == SUCCESS && ulSize )
         {
            /* Buffer is hot? */
            if( !pArea->fRecordChanged )
               errCode = SELF_GOHOT( ( AREAP ) pArea );
            if( errCode == SUCCESS )
            {
               from = FPT_BLOCK_OFFSET( ulBlock );
               pos = hb_fileSize( pArea->pMemoTmpFile );
               ulBlock = ( ULONG ) ( ( pos + pArea->uiNewBlockSize - 1 ) /
                                     pArea->uiNewBlockSize );
               pos = ( HB_FOFFSET ) ulBlock *
                     ( HB_FOFFSET ) pArea->uiNewBlockSize;
               errCode = hb_fptCopyToFile( pArea->pMemoFile, from,
                                           pArea->pMemoTmpFile, pos, ulSize );
               if( errCode == SUCCESS )
                  HB_PUT_LE_UINT32( pFieldBuf + pField->uiLen - 6, ulBlock );
            }
         }
      }
   }

   return errCode;
}
dbffpt1.c4324
STATIC ERRCODEhb_fptDoPack( FPTAREAP pArea, USHORT uiBlockSize, PHB_ITEM pEvalBlock, LONG lEvalStep )
static ERRCODE hb_fptDoPack( FPTAREAP pArea, USHORT uiBlockSize,
                             PHB_ITEM pEvalBlock, LONG lEvalStep )
{
   ERRCODE errCode = SUCCESS;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptDoPack(%p,%hu,%p,%ld)", pArea, uiBlockSize, pEvalBlock, lEvalStep));

   if( pArea->fReadonly )
      errCode = EDBF_READONLY;
   else if( pArea->fShared )
      errCode = EDBF_SHARED;
   else if( SELF_GOCOLD( ( AREAP ) pArea ) != SUCCESS )
      return FAILURE;
   else if( pArea->fHasMemo && pArea->pMemoFile && pArea->pDataFile )
   {
      BYTE szFile[ _POSIX_PATH_MAX + 1 ];
      ULONG ulRecNo, ulRecords;
      LONG lStep = lEvalStep;

      if( pEvalBlock && !HB_IS_BLOCK( pEvalBlock ) )
         pEvalBlock = NULL;

      errCode = SELF_RECCOUNT( ( AREAP ) pArea, &ulRecords );
      if( errCode == SUCCESS && ulRecords )
      {
         pArea->uiNewBlockSize = uiBlockSize && pArea->bMemoType != DB_MEMO_DBT
                                 ? uiBlockSize : pArea->uiMemoBlockSize;
         pArea->pMemoTmpFile = hb_fileCreateTemp( NULL, NULL, FC_NORMAL, szFile );
         if( pArea->pMemoTmpFile )
         {
            USHORT uiBlockSize = pArea->uiMemoBlockSize;
            PHB_FILE pFile = pArea->pMemoFile;

            pArea->uiMemoBlockSize = pArea->uiNewBlockSize;
            pArea->pMemoFile = pArea->pMemoTmpFile;
            errCode = SELF_CREATEMEMFILE( ( AREAP ) pArea, NULL );
            pArea->pMemoFile = pFile;
            pArea->uiMemoBlockSize = uiBlockSize;
            if( errCode == SUCCESS )
            {
               if( pEvalBlock )
               {
                  SELF_GOTO( ( AREAP ) pArea, 0 );
                  pArea->fEof = FALSE;
                  hb_vmEvalBlock( pEvalBlock );
               }

               for( ulRecNo = 1; ulRecNo <= ulRecords; ++ulRecNo )
               {
                  BOOL fDeleted;

                  errCode = SELF_GOTO( ( AREAP ) pArea, ulRecNo );
                  if( errCode != SUCCESS )
                     break;
                  if( pEvalBlock )
                  {
                     if( --lStep <= 0 )
                     {
                        hb_vmEvalBlock( pEvalBlock );
                        lStep = lEvalStep;
                     }
                  }

                  /* read record into bugger */
                  errCode = SELF_DELETED( ( AREAP ) pArea, &fDeleted );
                  if( errCode != SUCCESS )
                     break;
                  errCode = hb_fptDoPackRec( pArea );
                  if( errCode != SUCCESS )
                     break;
                  errCode = SELF_GOCOLD( ( AREAP ) pArea );
                  if( errCode != SUCCESS )
                     break;
               }

               if( errCode == SUCCESS && pEvalBlock )
               {
                  SELF_GOTO( ( AREAP ) pArea, 0 );
                  pArea->fBof = FALSE;
                  hb_vmEvalBlock( pEvalBlock );
               }
            }
            if( errCode == SUCCESS )
            {
               HB_FOFFSET size = hb_fileSize( pArea->pMemoTmpFile );
               ULONG ulNextBlock;
               BYTE buffer[4];

               ulNextBlock = ( ULONG ) ( ( size + pArea->uiNewBlockSize - 1 ) /
                                         pArea->uiNewBlockSize );
               if( pArea->bMemoType == DB_MEMO_SMT ||
                   pArea->bMemoType == DB_MEMO_DBT )
                  HB_PUT_LE_UINT32( buffer, ulNextBlock );
               else
                  HB_PUT_BE_UINT32( buffer, ulNextBlock );
               hb_fileWriteAt( pArea->pMemoTmpFile, buffer, sizeof( buffer ), 0 );
               errCode = hb_fptCopyToFile( pArea->pMemoTmpFile, 0,
                                           pArea->pMemoFile, 0, size );
               hb_fileTruncAt( pArea->pMemoFile, size );
               pArea->uiMemoBlockSize = pArea->uiNewBlockSize;
               if( errCode != SUCCESS )
               {
                  hb_memoErrorRT( pArea, 0, errCode, errCode == EDBF_READ ?
                           ( char * ) szFile : pArea->szMemoFileName, 0, 0 );
                  errCode = FAILURE;
               }
            }
            hb_fileClose( pArea->pMemoTmpFile );
            hb_fsDelete( ( BYTE * ) szFile );
            pArea->pMemoTmpFile = NULL;
         }
      }
   }

   if( errCode != SUCCESS && errCode != FAILURE )
   {
      hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
      errCode = FAILURE;
   }

   return errCode;
}
dbffpt1.c4445
STATIC ERRCODEhb_fptPackRec( FPTAREAP pArea, ULONG ulRecNo, BOOL *pfWritten )
static ERRCODE hb_fptPackRec( FPTAREAP pArea, ULONG ulRecNo, BOOL *pfWritten )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_fptPackRec(%p, %lu, %p)", pArea, ulRecNo, pfWritten));

   if( pArea->fPackMemo )
   {
      ERRCODE errCode = SUPER_PACKREC( ( AREAP ) pArea, ulRecNo, pfWritten );
      if( errCode == SUCCESS && *pfWritten )
      {
         errCode = hb_fptDoPackRec( pArea );
         if( errCode != SUCCESS && errCode != FAILURE )
         {
            hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
            errCode = FAILURE;
         }
      }
      return errCode;
   }

   return SUPER_PACKREC( ( AREAP ) pArea, ulRecNo, pfWritten );
}
dbffpt1.c4567
STATIC ERRCODEhb_fptPack( FPTAREAP pArea )
static ERRCODE hb_fptPack( FPTAREAP pArea )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_fptPack(%p)", pArea));

   if( !pArea->fReadonly && !pArea->fShared &&
       pArea->fHasMemo && pArea->pMemoFile && pArea->pDataFile )
   {
      BYTE szFile[ _POSIX_PATH_MAX + 1 ];

      if( SELF_GOCOLD( ( AREAP ) pArea ) != SUCCESS )
         return FAILURE;

      pArea->pMemoTmpFile = hb_fileCreateTemp( NULL, NULL, FC_NORMAL, szFile );
      if( pArea->pMemoTmpFile )
      {
         ERRCODE errCode;
         PHB_FILE pFile = pArea->pMemoFile;

         pArea->uiNewBlockSize = pArea->uiMemoBlockSize;

         pArea->pMemoFile = pArea->pMemoTmpFile;
         errCode = SELF_CREATEMEMFILE( ( AREAP ) pArea, NULL );
         pArea->pMemoFile = pFile;

         if( errCode == SUCCESS )
         {
            pArea->fPackMemo = TRUE;
            errCode = SUPER_PACK( ( AREAP ) pArea );
            pArea->fPackMemo = FALSE;
            if( errCode == SUCCESS )
            {
               HB_FOFFSET size = hb_fileSize( pArea->pMemoTmpFile );
               ULONG ulNextBlock;
               BYTE buffer[4];

               ulNextBlock = ( ULONG ) ( ( size + pArea->uiNewBlockSize - 1 ) /
                                         pArea->uiNewBlockSize );
               if( pArea->bMemoType == DB_MEMO_SMT ||
                   pArea->bMemoType == DB_MEMO_DBT )
                  HB_PUT_LE_UINT32( buffer, ulNextBlock );
               else
                  HB_PUT_BE_UINT32( buffer, ulNextBlock );
               hb_fileWriteAt( pArea->pMemoTmpFile, buffer, sizeof( buffer ), 0 );

               errCode = hb_fptCopyToFile( pArea->pMemoTmpFile, 0,
                                           pArea->pMemoFile, 0, size );
               hb_fileTruncAt( pArea->pMemoFile, size );
               pArea->uiMemoBlockSize = pArea->uiNewBlockSize;
               if( errCode != SUCCESS )
               {
                  hb_memoErrorRT( pArea, 0, errCode, errCode == EDBF_READ ?
                           ( char * ) szFile : pArea->szMemoFileName, 0, 0 );
                  errCode = FAILURE;
               }
            }
         }
         hb_fileClose( pArea->pMemoTmpFile );
         hb_fsDelete( ( BYTE * ) szFile );
         pArea->pMemoTmpFile = NULL;
         return errCode;
      }
   }

   return SUPER_PACK( ( AREAP ) pArea );
}
dbffpt1.c4593
STATIC ERRCODEhb_fptInfo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
static ERRCODE hb_fptInfo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_fptInfo(%p, %hu, %p)", pArea, uiIndex, pItem));

   switch( uiIndex )
   {
      case DBI_MEMOEXT:
         if( pArea->fHasMemo && pArea->pMemoFile )
         {
            PHB_FNAME pFileName;

            pFileName = hb_fsFNameSplit( ( char * ) pArea->szMemoFileName );
            hb_itemPutC( pItem, pFileName->szExtension );
            hb_xfree( pFileName );
         }
         else
         {
            LPDBFDATA pData = ( LPDBFDATA ) SELF_RDDNODE( pArea )->lpvCargo;
            char * szMFileExt;
            if( pData->szMemoExt[ 0 ] )
               hb_itemPutC( pItem, pData->szMemoExt );
            else if( pArea->bMemoType == DB_MEMO_FPT &&
                     ( szMFileExt = hb_setGetMFileExt() ) != NULL &&
                     *szMFileExt )
               hb_itemPutC( pItem, szMFileExt );
            else
            {
               const char * szExt = hb_memoDefaultFileExt( pArea->bMemoType, pArea->rddID );
               if( !szExt )
                  szExt = hb_memoDefaultFileExt( pData->bMemoType, pArea->rddID );
               hb_itemPutC( pItem, szExt );
            }
         }
         break;

      case DBI_MEMOBLOCKSIZE:
         if( pArea->fHasMemo && pArea->pMemoFile )
            hb_itemPutNI( pItem, pArea->uiMemoBlockSize );
         else if( pArea->bMemoType && pArea->uiMemoBlockSize )
            hb_itemPutNI( pItem, pArea->uiMemoBlockSize );
         else if( pArea->bMemoType == DB_MEMO_DBT )
            hb_itemPutNI( pItem, DBT_DEFBLOCKSIZE );
         else
         {
            hb_itemClear( pItem );
            return SELF_RDDINFO( SELF_RDDNODE( pArea ), RDDI_MEMOBLOCKSIZE, 0, pItem );
         }
         break;

      case DBI_MEMOTYPE:
         if( pArea->fHasMemo && pArea->pMemoFile )
            hb_itemPutNI( pItem, pArea->bMemoType );
         else if( pArea->bMemoType )
            hb_itemPutNI( pItem, pArea->bMemoType );
         else
         {
            hb_itemClear( pItem );
            return SELF_RDDINFO( SELF_RDDNODE( pArea ), RDDI_MEMOTYPE, 0, pItem );
         }
         break;

      case DBI_MEMOVERSION:
         if( pArea->fHasMemo && pArea->pMemoFile )
            hb_itemPutNI( pItem, pArea->uiMemoVersion );
         else if( pArea->bMemoType != DB_MEMO_NONE &&
                  pArea->uiMemoVersion != 0 )
            hb_itemPutNI( pItem, pArea->uiMemoVersion );
         else
         {
            hb_itemClear( pItem );
            return SELF_RDDINFO( SELF_RDDNODE( pArea ), RDDI_MEMOVERSION, 0, pItem );
         }
         break;

      case DBI_MEMOPACK:
         return hb_fptDoPack( pArea, hb_arrayGetNI( pItem, 1 ),
                                     hb_arrayGetItemPtr( pItem, 2 ),
                                     hb_arrayGetNL( pItem, 3 ) );

      /* case DBI_RDD_VERSION */

      case DBI_BLOB_DIRECT_EXPORT:  /* BLOBDirectExport() { , ,  } */
      {
         ERRCODE errCode = FAILURE;

         if( HB_IS_ARRAY( pItem ) )
         {
            ULONG ulBlock = hb_arrayGetNL( pItem, 1 );
            BYTE * szFile = ( BYTE * ) hb_arrayGetCPtr( pItem, 2 );

            if( ulBlock && szFile && *szFile )
               errCode = hb_fptGetVarFile( pArea, ulBlock, szFile,
                                           hb_arrayGetNI( pItem, 3 ) );
         }
         hb_itemPutL( pItem, errCode == SUCCESS );
         break;
      }
      case DBI_BLOB_DIRECT_GET:     /* BLOBDirectGet() { , ,  } */
      {
         /* pItem := { , ,  } */
         ULONG ulBlock, ulStart, ulCount;
         USHORT errCode;

         if( HB_IS_ARRAY( pItem ) )
         {
            ulBlock = hb_arrayGetNL( pItem, 1 );
            ulStart = hb_arrayGetNL( pItem, 2 );
            if( ulStart )
               --ulStart;
            ulCount = hb_arrayGetNL( pItem, 3 );
         }
         else
         {
            ulBlock = ulStart = ulCount = 0;
         }
         errCode = hb_fptGetMemo( pArea, 0, pItem, FS_ERROR, ulBlock, ulStart, ulCount );
         if( errCode != SUCCESS )
         {
            if( errCode != FAILURE )
               hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
            return FAILURE;
         }
         break;
      }
      case DBI_BLOB_DIRECT_IMPORT:  /* BLOBDirectImport() { ,  } */
         if( HB_IS_ARRAY( pItem ) )
            hb_itemPutNInt( pItem, hb_fptPutVarFile( pArea,
                                             hb_arrayGetNL( pItem, 1 ),
                                  ( BYTE * ) hb_arrayGetCPtr( pItem, 2 ) ) );
         else
            hb_itemPutNI( pItem, 0 );
         break;

      case DBI_BLOB_DIRECT_PUT:     /* BLOBDirectPut() { ,  } */
      {
         /* pItem := { ,  } */
         USHORT errCode = EDBF_UNSUPPORTED;
         ULONG ulBlock = 0;

         if( HB_IS_ARRAY( pItem ) )
         {
            PHB_ITEM pValue = hb_arrayGetItemPtr( pItem, 2 );
            ulBlock = hb_arrayGetNL( pItem, 1 );
            if( pValue )
            {
               if( hb_fptFileLockEx( pArea, TRUE ) )
               {
                  errCode = hb_fptPutMemo( pArea, 0, pValue, &ulBlock );
                  hb_fptFileUnLock( pArea );
               }
               else
                  errCode = EDBF_LOCK;
            }
         }
         hb_itemPutNInt( pItem, ulBlock );
         if( errCode != SUCCESS )
         {
            if( errCode != FAILURE )
               hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
            return FAILURE;
         }
         break;
      }
      case DBI_BLOB_ROOT_GET:       /* BLOBRootGet() */
      {
         ULONG ulBlock;
         USHORT errCode;

         errCode = hb_fptGetRootBlock( pArea, &ulBlock );
         if( errCode == SUCCESS )
         {
            errCode = hb_fptGetMemo( pArea, 0, pItem, FS_ERROR, ulBlock, 0, 0 );
         }
         if( errCode != SUCCESS )
         {
            if( errCode != FAILURE )
               hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
            hb_itemClear( pItem );
            return FAILURE;
         }
         break;
      }
      case DBI_BLOB_ROOT_PUT:       /* BLOBRootPut(  ) */
      {
         ULONG ulBlock;
         USHORT errCode;

         errCode = hb_fptGetRootBlock( pArea, &ulBlock );
         if( errCode == SUCCESS )
         {
            if( hb_fptFileLockEx( pArea, TRUE ) )
            {
               errCode = hb_fptPutMemo( pArea, 0, pItem, &ulBlock );
               hb_fptFileUnLock( pArea );
               if( errCode == SUCCESS )
                  errCode = hb_fptPutRootBlock( pArea, ulBlock );
            }
            else
               errCode = EDBF_LOCK;
         }
         if( errCode != SUCCESS )
         {
            if( errCode != FAILURE )
               hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
            hb_itemPutL( pItem, FALSE );
            return FAILURE;
         }
         hb_itemPutL( pItem, TRUE );
         break;
      }
      case DBI_BLOB_ROOT_LOCK:      /* BLOBRootLock() */
         hb_itemPutL( pItem, hb_fptRootBlockLock( pArea ) );
         break;

      case DBI_BLOB_ROOT_UNLOCK:    /* BLOBRootUnlock() */
         hb_itemPutL( pItem, hb_fptRootBlockUnLock( pArea ) );
         break;

      case DBI_BLOB_DIRECT_LEN:
      case DBI_BLOB_DIRECT_TYPE:
      case DBI_BLOB_INTEGRITY:
      case DBI_BLOB_OFFSET:
      case DBI_BLOB_RECOVER:
         /* TODO: implement it */
         break;

      default:
         return SUPER_INFO( ( AREAP ) pArea, uiIndex, pItem );
   }

   return SUCCESS;
}
dbffpt1.c4663
STATIC ERRCODEhb_fptFieldInfo( FPTAREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem )
static ERRCODE hb_fptFieldInfo( FPTAREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_fptFieldInfo(%p, %hu, %hu, %p)", pArea, uiIndex, uiType, pItem));

   if( !uiIndex || uiIndex > pArea->uiFieldCount )
      return FAILURE;

   if( pArea->fHasMemo && pArea->pMemoFile &&
       ( pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_MEMO ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_IMAGE ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_BLOB ||
         pArea->lpFields[ uiIndex - 1 ].uiType == HB_FT_OLE ) )
   {
      ULONG ulBlock, ulSize, ulType;
      BOOL bDeleted;

      SELF_DELETED( ( AREAP ) pArea, &bDeleted );
      switch( uiType )
      {
         case DBS_BLOB_GET:         /* BLOBGet() { ,  } */
         {
            /* pItem := { ,  } */
            ULONG ulStart, ulCount;
            USHORT errCode;

            if( HB_IS_ARRAY( pItem ) )
            {
               ulStart = hb_arrayGetNL( pItem, 1 );
               if( ulStart )
                  --ulStart;
               ulCount = hb_arrayGetNL( pItem, 2 );
            }
            else
            {
               ulStart = ulCount = 0;
            }
            errCode = hb_fptGetMemo( pArea, uiIndex, pItem, FS_ERROR, 0, ulStart, ulCount );
            if( errCode != SUCCESS )
            {
               if( errCode != FAILURE )
                  hb_memoErrorRT( pArea, 0, errCode, pArea->szMemoFileName, 0, 0 );
               return FAILURE;
            }
            return SUCCESS;
         }
         case DBS_BLOB_LEN:
            hb_itemPutNL( pItem, hb_fptGetMemoLen( pArea, uiIndex ) );
            return SUCCESS;
         case DBS_BLOB_OFFSET:
            /* Clipper 5.3 does not support it :-( [druzus] */
            hb_dbfGetMemoData( (DBFAREAP) pArea, uiIndex - 1,
                               &ulBlock, &ulSize, &ulType );
            hb_itemPutNInt( pItem, ( HB_FOFFSET ) ulBlock * pArea->uiMemoBlockSize +
                                   ( pArea->bMemoType == DB_MEMO_FPT ? sizeof( FPTBLOCK ) : 0 ) );
            return SUCCESS;
         case DBS_BLOB_POINTER:
            /*
             * Clipper 5.3 it returns the same value as DBS_BLOB_OFFSET
             * in Harbour - it's a Clipper bug [druzus]
             */
            hb_dbfGetMemoData( (DBFAREAP) pArea, uiIndex - 1,
                               &ulBlock, &ulSize, &ulType );
            hb_itemPutNL( pItem, ulBlock );
            return SUCCESS;
         case DBS_BLOB_TYPE:
            hb_itemPutC( pItem, hb_fptGetMemoType( pArea, uiIndex ) );
            return SUCCESS;
      }
   }
   return SUPER_FIELDINFO( ( AREAP ) pArea, uiIndex, uiType, pItem );
}
dbffpt1.c4900
STATIC ERRCODEhb_fptRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnect, PHB_ITEM pItem )
static ERRCODE hb_fptRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnect, PHB_ITEM pItem )
{
   LPDBFDATA pData;

   HB_TRACE(HB_TR_DEBUG, ("hb_fptRddInfo(%p, %hu, %lu, %p)", pRDD, uiIndex, ulConnect, pItem));

   pData = ( LPDBFDATA ) pRDD->lpvCargo;

   switch( uiIndex )
   {
      case RDDI_MEMOEXT:
      {
         char * szNew = hb_itemGetCPtr( pItem ), *szMFileExt;

         if( szNew && szNew[0] == '.' && szNew[1] )
            szNew = hb_strdup( szNew );
         else
            szNew = NULL;

         if( pData->szMemoExt[ 0 ] )
            hb_itemPutC( pItem, pData->szMemoExt );
         else if( pData->bMemoType == DB_MEMO_FPT && pRDD->rddID != s_uiRddIdBLOB &&
                  ( szMFileExt = hb_setGetMFileExt() ) != NULL &&
                  *szMFileExt )
            hb_itemPutC( pItem, szMFileExt );
         else
            hb_itemPutC( pItem, hb_memoDefaultFileExt( pData->bMemoType, pRDD->rddID ) );

         if( szNew )
         {
            hb_strncpy( pData->szMemoExt, szNew, sizeof( pData->szMemoExt ) - 1 );
            hb_xfree( szNew );
         }
         break;
      }
      case RDDI_MEMOBLOCKSIZE:
      {
         int iSize = hb_itemGetNI( pItem ), iOldSize;

         if( pData->uiMemoBlockSize )
            hb_itemPutNI( pItem, pData->uiMemoBlockSize );
         else if( ( iOldSize = hb_setGetMBlockSize() ) > 0 && iOldSize <= 0xFFFF )
            hb_itemPutNI( pItem, iOldSize );
         else if( pData->bMemoType == DB_MEMO_DBT )
            hb_itemPutNI( pItem, DBT_DEFBLOCKSIZE );
         else if( pData->bMemoType == DB_MEMO_SMT )
            hb_itemPutNI( pItem, SMT_DEFBLOCKSIZE );
         else
            hb_itemPutNI( pItem, FPT_DEFBLOCKSIZE );

         if( iSize > 0 && iSize <= 0xFFFF )
            pData->uiMemoBlockSize = iSize;
         break;
      }
      case RDDI_MEMOTYPE:
      {
         int iType = hb_itemGetNI( pItem );

         hb_itemPutNI( pItem, pData->bMemoType ? pData->bMemoType : DB_MEMO_FPT );

         if( pRDD->rddID != s_uiRddIdBLOB )
         {
            switch( iType )
            {
               case DB_MEMO_DBT:
               case DB_MEMO_FPT:
               case DB_MEMO_SMT:
                  pData->bMemoType = ( BYTE ) iType;
            }
         }
         break;
      }

      case RDDI_MEMOVERSION:
      {
         int iType = hb_itemGetNI( pItem );

         hb_itemPutNI( pItem, pData->bMemoExtType ? pData->bMemoExtType : DB_MEMOVER_FLEX );
         switch( iType )
         {
            case DB_MEMOVER_STD:
            case DB_MEMOVER_SIX:
            case DB_MEMOVER_FLEX:
            case DB_MEMOVER_CLIP:
               pData->bMemoExtType = ( BYTE ) iType;
         }
         break;
      }

      case RDDI_MEMOGCTYPE:
         hb_itemPutNI( pItem, 0 );
         break;

      case RDDI_MEMOREADLOCK:
#if defined( HB_MEMO_SAFELOCK )
         hb_itemPutL( pItem, pRDD->rddID != s_uiRddIdBLOB );
#else
         hb_itemPutL( pItem, FALSE );
#endif
         break;
      case RDDI_MEMOREUSE:
         hb_itemPutL( pItem, TRUE );
         break;

      case RDDI_BLOB_SUPPORT:
         hb_itemPutL( pItem, pRDD->rddID == s_uiRddIdBLOB );
         break;

      default:
         return SUPER_RDDINFO( pRDD, uiIndex, ulConnect, pItem );
   }

   return SUCCESS;
}

HB_FUNC( DBFDBT ) {;}
HB_FUNC( DBFSMT ) {;}
HB_FUNC( DBFFPT ) {;}
HB_FUNC( DBFBLOB ) {;}
dbffpt1.c4976
} STATIC VOIDhb_dbffptRegisterRDD( USHORT * pusRddId )
static void hb_dbffptRegisterRDD( USHORT * pusRddId )
{
   RDDFUNCS * pTable;
   USHORT * uiCount, uiRddId;

   uiCount = ( USHORT * ) hb_parptr( 1 );
   pTable = ( RDDFUNCS * ) hb_parptr( 2 );
   uiRddId = hb_parni( 4 );

   HB_TRACE(HB_TR_DEBUG, ("DBFFPT_GETFUNCTABLE(%p, %p)", uiCount, pTable));

   if( pTable )
   {
      ERRCODE errCode;

      if( uiCount )
         * uiCount = RDDFUNCSCOUNT;

      errCode = hb_rddInherit( pTable, &fptTable, &fptSuper, "DBF" );
      if( errCode == SUCCESS )
         *pusRddId = uiRddId;
      hb_retni( errCode );
   }
   else
      hb_retni( FAILURE );
}
dbffpt1.c5100
HB_FUNCDBFFPT_GETFUNCTABLE(void)
HB_FUNC( DBFFPT_GETFUNCTABLE )
{
   HB_TRACE(HB_TR_DEBUG, ("DBFFPT_GETFUNCTABLE()"));

   hb_dbffptRegisterRDD( &s_uiRddIdFPT );
}
dbffpt1.c5127
HB_FUNCDBFBLOB_GETFUNCTABLE(void)
HB_FUNC( DBFBLOB_GETFUNCTABLE )
{
   HB_TRACE(HB_TR_DEBUG, ("DBFBLOB_GETFUNCTABLE()"));

   hb_dbffptRegisterRDD( &s_uiRddIdBLOB );
}

#define __PRG_SOURCE__ __FILE__

#ifdef HB_PCODE_VER
#  undef HB_PRG_PCODE_VER
#  define HB_PRG_PCODE_VER HB_PCODE_VER
#endif

HB_FUNC_EXTERN( _DBF );
dbffpt1.c5134
STATIC VOIDhb_dbffptRddInit( void * cargo )
static void hb_dbffptRddInit( void * cargo )
{
   HB_SYMBOL_UNUSED( cargo );

   if( hb_rddRegister( "DBF",     RDT_FULL ) > 1 ||
       hb_rddRegister( "DBFFPT",  RDT_FULL ) > 1 ||
       hb_rddRegister( "DBFBLOB", RDT_FULL ) > 1 )
   {
      hb_errInternal( HB_EI_RDDINVALID, NULL, NULL, NULL );

      /* not executed, only to force DBF RDD linking */
      HB_FUNC_EXEC( _DBF );
   }
}
dbffpt1.c5150
HB_INIT_SYMBOLS_BEGIN(dbffpt1__InitSymbols )
HB_INIT_SYMBOLS_BEGIN( dbffpt1__InitSymbols )
{ "DBFFPT",               {HB_FS_PUBLIC|HB_FS_LOCAL}, {HB_FUNCNAME( DBFFPT )},               NULL },
{ "DBFFPT_GETFUNCTABLE",  {HB_FS_PUBLIC|HB_FS_LOCAL}, {HB_FUNCNAME( DBFFPT_GETFUNCTABLE )},  NULL },
{ "DBFBLOB",              {HB_FS_PUBLIC|HB_FS_LOCAL}, {HB_FUNCNAME( DBFBLOB )},              NULL },
{ "DBFBLOB_GETFUNCTABLE", {HB_FS_PUBLIC|HB_FS_LOCAL}, {HB_FUNCNAME( DBFBLOB_GETFUNCTABLE )}, NULL }
HB_INIT_SYMBOLS_END( dbffpt1__InitSymbols )

HB_CALL_ON_STARTUP_BEGIN( _hb_dbffpt_rdd_init_ )
   hb_vmAtInit( hb_dbffptRddInit, NULL );
HB_CALL_ON_STARTUP_END( _hb_dbffpt_rdd_init_ )

#if defined( HB_PRAGMA_STARTUP )
   #pragma startup dbffpt1__InitSymbols
   #pragma startup _hb_dbffpt_rdd_init_
#elif defined( HB_MSC_STARTUP )
   #if defined( HB_OS_WIN_64 )
      #pragma section( HB_MSC_START_SEGMENT, long, read )
   #endif
   #pragma data_seg( HB_MSC_START_SEGMENT )
   static HB_$INITSYM hb_vm_auto_dbffpt1__InitSymbols = dbffpt1__InitSymbols;
   static HB_$INITSYM hb_vm_auto_dbffpt_rdd_init = _hb_dbffpt_rdd_init_;
dbffpt1.c5165

Page url: http://www.yourdomain.com/help/index.html?dbffpt.htm