From 2f44c8201edc4d70285559fe8738052ad7fb7e53 Mon Sep 17 00:00:00 2001 From: Mindaugas Kavaliauskas Date: Mon, 9 Nov 2009 16:48:32 +0000 Subject: [PATCH] 2009-11-09 18:45 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * harbour/contrib/rddads/adsx.c * harbour/contrib/rddsql/hbrddsql.h * harbour/contrib/rddsql/sqlmix.c * updated to use hb_cdpcmp() --- harbour/ChangeLog | 10 +++- harbour/contrib/rddads/adsx.c | 83 +++++--------------------- harbour/contrib/rddsql/hbrddsql.h | 5 +- harbour/contrib/rddsql/sqlmix.c | 98 ++----------------------------- 4 files changed, 30 insertions(+), 166 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 99791a3b66..c094518a95 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,12 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-11-09 18:45 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * harbour/contrib/rddads/adsx.c + * harbour/contrib/rddsql/hbrddsql.h + * harbour/contrib/rddsql/sqlmix.c + * updated to use hb_cdpcmp() + 2009-11-09 17:33 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/bin/hb-func.sh ! added links with full version number to harbour shared library @@ -406,7 +412,7 @@ * minor formatting 2009-11-06 16:15 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) - * harbour/contib/rddads/adsfunc.c + * harbour/contrib/rddads/adsfunc.c * AdsIsConnectionAlive() guarded using #if ADS_LIB_VERSION >= 800 2009-11-06 00:15 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) @@ -48125,7 +48131,7 @@ * small cleanup in comment 2009-02-03 11:45 UTC+0100 Lorenzo Fiorini (lorenzo.fiorini/at/gmail.com) - * contib/xhb/hblognet.prg + * contrib/xhb/hblognet.prg * fixed thread function names 2009-02-03 03:02 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) diff --git a/harbour/contrib/rddads/adsx.c b/harbour/contrib/rddads/adsx.c index 70e380f220..33bbf5d791 100644 --- a/harbour/contrib/rddads/adsx.c +++ b/harbour/contrib/rddads/adsx.c @@ -101,7 +101,7 @@ typedef struct _MIXTAG ULONG ulRecMax; ULONG ulRecCount; - BYTE* pSortTable; /* National sorttable for character key tags, NULL otherwise */ + PHB_CODEPAGE pCodepage; /* National sorttable for character key tags, NULL otherwise */ ULONG ulKeyNo; } MIXTAG, *LPMIXTAG; @@ -115,8 +115,6 @@ typedef struct _ADSXAREA_ LPMIXTAG pTagList; LPMIXTAG pTagCurrent; - BYTE* pSortTable; - } ADSXAREA, *ADSXAREAP; @@ -274,55 +272,13 @@ static void mixKeyFree( LPMIXKEY pKey ) } -static BYTE * mixBuildSortTable( PHB_CODEPAGE pCodepage ) -{ - BYTE* pSortTable; - const BYTE* pChars; - int i, j; - BYTE c; - - pSortTable = ( BYTE * ) hb_xgrab( 256 ); - - if( pCodepage && pCodepage->sort ) - { - pChars = pCodepage->sort; - - c = 0; - for( i = 0; i < 256; i++ ) - { - for( j = 0; j < 256; j++ ) - { - if( pChars[ j ] == ( BYTE ) i ) - { - pSortTable[ j ] = c; - c++; - } - } - } - } - else - { - for( i = 0; i < 256; i++ ) - pSortTable[ i ] = ( BYTE ) i; - } - return pSortTable; -} - - -static int mixQSortCompare( LPMIXKEY p1, LPMIXKEY p2, USHORT uiLen, BYTE* pSortTable ) +static int mixQSortCompare( LPMIXKEY p1, LPMIXKEY p2, USHORT uiLen, PHB_CODEPAGE pCodepage ) { int i; - if( pSortTable ) + if( pCodepage ) { - int j = 0; - - i = 0; - while( i == 0 && j < (int) uiLen ) - { - i = pSortTable[ p1->val[ j ] ] - pSortTable[ p2->val[ j ] ]; - j++; - } + i = hb_cdpcmp( ( const char * ) p1->val, ( ULONG ) uiLen, ( const char * ) p2->val, ( ULONG ) uiLen, pCodepage, 0 ); } else i = memcmp( p1->val, p2->val, uiLen ); @@ -345,7 +301,7 @@ static int mixQSortCompare( LPMIXKEY p1, LPMIXKEY p2, USHORT uiLen, BYTE* pSortT } -static void mixQSort( LPMIXKEY* pKeys, ULONG left, ULONG right, USHORT uiLen, BYTE* pSortTable ) +static void mixQSort( LPMIXKEY* pKeys, ULONG left, ULONG right, USHORT uiLen, PHB_CODEPAGE pCodepage ) { ULONG l, r; LPMIXKEY x, h; @@ -356,9 +312,9 @@ static void mixQSort( LPMIXKEY* pKeys, ULONG left, ULONG right, USHORT uiLen, BY x = pKeys[ (l + r) / 2 ]; do { - while( mixQSortCompare( x, pKeys[ l ], uiLen, pSortTable ) > 0 ) + while( mixQSortCompare( x, pKeys[ l ], uiLen, pCodepage ) > 0 ) l++; - while( mixQSortCompare( pKeys[ r ], x, uiLen, pSortTable ) > 0 ) + while( mixQSortCompare( pKeys[ r ], x, uiLen, pCodepage ) > 0 ) r--; if( l < r ) @@ -370,10 +326,10 @@ static void mixQSort( LPMIXKEY* pKeys, ULONG left, ULONG right, USHORT uiLen, BY while( l < r ); if( left < r && ( r != right ) ) - mixQSort( pKeys, left, r, uiLen, pSortTable ); + mixQSort( pKeys, left, r, uiLen, pCodepage ); if( l < right && ( l != left ) ) - mixQSort( pKeys, l, right, uiLen, pSortTable ); + mixQSort( pKeys, l, right, uiLen, pCodepage ); } @@ -394,7 +350,7 @@ static LPMIXKEY mixFindKey( LPMIXTAG pTag, LPMIXKEY pKey, ULONG* ulKeyPos ) while( l < r ) { - i = mixQSortCompare( pTag->pKeys[ (l + r) / 2 ], pKey, pTag->uiLen, pTag->pSortTable ); + i = mixQSortCompare( pTag->pKeys[ (l + r) / 2 ], pKey, pTag->uiLen, pTag->pCodepage ); if( i < 0 ) l = (l + r) / 2 + 1; @@ -406,7 +362,7 @@ static LPMIXKEY mixFindKey( LPMIXTAG pTag, LPMIXKEY pKey, ULONG* ulKeyPos ) if( i ) { - i = mixQSortCompare( pTag->pKeys[ l ], pKey, pTag->uiLen, pTag->pSortTable ); + i = mixQSortCompare( pTag->pKeys[ l ], pKey, pTag->uiLen, pTag->pCodepage ); if( i < 0 ) l++; } @@ -420,7 +376,7 @@ static LPMIXKEY mixFindKey( LPMIXTAG pTag, LPMIXKEY pKey, ULONG* ulKeyPos ) static int mixCompareKey( LPMIXTAG pTag, ULONG ulKeyPos, LPMIXKEY pKey ) { - return mixQSortCompare( pTag->pKeys[ ulKeyPos ], pKey, pTag->uiLen, pTag->pSortTable ); + return mixQSortCompare( pTag->pKeys[ ulKeyPos ], pKey, pTag->uiLen, pTag->pCodepage ); } @@ -455,8 +411,8 @@ static LPMIXTAG mixTagCreate( const char * szTagName, PHB_ITEM pKeyExpr, PHB_ITE pTag->uiLen = uiLen; /* Use national support */ - if( bType == 'C' ) - pTag->pSortTable = pArea->pSortTable; + if( bType == 'C' && pArea->adsarea.area.cdPage && pArea->adsarea.area.cdPage->sort ) + pTag->pCodepage = pArea->adsarea.area.cdPage; pTag->pKeys = (LPMIXKEY*) hb_xgrab( sizeof( LPMIXKEY ) * MIX_KEYPOOLFIRST ); pTag->ulRecMax = MIX_KEYPOOLFIRST; @@ -558,7 +514,7 @@ static LPMIXTAG mixTagCreate( const char * szTagName, PHB_ITEM pKeyExpr, PHB_ITE /* QuickSort */ if( pTag->ulRecCount >= 2 ) - mixQSort( pTag->pKeys, 0, pTag->ulRecCount - 1, uiLen, pTag->pSortTable ); + mixQSort( pTag->pKeys, 0, pTag->ulRecCount - 1, uiLen, pTag->pCodepage ); return pTag; } @@ -831,11 +787,6 @@ static HB_ERRCODE adsxClose( ADSXAREAP pArea ) pArea->pTagList = pArea->pTagList->pNext; mixTagDestroy( pTag ); } - if( pArea->pSortTable ) - { - hb_xfree( pArea->pSortTable ); - pArea->pSortTable = NULL; - } return SUPER_CLOSE( (AREAP) pArea ); } @@ -852,8 +803,6 @@ static HB_ERRCODE adsxCreate( ADSXAREAP pArea, LPDBOPENINFO pCreateInfo ) } else pArea->adsarea.area.cdPage = hb_vmCDP(); - - pArea->pSortTable = mixBuildSortTable( pArea->adsarea.area.cdPage ); return HB_SUCCESS; } return HB_FAILURE; @@ -872,8 +821,6 @@ static HB_ERRCODE adsxOpen( ADSXAREAP pArea, LPDBOPENINFO pOpenInfo ) } else pArea->adsarea.area.cdPage = hb_vmCDP(); - - pArea->pSortTable = mixBuildSortTable( pArea->adsarea.area.cdPage ); return HB_SUCCESS; } return HB_FAILURE; diff --git a/harbour/contrib/rddsql/hbrddsql.h b/harbour/contrib/rddsql/hbrddsql.h index e9e856006b..02b0d63819 100644 --- a/harbour/contrib/rddsql/hbrddsql.h +++ b/harbour/contrib/rddsql/hbrddsql.h @@ -206,7 +206,7 @@ typedef struct _MIXTAG PMIXKEY HotKey; BOOL HotFor; - BYTE* pSortTable; /* National sorttable for character key tags, NULL otherwise */ + PHB_CODEPAGE pCodepage; /* National sorttable for character key tags, NULL otherwise */ } MIXTAG, *PMIXTAG; @@ -220,8 +220,7 @@ typedef struct _SQLMIXAREA PMIXTAG pTagList; PMIXTAG pTag; - BYTE* pSortTable; - + PHB_CODEPAGE pCodepage; } SQLMIXAREA, *SQLMIXAREAP; diff --git a/harbour/contrib/rddsql/sqlmix.c b/harbour/contrib/rddsql/sqlmix.c index aae8a4c908..084b2810b5 100644 --- a/harbour/contrib/rddsql/sqlmix.c +++ b/harbour/contrib/rddsql/sqlmix.c @@ -249,55 +249,11 @@ static void hb_mixKeyFree( PMIXKEY pKey ) } -#if 0 -/* This function is unused */ -static int hb_mixKeyCompareValue( PMIXTAG pTag, PMIXKEY pKey1, PMIXKEY pKey2, unsigned int uiLen ) -{ - BYTE* pSortTable = pTag->pSortTable; - unsigned int ui, uiSize; - int i; - - if ( ! pKey1->notnul || ! pKey2->notnul ) - { - return (int) pKey1->notnul - (int) pKey2->notnul; - } - - i = 0; - uiSize = pTag->uiKeyLen > uiLen ? uiLen : pTag->uiKeyLen; - - if ( pSortTable ) - { - ui = 0; - while ( i == 0 && ui < uiSize ) - { - i = pSortTable[ pKey1->val[ ui ] ] - pSortTable[ pKey2->val[ ui ] ]; - ui++; - } - } - else - { - if ( uiSize > 0 ) - i = memcmp( pKey1->val, pKey2->val, uiSize ); - } - - if ( i == 0 ) - { - /* This condition seems inverted, but it's ok for seek last */ - if ( pTag->uiKeyLen > uiLen ) - i = -1; - } - return i; -} -#endif - - static int hb_mixKeyCompare( PMIXTAG pTag, PMIXKEY pKey1, PMIXKEY pKey2, unsigned int uiLen ) { - BYTE* pSortTable = pTag->pSortTable; - unsigned int ui, uiSize; + unsigned int uiSize; int i; - if ( ! pKey1->notnul || ! pKey2->notnul ) { return (int) pKey1->notnul - (int) pKey2->notnul; @@ -306,14 +262,9 @@ static int hb_mixKeyCompare( PMIXTAG pTag, PMIXKEY pKey1, PMIXKEY pKey2, unsigne i = 0; uiSize = pTag->uiKeyLen > uiLen ? uiLen : pTag->uiKeyLen; - if ( pSortTable ) + if ( pTag->pCodepage ) { - ui = 0; - while ( i == 0 && ui < uiSize ) - { - i = pSortTable[ pKey1->val[ ui ] ] - pSortTable[ pKey2->val[ ui ] ]; - ui++; - } + i = hb_cdpcmp( ( const char * ) pKey1->val, ( ULONG ) uiSize, ( const char * ) pKey2->val, ( ULONG ) uiSize, pTag->pCodepage, 0 ); } else { @@ -841,41 +792,6 @@ static BOOL hb_mixTagDelKey( PMIXTAG pTag, PMIXKEY pKey ) } -static BYTE* hb_mixBuildSortTable( PHB_CODEPAGE pCodepage ) -{ - BYTE* pSortTable; - const BYTE* pChars; - int i, j; - BYTE c; - - pSortTable = ( BYTE * ) hb_xalloc( 256 ); - - if ( pCodepage && pCodepage->sort ) - { - pChars = pCodepage->sort; - - c = 0; - for ( i = 0; i < 256; i++ ) - { - for ( j = 0; j < 256; j++ ) - { - if ( pChars[ j ] == ( BYTE ) i ) - { - pSortTable[ j ] = c; - c++; - } - } - } - } - else - { - for ( i = 0; i < 256; i++ ) - pSortTable[ i ] = ( BYTE ) i; - } - return pSortTable; -} - - static PMIXTAG hb_mixTagCreate( const char* szTagName, PHB_ITEM pKeyExpr, PHB_ITEM pKeyItem, PHB_ITEM pForItem, PHB_ITEM pWhileItem, BYTE bType, unsigned int uiKeyLen, SQLMIXAREAP pArea ) { PMIXTAG pTag; @@ -909,11 +825,10 @@ static PMIXTAG hb_mixTagCreate( const char* szTagName, PHB_ITEM pKeyExpr, PHB_IT /* Use national support */ if ( bType == 'C' ) { - if( pArea->sqlarea.area.cdPage && pArea->sqlarea.area.cdPage->sort && !pArea->pSortTable ) + if( pArea->sqlarea.area.cdPage && pArea->sqlarea.area.cdPage->sort ) { - pArea->pSortTable = hb_mixBuildSortTable( pArea->sqlarea.area.cdPage ); + pTag->pCodepage = pArea->sqlarea.area.cdPage; } - pTag->pSortTable = pArea->pSortTable; } pTag->Root = hb_mixTagCreateNode( pTag, TRUE ); @@ -1645,9 +1560,6 @@ static HB_ERRCODE sqlmixClose( SQLMIXAREAP pArea ) if ( SELF_ORDLSTCLEAR( (AREAP) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( pArea->pSortTable ) - hb_xfree( pArea->pSortTable ); - return HB_SUCCESS; }