From a175314c3e5827eb193872241446f2f8f5c9d33c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 20:07:14 +0200 Subject: Adding upstream version 1:10.5.12. Signed-off-by: Daniel Baumann --- plugin/handler_socket/libhsclient/config.cpp | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 plugin/handler_socket/libhsclient/config.cpp (limited to 'plugin/handler_socket/libhsclient/config.cpp') diff --git a/plugin/handler_socket/libhsclient/config.cpp b/plugin/handler_socket/libhsclient/config.cpp new file mode 100644 index 00000000..3c90b36d --- /dev/null +++ b/plugin/handler_socket/libhsclient/config.cpp @@ -0,0 +1,67 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#include +#include +#include + +#include "config.hpp" + +namespace dena { + +unsigned int verbose_level = 0; + +std::string +config::get_str(const std::string& key, const std::string& def) const +{ + const_iterator iter = this->find(key); + if (iter == this->end()) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key.c_str(), + def.c_str())); + return def; + } + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", key.c_str(), + iter->second.c_str())); + return iter->second; +} + +long long +config::get_int(const std::string& key, long long def) const +{ + const_iterator iter = this->find(key); + if (iter == this->end()) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key.c_str(), + def)); + return def; + } + const long long r = atoll(iter->second.c_str()); + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key.c_str(), r)); + return r; +} + +void +parse_args(int argc, char **argv, config& conf) +{ + for (int i = 1; i < argc; ++i) { + const char *const arg = argv[i]; + const char *const eq = strchr(arg, '='); + if (eq == 0) { + continue; + } + const std::string key(arg, eq - arg); + const std::string val(eq + 1); + conf[key] = val; + } + config::const_iterator iter = conf.find("verbose"); + if (iter != conf.end()) { + verbose_level = atoi(iter->second.c_str()); + } +} + +}; + -- cgit v1.2.3