poaflocParser Of Arguments For Lines Of Commands |
git clone git://git.dimitrijedobrota.com/poafloc.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | |
commit | a23c8139cf1ef9d4141701edc0385ab26b07cebd |
parent | 31ec9d8f40fb2be1730ea600e5e73e2cebb8630a |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Thu, 6 Jun 2024 02:19:13 +0200 |
Ignore options after --
Diffstat:M | args.hpp | | | ++++++++- |
M | demo.cpp | | | ++-- |
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/args.hpp b/args.hpp
@@ -26,13 +26,14 @@ class Parser {
for (int i = 0; argp->options[i].key; i++) {
const auto &option = argp->options[i];
const uint8_t idx = option.key - 'a';
if (options[idx]) {
std::cerr << std::format("duplicate key {}\n", option.key);
throw new std::runtime_error("duplicate key");
}
options[idx] = &option;
if (option.name) trie.insert(option.name, option.key);
options[idx] = &option;
}
}
@@ -45,6 +46,8 @@ class Parser {
continue;
}
if (!std::strcmp(argv[i], "--")) break;
if (argv[i][1] != '-') {
const char *opt = argv[i] + 1;
for (int j = 0; opt[j]; j++) {
@@ -91,6 +94,10 @@ class Parser {
}
}
for (i = i + 1; i < argc; i++) {
argp->parser(-1, argv[i], input);
}
return 0;
unknown:
diff --git a/demo.cpp b/demo.cpp
@@ -6,8 +6,8 @@
void error(const std::string &message) { std::cerr << message << std::endl; }
struct arguments_t {
const char *output_file = 0;
const char *input_file = 0;
const char *output_file = "";
const char *input_file = "";
bool debug = 0;
bool hex = 0;