diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4615e8276d..4f4a4100e0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,31 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-08-21 16:00 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/vm/memvars.c + + added __MVSETBASE() function + + * harbour/source/pp/ppcore.c + * redirect error messages when error trap is not defined into + user dispout function + + * harbour/include/hbcomp.h + * harbour/source/compiler/hbmain.c + * harbour/source/compiler/cmdcheck.c + * harbour/source/compiler/hbcomp.c + * harbour/source/compiler/genjava.c + * harbour/source/compiler/genc.c + * harbour/source/compiler/hbcmplib.c + * harbour/source/compiler/ppcomp.c + * harbour/source/compiler/gencli.c + * harbour/source/compiler/genhrb.c + * harbour/source/compiler/gencobj.c + * harbour/source/compiler/genobj32.c + * harbour/source/compiler/hbusage.c + * harbour/source/compiler/hbgenerr.c + + added hb_compOutStd() and hb_compOutErr() + * redirected all compiler output to above functions + 2007-08-20 23:55 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/harbour.spec ! added workaround for undefined Epoch tag diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index dd66fba363..9b05ef5c04 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -267,6 +267,9 @@ extern BOOL hb_compCheckUnclosedStru( HB_COMP_DECL ); #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, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ); +extern void hb_compOutStd( HB_COMP_DECL, const char * szMessage ); +extern void hb_compOutErr( HB_COMP_DECL, const char * szMessage ); + extern void hb_compExprLstDealloc( HB_COMP_DECL ); extern HB_EXPR_PTR hb_compExprGenStatement( HB_EXPR_PTR, HB_COMP_DECL ); @@ -304,12 +307,10 @@ extern void hb_compChkCompilerSwitch( HB_COMP_DECL, int, char * Args[] ); extern void hb_compChkPaths( HB_COMP_DECL ); extern void hb_compChkDefines( HB_COMP_DECL, int iArg, char * Args[] ); -extern void hb_compPrintUsage( char * ); -extern void hb_compPrintCredits( void ); -extern void hb_compFileInfo( void ); -extern void hb_compPrintLogo( void ); -extern void hb_compPrintModes( void ); - +extern void hb_compPrintUsage( HB_COMP_DECL, char * ); +extern void hb_compPrintCredits( HB_COMP_DECL ); +extern void hb_compPrintLogo( HB_COMP_DECL ); +extern void hb_compPrintModes( HB_COMP_DECL ); /* Misc functions defined in harbour.c */ extern void hb_compNOOPfill( PFUNCTION pFunc, ULONG ulFrom, int iCount, BOOL fPop, BOOL fCheck ); diff --git a/harbour/source/compiler/cmdcheck.c b/harbour/source/compiler/cmdcheck.c index ff7ae6b598..8e16c62cd7 100644 --- a/harbour/source/compiler/cmdcheck.c +++ b/harbour/source/compiler/cmdcheck.c @@ -102,6 +102,16 @@ static ULONG PackDateTime( void ) return HB_MKLONG( szString[3], szString[2], szString[1], szString[0] ); } +static void hb_notSupportedInfo( HB_COMP_DECL, char *szSwitch ) +{ + char buffer[ 512 ]; + + snprintf( buffer, sizeof( buffer ), + "Not yet supported command line option: %s\n", szSwitch ); + + hb_compOutStd( HB_COMP_PARAM, buffer ); +} + static void hb_compChkEnvironVar( HB_COMP_DECL, char *szSwitch ) { if( szSwitch && !HB_COMP_PARAM->fExit ) @@ -109,13 +119,8 @@ static void hb_compChkEnvironVar( HB_COMP_DECL, char *szSwitch ) char *s = szSwitch; /* If szSwitch doesn't start with a HB_OSOPTSEP char - show an error + * show an error */ - - /* - printf( "Switch: %s\n", s ); - */ - if( !HB_ISOPTSEP( *s ) ) hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL ); else @@ -323,8 +328,8 @@ static void hb_compChkEnvironVar( HB_COMP_DECL, char *szSwitch ) switch( s[i++] ) { case '?': - hb_compPrintLogo( ); - hb_compPrintModes( ); + hb_compPrintLogo( HB_COMP_PARAM ); + hb_compPrintModes( HB_COMP_PARAM ); HB_COMP_PARAM->fLogo = FALSE; HB_COMP_PARAM->fQuiet = TRUE; break; @@ -463,7 +468,7 @@ static void hb_compChkEnvironVar( HB_COMP_DECL, char *szSwitch ) else { /* TODO: Implement this switch */ - printf( "Not yet supported command line option: %s\n", s ); + hb_notSupportedInfo( HB_COMP_PARAM, s ); } break; @@ -478,7 +483,7 @@ static void hb_compChkEnvironVar( HB_COMP_DECL, char *szSwitch ) case 't': case 'T': /* TODO: Implement this switch */ - printf( "Not yet supported command line option: %s\n", s ); + hb_notSupportedInfo( HB_COMP_PARAM, s ); break; case 'u': diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index 9efcddc2c2..bbeb0835c1 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -79,8 +79,10 @@ void hb_compGenCCode( HB_COMP_DECL, PHB_FNAME pFileName ) /* generates the if( ! HB_COMP_PARAM->fQuiet ) { - printf( "Generating C source output to \'%s\'... ", szFileName ); - fflush( stdout ); + char buffer[ 80 + _POSIX_PATH_MAX ]; + snprintf( buffer, sizeof( buffer ), + "Generating C source output to \'%s\'... ", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } { @@ -361,7 +363,7 @@ void hb_compGenCCode( HB_COMP_DECL, PHB_FNAME pFileName ) /* generates the fclose( yyc ); if( ! HB_COMP_PARAM->fQuiet ) - printf( "Done.\n" ); + hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); } static void hb_writeEndInit( HB_COMP_DECL, FILE* yyc, char * szModulname, char * szSourceFile ) diff --git a/harbour/source/compiler/gencli.c b/harbour/source/compiler/gencli.c index 9145857d67..11871a2971 100644 --- a/harbour/source/compiler/gencli.c +++ b/harbour/source/compiler/gencli.c @@ -85,8 +85,10 @@ void hb_compGenILCode( HB_COMP_DECL, PHB_FNAME pFileName ) /* generates the IL if( ! HB_COMP_PARAM->fQuiet ) { - printf( "Generating IL source output to \'%s\'... ", szFileName ); - fflush( stdout ); + char buffer[ 80 + _POSIX_PATH_MAX ]; + snprintf( buffer, sizeof( buffer ), + "Generating IL source output to \'%s\'... ", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } szVer = hb_verHarbour(); @@ -175,7 +177,7 @@ void hb_compGenILCode( HB_COMP_DECL, PHB_FNAME pFileName ) /* generates the IL fclose( yyc ); if( ! HB_COMP_PARAM->fQuiet ) - printf( "Done.\n" ); + hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); } static HB_GENC_FUNC( hb_p_and ) diff --git a/harbour/source/compiler/gencobj.c b/harbour/source/compiler/gencobj.c index 0c371902bb..7ebf3eb275 100644 --- a/harbour/source/compiler/gencobj.c +++ b/harbour/source/compiler/gencobj.c @@ -136,6 +136,7 @@ void hb_compGenCObj( HB_COMP_DECL, PHB_FNAME pFileName ) char szCommandLine[ HB_CFG_LINE_LEN * 2 + 1 ]; char szOutPath[ _POSIX_PATH_MAX + 1 ] = "\0"; char pszTemp[ _POSIX_PATH_MAX + 1 ] = ""; + char buffer[ HB_CFG_LINE_LEN * 2 + 1024 ]; #if defined( HOST_OS_UNIX_COMPATIBLE ) char * pszEnv = hb_strdup( "/etc:/usr/local/etc" ); #elif defined( OS_DOS_COMPATIBLE ) @@ -235,22 +236,22 @@ void hb_compGenCObj( HB_COMP_DECL, PHB_FNAME pFileName ) fclose( filecfg ); } else { - - printf( "\nError: Can't find %s file in %s.\n", pszCfgFileName, pszEnv ); - printf( "%s should be a text file that contains:\n", pszCfgFileName ); - printf( "CC=C compiler binary name eg. CC=gcc\n" ); - printf( "CFLAGS=C compiler options eg. -c -I\n" ); - printf( " ( 'compile only' and harbour include dir are mandatory )\n" ); - printf( "VERBOSE=NO|YES to show steps messages default is NO\n" ); - printf( "DELTMP=NO|YES to delete generated C source default is YES\n" ); - printf( "remember also to properly set the C compiler env.\n" ); + snprintf( buffer, sizeof( buffer ), + "\nError: Can't find %s file in %s.\n" + "%s should be a text file that contains:\n" + "CC=C compiler binary name eg. CC=gcc\n" + "CFLAGS=C compiler options eg. -c -I\n" + " ( 'compile only' and harbour include dir are mandatory )\n" + "VERBOSE=NO|YES to show steps messages default is NO\n" + "DELTMP=NO|YES to delete generated C source default is YES\n" + "remember also to properly set the C compiler env.\n", + pszCfgFileName, pszEnv, pszCfgFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); if( pszEnv ) hb_xfree( ( void * ) pszEnv ); hb_xfree( ( void * ) pszCfgFileName ); - return; - } if( pszEnv ) @@ -258,8 +259,10 @@ void hb_compGenCObj( HB_COMP_DECL, PHB_FNAME pFileName ) if( ! HB_COMP_PARAM->fQuiet ) { - printf( "\nBuilding object module for \'%s\'\nusing C compiler \'%s\' as defined in \'%s\'...\n", szFileName, szCompiler, pszCfgFileName ); - fflush( stdout ); + snprintf( buffer, sizeof( buffer ), + "\nBuilding object module for \'%s\'\nusing C compiler \'%s\' as defined in \'%s\'...\n", + szFileName, szCompiler, pszCfgFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } /* Check if -o was used */ @@ -293,9 +296,12 @@ void hb_compGenCObj( HB_COMP_DECL, PHB_FNAME pFileName ) if( *szCompiler ) { snprintf( szCommandLine, sizeof( szCommandLine ), "%s %s %s %s", szCompiler, szOptions, szOutPath, szFileName ); - + if( bVerbose ) - printf( "Exec: %s\n", szCommandLine ) ; + { + snprintf( buffer, sizeof( buffer ), "Exec: %s\n", szCommandLine ); + hb_compOutStd( HB_COMP_PARAM, buffer ); + } else hb_strncat( szCommandLine, HB_NULL_STR, sizeof( szCommandLine ) - 1 ); @@ -307,20 +313,31 @@ void hb_compGenCObj( HB_COMP_DECL, PHB_FNAME pFileName ) if( bDelTmp ) /* && iSuccess ) */ { if( bVerbose ) - printf( "Deleting: \"%s\"\n", szFileName ); + { + snprintf( buffer, sizeof( buffer ), "Deleting: \"%s\"\n", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); + } remove( ( char * ) szFileName ); } if( ! HB_COMP_PARAM->fQuiet ) { if( iSuccess ) - printf( "Done.\n" ); + hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); else - printf( "\nFailed to execute: \"%s\"\n", szCommandLine ); + { + snprintf( buffer, sizeof( buffer ), + "\nFailed to execute: \"%s\"\n", szCommandLine ); + hb_compOutErr( HB_COMP_PARAM, buffer ); + } } } else - printf( "\nError: No compiler defined in %s\n", pszCfgFileName ); + { + snprintf( buffer, sizeof( buffer ), + "\nError: No compiler defined in %s\n", pszCfgFileName ); + hb_compOutErr( HB_COMP_PARAM, buffer ); + } hb_xfree( ( void * ) pszCfgFileName ); } diff --git a/harbour/source/compiler/genhrb.c b/harbour/source/compiler/genhrb.c index 475f146612..3144842564 100644 --- a/harbour/source/compiler/genhrb.c +++ b/harbour/source/compiler/genhrb.c @@ -147,8 +147,10 @@ void hb_compGenPortObj( HB_COMP_DECL, PHB_FNAME pFileName ) if( ! HB_COMP_PARAM->fQuiet ) { - printf( "Generating Harbour Portable Object output to \'%s\'... ", szFileName ); - fflush( stdout ); + char buffer[ 80 + _POSIX_PATH_MAX ]; + snprintf( buffer, sizeof( buffer ), + "Generating Harbour Portable Object source output to \'%s\'... ", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } hb_compGenBufPortObj( HB_COMP_PARAM, &pHrbBody, &ulSize ); @@ -158,5 +160,5 @@ void hb_compGenPortObj( HB_COMP_DECL, PHB_FNAME pFileName ) fclose( yyc ); if( ! HB_COMP_PARAM->fQuiet ) - printf( "Done.\n" ); + hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); } diff --git a/harbour/source/compiler/genjava.c b/harbour/source/compiler/genjava.c index e69da2ea47..58f26bc02b 100644 --- a/harbour/source/compiler/genjava.c +++ b/harbour/source/compiler/genjava.c @@ -83,8 +83,10 @@ void hb_compGenJava( HB_COMP_DECL, PHB_FNAME pFileName ) if( ! HB_COMP_PARAM->fQuiet ) { - printf( "Generating Java source output to \'%s\'... ", szFileName ); - fflush( stdout ); + char buffer[ 80 + _POSIX_PATH_MAX ]; + snprintf( buffer, sizeof( buffer ), + "Generating Java source output to \'%s\'... ", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } nChar = 0; @@ -178,5 +180,5 @@ void hb_compGenJava( HB_COMP_DECL, PHB_FNAME pFileName ) fclose( fOut ); if( ! HB_COMP_PARAM->fQuiet ) - printf( "Done.\n" ); + hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); } diff --git a/harbour/source/compiler/genobj32.c b/harbour/source/compiler/genobj32.c index dfae0bb4cf..55c4742bcc 100644 --- a/harbour/source/compiler/genobj32.c +++ b/harbour/source/compiler/genobj32.c @@ -64,41 +64,43 @@ static char * szPrefix = "_HB_FUN_"; void hb_compGenObj32( HB_COMP_DECL, PHB_FNAME pFileName ) { - char szFileName[ _POSIX_PATH_MAX + 1 ]; - FILE * hObjFile; /* file handle for OBJ output */ - char * szVer; + char szFileName[ _POSIX_PATH_MAX + 1 ]; + FILE * hObjFile; /* file handle for OBJ output */ + char * szVer; - if( ! pFileName->szExtension ) - pFileName->szExtension = ".obj"; - hb_fsFNameMerge( szFileName, pFileName ); + if( ! pFileName->szExtension ) + pFileName->szExtension = ".obj"; + hb_fsFNameMerge( szFileName, pFileName ); - if( ( hObjFile = fopen( szFileName, "wb" ) ) == NULL ) - { + if( ( hObjFile = fopen( szFileName, "wb" ) ) == NULL ) + { hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_CREATE_OUTPUT, szFileName, NULL ); return; - } + } - if( ! HB_COMP_PARAM->fQuiet ) - { - printf( "Generating Windows/DOS OBJ32 output to \'%s\'... ", szFileName ); - fflush( stdout ); - } + if( ! HB_COMP_PARAM->fQuiet ) + { + char buffer[ 80 + _POSIX_PATH_MAX ]; + snprintf( buffer, sizeof( buffer ), + "Generating Windows/DOS OBJ32 output to \'%s\'... ", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); + } - CompiledFileName( hObjFile, szFileName ); - szVer = hb_verHarbour(); - CompilerVersion( hObjFile, szVer ); - hb_xfree( szVer ); - GenerateLocalNames( hObjFile ); - GenerateExternals( HB_COMP_PARAM, hObjFile ); - GenerateCodeSegment( HB_COMP_PARAM, hObjFile ); - GenerateDataSegment( HB_COMP_PARAM, hObjFile ); - GenerateSymbolsSegment( HB_COMP_PARAM, hObjFile ); - End( hObjFile ); + CompiledFileName( hObjFile, szFileName ); + szVer = hb_verHarbour(); + CompilerVersion( hObjFile, szVer ); + hb_xfree( szVer ); + GenerateLocalNames( hObjFile ); + GenerateExternals( HB_COMP_PARAM, hObjFile ); + GenerateCodeSegment( HB_COMP_PARAM, hObjFile ); + GenerateDataSegment( HB_COMP_PARAM, hObjFile ); + GenerateSymbolsSegment( HB_COMP_PARAM, hObjFile ); + End( hObjFile ); - fclose( hObjFile ); + fclose( hObjFile ); - if( ! HB_COMP_PARAM->fQuiet ) - printf( "Done.\n" ); + if( ! HB_COMP_PARAM->fQuiet ) + hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); } static USHORT hb_compFunctionGetPos( HB_COMP_DECL, char * szFunctionName ) /* return 0 if not found or order + 1 */ diff --git a/harbour/source/compiler/hbcmplib.c b/harbour/source/compiler/hbcmplib.c index ddde920d0e..63d14746c0 100644 --- a/harbour/source/compiler/hbcmplib.c +++ b/harbour/source/compiler/hbcmplib.c @@ -53,14 +53,15 @@ #include "hbapi.h" #include "hbcomp.h" -static void hb_compGenArgList( int iFirst, int * pArgC, char *** pArgV ) +static void hb_compGenArgList( int iFirst, int iLast, + int * pArgC, char *** pArgV ) { PHB_ITEM pParam, pItem; ULONG ul; - int iPCount = hb_pcount(), argc = 0, i; + int argc = 0, i; char ** argv; - for( i = iFirst; i <= iPCount; ++i ) + for( i = iFirst; i <= iLast; ++i ) { pParam = hb_param( i, HB_IT_ARRAY | HB_IT_STRING ); if( pParam ) @@ -83,7 +84,7 @@ static void hb_compGenArgList( int iFirst, int * pArgC, char *** pArgV ) argv = ( char ** ) hb_xgrab( sizeof( char * ) * ( argc + 1 ) ); argc = 0; - for( i = iFirst; i <= iPCount; ++i ) + for( i = iFirst; i <= iLast; ++i ) { pParam = hb_param( i, HB_IT_ARRAY | HB_IT_STRING ); if( pParam ) @@ -114,7 +115,7 @@ HB_FUNC( HB_COMPILE ) int argc; char ** argv; - hb_compGenArgList( 1, &argc, &argv ); + hb_compGenArgList( 1, hb_pcount(), &argc, &argv ); hb_retni( hb_compMain( argc, argv, NULL, NULL ) ); hb_xfree( argv ); @@ -127,7 +128,7 @@ HB_FUNC( HB_COMPILEBUF ) BYTE * pBuffer; ULONG ulLen; - hb_compGenArgList( 1, &argc, &argv ); + hb_compGenArgList( 1, hb_pcount(), &argc, &argv ); iResult = hb_compMain( argc, argv, &pBuffer, &ulLen ); hb_xfree( argv ); if( iResult == EXIT_SUCCESS && pBuffer ) diff --git a/harbour/source/compiler/hbcomp.c b/harbour/source/compiler/hbcomp.c index bc9ce0e72b..a811844f1b 100644 --- a/harbour/source/compiler/hbcomp.c +++ b/harbour/source/compiler/hbcomp.c @@ -289,3 +289,19 @@ void hb_comp_free( HB_COMP_PTR pComp ) hb_xfree( pComp->szStdCh ); hb_xfree( pComp ); } + +void hb_compOutStd( HB_COMP_DECL, const char * szMessage ) +{ + HB_SYMBOL_UNUSED( HB_COMP_PARAM ); + + fprintf( stderr, "%s", szMessage ); + fflush( stdout ); +} + +void hb_compOutErr( HB_COMP_DECL, const char * szMessage ) +{ + HB_SYMBOL_UNUSED( HB_COMP_PARAM ); + + fprintf( hb_comp_errFile, "%s", szMessage ); + fflush( hb_comp_errFile ); +} diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index b5c2475a2e..c58d3ade05 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -139,18 +139,34 @@ const char * hb_comp_szWarnings[] = "0Invalid variable '%s' for enumerator message" }; +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 ) + { + snprintf( buffer, sizeof( buffer ), "\r%s(%i) ", + HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine ); + hb_compOutErr( HB_COMP_PARAM, buffer ); + } + + snprintf( buffer, sizeof( buffer ), "%s %c%04i ", + cPrefix == 'W' ? "Warning" : "Error", cPrefix, iValue ); + hb_compOutErr( HB_COMP_PARAM, buffer ); + snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); + hb_compOutErr( HB_COMP_PARAM, buffer ); + hb_compOutErr( HB_COMP_PARAM, "\n" ); +} + void hb_compGenError( HB_COMP_DECL, const char * szErrors[], char cPrefix, int iError, const char * szError1, const char * szError2 ) { if( !HB_COMP_PARAM->fExit && ( cPrefix == 'F' || !HB_COMP_PARAM->fError ) ) { PFUNCTION pFunc = HB_COMP_PARAM->functions.pLast; - if( HB_COMP_PARAM->currModule ) - fprintf( hb_comp_errFile, "\r%s(%i) ", HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine ); - - fprintf( hb_comp_errFile, "Error %c%04i ", cPrefix, iError ); - fprintf( hb_comp_errFile, szErrors[ iError - 1 ], szError1, szError2 ); - fprintf( hb_comp_errFile, "\n" ); + hb_compDispMessage( HB_COMP_PARAM, cPrefix, iError, + szErrors[ iError - 1 ], szError1, szError2 ); HB_COMP_PARAM->iErrorCount++; HB_COMP_PARAM->fError = TRUE; @@ -171,12 +187,8 @@ void hb_compGenWarning( HB_COMP_DECL, const char * szWarnings[], char cPrefix, i if( !HB_COMP_PARAM->fExit && ( szText[ 0 ] - '0' <= HB_COMP_PARAM->iWarnings ) ) { - if( HB_COMP_PARAM->currModule ) - fprintf( hb_comp_errFile, "\r%s(%i) ", HB_COMP_PARAM->currModule, HB_COMP_PARAM->currLine ); - - fprintf( hb_comp_errFile, "Warning %c%04i ", cPrefix, iWarning ); - fprintf( hb_comp_errFile, szText + 1, szWarning1, szWarning2 ); - fprintf( hb_comp_errFile, "\n" ); + hb_compDispMessage( HB_COMP_PARAM, cPrefix, iWarning, + szText + 1, szWarning1, szWarning2 ); HB_COMP_PARAM->fAnyWarning = TRUE; /* report warnings at exit */ } diff --git a/harbour/source/compiler/hbmain.c b/harbour/source/compiler/hbmain.c index e46757798f..58e364e60d 100644 --- a/harbour/source/compiler/hbmain.c +++ b/harbour/source/compiler/hbmain.c @@ -111,11 +111,11 @@ int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) } if( HB_COMP_PARAM->fLogo ) - hb_compPrintLogo(); + hb_compPrintLogo( HB_COMP_PARAM ); if( HB_COMP_PARAM->fBuildInfo ) { - printf( "\n" ); + hb_compOutStd( HB_COMP_PARAM, "\n" ); hb_verBuildInfo(); hb_comp_free( HB_COMP_PARAM ); return iStatus; @@ -123,7 +123,7 @@ int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) if( HB_COMP_PARAM->fCredits ) { - hb_compPrintCredits(); + hb_compPrintCredits( HB_COMP_PARAM ); hb_comp_free( HB_COMP_PARAM ); return iStatus; } @@ -162,7 +162,7 @@ int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) if( ! bAnyFiles && ! HB_COMP_PARAM->fQuiet ) { - hb_compPrintUsage( argv[ 0 ] ); + hb_compPrintUsage( HB_COMP_PARAM, argv[ 0 ] ); iStatus = EXIT_FAILURE; } @@ -209,7 +209,10 @@ static int hb_compProcessRSPFile( HB_COMP_DECL, char * szRspName ) inFile = fopen( szRspName, "r" ); if( !inFile ) { - fprintf( hb_comp_errFile, "Cannot open input file: %s\n", szRspName ); + char buffer[ _POSIX_PATH_MAX + 80 ]; + snprintf( buffer, sizeof( buffer ), + "Cannot open input file: %s\n", szRspName ); + hb_compOutErr( HB_COMP_PARAM, buffer ); iStatus = EXIT_FAILURE; } else @@ -466,7 +469,11 @@ void hb_compVariableAdd( HB_COMP_DECL, char * szVarName, BYTE cValueType ) } else if( HB_COMP_PARAM->iVarScope != VS_PARAMETER ) { - fprintf( hb_comp_errFile, "Wrong type of codeblock parameter, is: %d, should be: %d\r\n", HB_COMP_PARAM->iVarScope, VS_PARAMETER ); + char buffer[ 80 ]; + snprintf( buffer, sizeof( buffer ), + "Wrong type of codeblock parameter, is: %d, should be: %d\r\n", + HB_COMP_PARAM->iVarScope, VS_PARAMETER ); + hb_compOutErr( HB_COMP_PARAM, buffer ); /* variable defined in a codeblock */ HB_COMP_PARAM->iVarScope = VS_PARAMETER; } @@ -483,9 +490,7 @@ void hb_compVariableAdd( HB_COMP_DECL, char * szVarName, BYTE cValueType ) if( toupper( cValueType ) == 'S' ) { - /* - printf( "\nVariable %s is of Class: %s\n", szVarName, HB_COMP_PARAM->szFromClass ); - */ + /* printf( "\nVariable %s is of Class: %s\n", szVarName, HB_COMP_PARAM->szFromClass ); */ pVar->pClass = hb_compClassFind( HB_COMP_PARAM, HB_COMP_PARAM->szFromClass ); if( ! pVar->pClass ) { @@ -1626,9 +1631,7 @@ void hb_compDeclaredParameterAdd( HB_COMP_DECL, char * szVarName, BYTE cValueTyp } else /* Declared Method Parameter */ { - /* - printf( "\nAdding parameter: %s Type: %c In Method: %s Class: %s FROM CLASS: %s\n", szVarName, cValueType, HB_COMP_PARAM->pLastMethod->szName, HB_COMP_PARAM->pLastClass->szName, HB_COMP_PARAM->szFromClass ); - */ + /* printf( "\nAdding parameter: %s Type: %c In Method: %s Class: %s FROM CLASS: %s\n", szVarName, cValueType, HB_COMP_PARAM->pLastMethod->szName, HB_COMP_PARAM->pLastClass->szName, HB_COMP_PARAM->szFromClass ); */ HB_COMP_PARAM->pLastMethod->iParamCount++; @@ -1650,9 +1653,7 @@ void hb_compDeclaredParameterAdd( HB_COMP_DECL, char * szVarName, BYTE cValueTyp { HB_COMP_PARAM->pLastMethod->pParamClasses[ HB_COMP_PARAM->pLastMethod->iParamCount - 1 ] = hb_compClassFind( HB_COMP_PARAM, HB_COMP_PARAM->szFromClass ); - /* - printf( "\nParameter: %s FROM CLASS: %s\n", szVarName, HB_COMP_PARAM->pLastMethod->pParamClasses[ HB_COMP_PARAM->pLastMethod->iParamCount - 1 ]->szName ); - */ + /* printf( "\nParameter: %s FROM CLASS: %s\n", szVarName, HB_COMP_PARAM->pLastMethod->pParamClasses[ HB_COMP_PARAM->pLastMethod->iParamCount - 1 ]->szName ); */ /* Resetting */ HB_COMP_PARAM->szFromClass = NULL; @@ -4241,6 +4242,7 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) { char szFileName[ _POSIX_PATH_MAX + 1 ]; /* filename to parse */ char szPpoName[ _POSIX_PATH_MAX + 1 ]; + char buffer[ _POSIX_PATH_MAX * 2 + 80 ]; /* Add /D command line or envvar defines */ /* hb_compChkDefines( argc, argv ); */ @@ -4257,7 +4259,9 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) if( !hb_pp_inFile( HB_COMP_PARAM->pLex->pPP, szFileName, FALSE, NULL, FALSE ) ) { - fprintf( hb_comp_errFile, "Cannot open input file: %s\n", szFileName ); + snprintf( buffer, sizeof( buffer ), + "Cannot open input file: %s\n", szFileName ); + hb_compOutErr( HB_COMP_PARAM, buffer ); iStatus = EXIT_FAILURE; } else if( bSingleFile ) @@ -4290,9 +4294,12 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) if( ! HB_COMP_PARAM->fQuiet ) { if( HB_COMP_PARAM->fPPO ) - printf( "Compiling '%s' and generating preprocessed output to '%s'...\n", szFileName, szPpoName ); + snprintf( buffer, sizeof( buffer ), + "Compiling '%s' and generating preprocessed output to '%s'...\n", + szFileName, szPpoName ); else - printf( "Compiling '%s'...\n", szFileName ); + snprintf( buffer, sizeof( buffer ), "Compiling '%s'...\n", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } /* Generate the starting procedure frame */ @@ -4317,7 +4324,8 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) } else { - printf( "Reading '%s'...\n", szFileName ); + snprintf( buffer, sizeof( buffer ), "Reading '%s'...\n", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } /* Open refernced modules (using DO ... WITh statement @@ -4400,7 +4408,11 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) { iStatus = EXIT_FAILURE; bSkipGen = TRUE; - printf( "\r%i error%s\n\nNo code generated\n", HB_COMP_PARAM->iErrorCount, ( HB_COMP_PARAM->iErrorCount > 1 ? "s" : "" ) ); + snprintf( buffer, sizeof( buffer ), + "\r%i error%s\n\nNo code generated\n", + HB_COMP_PARAM->iErrorCount, + HB_COMP_PARAM->iErrorCount > 1 ? "s" : "" ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } else if( HB_COMP_PARAM->iExitLevel == HB_EXITLEVEL_SETEXIT ) { @@ -4410,7 +4422,7 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) { iStatus = EXIT_FAILURE; bSkipGen = TRUE; - printf( "\nNo code generated.\n" ); + hb_compOutStd( HB_COMP_PARAM, "\nNo code generated.\n" ); } } @@ -4470,7 +4482,13 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) } if( ! HB_COMP_PARAM->fQuiet ) - printf( "\rLines %i, Functions/Procedures %i\n", hb_pp_lineTot( HB_COMP_PARAM->pLex->pPP ), HB_COMP_PARAM->iFunctionCnt ); + { + snprintf( buffer, sizeof( buffer ), + "\rLines %i, Functions/Procedures %i\n", + hb_pp_lineTot( HB_COMP_PARAM->pLex->pPP ), + HB_COMP_PARAM->iFunctionCnt ); + hb_compOutStd( HB_COMP_PARAM, buffer ); + } hb_compGenOutput( HB_COMP_PARAM, HB_COMP_PARAM->iLanguage ); } @@ -4545,6 +4563,7 @@ static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * pbSkipGen, BOOL b { char szFileName[ _POSIX_PATH_MAX + 1 ]; /* filename to parse */ char szPpoName[ _POSIX_PATH_MAX + 1 ]; + char buffer[ _POSIX_PATH_MAX * 2 + 80 ]; /* Clear and reinitialize preprocessor state */ hb_pp_reset( HB_COMP_PARAM->pLex->pPP ); @@ -4556,7 +4575,9 @@ static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * pbSkipGen, BOOL b if( !hb_pp_inFile( HB_COMP_PARAM->pLex->pPP, szFileName, FALSE, NULL, FALSE ) ) { - fprintf( hb_comp_errFile, "Cannot open %s, assumed external\n", szFileName ); + snprintf( buffer, sizeof( buffer ), + "Cannot open %s, assumed external\n", szFileName ); + hb_compOutErr( HB_COMP_PARAM, buffer ); iStatus = EXIT_FAILURE; } else if( HB_COMP_PARAM->fPPT ) @@ -4583,9 +4604,13 @@ static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * pbSkipGen, BOOL b if( ! HB_COMP_PARAM->fQuiet ) { if( HB_COMP_PARAM->fPPO ) - printf( "Compiling module '%s' and generating preprocessed output to '%s'...\n", szFileName, szPpoName ); + snprintf( buffer, sizeof( buffer ), + "Compiling module '%s' and generating preprocessed output to '%s'...\n", + szFileName, szPpoName ); else - printf( "Compiling module '%s'...\n", szFileName ); + snprintf( buffer, sizeof( buffer ), + "Compiling module '%s'...\n", szFileName ); + hb_compOutStd( HB_COMP_PARAM, buffer ); } /* Generate the starting procedure frame */ @@ -4615,7 +4640,7 @@ static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * pbSkipGen, BOOL b { iStatus = EXIT_FAILURE; *pbSkipGen = TRUE; - printf( "\nNo code generated.\n" ); + hb_compOutStd( HB_COMP_PARAM, "\nNo code generated.\n" ); } } } diff --git a/harbour/source/compiler/hbusage.c b/harbour/source/compiler/hbusage.c index 4487c58797..5cd4d81578 100644 --- a/harbour/source/compiler/hbusage.c +++ b/harbour/source/compiler/hbusage.c @@ -55,7 +55,7 @@ /* * Prints available options */ -void hb_compPrintUsage( char * szSelf ) +void hb_compPrintUsage( HB_COMP_DECL, char * szSelf ) { static const char * szOptions [] = { @@ -101,20 +101,25 @@ void hb_compPrintUsage( char * szSelf ) "\n @ compile list of modules in ", "\n" }; - + char buffer[ 256 ]; int iLine; - printf( "\nSyntax: %s [options]" - "\n", szSelf ); + snprintf( buffer, sizeof( buffer ), + "\nSyntax: %s [options]\n", szSelf ); + hb_compOutStd( HB_COMP_PARAM, buffer ); for( iLine = 0; iLine < ( int ) ( sizeof( szOptions ) / sizeof( char * ) ); iLine++ ) - printf( szOptions[ iLine ], OS_OPT_DELIMITER_LIST[ 0 ] ); + { + snprintf( buffer, sizeof( buffer ), + szOptions[ iLine ], OS_OPT_DELIMITER_LIST[ 0 ] ); + hb_compOutStd( HB_COMP_PARAM, buffer ); + } } /* * List of compatibility/features modes */ -void hb_compPrintModes( void ) +void hb_compPrintModes( HB_COMP_DECL ) { static const char * szOptions [] = { @@ -129,91 +134,93 @@ void hb_compPrintModes( void ) "\n ? this info", "\n" }; - int iLine; - printf( "\nCompatibility flags (lowercase/uppercase significant): -k[options]\n" ); + hb_compOutStd( HB_COMP_PARAM, + "\nCompatibility flags (lowercase/uppercase significant): -k[options]\n" ); for( iLine = 0; iLine < ( int ) ( sizeof( szOptions ) / sizeof( char * ) ); iLine++ ) - printf( szOptions[ iLine ] ); + hb_compOutStd( HB_COMP_PARAM, szOptions[ iLine ] ); } /* * Prints credits */ -void hb_compPrintCredits( void ) +void hb_compPrintCredits( HB_COMP_DECL ) { - printf( "\n" - "Credits: The Harbour Team at www.harbour-project.org\n" - " (replace space with @ in e-mail addresses)\n" - "\n" - "April White \n" - "Alejandro de Garate \n" - "Alexander S. Kresin \n" - "Andi Jahja \n" - "Antonio Carlos Pantaglione \n" - "Antonio Linares \n" - "Bil Simser \n" - "Brian Hays \n" - "Bruno Cantero \n" - "Chen Kedem \n" - "Dave Pearson \n" - "David Arturo Macias Corona \n" - "David G. Holm \n" - "Davor Siklic \n" - "Dmitry V. Korzhov \n" - "Eddie Runia \n" - "Enrico Maria Giordano \n" - "Felipe G. Coury \n" - "Francesco Saverio Giudice \n" - "Giancarlo Niccolai \n" - "Gonzalo A. Diethelm \n" - "Hannes Ziegler \n" - "Horacio D. Roldan Kasimatis \n" - "Ignacio Ortiz de Zuniga \n" - "Janica Lubos \n" - "Jean-Francois Lefebvre (mafact) \n" - "Jose Lalin \n" - "Leslee Griffith \n" - "Lorenzo Fiorini \n" - "Luis Krause Mantilla \n" - "Luiz Rafael Culik \n" - "Manuel Ruiz \n" - "Marek Paliwoda \n" - "Martin Vogel \n" - "Matteo Baccan \n" - "Matthew Hamilton \n" - "Mauricio Abre \n" - "Maurilio Longo \n" - "Miguel Angel Marchuet Frutos \n" - "Mindaugas Kavaliauskas \n" - "Nicolas del Pozo \n" - "Patrick Mast \n" - "Paul Tucker \n" - "Pavel Tsarenko \n" - "Peter Rees \n" - "Peter Townsend \n" - "Phil Barnett \n" - "Phil Krylov \n" - "Przemyslaw Czerpak \n" - "Ron Pinkas \n" - "Ryszard Glab \n" - "Tim Stone \n" - "Tomaž Zupan \n" - "Viktor Szakats \n" - "Vladimir Kazimirchik \n" - "Walter Negro \n" - ); + hb_compOutStd( HB_COMP_PARAM, + "\n" + "Credits: The Harbour Team at www.harbour-project.org\n" + " (replace space with @ in e-mail addresses)\n" + "\n" + "April White \n" + "Alejandro de Garate \n" + "Alexander S. Kresin \n" + "Andi Jahja \n" + "Antonio Carlos Pantaglione \n" + "Antonio Linares \n" + "Bil Simser \n" + "Brian Hays \n" + "Bruno Cantero \n" + "Chen Kedem \n" + "Dave Pearson \n" + "David Arturo Macias Corona \n" + "David G. Holm \n" + "Davor Siklic \n" + "Dmitry V. Korzhov \n" + "Eddie Runia \n" + "Enrico Maria Giordano \n" + "Felipe G. Coury \n" + "Francesco Saverio Giudice \n" + "Giancarlo Niccolai \n" + "Gonzalo A. Diethelm \n" + "Hannes Ziegler \n" + "Horacio D. Roldan Kasimatis \n" + "Ignacio Ortiz de Zuniga \n" + "Janica Lubos \n" + "Jean-Francois Lefebvre (mafact) \n" + "Jose Lalin \n" + "Leslee Griffith \n" + "Lorenzo Fiorini \n" + "Luis Krause Mantilla \n" + "Luiz Rafael Culik \n" + "Manuel Ruiz \n" + "Marek Paliwoda \n" + "Martin Vogel \n" + "Matteo Baccan \n" + "Matthew Hamilton \n" + "Mauricio Abre \n" + "Maurilio Longo \n" + "Miguel Angel Marchuet Frutos \n" + "Mindaugas Kavaliauskas \n" + "Nicolas del Pozo \n" + "Patrick Mast \n" + "Paul Tucker \n" + "Pavel Tsarenko \n" + "Peter Rees \n" + "Peter Townsend \n" + "Phil Barnett \n" + "Phil Krylov \n" + "Przemyslaw Czerpak \n" + "Ron Pinkas \n" + "Ryszard Glab \n" + "Tim Stone \n" + "Tomaž Zupan \n" + "Viktor Szakats \n" + "Vladimir Kazimirchik \n" + "Walter Negro \n" + ); } /* * Prints logo */ -void hb_compPrintLogo( void ) +void hb_compPrintLogo( HB_COMP_DECL ) { char * szVer = hb_verHarbour(); - printf( "%s\n", szVer ); - printf( "Copyright 1999-2007, http://www.harbour-project.org/\n" ); + hb_compOutStd( HB_COMP_PARAM, szVer ); + hb_compOutStd( HB_COMP_PARAM, + "\nCopyright 1999-2007, http://www.harbour-project.org/\n" ); hb_xfree( szVer ); } diff --git a/harbour/source/compiler/ppcomp.c b/harbour/source/compiler/ppcomp.c index 4cef208d50..5a26d23381 100644 --- a/harbour/source/compiler/ppcomp.c +++ b/harbour/source/compiler/ppcomp.c @@ -219,10 +219,7 @@ void hb_compInitPP( HB_COMP_DECL, int argc, char * argv[] ) else if( HB_COMP_PARAM->szStdCh[ 0 ] > ' ' ) hb_pp_readRules( HB_COMP_PARAM->pLex->pPP, HB_COMP_PARAM->szStdCh ); else if( ! HB_COMP_PARAM->fQuiet ) - { - printf( "Standard command definitions excluded.\n" ); - fflush( stdout ); - } + hb_compOutStd( HB_COMP_PARAM, "Standard command definitions excluded.\n" ); hb_pp_initDynDefines( HB_COMP_PARAM->pLex->pPP ); diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index ec2466413e..0d815cef42 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -224,12 +224,18 @@ static void hb_pp_error( PHB_PP_STATE pState, char type, int iError, const char } else { + char line[ 16 ]; + char msg[ 200 ]; + char buffer[ 256 ]; + if( pState->pFile ) - fprintf( stderr, "(%d) ", pState->pFile->iCurrentLine ); - fprintf( stderr, "%s: ", type == 'F' ? "Fatal" : type == 'W' ? "Warning" : "Error" ); - fprintf( stderr, szMsgTable[ iError - 1 ], szParam ); - fprintf( stderr, "\n" ); - fflush( stderr ); + snprintf( line, sizeof( line ), "(%d) ", pState->pFile->iCurrentLine ); + else + line[ 0 ] = '\0'; + snprintf( msg, sizeof( msg ), szMsgTable[ iError - 1 ], szParam ); + snprintf( buffer, sizeof( buffer ), "%s%s: %s\n", line, + type == 'F' ? "Fatal" : type == 'W' ? "Warning" : "Error", msg ); + hb_pp_disp( pState, buffer ); } if( type != 'W' ) pState->fError = TRUE; diff --git a/harbour/source/vm/memvars.c b/harbour/source/vm/memvars.c index c4566c18aa..a234ab9bf3 100644 --- a/harbour/source/vm/memvars.c +++ b/harbour/source/vm/memvars.c @@ -1568,6 +1568,22 @@ HB_FUNC( __MVRESTORE ) hb_errRT_BASE( EG_ARG, 2007, NULL, "__MRESTORE", HB_ERR_ARGS_BASEPARAMS ); } +/* + * This is a hacking function which changes base private offset so + * PRIVATE variables created in function which calls __MVSETBASE() + * will not be released when the function exit but will be inherited + * by its caller. [druzus] + */ +HB_FUNC( __MVSETBASE ) +{ + long lOffset = hb_stackBaseProcOffset( 0 ); + + if( lOffset > 0 ) + hb_stackItem( lOffset )->item.asSymbol.stackstate->ulPrivateBase = + hb_memvarGetPrivatesBase(); +} + + /* ----------------------------------------------------------------------- */ /* The garbage collector interface */ /* ----------------------------------------------------------------------- */