diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8351a1f710..875474878b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,20 @@ +2001-06-07 10:15 GMT+3 Alexander Kresin + * include/hbpp.h + * source/pp/ppcore.c + + hb_pp_Free() added ( separated from hb_pp_Init() ) + * source/pp/pplib.c + + __PP_INIT() added + + __PP_FREE() added + + __PPADDRULE() added + * __PPADDRULE( cString ) can be called to preprocess a directive + ( #include, #command, etc. ) + __PP_FREE() should be called if __PPADDRULE() or __PP_INIT() was used + to free memory, allocated for pp tables. + * tests/testpre.prg + * modified to demonstrate __ppAddRule() and __pp_Free() using + * source/rdd/dbfntx/dbfntx1.c + * bug fixed in ntxOrderListAdd() + 2001-06-06 16:00 UTC-0400 David G. Holm * contrib/libct/charmix.c diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index 89c0f4aa98..0c67bfc144 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -103,6 +103,8 @@ typedef HB_INCLUDE_FUNC * HB_INCLUDE_FUNC_PTR; extern void hb_pp_SetRules( HB_INCLUDE_FUNC_PTR hb_compInclude, BOOL hb_comp_bQuiet ); extern int hb_pp_ReadRules( void ); extern void hb_pp_Init( void ); +extern void hb_pp_Free( void ); +extern void CloseInclude( void ); extern int hb_pp_ParseDirective( char * ); /* Parsing preprocessor directives ( #... ) */ extern int hb_pp_ParseExpression( char *, char * ); /* Parsing a line ( without preprocessor directive ) */ extern int hb_pp_WrStr( FILE *, char * ); diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index c0015feb64..fb3390ee6e 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -131,7 +131,6 @@ static int NextWord( char **, char *, BOOL ); static int NextName( char **, char * ); static int NextParm( char **, char * ); static BOOL OpenInclude( char *, PATHNAMES *, PHB_FNAME, BOOL bStandardOnly, char * ); -void CloseInclude( void ); #define ISNAME( c ) ( isalnum( ( int ) c ) || ( c ) == '_' || ( c ) > 0x7E ) #define MAX_NAME 255 @@ -335,12 +334,12 @@ void hb_pp_SetRules( HB_INCLUDE_FUNC_PTR hb_compInclude, BOOL hb_comp_bQuiet ) } } -void hb_pp_Init( void ) +void hb_pp_Free( void ) { DEFINES * stdef; COMMANDS * stcmd; - HB_TRACE(HB_TR_DEBUG, ("hb_pp_Init()")); + HB_TRACE(HB_TR_DEBUG, ("hb_pp_Free()")); while( s_kolAddDefs ) { @@ -372,6 +371,13 @@ void hb_pp_Init( void ) hb_xfree( stcmd ); s_kolAddTras--; } +} + +void hb_pp_Init( void ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_pp_Init()")); + + hb_pp_Free(); s_ParseState = 0; s_maxCondCompile = 5; @@ -3766,6 +3772,7 @@ static BOOL OpenInclude( char * szFileName, PATHNAMES * pSearch, PHB_FNAME pMain return FALSE; } + void CloseInclude( void ) { PFILE pFile; diff --git a/harbour/source/pp/pplib.c b/harbour/source/pp/pplib.c index f5414aa626..39c726f097 100644 --- a/harbour/source/pp/pplib.c +++ b/harbour/source/pp/pplib.c @@ -100,6 +100,53 @@ static jmp_buf s_env; /* TODO: This function should return an error code. The preprocessed sting * should be returned by a reference. */ +HB_FUNC( __PP_INIT ) +{ + hb_pp_Table(); + hb_pp_Init(); + hb_comp_files.iFiles = 0; +} + +HB_FUNC( __PP_FREE ) +{ + hb_pp_Free(); + if( hb_pp_aCondCompile ) + hb_xfree( hb_pp_aCondCompile ); +} + +HB_FUNC( __PPADDRULE ) +{ + if( ISCHAR( 1 ) ) + { + char * ptr = hb_parc( 1 ); + char * hb_buffer; + + HB_SKIPTABSPACES( ptr ); + if( *ptr == '#' ) + { + if( !hb_pp_aCondCompile ) + { + hb_pp_Table(); + hb_pp_Init(); + hb_comp_files.iFiles = 0; + } + hb_pp_ParseDirective( ptr + 1 ); + if( hb_comp_files.pLast ) + { + hb_buffer = ( char* ) hb_xgrab( HB_PP_STR_SIZE ); + while( hb_pp_Internal( NULL,hb_buffer ) > 0 ); + CloseInclude(); + hb_xfree( hb_buffer ); + } + hb_retl( 1 ); + } + else + hb_retl( 0 ); + } + else + hb_retl( 0 ); +} + HB_FUNC( __PREPROCESS ) { if( ISCHAR( 1 ) ) diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index 7fed559c4b..fa1f629fb4 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -2620,6 +2620,9 @@ static ERRCODE ntxOrderListAdd( NTXAREAP pArea, LPDBORDERINFO pOrderInfo ) HB_TRACE(HB_TR_DEBUG, ("ntxOrderListAdd(%p, %p)", pArea, pOrderInfo)); + if( SELF_GOCOLD( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); szFileName[ 0 ] = '\0'; strcpy( szFileName, hb_itemGetCPtr( pOrderInfo->atomBagName ) ); diff --git a/harbour/tests/testpre.prg b/harbour/tests/testpre.prg index efca44096f..ae3a3feca7 100644 --- a/harbour/tests/testpre.prg +++ b/harbour/tests/testpre.prg @@ -33,12 +33,20 @@ FUNCTION Main() qOut( __Preprocess( cString ) ) qOut( "" ) - cString := 'CLOSE ALL' + cString := "#xcommand DEFAULT := => IF == NIL ; := ; END" + qOut( cString ) + IF __ppAddRule( cString ) + qOut( "Rule added successfully !" ) + ELSE + qOut( "Rule addition failed ..." ) + ENDIF + + cString := 'DEFAULT x := 100' qOut( cString ) qOut( __Preprocess( cString ) ) qOut( "" ) - qOut( chr(13)+chr(10)+"Press ..." ) + qOut( "Press ..." ) __Accept( "" ) CLS @@ -69,3 +77,7 @@ FUNCTION Main() NEXT RETURN( NIL ) + +Exit PROCEDURE ExitTest + __PP_Free() +Return \ No newline at end of file