diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index e57ff867c..e96b6e595 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -69,8 +69,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat { // Create a local alias for brevity namespace bpo = boost::program_options; - typedef std::vector EscapeStringsVector; - typedef std::vector StringsVector; + typedef std::vector EscapeStringsVector; + typedef std::vector StringsVector; bpo::options_description desc("Syntax: openmw \nAllowed options"); @@ -80,16 +80,16 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("data", bpo::value()->default_value(Files::PathContainer(), "data") ->multitoken()->composing(), "set data directories (later directories have higher priority)") - ("data-local", bpo::value()->default_value(""), + ("data-local", bpo::value()->default_value(""), "set local data directory (highest priority)") ("fallback-archive", bpo::value()->default_value(EscapeStringsVector(), "fallback-archive") ->multitoken(), "set fallback BSA archives (later archives have higher priority)") - ("resources", bpo::value()->default_value("resources"), + ("resources", bpo::value()->default_value("resources"), "set resources directory") - ("start", bpo::value()->default_value(""), + ("start", bpo::value()->default_value(""), "set initial cell") ("content", bpo::value()->default_value(EscapeStringsVector(), "") @@ -110,7 +110,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("script-console", bpo::value()->implicit_value(true) ->default_value(false), "enable console-only script functionality") - ("script-run", bpo::value()->default_value(""), + ("script-run", bpo::value()->default_value(""), "select a file containing a list of console commands that is executed on startup") ("script-warn", bpo::value()->implicit_value (1) @@ -126,7 +126,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("script-blacklist-use", bpo::value()->implicit_value(true) ->default_value(true), "enable script blacklisting") - ("load-savegame", bpo::value()->default_value(""), + ("load-savegame", bpo::value()->default_value(""), "load a save game file on game startup (specify an absolute filename or a filename relative to the current working directory)") ("skip-menu", bpo::value()->implicit_value(true) @@ -138,14 +138,14 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("fs-strict", bpo::value()->implicit_value(true) ->default_value(false), "strict file system handling (no case folding)") - ("encoding", bpo::value()-> + ("encoding", bpo::value()-> default_value("win1252"), "Character encoding used in OpenMW game messages:\n" "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" "\n\twin1252 - Western European (Latin) alphabet, used by default") - ("fallback", bpo::value()->default_value(FallbackMap(), "") + ("fallback", bpo::value()->default_value(FallbackMap(), "") ->multitoken()->composing(), "fallback values") ("no-grab", "Don't grab mouse cursor") @@ -215,7 +215,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setResourceDir(variables["resources"].as().toStdString()); - StringsVector content = Files::EscapeHashString::toStdStringVector(variables["content"].as()); + StringsVector content = Files::EscapeHashString::toStdStringVector(variables["content"].as()); if (content.empty()) { std::cout << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting..." << std::endl; @@ -248,7 +248,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat // other settings engine.setSoundUsage(!variables["no-sound"].as()); - engine.setFallbackValues(variables["fallback"].as().mMap); + engine.setFallbackValues(variables["fallback"].as().mMap); engine.setActivationDistanceOverride (variables["activate-dist"].as()); engine.enableFontExport(variables["export-fonts"].as()); diff --git a/components/fallback/validate.hpp b/components/fallback/validate.hpp index fe545ce4b..e609297ae 100644 --- a/components/fallback/validate.hpp +++ b/components/fallback/validate.hpp @@ -12,49 +12,49 @@ namespace Fallback { - struct FallbackMap { - std::map mMap; - }; - - void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int) - { - if (v.empty()) - { - v = boost::any(FallbackMap()); - } - - FallbackMap *map = boost::any_cast(&v); - - for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) - { - std::string temp = Files::EscapeHashString::processString(*it); - int sep = temp.find(","); - if (sep < 1 || sep == (int)temp.length() - 1) + struct FallbackMap { + std::map mMap; + }; + + void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int) + { + if (v.empty()) + { + v = boost::any(FallbackMap()); + } + + FallbackMap *map = boost::any_cast(&v); + + for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) + { + std::string temp = Files::EscapeHashString::processString(*it); + int sep = temp.find(","); + if (sep < 1 || sep == (int)temp.length() - 1) #if (BOOST_VERSION < 104200) - throw boost::program_options::validation_error("invalid value"); + throw boost::program_options::validation_error("invalid value"); #else - throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); #endif - std::string key(temp.substr(0, sep)); - std::string value(temp.substr(sep + 1)); + std::string key(temp.substr(0, sep)); + std::string value(temp.substr(sep + 1)); - if (map->mMap.find(key) == map->mMap.end()) - { - map->mMap.insert(std::make_pair(key, value)); - } - } - } + if (map->mMap.find(key) == map->mMap.end()) + { + map->mMap.insert(std::make_pair(key, value)); + } + } + } } namespace Files { - void validate(boost::any &v, const std::vector &tokens, Files::EscapeHashString * eHS, int a) - { - boost::program_options::validators::check_first_occurrence(v); - - if (v.empty()) - v = boost::any(EscapeHashString(boost::program_options::validators::get_single_string(tokens))); - } + void validate(boost::any &v, const std::vector &tokens, Files::EscapeHashString * eHS, int a) + { + boost::program_options::validators::check_first_occurrence(v); + + if (v.empty()) + v = boost::any(EscapeHashString(boost::program_options::validators::get_single_string(tokens))); + } } #endif diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 46775a7fb..511dbe411 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -142,9 +142,9 @@ bool ConfigurationManager::loadConfig(const boost::filesystem::path& path, std::cout << "Loading config file: " << cfgFile.string() << "... "; boost::filesystem::ifstream configFileStreamUnfiltered(cfgFile); - boost::iostreams::filtering_istream configFileStream; - configFileStream.push(escape_hash_filter()); - configFileStream.push(configFileStreamUnfiltered); + boost::iostreams::filtering_istream configFileStream; + configFileStream.push(escape_hash_filter()); + configFileStream.push(configFileStreamUnfiltered); if (configFileStreamUnfiltered.is_open()) { boost::program_options::store(boost::program_options::parse_config_file( @@ -179,80 +179,80 @@ escape_hash_filter::~escape_hash_filter() template int escape_hash_filter::get(Source & src) { - if (mNext.empty()) - { - int character = boost::iostreams::get(src); - bool record = true; - if (character == boost::iostreams::WOULD_BLOCK) - { - mNext.push(character); - record = false; - } - else if (character == EOF) - { - mSeenNonWhitespace = false; - mFinishLine = false; - mNext.push(character); - } - else if (character == '\n') - { - mSeenNonWhitespace = false; - mFinishLine = false; - mNext.push(character); - } - else if (mFinishLine) - { - mNext.push(character); - } - else if (character == '#') - { - if (mSeenNonWhitespace) - { - mNext.push(sEscape); - mNext.push(sHashIdentifier); - } - else - { - //it's fine being interpreted by Boost as a comment, and so is anything afterwards - mNext.push(character); - mFinishLine = true; - } - } - else if (mPrevious == sEscape) - { - mNext.push(sEscape); - mNext.push(sEscapeIdentifier); - } - else - { - mNext.push(character); - } - if (!mSeenNonWhitespace && !isspace(character)) - mSeenNonWhitespace = true; - if (record) - mPrevious = character; - } - int retval = mNext.front(); - mNext.pop(); - return retval; + if (mNext.empty()) + { + int character = boost::iostreams::get(src); + bool record = true; + if (character == boost::iostreams::WOULD_BLOCK) + { + mNext.push(character); + record = false; + } + else if (character == EOF) + { + mSeenNonWhitespace = false; + mFinishLine = false; + mNext.push(character); + } + else if (character == '\n') + { + mSeenNonWhitespace = false; + mFinishLine = false; + mNext.push(character); + } + else if (mFinishLine) + { + mNext.push(character); + } + else if (character == '#') + { + if (mSeenNonWhitespace) + { + mNext.push(sEscape); + mNext.push(sHashIdentifier); + } + else + { + //it's fine being interpreted by Boost as a comment, and so is anything afterwards + mNext.push(character); + mFinishLine = true; + } + } + else if (mPrevious == sEscape) + { + mNext.push(sEscape); + mNext.push(sEscapeIdentifier); + } + else + { + mNext.push(character); + } + if (!mSeenNonWhitespace && !isspace(character)) + mSeenNonWhitespace = true; + if (record) + mPrevious = character; + } + int retval = mNext.front(); + mNext.pop(); + return retval; } std::string EscapeHashString::processString(const std::string & str) { - std::string temp = boost::replace_all_copy(str, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sHashIdentifier, "#"); - boost::replace_all(temp, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sEscapeIdentifier, std::string((char) escape_hash_filter::sEscape, 1)); - return temp; + std::string temp = boost::replace_all_copy(str, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sHashIdentifier, "#"); + boost::replace_all(temp, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sEscapeIdentifier, std::string((char) escape_hash_filter::sEscape, 1)); + return temp; } std::vector EscapeHashString::toStdStringVector(const std::vector & vec) { - std::vector temp = std::vector(); - for (std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) - { - temp.push_back(it->toStdString()); - } - return temp; + std::vector temp = std::vector(); + for (std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) + { + temp.push_back(it->toStdString()); + } + return temp; } EscapeHashString::EscapeHashString() : mData() @@ -286,12 +286,12 @@ EscapeHashString::EscapeHashString(InputIterator first, InputIterator last) : mD std::string EscapeHashString::toStdString() const { - return std::string(mData); + return std::string(mData); } std::string * EscapeHashString::toStdStringPtr() const { - return new std::string(mData); + return new std::string(mData); } const boost::filesystem::path& ConfigurationManager::getGlobalPath() const diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 6e1cfbdb1..5138b3ca7 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -71,21 +71,21 @@ struct ConfigurationManager */ struct escape_hash_filter : public boost::iostreams::input_filter { - static const int sEscape; - static const int sHashIdentifier; - static const int sEscapeIdentifier; + static const int sEscape; + static const int sHashIdentifier; + static const int sEscapeIdentifier; - escape_hash_filter(); - virtual ~escape_hash_filter(); + escape_hash_filter(); + virtual ~escape_hash_filter(); - template int get(Source & src); + template int get(Source & src); - private: - std::queue mNext; - int mPrevious; + private: + std::queue mNext; + int mPrevious; - bool mSeenNonWhitespace; - bool mFinishLine; + bool mSeenNonWhitespace; + bool mFinishLine; }; /** @@ -93,23 +93,23 @@ struct escape_hash_filter : public boost::iostreams::input_filter */ class EscapeHashString : public std::string { - private: - std::string mData; - public: - static std::string processString(const std::string & str); - static std::vector toStdStringVector(const std::vector & vec); - - EscapeHashString(); - EscapeHashString(const std::string & str); - EscapeHashString(const std::string & str, size_t pos, size_t len = std::string::npos); - EscapeHashString(const char * s); - EscapeHashString(const char * s, size_t n); - EscapeHashString(size_t n, char c); - template - EscapeHashString(InputIterator first, InputIterator last); - - std::string toStdString() const; - std::string * toStdStringPtr() const; + private: + std::string mData; + public: + static std::string processString(const std::string & str); + static std::vector toStdStringVector(const std::vector & vec); + + EscapeHashString(); + EscapeHashString(const std::string & str); + EscapeHashString(const std::string & str, size_t pos, size_t len = std::string::npos); + EscapeHashString(const char * s); + EscapeHashString(const char * s, size_t n); + EscapeHashString(size_t n, char c); + template + EscapeHashString(InputIterator first, InputIterator last); + + std::string toStdString() const; + std::string * toStdStringPtr() const; }; } /* namespace Cfg */