diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a87adc4a01..0efe7aa237 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,18 @@ +19991121-23:23 GMT+1 Victor Szel + * source/pp/* + include/hbpp.h + ! static variables and functions marked static (continued). + ! public pp variables prefixed with "hb_pp_". + % pp_strAt() removed and calls replaced with common hb_strAt() function. + * Cleaned up standard header file usage. (Please report any errors caused + by this.) + * static variables prefixed with "s_". + * source/compiler/harbour.c + source/compiler/harbour.y + include/compiler.h + source/pp/hbppint.c + * Two PPO related variable declarations moved to the compiler. + 19991121-22:38 GMT+1 Victor Szel * source/pp/* source/compiler/harbour.c diff --git a/harbour/include/compiler.h b/harbour/include/compiler.h index 2e9422b813..86992ba10c 100644 --- a/harbour/include/compiler.h +++ b/harbour/include/compiler.h @@ -294,32 +294,35 @@ void hb_compGenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * /* variable used by compiler */ -extern int hb_comp_iLine; -extern FUNCTIONS hb_comp_functions, hb_comp_funcalls; -extern SYMBOLS hb_comp_symbols; +extern int hb_comp_iLine; +extern FUNCTIONS hb_comp_functions; +extern FUNCTIONS hb_comp_funcalls; +extern SYMBOLS hb_comp_symbols; extern PATHNAMES * hb_comp_pIncludePath; -extern PFUNCTION hb_comp_pInitFunc; -extern PHB_FNAME hb_comp_pFileName; -extern BOOL hb_comp_bStartProc; -extern BOOL hb_comp_bLineNumbers; -extern BOOL hb_comp_bQuiet; -extern BOOL hb_comp_bRestrictSymbolLength; -extern BOOL hb_comp_bShortCuts; -extern int hb_comp_iWarnings; -extern BOOL hb_comp_bAnyWarning; -extern BOOL hb_comp_bAutoMemvarAssume; -extern BOOL hb_comp_bForceMemvars; -extern BOOL hb_comp_bDebugInfo; -extern char hb_comp_szPrefix[ 20 ]; -extern BOOL hb_comp_bGenCVerbose; -extern int hb_comp_iExitLevel; -extern int hb_comp_iFunctionCnt; -extern char hb_comp_cVarType; -extern int hb_comp_iVarScope; -extern BOOL hb_comp_bDontGenLineNum; -extern FILES hb_comp_files; -extern int hb_comp_iStaticCnt; -extern int hb_comp_iErrorCount; +extern PFUNCTION hb_comp_pInitFunc; +extern PHB_FNAME hb_comp_pFileName; +extern BOOL hb_comp_bPPO; +extern FILE * hb_comp_yyppo; +extern BOOL hb_comp_bStartProc; +extern BOOL hb_comp_bLineNumbers; +extern BOOL hb_comp_bQuiet; +extern BOOL hb_comp_bRestrictSymbolLength; +extern BOOL hb_comp_bShortCuts; +extern int hb_comp_iWarnings; +extern BOOL hb_comp_bAnyWarning; +extern BOOL hb_comp_bAutoMemvarAssume; +extern BOOL hb_comp_bForceMemvars; +extern BOOL hb_comp_bDebugInfo; +extern char hb_comp_szPrefix[ 20 ]; +extern BOOL hb_comp_bGenCVerbose; +extern int hb_comp_iExitLevel; +extern int hb_comp_iFunctionCnt; +extern char hb_comp_cVarType; +extern int hb_comp_iVarScope; +extern BOOL hb_comp_bDontGenLineNum; +extern FILES hb_comp_files; +extern int hb_comp_iStaticCnt; +extern int hb_comp_iErrorCount; extern USHORT hb_comp_wSeqCounter; extern USHORT hb_comp_wForCounter; diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index 2e73170b6a..15bbdb21cd 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -77,9 +77,8 @@ typedef struct _COMMANDS extern int Hp_Parse( FILE *, FILE *, char * ); extern int ParseDirective( char * ); /* Parsing preprocessor directives ( #... ) */ extern int ParseExpression( char *, char * ); /* Parsing a line ( without preprocessor directive ) */ -extern int pp_RdStr( FILE *, char *, int, int, char *, int *, int * ); extern int pp_WrStr( FILE *, char * ); -extern int pp_strAt( char *, int, char *, int ); +extern int pp_RdStr( FILE *, char *, int, int, char *, int *, int * ); extern void pp_Stuff( char *, char *, int, int, int ); extern int strolen( char * ); extern int strocpy( char *, char * ); @@ -88,23 +87,22 @@ extern DEFINES * AddDefine( char *, char * ); /* Add new #define to a li /* HBPPINT.C exported functions */ -extern void Hbpp_init ( void ); +extern void Hbpp_init( void ); extern int PreProcess( FILE *, FILE *, char * ); /* HBPP.C exported variables */ -extern int lInclude; -extern int * aCondCompile; -extern int nCondCompile; -extern int nline; -extern char * _szPErrors[]; -extern char * _szPWarnings[]; +extern int hb_pp_lInclude; +extern int * hb_pp_aCondCompile; +extern int hb_pp_nCondCompile; +extern char * hb_pp_szErrors[]; +extern char * hb_pp_szWarnings[]; /* TABLE.C exported variables */ -extern DEFINES * topDefine; -extern COMMANDS * topCommand; -extern COMMANDS * topTranslate; +extern DEFINES * hb_pp_topDefine; +extern COMMANDS * hb_pp_topCommand; +extern COMMANDS * hb_pp_topTranslate; /* Needed support modules, but not contained in HBPP.C */ @@ -112,6 +110,8 @@ extern void * hb_xgrab( ULONG lSize ); /* allocates memory, exists on failur extern void * hb_xrealloc( void * pMem, ULONG lSize ); /* reallocates memory */ extern void hb_xfree( void * pMem ); /* frees memory */ +extern ULONG hb_strAt( const char * szSub, ULONG ulSubLen, const char * szText, ULONG ulLen ); + #include "compiler.h" #endif /* HB_PP_H_ */ diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 85cf7efaee..751e6c0ed3 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -70,11 +70,6 @@ extern void GenPortObj( PHB_FNAME ); /* generates the portable objects */ extern void GenObj32( PHB_FNAME ); /* generates OBJ 32 bits */ #endif - /* Following two lines added for preprocessor */ -extern BOOL _bPPO; /* flag indicating, is ppo output needed */ -extern FILE *yyppo; /* output .ppo file */ - - static void PrintUsage( char * ); static void PrintCredits( void ); static BOOL SwitchCmp( char * szString, char * szSwitch ); @@ -103,10 +98,11 @@ FILES hb_comp_files; FUNCTIONS hb_comp_functions, hb_comp_funcalls; SYMBOLS hb_comp_symbols; - int hb_comp_iLine = 1; /* currently processed line number */ PFUNCTION hb_comp_pInitFunc; PHB_FNAME hb_comp_pFileName = NULL; +BOOL hb_comp_bPPO = FALSE; /* flag indicating, is ppo output needed */ +FILE * hb_comp_yyppo = NULL; /* output .ppo file */ BOOL hb_comp_bStartProc = TRUE; /* holds if we need to create the starting procedure */ BOOL hb_comp_bLineNumbers = TRUE; /* holds if we need pcodes with line numbers */ BOOL hb_comp_bQuiet = FALSE; /* quiet mode */ @@ -508,7 +504,7 @@ int main( int argc, char * argv[] ) /* Added for preprocessor needs */ case 'p': case 'P': - _bPPO = TRUE; + hb_comp_bPPO = TRUE; break; case 'q': @@ -610,12 +606,12 @@ int main( int argc, char * argv[] ) if( !hb_comp_pFileName->szExtension ) hb_comp_pFileName->szExtension = ".prg"; hb_fsFNameMerge( szFileName, hb_comp_pFileName ); - if( _bPPO ) + if( hb_comp_bPPO ) { hb_comp_pFileName->szExtension = ".ppo"; hb_fsFNameMerge( szPpoName, hb_comp_pFileName ); - yyppo = fopen( szPpoName, "w" ); - if( ! yyppo ) + hb_comp_yyppo = fopen( szPpoName, "w" ); + if( ! hb_comp_yyppo ) { hb_compGenError( hb_comp_szCErrors, 'F', ERR_CREATE_PPO, szPpoName, NULL ); return iStatus; @@ -740,8 +736,8 @@ int main( int argc, char * argv[] ) } } - if( _bPPO ) - fclose( yyppo ); + if( hb_comp_bPPO ) + fclose( hb_comp_yyppo ); } else { diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 9c9464eccb..bb9df44256 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -66,10 +66,7 @@ int yywrap( void ); #undef YY_INPUT /* to implement our own YY_INPUT function to manage PRGs without \n at the end */ extern FILE * yyin; /* currently yacc parsed file */ -/* Following three lines added for preprocessor */ -extern FILE *yyppo; /* output .ppo file */ -extern BOOL _bPPO; /* flag indicating, is ppo output needed */ -extern int PreProcess( FILE*, FILE*, char *); +/* Following two lines added for preprocessor */ int yy_lex_input( char *, int ); #define YY_INPUT( buf, result, max_size ) result = yy_lex_input( buf, max_size ); @@ -1297,7 +1294,7 @@ int yy_lex_input( char *buffer, int iBufferSize ) { HB_SYMBOL_UNUSED( iBufferSize ); - return PreProcess( yyin, _bPPO ? yyppo : NULL, buffer ); + return PreProcess( yyin, hb_comp_bPPO ? hb_comp_yyppo : NULL, buffer ); } static int yy_ConvertNumber( char * szBuffer ) diff --git a/harbour/source/pp/hbpp.c b/harbour/source/pp/hbpp.c index 973d971e69..ddcf662fb4 100644 --- a/harbour/source/pp/hbpp.c +++ b/harbour/source/pp/hbpp.c @@ -42,17 +42,9 @@ #endif #endif -#include -#if ( defined(_MSC_VER) || defined(__IBMCPP__) || defined(__MINGW32_) ) - #include -#elif defined(__GNUC__) - #include - #include -#else - #include -#endif - #include +#include +#include #include #include "hbpp.h" #include "hberrors.h" @@ -127,13 +119,12 @@ static int lReplacePat = 1; static int numBrackets; static char groupchar; -int lInclude = 0; -int * aCondCompile; -int nCondCompile = 0; -int nline = 0; +int hb_pp_lInclude = 0; +int * hb_pp_aCondCompile; +int hb_pp_nCondCompile = 0; /* Table with parse errors */ -char * _szPErrors[] = +char * hb_pp_szErrors[] = { "Can\'t open #include file: \'%s\'", "#else does not match #ifdef", @@ -154,7 +145,7 @@ char * _szPErrors[] = /* NOTE: The first character stores the warning's level that triggers this * warning. The warning's level is set by -w command line option. */ -char * _szPWarnings[] = +char * hb_pp_szWarnings[] = { "3Non directive in include file %s(%s)" }; @@ -175,17 +166,17 @@ int ParseDirective( char* sLine ) if( i == 4 && memcmp( sDirective, "ELSE", 4 ) == 0 ) { /* --- #else --- */ - if( nCondCompile == 0 ) - hb_compGenError( _szPErrors, 'F', ERR_DIRECTIVE_ELSE, NULL, NULL ); - else if( nCondCompile == 1 || aCondCompile[nCondCompile-2] ) - aCondCompile[nCondCompile-1] = 1 - aCondCompile[nCondCompile-1]; + if( hb_pp_nCondCompile == 0 ) + hb_compGenError( hb_pp_szErrors, 'F', ERR_DIRECTIVE_ELSE, NULL, NULL ); + else if( hb_pp_nCondCompile == 1 || hb_pp_aCondCompile[hb_pp_nCondCompile-2] ) + hb_pp_aCondCompile[hb_pp_nCondCompile-1] = 1 - hb_pp_aCondCompile[hb_pp_nCondCompile-1]; } else if( i == 5 && memcmp( sDirective, "ENDIF", 5 ) == 0 ) { /* --- #endif --- */ - if( nCondCompile == 0 ) - hb_compGenError( _szPErrors, 'F', ERR_DIRECTIVE_ENDIF, NULL, NULL ); - else nCondCompile--; + if( hb_pp_nCondCompile == 0 ) + hb_compGenError( hb_pp_szErrors, 'F', ERR_DIRECTIVE_ENDIF, NULL, NULL ); + else hb_pp_nCondCompile--; } else if( i == 5 && memcmp( sDirective, "IFDEF", 5 ) == 0 ) @@ -194,14 +185,14 @@ int ParseDirective( char* sLine ) else if( i == 6 && memcmp( sDirective, "IFNDEF", 6 ) == 0 ) ParseIfdef( sLine, FALSE ); /* --- #ifndef --- */ - else if( nCondCompile==0 || aCondCompile[nCondCompile-1]) + else if( hb_pp_nCondCompile==0 || hb_pp_aCondCompile[hb_pp_nCondCompile-1]) { if( i == 7 && memcmp( sDirective, "INCLUDE", 7 ) == 0 ) { /* --- #include --- */ char cDelimChar; if( *sLine != '\"' && *sLine != '\'' && *sLine != '<' ) - hb_compGenError( _szPErrors, 'F', ERR_WRONG_NAME, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_WRONG_NAME, NULL, NULL ); cDelimChar = *sLine; if( cDelimChar == '<' ) @@ -212,19 +203,19 @@ int ParseDirective( char* sLine ) sLine++; i = 0; while( *(sLine+i) != '\0' && *(sLine+i) != cDelimChar ) i++; if( *(sLine+i) != cDelimChar ) - hb_compGenError( _szPErrors, 'F', ERR_WRONG_NAME, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_WRONG_NAME, NULL, NULL ); *(sLine+i) = '\0'; /* if((handl_i = fopen(sLine, "r")) == NULL) */ if( OpenInclude( sLine, hb_comp_pIncludePath, &handl_i, ( cDelimChar == '>' ), szInclude ) ) { - lInclude++; + hb_pp_lInclude++; Hp_Parse(handl_i, 0, szInclude ); - lInclude--; + hb_pp_lInclude--; fclose(handl_i); } else - hb_compGenError( _szPErrors, 'F', ERR_CANNOT_OPEN, sLine, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_CANNOT_OPEN, sLine, NULL ); } else if( i == 6 && memcmp( sDirective, "DEFINE", 6 ) == 0 ) @@ -248,12 +239,12 @@ int ParseDirective( char* sLine ) else if( i == 5 && memcmp( sDirective, "ERROR", 5 ) == 0 ) /* --- #error --- */ - hb_compGenError( _szPErrors, 'F', ERR_EXPLICIT, sLine, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_EXPLICIT, sLine, NULL ); else if( i == 4 && memcmp( sDirective, "LINE", 4 ) == 0 ) return -1; else - hb_compGenError( _szPErrors, 'F', ERR_WRONG_DIRECTIVE, sDirective, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_WRONG_DIRECTIVE, sDirective, NULL ); } return 0; } @@ -292,7 +283,7 @@ static int ParseDefine( char* sLine) lastdef->pars = ( npars <= 0 )? NULL : strodup ( pars ); } else - hb_compGenError( _szPErrors, 'F', ERR_DEFINE_ABSENT, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_DEFINE_ABSENT, NULL, NULL ); return 0; } @@ -314,8 +305,8 @@ DEFINES * AddDefine( char * defname, char * value ) else { stdef = ( DEFINES * ) hb_xgrab( sizeof( DEFINES ) ); - stdef->last = topDefine; - topDefine = stdef; + stdef->last = hb_pp_topDefine; + hb_pp_topDefine = stdef; stdef->name = strodup( defname ); kolAddDefs++; } @@ -353,27 +344,27 @@ static int ParseIfdef( char * sLine, int usl ) HB_TRACE(HB_TR_DEBUG, ("ParseIfdef(%s, %d)", sLine, usl)); - if( nCondCompile==0 || aCondCompile[nCondCompile-1]) + if( hb_pp_nCondCompile==0 || hb_pp_aCondCompile[hb_pp_nCondCompile-1]) { NextWord( &sLine, defname, FALSE ); if( *defname == '\0' ) - hb_compGenError( _szPErrors, 'F', ERR_DEFINE_ABSENT, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_DEFINE_ABSENT, NULL, NULL ); } - if( nCondCompile == maxCondCompile ) + if( hb_pp_nCondCompile == maxCondCompile ) { maxCondCompile += 5; - aCondCompile = (int*)hb_xrealloc( aCondCompile, sizeof( int ) * maxCondCompile ); + hb_pp_aCondCompile = (int*)hb_xrealloc( hb_pp_aCondCompile, sizeof( int ) * maxCondCompile ); } - if( nCondCompile==0 || aCondCompile[nCondCompile-1]) + if( hb_pp_nCondCompile==0 || hb_pp_aCondCompile[hb_pp_nCondCompile-1]) { if( ( (stdef = DefSearch(defname,NULL)) != NULL && usl ) - || ( stdef == NULL && !usl ) ) aCondCompile[nCondCompile] = 1; - else aCondCompile[nCondCompile] = 0; + || ( stdef == NULL && !usl ) ) hb_pp_aCondCompile[hb_pp_nCondCompile] = 1; + else hb_pp_aCondCompile[hb_pp_nCondCompile] = 0; } else - aCondCompile[ nCondCompile ] = 0; + hb_pp_aCondCompile[ hb_pp_nCondCompile ] = 0; - nCondCompile++; + hb_pp_nCondCompile++; return 0; } @@ -381,7 +372,7 @@ static int ParseIfdef( char * sLine, int usl ) static DEFINES* DefSearch(char *defname, int *isNew) { int kol = 0,j; - DEFINES * stdef = topDefine; + DEFINES * stdef = hb_pp_topDefine; HB_TRACE(HB_TR_DEBUG, ("DefSearch(%s)", defname)); @@ -406,7 +397,7 @@ static DEFINES* DefSearch(char *defname, int *isNew) static COMMANDS* ComSearch(char *cmdname, COMMANDS *stcmdStart) { int j; - COMMANDS *stcmd = ( stcmdStart )? stcmdStart:topCommand; + COMMANDS *stcmd = ( stcmdStart ) ? stcmdStart : hb_pp_topCommand; HB_TRACE(HB_TR_DEBUG, ("ComSearch(%s, %p)", cmdname, stcmdStart)); @@ -428,7 +419,7 @@ static COMMANDS* ComSearch(char *cmdname, COMMANDS *stcmdStart) static COMMANDS* TraSearch(char *cmdname, COMMANDS *sttraStart) { int j; - COMMANDS *sttra = ( sttraStart )? sttraStart:topTranslate; + COMMANDS *sttra = ( sttraStart ) ? sttraStart : hb_pp_topTranslate; HB_TRACE(HB_TR_DEBUG, ("TraSearch(%s, %p)", cmdname, sttraStart)); @@ -460,7 +451,7 @@ static void ParseCommand( char* sLine, int com_or_xcom, int com_or_tra ) stroupper( cmdname ); SKIPTABSPACES(sLine); - if( (ipos = pp_strAt( "=>", 2, sLine, strolen(sLine) )) > 0 ) + if( (ipos = hb_strAt( "=>", 2, sLine, strolen(sLine) )) > 0 ) { stroncpy( mpatt, sLine, ipos-1 ); @@ -484,7 +475,7 @@ static void ParseCommand( char* sLine, int com_or_xcom, int com_or_tra ) stcmd->value = ( rlen > 0 )? strodup( rpatt ) : NULL; } else - hb_compGenError( _szPErrors, 'F', ERR_COMMAND_DEFINITION, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_COMMAND_DEFINITION, NULL, NULL ); } /* ConvertPatterns() @@ -533,13 +524,13 @@ static void ConvertPatterns( char *mpatt, int mlen, char *rpatt, int rlen ) { if( *(exppatt+explen-1) == '*' ) explen--; else - hb_compGenError( _szPErrors, 'F', ERR_PATTERN_DEFINITION, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_PATTERN_DEFINITION, NULL, NULL ); } else if( exptype == '4' ) { if( *(exppatt+explen-1) == ')' ) explen--; else - hb_compGenError( _szPErrors, 'F', ERR_PATTERN_DEFINITION, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_PATTERN_DEFINITION, NULL, NULL ); } rmlen = i - ipos + 1; @@ -554,7 +545,7 @@ static void ConvertPatterns( char *mpatt, int mlen, char *rpatt, int rlen ) /* Look for appropriate result markers */ ptr = rpatt; - while( (ifou = pp_strAt( exppatt, explen, ptr, rlen-(ptr-rpatt) )) > 0 ) + while( (ifou = hb_strAt( exppatt, explen, ptr, rlen-(ptr-rpatt) )) > 0 ) { /* Convert result marker into inner format */ ptr += ifou; @@ -594,8 +585,8 @@ static COMMANDS* AddCommand( char *cmdname ) HB_TRACE(HB_TR_DEBUG, ("AddCommand(%s)", cmdname)); stcmd = ( COMMANDS * ) hb_xgrab( sizeof( COMMANDS ) ); - stcmd->last = topCommand; - topCommand = stcmd; + stcmd->last = hb_pp_topCommand; + hb_pp_topCommand = stcmd; stcmd->name = strodup( cmdname ); return stcmd; } @@ -607,8 +598,8 @@ static COMMANDS* AddTranslate( char *traname ) HB_TRACE(HB_TR_DEBUG, ("AddTranslate(%s)", traname)); sttra = ( COMMANDS * ) hb_xgrab( sizeof( COMMANDS ) ); - sttra->last = topTranslate; - topTranslate = sttra; + sttra->last = hb_pp_topTranslate; + hb_pp_topTranslate = sttra; sttra->name = strodup( traname ); return sttra; } @@ -671,7 +662,7 @@ int ParseExpression( char* sLine, char* sOutLine ) } /* Look for definitions from #translate */ - stcmd = topTranslate; + stcmd = hb_pp_topTranslate; while( stcmd != NULL ) { ptri = sLine + isdvig; @@ -756,7 +747,7 @@ int ParseExpression( char* sLine, char* sOutLine ) kolpass++; if( kolpass > 20 && rezDef ) { - hb_compGenError( _szPErrors, 'F', ERR_RECURSE, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'F', ERR_RECURSE, NULL, NULL ); break; } } @@ -824,7 +815,7 @@ static int WorkPseudoF( char** ptri, char* ptro, DEFINES *stdef ) lenreal = NextParm( ptri, NULL); ptrb = ptro; - while( (ifou = pp_strAt( parfict, lenfict, ptrb, lenres-(ptrb-ptro) )) > 0 ) + while( (ifou = hb_strAt( parfict, lenfict, ptrb, lenres-(ptrb-ptro) )) > 0 ) { ptrb = ptrb+ifou-1; if( !ISNAME(*(ptrb-1)) && !ISNAME(*(ptrb+lenfict)) ) @@ -1592,7 +1583,7 @@ static void SearnRep( char *exppatt,char *expreal,int lenreal,char *ptro, int *l memcpy( expnew, ptr+1, lennew ); *(expnew + lennew++) = ' '; *(expnew + lennew) = '\0'; - while( (i = pp_strAt( exppatt, 2, expnew, lennew )) > 0 ) + while( (i = hb_strAt( exppatt, 2, expnew, lennew )) > 0 ) lennew += ReplacePattern( exppatt[2], expreal, lenreal, expnew+i-1, lennew ); if( kolmarkers ) { @@ -1895,38 +1886,6 @@ int pp_WrStr(FILE* handl_o,char *buffer) return 0; } -/* locates a substring in a string */ -int pp_strAt(char *szSub, int lSubLen, char *szText, int lLen) -{ - HB_TRACE(HB_TR_DEBUG, ("pp_strAt(%s, %d, %s, %d)", szSub, lSubLen, szText, lLen)); - - if( lSubLen ) - { - if( lLen >= lSubLen ) - { - long lPos = 0, lSubPos = 0; - - while( lPos < lLen && lSubPos < lSubLen ) - { - if( *(szText + lPos) == *(szSub + lSubPos) ) - { - lSubPos++; - lPos++; - } - else if( lSubPos ) - lSubPos = 0; - else - lPos++; - } - return (lSubPos < lSubLen? 0: lPos - lSubLen + 1); - } - else - return 0; - } - else - return 1; -} - static int md_strAt(char *szSub, int lSubLen, char *szText, int checkword, int checkPrth) { int State = STATE_NORMAL; diff --git a/harbour/source/pp/hbppint.c b/harbour/source/pp/hbppint.c index 8e1cd1ec39..2f6baa1867 100644 --- a/harbour/source/pp/hbppint.c +++ b/harbour/source/pp/hbppint.c @@ -42,32 +42,24 @@ #endif #endif -#if ( defined(_MSC_VER) || defined(__IBMCPP__) || defined(__MINW32__) ) - #include - #include -#elif ( defined(__GNUC__) || defined(__WATCOMC__) ) - #include - #include -#else - #include - #include -#endif #include +#include +#include #include "hbpp.h" #include "hberrors.h" -int iBuffer, lenBuffer; -BOOL _bPPO = 0; -char sLine[ STR_SIZE ], sOutLine[ STR_SIZE ]; -FILE * yyppo; +static int s_iBuffer; +static int s_lenBuffer; +static char s_szLine[ STR_SIZE ]; +static char s_szOutLine[ STR_SIZE ]; void Hbpp_init( void ) { HB_TRACE(HB_TR_DEBUG, ("Hbpp_init()")); - lenBuffer = 10; - iBuffer = 10; - aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 ); + s_lenBuffer = 10; + s_iBuffer = 10; + hb_pp_aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 ); } int PreProcess( FILE * handl_i, FILE * handl_o, char * sOut ) @@ -77,26 +69,27 @@ int PreProcess( FILE * handl_i, FILE * handl_o, char * sOut ) int lContinue = 0; int lens = 0, rdlen; int rezParse; + int nline = 0; HB_TRACE(HB_TR_DEBUG, ("PreProcess(%p, %p, %s)", handl_i, handl_o, sOut)); HB_SYMBOL_UNUSED( handl_o ); - while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue, - sBuffer, &lenBuffer, &iBuffer ) ) >= 0 ) + while( ( rdlen = pp_RdStr( handl_i, s_szLine + lens, STR_SIZE - lens, lContinue, + sBuffer, &s_lenBuffer, &s_iBuffer ) ) >= 0 ) { - if( ! lInclude ) + if( ! hb_pp_lInclude ) nline++; lens += rdlen; - if( sLine[ lens - 1 ] == ';' ) + if( s_szLine[ lens - 1 ] == ';' ) { lContinue = 1; lens--; lens--; - while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--; - sLine[ ++lens ] = ' '; - sLine[ ++lens ] = '\0'; + while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' ) lens--; + s_szLine[ ++lens ] = ' '; + s_szLine[ ++lens ] = '\0'; *ptrOut++ = '\n'; } @@ -108,26 +101,26 @@ int PreProcess( FILE * handl_i, FILE * handl_o, char * sOut ) if( !lContinue ) { - if( *sLine != '\0' ) + if( *s_szLine != '\0' ) { - ptr = sLine; + ptr = s_szLine; SKIPTABSPACES( ptr ); if( *ptr == '#' ) { if( ( rezParse = ParseDirective( ptr + 1 ) ) == 0 ) - *sLine = '\0'; + *s_szLine = '\0'; } else { - if( nCondCompile == 0 || aCondCompile[ nCondCompile - 1 ] ) + if( hb_pp_nCondCompile == 0 || hb_pp_aCondCompile[ hb_pp_nCondCompile - 1 ] ) { - if( ( rezParse = ParseExpression( ptr, sOutLine ) ) > 0 ) + if( ( rezParse = ParseExpression( ptr, s_szOutLine ) ) > 0 ) { printf( "\nError number %u in line %u\n", rezParse, nline ); } } else - *sLine = '\0'; + *s_szLine = '\0'; } } break; @@ -135,13 +128,10 @@ int PreProcess( FILE * handl_i, FILE * handl_o, char * sOut ) } if( rdlen < 0 ) return 0; - lens = strocpy( ptrOut, sLine ) + ( ptrOut - sOut ); + lens = strocpy( ptrOut, s_szLine ) + ( ptrOut - sOut ); *( sOut + lens++ ) = '\n'; *( sOut + lens ) = '\0'; - if( _bPPO ) - pp_WrStr( handl_o, sOut ); - return lens; } @@ -156,20 +146,20 @@ int Hp_Parse( FILE * handl_i, FILE * handl_o, char * szSource ) HB_TRACE(HB_TR_DEBUG, ("Hp_Parse(%p, %p)", handl_i, handl_o)); - while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue, + while( ( rdlen = pp_RdStr( handl_i, s_szLine + lens, STR_SIZE - lens, lContinue, sBuffer, &lenBuffer, &iBuffer ) ) >= 0 ) { lens += rdlen; iLine++; - if( sLine[ lens - 1 ] == ';' ) + if( s_szLine[ lens - 1 ] == ';' ) { lContinue = 1; lens--; lens--; - while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--; - sLine[ ++lens ] = ' '; - sLine[ ++lens ] = '\0'; + while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' ) lens--; + s_szLine[ ++lens ] = ' '; + s_szLine[ ++lens ] = '\0'; } else { @@ -179,19 +169,19 @@ int Hp_Parse( FILE * handl_i, FILE * handl_o, char * szSource ) if( !lContinue ) { - if( *sLine != '\0' ) + if( *s_szLine != '\0' ) { - ptr = sLine; + ptr = s_szLine; SKIPTABSPACES( ptr ); if( *ptr == '#' ) { ParseDirective( ptr + 1 ); - *sLine = '\0'; + *s_szLine = '\0'; } else { sprintf( szLine, "%d", iLine ); - hb_compGenWarning( _szPWarnings, 'I', WARN_NONDIRECTIVE, szSource, szLine ); + hb_compGenWarning( hb_pp_szWarnings, 'I', WARN_NONDIRECTIVE, szSource, szLine ); } } } diff --git a/harbour/source/pp/hbpplib.c b/harbour/source/pp/hbpplib.c index 5b81607565..35bc733545 100644 --- a/harbour/source/pp/hbpplib.c +++ b/harbour/source/pp/hbpplib.c @@ -53,7 +53,7 @@ PATHNAMES * hb_comp_pIncludePath = NULL; PHB_FNAME hb_comp_pFileName = NULL; -jmp_buf s_env; +static jmp_buf s_env; /* TODO: Extend the function to allow directives and external include files */ diff --git a/harbour/source/pp/stdalone/hbpp.c b/harbour/source/pp/stdalone/hbpp.c index 26ca81b59a..46624dfdbe 100644 --- a/harbour/source/pp/stdalone/hbpp.c +++ b/harbour/source/pp/stdalone/hbpp.c @@ -42,18 +42,9 @@ #endif #endif -#include -#if ( defined(_MSC_VER) || defined(__IBMCPP__) || defined(__MINGW32__) ) - #include -#elif defined(__GNUC__) - #include -#elif ! defined(__MPW__) - #include -#else - #include -#endif -#include #include +#include +#include #include #include "hbpp.h" #include "hberrors.h" @@ -62,11 +53,13 @@ static void AddSearchPath( char * szPath, PATHNAMES * * pSearchList ); static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ); -char sLine[ STR_SIZE ], sOutLine[ STR_SIZE ]; +static int s_nline = 0; +static char s_szLine[ STR_SIZE ]; +static char s_szOutLine[ STR_SIZE ]; +static int s_iWarnings = 0; -PATHNAMES *hb_comp_pIncludePath = NULL; +PATHNAMES * hb_comp_pIncludePath = NULL; PHB_FNAME hb_comp_pFileName = NULL; -int _iWarnings = 0; int main( int argc, char * argv[] ) { @@ -77,8 +70,8 @@ int main( int argc, char * argv[] ) int iArg = 1, i; BOOL bOutTable = FALSE; BOOL bOutNew = FALSE; - DEFINES * stdef = topDefine; - COMMANDS * stcmd = topCommand; + DEFINES * stdef = hb_pp_topDefine; + COMMANDS * stcmd = hb_pp_topCommand; HB_TRACE(HB_TR_DEBUG, ("main(%d, %p)", argc, argv)); @@ -123,11 +116,11 @@ int main( int argc, char * argv[] ) break; case 'w': case 'W': - _iWarnings = 1; + s_iWarnings = 1; if( argv[ iArg ][ 2 ] ) { /*there is -w<0,1,2,3> probably */ - _iWarnings = argv[ iArg ][ 2 ] - '0'; - if( _iWarnings < 0 || _iWarnings > 3 ) + s_iWarnings = argv[ iArg ][ 2 ] - '0'; + if( s_iWarnings < 0 || s_iWarnings > 3 ) printf( "\nInvalid command line option: %s\n", argv[ iArg ] ); } break; @@ -200,7 +193,7 @@ int main( int argc, char * argv[] ) } } - aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 ); + hb_pp_aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 ); Hp_Parse( handl_i, handl_o, NULL ); fclose( handl_i ); @@ -226,20 +219,20 @@ int Hp_Parse( FILE * handl_i, FILE * handl_o, char * szSource ) HB_TRACE(HB_TR_DEBUG, ("Hp_parse(%p, %p)", handl_i, handl_o)); - while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue, + while( ( rdlen = pp_RdStr( handl_i, s_szLine + lens, STR_SIZE - lens, lContinue, sBuffer, &lenBuffer, &iBuffer ) ) >= 0 ) { - if( ! lInclude ) nline++; + if( ! hb_pp_lInclude ) s_nline++; lens += rdlen; - if( sLine[ lens - 1 ] == ';' ) + if( s_szLine[ lens - 1 ] == ';' ) { lContinue = 1; lens--; lens--; - while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--; - sLine[ ++lens ] = ' '; - sLine[ ++lens ] = '\0'; + while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' ) lens--; + s_szLine[ ++lens ] = ' '; + s_szLine[ ++lens ] = '\0'; } else { @@ -247,29 +240,29 @@ int Hp_Parse( FILE * handl_i, FILE * handl_o, char * szSource ) lens = 0; } - if( *sLine != '\0' && !lContinue ) + if( *s_szLine != '\0' && !lContinue ) { - printf( "\r line %i", nline ); - ptr = sLine; + printf( "\r line %i", s_nline ); + ptr = s_szLine; SKIPTABSPACES( ptr ); if( *ptr == '#' ) { if( ParseDirective( ptr + 1 ) == 0 ) - *sLine = '\0'; + *s_szLine = '\0'; } else { - if( nCondCompile == 0 || aCondCompile[ nCondCompile - 1 ] ) - ParseExpression( ptr, sOutLine ); + if( hb_pp_nCondCompile == 0 || hb_pp_aCondCompile[ hb_pp_nCondCompile - 1 ] ) + ParseExpression( ptr, s_szOutLine ); else - *sLine = '\0'; + *s_szLine = '\0'; } } - if( ! lInclude ) + if( ! hb_pp_lInclude ) { if( lContinue ) pp_WrStr( handl_o, "\n" ); - else pp_WrStr( handl_o, sLine ); + else pp_WrStr( handl_o, s_szLine ); } } @@ -281,8 +274,8 @@ static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ) FILE *handl_o; int ipos, len_mpatt, len_value; int num; - DEFINES * stdef1 = topDefine, * stdef2 = NULL, * stdef3; - COMMANDS * stcmd1 = topCommand, * stcmd2 = NULL, * stcmd3; + DEFINES * stdef1 = hb_pp_topDefine, * stdef2 = NULL, * stdef3; + COMMANDS * stcmd1 = hb_pp_topCommand, * stcmd2 = NULL, * stcmd3; HB_TRACE(HB_TR_DEBUG, ("OutTable(%p, %p)", endDefine, endCommand)); @@ -328,7 +321,7 @@ static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ) stdef2 = stdef2->last; num++; } - fprintf( handl_o, "\n DEFINES * topDefine = " ); + fprintf( handl_o, "\n DEFINES * hb_pp_topDefine = " ); if( num == 1 ) fprintf( handl_o, "NULL;" ); else @@ -341,27 +334,27 @@ static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ) fprintf( handl_o, "{%d,\"%s\",", stcmd2->com_or_xcom, stcmd2->name ); if( stcmd2->mpatt != NULL ) { - len_mpatt = strocpy( sLine, stcmd2->mpatt ); - while( ( ipos = pp_strAt( "\1", 1, sLine, len_mpatt ) ) > 0 ) + len_mpatt = strocpy( s_szLine, stcmd2->mpatt ); + while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 ) { - pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_mpatt ); + pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt ); len_mpatt++; } - fprintf( handl_o, "\"%s\",", sLine ); + fprintf( handl_o, "\"%s\",", s_szLine ); } else fprintf( handl_o, "NULL," ); if( stcmd2->value != NULL ) { - len_value = strocpy( sLine, stcmd2->value ); - while( ( ipos = pp_strAt( "\1", 1, sLine, len_value ) ) > 0 ) + len_value = strocpy( s_szLine, stcmd2->value ); + while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 ) { - pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_value ); + pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value ); len_value++; } if( len_mpatt + len_value > 80 ) fprintf( handl_o, "\n " ); - fprintf( handl_o, "\"%s\"", sLine ); + fprintf( handl_o, "\"%s\"", s_szLine ); } else fprintf( handl_o, "NULL" ); if( num == 1 ) @@ -371,13 +364,13 @@ static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ) stcmd2 = stcmd2->last; num++; } - fprintf( handl_o, "\n COMMANDS * topCommand = " ); + fprintf( handl_o, "\n COMMANDS * hb_pp_topCommand = " ); if( num == 1 ) fprintf( handl_o, "NULL;" ); else fprintf( handl_o, " = &sC___%i;\n", num - 1 ); - stcmd1 = topTranslate; + stcmd1 = hb_pp_topTranslate; stcmd2 = NULL; while( stcmd1 != NULL ) { @@ -393,27 +386,27 @@ static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ) fprintf( handl_o, "{%d,\"%s\",", stcmd2->com_or_xcom, stcmd2->name ); if( stcmd2->mpatt != NULL ) { - len_mpatt = strocpy( sLine, stcmd2->mpatt ); - while( ( ipos = pp_strAt( "\1", 1, sLine, len_mpatt ) ) > 0 ) + len_mpatt = strocpy( s_szLine, stcmd2->mpatt ); + while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 ) { - pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_mpatt ); + pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt ); len_mpatt++; } - fprintf( handl_o, "\"%s\",", sLine ); + fprintf( handl_o, "\"%s\",", s_szLine ); } else fprintf( handl_o, "NULL," ); if( stcmd2->value != NULL ) { - len_value = strocpy( sLine, stcmd2->value ); - while( ( ipos = pp_strAt( "\1", 1, sLine, len_value ) ) > 0 ) + len_value = strocpy( s_szLine, stcmd2->value ); + while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 ) { - pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_value ); + pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value ); len_value++; } if( len_mpatt + len_value > 80 ) fprintf( handl_o, "\n " ); - fprintf( handl_o, "\"%s\"", sLine ); + fprintf( handl_o, "\"%s\"", s_szLine ); } else fprintf( handl_o, "NULL" ); if( num == 1 ) @@ -423,7 +416,7 @@ static void OutTable( DEFINES * endDefine, COMMANDS * endCommand ) stcmd2 = stcmd2->last; num++; } - fprintf( handl_o, "\n COMMANDS * topTranslate = " ); + fprintf( handl_o, "\n COMMANDS * hb_pp_topTranslate = " ); if( num == 1 ) fprintf( handl_o, "NULL;" ); else @@ -460,7 +453,7 @@ void hb_compGenError( char * _szErrors[], char cPrefix, int iError, char * szErr { HB_TRACE(HB_TR_DEBUG, ("hb_compGenError(%p, %c, %d, %s, %s)", _szErrors, cPrefix, iError, szError1, szError2)); - printf( "\r(%i) ", nline ); + printf( "\r(%i) ", s_nline ); printf( "Error %c%04i ", cPrefix, iError ); printf( _szErrors[ iError - 1 ], szError1, szError2 ); printf( "\n\n" ); @@ -472,13 +465,13 @@ void hb_compGenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * { HB_TRACE(HB_TR_DEBUG, ("hb_compGenWarning(%p, %c, %d, %s, %s)", _szWarnings, cPrefix, iWarning, szWarning1, szWarning2)); - if( _iWarnings ) + if( s_iWarnings ) { char *szText = _szWarnings[ iWarning - 1 ]; - if( (szText[ 0 ] - '0') <= _iWarnings ) + if( (szText[ 0 ] - '0') <= s_iWarnings ) { - printf( "\r(%i) ", nline ); + printf( "\r(%i) ", s_nline ); printf( "Warning %c%04i ", cPrefix, iWarning ); printf( szText + 1, szWarning1, szWarning2 ); printf( "\n" ); @@ -493,7 +486,7 @@ void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on fail HB_TRACE(HB_TR_DEBUG, ("hb_xgrab(%lu)", ulSize)); if( ! pMem ) - hb_compGenError( _szPErrors, 'P', ERR_PPMEMALLOC, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'P', ERR_PPMEMALLOC, NULL, NULL ); return pMem; } @@ -505,7 +498,7 @@ void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */ HB_TRACE(HB_TR_DEBUG, ("hb_xrealloc(%p, %lu)", pMem, ulSize)); if( ! pResult ) - hb_compGenError( _szPErrors, 'P', ERR_PPMEMREALLOC, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'P', ERR_PPMEMREALLOC, NULL, NULL ); return pResult; } @@ -517,5 +510,5 @@ void hb_xfree( void * pMem ) /* frees fixed memory */ if( pMem ) free( pMem ); else - hb_compGenError( _szPErrors, 'P', ERR_PPMEMFREE, NULL, NULL ); + hb_compGenError( hb_pp_szErrors, 'P', ERR_PPMEMFREE, NULL, NULL ); } diff --git a/harbour/source/pp/table.c b/harbour/source/pp/table.c index 4de0aa63e2..fd77721087 100644 --- a/harbour/source/pp/table.c +++ b/harbour/source/pp/table.c @@ -97,7 +97,7 @@ static DEFINES sD___50 = {"_SET_AUTORDER",NULL,-1,"46", &sD___49 }; static DEFINES sD___51 = {"_SET_AUTOSHARE",NULL,-1,"47", &sD___50 }; - DEFINES * topDefine = &sD___51; + DEFINES * hb_pp_topDefine = &sD___51; static COMMANDS sC___1 = {0,"NOTE","\1A30",NULL,NULL }; static COMMANDS sC___2 = {0,"DO","WHILE \1A00","while \1A00",&sC___1 }; @@ -390,5 +390,5 @@ static COMMANDS sC___239 = {0,"SET","ORDER TO","ordSetFocus(0)",&sC___238 }; static COMMANDS sC___240 = {0,"ANNOUNCE","\1A10","procedure \1A00 ; return",&sC___239 }; - COMMANDS * topCommand = &sC___240; - COMMANDS * topTranslate = NULL; + COMMANDS * hb_pp_topCommand = &sC___240; + COMMANDS * hb_pp_topTranslate = NULL;