aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorChun Kuan Lee <ken2812221@gmail.com>2018-06-16 02:31:26 +0000
committerChun Kuan Lee <ken2812221@gmail.com>2018-07-18 02:48:25 +0000
commit11588c639e8912f1b28e981c1a2a0e4306dbd093 (patch)
treec70628a0f9244e46e7d4c4f57213cb557ef943f9 /src/util.cpp
parentb1dc39df6ec878d06fc7217a3d7bf07397edf3ea (diff)
downloadbitcoin-11588c639e8912f1b28e981c1a2a0e4306dbd093.tar.xz
Replace boost program_options
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/util.cpp b/src/util.cpp
index ab262b4063..97b5205abf 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -72,7 +72,6 @@
#endif
#include <boost/interprocess/sync/file_lock.hpp>
-#include <boost/program_options/detail/config_file.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
@@ -811,17 +810,47 @@ fs::path GetConfigFile(const std::string& confPath)
return AbsPathForConfigVal(fs::path(confPath), false);
}
+static std::string TrimString(const std::string& str, const std::string& pattern)
+{
+ std::string::size_type front = str.find_first_not_of(pattern);
+ if (front == std::string::npos) {
+ return std::string();
+ }
+ std::string::size_type end = str.find_last_not_of(pattern);
+ return str.substr(front, end - front + 1);
+}
+
+static std::vector<std::pair<std::string, std::string>> GetConfigOptions(std::istream& stream)
+{
+ std::vector<std::pair<std::string, std::string>> options;
+ std::string str, prefix;
+ std::string::size_type pos;
+ while (std::getline(stream, str)) {
+ if ((pos = str.find('#')) != std::string::npos) {
+ str = str.substr(0, pos);
+ }
+ const static std::string pattern = " \t\r\n";
+ str = TrimString(str, pattern);
+ if (!str.empty()) {
+ if (*str.begin() == '[' && *str.rbegin() == ']') {
+ prefix = str.substr(1, str.size() - 2) + '.';
+ } else if ((pos = str.find('=')) != std::string::npos) {
+ std::string name = prefix + TrimString(str.substr(0, pos), pattern);
+ std::string value = TrimString(str.substr(pos + 1), pattern);
+ options.emplace_back(name, value);
+ }
+ }
+ }
+ return options;
+}
+
bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, bool ignore_invalid_keys)
{
LOCK(cs_args);
- std::set<std::string> setOptions;
- setOptions.insert("*");
-
- for (boost::program_options::detail::config_file_iterator it(stream, setOptions), end; it != end; ++it)
- {
- std::string strKey = std::string("-") + it->string_key;
- std::string strValue = it->value[0];
+ for (const std::pair<std::string, std::string>& option : GetConfigOptions(stream)) {
+ std::string strKey = std::string("-") + option.first;
+ std::string strValue = option.second;
if (InterpretNegatedOption(strKey, strValue)) {
m_config_args[strKey].clear();
@@ -831,7 +860,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
// Check that the arg is known
if (!IsArgKnown(strKey, error) && !ignore_invalid_keys) {
- error = strprintf("Invalid configuration value %s", it->string_key.c_str());
+ error = strprintf("Invalid configuration value %s", option.first.c_str());
return false;
}
}