forked from mirror/openmw-tes3mp
Make it work by realising that what boost::program_options calls validation is what any sane person would regard as parsing
This commit is contained in:
parent
195dd27780
commit
1a0642f1db
2 changed files with 11 additions and 32 deletions
|
@ -145,7 +145,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
"\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other 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")
|
"\n\twin1252 - Western European (Latin) alphabet, used by default")
|
||||||
|
|
||||||
("fallback", bpo::value<EscapeFallbackMap>()->default_value(EscapeFallbackMap(), "")
|
("fallback", bpo::value<FallbackMap>()->default_value(FallbackMap(), "")
|
||||||
->multitoken()->composing(), "fallback values")
|
->multitoken()->composing(), "fallback values")
|
||||||
|
|
||||||
("no-grab", "Don't grab mouse cursor")
|
("no-grab", "Don't grab mouse cursor")
|
||||||
|
@ -248,7 +248,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
|
|
||||||
// other settings
|
// other settings
|
||||||
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
||||||
engine.setFallbackValues(variables["fallback"].as<EscapeFallbackMap>().toFallbackMap().mMap);
|
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
|
||||||
engine.setActivationDistanceOverride (variables["activate-dist"].as<int>());
|
engine.setActivationDistanceOverride (variables["activate-dist"].as<int>());
|
||||||
engine.enableFontExport(variables["export-fonts"].as<bool>());
|
engine.enableFontExport(variables["export-fonts"].as<bool>());
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,6 @@ namespace Fallback
|
||||||
std::map<std::string, std::string> mMap;
|
std::map<std::string, std::string> mMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EscapeFallbackMap : FallbackMap
|
|
||||||
{
|
|
||||||
std::map<Files::EscapeHashString, Files::EscapeHashString> mMap;
|
|
||||||
|
|
||||||
FallbackMap toFallbackMap() const
|
|
||||||
{
|
|
||||||
FallbackMap temp = FallbackMap();
|
|
||||||
for (std::map<Files::EscapeHashString, Files::EscapeHashString>::const_iterator it = mMap.begin(); it != mMap.end(); ++it)
|
|
||||||
temp.mMap[it->first.toStdString()] = it->second.toStdString();
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
|
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
|
||||||
{
|
{
|
||||||
if (v.empty())
|
if (v.empty())
|
||||||
|
@ -40,16 +27,17 @@ namespace Fallback
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
|
for (std::vector<std::string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
|
||||||
{
|
{
|
||||||
int sep = it->find(",");
|
std::string temp = Files::EscapeHashString::processString(*it);
|
||||||
if (sep < 1 || sep == (int)it->length() - 1)
|
int sep = temp.find(",");
|
||||||
|
if (sep < 1 || sep == (int)temp.length() - 1)
|
||||||
#if (BOOST_VERSION < 104200)
|
#if (BOOST_VERSION < 104200)
|
||||||
throw boost::program_options::validation_error("invalid value");
|
throw boost::program_options::validation_error("invalid value");
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
std::string key(it->substr(0, sep));
|
std::string key(temp.substr(0, sep));
|
||||||
std::string value(it->substr(sep + 1));
|
std::string value(temp.substr(sep + 1));
|
||||||
|
|
||||||
if (map->mMap.find(key) == map->mMap.end())
|
if (map->mMap.find(key) == map->mMap.end())
|
||||||
{
|
{
|
||||||
|
@ -57,24 +45,15 @@ namespace Fallback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void validate(boost::any &v, std::vector<std::string> const &tokens, EscapeFallbackMap* eFM, int a)
|
|
||||||
{
|
|
||||||
validate(v, tokens, (FallbackMap *)eFM, a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Files {
|
namespace Files {
|
||||||
void validate(boost::any &v, const std::vector<std::string> &tokens, Files::EscapeHashString * eHS, int a)
|
void validate(boost::any &v, const std::vector<std::string> &tokens, Files::EscapeHashString * eHS, int a)
|
||||||
{
|
{
|
||||||
if (eHS == NULL)
|
boost::program_options::validators::check_first_occurrence(v);
|
||||||
boost::program_options::validate(v, tokens, (std::string *) NULL, a);
|
|
||||||
else
|
if (v.empty())
|
||||||
{
|
v = boost::any(EscapeHashString(boost::program_options::validators::get_single_string(tokens)));
|
||||||
std::string * temp = eHS->toStdStringPtr();
|
|
||||||
boost::program_options::validate(v, tokens, temp, a);
|
|
||||||
delete temp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue