aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/util.cpp b/src/util.cpp
index ab262b4063..2f81f50a71 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>
@@ -447,7 +446,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
// Check that the arg is known
if (!(IsSwitchChar(key[0]) && key.size() == 1)) {
- if (!IsArgKnown(key, error)) {
+ if (!IsArgKnown(key)) {
error = strprintf("Invalid parameter %s", key.c_str());
return false;
}
@@ -467,7 +466,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
return true;
}
-bool ArgsManager::IsArgKnown(const std::string& key, std::string& error)
+bool ArgsManager::IsArgKnown(const std::string& key) const
{
size_t option_index = key.find('.');
std::string arg_no_net;
@@ -592,7 +591,7 @@ void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
}
}
-std::string ArgsManager::GetHelpMessage()
+std::string ArgsManager::GetHelpMessage() const
{
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
@@ -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();
@@ -830,8 +859,8 @@ 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());
+ if (!IsArgKnown(strKey) && !ignore_invalid_keys) {
+ error = strprintf("Invalid configuration value %s", option.first.c_str());
return false;
}
}
@@ -992,7 +1021,7 @@ bool FileCommit(FILE *file)
LogPrintf("%s: fdatasync failed: %d\n", __func__, errno);
return false;
}
- #elif defined(__APPLE__) && defined(F_FULLFSYNC)
+ #elif defined(MAC_OSX) && defined(F_FULLFSYNC)
if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success
LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
return false;