bool CommandRenumber::setup(const std::vector<std::string>& arguments) { po::options_description cmdline("Allowed options"); cmdline.add_options() ("index-directory,i", po::value<std::string>(), "Index directory") ; add_common_options(cmdline); add_single_input_options(cmdline); add_output_options(cmdline); po::options_description hidden("Hidden options"); hidden.add_options() ("input-filename", po::value<std::string>(), "Input file") ; po::options_description desc("Allowed options"); desc.add(cmdline).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm); po::notify(vm); setup_common(vm); setup_input_file(vm); setup_output_file(vm); if (vm.count("index-directory")) { m_index_directory = vm["index-directory"].as<std::string>(); } return true; }
bool CommandRenumber::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("index-directory,i", po::value<std::string>(), "Index directory") ("object-type,t", po::value<std::vector<std::string>>(), "Renumber only objects of given type (node, way, relation)") ("show-index", po::value<std::string>(), "Show contents of index file") ("start-id,s", po::value<std::string>(), "Comma separated list of first node, way, and relation id to use (default: 1,1,1)") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_single_input_options()}; po::options_description opts_output{add_output_options()}; po::options_description hidden; hidden.add_options() ("input-filename", po::value<std::string>(), "Input file") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input).add(opts_output); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); if (vm.count("index-directory")) { m_index_directory = vm["index-directory"].as<std::string>(); } if (vm.count("show-index")) { show_index(vm["show-index"].as<std::string>()); return false; } setup_common(vm, desc); setup_progress(vm); setup_object_type_nwr(vm); setup_input_file(vm); setup_output_file(vm); if (vm.count("start-id")) { set_start_ids(vm["start-id"].as<std::string>()); } return true; }
bool simulation::execute(string dna, uint32 id) { int status, ret; pid_t pid; string args; setup_input_file(dna, id); if (!file_exists(get_bin_path(id).c_str())) { INFO("verbose", "* simulation: simulator binary does not exists.\n"); exit(0); } pid = fork(); // con vfork gdb si blocca if (pid == 0) { int fd; ret = chdir((char *)get_sim_path(id).c_str()); if((fd = open("/dev/null", O_RDWR | O_CREAT, 0777)) == -1) { perror("open"); _exit(0); } dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); close(fd); ret = execle(get_bin_path(id).c_str(), conf->get_string_config(CONFIG_SIMULATOR_BIN).c_str(), "-N", "1", "-a", conf->get_string_config(CONFIG_TEST_FILE_OUT).c_str() , NULL, environ); perror("execle"); // qui non ci arriva mai ( si spera :D ) _exit(0); } else if (pid == -1) { perror("fork"); return false; } waitpid(pid, &status, 0); return true; }
bool CommandCheckRefs::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("show-ids,i", "Show IDs of missing objects") ("check-relations,r", "Also check relations") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_single_input_options()}; po::options_description hidden; hidden.add_options() ("input-filename", po::value<std::string>(), "Input file") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); setup_common(vm, desc); setup_progress(vm); setup_input_file(vm); if (vm.count("show-ids")) { m_show_ids = true; } if (vm.count("check-relations")) { m_check_relations = true; } return true; }
bool CommandGetParents::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("default-type", po::value<std::string>()->default_value("node"), "Default item type") ("id-file,i", po::value<std::vector<std::string>>(), "Read OSM IDs from text file") ("id-osm-file,I", po::value<std::vector<std::string>>(), "Read OSM IDs from OSM file") ("add-self,s", "Add objects with specified IDs themselves") ("verbose-ids", "Print all requested IDs") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_single_input_options()}; po::options_description opts_output{add_output_options()}; po::options_description hidden; hidden.add_options() ("input-filename", po::value<std::string>(), "OSM input file") ("ids", po::value<std::vector<std::string>>(), "OSM IDs") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input).add(opts_output); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); positional.add("ids", -1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); setup_common(vm, desc); setup_progress(vm); setup_input_file(vm); setup_output_file(vm); if (vm.count("add-self")) { m_add_self = true; } if (vm.count("default-type")) { m_default_item_type = parse_item_type(vm["default-type"].as<std::string>()); } if (vm.count("verbose-ids")) { m_vout.verbose(true); m_verbose_ids = true; } if (vm.count("id-file")) { for (const std::string& filename : vm["id-file"].as<std::vector<std::string>>()) { if (filename == "-") { if (m_input_filename.empty() || m_input_filename == "-") { throw argument_error{"Can not read OSM input and IDs both from STDIN."}; } m_vout << "Reading IDs from STDIN...\n"; read_id_file(std::cin, m_ids, m_default_item_type); } else { std::ifstream id_file{filename}; if (!id_file.is_open()) { throw argument_error{"Could not open file '" + filename + "'"}; } m_vout << "Reading ID file...\n"; read_id_file(id_file, m_ids, m_default_item_type); } } } if (vm.count("id-osm-file")) { for (const std::string& filename : vm["id-osm-file"].as<std::vector<std::string>>()) { m_vout << "Reading OSM ID file...\n"; read_id_osm_file(filename, m_ids); } } if (vm.count("ids")) { std::string sids; for (const auto& s : vm["ids"].as<std::vector<std::string>>()) { sids += s + " "; } for (const auto& s : osmium::split_string(sids, "\t ;,/|", true)) { parse_and_add_id(s, m_ids, m_default_item_type); } } if (no_ids(m_ids)) { throw argument_error{"Please specify IDs to look for on command line or with option --id-file/-i or --id-osm-file/-I."}; } return true; }
bool CommandTimeFilter::setup(const std::vector<std::string>& arguments) { po::options_description cmdline("Available options"); add_common_options(cmdline); add_single_input_options(cmdline); add_output_options(cmdline); po::options_description hidden("Hidden options"); hidden.add_options() ("input-filename", po::value<std::string>(), "OSM input file") ("time-from", po::value<std::string>(), "Start of time range") ("time-to", po::value<std::string>(), "End of time range") ; po::options_description desc("Allowed options"); desc.add(cmdline).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); positional.add("time-from", 1); positional.add("time-to", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << "Usage: osmium time-filter [OPTIONS] OSM-HISTORY-FILE [TIME]\n" << " osmium time-filter [OPTIONS] OSM-HISTORY-FILE FROM-TIME TO-TIME\n\n"; std::cout << cmdline << "\n"; exit(0); } setup_common(vm); setup_input_file(vm); setup_output_file(vm); m_from = osmium::Timestamp(time(0)); m_to = m_from; if (vm.count("time-from")) { auto ts = vm["time-from"].as<std::string>(); try { m_from = osmium::Timestamp(ts); } catch (std::invalid_argument&) { throw argument_error("Wrong format for (first) timestamp (use YYYY-MM-DDThh:mm:ssZ)."); } m_to = m_from; } if (vm.count("time-to")) { auto ts = vm["time-to"].as<std::string>(); try { m_to = osmium::Timestamp(ts); } catch (std::invalid_argument&) { throw argument_error("Wrong format for second timestamp (use YYYY-MM-DDThh:mm:ssZ)."); } } if (m_from > m_to) { throw argument_error("Second timestamp is before first one."); } if (m_from == m_to) { // point in time if (m_output_file.has_multiple_object_versions()) { std::cerr << "Warning! You are writing to a file marked as having multiple object versions,\n"; std::cerr << "but there will be only a single version of each object.\n"; } } else { // time range if (!m_output_file.has_multiple_object_versions()) { std::cerr << "Warning! You are writing to a file marked as having a single object version,\n"; std::cerr << "but there might be multiple versions of each object.\n"; } } return true; }
bool CommandShow::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("format-debug,d", "Use debug format") ("format-opl,o", "Use OPL format") ("format-xml,x", "Use XML format") #ifndef _MSC_VER ("no-pager", "Do not run pager program") #endif ("object-type,t", po::value<std::vector<std::string>>(), "Read only objects of given type (node, way, relation, changeset)") ("output-format,f", po::value<std::string>(), "Format of output file") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_single_input_options()}; po::options_description hidden; hidden.add_options() ("input-filename", po::value<std::string>(), "Input file") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); setup_common(vm, desc); setup_object_type_nrwc(vm); setup_input_file(vm); #ifndef _MSC_VER if (vm.count("no-pager")) { m_pager = ""; } else { setup_pager_from_env(); } #endif if (vm.count("output-format") && vm.count("format-debug") && vm.count("format-opl") && vm.count("format-xml")) { throw argument_error("You can only use at most one of the following options: -f/--output-format, -d/--format-debug, -o/--format-opl, and -x/--format-xml."); } if (vm.count("output-format")) { m_output_format = vm["output-format"].as<std::string>(); } else if (vm.count("format-debug")) { m_output_format = "debug,color=true"; } else if (vm.count("format-opl")) { m_output_format = "opl"; } else if (vm.count("format-xml")) { m_output_format = "xml"; } else { const char* output_format_from_env = ::getenv("OSMIUM_SHOW_FORMAT"); if (output_format_from_env) { m_output_format = output_format_from_env; } } return true; }