2001-12-16 12:07 UTC+0100 Viktor Szakats <viktor.szakats@syenar.hu>

This commit is contained in:
Viktor Szakats
2001-12-16 11:12:23 +00:00
parent 351c2418d3
commit 22763b075b
12 changed files with 150 additions and 67 deletions

View File

@@ -8,6 +8,30 @@
2002-12-01 23:12 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
2001-12-16 12:07 UTC+0100 Viktor Szakats <viktor.szakats@syenar.hu>
* source/common/hbgete.c
* source/common/hbtrace.c
* source/compiler/cmdcheck.c
* source/compiler/gencobj.c
* source/rtl/gete.c
* source/rtl/gtcrs/gtcrs.c
* source/rtl/gtcrs/kbdcrs.c
* source/rtl/gtsln/gtsln.c
* source/rtl/gtsln/kbsln.c
* source/vm/cmdarg.c
* source/vm/hvm.c
* hb_getenv() now may return a NULL if the env.var
getting process failed for some reason.
! Reviewed, cleaned up and fixed all the hb_getenv()
calls, considering that it now may return NULL, all
caller now consistently check for env[ 0 ] != '\0'
! Fixed one leak in gtcrs.c
; I'd ask everybody to test the new code, with special
attention to the CLIPPER/HARBOUR/CLIPPERCMD/HARBOURCMD,
Linux environment variables, HB_TRACE_* variables.
2001-12-15 23:13 UTC+0100 Viktor Szakats <viktor.szakats@syenar.hu>
* source/debug/dbgwa.prg

View File

@@ -60,6 +60,11 @@
#include "hbapi.h"
/* NOTE: Warning, this function _may_ return NULL as a result if
the environment variable reading fails form some reason.
If the return value is not NULL, the caller must free
the pointer. [vszakats] */
char * hb_getenv( const char * szName )
{
char * pszBuffer = NULL;
@@ -102,13 +107,5 @@ char * hb_getenv( const char * szName )
#endif
/* Return an empty string if some error occured. */
if( pszBuffer == NULL )
{
pszBuffer = ( char * ) hb_xgrab( 1 );
pszBuffer[ 0 ] = '\0';
}
return pszBuffer;
}

View File

@@ -106,15 +106,16 @@ int hb_tr_level( void )
if( s_level == -1 )
{
char * out;
char * env;
s_level = HB_TR_DEFAULT;
out = hb_getenv( "HB_TR_OUTPUT" );
if( out != NULL && out[ 0 ] != '\0' )
/* ; */
env = hb_getenv( "HB_TR_OUTPUT" );
if( env != NULL && env[ 0 ] != '\0' )
{
s_fp = fopen( out, "w" );
s_fp = fopen( env, "w" );
if( s_fp == NULL )
s_fp = stderr;
@@ -122,7 +123,10 @@ int hb_tr_level( void )
else
s_fp = stderr;
hb_xfree( ( void * ) out );
if( env )
hb_xfree( ( void * ) env );
/* ; */
env = hb_getenv( "HB_TR_LEVEL" );
if( env != NULL && env[ 0 ] != '\0' )
@@ -140,7 +144,11 @@ int hb_tr_level( void )
}
}
}
hb_xfree( ( void * ) env );
if( env )
hb_xfree( ( void * ) env );
/* ; */
env = hb_getenv( "HB_TR_FLUSH" );
if( env != NULL && env[ 0 ] != '\0' )
@@ -148,8 +156,8 @@ int hb_tr_level( void )
else
s_flush = 0;
hb_xfree( ( void * ) env );
if( env )
hb_xfree( ( void * ) env );
}
return s_level;
@@ -213,11 +221,11 @@ void hb_tr_trace( char * fmt, ... )
hb_tr_file_ = "";
hb_tr_line_ = -1;
}
if ( s_flush )
{
fflush( s_fp ) ;
close( dup( fileno( s_fp ))) ;
}
}
}
}

View File

@@ -386,13 +386,15 @@ void hb_compChkCompilerSwitch( int iArg, char * Args[] )
*/
char * szStrEnv = hb_getenv( "HARBOURCMD" );
if( szStrEnv[ 0 ] == '\0' )
if( !szStrEnv || szStrEnv[ 0 ] == '\0' )
{
hb_xfree( ( void * ) szStrEnv );
if( szStrEnv )
hb_xfree( ( void * ) szStrEnv );
szStrEnv = hb_getenv( "CLIPPERCMD" );
}
if( szStrEnv[ 0 ] != '\0' )
if( szStrEnv && szStrEnv[ 0 ] != '\0' )
{
char * szSwitch = strtok( szStrEnv, " " );
@@ -405,7 +407,9 @@ void hb_compChkCompilerSwitch( int iArg, char * Args[] )
szSwitch = strtok( NULL, " " );
}
}
hb_xfree( ( void * ) szStrEnv );
if( szStrEnv )
hb_xfree( ( void * ) szStrEnv );
}
}
@@ -780,11 +784,11 @@ void hb_compChkPaths( void )
{
char * szInclude = hb_getenv( "INCLUDE" );
if( szInclude )
{
if( szInclude && szInclude[ 0 ] != '\0' )
hb_fsAddSearchPath( szInclude, &hb_comp_pIncludePath );
}
hb_xfree( ( void * ) szInclude );
if( szInclude )
hb_xfree( ( void * ) szInclude );
}
static void hb_compChkDefineSwitch( char * pszSwitch )
@@ -829,13 +833,15 @@ void hb_compChkDefines( int iArg, char * Args[] )
if HARBOURCMD exists */
char * szStrEnv = hb_getenv( "HARBOURCMD" );
if( szStrEnv[ 0 ] == '\0' )
if( !szStrEnv || szStrEnv[ 0 ] == '\0' )
{
hb_xfree( ( void * ) szStrEnv );
if( szStrEnv )
hb_xfree( ( void * ) szStrEnv );
szStrEnv = hb_getenv( "CLIPPERCMD" );
}
if( szStrEnv[ 0 ] != '\0' )
if( szStrEnv && szStrEnv[ 0 ] != '\0' )
{
char * szSwitch = strtok( szStrEnv, " " );
@@ -846,7 +852,9 @@ void hb_compChkDefines( int iArg, char * Args[] )
szSwitch = strtok( NULL, " " );
}
}
hb_xfree( ( void * ) szStrEnv );
if( szStrEnv )
hb_xfree( ( void * ) szStrEnv );
}
/* Check the command line options */
@@ -858,4 +866,4 @@ void hb_compChkDefines( int iArg, char * Args[] )
for( i = 0; i < iArg; i++ )
hb_compChkDefineSwitch( Args[ i ] );
}
}
}

View File

@@ -72,11 +72,14 @@ void hb_compGenCObj( PHB_FNAME pFileName )
pszEnv = hb_getenv( "PATH" );
#elif defined( OS_UNIX_COMPATIBLE )
pszEnv = szDefaultUnixPath;
#else
pszEnv = NULL;
#endif
/* Grab space */
pszCfg = ( char * ) hb_xgrab( /*strlen( pszEnv )*/ _POSIX_PATH_MAX );
if ( *hb_searchpath( HB_CFG_FILENAME, pszEnv, pszCfg ) )
if( pszEnv && pszEnv[ 0 ] != '\0' && *hb_searchpath( HB_CFG_FILENAME, pszEnv, pszCfg ) )
{
yyc = fopen( pszCfg, "rt" );
@@ -151,13 +154,16 @@ void hb_compGenCObj( PHB_FNAME pFileName )
}
}
}
#ifndef OS_UNIX_COMPATIBLE
hb_xfree( ( void * ) pszEnv );
#endif
fclose( yyc );
}
#if defined(__MSDOS__) || defined(__WIN32__) || defined(_Windows)
{
if( pszEnv )
hb_xfree( ( void * ) pszEnv );
}
#endif
if( ! hb_comp_bQuiet )

View File

@@ -102,8 +102,10 @@ HB_FUNC( GETENV )
szValue = hb_getenv( pszName );
hb_retc( szValue ? szValue : ( ( ISCHAR( 2 ) ? hb_parc( 2 ) : "" ) ) );
hb_xfree( ( void * ) szValue );
hb_retc( szValue && szValue[ 0 ] != '\0' ? szValue : ( ( ISCHAR( 2 ) ? hb_parc( 2 ) : "" ) ) );
if( szValue )
hb_xfree( ( void * ) szValue );
}
else
hb_retc( "" );
@@ -119,4 +121,4 @@ HB_FUNC( GETENV )
HB_FUNC( GETE )
{
HB_FUNCNAME( GETENV )();
}
}

View File

@@ -126,7 +126,13 @@ static void hb_gt_terminal_Init( void )
nodelay( stdscr, TRUE );
keypad( stdscr, FALSE );
s_under_xterm = ( strncmp( hb_getenv( "TERM" ), "xterm", 5 ) == 0 );
{
char * tmp = hb_getenv( "TERM" );
s_under_xterm = tmp && tmp[ 0 ] != '\0' && ( strncmp( tmp, "xterm", 5 ) == 0 );
if( tmp )
hb_xfree( ( void * ) tmp );
}
if( s_under_xterm )
{
/* Alternate characters set will be enabled only by request because

View File

@@ -86,7 +86,6 @@ static int s_mouse_event_len;
void hb_gt_keyboard_Init( void )
{
int i;
char * tmp;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Initialize_Keyboard()"));
@@ -94,8 +93,13 @@ void hb_gt_keyboard_Init( void )
for( i = 0; i < HB_HASH_KEY; i++ )
s_keymap_table[ i ] = NULL;
s_under_xterm = ( strncmp( ( tmp = hb_getenv("TERM") ), "xterm", 5 ) == 0 );
hb_xfree( ( void * ) tmp );
{
char * tmp = hb_getenv( "TERM" );
s_under_xterm = tmp && tmp[ 0 ] != '\0' && ( strncmp( tmp, "xterm", 5 ) == 0 );
if( tmp )
hb_xfree( ( void * ) tmp );
}
if( s_under_xterm )
{
/* NOTE: under xterm \E[M is used as a leading code for a mouse event

View File

@@ -169,7 +169,6 @@ static void sigwinch_handler( int sig )
void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr )
{
BOOL gt_Inited = FALSE;
char * tmp;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Init()"));
@@ -208,12 +207,20 @@ void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr )
s_sCursorStyle = SC_UNAVAIL;
/* an uncertain way to check if we run under linux console */
s_linuxConsole = ( strncmp( ( tmp = hb_getenv( "TERM" ) ), "linux", 5 ) == 0 );
hb_xfree( ( void * ) tmp );
{
char * tmp = hb_getenv( "TERM" );
s_linuxConsole = tmp && tmp[ 0 ] != '\0' && ( strncmp( tmp, "linux", 5 ) == 0 );
if( tmp )
hb_xfree( ( void * ) tmp );
}
/* an uncertain way to check if we run under xterm */
s_underXTerm = ( strstr( ( tmp = hb_getenv( "TERM" ) ), "xterm" ) != NULL );
hb_xfree( ( void * ) tmp );
{
char * tmp = hb_getenv( "TERM" );
s_underXTerm = tmp && tmp[ 0 ] != '\0' && ( strncmp( tmp, "xterm", 5 ) == 0 );
if( tmp )
hb_xfree( ( void * ) tmp );
}
/* NOTE: this driver is implemented in a way that it is
imposible to get intensity/blinking background mode.
@@ -1117,7 +1124,7 @@ BOOL hb_gt_PostExt()
static void hb_gt_build_conv_tabs()
{
int i, fg, bg, len;
unsigned char *p, ch;
unsigned char * p, ch;
SLsmg_Char_Type SLch;
/* COMPATIBILITY: Slang uses bit 0x8000 as an alternate
@@ -1238,7 +1245,10 @@ static void hb_gt_build_conv_tabs()
}
/* init national chars */
if( ( p = hb_getenv( hb_NationCharsEnvName ) && p[ 0 ] != '\0' ) )
p = hb_getenv( hb_NationCharsEnvName );
if( p && p[ 0 ] != '\0' )
{
unsigned char Pos, Msk;
@@ -1272,7 +1282,9 @@ static void hb_gt_build_conv_tabs()
ch=getc( stdin );
*/
}
hb_xfree( ( void * ) p );
if( p )
hb_xfree( ( void * ) p );
}
/* *********************************************************************** */
/* *********************************************************************** */

View File

@@ -201,21 +201,28 @@ static void hb_gt_Init_KeyTranslations()
int hb_gt_Init_Terminal( int phase )
{
struct termios newTTY;
unsigned char *p;
unsigned char * p;
int ret = 0;
char * tmp;
/* first time init phase - we don't want this after
return from system command ( see run.c ) */
if( phase == 0 )
{
/* an uncertain way to check if we run under linux console */
s_linuxConsole = ( ! strncmp( ( tmp = hb_getenv( "TERM" ) ), "linux", 5 ) );
hb_xfree( ( void * ) tmp );
{
char * tmp = hb_getenv( "TERM" );
s_linuxConsole = tmp && tmp[ 0 ] != '\0' && ( strncmp( tmp, "linux", 5 ) == 0 );
if( tmp )
hb_xfree( ( void * ) tmp );
}
/* an uncertain way to check if we run under linux xterm */
s_underXTerm = ( strstr( ( tmp = hb_getenv( "TERM" ) ), "xterm" ) != NULL );
hb_xfree( ( void * ) tmp );
{
char * tmp = hb_getenv( "TERM" );
s_underXTerm = tmp && tmp[ 0 ] != '\0' && ( strncmp( tmp, "xterm", 5 ) == 0 );
if( tmp )
hb_xfree( ( void * ) tmp );
}
#ifdef __linux__
/* for Linux console */
@@ -224,13 +231,18 @@ int hb_gt_Init_Terminal( int phase )
#endif
/* get Dead key definition */
if( ( p = hb_getenv( hb_DeadKeyEnvName ) ) && p[ 0 ] != '\0' )
p = hb_getenv( hb_DeadKeyEnvName );
if( p && p[ 0 ] != '\0' )
{
int len = strlen( p );
if( len > 0 )
hb_DeadKey = ( int ) *p;
int len = strlen( p );
if( len > 0 )
hb_DeadKey = ( int ) *p;
}
hb_xfree( ( void * ) p );
if( p )
hb_xfree( ( void * ) p );
/* number of keys dealing with a Dead key */
s_convKDeadKeys[ 0 ] = 0;

View File

@@ -123,14 +123,17 @@ static char * hb_cmdargGet( const char * pszName, BOOL bRetValue )
pszEnvVar = hb_getenv( "HARBOUR" );
if( pszEnvVar[ 0 ] == '\0' )
if( !pszEnvVar || pszEnvVar[ 0 ] == '\0' )
{
hb_xfree( ( void * ) pszEnvVar );
if( pszEnvVar )
hb_xfree( ( void * ) pszEnvVar );
pszEnvVar = hb_getenv( "CLIPPER" );
}
tmp = pszEnvVar;
if( pszEnvVar != NULL && pszEnvVar[ 0 ] != '\0' )
if( pszEnvVar && pszEnvVar[ 0 ] != '\0' )
{
char * pszNext;
@@ -193,7 +196,8 @@ static char * hb_cmdargGet( const char * pszName, BOOL bRetValue )
}
}
hb_xfree( ( void * ) tmp );
if( tmp )
hb_xfree( ( void * ) tmp );
return NULL;
}

View File

@@ -4701,4 +4701,4 @@ HB_FUNC( __TRACEPRGCALLS )
#endif
{
hb_vmExecute( pCode, pSymbols );
}
}