diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a034256f25..bfc5e7c85d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -7,6 +7,16 @@ For example: 2002-12-01 23:12 UTC+0100 Foo Bar */ + * source/rtl/Tgetlist.prg + * Minor modifications proposed by Walter Negro + +2002-02-04 13:50 UTC+0100 Ignacio Ortiz + * source/rtl/memoline.c + * source/rtl/mlcount.c + * Disable limitation of string length to 254 when + no HB_C52_STRICT used. + * source/rtl/at.c + * source/source/compiler/Hbfuncchk.c * doc/en/string.txt * Two new parameters nStart & nEnd of At() function when no HB_C52_STRICT used. diff --git a/harbour/include/hbrddntx.h b/harbour/include/hbrddntx.h index 24867c577d..89e92c86bf 100644 --- a/harbour/include/hbrddntx.h +++ b/harbour/include/hbrddntx.h @@ -91,7 +91,7 @@ extern "C" { #define NTX_MAX_REC_NUM 0x7FFFFFFFL #define NTX_IGNORE_REC_NUM -1 -#define NTX_MAX_KEY 250 /* Max len of key */ +#define NTX_MAX_KEY 256 /* Max len of key */ #define NTXBLOCKSIZE 1024 /* Size of block in NTX file */ /* forward declarations @@ -193,7 +193,9 @@ typedef struct _NTXHEADER /* Header of NTX file */ USHORT half_page; char key_expr[ NTX_MAX_KEY ]; char unique; - char reserve[9]; + char unknown; + char descend; + char reserve[7]; char for_expr[ NTX_MAX_KEY ]; } NTXHEADER; diff --git a/harbour/source/compiler/genhrb.c b/harbour/source/compiler/genhrb.c index 466d9b29c8..1a47c134f7 100644 --- a/harbour/source/compiler/genhrb.c +++ b/harbour/source/compiler/genhrb.c @@ -67,6 +67,11 @@ void hb_compGenPortObj( PHB_FNAME pFileName ) lSymbols++; pSym = pSym->pNext; } + fputc( ( BYTE ) 192, yyc ); + fputs( "HRB", yyc ); + fputc( 2, yyc ); + fputc( 0, yyc ); + fputc( ( BYTE ) ( ( lSymbols ) & 255 ), yyc ); /* Write number symbols */ fputc( ( BYTE ) ( ( lSymbols >> 8 ) & 255 ), yyc ); fputc( ( BYTE ) ( ( lSymbols >> 16 ) & 255 ), yyc ); diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index a799006356..d8859feac4 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -759,6 +759,7 @@ static BOOL hb_ntxPageReadBottomKey( LPPAGEINFO pPage, ULONG ulOffset ) static void hb_ntxTagKeyRead( LPTAGINFO pTag, BYTE bTypRead, BOOL * lContinue ) { +/* if( !pTag->AscendKey ) { switch( bTypRead ) @@ -780,6 +781,7 @@ static void hb_ntxTagKeyRead( LPTAGINFO pTag, BYTE bTypRead, BOOL * lContinue ) break; } } +*/ pTag->TagBOF = pTag->TagEOF = FALSE; if( pTag->Owner->Owner->ulRecCount ) { @@ -1335,6 +1337,8 @@ static int hb_ntxPageKeyAdd( LPPAGEINFO pPage, PHB_ITEM pKey, int level, BOOL is { nBegin = pPage->uiKeys / 2; cmp = hb_ntxItemCompare( pPage->pKeys[ nBegin ].pItem , pKey, TRUE ); + if( !pPage->TagParent->AscendKey ) + cmp = -cmp; if( !cmp && pPage->TagParent->UniqueKey ) return 1; if( cmp > 0 ) @@ -1378,6 +1382,8 @@ static int hb_ntxPageKeyAdd( LPPAGEINFO pPage, PHB_ITEM pKey, int level, BOOL is if( i == pPage->uiKeys ) break; cmp = hb_ntxItemCompare( pPage->pKeys[ i ].pItem , pKey, TRUE ); + if( !pPage->TagParent->AscendKey ) + cmp = -cmp; if( !cmp && pPage->TagParent->UniqueKey ) return 1; } @@ -1503,6 +1509,7 @@ static BOOL hb_ntxSortKeyAdd( LPTAGINFO pTag, LPNTXSORTINFO pSortInfo, char* szk LPSORTITEM pKeyNew, pKey, pKeyTmp, pKeyLast = NULL, pKeyPrev; int result; + BOOL fDescend = !pTag->AscendKey; /* printf( "\n\rhb_ntxSortKeyAdd - 0 ( %s )",szkey ); */ pKeyNew = (LPSORTITEM) ( pSortInfo->sortBuffer + @@ -1521,7 +1528,10 @@ static BOOL hb_ntxSortKeyAdd( LPTAGINFO pTag, LPNTXSORTINFO pSortInfo, char* szk { pKeyTmp = (LPSORTITEM) ( pSortInfo->sortBuffer + pSortInfo->itemLength * ( ulKeyNo - 2 ) ); - if( memcmp( pKeyNew->key, pKeyTmp->key, pTag->KeyLength ) < 0 ) + result = memcmp( pKeyNew->key, pKeyTmp->key, pTag->KeyLength ); + if( fDescend && result ) + result = ( result > 0 )? -1:1; + if( result < 0 ) pKeyNew->pNext = pKeyTmp; else { @@ -1547,27 +1557,37 @@ static BOOL hb_ntxSortKeyAdd( LPTAGINFO pTag, LPNTXSORTINFO pSortInfo, char* szk pKeyPrev = pKeyLast; pKey = pKeyLast->pNext; } - else if( pSortInfo->pKey1 && - ( result = memcmp( pKeyNew->key, pSortInfo->pKey1->key, pTag->KeyLength ) ) >= 0 ) + else if( pSortInfo->pKey1 ) { - if( !result && pTag->UniqueKey ) + result = memcmp( pKeyNew->key, pSortInfo->pKey1->key, pTag->KeyLength ); + if( fDescend && result ) + result = ( result > 0 )? -1:1; + if( result >= 0 ) { - pSortInfo->ulKeyCount --; - pKeyNew = pKeyTmp; - ( pSortInfo->nItems ) --; - continue; + if( !result && pTag->UniqueKey ) + { + pSortInfo->ulKeyCount --; + pKeyNew = pKeyTmp; + ( pSortInfo->nItems ) --; + continue; + } + else + { + pKeyPrev = pSortInfo->pKey1; + pKey = pSortInfo->pKey1->pNext; + } } else - { - pKeyPrev = pSortInfo->pKey1; - pKey = pSortInfo->pKey1->pNext; - } + pKey = pSortInfo->pKeyFirst; } else pKey = pSortInfo->pKeyFirst; while( pKey ) { - if( ( result = memcmp( pKeyNew->key, pKey->key, pTag->KeyLength ) ) < 0 ) + result = memcmp( pKeyNew->key, pKey->key, pTag->KeyLength ); + if( fDescend && result ) + result = ( result > 0 )? -1:1; + if( result < 0 ) { pKeyNew->pNext = pKey; if( pKeyPrev ) @@ -1661,6 +1681,8 @@ static BOOL hb_ntxGetSortedKey( LPTAGINFO pTag, LPNTXSORTINFO pSortInfo, LPSORTI { char *key1, *key2; short int nPage, iPage; + int result; + BOOL fDescend = !pTag->AscendKey; USHORT itemLength = sizeof( ULONG ) + pTag->KeyLength; LPSORTITEM pKey = *ppKey; LPSWAPPAGE pSwapPage = (LPSWAPPAGE) ( pSortInfo->swappages ); @@ -1678,14 +1700,26 @@ static BOOL hb_ntxGetSortedKey( LPTAGINFO pTag, LPNTXSORTINFO pSortInfo, LPSORTI { key2 = ( (LPPAGEITEM) ( pSwapPage->page + itemLength*pSwapPage->curkey ) )->key; - if( !key1 || memcmp( (BYTE*)key1,(BYTE*)key2,pTag->KeyLength ) > 0 ) + if( key1 ) + { + result = memcmp( (BYTE*)key1,(BYTE*)key2,pTag->KeyLength ); + if( fDescend && result ) + result = ( result > 0 )? -1:1; + } + if( !key1 || result > 0 ) { nPage = iPage; key1 = key2; } } } - if( ( pKey && !key1 ) || ( pKey && memcmp( (BYTE*)key1,(BYTE*)pKey->key,pTag->KeyLength ) > 0 ) ) + if( pKey && key1 ) + { + result = memcmp( (BYTE*)key1,(BYTE*)pKey->key,pTag->KeyLength ); + if( fDescend && result ) + result = ( result > 0 )? -1:1; + } + if( ( pKey && !key1 ) || ( pKey && result > 0 ) ) { pKeyRoot->rec_no = pKey->rec_no; memcpy( pKeyRoot->key, pKey->key, pTag->KeyLength ); @@ -2122,6 +2156,7 @@ static void hb_ntxHeaderSave( LPNTXINDEX pIndex ) if( pIndex->CompoundTag->ForExpr ) strcpy( Header.for_expr , pIndex->CompoundTag->ForExpr ); Header.unique = pIndex->CompoundTag->UniqueKey; + Header.descend = !pIndex->CompoundTag->AscendKey; hb_fsSeek( pIndex->DiskFile , 0 , 0 ); hb_fsWrite( pIndex->DiskFile,(BYTE*)&Header,sizeof(NTXHEADER)); if( pIndex->CompoundTag->RootPage ) @@ -2254,8 +2289,8 @@ static ERRCODE hb_ntxHeaderLoad( LPNTXINDEX pIndex , char *ITN) pTag->pKeyItem = pKeyExp; pTag->pForItem = pForExp; - pTag->AscendKey = 1; /* fAscendKey; */ pTag->UniqueKey = Header.unique; + pTag->AscendKey = !Header.descend; pTag->KeyType = 'C'; /* bKeyType; */ pTag->KeyLength = Header.key_size; pTag->KeyDec = Header.key_dec; @@ -3411,6 +3446,7 @@ HB_FUNC(_DBFNTX ) { } + HB_FUNC( DBFNTX_GETFUNCTABLE ) { RDDFUNCS * pTable; diff --git a/harbour/source/vm/runner.c b/harbour/source/vm/runner.c index 7b6b599357..56972dfe24 100644 --- a/harbour/source/vm/runner.c +++ b/harbour/source/vm/runner.c @@ -135,6 +135,7 @@ static void hb_hrbAsmPatchRelative( BYTE * pCode, ULONG ulOffset, void * Ad static FILE * hb_hrbFileOpen( char * szFileName ); static void hb_hrbFileRead( FILE * file, char * szFileName, char * cBuffer, int iSize, int iCount ); static BYTE hb_hrbFileReadByte( FILE * file, char * szFileName ); +static int hb_hrbFileReadHead( FILE * file, char * szFileName ); static char * hb_hrbFileReadId( FILE * file, char * szFileName ); static long hb_hrbFileReadLong( FILE * file, char * szFileName ); static void hb_hrbFileClose( FILE * file ); @@ -300,7 +301,13 @@ PHRB_BODY hb_hrbLoad( char* szHrb ) PHB_SYMB pSymRead; /* Symbols read */ PHB_DYNF pDynFunc; /* Functions read */ PHB_DYNS pDynSym; + int nVersion = hb_hrbFileReadHead( file, szFileName ); + if( !nVersion ) + { + hb_hrbFileClose( file ); + return NULL; + } pHrbBody = ( PHRB_BODY ) hb_xgrab( sizeof( HRB_BODY ) ); pHrbBody->ulSymStart = -1; pHrbBody->ulSymbols = hb_hrbFileReadLong( file, szFileName ); @@ -498,6 +505,25 @@ static ULONG hb_hrbFindSymbol( char * szName, PHB_DYNF pDynFunc, ULONG ulLoaded return ulRet; } +static int hb_hrbFileReadHead( FILE * file, char * szFileName ) +{ + char szHead[] = { '\192','H','R','B' }, szBuf[4]; + char cInt[ 2 ]; + + HB_TRACE(HB_TR_DEBUG, ("hb_hrbFileReadHead(%p)", file )); + + hb_hrbFileRead( file, szFileName, szBuf, 1, 4 ); + if( !strncmp( szHead,szBuf,4 ) ) + { + hb_errRT_BASE_Ext1( EG_CORRUPTION, 9999, NULL, szFileName, 0, EF_CANDEFAULT, 1, hb_paramError( 1 ) ); + return 0; + } + hb_hrbFileRead( file, szFileName, cInt, 2, 1 ); + + return ( ( BYTE ) cInt[ 0 ] ) + + ( ( BYTE ) cInt[ 1 ] ) * 0x100 ; + +} /* ReadId Read the next (zero terminated) identifier */