void hb_compInitPP( HB_COMP_DECL, int argc, const char * const argv[], PHB_PP_OPEN_FUNC pOpenFunc ) { HB_TRACE( HB_TR_DEBUG, ( "hb_compInitPP()" ) ); if( HB_COMP_PARAM->pLex->pPP ) { hb_pp_init( HB_COMP_PARAM->pLex->pPP, HB_COMP_PARAM->fQuiet, HB_COMP_PARAM->iMaxTransCycles, HB_COMP_PARAM, pOpenFunc, NULL, hb_pp_ErrorGen, hb_pp_Disp, hb_pp_PragmaDump, HB_COMP_ISSUPPORTED( HB_COMPFLAG_HB_INLINE ) ? hb_pp_hb_inLine : NULL, hb_pp_CompilerSwitch ); if( HB_COMP_PARAM->iTraceInclude ) hb_pp_setIncFunc( HB_COMP_PARAM->pLex->pPP, hb_pp_fileIncluded ); if( ! HB_COMP_PARAM->szStdCh ) hb_pp_setStdRules( HB_COMP_PARAM->pLex->pPP ); else if( HB_COMP_PARAM->szStdCh[ 0 ] > ' ' ) hb_pp_readRules( HB_COMP_PARAM->pLex->pPP, HB_COMP_PARAM->szStdCh ); else if( ! HB_COMP_PARAM->fQuiet ) hb_compOutStd( HB_COMP_PARAM, "Standard command definitions excluded.\n" ); hb_pp_initDynDefines( HB_COMP_PARAM->pLex->pPP, ! HB_COMP_PARAM->fNoArchDefs ); /* Add /D and /undef: command line or envvar defines */ hb_compChkDefines( HB_COMP_PARAM, argc, argv ); /* add extended definitions files (-u+<file>) */ if( HB_COMP_PARAM->iStdChExt > 0 ) { int i = 0; while( i < HB_COMP_PARAM->iStdChExt ) hb_pp_readRules( HB_COMP_PARAM->pLex->pPP, HB_COMP_PARAM->szStdChExt[ i++ ] ); } /* mark current rules as standard ones */ hb_pp_setStdBase( HB_COMP_PARAM->pLex->pPP ); } }
int main( int argc, char * argv[] ) { char * szFile = NULL, * szRuleFile = NULL, * szVerFile = NULL; char * szStdCh = NULL, * szLogFile = NULL, * szInclude; HB_BOOL fWrite = HB_FALSE, fChgLog = HB_FALSE; char * szChangeLogID = NULL, * szLastEntry = NULL; int iRevID = 0, iResult = 0, iQuiet = 0, i; char * szPPRuleFuncName = NULL; PHB_PP_STATE pState; pState = hb_pp_new(); if( argc >= 2 ) { szFile = argv[ 1 ]; for( i = 2; szFile && i < argc; i++ ) { if( ! HB_ISOPTSEP( argv[ i ][ 0 ] ) ) szFile = NULL; else { switch( argv[ i ][ 1 ] ) { case 'q': case 'Q': if( ! argv[ i ][ 2 ] ) iQuiet = 1; else if( argv[ i ][ 2 ] == '-' && ! argv[ i ][ 3 ] ) iQuiet = 0; else if( argv[ i ][ 2 ] >= '0' && argv[ i ][ 2 ] <= '2' && ! argv[ i ][ 3 ] ) iQuiet = argv[ i ][ 2 ] - '0'; else szFile = NULL; break; case 'd': case 'D': if( ! argv[ i ][ 2 ] ) szFile = NULL; else { char * szDefText = hb_strdup( argv[ i ] + 2 ), * szAssign; szAssign = strchr( szDefText, '=' ); if( szAssign ) *szAssign++ = '\0'; hb_pp_addDefine( pState, szDefText, szAssign ); hb_xfree( szDefText ); } break; case 'e': case 'E': if( argv[ i ][ 2 ] ) szPPRuleFuncName = argv[ i ] + 2; else szPPRuleFuncName = NULL; break; case 'w': case 'W': if( argv[ i ][ 2 ] ) szFile = NULL; else fWrite = HB_TRUE; break; case 'c': case 'C': fChgLog = HB_TRUE; if( argv[ i ][ 2 ] ) szLogFile = argv[ i ] + 2; break; case 'i': case 'I': if( argv[ i ][ 2 ] ) hb_pp_addSearchPath( pState, argv[ i ] + 2, HB_FALSE ); else szFile = NULL; break; case 'o': case 'O': if( argv[ i ][ 2 ] ) szRuleFile = argv[ i ] + 2; else szFile = NULL; break; case 'v': case 'V': if( argv[ i ][ 2 ] ) szVerFile = argv[ i ] + 2; else szFile = NULL; break; case 'u': case 'U': if( argv[ i ][ 2 ] ) szStdCh = argv[ i ] + 2; else szStdCh = NULL; break; default: szFile = NULL; break; } } } } if( iQuiet < 2 ) { printf( "Harbour Preprocessor %d.%d.%d%s\n", HB_VER_MAJOR, HB_VER_MINOR, HB_VER_RELEASE, HB_VER_STATUS ); printf( "Copyright (c) 1999-2014, http://harbour-project.org/\n" ); } if( szFile ) { if( ! szRuleFile && ! szVerFile ) fWrite = HB_TRUE; hb_pp_init( pState, iQuiet != 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); szInclude = hb_getenv( "INCLUDE" ); if( szInclude ) { if( szInclude[ 0 ] ) hb_pp_addSearchPath( pState, szInclude, HB_FALSE ); hb_xfree( szInclude ); } if( szStdCh ) hb_pp_readRules( pState, szStdCh ); if( hb_pp_inFile( pState, szFile, HB_TRUE, NULL, HB_TRUE ) ) { if( fWrite ) { char szFileName[ HB_PATH_MAX ]; PHB_FNAME pFileName; pFileName = hb_fsFNameSplit( szFile ); pFileName->szExtension = ".ppo"; hb_fsFNameMerge( szFileName, pFileName ); hb_xfree( pFileName ); hb_pp_outFile( pState, szFileName, NULL ); } if( fChgLog ) iResult = hb_pp_parseChangelog( pState, szLogFile, iQuiet, &iRevID, &szChangeLogID, &szLastEntry ); if( iResult == 0 ) iResult = hb_pp_preprocesfile( pState, szRuleFile, szPPRuleFuncName ); if( iResult == 0 && szVerFile ) iResult = hb_pp_generateVerInfo( szVerFile, iRevID, szChangeLogID, szLastEntry ); if( iResult == 0 && hb_pp_errorCount( pState ) > 0 ) iResult = 1; } else iResult = 1; } else { hb_pp_usage( argv[ 0 ] ); iResult = 1; } if( szChangeLogID ) hb_xfree( szChangeLogID ); if( szLastEntry ) hb_xfree( szLastEntry ); hb_pp_free( pState ); return iResult; }