poafloc

Parser 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 1b478249f70511cd5061d33e52322c5f6df7025f
parent 8950af9d55d13335e71fe92c0cfc6ee132919584
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Mon, 10 Jun 2024 22:05:57 +0200

Put everything into args namespace

Diffstat:
M demo/main.cpp | ++
M include/args.h | ++
M include/args.hpp | ++++
M src/args.cpp | ++++
M src/c_bindings.cpp | ++++
M src/help.cpp | ++++
M src/trie.cpp | ++++

7 files changed, 24 insertions(+), 0 deletions(-)


diff --git a/ demo/main.cpp b/ demo/main.cpp

@@ -4,6 +4,8 @@ #include <iostream> #include <vector>
using namespace args;
void error(const std::string &message) { std::cerr << message << std::endl; } struct arguments_t { const char *output_file = "";

diff --git a/ include/args.h b/ include/args.h

@@ -3,6 +3,7 @@ #ifdef __cplusplus extern "C" {
namespace args {
struct Parser; typedef Parser args_parser; #else

@@ -48,6 +49,7 @@ int args_parse(args_argp_t *argp, int argc, char *argv[], void *input); void *args_parser_input(args_parser *parser); #ifdef __cplusplus
} // namespace args
} // extern "C" #endif

diff --git a/ include/args.hpp b/ include/args.hpp

@@ -7,6 +7,8 @@ #include <unordered_map> #include <vector>
namespace args {
class Parser { public: using option_t = args_option_t;

@@ -83,4 +85,6 @@ class Parser { trie_t trie; };
} // namespace args
#endif

diff --git a/ src/args.cpp b/ src/args.cpp

@@ -7,6 +7,8 @@ #include <iostream> #include <sstream>
namespace args {
Parser::Parser(void *input, argp_t *argp) : input(input), argp(argp) { int group = 0, key_last = 0; bool hidden = false;

@@ -197,3 +199,5 @@ excess: argp->parse(Key::ERROR, 0, this); return 3; }
} // namespace args

diff --git a/ src/c_bindings.cpp b/ src/c_bindings.cpp

@@ -1,8 +1,12 @@ #include "args.h" #include "args.hpp"
namespace args {
int args_parse(args_argp_t *argp, int argc, char *argv[], void *input) { return Parser::parse(argp, argc, argv, input); } void *args_parser_input(args_parser *parser) { return parser->input; }
} // namespace args

diff --git a/ src/help.cpp b/ src/help.cpp

@@ -5,6 +5,8 @@ #include <iostream> #include <sstream>
namespace args {
bool Parser::help_entry_t::operator<(const help_entry_t &rhs) const { if (group != rhs.group) { if (group && rhs.group) {

@@ -180,3 +182,5 @@ void Parser::usage(const char *name) const { exit(0); }
} // namespace args

diff --git a/ src/trie.cpp b/ src/trie.cpp

@@ -2,6 +2,8 @@ #include <cstdint>
namespace args {
Parser::trie_t::~trie_t() noexcept { for (uint8_t i = 0; i < 26; i++) { delete children[i];

@@ -36,3 +38,5 @@ int Parser::trie_t::get(const std::string &option) const { if (!crnt->terminal && crnt->count > 1) return 0; return crnt->key; }
} // namespace args