From 5da47b4d314d61b5443a8c4ae0a0213612b260da Mon Sep 17 00:00:00 2001 From: "Alexander S.Kresin" Date: Fri, 29 Mar 2002 11:12:59 +0000 Subject: [PATCH] 2002-03-29 14:17 UTC+0300 Alexander Kresin --- harbour/ChangeLog | 5 ++ harbour/include/hbrddntx.h | 1 + harbour/source/rdd/dbfntx/dbfntx1.c | 76 ++++++++++++++++++++++++----- 3 files changed, 70 insertions(+), 12 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 048053409c..85725d0b2e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -7,6 +7,11 @@ For example: 2002-12-01 23:12 UTC+0100 Foo Bar */ +2002-03-29 13:15 UTC-0500 David G. Holm + * libnf/descend.c + * libnf/getenvrn.c + * libnf/ontick.c + * libnf/peek.c * libnf/poke.c ! All include file names must be lower case for Un*x type systems. diff --git a/harbour/include/hbrddntx.h b/harbour/include/hbrddntx.h index 598e9d3d4e..0920ce95fb 100644 --- a/harbour/include/hbrddntx.h +++ b/harbour/include/hbrddntx.h @@ -154,6 +154,7 @@ typedef struct _TAGINFO LONG blockNext; USHORT keyPrev; USHORT keyNext; + ULONG keyCount; LPKEYINFO CurKeyInfo; LPPAGEINFO RootPage; BOOL InIndex; diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index ee5311b2c0..d31f08116d 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -133,6 +133,8 @@ static ERRCODE hb_ntxPageKeyInsert( LPPAGEINFO pPage, char* key, int pos ); static int hb_ntxItemCompare( char* s1, char* s2, int ilen1, int ilen2, BOOL Exact ); static ERRCODE hb_ntxPageAddPageKeyAdd( LPPAGEINFO pPage, char* key, int pos ); +#define KEYITEM(P,N) ( (NTXITEM*)( (P)->buffer+ *((USHORT*)((P)->buffer+(N)*2+2)) ) ) + static void commonError( NTXAREAP pArea, USHORT uiGenCode, USHORT uiSubCode, char* filename, USHORT uiFlags ) { PHB_ITEM pError; @@ -236,6 +238,22 @@ static BOOL checkLogicalExpr( PHB_ITEM pForItem, PHB_ITEM pItem ) return res; } +static void hb__ntxTagKeyCount( LPPAGEINFO pPage, ULONG* ulKeyCount ) +{ + LPNTXITEM p; + int i; + + *ulKeyCount += pPage->uiKeys; + for( i=0;iuiKeys+1;i++ ) + { + p = KEYITEM( pPage, i ); + if( p->page ) + hb__ntxTagKeyCount( hb_ntxPageLoad( pPage->TagParent->Owner,p->page ), + ulKeyCount ); + } + hb_ntxPageRelease( pPage ); +} + static ULONG hb_ntxTagKeyNo( LPTAGINFO pTag ) { HB_SYMBOL_UNUSED( pTag ); @@ -244,8 +262,39 @@ static ULONG hb_ntxTagKeyNo( LPTAGINFO pTag ) static ULONG hb_ntxTagKeyCount( LPTAGINFO pTag ) { - HB_SYMBOL_UNUSED( pTag ); - return 0; + LPPAGEINFO pPage; + LPNTXITEM p; + ULONG ulKeyCount = 0; + int i; + + if( pTag->Owner->Owner->fShared ) + { + while( !hb_fsLock( pTag->Owner->DiskFile, 0, 512, FL_LOCK ) ); + pTag->Owner->Locked = TRUE; + } + else if( pTag->keyCount ) + return pTag->keyCount + + pPage = hb_ntxPageLoad( pTag->Owner,0 ); + ulKeyCount += pPage->uiKeys; + for( i=0;iuiKeys+1;i++ ) + { + p = KEYITEM( pPage, i ); + if( p->page ) + hb__ntxTagKeyCount( hb_ntxPageLoad( pTag->Owner,p->page ), + &ulKeyCount ); + } + hb_ntxPageRelease( pPage ); + + if( pTag->Owner->Owner->fShared ) + { + hb_ntxPageFree( pTag->RootPage,FALSE ); + hb_fsLock( pTag->Owner->DiskFile, 0, 512, FL_UNLOCK ); + pTag->Owner->Locked = FALSE; + } + else + pTag->keyCount = ulKeyCount; + return ulKeyCount; } static void hb_ntxClearScope( LPTAGINFO pTag, USHORT nScope ) @@ -367,8 +416,6 @@ static LONG hb_ntxTagKeyFind( LPTAGINFO pTag, LPKEYINFO pKey, BOOL * result ) return 0; } -#define KEYITEM(P,N) ( (NTXITEM*)( (P)->buffer+ *((USHORT*)((P)->buffer+(N)*2+2)) ) ) - static int hb_ntxTagFindCurrentKey( LPPAGEINFO pPage, LPKEYINFO pKey, BOOL bExact, BOOL lSeek ) { int k = 1, kChild, keylen = strlen( pKey->key ); @@ -737,9 +784,9 @@ static BOOL hb_ntxPageReadTopKey( LPTAGINFO pTag, LPPAGEINFO pPage, ULONG ulOffs } else { - strcpy( pChildPage->TagParent->CurKeyInfo->key, p->key ); - pChildPage->TagParent->CurKeyInfo->Xtra = p->rec_no; - pChildPage->TagParent->CurKeyInfo->Tag = pChildPage->Page; + strcpy( pTag->CurKeyInfo->key, p->key ); + pTag->CurKeyInfo->Xtra = p->rec_no; + pTag->CurKeyInfo->Tag = pChildPage->Page; hb_ntxPageRelease( pChildPage ); return TRUE; } @@ -758,16 +805,15 @@ static BOOL hb_ntxPageReadBottomKey( LPTAGINFO pTag, LPPAGEINFO pPage, ULONG ulO hb_ntxPageRelease( pPage ); if( pChildPage != NULL && pChildPage->uiKeys ) { - p = KEYITEM( pChildPage, pChildPage->uiKeys ); - ulOffset = p->page; + ulOffset = ( KEYITEM( pChildPage, pChildPage->uiKeys ) )->page; if( ulOffset ) return hb_ntxPageReadBottomKey( pTag,pChildPage,ulOffset ); else { p = KEYITEM( pChildPage, pChildPage->uiKeys-1 ); - strcpy( pChildPage->TagParent->CurKeyInfo->key, p->key ); - pChildPage->TagParent->CurKeyInfo->Xtra = p->rec_no; - pChildPage->TagParent->CurKeyInfo->Tag = pChildPage->Page; + strcpy( pTag->CurKeyInfo->key, p->key ); + pTag->CurKeyInfo->Xtra = p->rec_no; + pTag->CurKeyInfo->Tag = pChildPage->Page; hb_ntxPageRelease( pChildPage ); return TRUE; } @@ -2666,9 +2712,15 @@ static ERRCODE ntxGoCold( NTXAREAP pArea ) pPage = hb_ntxPageLoad( pTag->Owner,pTag->CurKeyInfo->Tag ); pPage->CurKey = hb_ntxPageFindCurrentKey( pPage,pTag->CurKeyInfo->Xtra ) - 1; hb_ntxPageKeyDel( pPage, pPage->CurKey, 1 ); + if( !pArea->fShared && pTag->keyCount ) + pTag->keyCount --; } if( InIndex ) + { hb_ntxPageKeyAdd( hb_ntxPageLoad( pTag->Owner,0 ), pKey->key, FALSE ); + if( !pArea->fShared && pTag->keyCount ) + pTag->keyCount ++; + } if( pArea->fShared ) { hb_ntxPageFree( pTag->RootPage,FALSE );