int main( int argc, char * argv[] ) { char * szFile = NULL, * szRuleFile = NULL, * szWordFile = NULL, * szVerFile = NULL; char * szLogFile = NULL; BOOL fQuiet = FALSE, fWrite = FALSE, fChgLog = FALSE; char * szChangeLogID = NULL, * szLastEntry = NULL; int iResult = 0, i; 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 ] ) szFile = NULL; else fQuiet = TRUE; break; case 'w': case 'W': if( argv[ i ][ 2 ] ) szFile = NULL; else fWrite = TRUE; break; case 'c': case 'C': fChgLog = 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, FALSE ); else szFile = NULL; break; case 'o': case 'O': if( argv[ i ][ 2 ] ) szRuleFile = argv[ i ] + 2; else szFile = NULL; break; case 'x': case 'X': if( argv[ i ][ 2 ] ) szWordFile = argv[ i ] + 2; else szWordFile = NULL; break; case 'v': case 'V': if( argv[ i ][ 2 ] ) szVerFile = argv[ i ] + 2; else szFile = NULL; break; default: szFile = NULL; break; } } } } if( szFile ) { hb_pp_init( pState, fQuiet, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); if( hb_pp_inFile( pState, szFile, TRUE, NULL, TRUE ) ) { char * szSVNID = ( char * ) hb_xgrab( 10 ); char * szSVNDateID = ( char * ) hb_xgrab( 10 ); 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, fQuiet, szSVNID, szSVNDateID, &szChangeLogID, &szLastEntry ); if( iResult == 0 ) iResult = hb_pp_preprocesfile( pState, szRuleFile, szWordFile ); if( iResult == 0 && szVerFile ) iResult = hb_pp_generateVerInfo( szVerFile, szSVNID, szSVNDateID, szChangeLogID, szLastEntry ); hb_xfree( szSVNID ); hb_xfree( szSVNDateID ); } 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; }
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; }