diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e8da9ceff4..e535ead427 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,12 @@ past entries belonging to these authors: Viktor Szakats. */ + +2009-05-04 10:00 UTC+0100 Miguel Angel Marchuet + * contrib/hbbmcdx/bmdbfcdx.c + * contrib/hbbmcdx/hbbmcdx.h + * Synchronized with current dbfcdx. + 2009-05-03 15:44 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * utils/hbmk2/hbmk2.prg * Translation improvements. diff --git a/harbour/contrib/hbbmcdx/bmdbfcdx.c b/harbour/contrib/hbbmcdx/bmdbfcdx.c index 72a770ad0a..020ac1a613 100644 --- a/harbour/contrib/hbbmcdx/bmdbfcdx.c +++ b/harbour/contrib/hbbmcdx/bmdbfcdx.c @@ -312,11 +312,11 @@ static void hb_cdxDspTags( LPCDXINDEX pIndex ) LPCDXTAG pTag = NULL; printf( "\r\n*TAGS*" ); - while ( pIndex ) + while( pIndex ) { printf( "\r\nBAG: [%s] ->", pIndex->szFileName ); pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { printf( " {%s}", pTag->szName ); pTag = pTag->pNext; @@ -407,7 +407,7 @@ static HB_ERRCODE hb_cdxErrorRT( CDXAREAP pArea, USHORT uiGenCode, USHORT uiSubC static void hb_cdxMakeSortTab( CDXAREAP pArea ) { #ifndef HB_CDP_SUPPORT_OFF - if ( pArea->cdPage && pArea->cdPage->lSort && !pArea->bCdxSortTab ) + if( pArea->cdPage && pArea->cdPage->lSort && !pArea->bCdxSortTab ) { int i, j, l; BYTE * pbSort; @@ -417,7 +417,7 @@ static void hb_cdxMakeSortTab( CDXAREAP pArea ) pbSort = ( BYTE * ) hb_xgrab( 256 ); /* this table should be allready quite good sorted so this simple algorithms will be one of the most efficient one. */ - for ( i = 0; i <= 255; i++ ) + for( i = 0; i <= 255; i++ ) pbSort[i] = ( BYTE ) i; l = 255; do @@ -425,7 +425,7 @@ static void hb_cdxMakeSortTab( CDXAREAP pArea ) j = l; for( i = 0; i < j; i++ ) { - if ( hb_cdpchrcmp( pbSort[i], pbSort[i+1], pArea->cdPage ) > 0 ) + if( hb_cdpchrcmp( pbSort[i], pbSort[i+1], pArea->cdPage ) > 0 ) { b = pbSort[i+1]; pbSort[i+1] = pbSort[i]; @@ -433,8 +433,8 @@ static void hb_cdxMakeSortTab( CDXAREAP pArea ) l = i; } } - } while ( j != l ); - for ( i = 0; i <= 255; i++ ) + } while( j != l ); + for( i = 0; i <= 255; i++ ) pArea->bCdxSortTab[pbSort[i]] = i; hb_xfree( pbSort ); } @@ -460,7 +460,7 @@ static LPCDXKEY hb_cdxKeyNew( void ) */ static void hb_cdxKeyFree( LPCDXKEY pKey ) { - if ( pKey->val ) + if( pKey->val ) hb_xfree( pKey->val ); hb_xfree( pKey ); } @@ -470,29 +470,31 @@ static void hb_cdxKeyFree( LPCDXKEY pKey ) */ static LPCDXKEY hb_cdxKeyCopy( LPCDXKEY pKeyDest, LPCDXKEY pKey ) { - if ( !pKeyDest ) + if( !pKeyDest ) pKeyDest = hb_cdxKeyNew(); else { pKeyDest->rec = 0; - if ( pKeyDest->val && pKeyDest->len != pKey->len ) + pKeyDest->mode = CDX_CMP_EXACT; + if( pKeyDest->val && pKeyDest->len != pKey->len ) { hb_xfree( pKeyDest->val ); pKeyDest->val = NULL; pKeyDest->len = 0; } } - if ( pKey ) + if( pKey ) { - if ( pKey->len ) + if( pKey->len ) { - if ( !pKeyDest->val ) + if( !pKeyDest->val ) pKeyDest->val = (BYTE *) hb_xgrab( pKey->len + 1 ); memcpy( pKeyDest->val, pKey->val, pKey->len ); pKeyDest->len = pKey->len; pKeyDest->val[ pKeyDest->len ] = '\0'; } pKeyDest->rec = pKey->rec; + pKeyDest->mode = pKey->mode; } return pKeyDest; } @@ -502,25 +504,26 @@ static LPCDXKEY hb_cdxKeyCopy( LPCDXKEY pKeyDest, LPCDXKEY pKey ) */ static LPCDXKEY hb_cdxKeyPut( LPCDXKEY pKey, BYTE * pbVal, USHORT uiLen, ULONG ulRec ) { - if ( !pKey ) + if( !pKey ) pKey = hb_cdxKeyNew(); else { - if ( pKey->val && pKey->len != uiLen ) + if( pKey->val && pKey->len != uiLen ) { hb_xfree( pKey->val ); pKey->val = NULL; pKey->len = 0; } } - if ( pbVal && uiLen ) + if( pbVal && uiLen ) { pKey->len = (BYTE) uiLen; - if ( !pKey->val ) + if( !pKey->val ) pKey->val = ( BYTE * ) hb_xgrab( uiLen + 1 ); memcpy( pKey->val, pbVal, uiLen ); pKey->val[ uiLen ] = '\0'; } + pKey->mode = CDX_CMP_EXACT; pKey->rec = ulRec; return pKey; } @@ -532,27 +535,28 @@ static LPCDXKEY hb_cdxKeyPutC( LPCDXKEY pKey, char * szText, USHORT uiRealLen, U { USHORT uiLen; - if ( !pKey ) + if( !pKey ) pKey = hb_cdxKeyNew(); else { - if ( pKey->val ) + if( pKey->val ) { hb_xfree( pKey->val ); pKey->val = NULL; pKey->len = 0; } } - uiLen = (USHORT) ( szText ? strlen( szText ) : 0 ); - if ( uiLen > uiRealLen ) + uiLen = ( USHORT ) ( szText ? strlen( szText ) : 0 ); + if( uiLen > uiRealLen ) uiLen = uiRealLen; pKey->len = ( BYTE ) uiRealLen; pKey->val = ( BYTE * ) hb_xgrab( uiRealLen + 1 ); - if ( uiLen ) + if( uiLen ) memcpy( pKey->val, szText, uiLen ); - if ( uiLen < uiRealLen ) + if( uiLen < uiRealLen ) memset( &pKey->val[ uiLen ], ' ', uiRealLen - uiLen ); pKey->val[ uiRealLen ] = '\0'; + pKey->mode = CDX_CMP_EXACT; pKey->rec = ulRec; return pKey; } @@ -561,20 +565,20 @@ static LPCDXKEY hb_cdxKeyPutC( LPCDXKEY pKey, char * szText, USHORT uiRealLen, U * compare two values using Tag conditions (len & type) */ static int hb_cdxValCompare( LPCDXTAG pTag, BYTE * val1, BYTE len1, - BYTE * val2, BYTE len2, BOOL fExact ) + BYTE * val2, BYTE len2, int iMode ) { int iLimit, iResult = 0; - iLimit = (len1 > len2) ? len2 : len1; + iLimit = ( len1 > len2 ) ? len2 : len1; - if ( pTag->uiType == 'C' ) + if( pTag->uiType == 'C' ) { #ifndef HB_CDP_SUPPORT_OFF - if ( pTag->pIndex->pArea->bCdxSortTab ) + if( pTag->pIndex->pArea->bCdxSortTab ) { BYTE * pSort = pTag->pIndex->pArea->bCdxSortTab; int iPos = 0; - while ( iResult == 0 && iPos < iLimit ) + while( iResult == 0 && iPos < iLimit ) { iResult = pSort[ val1[ iPos ] ] - pSort[ val2[ iPos ] ]; iPos++; @@ -582,24 +586,37 @@ static int hb_cdxValCompare( LPCDXTAG pTag, BYTE * val1, BYTE len1, } else #endif - if ( iLimit > 0 ) + if( iLimit > 0 ) iResult = memcmp( val1, val2, iLimit ); - if ( iResult == 0 ) + if( iResult == 0 ) { - if ( len1 > len2 ) + if( len1 > len2 ) iResult = 1; - else if ( len1 < len2 && fExact ) + else if( len1 < len2 && iMode == CDX_CMP_EXACT ) iResult = -1; } } + else if( iMode == CDX_CMP_DATE && iLimit == 8 ) + { + double d1, d2; + long l; + + HB_ORD2DBL( val1, &d1 ); + HB_ORD2DBL( val2, &d2 ); + l = ( long ) d1 - ( long ) d2; + if( l < 0 ) + iResult = -1; + else if( l > 0 ) + iResult = 1; + } else { - if ( iLimit == 0 || (iResult = memcmp( val1, val2, iLimit )) == 0 ) + if( iLimit == 0 || (iResult = memcmp( val1, val2, iLimit )) == 0 ) { - if ( len1 > len2 ) + if( len1 > len2 ) iResult = 1; - else if ( len1 < len2 ) + else if( len1 < len2 ) iResult = -1; } } @@ -625,6 +642,9 @@ static BYTE hb_cdxItemType( PHB_ITEM pItem ) case HB_IT_DATE: return 'D'; + case HB_IT_TIMESTAMP: + return 'T'; + case HB_IT_LOGICAL: return 'L'; @@ -634,11 +654,19 @@ static BYTE hb_cdxItemType( PHB_ITEM pItem ) } +/* + * convert internal type of key expression to comparable type + */ +static BYTE hb_cdxItemTypeCmp( BYTE bType ) +{ + return bType == 'T' ? 'D' : bType; +} + /* * store Item in index key * TODO: uiType check and generate RT error if necessary */ -static LPCDXKEY hb_cdxKeyPutItem( LPCDXKEY pKey, PHB_ITEM pItem, ULONG ulRec, LPCDXTAG pTag, BOOL fTrans, BOOL fSize ) +static LPCDXKEY hb_cdxKeyPutItem( LPCDXKEY pKey, PHB_ITEM pItem, ULONG ulRec, LPCDXTAG pTag, BOOL fTrans, int iMode ) { BYTE buf[CDX_MAXKEY], *ptr; ULONG ulLen = 0; @@ -646,13 +674,13 @@ static LPCDXKEY hb_cdxKeyPutItem( LPCDXKEY pKey, PHB_ITEM pItem, ULONG ulRec, LP ptr = &buf[0]; - switch ( hb_cdxItemType( pItem ) ) + switch( hb_cdxItemType( pItem ) ) { case 'C': ulLen = hb_itemGetCLen( pItem ); - if( ulLen > (ULONG) pTag->uiLen ) + if( ulLen > ( ULONG ) pTag->uiLen ) ulLen = pTag->uiLen; - if ( fSize && ulLen < (ULONG) pTag->uiLen ) + if( iMode == CDX_CMP_EXACT && ulLen < ( ULONG ) pTag->uiLen ) { memcpy( ptr, hb_itemGetCPtr( pItem ), ulLen ); memset( ptr + ulLen, pTag->bTrail, pTag->uiLen - ulLen ); @@ -664,12 +692,31 @@ static LPCDXKEY hb_cdxKeyPutItem( LPCDXKEY pKey, PHB_ITEM pItem, ULONG ulRec, LP } break; case 'N': - d = hb_itemGetND( pItem ); - HB_DBL2ORD( &d, ptr ); - ulLen = 8; + if( pTag->uiLen == 4 ) + { + UINT32 uiVal = ( UINT32 ) hb_itemGetNI( pItem ) + 0x80000000; + HB_PUT_BE_UINT32( ptr, uiVal ); + ulLen = 4; + } + else + { + d = hb_itemGetND( pItem ); + HB_DBL2ORD( &d, ptr ); + ulLen = 8; + } break; case 'D': - d = (double) hb_itemGetDL( pItem ); + d = ( double ) hb_itemGetDL( pItem ); + HB_DBL2ORD( &d, ptr ); + ulLen = 8; + if( iMode == CDX_CMP_PREFIX && pTag->uiType == 'T' ) + iMode = CDX_CMP_DATE; + break; + case 'T': + if( pTag->uiType == 'D' ) + d = ( double ) hb_itemGetDL( pItem ); + else + d = hb_itemGetTD( pItem ); HB_DBL2ORD( &d, ptr ); ulLen = 8; break; @@ -682,12 +729,18 @@ static LPCDXKEY hb_cdxKeyPutItem( LPCDXKEY pKey, PHB_ITEM pItem, ULONG ulRec, LP break; } pKey = hb_cdxKeyPut( pKey, ptr, ( USHORT ) ulLen, ulRec ); + pKey->mode = ( USHORT ) iMode; + if( pTag->uiType == 'C' ) + { #ifndef HB_CDP_SUPPORT_OFF - if ( fTrans && pTag->uiType == 'C' ) - hb_cdpnTranslate( ( char * ) pKey->val, hb_vmCDP(), pTag->pIndex->pArea->cdPage, pKey->len ); + if( fTrans ) + hb_cdpnTranslate( ( char * ) pKey->val, hb_vmCDP(), pTag->pIndex->pArea->cdPage, pKey->len ); #else - HB_SYMBOL_UNUSED( fTrans ); + HB_SYMBOL_UNUSED( fTrans ); #endif + if( pTag->IgnoreCase ) + hb_strUpper( ( char * ) pKey->val, pKey->len ); + } return pKey; } @@ -698,7 +751,7 @@ static PHB_ITEM hb_cdxKeyGetItem( LPCDXKEY pKey, PHB_ITEM pItem, LPCDXTAG pTag, { double d; - if ( pKey ) + if( pKey ) { switch( pTag->uiType ) { @@ -722,24 +775,36 @@ static PHB_ITEM hb_cdxKeyGetItem( LPCDXKEY pKey, PHB_ITEM pItem, LPCDXTAG pTag, } break; case 'N': - HB_ORD2DBL( pKey->val, &d ); - pItem = hb_itemPutND( pItem, d ); + if( pKey->len == 4 ) + { + INT32 iVal = ( INT32 ) ( HB_GET_BE_UINT32( pKey->val ) ) - 0x80000000; + pItem = hb_itemPutNI( pItem, iVal ); + } + else + { + HB_ORD2DBL( pKey->val, &d ); + pItem = hb_itemPutND( pItem, d ); + } break; case 'D': HB_ORD2DBL( pKey->val, &d ); pItem = hb_itemPutDL( pItem, ( LONG ) d ); break; + case 'T': + HB_ORD2DBL( pKey->val, &d ); + pItem = hb_itemPutTD( pItem, d ); + break; case 'L': pItem = hb_itemPutL( pItem, pKey->val[0] == 'T' ); break; default: - if ( pItem ) + if( pItem ) hb_itemClear( pItem ); else pItem = hb_itemNew( NULL ); } } - else if ( pItem ) + else if( pItem ) hb_itemClear( pItem ); else pItem = hb_itemNew( NULL ); @@ -758,26 +823,26 @@ static LPCDXKEY hb_cdxKeyEval( LPCDXKEY pKey, LPCDXTAG pTag ) PHB_CODEPAGE cdpTmp = hb_cdpSelect( pArea->cdPage ); #endif - if ( pTag->nField ) + if( pTag->nField ) { pItem = hb_itemNew( NULL ); SELF_GETVALUE( ( AREAP ) pArea, pTag->nField, pItem ); - pKey = hb_cdxKeyPutItem( pKey, pItem, pArea->ulRecNo, pTag, FALSE, TRUE ); + pKey = hb_cdxKeyPutItem( pKey, pItem, pArea->ulRecNo, pTag, FALSE, CDX_CMP_EXACT ); hb_itemRelease( pItem ); } else { int iCurrArea = hb_rddGetCurrentWorkAreaNumber(); - if ( iCurrArea != pArea->uiArea ) + if( iCurrArea != pArea->uiArea ) hb_rddSelectWorkAreaNumber( pArea->uiArea ); else iCurrArea = 0; pItem = hb_vmEvalBlockOrMacro( pTag->pKeyItem ); - pKey = hb_cdxKeyPutItem( pKey, pItem, pArea->ulRecNo, pTag, FALSE, TRUE ); + pKey = hb_cdxKeyPutItem( pKey, pItem, pArea->ulRecNo, pTag, FALSE, CDX_CMP_EXACT ); - if ( iCurrArea ) + if( iCurrArea ) hb_rddSelectWorkAreaNumber( iCurrArea ); } @@ -796,10 +861,10 @@ static BOOL hb_cdxEvalCond( CDXAREAP pArea, PHB_ITEM pCondItem, BOOL fSetWA ) int iCurrArea = 0; BOOL fRet; - if ( fSetWA ) + if( fSetWA ) { iCurrArea = hb_rddGetCurrentWorkAreaNumber(); - if ( iCurrArea != pArea->uiArea ) + if( iCurrArea != pArea->uiArea ) hb_rddSelectWorkAreaNumber( pArea->uiArea ); else iCurrArea = 0; @@ -807,7 +872,7 @@ static BOOL hb_cdxEvalCond( CDXAREAP pArea, PHB_ITEM pCondItem, BOOL fSetWA ) fRet = hb_itemGetL( hb_vmEvalBlockOrMacro( pCondItem ) ); - if ( iCurrArea ) + if( iCurrArea ) hb_rddSelectWorkAreaNumber( iCurrArea ); return fRet; @@ -839,19 +904,21 @@ static BOOL hb_cdxTopScope( LPCDXTAG pTag ) { LPCDXKEY pKey; - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) { pKey = pTag->topScopeKey; return !pKey || !pKey->len || hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, FALSE ) <= 0; + pTag->CurKey->val, pTag->CurKey->len, + pKey->mode ) <= 0; } else { pKey = pTag->bottomScopeKey; return !pKey || !pKey->len || hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, FALSE ) >= 0; + pTag->CurKey->val, pTag->CurKey->len, + pKey->mode ) >= 0; } } @@ -862,19 +929,21 @@ static BOOL hb_cdxBottomScope( LPCDXTAG pTag ) { LPCDXKEY pKey; - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) { pKey = pTag->bottomScopeKey; return !pKey || !pKey->len || hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, FALSE ) >= 0; + pTag->CurKey->val, pTag->CurKey->len, + pKey->mode ) >= 0; } else { pKey = pTag->topScopeKey; return !pKey || !pKey->len || hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, FALSE ) <= 0; + pTag->CurKey->val, pTag->CurKey->len, + pKey->mode ) <= 0; } } @@ -893,7 +962,7 @@ static void hb_cdxTagClearScope( LPCDXTAG pTag, USHORT nScope ) if( pArea->lpdbPendingRel && pArea->lpdbPendingRel->isScoped ) SELF_FORCEREL( ( AREAP ) pArea ); - if ( pTag->UsrAscend ? nScope == 0 : nScope != 0 ) + if( pTag->UsrAscend ? nScope == 0 : nScope != 0 ) { pScope = &pTag->topScope; pScopeKey = &pTag->topScopeKey; @@ -903,17 +972,17 @@ static void hb_cdxTagClearScope( LPCDXTAG pTag, USHORT nScope ) pScope = &pTag->bottomScope; pScopeKey = &pTag->bottomScopeKey; } - if ( *pScope ) + if( *pScope ) { hb_itemRelease( *pScope ); *pScope = NULL; } - if ( *pScopeKey ) + if( *pScopeKey ) { hb_cdxKeyFree( *pScopeKey ); *pScopeKey = NULL; pTag->curKeyState &= ~( CDX_CURKEY_RAWCNT | CDX_CURKEY_LOGCNT ); - if ( nScope == 0 ) + if( nScope == 0 ) pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS ); } } @@ -933,13 +1002,13 @@ static void hb_cdxTagSetScope( LPCDXTAG pTag, USHORT nScope, PHB_ITEM pItem ) pScopeVal = ( hb_itemType( pItem ) == HB_IT_BLOCK ) ? hb_vmEvalBlock( pItem ) : pItem; - if ( pTag->uiType == hb_cdxItemType( pScopeVal ) ) + if( hb_cdxItemTypeCmp( pTag->uiType ) == hb_cdxItemTypeCmp( hb_cdxItemType( pScopeVal ) ) ) { PHB_ITEM *pScope; LPCDXKEY *pScopeKey; ULONG ulRec; - if ( pTag->UsrAscend ? nScope == 0 : nScope != 0 ) + if( pTag->UsrAscend ? nScope == 0 : nScope != 0 ) { pScope = &(pTag->topScope); pScopeKey = &(pTag->topScopeKey); @@ -952,12 +1021,12 @@ static void hb_cdxTagSetScope( LPCDXTAG pTag, USHORT nScope, PHB_ITEM pItem ) ulRec = CDX_MAX_REC_NUM; } - if ( *pScope == NULL ) + if( *pScope == NULL ) *pScope = hb_itemNew( NULL ); hb_itemCopy( *pScope, pItem ); - *pScopeKey = hb_cdxKeyPutItem( *pScopeKey, pScopeVal, ulRec, pTag, TRUE, FALSE ); + *pScopeKey = hb_cdxKeyPutItem( *pScopeKey, pScopeVal, ulRec, pTag, TRUE, CDX_CMP_PREFIX ); pTag->curKeyState &= ~( CDX_CURKEY_RAWCNT | CDX_CURKEY_LOGCNT ); - if ( nScope == 0 ) + if( nScope == 0 ) pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS ); } else @@ -980,7 +1049,7 @@ static void hb_cdxTagGetScope( LPCDXTAG pTag, USHORT nScope, PHB_ITEM pItem ) pScope = ( pTag->UsrAscend ? nScope == 0 : nScope != 0 ) ? &(pTag->topScope) : &(pTag->bottomScope); - if ( *pScope ) + if( *pScope ) hb_itemCopy( pItem, *pScope ); else hb_itemClear( pItem ); @@ -997,17 +1066,19 @@ static void hb_cdxTagRefreshScope( LPCDXTAG pTag ) pTag->pIndex->pArea->lpdbPendingRel->isScoped ) SELF_FORCEREL( ( AREAP ) pTag->pIndex->pArea ); - if ( hb_itemType( pTag->topScope ) == HB_IT_BLOCK ) + if( hb_itemType( pTag->topScope ) == HB_IT_BLOCK ) { pItem = hb_vmEvalBlock( pTag->topScope ); pTag->topScopeKey = hb_cdxKeyPutItem( pTag->topScopeKey, pItem, - pTag->topScopeKey->rec, pTag, TRUE, FALSE ); + pTag->topScopeKey->rec, pTag, + TRUE, CDX_CMP_PREFIX ); } - if ( hb_itemType( pTag->bottomScope ) == HB_IT_BLOCK ) + if( hb_itemType( pTag->bottomScope ) == HB_IT_BLOCK ) { pItem = hb_vmEvalBlock( pTag->bottomScope ); pTag->bottomScopeKey = hb_cdxKeyPutItem( pTag->bottomScopeKey, pItem, - pTag->bottomScopeKey->rec, pTag, TRUE, FALSE ); + pTag->bottomScopeKey->rec, pTag, + TRUE, CDX_CMP_PREFIX ); } } @@ -1021,9 +1092,9 @@ static void hb_cdxTagPoolCheck( LPCDXTAG pTag ) pPage = pTag->pagePool; pPrevPage = NULL; - while ( pPage ) + while( pPage ) { - if ( pPage->pPoolPrev != pPrevPage || pPage->TagParent != pTag ) + if( pPage->pPoolPrev != pPrevPage || pPage->TagParent != pTag ) hb_cdxErrInternal( "hb_cdxTagPoolCheck: data integrity error." ); pPrevPage = pPage; pPage = pPage->pPoolNext; @@ -1038,18 +1109,18 @@ static void hb_cdxTagCheckBuffers( LPCDXTAG pTag ) BOOL fChanged = FALSE; hb_cdxTagPoolCheck( pTag ); - if ( pTag->TagChanged ) + if( pTag->TagChanged ) fChanged = TRUE; else { LPCDXPAGE pPage = pTag->pagePool; - while ( pPage && !fChanged ) + while( pPage && !fChanged ) { fChanged = pPage->fChanged; pPage = pPage->pPoolNext; } } - if ( fChanged ) + if( fChanged ) hb_cdxErrInternal( "hb_cdxTagCheckBuffers: modification without write lock." ); } @@ -1060,13 +1131,13 @@ static void hb_cdxIndexCheckBuffers( LPCDXINDEX pIndex ) { LPCDXTAG pTag; - if ( pIndex->fChanged || ( pIndex->freeLst && pIndex->freeLst->fStat ) ) + if( pIndex->fChanged || ( pIndex->freeLst && pIndex->freeLst->fStat ) ) hb_cdxErrInternal( "hb_cdxIndexCheckBuffers: modification without write lock." ); - if ( pIndex->pCompound ) + if( pIndex->pCompound ) hb_cdxTagCheckBuffers( pIndex->pCompound ); pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { hb_cdxTagCheckBuffers( pTag ); pTag = pTag->pNext; @@ -1083,19 +1154,19 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader ) BYTE byBuf[4]; ULONG ulPos; - if ( pIndex->fReadonly ) + if( pIndex->fReadonly ) { hb_errInternal( 9101, "hb_cdxIndexGetAvailPage on readonly database.", NULL, NULL ); } - if ( pIndex->fShared && !pIndex->lockWrite ) + if( pIndex->fShared && !pIndex->lockWrite ) { hb_errInternal( 9102, "hb_cdxIndexGetAvailPage on not locked index file.", NULL, NULL ); } - if ( pIndex->freePage != 0 && pIndex->freePage != CDX_DUMMYNODE && !bHeader ) + if( pIndex->freePage != 0 && pIndex->freePage != CDX_DUMMYNODE && !bHeader ) { ulPos = pIndex->freePage; - if ( pIndex->freeLst != NULL ) + if( pIndex->freeLst != NULL ) { LPCDXLIST pLst = pIndex->freeLst; pIndex->freePage = pLst->ulAddr; @@ -1104,7 +1175,7 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader ) } else { - if ( hb_fileReadAt( pFile, (BYTE *) byBuf, 4, ulPos ) != 4 ) + if( hb_fileReadAt( pFile, (BYTE *) byBuf, 4, ulPos ) != 4 ) hb_errInternal( EDBF_READ, "hb_cdxIndexGetAvailPage: Read index page failed.", NULL, NULL ); pIndex->freePage = HB_GET_LE_UINT32( byBuf ); #ifdef HB_CDX_DBGUPDT @@ -1116,21 +1187,21 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader ) { int iCnt = ( bHeader ? CDX_HEADERPAGES : 1 ); - if ( pIndex->nextAvail != CDX_DUMMYNODE ) + if( pIndex->nextAvail != CDX_DUMMYNODE ) ulPos = pIndex->nextAvail; else ulPos = ( ULONG ) hb_fileSize( pFile ); pIndex->nextAvail = ulPos + iCnt * CDX_PAGELEN; /* TODO: ### */ - if ( bHeader ) + if( bHeader ) { - BYTE byBuf[CDX_PAGELEN]; + BYTE byPageBuf[CDX_PAGELEN]; HB_FOFFSET fOffset = ulPos; - memset( byBuf, 0, CDX_PAGELEN ); + memset( byPageBuf, 0, CDX_PAGELEN ); do { - if( hb_fileWriteAt( pFile, byBuf, CDX_PAGELEN, fOffset ) != CDX_PAGELEN ) + if( hb_fileWriteAt( pFile, byPageBuf, CDX_PAGELEN, fOffset ) != CDX_PAGELEN ) hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL ); fOffset += CDX_PAGELEN; } @@ -1146,17 +1217,17 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader ) */ static void hb_cdxIndexPutAvailPage( LPCDXINDEX pIndex, ULONG ulPos, BOOL bHeader ) { - if ( ulPos != 0 && ulPos != CDX_DUMMYNODE ) + if( ulPos != 0 && ulPos != CDX_DUMMYNODE ) { int iCnt = ( bHeader ? CDX_HEADERPAGES : 1 ); LPCDXLIST pLst; - if ( pIndex->fReadonly ) + if( pIndex->fReadonly ) hb_errInternal( 9101, "hb_cdxIndexPutAvailPage on readonly database.", NULL, NULL ); - if ( pIndex->fShared && !pIndex->lockWrite ) + if( pIndex->fShared && !pIndex->lockWrite ) hb_errInternal( 9102, "hb_cdxIndexPutAvailPage on not locked index file.", NULL, NULL ); - while ( iCnt-- ) + while( iCnt-- ) { pLst = (LPCDXLIST) hb_xgrab( sizeof( CDXLIST ) ); pLst->ulAddr = pIndex->freePage; @@ -1179,15 +1250,15 @@ static void hb_cdxIndexFlushAvailPage( LPCDXINDEX pIndex ) ULONG ulPos; BOOL fClean = TRUE; - if ( pIndex->fReadonly ) + if( pIndex->fReadonly ) hb_errInternal( 9101, "hb_cdxIndexPutAvailPage on readonly database.", NULL, NULL ); - if ( pIndex->fShared && !pIndex->lockWrite ) + if( pIndex->fShared && !pIndex->lockWrite ) hb_errInternal( 9102, "hb_cdxIndexPutAvailPage on not locked index file.", NULL, NULL ); ulPos = pIndex->freePage; - while ( pLst && pLst->fStat ) + while( pLst && pLst->fStat ) { - if ( fClean ) + if( fClean ) { memset( byPageBuf, 0, CDX_PAGELEN ); fClean = FALSE; @@ -1214,7 +1285,7 @@ static void hb_cdxIndexDropAvailPage( LPCDXINDEX pIndex ) { LPCDXLIST pLst; - while ( pIndex->freeLst ) + while( pIndex->freeLst ) { pLst = pIndex->freeLst->pNext; hb_xfree( pIndex->freeLst ); @@ -1277,9 +1348,9 @@ static void hb_cdxIndexCheckVersion( LPCDXINDEX pIndex ) #endif ulFree = HB_GET_LE_UINT32( &byBuf[0] ); ulVer = HB_GET_BE_UINT32( &byBuf[4] ); - if ( !pIndex->fShared ) + if( !pIndex->fShared ) pIndex->ulVersion = pIndex->freePage; - else if ( ulVer != pIndex->ulVersion || ulFree != pIndex->freePage ) + else if( ulVer != pIndex->ulVersion || ulFree != pIndex->freePage ) { pIndex->nextAvail = CDX_DUMMYNODE; pIndex->ulVersion = ulVer; @@ -1297,7 +1368,7 @@ static BOOL hb_cdxIndexLockRead( LPCDXINDEX pIndex ) { BOOL ret; - if ( pIndex->lockRead > 0 || pIndex->lockWrite > 0 || + if( pIndex->lockRead > 0 || pIndex->lockWrite > 0 || !pIndex->pArea->fShared || !pIndex->fShared || HB_DIRTYREAD( pIndex->pArea ) ) { @@ -1305,15 +1376,15 @@ static BOOL hb_cdxIndexLockRead( LPCDXINDEX pIndex ) return TRUE; } #ifdef HB_CDX_DBGCODE - if ( pIndex->lockRead != 0 ) + if( pIndex->lockRead != 0 ) hb_errInternal( 9105, "hb_cdxIndexLockRead: bad count of locks.", NULL, NULL ); - if ( pIndex->WrLck || pIndex->RdLck ) + if( pIndex->WrLck || pIndex->RdLck ) hb_errInternal( 9107, "hb_cdxIndexLockRead: lock failure (*)", NULL, NULL ); pIndex->RdLck = TRUE; #endif - if ( bTurbo ) + if( bTurbo ) { pIndex->lockRead++; hb_cdxIndexCheckVersion( pIndex ); @@ -1323,10 +1394,10 @@ static BOOL hb_cdxIndexLockRead( LPCDXINDEX pIndex ) { ret = hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_LOCK | FLX_SHARED | FLX_WAIT, &pIndex->ulLockPos ); - if ( !ret ) + if( !ret ) hb_cdxErrorRT( pIndex->pArea, EG_LOCK, EDBF_LOCK, pIndex->szFileName, hb_fsError(), 0, NULL ); - if ( ret ) + if( ret ) { pIndex->lockRead++; hb_cdxIndexCheckVersion( pIndex ); @@ -1343,37 +1414,37 @@ static BOOL hb_cdxIndexLockWrite( LPCDXINDEX pIndex ) { BOOL ret; - if ( pIndex->fReadonly ) + if( pIndex->fReadonly ) hb_errInternal( 9101, "hb_cdxIndexLockWrite: readonly index.", NULL, NULL ); - if ( pIndex->lockRead ) + if( pIndex->lockRead ) hb_errInternal( 9105, "hb_cdxIndexLockWrite: writeLock after readLock.", NULL, NULL ); - if ( pIndex->lockWrite > 0 ) + if( pIndex->lockWrite > 0 ) { pIndex->lockWrite++; return TRUE; } - if ( pIndex->lockWrite != 0 ) + if( pIndex->lockWrite != 0 ) hb_errInternal( 9105, "hb_cdxIndexLockWrite: bad count of locks.", NULL, NULL ); - if ( !pIndex->pArea->fShared || !pIndex->fShared ) + if( !pIndex->pArea->fShared || !pIndex->fShared ) ret = TRUE; else { #ifdef HB_CDX_DBGCODE - if ( pIndex->WrLck || pIndex->RdLck ) + if( pIndex->WrLck || pIndex->RdLck ) hb_errInternal( 9107, "hb_cdxIndexLockWrite: lock failure (*)", NULL, NULL ); pIndex->WrLck = TRUE; #endif ret = hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_LOCK | FLX_EXCLUSIVE | FLX_WAIT, &pIndex->ulLockPos ); } - if ( !ret ) + if( !ret ) hb_cdxErrorRT( pIndex->pArea, EG_LOCK, EDBF_LOCK, pIndex->szFileName, hb_fsError(), 0, NULL ); - if ( ret ) + if( ret ) { pIndex->lockWrite++; - if ( pIndex->fShared || pIndex->nextAvail == CDX_DUMMYNODE ) + if( pIndex->fShared || pIndex->nextAvail == CDX_DUMMYNODE ) hb_cdxIndexCheckVersion( pIndex ); } return ret; @@ -1385,11 +1456,11 @@ static BOOL hb_cdxIndexLockWrite( LPCDXINDEX pIndex ) static BOOL hb_cdxIndexUnLockRead( LPCDXINDEX pIndex ) { pIndex->lockRead--; - if ( pIndex->lockRead < 0 ) + if( pIndex->lockRead < 0 ) { hb_errInternal( 9106, "hb_cdxIndexUnLockRead: bad count of locks.", NULL, NULL ); } - if ( pIndex->lockRead || pIndex->lockWrite ) + if( pIndex->lockRead || pIndex->lockWrite ) { return TRUE; } @@ -1399,7 +1470,7 @@ static BOOL hb_cdxIndexUnLockRead( LPCDXINDEX pIndex ) hb_cdxIndexPoolFree( pIndex, CDX_PAGECACHESIZE ); - if ( bTurbo ) + if( bTurbo ) { #ifdef HB_CDX_DBGCODE if( pIndex->pArea->fShared && pIndex->fShared && @@ -1409,15 +1480,15 @@ static BOOL hb_cdxIndexUnLockRead( LPCDXINDEX pIndex ) } else { - if ( pIndex->pArea->fShared && pIndex->fShared && - !HB_DIRTYREAD( pIndex->pArea ) ) + if( pIndex->pArea->fShared && pIndex->fShared && + !HB_DIRTYREAD( pIndex->pArea ) ) { #ifdef HB_CDX_DBGCODE - if ( pIndex->WrLck || ! pIndex->RdLck ) + if( pIndex->WrLck || ! pIndex->RdLck ) hb_errInternal( 9108, "hb_cdxIndexUnLockRead: unlock error (*)", NULL, NULL ); pIndex->RdLck = FALSE; #endif - if ( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) ) + if( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) ) { hb_errInternal( 9108, "hb_cdxIndexUnLockRead: unlock error.", NULL, NULL ); } @@ -1431,17 +1502,17 @@ static BOOL hb_cdxIndexUnLockRead( LPCDXINDEX pIndex ) */ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex ) { - if ( pIndex->lockWrite > 1 ) + if( pIndex->lockWrite > 1 ) { pIndex->lockWrite--; return TRUE; } - if ( pIndex->lockWrite < 1 ) + if( pIndex->lockWrite < 1 ) { hb_errInternal( 9106, "hb_cdxIndexUnLockWrite: bad count of locks.", NULL, NULL ); } - if ( pIndex->lockRead ) + if( pIndex->lockRead ) { hb_errInternal( 9105, "hb_cdxIndexUnLockWrite: writeUnLock before readUnLock.", NULL, NULL ); } @@ -1450,9 +1521,9 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex ) hb_cdxIndexPoolFree( pIndex, CDX_PAGECACHESIZE ); pIndex->lockWrite--; - if ( pIndex->pArea->fShared && pIndex->fShared ) + if( pIndex->pArea->fShared && pIndex->fShared ) { - if ( pIndex->fChanged ) + if( pIndex->fChanged ) { BYTE byBuf[8]; (pIndex->ulVersion)++; @@ -1466,18 +1537,18 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex ) pIndex->fChanged = FALSE; } #ifdef HB_CDX_DBGCODE - if ( ! pIndex->WrLck || pIndex->RdLck ) + if( ! pIndex->WrLck || pIndex->RdLck ) hb_errInternal( 9108, "hb_cdxIndexUnLockWrite: unlock error (*)", NULL, NULL ); pIndex->WrLck = FALSE; #endif - if ( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) ) + if( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) ) { hb_errInternal( 9108, "hb_cdxIndexUnLockWrite: unlock error.", NULL, NULL ); } } else { - if ( pIndex->ulVersion != pIndex->freePage ) + if( pIndex->ulVersion != pIndex->freePage ) { BYTE byBuf[4]; HB_PUT_LE_UINT32( &byBuf[0], pIndex->freePage ); @@ -1491,7 +1562,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex ) cdxWriteNO++; #endif } - else if ( pIndex->fChanged ) + else if( pIndex->fChanged ) { pIndex->fFlush = TRUE; } @@ -1512,23 +1583,23 @@ static void hb_cdxIndexDiscardBuffers( LPCDXINDEX pIndex ) #endif hb_cdxIndexDropAvailPage( pIndex ); - if ( pIndex->pCompound ) + if( pIndex->pCompound ) { hb_cdxTagClose( pIndex->pCompound ); hb_cdxTagPoolFree( pIndex->pCompound, 0 ); pIndex->pCompound->fRePos = TRUE; pIndex->pCompound->curKeyState = 0; - if ( pIndex->pCompound->CurKey ) + if( pIndex->pCompound->CurKey ) pIndex->pCompound->CurKey->rec = 0; } pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { hb_cdxTagClose( pTag ); hb_cdxTagPoolFree( pTag, 0 ); pTag->fRePos = TRUE; pTag->curKeyState = 0; - if ( pTag->CurKey && !pTag->Custom ) + if( pTag->CurKey && !pTag->Custom ) pTag->CurKey->rec = 0; pTag = pTag->pNext; } @@ -1541,17 +1612,17 @@ static void hb_cdxIndexFlushBuffers( LPCDXINDEX pIndex ) { LPCDXTAG pTag; - if ( pIndex->pCompound ) + if( pIndex->pCompound ) { hb_cdxTagPoolFlush( pIndex->pCompound ); - if ( pIndex->pCompound->TagChanged ) + if( pIndex->pCompound->TagChanged ) hb_cdxTagHeaderStore( pIndex->pCompound ); } pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { hb_cdxTagPoolFlush( pTag ); - if ( pTag->TagChanged ) + if( pTag->TagChanged ) hb_cdxTagHeaderStore( pTag ); pTag = pTag->pNext; } @@ -1565,12 +1636,12 @@ static void hb_cdxIndexPoolFree( LPCDXINDEX pIndex, int nPagesLeft ) { LPCDXTAG pTag; - if ( pIndex->pCompound ) + if( pIndex->pCompound ) { hb_cdxTagPoolFree( pIndex->pCompound, nPagesLeft ); } pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { hb_cdxTagPoolFree( pTag, nPagesLeft ); pTag = pTag->pNext; @@ -1583,46 +1654,46 @@ static void hb_cdxIndexPoolFree( LPCDXINDEX pIndex, int nPagesLeft ) static BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, int iKey ) { #ifdef HB_CDX_DBGCODE - if ( iKey < 0 || iKey >= pPage->iKeys ) + if( iKey < 0 || iKey >= pPage->iKeys ) hb_cdxErrInternal( "hb_cdxPageGetKeyVal: wrong iKey index." ); #endif - if ( pPage->pKeyBuf ) + if( pPage->pKeyBuf ) return &pPage->pKeyBuf[ iKey * ( pPage->TagParent->uiLen + 6 ) ]; - else if ( pPage->PageType & CDX_NODE_LEAF ) + else if( pPage->PageType & CDX_NODE_LEAF ) { int iPos, iLen, iTmp, iTrl, iDup; BYTE bTrail; iLen = pPage->TagParent->uiLen; bTrail = pPage->TagParent->bTrail; - if ( iKey < pPage->bufKeyNum - 1 ) + if( iKey < pPage->bufKeyNum - 1 ) pPage->bufKeyNum = 0; - if ( pPage->bufKeyNum == 0 ) + if( pPage->bufKeyNum == 0 ) { pPage->bufKeyPos = CDX_EXT_FREESPACE; pPage->bufKeyLen = iLen; } - while ( pPage->bufKeyNum <= iKey ) + while( pPage->bufKeyNum <= iKey ) { iPos = pPage->bufKeyNum * pPage->ReqByte; iTmp = HB_GET_LE_UINT16( &pPage->node.extNode.keyPool[ iPos + pPage->ReqByte - 2 ] ) >> ( 16 - pPage->TCBits - pPage->DCBits ); iDup = ( pPage->bufKeyNum == 0 ) ? 0 : ( iTmp & pPage->DCMask ); iTrl = ( iTmp >> pPage->DCBits ) & pPage->TCMask; - if ( ( iTmp = iLen - iDup - iTrl ) > 0 ) + if( ( iTmp = iLen - iDup - iTrl ) > 0 ) { pPage->bufKeyPos -= iTmp; memcpy( &pPage->bufKeyVal[ iDup ], &pPage->node.extNode.keyPool[ pPage->bufKeyPos ], iTmp ); } #ifdef HB_CDX_DBGCODE - else if ( iTmp < 0 ) + else if( iTmp < 0 ) { printf("\r\npPage->Page=%lx, iLen=%d, iDup=%d, iTrl=%d", pPage->Page, iLen, iDup, iTrl); fflush(stdout); hb_cdxErrInternal( "hb_cdxPageGetKeyVal: index corrupted." ); } #endif - if ( iTrl > 0 && ( iTmp = pPage->bufKeyLen - iLen + iTrl ) > 0 ) + if( iTrl > 0 && ( iTmp = pPage->bufKeyLen - iLen + iTrl ) > 0 ) memset( &pPage->bufKeyVal[ iLen - iTrl ], bTrail, iTmp ); pPage->bufKeyLen = iLen - iTrl; pPage->bufKeyNum++; @@ -1639,12 +1710,12 @@ static BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, int iKey ) static ULONG hb_cdxPageGetKeyRec( LPCDXPAGE pPage, int iKey ) { #ifdef HB_CDX_DBGCODE - if ( iKey < 0 || iKey >= pPage->iKeys ) + if( iKey < 0 || iKey >= pPage->iKeys ) hb_cdxErrInternal( "hb_cdxPageGetKeyRec: wrong iKey index." ); #endif - if ( pPage->pKeyBuf ) + if( pPage->pKeyBuf ) return HB_GET_LE_UINT32( &pPage->pKeyBuf[ ( iKey + 1 ) * ( pPage->TagParent->uiLen + 6 ) - 6 ] ); - else if ( pPage->PageType & CDX_NODE_LEAF ) + else if( pPage->PageType & CDX_NODE_LEAF ) return HB_GET_LE_UINT32( &pPage->node.extNode.keyPool[ iKey * pPage->ReqByte ] ) & pPage->RNMask; else return HB_GET_BE_UINT32( &pPage->node.intNode.keyPool[ @@ -1657,9 +1728,9 @@ static ULONG hb_cdxPageGetKeyRec( LPCDXPAGE pPage, int iKey ) static ULONG hb_cdxPageGetKeyPage( LPCDXPAGE pPage, int iKey ) { #ifdef HB_CDX_DBGCODE - if ( iKey < 0 || iKey >= pPage->iKeys ) + if( iKey < 0 || iKey >= pPage->iKeys ) hb_cdxErrInternal( "hb_cdxPageGetKeyPage: wrong iKey index." ); - if ( pPage->PageType & CDX_NODE_LEAF ) + if( pPage->PageType & CDX_NODE_LEAF ) hb_cdxErrInternal( "hb_cdxPageGetKeyPage: page is a leaf." ); #endif return HB_GET_BE_UINT32( &pPage->node.intNode.keyPool[ @@ -1672,9 +1743,9 @@ static ULONG hb_cdxPageGetKeyPage( LPCDXPAGE pPage, int iKey ) static SHORT hb_cdxPageGetKeyTrl( LPCDXPAGE pPage, SHORT iKey ) { #ifdef HB_CDX_DBGCODE_EXT - if ( iKey < 0 || iKey >= pPage->iKeys ) + if( iKey < 0 || iKey >= pPage->iKeys ) hb_cdxErrInternal( "hb_cdxPageGetKeyTrl: wrong iKey index." ); - if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) hb_cdxErrInternal( "hb_cdxPageGetKeyTrl: page is not a leaf." ); #endif if( pPage->pKeyBuf ) @@ -1709,12 +1780,12 @@ static void hb_cdxPageCheckKeys( LPCDXPAGE pPage ) ULONG ulRec, ulRecPrev; BYTE * pbVal, pbValPrev[CDX_MAXKEY]; - if ( pPage->iKeys > 1 ) + if( pPage->iKeys > 1 ) { pPage->bufKeyNum = 0; pbVal = hb_cdxPageGetKeyVal( pPage, 0 ); ulRec = hb_cdxPageGetKeyRec( pPage, 0 ); - for ( i = 1; i < pPage->iKeys; i++ ) + for( i = 1; i < pPage->iKeys; i++ ) { memcpy( pbValPrev, pbVal, iLen ); ulRecPrev = ulRec; @@ -1722,8 +1793,8 @@ static void hb_cdxPageCheckKeys( LPCDXPAGE pPage ) ulRec = hb_cdxPageGetKeyRec( pPage, i ); K = hb_cdxValCompare( pPage->TagParent, pbValPrev, iLen, - pbVal, iLen, TRUE ); - if ( K > 0 || ( K == 0 && ulRecPrev >= ulRec ) ) + pbVal, iLen, CDX_CMP_EXACT ); + if( K > 0 || ( K == 0 && ulRecPrev >= ulRec ) ) { printf( "\r\nikey=%d, pPage->iKeys=%d, K=%d, ulRecPrev=%ld, ulRec=%ld", i, pPage->iKeys, K, ulRecPrev, ulRec );fflush(stdout); @@ -1747,42 +1818,42 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys, B BYTE bTrail = pPage->TagParent->bTrail; BOOL bErr = FALSE; - for ( iKey = 0; iKey < iKeys; iKey++ ) + for( iKey = 0; iKey < iKeys; iKey++ ) { iPos = iKey * iLen; bTrl = bDup = 0; - while ( bTrl < iNum && pKeyBuf[ iPos + iNum - bTrl - 1 ] == bTrail ) + while( bTrl < iNum && pKeyBuf[ iPos + iNum - bTrl - 1 ] == bTrail ) ++bTrl; - if ( iKey > 0 ) + if( iKey > 0 ) { #ifdef HB_CDX_PACKTRAIL int iMax = iNum - bTrl; #else int iMax = iNum - HB_MAX( pKeyBuf[ iPos - 1 ], bTrl ); #endif - while ( bDup < iMax && pKeyBuf[ iPos + bDup ] == - pKeyBuf[ iPos - iLen + bDup ] ) + while( bDup < iMax && pKeyBuf[ iPos + bDup ] == + pKeyBuf[ iPos - iLen + bDup ] ) ++bDup; } - if ( bTrl != pKeyBuf[ iPos + iNum + 5 ] ) + if( bTrl != pKeyBuf[ iPos + iNum + 5 ] ) { printf("\r\nbTrl=%d, keybuf->bTrl=%d, iKey=%d/%d\r\n", bTrl, pKeyBuf[ iPos + iNum + 5 ], iKey, iKeys ); fflush(stdout); bErr = TRUE; } - if ( bDup != ( iKey == 0 ? 0 : pKeyBuf[ iPos + iNum + 4 ] ) ) + if( bDup != ( iKey == 0 ? 0 : pKeyBuf[ iPos + iNum + 4 ] ) ) { printf("\r\nbDup=%d, keybuf->bDup=%d (bTrl=%d), iKey=%d/%d\r\n", bDup, pKeyBuf[ iPos + iNum + 4 ], bTrl, iKey, iKeys ); fflush(stdout); bErr = TRUE; } - if ( iKey > 0 ) + if( iKey > 0 ) { int K; K = hb_cdxValCompare( pPage->TagParent, &pKeyBuf[ iPos - iLen ], iNum, - &pKeyBuf[ iPos ], iNum, TRUE ); - if ( K > 0 || ( K == 0 && + &pKeyBuf[ iPos ], iNum, CDX_CMP_EXACT ); + if( K > 0 || ( K == 0 && HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum - iLen ] ) >= HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum ] ) ) ) { @@ -1800,14 +1871,14 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys, B } iFree -= iNum + pPage->ReqByte - bDup - bTrl; } - if ( fSpc && ( iFree != pPage->iFree /* || iFree < 0 */ ) ) + if( fSpc && ( iFree != pPage->iFree /* || iFree < 0 */ ) ) { printf( "\r\nFreeSpace calculated wrong! iFree=%d, pPage->iFree=%d", iFree, pPage->iFree ); fflush(stdout); bErr = TRUE; } - if ( bErr ) + if( bErr ) { printf("\r\nPage=%lx, Page->iFree=%d, iLen=%d\r\n", pPage->Page, pPage->iFree, iNum ); fflush(stdout); @@ -1836,11 +1907,11 @@ static void hb_cdxSetLeafRecord( BYTE *pDst, ULONG ulRec, int iDup, int iTrl, USHORT usBit; usBit = ( ( iTrl << iDCbits ) | iDup ) << ( 16 - iTCbits - iDCbits ); - for ( i = 0; i < iReq; i++, ulRec >>= 8 ) + for( i = 0; i < iReq; i++, ulRec >>= 8 ) { - if ( i < iReq - 2 ) + if( i < iReq - 2 ) pDst[ i ] = ( BYTE ) ( ulRec & 0xff ); - else if ( i == iReq - 2 ) + else if( i == iReq - 2 ) pDst[ i ] = ( BYTE ) ( ulRec & 0xff ) | ( usBit & 0xff ); else pDst[ i ] = ( BYTE ) ( ulRec & 0xff ) | ( ( usBit >> 8 ) & 0xff ); @@ -1856,7 +1927,7 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys ) BYTE *pKeyPos, *pRecPos, *pSrc; #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) { printf("\r\npPage->Page=%lx. left=%lx, right=%lx", pPage->Page, pPage->Left, pPage->Right); fflush(stdout); @@ -1864,7 +1935,7 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys ) } #endif #ifdef HB_CDX_DBGCODE_EXT - if ( ! pKeyBuf ) + if( ! pKeyBuf ) hb_cdxErrInternal( "hb_cdxPageLeafEncode: page has no buffer." ); hb_cdxPageCheckDupTrl( pPage, pKeyBuf, iKeys, TRUE ); #endif @@ -1874,20 +1945,20 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys ) pKeyPos = &pPage->node.extNode.keyPool[ CDX_EXT_FREESPACE ]; pRecPos = &pPage->node.extNode.keyPool[ 0 ]; pSrc = &pKeyBuf[ 0 ]; - for ( iKey = 0; iKey < iKeys; iKey++, pSrc += iLen, pRecPos += iReq ) + for( iKey = 0; iKey < iKeys; iKey++, pSrc += iLen, pRecPos += iReq ) { iDup = pSrc[ iNum + 4 ]; iTrl = pSrc[ iNum + 5 ]; iTmp = iNum - iTrl - iDup; hb_cdxSetLeafRecord( pRecPos, HB_GET_LE_UINT32( &pSrc[ iNum ] ), iDup, iTrl, iReq, pPage->DCBits, pPage->TCBits ); - if ( iTmp > 0 ) + if( iTmp > 0 ) { pKeyPos -= iTmp; memcpy( pKeyPos, &pSrc[ iDup ], iTmp ); } #ifdef HB_CDX_DBGCODE - else if ( iTmp < 0 ) + else if( iTmp < 0 ) { printf("\r\n[%s][%s]", pSrc - iLen, pSrc); printf("\r\npPage->Page=0x%lx, iKey=%d, iNum=%d, iDup=%d, iTrl=%d", pPage->Page, iKey, iNum, iDup, iTrl); fflush(stdout); @@ -1895,17 +1966,17 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys ) } #endif } - if ( pRecPos < pKeyPos ) + if( pRecPos < pKeyPos ) memset( pRecPos, 0, pKeyPos - pRecPos ); #ifdef HB_CDX_DBGCODE - if ( pKeyPos - pRecPos != pPage->iFree ) + if( pKeyPos - pRecPos != pPage->iFree ) { printf("\r\nPage=0x%lx, calc=%d, iFree=%d, req=%d, keys=%d, keyLen=%d\r\n", pPage->Page, (int) (pKeyPos - pRecPos), pPage->iFree, pPage->ReqByte, iKeys, iNum ); fflush(stdout); hb_cdxErrInternal( "hb_cdxPageLeafEncode: FreeSpace calculated wrong!." ); } - if ( pPage->iFree < 0 ) + if( pPage->iFree < 0 ) hb_cdxErrInternal( "hb_cdxPageLeafEncode: FreeSpace calculated wrong!!." ); #endif pPage->iKeys = iKeys; @@ -1933,7 +2004,7 @@ static void hb_cdxPageLeafDecode( LPCDXPAGE pPage, BYTE * pKeyBuf ) ULONG ulRec; #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) { printf("\r\npPage->Page=%lx", pPage->Page); fflush(stdout); hb_cdxErrInternal( "hb_cdxPageLeafDecode: page is not a leaf." ); @@ -1944,32 +2015,32 @@ static void hb_cdxPageLeafDecode( LPCDXPAGE pPage, BYTE * pKeyBuf ) pSrc = &pPage->node.extNode.keyPool[ CDX_EXT_FREESPACE ]; pRec = pPage->node.extNode.keyPool; iReq = pPage->ReqByte; - for ( iKey = 0; iKey < pPage->iKeys; iKey++, pRec += iReq ) + for( iKey = 0; iKey < pPage->iKeys; iKey++, pRec += iReq ) { pTmp = &pRec[ iReq - 2 ]; iTmp = HB_GET_LE_UINT16( pTmp ) >> iBits; iDup = ( iKey == 0 ) ? 0 : ( iTmp & pPage->DCMask ); iTrl = ( iTmp >> pPage->DCBits ) & pPage->TCMask; iNew = iLen - iDup - iTrl; - if ( iDup > 0 ) + if( iDup > 0 ) { memcpy( pDst, pDst - iLen - 6, iDup ); pDst += iDup; } - if ( iNew > 0 ) + if( iNew > 0 ) { pSrc -= iNew; memcpy( pDst, pSrc, iNew ); pDst += iNew; } #ifdef HB_CDX_DBGCODE - else if ( iNew < 0 ) + else if( iNew < 0 ) { printf("\r\npPage->Page=%lx, iLen=%d, iDup=%d, iTrl=%d", pPage->Page, iLen, iDup, iTrl); fflush(stdout); hb_cdxErrInternal( "hb_cdxPageLeafDecode: index corrupted." ); } #endif - if ( iTrl > 0 ) + if( iTrl > 0 ) { memset( pDst, bTrail, iTrl ); pDst += iTrl; @@ -1997,7 +2068,7 @@ static void hb_cdxPageLeafInitSpace( LPCDXPAGE pPage ) int iLen = pPage->TagParent->uiLen; BYTE bBits; - for ( bBits = 0; iLen; bBits++, iLen >>= 1 ) {} + for( bBits = 0; iLen; bBits++, iLen >>= 1 ) {} pPage->ReqByte = 3; pPage->RNBits = 24 - ( bBits << 1 ); pPage->DCBits = pPage->TCBits = bBits; @@ -2024,27 +2095,27 @@ static void hb_cdxPageCalcLeafSpace( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckDupTrl( pPage, pKeyBuf, iKeys, FALSE ); #endif - for ( iKey = 0; iKey < iKeys; iKey++ ) + for( iKey = 0; iKey < iKeys; iKey++ ) { bPtr = &pKeyBuf[ iKey * iLen + iNum ]; bTrl = bPtr[ 5 ]; - if ( iKey == 0 ) + if( iKey == 0 ) bDup = bPtr[ 4 ] = 0; else bDup = bPtr[ 4 ]; ulRec = HB_GET_LE_UINT32( bPtr ); iSize = ReqByte + iNum - bTrl - bDup; - if ( ulRec > RNMask ) + if( ulRec > RNMask ) { BYTE RNBits = pPage->RNBits; - while ( ulRec > RNMask ) + while( ulRec > RNMask ) { ReqByte++; RNBits += 8; RNMask = ( RNMask << 8 ) | 0xFF; iSize += ( iKey + 1 ); } - if ( iSize > pPage->iFree ) + if( iSize > pPage->iFree ) break; #ifdef HB_CDX_DSPDBG_INFO_X printf("\r\npPage->Page=%lx, ulRec=%lx, RNMask=%lx/%lx, RNBits=%d/%d, DCB=%d, TCB=%d (%lx), iKey=%d/%d", @@ -2056,7 +2127,7 @@ static void hb_cdxPageCalcLeafSpace( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys pPage->RNBits = RNBits; pPage->ReqByte = ReqByte; } - else if ( iSize > pPage->iFree ) + else if( iSize > pPage->iFree ) break; pPage->iFree -= iSize; pPage->iKeys++; @@ -2072,12 +2143,12 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) int iRet = 0; #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) hb_cdxErrInternal( "hb_cdxPageLeafDelKey: page is not a leaf." ); - if ( iKey < 0 || iKey >= pPage->iKeys ) + if( iKey < 0 || iKey >= pPage->iKeys ) hb_cdxErrInternal( "hb_cdxPageLeafDelKey: wrong iKey index." ); #endif - if ( !pPage->pKeyBuf ) + if( !pPage->pKeyBuf ) { BYTE *pKeyBuf = (BYTE *) hb_xgrab( ( pPage->iKeys ) * iLen ); hb_cdxPageLeafDecode( pPage, pKeyBuf ); @@ -2093,11 +2164,11 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) iSpc = pPage->ReqByte + pPage->TagParent->uiLen - pPage->pKeyBuf[ ( iKey + 1 ) * iLen - 2 ] - pPage->pKeyBuf[ ( iKey + 1 ) * iLen - 1 ]; - if ( iKey < pPage->iKeys - 1 ) + if( iKey < pPage->iKeys - 1 ) { int iPos = ( iKey + 2 ) * iLen - 2, iDup = 0; iSpc -= pPage->pKeyBuf[ iPos ]; - if ( iKey > 0 ) + if( iKey > 0 ) { int iPrev = ( iKey - 1 ) * iLen, iNext = ( iKey + 1 ) * iLen, iNum = pPage->TagParent->uiLen; @@ -2109,19 +2180,19 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) #endif iDup = HB_MIN( pPage->pKeyBuf[ iPos ], pPage->pKeyBuf[ iNext - 2] ); - if ( iDup > iNum ) + if( iDup > iNum ) { iDup = iNum; } else { - while ( iDup < iNum && pPage->pKeyBuf[ iPrev + iDup ] == - pPage->pKeyBuf[ iNext + iDup ] ) + while( iDup < iNum && pPage->pKeyBuf[ iPrev + iDup ] == + pPage->pKeyBuf[ iNext + iDup ] ) ++iDup; } #ifdef HB_CDX_DSPDBG_INFO printf("+%d=%d", iSpc+iDup, pPage->iFree+iSpc+iDup ); - if ( iSpc+iDup < 0 ) + if( iSpc+iDup < 0 ) printf( " iLen=%d, iDup=%d, iNum=%d pd=%d pt=%d cd=%d ct=%d nd=%d nt=%d", iLen-6, iDup, iNum, pPage->pKeyBuf[ iPrev + iLen - 2 ], @@ -2136,7 +2207,7 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) iSpc += ( pPage->pKeyBuf[ iPos ] = ( BYTE ) iDup ); } pPage->iFree += iSpc; - if ( --pPage->iKeys > iKey ) + if( --pPage->iKeys > iKey ) { memmove( &pPage->pKeyBuf[ iKey * iLen ], &pPage->pKeyBuf[ ( iKey + 1 ) * iLen ], @@ -2147,14 +2218,14 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) hb_cdxPageCheckKeys( pPage ); hb_cdxPageCheckDupTrl( pPage, pPage->pKeyBuf, pPage->iKeys, TRUE ); #endif - if ( iKey >= pPage->iKeys ) + if( iKey >= pPage->iKeys ) iRet |= NODE_NEWLASTKEY; - if ( pPage->iKeys == 0 ) + if( pPage->iKeys == 0 ) iRet |= NODE_JOIN; - else if ( pPage->iFree < 0 ) + else if( pPage->iFree < 0 ) iRet |= NODE_SPLIT; - /* if ( pPage->iFree >= CDX_EXT_FREESPACE / 2 ) */ - if ( pPage->iFree >= pPage->ReqByte ) + /* if( pPage->iFree >= CDX_EXT_FREESPACE / 2 ) */ + if( pPage->iFree >= pPage->ReqByte ) iRet |= NODE_BALANCE; return iRet; } @@ -2175,12 +2246,12 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) fflush(stdout); #endif #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) hb_cdxErrInternal( "hb_cdxPageLeafAddKey: page is not a leaf." ); - if ( pPage->iCurKey < 0 || pPage->iCurKey > pPage->iKeys ) + if( pPage->iCurKey < 0 || pPage->iCurKey > pPage->iKeys ) hb_cdxErrInternal( "hb_cdxPageLeafAddKey: wrong iKey index." ); #endif - if ( !pPage->pKeyBuf ) + if( !pPage->pKeyBuf ) { BYTE *pKeyBuf = (BYTE *) hb_xgrab( ( pPage->iKeys + 1 ) * iLen ); hb_cdxPageLeafDecode( pPage, pKeyBuf ); @@ -2199,13 +2270,13 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) iTrl = iDup = 0; iKey = pPage->iCurKey; iPos = iKey * iLen; - if ( iKey < pPage->iKeys ) + if( iKey < pPage->iKeys ) { iDup = pPage->pKeyBuf[ iPos + iNum + 4 ]; memmove( &pPage->pKeyBuf[ iPos + iLen ], &pPage->pKeyBuf[ iPos ], iLen * ( pPage->iKeys - iKey ) ); } - if ( pKey->len >= iNum ) + if( pKey->len >= iNum ) memcpy( &pPage->pKeyBuf[ iPos ], pKey->val, iNum ); else { @@ -2213,30 +2284,30 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) memset( &pPage->pKeyBuf[ iPos + pKey->len ], bTrail, iNum - pKey->len ); } HB_PUT_LE_UINT32( &pPage->pKeyBuf[ iPos + iNum ], pKey->rec ); - while ( iTrl < iNum && pPage->pKeyBuf[ iPos + iNum - iTrl - 1 ] == bTrail ) + while( iTrl < iNum && pPage->pKeyBuf[ iPos + iNum - iTrl - 1 ] == bTrail ) ++iTrl; - if ( iKey > 0 ) + if( iKey > 0 ) { #ifdef HB_CDX_PACKTRAIL iMax = iNum - iTrl; #else iMax = iNum - HB_MAX( iTrl, pPage->pKeyBuf[ iPos - 1 ] ); #endif - if ( iDup > iMax ) + if( iDup > iMax ) { iDup = iMax; } else { - while ( iDup < iMax && pPage->pKeyBuf[ iPos + iDup ] == - pPage->pKeyBuf[ iPos + iDup - iLen ] ) + while( iDup < iMax && pPage->pKeyBuf[ iPos + iDup ] == + pPage->pKeyBuf[ iPos + iDup - iLen ] ) ++iDup; } } pPage->pKeyBuf[ iPos + iNum + 4 ] = (BYTE) iDup; pPage->pKeyBuf[ iPos + iNum + 5 ] = (BYTE) iTrl; iSpc = pPage->ReqByte + iNum - iTrl - iDup; - if ( iKey < pPage->iKeys ) + if( iKey < pPage->iKeys ) { #ifdef HB_CDX_PACKTRAIL iMax = iNum - pPage->pKeyBuf[ iPos + iLen + iLen - 1 ]; @@ -2245,13 +2316,13 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) #endif iSpc += pPage->pKeyBuf[ iPos + iLen + iLen - 2 ]; iDup = 0; - while ( iDup < iMax && pPage->pKeyBuf[ iPos + iDup ] == - pPage->pKeyBuf[ iPos + iDup + iLen ] ) + while( iDup < iMax && pPage->pKeyBuf[ iPos + iDup ] == + pPage->pKeyBuf[ iPos + iDup + iLen ] ) ++iDup; iSpc -= ( pPage->pKeyBuf[ iPos + iLen + iLen - 2 ] = ( BYTE ) iDup ); } pPage->iKeys++; - while ( pKey->rec > pPage->RNMask ) + while( pKey->rec > pPage->RNMask ) { pPage->RNMask = ( pPage->RNMask << 8 ) | 0xFF; pPage->ReqByte++; @@ -2264,11 +2335,11 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) hb_cdxPageCheckKeys( pPage ); hb_cdxPageCheckDupTrl( pPage, pPage->pKeyBuf, pPage->iKeys, TRUE ); #endif - if ( iKey >= pPage->iKeys - 1 ) + if( iKey >= pPage->iKeys - 1 ) iRet |= NODE_NEWLASTKEY; - if ( pPage->iFree < 0 ) + if( pPage->iFree < 0 ) iRet |= NODE_SPLIT; - if ( pPage->iFree >= pPage->ReqByte && + if( pPage->iFree >= pPage->ReqByte && pPage->Left != CDX_DUMMYNODE && pPage->Right != CDX_DUMMYNODE ) iRet |= NODE_BALANCE; return iRet; @@ -2288,16 +2359,16 @@ static void hb_cdxPageIntSetKey( LPCDXPAGE pPage, int iKey, BOOL fIns, BYTE * pb fflush(stdout); #endif #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) hb_cdxErrInternal( "hb_cdxPageIntSetKey: page is a leaf!" ); - if ( iKey < 0 || iKey >= pPage->iKeys + ( fIns ? 1 : 0 ) ) + if( iKey < 0 || iKey >= pPage->iKeys + ( fIns ? 1 : 0 ) ) { hb_cdxErrInternal( "hb_cdxPageIntSetKey: wrong iKey index." ); } #endif - if ( fIns ) + if( fIns ) { - if ( iKey < pPage->iKeys ) + if( iKey < pPage->iKeys ) { memmove( &pPage->node.intNode.keyPool[ iPos + iLen + 8 ], &pPage->node.intNode.keyPool[ iPos ], @@ -2305,12 +2376,12 @@ static void hb_cdxPageIntSetKey( LPCDXPAGE pPage, int iKey, BOOL fIns, BYTE * pb } pPage->iKeys++; } - if ( pbVal ) + if( pbVal ) memcpy( &pPage->node.intNode.keyPool[ iPos ], pbVal, iLen ); - else if ( fIns ) + else if( fIns ) memset( &pPage->node.intNode.keyPool[ iPos ], pPage->TagParent->bTrail, iLen ); - if ( ulRec ) + if( ulRec ) HB_PUT_BE_UINT32( &pPage->node.intNode.keyPool[ iPos + iLen ], ulRec ); HB_PUT_BE_UINT32( &pPage->node.intNode.keyPool[ iPos + iLen + 4 ], ulPag ); pPage->fChanged = TRUE; @@ -2330,15 +2401,15 @@ static void hb_cdxPageIntDelKey( LPCDXPAGE pPage, int iKey ) fflush(stdout); #endif #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) hb_cdxErrInternal( "hb_cdxPageIntDelKey: page is a leaf!" ); - if ( iKey < 0 || iKey >= pPage->iKeys ) + if( iKey < 0 || iKey >= pPage->iKeys ) { hb_cdxErrInternal( "hb_cdxPageIntDelKey: wrong iKey index." ); } #endif pPage->iKeys--; - if ( pPage->iKeys > iKey ) + if( pPage->iKeys > iKey ) { memmove( &pPage->node.intNode.keyPool[ iKey * iLen ], &pPage->node.intNode.keyPool[ ( iKey + 1 ) * iLen ], ( pPage->iKeys - iKey ) * iLen ); @@ -2352,7 +2423,7 @@ static void hb_cdxPageIntDelKey( LPCDXPAGE pPage, int iKey ) */ static void hb_cdxPageLoad( LPCDXPAGE pPage ) { - if ( pPage->pKeyBuf ) + if( pPage->pKeyBuf ) { hb_xfree( pPage->pKeyBuf ); pPage->pKeyBuf = NULL; @@ -2365,7 +2436,7 @@ static void hb_cdxPageLoad( LPCDXPAGE pPage ) pPage->iKeys = HB_GET_LE_UINT16( pPage->node.intNode.nKeys ); pPage->fChanged = FALSE; - if ( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) { pPage->iFree = HB_GET_LE_UINT16( pPage->node.extNode.freeSpc ); pPage->RNMask = HB_GET_LE_UINT32( pPage->node.extNode.recMask ); @@ -2378,7 +2449,7 @@ static void hb_cdxPageLoad( LPCDXPAGE pPage ) pPage->ReqByte = pPage->node.extNode.keyBytes; pPage->bufKeyNum = 0; #if 0 - if ( !pPage->pKeyBuf ) + if( !pPage->pKeyBuf ) { BYTE *pKeyBuf = (BYTE *) hb_xgrab( ( pPage->iKeys + 1 ) * ( pPage->TagParent->uiLen + 6 ) ); hb_cdxPageLeafDecode( pPage, pKeyBuf ); @@ -2397,14 +2468,14 @@ static void hb_cdxPageLoad( LPCDXPAGE pPage ) static void hb_cdxPageStore( LPCDXPAGE pPage ) { #ifdef HB_CDX_DBGCODE - if ( pPage->Page == 0 || pPage->Page == CDX_DUMMYNODE ) + if( pPage->Page == 0 || pPage->Page == CDX_DUMMYNODE ) hb_cdxErrInternal( "hb_cdxPageStore: Page number wrong!." ); - if ( pPage->PageType & CDX_NODE_LEAF ) + if( pPage->PageType & CDX_NODE_LEAF ) { - if ( pPage->iFree < 0 ) + if( pPage->iFree < 0 ) hb_cdxErrInternal( "hb_cdxPageStore: FreeSpace calculated wrong!." ); } - else if ( pPage->iKeys > pPage->TagParent->MaxKeys ) + else if( pPage->iKeys > pPage->TagParent->MaxKeys ) hb_cdxErrInternal( "hb_cdxPageStore: number of keys exceed!." ); #endif HB_PUT_LE_UINT16( pPage->node.intNode.attr, ( UINT16 ) pPage->PageType ); @@ -2412,7 +2483,7 @@ static void hb_cdxPageStore( LPCDXPAGE pPage ) HB_PUT_LE_UINT32( pPage->node.intNode.leftPtr, pPage->Left ); HB_PUT_LE_UINT32( pPage->node.intNode.rightPtr, pPage->Right ); - if ( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) { HB_PUT_LE_UINT16( pPage->node.extNode.freeSpc, pPage->iFree ); HB_PUT_LE_UINT32( pPage->node.extNode.recMask, pPage->RNMask ); @@ -2424,13 +2495,13 @@ static void hb_cdxPageStore( LPCDXPAGE pPage ) pPage->node.extNode.trlBits = pPage->TCBits; pPage->node.extNode.keyBytes = pPage->ReqByte; - if ( pPage->pKeyBuf && pPage->fBufChanged ) + if( pPage->pKeyBuf && pPage->fBufChanged ) { hb_cdxPageLeafEncode( pPage, pPage->pKeyBuf, pPage->iKeys ); pPage->fBufChanged = FALSE; } #ifdef HB_CDX_DBGCODE_EXT - if ( pPage->pKeyBuf ) + if( pPage->pKeyBuf ) { hb_xfree( pPage->pKeyBuf ); pPage->pKeyBuf = NULL; @@ -2455,20 +2526,20 @@ static LPCDXPAGE hb_cdxPageNew( LPCDXTAG pTag, LPCDXPAGE pOwnerPage, ULONG ulPag #ifdef HB_CDX_DBGCODE_EXT hb_cdxTagPoolCheck( pTag ); #endif - if ( ulPage && ulPage != CDX_DUMMYNODE && pTag->pagePool ) + if( ulPage && ulPage != CDX_DUMMYNODE && pTag->pagePool ) { pPage = pTag->pagePool; - while ( pPage && pPage->Page != ulPage ) + while( pPage && pPage->Page != ulPage ) { pPage = pPage->pPoolNext; } } - if ( pPage ) + if( pPage ) { - if ( pPage->pPoolPrev ) + if( pPage->pPoolPrev ) { pPage->pPoolPrev->pPoolNext = pPage->pPoolNext; - if ( pPage->pPoolNext ) + if( pPage->pPoolNext ) { pPage->pPoolNext->pPoolPrev = pPage->pPoolPrev; } @@ -2486,12 +2557,12 @@ static LPCDXPAGE hb_cdxPageNew( LPCDXTAG pTag, LPCDXPAGE pOwnerPage, ULONG ulPag pPage->Left = pPage->Right = CDX_DUMMYNODE; pPage->TagParent = pTag; - if ( ulPage && ulPage != CDX_DUMMYNODE ) + if( ulPage && ulPage != CDX_DUMMYNODE ) { pPage->Page = ulPage; hb_cdxPageLoad( pPage ); } - else if ( ! ulPage ) + else if( ! ulPage ) { pPage->Page = hb_cdxIndexGetAvailPage( pTag->pIndex, FALSE ); pPage->fChanged = TRUE; @@ -2499,7 +2570,7 @@ static LPCDXPAGE hb_cdxPageNew( LPCDXTAG pTag, LPCDXPAGE pOwnerPage, ULONG ulPag pPage->pPoolPrev = NULL; pPage->pPoolNext = pTag->pagePool; pTag->pagePool = pPage; - if ( pPage->pPoolNext ) + if( pPage->pPoolNext ) pPage->pPoolNext->pPoolPrev = pPage; } pPage->Owner = pOwnerPage; @@ -2520,30 +2591,30 @@ static void hb_cdxPageFree( LPCDXPAGE pPage, BOOL fReal ) LPCDXTAG pTag = pPage->TagParent; hb_cdxTagPoolCheck( pTag ); #endif - if ( pPage->Child != NULL ) + if( pPage->Child != NULL ) { hb_cdxPageFree( pPage->Child, fReal ); pPage->Child = NULL; } - if ( pPage->PageType == CDX_NODE_UNUSED ) + if( pPage->PageType == CDX_NODE_UNUSED ) { fReal = TRUE; pPage->fChanged = FALSE; } - if ( fReal ) + if( fReal ) { - if ( pPage->fChanged ) + if( pPage->fChanged ) hb_cdxPageStore( pPage ); #ifdef HB_CDX_DBGCODE_EXT hb_cdxTagPoolCheck( pTag ); #endif - if ( pPage->pPoolPrev ) + if( pPage->pPoolPrev ) { pPage->pPoolPrev->pPoolNext = pPage->pPoolNext; - if ( pPage->pPoolNext ) + if( pPage->pPoolNext ) { pPage->pPoolNext->pPoolPrev = pPage->pPoolPrev; } @@ -2551,7 +2622,7 @@ static void hb_cdxPageFree( LPCDXPAGE pPage, BOOL fReal ) else { pPage->TagParent->pagePool = pPage->pPoolNext; - if ( pPage->pPoolNext ) + if( pPage->pPoolNext ) { pPage->pPoolNext->pPoolPrev = NULL; } @@ -2561,16 +2632,16 @@ static void hb_cdxPageFree( LPCDXPAGE pPage, BOOL fReal ) #endif } - if ( pPage->Owner != NULL && pPage->Owner->Child == pPage ) + if( pPage->Owner != NULL && pPage->Owner->Child == pPage ) pPage->Owner->Child = NULL; pPage->Owner = NULL; pPage->bUsed = 0; - if ( fReal ) + if( fReal ) { - if ( pPage->PageType == CDX_NODE_UNUSED ) + if( pPage->PageType == CDX_NODE_UNUSED ) hb_cdxIndexPutAvailPage( pPage->TagParent->pIndex, pPage->Page, FALSE ); - if ( pPage->pKeyBuf ) + if( pPage->pKeyBuf ) hb_xfree( pPage->pKeyBuf ); hb_xfree( pPage ); } @@ -2587,14 +2658,14 @@ static void hb_cdxPageGetChild( LPCDXPAGE pPage ) ULONG ulPage; #ifdef HB_CDX_DBGCODE - if ( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) hb_cdxErrInternal( "hb_cdxPageGetChild: index corrupted." ); #endif ulPage = hb_cdxPageGetKeyPage( pPage, pPage->iCurKey ); - if ( pPage->Child != NULL ) + if( pPage->Child != NULL ) { - if ( pPage->Child->Page != ulPage ) + if( pPage->Child->Page != ulPage ) { hb_cdxPageFree( pPage->Child, FALSE ); pPage->Child = NULL; @@ -2603,7 +2674,7 @@ static void hb_cdxPageGetChild( LPCDXPAGE pPage ) #ifdef HB_CDX_DSPDBG_INFO printf("GetChild: Parent=%lx, Child=%lx\r\n", pPage->Page, ulPage); fflush(stdout); #endif - if ( pPage->Child == NULL ) + if( pPage->Child == NULL ) pPage->Child = hb_cdxPageNew( pPage->TagParent, pPage, ulPage ); } @@ -2624,19 +2695,19 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageCheckKeys( pPage ); #endif - if ( pPage->iCurKey > 0 ) + if( pPage->iCurKey > 0 ) iFirstKey = pPage->iCurKey - 1; else { iFirstKey = 0; --iBlncKeys; - if ( pPage->Left != CDX_DUMMYNODE ) + if( pPage->Left != CDX_DUMMYNODE ) iRet |= NODE_BALANCE; } - if ( iBlncKeys > pPage->iKeys - iFirstKey ) + if( iBlncKeys > pPage->iKeys - iFirstKey ) { iBlncKeys = pPage->iKeys - iFirstKey; - if ( pPage->Right != CDX_DUMMYNODE ) + if( pPage->Right != CDX_DUMMYNODE ) iRet |= NODE_BALANCE; } @@ -2645,14 +2716,14 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) fflush(stdout); #endif - if ( ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) == 0 && + if( ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) == 0 && ( iBlncKeys < 2 || ( iChildRet & NODE_BALANCE ) == 0 ) ) return iRet; - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) { ulPage = hb_cdxPageGetKeyPage( pPage, iFirstKey + i ); - if ( pPage->Child && pPage->Child->Page == ulPage ) + if( pPage->Child && pPage->Child->Page == ulPage ) { childs[i] = pPage->Child; pPage->Child = NULL; @@ -2662,7 +2733,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) childs[i] = hb_cdxPageNew( pPage->TagParent, pPage, ulPage ); } #ifdef HB_CDX_DBGCODE - if ( i > 0 && ( childs[i]->Page != childs[i-1]->Right || + if( i > 0 && ( childs[i]->Page != childs[i-1]->Right || childs[i]->Left != childs[i-1]->Page ) ) { printf("\r\nchilds[%d]->Page=%lx, childs[%d]->Right=%lx, childs[%d]->Page=%lx, childs[%d]->Left=%lx", @@ -2674,21 +2745,21 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) #endif iChKeys[i] = childs[i]->iKeys; iChFree[i] = childs[i]->iFree; - if ( childs[i]->iFree >= childs[i]->ReqByte ) /* TODO: increase limit for last page */ + if( childs[i]->iFree >= childs[i]->ReqByte ) /* TODO: increase limit for last page */ iFree += childs[i]->iFree; - else if ( childs[i]->iFree >= 0 ) + else if( childs[i]->iFree >= 0 ) { - if ( i == iSkip ) + if( i == iSkip ) ++iSkip; #if 1 - else if ( i + 1 == iBlncKeys && ( iChildRet & NODE_SPLIT ) == 0 ) + else if( i + 1 == iBlncKeys && ( iChildRet & NODE_SPLIT ) == 0 ) { iBlncKeys--; hb_cdxPageFree( childs[i], FALSE ); } #endif } - if ( i >= iSkip && i < iBlncKeys ) + if( i >= iSkip && i < iBlncKeys ) iKeys += childs[i]->iKeys; #ifdef HB_CDX_DSPDBG_INFO @@ -2697,19 +2768,19 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) fflush(stdout); #endif } - if ( ( iChildRet & NODE_SPLIT ) == 0 ) + if( ( iChildRet & NODE_SPLIT ) == 0 ) { - for ( i = iBlncKeys - 1; i > iSkip && childs[i]->iFree >= 0 && childs[i]->iFree < childs[i]->ReqByte; i-- ) + for( i = iBlncKeys - 1; i > iSkip && childs[i]->iFree >= 0 && childs[i]->iFree < childs[i]->ReqByte; i-- ) { iKeys -= childs[i]->iKeys; hb_cdxPageFree( childs[i], FALSE ); iBlncKeys--; } } - if ( ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) == 0 && + if( ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) == 0 && ( iBlncKeys < 2 || iFree < CDX_EXT_FREESPACE ) ) { - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) hb_cdxPageFree( childs[i], FALSE ); return iRet; } @@ -2717,20 +2788,20 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) printf("\r\nleaf balance: Page=%lx iKeys=%d", pPage->Page, iKeys); fflush(stdout); #endif - if ( iKeys > 0 ) + if( iKeys > 0 ) { iBufSize = iKeys; pPtr = pKeyPool = (BYTE *) hb_xgrab( iBufSize * iLen ); - for ( i = iSkip; i < iBlncKeys && iKeys > 0; i++ ) + for( i = iSkip; i < iBlncKeys && iKeys > 0; i++ ) { - if ( childs[i]->iKeys > 0 ) + if( childs[i]->iKeys > 0 ) { - if ( childs[i]->pKeyBuf ) + if( childs[i]->pKeyBuf ) memcpy( pPtr, childs[i]->pKeyBuf, childs[i]->iKeys * iLen ); else hb_cdxPageLeafDecode( childs[i], pPtr ); /* update number of duplicate characters when join pages */ - if ( pPtr > pKeyPool ) + if( pPtr > pKeyPool ) { BYTE bDup = 0, bMax; #ifdef HB_CDX_PACKTRAIL @@ -2738,12 +2809,12 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) #else bMax = iLen - 6 - HB_MAX( pPtr[ iLen - 1 ], pPtr[ -1 ] ); #endif - while ( bDup < bMax && pPtr[ bDup ] == pPtr[ bDup - iLen ] ) + while( bDup < bMax && pPtr[ bDup ] == pPtr[ bDup - iLen ] ) ++bDup; pPtr[ iLen - 2 ] = bDup; - if ( iSkip == i - 1 && childs[iSkip]->iFree >= 0 && - iLen - 6 - bDup - pPtr[ iLen - 1 ] > - childs[iSkip]->iFree - childs[iSkip]->ReqByte ) + if( iSkip == i - 1 && childs[iSkip]->iFree >= 0 && + iLen - 6 - bDup - pPtr[ iLen - 1 ] > + childs[iSkip]->iFree - childs[iSkip]->ReqByte ) { memmove( pKeyPool, pPtr, childs[i]->iKeys * iLen ); pPtr = pKeyPool; @@ -2770,36 +2841,36 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) pPtr = pKeyPool; fIns = FALSE; i = iSkip; - while ( iKeys > 0 ) + while( iKeys > 0 ) { - if ( i == iBlncKeys ) + if( i == iBlncKeys ) { - if ( childs[i-1]->Right != CDX_DUMMYNODE ) + if( childs[i-1]->Right != CDX_DUMMYNODE ) lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, childs[i-1]->Right ); else lpTmpPage = NULL; #if 1 - if ( !fIns && lpTmpPage != NULL ) + if( !fIns && lpTmpPage != NULL ) { int j, iSize = 0, iMaxReq; ULONG ulMaxRec = 0, ul; BYTE * pbKey, bMax; - for ( j = 0; j < iKeys; j++ ) + for( j = 0; j < iKeys; j++ ) { - if ( ulMaxRec < ( ul = HB_GET_LE_UINT32( &pPtr[ ( j + 1 ) * iLen - 6 ] ) ) ) + if( ulMaxRec < ( ul = HB_GET_LE_UINT32( &pPtr[ ( j + 1 ) * iLen - 6 ] ) ) ) ulMaxRec = ul; iSize += iLen - 6 - ( j == 0 ? 0 : pPtr[ ( j + 1 ) * iLen - 2 ] ) - pPtr[ ( j + 1 ) * iLen - 1 ]; } pbKey = hb_cdxPageGetKeyVal( lpTmpPage, 0 ); - bMax = (BYTE) hb_cdxPageGetKeyTrl( lpTmpPage, 0 ); + bMax = hb_cdxPageGetKeyTrl( lpTmpPage, 0 ); #ifdef HB_CDX_PACKTRAIL bMax = iLen - 6 - bMax; #else bMax = iLen - 6 - HB_MAX( pPtr[ iKeys * iLen - 1 ], bMax ); #endif - for ( j = 0; j < bMax && + for( j = 0; j < bMax && pPtr[ ( iKeys - 1 ) * iLen + j ] == pbKey[ j ]; j++ ) {} #ifdef HB_CDX_DSPDBG_INFO printf("\r\nbDup=%d, bTrl=%d ", j, iLen - 6 - bMax ); fflush(stdout); @@ -2807,7 +2878,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) iSize -= j; iMaxReq = lpTmpPage->ReqByte; ul = lpTmpPage->RNMask; - while ( ulMaxRec > ul ) + while( ulMaxRec > ul ) { ++iMaxReq; ul = ( ul << 8 ) | 0xFF; @@ -2815,7 +2886,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) iSize += iKeys * iMaxReq; iSize = lpTmpPage->iFree - iSize - ( iMaxReq - lpTmpPage->ReqByte ) * lpTmpPage->iKeys; - if ( iSize < 0 ) + if( iSize < 0 ) fIns = TRUE; else { @@ -2824,7 +2895,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) j, iKeys, lpTmpPage->iKeys, i, pPage->Page, lpTmpPage->Page, iSize, (ULONG) HB_GET_LE_UINT32( pPtr + iLen - 6 )); fflush(stdout); #endif - if ( iBufSize >= iKeys + lpTmpPage->iKeys ) + if( iBufSize >= iKeys + lpTmpPage->iKeys ) { memmove( pKeyPool, pPtr, iKeys * iLen ); } @@ -2837,11 +2908,11 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) hb_xfree( pKeyPool ); pKeyPool = pTmp; } - if ( lpTmpPage->iKeys > 0 ) + if( lpTmpPage->iKeys > 0 ) { BYTE bDup = 0; pPtr = &pKeyPool[ iKeys * iLen ]; - if ( lpTmpPage->pKeyBuf ) + if( lpTmpPage->pKeyBuf ) memcpy( pPtr, lpTmpPage->pKeyBuf, lpTmpPage->iKeys * iLen ); else hb_cdxPageLeafDecode( lpTmpPage, pPtr ); @@ -2850,7 +2921,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) #else bMax = iLen - 6 - HB_MAX( pPtr[ iLen - 1 ], pPtr[ -1 ] ); #endif - while ( bDup < bMax && pPtr[ bDup ] == pPtr[ bDup - iLen ] ) + while( bDup < bMax && pPtr[ bDup ] == pPtr[ bDup - iLen ] ) ++bDup; pPtr[ iLen - 2 ] = bDup; iKeys += lpTmpPage->iKeys; @@ -2860,11 +2931,11 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) } pPtr = pKeyPool; childs[i] = lpTmpPage; - if ( iFirstKey + i >= pPage->iKeys ) + if( iFirstKey + i >= pPage->iKeys ) iRet |= NODE_NEWLASTKEY; #ifdef HB_CDX_DBGCODE_EXT childs[i]->iKeys = 0; - if ( childs[i]->pKeyBuf ) + if( childs[i]->pKeyBuf ) { hb_xfree( childs[i]->pKeyBuf ); childs[i]->pKeyBuf = NULL; @@ -2873,7 +2944,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageCalcLeafSpace( childs[i], pPtr, iKeys ); hb_cdxPageLeafEncode( childs[i], pPtr, childs[i]->iKeys ); iSize += ( iMaxReq - childs[i]->ReqByte ) * childs[i]->iKeys; - if ( iSize != childs[i]->iFree ) + if( iSize != childs[i]->iFree ) { printf("\r\ninserting, iSize=%d, childs[i]->iFree=%d", iSize, childs[i]->iFree); fflush(stdout); printf("\r\niKeys=%d, iMaxReq=%d", iKeys, iMaxReq); fflush(stdout); @@ -2886,7 +2957,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) else fIns = TRUE; - if ( fIns ) + if( fIns ) { childs[ i ] = hb_cdxPageNew( pPage->TagParent, pPage, 0 ); childs[ i ]->PageType = CDX_NODE_LEAF; @@ -2895,7 +2966,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) childs[ i ]->Right = childs[i-1]->Right; childs[i-1]->Right = childs[ i ]->Page; childs[i-1]->fChanged = TRUE; - if ( lpTmpPage != NULL ) + if( lpTmpPage != NULL ) { lpTmpPage->Left = childs[i]->Page; lpTmpPage->fChanged = TRUE; @@ -2910,16 +2981,16 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) } } childs[i]->iKeys = 0; - if ( childs[i]->pKeyBuf ) + if( childs[i]->pKeyBuf ) { hb_xfree( childs[i]->pKeyBuf ); childs[i]->pKeyBuf = NULL; childs[i]->fBufChanged = FALSE; } hb_cdxPageCalcLeafSpace( childs[i], pPtr, iKeys ); - if ( i == iSkip && i < iBlncKeys && !childs[i]->fChanged && - childs[i]->iKeys == iChKeys[i] && - childs[i]->iFree == iChFree[i] ) + if( i == iSkip && i < iBlncKeys && !childs[i]->fChanged && + childs[i]->iKeys == iChKeys[i] && + childs[i]->iFree == iChFree[i] ) { #ifdef HB_CDX_DSPDBG_INFO printf("\r\niskip++\r\n");fflush(stdout); @@ -2933,7 +3004,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) pPtr += childs[i]->iKeys * iLen; iKeys -= childs[i]->iKeys; /* update parent key */ - if ( i < iBlncKeys ) + if( i < iBlncKeys ) hb_cdxPageIntSetKey( pPage, iFirstKey + i, fIns, pPtr - iLen, HB_GET_LE_UINT32( pPtr - 6 ), childs[i]->Page ); @@ -2948,12 +3019,12 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) #endif i++; } - if ( i < iBlncKeys ) + if( i < iBlncKeys ) { /* Update siblings links */ #if 1 - if ( childs[iBlncKeys-1]->Right != CDX_DUMMYNODE && - ( i > 1 || ( i == 1 && childs[0]->Left == CDX_DUMMYNODE ) ) ) + if( childs[iBlncKeys-1]->Right != CDX_DUMMYNODE && + ( i > 1 || ( i == 1 && childs[0]->Left == CDX_DUMMYNODE ) ) ) { ULONG Page; Page = childs[iBlncKeys-1]->Page; @@ -2962,7 +3033,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageIntSetKey( pPage, iFirstKey + i - 1, FALSE, NULL, 0, Page ); childs[i-1]->Right = childs[iBlncKeys-1]->Right; childs[i-1]->fChanged = TRUE; - if ( i > 1 ) + if( i > 1 ) { childs[i-2]->Right = Page; childs[i-2]->fChanged = TRUE; @@ -2973,7 +3044,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) { ULONG Left, Right; Right = childs[iBlncKeys-1]->Right; - if ( i > 0 ) + if( i > 0 ) { Left = childs[i-1]->Page; childs[i-1]->Right = Right; @@ -2982,7 +3053,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) else { Left = childs[0]->Left; - if ( Left != CDX_DUMMYNODE ) + if( Left != CDX_DUMMYNODE ) { lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, Left ); lpTmpPage->Right = Right; @@ -2990,7 +3061,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageFree( lpTmpPage, FALSE ); } } - if ( Right != CDX_DUMMYNODE ) + if( Right != CDX_DUMMYNODE ) { lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, Right ); lpTmpPage->Left = Left; @@ -2999,7 +3070,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) } } /* Unlink empty pages from parent */ - while ( i < iBlncKeys ) + while( i < iBlncKeys ) { /* Delete parent key */ iBlncKeys--; @@ -3007,7 +3078,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) printf("\r\nleaf balance: free child[%d]->Page=%lx", iBlncKeys, childs[iBlncKeys]->Page); fflush(stdout); #endif - if ( childs[iBlncKeys]->pKeyBuf ) + if( childs[iBlncKeys]->pKeyBuf ) { hb_xfree( childs[iBlncKeys ]->pKeyBuf ); childs[iBlncKeys]->pKeyBuf = NULL; @@ -3023,16 +3094,16 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) } iRet |= NODE_BALANCE; } - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) hb_cdxPageFree( childs[i], FALSE ); - if ( pKeyPool ) + if( pKeyPool ) hb_xfree( pKeyPool ); pPage->fChanged = TRUE; #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckKeys( pPage ); #endif - if ( pPage->iKeys > pPage->TagParent->MaxKeys ) + if( pPage->iKeys > pPage->TagParent->MaxKeys ) iRet |= NODE_SPLIT; return iRet; } @@ -3048,23 +3119,23 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) BOOL fForce = ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) != 0; int iRet = 0, i; - if ( !fForce && ( iChildRet & NODE_BALANCE ) == 0 ) + if( !fForce && ( iChildRet & NODE_BALANCE ) == 0 ) return iRet; - if ( pPage->Child && pPage->Child->Child ) + if( pPage->Child && pPage->Child->Child ) hb_cdxPageFree( pPage->Child->Child, FALSE ); #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckKeys( pPage ); #endif - if ( pPage->iKeys <= iBlncKeys || pPage->iCurKey <= iBlncKeys / 2 ) + if( pPage->iKeys <= iBlncKeys || pPage->iCurKey <= iBlncKeys / 2 ) iFirstKey = 0; - else if ( pPage->iCurKey + ( iBlncKeys >> 1 ) >= pPage->iKeys ) + else if( pPage->iCurKey + ( iBlncKeys >> 1 ) >= pPage->iKeys ) iFirstKey = pPage->iKeys - iBlncKeys; else iFirstKey = pPage->iCurKey - ( iBlncKeys >> 1 ); - if ( iBlncKeys > pPage->iKeys - iFirstKey ) + if( iBlncKeys > pPage->iKeys - iFirstKey ) { iBlncKeys = pPage->iKeys - iFirstKey; iRet |= NODE_BALANCE; @@ -3075,13 +3146,13 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) fflush(stdout); #endif - if ( !fForce && iBlncKeys < 2 ) + if( !fForce && iBlncKeys < 2 ) return iRet; - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) { ulPage = hb_cdxPageGetKeyPage( pPage, iFirstKey + i ); - if ( pPage->Child && pPage->Child->Page == ulPage ) + if( pPage->Child && pPage->Child->Page == ulPage ) { childs[i] = pPage->Child; pPage->Child = NULL; @@ -3091,8 +3162,8 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) childs[i] = hb_cdxPageNew( pPage->TagParent, pPage, ulPage ); } #ifdef HB_CDX_DBGCODE - if ( i > 0 && ( childs[i]->Page != childs[i-1]->Right || - childs[i]->Left != childs[i-1]->Page ) ) + if( i > 0 && ( childs[i]->Page != childs[i-1]->Right || + childs[i]->Left != childs[i-1]->Page ) ) { printf("\r\nchilds[%d]->Page=%lx, childs[%d]->Right=%lx, childs[%d]->Page=%lx, childs[%d]->Left=%lx", i-1, childs[i-1]->Page, i-1, childs[i-1]->Right, @@ -3103,9 +3174,9 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) #endif iKeys += childs[i]->iKeys; - if ( childs[i]->iKeys > iMax ) + if( childs[i]->iKeys > iMax ) iMax = childs[i]->iKeys; - if ( childs[i]->iKeys < iMin ) + if( childs[i]->iKeys < iMin ) iMin = childs[i]->iKeys; #ifdef HB_CDX_DSPDBG_INFO printf(", childs[%d]->Page=%lx(%d)", i, childs[i]->Page, childs[i]->iKeys); @@ -3115,10 +3186,10 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) iNeedKeys = ( iKeys + pPage->TagParent->MaxKeys - 1 ) / pPage->TagParent->MaxKeys; #if 1 - if ( iNeedKeys == 1 && iBlncKeys > 1 && childs[0]->Left != CDX_DUMMYNODE && - childs[iBlncKeys-1]->Right != CDX_DUMMYNODE && - iKeys >= ( CDX_BALANCE_INTPAGES << 1 ) && - iKeys > ( ( pPage->TagParent->MaxKeys * 3 ) >> 1 ) ) + if( iNeedKeys == 1 && iBlncKeys > 1 && childs[0]->Left != CDX_DUMMYNODE && + childs[iBlncKeys-1]->Right != CDX_DUMMYNODE && + iKeys >= ( CDX_BALANCE_INTPAGES << 1 ) && + iKeys > ( ( pPage->TagParent->MaxKeys * 3 ) >> 1 ) ) { iNeedKeys = 2; } @@ -3129,16 +3200,16 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) #else iDiv = iMax - iMin; #endif - if ( iKeys > 0 && ( iDiv >= 2 || fForce ) ) + if( iKeys > 0 && ( iDiv >= 2 || fForce ) ) { #if 1 - if ( iBlncKeys == 1 && iKeys > pPage->TagParent->MaxKeys && - childs[0]->Right != CDX_DUMMYNODE ) + if( iBlncKeys == 1 && iKeys > pPage->TagParent->MaxKeys && + childs[0]->Right != CDX_DUMMYNODE ) { lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, childs[0]->Right ); iKeys += lpTmpPage->iKeys; childs[iBlncKeys++] = lpTmpPage; - if ( iFirstKey + iBlncKeys > pPage->iKeys ) + if( iFirstKey + iBlncKeys > pPage->iKeys ) iRet |= NODE_NEWLASTKEY; iNeedKeys = ( iKeys + pPage->TagParent->MaxKeys - 1 ) / pPage->TagParent->MaxKeys; @@ -3148,7 +3219,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) { iMin = HB_MAX( iKeys / iNeedKeys, 2 ); iMax = HB_MAX( ( iKeys + iNeedKeys - 1 ) / iNeedKeys, iMin ); - for ( i = iBlncKeys - 1; i > 1 && + for( i = iBlncKeys - 1; i > 1 && childs[i]->iKeys >= iMin && childs[i]->iKeys <= iMax; i-- ) { iKeys -= childs[i]->iKeys; @@ -3157,13 +3228,13 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) iMin = HB_MAX( iKeys / iNeedKeys, 2 ); iMax = HB_MAX( ( iKeys + iNeedKeys - 1 ) / iNeedKeys, iMin ); } - while ( iBlncKeys > 2 && childs[0]->iKeys >= iMin && childs[0]->iKeys <= iMax ) + while( iBlncKeys > 2 && childs[0]->iKeys >= iMin && childs[0]->iKeys <= iMax ) { iKeys -= childs[0]->iKeys; hb_cdxPageFree( childs[0], FALSE ); iBlncKeys--; iFirstKey++; - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) { childs[i] = childs[i+1]; } @@ -3172,19 +3243,19 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) } } } - if ( !fForce && ( iBlncKeys < 2 || iDiv < 2 ) ) + if( !fForce && ( iBlncKeys < 2 || iDiv < 2 ) ) { - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) hb_cdxPageFree( childs[i], FALSE ); return iRet; } - if ( iKeys > 0 ) + if( iKeys > 0 ) { pPtr = pKeyPool = (BYTE*) hb_xgrab( iKeys * iLen ); - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) { - if ( childs[i]->iKeys > 0 ) + if( childs[i]->iKeys > 0 ) { memcpy( pPtr, childs[i]->node.intNode.keyPool, childs[i]->iKeys * iLen ); pPtr += childs[i]->iKeys * iLen; @@ -3192,9 +3263,9 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) } } - if ( iNeedKeys > iBlncKeys ) + if( iNeedKeys > iBlncKeys ) { - if ( iBlncKeys < 2 ) + if( iBlncKeys < 2 ) i = iBlncKeys; else { @@ -3212,9 +3283,9 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) childs[ i ]->Left = childs[i-1]->Page; childs[ i ]->Right = childs[i-1]->Right; childs[i-1]->Right = childs[ i ]->Page; - if ( i < iBlncKeys ) + if( i < iBlncKeys ) childs[i+1]->Left = childs[i]->Page; - else if ( childs[i]->Right != CDX_DUMMYNODE ) + else if( childs[i]->Right != CDX_DUMMYNODE ) { lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, childs[iBlncKeys]->Right ); lpTmpPage->Left = childs[i]->Page; @@ -3228,12 +3299,12 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) iBlncKeys++; iRet |= NODE_BALANCE; } - else if ( iNeedKeys < iBlncKeys ) + else if( iNeedKeys < iBlncKeys ) { ULONG Left, Right; /* Update siblings links */ - if ( iNeedKeys > 1 ) + if( iNeedKeys > 1 ) { childs[iNeedKeys-2]->Right = childs[iBlncKeys-1]->Page; childs[iBlncKeys-1]->Left = childs[iNeedKeys-2]->Page; @@ -3241,7 +3312,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) childs[iBlncKeys-1] = childs[iNeedKeys-1]; childs[iNeedKeys-1] = lpTmpPage; } - else if ( iNeedKeys > 0 && childs[0]->Left == CDX_DUMMYNODE ) + else if( iNeedKeys > 0 && childs[0]->Left == CDX_DUMMYNODE ) { lpTmpPage = childs[iBlncKeys-1]; childs[iBlncKeys-1] = childs[0]; @@ -3251,7 +3322,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) else { Right = childs[iBlncKeys-1]->Right; - if ( iNeedKeys > 0 ) + if( iNeedKeys > 0 ) { Left = childs[iNeedKeys-1]->Page; childs[iNeedKeys-1]->Right = Right; @@ -3259,7 +3330,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) else { Left = childs[0]->Left; - if ( Left != CDX_DUMMYNODE ) + if( Left != CDX_DUMMYNODE ) { lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, Left ); lpTmpPage->Right = Right; @@ -3267,7 +3338,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageFree( lpTmpPage, FALSE ); } } - if ( Right != CDX_DUMMYNODE ) + if( Right != CDX_DUMMYNODE ) { lpTmpPage = hb_cdxPageNew( pPage->TagParent, pPage, Right ); lpTmpPage->Left = Left; @@ -3276,7 +3347,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) } } /* Unlink empty pages from parent */ - for ( i = iBlncKeys - 1; i >= iNeedKeys; i-- ) + for( i = iBlncKeys - 1; i >= iNeedKeys; i-- ) { /* Delete parent key */ #ifdef HB_CDX_DSPDBG_INFO @@ -3299,14 +3370,14 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) /* * Redistribute childs internal node's keys and update parent keys */ - if ( iKeys > 0 ) + if( iKeys > 0 ) { pPtr = pKeyPool; - for ( i = 0; i < iBlncKeys; i++ ) + for( i = 0; i < iBlncKeys; i++ ) { iNodeKeys = ( iKeys + iBlncKeys - i - 1 ) / ( iBlncKeys - i ); #ifdef HB_CDX_DBGCODE - if ( iNodeKeys > pPage->TagParent->MaxKeys ) + if( iNodeKeys > pPage->TagParent->MaxKeys ) hb_cdxErrInternal( "hb_cdxPageKeyIntBalance: iNodeKeys calculated wrong!." ); #endif /* TODO: do nothing if iNodeKeys == childs[i]->iKeys && i == iSkip */ @@ -3316,7 +3387,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) pPtr += iNodeKeys * iLen; iKeys -= iNodeKeys; /* update parent key */ - if ( iFirstKey + i < pPage->iKeys ) + if( iFirstKey + i < pPage->iKeys ) { hb_cdxPageIntSetKey( pPage, iFirstKey + i, FALSE, pPtr - iLen, HB_GET_BE_UINT32( pPtr - 8 ), @@ -3336,7 +3407,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckKeys( pPage ); #endif - if ( pPage->iKeys > pPage->TagParent->MaxKeys ) + if( pPage->iKeys > pPage->TagParent->MaxKeys ) iRet |= NODE_SPLIT; return iRet; } @@ -3348,13 +3419,13 @@ static int hb_cdxPageBalance( LPCDXPAGE pPage, int iChildRet ) { int iRet = 0; - if ( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) iRet = iChildRet; else { - if ( iChildRet & NODE_NEWLASTKEY ) + if( iChildRet & NODE_NEWLASTKEY ) { - if ( pPage->Child->iKeys == 0 ) + if( pPage->Child->iKeys == 0 ) { iChildRet |= NODE_JOIN; iRet |= NODE_NEWLASTKEY; @@ -3369,23 +3440,23 @@ static int hb_cdxPageBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageCheckKeys( pPage ); #endif pPage->fChanged = TRUE; - if ( pPage->iCurKey >= pPage->iKeys - 1 ) + if( pPage->iCurKey >= pPage->iKeys - 1 ) iRet |= NODE_NEWLASTKEY; } } - if ( ( pPage->Child->PageType & CDX_NODE_LEAF ) != 0 ) + if( ( pPage->Child->PageType & CDX_NODE_LEAF ) != 0 ) iRet |= hb_cdxPageKeyLeafBalance( pPage, iChildRet ); else iRet |= hb_cdxPageKeyIntBalance( pPage, iChildRet ); } - if ( !pPage->Owner ) + if( !pPage->Owner ) { - if ( pPage->iKeys == 0 ) + if( pPage->iKeys == 0 ) { pPage->PageType |= CDX_NODE_LEAF; hb_cdxPageLeafInitSpace( pPage ); } - else if ( iRet & NODE_SPLIT ) + else if( iRet & NODE_SPLIT ) iRet = hb_cdxPageRootSplit( pPage ); } return iRet; @@ -3434,7 +3505,7 @@ static int hb_cdxPageKeyRemove( LPCDXPAGE pPage ) { int iChildRet; - if ( pPage->PageType & CDX_NODE_LEAF ) + if( pPage->PageType & CDX_NODE_LEAF ) iChildRet = hb_cdxPageLeafDelKey( pPage ); else /* interior node */ iChildRet = hb_cdxPageKeyRemove( pPage->Child ); @@ -3448,7 +3519,7 @@ static int hb_cdxPageKeyInsert( LPCDXPAGE pPage, LPCDXKEY pKey ) { int iChildRet; - if ( pPage->PageType & CDX_NODE_LEAF ) + if( pPage->PageType & CDX_NODE_LEAF ) iChildRet = hb_cdxPageLeafAddKey( pPage, pKey ); else /* interior node */ iChildRet = hb_cdxPageKeyInsert( pPage->Child, pKey ); @@ -3466,7 +3537,7 @@ static void hb_cdxTagHeaderStore( LPCDXTAG pTag ) USHORT uiKeyLen, uiForLen; CDXTAGHEADER tagHeader; - if ( !pTag->TagChanged ) + if( !pTag->TagChanged ) return; /* @@ -3480,21 +3551,21 @@ static void hb_cdxTagHeaderStore( LPCDXTAG pTag ) pTag->TagChanged = FALSE; pTag->OptFlags &= ~( CDX_TYPE_UNIQUE | CDX_TYPE_FORFILTER | CDX_TYPE_TEMPORARY | CDX_TYPE_CUSTOM ); - if ( pTag->UniqueKey ) + if( pTag->UniqueKey ) pTag->OptFlags |= CDX_TYPE_UNIQUE; - if ( pTag->pForItem != NULL ) + if( pTag->pForItem != NULL ) pTag->OptFlags |= CDX_TYPE_FORFILTER; #if defined( HB_SIXCDX ) - if ( pTag->Custom ) + if( pTag->Custom ) pTag->OptFlags |= CDX_TYPE_TEMPORARY | CDX_TYPE_CUSTOM; - else if ( pTag->ChgOnly ) + else if( pTag->ChgOnly ) pTag->OptFlags |= CDX_TYPE_CUSTOM; - else if ( pTag->Partial ) + else if( pTag->Partial ) pTag->OptFlags |= CDX_TYPE_TEMPORARY; #else - if ( pTag->Temporary ) + if( pTag->Temporary ) pTag->OptFlags |= CDX_TYPE_TEMPORARY; - if ( pTag->Custom ) + if( pTag->Custom ) pTag->OptFlags |= CDX_TYPE_CUSTOM; #endif @@ -3503,8 +3574,10 @@ static void hb_cdxTagHeaderStore( LPCDXTAG pTag ) HB_PUT_LE_UINT16( tagHeader.keySize, pTag->uiLen ); tagHeader.indexOpt = pTag->OptFlags; tagHeader.indexSig = 1; - if ( !pTag->AscendKey ) + if( !pTag->AscendKey ) HB_PUT_LE_UINT16( tagHeader.ascendFlg, 1 ); + if( pTag->IgnoreCase ) + tagHeader.ignoreCase = 1; uiKeyLen = pTag->KeyExpr == NULL ? 0 : strlen( pTag->KeyExpr ); uiForLen = pTag->ForExpr == NULL ? 0 : strlen( pTag->ForExpr ); @@ -3609,6 +3682,11 @@ static void hb_cdxTagLoad( LPCDXTAG pTag ) pTag->AscendKey = pTag->UsrAscend = ( HB_GET_LE_UINT16( tagHeader.ascendFlg ) == 0 ); pTag->UsrUnique = FALSE; + if( tagHeader.indexSig == 0x01 ) + pTag->IgnoreCase = tagHeader.ignoreCase == 1; + else + pTag->IgnoreCase = FALSE; + if( pTag->OptFlags & CDX_TYPE_STRUCTURE ) return; @@ -3626,34 +3704,37 @@ static void hb_cdxTagLoad( LPCDXTAG pTag ) pTag->uiType = hb_cdxItemType( hb_vmEvalBlockOrMacro( pTag->pKeyItem ) ); pTag->bTrail = ( pTag->uiType == 'C' ) ? ' ' : '\0'; - if ( pTag->uiType == 'C' ) + if( pTag->uiType == 'C' ) hb_cdxMakeSortTab( pTag->pIndex->pArea ); + else + pTag->IgnoreCase = FALSE; pTag->nField = hb_rddFieldExpIndex( ( AREAP ) pTag->pIndex->pArea, pTag->KeyExpr ); /* Check if there is a FOR expression: pTag->OptFlags & CDX_TYPE_FORFILTER */ - if ( tagHeader.keyExpPool[ uiForPos ] != 0 ) + if( tagHeader.keyExpPool[ uiForPos ] != 0 ) { pTag->ForExpr = ( char * ) hb_xgrab( uiForLen + 1 ); hb_strncpyTrim( pTag->ForExpr, ( const char * ) tagHeader.keyExpPool + uiForPos, uiForLen ); - if ( SELF_COMPILE( ( AREAP ) pTag->pIndex->pArea, ( BYTE * ) pTag->ForExpr ) == HB_FAILURE ) + if( SELF_COMPILE( ( AREAP ) pTag->pIndex->pArea, ( BYTE * ) pTag->ForExpr ) == HB_FAILURE ) pTag->RootBlock = 0; /* To force RT error - index corrupted */ else { pTag->pForItem = pTag->pIndex->pArea->valResult; pTag->pIndex->pArea->valResult = NULL; - if ( hb_cdxItemType( hb_vmEvalBlockOrMacro( pTag->pForItem ) ) != 'L' ) + if( hb_cdxItemType( hb_vmEvalBlockOrMacro( pTag->pForItem ) ) != 'L' ) pTag->RootBlock = 0; /* To force RT error - index corrupted */ } } SELF_GOTO( ( AREAP ) pTag->pIndex->pArea, ulRecNo ); - if ( pTag->uiLen > CDX_MAXKEY || pTag->uiType == 'U' || - ( pTag->uiType == 'N' && pTag->uiLen != 8 ) || - ( pTag->uiType == 'D' && pTag->uiLen != 8 ) || - ( pTag->uiType == 'L' && pTag->uiLen != 1 ) ) + if( pTag->uiLen > CDX_MAXKEY || pTag->uiType == 'U' || + ( pTag->uiType == 'N' && pTag->uiLen != 8 && pTag->uiLen != 4 ) || + ( pTag->uiType == 'D' && pTag->uiLen != 8 ) || + ( pTag->uiType == 'T' && pTag->uiLen != 8 ) || + ( pTag->uiType == 'L' && pTag->uiLen != 1 ) ) { pTag->RootBlock = 0; /* To force RT error - index corrupted */ } @@ -3664,27 +3745,27 @@ static void hb_cdxTagLoad( LPCDXTAG pTag ) */ static void hb_cdxTagFree( LPCDXTAG pTag ) { - if ( pTag->RootPage != NULL ) + if( pTag->RootPage != NULL ) { hb_cdxPageFree( pTag->RootPage, FALSE ); pTag->RootPage = NULL; } hb_cdxTagPoolFlush( pTag ); hb_cdxTagPoolFree( pTag, 0 ); - if ( pTag->TagChanged ) + if( pTag->TagChanged ) hb_cdxTagHeaderStore( pTag ); - if ( pTag->szName != NULL ) + if( pTag->szName != NULL ) hb_xfree( pTag->szName ); - if ( pTag->KeyExpr != NULL ) + if( pTag->KeyExpr != NULL ) hb_xfree( pTag->KeyExpr ); - if ( pTag->pKeyItem != NULL ) + if( pTag->pKeyItem != NULL ) hb_vmDestroyBlockOrMacro( pTag->pKeyItem ); - if ( pTag->ForExpr != NULL ) + if( pTag->ForExpr != NULL ) hb_xfree( pTag->ForExpr ); - if ( pTag->pForItem != NULL ) + if( pTag->pForItem != NULL ) hb_vmDestroyBlockOrMacro( pTag->pForItem ); hb_cdxKeyFree( pTag->CurKey ); - if ( pTag->HotKey ) + if( pTag->HotKey ) hb_cdxKeyFree( pTag->HotKey ); hb_cdxTagClearScope( pTag, 0); hb_cdxTagClearScope( pTag, 1); @@ -3707,11 +3788,11 @@ static LPCDXTAG hb_cdxTagNew( LPCDXINDEX pIndex, char *szTagName, ULONG TagHdr ) pTag->szName = hb_strdup( szName ); pTag->pIndex = pIndex; pTag->AscendKey = pTag->UsrAscend = TRUE; - pTag->UsrUnique = FALSE; + pTag->UsrUnique = pTag->IgnoreCase = FALSE; pTag->uiType = 'C'; pTag->bTrail = ' '; pTag->CurKey = hb_cdxKeyNew(); - if ( TagHdr == CDX_DUMMYNODE ) + if( TagHdr == CDX_DUMMYNODE ) { pTag->TagBlock = hb_cdxIndexGetAvailPage( pIndex, TRUE ); pTag->TagChanged = TRUE; @@ -3721,7 +3802,7 @@ static LPCDXTAG hb_cdxTagNew( LPCDXINDEX pIndex, char *szTagName, ULONG TagHdr ) { pTag->TagBlock = TagHdr; hb_cdxTagLoad( pTag ); - if ( pTag->RootBlock == 0 ) + if( pTag->RootBlock == 0 ) { /* index file is corrupted */ hb_cdxTagFree( pTag ); @@ -3736,12 +3817,12 @@ static LPCDXTAG hb_cdxTagNew( LPCDXINDEX pIndex, char *szTagName, ULONG TagHdr ) */ static void hb_cdxTagClose( LPCDXTAG pTag ) { - if ( pTag->RootPage != NULL ) + if( pTag->RootPage != NULL ) { hb_cdxPageFree( pTag->RootPage, FALSE ); pTag->RootPage = NULL; } - if ( pTag->TagChanged ) + if( pTag->TagChanged ) { hb_cdxTagHeaderStore( pTag ); } @@ -3755,13 +3836,13 @@ static void hb_cdxTagOpen( LPCDXTAG pTag ) { CDXTAGHEADER tagHeader; - if ( !pTag->RootPage ) + if( !pTag->RootPage ) { hb_cdxIndexPageRead( pTag->pIndex, pTag->TagBlock, (BYTE *) &tagHeader, sizeof( CDXTAGHEADER ) ); pTag->RootBlock = HB_GET_LE_UINT32( tagHeader.rootPtr ); - if ( pTag->RootBlock && pTag->RootBlock != CDX_DUMMYNODE ) + if( pTag->RootBlock && pTag->RootBlock != CDX_DUMMYNODE ) pTag->RootPage = hb_cdxPageNew( pTag, NULL, pTag->RootBlock ); - if ( !pTag->RootPage ) + if( !pTag->RootPage ) hb_cdxErrInternal("hb_cdxTagOpen: index corrupted"); } } @@ -3777,15 +3858,15 @@ static void hb_cdxTagPoolFree( LPCDXTAG pTag, int nPagesLeft ) hb_cdxTagPoolCheck( pTag ); #endif pPage = pTag->pagePool; - while ( nPagesLeft && pPage ) + while( nPagesLeft && pPage ) { pPage = pPage->pPoolNext; nPagesLeft--; } - while ( pPage ) + while( pPage ) { pPageNext = pPage->pPoolNext; - if ( ! pPage->bUsed ) + if( ! pPage->bUsed ) { hb_cdxPageFree( pPage, TRUE ); } @@ -3804,9 +3885,9 @@ static void hb_cdxTagPoolFlush( LPCDXTAG pTag ) LPCDXPAGE pPage; pPage = pTag->pagePool; - while ( pPage ) + while( pPage ) { - if ( pPage->fChanged ) + if( pPage->fChanged ) { hb_cdxPageStore( pPage ); } @@ -3822,7 +3903,7 @@ static void hb_cdxTagPoolFlush( LPCDXTAG pTag ) */ static void hb_cdxSetCurKey( LPCDXPAGE pPage ) { - while ( pPage->Child ) + while( pPage->Child ) pPage = pPage->Child; hb_cdxKeyPut( pPage->TagParent->CurKey, @@ -3834,12 +3915,12 @@ static void hb_cdxSetCurKey( LPCDXPAGE pPage ) /* * seek given Key in the Page or in its children */ -static int hb_cdxPageSeekKey( LPCDXPAGE pPage, LPCDXKEY pKey, ULONG ulKeyRec, BOOL fExact ) +static int hb_cdxPageSeekKey( LPCDXPAGE pPage, LPCDXKEY pKey, ULONG ulKeyRec ) { int l, r, n, k; BOOL fLeaf = ( pPage->PageType & CDX_NODE_LEAF ) != 0; - if ( fLeaf && !pPage->pKeyBuf && pPage->iKeys > 0 ) + if( fLeaf && !pPage->pKeyBuf && pPage->iKeys > 0 ) { int iLen = pPage->TagParent->uiLen + 6; BYTE *pKeyBuf = (BYTE *) hb_xgrab( pPage->iKeys * iLen ); @@ -3851,43 +3932,43 @@ static int hb_cdxPageSeekKey( LPCDXPAGE pPage, LPCDXKEY pKey, ULONG ulKeyRec, BO n = -1; l = 0; r = pPage->iKeys - 1; - while ( l < r ) + while( l < r ) { n = (l + r ) >> 1; k = hb_cdxValCompare( pPage->TagParent, pKey->val, pKey->len, hb_cdxPageGetKeyVal( pPage, n ), - (BYTE) pPage->TagParent->uiLen, fExact ); - if ( k == 0 ) + (BYTE) pPage->TagParent->uiLen, pKey->mode ); + if( k == 0 ) { - if ( ulKeyRec == CDX_MAX_REC_NUM ) + if( ulKeyRec == CDX_MAX_REC_NUM ) k = 1; - else if ( ulKeyRec != CDX_IGNORE_REC_NUM ) + else if( ulKeyRec != CDX_IGNORE_REC_NUM ) { ULONG ulRec = hb_cdxPageGetKeyRec( pPage, n ); - if ( ulKeyRec > ulRec ) + if( ulKeyRec > ulRec ) k = 1; - else if ( ulKeyRec < ulRec ) + else if( ulKeyRec < ulRec ) k = -1; } } - if ( k > 0 ) + if( k > 0 ) l = n + 1; else r = n; } pPage->iCurKey = l; - if ( r < 0 ) + if( r < 0 ) return k; - if ( !fLeaf ) + if( !fLeaf ) { hb_cdxPageGetChild( pPage ); #ifdef HB_CDX_DBGCODE - if ( memcmp( hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), - hb_cdxPageGetKeyVal( pPage->Child, pPage->Child->iKeys-1 ), - pPage->TagParent->uiLen ) != 0 || - hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ) != - hb_cdxPageGetKeyRec( pPage->Child, pPage->Child->iKeys-1 ) ) + if( memcmp( hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), + hb_cdxPageGetKeyVal( pPage->Child, pPage->Child->iKeys-1 ), + pPage->TagParent->uiLen ) != 0 || + hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ) != + hb_cdxPageGetKeyRec( pPage->Child, pPage->Child->iKeys-1 ) ) { printf("\r\nkeyLen=%d", pPage->TagParent->uiLen); printf("\r\nparent=%lx, iKey=%d, rec=%ld", pPage->Page, pPage->iCurKey, hb_cdxPageGetKeyRec( pPage, pPage->iCurKey )); @@ -3898,40 +3979,40 @@ static int hb_cdxPageSeekKey( LPCDXPAGE pPage, LPCDXKEY pKey, ULONG ulKeyRec, BO hb_cdxErrInternal("hb_cdxPageSeekKey: wrong parent key."); } #endif - k = hb_cdxPageSeekKey( pPage->Child, pKey, ulKeyRec, fExact ); + k = hb_cdxPageSeekKey( pPage->Child, pKey, ulKeyRec ); } - else if ( l != n || ulKeyRec == CDX_MAX_REC_NUM ) + else if( l != n || ulKeyRec == CDX_MAX_REC_NUM ) { k = hb_cdxValCompare( pPage->TagParent, pKey->val, pKey->len, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), - (BYTE) pPage->TagParent->uiLen, fExact ); - if ( k == 0 && ulKeyRec != CDX_MAX_REC_NUM && - ulKeyRec != CDX_IGNORE_REC_NUM ) + (BYTE) pPage->TagParent->uiLen, pKey->mode ); + if( k == 0 && ulKeyRec != CDX_MAX_REC_NUM && + ulKeyRec != CDX_IGNORE_REC_NUM ) { ULONG ulRec = hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ); - if ( ulKeyRec > ulRec ) + if( ulKeyRec > ulRec ) k = 1; - else if ( ulKeyRec < ulRec ) + else if( ulKeyRec < ulRec ) k = -1; } } - if ( ulKeyRec == CDX_MAX_REC_NUM ) + if( ulKeyRec == CDX_MAX_REC_NUM ) { - if ( pPage->iCurKey > 0 && k < 0 ) + if( pPage->iCurKey > 0 && k < 0 ) { pPage->iCurKey--; - if ( !fLeaf ) + if( !fLeaf ) { hb_cdxPageGetChild( pPage ); - k = hb_cdxPageSeekKey( pPage->Child, pKey, ulKeyRec, fExact ); + k = hb_cdxPageSeekKey( pPage->Child, pKey, ulKeyRec ); } else k = hb_cdxValCompare( pPage->TagParent, pKey->val, pKey->len, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), - (BYTE) pPage->TagParent->uiLen, fExact ); + (BYTE) pPage->TagParent->uiLen, pKey->mode ); } } - else if ( k > 0 && fLeaf ) + else if( k > 0 && fLeaf ) pPage->iCurKey++; return k; } @@ -3943,7 +4024,7 @@ static BOOL hb_cdxCheckRecordScope( CDXAREAP pArea, ULONG ulRec ) { LONG lRecNo = ( LONG ) ulRec; - if ( SELF_COUNTSCOPE( ( AREAP ) pArea, NULL, &lRecNo ) == HB_SUCCESS && lRecNo == 0 ) + if( SELF_COUNTSCOPE( ( AREAP ) pArea, NULL, &lRecNo ) == HB_SUCCESS && lRecNo == 0 ) { return FALSE; } @@ -3958,9 +4039,9 @@ static BOOL hb_cdxCheckRecordFilter( CDXAREAP pArea, ULONG ulRecNo ) BOOL lResult = FALSE; BOOL fDeleted = hb_setGetDeleted(); - if ( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) + if( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) { - if ( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, ulRecNo ) ) + if( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, ulRecNo ) ) { if( pArea->ulRecNo != ulRecNo || pArea->lpdbPendingRel ) SELF_GOTO( ( AREAP ) pArea, ulRecNo ); @@ -3972,12 +4053,12 @@ static BOOL hb_cdxCheckRecordFilter( CDXAREAP pArea, ULONG ulRecNo ) { PHB_ITEM pResult = hb_vmEvalBlock( pArea->dbfi.itmCobExpr ); lResult = HB_IS_LOGICAL( pResult ) && !hb_itemGetL( pResult ); - if ( lResult ) + if( lResult ) { LPCDXTAG pTag; BM_ClrBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, ulRecNo ); pTag = hb_cdxGetActiveTag( pArea ); - if ( pTag && CURKEY_LOGCNT(pTag) ) + if( pTag && CURKEY_LOGCNT(pTag) ) CURKEY_SETLOGCNT( pTag, pTag->logKeyCount - 1 ) } } @@ -3985,7 +4066,7 @@ static BOOL hb_cdxCheckRecordFilter( CDXAREAP pArea, ULONG ulRecNo ) else lResult = TRUE; } - else if ( pArea->dbfi.itmCobExpr || fDeleted ) + else if( pArea->dbfi.itmCobExpr || fDeleted ) { if( pArea->ulRecNo != ulRecNo || pArea->lpdbPendingRel ) SELF_GOTO( ( AREAP ) pArea, ulRecNo ); @@ -4007,13 +4088,13 @@ static BOOL hb_cdxCheckRecordFilter( CDXAREAP pArea, ULONG ulRecNo ) */ static BOOL hb_cdxPageReadTopKey( LPCDXPAGE pPage ) { - while ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 && pPage->iKeys > 0 ) + while( ( pPage->PageType & CDX_NODE_LEAF ) == 0 && pPage->iKeys > 0 ) { pPage->iCurKey = 0; hb_cdxPageGetChild( pPage ); pPage = pPage->Child; } - if ( pPage->iKeys == 0 ) + if( pPage->iKeys == 0 ) return FALSE; pPage->iCurKey = 0; @@ -4026,13 +4107,13 @@ static BOOL hb_cdxPageReadTopKey( LPCDXPAGE pPage ) */ static BOOL hb_cdxPageReadBottomKey( LPCDXPAGE pPage ) { - while ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 && pPage->iKeys > 0 ) + while( ( pPage->PageType & CDX_NODE_LEAF ) == 0 && pPage->iKeys > 0 ) { pPage->iCurKey = pPage->iKeys - 1; hb_cdxPageGetChild( pPage ); pPage = pPage->Child; } - if ( pPage->iKeys == 0 ) + if( pPage->iKeys == 0 ) return FALSE; pPage->iCurKey = pPage->iKeys - 1; @@ -4047,7 +4128,7 @@ static BOOL hb_cdxPageReadPrevKey( LPCDXPAGE pPage ) { LPCDXPAGE pOwnerPage = NULL; - while ( pPage->Child ) + while( pPage->Child ) { pOwnerPage = pPage; pPage = pPage->Child; @@ -4056,12 +4137,12 @@ static BOOL hb_cdxPageReadPrevKey( LPCDXPAGE pPage ) do { pPage->iCurKey--; - while ( pPage->iCurKey < 0 ) + while( pPage->iCurKey < 0 ) { - if ( pPage->Left == CDX_DUMMYNODE || !pOwnerPage ) + if( pPage->Left == CDX_DUMMYNODE || !pOwnerPage ) { pPage->iCurKey = 0; - if ( pPage->iKeys > 0 ) + if( pPage->iKeys > 0 ) hb_cdxSetCurKey( pPage ); return FALSE; } @@ -4093,7 +4174,7 @@ static BOOL hb_cdxPageReadNextKey( LPCDXPAGE pPage ) { LPCDXPAGE pOwnerPage = NULL; - while ( pPage->Child ) + while( pPage->Child ) { pOwnerPage = pPage; pPage = pPage->Child; @@ -4102,9 +4183,9 @@ static BOOL hb_cdxPageReadNextKey( LPCDXPAGE pPage ) do { pPage->iCurKey++; - while ( pPage->iCurKey >= pPage->iKeys ) + while( pPage->iCurKey >= pPage->iKeys ) { - if ( pPage->Right == CDX_DUMMYNODE || !pOwnerPage ) + if( pPage->Right == CDX_DUMMYNODE || !pOwnerPage ) { pPage->iCurKey = pPage->iKeys; return FALSE; @@ -4137,21 +4218,21 @@ static BOOL hb_cdxPageReadPrevUniqKey( LPCDXPAGE pPage ) { LPCDXPAGE pOwnerPage = NULL; - while ( pPage->Child ) + while( pPage->Child ) { pOwnerPage = pPage; pPage = pPage->Child; } - while ( pPage->iCurKey < 0 || memcmp( pPage->TagParent->CurKey->val, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ) == 0 ) + while( pPage->iCurKey < 0 || memcmp( pPage->TagParent->CurKey->val, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ) == 0 ) { - if ( pPage->iCurKey > 0 ) + if( pPage->iCurKey > 0 ) pPage->iCurKey--; else { - if ( pPage->Left == CDX_DUMMYNODE || !pOwnerPage ) + if( pPage->Left == CDX_DUMMYNODE || !pOwnerPage ) { pPage->iCurKey = 0; - if ( pPage->iKeys > 0 ) + if( pPage->iKeys > 0 ) hb_cdxSetCurKey( pPage ); return FALSE; } @@ -4174,7 +4255,7 @@ static BOOL hb_cdxPageReadNextUniqKey( LPCDXPAGE pPage ) LPCDXPAGE pOwnerPage = NULL; /* BYTE pbVal[CDX_MAXKEY]; */ - while ( pPage->Child ) + while( pPage->Child ) { pOwnerPage = pPage; pPage = pPage->Child; @@ -4182,18 +4263,18 @@ static BOOL hb_cdxPageReadNextUniqKey( LPCDXPAGE pPage ) /* memcpy( pbVal, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ); pPage->iCurKey++; - while ( pPage->iCurKey >= pPage->iKeys || memcmp( pbVal, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ) == 0 ) + while( pPage->iCurKey >= pPage->iKeys || memcmp( pbVal, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ) == 0 ) */ - while ( pPage->iCurKey >= pPage->iKeys || memcmp( pPage->TagParent->CurKey->val, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ) == 0 ) + while( pPage->iCurKey >= pPage->iKeys || memcmp( pPage->TagParent->CurKey->val, hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ), pPage->TagParent->uiLen ) == 0 ) { - if ( pPage->iCurKey < pPage->iKeys - 1 ) + if( pPage->iCurKey < pPage->iKeys - 1 ) pPage->iCurKey++; else { - if ( pPage->Right == CDX_DUMMYNODE || !pOwnerPage ) + if( pPage->Right == CDX_DUMMYNODE || !pOwnerPage ) { pPage->iCurKey = pPage->iKeys - 1; - if ( pPage->iKeys > 0 ) + if( pPage->iKeys > 0 ) hb_cdxSetCurKey( pPage ); return FALSE; } @@ -4218,7 +4299,7 @@ static void hb_cdxTagKeyRead( LPCDXTAG pTag, BYTE bTypRead ) pTag->fRePos = FALSE; hb_cdxTagOpen( pTag ); - if ( pTag->UsrUnique ) + if( pTag->UsrUnique ) { switch( bTypRead ) { @@ -4233,7 +4314,7 @@ static void hb_cdxTagKeyRead( LPCDXTAG pTag, BYTE bTypRead ) break; } } - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) { fBof = pTag->TagBOF; fEof = pTag->TagEOF; @@ -4280,43 +4361,43 @@ static void hb_cdxTagKeyRead( LPCDXTAG pTag, BYTE bTypRead ) break; case PREV_RECORD: - if ( !fBof ) + if( !fBof ) fBof = !hb_cdxPageReadPrevKey( pTag->RootPage ); break; case NEXT_RECORD: - if ( !fEof ) + if( !fEof ) fEof = !hb_cdxPageReadNextKey( pTag->RootPage ); break; case PRVU_RECORD: - if ( !fBof ) + if( !fBof ) fBof = !hb_cdxPageReadPrevUniqKey( pTag->RootPage ); break; case NXTU_RECORD: - if ( !fEof ) + if( !fEof ) fEof = !hb_cdxPageReadNextUniqKey( pTag->RootPage ); break; } - if ( fEof ) + if( fEof ) pTag->CurKey->rec = 0; - else if ( fAfter && !fBof ) + else if( fAfter && !fBof ) { - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) { - if ( hb_cdxPageReadPrevUniqKey( pTag->RootPage ) ) + if( hb_cdxPageReadPrevUniqKey( pTag->RootPage ) ) hb_cdxPageReadNextKey( pTag->RootPage ); } else { - if ( hb_cdxPageReadNextUniqKey( pTag->RootPage ) ) + if( hb_cdxPageReadNextUniqKey( pTag->RootPage ) ) hb_cdxPageReadPrevKey( pTag->RootPage ); } } - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) { pTag->TagBOF = fBof; pTag->TagEOF = fEof; @@ -4340,11 +4421,11 @@ static ULONG hb_cdxTagKeyFind( LPCDXTAG pTag, LPCDXKEY pKey ) hb_cdxTagOpen( pTag ); pTag->TagBOF = pTag->TagEOF = FALSE; - K = hb_cdxPageSeekKey( pTag->RootPage, pKey, ulKeyRec, FALSE ); - if ( ulKeyRec == CDX_MAX_REC_NUM ) + K = hb_cdxPageSeekKey( pTag->RootPage, pKey, ulKeyRec ); + if( ulKeyRec == CDX_MAX_REC_NUM ) K = - K; - if ( K > 0 ) + if( K > 0 ) { pTag->CurKey->rec = 0; pTag->TagEOF = TRUE; @@ -4352,7 +4433,7 @@ static ULONG hb_cdxTagKeyFind( LPCDXTAG pTag, LPCDXKEY pKey ) else { hb_cdxSetCurKey( pTag->RootPage ); - if ( K == 0 ) + if( K == 0 ) return pTag->CurKey->rec; } return 0; @@ -4365,9 +4446,8 @@ static BOOL hb_cdxTagKeyAdd( LPCDXTAG pTag, LPCDXKEY pKey ) { hb_cdxTagOpen( pTag ); if( hb_cdxPageSeekKey( pTag->RootPage, pKey, - pTag->UniqueKey ? CDX_IGNORE_REC_NUM : pKey->rec, - TRUE ) != 0 || ( pTag->Custom && pTag->MultiKey && - !pTag->UniqueKey ) ) + pTag->UniqueKey ? CDX_IGNORE_REC_NUM : pKey->rec ) != 0 || + ( pTag->Custom && pTag->MultiKey && !pTag->UniqueKey ) ) { hb_cdxPageKeyInsert( pTag->RootPage, pKey ); pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS | @@ -4385,7 +4465,7 @@ static BOOL hb_cdxTagKeyAdd( LPCDXTAG pTag, LPCDXKEY pKey ) */ static BOOL hb_cdxTagKeyDel( LPCDXTAG pTag, LPCDXKEY pKey ) { - if ( hb_cdxTagKeyFind( pTag, pKey ) != 0 ) + if( hb_cdxTagKeyFind( pTag, pKey ) != 0 ) { hb_cdxPageKeyRemove( pTag->RootPage ); pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS | @@ -4404,21 +4484,21 @@ static void hb_cdxTagGoTop( LPCDXTAG pTag ) LPCDXKEY pKey = pTag->UsrAscend ? pTag->topScopeKey : pTag->bottomScopeKey; ULONG ulPos = 1; - if ( pKey ) + if( pKey ) hb_cdxTagKeyFind( pTag, pKey ); else hb_cdxTagKeyRead( pTag, TOP_RECORD ); - do + for( ; ; ) { - if ( pTag->CurKey->rec == 0 || pTag->TagEOF || ! hb_cdxBottomScope( pTag ) ) + if( pTag->CurKey->rec == 0 || pTag->TagEOF || ! hb_cdxBottomScope( pTag ) ) { pTag->TagBOF = pTag->TagEOF = TRUE; pTag->CurKey->rec = 0; break; } - else if ( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || - hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) + else if( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || + hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) { pTag->rawKeyPos = ulPos; CURKEY_SETRAWPOS( pTag ); @@ -4427,7 +4507,6 @@ static void hb_cdxTagGoTop( LPCDXTAG pTag ) hb_cdxTagKeyRead( pTag, NEXT_RECORD ); ulPos++; } - while ( TRUE ); } /* @@ -4438,23 +4517,23 @@ static void hb_cdxTagGoBottom( LPCDXTAG pTag ) LPCDXKEY pKey = pTag->UsrAscend ? pTag->bottomScopeKey : pTag->topScopeKey; ULONG ulPos = 0; - if ( pKey ) + if( pKey ) hb_cdxTagKeyFind( pTag, pKey ); else hb_cdxTagKeyRead( pTag, BTTM_RECORD ); - do + for( ; ; ) { - if ( pTag->CurKey->rec == 0 || pTag->TagBOF || ! hb_cdxTopScope( pTag ) ) + if( pTag->CurKey->rec == 0 || pTag->TagBOF || ! hb_cdxTopScope( pTag ) ) { pTag->TagBOF = pTag->TagEOF = TRUE; pTag->CurKey->rec = 0; break; } - else if ( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || - hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) + else if( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || + hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) { - if ( CURKEY_RAWCNT( pTag ) ) + if( CURKEY_RAWCNT( pTag ) ) { pTag->rawKeyPos = pTag->rawKeyCount - ulPos; CURKEY_SETRAWPOS( pTag ); @@ -4464,7 +4543,6 @@ static void hb_cdxTagGoBottom( LPCDXTAG pTag ) hb_cdxTagKeyRead( pTag, PREV_RECORD ); ulPos++; } - while ( TRUE ); } /* @@ -4475,9 +4553,9 @@ static void hb_cdxTagSkipNext( LPCDXTAG pTag ) BOOL fPos = CURKEY_RAWPOS( pTag ), fEof = FALSE; ULONG ulSkip = 1; - if ( pTag->CurKey->rec != 0 ) + if( pTag->CurKey->rec != 0 ) { - if ( !hb_cdxTopScope( pTag ) ) + if( !hb_cdxTopScope( pTag ) ) { ulSkip = 0; hb_cdxTagGoTop( pTag ); @@ -4486,24 +4564,24 @@ static void hb_cdxTagSkipNext( LPCDXTAG pTag ) hb_cdxTagKeyRead( pTag, NEXT_RECORD ); } - while ( !fEof ) + while( !fEof ) { - if ( pTag->TagEOF || pTag->CurKey->rec == 0 || - !hb_cdxBottomScope( pTag ) || !hb_cdxTopScope( pTag ) ) + if( pTag->TagEOF || pTag->CurKey->rec == 0 || + !hb_cdxBottomScope( pTag ) || !hb_cdxTopScope( pTag ) ) fEof = TRUE; - else if ( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || - hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) + else if( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || + hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) break; hb_cdxTagKeyRead( pTag, NEXT_RECORD ); ulSkip++; } - if ( fEof ) + if( fEof ) { pTag->CurKey->rec = 0; pTag->TagEOF = TRUE; } - else if ( fPos ) + else if( fPos ) { pTag->rawKeyPos += ulSkip; CURKEY_SETRAWPOS( pTag ); @@ -4518,7 +4596,7 @@ static void hb_cdxTagSkipPrev( LPCDXTAG pTag ) BOOL fPos = CURKEY_RAWPOS( pTag ), fBof = FALSE; ULONG ulSkip = 1; - if ( pTag->CurKey->rec == 0 ) + if( pTag->CurKey->rec == 0 ) { ulSkip = 0; hb_cdxTagGoBottom( pTag ); @@ -4526,25 +4604,25 @@ static void hb_cdxTagSkipPrev( LPCDXTAG pTag ) else hb_cdxTagKeyRead( pTag, PREV_RECORD ); - while ( !fBof ) + while( !fBof ) { - if ( pTag->TagBOF || pTag->CurKey->rec == 0 || - !hb_cdxBottomScope( pTag ) || !hb_cdxTopScope( pTag ) ) + if( pTag->TagBOF || pTag->CurKey->rec == 0 || + !hb_cdxBottomScope( pTag ) || !hb_cdxTopScope( pTag ) ) fBof = TRUE; - else if ( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || - hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) + else if( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) != 0 || + hb_cdxCheckRecordScope( pTag->pIndex->pArea, pTag->CurKey->rec ) ) break; hb_cdxTagKeyRead( pTag, PREV_RECORD ); ulSkip++; } - if ( fBof ) + if( fBof ) { hb_cdxTagGoTop( pTag ); pTag->TagBOF = TRUE; } - else if ( fPos ) + else if( fPos ) { pTag->rawKeyPos -= ulSkip; CURKEY_SETRAWPOS( pTag ); @@ -4560,13 +4638,13 @@ static void hb_cdxReorderTagList( LPCDXTAG * TagListPtr ) LPCDXTAG *pTagPtr, pTagTmp; BOOL fRepeat = TRUE; - while ( fRepeat ) + while( fRepeat ) { fRepeat = FALSE; pTagPtr = TagListPtr; - while ( *pTagPtr && (*pTagPtr)->pNext ) + while( *pTagPtr && (*pTagPtr)->pNext ) { - if ( (*pTagPtr)->TagBlock > (*pTagPtr)->pNext->TagBlock ) + if( (*pTagPtr)->TagBlock > (*pTagPtr)->pNext->TagBlock ) { pTagTmp = (*pTagPtr); (*pTagPtr) = (*pTagPtr)->pNext; @@ -4587,38 +4665,39 @@ static LPCDXTAG hb_cdxIndexCreateTag( BOOL fStruct, LPCDXINDEX pIndex, char * KeyExp, PHB_ITEM pKeyItem, BYTE bType, USHORT uiLen, char * ForExp, PHB_ITEM pForItem, - BOOL fAscnd, BOOL fUniq, BOOL fCustom, - BOOL fReindex ) + BOOL fAscnd, BOOL fUniq, BOOL fNoCase, + BOOL fCustom, BOOL fReindex ) { LPCDXTAG pTag; pTag = hb_cdxTagNew( pIndex, szTagName, CDX_DUMMYNODE ); - if ( fStruct ) + if( fStruct ) pTag->OptFlags |= CDX_TYPE_STRUCTURE; - if ( bType == 'C' ) + if( bType == 'C' ) hb_cdxMakeSortTab( pTag->pIndex->pArea ); - if ( KeyExp != NULL ) + if( KeyExp != NULL ) { pTag->KeyExpr = hb_strduptrim( KeyExp ); pTag->nField = hb_rddFieldExpIndex( ( AREAP ) pTag->pIndex->pArea, pTag->KeyExpr ); } pTag->pKeyItem = pKeyItem; - if ( ForExp != NULL ) + if( ForExp != NULL ) pTag->ForExpr = hb_strduptrim( ForExp ); pTag->pForItem = pForItem; pTag->AscendKey = pTag->UsrAscend = fAscnd; pTag->UniqueKey = fUniq; pTag->UsrUnique = FALSE; - pTag->Custom = fCustom; - pTag->Template = pTag->MultiKey = pTag->Custom; - pTag->Partial = pTag->ChgOnly = FALSE; + pTag->IgnoreCase = fNoCase && bType == 'C'; + pTag->Custom = fCustom; + pTag->Template = pTag->MultiKey = pTag->Custom; + pTag->Partial = pTag->ChgOnly = FALSE; pTag->uiType = bType; - pTag->bTrail = ( pTag->uiType == 'C' ) ? ' ' : '\0'; + pTag->bTrail = ( bType == 'C' ) ? ' ' : '\0'; pTag->uiLen = uiLen; pTag->MaxKeys = CDX_INT_FREESPACE / ( uiLen + 8 ); pTag->TagChanged = TRUE; @@ -4635,7 +4714,7 @@ static void hb_cdxIndexCreateStruct( LPCDXINDEX pIndex, char * szTagName ) /* here we can change default tag name */ pIndex->pCompound = hb_cdxIndexCreateTag( TRUE, pIndex, szTagName, NULL, NULL, 'C', CDX_MAXTAGNAMELEN, NULL, NULL, - TRUE, FALSE, FALSE, FALSE ); + TRUE, FALSE, FALSE, FALSE, FALSE ); } /* @@ -4643,16 +4722,16 @@ static void hb_cdxIndexCreateStruct( LPCDXINDEX pIndex, char * szTagName ) */ static void hb_cdxIndexFreePages( LPCDXPAGE pPage ) { - if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) + if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) { LPCDXPAGE pChildPage; int iKey; - for ( iKey = 0; iKey < pPage->iKeys; iKey++ ) + for( iKey = 0; iKey < pPage->iKeys; iKey++ ) { pChildPage = hb_cdxPageNew( pPage->TagParent, NULL, hb_cdxPageGetKeyPage( pPage, iKey ) ); - if ( pChildPage ) + if( pChildPage ) hb_cdxIndexFreePages( pChildPage ); } } @@ -4667,26 +4746,26 @@ static void hb_cdxIndexDelTag( LPCDXINDEX pIndex, char * szTagName ) { LPCDXTAG *pTagPtr = &pIndex->TagList; - while ( *pTagPtr && hb_stricmp( (*pTagPtr)->szName, szTagName ) != 0 ) + while( *pTagPtr && hb_stricmp( (*pTagPtr)->szName, szTagName ) != 0 ) pTagPtr = &(*pTagPtr)->pNext; - if ( *pTagPtr ) + if( *pTagPtr ) { LPCDXTAG pTag = *pTagPtr; LPCDXKEY pKey = hb_cdxKeyPutC( NULL, szTagName, pIndex->pCompound->uiLen, pTag->TagBlock ); - if ( hb_cdxTagKeyDel( pIndex->pCompound, pKey ) ) + if( hb_cdxTagKeyDel( pIndex->pCompound, pKey ) ) { - if ( pTag != pIndex->TagList || pTag->pNext != NULL ) + if( pTag != pIndex->TagList || pTag->pNext != NULL ) { LPCDXPAGE pPage; hb_cdxTagOpen( pTag ); pPage = pTag->RootPage; hb_cdxTagClose( pTag ); - if ( ! pIndex->fShared ) + if( ! pIndex->fShared ) { - if ( pPage ) + if( pPage ) hb_cdxIndexFreePages( pPage ); hb_cdxIndexPutAvailPage( pIndex, pTag->TagBlock, TRUE ); } @@ -4706,8 +4785,8 @@ static LPCDXTAG hb_cdxIndexAddTag( LPCDXINDEX pIndex, char * szTagName, char * szKeyExp, PHB_ITEM pKeyItem, BYTE bType, USHORT uiLen, char * szForExp, PHB_ITEM pForItem, - BOOL fAscend, BOOL fUnique, BOOL fCustom, - BOOL fReindex ) + BOOL fAscend, BOOL fUnique, BOOL fNoCase, + BOOL fCustom, BOOL fReindex ) { LPCDXTAG pTag, *pTagPtr; LPCDXKEY pKey; @@ -4720,9 +4799,9 @@ static LPCDXTAG hb_cdxIndexAddTag( LPCDXINDEX pIndex, char * szTagName, /* Create new tag an add to tag list */ pTag = hb_cdxIndexCreateTag( FALSE, pIndex, szTagName, szKeyExp, pKeyItem, bType, uiLen, szForExp, pForItem, - fAscend, fUnique, fCustom, fReindex ); + fAscend, fUnique, fNoCase, fCustom, fReindex ); pTagPtr = &pIndex->TagList; - while ( *pTagPtr ) + while( *pTagPtr ) pTagPtr = &(*pTagPtr)->pNext; *pTagPtr = pTag; pKey = hb_cdxKeyPutC( NULL, szTagName, pIndex->pCompound->uiLen, pTag->TagBlock ); @@ -4753,19 +4832,19 @@ static void hb_cdxIndexReindex( LPCDXINDEX pIndex ) pIndex->fChanged = TRUE; /* Rebuild the compound (master) tag */ - if ( pCompound ) + if( pCompound ) { hb_cdxIndexCreateStruct( pIndex, pCompound->szName ); hb_cdxTagFree( pCompound ); } /* Rebuild each tag */ - while ( pTagList ) + while( pTagList ) { pTag = pTagList; hb_cdxIndexAddTag( pIndex, pTag->szName, pTag->KeyExpr, pTag->pKeyItem, - (BYTE) pTag->uiType, pTag->uiLen, pTag->ForExpr, pTag->pForItem, - pTag->AscendKey, pTag->UniqueKey, pTag->Custom, TRUE ); + ( BYTE ) pTag->uiType, pTag->uiLen, pTag->ForExpr, pTag->pForItem, + pTag->AscendKey, pTag->UniqueKey, pTag->IgnoreCase, pTag->Custom, TRUE ); pTagList = pTag->pNext; pTag->pKeyItem = pTag->pForItem = NULL; hb_cdxTagFree( pTag ); @@ -4796,13 +4875,13 @@ static void hb_cdxIndexFreeTags( LPCDXINDEX pIndex ) LPCDXTAG pTag; /* Free Compound tag */ - if ( pIndex->pCompound != NULL ) + if( pIndex->pCompound != NULL ) { hb_cdxTagFree( pIndex->pCompound ); pIndex->pCompound = NULL; } - while ( pIndex->TagList ) + while( pIndex->TagList ) { pTag = pIndex->TagList; pIndex->TagList = pTag->pNext; @@ -4842,7 +4921,7 @@ static void hb_cdxIndexFree( LPCDXINDEX pIndex ) hb_errInternal( 9104, "hb_cdxIndexFree: index file still locked (*)", NULL, NULL ); #endif - if ( pIndex->szFileName != NULL ) + if( pIndex->szFileName != NULL ) hb_xfree( pIndex->szFileName ); if( pIndex->szRealName ) hb_xfree( pIndex->szRealName ); @@ -4866,17 +4945,17 @@ static BOOL hb_cdxIndexLoad( LPCDXINDEX pIndex, char * szBaseName ) pIndex->pCompound = hb_cdxTagNew( pIndex, szBaseName, 0L ); /* check if index is not corrupted */ - if ( pIndex->pCompound ) + if( pIndex->pCompound ) { fResult = TRUE; pIndex->pCompound->OptFlags = CDX_TYPE_COMPACT | CDX_TYPE_COMPOUND | CDX_TYPE_STRUCTURE; hb_cdxTagGoTop( pIndex->pCompound ); - while ( !pIndex->pCompound->TagEOF ) + while( !pIndex->pCompound->TagEOF ) { *pTagPtr = hb_cdxTagNew( pIndex, (char *) pIndex->pCompound->CurKey->val, pIndex->pCompound->CurKey->rec ); /* tag is corrupted - break tags loading */ - if ( *pTagPtr == NULL ) + if( *pTagPtr == NULL ) { fResult = FALSE; break; @@ -4889,7 +4968,7 @@ static BOOL hb_cdxIndexLoad( LPCDXINDEX pIndex, char * szBaseName ) hb_cdxIndexUnLockRead( pIndex ); hb_cdxReorderTagList( &TagList ); pTagPtr = &pIndex->TagList; - while ( *pTagPtr != NULL ) + while( *pTagPtr != NULL ) pTagPtr = &(*pTagPtr)->pNext; (*pTagPtr) = TagList; @@ -4971,11 +5050,11 @@ static void hb_cdxOrdListClear( CDXAREAP pArea, BOOL fAll, LPCDXINDEX pKeepInd ) { HB_TRACE(HB_TR_DEBUG, ("hb_cdxOrdListClear(%p, %d)", pArea, (int) fAll)); - if ( pArea->lpIndexes ) + if( pArea->lpIndexes ) { LPCDXINDEX pIndex, * pIndexPtr; - if ( !fAll ) + if( !fAll ) { /* TODO: we have to control this on open */ PHB_FNAME pFileNameDbf, pFileNameCdx; @@ -5001,10 +5080,10 @@ static void hb_cdxOrdListClear( CDXAREAP pArea, BOOL fAll, LPCDXINDEX pKeepInd ) hb_xfree( pFileNameCdx ); } pIndexPtr = fAll ? &pArea->lpIndexes : &pArea->lpIndexes->pNext; - while ( *pIndexPtr ) + while( *pIndexPtr ) { pIndex = *pIndexPtr; - if ( pKeepInd == pIndex ) + if( pKeepInd == pIndex ) pIndexPtr = &pIndex->pNext; else { @@ -5032,23 +5111,23 @@ static LPCDXINDEX hb_cdxFindBag( CDXAREAP pArea, char * szBagName ) hb_strUpper( szBaseName, strlen(szBaseName) ); pIndex = pArea->lpIndexes; - while ( pIndex ) + while( pIndex ) { hb_xfree( pFileName ); pFileName = hb_fsFNameSplit( pIndex->szFileName ); - if ( !hb_stricmp( pFileName->szName ? pFileName->szName : "", szBaseName ) && - ( !szBasePath || - ( pFileName->szPath && !hb_stricmp( pFileName->szPath, szBasePath ) ) ) && - ( !szBaseExt || - ( pFileName->szExtension && !hb_stricmp( pFileName->szExtension, szBaseExt ) ) ) ) + if( !hb_stricmp( pFileName->szName ? pFileName->szName : "", szBaseName ) && + ( !szBasePath || + ( pFileName->szPath && !hb_stricmp( pFileName->szPath, szBasePath ) ) ) && + ( !szBaseExt || + ( pFileName->szExtension && !hb_stricmp( pFileName->szExtension, szBaseExt ) ) ) ) break; pIndex = pIndex->pNext; } hb_xfree( pFileName ); hb_xfree( szBaseName ); - if ( szBasePath ) + if( szBasePath ) hb_xfree( szBasePath ); - if ( szBaseExt ) + if( szBaseExt ) hb_xfree( szBaseExt ); return pIndex; } @@ -5061,12 +5140,12 @@ static LPCDXTAG hb_cdxGetTagByNumber( CDXAREAP pArea, USHORT uiTag ) LPCDXTAG pTag = NULL; LPCDXINDEX pIndex = pArea->lpIndexes; - while ( uiTag && pIndex ) + while( uiTag && pIndex ) { pTag = pIndex->TagList; - while ( uiTag && pTag ) + while( uiTag && pTag ) { - if ( --uiTag ) + if( --uiTag ) pTag = pTag->pNext; } pIndex = pIndex->pNext; @@ -5083,21 +5162,21 @@ static USHORT hb_cdxGetTagNumber( CDXAREAP pArea, LPCDXTAG pFindTag ) LPCDXTAG pTag = NULL; LPCDXINDEX pIndex = pArea->lpIndexes; - if ( pFindTag ) + if( pFindTag ) { - while ( pIndex && ( pTag != pFindTag ) ) + while( pIndex && ( pTag != pFindTag ) ) { pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { uiTag++; - if ( pTag == pFindTag ) + if( pTag == pFindTag ) break; pTag = pTag->pNext; } pIndex = pIndex->pNext; } - if ( !pTag ) + if( !pTag ) uiTag = 0; } return uiTag; @@ -5153,14 +5232,14 @@ static LPCDXTAG hb_cdxFindTag( CDXAREAP pArea, PHB_ITEM pTagItem, while( pTag ) { iTag++; - if ( ( iFind != 0 ? iTag == iFind : !hb_stricmp( pTag->szName, szTag ) ) ) + if( ( iFind != 0 ? iTag == iFind : !hb_stricmp( pTag->szName, szTag ) ) ) break; pTag = pTag->pNext; } - if ( pTag || fBag ) + if( pTag || fBag ) break; pIndex = pIndex->pNext; - } while ( pIndex ); + } while( pIndex ); } if( puiTag ) @@ -5183,10 +5262,10 @@ static LPCDXTAG hb_cdxGetActiveTag( CDXAREAP pArea ) { LPCDXTAG pTag; - if ( !pArea->uiTag ) + if( !pArea->uiTag ) return NULL; pTag = hb_cdxGetTagByNumber( pArea, pArea->uiTag ); - if ( !pTag ) + if( !pTag ) pArea->uiTag = 0; return pTag; } @@ -5199,44 +5278,44 @@ static BOOL hb_cdxCurKeyRefresh( CDXAREAP pArea, LPCDXTAG pTag ) if( pArea->lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); - if ( !pArea->fPositioned ) + if( !pArea->fPositioned ) { pTag->TagEOF = TRUE; pTag->fRePos = FALSE; pTag->CurKey->rec = 0; return FALSE; } - else if ( pTag->fRePos || pTag->CurKey->rec != pArea->ulRecNo ) + else if( pTag->fRePos || pTag->CurKey->rec != pArea->ulRecNo ) { BYTE buf[CDX_MAXKEY]; BOOL fBuf = FALSE; LPCDXKEY pKey = NULL; /* Try to find previous if it's key for the same record */ - if ( pTag->CurKey->rec == pArea->ulRecNo ) + if( pTag->CurKey->rec == pArea->ulRecNo ) { fBuf = TRUE; memcpy( buf, pTag->CurKey->val, pTag->CurKey->len ); pKey = hb_cdxKeyCopy( pKey, pTag->CurKey ); hb_cdxTagKeyFind( pTag, pKey ); } - if ( pTag->CurKey->rec != pArea->ulRecNo ) + if( pTag->CurKey->rec != pArea->ulRecNo ) { BOOL fValidBuf = pArea->fValidBuffer; /* not found, create new key from DBF and if differs seek again */ pKey = hb_cdxKeyEval( pKey, pTag ); - if ( !fBuf || memcmp( buf, pKey->val, pKey->len ) != 0 ) + if( !fBuf || memcmp( buf, pKey->val, pKey->len ) != 0 ) { hb_cdxTagKeyFind( pTag, pKey ); } /* not found, if key was generated from DBF buffer then force to * update it, create the new key and if differs seek again */ - if ( pTag->CurKey->rec != pArea->ulRecNo && fValidBuf ) + if( pTag->CurKey->rec != pArea->ulRecNo && fValidBuf ) { SELF_GOTO( ( AREAP ) pArea, pArea->ulRecNo ); memcpy( buf, pKey->val, pKey->len ); pKey = hb_cdxKeyEval( pKey, pTag ); - if ( memcmp( buf, pKey->val, pKey->len ) != 0 ) + if( memcmp( buf, pKey->val, pKey->len ) != 0 ) hb_cdxTagKeyFind( pTag, pKey ); } } @@ -5255,10 +5334,10 @@ static HB_ERRCODE hb_cdxDBOISkipUnique( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFor HB_TRACE(HB_TR_DEBUG, ("hb_cdxDBOISkipUnique(%p, %p, %i)", pArea, pTag, fForward)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( ! pTag ) + if( ! pTag ) return SELF_SKIP( ( AREAP ) pArea, fForward ? 1 : -1 ); if( pArea->lpdbPendingRel ) @@ -5266,9 +5345,9 @@ static HB_ERRCODE hb_cdxDBOISkipUnique( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFor pArea->fTop = pArea->fBottom = FALSE; - if ( !pArea->fPositioned ) + if( !pArea->fPositioned ) { - if ( fForward ) + if( fForward ) retval = SELF_GOTO( ( AREAP ) pArea, 0 ); else retval = SELF_GOBOTTOM( ( AREAP ) pArea ); @@ -5280,31 +5359,32 @@ static HB_ERRCODE hb_cdxDBOISkipUnique( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFor hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) { - if ( pTag->TagEOF || ( fForward ? !hb_cdxBottomScope( pTag ) : - !hb_cdxTopScope( pTag ) ) ) + if( pTag->TagEOF || ( fForward ? !hb_cdxBottomScope( pTag ) : + !hb_cdxTopScope( pTag ) ) ) fOut = TRUE; - else if ( ( fForward ? pTag->UsrAscend && hb_cdxTopScope( pTag ) : - !pTag->UsrAscend && hb_cdxBottomScope( pTag ) ) && + else if( ( fForward ? pTag->UsrAscend && hb_cdxTopScope( pTag ) : + !pTag->UsrAscend && hb_cdxBottomScope( pTag ) ) && pTag->CurKey->rec != 0 ) { pKey = hb_cdxKeyEval( pKey, pTag ); } } - if ( fForward ) + if( fForward ) { - if ( pArea->fPositioned && !pTag->TagEOF ) + if( pArea->fPositioned && !pTag->TagEOF ) { - if ( !pKey ) + if( !pKey ) { pKey = hb_cdxKeyCopy( NULL, pTag->CurKey ); hb_cdxTagSkipNext( pTag ); } - while ( !pTag->TagEOF ) + while( !pTag->TagEOF ) { - if ( hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, TRUE ) != 0 ) + if( hb_cdxValCompare( pTag, pKey->val, pKey->len, + pTag->CurKey->val, pTag->CurKey->len, + CDX_CMP_EXACT ) != 0 ) { SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); @@ -5318,17 +5398,18 @@ static HB_ERRCODE hb_cdxDBOISkipUnique( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFor } else { - if ( !fOut && !pTag->TagBOF ) + if( !fOut && !pTag->TagBOF ) { - if ( !pKey ) + if( !pKey ) { pKey = hb_cdxKeyCopy( NULL, pTag->CurKey ); hb_cdxTagSkipPrev( pTag ); } - while ( !pTag->TagBOF ) + while( !pTag->TagBOF ) { - if ( hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, TRUE ) != 0 ) + if( hb_cdxValCompare( pTag, pKey->val, pKey->len, + pTag->CurKey->val, pTag->CurKey->len, + CDX_CMP_EXACT ) != 0 ) { SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); @@ -5338,7 +5419,7 @@ static HB_ERRCODE hb_cdxDBOISkipUnique( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFor } } - if ( fOut || pTag->TagBOF ) + if( fOut || pTag->TagBOF ) { retval = SELF_GOTOP( ( AREAP ) pArea ); pArea->fBof = TRUE; @@ -5349,7 +5430,7 @@ static HB_ERRCODE hb_cdxDBOISkipUnique( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFor } } hb_cdxIndexUnLockRead( pTag->pIndex ); - if ( pKey ) + if( pKey ) hb_cdxKeyFree( pKey ); } /* Update Bof and Eof flags */ @@ -5388,26 +5469,26 @@ static BOOL hb_cdxDBOISkipEval( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) { - if ( !pTag->TagEOF && pTag->CurKey->rec != 0 && - ( fForward ? pTag->UsrAscend : !pTag->UsrAscend ) && - hb_cdxTopScope( pTag ) && hb_cdxBottomScope( pTag ) ) + if( !pTag->TagEOF && pTag->CurKey->rec != 0 && + ( fForward ? pTag->UsrAscend : !pTag->UsrAscend ) && + hb_cdxTopScope( pTag ) && hb_cdxBottomScope( pTag ) ) fFirst = FALSE; } - if ( fForward ) + if( fForward ) { - if ( fFirst ) + if( fFirst ) hb_cdxTagSkipNext( pTag ); - while ( !pTag->TagEOF ) + while( !pTag->TagEOF ) { - if ( SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ) == HB_FAILURE ) + if( SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ) == HB_FAILURE ) break; - if ( hb_cdxEvalSeekCond( pTag, pEval ) ) + if( hb_cdxEvalSeekCond( pTag, pEval ) ) { ULONG ulRecNo = pArea->ulRecNo; SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); - if ( pArea->ulRecNo == ulRecNo || hb_cdxEvalSeekCond( pTag, pEval ) ) + if( pArea->ulRecNo == ulRecNo || hb_cdxEvalSeekCond( pTag, pEval ) ) { fFound = TRUE; break; @@ -5415,22 +5496,22 @@ static BOOL hb_cdxDBOISkipEval( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, } hb_cdxTagSkipNext( pTag ); } - if ( !fFound ) + if( !fFound ) SELF_GOTO( ( AREAP ) pArea, 0 ); } else { - if ( fFirst ) + if( fFirst ) hb_cdxTagSkipPrev( pTag ); - while ( !pTag->TagBOF ) + while( !pTag->TagBOF ) { - if ( SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ) == HB_FAILURE ) + if( SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ) == HB_FAILURE ) break; - if ( hb_cdxEvalSeekCond( pTag, pEval ) ) + if( hb_cdxEvalSeekCond( pTag, pEval ) ) { ULONG ulRecNo = pArea->ulRecNo; SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); - if ( pArea->ulRecNo == ulRecNo || hb_cdxEvalSeekCond( pTag, pEval ) ) + if( pArea->ulRecNo == ulRecNo || hb_cdxEvalSeekCond( pTag, pEval ) ) { fFound = TRUE; break; @@ -5438,7 +5519,7 @@ static BOOL hb_cdxDBOISkipEval( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, } hb_cdxTagSkipPrev( pTag ); } - if ( !fFound ) + if( !fFound ) { SELF_GOTOP( ( AREAP ) pArea ); pArea->fBof = TRUE; @@ -5467,14 +5548,14 @@ static BOOL hb_cdxDBOISkipWild( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, HB_TRACE(HB_TR_DEBUG, ("hb_cdxDBOISkipWild(%p, %p, %i, %p)", pArea, pTag, fForward, pWildItm)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return FALSE; szPattern = hb_itemGetCPtr( pWildItm ); - if ( ! pTag || pTag->uiType != 'C' || !szPattern || !*szPattern ) + if( ! pTag || pTag->uiType != 'C' || !szPattern || !*szPattern ) { - if ( SELF_SKIP( ( AREAP ) pArea, fForward ? 1 : -1 ) == HB_FAILURE ) + if( SELF_SKIP( ( AREAP ) pArea, fForward ? 1 : -1 ) == HB_FAILURE ) return FALSE; return fForward ? pArea->fPositioned : !pArea->fBof; } @@ -5499,9 +5580,9 @@ static BOOL hb_cdxDBOISkipWild( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) { - if ( !pTag->TagEOF && pTag->CurKey->rec != 0 && + if( !pTag->TagEOF && pTag->CurKey->rec != 0 && ( fForward ? pTag->UsrAscend : !pTag->UsrAscend ) && hb_cdxTopScope( pTag ) && hb_cdxBottomScope( pTag ) ) fFirst = FALSE; @@ -5513,12 +5594,14 @@ static BOOL hb_cdxDBOISkipWild( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, if( iFixed && !pTag->TagEOF && pTag->CurKey->rec != 0 && hb_cdxValCompare( pTag, ( BYTE * ) szPattern, iFixed, - pTag->CurKey->val, iFixed, FALSE ) == -iStop ) + pTag->CurKey->val, iFixed, + CDX_CMP_PREFIX ) == -iStop ) { LPCDXKEY pKey; pKey = hb_cdxKeyPut( NULL, ( BYTE * ) szPattern, iFixed, pTag->UsrAscend ? CDX_IGNORE_REC_NUM : CDX_MAX_REC_NUM ); + pKey->mode = CDX_CMP_PREFIX; if( !hb_cdxTagKeyFind( pTag, pKey ) ) { if( fForward ) @@ -5530,27 +5613,28 @@ static BOOL hb_cdxDBOISkipWild( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, fFirst = FALSE; } - if ( fForward ) + if( fForward ) { - if ( fFirst ) + if( fFirst ) hb_cdxTagSkipNext( pTag ); - while ( !pTag->TagEOF ) + while( !pTag->TagEOF ) { - if ( hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) + if( hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) { ULONG ulRecNo = pTag->CurKey->rec; if( SELF_GOTO( ( AREAP ) pArea, ulRecNo ) != HB_SUCCESS ) break; SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); - if ( pArea->ulRecNo == ulRecNo || - hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) + if( pArea->ulRecNo == ulRecNo || + hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) { fFound = TRUE; break; } } if( iFixed && hb_cdxValCompare( pTag, ( BYTE * ) szPattern, iFixed, - pTag->CurKey->val, iFixed, FALSE ) == iStop ) + pTag->CurKey->val, iFixed, + CDX_CMP_PREFIX ) == iStop ) { break; } @@ -5561,31 +5645,32 @@ static BOOL hb_cdxDBOISkipWild( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, } else { - if ( fFirst ) + if( fFirst ) hb_cdxTagSkipPrev( pTag ); - while ( !pTag->TagBOF ) + while( !pTag->TagBOF ) { - if ( hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) + if( hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) { ULONG ulRecNo = pTag->CurKey->rec; if( SELF_GOTO( ( AREAP ) pArea, ulRecNo ) != HB_SUCCESS ) break; SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); - if ( pArea->ulRecNo == ulRecNo || - hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) + if( pArea->ulRecNo == ulRecNo || + hb_strMatchWild( (const char *) pTag->CurKey->val, szPattern ) ) { fFound = TRUE; break; } } if( iFixed && hb_cdxValCompare( pTag, ( BYTE * ) szPattern, iFixed, - pTag->CurKey->val, iFixed, FALSE ) == iStop ) + pTag->CurKey->val, iFixed, + CDX_CMP_PREFIX ) == iStop ) { break; } hb_cdxTagSkipPrev( pTag ); } - if ( !fFound ) + if( !fFound ) { SELF_GOTOP( ( AREAP ) pArea ); pArea->fBof = TRUE; @@ -5634,7 +5719,7 @@ static BOOL hb_cdxDBOISkipRegEx( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, HB_TRACE(HB_TR_DEBUG, ("hb_cdxDBOISkipRegEx(%p, %p, %i, %p)", pArea, pTag, fForward, pRegExItm)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return FALSE; if( !pTag || pTag->uiType != 'C' || ( pRegEx = hb_regexGet( pRegExItm, 0 ) ) == NULL ) @@ -5651,25 +5736,25 @@ static BOOL hb_cdxDBOISkipRegEx( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) { - if ( !pTag->TagEOF && pTag->CurKey->rec != 0 && - ( fForward ? pTag->UsrAscend : !pTag->UsrAscend ) && - hb_cdxTopScope( pTag ) && hb_cdxBottomScope( pTag ) ) + if( !pTag->TagEOF && pTag->CurKey->rec != 0 && + ( fForward ? pTag->UsrAscend : !pTag->UsrAscend ) && + hb_cdxTopScope( pTag ) && hb_cdxBottomScope( pTag ) ) fFirst = FALSE; } - if ( fForward ) + if( fForward ) { - if ( fFirst ) + if( fFirst ) hb_cdxTagSkipNext( pTag ); - while ( !pTag->TagEOF ) + while( !pTag->TagEOF ) { if( hb_cdxRegexMatch( pArea, pRegEx, pTag->CurKey ) ) { ULONG ulRecNo = pArea->ulRecNo; SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); - if ( pArea->ulRecNo == ulRecNo || - hb_cdxRegexMatch( pArea, pRegEx, pTag->CurKey ) ) + if( pArea->ulRecNo == ulRecNo || + hb_cdxRegexMatch( pArea, pRegEx, pTag->CurKey ) ) { fFound = TRUE; break; @@ -5681,16 +5766,16 @@ static BOOL hb_cdxDBOISkipRegEx( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, } else { - if ( fFirst ) + if( fFirst ) hb_cdxTagSkipPrev( pTag ); - while ( !pTag->TagBOF ) + while( !pTag->TagBOF ) { if( hb_cdxRegexMatch( pArea, pRegEx, pTag->CurKey ) ) { ULONG ulRecNo = pArea->ulRecNo; SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); - if ( pArea->ulRecNo == ulRecNo || - hb_cdxRegexMatch( pArea, pRegEx, pTag->CurKey ) ) + if( pArea->ulRecNo == ulRecNo || + hb_cdxRegexMatch( pArea, pRegEx, pTag->CurKey ) ) { fFound = TRUE; break; @@ -5698,7 +5783,7 @@ static BOOL hb_cdxDBOISkipRegEx( CDXAREAP pArea, LPCDXTAG pTag, BOOL fForward, } hb_cdxTagSkipPrev( pTag ); } - if ( fFound ) + if( fFound ) SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); else { @@ -5730,15 +5815,17 @@ static ULONG hb_cdxDBOIScopeEval( LPCDXTAG pTag, HB_EVALSCOPE_FUNC pFunc, void * pBtmScopeKey = pTag->bottomScopeKey; /* TODO: RT error when item type differ then Tag type */ - if ( !pItemLo || HB_IS_NIL( pItemLo ) ) + if( !pItemLo || HB_IS_NIL( pItemLo ) ) pTag->topScopeKey = NULL; else - pTag->topScopeKey = hb_cdxKeyPutItem( NULL, pItemLo, CDX_IGNORE_REC_NUM, pTag, TRUE, FALSE ); + pTag->topScopeKey = hb_cdxKeyPutItem( NULL, pItemLo, CDX_IGNORE_REC_NUM, + pTag, TRUE, CDX_CMP_PREFIX ); - if ( !pItemHi || HB_IS_NIL( pItemHi ) ) + if( !pItemHi || HB_IS_NIL( pItemHi ) ) pTag->bottomScopeKey = NULL; else - pTag->bottomScopeKey = hb_cdxKeyPutItem( NULL, pItemHi, CDX_MAX_REC_NUM, pTag, TRUE, FALSE ); + pTag->bottomScopeKey = hb_cdxKeyPutItem( NULL, pItemHi, CDX_MAX_REC_NUM, + pTag, TRUE, CDX_CMP_PREFIX ); hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagGoTop( pTag ); @@ -5750,10 +5837,10 @@ static ULONG hb_cdxDBOIScopeEval( LPCDXTAG pTag, HB_EVALSCOPE_FUNC pFunc, void * } hb_cdxIndexUnLockRead( pTag->pIndex ); - if ( pTag->topScopeKey ) + if( pTag->topScopeKey ) hb_cdxKeyFree( pTag->topScopeKey ); pTag->topScopeKey = pTopScopeKey; - if ( pTag->bottomScopeKey ) + if( pTag->bottomScopeKey ) hb_cdxKeyFree( pTag->bottomScopeKey ); pTag->bottomScopeKey = pBtmScopeKey; pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS ); @@ -5773,7 +5860,7 @@ static LONG hb_cdxDBOIKeyCount( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) ULONG ulKeyCount = 0; BOOL fLogOpt = pArea->dbfi.itmCobExpr || !pArea->dbfi.fFilter; - if ( pTag ) + if( pTag ) { BOOL fCheckFilter = ( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ); ULONG ulRecNo = pArea->ulRecNo; @@ -5781,46 +5868,46 @@ static LONG hb_cdxDBOIKeyCount( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( pTag && ( fFilters ? fLogOpt && CURKEY_LOGCNT( pTag ) : CURKEY_RAWCNT( pTag ) ) ) + if( pTag && ( fFilters ? fLogOpt && CURKEY_LOGCNT( pTag ) : CURKEY_RAWCNT( pTag ) ) ) { ulKeyCount = fFilters ? pTag->logKeyCount : pTag->rawKeyCount; } else { - if ( pTag->topScopeKey || pTag->bottomScopeKey || pTag->UsrUnique || pArea->dbfi.fFilter ) + if( pTag->topScopeKey || pTag->bottomScopeKey || pTag->UsrUnique || pArea->dbfi.fFilter ) { pCurKey = hb_cdxKeyCopy( NULL, pTag->CurKey ); hb_cdxTagGoTop( pTag ); - while ( !pTag->TagEOF ) + while( !pTag->TagEOF ) { - if ( !fCheckFilter || hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) + if( !fCheckFilter || hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) ulKeyCount++; hb_cdxTagSkipNext( pTag ); } pTag->fRePos = TRUE; hb_cdxKeyCopy( pTag->CurKey, pCurKey ); hb_cdxKeyFree( pCurKey ); - if ( fCheckFilter ) + if( fCheckFilter ) SELF_GOTO( ( AREAP ) pArea, ulRecNo ); } else { LPCDXPAGE pPage; pCurKey = hb_cdxKeyCopy( NULL, pTag->CurKey ); - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) hb_cdxTagGoTop( pTag ); else hb_cdxTagGoBottom( pTag ); pPage = pTag->RootPage; - while ( pPage->Child ) + while( pPage->Child ) pPage = pPage->Child; ulKeyCount = pPage->iKeys; - if ( pPage->Right != CDX_DUMMYNODE ) + if( pPage->Right != CDX_DUMMYNODE ) { ULONG ulPage = pPage->Right; pPage = hb_cdxPageNew( pTag, NULL, CDX_DUMMYNODE ); pPage->Page = ulPage; - while ( pPage->Page != CDX_DUMMYNODE ) + while( pPage->Page != CDX_DUMMYNODE ) { hb_cdxPageLoad( pPage ); ulKeyCount += pPage->iKeys; @@ -5832,12 +5919,12 @@ static LONG hb_cdxDBOIKeyCount( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) hb_cdxKeyCopy( pTag->CurKey, pCurKey ); hb_cdxKeyFree( pCurKey ); } - if ( !fFilters ) + if( !fFilters ) { pTag->rawKeyCount = ulKeyCount; pTag->curKeyState |= CDX_CURKEY_RAWCNT; } - else if ( fLogOpt ) + else if( fLogOpt ) CURKEY_SETLOGCNT( pTag, ulKeyCount ) } @@ -5845,16 +5932,16 @@ static LONG hb_cdxDBOIKeyCount( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) } else /* no filter, no order */ { - if ( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ) + if( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ) { ULONG ulRecNo = pArea->ulRecNo; - if ( SELF_GOTOP( ( AREAP ) pArea ) == HB_SUCCESS ) + if( SELF_GOTOP( ( AREAP ) pArea ) == HB_SUCCESS ) { - while ( !pArea->fEof ) + while( !pArea->fEof ) { ulKeyCount++; - if ( SELF_SKIP( ( AREAP ) pArea, 1 ) != HB_SUCCESS ) + if( SELF_SKIP( ( AREAP ) pArea, 1 ) != HB_SUCCESS ) break; } SELF_GOTO( ( AREAP ) pArea, ulRecNo ); @@ -5879,9 +5966,9 @@ static LONG hb_cdxDBOIKeyNo( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) if( pArea->lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); - if ( !pArea->fPositioned ) + if( !pArea->fPositioned ) ulKeyNo = 0; - else if ( pTag ) + else if( pTag ) { BOOL fCheckFilter = ( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ); ULONG ulRecNo = pArea->ulRecNo; @@ -5889,8 +5976,8 @@ static LONG hb_cdxDBOIKeyNo( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( fFilters ? ( fLogOpt && CURKEY_LOGPOS( pTag ) ) : - ( CURKEY_RAWPOS( pTag ) && + if( fFilters ? ( fLogOpt && CURKEY_LOGPOS( pTag ) ) : + ( CURKEY_RAWPOS( pTag ) && pTag->rawKeyRec == pArea->ulRecNo ) ) { ulKeyNo = fFilters ? pTag->logKeyPos : pTag->rawKeyPos; @@ -5898,43 +5985,43 @@ static LONG hb_cdxDBOIKeyNo( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) else { hb_cdxTagOpen( pTag ); - if ( hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( hb_cdxCurKeyRefresh( pArea, pTag ) ) { - if ( pTag->topScopeKey || pTag->bottomScopeKey || pTag->UsrUnique || pArea->dbfi.fFilter ) + if( pTag->topScopeKey || pTag->bottomScopeKey || pTag->UsrUnique || pArea->dbfi.fFilter ) { - if ( hb_cdxBottomScope( pTag ) && hb_cdxTopScope( pTag ) && - ( !fCheckFilter || hb_cdxCheckRecordFilter( pArea, ulRecNo ) ) ) + if( hb_cdxBottomScope( pTag ) && hb_cdxTopScope( pTag ) && + ( !fCheckFilter || hb_cdxCheckRecordFilter( pArea, ulRecNo ) ) ) { LPCDXKEY pCurKey = hb_cdxKeyCopy( NULL, pTag->CurKey ); - if ( !hb_cdxCheckRecordScope( pArea, pTag->CurKey->rec ) ) + if( !hb_cdxCheckRecordScope( pArea, pTag->CurKey->rec ) ) hb_cdxTagSkipPrev( pTag ); - while ( !pTag->TagBOF ) + while( !pTag->TagBOF ) { - if ( !fCheckFilter || hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) + if( !fCheckFilter || hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) ulKeyNo++; hb_cdxTagSkipPrev( pTag ); } pTag->fRePos = TRUE; hb_cdxKeyCopy( pTag->CurKey, pCurKey ); hb_cdxKeyFree( pCurKey ); - if ( fCheckFilter ) + if( fCheckFilter ) SELF_GOTO( ( AREAP ) pArea, ulRecNo ); } } else { LPCDXPAGE pPage = pTag->RootPage; - while ( pPage->Child ) + while( pPage->Child ) pPage = pPage->Child; - if ( pTag->UsrAscend ) + if( pTag->UsrAscend ) { ulKeyNo = pPage->iCurKey + 1; - if ( pPage->Left != CDX_DUMMYNODE ) + if( pPage->Left != CDX_DUMMYNODE ) { ULONG ulPage = pPage->Left; pPage = hb_cdxPageNew( pTag, NULL, CDX_DUMMYNODE ); pPage->Page = ulPage; - while ( pPage->Page != CDX_DUMMYNODE ) + while( pPage->Page != CDX_DUMMYNODE ) { hb_cdxPageLoad( pPage ); ulKeyNo += pPage->iKeys; @@ -5946,12 +6033,12 @@ static LONG hb_cdxDBOIKeyNo( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) else { ulKeyNo = pPage->iKeys - pPage->iCurKey; - if ( pPage->Right != CDX_DUMMYNODE ) + if( pPage->Right != CDX_DUMMYNODE ) { ULONG ulPage = pPage->Right; pPage = hb_cdxPageNew( pTag, NULL, CDX_DUMMYNODE ); pPage->Page = ulPage; - while ( pPage->Page != CDX_DUMMYNODE ) + while( pPage->Page != CDX_DUMMYNODE ) { hb_cdxPageLoad( pPage ); ulKeyNo += pPage->iKeys; @@ -5961,14 +6048,14 @@ static LONG hb_cdxDBOIKeyNo( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) } } } - if ( ulKeyNo != 0 ) + if( ulKeyNo != 0 ) { - if ( !fFilters ) + if( !fFilters ) { pTag->rawKeyPos = ulKeyNo; CURKEY_SETRAWPOS( pTag ); } - else if ( fLogOpt ) + else if( fLogOpt ) { pTag->logKeyPos = ulKeyNo; CURKEY_SETLOGPOS( pTag ); @@ -5982,16 +6069,16 @@ static LONG hb_cdxDBOIKeyNo( CDXAREAP pArea, LPCDXTAG pTag, BOOL fFilters ) { ULONG ulRecNo = pArea->ulRecNo; - if ( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ) + if( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ) { - if ( hb_cdxCheckRecordFilter( pArea, ulRecNo ) ) + if( hb_cdxCheckRecordFilter( pArea, ulRecNo ) ) { do { ulKeyNo++; - if ( SELF_SKIP( ( AREAP ) pArea, -1 ) != HB_SUCCESS ) + if( SELF_SKIP( ( AREAP ) pArea, -1 ) != HB_SUCCESS ) break; - } while ( !( ( AREAP ) pArea )->fBof ); + } while( !( ( AREAP ) pArea )->fBof ); SELF_GOTO( ( AREAP ) pArea, ulRecNo ); } } @@ -6012,14 +6099,14 @@ static HB_ERRCODE hb_cdxDBOIKeyGoto( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulKeyN ULONG ulKeyCnt = ulKeyNo; BOOL fLogOpt = pArea->dbfi.itmCobExpr || !pArea->dbfi.fFilter; - if ( ulKeyNo == 0 ) + if( ulKeyNo == 0 ) retval = SELF_GOTO( ( AREAP ) pArea, 0 ); - else if ( pTag ) + else if( pTag ) { BOOL fCheckFilter = ( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ); hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( ! pArea->lpdbPendingRel && ( fFilters ? + if( ! pArea->lpdbPendingRel && ( fFilters ? fLogOpt && CURKEY_LOGPOS( pTag ) && pTag->logKeyPos == ulKeyNo : ( CURKEY_RAWPOS( pTag ) && pTag->rawKeyPos == ulKeyNo ) ) ) { @@ -6027,15 +6114,15 @@ static HB_ERRCODE hb_cdxDBOIKeyGoto( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulKeyN } else { - if ( pTag->topScopeKey || pTag->bottomScopeKey || pTag->UsrUnique || pArea->dbfi.fFilter ) + if( pTag->topScopeKey || pTag->bottomScopeKey || pTag->UsrUnique || pArea->dbfi.fFilter ) { hb_cdxTagGoTop( pTag ); - if ( fCheckFilter ) - while ( !pTag->TagEOF ) + if( fCheckFilter ) + while( !pTag->TagEOF ) { - if ( hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) + if( hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) { - if ( ! --ulKeyCnt ) + if( ! --ulKeyCnt ) break; } hb_cdxTagSkipNext( pTag ); @@ -6050,21 +6137,21 @@ static HB_ERRCODE hb_cdxDBOIKeyGoto( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulKeyN ULONG ulNextPg; hb_cdxTagGoTop( pTag ); pPage = pTag->RootPage; - while ( pPage->Child ) + while( pPage->Child ) { pOwnerPage = pPage; pPage = pPage->Child; } - while ( (ULONG) pPage->iKeys < ulKeyCnt && pOwnerPage && - ( ulNextPg = pTag->UsrAscend ? - pPage->Right : pPage->Left ) != CDX_DUMMYNODE ) + while( ( ULONG ) pPage->iKeys < ulKeyCnt && pOwnerPage && + ( ulNextPg = pTag->UsrAscend ? + pPage->Right : pPage->Left ) != CDX_DUMMYNODE ) { ulKeyCnt -= pPage->iKeys; pOwnerPage->Child = hb_cdxPageNew( pPage->TagParent, pPage->Owner, ulNextPg ); hb_cdxPageFree( pPage, FALSE ); pPage = pOwnerPage->Child; } - if ( (ULONG) pPage->iKeys >= ulKeyCnt ) + if( (ULONG) pPage->iKeys >= ulKeyCnt ) { pPage->iCurKey = pTag->UsrAscend ? ( int ) ulKeyCnt - 1 : pPage->iKeys - ( int ) ulKeyCnt; hb_cdxSetCurKey( pPage ); @@ -6075,14 +6162,14 @@ static HB_ERRCODE hb_cdxDBOIKeyGoto( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulKeyN } } retval = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); - if ( pArea->fPositioned ) + if( pArea->fPositioned ) { - if ( !fFilters ) + if( !fFilters ) { pTag->rawKeyPos = ulKeyNo; CURKEY_SETRAWPOS( pTag ); } - else if ( fLogOpt ) + else if( fLogOpt ) { pTag->logKeyPos = ulKeyNo; CURKEY_SETLOGPOS( pTag ); @@ -6093,7 +6180,7 @@ static HB_ERRCODE hb_cdxDBOIKeyGoto( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulKeyN } else { - if ( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ) + if( fLogOpt && fFilters && pArea->dbfi.itmCobExpr ) { retval = SELF_GOTOP( ( AREAP ) pArea ); if( retval == HB_SUCCESS && --ulKeyCnt ) @@ -6276,7 +6363,6 @@ static void hb_cdxDBOISetRelKeyPos( CDXAREAP pArea, LPCDXTAG pTag, double dPos ) { LPCDXKEY pKey; double dStart, dStop, dFact = 0.0000000000001; - BOOL fOK = TRUE; if( pTag->UsrAscend ) { @@ -6353,7 +6439,7 @@ static void hb_cdxDBOISetRelKeyPos( CDXAREAP pArea, LPCDXTAG pTag, double dPos ) hb_cdxTagGoTop( pTag ); while( !pTag->TagEOF ) { - if ( hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) + if( hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) break; hb_cdxTagSkipNext( pTag ); } @@ -6365,7 +6451,7 @@ static void hb_cdxDBOISetRelKeyPos( CDXAREAP pArea, LPCDXTAG pTag, double dPos ) hb_cdxTagGoBottom( pTag ); while( !pTag->TagBOF ) { - if ( hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) + if( hb_cdxCheckRecordFilter( pArea, pTag->CurKey->rec ) ) break; hb_cdxTagSkipPrev( pTag ); } @@ -6389,16 +6475,16 @@ static BOOL hb_cdxDBOIFindRec( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulRecNo, BOO { BOOL fFound = FALSE; - if ( pTag && ulRecNo ) + if( pTag && ulRecNo ) { if( pArea->lpdbPendingRel && pArea->lpdbPendingRel->isScoped ) SELF_FORCEREL( ( AREAP ) pArea ); hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( fCont ) + if( fCont ) { - if ( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) ulRecNo = 0; else hb_cdxTagSkipNext( pTag ); @@ -6407,11 +6493,11 @@ static BOOL hb_cdxDBOIFindRec( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulRecNo, BOO { hb_cdxTagGoTop( pTag ); } - if ( ulRecNo ) + if( ulRecNo ) { - while ( !pTag->TagBOF && !pTag->TagEOF && hb_cdxBottomScope( pTag ) ) + while( !pTag->TagBOF && !pTag->TagEOF && hb_cdxBottomScope( pTag ) ) { - if ( pTag->CurKey->rec == ulRecNo ) + if( pTag->CurKey->rec == ulRecNo ) { fFound = TRUE; break; @@ -6430,10 +6516,10 @@ static void hb_cdxClearLogPosInfo( CDXAREAP pArea ) LPCDXINDEX pIndex = pArea->lpIndexes; LPCDXTAG pTag; - while ( pIndex ) + while( pIndex ) { pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { pTag->curKeyState &= ~( CDX_CURKEY_LOGPOS | CDX_CURKEY_LOGCNT ); pTag = pTag->pNext; @@ -6458,11 +6544,11 @@ static HB_ERRCODE hb_cdxGoBottom( CDXAREAP pArea ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxGoBottom(%p)", pArea)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pTag = hb_cdxGetActiveTag( pArea ); - if ( ! pTag ) + if( ! pTag ) return SUPER_GOBOTTOM( ( AREAP ) pArea ); if( pArea->lpdbPendingRel && pArea->lpdbPendingRel->isScoped ) @@ -6478,11 +6564,11 @@ static HB_ERRCODE hb_cdxGoBottom( CDXAREAP pArea ) retval = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); - if ( retval != HB_FAILURE && pArea->fPositioned ) + if( retval != HB_FAILURE && pArea->fPositioned ) { retval = SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); - if ( pArea->fPositioned && CURKEY_LOGCNT( pTag ) ) + if( pArea->fPositioned && CURKEY_LOGCNT( pTag ) ) { pTag->logKeyPos = pTag->logKeyCount; CURKEY_SETLOGPOS( pTag ); @@ -6504,11 +6590,11 @@ static HB_ERRCODE hb_cdxGoTop( CDXAREAP pArea ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxGoTop(%p)", pArea)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pTag = hb_cdxGetActiveTag( pArea ); - if ( ! pTag ) + if( ! pTag ) return SUPER_GOTOP( ( AREAP ) pArea ); if( pArea->lpdbPendingRel && pArea->lpdbPendingRel->isScoped ) @@ -6524,10 +6610,10 @@ static HB_ERRCODE hb_cdxGoTop( CDXAREAP pArea ) retval = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); - if ( retval != HB_FAILURE && pArea->fPositioned ) + if( retval != HB_FAILURE && pArea->fPositioned ) retval = SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); - if ( retval != HB_FAILURE && pArea->fPositioned ) + if( retval != HB_FAILURE && pArea->fPositioned ) { pTag->logKeyPos = 1; CURKEY_SETLOGPOS( pTag ); @@ -6544,12 +6630,12 @@ static HB_ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pKeyItm, HB_TRACE(HB_TR_DEBUG, ("hb_cdxSeek(%p, %d, %p, %d)", pArea, fSoftSeek, pKeyItm, fFindLast)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pTag = hb_cdxGetActiveTag( pArea ); - if ( ! pTag ) + if( ! pTag ) { hb_cdxErrorRT( pArea, EG_NOORDER, EDBF_NOTINDEXED, NULL, 0, EF_CANDEFAULT, NULL ); return HB_FAILURE; @@ -6567,50 +6653,53 @@ static HB_ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pKeyItm, pArea->fTop = pArea->fBottom = FALSE; pArea->fEof = FALSE; - if ( pTag->UsrUnique ) + if( pTag->UsrUnique ) fLast = !pTag->UsrAscend; else fLast = pTag->UsrAscend ? fFindLast : !fFindLast; /* TODO: runtime error if valtype(pKeyItm) != pTag->Type */ - pKey = hb_cdxKeyPutItem( NULL, pKeyItm, fLast ? CDX_MAX_REC_NUM : CDX_IGNORE_REC_NUM, pTag, TRUE, FALSE ); + pKey = hb_cdxKeyPutItem( NULL, pKeyItm, + fLast ? CDX_MAX_REC_NUM : CDX_IGNORE_REC_NUM, + pTag, TRUE, CDX_CMP_PREFIX ); hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); ulRec = hb_cdxTagKeyFind( pTag, pKey ); - if ( ( ulRec == 0 && ! fSoftSeek ) || pTag->TagEOF ) + if( ( ulRec == 0 && ! fSoftSeek ) || pTag->TagEOF ) fEOF = TRUE; - else /* if ( fSoftSeek ) */ + else /* if( fSoftSeek ) */ { - if ( ! hb_cdxBottomScope( pTag ) ) + if( ! hb_cdxBottomScope( pTag ) ) fEOF = TRUE; - else if ( ! hb_cdxTopScope( pTag ) ) + else if( ! hb_cdxTopScope( pTag ) ) { hb_cdxTagGoTop( pTag ); - if ( pTag->CurKey->rec == 0 ) + if( pTag->CurKey->rec == 0 ) fEOF = TRUE; } } hb_cdxIndexUnLockRead( pTag->pIndex ); - if ( !fEOF ) + if( !fEOF ) { retval = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); - if ( retval != HB_FAILURE && pArea->fPositioned ) + if( retval != HB_FAILURE && pArea->fPositioned ) { retval = SELF_SKIPFILTER( ( AREAP ) pArea, fFindLast ? -1 : 1 ); - if ( retval != HB_FAILURE && ulRec && pArea->fPositioned ) + if( retval != HB_FAILURE && ulRec && pArea->fPositioned ) { pArea->fFound = ( ulRec == pArea->ulRecNo || hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->CurKey->val, pTag->CurKey->len, FALSE ) == 0 ); - if ( ! pArea->fFound && ! fSoftSeek ) + pTag->CurKey->val, pTag->CurKey->len, + pKey->mode ) == 0 ); + if( ! pArea->fFound && ! fSoftSeek ) fEOF = TRUE; } } } - if ( retval != HB_FAILURE && - ( fEOF || ! hb_cdxTopScope( pTag ) || - ! hb_cdxBottomScope( pTag ) ) ) + if( retval != HB_FAILURE && + ( fEOF || ! hb_cdxTopScope( pTag ) || + ! hb_cdxBottomScope( pTag ) ) ) { retval = SELF_GOTO( ( AREAP ) pArea, 0 ); } @@ -6624,7 +6713,7 @@ static HB_ERRCODE hb_cdxSeek( CDXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pKeyItm, static BYTE * hb_cdxPageGetKeyValActual( LPCDXPAGE pPage ) { - while ( pPage->Child ) + while( pPage->Child ) { pPage = pPage->Child; } @@ -6649,28 +6738,28 @@ static int hb_cdxPageSeekKeyWild( LPCDXPAGE pPage, LPCDXKEY pKey, ULONG ulKeyRec k = ( ulKeyRec == CDX_MAX_REC_NUM ) ? -1 : 1; - if ( fNext ? hb_cdxPageReadNextKey( pPage ) : hb_cdxPageReadTopKey( pPage ) ) + if( fNext ? hb_cdxPageReadNextKey( pPage ) : hb_cdxPageReadTopKey( pPage ) ) { do { k = hb_cdxValCompareWild( pKey->val, hb_cdxPageGetKeyValActual( pPage ), fExact ); } - while ( k && hb_cdxPageReadNextKey( pPage ) ); + while( k && hb_cdxPageReadNextKey( pPage ) ); - if ( k == 0 ) + if( k == 0 ) { - while ( pPage->Child ) + while( pPage->Child ) { pPage = pPage->Child; } - if ( ulKeyRec == CDX_MAX_REC_NUM ) + if( ulKeyRec == CDX_MAX_REC_NUM ) k = 1; - else if ( ulKeyRec != CDX_IGNORE_REC_NUM ) + else if( ulKeyRec != CDX_IGNORE_REC_NUM ) { ULONG ulRec = hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ); - if ( ulKeyRec > ulRec ) + if( ulKeyRec > ulRec ) k = 1; - else if ( ulKeyRec < ulRec ) + else if( ulKeyRec < ulRec ) k = -1; } } @@ -6691,10 +6780,10 @@ static ULONG hb_cdxTagKeyFindWild( LPCDXTAG pTag, LPCDXKEY pKey, BOOL fNext ) pTag->TagBOF = pTag->TagEOF = FALSE; K = hb_cdxPageSeekKeyWild( pTag->RootPage, pKey, ulKeyRec, FALSE, fNext ); - if ( ulKeyRec == CDX_MAX_REC_NUM ) + if( ulKeyRec == CDX_MAX_REC_NUM ) K = - K; - if ( K > 0 ) + if( K > 0 ) { pTag->CurKey->rec = 0; pTag->TagEOF = TRUE; @@ -6702,7 +6791,7 @@ static ULONG hb_cdxTagKeyFindWild( LPCDXTAG pTag, LPCDXKEY pKey, BOOL fNext ) else { hb_cdxSetCurKey( pTag->RootPage ); - if ( K == 0 ) + if( K == 0 ) return pTag->CurKey->rec; } return 0; @@ -6716,12 +6805,12 @@ static HB_ERRCODE hb_cdxSeekWild( CDXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pKeyI HB_TRACE(HB_TR_DEBUG, ("hb_cdxSeekWild(%p, %d, %p, %d, %d)", pArea, fSoftSeek, pKeyItm, fFindLast, fNext)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pTag = hb_cdxGetActiveTag( pArea ); - if ( ! pTag ) + if( ! pTag ) { hb_cdxErrorRT( pArea, EG_NOORDER, 1201, NULL, 0, EF_CANDEFAULT, NULL ); return HB_FAILURE; @@ -6739,7 +6828,7 @@ static HB_ERRCODE hb_cdxSeekWild( CDXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pKeyI pArea->fTop = pArea->fBottom = FALSE; pArea->fEof = FALSE; - if ( pTag->UsrUnique ) + if( pTag->UsrUnique ) fLast = !pTag->UsrAscend; else fLast = pTag->UsrAscend ? fFindLast : !fFindLast; @@ -6750,36 +6839,36 @@ static HB_ERRCODE hb_cdxSeekWild( CDXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pKeyI hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); ulRec = hb_cdxTagKeyFindWild( pTag, pKey, fNext ); - if ( ( ulRec == 0 && ! fSoftSeek ) || pTag->TagEOF ) + if( ( ulRec == 0 && ! fSoftSeek ) || pTag->TagEOF ) fEOF = TRUE; - else /* if ( fSoftSeek ) */ + else /* if( fSoftSeek ) */ { - if ( ! hb_cdxBottomScope( pTag ) ) + if( ! hb_cdxBottomScope( pTag ) ) fEOF = TRUE; - else if ( ! hb_cdxTopScope( pTag ) ) + else if( ! hb_cdxTopScope( pTag ) ) { hb_cdxTagGoTop( pTag ); - if ( pTag->CurKey->rec == 0 ) + if( pTag->CurKey->rec == 0 ) fEOF = TRUE; } } hb_cdxIndexUnLockRead( pTag->pIndex ); - if ( !fEOF ) + if( !fEOF ) { retval = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); - if ( retval != HB_FAILURE && pArea->fPositioned ) + if( retval != HB_FAILURE && pArea->fPositioned ) { retval = SELF_SKIPFILTER( ( AREAP ) pArea, fFindLast ? -1 : 1 ); - if ( retval != HB_FAILURE && ulRec && pArea->fPositioned ) + if( retval != HB_FAILURE && ulRec && pArea->fPositioned ) { pArea->fFound = ( ulRec == pArea->ulRecNo || hb_cdxValCompareWild( pKey->val, pTag->CurKey->val, FALSE ) == 0 ); - if ( ! pArea->fFound && ! fSoftSeek ) + if( ! pArea->fFound && ! fSoftSeek ) fEOF = TRUE; } } } - if ( retval != HB_FAILURE && + if( retval != HB_FAILURE && ( fEOF || ! hb_cdxTopScope( pTag ) || ! hb_cdxBottomScope( pTag ) ) ) { @@ -6803,7 +6892,7 @@ HB_FUNC( BM_DBGETFILTERARRAY ) PHB_ITEM pList = hb_itemArrayNew( 0 ); ULONG ulRec,ulRecOld; - if ( pArea->dbfi.fOptimized ) + if( pArea->dbfi.fOptimized ) { ULONG ulSize = ( ( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size+1) >> 5 ) + 1; ULONG ulLong, ulByte, ulBytes, ulRecno; @@ -6811,12 +6900,12 @@ HB_FUNC( BM_DBGETFILTERARRAY ) ulRecOld = pArea->ulRecNo; - for ( ulLong = 0; ulLong < ulSize; ulLong++ ) - if ( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap[ulLong] ) - for ( ulByte = (ulLong<<2), ulBytes = 0; ulBytes < 4; ulByte++, ulBytes++ ) - if ( ((char*)( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap)[ulByte] ) - for ( ulRec=(ulByte<<3)+1, ulRecno=0; ulRecno < 8; ulRec++, ulRecno++ ) - if ( hb_cdxCheckRecordFilter( pArea, ulRec ) ) + for( ulLong = 0; ulLong < ulSize; ulLong++ ) + if( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap[ulLong] ) + for( ulByte = (ulLong<<2), ulBytes = 0; ulBytes < 4; ulByte++, ulBytes++ ) + if( ((char*)( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap)[ulByte] ) + for( ulRec=(ulByte<<3)+1, ulRecno=0; ulRecno < 8; ulRec++, ulRecno++ ) + if( hb_cdxCheckRecordFilter( pArea, ulRec ) ) hb_arrayAddForward( pList, hb_itemPutNL( pItem, ulRec ) ); SELF_GOTO( (AREAP) pArea, ulRecOld ); @@ -6851,10 +6940,10 @@ HB_FUNC( BM_DBSETFILTERARRAY ) ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap = ( ULONG * ) hb_xgrab( sizeof( ULONG ) * (((ulRecCount+1) >> 5) + 1) ); memset( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, 0, sizeof(ULONG) * (((ulRecCount+1) >> 5) + 1 ) ); - for ( ulPos = 1; ulPos <= hb_arrayLen( pArray ); ulPos++ ) + for( ulPos = 1; ulPos <= hb_arrayLen( pArray ); ulPos++ ) BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ulRecCount, ( ULONG ) hb_arrayGetNL( pArray, ulPos ) ); pTag = hb_cdxGetActiveTag( ( CDXAREAP ) pArea ); - if ( pTag ) /* Con índice activo */ + if( pTag ) /* Con índice activo */ { pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_RAWCNT ); CURKEY_SETLOGCNT( pTag, (hb_arrayLen( pArray )) ) @@ -6879,14 +6968,14 @@ HB_FUNC( BM_DBSETFILTERARRAYADD ) { LPCDXTAG pTag; - for ( ulPos = 1; ulPos <= hb_arrayLen( pArray ); ulPos++ ) - if ( ! BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, (ULONG) hb_arrayGetNL( pArray, ulPos ) ) ) + for( ulPos = 1; ulPos <= hb_arrayLen( pArray ); ulPos++ ) + if( ! BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, (ULONG) hb_arrayGetNL( pArray, ulPos ) ) ) { BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, (ULONG) hb_arrayGetNL( pArray, ulPos ) ); ulAdd++; } pTag = hb_cdxGetActiveTag( (CDXAREAP) pArea ); - if ( pTag ) /* Con índice activo */ + if( pTag ) /* Con índice activo */ CURKEY_SETLOGCNT( pTag, (pTag->logKeyCount + ulAdd) ) } else @@ -6908,14 +6997,14 @@ HB_FUNC( BM_DBSETFILTERARRAYDEL ) { LPCDXTAG pTag; - for ( ulPos = 1; ulPos <= hb_arrayLen( pArray ); ulPos++ ) - if ( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, (ULONG) hb_arrayGetNL( pArray, ulPos ) ) ) + for( ulPos = 1; ulPos <= hb_arrayLen( pArray ); ulPos++ ) + if( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, (ULONG) hb_arrayGetNL( pArray, ulPos ) ) ) { BM_ClrBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, (ULONG) hb_arrayGetNL( pArray, ulPos ) ); ulDel++; } pTag = hb_cdxGetActiveTag( (CDXAREAP) pArea ); - if ( pTag ) /* Con índice activo */ + if( pTag ) /* Con índice activo */ CURKEY_SETLOGCNT( pTag, pTag->logKeyCount - ulDel ) } else @@ -6941,18 +7030,18 @@ HB_FUNC( BM_DBSEEKWILD ) bFindLast = ISLOG( 3 ) ? hb_parl( 3 ) : FALSE; bNext = ISLOG( 4 ) ? hb_parl( 4 ) : FALSE; bAll = ISLOG( 5 ) ? hb_parl( 5 ) : FALSE; - if ( bAll) + if( bAll) { PHB_ITEM pList; pList = hb_itemNew( NULL ); hb_arrayNew( pList, 0 ); SELF_GOTOP( ( AREAP ) pArea ); - if ( hb_cdxSeekWild( (CDXAREAP) pArea, bSoftSeek, pKey, bFindLast, FALSE, bAll ) == HB_SUCCESS && + if( hb_cdxSeekWild( (CDXAREAP) pArea, bSoftSeek, pKey, bFindLast, FALSE, bAll ) == HB_SUCCESS && pArea->fEof == FALSE && SELF_FOUND( pArea, &fFound ) == HB_SUCCESS ) { hb_arrayAddForward( pList, hb_itemPutNL( NULL, ((CDXAREAP) pArea)->ulRecNo ) ); - while ( hb_cdxSeekWild( (CDXAREAP) pArea, bSoftSeek, pKey, bFindLast, TRUE, bAll ) == HB_SUCCESS && + while( hb_cdxSeekWild( (CDXAREAP) pArea, bSoftSeek, pKey, bFindLast, TRUE, bAll ) == HB_SUCCESS && pArea->fEof == FALSE && SELF_FOUND( pArea, &fFound ) == HB_SUCCESS ) { @@ -7006,39 +7095,39 @@ static HB_ERRCODE hb_cdxSkip( CDXAREAP pArea, LONG lToSkip ) ulPos = ulRec = 0; } - if ( SUPER_SKIP( ( AREAP ) pArea, lToSkip ) == HB_FAILURE ) + if( SUPER_SKIP( ( AREAP ) pArea, lToSkip ) == HB_FAILURE ) return HB_FAILURE; - if ( pTag ) + if( pTag ) { - if ( ulPos && ( pTag->logKeyPos != ulPos || pTag->logKeyRec != ulRec || - ( pTag->curKeyState & CDX_CURKEY_LOGPOS ) == 0 ) ) + if( ulPos && ( pTag->logKeyPos != ulPos || pTag->logKeyRec != ulRec || + ( pTag->curKeyState & CDX_CURKEY_LOGPOS ) == 0 ) ) { ulPos = 0; } - if ( lToSkip > 0 ) + if( lToSkip > 0 ) { - if ( pArea->fEof ) + if( pArea->fEof ) { - if ( lToSkip == 1 && ulPos && !CURKEY_LOGCNT( pTag ) ) + if( lToSkip == 1 && ulPos && !CURKEY_LOGCNT( pTag ) ) CURKEY_SETLOGCNT( pTag, ulPos ) } - else if ( ulPos ) + else if( ulPos ) { pTag->logKeyPos += lToSkip; pTag->logKeyRec = pArea->ulRecNo; } } - else if ( pArea->fBof ) + else if( pArea->fBof ) { - if ( pArea->fPositioned ) + if( pArea->fPositioned ) { pTag->logKeyPos = 1; CURKEY_SETLOGPOS( pTag ); } } - else if ( ulPos ) + else if( ulPos ) { pTag->logKeyPos += lToSkip; pTag->logKeyRec = pArea->ulRecNo; @@ -7084,7 +7173,7 @@ static HB_ERRCODE hb_cdxSkipFilter( CDXAREAP pArea, LONG lUpDown ) { if( SELF_SKIPRAW( (AREAP) pArea, lUpDown ) != HB_SUCCESS ) return HB_FAILURE; - else if ( pTag ) + else if( pTag ) pTag->logKeyPos += lUpDown; continue; } @@ -7147,12 +7236,12 @@ static HB_ERRCODE hb_cdxSkipRaw( CDXAREAP pArea, LONG lToSkip ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxSkipRaw(%p, %ld)", pArea, lToSkip)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pTag = hb_cdxGetActiveTag( pArea ); - if ( ! pTag || lToSkip == 0 ) + if( ! pTag || lToSkip == 0 ) return SUPER_SKIPRAW( ( AREAP ) pArea, lToSkip ); if( pArea->lpdbPendingRel ) @@ -7162,31 +7251,31 @@ static HB_ERRCODE hb_cdxSkipRaw( CDXAREAP pArea, LONG lToSkip ) hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); - if ( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) + if( ! hb_cdxCurKeyRefresh( pArea, pTag ) ) { - if ( fForward ) + if( fForward ) { - if ( pTag->TagEOF || !hb_cdxBottomScope( pTag ) ) + if( pTag->TagEOF || !hb_cdxBottomScope( pTag ) ) fOut = TRUE; - else if ( pTag->UsrAscend && hb_cdxTopScope( pTag ) ) + else if( pTag->UsrAscend && hb_cdxTopScope( pTag ) ) lToSkip--; } - else if ( pArea->fPositioned ) + else if( pArea->fPositioned ) { - if ( pTag->TagEOF || !hb_cdxTopScope( pTag ) ) + if( pTag->TagEOF || !hb_cdxTopScope( pTag ) ) fOut = TRUE; - else if ( !pTag->UsrAscend && hb_cdxBottomScope( pTag ) ) + else if( !pTag->UsrAscend && hb_cdxBottomScope( pTag ) ) lToSkip++; } } - if ( fForward ) + if( fForward ) { - if ( !fOut ) + if( !fOut ) { - while ( lToSkip-- > 0 ) + while( lToSkip-- > 0 ) { hb_cdxTagSkipNext( pTag ); - if ( pTag->TagEOF ) + if( pTag->TagEOF ) { fOut = TRUE; break; @@ -7196,16 +7285,16 @@ static HB_ERRCODE hb_cdxSkipRaw( CDXAREAP pArea, LONG lToSkip ) retval = SELF_GOTO( ( AREAP ) pArea, ( pTag->TagEOF || fOut ) ? 0 : pTag->CurKey->rec ); } - else /* if ( lToSkip < 0 ) */ + else /* if( lToSkip < 0 ) */ { - if ( fOut ) + if( fOut ) hb_cdxTagGoTop( pTag ); else { - while ( lToSkip++ < 0 ) + while( lToSkip++ < 0 ) { hb_cdxTagSkipPrev( pTag ); - if ( pTag->TagBOF ) + if( pTag->TagBOF ) { fOut = TRUE; break; @@ -7230,27 +7319,27 @@ static HB_ERRCODE hb_cdxSkipRaw( CDXAREAP pArea, LONG lToSkip ) /* ( DBENTRYP_B ) hb_cdxAppend */ static HB_ERRCODE hb_cdxAppend( CDXAREAP pArea, BOOL bUnLockAll ) { - if ( SUPER_APPEND( (AREAP) pArea, bUnLockAll ) == HB_SUCCESS ) + if( SUPER_APPEND( (AREAP) pArea, bUnLockAll ) == HB_SUCCESS ) { - if ( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) + if( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) { ULONG ulRecCount, bytes; SELF_RECCOUNT( ( AREAP ) pArea, &ulRecCount ); bytes = ( (ulRecCount + 1) >> 5 ) + 1; - if ( ( (ulRecCount) >> 5 ) + 1 < bytes ) + if( ( (ulRecCount) >> 5 ) + 1 < bytes ) { ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap = (ULONG *) hb_xrealloc( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, bytes << 2 ); ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size = ulRecCount; } pArea->dbfi.fFilter = FALSE; - if ( hb_cdxCheckRecordFilter( pArea, ulRecCount ) ) + if( hb_cdxCheckRecordFilter( pArea, ulRecCount ) ) { LPCDXTAG pTag; BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, ulRecCount ); pTag = hb_cdxGetActiveTag( (CDXAREAP) pArea ); - if ( pTag && CURKEY_LOGCNT(pTag) ) /* Con índice activo */ + if( pTag && CURKEY_LOGCNT(pTag) ) /* Con índice activo */ CURKEY_SETLOGCNT( pTag, (pTag)->logKeyCount + 1 ) } else @@ -7266,30 +7355,30 @@ static HB_ERRCODE hb_cdxAppend( CDXAREAP pArea, BOOL bUnLockAll ) /* ( DBENTRYP_V ) hb_cdxDeleteRec */ static HB_ERRCODE hb_cdxDeleteRec( CDXAREAP pArea ) { - if ( SUPER_DELETE( (AREAP) pArea ) == HB_SUCCESS ) + if( SUPER_DELETE( (AREAP) pArea ) == HB_SUCCESS ) { - if ( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) + if( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) { pArea->dbfi.fFilter = FALSE; - if ( hb_cdxCheckRecordFilter( pArea, pArea->ulRecNo ) ) + if( hb_cdxCheckRecordFilter( pArea, pArea->ulRecNo ) ) { - if ( ! BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) + if( ! BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) { LPCDXTAG pTag; BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ); pTag = hb_cdxGetActiveTag( (CDXAREAP) pArea ); - if ( pTag && CURKEY_LOGCNT(pTag) ) + if( pTag && CURKEY_LOGCNT(pTag) ) CURKEY_SETLOGCNT( pTag, (pTag)->logKeyCount + 1 ) } } else { - if ( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) + if( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) { LPCDXTAG pTag; BM_ClrBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ); pTag = hb_cdxGetActiveTag( (CDXAREAP) pArea ); - if ( pTag && CURKEY_LOGCNT(pTag) ) + if( pTag && CURKEY_LOGCNT(pTag) ) CURKEY_SETLOGCNT( pTag, (pTag)->logKeyCount - 1 ) } } @@ -7323,12 +7412,12 @@ static HB_ERRCODE hb_cdxFlush( CDXAREAP pArea ) uiError = SUPER_FLUSH( ( AREAP ) pArea ); - if ( hb_setGetHardCommit() ) + if( hb_setGetHardCommit() ) { pIndex = pArea->lpIndexes; - while ( pIndex ) + while( pIndex ) { - if ( pIndex->pFile && pIndex->fFlush ) + if( pIndex->pFile && pIndex->fFlush ) { hb_fileCommit( pIndex->pFile ); pIndex->fFlush = FALSE; @@ -7355,21 +7444,21 @@ static HB_ERRCODE hb_cdxGoCold( CDXAREAP pArea ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxGoCold(%p)", pArea)); - if ( SUPER_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( SUPER_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( ( fRecordChanged || pArea->fCdxAppend ) && pArea->lpIndexes ) + if( ( fRecordChanged || pArea->fCdxAppend ) && pArea->lpIndexes ) { LPCDXTAG pTag = pArea->lpIndexes->TagList; LPCDXKEY pKey = NULL; BOOL fAdd, fDel, fLck = FALSE; LPDBRELINFO lpdbPendingRel; - if ( pArea->fShared ) + if( pArea->fShared ) { - if ( fAppend ) + if( fAppend ) { - if ( pArea->fCdxAppend ) + if( pArea->fCdxAppend ) hb_cdxErrInternal( "hb_cdxGoCold: multiple appending without GOCOLD." ); pArea->fCdxAppend = TRUE; return HB_SUCCESS; @@ -7397,23 +7486,24 @@ static HB_ERRCODE hb_cdxGoCold( CDXAREAP pArea ) * Druzus, 05 Oct 2003 10:27:52 CEST */ - while ( pTag ) + while( pTag ) { - if ( !pTag->Custom ) + if( !pTag->Custom ) { pKey = hb_cdxKeyEval( pKey, pTag ); - if ( pTag->pForItem != NULL ) + if( pTag->pForItem != NULL ) fAdd = hb_cdxEvalCond( pArea, pTag->pForItem, TRUE ); else fAdd = TRUE; - if ( fAppend ) + if( fAppend ) fDel = FALSE; else { - if ( hb_cdxValCompare( pTag, pKey->val, pKey->len, - pTag->HotKey->val, pTag->HotKey->len, TRUE ) == 0 ) + if( hb_cdxValCompare( pTag, pKey->val, pKey->len, + pTag->HotKey->val, pTag->HotKey->len, + CDX_CMP_EXACT ) == 0 ) { fDel = !fAdd && pTag->HotFor; fAdd = fAdd && !pTag->HotFor; @@ -7423,36 +7513,36 @@ static HB_ERRCODE hb_cdxGoCold( CDXAREAP pArea ) fDel = pTag->HotFor; } } - if ( fDel || fAdd ) + if( fDel || fAdd ) { - if ( !fLck ) + if( !fLck ) { hb_cdxIndexLockWrite( pTag->pIndex ); fLck = TRUE; } - if ( fDel ) + if( fDel ) hb_cdxTagKeyDel( pTag, pTag->HotKey ); - if ( fAdd ) + if( fAdd ) hb_cdxTagKeyAdd( pTag, pKey ); } } - if ( pTag->pNext ) + if( pTag->pNext ) pTag = pTag->pNext; else { - if ( fLck ) + if( fLck ) { hb_cdxIndexUnLockWrite( pTag->pIndex ); fLck = FALSE; } - if ( pTag->pIndex->pNext ) + if( pTag->pIndex->pNext ) pTag = pTag->pIndex->pNext->TagList; else pTag = NULL; } } - if ( pKey ) + if( pKey ) hb_cdxKeyFree( pKey ); /* Restore disabled pending relation */ @@ -7471,28 +7561,28 @@ static HB_ERRCODE hb_cdxGoHot( CDXAREAP pArea ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxGoHot(%p)", pArea)); - if ( pArea->fRecordChanged ) + if( pArea->fRecordChanged ) hb_cdxErrInternal( "hb_cdxGoHot: multiple marking buffer as hot." ); - if ( SUPER_GOHOT( ( AREAP ) pArea ) == HB_FAILURE ) + if( SUPER_GOHOT( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( pArea->lpIndexes && !pArea->fCdxAppend ) + if( pArea->lpIndexes && !pArea->fCdxAppend ) { LPCDXTAG pTag = pArea->lpIndexes->TagList; - while ( pTag ) + while( pTag ) { - if ( !pTag->Custom ) + if( !pTag->Custom ) { pTag->HotKey = hb_cdxKeyEval( pTag->HotKey, pTag ); pTag->HotFor = pTag->pForItem == NULL || hb_cdxEvalCond( pArea, pTag->pForItem, TRUE ); } - if ( pTag->pNext ) + if( pTag->pNext ) pTag = pTag->pNext; else { - if ( pTag->pIndex->pNext ) + if( pTag->pIndex->pNext ) pTag = pTag->pIndex->pNext->TagList; else pTag = NULL; @@ -7505,31 +7595,31 @@ static HB_ERRCODE hb_cdxGoHot( CDXAREAP pArea ) /* ( DBENTRYP_P ) hb_cdxPutRec : NULL */ static HB_ERRCODE hb_cdxPutRec( CDXAREAP pArea, BYTE * pBuffer ) { - if ( SUPER_PUTREC( (AREAP) pArea, pBuffer ) == HB_SUCCESS ) + if( SUPER_PUTREC( (AREAP) pArea, pBuffer ) == HB_SUCCESS ) { - if ( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) + if( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) { pArea->dbfi.fFilter = FALSE; - if ( hb_cdxCheckRecordFilter( pArea, pArea->ulRecNo ) ) + if( hb_cdxCheckRecordFilter( pArea, pArea->ulRecNo ) ) { - if ( ! BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) + if( ! BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) { LPCDXTAG pTag; BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ); pTag = hb_cdxGetActiveTag( pArea ); - if ( pTag ) + if( pTag ) CURKEY_SETLOGCNT( pTag, pTag->logKeyCount + 1 ) } } else { - if ( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) + if( BM_GetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ) ) { LPCDXTAG pTag; BM_ClrBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ); pTag = hb_cdxGetActiveTag( pArea ); - if ( pTag ) + if( pTag ) CURKEY_SETLOGCNT( pTag, pTag->logKeyCount - 1 ) } } @@ -7544,12 +7634,12 @@ static HB_ERRCODE hb_cdxPutRec( CDXAREAP pArea, BYTE * pBuffer ) /* ( DBENTRYP_V ) hb_cdxRecall */ static HB_ERRCODE hb_cdxRecall( CDXAREAP pArea ) { - if ( SUPER_RECALL( (AREAP) pArea ) == HB_SUCCESS ) + if( SUPER_RECALL( (AREAP) pArea ) == HB_SUCCESS ) { - if ( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) + if( pArea->dbfi.fFilter && pArea->dbfi.fOptimized ) { pArea->dbfi.fFilter = FALSE; - if ( hb_cdxCheckRecordFilter( pArea, pArea->ulRecNo ) ) + if( hb_cdxCheckRecordFilter( pArea, pArea->ulRecNo ) ) BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ); else BM_ClrBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->Size, pArea->ulRecNo ); @@ -7578,21 +7668,21 @@ static HB_ERRCODE hb_cdxClose( CDXAREAP pArea ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxClose(%p)", pArea)); - if ( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; errCode = SUPER_CLOSE( ( AREAP ) pArea ); if( errCode == HB_SUCCESS ) { - if ( pArea->pSort ) + if( pArea->pSort ) { hb_cdxSortFree( pArea->pSort ); pArea->pSort = NULL; } hb_cdxOrdListClear( pArea, TRUE, NULL ); - if ( pArea->bCdxSortTab ) + if( pArea->bCdxSortTab ) { hb_xfree( pArea->bCdxSortTab ); pArea->bCdxSortTab = NULL; @@ -7638,7 +7728,7 @@ static HB_ERRCODE hb_cdxOpen( CDXAREAP pArea, LPDBOPENINFO pOpenInfo ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxOpen(%p, %p)", pArea, pOpenInfo)); - if ( !pArea->bLockType ) + if( !pArea->bLockType ) { PHB_ITEM pItem = hb_itemNew( NULL ); if( SELF_INFO( ( AREAP ) pArea, DBI_LOCKSCHEME, pItem ) != HB_SUCCESS ) @@ -7653,7 +7743,7 @@ static HB_ERRCODE hb_cdxOpen( CDXAREAP pArea, LPDBOPENINFO pOpenInfo ) pArea->bLockType = DB_DBFLOCK_VFP; } } - if ( SUPER_OPEN( ( AREAP ) pArea, pOpenInfo ) == HB_FAILURE ) + if( SUPER_OPEN( ( AREAP ) pArea, pOpenInfo ) == HB_FAILURE ) { return HB_FAILURE; } @@ -7665,8 +7755,8 @@ static HB_ERRCODE hb_cdxOpen( CDXAREAP pArea, LPDBOPENINFO pOpenInfo ) pArea->fHasTags = FALSE; hb_cdxCreateFName( pArea, NULL, NULL, szFileName, NULL ); - if ( hb_spFileExists( ( BYTE * ) szFileName, NULL ) || - DBFAREA_DATA( pArea )->fStrictStruct ) + if( hb_spFileExists( ( BYTE * ) szFileName, NULL ) || + DBFAREA_DATA( pArea )->fStrictStruct ) { DBORDERINFO pOrderInfo; @@ -7719,10 +7809,10 @@ static HB_ERRCODE hb_cdxPack( CDXAREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_cdxPack(%p)", pArea )); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( SUPER_PACK( ( AREAP ) pArea ) == HB_SUCCESS ) + if( SUPER_PACK( ( AREAP ) pArea ) == HB_SUCCESS ) { return SELF_ORDLSTREBUILD( ( AREAP ) pArea ); } @@ -7740,10 +7830,10 @@ static HB_ERRCODE hb_cdxZap ( CDXAREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("nb_cdxZap(%p)", pArea )); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( SUPER_ZAP( ( AREAP ) pArea ) == HB_SUCCESS ) + if( SUPER_ZAP( ( AREAP ) pArea ) == HB_SUCCESS ) { return SELF_ORDLSTREBUILD( ( AREAP ) pArea ); } @@ -7775,25 +7865,25 @@ static HB_ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxOrderListAdd(%p, %p)", pArea, pOrderInfo)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( hb_itemGetCLen( pOrderInfo->atomBagName ) == 0 ) + if( hb_itemGetCLen( pOrderInfo->atomBagName ) == 0 ) return HB_FAILURE; hb_cdxCreateFName( pArea, hb_itemGetCPtr( pOrderInfo->atomBagName ), &fProd, szFileName, szBaseName ); /* - if ( ! szBaseName[0] ) + if( ! szBaseName[0] ) return HB_FAILURE; */ pIndex = hb_cdxFindBag( pArea, szFileName ); - if ( pIndex ) + if( pIndex ) { /* index already open, do nothing */ - if ( ! pArea->uiTag ) + if( ! pArea->uiTag ) { pArea->uiTag = hb_cdxGetTagNumber( pArea, pIndex->TagList ); SELF_GOTOP( ( AREAP ) pArea ); @@ -7841,11 +7931,11 @@ static HB_ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) pIndex->szFileName = hb_strdup( szFileName ); pIndexPtr = &pArea->lpIndexes; - while ( *pIndexPtr != NULL ) + while( *pIndexPtr != NULL ) pIndexPtr = &( *pIndexPtr )->pNext; *pIndexPtr = pIndex; - if ( ! hb_cdxIndexLoad( pIndex, szBaseName ) ) + if( ! hb_cdxIndexLoad( pIndex, szBaseName ) ) { /* index file is corrupted */ *pIndexPtr = NULL; @@ -7862,7 +7952,7 @@ static HB_ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) * This is the behaviour of Clipper's bmdbfcdx, although * Clipper doc says a different rule */ - if ( ! pArea->uiTag ) + if( ! pArea->uiTag ) { pArea->uiTag = hb_cdxGetTagNumber( pArea, pIndex->TagList ); SELF_GOTOP( ( AREAP ) pArea ); @@ -7878,7 +7968,7 @@ static HB_ERRCODE hb_cdxOrderListClear( CDXAREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_cdxOrderListClear(%p)", pArea)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; hb_cdxOrdListClear( pArea, !( DBFAREA_DATA( pArea )->fStrictStruct ? @@ -7937,17 +8027,17 @@ static HB_ERRCODE hb_cdxOrderListFocus( CDXAREAP pArea, LPDBORDERINFO pOrderInfo HB_TRACE(HB_TR_DEBUG, ("hb_cdxOrderListFocus(%p, %p)", pArea, pOrderInfo)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( ! pArea->lpIndexes ) + if( ! pArea->lpIndexes ) return HB_SUCCESS; pTag = hb_cdxGetActiveTag( pArea ); - if ( pTag ) + if( pTag ) pOrderInfo->itmResult = hb_itemPutC( pOrderInfo->itmResult, pTag->szName ); - if ( pOrderInfo->itmOrder ) + if( pOrderInfo->itmOrder ) { hb_cdxFindTag( pArea, pOrderInfo->itmOrder, pOrderInfo->atomBagName, &(pArea->uiTag) ); /* TODO: RTerror if not found? */ @@ -7964,21 +8054,21 @@ static HB_ERRCODE hb_cdxOrderListRebuild( CDXAREAP pArea ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxPack(%p)", pArea )); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( pArea->fShared ) + if( pArea->fShared ) { hb_cdxErrorRT( pArea, EG_SHARED, EDBF_SHARED, pArea->szDataFileName, 0, 0, NULL ); return HB_FAILURE; } - if ( pArea->fReadonly ) + if( pArea->fReadonly ) { hb_cdxErrorRT( pArea, EG_READONLY, EDBF_READONLY, pArea->szDataFileName, 0, 0, NULL ); return HB_FAILURE; } - if ( ! pArea->lpIndexes ) + if( ! pArea->lpIndexes ) return HB_SUCCESS; uiPrevTag = pArea->uiTag; @@ -7987,7 +8077,7 @@ static HB_ERRCODE hb_cdxOrderListRebuild( CDXAREAP pArea ) pIndex = pArea->lpIndexes; pArea->lpIndexes = NULL; pIndexPtr = &pArea->lpIndexes; - while ( pIndex ) + while( pIndex ) { (*pIndexPtr) = pIndex; pIndex = pIndex->pNext; @@ -8012,8 +8102,8 @@ static HB_ERRCODE hb_cdxOrderListRebuild( CDXAREAP pArea ) static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo ) { ULONG ulRecNo; - BOOL fNewFile, fOpenedIndex, fProd, fAscend = TRUE, fCustom = FALSE, - fTemporary = FALSE, fExclusive = FALSE; + BOOL fNewFile, fOpenedIndex, fProd, fAscend = TRUE, fNoCase = FALSE, + fCustom = FALSE, fTemporary = FALSE, fExclusive = FALSE; PHB_ITEM pKeyExp, pForExp = NULL, pResult; char szCpndTagName[ CDX_MAXTAGNAMELEN + 1 ], szTagName[ CDX_MAXTAGNAMELEN + 1 ]; char szFileName[ HB_PATH_MAX ], szTempFile[ HB_PATH_MAX ]; @@ -8077,10 +8167,11 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI pArea->valResult = NULL; bType = hb_cdxItemType( pResult ); - switch ( bType ) + switch( bType ) { case 'N': case 'D': + case 'T': uiLen = 8; break; case 'L': @@ -8096,7 +8187,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI hb_itemRelease( pResult ); /* Make sure KEY has proper type and iLen lower than 240 */ - if ( bType == 'C' && uiLen > CDX_MAXKEY ) + if( bType == 'C' && uiLen > CDX_MAXKEY ) { if( hb_cdxErrorRT( pArea, EG_DATAWIDTH, EDBF_INVALIDKEY, NULL, 0, EF_CANDEFAULT, NULL ) == E_DEFAULT ) uiLen = CDX_MAXKEY; @@ -8108,7 +8199,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI } } /* Make sure KEY has proper type and iLen is not 0 */ - else if ( bType == 'U' || uiLen == 0 ) + else if( bType == 'U' || uiLen == 0 ) { hb_vmDestroyBlockOrMacro( pKeyExp ); SELF_GOTO( ( AREAP ) pArea, ulRecNo ); @@ -8149,11 +8240,11 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI fTemporary = TRUE; /* Test conditional expression */ - if ( pForExp ) + if( pForExp ) { BOOL fOK; - if ( SELF_EVALBLOCK( ( AREAP ) pArea, pForExp ) == HB_FAILURE ) + if( SELF_EVALBLOCK( ( AREAP ) pArea, pForExp ) == HB_FAILURE ) { hb_vmDestroyBlockOrMacro( pKeyExp ); hb_vmDestroyBlockOrMacro( pForExp ); @@ -8163,7 +8254,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI fOK = hb_itemType( pArea->valResult ) == HB_IT_LOGICAL; hb_itemRelease( pArea->valResult ); pArea->valResult = NULL; - if ( ! fOK ) + if( ! fOK ) { hb_vmDestroyBlockOrMacro( pKeyExp ); hb_vmDestroyBlockOrMacro( pForExp ); @@ -8186,7 +8277,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI hb_cdxCreateFName( pArea, ( char * ) pOrderInfo->abBagName, &fProd, szFileName, szCpndTagName ); - if ( pOrderInfo->atomBagName && pOrderInfo->atomBagName[0] ) + if( pOrderInfo->atomBagName && pOrderInfo->atomBagName[0] ) { hb_strncpyUpperTrim( szTagName, ( char * ) pOrderInfo->atomBagName, sizeof( szTagName ) - 1 ); fNewFile = FALSE; @@ -8197,19 +8288,19 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI fNewFile = TRUE; } - if ( !pArea->lpdbOrdCondInfo || - ( pArea->lpdbOrdCondInfo->fAll && !pArea->lpdbOrdCondInfo->fAdditive ) ) + if( !pArea->lpdbOrdCondInfo || + ( pArea->lpdbOrdCondInfo->fAll && !pArea->lpdbOrdCondInfo->fAdditive ) ) hb_cdxOrdListClear( pArea, !( DBFAREA_DATA( pArea )->fStrictStruct ? pArea->fHasTags : hb_setGetAutOpen() ), NULL ); pIndex = hb_cdxFindBag( pArea, szFileName ); - if ( fNewFile && pIndex != NULL ) + if( fNewFile && pIndex != NULL ) { LPCDXINDEX * pIndexPtr = &pArea->lpIndexes; - while ( *pIndexPtr ) + while( *pIndexPtr ) { - if ( pIndex == *pIndexPtr ) + if( pIndex == *pIndexPtr ) { *pIndexPtr = pIndex->pNext; break; @@ -8221,7 +8312,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI } fOpenedIndex = ( pIndex != NULL ); - if ( !fOpenedIndex ) + if( !fOpenedIndex ) { PHB_FILE pFile; BOOL bRetry, fShared = pArea->fShared && !fTemporary && !fExclusive; @@ -8269,10 +8360,10 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI if( fTemporary ) pIndex->szRealName = hb_strdup( szTempFile ); - if ( !fNewFile ) + if( !fNewFile ) { /* index file is corrupted? */ - if ( ! hb_cdxIndexLoad( pIndex, szCpndTagName ) ) + if( ! hb_cdxIndexLoad( pIndex, szCpndTagName ) ) { /* TODO: What should be default? */ /* @@ -8291,26 +8382,26 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI if( !pFile ) { hb_vmDestroyBlockOrMacro( pKeyExp ); - if ( pForExp != NULL ) + if( pForExp != NULL ) hb_vmDestroyBlockOrMacro( pForExp ); return HB_FAILURE; } } hb_cdxIndexLockWrite( pIndex ); - if ( !fNewFile ) + if( !fNewFile ) { /* Delete new tag if exist */ hb_cdxIndexDelTag( pIndex, szTagName ); fNewFile = ( pIndex->TagList == NULL ); } - if ( fNewFile ) + if( fNewFile ) { hb_fileTruncAt( pIndex->pFile, 0 ); pIndex->fChanged = TRUE; hb_cdxIndexDropAvailPage( pIndex ); - if ( pIndex->pCompound != NULL ) + if( pIndex->pCompound != NULL ) hb_cdxTagFree( pIndex->pCompound ); pIndex->nextAvail = pIndex->freePage = 0; hb_cdxIndexCreateStruct( pIndex, szCpndTagName ); @@ -8318,10 +8409,10 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI pTag = hb_cdxIndexAddTag( pIndex, szTagName, hb_itemGetCPtr( pOrderInfo->abExpr ), pKeyExp, bType, uiLen, szFor, pForExp, - fAscend , pOrderInfo->fUnique, fCustom, FALSE ); + fAscend , pOrderInfo->fUnique, fNoCase, fCustom, FALSE ); - if ( pArea->lpdbOrdCondInfo && ( !pArea->lpdbOrdCondInfo->fAll && - !pArea->lpdbOrdCondInfo->fAdditive ) ) + if( pArea->lpdbOrdCondInfo && ( !pArea->lpdbOrdCondInfo->fAll && + !pArea->lpdbOrdCondInfo->fAdditive ) ) { hb_cdxOrdListClear( pArea, !( DBFAREA_DATA( pArea )->fStrictStruct ? pArea->fHasTags : hb_setGetAutOpen() ), NULL ); @@ -8331,8 +8422,8 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI if( !pArea->fHasTags && !fOpenedIndex && !pIndex->fDelete && fProd ) { pArea->fHasTags = TRUE; - if ( !pArea->fReadonly && ( pArea->dbfHeader.bHasTags & 0x01 ) == 0 && - ( hb_setGetAutOpen() || DBFAREA_DATA( pArea )->fStrictStruct ) ) + if( !pArea->fReadonly && ( pArea->dbfHeader.bHasTags & 0x01 ) == 0 && + ( hb_setGetAutOpen() || DBFAREA_DATA( pArea )->fStrictStruct ) ) SELF_WRITEDBHEADER( ( AREAP ) pArea ); } else @@ -8342,7 +8433,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI if( !fOpenedIndex ) { - if ( fProd || pArea->lpIndexes == NULL ) + if( fProd || pArea->lpIndexes == NULL ) { pIndex->pNext = pArea->lpIndexes; pArea->lpIndexes = pIndex; @@ -8350,7 +8441,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI else { LPCDXINDEX pIndexTmp = pArea->lpIndexes; - while ( pIndexTmp->pNext ) + while( pIndexTmp->pNext ) pIndexTmp = pIndexTmp->pNext; pIndexTmp->pNext = pIndex; } @@ -8373,10 +8464,10 @@ static HB_ERRCODE hb_cdxOrderDestroy( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) HB_TRACE(HB_TR_DEBUG, ("hb_cdxOrderDestroy(%p, %p)", pArea, pOrderInfo)); - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( ! pArea->lpIndexes ) + if( ! pArea->lpIndexes ) return HB_SUCCESS; if( pOrderInfo->itmOrder ) @@ -8385,33 +8476,32 @@ static HB_ERRCODE hb_cdxOrderDestroy( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) if( pTag ) { pIndex = pTag->pIndex; - if ( /* !pIndex->fShared && */ !pIndex->fReadonly ) + if( /* !pIndex->fShared && */ !pIndex->fReadonly ) { hb_cdxIndexLockWrite( pIndex ); hb_cdxIndexDelTag( pIndex, pTag->szName ); hb_cdxIndexUnLockWrite( pIndex ); - if ( !pIndex->TagList ) + if( !pIndex->TagList ) { - if ( pArea->lpIndexes == pIndex ) + if( pArea->lpIndexes == pIndex ) { pArea->lpIndexes = pIndex->pNext; - if ( pArea->fHasTags ) + if( pArea->fHasTags ) { pArea->fHasTags = FALSE; - if ( !pArea->fReadonly && ( pArea->dbfHeader.bHasTags & 0x01 ) != 0 && - ( hb_setGetAutOpen() || - DBFAREA_DATA( pArea )->fStrictStruct ) ) + if( !pArea->fReadonly && ( pArea->dbfHeader.bHasTags & 0x01 ) != 0 && + ( hb_setGetAutOpen() || DBFAREA_DATA( pArea )->fStrictStruct ) ) SELF_WRITEDBHEADER( ( AREAP ) pArea ); } } else { pIndexTmp = pArea->lpIndexes; - while ( pIndexTmp->pNext && ( pIndexTmp->pNext != pIndex ) ) + while( pIndexTmp->pNext && ( pIndexTmp->pNext != pIndex ) ) { pIndexTmp = pIndexTmp->pNext; } - if ( pIndexTmp->pNext == pIndex ) + if( pIndexTmp->pNext == pIndex ) { pIndexTmp->pNext = pIndex->pNext; } @@ -8520,7 +8610,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO HB_FOFFSET ulPos, ulPool; hb_dbfLockIdxGetData( pArea->bLockType, &ulPos, &ulPool ); - if ( uiIndex == DBOI_LOCKOFFSET ) + if( uiIndex == DBOI_LOCKOFFSET ) pInfo->itmResult = hb_itemPutNInt( pInfo->itmResult, ulPos ); else pInfo->itmResult = hb_itemPutL( pInfo->itmResult, ulPool > 0 ); @@ -8533,10 +8623,10 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO char *pszBag = hb_itemGetCLen( pInfo->atomBagName ) > 0 ? hb_itemGetCPtr( pInfo->atomBagName ) : NULL; pIndex = pszBag ? hb_cdxFindBag( pArea, pszBag ) : pArea->lpIndexes; - while ( pIndex ) + while( pIndex ) { pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { ++uiTag; pTag = pTag->pNext; @@ -8550,7 +8640,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO case DBOI_BAGCOUNT: { LPCDXINDEX pIndex = pArea->lpIndexes; - while ( pIndex ) + while( pIndex ) { ++uiTag; pIndex = pIndex->pNext; @@ -8581,7 +8671,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; pIndex = pIndex->pNext; } - while ( pIndex ); + while( pIndex ); } pInfo->itmResult = hb_itemPutNI( pInfo->itmResult, pIndex ? uiTag : 0 ); @@ -8609,14 +8699,14 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO if( pIndex == pIndexSeek ) break; pTag = pIndex->TagList; - while ( pTag ) + while( pTag ) { ++uiTag; pTag = pTag->pNext; } pIndex = pIndex->pNext; } - while ( pIndex ); + while( pIndex ); } pInfo->itmResult = hb_itemPutNI( pInfo->itmResult, pIndex ? uiTag : 0 ); @@ -8641,29 +8731,29 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO { case DBOI_CONDITION: pInfo->itmResult = hb_itemPutC( pInfo->itmResult, pTag ? pTag->ForExpr : NULL ); - if ( pTag && pInfo->itmNewVal && HB_IS_STRING( pInfo->itmNewVal ) ) + if( pTag && pInfo->itmNewVal && HB_IS_STRING( pInfo->itmNewVal ) ) { - if ( pTag->ForExpr != NULL ) + if( pTag->ForExpr != NULL ) { hb_xfree( pTag->ForExpr ); pTag->ForExpr = NULL; } - if ( pTag->pForItem != NULL ) + if( pTag->pForItem != NULL ) { hb_vmDestroyBlockOrMacro( pTag->pForItem ); pTag->pForItem = NULL; } - if ( hb_itemGetCLen( pInfo->itmNewVal ) > 0 ) + if( hb_itemGetCLen( pInfo->itmNewVal ) > 0 ) { char * pForExpr = hb_itemGetCPtr( pInfo->itmNewVal ); - if ( SELF_COMPILE( ( AREAP ) pArea, ( BYTE *) pForExpr ) == HB_SUCCESS ) + if( SELF_COMPILE( ( AREAP ) pArea, ( BYTE *) pForExpr ) == HB_SUCCESS ) { PHB_ITEM pForItem = pArea->valResult; pArea->valResult = NULL; - if ( SELF_EVALBLOCK( ( AREAP ) pArea, pForItem ) == HB_SUCCESS ) + if( SELF_EVALBLOCK( ( AREAP ) pArea, pForItem ) == HB_SUCCESS ) { - if ( hb_itemType( pArea->valResult ) == HB_IT_LOGICAL ) + if( hb_itemType( pArea->valResult ) == HB_IT_LOGICAL ) { pTag->pForItem = pForItem; pForItem = NULL; @@ -8671,7 +8761,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO hb_itemRelease( pArea->valResult ); pArea->valResult = NULL; } - if ( pForItem ) + if( pForItem ) hb_vmDestroyBlockOrMacro( pForItem ); } } @@ -8683,7 +8773,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_POSITION: - if ( pInfo->itmNewVal && HB_IS_NUMERIC( pInfo->itmNewVal ) ) + if( pInfo->itmNewVal && HB_IS_NUMERIC( pInfo->itmNewVal ) ) { pInfo->itmResult = hb_itemPutL( pInfo->itmResult, hb_cdxDBOIKeyGoto( pArea, pTag, @@ -8697,7 +8787,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO /* TODO: is this ok? DBOI_RECNO == DBOI_KEYNORAW ? No, it isn't. */ /* case DBOI_RECNO: */ case DBOI_KEYNORAW: - if ( pInfo->itmNewVal && HB_IS_NUMERIC( pInfo->itmNewVal ) ) + if( pInfo->itmNewVal && HB_IS_NUMERIC( pInfo->itmNewVal ) ) { pInfo->itmResult = hb_itemPutL( pInfo->itmResult, hb_cdxDBOIKeyGoto( pArea, pTag, @@ -8719,7 +8809,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_RELKEYPOS: - if ( pInfo->itmNewVal && HB_IS_NUMERIC( pInfo->itmNewVal ) ) + if( pInfo->itmNewVal && HB_IS_NUMERIC( pInfo->itmNewVal ) ) hb_cdxDBOISetRelKeyPos( pArea, pTag, hb_itemGetND( pInfo->itmNewVal ) ); else @@ -8776,9 +8866,9 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_SCOPEEVAL: - if ( pTag && pInfo->itmNewVal && - hb_arrayLen( pInfo->itmNewVal ) == DBRMI_SIZE && - hb_arrayGetPtr( pInfo->itmNewVal, DBRMI_FUNCTION ) != NULL ) + if( pTag && pInfo->itmNewVal && + hb_arrayLen( pInfo->itmNewVal ) == DBRMI_SIZE && + hb_arrayGetPtr( pInfo->itmNewVal, DBRMI_FUNCTION ) != NULL ) { pInfo->itmResult = hb_itemPutNL( pInfo->itmResult, hb_cdxDBOIScopeEval( pTag, ( HB_EVALSCOPE_FUNC ) @@ -8803,7 +8893,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_BAGNAME: - if ( pTag ) + if( pTag ) { PHB_FNAME pFileName = hb_fsFNameSplit( pTag->pIndex->szFileName ); pInfo->itmResult = hb_itemPutC( pInfo->itmResult, pFileName->szName ); @@ -8828,7 +8918,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO case DBOI_ISDESC: pInfo->itmResult = hb_itemPutL( pInfo->itmResult, pTag && !pTag->UsrAscend ); - if ( pTag && pInfo->itmNewVal && HB_IS_LOGICAL( pInfo->itmNewVal ) ) + if( pTag && pInfo->itmNewVal && HB_IS_LOGICAL( pInfo->itmNewVal ) ) { pTag->UsrAscend = ! hb_itemGetL( pInfo->itmNewVal ); pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS ); @@ -8837,7 +8927,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO case DBOI_UNIQUE: pInfo->itmResult = hb_itemPutL( pInfo->itmResult, ( pTag ? pTag->UniqueKey || pTag->UsrUnique : FALSE ) ); - if ( pTag && pInfo->itmNewVal && HB_IS_LOGICAL( pInfo->itmNewVal ) && !pTag->UniqueKey ) + if( pTag && pInfo->itmNewVal && HB_IS_LOGICAL( pInfo->itmNewVal ) && !pTag->UniqueKey ) { pTag->UsrUnique = hb_itemGetL( pInfo->itmNewVal ); pTag->curKeyState &= ~( CDX_CURKEY_RAWPOS | CDX_CURKEY_LOGPOS | @@ -8846,7 +8936,7 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_KEYTYPE: - if ( pTag ) + if( pTag ) { char szType[2]; szType[0] = (char) pTag->uiType; @@ -8871,86 +8961,86 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO hb_itemClear( pInfo->itmResult ); if( pArea->lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); - if ( pTag && pArea->fPositioned ) + if( pTag && pArea->fPositioned ) { - if ( pTag->CurKey->rec != pArea->ulRecNo ) + if( pTag->CurKey->rec != pArea->ulRecNo ) { hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxCurKeyRefresh( pArea, pTag ); hb_cdxIndexUnLockRead( pTag->pIndex ); } - if ( pTag->CurKey->rec == pArea->ulRecNo ) + if( pTag->CurKey->rec == pArea->ulRecNo ) pInfo->itmResult = hb_cdxKeyGetItem( pTag->CurKey, pInfo->itmResult, pTag, TRUE ); } break; case DBOI_SCOPETOP: - if ( pTag ) + if( pTag ) { - if ( pInfo->itmResult ) + if( pInfo->itmResult ) hb_cdxTagGetScope( pTag, 0, pInfo->itmResult ); - if ( pInfo->itmNewVal ) + if( pInfo->itmNewVal ) hb_cdxTagSetScope( pTag, 0, pInfo->itmNewVal ); } - else if ( pInfo->itmResult ) + else if( pInfo->itmResult ) hb_itemClear( pInfo->itmResult ); break; case DBOI_SCOPEBOTTOM: - if ( pTag ) + if( pTag ) { - if ( pInfo->itmResult ) + if( pInfo->itmResult ) hb_cdxTagGetScope( pTag, 1, pInfo->itmResult ); - if ( pInfo->itmNewVal ) + if( pInfo->itmNewVal ) hb_cdxTagSetScope( pTag, 1, pInfo->itmNewVal ); } - else if ( pInfo->itmResult ) + else if( pInfo->itmResult ) hb_itemClear( pInfo->itmResult ); break; case DBOI_SCOPESET: - if ( pTag ) + if( pTag ) { - if ( pInfo->itmNewVal ) + if( pInfo->itmNewVal ) { hb_cdxTagSetScope( pTag, 0, pInfo->itmNewVal ); hb_cdxTagSetScope( pTag, 1, pInfo->itmNewVal ); } } - if ( pInfo->itmResult ) + if( pInfo->itmResult ) hb_itemClear( pInfo->itmResult ); break; case DBOI_SCOPETOPCLEAR: - if ( pTag ) + if( pTag ) { - if ( pInfo->itmResult ) + if( pInfo->itmResult ) hb_cdxTagGetScope( pTag, 0, pInfo->itmResult ); hb_cdxTagClearScope( pTag, 0 ); } - else if ( pInfo->itmResult ) + else if( pInfo->itmResult ) hb_itemClear( pInfo->itmResult ); break; case DBOI_SCOPEBOTTOMCLEAR: - if ( pTag ) + if( pTag ) { - if ( pInfo->itmResult ) + if( pInfo->itmResult ) hb_cdxTagGetScope( pTag, 1, pInfo->itmResult ); hb_cdxTagClearScope( pTag, 1 ); } - else if ( pInfo->itmResult ) + else if( pInfo->itmResult ) hb_itemClear( pInfo->itmResult ); break; case DBOI_SCOPECLEAR: - if ( pTag ) + if( pTag ) { hb_cdxTagClearScope( pTag, 0 ); hb_cdxTagClearScope( pTag, 1 ); } - if ( pInfo->itmResult ) + if( pInfo->itmResult ) hb_itemClear( pInfo->itmResult ); break; @@ -9022,13 +9112,13 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_KEYADD: - if ( !pTag ) + if( !pTag ) { pInfo->itmResult = hb_itemPutL( pInfo->itmResult, FALSE ); } else { - if ( pTag->Custom ) + if( pTag->Custom ) { if( pArea->lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); @@ -9043,9 +9133,11 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO { LPCDXKEY pKey; hb_cdxIndexLockWrite( pTag->pIndex ); - if ( pInfo->itmNewVal && !HB_IS_NIL( pInfo->itmNewVal ) && - pTag->Template ) - pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, pArea->ulRecNo, pTag, TRUE, TRUE ); + if( pInfo->itmNewVal && !HB_IS_NIL( pInfo->itmNewVal ) && + pTag->Template ) + pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, + pArea->ulRecNo, pTag, + TRUE, CDX_CMP_EXACT ); else pKey = hb_cdxKeyEval( NULL, pTag ); pInfo->itmResult = hb_itemPutL( pInfo->itmResult, @@ -9062,13 +9154,13 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO break; case DBOI_KEYDELETE: - if ( !pTag ) + if( !pTag ) { pInfo->itmResult = hb_itemPutL( pInfo->itmResult, FALSE ); } else { - if ( pTag->Custom ) + if( pTag->Custom ) { if( pArea->lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); @@ -9083,15 +9175,17 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO { LPCDXKEY pKey; hb_cdxIndexLockWrite( pTag->pIndex ); - if ( pInfo->itmNewVal && !HB_IS_NIL( pInfo->itmNewVal ) && - pTag->Template ) - pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, pArea->ulRecNo, pTag, TRUE, TRUE ); + if( pInfo->itmNewVal && !HB_IS_NIL( pInfo->itmNewVal ) && + pTag->Template ) + pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, + pArea->ulRecNo, pTag, + TRUE, CDX_CMP_EXACT ); else { - if ( pTag->CurKey->rec != pArea->ulRecNo ) + if( pTag->CurKey->rec != pArea->ulRecNo ) hb_cdxCurKeyRefresh( pArea, pTag ); - if ( pTag->CurKey->rec == pArea->ulRecNo ) + if( pTag->CurKey->rec == pArea->ulRecNo ) pKey = hb_cdxKeyCopy( NULL, pTag->CurKey ); else pKey = hb_cdxKeyEval( NULL, pTag ); @@ -9192,7 +9286,7 @@ static HB_ERRCODE hb_cdxClearFilter( CDXAREAP pArea ) { hb_cdxClearLogPosInfo( pArea ); /* Limpiamos filtro tipo array */ - if ( pArea->dbfi.lpvCargo ) + if( pArea->dbfi.lpvCargo ) { hb_xfree( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap ); hb_xfree( pArea->dbfi.lpvCargo ); @@ -9209,7 +9303,7 @@ static HB_ERRCODE hb_cdxCountScope( CDXAREAP pArea, void * pPtr, LONG * plRec ) { HB_TRACE(HB_TR_DEBUG, ("hb_cdxCountScope(%p, %p, %p)", pArea, pPtr, plRec)); - if ( pPtr == NULL ) + if( pPtr == NULL ) { LPBM_FILTER pMap = (LPBM_FILTER) pArea->dbfi.lpvCargo; if( pArea->dbfi.fFilter && pMap && @@ -9236,12 +9330,12 @@ static HB_ERRCODE hb_cdxSetFilter( CDXAREAP pArea, LPDBFILTERINFO pFilterInfo ) hb_cdxClearLogPosInfo( pArea ); - if ( SUPER_SETFILTER( ( AREAP ) pArea, pFilterInfo ) != HB_SUCCESS ) + if( SUPER_SETFILTER( ( AREAP ) pArea, pFilterInfo ) != HB_SUCCESS ) return HB_FAILURE; pArea->dbfi.fOptimized = hb_setGetOptimize(); - if ( pArea->dbfi.fOptimized ) + if( pArea->dbfi.fOptimized ) { pArea->dbfi.lpvCargo = hb_xgrab( sizeof( BM_FILTER ) ); memset( pArea->dbfi.lpvCargo, 0, sizeof( BM_FILTER ) ); @@ -9254,21 +9348,21 @@ static HB_ERRCODE hb_cdxSetFilter( CDXAREAP pArea, LPDBFILTERINFO pFilterInfo ) ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap = (ULONG *) hb_xgrab( sizeof(ULONG) * (((ulRecCount+1) >> 5) + 1 ) ); memset( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, 0, sizeof(ULONG) * (((ulRecCount+1) >> 5) + 1 ) ); - if ( pTag ) /* with active index */ + if( pTag ) /* with active index */ { - if ( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) + if( FAST_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; hb_cdxIndexLockRead( pTag->pIndex ); hb_cdxTagRefreshScope( pTag ); hb_cdxTagGoTop( pTag ); ulLogKeyCount = 0; - while ( !pTag->TagEOF ) + while( !pTag->TagEOF ) { if( pArea->ulRecNo != pTag->CurKey->rec || pArea->lpdbPendingRel ) SELF_GOTO( (AREAP) pArea, pTag->CurKey->rec ); pResult = hb_vmEvalBlock( pArea->dbfi.itmCobExpr ); - if ( HB_IS_LOGICAL( pResult ) && hb_itemGetL( pResult ) ) + if( HB_IS_LOGICAL( pResult ) && hb_itemGetL( pResult ) ) { BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ulRecCount, pTag->CurKey->rec ); ulLogKeyCount++; @@ -9282,10 +9376,10 @@ static HB_ERRCODE hb_cdxSetFilter( CDXAREAP pArea, LPDBFILTERINFO pFilterInfo ) else { SELF_GOTOP( ( AREAP ) pArea ); - while ( ! pArea->fEof ) + while( ! pArea->fEof ) { pResult = hb_vmEvalBlock( pArea->dbfi.itmCobExpr ); - if ( HB_IS_LOGICAL( pResult ) && hb_itemGetL( pResult ) ) + if( HB_IS_LOGICAL( pResult ) && hb_itemGetL( pResult ) ) BM_SetBit( ( ( LPBM_FILTER ) pArea->dbfi.lpvCargo)->rmap, ulRecCount, (pArea)->ulRecNo ); SELF_SKIP( ( AREAP ) pArea, 1 ); } @@ -9385,9 +9479,9 @@ static int hb_cdxQuickSortCompare( LPCDXSORTINFO pSort, BYTE * pKey1, BYTE * pKe { int i, iLen = pSort->keyLen; - i = hb_cdxValCompare( pSort->pTag, pKey1, iLen, pKey2, iLen, TRUE ); + i = hb_cdxValCompare( pSort->pTag, pKey1, iLen, pKey2, iLen, CDX_CMP_EXACT ); - if ( i == 0 ) + if( i == 0 ) { i = ( HB_GET_LE_UINT32( pKey1 + iLen ) < HB_GET_LE_UINT32( pKey2 + iLen ) ) ? -1 : 1; } @@ -9397,7 +9491,7 @@ static int hb_cdxQuickSortCompare( LPCDXSORTINFO pSort, BYTE * pKey1, BYTE * pKe static BOOL hb_cdxQSort( LPCDXSORTINFO pSort, BYTE * pSrc, BYTE * pBuf, LONG lKeys ) { - if ( lKeys > 1 ) + if( lKeys > 1 ) { int iLen = pSort->keyLen + 4; LONG l1, l2; @@ -9411,7 +9505,7 @@ static BOOL hb_cdxQSort( LPCDXSORTINFO pSort, BYTE * pSrc, BYTE * pBuf, LONG lKe f1 = hb_cdxQSort( pSort, pPtr1, &pBuf[ 0 ], l1 ); f2 = hb_cdxQSort( pSort, pPtr2, &pBuf[ l1 * iLen ], l2 ); - if ( f1 ) + if( f1 ) { pDst = pBuf; } @@ -9420,13 +9514,13 @@ static BOOL hb_cdxQSort( LPCDXSORTINFO pSort, BYTE * pSrc, BYTE * pBuf, LONG lKe pDst = pSrc; pPtr1 = &pBuf[ 0 ]; } - if ( !f2 ) + if( !f2 ) { pPtr2 = &pBuf[ l1 * iLen ]; } - while ( l1 > 0 && l2 > 0 ) + while( l1 > 0 && l2 > 0 ) { - if ( hb_cdxQuickSortCompare( pSort, pPtr1, pPtr2 ) <= 0 ) + if( hb_cdxQuickSortCompare( pSort, pPtr1, pPtr2 ) <= 0 ) { memcpy( pDst, pPtr1, iLen ); pPtr1 += iLen; @@ -9440,11 +9534,11 @@ static BOOL hb_cdxQSort( LPCDXSORTINFO pSort, BYTE * pSrc, BYTE * pBuf, LONG lKe } pDst += iLen; } - if ( l1 > 0 ) + if( l1 > 0 ) { memcpy( pDst, pPtr1, iLen * l1 ); } - else if ( l2 > 0 && f1 == f2 ) + else if( l2 > 0 && f1 == f2 ) { memcpy( pDst, pPtr2, iLen * l2 ); } @@ -9459,7 +9553,7 @@ static void hb_cdxSortSortPage( LPCDXSORTINFO pSort ) #ifdef HB_CDX_DBGTIME cdxTimeIdxBld -= hb_cdxGetTime(); #endif - if ( !hb_cdxQSort( pSort, pSort->pKeyPool, &pSort->pKeyPool[ ulSize ], pSort->ulKeys ) ) + if( !hb_cdxQSort( pSort, pSort->pKeyPool, &pSort->pKeyPool[ ulSize ], pSort->ulKeys ) ) { memcpy( pSort->pKeyPool, &pSort->pKeyPool[ ulSize ], ulSize ); } @@ -9476,20 +9570,20 @@ static void hb_cdxSortAddNodeKey( LPCDXSORTINFO pSort, int iLevel, BYTE *pKeyVal BYTE *pTmp; pPage = pSort->NodeList[ iLevel ]; - if ( iLevel == 0 ) + if( iLevel == 0 ) { - while ( iTrl < iLen && pKeyVal[ iLen - iTrl - 1 ] == pSort->bTrl ) + while( iTrl < iLen && pKeyVal[ iLen - iTrl - 1 ] == pSort->bTrl ) { iTrl++; } - if ( pPage != NULL && pPage->iKeys > 0 ) + if( pPage != NULL && pPage->iKeys > 0 ) { #ifdef HB_CDX_PACKTRAIL int iMax = iLen - iTrl; #else int iMax = iLen - HB_MAX( iTrl, pSort->iLastTrl ); #endif - while ( pKeyVal[ iDup ] == pSort->pLastKey[ iDup ] && iDup < iMax ) + while( pKeyVal[ iDup ] == pSort->pLastKey[ iDup ] && iDup < iMax ) { iDup++; } @@ -9504,7 +9598,7 @@ static void hb_cdxSortAddNodeKey( LPCDXSORTINFO pSort, int iLevel, BYTE *pKeyVal } else { - if ( iLevel == 0 ) + if( iLevel == 0 ) { fNew = ( pPage->iFree - ( iLen - iDup - iTrl ) - pPage->ReqByte ) < 0; } @@ -9518,22 +9612,22 @@ static void hb_cdxSortAddNodeKey( LPCDXSORTINFO pSort, int iLevel, BYTE *pKeyVal { pPage = hb_cdxPageNew( pSort->pTag, NULL, 0 ); pPage->PageType = ( iLevel == 0 ) ? CDX_NODE_LEAF : CDX_NODE_BRANCH; - if ( iLevel == 0 ) + if( iLevel == 0 ) { hb_cdxPageLeafInitSpace( pPage ); iDup = 0; - while ( pSort->ulMaxRec > pPage->RNMask ) + while( pSort->ulMaxRec > pPage->RNMask ) { pPage->ReqByte++; pPage->RNBits += 8; pPage->RNMask = ( pPage->RNMask << 8 ) | 0xFF; } } - if ( pSort->NodeList[ iLevel ] != NULL ) + if( pSort->NodeList[ iLevel ] != NULL ) { pSort->NodeList[ iLevel ]->Right = pPage->Page; pPage->Left = pSort->NodeList[ iLevel ]->Page; - if ( iLevel == 0 ) + if( iLevel == 0 ) { #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckDupTrlRaw( pSort->NodeList[ iLevel ] ); @@ -9550,14 +9644,14 @@ static void hb_cdxSortAddNodeKey( LPCDXSORTINFO pSort, int iLevel, BYTE *pKeyVal } pSort->NodeList[ iLevel ] = pPage; } - if ( iLevel == 0 ) + if( iLevel == 0 ) { iPos = pPage->iKeys * pPage->ReqByte; hb_cdxSetLeafRecord( &pPage->node.extNode.keyPool[ iPos ], ulRec, iDup, iTrl, pPage->ReqByte, pPage->DCBits, pPage->TCBits ); iTmp = iLen - iDup - iTrl; - if ( iTmp > 0 ) + if( iTmp > 0 ) { memcpy( &pPage->node.extNode.keyPool[ pPage->iFree + iPos - iTmp ], &pKeyVal[ iDup ], iTmp ); @@ -9586,11 +9680,11 @@ static void hb_cdxSortWritePage( LPCDXSORTINFO pSort ) hb_cdxSortSortPage( pSort ); - if ( pSort->hTempFile == FS_ERROR ) + if( pSort->hTempFile == FS_ERROR ) { BYTE szName[ HB_PATH_MAX ]; pSort->hTempFile = hb_fsCreateTemp( NULL, NULL, FC_NORMAL, szName ); - if ( pSort->hTempFile == FS_ERROR ) + if( pSort->hTempFile == FS_ERROR ) { hb_errInternal( 9301, "hb_cdxSortWritePage: Can't create temporary file.", NULL, NULL ); } @@ -9598,7 +9692,7 @@ static void hb_cdxSortWritePage( LPCDXSORTINFO pSort ) } pSort->pSwapPage[ pSort->ulCurPage ].ulKeys = pSort->ulKeys; pSort->pSwapPage[ pSort->ulCurPage ].nOffset = hb_fsSeekLarge( pSort->hTempFile, 0, FS_END ); - if ( hb_fsWriteLarge( pSort->hTempFile, pSort->pKeyPool, ulSize ) != ulSize ) + if( hb_fsWriteLarge( pSort->hTempFile, pSort->pKeyPool, ulSize ) != ulSize ) { hb_errInternal( 9302, "hb_cdxSortWritePage: Write error in temporary file.", NULL, NULL ); } @@ -9611,12 +9705,12 @@ static void hb_cdxSortGetPageKey( LPCDXSORTINFO pSort, ULONG ulPage, { int iLen = pSort->keyLen; - if ( pSort->pSwapPage[ ulPage ].ulKeyBuf == 0 ) + if( pSort->pSwapPage[ ulPage ].ulKeyBuf == 0 ) { ULONG ulKeys = HB_MIN( pSort->ulPgKeys, pSort->pSwapPage[ ulPage ].ulKeys ); ULONG ulSize = ulKeys * ( iLen + 4 ); - if ( hb_fsSeekLarge( pSort->hTempFile, pSort->pSwapPage[ ulPage ].nOffset, SEEK_SET ) != pSort->pSwapPage[ ulPage ].nOffset || + if( hb_fsSeekLarge( pSort->hTempFile, pSort->pSwapPage[ ulPage ].nOffset, SEEK_SET ) != pSort->pSwapPage[ ulPage ].nOffset || hb_fsReadLarge( pSort->hTempFile, pSort->pSwapPage[ ulPage ].pKeyPool, ulSize ) != ulSize ) { hb_errInternal( 9303, "hb_cdxSortGetPageKey: Read error from temporary file.", NULL, NULL ); @@ -9641,27 +9735,27 @@ static void hb_cdxSortOrderPages( LPCDXSORTINFO pSort ) pSort->pSortedPages = ( ULONG * ) hb_xgrab( pSort->ulPages * sizeof( ULONG ) ); pSort->pSortedPages[ 0 ] = 0; - if ( pSort->ulTotKeys > 0 ) + if( pSort->ulTotKeys > 0 ) { - for ( n = 0; n < pSort->ulPages; n++ ) + for( n = 0; n < pSort->ulPages; n++ ) { hb_cdxSortGetPageKey( pSort, n, &pKey, &ulRec ); l = 0; r = n - 1; - while ( l <= r ) + while( l <= r ) { m = ( l + r ) >> 1; ulPage = pSort->pSortedPages[ m ]; pTmp = &pSort->pSwapPage[ ulPage ].pKeyPool[ pSort->pSwapPage[ ulPage ].ulCurKey * ( iLen + 4 ) ]; - i = hb_cdxValCompare( pSort->pTag, pKey, iLen, pTmp, iLen, TRUE ); - if ( i == 0 ) + i = hb_cdxValCompare( pSort->pTag, pKey, iLen, pTmp, iLen, CDX_CMP_EXACT ); + if( i == 0 ) i = ( ulRec < HB_GET_LE_UINT32( &pTmp[ iLen ] ) ) ? -1 : 1; - if ( i > 0 ) + if( i > 0 ) l = m + 1; else r = m - 1; } - for ( r = n; r > l; r-- ) + for( r = n; r > l; r-- ) pSort->pSortedPages[ r ] = pSort->pSortedPages[ r - 1 ]; pSort->pSortedPages[ l ] = n; } @@ -9677,7 +9771,7 @@ static BOOL hb_cdxSortKeyGet( LPCDXSORTINFO pSort, BYTE ** pKeyVal, ULONG *pulRe ulPage = pSort->pSortedPages[ pSort->ulFirst ]; /* check if first page has some keys yet */ - if ( pSort->pSwapPage[ ulPage ].ulKeys > 0 ) + if( pSort->pSwapPage[ ulPage ].ulKeys > 0 ) { BYTE *pKey, *pTmp; ULONG ulRec; @@ -9694,24 +9788,24 @@ static BOOL hb_cdxSortKeyGet( LPCDXSORTINFO pSort, BYTE ** pKeyVal, ULONG *pulRe l = pSort->ulFirst + 1; r = pSort->ulPages - 1; - while ( l <= r ) + while( l <= r ) { m = ( l + r ) >> 1; ulPage = pSort->pSortedPages[ m ]; pTmp = &pSort->pSwapPage[ ulPage ].pKeyPool[ pSort->pSwapPage[ ulPage ].ulCurKey * ( iLen + 4 ) ]; - i = hb_cdxValCompare( pSort->pTag, pKey, iLen, pTmp, iLen, TRUE ); - if ( i == 0 ) + i = hb_cdxValCompare( pSort->pTag, pKey, iLen, pTmp, iLen, CDX_CMP_EXACT ); + if( i == 0 ) i = ( ulRec < HB_GET_LE_UINT32( &pTmp[ iLen ] ) ) ? -1 : 1; - if ( i > 0 ) + if( i > 0 ) l = m + 1; else r = m - 1; } - if ( l > ( LONG ) pSort->ulFirst + 1 ) + if( l > ( LONG ) pSort->ulFirst + 1 ) { ulPage = pSort->pSortedPages[ pSort->ulFirst ]; - for ( r = pSort->ulFirst + 1; r < l; r++ ) + for( r = pSort->ulFirst + 1; r < l; r++ ) pSort->pSortedPages[ r - 1 ] = pSort->pSortedPages[ r ]; pSort->pSortedPages[ l - 1 ] = ulPage; } @@ -9720,7 +9814,7 @@ static BOOL hb_cdxSortKeyGet( LPCDXSORTINFO pSort, BYTE ** pKeyVal, ULONG *pulRe { pSort->ulFirst++; } - if ( pSort->ulFirst < pSort->ulPages ) + if( pSort->ulFirst < pSort->ulPages ) { ulPage = pSort->pSortedPages[ pSort->ulFirst ]; hb_cdxSortGetPageKey( pSort, ulPage, pKeyVal, pulRec ); @@ -9740,24 +9834,24 @@ static BOOL hb_cdxSortKeyGet( LPCDXSORTINFO pSort, BYTE ** pKeyVal, ULONG *pulRe ULONG ulPage, ulKeyPage = 0, ulRec = 0, ulRecTmp; BYTE *pKey = NULL, *pTmp; - for ( ulPage = 0; ulPage < pSort->ulPages; ulPage++ ) + for( ulPage = 0; ulPage < pSort->ulPages; ulPage++ ) { - if ( pSort->pSwapPage[ ulPage ].ulKeys > 0 ) + if( pSort->pSwapPage[ ulPage ].ulKeys > 0 ) { hb_cdxSortGetPageKey( pSort, ulPage, &pTmp, &ulRecTmp ); - if ( ! pKey ) + if( ! pKey ) { i = 1; } else { - i = hb_cdxValCompare( pSort->pTag, pKey, iLen, pTmp, iLen, TRUE ); - if ( i == 0 ) + i = hb_cdxValCompare( pSort->pTag, pKey, iLen, pTmp, iLen, CDX_CMP_EXACT ); + if( i == 0 ) { i = ( ulRec < ulRecTmp ) ? -1 : 1; } } - if ( i > 0 ) + if( i > 0 ) { pKey = pTmp; ulRec = ulRecTmp; @@ -9765,7 +9859,7 @@ static BOOL hb_cdxSortKeyGet( LPCDXSORTINFO pSort, BYTE ** pKeyVal, ULONG *pulRe } } } - if ( pKey ) + if( pKey ) { pSort->pSwapPage[ ulKeyPage ].ulCurKey++; pSort->pSwapPage[ ulKeyPage ].ulKeys--; @@ -9784,13 +9878,13 @@ static void hb_cdxSortKeyAdd( LPCDXSORTINFO pSort, ULONG ulRec, BYTE * pKeyVal, int iLen = pSort->keyLen; BYTE *pDst; - if ( pSort->ulKeys >= pSort->ulPgKeys ) + if( pSort->ulKeys >= pSort->ulPgKeys ) { hb_cdxSortWritePage( pSort ); } pDst = &pSort->pKeyPool[ pSort->ulKeys * ( iLen + 4 ) ]; - if ( iLen > iKeyLen ) + if( iLen > iKeyLen ) { memcpy( pDst, pKeyVal, iKeyLen ); memset( &pDst[ iKeyLen ], pSort->bTrl, iLen - iKeyLen ); @@ -9799,6 +9893,8 @@ static void hb_cdxSortKeyAdd( LPCDXSORTINFO pSort, ULONG ulRec, BYTE * pKeyVal, { memcpy( pDst, pKeyVal, iLen ); } + if( pSort->pTag->IgnoreCase ) + hb_strUpper( ( char * ) pDst, iLen ); HB_PUT_LE_UINT32( &pDst[ iLen ], ulRec ); pSort->ulKeys++; pSort->ulTotKeys++; @@ -9811,23 +9907,23 @@ static LPCDXSORTINFO hb_cdxSortNew( LPCDXTAG pTag, ULONG ulRecCount ) int iLen = pTag->uiLen; ULONG ulSize, ulMax, ulMin; - if ( ulRecCount == 0 ) + if( ulRecCount == 0 ) ulRecCount = 1; pSort = ( LPCDXSORTINFO ) hb_xgrab( sizeof( CDXSORTINFO ) ); memset( pSort, 0, sizeof( CDXSORTINFO ) ); ulMax = ulMin = ( ULONG ) ceil( sqrt( ( double ) ulRecCount ) ); ulSize = ( 1L << 20 ) / ( iLen + 4 ); - while ( ulMax < ulSize ) + while( ulMax < ulSize ) ulMax <<= 1; - if ( ulMax > ulRecCount ) + if( ulMax > ulRecCount ) ulMax = ulRecCount; do { ulSize = ulMax * ( iLen + 4 ); pBuf = ( BYTE * ) hb_xalloc( ulSize << 2 ); - if ( pBuf ) + if( pBuf ) { hb_xfree( pBuf ); pBuf = ( BYTE * ) hb_xalloc( ulSize << 1 ); @@ -9837,9 +9933,9 @@ static LPCDXSORTINFO hb_cdxSortNew( LPCDXTAG pTag, ULONG ulRecCount ) ulMax >>= 1; } } - while ( ! pBuf && ulMax >= ulMin ); + while( ! pBuf && ulMax >= ulMin ); - if ( ! pBuf ) + if( ! pBuf ) { /* call hb_xgrab() to force out of memory error, * though in multi process environment this call may return @@ -9881,28 +9977,28 @@ static LPCDXSORTINFO hb_cdxSortNew( LPCDXTAG pTag, ULONG ulRecCount ) static void hb_cdxSortFree( LPCDXSORTINFO pSort ) { - if ( pSort->hTempFile != FS_ERROR ) + if( pSort->hTempFile != FS_ERROR ) { hb_fsClose( pSort->hTempFile ); } - if ( pSort->szTempFileName ) + if( pSort->szTempFileName ) { hb_fsDelete( (BYTE *) ( pSort->szTempFileName ) ); hb_xfree( pSort->szTempFileName ); } - if ( pSort->pKeyPool ) + if( pSort->pKeyPool ) { hb_xfree( pSort->pKeyPool ); } - if ( pSort->pSwapPage ) + if( pSort->pSwapPage ) { hb_xfree( pSort->pSwapPage ); } - if ( pSort->pRecBuff ) + if( pSort->pRecBuff ) { hb_xfree( pSort->pRecBuff ); } - if ( pSort->pSortedPages ) + if( pSort->pSortedPages ) { hb_xfree( pSort->pSortedPages ); } @@ -9923,11 +10019,11 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) pSort->ulMaxKey, pSort->ulPages, pSort->ulPgKeys, pSort->ulMaxKey * ( pSort->keyLen + 4 ) ); fflush(stdout); */ - if ( pSort->ulPages > 1 ) + if( pSort->ulPages > 1 ) { BYTE * pBuf = pSort->pKeyPool; hb_cdxSortWritePage( pSort ); - for ( ulPage = 0; ulPage < pSort->ulPages; ulPage++ ) + for( ulPage = 0; ulPage < pSort->ulPages; ulPage++ ) { pSort->pSwapPage[ ulPage ].ulKeyBuf = 0; pSort->pSwapPage[ ulPage ].ulCurKey = 0; @@ -9948,28 +10044,28 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) hb_cdxSortOrderPages( pSort ); #endif - for ( ulKey = 0; ulKey < pSort->ulTotKeys; ulKey++ ) + for( ulKey = 0; ulKey < pSort->ulTotKeys; ulKey++ ) { - if ( ! hb_cdxSortKeyGet( pSort, &pKeyVal, &ulRec ) ) + if( ! hb_cdxSortKeyGet( pSort, &pKeyVal, &ulRec ) ) { hb_errInternal( 9304, "hb_cdxSortOut: memory structure corrupted.", NULL, NULL ); } - if ( fUnique ) + if( fUnique ) { - if ( ulKey != 0 && hb_cdxValCompare( pSort->pTag, pSort->pLastKey, iLen, pKeyVal, iLen, TRUE ) == 0 ) + if( ulKey != 0 && hb_cdxValCompare( pSort->pTag, pSort->pLastKey, iLen, pKeyVal, iLen, CDX_CMP_EXACT ) == 0 ) { continue; } } #ifdef HB_CDX_DBGCODE_EXT - if ( ulKey != 0 ) + if( ulKey != 0 ) { - int i = hb_cdxValCompare( pSort->pTag, pSort->pLastKey, iLen, pKeyVal, iLen, TRUE ); - if ( i == 0 ) + int i = hb_cdxValCompare( pSort->pTag, pSort->pLastKey, iLen, pKeyVal, iLen, CDX_CMP_EXACT ); + if( i == 0 ) { i = ( pSort->ulLastRec < ulRec ) ? -1 : 1; } - if ( i > 0 ) + if( i > 0 ) { printf("\r\nulKey=%ld, pKeyVal=[%s][%ld], pKeyLast=[%s][%ld]\r\n", ulKey, pKeyVal, ulRec, pSort->pLastKey, pSort->ulLastRec); fflush(stdout); @@ -9983,13 +10079,13 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) } #ifdef HB_CDX_DBGCODE - if ( hb_cdxSortKeyGet( pSort, &pKeyVal, &ulRec ) ) + if( hb_cdxSortKeyGet( pSort, &pKeyVal, &ulRec ) ) { hb_errInternal( 9306, "hb_cdxSortOut: memory structure corrupted(2).", NULL, NULL ); } #endif - if ( pSort->NodeList[ 0 ] == NULL ) + if( pSort->NodeList[ 0 ] == NULL ) { pSort->NodeList[ 0 ] = hb_cdxPageNew( pSort->pTag, NULL, 0 ); pSort->NodeList[ 0 ]->PageType = CDX_NODE_LEAF; @@ -10000,7 +10096,7 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) fNext = TRUE; do { - if ( iLevel + 1 == CDX_STACKSIZE || pSort->NodeList[ iLevel + 1 ] == NULL ) + if( iLevel + 1 == CDX_STACKSIZE || pSort->NodeList[ iLevel + 1 ] == NULL ) { pSort->NodeList[ iLevel ]->PageType |= CDX_NODE_ROOT; pSort->pTag->RootBlock = pSort->NodeList[ iLevel ]->Page; @@ -10013,7 +10109,7 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) hb_cdxPageFree( pSort->NodeList[ iLevel ], TRUE ); iLevel++; } - while ( fNext ); + while( fNext ); } static void hb_cdxTagEmptyIndex( LPCDXTAG pTag ) @@ -10035,7 +10131,7 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) PHB_CODEPAGE cdpTmp = hb_cdpSelect( pArea->cdPage ); #endif - if ( pArea->lpdbOrdCondInfo ) + if( pArea->lpdbOrdCondInfo ) { pEvalItem = pArea->lpdbOrdCondInfo->itmCobEval; pWhileItem = pArea->lpdbOrdCondInfo->itmCobWhile; @@ -10055,10 +10151,10 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) pSort->fReindex = fReindex; #if defined( HB_SIXCDX ) - if ( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) == 0 && pEvalItem ) + if( ( pTag->OptFlags & CDX_TYPE_STRUCTURE ) == 0 && pEvalItem ) { SELF_GOTO( ( AREAP ) pArea, 0 ); - if ( !hb_cdxEvalCond( pArea, pEvalItem, FALSE ) ) + if( !hb_cdxEvalCond( pArea, pEvalItem, FALSE ) ) { hb_cdxSortFree( pSort ); pArea->pSort = NULL; @@ -10080,10 +10176,10 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) int iRecBuff = 0, iRecBufSize = USHRT_MAX / pArea->uiRecordLen, iRec; pForItem = pTag->pForItem; - if ( pTag->nField ) + if( pTag->nField ) pItem = hb_itemNew( NULL ); - if ( !pArea->lpdbOrdCondInfo || pArea->lpdbOrdCondInfo->fAll ) + if( !pArea->lpdbOrdCondInfo || pArea->lpdbOrdCondInfo->fAll ) { pArea->uiTag = 0; } @@ -10091,11 +10187,11 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) { if( pArea->lpdbOrdCondInfo->itmRecID ) ulStartRec = hb_itemGetNL( pArea->lpdbOrdCondInfo->itmRecID ); - if ( ulStartRec ) + if( ulStartRec ) { ulNextCount = 1; } - else if ( pArea->lpdbOrdCondInfo->fRest || pArea->lpdbOrdCondInfo->lNextCount > 0 ) + else if( pArea->lpdbOrdCondInfo->fRest || pArea->lpdbOrdCondInfo->lNextCount > 0 ) { if( pArea->lpdbOrdCondInfo->itmStartRecID ) ulStartRec = hb_itemGetNL( pArea->lpdbOrdCondInfo->itmStartRecID ); @@ -10108,7 +10204,7 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) { fUseFilter = TRUE; } - else if ( !pArea->lpdbOrdCondInfo->fUseCurrent ) + else if( !pArea->lpdbOrdCondInfo->fUseCurrent ) { pArea->uiTag = 0; } @@ -10117,34 +10213,34 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) ( !pArea->lpdbOrdCondInfo || pArea->lpdbOrdCondInfo->fAll || ( pArea->uiTag == 0 && !fUseFilter ) ); - if ( fDirectRead ) + if( fDirectRead ) pSort->pRecBuff = (BYTE *) hb_xgrab( pArea->uiRecordLen * iRecBufSize ); - if ( ulStartRec == 0 && pArea->uiTag == 0 ) + if( ulStartRec == 0 && pArea->uiTag == 0 ) ulStartRec = 1; - if ( ulStartRec == 0 ) + if( ulStartRec == 0 ) { SELF_GOTOP( ( AREAP ) pArea ); } else { SELF_GOTO( ( AREAP ) pArea, ulStartRec ); - if ( fUseFilter ) + if( fUseFilter ) SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); } ulRecNo = pArea->ulRecNo; - while ( !pArea->fEof ) + while( !pArea->fEof ) { - if ( fDirectRead ) + if( fDirectRead ) { - if ( ulRecNo > ulRecCount ) + if( ulRecNo > ulRecCount ) break; - if ( iRecBuff == 0 || iRecBuff >= iRecBufSize ) + if( iRecBuff == 0 || iRecBuff >= iRecBufSize ) { - if ( ulRecCount - ulRecNo >= ( ULONG ) iRecBufSize ) + if( ulRecCount - ulRecNo >= ( ULONG ) iRecBufSize ) iRec = iRecBufSize; else iRec = ulRecCount - ulRecNo + 1; @@ -10170,27 +10266,27 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) } #if !defined( HB_SIXCDX ) - if ( pEvalItem ) + if( pEvalItem ) { - if ( lStep >= pArea->lpdbOrdCondInfo->lStep ) + if( lStep >= pArea->lpdbOrdCondInfo->lStep ) { lStep = 0; - if ( !hb_cdxEvalCond( pArea, pEvalItem, FALSE ) ) + if( !hb_cdxEvalCond( pArea, pEvalItem, FALSE ) ) break; } ++lStep; } #endif - if ( pWhileItem && !hb_cdxEvalCond( NULL, pWhileItem, FALSE ) ) + if( pWhileItem && !hb_cdxEvalCond( NULL, pWhileItem, FALSE ) ) break; - if ( ulRecNo <= ulRecCount && + if( ulRecNo <= ulRecCount && ( pForItem == NULL || hb_cdxEvalCond( pArea, pForItem, FALSE ) ) ) { double d; - if ( pTag->nField ) + if( pTag->nField ) SELF_GETVALUE( ( AREAP ) pArea, pTag->nField, pItem ); else pItem = hb_vmEvalBlockOrMacro( pTag->pKeyItem ); @@ -10207,13 +10303,28 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) case HB_IT_INTEGER: case HB_IT_LONG: case HB_IT_DOUBLE: - d = hb_itemGetND( pItem ); + if( pTag->uiLen == 4 ) + { + UINT32 uiVal = ( UINT32 ) hb_itemGetNI( pItem ) + 0x80000000; + HB_PUT_BE_UINT32( &cTemp[0], uiVal ); + hb_cdxSortKeyAdd( pSort, pArea->ulRecNo, cTemp, 4 ); + } + else + { + d = hb_itemGetND( pItem ); + HB_DBL2ORD( &d, &cTemp[0] ); + hb_cdxSortKeyAdd( pSort, pArea->ulRecNo, cTemp, 8 ); + } + break; + + case HB_IT_DATE: + d = ( double ) hb_itemGetDL( pItem ); HB_DBL2ORD( &d, &cTemp[0] ); hb_cdxSortKeyAdd( pSort, pArea->ulRecNo, cTemp, 8 ); break; - case HB_IT_DATE: - d = (double) hb_itemGetDL( pItem ); + case HB_IT_TIMESTAMP: + d = hb_itemGetTD( pItem ); HB_DBL2ORD( &d, &cTemp[0] ); hb_cdxSortKeyAdd( pSort, pArea->ulRecNo, cTemp, 8 ); break; @@ -10224,7 +10335,7 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) break; default: - if ( hb_vmRequestQuery() ) + if( hb_vmRequestQuery() ) { pEvalItem = NULL; ulNextCount = 1; @@ -10244,12 +10355,12 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) } #if defined( HB_SIXCDX ) - if ( pEvalItem ) + if( pEvalItem ) { - if ( lStep >= pArea->lpdbOrdCondInfo->lStep ) + if( lStep >= pArea->lpdbOrdCondInfo->lStep ) { lStep = 0; - if ( !hb_cdxEvalCond( pArea, pEvalItem, FALSE ) ) + if( !hb_cdxEvalCond( pArea, pEvalItem, FALSE ) ) break; } ++lStep; @@ -10269,10 +10380,10 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) } hb_cdxSortOut( pSort ); - if ( pTag->nField ) + if( pTag->nField ) hb_itemRelease( pItem ); - if ( fDirectRead ) + if( fDirectRead ) { pArea->pRecord = pSaveRecBuff; SELF_GOTO( ( AREAP ) pArea, ulRecNo ); @@ -10280,7 +10391,7 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) pArea->uiTag = uiSaveTag; #if !defined( HB_SIXCDX ) - if ( pEvalItem && lStep ) + if( pEvalItem && lStep ) { /* pArea->fEof = TRUE; */ hb_cdxEvalCond( pArea, pEvalItem, FALSE ); @@ -10289,7 +10400,7 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex ) } #if defined( HB_SIXCDX ) - if ( pEvalItem ) + if( pEvalItem ) { SELF_GOTO( ( AREAP ) pArea, 0 ); pArea->fBof = FALSE; diff --git a/harbour/contrib/hbbmcdx/hbbmcdx.h b/harbour/contrib/hbbmcdx/hbbmcdx.h index 0c10765e39..76933b60e2 100644 --- a/harbour/contrib/hbbmcdx/hbbmcdx.h +++ b/harbour/contrib/hbbmcdx/hbbmcdx.h @@ -151,6 +151,10 @@ HB_EXTERN_BEGIN #define CDX_TYPE_COMPOUND 0x40 /* FoxPro */ #define CDX_TYPE_STRUCTURE 0x80 /* FoxPro */ +#define CDX_CMP_EXACT 0x00 /* exact comparision */ +#define CDX_CMP_PREFIX 0x01 /* prefix comparision */ +#define CDX_CMP_DATE 0x02 /* date comparision */ + /* SIx3 order temperature flags: switch ( indexOpt & ( CDX_TYPE_TEMPORARY | CDX_TYPE_CUSTOM ) ) @@ -195,8 +199,10 @@ typedef struct _CDXTAGHEADER BYTE keySize [ 2 ]; /* key length */ BYTE indexOpt; /* index options see CDX_TYPE_* */ BYTE indexSig; /* index signature */ - BYTE reserved2[ 484 ]; - BYTE ignoreCase[ 2 ]; /* 1 = ignore case, key converted to upper */ + BYTE reserved2[ 478 ]; + BYTE codepage[ 5 ]; /* VFP codepage */ + BYTE ignoreCase; /* 1 = ignore case, key converted to upper */ + BYTE reserved3[ 2 ]; BYTE ascendFlg[ 2 ]; /* 0 = ascending 1 = descending */ BYTE forExpPos[ 2 ]; /* offset of filter expression */ BYTE forExpLen[ 2 ]; /* length of filter expression */ @@ -249,7 +255,8 @@ struct _CDXTAG; /* forward declaration */ typedef struct _CDXKEY { BYTE * val; - BYTE len; + USHORT len; + USHORT mode; ULONG rec; } CDXKEY; typedef CDXKEY * LPCDXKEY; @@ -333,6 +340,7 @@ typedef struct _CDXTAG BOOL ChgOnly; /* only existing key modifications are updated, no new key added */ BOOL UsrAscend; /* user settable ascending/descending order flag */ BOOL UsrUnique; /* user settable unique order flag */ + BOOL IgnoreCase; /* ignore case (upper keys) */ BOOL TagChanged; BOOL TagBOF; @@ -492,12 +500,15 @@ typedef struct _CDXAREA USHORT uiNewBlockSize; /* Size of new memo block */ USHORT uiMemoVersion; /* MEMO file version */ USHORT uiDirtyRead; /* Index dirty read bit filed */ + USHORT uiNullOffset; /* Offset to _NullFlags filed */ + USHORT uiNullCount; /* Number of null flags */ BYTE bTableType; /* DBF type */ BYTE bMemoType; /* MEMO type used in DBF memo fields */ BYTE bLockType; /* Type of locking shemes */ BYTE bCryptType; /* Type of used encryption */ DBFHEADER dbfHeader; /* DBF header buffer */ USHORT * pFieldOffset; /* Pointer to field offset array */ + PHB_DBFFIELDBITS pFieldBits; /* Pointer to extended DBF field info array */ BYTE * pRecord; /* Buffer of record data */ ULONG ulRecCount; /* Total records */ ULONG ulRecNo; /* Current record */