Added --strict-validation command line option.

(Validation errors are treated as fatal)
This commit is contained in:
Sytyi Nick 2011-08-17 22:26:10 +00:00
parent 1ba5171b81
commit 8c74ce90d1
11 changed files with 37 additions and 9 deletions

View file

@ -188,6 +188,9 @@ sets the screen resolution. Example:
connects to the specified host if any, otherwise connect to the first server in preferences. Example:
.B --server server.wesnoth.org
.TP
.B --strict-validation
validation errors are treated as fatal errors.
.TP
.B -t, --test
runs the game in a small test scenario.
.TP

View file

@ -214,6 +214,7 @@ set(libwesnoth-core_STAT_SRC
serialization/preprocessor.cpp
serialization/string_utils.cpp
serialization/tokenizer.cpp
serialization/validator.cpp
${REVISION_FILE}
)
@ -811,13 +812,10 @@ set_target_properties(schema_generator PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}sc
install(TARGETS schema_generator DESTINATION ${BINDIR})
set_property(
SOURCE serialization/schema_validator.cpp
PROPERTY COMPILE_DEFINITIONS VALIDATION_ERRORS_LOG
)
set(schema_validator_SRC
tools/validator/validator_tool.cpp
serialization/schema_validator.cpp
serialization/validator.cpp
tools/schema/tag.cpp
filesystem.cpp
config_cache.cpp
@ -827,7 +825,8 @@ set(schema_validator_SRC
add_executable(schema_validator ${schema_validator_SRC})
target_link_libraries(schema_validator wesnoth-core ${common-external-libs})
set_target_properties(schema_validator PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}schema_validator${BINARY_SUFFIX})
set_target_properties(schema_validator PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}schema_validator${BINARY_SUFFIX}
COMPILE_DEFINITIONS VALIDATION_ERRORS_LOG)
install(TARGETS schema_validator DESTINATION ${BINDIR})

View file

@ -103,6 +103,7 @@ commandline_options::commandline_options ( int argc, char** argv ) :
screenshot_map_file(),
screenshot_output_file(),
smallgui(false),
strict_validation(false),
test(),
validcache(false),
version(false),
@ -141,6 +142,7 @@ commandline_options::commandline_options ( int argc, char** argv ) :
("rng-seed", po::value<unsigned int>(), "seeds the random number generator with number <arg>. Example: --rng-seed 0")
("screenshot", po::value<two_strings>()->multitoken(), "takes two arguments: <map> <output>. Saves a screenshot of <map> to <output> without initializing a screen. Editor must be compiled in for this to work.")
("server,s", po::value<std::string>()->implicit_value(std::string()), "connects to the host <arg> if specified or to the first host in your preferences.")
("strict-validation", "makes validation errors fatal")
("test,t", po::value<std::string>()->implicit_value(std::string()), "runs the game in a small test scenario. If specified, scenario <arg> will be used instead.")
("validcache", "assumes that the cache is valid. (dangerous)")
("version,v", "prints the game's version number and exits.")
@ -352,6 +354,8 @@ commandline_options::commandline_options ( int argc, char** argv ) :
multiplayer_turns = vm["turns"].as<std::string>();
if (vm.count("smallgui"))
smallgui = true;
if (vm.count("strict-validation"))
strict_validation = true;
if (vm.count("validcache"))
validcache = true;
if (vm.count("version"))

View file

@ -152,6 +152,8 @@ public:
boost::optional<std::string> screenshot_output_file;
/// True if --smallgui was given on the command line. Makes Wesnoth use small gui layout.
bool smallgui;
/// True if --strict-validation was given on the command line. Makes Wesnoth trust validation errors as fatal WML errors and create WML exception, if so.
bool strict_validation;
/// Non-empty if --test was given on the command line. Goes directly into test mode, into a scenario, if specified.
boost::optional<std::string> test;
/// True if --validcache was given on the command line. Makes Wesnoth assume the cache is valid.

View file

@ -32,6 +32,7 @@
#include "replay.hpp"
#include "statistics.hpp"
#include "serialization/parser.hpp"
#include "serialization/validator.hpp"
#include <cerrno>
#include <clocale>
@ -180,6 +181,9 @@ static int process_command_args(const commandline_options& cmdline_opts) {
static char opt[] = "SDL_VIDEODRIVER=dummy";
SDL_putenv(opt);
}
if(cmdline_opts.strict_validation) {
strict_validation_enabled = true;
}
if(cmdline_opts.version) {
std::cout << "Battle for Wesnoth" << " " << game_config::version << "\n";
return 0;

View file

@ -106,7 +106,7 @@ static void wrong_value_error(const std::string & file, int line,
schema_validator::schema_validator()
: config_read_(false)
, create_exceptions_(false)
, create_exceptions_(strict_validation_enabled)
, root_()
, stack_()
, counter_()
@ -121,7 +121,7 @@ schema_validator::~schema_validator(){}
schema_validator::schema_validator(const std::string & config_file_name)
: config_read_ (false)
, create_exceptions_(false)
, create_exceptions_(strict_validation_enabled)
, root_()
, stack_()
, counter_()

View file

@ -17,3 +17,4 @@
*/
#include "serialization/validator.hpp"
bool strict_validation_enabled = false;

View file

@ -26,13 +26,14 @@
class config;
extern bool strict_validation_enabled;
/**
* @class abstract_validator
* Used in parsing config file. @ref parser.cpp
* Contains virtual methods, which are called by parser
* and take information about config to be validated
*/
class abstract_validator
{
public:

View file

@ -253,6 +253,18 @@ void class_tag::printl(std::ostream &os,int level, int step){
return NULL;
}
// class_tag & class_tag::operator= (class_tag const& t){
// if (&t != this){
// name_ = t.name_;
// min_ = t.min_;
// max_ = t.max_;
// super_ = t.super_;
// tags_ = t.tags_;
// keys_ = t.keys_;
// links_ = t.links_;
// }
// return *this;
// }
void class_tag::add_tag(const std::string &path, const class_tag &tag,
class_tag &root){

View file

@ -156,6 +156,7 @@ public:
, links_()
{
}
class_tag(const std::string & name,
int min,
int max,
@ -288,6 +289,8 @@ public:
/** Removes all keys with this type. Works recursively */
void remove_keys_by_type(const std::string &type);
// class_tag & operator= (class_tag const& );
private:
/** name of tag*/
std::string name_;

View file

@ -60,7 +60,6 @@ int main(int argc, char *argv[]){
}
}
schema_validator validator (default_schema);
//Now you can only test, how it read schema file
if (input.empty()) input = "./data/gui/default.cfg";
std::cout << "Processing "<< input <<"\n";
config cfg;