int main(int argc, char *argv[]) { CheckearthqParameters p; p.iterations = -1; try { /* Parse command line options and config file */ getProgramOptions(argc, argv, &p); list<Earthquake> earthquakes{ getEarthquakes(p.input_file, p.excl_unknown, p.skip_bad, p.dbf) }; for(auto e : earthquakes) { if(e.deaths >= p.min_deaths && e.when.date().year() >= p.year_from && e.when.date().year() <= p.year_to) { p.earthquakes.push_back(e.when); } } Random::RandomGen r(p.config_file); Ephemeris::SwissEphemeris se(p.ephemeris_path); Ephemeris::ephemeris = &se; performMainTest(p, &r); return 0; } catch(const exception& e) { cerr << e.what() << "\n"; } catch(...) { cerr << "unknown error\n"; } return 1; }
int main(int argc, char *argv[]) { try { CheckearthqParameters p; getProgramOptions(argc, argv, &p); Random::RandomGen r(p.config_file); Ephemeris::SwissEphemeris se(p.ephemeris_path); Ephemeris::ephemeris = &se; list<Earthquake> earthquakes{ getEarthquakes(p.input_file, p.excl_unknown, p.skip_bad, p.dbf) }; list<DateTime> earthquake_date_times; for(auto e : earthquakes) { if(e.deaths >= p.min_deaths && e.when.date().year() >= p.year_from && e.when.date().year() <= p.year_to) { earthquake_date_times.push_back(e.when); } } Test::performMainTest(earthquake_date_times, p, &r); return 0; } catch(const exception& e) { cerr << e.what() << "\n"; } catch(...) { cerr << "unknown error\n"; } return 1; }
int main(int argc, char* argv[]) { Params args; size_t countFiles = 0; if (getProgramOptions(argc, argv, args)) { auto start = std::chrono::steady_clock::now(); if(!args.parallel) { for (auto path : args.inputs) { if (fs::is_directory(path)) { fs::directory_iterator end; fs::directory_iterator entry(path); while(entry != end) { if (_stricmp(entry->path().extension().string().c_str(), ".pex") == 0) { for (auto line : processFile(entry->path(), args)) { std::cout << line << '\n'; } ++countFiles; } entry++; } } else { ++countFiles; for (auto line : processFile(path, args)) { std::cout << line << '\n'; } } } } else { std::vector<std::future<ProcessResults>> results; for (auto& path : args.inputs) { if (fs::is_directory(path)) { fs::directory_iterator end; fs::directory_iterator entry(path); while(entry != end) { if (_stricmp(entry->path().extension().string().c_str(), ".pex") == 0) { results.push_back(std::async(std::launch::async, processFile, fs::path(entry->path()), args)); } entry++; } } else { results.push_back(std::async(std::launch::async, processFile, path, args)); } } for (auto& result : results) { for(auto& line : result.get()) { std::cout << line << '\n'; } } countFiles = results.size(); } auto end = std::chrono::steady_clock::now(); auto diff = end - start; std::cout << countFiles << " files processed in " << std::chrono::duration <double> (diff).count() << " s" << std::endl; return 0; } return 1; }
void parseCommandLineArgs(int argc, char** argv, std::vector<TagDisplayDesc>& tag_disp_descs, StatCmd& cmd, boost::any& cmd_arg) { //TODO: fill in the print_options arg. // --table, etc. cmd = StatCmd::NO_CMD; auto desc = getProgramOptions(); po::variables_map vm; auto parsed = po::command_line_parser(argc, argv) .options(desc) .allow_unregistered() .run(); po::store(parsed, vm); auto tags = std::vector<std::string>{}; if(vm.count("tags")) tags = vm["tags"].as<std::vector<std::string>>(); tag_disp_descs.clear(); if(tags.empty()) { tag_disp_descs.push_back(TagDisplayDesc{}); } for(auto& tag: tags) { TagDisplayDesc tag_desc; std::vector<std::string> tag_indices; boost::split(tag_indices, tag, boost::is_any_of(":")); tag_desc.tag_hname = tag_indices[0]; if(tag_indices.size() > 1) { tag_desc.print_options.array_indices = tag_indices[1]; } tag_disp_descs.push_back(std::move(tag_desc)); } if(vm["show-tags"].as<bool>()) { cmd = StatCmd::PRINT_TAG; } else if(vm["stat-types"].as<bool>()) { cmd = StatCmd::PRINT_STAT_TYPE; } else if(vm["dump-stats"].as<bool>()) { cmd = StatCmd::DUMP_STAT; } else if(vm["clear-stats"].as<bool>()) { cmd = StatCmd::CLEAR_STAT; } else if(vm.count("log-level")) { //Args: <LoggerIdx> [<LogLevel>] //No LogLevel arg will print the current log level auto arg_vec = vm["log-level"].as<std::vector<std::string>>(); int logger_idx = 0; if(arg_vec.size() > 0) { try { logger_idx = boost::lexical_cast<int>(arg_vec[0]); } catch(boost::bad_lexical_cast&) { std::cerr << "Invalid logger idx!\n"; } } LogLevelCommand logCmd; if(arg_vec.size() == 2) { logCmd.new_log_level = arg_vec[1]; logCmd.set_log_level = true; } logCmd.logger_idx = logger_idx; cmd = StatCmd::LOG_LEVEL; cmd_arg = logCmd; } else if(vm.count("output-log")) { LogOutputCommand log_cmd; auto arg_vec = vm["output-log"].as<std::vector<std::string>>(); po::options_description log_desc("output log options"); log_desc.add_options() ("help", "Show help") ("out-file", po::value<std::string>(), "Output file name, if not given will default to stdout.") ("log-idx", po::value<int>(), "Logger index") ("no-tag", "Don't show tag") ("no-time-stamp", "Don't show time stamp") ("no-log-level", "Don't show log level") ("exclude-tags", po::value<std::vector<std::string>>()->multitoken()->zero_tokens(), "Do not output log entries corresponding to the supplied list of tags") ("exclude-log-levels", po::value<std::vector<std::string>>()->multitoken()->zero_tokens(), "Do not output log entries corresponding to the supplied list of log-levels\n" "For example \"DEBUG INFO\"") ; auto opts = po::collect_unrecognized(parsed.options, po::include_positional); po::store(po::command_line_parser(opts).options(log_desc).run(), vm); if(vm.count("help")) { std::cout << log_desc << std::endl; std::exit(0); } if(vm.count("out-file")) { log_cmd.output_filename = vm["out-file"].as<std::string>(); } if(vm.count("log-idx")) { log_cmd.logger_idx = vm["log-idx"].as<int>(); } if(vm.count("no-tag")) { log_cmd.show_tag = false; } if(vm.count("no-time-stamp")) { log_cmd.show_time_stamp = false; } if(vm.count("no-log-level")) { log_cmd.show_log_level = false; } if(vm.count("exclude-tags")) { log_cmd.exclude_tags = vm["exclude-tags"].as<std::vector<std::string>>(); } if(vm.count("exclude-log-levels")) { log_cmd.exclude_log_levels = vm["exclude-log-levels"].as<std::vector<std::string>>(); } cmd = StatCmd::DUMP_LOG; cmd_arg = log_cmd; } if(vm.count("help")) { std::cout << desc << std::endl; std::exit(0); } }