mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 18:09:47 +01:00
Replace boost program_options
This commit is contained in:
parent
b1dc39df6e
commit
11588c639e
47
src/util.cpp
47
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user