diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9391e583e2..2eca489c66 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,20 @@ The license applies to all entries newer than 2009-04-28. */ +2011-10-20 20:19 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbpp.h + * harbour/include/hbcomp.h + * harbour/include/hbcompdf.h + * harbour/src/compiler/hbmain.c + * harbour/src/compiler/hbcomp.c + * harbour/src/compiler/hbgenerr.c + + added support for redirecting compiler warning and error messages + to user function. + + * harbour/src/compiler/hbcmplib.c + + optional support for generating RTE in HB_COMPILE*() functions + on compile errors. + 2011-10-20 15:21 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbpgsql/hbpgsql.hbx * contrib/hbpgsql/hbpgsql.hbp diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 6aab01fa31..5d707a6d77 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -266,7 +266,7 @@ extern HB_BOOL hb_compCheckUnclosedStru( HB_COMP_DECL, PFUNCTION ); #define HB_GEN_FUNC4( func, p1,p2,p3,p4 ) hb_compGen##func( p1, p2, p3, p4, HB_COMP_PARAM ) extern int hb_compMain( int argc, const char * const argv[] ); -extern int hb_compMainExt( int argc, const char * const argv[], HB_BYTE ** pBufPtr, HB_SIZE * pnSize, const char * szSource, void * cargo, PHB_PP_OPEN_FUNC pOpenFunc ); +extern int hb_compMainExt( int argc, const char * const argv[], HB_BYTE ** pBufPtr, HB_SIZE * pnSize, const char * szSource, void * cargo, PHB_PP_OPEN_FUNC pOpenFunc, PHB_PP_MSG_FUNC pMsgFunc ); extern void hb_compOutStd( HB_COMP_DECL, const char * szMessage ); extern void hb_compOutErr( HB_COMP_DECL, const char * szMessage ); diff --git a/harbour/include/hbcompdf.h b/harbour/include/hbcompdf.h index 3f66e1cceb..57dc85d784 100644 --- a/harbour/include/hbcompdf.h +++ b/harbour/include/hbcompdf.h @@ -775,6 +775,7 @@ typedef struct _HB_COMP void ( * outStdFunc ) ( void *, const char* ); void ( * outErrFunc ) ( void *, const char* ); + PHB_PP_MSG_FUNC outMsgFunc; void * cargo; HB_SIZE nOutBufSize; /* memory output buffer size */ diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index ba2957f07b..e51db2ebdd 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -120,6 +120,10 @@ typedef HB_PP_SWITCH_FUNC_( ( * PHB_PP_SWITCH_FUNC ) ); #define HB_PP_INC_FUNC_( func ) void func( void *, const char * ) typedef HB_PP_INC_FUNC_( ( * PHB_PP_INC_FUNC ) ); +/* function to generate errors */ +#define HB_PP_MSG_FUNC_( func ) void func( void * cargo, int iErrorFmt, int iLine, const char * szModule, char cPrefix, int iValue, const char * szText, const char * szPar1, const char * szPar2 ) +typedef HB_PP_MSG_FUNC_( ( * PHB_PP_MSG_FUNC ) ); + /* preprocessor tokens */ #define HB_PP_TOKEN_NUL 0 diff --git a/harbour/src/compiler/hbcmplib.c b/harbour/src/compiler/hbcmplib.c index 01a6a0b7b4..5b98c523b2 100644 --- a/harbour/src/compiler/hbcmplib.c +++ b/harbour/src/compiler/hbcmplib.c @@ -53,6 +53,34 @@ #include "hbapi.h" #include "hbcomp.h" +static void s_pp_msg( void * cargo, int iErrorFmt, int iLine, + const char * szModule, char cPrefix, int iValue, + const char * szText, + const char * szPar1, const char * szPar2 ) +{ + HB_SYMBOL_UNUSED( cargo ); + + /* ignore all warning messages and errors when break or quit request */ + if( cPrefix != 'W' && hb_vmRequestQuery() == 0 ) + { + char szMsgBuf[ 512 ], szLine[ 512 ]; + PHB_ITEM pError; + + hb_snprintf( szMsgBuf, sizeof( szMsgBuf ), szText, szPar1, szPar2 ); + if( !szModule || *szModule == 0 || strcmp( szModule, "{SOURCE}" ) == 0 ) + hb_snprintf( szLine, sizeof( szLine ), + "line:%i", iLine ); + else + hb_snprintf( szLine, sizeof( szLine ), + iErrorFmt == HB_ERRORFMT_CLIPPER ? "%s(%i)" : "%s:%i", + szModule, iLine ); + pError = hb_errRT_New( ES_ERROR, "COMPILER", 1001, ( HB_ERRCODE ) iValue, szMsgBuf, + szLine, 0 /*OsCode*/, EF_NONE | EF_CANDEFAULT ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + } +} + static int s_pp_openFile( void * cargo, char * szFileName, HB_BOOL fBefore, HB_BOOL fSysFile, HB_BOOL fBinary, HB_PATHNAMES * pIncludePaths, @@ -97,13 +125,25 @@ static int s_pp_openFile( void * cargo, char * szFileName, static void hb_compGenArgList( int iFirst, int iLast, int * pArgC, const char *** pArgV, PHB_ITEM * pIncItem, - PHB_PP_OPEN_FUNC * pOpenFunc ) + PHB_PP_OPEN_FUNC * pOpenFunc, + PHB_PP_MSG_FUNC * pMsgFunc ) { PHB_ITEM pParam; HB_SIZE ul, nLen; int argc = 1, i; const char ** argv; + if( pMsgFunc ) + { + * pMsgFunc = NULL; + if( HB_ISLOG( iFirst ) ) + { + if( hb_parl( iFirst ) ) + * pMsgFunc = s_pp_msg; + ++iFirst; + } + } + if( pIncItem && pOpenFunc ) { *pOpenFunc = NULL; @@ -167,10 +207,10 @@ HB_FUNC( HB_COMPILE ) const char ** argv; PHB_ITEM pIncItem; PHB_PP_OPEN_FUNC pOpenFunc; + PHB_PP_MSG_FUNC pMsgFunc; - hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc ); - - hb_retni( hb_compMainExt( argc, argv, NULL, NULL, NULL, pIncItem, pOpenFunc ) ); + hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc ); + hb_retni( hb_compMainExt( argc, argv, NULL, NULL, NULL, pIncItem, pOpenFunc, pMsgFunc ) ); hb_xfree( argv ); } @@ -180,12 +220,14 @@ HB_FUNC( HB_COMPILEBUF ) const char ** argv; PHB_ITEM pIncItem; PHB_PP_OPEN_FUNC pOpenFunc; + PHB_PP_MSG_FUNC pMsgFunc; HB_BYTE * pBuffer; HB_SIZE nLen; - hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc ); - iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, NULL, pIncItem, pOpenFunc ); + hb_compGenArgList( 1, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc ); + iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, NULL, pIncItem, pOpenFunc, pMsgFunc ); hb_xfree( argv ); + if( iResult == EXIT_SUCCESS && pBuffer ) hb_retclen_buffer( ( char * ) pBuffer, nLen ); } @@ -197,15 +239,17 @@ HB_FUNC( HB_COMPILEFROMBUF ) const char * szSource; PHB_ITEM pIncItem; PHB_PP_OPEN_FUNC pOpenFunc; + PHB_PP_MSG_FUNC pMsgFunc; HB_BYTE * pBuffer; HB_SIZE nLen; szSource = hb_parc( 1 ); if( szSource ) { - hb_compGenArgList( 2, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc ); - iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, szSource, pIncItem, pOpenFunc ); + hb_compGenArgList( 2, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc ); + iResult = hb_compMainExt( argc, argv, &pBuffer, &nLen, szSource, pIncItem, pOpenFunc, pMsgFunc ); hb_xfree( argv ); + if( iResult == EXIT_SUCCESS && pBuffer ) hb_retclen_buffer( ( char * ) pBuffer, nLen ); } diff --git a/harbour/src/compiler/hbcomp.c b/harbour/src/compiler/hbcomp.c index 462b121984..6f1d930ae4 100644 --- a/harbour/src/compiler/hbcomp.c +++ b/harbour/src/compiler/hbcomp.c @@ -165,6 +165,67 @@ static void hb_compErrorDuplVar( HB_COMP_DECL, const char * szVarName ) hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_VAR_DUPL, szVarName, NULL ); } +static void hb_compOutMsg( void * cargo, int iErrorFmt, int iLine, + const char * szModule, char cPrefix, int iValue, + const char * szText, + const char * szPar1, const char * szPar2 ) +{ + char buffer[ 512 ]; + + if( szModule ) + { + if( iErrorFmt == HB_ERRORFMT_CLIPPER ) + hb_snprintf( buffer, sizeof( buffer ), "\r%s(%i) ", szModule, iLine ); + else if( iLine ) + hb_snprintf( buffer, sizeof( buffer ), "\n%s:%i: ", szModule, iLine ); + else + hb_snprintf( buffer, sizeof( buffer ), "\n%s:%s ", szModule, szPar2 ); + + hb_compOutErr( ( HB_COMP_PTR ) cargo, buffer ); + } + + if( iErrorFmt == HB_ERRORFMT_CLIPPER ) + hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ", + cPrefix == 'W' ? "Warning" : "Error", cPrefix, iValue ); + else + hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ", + cPrefix == 'W' ? "warning" : "error", cPrefix, iValue ); + + hb_compOutErr( ( HB_COMP_PTR ) cargo, buffer ); + hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); + hb_compOutErr( ( HB_COMP_PTR ) cargo, buffer ); + hb_compOutErr( ( HB_COMP_PTR ) cargo, "\n" ); +} + +void hb_compOutStd( HB_COMP_DECL, const char * szMessage ) +{ + if( ! HB_COMP_PARAM->fFullQuiet ) + { + if( HB_COMP_PARAM->outStdFunc ) + HB_COMP_PARAM->outStdFunc( HB_COMP_PARAM, szMessage ); + else +#if defined( HB_OS_DOS ) + fprintf( stderr, "%s", szMessage ); fflush( stderr ); +#else + fprintf( stdout, "%s", szMessage ); fflush( stdout ); +#endif + } +} + +void hb_compOutErr( HB_COMP_DECL, const char * szMessage ) +{ + if( ! HB_COMP_PARAM->fFullQuiet ) + { + if( HB_COMP_PARAM->outErrFunc ) + HB_COMP_PARAM->outErrFunc( HB_COMP_PARAM, szMessage ); + else +#if defined( HB_OS_DOS ) + fprintf( stdout, "%s", szMessage ); fflush( stdout ); +#else + fprintf( stderr, "%s", szMessage ); fflush( stderr ); +#endif + } +} static const HB_COMP_FUNCS s_comp_funcs = { hb_compExprNew, @@ -227,6 +288,8 @@ HB_COMP_PTR hb_comp_new( void ) pComp->iExitLevel = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */ pComp->iLanguage = HB_LANG_C; /* default Harbour generated output language */ pComp->iErrorFmt = HB_ERRORFMT_CLIPPER; /* default Harbour generated output language */ + + pComp->outMsgFunc = hb_compOutMsg; } return pComp; @@ -299,33 +362,3 @@ void hb_comp_free( HB_COMP_PTR pComp ) hb_xfree( pComp ); } - -void hb_compOutStd( HB_COMP_DECL, const char * szMessage ) -{ - if( ! HB_COMP_PARAM->fFullQuiet ) - { - if( HB_COMP_PARAM->outStdFunc ) - HB_COMP_PARAM->outStdFunc( HB_COMP_PARAM->cargo, szMessage ); - else -#if defined( HB_OS_DOS ) - fprintf( stderr, "%s", szMessage ); fflush( stderr ); -#else - fprintf( stdout, "%s", szMessage ); fflush( stdout ); -#endif - } -} - -void hb_compOutErr( HB_COMP_DECL, const char * szMessage ) -{ - if( ! HB_COMP_PARAM->fFullQuiet ) - { - if( HB_COMP_PARAM->outErrFunc ) - HB_COMP_PARAM->outErrFunc( HB_COMP_PARAM->cargo, szMessage ); - else -#if defined( HB_OS_DOS ) - fprintf( stdout, "%s", szMessage ); fflush( stdout ); -#else - fprintf( stderr, "%s", szMessage ); fflush( stderr ); -#endif - } -} diff --git a/harbour/src/compiler/hbgenerr.c b/harbour/src/compiler/hbgenerr.c index 787dca9277..f8afca3954 100644 --- a/harbour/src/compiler/hbgenerr.c +++ b/harbour/src/compiler/hbgenerr.c @@ -153,34 +153,9 @@ static void hb_compDispMessage( HB_COMP_DECL, char cPrefix, int iValue, const char * szText, const char * szPar1, const char * szPar2 ) { - char buffer[ 512 ]; - - if( HB_COMP_PARAM->currModule ) - { - if( HB_COMP_PARAM->iErrorFmt == HB_ERRORFMT_CLIPPER ) - hb_snprintf( buffer, sizeof( buffer ), "\r%s(%i) ", - HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine ); - else if( HB_COMP_PARAM->currLine ) - hb_snprintf( buffer, sizeof( buffer ), "\n%s:%i: ", - HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine ); - else - hb_snprintf( buffer, sizeof( buffer ), "\n%s:%s ", - HB_COMP_PARAM->currModule, szPar2 ); - - hb_compOutErr( HB_COMP_PARAM, buffer ); - } - - if( HB_COMP_PARAM->iErrorFmt == HB_ERRORFMT_CLIPPER ) - hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ", - cPrefix == 'W' ? "Warning" : "Error", cPrefix, iValue ); - else - hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ", - cPrefix == 'W' ? "warning" : "error", cPrefix, iValue ); - - hb_compOutErr( HB_COMP_PARAM, buffer ); - hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); - hb_compOutErr( HB_COMP_PARAM, buffer ); - hb_compOutErr( HB_COMP_PARAM, "\n" ); + HB_COMP_PARAM->outMsgFunc( HB_COMP_PARAM, HB_COMP_PARAM->iErrorFmt, + HB_COMP_PARAM->currLine, HB_COMP_PARAM->currModule, + cPrefix, iValue, szText, szPar1, szPar2 ); } void hb_compGenError( HB_COMP_DECL, const char * const szErrors[], diff --git a/harbour/src/compiler/hbmain.c b/harbour/src/compiler/hbmain.c index bd031d97e9..61b083964c 100644 --- a/harbour/src/compiler/hbmain.c +++ b/harbour/src/compiler/hbmain.c @@ -62,7 +62,8 @@ static HB_BOOL hb_compRegisterFunc( HB_COMP_DECL, PFUNCTION pFunc, HB_BOOL fErro int hb_compMainExt( int argc, const char * const argv[], HB_BYTE ** pBufPtr, HB_SIZE * pnSize, const char * szSource, - void * cargo, PHB_PP_OPEN_FUNC pOpenFunc ) + void * cargo, PHB_PP_OPEN_FUNC pOpenFunc, + PHB_PP_MSG_FUNC pMsgFunc ) { HB_COMP_DECL; int iStatus = EXIT_SUCCESS; @@ -79,6 +80,8 @@ int hb_compMainExt( int argc, const char * const argv[], HB_COMP_PARAM = hb_comp_new(); HB_COMP_PARAM->cargo = cargo; + if( pMsgFunc ) + HB_COMP_PARAM->outMsgFunc = pMsgFunc; HB_COMP_PARAM->pOutPath = NULL; @@ -180,7 +183,7 @@ int hb_compMainExt( int argc, const char * const argv[], int hb_compMain( int argc, const char * const argv[] ) { - return hb_compMainExt( argc, argv, NULL, NULL, NULL, NULL, NULL ); + return hb_compMainExt( argc, argv, NULL, NULL, NULL, NULL, NULL, NULL ); } static int hb_compReadClpFile( HB_COMP_DECL, const char * szClpFile )