From 04f1dd6091972bcd9ae5a0c10526645a2b030bb3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 19 Sep 1999 14:17:34 +0000 Subject: [PATCH] 19990919-15:34 GMT+1 --- harbour/ChangeLog | 24 +++++++- harbour/source/rtl/console.c | 98 ++++++++++++++---------------- harbour/source/rtl/fm.c | 9 +-- harbour/source/rtl/gt/gtwin.c | 3 + harbour/source/vm/cmdarg.c | 8 +-- harbour/source/vm/hvm.c | 4 +- harbour/tests/working/rtl_test.prg | 1 + 7 files changed, 82 insertions(+), 65 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9c4ccf7991..290474df25 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,25 @@ +19990919-15:34 GMT+1 Victor Szel + + * source/rtl/console.c + + Support added for //STDERR:x switch form. + ! Fixed the redirection, it needed a bit more work, see next two items. + % Some variable scopes adjusted. (these were removed with the next change) + % fputs()/fputc()/fflush() changed to hb_fsWriteLarge() + % Some (BYTE*) casts for BYTE* variables removed. + * source/vm/cmdarg.c + ! hb_cmdargNum() to not return -1 when the switch was found, but with + not parameter. + * source/vm/hvm.c + ! Fixed constant error message about no starting procedure. + * source/rtl/gt/gtwin.c + ! Commented out closing of standard input and output, now printf() + works after hb_consoleRelease(). (Thanks Paul) + * tests/working/rtl_test.prg + + Added Empty(ErrorNew()) test. + * source/rtl/fm.c + * Changed the ending message, since this is not the maximum memory + consumed, but the total. Made it more compact, and meaningful. + 19990919-15:45 GMT+2 Ryszard Glab *source/vm/hvm.c @@ -5,7 +27,7 @@ 19990919-14:25 GMT+2 Ryszard Glab - *soource/rtl/console.c + *source/rtl/console.c * added two (char *) casts *source/compiler/harbour.y diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index 03bbf0e9de..e0b999fab9 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -106,6 +106,8 @@ static int s_iFilenoStderr; void hb_consoleInitialize( void ) { + int iStderr; + #if defined(OS_DOS_COMPATIBLE) s_szCrLf[ 0 ] = HB_CHAR_CR; s_szCrLf[ 1 ] = HB_CHAR_LF; @@ -124,10 +126,16 @@ void hb_consoleInitialize( void ) s_iFilenoStdout = fileno( stdout ); hb_fsSetDevMode( s_iFilenoStdout, FM_BINARY ); - if( hb_cmdargCheck( "STDERR" ) ) /* Undocumented CA-Clipper switch */ - s_iFilenoStderr = s_iFilenoStdout; - else + + iStderr = hb_cmdargNum( "STDERR" ); /* Undocumented CA-Clipper switch //STDERR:x */ + + if( iStderr < 0 ) /* //STDERR not used or invalid */ s_iFilenoStderr = fileno( stderr ); + else if( iStderr == 0 ) /* //STDERR with no parameter or 0 */ + s_iFilenoStderr = s_iFilenoStdout; + else /* //STDERR:x */ + s_iFilenoStderr = iStderr; + hb_fsSetDevMode( s_iFilenoStderr, FM_BINARY ); #ifdef HARBOUR_USE_GTAPI @@ -270,18 +278,16 @@ static void hb_out( USHORT uiParam, hb_out_func_typedef * hb_out_func ) /* Output an item to STDOUT */ static void hb_outstd( BYTE * pStr, ULONG ulLen ) { - ULONG ulCount = ulLen; - BYTE * pPtr = pStr; + USHORT user_ferror; #ifdef HARBOUR_USE_GTAPI hb_gtPreExt(); #endif - if( strlen( ( const char * ) pStr ) != ulCount ) - while( ulCount-- ) fputc( *pPtr++, stdout ); - else - fputs( ( char * ) pStr, stdout ); - fflush( stdout ); + user_ferror = hb_fsError(); /* Save current user file error code */ + hb_fsWriteLarge( s_iFilenoStdout, pStr, ulLen ); + hb_fsSetError( user_ferror ); /* Restore last user file error code */ + #ifdef HARBOUR_USE_GTAPI #ifndef __CYGWIN__ if( isatty( s_iFilenoStdout ) ) @@ -300,18 +306,16 @@ static void hb_outstd( BYTE * pStr, ULONG ulLen ) /* Output an item to STDERR */ static void hb_outerr( BYTE * pStr, ULONG ulLen ) { - ULONG ulCount = ulLen; - BYTE * pPtr = pStr; + USHORT user_ferror; #ifdef HARBOUR_USE_GTAPI hb_gtPreExt(); #endif - if( strlen( ( const char * ) pStr ) != ulCount ) - while( ulCount-- ) fputc( *pPtr++, stderr ); - else - fputs( ( char * ) pStr, stderr ); - fflush( stderr ); + user_ferror = hb_fsError(); /* Save current user file error code */ + hb_fsWriteLarge( s_iFilenoStderr, pStr, ulLen ); + hb_fsSetError( user_ferror ); /* Restore last user file error code */ + #ifdef HARBOUR_USE_GTAPI #ifndef __CYGWIN__ if( isatty( s_iFilenoStdout ) ) @@ -337,9 +341,9 @@ static void hb_altout( BYTE * pStr, ULONG ulLen ) hb_gtGetPos( &s_uiDevRow, &s_uiDevCol ); #else USHORT user_ferror = hb_fsError(); /* Save current user file error code */ - adjust_pos( pStr, ulLen, &s_uiDevRow, &s_uiDevCol, hb_max_row(), hb_max_col() ); hb_fsWriteLarge( s_iFilenoStdout, pStr, ulLen ); hb_fsSetError( user_ferror ); /* Restore last user file error code */ + adjust_pos( pStr, ulLen, &s_uiDevRow, &s_uiDevCol, hb_max_row(), hb_max_col() ); #endif } @@ -347,7 +351,7 @@ static void hb_altout( BYTE * pStr, ULONG ulLen ) { /* Print to alternate file if SET ALTERNATE ON and valid alternate file */ USHORT user_ferror = hb_fsError(); /* Save current user file error code */ - hb_fsWriteLarge( hb_set_althan, ( BYTE * ) pStr, ulLen ); + hb_fsWriteLarge( hb_set_althan, pStr, ulLen ); hb_fsSetError( user_ferror ); /* Restore last user file error code */ } @@ -355,7 +359,7 @@ static void hb_altout( BYTE * pStr, ULONG ulLen ) { /* Print to extra file if valid alternate file */ USHORT user_ferror = hb_fsError(); /* Save current user file error code */ - hb_fsWriteLarge( hb_set_extrahan, ( BYTE * ) pStr, ulLen ); + hb_fsWriteLarge( hb_set_extrahan, pStr, ulLen ); hb_fsSetError( user_ferror ); /* Restore last user file error code */ } @@ -363,10 +367,10 @@ static void hb_altout( BYTE * pStr, ULONG ulLen ) { /* Print to printer if SET PRINTER ON and valid printer file */ USHORT user_ferror = hb_fsError(); /* Save current user file error code */ - hb_fsWriteLarge( hb_set_printhan, ( BYTE * ) pStr, ulLen ); + hb_fsWriteLarge( hb_set_printhan, pStr, ulLen ); + hb_fsSetError( user_ferror ); /* Restore last user file error code */ if( ulLen + s_uiPCol > USHRT_MAX ) s_uiPCol = USHRT_MAX; else s_uiPCol += ulLen; - hb_fsSetError( user_ferror ); /* Restore last user file error code */ } } @@ -377,10 +381,10 @@ static void hb_devout( BYTE * pStr, ULONG ulLen ) { /* Display to printer if SET DEVICE TO PRINTER and valid printer file */ USHORT user_ferror = hb_fsError(); /* Save current user file error code */ - hb_fsWriteLarge( hb_set_printhan, ( BYTE * ) pStr, ulLen ); + hb_fsWriteLarge( hb_set_printhan, pStr, ulLen ); + hb_fsSetError( user_ferror ); /* Restore last user file error code */ if( ulLen + s_uiPCol > USHRT_MAX ) s_uiPCol = USHRT_MAX; else s_uiPCol += ulLen; - hb_fsSetError( user_ferror ); /* Restore last user file error code */ } else { @@ -389,12 +393,9 @@ static void hb_devout( BYTE * pStr, ULONG ulLen ) hb_gtWrite( pStr, ulLen ); hb_gtGetPos( &s_uiDevRow, &s_uiDevCol ); #else - ULONG ulCount = ulLen; - BYTE * pPtr = pStr; - if( strlen( (char *) pStr ) != ulCount ) - while( ulCount-- ) fputc( *pPtr++, stdout ); - else - fputs( ( char * ) pStr, stdout ); + USHORT user_ferror = hb_fsError(); /* Save current user file error code */ + hb_fsWriteLarge( s_iFilenoStdout, pStr, ulLen ); + hb_fsSetError( user_ferror ); /* Restore last user file error code */ adjust_pos( pStr, ulLen, &s_uiDevRow, &s_uiDevCol, hb_max_row(), hb_max_col() ); #endif } @@ -408,12 +409,9 @@ static void hb_dispout( BYTE * pStr, ULONG ulLen ) hb_gtWrite( pStr, ulLen ); hb_gtGetPos( &s_uiDevRow, &s_uiDevCol ); #else - ULONG ulCount = ulLen; - BYTE * pPtr = pStr; - if( strlen( (char *) pStr ) != ulCount ) - while( ulCount-- ) fputc( *pPtr++, stdout ); - else - fputs( ( char * ) pStr, stdout ); + USHORT user_ferror = hb_fsError(); /* Save current user file error code */ + hb_fsWriteLarge( s_iFilenoStdout, pStr, ulLen ); + hb_fsSetError( user_ferror ); /* Restore last user file error code */ adjust_pos( pStr, ulLen, &s_uiDevRow, &s_uiDevCol, hb_max_row(), hb_max_col() ); #endif } @@ -421,21 +419,21 @@ static void hb_dispout( BYTE * pStr, ULONG ulLen ) void hb_setpos( USHORT row, USHORT col ) { #ifdef HARBOUR_USE_GTAPI - hb_gtSetPos( row, col ); + hb_gtSetPos( row, col ); #else - USHORT uiCount; + USHORT uiCount; - if( row < s_uiDevRow || col < s_uiDevCol ) - { - fputs( s_szCrLf, stdout ); - s_uiDevCol = 0; - s_uiDevRow++; - } - else if( row > s_uiDevRow ) s_uiDevCol = 0; - for( uiCount = s_uiDevRow; uiCount < row; uiCount++ ) - fputs( s_szCrLf, stdout ); - for( uiCount = s_uiDevCol; uiCount < col; uiCount++ ) - fputc( ' ', stdout ); + if( row < s_uiDevRow || col < s_uiDevCol ) + { + fputs( s_szCrLf, stdout ); + s_uiDevCol = 0; + s_uiDevRow++; + } + else if( row > s_uiDevRow ) s_uiDevCol = 0; + for( uiCount = s_uiDevRow; uiCount < row; uiCount++ ) + fputs( s_szCrLf, stdout ); + for( uiCount = s_uiDevCol; uiCount < col; uiCount++ ) + fputc( ' ', stdout ); #endif s_uiDevRow = row; @@ -470,9 +468,7 @@ void hb_devpos( USHORT row, USHORT col ) hb_fsSetError( user_ferror ); /* Restore last user file error code */ } else - { hb_setpos( row, col ); - } } HARBOUR HB_OUTSTD( void ) /* writes a list of values to the standard output device */ diff --git a/harbour/source/rtl/fm.c b/harbour/source/rtl/fm.c index 03a420aa42..cf4f25ba0f 100644 --- a/harbour/source/rtl/fm.c +++ b/harbour/source/rtl/fm.c @@ -150,17 +150,12 @@ void hb_xexit( void ) /* Deinitialize fixed memory subsystem */ if( s_ulMemoryBlocks || hb_cmdargCheck( "INFO" ) ) { printf( hb_consoleGetNewLine() ); - printf( "total memory blocks allocated: %lu", s_ulMemoryMaxBlocks ); - printf( hb_consoleGetNewLine() ); - printf( "memory maximum size consumed: %ld", s_ulMemoryMaxConsumed ); + printf( "Total memory allocated: %ld bytes (%lu blocks)", s_ulMemoryMaxConsumed, s_ulMemoryMaxBlocks ); if( s_ulMemoryBlocks ) { printf( hb_consoleGetNewLine() ); - printf( "memory blocks not released: %ld", s_ulMemoryBlocks ); - printf( hb_consoleGetNewLine() ); - printf( "memory size not released: %ld", s_ulMemoryConsumed ); + printf( "WARNING! Memory allocated by not released: %ld bytes (%ld blocks)", s_ulMemoryConsumed, s_ulMemoryBlocks ); } - printf( hb_consoleGetNewLine() ); } #endif } diff --git a/harbour/source/rtl/gt/gtwin.c b/harbour/source/rtl/gt/gtwin.c index 0cba3cd24d..54409a2ac9 100644 --- a/harbour/source/rtl/gt/gtwin.c +++ b/harbour/source/rtl/gt/gtwin.c @@ -125,10 +125,13 @@ void hb_gt_Done( void ) hb_gtDispBegin(); /* must use these versions ! */ hb_gtDispEnd(); } +/* NOTE: There's not need to close these explicitly, moreover if we close them + functions using stdout will not show anything. CloseHandle( HInput ); HInput = INVALID_HANDLE_VALUE; CloseHandle( HOutput ); HOutput = INVALID_HANDLE_VALUE; +*/ if( HStealth != INVALID_HANDLE_VALUE ) { CloseHandle( HStealth ); diff --git a/harbour/source/vm/cmdarg.c b/harbour/source/vm/cmdarg.c index 43de69e616..1bae67fd85 100644 --- a/harbour/source/vm/cmdarg.c +++ b/harbour/source/vm/cmdarg.c @@ -108,9 +108,9 @@ static char * hb_cmdargGet( const char * pszName, BOOL bRetValue ) /* Step through all envvar switches. */ - /* NOTE: CA-Clipper don't need the switches to be separated by any chars - at all, Harbour is more strict/standard in this respect, it - requires the switches to be separated. */ + /* NOTE: CA-Clipper doesn't need the switches to be separated by any + chars at all, Harbour is more strict/standard in this respect, + it requires the switches to be separated. */ pszNext = pszEnvVar; @@ -181,7 +181,7 @@ int hb_cmdargNum( const char * pszName ) if( pszValue ) { - int iValue = strlen( pszValue ) > 0 ? atoi( pszValue ) : -1; + int iValue = atoi( pszValue ); hb_xfree( pszValue ); diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index c4f27542ad..918cc324aa 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -215,8 +215,8 @@ int main( int argc, char * argv[] ) } #else #ifndef HARBOUR_STRICT_CLIPPER_COMPATIBLE - else - hb_errInternal( 9999, "Starting procedure not found", NULL, NULL ); + else if( ! s_pSymStart ) + hb_errInternal( 9999, "No starting procedure", NULL, NULL ); #endif #endif } diff --git a/harbour/tests/working/rtl_test.prg b/harbour/tests/working/rtl_test.prg index 15f0bdb0e1..14485ce36f 100644 --- a/harbour/tests/working/rtl_test.prg +++ b/harbour/tests/working/rtl_test.prg @@ -675,6 +675,7 @@ STATIC FUNCTION Main_HVM() TEST_LINE( Empty( {} ) , .T. ) TEST_LINE( Empty( {0} ) , .F. ) TEST_LINE( Empty( {|x|x+x} ) , .F. ) + TEST_LINE( Empty( ErrorNew() ) , .F. ) RETURN NIL