diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 420e8f89a8..6b260abe3a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,60 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ + + * harbour/source/pp/ppcore.c + + added decoding C escaped strings (e"...") to PP so they can be + preprocessed like a normal strings, it's not enabled when + HB_C52_STRICT macro is set + +2006-11-17 13:30 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapi.h + * harbour/source/common/hbstr.c + * harbour/source/compiler/harbour.l + * harbour/source/macro/macro.l + * harbour/source/macro/macro.slx + * harbour/source/compiler/harbour.slx + * changed parameters in function: hb_compStrToNum() now the string + size is passed explicitly so it can work with strings which does + not have trailing ASCII NUL character. + + * harbour/source/macro/macro.y + * indenting + + * harbour/include/hbmacro.h + * harbour/source/common/hbstr.c + * harbour/source/macro/macro.l + * harbour/source/macro/macro.y + * added two new functions for macro compiler: hb_macroLexNew() and + hb_macroLexDelete() to clearly separate lexer from grammar parser. + + * harbour/source/compiler/harbour.l + * harbour/source/common/hbstr.c + * harbour/source/pp/ppcore.c + * added error generation for wrong e"..." strings and fixed \" quoting + * removed \q quoting + + * harbour/source/pp/ppcore.c + * harbour/source/pp/ppgen.c + * added small description in headers + + * harbour/common.mak + * harbour/source/pp/Makefile + * harbour/source/pp/pplib.c + + harbour/source/pp/pplib2.c + * harbour/include/hbextern.ch + + added auto destructor for allocated PP context, it's not longer + necessary to execute __PP_FREE() so this function was moved from + the standard .prg API to file with backward compatible functions + * changed __PREPROCESS() to __PP_PROCESS() + * moved setting std rules to separate file so now if user uses PP + with only his own rules we are not forcing linking static tables + which are quite huge (over 100kb) + To include stdandard rules in static binaries user should add + to his code: + REQUEST __PP_STDRULES + + + harbour/source/pp/pplib3.c * old PP functions for backward compatibility: __PPADDRULE(), __PREPROCESS(), __PP_FREE() Please note that using this function is not MT safe. They should diff --git a/harbour/common.mak b/harbour/common.mak index e48f01c972..e686176ad1 100644 --- a/harbour/common.mak +++ b/harbour/common.mak @@ -240,6 +240,8 @@ PP_LIB_OBJS = \ $(OBJ_DIR)\pptable.obj \ $(OBJ_DIR)\ppcore.obj \ $(OBJ_DIR)\pplib.obj \ + $(OBJ_DIR)\pplib2.obj \ + $(OBJ_DIR)\pplib3.obj \ #********************************************************** diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index a2e1c6c314..e6df4ef82d 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -651,7 +651,7 @@ extern HB_EXPORT char * hb_strndup( const char * pszText, ULONG ulLen ); /* re extern HB_EXPORT ULONG hb_strnlen( const char * pszText, ULONG ulLen ); /* like strlen() but result is limited to ulLen */ extern HB_EXPORT char * hb_xstrcat( char *dest, const char *src, ... ); /* Concatenates multiple strings into a single result */ extern HB_EXPORT char * hb_xstrcpy( char *szDest, const char *szSrc, ...); /* Concatenates multiple strings into a single result */ -extern HB_EXPORT BOOL hb_compStrToNum( const char* szNum, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by compiler */ +extern HB_EXPORT BOOL hb_compStrToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by compiler */ extern HB_EXPORT BOOL hb_valStrnToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by VAL() */ extern HB_EXPORT BOOL hb_strToNum( const char* szNum, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ extern HB_EXPORT BOOL hb_strnToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index 630d96cbcb..99f377f866 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -657,7 +657,14 @@ EXTERNAL ORDWILDSEEK EXTERNAL __DYNSCOUNT EXTERNAL __DYNSGETINDEX EXTERNAL __DYNSGETNAME -EXTERNAL __PREPROCESS + +EXTERNAL __PP_INIT +EXTERNAL __PP_PATH +EXTERNAL __PP_RESET +EXTERNAL __PP_ADDRULE +EXTERNAL __PP_PROCESS +EXTERNAL __PP_STDRULES + EXTERNAL HB_ANSITOOEM EXTERNAL HB_CLRAREA EXTERNAL HB_COLORTON diff --git a/harbour/include/hbmacro.h b/harbour/include/hbmacro.h index 23629e122d..0b9c884278 100644 --- a/harbour/include/hbmacro.h +++ b/harbour/include/hbmacro.h @@ -105,6 +105,8 @@ extern void hb_macroError( int iError, HB_BISON_PTR pMacro ); extern int hb_macroYYParse( HB_MACRO_PTR pMacro ); extern ULONG hb_macroSetMacro( BOOL bSet, ULONG ulFlag ); extern ULONG hb_macroAutoSetMacro( ULONG ulFlag ); +extern BOOL hb_macroLexNew( HB_MACRO_PTR pMacro ); +extern void hb_macroLexDelete( HB_MACRO_PTR pMacro ); extern void hb_compGenPCode1( BYTE byte, HB_BISON_PTR pMacro ); extern void hb_compGenPData1( BYTE byte, HB_BISON_PTR pMacro ); diff --git a/harbour/source/common/hbstr.c b/harbour/source/common/hbstr.c index 0c79f1046b..f873c674c3 100644 --- a/harbour/source/common/hbstr.c +++ b/harbour/source/common/hbstr.c @@ -623,10 +623,10 @@ static BOOL hb_str2number( BOOL fPCode, const char* szNum, ULONG ulLen, HB_LONG return fDbl; } -HB_EXPORT BOOL hb_compStrToNum( const char* szNum, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ) +HB_EXPORT BOOL hb_compStrToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ) { - HB_TRACE(HB_TR_DEBUG, ("hb_compStrToNum( %s, %p, %p, %p, %p)", szNum, plVal, pdVal, piDec, piWidth )); - return hb_str2number( TRUE, szNum, strlen( szNum ), plVal, pdVal, piDec, piWidth ); + HB_TRACE(HB_TR_DEBUG, ("hb_compStrToNum( %s, %lu, %p, %p, %p, %p)", szNum, ulLen, plVal, pdVal, piDec, piWidth )); + return hb_str2number( TRUE, szNum, ulLen, plVal, pdVal, piDec, piWidth ); } HB_EXPORT BOOL hb_valStrnToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ) @@ -886,9 +886,6 @@ char * hb_strRemEscSeq( char *str, ULONG *pLen ) case 'b': ch = '\b'; break; - case 'q': - ch = '"'; - break; case '\\': default: break; diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index a56651e360..6a56944976 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -178,7 +178,16 @@ Separator {SpaceTab} } } -[^\x22\n]*\x22 { BEGIN 0; +([^\x22\n]|\\\x22)*\n { BEGIN 0; + unput( '\n' ); + yytext[--yyleng] = '\0'; + hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + hb_comp_iState = LOOKUP; + + return NIL; + } + +([^\x22\n]|\\\x22)*\x22 { BEGIN 0; yytext[--yyleng] = '\0'; { ULONG len = yyleng; @@ -1816,7 +1825,7 @@ static int yy_ConvertNumber( char * szBuffer ) double dNumber; int iDec, iWidth; - if( hb_compStrToNum( szBuffer, &lNumber, &dNumber, &iDec, &iWidth ) ) + if( hb_compStrToNum( szBuffer, strlen( szBuffer ), &lNumber, &dNumber, &iDec, &iWidth ) ) { yylval.valDouble.dNumber = dNumber; yylval.valDouble.bDec = iDec; diff --git a/harbour/source/compiler/harbour.slx b/harbour/source/compiler/harbour.slx index 335e0775eb..1acdf6a4ce 100644 --- a/harbour/source/compiler/harbour.slx +++ b/harbour/source/compiler/harbour.slx @@ -712,7 +712,7 @@ static int hb_comp_SLX_Str2Num( char* szNum, HB_LONG * plVal, double * pdVal, in { BOOL fDbl; - fDbl = hb_compStrToNum( szNum, plVal, pdVal, piDec, piWidth ); + fDbl = hb_compStrToNum( szNum, strlen( szNum ), plVal, pdVal, piDec, piWidth ); return fDbl ? NUM_DOUBLE : NUM_LONG; } diff --git a/harbour/source/macro/macro.l b/harbour/source/macro/macro.l index 56e5786c9f..78b9f0648a 100644 --- a/harbour/source/macro/macro.l +++ b/harbour/source/macro/macro.l @@ -256,7 +256,7 @@ MacroTxt ({MacroVar}|{MacroEnd}|{MacroId})+ pMacro->FlexState = LOOKUP; - if( hb_compStrToNum( yytext, &lNumber, &dNumber, &iDec, &iWidth ) ) + if( hb_compStrToNum( yytext, strlen( yytext ), &lNumber, &dNumber, &iDec, &iWidth ) ) { yylval_ptr->valDouble.dNumber = dNumber; yylval_ptr->valDouble.bDec = iDec; @@ -330,7 +330,7 @@ MacroTxt ({MacroVar}|{MacroEnd}|{MacroId})+ #endif -void * hb_compFlexNew( HB_MACRO_PTR pMacro ) +BOOL hb_macroLexNew( HB_MACRO_PTR pMacro ) { /* This creates the scanner buffer based on passed string. * Unfortunately it creates a copy of this string - the string can be @@ -340,12 +340,17 @@ void * hb_compFlexNew( HB_MACRO_PTR pMacro ) */ HB_TRACE(HB_TR_DEBUG, ("hb_compFlexNew(%s, %i)", pMacro->string, pMacro->length)); pMacro->FlexState = LOOKUP; - return (void *) yy_scan_bytes( pMacro->string, pMacro->length ); + pMacro->pLex = ( void * ) yy_scan_bytes( pMacro->string, pMacro->length ); + return pMacro->pLex != NULL; } -void hb_compFlexDelete( void * pBuffer ) +void hb_macroLexDelete( HB_MACRO_PTR pMacro ) { - yy_delete_buffer( ( YY_BUFFER_STATE ) pBuffer ); + if( pMacro->pLex ) + { + yy_delete_buffer( ( YY_BUFFER_STATE ) pMacro->pLex ); + pMacro->pLex = NULL; + } } /* diff --git a/harbour/source/macro/macro.slx b/harbour/source/macro/macro.slx index 3090170136..f3d23d50d3 100644 --- a/harbour/source/macro/macro.slx +++ b/harbour/source/macro/macro.slx @@ -341,7 +341,7 @@ static int hb_comp_SLX_Str2Num( char* szNum, HB_LONG * plVal, double * pdVal, in { BOOL fDbl; - fDbl = hb_compStrToNum( szNum, plVal, pdVal, piDec, piWidth ); + fDbl = hb_compStrToNum( szNum, strlen( szNum ), plVal, pdVal, piDec, piWidth ); return fDbl ? NUM_DOUBLE : NUM_LONG; } diff --git a/harbour/source/macro/macro.y b/harbour/source/macro/macro.y index b1ea17feba..decf679f41 100644 --- a/harbour/source/macro/macro.y +++ b/harbour/source/macro/macro.y @@ -104,11 +104,8 @@ #undef YYLEX_PARAM #define YYLEX_PARAM ( (HB_MACRO_PTR)YYPARSE_PARAM ) /* additional parameter passed to yylex */ -extern int yyparse( void * ); /* to make happy some purist compiler */ -extern void * hb_compFlexNew( HB_MACRO_PTR ); -extern void hb_compFlexDelete( void * ); - -extern void yyerror( char * ); /* parsing error management function */ +extern int yyparse( void * ); /* to make happy some purist compiler */ +extern void yyerror( char * ); /* parsing error management function */ /* Standard checking for valid expression creation */ @@ -363,7 +360,7 @@ MacroExprAlias : MacroExpr ALIASOP { $$ = $1; } */ /* special case: _FIELD-> and FIELD-> can be nested */ -FieldAlias : FIELD ALIASOP { $$ = hb_compExprNewAlias( hb_strdup( "FIELD") ); } +FieldAlias : FIELD ALIASOP { $$ = hb_compExprNewAlias( hb_strdup( "FIELD" ) ); } | FIELD ALIASOP FieldAlias { $$ = $3; } ; @@ -827,41 +824,16 @@ void yyerror( char * s ) /* ************************************************************************* */ -/* #define HB_PP_MACROLEX */ - -#ifndef HB_PP_MACROLEX - -int hb_macroYYParse( HB_MACRO_PTR pMacro ) -{ - int iResult; - void * lexBuffer; - - lexBuffer = hb_compFlexNew( pMacro ); - - pMacro->status = HB_MACRO_CONT; - /* NOTE: bison requires (void *) pointer - */ - iResult = yyparse( ( void * ) pMacro ); - - hb_compFlexDelete( lexBuffer ); - - return iResult; -} - -#else - int hb_macroYYParse( HB_MACRO_PTR pMacro ) { int iResult; - pMacro->pLex = ( void * ) hb_pp_lexNew( pMacro->string, pMacro->length ); - if( pMacro->pLex ) + if( hb_macroLexNew( pMacro ) ) { pMacro->status = HB_MACRO_CONT; /* NOTE: bison requires (void *) pointer */ iResult = yyparse( ( void * ) pMacro ); - hb_pp_free( ( PHB_PP_STATE ) pMacro->pLex ); - pMacro->pLex = NULL; + hb_macroLexDelete( pMacro ); } else iResult = HB_MACRO_FAILURE; @@ -869,6 +841,23 @@ int hb_macroYYParse( HB_MACRO_PTR pMacro ) return iResult; } +#if defined( HB_MACRO_PPLEX ) + +BOOL hb_macroLexNew( HB_MACRO_PTR pMacro ) +{ + pMacro->pLex = ( void * ) hb_pp_lexNew( pMacro->string, pMacro->length ); + return pMacro->pLex != NULL; +} + +void hb_macroLexDelete( HB_MACRO_PTR pMacro ) +{ + if( pMacro->pLex ) + { + hb_pp_free( ( PHB_PP_STATE ) pMacro->pLex ); + pMacro->pLex = NULL; + } +} + int hb_complex( YYSTYPE *yylval_ptr, HB_MACRO_PTR pMacro ) { PHB_PP_TOKEN pToken = hb_pp_lex( ( PHB_PP_STATE ) pMacro->pLex ); @@ -886,7 +875,7 @@ int hb_complex( YYSTYPE *yylval_ptr, HB_MACRO_PTR pMacro ) else if( pToken->len == 3 && hb_stricmp( "IIF", pToken->value ) == 0 ) return IIF; else if( pToken->len == 2 && hb_stricmp( "IF", pToken->value ) == 0 ) - return IIF; + return IF; else if( pToken->len == 3 && hb_stricmp( "NIL", pToken->value ) == 0 ) return NIL; @@ -910,7 +899,7 @@ int hb_complex( YYSTYPE *yylval_ptr, HB_MACRO_PTR pMacro ) double dNumber; int iDec, iWidth; - if( hb_compStrToNum( pToken->value, &lNumber, &dNumber, &iDec, &iWidth ) ) + if( hb_compStrToNum( pToken->value, pToken->len, &lNumber, &dNumber, &iDec, &iWidth ) ) { yylval_ptr->valDouble.dNumber = dNumber; yylval_ptr->valDouble.bDec = ( UCHAR ) iDec; @@ -1005,4 +994,4 @@ int hb_complex( YYSTYPE *yylval_ptr, HB_MACRO_PTR pMacro ) } } -#endif /* HB_PP_MACROLEX */ +#endif /* HB_MACRO_PPLEX */ diff --git a/harbour/source/pp/Makefile b/harbour/source/pp/Makefile index f6683f0946..b6913b96f7 100644 --- a/harbour/source/pp/Makefile +++ b/harbour/source/pp/Makefile @@ -5,9 +5,11 @@ ROOT = ../../ C_SOURCES=\ - pplib.c \ pptable.c \ - ppcore.c \ + ppcore.c \ + pplib.c \ + pplib2.c \ + pplib3.c \ LIBNAME=pp diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 9216801765..2a6e1d33ee 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * + * Clipper compatible preprocessor * * Copyright 2006 Przemyslaw Czerpak * www - http://www.harbour-project.org @@ -930,7 +930,9 @@ static void hb_pp_getLine( PHB_PP_STATE pState ) if( ul == ulLen ) { + ULONG ulSkip = pBuffer - hb_membufPtr( pState->pBuffer ); hb_membufAddCh( pState->pBuffer, '\0' ); + pBuffer = hb_membufPtr( pState->pBuffer ) + ulSkip; hb_pp_error( pState, 'E', HB_PP_ERR_STRING_TERMINATOR, pBuffer ); } else @@ -950,10 +952,10 @@ static void hb_pp_getLine( PHB_PP_STATE pState ) ul = ulLen; } else if( ch == '*' && pState->pFile->iTokens == 0 ) - { + { /* strip the rest of line with // or && comment */ ul = ulLen; - } + } else if( ch == '/' && ulLen > 1 && pBuffer[ 1 ] == '*' ) { #ifdef HB_C52_STRICT @@ -1254,8 +1256,6 @@ static int hb_pp_tokenStr( PHB_PP_TOKEN pToken, PHB_MEM_BUFFER pBuffer, iq = ch = 'b'; break; case '"': - iq = ch = 'q'; - break; case '\\': iq = 1; break; diff --git a/harbour/source/pp/ppgen.c b/harbour/source/pp/ppgen.c index 362a194dce..9e17b618fe 100644 --- a/harbour/source/pp/ppgen.c +++ b/harbour/source/pp/ppgen.c @@ -4,7 +4,9 @@ /* * Harbour Project source code: - * + * preprocessor static rules generator. + * It creates .c file with tables for defines/[x]translates/[x]commands + * found in given file .ch or .prg file * * Copyright 2006 Przemyslaw Czerpak * www - http://www.harbour-project.org diff --git a/harbour/source/pp/pplib.c b/harbour/source/pp/pplib.c index 59cbe00739..7679e67757 100644 --- a/harbour/source/pp/pplib.c +++ b/harbour/source/pp/pplib.c @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * + * .prg interface to preprocessor * * Copyright 2006 Przemyslaw Czerpak * www - http://www.harbour-project.org @@ -58,8 +58,6 @@ #include "hbapierr.h" #include "hbvm.h" -static PHB_PP_STATE s_pp_state = NULL; - static void hb_pp_ErrorMessage( char * szMsgTable[], char cPrefix, int iCode, const char * szParam1, const char * szParam2 ) { @@ -84,56 +82,46 @@ static void hb_pp_Disp( const char * szMessage ) HB_SYMBOL_UNUSED( szMessage ); } -static PHB_PP_STATE hb_pp_stateNew( BOOL fInit ) +/* PP destructor */ +static HB_GARBAGE_FUNC( hb_pp_Destructor ) { - PHB_PP_STATE pState = hb_pp_new(); + PHB_PP_STATE * pStatePtr = ( PHB_PP_STATE * ) Cargo; - if( pState ) + if( * pStatePtr ) { - hb_pp_init( pState, TRUE, NULL, NULL, - hb_pp_ErrorMessage, hb_pp_Disp, NULL, NULL, NULL ); - - if( fInit ) - { - hb_pp_setStdRules( pState ); - hb_pp_initDynDefines( pState ); - hb_pp_setStdBase( pState ); - } - if( ! s_pp_state ) - s_pp_state = pState; - } - - return pState; -} - -static void hb_pp_stateFree( PHB_PP_STATE pState ) -{ - if( pState ) - { - if( pState == s_pp_state ) - s_pp_state = NULL; - hb_pp_free( pState ); + hb_pp_free( * pStatePtr ); + * pStatePtr = NULL; } } - -static PHB_PP_STATE hb_pp_stateParam( int * piParam ) +static void hb_pp_StdRules( PHB_PP_STATE pState ) { - PHB_PP_STATE pState = ( PHB_PP_STATE ) hb_parptr( 1 ); + static BOOL s_fInit = TRUE; + static PHB_DYNS s_pDynSym; - if( pState ) + if( s_fInit ) { - * piParam = 2; - return pState; + s_pDynSym = hb_dynsymFind( "__PP_STDRULES" ); + s_fInit = FALSE; } + + if( s_pDynSym ) + { + hb_vmPushDynSym( s_pDynSym ); + hb_vmPushNil(); + hb_vmPushPointer( ( void * ) &pState ); + hb_vmDo( 1 ); + } +} + +static PHB_PP_STATE hb_pp_Param( int iParam ) +{ + PHB_PP_STATE * pStatePtr = ( PHB_PP_STATE * ) hb_parptr( iParam ); + + if( pStatePtr ) + return * pStatePtr; else - { - * piParam = 1; - if( !s_pp_state ) - return hb_pp_stateNew( TRUE ); - else - return s_pp_state; - } + return NULL; } /* @@ -144,56 +132,45 @@ static PHB_PP_STATE hb_pp_stateParam( int * piParam ) */ HB_FUNC( __PP_INIT ) { - PHB_PP_STATE pState; + PHB_PP_STATE * pStatePtr, pState = hb_pp_new(); - hb_pp_stateFree( s_pp_state ); - pState = hb_pp_stateNew( FALSE ); if( pState ) { char * szPath = hb_parc( 1 ), * szStdCh = hb_parc( 2 ); + hb_pp_init( pState, TRUE, NULL, NULL, + hb_pp_ErrorMessage, hb_pp_Disp, NULL, NULL, NULL ); + if( szPath ) hb_pp_addSearchPath( pState, szPath, TRUE ); if( szStdCh ) hb_pp_readRules( pState, szStdCh ); else - hb_pp_setStdRules( pState ); + hb_pp_StdRules( pState ); + hb_pp_initDynDefines( pState ); hb_pp_setStdBase( pState ); - hb_retptr( pState ); + pStatePtr = ( PHB_PP_STATE * ) hb_gcAlloc( sizeof( PHB_PP_STATE ), + hb_pp_Destructor ); + * pStatePtr = pState; + hb_retptrGC( pStatePtr ); } else hb_ret(); } -/* - * free PP context. - * __PP_FREE( ) - */ -HB_FUNC( __PP_FREE ) -{ - if( hb_pcount() == 0 ) - hb_pp_stateFree( s_pp_state ); - else - hb_pp_stateFree( ( PHB_PP_STATE ) hb_parptr( 1 ) ); -} - /* * add new (or replace previous) include paths. * __PP_PATH( , [, ] ) */ HB_FUNC( __PP_PATH ) { - PHB_PP_STATE pState; - int iParam; + PHB_PP_STATE pState = hb_pp_Param( 1 ); - pState = hb_pp_stateParam( &iParam ); if( pState ) - { - hb_pp_addSearchPath( pState, hb_parc( iParam ), hb_parl( iParam + 1 ) ); - } + hb_pp_addSearchPath( pState, hb_parc( 2 ), hb_parl( 3 ) ); } /* @@ -202,14 +179,10 @@ HB_FUNC( __PP_PATH ) */ HB_FUNC( __PP_RESET ) { - PHB_PP_STATE pState; - int iParam; + PHB_PP_STATE pState = hb_pp_Param( 1 ); - pState = hb_pp_stateParam( &iParam ); if( pState ) - { hb_pp_reset( pState ); - } } /* @@ -218,14 +191,12 @@ HB_FUNC( __PP_RESET ) */ HB_FUNC( __PP_ADDRULE ) { - PHB_PP_STATE pState; - int iParam; + PHB_PP_STATE pState = hb_pp_Param( 1 ); - pState = hb_pp_stateParam( &iParam ); if( pState ) { - char * szText = hb_parc( iParam ); - ULONG ulLen = hb_parclen( iParam ); + char * szText = hb_parc( 2 ); + ULONG ulLen = hb_parclen( 2 ); if( szText ) { @@ -258,22 +229,19 @@ HB_FUNC( __PP_ADDRULE ) /* * preprocess given code and return result - * __PREPROCESS( , ) -> + * __PP_PROCESS( , ) -> */ -HB_FUNC( __PREPROCESS ) +HB_FUNC( __PP_PROCESS ) { - PHB_PP_STATE pState; - int iParam; + PHB_PP_STATE pState = hb_pp_Param( 1 ); - pState = hb_pp_stateParam( &iParam ); if( pState ) { - char * szText = hb_parc( iParam ); - ULONG ulLen = hb_parclen( iParam ); + ULONG ulLen = hb_parclen( 2 ); - if( szText && ulLen ) + if( ulLen ) { - szText = hb_pp_parseLine( pState, szText, &ulLen ); + char * szText = hb_pp_parseLine( pState, hb_parc( 2 ), &ulLen ); hb_retclen( szText, ulLen ); return; } diff --git a/harbour/source/pp/pplib2.c b/harbour/source/pp/pplib2.c new file mode 100644 index 0000000000..968691773d --- /dev/null +++ b/harbour/source/pp/pplib2.c @@ -0,0 +1,67 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * .prg interface to preprocessor + * __PP_STDRULE() function + * intentionally in separate file to not force linking + * standard PP rules table when user does not need them + * + * Copyright 2006 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbpp.h" +#include "hbapi.h" + +HB_FUNC( __PP_STDRULES ) +{ + PHB_PP_STATE * pStatePtr = ( PHB_PP_STATE * ) hb_parptr( 1 ); + + if( pStatePtr && * pStatePtr ) + { + hb_pp_setStdRules( * pStatePtr ); + } +} diff --git a/harbour/source/pp/pplib3.c b/harbour/source/pp/pplib3.c new file mode 100644 index 0000000000..bc6f6f5b00 --- /dev/null +++ b/harbour/source/pp/pplib3.c @@ -0,0 +1,160 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * backward compatible old .prg interface to preprocessor + * + * Copyright 2006 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbvm.h" +#include "hbinit.h" + +HB_FUNC_EXTERN( __PP_INIT ); +HB_FUNC_EXTERN( __PP_ADDRULE ); +HB_FUNC_EXTERN( __PP_PROCESS ); +HB_FUNC_EXTERN( __PP_STDRULES ); + +HB_INIT_SYMBOLS_BEGIN( hb_vm_SymbolInit_PPLIB3 ) +{ "__PP_INIT", {HB_FS_PUBLIC}, {HB_FUNCNAME( __PP_INIT )}, NULL }, +{ "__PP_ADDRULE", {HB_FS_PUBLIC}, {HB_FUNCNAME( __PP_ADDRULE )}, NULL }, +{ "__PP_PROCESS", {HB_FS_PUBLIC}, {HB_FUNCNAME( __PP_PROCESS )}, NULL }, +{ "__PP_STDRULES", {HB_FS_PUBLIC}, {HB_FUNCNAME( __PP_STDRULES )}, NULL }, +HB_INIT_SYMBOLS_EX_END( hb_vm_SymbolInit_PPLIB3, "pplib3.c", 0, 0 ) + +#if defined(HB_PRAGMA_STARTUP) + #pragma startup hb_vm_SymbolInit_PPLIB3 +#elif defined(HB_MSC_STARTUP) + #if _MSC_VER >= 1010 + #pragma data_seg( ".CRT$XIY" ) + #pragma comment( linker, "/Merge:.CRT=.data" ) + #else + #pragma data_seg( "XIY" ) + #endif + static HB_$INITSYM hb_vm_auto_SymbolInit_PPLIB3 = hb_vm_SymbolInit_PPLIB3; + #pragma data_seg() +#endif + + +static PHB_ITEM s_pp = NULL; + +static PHB_ITEM hb_pp_Get( void ) +{ + static PHB_DYNS s_pDynSym = NULL; + + if( s_pp == NULL ) + { + if( s_pDynSym == NULL ) + s_pDynSym = hb_dynsymFind( "__PP_INIT" ); + if( s_pDynSym ) + { + hb_vmPushDynSym( s_pDynSym ); + hb_vmPushNil(); + hb_vmDo( 0 ); + } + if( hb_param( -1, HB_IT_POINTER ) ) + s_pp = hb_itemNew( hb_param( -1, HB_IT_POINTER ) ); + } + + return s_pp; +} + +HB_FUNC( __PPADDRULE ) +{ + static PHB_DYNS s_pDynSym = NULL; + PHB_ITEM pp = hb_pp_Get(), pLine = hb_param( 1, HB_IT_ANY ); + + if( pp ) + { + if( s_pDynSym == NULL ) + s_pDynSym = hb_dynsymFind( "__PP_ADDRULE" ); + if( s_pDynSym ) + { + hb_vmPushDynSym( s_pDynSym ); + hb_vmPushNil(); + hb_vmPush( pp ); + if( pLine ) + hb_vmPush( pLine ); + else + hb_vmPushNil(); + hb_vmDo( 2 ); + } + } +} + +HB_FUNC( __PREPROCESS ) +{ + static PHB_DYNS s_pDynSym = NULL; + PHB_ITEM pp = hb_pp_Get(), pLine = hb_param( 1, HB_IT_ANY ); + + if( pp ) + { + if( s_pDynSym == NULL ) + s_pDynSym = hb_dynsymFind( "__PP_PROCESS" ); + if( s_pDynSym ) + { + hb_vmPushDynSym( s_pDynSym ); + hb_vmPushNil(); + hb_vmPush( pp ); + if( pLine ) + hb_vmPush( pLine ); + else + hb_vmPushNil(); + hb_vmDo( 2 ); + } + } +} + +HB_FUNC( __PP_FREE ) +{ + if( s_pp ) + { + hb_itemRelease( s_pp ); + s_pp = NULL; + } +}