void ExtractKyra::execute() { Common::Filename inputpath(_inputPaths[0].path); Extractor *extract = 0; if (isHoFInstaller) { extract = new HoFInstaller(inputpath.getFullPath().c_str()); } else { PAKFile *myfile = new PAKFile; if (!myfile->loadFile(inputpath.getFullPath().c_str(), isAmiga)) { delete myfile; error("Couldn't load file '%s'", inputpath.getFullPath().c_str()); } extract = myfile; } // Everything has been decided, do the actual extraction if (extractAll) { extract->outputAllFiles(&_outputPath); } else if (extractOne) { inputpath.setFullName(singleFilename); extract->outputFileAs(singleFilename.c_str(), inputpath.getFullPath().c_str()); } else { extract->drawFileList(); } delete extract; }
int main(int argc, char *argv[]) { bool success = true; if (argc < 3) { std::cerr << "Syntax error: use" << std::endl; std::cerr << argv[0] << " classname inputpath" << std::endl; return 1; } std::string modname(argv[1]); std::string inputpath(argv[2]); std::string ifname = inputpath + std::string("/") + modname + std::string("_tests.un"); std::string impl_fname = modname + std::string("_test_impls-tmp.F90"); std::string calls_fname = modname + std::string("_test_calls.F90"); std::string list_fname = modname + std::string("_tests.tests"); std::string mpilist_fname = modname + std::string("_tests.mpitests"); std::vector<std::string> input, output; try { success = success && read_template(ifname, input); success = success && replace_modname(modname, input); success = success && parse_impl(ifname, input, output); success = success && write_output(impl_fname, output); output.clear(); success = success && parse_calls(ifname, input, output); success = success && write_output(calls_fname, output); output.clear(); success = success && parse_list(ifname, input, output); success = success && write_output(list_fname, output); output.clear(); success = success && parse_mpilist(ifname, input, output); success = success && write_output(mpilist_fname, output); output.clear(); } catch (ParserException &ex) { std::cerr << "Caught exception: " << ex.getMsg() << std::endl; success = false; } catch (std::string &ex) { std::cerr << "Caught exception: " << ex << std::endl; success = false; } catch (...) { std::cerr << "Caught unknown exception." << std::endl; success = false; } return (success ? 0 : 1); }
int _tmain(int argc, _TCHAR* argv[]) { try { po::options_description desc( "Options" ); desc.add_options() ( "help,h", "Show detailed help." ) ( "options,p", "Show parameter information." ) ( "version,p", "Show version information." ) ( "input-file,i", po::value<std::vector<std::string>>(), "Define file(s) for the convertion input." ) ( "input-type,I", po::value<std::vector<std::string>>(), "Define file type(s) for automatic conversion of files in the working directory." ) ( "output-file,o", po::value<std::string>(), "Define file for the convertion output." ) ( "noheader,h", "Disable adding of header support defines." ) ( "const,C", "Define array as const." ) ( "respectcase,r", "Disable converting file types into lower case." ) ( "wxnone,w", "Disable adding of wxWidgets support macro's." ) ( "wxheader,W", po::value<std::string>()->default_value( "wx/wx.h" ), "Select the header that includes wxWidgets (precompiled header?)." ) ( "appendtype,t", "Add the file type at the end of the identifier (myimage_png)." ) ( "text,T", "Disable binary output and use text output, converts feed codes to systems defaults." ) ; po::positional_options_description posdesc; posdesc.add( "input-file", -1 ); po::variables_map opt; po::store( po::command_line_parser( argc, argv ).options( desc ).positional( posdesc ).run(), opt ); po::store( po::parse_config_file( fs::ifstream( fs::path( "default.cfg" ) ), desc ), opt ); po::notify( opt ); std::cout << WXINCLUDE_INFO << std::endl; /* Show options when requested */ if ( opt.count( "options" ) ) { std::cout << desc << std::endl << std::endl; exit( 0 ); } /* Show help when requested */ if ( opt.count( "help" ) ) { std::cout << WXINCLUDE_HELP; std::cout << std::endl << desc << std::endl << std::endl; exit( 0 ); } /* Show version when requested */ if ( opt.count( "version" ) ) { std::cout << WXINCLUDE_VERSION << std::endl; exit( 0 ); } /* Process */ if ( opt.count( "input-file" ) || opt.count( "input-type" ) ) { if ( opt.count( "output-file" ) ) { /* Create timer */ boost::timer timer; /* Create output file */ std::string headername( opt[ "output-file" ].as<std::string>() ); fs::path outputpath( headername ); fs::ofstream output( outputpath, std::ios::out | std::ios::trunc ); /* Use buffer */ char outbuffer[BUFFER_SIZE]; output.rdbuf()->pubsetbuf( outbuffer, BUFFER_SIZE ); if ( !opt.count( "text" ) ) output.setf( std::ios::binary ); if ( !output ) throw std::runtime_error( "Failed to create output file!" ); /* Show status */ std::cout << "Build : file '" << outputpath.leaf() << "'..." << std::endl; /* Get base name of file */ headername = fs::basename( outputpath ); /* Data string stream */ std::ostringstream data; /* Write header start when wanted */ if ( !opt.count( "noheader" ) ) defineheader_start( data, headername, opt.count( "wxnone" ) ? false : true, opt.count( "const" ) ? true : false ); /* Get defined or else default wx header */ std::string includename( opt[ "wxheader" ].as<std::string>() ); /* Write macros when wanted */ if ( !opt.count( "wxnone" ) ) definemacros( data, includename, opt[ "wxheader" ].defaulted() ); /* Common input buffer */ char inbuffer[BUFFER_SIZE]; /* Process input files based on provided list */ if ( opt.count( "input-file" ) ) { std::vector<std::string> files( opt[ "input-file" ].as<std::vector<std::string>>() ); BOOST_FOREACH( std::string& file, files ) { fs::path inputpath( file ); std::string fileext( fs::extension( inputpath ) ); fs::ifstream input( inputpath, std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ boost::erase_last( file, fileext ); if ( !opt.count( "respectcase" ) ) boost::to_lower( fileext ); /* Append type */ if ( opt.count( "appendtype" ) ) { boost::erase_first( fileext, "." ); /* Static and NO copy constructor for speed */ static boost::format fmt( "%1%_%2%" ); file = boost::str( fmt % file % fileext ); } /* Lower case names when wanted */ if ( !opt.count( "respectcase" ) ) boost::to_lower( file ); /* Process file */ definefile( data, input, file, opt.count( "const" ) ? true : false ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } } /* Process input files based on provided type */ if ( opt.count( "input-type" ) ) { std::vector<std::string> types( opt[ "input-type" ].as<std::vector<std::string>>() ); for ( fs::directory_iterator dir_itr( fs::initial_path() ); dir_itr != fs::directory_iterator(); ++dir_itr ) { BOOST_FOREACH( std::string& type, types ) { /* Normal file? */ if ( fs::is_regular( dir_itr->status() ) ) { /* Wanted type? */ std::string fileext( fs::extension( dir_itr->path() )); bool equals = false; if ( opt.count( "respectcase" ) ) equals = boost::equals( fileext, type ); else equals = boost::iequals( fileext, type ); if ( equals ) { fs::ifstream input( dir_itr->path(), std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); std::string file( dir_itr->path().leaf() ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ boost::erase_last( file, fileext ); /* Append type */ if ( opt.count( "appendtype" ) ) { boost::erase_first( fileext, "." ); /* Static and NO copy constructor for speed */ static boost::format fmt( "%1%_%2%" ); file = boost::str( fmt % file % fileext ); } /* Lower case names when wanted */ if ( !opt.count( "respectcase" ) ) boost::to_lower( file ); /* Process file */ definefile( data, input, file, opt.count( "const" ) ? true : false ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } } } } }