int main ( int iArgumentCount, char* szArgs [] ) { char* szInputFile = NULL; char* szOutputFile = NULL; bool bError = false; char szError [32]; // Load the input file int i = 0; while ( i < iArgumentCount ) { // -i if ( stricmp ( szArgs [i], "-i" ) == 0 ) { ++i; if ( i < iArgumentCount ) { if ( !szInputFile ) { szInputFile = new char [ strlen ( szArgs [i] ) + 1 ]; strcpy ( szInputFile, szArgs [i] ); } else { bError = true; strcpy ( szError, "-i defined more than once" ); } } } // -o if ( stricmp ( szArgs [i], "-o" ) == 0 ) { ++i; if ( i < iArgumentCount ) { if ( !szOutputFile ) { szOutputFile = new char [ strlen ( szArgs [i] ) + 1 ]; strcpy ( szOutputFile, szArgs [i] ); } else { bError = true; strcpy ( szError, "-o defined more than once" ); } } } // Increase index ++i; } // Error? if ( bError ) { printf ( "ERROR: %s\n", szError ); return 1; } // User specified an input/output file? if ( !szInputFile ) { printf ( "ERROR: input file not specified (use -i)\n" ); return 1; } if ( !szOutputFile ) { printf ( "ERROR: output file not specified (use -o)\n" ); return 1; } // Try to open the input file CConfig* pInput = new CConfig ( szInputFile ); if ( pInput->DoesFileExist () ) { // Try to open the output file FILE* pOutput = fopen ( szOutputFile, "w+" ); if ( pOutput ) { // Start converting return Convert ( pInput, pOutput ); } else { printf ( "ERROR: couldn't open output file '%s'\n", szInputFile ); return 1; } } else { printf ( "ERROR: couldn't open input file '%s'\n", szInputFile ); return 1; } return 0; }