From bdc6e81793b2bde69babd82aba2c8268975bc4f3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 13 Feb 2009 10:04:16 +0000 Subject: [PATCH] 2009-02-13 11:08 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbpp.h * harbour/source/pp/hbpp.c * harbour/source/pp/ppcore.c * harbour/source/compiler/hbmain.c + added support for dynamically calculated #define results ! removed old code which was adding __FILE__ #define constant It was not working correctly like in other compilers ignoring #include + added __FILE__ and __LINE__ #define directives using dynamically calculated results - now it works as expected respecting #include directives and the implementation is local to PP without any hacks in core compiler code. * harbour/contrib/hbct/files.c * added support for optional milliseconds part in HB_FSETDATETIME()/ HB_FGETDATETIME(). * harbour/source/rtl/philes.c ! minor fix in return value --- harbour/ChangeLog | 21 ++++++++++ harbour/contrib/hbct/files.c | 2 +- harbour/include/hbpp.h | 1 + harbour/source/compiler/hbmain.c | 20 ---------- harbour/source/pp/hbpp.c | 1 + harbour/source/pp/ppcore.c | 68 ++++++++++++++++++-------------- harbour/source/rtl/philes.c | 19 +++++---- 7 files changed, 75 insertions(+), 57 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3319984747..5956e12310 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,27 @@ 2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-02-13 11:08 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbpp.h + * harbour/source/pp/hbpp.c + * harbour/source/pp/ppcore.c + * harbour/source/compiler/hbmain.c + + added support for dynamically calculated #define results + ! removed old code which was adding __FILE__ #define constant + It was not working correctly like in other compilers ignoring + #include + + added __FILE__ and __LINE__ #define directives using dynamically + calculated results - now it works as expected respecting #include + directives and the implementation is local to PP without any hacks + in core compiler code. + + * harbour/contrib/hbct/files.c + * added support for optional milliseconds part in HB_FSETDATETIME()/ + HB_FGETDATETIME(). + + * harbour/source/rtl/philes.c + ! minor fix in return value + 2009-02-13 10:51 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * include/hbdefs.h * contrib/gtwvg/gtwvg.h diff --git a/harbour/contrib/hbct/files.c b/harbour/contrib/hbct/files.c index e534259cda..afec40b24c 100644 --- a/harbour/contrib/hbct/files.c +++ b/harbour/contrib/hbct/files.c @@ -260,7 +260,7 @@ HB_FUNC( SETFDATI ) } SystemTimeToFileTime( &st, &local_ft ); LocalFileTimeToFileTime( &local_ft, &ft ); - hb_retl( SetFileTime( f, NULL, &ft, &ft ) ); + hb_retl( SetFileTime( f, NULL, &ft, &ft ) != 0 ); _lclose( ( HFILE ) f ); return; } diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index f6a7e1cf04..f33cd550c9 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -136,6 +136,7 @@ typedef HB_PP_SWITCH_FUNC * PHB_PP_SWITCH_FUNC; #define HB_PP_RMARKER_LOGICAL 16 #define HB_PP_RMARKER_NUL 17 #define HB_PP_RMARKER_OPTIONAL 18 +#define HB_PP_RMARKER_DYNVAL 19 /* keywords, pseudo keywords and PP only tokens */ #define HB_PP_TOKEN_KEYWORD 21 diff --git a/harbour/source/compiler/hbmain.c b/harbour/source/compiler/hbmain.c index 1b3caf83dd..10972a1ff5 100644 --- a/harbour/source/compiler/hbmain.c +++ b/harbour/source/compiler/hbmain.c @@ -3921,26 +3921,6 @@ static int hb_compCompile( HB_COMP_DECL, const char * szPrg, int iFileType ) { BOOL bSkipGen = FALSE ; - /* Add __FILE__ define */ - hb_pp_delDefine( HB_COMP_PARAM->pLex->pPP, "__FILE__" ); - if( iFileType == HB_COMP_SINGLEFILE ) - { - char* pBuf; - ULONG ulLen = strlen( szFileName ); - - pBuf = ( char* ) hb_xgrab( ulLen + 3 ); - pBuf[ 0 ] = '"'; - memcpy( pBuf + 1, szFileName, ulLen ); - pBuf[ ulLen + 1 ] = '"'; - pBuf[ ulLen + 2 ] = '\0'; - hb_pp_addDefine( HB_COMP_PARAM->pLex->pPP, "__FILE__", pBuf ); - hb_xfree( pBuf ); - } - else - { - hb_pp_addDefine( HB_COMP_PARAM->pLex->pPP, "__FILE__", "\"\"" ); - } - HB_COMP_PARAM->szFile = HB_COMP_PARAM->currModule = hb_compIdentifierNew( HB_COMP_PARAM, szFileName, HB_IDENT_COPY ); HB_COMP_PARAM->currLine = 1; diff --git a/harbour/source/pp/hbpp.c b/harbour/source/pp/hbpp.c index dd821bddde..b7d5d61642 100644 --- a/harbour/source/pp/hbpp.c +++ b/harbour/source/pp/hbpp.c @@ -244,6 +244,7 @@ static void hb_pp_undefCompilerRules( PHB_PP_STATE pState ) "__DATE__", "__TIME__", "__FILE__", + "__LINE__", "__HB_MAIN__", "__ARCH16BIT__", "__ARCH32BIT__", diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 855e64af92..d1a9c86345 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -208,6 +208,8 @@ static const HB_PP_OPERATOR s_operators[] = /* illegal in Clipper: ~ */ }; +static const char s_pp_dynamicResult = 0; + static void hb_pp_disp( PHB_PP_STATE pState, const char * szMessage ) { if( !pState->pDispFunc ) @@ -4028,6 +4030,26 @@ static PHB_PP_TOKEN * hb_pp_patternStuff( PHB_PP_STATE pState, pResultPtr ); } } + else if( HB_PP_TOKEN_TYPE( pResultPattern->type ) == HB_PP_RMARKER_DYNVAL ) + { + if( hb_pp_tokenValueCmp( pResultPattern, "__FILE__", HB_PP_CMP_CASE ) ) + { + const char * szFileName = pState->pFile ? pState->pFile->szFileName : NULL; + if( !szFileName ) + szFileName = ""; + * pResultPtr = hb_pp_tokenNew( szFileName, strlen( szFileName ), 0, + HB_PP_TOKEN_STRING ); + pResultPtr = &( * pResultPtr )->pNext; + } + else if( hb_pp_tokenValueCmp( pResultPattern, "__LINE__", HB_PP_CMP_CASE ) ) + { + char line[ 16 ]; + hb_snprintf( line, sizeof( line ), "%d", pState->pFile ? pState->pFile->iCurrentLine : 0 ); + * pResultPtr = hb_pp_tokenNew( line, strlen( line ), 0, + HB_PP_TOKEN_NUMBER ); + pResultPtr = &( * pResultPtr )->pNext; + } + } else { * pResultPtr = hb_pp_tokenClone( pResultPattern ); @@ -5295,28 +5317,8 @@ void hb_pp_initDynDefines( PHB_PP_STATE pState ) szResult[ 9 ] = '"'; szResult[ 10 ] = '\0'; hb_pp_addDefine( pState, "__TIME__", szResult ); - - /* __FILE__ */ - if( pState->pFile ) - { - char* pBuf; - ULONG ulLen = strlen( pState->pFile->szFileName ); - - pBuf = ( char* ) hb_xgrab( ulLen + 3 ); - pBuf[ 0 ] = '"'; - memcpy( pBuf + 1, pState->pFile->szFileName, ulLen ); - pBuf[ ulLen + 1 ] = '"'; - pBuf[ ulLen + 2 ] = '\0'; - hb_pp_addDefine( pState, "__FILE__", pBuf ); - hb_xfree( pBuf ); - } - else - { - szResult[ 0 ] = '"'; - szResult[ 1 ] = '"'; - szResult[ 2 ] = '\0'; - hb_pp_addDefine( pState, "__FILE__", szResult ); - } + hb_pp_addDefine( pState, "__FILE__", &s_pp_dynamicResult ); + hb_pp_addDefine( pState, "__LINE__", &s_pp_dynamicResult ); hb_snprintf( szResult, sizeof( szResult ), "%d", ( int ) sizeof( void * ) ); #if defined( HB_ARCH_16BIT ) @@ -5568,13 +5570,21 @@ void hb_pp_addDefine( PHB_PP_STATE pState, const char * szDefName, if( szDefValue && !pState->fError ) { - pFile->pLineBuf = szDefValue; - pFile->ulLineBufLen = strlen( szDefValue ); - hb_pp_getLine( pState ); - pResult = pState->pFile->pTokenList; - pState->pFile->pTokenList = NULL; - pToken = hb_pp_tokenResultEnd( &pResult, TRUE ); - hb_pp_tokenListFree( &pToken ); + if( szDefValue == &s_pp_dynamicResult ) + { + pResult = hb_pp_tokenNew( szDefName, strlen( szDefName ), 0, + HB_PP_RMARKER_DYNVAL | HB_PP_TOKEN_STATIC ); + } + else + { + pFile->pLineBuf = szDefValue; + pFile->ulLineBufLen = strlen( szDefValue ); + hb_pp_getLine( pState ); + pResult = pState->pFile->pTokenList; + pState->pFile->pTokenList = NULL; + pToken = hb_pp_tokenResultEnd( &pResult, TRUE ); + hb_pp_tokenListFree( &pToken ); + } } else pResult = NULL; diff --git a/harbour/source/rtl/philes.c b/harbour/source/rtl/philes.c index b11efa1f9e..6f91077be9 100644 --- a/harbour/source/rtl/philes.c +++ b/harbour/source/rtl/philes.c @@ -391,14 +391,18 @@ HB_FUNC( HB_FSETATTR ) HB_FUNC( HB_FSETDATETIME ) { - int iHour, iMinutes, iSeconds; + const char * szTime = hb_parc( 3 ); + LONG lTime = -1; - hb_timeStrGet( hb_parcx( 3 ), &iHour, &iMinutes, &iSeconds, NULL ); + if( szTime ) + { + int iHour, iMinutes, iSeconds, iMSec; + hb_timeStrGet( szTime, &iHour, &iMinutes, &iSeconds, &iMSec ); + lTime = hb_timeStampEncode( iHour, iMinutes, iSeconds, iMSec ); + } - hb_retl( hb_fsSetFileTime( - ( UCHAR * ) hb_parcx( 1 ), - ISDATE( 2 ) ? hb_pardl( 2 ) : -1, - ISCHAR( 3 ) ? hb_timeStampEncode( iHour, iMinutes, iSeconds, 0 ) : -1 ) ); + hb_retl( hb_fsSetFileTime( ( UCHAR * ) hb_parcx( 1 ), + ISDATE( 2 ) ? hb_pardl( 2 ) : -1, lTime ) ); } HB_FUNC( HB_FGETDATETIME ) @@ -412,7 +416,8 @@ HB_FUNC( HB_FGETDATETIME ) hb_stordl( lJulian, 2 ); hb_timeStampStr( buf, lMillisec ); - buf[ 8 ] = '\0'; + if( lMillisec % 1000 == 0 ) + buf[ 8 ] = '\0'; hb_storc( buf, 3 ); /* hb_stornl( lMillisec, 4 ); */