From c58df7356fef29290b0a469647af79f940ce21c7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2000 20:18:59 +0000 Subject: [PATCH] 20000403-22:20 GMT+1 Victor Szakats --- harbour/ChangeLog | 9 ++++ harbour/include/hbcomp.h | 3 +- harbour/source/compiler/cmdcheck.c | 77 ++++++++++++++++++++++-------- harbour/source/compiler/harbour.c | 5 +- harbour/source/pp/stdalone/hbpp.c | 4 +- 5 files changed, 74 insertions(+), 24 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 894b1082dd..23ee6fb079 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,12 @@ +20000403-22:20 GMT+1 Victor Szakats + + * source/pp/stdalone/hbpp.c + * source/compiler/cmdcheck.c + * source/compiler/harbour.c + * include/hbcomp.h + ! Fixed handling of the /D switch, it broke when introducing the + multiple filenames at the command line feature. + 20000403-21:08 GMT+1 Victor Szakats * source/rtl/readvar.prg diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index e146ff1786..2b4bb948d4 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -291,7 +291,8 @@ extern HB_EXPR_PTR hb_compWarnMeaningless( HB_EXPR_PTR ); extern void hb_compChkCompilerSwitch( int, char * Args[] ); extern void hb_compChkEnvironVar( char * ); -extern void hb_compCheckPaths( void ); +extern void hb_compChkPaths( void ); +extern void hb_compChkDefines( int iArg, char * Args[] ); extern void hb_compPrintUsage( char * ); extern void hb_compPrintCredits( void ); diff --git a/harbour/source/compiler/cmdcheck.c b/harbour/source/compiler/cmdcheck.c index a783e30700..3cd256a268 100644 --- a/harbour/source/compiler/cmdcheck.c +++ b/harbour/source/compiler/cmdcheck.c @@ -39,7 +39,7 @@ * * Copyright 1999 {list of individual authors and e-mail addresses} * hb_compChkEnvironVar() - * hb_compCheckPaths() + * hb_compChkPaths() * AddSearchPath() * * Copyright 1999 Victor Szakats @@ -220,25 +220,9 @@ void hb_compChkEnvironVar( char * szSwitch ) } break; - /* QUESTION: - Why not add support for multiple defines ? - -DONE;TWO=2;THREE - */ case 'd': - case 'D': /* defines a Lex #define from the environment */ - { - unsigned int i = 0; - char * szDefText = hb_strdup( s + 1 ); - while( i < strlen( szDefText ) && !HB_ISOPTSEP( szDefText[ i ] ) ) - i++; - - szDefText[ i ] = '\0'; - if( szDefText ) - { - hb_pp_AddDefine( szDefText, 0 ); - } - free( szDefText ); - } + case 'D': + /* NOTE: Ignore these -d switches will be processed separately */ break; case 'e': @@ -469,7 +453,7 @@ void hb_compChkEnvironVar( char * szSwitch ) } } -void hb_compCheckPaths( void ) +void hb_compChkPaths( void ) { char * szInclude = getenv( "INCLUDE" ); @@ -489,3 +473,56 @@ void hb_compCheckPaths( void ) } } +static void hb_compChkDefineSwitch( char * pszSwitch ) +{ + if( pszSwitch && HB_ISOPTSEP( pszSwitch[ 0 ] ) && + ( pszSwitch[ 1 ] == 'd' || pszSwitch[ 1 ] == 'D' ) ) + { + char * szDefText = hb_strdup( pszSwitch + 2 ); + unsigned int i = 0; + + while( i < strlen( szDefText ) && ! HB_ISOPTSEP( szDefText[ i ] ) ) + i++; + + szDefText[ i ] = '\0'; + if( szDefText ) + hb_pp_AddDefine( szDefText, 0 ); + + free( szDefText ); + } +} + +void hb_compChkDefines( int iArg, char * Args[] ) +{ + /* Chech the environment variables */ + { + /* NOTE: CLIPPERCMD enviroment variable is overriden + if HARBOURCMD exists */ + char * szStrEnv = getenv( "HARBOURCMD" ); + + if( ! szStrEnv ) + szStrEnv = getenv( "CLIPPERCMD" ); + + if( szStrEnv ) + { + char * szSwitch = strtok( szStrEnv, " " ); + + /* Check the environment var while it isn't empty. */ + while( szSwitch != NULL ) + { + hb_compChkDefineSwitch( szSwitch ); + szSwitch = strtok( NULL, " " ); + } + } + } + + /* Check the command line options */ + { + int i; + + /* Check all switches in command line They start with an OS_OPT_DELIMITER + char */ + for( i = 0; i < iArg; i++ ) + hb_compChkDefineSwitch( Args[ i ] ); + } +} diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index f15aacb5b8..2bf6cbe580 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -151,7 +151,7 @@ int main( int argc, char * argv[] ) { if( !bAnyFiles ) { - hb_compCheckPaths(); + hb_compChkPaths(); bAnyFiles = TRUE; } @@ -184,6 +184,9 @@ int main( int argc, char * argv[] ) /* Initialization of preprocessor arrays */ hb_pp_Init(); + /* Add /D command line or envvar defines */ + hb_compChkDefines( argc, argv ); + /* Initialize support variables */ hb_compInitVars(); diff --git a/harbour/source/pp/stdalone/hbpp.c b/harbour/source/pp/stdalone/hbpp.c index 40199924d8..74b9fb39a1 100644 --- a/harbour/source/pp/stdalone/hbpp.c +++ b/harbour/source/pp/stdalone/hbpp.c @@ -95,6 +95,8 @@ int main( int argc, char * argv[] ) HB_VER_MAJOR, HB_VER_MINOR, HB_VER_REVISION, HB_VER_BUILD, HB_VER_YEAR, HB_VER_MONTH, HB_VER_DAY ); printf( "Copyright 1999-2000, http://www.harbour-project.org\n" ); + hb_pp_Init(); + while( iArg < argc ) { if( HB_ISOPTSEP(argv[ iArg ][ 0 ])) @@ -210,8 +212,6 @@ int main( int argc, char * argv[] ) } } - hb_pp_Init(); - while( hb_pp_Parse( handl_o ) > 0 ); fclose( hb_comp_files.pLast->handle ); hb_xfree( hb_comp_files.pLast->pBuffer );