From 6ccb5835ff55d85156be91473c598eca9d6cb9a6 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 4 Nov 2020 16:57:41 +0100 Subject: Revert "Make Lint Happy" This reverts commit ad148587dcf5244c2d2011dba339786c765c54c4. --- src/settings.cpp | 237 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 153 insertions(+), 84 deletions(-) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index 4f8b7b617..55404319e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -42,14 +42,16 @@ Settings::~Settings() clear(); } -Settings &Settings::operator+=(const Settings &other) + +Settings & Settings::operator += (const Settings &other) { update(other); return *this; } -Settings &Settings::operator=(const Settings &other) + +Settings & Settings::operator = (const Settings &other) { if (&other == this) return *this; @@ -63,6 +65,7 @@ Settings &Settings::operator=(const Settings &other) return *this; } + bool Settings::checkNameValid(const std::string &name) { bool valid = name.find_first_of("=\"{}#") == std::string::npos; @@ -70,19 +73,20 @@ bool Settings::checkNameValid(const std::string &name) valid = std::find_if(name.begin(), name.end(), ::isspace) == name.end(); if (!valid) { - errorstream << "Invalid setting name \"" << name << "\"" << std::endl; + errorstream << "Invalid setting name \"" << name << "\"" + << std::endl; return false; } return true; } + bool Settings::checkValueValid(const std::string &value) { if (value.substr(0, 3) == "\"\"\"" || - value.find("\n\"\"\"") != std::string::npos) { + value.find("\n\"\"\"") != std::string::npos) { errorstream << "Invalid character sequence '\"\"\"' found in" - " setting value!" - << std::endl; + " setting value!" << std::endl; return false; } return true; @@ -113,6 +117,7 @@ std::string Settings::getMultiline(std::istream &is, size_t *num_lines) return value; } + bool Settings::readConfigFile(const char *filename) { std::ifstream is(filename); @@ -122,6 +127,7 @@ bool Settings::readConfigFile(const char *filename) return parseConfigLines(is, ""); } + bool Settings::parseConfigLines(std::istream &is, const std::string &end) { MutexAutoLock lock(m_mutex); @@ -160,6 +166,7 @@ bool Settings::parseConfigLines(std::istream &is, const std::string &end) return end.empty(); } + void Settings::writeLines(std::ostream &os, u32 tab_depth) const { MutexAutoLock lock(m_mutex); @@ -168,8 +175,9 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const printEntry(os, setting_it.first, setting_it.second, tab_depth); } + void Settings::printEntry(std::ostream &os, const std::string &name, - const SettingsEntry &entry, u32 tab_depth) + const SettingsEntry &entry, u32 tab_depth) { for (u32 i = 0; i != tab_depth; i++) os << "\t"; @@ -192,8 +200,9 @@ void Settings::printEntry(std::ostream &os, const std::string &name, } } -bool Settings::updateConfigObject( - std::istream &is, std::ostream &os, const std::string &end, u32 tab_depth) + +bool Settings::updateConfigObject(std::istream &is, std::ostream &os, + const std::string &end, u32 tab_depth) { SettingEntries::const_iterator it; std::set present_entries; @@ -218,8 +227,7 @@ bool Settings::updateConfigObject( case SPE_KVPAIR: it = m_settings.find(name); if (it != m_settings.end() && - (it->second.is_group || - it->second.value != value)) { + (it->second.is_group || it->second.value != value)) { printEntry(os, name, it->second, tab_depth); was_modified = true; } else if (it == m_settings.end()) { @@ -238,15 +246,14 @@ bool Settings::updateConfigObject( if (it != m_settings.end() && it->second.is_group) { os << line << "\n"; sanity_check(it->second.group != NULL); - was_modified |= it->second.group->updateConfigObject( - is, os, "}", tab_depth + 1); + was_modified |= it->second.group->updateConfigObject(is, os, + "}", tab_depth + 1); } else if (it == m_settings.end()) { // Remove by skipping was_modified = true; Settings removed_group; // Move 'is' to group end std::stringstream ss; - removed_group.updateConfigObject( - is, ss, "}", tab_depth + 1); + removed_group.updateConfigObject(is, ss, "}", tab_depth + 1); break; } else { printEntry(os, name, it->second, tab_depth); @@ -272,6 +279,7 @@ bool Settings::updateConfigObject( return was_modified; } + bool Settings::updateConfigFile(const char *filename) { MutexAutoLock lock(m_mutex); @@ -286,31 +294,32 @@ bool Settings::updateConfigFile(const char *filename) return true; if (!fs::safeWriteToFile(filename, os.str())) { - errorstream << "Error writing configuration file: \"" << filename << "\"" - << std::endl; + errorstream << "Error writing configuration file: \"" + << filename << "\"" << std::endl; return false; } return true; } -bool Settings::parseCommandLine( - int argc, char *argv[], std::map &allowed_options) + +bool Settings::parseCommandLine(int argc, char *argv[], + std::map &allowed_options) { int nonopt_index = 0; for (int i = 1; i < argc; i++) { std::string arg_name = argv[i]; if (arg_name.substr(0, 2) != "--") { // If option doesn't start with -, read it in as nonoptX - if (arg_name[0] != '-') { + if (arg_name[0] != '-'){ std::string name = "nonopt"; name += itos(nonopt_index); set(name, arg_name); nonopt_index++; continue; } - errorstream << "Invalid command-line parameter \"" << arg_name - << "\": --