From bedaef925f0f2a3aa140244534dad11a8f35597d Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 28 May 2007 07:52:08 +0000 Subject: [PATCH] 2007-05-28 09:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/make_xmingw.sh * harbour/source/pp/Makefile * recent xHarbour fixes for MinGW Linux->W32 cross build by Phil Krylow with small modifications * harbour/config/rules.cf + added rules for C++ files * harbour/include/hbapi.h * harbour/source/vm/arrays.c + added hb_arraySetForward() * harbour/include/hbapi.h * harbour/source/rtl/strmatch.c + added hb_strMatchFile() - compare two strings using platform dependent rules for file matching, respects platform dependent wildcards + added hb_strMatchCaseWildExact() - compare two strings using pattern with wildcard (?*) ignoring the case of the characters - patern have to cover whole string * changed hb_strMatchRegExp() to use real reguar expresions, if build does not support regex then redirected to hb_strMatchWildExact() - removed not longer used hb_strMatchDOS() - in fact it was neither DOS nor classic wildcards (?*) compatible * harbour/source/common/hbstr.c ! casting to avoid possible problem on platforms where toupper does not accept negative char value * harbour/include/hbcomp.h * harbour/source/compiler/hbcomp.c * harbour/source/compiler/hbmain.c * minor modifications in cleanup functions * harbour/source/rtl/hbffind.c * use hb_strMatchFile() * harbour/source/vm/memvars.c * use hb_strMatchCaseWildExact() instead of hb_strMatchRegExp() I still keep the hack which translates any mask starting with '*' to "*" but if you think that we should fully respect wildcards patterns then we should remove it from function hb_memvarGetMask() Opinions? --- harbour/ChangeLog | 44 +++++++++ harbour/config/rules.cf | 14 +++ harbour/include/hbapi.h | 5 +- harbour/include/hbcomp.h | 1 + harbour/make_xmingw.sh | 21 ++++- harbour/source/common/hbstr.c | 2 +- harbour/source/compiler/hbcomp.c | 30 ++++++ harbour/source/compiler/hbmain.c | 36 +------ harbour/source/pp/Makefile | 4 +- harbour/source/rtl/hbffind.c | 10 +- harbour/source/rtl/strmatch.c | 155 +++++++++++++++++++++---------- harbour/source/vm/arrays.c | 16 ++++ harbour/source/vm/memvars.c | 51 +++++----- 13 files changed, 266 insertions(+), 123 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 71a5915fe7..42ad1097a7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,50 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-05-28 09:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/make_xmingw.sh + * harbour/source/pp/Makefile + * recent xHarbour fixes for MinGW Linux->W32 cross build by Phil Krylow + with small modifications + + * harbour/config/rules.cf + + added rules for C++ files + + * harbour/include/hbapi.h + * harbour/source/vm/arrays.c + + added hb_arraySetForward() + + * harbour/include/hbapi.h + * harbour/source/rtl/strmatch.c + + added hb_strMatchFile() - compare two strings using platform dependent + rules for file matching, respects platform dependent wildcards + + added hb_strMatchCaseWildExact() - compare two strings using pattern + with wildcard (?*) ignoring the case of the characters - patern have + to cover whole string + * changed hb_strMatchRegExp() to use real reguar expresions, if build + does not support regex then redirected to hb_strMatchWildExact() + - removed not longer used hb_strMatchDOS() - in fact it was neither DOS + nor classic wildcards (?*) compatible + + * harbour/source/common/hbstr.c + ! casting to avoid possible problem on platforms where toupper does not + accept negative char value + + * harbour/include/hbcomp.h + * harbour/source/compiler/hbcomp.c + * harbour/source/compiler/hbmain.c + * minor modifications in cleanup functions + + * harbour/source/rtl/hbffind.c + * use hb_strMatchFile() + + * harbour/source/vm/memvars.c + * use hb_strMatchCaseWildExact() instead of hb_strMatchRegExp() + I still keep the hack which translates any mask starting with '*' + to "*" but if you think that we should fully respect wildcards + patterns then we should remove it from function hb_memvarGetMask() + Opinions? + 2007-05-26 09:05 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/pp/ppcore.c ! fixed bug reported by Lorenzo diff --git a/harbour/config/rules.cf b/harbour/config/rules.cf index 897a5596bf..2c682e670c 100644 --- a/harbour/config/rules.cf +++ b/harbour/config/rules.cf @@ -34,6 +34,12 @@ ifeq ($(CC_RULE),) CC_RULE = $(CC) $(CPPFLAGS) $(CFLAGS) $(C_USR) $(CC_IN) $? $(CC_OUT)$(?F:.c=$(OBJ_EXT)) endif +# The rule to compile a C++ source file. +ifeq ($(CPP_RULE),) +# Use default rule if architecture/compiler specific rule is not defined +CPP_RULE = $(CC) $(CPPFLAGS) $(CFLAGS) $(C_USR) $(CC_IN) $? $(CC_OUT)$(?F:.cpp=$(OBJ_EXT)) +endif + # Eliminate these rules. @@ -57,6 +63,14 @@ endif %$(OBJ_EXT) : %.c $(CC_RULE) +#rules for CPP files +%$(OBJ_EXT) : $(SOURCE_DIR)%.cpp + $(CPP_RULE) + +%$(OBJ_EXT) : %.cpp + $(CPP_RULE) + + # Rule to generate an executable file from an object file. %$(EXE_EXT) : %$(OBJ_EXT) $(LD_RULE) diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 20909e44b3..49a770e848 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -658,6 +658,7 @@ extern HB_EXPORT BOOL hb_arrayDel( PHB_ITEM pArray, ULONG ulIndex ); /* del extern HB_EXPORT BOOL hb_arraySize( PHB_ITEM pArray, ULONG ulLen ); /* sets the array total length */ extern HB_EXPORT BOOL hb_arrayLast( PHB_ITEM pArray, PHB_ITEM pResult ); /* retrieve last item in an array */ extern HB_EXPORT BOOL hb_arraySet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ); /* sets an array element */ +extern HB_EXPORT BOOL hb_arraySetForward( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ); /* sets an array element by forwarding it's value */ extern HB_EXPORT BOOL hb_arrayGet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ); /* retrieves an item */ extern HB_EXPORT BOOL hb_arrayGetItemRef( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ); /* create a reference to an array element */ /* hb_arrayGetItemPtr() is dangerous */ @@ -765,9 +766,11 @@ extern HB_EXPORT BOOL hb_valStrnToNum( const char* szNum, ULONG ulLen, HB_L extern HB_EXPORT BOOL hb_strToNum( const char* szNum, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ extern HB_EXPORT BOOL hb_strnToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ -extern HB_EXPORT BOOL hb_strMatchRegExp( const char * szString, const char * szMask ); /* compare two strings using a regular expression pattern */ +extern HB_EXPORT BOOL hb_strMatchFile( const char * pszString, const char * szPattern ); /* compare two strings using platform dependent rules for file matching */ +extern HB_EXPORT BOOL hb_strMatchRegExp( const char * szString, const char * szPattern ); /* compare two strings using a regular expression pattern */ extern HB_EXPORT BOOL hb_strMatchWild(const char *szString, const char *szPattern ); /* compare two strings using pattern with wildcard (?*) - patern have to be prefix of given string */ extern HB_EXPORT BOOL hb_strMatchWildExact( const char *szString, const char *szPattern ); /* compare two strings using pattern with wildcard (?*) - patern have to cover whole string */ +extern HB_EXPORT BOOL hb_strMatchCaseWildExact( const char *szString, const char *szPattern ); /* compare two strings using pattern with wildcard (?*) ignoring the case of the characters - patern have to cover whole string */ extern HB_EXPORT BOOL hb_strEmpty( const char * szText, ULONG ulLen ); /* returns whether a string contains only white space */ extern HB_EXPORT void hb_strDescend( char * szStringTo, const char * szStringFrom, ULONG ulLen ); /* copy a string to a buffer, inverting each character */ extern HB_EXPORT ULONG hb_strAt( const char * szSub, ULONG ulSubLen, const char * szText, ULONG ulLen ); /* returns an index to a sub-string within another string */ diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 7d1f6ca80d..888dd1eaf3 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -88,6 +88,7 @@ extern void hb_compGenLabelTable( PFUNCTION pFunc, PHB_LABEL_INFO label_info ); extern PHB_DEBUGINFO hb_compGetDebugInfo( HB_COMP_DECL ); extern void hb_compInitPP( HB_COMP_DECL, int argc, char * argv[] ); +extern void hb_compCompileEnd( HB_COMP_DECL ); extern int hb_compparse( HB_COMP_DECL ); extern void hb_compParserStop( HB_COMP_DECL ); diff --git a/harbour/make_xmingw.sh b/harbour/make_xmingw.sh index 6787620e55..d41b1291eb 100644 --- a/harbour/make_xmingw.sh +++ b/harbour/make_xmingw.sh @@ -8,6 +8,11 @@ # Copyright 2003-2005 by Phil Krylov # +cleanup() +{ + rm -fR "${HB_BIN_COMPILE}" +} + UNAME=`uname` export HB_ARCHITECTURE=w32 @@ -43,15 +48,21 @@ fi CCPATH="$MINGW_PREFIX/bin:$MINGW_PREFIX/$TARGET/bin:" PATH="$CCPATH$PATH" +export HB_BIN_COMPILE=/tmp/hb-xmingw-$$ +rm -fR "${HB_BIN_COMPILE}" +trap cleanup EXIT &>/dev/null +mkdir ${HB_BIN_COMPILE} + if which harbour &> /dev/null; then - rm -f -r /tmp/harbour.exe - ln -s `which harbour` /tmp/harbour.exe - export HB_BIN_COMPILE=/tmp + ln -s `which harbour` ${HB_BIN_COMPILE}/harbour.exe else echo "You must have a working Harbour executable for your platform on your PATH." exit 1 fi +(cd `dirname $0`; ln -s `pwd`/source/pp/linux/gcc/ppgen ${HB_BIN_COMPILE}/ppgen.exe) +export HB_PPGEN_PATH=${HB_BIN_COMPILE} + export PATH CCPATH CCPREFIX case "$1" in @@ -64,3 +75,7 @@ case "$1" in . `dirname $0`/make_gnu.sh "$@" ;; esac + +stat="$?" +cleanup +exit "${stat}" diff --git a/harbour/source/common/hbstr.c b/harbour/source/common/hbstr.c index b64fd09968..67557fd3a7 100644 --- a/harbour/source/common/hbstr.c +++ b/harbour/source/common/hbstr.c @@ -124,7 +124,7 @@ HB_EXPORT char * hb_strupr( char * pszText ) HB_TRACE(HB_TR_DEBUG, ("hb_strupr(%s)", pszText)); for( pszPos = pszText; *pszPos; pszPos++ ) - *pszPos = toupper( *pszPos ); + *pszPos = toupper( ( UCHAR ) *pszPos ); return pszText; } diff --git a/harbour/source/compiler/hbcomp.c b/harbour/source/compiler/hbcomp.c index d75b62dbc3..bc9ce0e72b 100644 --- a/harbour/source/compiler/hbcomp.c +++ b/harbour/source/compiler/hbcomp.c @@ -249,6 +249,36 @@ HB_COMP_PTR hb_comp_new( void ) void hb_comp_free( HB_COMP_PTR pComp ) { + hb_compCompileEnd( pComp ); + hb_compParserStop( pComp ); + + /* free allocated expressions only when errors appear - in all + * other cases expressions should be always cleanly freed so + * executing hb_compExprLstDealloc() may only hides some real + * memory leaks + */ + if( pComp->iErrorCount != 0 ) + hb_compExprLstDealloc( pComp ); + + hb_compIdentifierClose( pComp ); + + if( pComp->pOutPath ) + hb_xfree( pComp->pOutPath ); + + if( pComp->pPpoPath ) + hb_xfree( pComp->pPpoPath ); + + while( pComp->autoopen ) + { + PAUTOOPEN pAutoOpen = pComp->autoopen; + + pComp->autoopen = pComp->autoopen->pNext; + hb_xfree( pAutoOpen ); + } + + if( pComp->pOutBuf ) + hb_xfree( pComp->pOutBuf ); + if( pComp->pLex ) { if( pComp->pLex->pPP ) diff --git a/harbour/source/compiler/hbmain.c b/harbour/source/compiler/hbmain.c index 72f212f49a..3481c23e2c 100644 --- a/harbour/source/compiler/hbmain.c +++ b/harbour/source/compiler/hbmain.c @@ -78,33 +78,6 @@ FILE * hb_comp_errFile = NULL; /* ************************************************************************* */ -static void hb_compMainExit( HB_COMP_DECL ) -{ - hb_compParserStop( HB_COMP_PARAM ); - if( HB_COMP_PARAM->iErrorCount != 0 ) - hb_compExprLstDealloc( HB_COMP_PARAM ); - hb_compIdentifierClose( HB_COMP_PARAM ); - - if( HB_COMP_PARAM->pOutPath ) - hb_xfree( HB_COMP_PARAM->pOutPath ); - - if( HB_COMP_PARAM->pPpoPath ) - hb_xfree( HB_COMP_PARAM->pPpoPath ); - - while( HB_COMP_PARAM->autoopen ) - { - PAUTOOPEN pAutoOpen = HB_COMP_PARAM->autoopen; - - HB_COMP_PARAM->autoopen = HB_COMP_PARAM->autoopen->pNext; - hb_xfree( pAutoOpen ); - } - - if( HB_COMP_PARAM->pOutBuf ) - hb_xfree( HB_COMP_PARAM->pOutBuf ); - - hb_comp_free( HB_COMP_PARAM ); -} - int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) { HB_COMP_DECL; @@ -144,14 +117,14 @@ int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) { printf( "\n" ); hb_verBuildInfo(); - hb_compMainExit( HB_COMP_PARAM ); + hb_comp_free( HB_COMP_PARAM ); return iStatus; } if( HB_COMP_PARAM->fCredits ) { hb_compPrintCredits(); - hb_compMainExit( HB_COMP_PARAM ); + hb_comp_free( HB_COMP_PARAM ); return iStatus; } @@ -212,7 +185,7 @@ int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) } } - hb_compMainExit( HB_COMP_PARAM ); + hb_comp_free( HB_COMP_PARAM ); return iStatus; } @@ -4134,7 +4107,7 @@ static void hb_compAddInitFunc( HB_COMP_DECL, PFUNCTION pFunc ) hb_compGenPCode1( HB_P_ENDPROC, HB_COMP_PARAM ); } -static void hb_compCompileEnd( HB_COMP_DECL ) +void hb_compCompileEnd( HB_COMP_DECL ) { hb_compRTVariableKill( HB_COMP_PARAM ); hb_compLoopKill( HB_COMP_PARAM ); @@ -4150,6 +4123,7 @@ static void hb_compCompileEnd( HB_COMP_DECL ) hb_xfree( HB_COMP_PARAM->pMainFileName ); HB_COMP_PARAM->pMainFileName = NULL; } + if( HB_COMP_PARAM->pFileName ) { hb_xfree( HB_COMP_PARAM->pFileName ); diff --git a/harbour/source/pp/Makefile b/harbour/source/pp/Makefile index b6913b96f7..9bc3f1da9e 100644 --- a/harbour/source/pp/Makefile +++ b/harbour/source/pp/Makefile @@ -16,7 +16,9 @@ LIBNAME=pp LIBS=\ common \ +HB_PPGEN_PATH ?= . + include $(TOP)$(ROOT)config/lib.cf pptable.c : ppgen$(EXE_EXT) - ./ppgen$(EXE_EXT) $(TOP)$(ROOT)include/hbstdgen.ch -opptable.c -q + $(HB_PPGEN_PATH)/ppgen$(EXE_EXT) $(TOP)$(ROOT)include/hbstdgen.ch -opptable.c -q diff --git a/harbour/source/rtl/hbffind.c b/harbour/source/rtl/hbffind.c index e32d85604a..50ed85f53d 100644 --- a/harbour/source/rtl/hbffind.c +++ b/harbour/source/rtl/hbffind.c @@ -150,9 +150,6 @@ HB_FILE_VER( "$Id$" ) #include #include #include -#if !defined( __WATCOMC__ ) - #include -#endif typedef struct { @@ -665,12 +662,7 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) while( ( info->entry = readdir( info->dir ) ) != NULL ) { hb_strncpy( string, info->entry->d_name, sizeof( string ) - 1 ); - -#if defined( __WATCOMC__ ) - if( hb_strMatchWild( string, info->pattern ) ) -#else - if( fnmatch( info->pattern, string, FNM_PERIOD | FNM_PATHNAME ) == 0 ) -#endif + if( hb_strMatchFile( string, info->pattern ) ) { bFound = TRUE; break; diff --git a/harbour/source/rtl/strmatch.c b/harbour/source/rtl/strmatch.c index c47b4218ce..a3cb194930 100644 --- a/harbour/source/rtl/strmatch.c +++ b/harbour/source/rtl/strmatch.c @@ -50,52 +50,12 @@ * */ -#include - #include "hbapi.h" +#include "hbregex.h" -static BOOL hb_strMatchDOS( const char * pszString, const char * pszMask ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_strMatchDOS(%s, %s)", pszString, pszMask)); - - while( *pszMask != '\0' && *pszString != '\0' ) - { - if( *pszMask == '*' ) - { - while( *pszMask == '*' ) - pszMask++; - - if( *pszMask == '\0' ) - return TRUE; - else if( *pszMask == '?' ) - pszString++; - else - { - while( hb_charUpper( *pszString ) != hb_charUpper( *pszMask ) ) - { - if( *( ++pszString ) == '\0' ) - return FALSE; - } - while( hb_charUpper( *pszString ) == hb_charUpper( *pszMask ) ) - { - if( *( ++pszString ) == '\0' ) - break; - } - pszMask++; - } - } - else if( hb_charUpper( *pszMask ) != hb_charUpper( *pszString ) && *pszMask != '?' ) - return FALSE; - else - { - pszMask++; - pszString++; - } - } - - return ! ( ( *pszMask != '\0' && *pszString == '\0' && *pszMask != '*') || - ( *pszMask == '\0' && *pszString != '\0' ) ); -} +#if defined( HB_OS_UNIX ) && !defined( __WATCOMC__ ) +# include +#endif #define HB_MAX_WILDPATTERN 256 @@ -240,21 +200,114 @@ HB_EXPORT BOOL hb_strMatchWildExact( const char *szString, const char *szPattern return fMatch; } -/* TODO: Replace it with a code that supports real regular expressions - * - */ -BOOL hb_strMatchRegExp( const char * szString, const char * szMask ) +HB_EXPORT BOOL hb_strMatchCaseWildExact( const char *szString, const char *szPattern ) { - HB_TRACE(HB_TR_DEBUG, ("hb_strMatchRegExp(%s, %s)", szString, szMask)); + BOOL fMatch = TRUE, fAny = FALSE; + ULONG pulBufPosP[ HB_MAX_WILDPATTERN ], pulBufPosV[ HB_MAX_WILDPATTERN ], + ulBufSize = HB_MAX_WILDPATTERN; + ULONG * ulAnyPosP = pulBufPosP, * ulAnyPosV = pulBufPosV, + ulSize, ulLen, ulAny, i, j; - return hb_strMatchDOS( szString, szMask ); + i = j = ulAny = 0; + ulLen = strlen( szString ); + ulSize = strlen( szPattern ); + while ( i < ulSize || ( j < ulLen && !fAny ) ) + { + if ( i < ulSize && szPattern[i] == '*' ) + { + fAny = TRUE; + i++; + } + else if ( j < ulLen && i < ulSize && + ( szPattern[i] == '?' || + hb_charUpper( szPattern[i] ) == hb_charUpper( szString[j] ) ) ) + { + if ( fAny ) + { + if ( ulAny >= ulBufSize ) + { + if( ( ulBufSize <<= 1 ) == ( HB_MAX_WILDPATTERN << 1 ) ) + { + ulAnyPosP = ( ULONG * ) hb_xgrab( ulBufSize * sizeof( ULONG ) ); + ulAnyPosV = ( ULONG * ) hb_xgrab( ulBufSize * sizeof( ULONG ) ); + memcpy( ulAnyPosP, pulBufPosP, HB_MAX_WILDPATTERN * sizeof( ULONG ) ); + memcpy( ulAnyPosV, pulBufPosV, HB_MAX_WILDPATTERN * sizeof( ULONG ) ); + } + else + { + ulAnyPosP = ( ULONG * ) hb_xrealloc( ulAnyPosP, ulBufSize * sizeof( ULONG ) ); + ulAnyPosV = ( ULONG * ) hb_xrealloc( ulAnyPosV, ulBufSize * sizeof( ULONG ) ); + } + } + ulAnyPosP[ulAny] = i; + ulAnyPosV[ulAny] = j; + ulAny++; + fAny = FALSE; + } + j++; + i++; + } + else if ( fAny && j < ulLen ) + { + j++; + } + else if ( ulAny > 0 ) + { + ulAny--; + i = ulAnyPosP[ulAny]; + j = ulAnyPosV[ulAny] + 1; + fAny = TRUE; + } + else + { + fMatch = FALSE; + break; + } + } + if( ulBufSize > HB_MAX_WILDPATTERN ) + { + hb_xfree( ulAnyPosP ); + hb_xfree( ulAnyPosV ); + } + return fMatch; +} + +BOOL hb_strMatchRegExp( const char * szString, const char * szPattern ) +{ + PHB_REGEX pRegEx; + + HB_TRACE(HB_TR_DEBUG, ("hb_strMatchRegExp(%s, %s)", szString, szPattern)); + + pRegEx = hb_regexCompile( szPattern, strlen( szPattern ), HBREG_EXTENDED ); + if( pRegEx ) + { + BOOL fMatch; + fMatch = hb_regexMatch( pRegEx, szString, TRUE ); + hb_regexFree( pRegEx ); + return fMatch; + } + else + return hb_strMatchWildExact( szString, szPattern ); +} + +HB_EXPORT BOOL hb_strMatchFile( const char * szString, const char * szPattern ) +{ +#if defined( HB_OS_UNIX ) +# if defined( __WATCOMC__ ) + return hb_strMatchWildExact( szString, szPattern ); +# else + return fnmatch( szPattern, szString, FNM_PERIOD | FNM_PATHNAME ) == 0; +# endif +#else + return hb_strMatchCaseWildExact( szString, szPattern ); +#endif } /* * WildMatch( cPattern, cValue [, lExact] ) compares * cValue with cPattern, cPattern * may contain wildcard characters (?*) * When lExact is TRUE then it will check if whole cValue is covered by - * cPattern else if will check if cPatern is a prefix of cValue + * cPattern else it will check if cPatern is a prefix of cValue */ /* NOTE: This function is compatible with sx_WildMatch(), except when diff --git a/harbour/source/vm/arrays.c b/harbour/source/vm/arrays.c index 6d5d491b69..cb11e27d2d 100644 --- a/harbour/source/vm/arrays.c +++ b/harbour/source/vm/arrays.c @@ -391,6 +391,22 @@ HB_EXPORT BOOL hb_arraySet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ) return FALSE; } +HB_EXPORT BOOL hb_arraySetForward( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_arraySetForward(%p, %lu, %p)", pArray, ulIndex, pItem)); + + if( HB_IS_ARRAY( pArray ) && ulIndex > 0 && ulIndex <= pArray->item.asArray.value->ulLen ) + { + hb_itemMove( pArray->item.asArray.value->pItems + ( ulIndex - 1 ), pItem ); + return TRUE; + } + else + { + hb_itemClear( pItem ); + return FALSE; + } +} + HB_EXPORT BOOL hb_arrayGet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ) { HB_TRACE(HB_TR_DEBUG, ("hb_arrayGet(%p, %lu, %p)", pArray, ulIndex, pItem)); diff --git a/harbour/source/vm/memvars.c b/harbour/source/vm/memvars.c index a192f7f03b..4c70164905 100644 --- a/harbour/source/vm/memvars.c +++ b/harbour/source/vm/memvars.c @@ -762,12 +762,8 @@ static void hb_memvarReleaseWithMask( char *szMask, BOOL bInclude ) */ if( pDynVar->hMemvar ) { - if( bInclude ) - { - if( ( szMask[ 0 ] == '*') || hb_strMatchRegExp( pDynVar->pSymbol->szName, szMask ) ) - hb_itemClear( s_globalTable[ pDynVar->hMemvar ].pVarItem ); - } - else if( ! hb_strMatchRegExp( pDynVar->pSymbol->szName, szMask ) ) + BOOL fMatch = hb_strMatchCaseWildExact( pDynVar->pSymbol->szName, szMask ); + if( bInclude ? fMatch : !fMatch ) hb_itemClear( s_globalTable[ pDynVar->hMemvar ].pVarItem ); } } @@ -935,6 +931,14 @@ static HB_ITEM_PTR hb_memvarDebugVariable( int iScope, int iPos, const char * * /* ************************************************************************** */ +static char * hb_memvarGetMask( int iParam ) +{ + char * pszMask = hb_parc( iParam ); + if( !pszMask || pszMask[ 0 ] == '*' ) + pszMask = "*"; + return pszMask; +} + HB_FUNC( __MVPUBLIC ) { int iCount = hb_pcount(); @@ -1036,23 +1040,15 @@ HB_FUNC( __MVRELEASE ) { int iCount = hb_pcount(); - if( iCount ) + if( iCount && ISCHAR( 1 ) ) { - PHB_ITEM pMask = hb_param( 1, HB_IT_STRING ); + BOOL bIncludeVar; + char * pszMask; - if( pMask ) - { - BOOL bIncludeVar; - - if( iCount > 1 ) - bIncludeVar = hb_parl( 2 ); - else - bIncludeVar = TRUE; - - if( pMask->item.asString.value[ 0 ] == '*' ) - bIncludeVar = TRUE; /* delete all memvar variables */ - hb_memvarReleaseWithMask( pMask->item.asString.value, bIncludeVar ); - } + pszMask = hb_memvarGetMask( 1 ); + bIncludeVar = ( pszMask[ 0 ] == '*' && !pszMask[ 1 ] ) || + iCount < 2 || hb_parl( 2 ); + hb_memvarReleaseWithMask( pszMask, bIncludeVar ); } } @@ -1254,7 +1250,7 @@ static HB_DYNS_FUNC( hb_memvarSave ) if( pDynSymbol->hMemvar ) { - BOOL bMatch = ( pszMask[ 0 ] == '*' || hb_strMatchRegExp( pDynSymbol->pSymbol->szName, pszMask ) ); + BOOL bMatch = hb_strMatchCaseWildExact( pDynSymbol->pSymbol->szName, pszMask ); PHB_ITEM pItem = s_globalTable[ pDynSymbol->hMemvar ].pVarItem; @@ -1374,7 +1370,7 @@ HB_FUNC( __MVSAVE ) BYTE buffer[ HB_MEM_REC_LEN ]; MEMVARSAVE_CARGO msc; - msc.pszMask = hb_parc( 2 ); + msc.pszMask = hb_memvarGetMask( 2 ); msc.bIncludeMask = hb_parl( 3 ); msc.buffer = buffer; msc.fhnd = fhnd; @@ -1441,9 +1437,12 @@ HB_FUNC( __MVRESTORE ) if( fhnd != FS_ERROR ) { - char * pszMask = ISCHAR( 3 ) ? hb_parc( 3 ) : ( char * ) "*"; - BOOL bIncludeMask = ISLOG( 4 ) ? hb_parl( 4 ) : TRUE; + BOOL bIncludeMask; BYTE buffer[ HB_MEM_REC_LEN ]; + char * pszMask; + + pszMask = hb_memvarGetMask( 3 ); + bIncludeMask = !ISLOG( 4 ) || hb_parl( 4 ); while( hb_fsRead( fhnd, buffer, HB_MEM_REC_LEN ) == HB_MEM_REC_LEN ) { @@ -1503,7 +1502,7 @@ HB_FUNC( __MVRESTORE ) if( pItem ) { - BOOL bMatch = ( pszMask[ 0 ] == '*' || hb_strMatchRegExp( szName, pszMask ) ); + BOOL bMatch = hb_strMatchCaseWildExact( szName, pszMask ); /* Process it if it matches the passed mask */ if( bIncludeMask ? bMatch : ! bMatch )