From 517ad9d4b6eae320b708d03a9340a22893b0cab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 29 Jan 2023 15:45:51 +0100 Subject: New upstream version 4.0.3 --- src/core/xbmemo3.cpp | 109 ++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 62 deletions(-) (limited to 'src/core/xbmemo3.cpp') diff --git a/src/core/xbmemo3.cpp b/src/core/xbmemo3.cpp index b5494fb..60c1d53 100755 --- a/src/core/xbmemo3.cpp +++ b/src/core/xbmemo3.cpp @@ -92,6 +92,7 @@ xbInt16 xbMemoDbt3::DumpMemoFreeChain() { std::cout << "Xbase version 3 file - no free block chain" << std::endl; return XB_NO_ERROR; } +#endif // XB_DEBUG_SUPPORT //! @brief Dump memo file header. /*! @@ -114,7 +115,6 @@ xbInt16 xbMemoDbt3::DumpMemoHeader(){ std::cout << "Block Count = " << stFileSize / GetBlockSize() << std::endl; return XB_NO_ERROR; } -#endif // XB_DEBUG_SUPPORT /***********************************************************************/ //! @brief Get a memo field for a given field number. /*! @@ -134,7 +134,7 @@ xbInt16 xbMemoDbt3::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ sMemoData = ""; try{ if(( rc = dbf->GetULongField( iFieldNo, ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if( ulBlockNo == 0L ){ @@ -144,7 +144,7 @@ xbInt16 xbMemoDbt3::GetMemoField( xbInt16 iFieldNo, xbString & sMemoData ){ spp = NULL; while( !bDone ){ if(( rc = ReadBlock( ulBlockNo++, GetBlockSize(), mbb )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 120; throw rc; } ulScnt = 0; @@ -185,7 +185,7 @@ xbInt16 xbMemoDbt3::GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 & ulFieldLen ){ xbInt16 iNotDone; try{ if(( rc = dbf->GetULongField( iFieldNo, ulBlockNo )) < XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } if( ulBlockNo == 0 ){ @@ -197,7 +197,7 @@ xbInt16 xbMemoDbt3::GetMemoFieldLen( xbInt16 iFieldNo, xbUInt32 & ulFieldLen ){ iNotDone = 1; while( iNotDone ){ if(( rc = ReadBlock( ulBlockNo++, GetBlockSize(), mbb )) != XB_NO_ERROR ){ - iErrorStop = 1; + iErrorStop = 110; throw rc; } iScnt = 0; @@ -251,22 +251,21 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI char * cBlock = NULL; #ifdef XB_LOCKING_SUPPORT - xbInt16 iAutoLock = dbf->GetAutoLock(); xbBool bTableLocked = xbFalse; xbBool bMemoLocked = xbFalse; #endif try{ #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && !dbf->GetTableLocked() ){ + if( dbf->GetAutoLock() && !dbf->GetTableLocked() ){ if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } else { bTableLocked = xbTrue; } if(( iRc = LockMemo( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } else { bMemoLocked = xbTrue; @@ -277,20 +276,20 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI // create temp file xbString sTempMemoName; if(( iRc = CreateUniqueFileName( GetDirectory(), "dbt", sTempMemoName )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 120; throw iRc; } xbMemoDbt3 *pMemo = new xbMemoDbt3( dbf, sTempMemoName ); if(( iRc = pMemo->CreateMemoFile()) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 130; throw iRc; } // for dbase III, block size is always 512, don't need to reset it // for each record in dbf xbUInt32 ulRecCnt; if(( iRc = dbf->GetRecordCnt( ulRecCnt )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 140; throw iRc; } xbInt32 lFldCnt = dbf->GetFieldCnt(); @@ -299,7 +298,7 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI for( xbUInt32 ulI = 1; ulI <= ulRecCnt; ulI++ ){ if(( iRc = dbf->GetRecord( ulI )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 150; throw iRc; } if( (void *) memoStatusFunc ) @@ -308,18 +307,18 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI // for each memo field for( xbInt32 lFc = 0; lFc < lFldCnt; lFc++ ){ if(( iRc = dbf->GetFieldType( lFc, cFldType )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 160; throw iRc; } if( cFldType == 'M' ){ // copy it to work field if(( iRc = dbf->GetMemoField( lFc, sMemoFldData )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 170; throw iRc; } // write it to new field if(( iRc = pMemo->UpdateMemoField( lFc, sMemoFldData )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 180; throw iRc; } } @@ -330,25 +329,25 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI xbUInt32 ulBlkSize = GetBlockSize(); xbUInt64 ullFileSize; if(( iRc = pMemo->GetFileSize( ullFileSize )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 190; throw iRc; } // file size should be evenly divisible by block size xbUInt32 ulBlkCnt; if( ullFileSize % ulBlkSize ){ - iErrorStop = 90; + iErrorStop = 200; throw iRc; } else { ulBlkCnt = (xbUInt32) (ullFileSize / ulBlkSize); } if(( iRc = xbTruncate( 0 )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 210; throw iRc; } if(( cBlock = (char *) malloc( (size_t) ulBlkSize )) == NULL ){ - iErrorStop = 110; + iErrorStop = 220; throw iRc; } @@ -356,54 +355,40 @@ xbInt16 xbMemoDbt3::PackMemo( void (*memoStatusFunc ) ( xbUInt32 ulItemNum, xbUI // copy work table back to source table for( xbUInt32 ulBc = 0; ulBc < ulBlkCnt; ulBc++ ){ if(( iRc = pMemo->ReadBlock( ulBc, ulBlkSize, cBlock )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 230; throw iRc; } if(( iRc = WriteBlock( ulBc, ulBlkSize, cBlock )) != XB_NO_ERROR ){ - iErrorStop = 130; + iErrorStop = 240; throw iRc; } } //close and delete target if(( iRc = pMemo->xbFclose()) != XB_NO_ERROR ){ - iErrorStop = 140; + iErrorStop = 250; throw iRc; } if(( iRc = pMemo->xbRemove()) != XB_NO_ERROR ){ - iErrorStop = 150; + iErrorStop = 260; throw iRc; } free( cBlock ); delete pMemo; - - #ifdef XB_LOCKING_SUPPORT - if( iAutoLock && !dbf->GetTableLocked() ){ - if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 200; - throw iRc; - } - if(( iRc = LockMemo( XB_UNLOCK )) != XB_NO_ERROR ){ - iErrorStop = 210; - throw iRc; - } - } - #endif } catch (xbInt16 iRc ){ free( cBlock ); - - #ifdef XB_LOCKING_SUPPORT - if( bTableLocked ) - dbf->LockTable( XB_UNLOCK ); - if( bMemoLocked ) - LockMemo( XB_UNLOCK ); - #endif - xbString sMsg; sMsg.Sprintf( "xbMemoDbt3::PackMemo() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc ); xbase->WriteLogMessage( sMsg.Str() ); xbase->WriteLogMessage( GetErrorMessage( iRc )); } + + #ifdef XB_LOCKING_SUPPORT + if( bTableLocked ) + dbf->LockTable( XB_UNLOCK ); + if( bMemoLocked ) + LockMemo( XB_UNLOCK ); + #endif return iRc; } @@ -424,7 +409,7 @@ xbInt16 xbMemoDbt3::ReadDbtHeader( xbInt16 iOption ){ try{ if( !FileIsOpen() ){ - iErrorStop = 10; + iErrorStop = 100; rc = XB_NOT_OPEN; throw rc; } @@ -433,26 +418,26 @@ xbInt16 xbMemoDbt3::ReadDbtHeader( xbInt16 iOption ){ else{ xbUInt64 stFileSize = 0; if(( rc = GetFileSize( stFileSize )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } if( stFileSize < 4 ){ - iErrorStop = 30; + iErrorStop = 120; rc = XB_INVALID_BLOCK_NO; throw rc; } else if( stFileSize > 20 ) - ulReadSize = 40; + ulReadSize = 130; else ulReadSize = 4; } if( xbFseek( 0, SEEK_SET )){ - iErrorStop = 50; + iErrorStop = 140; rc = XB_SEEK_ERROR; throw rc; } if(( xbFread( &MemoBlock, ulReadSize, 1 )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; rc = XB_READ_ERROR; throw rc; } @@ -498,7 +483,7 @@ xbInt16 xbMemoDbt3::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat try{ if( sMemoData == "" ){ if(( rc = dbf->PutField( iFieldNo, "" )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw rc; } } else { @@ -506,32 +491,32 @@ xbInt16 xbMemoDbt3::UpdateMemoField( xbInt16 iFieldNo, const xbString & sMemoDat xbUInt32 ulBlocksNeeded = (ulDataLen / 512) + 1; xbUInt32 ulLastDataBlock; if(( rc = CalcLastDataBlock( ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw rc; } if(( rc = xbFseek( ((xbInt64) ulLastDataBlock * 512), SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw rc; } if(( rc = xbFwrite( sMemoData.Str(), sMemoData.Len(), 1 )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw rc; } if(( rc = xbFputc( 0x1a, 2 )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw rc; } if(( rc = xbFputc( 0x00, (xbInt32) ( ulBlocksNeeded * 512 ) - (xbInt32) ulDataLen )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 150; throw rc; } if(( rc = dbf->PutULongField( iFieldNo, ulLastDataBlock )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 160; throw rc; } ulHdrNextBlock = ulLastDataBlock + ulBlocksNeeded; if(( rc = UpdateHeadNextNode()) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 170; throw rc; } } @@ -563,15 +548,15 @@ xbInt16 xbMemoDbt3::Zap(){ ePutUInt32( cBuf, ulHdrNextBlock ); if(( iRc != xbFseek( 0, SEEK_SET )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } if(( iRc != xbFwrite( cBuf, 4, 1 ))!= XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } if(( iRc != xbTruncate( 512 )) != XB_NO_ERROR ){ - iErrorStop = 30; + iErrorStop = 120; throw iRc; } } -- cgit v1.2.3