From a095d3da4928cada4e8aae8293ee141f1ece3132 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 20 Oct 2010 14:29:50 +0000 Subject: [PATCH] 2010-10-20 16:29 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/common/hbtrace.c ! fixed to not overwrite user trace settings with default or environment configuration on 1-st call to hb_tr_level()/ hb_tracelevel() function --- harbour/ChangeLog | 6 ++++ harbour/src/common/hbtrace.c | 67 ++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8c1f91b2dd..fa107f06a4 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,12 @@ The license applies to all entries newer than 2009-04-28. */ +2010-10-20 16:29 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/common/hbtrace.c + ! fixed to not overwrite user trace settings with default or + environment configuration on 1-st call to hb_tr_level()/ + hb_tracelevel() function + 2010-10-20 07:36 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbct/hbct.hbx * harbour/contrib/hbqt/qtuitools/hbqtuitools.hbx diff --git a/harbour/src/common/hbtrace.c b/harbour/src/common/hbtrace.c index c5e412cc25..7953c36624 100644 --- a/harbour/src/common/hbtrace.c +++ b/harbour/src/common/hbtrace.c @@ -80,8 +80,8 @@ static int s_enabled = 1; static int s_level = -1; -static int s_flush = 0; -static int s_sysout = 0; +static int s_flush = -1; +static int s_sysout = -1; static FILE * s_fp = NULL; @@ -137,7 +137,7 @@ HB_BOOL hb_tracefile( const char * szFile ) int hb_traceflush( int new_flush ) { - int old_flush = s_flush; + int old_flush = HB_MAX( s_flush, 0 ); if( new_flush == 0 || new_flush == 1 ) @@ -148,7 +148,7 @@ int hb_traceflush( int new_flush ) int hb_tracesysout( int new_sysout ) { - int old_sysout = s_sysout; + int old_sysout = HB_MAX( s_sysout, 0 ); if( new_sysout == 0 || new_sysout == 1 ) @@ -167,19 +167,22 @@ int hb_tr_level( void ) /* ; */ - env = hb_getenv( "HB_TR_OUTPUT" ); - if( env != NULL && env[ 0 ] != '\0' ) + if( s_fp == NULL ) { - s_fp = hb_fopen( env, "w" ); + env = hb_getenv( "HB_TR_OUTPUT" ); + if( env != NULL && env[ 0 ] != '\0' ) + { + s_fp = hb_fopen( env, "w" ); - if( s_fp == NULL ) + if( s_fp == NULL ) + s_fp = stderr; + } + else s_fp = stderr; - } - else - s_fp = stderr; - if( env ) - hb_xfree( env ); + if( env ) + hb_xfree( env ); + } /* ; */ @@ -204,25 +207,31 @@ int hb_tr_level( void ) /* ; */ - env = hb_getenv( "HB_TR_SYSOUT" ); - if( env != NULL && env[ 0 ] != '\0' ) - s_sysout = 1; - else - s_sysout = 0; + if( s_sysout < 0 ) + { + env = hb_getenv( "HB_TR_SYSOUT" ); + if( env != NULL && env[ 0 ] != '\0' ) + s_sysout = 1; + else + s_sysout = 0; - if( env ) - hb_xfree( env ); + if( env ) + hb_xfree( env ); + } /* ; */ - env = hb_getenv( "HB_TR_FLUSH" ); - if( env != NULL && env[ 0 ] != '\0' ) - s_flush = 1; - else - s_flush = 0; + if( s_flush < 0 ) + { + env = hb_getenv( "HB_TR_FLUSH" ); + if( env != NULL && env[ 0 ] != '\0' ) + s_flush = 1; + else + s_flush = 0; - if( env ) - hb_xfree( env ); + if( env ) + hb_xfree( env ); + } } return s_level; @@ -253,7 +262,7 @@ static void hb_tracelog_( int level, const char * file, int line, const char * p pszLevel = ( level >= HB_TR_ALWAYS && level <= HB_TR_LAST ) ? s_slevel[ level ] : "(\?\?\?)"; - if( s_sysout ) + if( s_sysout > 0 ) { #if ( defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) ) || \ ( defined( HB_OS_UNIX ) && \ @@ -342,7 +351,7 @@ static void hb_tracelog_( int level, const char * file, int line, const char * p */ fprintf( s_fp, "\n" ); - if( s_flush ) + if( s_flush > 0 ) fflush( s_fp ); }