aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-02 04:19:08 +0000
committer_ov4 <ov4@ov4.org>2026-09-02 04:19:08 +0000
commitfc7eec4af8c35012effdb62992adc9b49b869c28 (patch)
tree8949790dbc7033f189304d4b594cab5226f6f888 /src/util
parent7d44fcb22f8c3817627815322e57dda893f3cab4 (diff)
better option sys
Diffstat (limited to 'src/util')
-rw-r--r--src/util/option_parse.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/util/option_parse.cc b/src/util/option_parse.cc
new file mode 100644
index 0000000..f9185fb
--- /dev/null
+++ b/src/util/option_parse.cc
@@ -0,0 +1,52 @@
+#include "util/option_parse.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <unordered_map>
+#include <functional>
+#include <utility>
+
+#include "all.h"
+
+using namespace std;
+
+const char option_key_value_split = '=';
+constexpr char option_prefix = '-';
+
+namespace ov4
+{
+
+void exe_option(char **c_argv)
+{
+ vector<string> argv;
+ argv2string(&argv, c_argv);
+
+ for (auto c : argv)
+ {
+ pair<string, string> key_value = option_split(c);
+ if (key_value.first != "")
+ {
+ if (option_list.find(key_value.first) == option_list.end())
+ {
+ cerr << key_value.first << ": option not fund" << endl;
+ continue;
+ }
+ option_list.at(key_value.first)(key_value.second);
+ }
+ }
+}
+
+pair<string, string> option_split(string s)
+{
+ if (s.size() == 0) return make_pair("", "");
+ if (s[0] != option_prefix) return make_pair("", "");
+ size_t pos = s.find(option_key_value_split);
+ if (pos == string::npos) return make_pair(s, "");
+ if (pos == s.size()+1) return make_pair(s.substr(0, pos), "");
+ string key = s.substr(0, pos);
+ string value = s.substr(pos+1);
+ return make_pair(key, value);
+}
+
+}