int main(int argc, char** argv) { TCLAP::CmdLine cmd("A tools to dump 3d model files to mesh format", ' ', "1.5.5"); // add input file argument TCLAP::ValueArg<std::string> inputFileArg("i", "input", "input file", true, "", "path"); cmd.add(inputFileArg); // add output file argument TCLAP::ValueArg<std::string> outputFileArg("o", "output", "output file", true, "", "path"); cmd.add(outputFileArg); cmd.parse(argc, argv); spank::Convertor conv; if (!conv.openModelFile(inputFileArg.getValue().c_str())) { std::cout << "Error, open file failed, " << inputFileArg.getValue() << std::endl; return 1; } if (!conv.saveFile(outputFileArg.getValue().c_str())) { std::cout << "Error, save file failed, " << outputFileArg.getValue() << std::endl; return 1; } return 0; }
int main(int argc, char** argv) { try { TCLAP::CmdLine cmd("Train BDT", ' ', "0.1"); TCLAP::ValueArg<std::string> inputListArg("", "input-list", "A text file containing a list of input files", true, "", "string"); TCLAP::ValueArg<std::string> inputFileArg("i", "input-file", "The input file", true, "", "string"); cmd.xorAdd(inputListArg, inputFileArg); TCLAP::ValueArg<std::string> nameArg("n", "name", "dataset name", true, "", "string", cmd); TCLAP::ValueArg<std::string> outputFileArg("o", "output-file", "output file", true, "", "string", cmd); cmd.parse(argc, argv); std::vector<std::string> inputFiles; if (inputFileArg.isSet()) { inputFiles.push_back(inputFileArg.getValue()); } else { loadInputFiles(inputListArg.getValue(), inputFiles); } process(inputFiles, nameArg.getValue(), outputFileArg.getValue()); } catch (TCLAP::ArgException &e) { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; return 1; } return 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int main (int argc, char const *argv[]) { // This code is NOT READY to run AT ALL. IT was just a PLACE TO START BOOST_ASSERT(false); QString configFile; try { // Handle program options passed on command line. TCLAP::CmdLine cmd("PipelineRunner", ' ', DREAM3DLib::Version::Complete()); TCLAP::ValueArg<std::string> inputFileArg( "c", "config", "The text file containing the pipeline information.", true, "", "Pipeline Config File"); cmd.add(inputFileArg); // Parse the argv array. cmd.parse(argc, argv); if (argc == 1) { std::cout << "PipelineRunner program was not provided any arguments. Use the --help argument to show the help listing." << std::endl; return EXIT_FAILURE; } configFile = QString::fromStdString(inputFileArg.getValue()); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << logTime() << " error: " << e.error() << " for arg " << e.argId() << std::endl; return EXIT_FAILURE; } // Create the QSettings Object QSettings prefs(configFile, QSettings::IniFormat, NULL); readSettings(prefs); return EXIT_SUCCESS; }
int main(int argc, char** argv) { try { TCLAP::CmdLine cmd("reduce Zprime dataset", ' ', "0.1"); TCLAP::ValueArg<std::string> inputListArg("", "input-list", "A text file containing a list of input files", true, "", "string"); TCLAP::ValueArg<std::string> inputFileArg("i", "input-file", "The input file", true, "", "string"); cmd.xorAdd(inputListArg, inputFileArg); TCLAP::ValueArg<std::string> outputFileArg("o", "output-file", "output file", true, "", "string", cmd); TCLAP::SwitchArg dataArg("", "data", "Is this data?", false); TCLAP::SwitchArg mcArg("", "mc", "Is this mc?", false); cmd.xorAdd(dataArg, mcArg); TCLAP::ValueArg<std::string> typeArg("", "type", "current inputfile type (semie or semimu)", true, "", "string", cmd); TCLAP::ValueArg<std::string> pileupArg("", "pileup", "PU profile used for MC production", false, "S10", "string", cmd); TCLAP::ValueArg<int> maxEntriesArg("n", "", "Maximal number of entries to process", false, -1, "int", cmd); TCLAP::ValueArg<double> generatorWeightArg("", "weight", "MC generator weight", false, 1., "double", cmd); TCLAP::ValueArg<std::string> pdfSystArg("", "pdf-syst", "PDF systematic to compute", false, "nominal", "string", cmd); TCLAP::ValueArg<std::string> jecSystArg("", "jec-syst", "Computing trigger weight for this JEC up / down", false, "nominal", "string", cmd); TCLAP::ValueArg<std::string> triggerSystArg("", "trigger-syst", "Computing trigger weight systematic", false, "nominal", "string", cmd); TCLAP::ValueArg<std::string> pileupSystArg("", "pileup-syst", "PU profile to use for pileup reweigthing", false, "nominal", "string", cmd); TCLAP::ValueArg<std::string> btagSystArg("", "btag-syst", "Compute btag weight systematic", false, "nominal", "string", cmd); TCLAP::ValueArg<std::string> leptonSystArg("", "lepton-syst", "Compute lepton weight systematic", false, "nominal", "string", cmd); TCLAP::SwitchArg skimArg("", "skim", "Run over a skimmed file", cmd, false); TCLAP::SwitchArg chi2Arg("", "chi2", "Use chi2 sorting algorithm", false); TCLAP::SwitchArg mvaArg("", "mva", "Use MVA instead of chi2", false); TCLAP::SwitchArg kfArg("", "kf", "Use KF instead of chi2", false); TCLAP::SwitchArg hybridArg("", "hybrid", "Use hybrid method for sorting algorithm", false); std::vector<TCLAP::Arg*> xorlist; xorlist.push_back(&chi2Arg); xorlist.push_back(&mvaArg); xorlist.push_back(&kfArg); xorlist.push_back(&hybridArg); cmd.xorAdd( xorlist ); cmd.parse(argc, argv); std::string p = pileupArg.getValue(); std::transform(p.begin(), p.end(), p.begin(), ::tolower); if (p == "s6") puProfile = PUProfile::S6; else if (p == "s7") puProfile = PUProfile::S7; else if (p == "s10") puProfile = PUProfile::S10; std::string triggerSyst = triggerSystArg.getValue(); std::transform(triggerSyst.begin(), triggerSyst.end(), triggerSyst.begin(), ::tolower); if (triggerSyst != "nominal" && triggerSyst != "up" && triggerSyst != "down") { std::cerr << "--trigger-syst can only be 'nominal', 'up' or 'down'" << std::endl; exit(1); } std::string jecSyst = jecSystArg.getValue(); std::transform(jecSyst.begin(), jecSyst.end(), jecSyst.begin(), ::tolower); if (jecSyst != "nominal" && jecSyst != "up" && jecSyst != "down") { std::cerr << "--jec-syst can only be 'nominal', 'up' or 'down'" << std::endl; exit(1); } std::string puSyst = pileupSystArg.getValue(); std::transform(puSyst.begin(), puSyst.end(), puSyst.begin(), ::tolower); if (puSyst != "nominal" && puSyst != "up" && puSyst != "down") { std::cerr << "--pilup-syst can only be 'nominal', 'up' or 'down'" << std::endl; exit(1); } std::string pdfSyst = pdfSystArg.getValue(); std::transform(pdfSyst.begin(), pdfSyst.end(), pdfSyst.begin(), ::tolower); if (pdfSyst != "nominal" && pdfSyst != "up" && pdfSyst != "down") { std::cerr << "--pdf-syst can only be 'nominal', 'up' or 'down'" << std::endl; exit(1); } std::string leptonSyst = leptonSystArg.getValue(); std::transform(leptonSyst.begin(), leptonSyst.end(), leptonSyst.begin(), ::tolower); if (leptonSyst != "nominal" && leptonSyst != "up" && leptonSyst != "down") { std::cerr << "--lepton-syst can only be 'nominal', 'up' or 'down'" << std::endl; exit(1); } std::string btagSyst = btagSystArg.getValue(); std::transform(btagSyst.begin(), btagSyst.end(), btagSyst.begin(), ::tolower); if (btagSyst != "nominal" && btagSyst != "up" && btagSyst != "down") { std::cerr << "--btag-syst can only be 'nominal', 'up' or 'down'" << std::endl; exit(1); } bool isData = dataArg.isSet(); std::vector<std::string> inputFiles; if (inputFileArg.isSet()) { inputFiles.push_back(inputFileArg.getValue()); } else { loadInputFiles(inputListArg.getValue(), inputFiles); } reduce(inputFiles, outputFileArg.getValue(), isData, typeArg.getValue(), maxEntriesArg.getValue(), generatorWeightArg.getValue(), puSyst, pdfSyst, jecSyst, triggerSyst, leptonSyst, btagSyst, mvaArg.getValue(), chi2Arg.getValue(), kfArg.getValue(), hybridArg.getValue(), skimArg.getValue()); } catch (TCLAP::ArgException& e) { std::cout << e.what() << std::endl; } }
int main(int argc, char** argv) { try { TCLAP::CmdLine cmd("Create uncertainties histograms from systematic samples", ' ', "0.1"); TCLAP::ValueArg<std::string> inputFileArg("i", "input-file", "Input file in YML format", true, "", "string", cmd); cmd.parse(argc, argv); if (inputFileArg.getValue().length() == 0) return 1; YAML::Node root = YAML::LoadFile(inputFileArg.getValue()); // Load systematics, btag and type std::vector<std::string> systs = root["systs"].as<std::vector<std::string>>(); std::vector<int> btags = root["btags"].as<std::vector<int>>(); std::vector<std::string> types = root["types"].as<std::vector<std::string>>(); for (const auto& it: root["data"]) { std::vector<Input> inputs; const YAML::Node& inputs_node = it["inputs"]; for (const auto& input_node: inputs_node) { Input input; input.filename = input_node["file"].as<std::string>(); std::string type = input_node["type"].as<std::string>(); if (type == "nominal") input.type = 0; else if (type == "up") input.type = 1; else if (type == "down") input.type = -1; if (input_node["generated-events"]) input.generated_events = input_node["generated-events"].as<uint64_t>(); else input.generated_events = 1; if (input_node["cross-section"]) input.cross_section = input_node["cross-section"].as<float>(); else input.cross_section = 1.; input.top_pt_weight = 1.; inputs.push_back(input); } boost::filesystem::path output = it["output"].as<std::string>(); bool manual = false; if (it["manual"]) manual = it["manual"].as<bool>(); // Loop over systematics, btag & type for (auto& btag: btags) { for (auto& type: types) { // Create main output file, containing all systematic uncertainties merged boost::format mainFormatter(output.string()); mainFormatter.exceptions(boost::io::all_error_bits ^ (boost::io::too_many_args_bit | boost::io::too_few_args_bit ) ); mainFormatter % btag % type % "total_syst_errors"; std::shared_ptr<TFile> mainOutputFile; if (! manual) { mainOutputFile.reset(TFile::Open(mainFormatter.str().c_str(), "recreate")); } std::map<std::string, std::shared_ptr<TH1>> total_uncertainties_hists; std::vector<std::string> goodSysts = (manual) ? std::vector<std::string>({"dummy"}) : systs; for (auto& syst: goodSysts) { // Load input files for (auto& input: inputs) { boost::format formatter(input.filename.string()); formatter.exceptions(boost::io::all_error_bits ^ (boost::io::too_many_args_bit | boost::io::too_few_args_bit ) ); std::string systSuffix; if (input.type == 1) systSuffix += "Up"; else if (input.type == -1) systSuffix += "Down"; // Hack for JEC & JER if (syst == "JEC" || syst == "JER") std::transform(systSuffix.begin(), systSuffix.end(), systSuffix.begin(), ::tolower); std::string fullSyst = syst + systSuffix; formatter % btag % type; if (! manual) formatter % fullSyst; input.file.reset(TFile::Open(formatter.str().c_str())); // Try to find if a '.info' file exists, containing the mean // value of the top pt weights boost::filesystem::path p(formatter.str()); p.replace_extension("info"); if (boost::filesystem::exists(p)) { std::ifstream info(p.string()); info >> input.top_pt_weight; } } // List all histograms // For each, retrieve the nominal histogram, as well as the up & down variation // Retrieve just the names of the histograms std::vector<std::string> histograms; TList* list = inputs[0].file->GetListOfKeys(); TIter iter(list); TKey* key; TObject* obj; while ((key = (TKey*) iter())) { obj = key->ReadObj(); if (obj->InheritsFrom("TH1")) { histograms.push_back(obj->GetName()); } } // Create output file boost::format formatter(output.string()); formatter.exceptions(boost::io::all_error_bits ^ (boost::io::too_many_args_bit | boost::io::too_few_args_bit ) ); formatter % btag % type % syst; std::shared_ptr<TFile> outputFile(TFile::Open(formatter.str().c_str(), "recreate")); std::vector<std::shared_ptr<TH1>> uncertainties_hists; for (const auto& histogram: histograms) { std::shared_ptr<TH1> nominal = getHistogram(histogram, inputs, 0); std::shared_ptr<TH1> up = getHistogram(histogram, inputs, 1); std::shared_ptr<TH1> down = getHistogram(histogram, inputs, -1); std::string name = nominal->GetName(); nominal->SetName(TString::Format("%s_%s_%s", name.c_str(), syst.c_str(), "nominal")); up->SetName(TString::Format("%s_%s_%s", name.c_str(), syst.c_str(), "up")); down->SetName(TString::Format("%s_%s_%s", name.c_str(), syst.c_str(), "down")); outputFile->cd(); nominal->Write(); up->Write(); down->Write(); if (! manual) { mainOutputFile->cd(); nominal->Write(); up->Write(); down->Write(); } std::shared_ptr<TH1> uncertainties(static_cast<TH1*>(nominal->Clone())); uncertainties->SetDirectory(NULL); uncertainties->Reset(); // Keep binning but remove all events uncertainties->SetName(name.c_str()); std::shared_ptr<TGraphAsymmErrors> uncertainties_asym = std::make_shared<TGraphAsymmErrors>(); uncertainties_asym->SetName(TString::Format("%s_%s_asym", name.c_str(), syst.c_str())); std::shared_ptr<TH1>& total_uncertainties = total_uncertainties_hists[histogram]; if (! manual) { if (! total_uncertainties.get()) { total_uncertainties.reset(static_cast<TH1*>(uncertainties->Clone())); total_uncertainties->SetDirectory(NULL); } } uint32_t index = 0; for (int i = 1; i <= uncertainties->GetNbinsX(); i++) { float nominal_x = nominal->GetBinCenter(i); float nominal_value = nominal->GetBinContent(i); //float error_high = fabs(up->GetBinContent(i) - nominal_value); //float error_low = fabs(nominal_value - down->GetBinContent(i)); // Normal approximation float norm_plus = 0; float norm_minus = 0; if (up->GetBinError(i) / up->GetBinContent(i) < 0.4) norm_plus = up->GetBinContent(i) - nominal_value; if (down->GetBinError(i) / down->GetBinContent(i) < 0.4) norm_minus = nominal_value - down->GetBinContent(i); float mu = (norm_plus + norm_minus) / 3.; float mu_percent = (mu == 0 || nominal_value == 0) ? 0 : mu / nominal_value; float sigma = std::sqrt(( std::pow(norm_plus - mu, 2) + mu * mu + std::pow(norm_minus - mu, 2) ) / 2.); float sigma_percent = (sigma == 0 || nominal_value == 0) ? 0 : sigma / nominal_value; //float mean_error = (error_high + error_low) / 2.; //float error = (nominal_value == 0) ? 0. : mean_error / nominal_value; //std::cout << "Nominal: " << nominal_value << std::endl; //std::cout << "Nominal + mu: " << nominal_value + mu << std::endl; //std::cout << "Error: " << mean_error << std::endl; //std::cout << "Sigma: " << sigma << std::endl; uncertainties->SetBinContent(i, mu_percent); uncertainties->SetBinError(i, sigma_percent); uncertainties_asym->SetPoint(index, nominal_x, nominal_value + mu); uncertainties_asym->SetPointError(index, 0, 0, sigma, sigma); index++; if (! manual) { total_uncertainties->SetBinContent(i, total_uncertainties->GetBinContent(i) + mu_percent); float total_error = total_uncertainties->GetBinError(i); total_uncertainties->SetBinError(i, sqrt(sigma_percent * sigma_percent + total_error * total_error)); } } uncertainties_hists.push_back(uncertainties); outputFile->cd(); uncertainties_asym->Write(); if (! manual) { mainOutputFile->cd(); uncertainties_asym->Write(); } } outputFile->cd(); for (auto& h: uncertainties_hists) { h->Write(); } outputFile->Close(); } if (! manual) { mainOutputFile->cd(); for (auto& it: total_uncertainties_hists) { it.second->Write(); } mainOutputFile->Close(); } } } } } catch (TCLAP::ArgException &e) { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; return 1; } return 0; }
int main(int argc, char* argv[]) { TCLAP::CmdLine cmd("EnvMapTool. Stanislav Podgorskiy.", ' ', "0.1", true); TCLAP::ValueArg<std::string> inputFileArg("i", "input", "The input texture file. Can be of the following formats: *.tga, *.png, *.dds", true, "", "Input file"); TCLAP::MultiArg<std::string> inputMultiFileArg("I", "inputSequence", "The input texture files for cube map. You need specify six files: xp, xn yp, yn, zp, zn. WARNING! All the files MUST be the same format and size!", true, "Input files"); TCLAP::ValueArg<std::string> outputFileArg("o", "output", "The output texture file.", true, "", "Output file"); TCLAP::MultiArg<std::string> outputMultiFileArg("O", "outputSequence", "The output texture files for cube map. You need specify six files: xp, xn yp, yn, zp, zn", true, "Output files"); TCLAP::ValueArg<std::string> outputFormatFileArg("f", "format", "Output texture file format. Can be one of the following \"TGA\", \"DDS\", \"PNG\". Default TGA.", false, "TGA", "Output format"); TCLAP::ValueArg<int> faceToWriteArg("F", "faceToWrite", "If cubemap texture is written to format that does not support faces, this face will be written", false, 0, "Face to write"); TCLAP::ValueArg<int> blurQualityArg("q", "blurQuality", "Effects the number of samples in Monte Carlo integration. Reasonable values are between 4 - 8. Large values will increase calculation time dramatically. Default is 4", false, 4, "Blur quality"); TCLAP::ValueArg<float> blurRadiusArg("b", "blurRadius", "Gaussian blur radius. Default is 10.0", false, 10.0f, "Blur radius"); TCLAP::SwitchArg doNotRemoveOuterAreaFlag("l", "leaveOuter", "If flag is set, than while cubemap -> sphere transform area around the sphere circule are not filled black, but represent mathematical extrapolation.", false); TCLAP::ValueArg<float> inputGammaArg("g", "inputGamma", "Gamma of input texture. Default is 2.2", false, 2.2f, "Input gamma"); TCLAP::ValueArg<float> outputGammaArg("G", "outputGamma", "Gamma of output texture. Default is 2.2", false, 2.2f, "Output gamma"); TCLAP::ValueArg<int> outputWidthArg("W", "outputWidth", "Width of output texture. Default is the same as input, or 4 times upscaled in case of cube2sphere transform, or 4 times downscaled in case of sphere2cube transform", false, -1, "Output texture width"); TCLAP::ValueArg<int> outputHeightArg("H", "outputHeight", "Height of output texture. Default is the same as input, or 4 times upscaled in case of cube2sphere transform, or 4 times downscaled in case of sphere2cube transform", false, -1, "Output texture height"); std::vector<std::string> allowed; allowed.push_back("cube2sphere"); allowed.push_back("sphere2cube"); allowed.push_back("blurCubemap"); allowed.push_back("fastBlurCubemap"); allowed.push_back("convert"); TCLAP::ValuesConstraint<std::string> allowedVals( allowed ); TCLAP::UnlabeledValueArg<std::string> actionLable( "action", "Action. Can be:\n" "\tcube2sphere - Converts cube map texture to spherical map\n" "\tsphere2cube - Converts spherical map texture to cube map\n" "\tblurCubemap - Gaussian blur of cubemap\n" "\tconvert - Do nothing. Just to convert txture from one format to other\n", true, "", &allowedVals ); cmd.add(actionLable); cmd.add(outputWidthArg); cmd.add(outputHeightArg); cmd.add(outputGammaArg); cmd.add(inputGammaArg); cmd.add(doNotRemoveOuterAreaFlag); cmd.add(blurRadiusArg); cmd.add(blurQualityArg); cmd.add(faceToWriteArg); cmd.add(outputFormatFileArg); cmd.xorAdd(outputFileArg, outputMultiFileArg); cmd.xorAdd(inputFileArg, inputMultiFileArg); cmd.parse( argc, argv ); Texture* inputTex = new Texture; inputTex->m_gamma = inputGammaArg.getValue(); if ( inputFileArg.isSet() ) { inputTex->LoadFromFile(inputFileArg.getValue().c_str()); } else if ( inputMultiFileArg.isSet() ) { std::vector<std::string> files = inputMultiFileArg.getValue(); if(files.size() != 6) { printf("Error: You should specify exactly six input files.\n"); return 0; } int face = 0; for(std::vector<std::string>::iterator it = files.begin(); it != files.end(); ++it) { inputTex->LoadFromFile(it->c_str(), face); face++; } inputTex->m_cubemap = true; } Texture* outputTex = new Texture; outputTex->m_gamma = outputGammaArg.getValue(); IFileFormat* format = NULL; std::string formatString = outputFormatFileArg.getValue(); if (formatString == "TGA") { format = new TGAFile; } else if (formatString == "DDS") { format = new DDSFile; } else if (formatString == "PNG") { format = new PNGFile; } else { printf("Error: Wrong output format!\n"); return 0; } int outputWidth = inputTex->m_width; int outputHeight = inputTex->m_height; IAction* action = NULL; std::string actionString = actionLable.getValue(); if (actionString == "cube2sphere") { outputWidth *= 4; outputHeight *= 4; CubeMap2Sphere* cube2s = new CubeMap2Sphere; cube2s->m_doNotRemoveOuterAreas = doNotRemoveOuterAreaFlag.getValue(); action = cube2s; } else if (actionString == "sphere2cube") { outputWidth /= 4; outputHeight /= 4; action = new Sphere2CubeMap; } else if (actionString == "blurCubemap") { BlurCubemap* blur = new BlurCubemap; blur->m_blurQuality = blurQualityArg.getValue(); blur->m_blurRadius = blurRadiusArg.getValue(); action = blur; } else if (actionString == "fastBlurCubemap") { FastBlurCubemap* blur = new FastBlurCubemap; blur->m_blurRadius = blurRadiusArg.getValue(); action = blur; } else if (actionString == "convert") { action = new DummyAction; } else { printf("Error: Wrong action!\n"); return 0; } outputTex->m_width = outputWidthArg.isSet() ? outputWidthArg.getValue() : outputWidth; outputTex->m_height = outputHeightArg.isSet() ? outputHeightArg.getValue() : outputHeight; action->DoTask(*inputTex, *outputTex); if ( outputFileArg.isSet() ) { int face = 0; if(outputTex->m_cubemap) { face = faceToWriteArg.getValue(); face = face > 5 ? 5 : face; face = face < 0 ? 0 : face; } outputTex->SaveToFile(outputFileArg.getValue().c_str(), format, face); } else if ( outputMultiFileArg.isSet() ) { if(!outputTex->m_cubemap) { printf("Error: Can't output not a cube map to a sequence of files.\n"); return 0; } std::vector<std::string> files = outputMultiFileArg.getValue(); if(files.size() != 6) { printf("Error: You should specify exactly six output files.\n"); return 0; } int face = 0; for(std::vector<std::string>::iterator it = files.begin(); it != files.end(); ++it) { outputTex->SaveToFile(it->c_str(), format, face); face++; } } return 0; }
int main(const int argc, const char* argv[]) { std::cout << "DatCC v0.2 created by pastelmind\n" << std::endl; datcc::setCurrentProgramDir(argv[0]); try { const char exampleStr[] = "EXAMPLES:" "\nDatCC -d -u ." "\n\tDecompiles the default units.dat file." "\nDatCC -c -w \"C:\\My Mod\\my weapons.ini\"" "\n\tCompiles \"C:\\My Mod\\my weapons.ini\" into \"C:\\My Mod\\my weapons.dat\"" "\nDatCC -c -t \"C:\\test\\tech.ini\" -b C:\\test\\techdata.dat" "\n\tCompiles \"C:\\test\\tech.ini\" into \"C:\\test\\tech.dat\", using C:\\test\\techdata.dat as the base DAT file" "\nDatCC -r -f \"example mod-flingy.dat\" output.ini" "\n\tCompares \"example mod-flingy.dat\" with the default flingy.dat and save the differences to output.ini"; TCLAP::CmdLine cmd(exampleStr, ' ', "0.1"); TCLAP::SwitchArg isCompileModeArg ("c", "compile", "Compiles INI files to DAT files."); TCLAP::SwitchArg isDecompileModeArg("d", "decompile", "Decompiles DAT files to INI files."); TCLAP::SwitchArg isCompareModeArg ("r", "compare", "Compares the DAT file with the base DAT file and decompiles the differences to an INI file"); std::vector<TCLAP::Arg*> modeSwitchArgs; modeSwitchArgs.push_back(&isCompileModeArg); modeSwitchArgs.push_back(&isDecompileModeArg); modeSwitchArgs.push_back(&isCompareModeArg); cmd.xorAdd(modeSwitchArgs); TCLAP::ValueArg<std::string> baseDatArg("b", "basedat", "Base DAT file to use when compiling/comparing. If omitted, the default DAT files are used.", false, ".", "base file"); cmd.add(baseDatArg); TCLAP::UnlabeledValueArg<std::string> inputFileArg("input", "In compile mode, specify the INI file to compile. In decompile or compare mode, specify the DAT file to decompile or compare. Use . to decompile the default DAT files.", true, "", "input file"); cmd.add(inputFileArg); TCLAP::UnlabeledValueArg<std::string> outputFileArg("output", "Specify the output DAT file (in compile mode) or INI file (in decompile/compare mode). If omitted, the output file is named after the input file.", false, "", "output file"); cmd.add(outputFileArg); TCLAP::SwitchArg useUnitsDatArg ("u", "units", "Operate on units.dat"); TCLAP::SwitchArg useWeaponsDatArg ("w", "weapons", "Operate on weapons.dat"); TCLAP::SwitchArg useFlingyDatArg ("f", "flingy", "Operate on flingy.dat"); TCLAP::SwitchArg useSpritesDatArg ("s", "sprites", "Operate on sprites.dat"); TCLAP::SwitchArg useImagesDatArg ("i", "images", "Operate on images.dat"); TCLAP::SwitchArg useUpgradesDatArg("g", "upgrades", "Operate on upgrades.dat"); TCLAP::SwitchArg useTechdataDatArg("t", "techdata", "Operate on techdata.dat"); TCLAP::SwitchArg useSfxdataDatArg ("x", "sfxdata", "Operate on sfxdata.dat"); //TCLAP::SwitchArg usePortdataDatArg("p", "portdata", "Operate on portdata.dat (NOT SUPPORTED YET!)"); //TCLAP::SwitchArg useMapdataDatArg ("m", "mapdata", "Operate on mapdata.dat (NOT SUPPORTED YET)"); TCLAP::SwitchArg useOrdersDatArg ("o", "orders", "Operate on orders.dat"); std::vector<TCLAP::Arg*> datSwitchArgs; datSwitchArgs.push_back(&useUnitsDatArg); datSwitchArgs.push_back(&useWeaponsDatArg); datSwitchArgs.push_back(&useFlingyDatArg); datSwitchArgs.push_back(&useSpritesDatArg); datSwitchArgs.push_back(&useImagesDatArg); datSwitchArgs.push_back(&useUpgradesDatArg); datSwitchArgs.push_back(&useTechdataDatArg); datSwitchArgs.push_back(&useSfxdataDatArg); //datSwitchArgs.push_back(&usePortdataDatArg); //datSwitchArgs.push_back(&useMapdataDatArg); datSwitchArgs.push_back(&useOrdersDatArg); cmd.xorAdd(datSwitchArgs); cmd.parse(argc, argv); //-------- Main program logic start --------// datcc::loadData(); if (isCompileModeArg.isSet()) { //Compile mode if (useUnitsDatArg.isSet()) datcc::compileUnits(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useWeaponsDatArg.isSet()) datcc::compileWeapons(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useFlingyDatArg.isSet()) datcc::compileFlingy(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useSpritesDatArg.isSet()) datcc::compileSprites(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useImagesDatArg.isSet()) datcc::compileImages(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useUpgradesDatArg.isSet()) datcc::compileUpgrades(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useTechdataDatArg.isSet()) datcc::compileTechdata(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useSfxdataDatArg.isSet()) datcc::compileSfxdata(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useOrdersDatArg.isSet()) datcc::compileOrders(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else throw TCLAP::ArgException("Unsupported DAT file format, please wait for new version.", "UnsupportedFormat", "Unsupported DAT format exception"); } else if (isDecompileModeArg.isSet()) { if (baseDatArg.isSet()) throw TCLAP::ArgException("Base DAT argument is unnecessary for decompile mode", "unused_basedat", "Unused base DAT argument"); //Decompile mode if (useUnitsDatArg.isSet()) datcc::decompileUnits(inputFileArg.getValue(), outputFileArg.getValue()); else if (useWeaponsDatArg.isSet()) datcc::decompileWeapons(inputFileArg.getValue(), outputFileArg.getValue()); else if (useFlingyDatArg.isSet()) datcc::decompileFlingy(inputFileArg.getValue(), outputFileArg.getValue()); else if (useSpritesDatArg.isSet()) datcc::decompileSprites(inputFileArg.getValue(), outputFileArg.getValue()); else if (useImagesDatArg.isSet()) datcc::decompileImages(inputFileArg.getValue(), outputFileArg.getValue()); else if (useUpgradesDatArg.isSet()) datcc::decompileUpgrades(inputFileArg.getValue(), outputFileArg.getValue()); else if (useTechdataDatArg.isSet()) datcc::decompileTechdata(inputFileArg.getValue(), outputFileArg.getValue()); else if (useSfxdataDatArg.isSet()) datcc::decompileSfxdata(inputFileArg.getValue(), outputFileArg.getValue()); else if (useOrdersDatArg.isSet()) datcc::decompileOrders(inputFileArg.getValue(), outputFileArg.getValue()); else throw TCLAP::ArgException("Unsupported DAT file format, please wait for new version.", "UnsupportedFormat", "Unsupported DAT format exception"); } else if (isCompareModeArg.isSet()) { //Compare mode if (useUnitsDatArg.isSet()) datcc::compareUnits(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useWeaponsDatArg.isSet()) datcc::compareWeapons(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useFlingyDatArg.isSet()) datcc::compareFlingy(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useSpritesDatArg.isSet()) datcc::compareSprites(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useImagesDatArg.isSet()) datcc::compareImages(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useUpgradesDatArg.isSet()) datcc::compareUpgrades(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useTechdataDatArg.isSet()) datcc::compareTechdata(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useSfxdataDatArg.isSet()) datcc::compareSfxdata(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else if (useOrdersDatArg.isSet()) datcc::compareOrders(inputFileArg.getValue(), outputFileArg.getValue(), baseDatArg.getValue()); else throw TCLAP::ArgException("Unsupported DAT file format, please wait for new version.", "UnsupportedFormat", "Unsupported DAT format exception"); } else { //Should never reach here throw TCLAP::ArgException("Cannot determine compile/decompile mode"); } } catch (TCLAP::ArgException &e) { std::cerr << "Error: " << e.what() << std::endl; } return 0; }