diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15a91ca60eb..7007684d296 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -542,6 +542,7 @@ set(wesnoth-main_SRC savegame.cpp savegame_config.cpp scripting/lua.cpp + serialization/schema_validator.cpp settings.cpp sha1.cpp side_filter.cpp @@ -555,6 +556,7 @@ set(wesnoth-main_SRC terrain_filter.cpp tod_manager.cpp tooltips.cpp + tools/schema/tag.cpp unit.cpp unit_abilities.cpp unit_animation.cpp @@ -808,6 +810,27 @@ target_link_libraries(schema_generator wesnoth-core ${tools-external-libs} ${Boo set_target_properties(schema_generator PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}schema_generator${BINARY_SUFFIX}) 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 + tools/schema/tag.cpp + filesystem.cpp + config_cache.cpp + sha1.cpp + loadscreen_empty.cpp +) + +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}) + +install(TARGETS schema_validator DESTINATION ${BINDIR}) + endif(ENABLE_TOOLS) ########### Unit tests ############### diff --git a/src/tools/validator/validator_tool.cpp b/src/tools/validator/validator_tool.cpp new file mode 100644 index 00000000000..2acd8d1bacf --- /dev/null +++ b/src/tools/validator/validator_tool.cpp @@ -0,0 +1,82 @@ +/* $Id$ */ +/* + Copyright (C) 2011 - 2011 by Sytyi Nick + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#include "serialization/schema_validator.hpp" + +std::string version = "0.2.0"; + +#include + +#include "filesystem.hpp" +#include "foreach.hpp" +#include "serialization/parser.hpp" +#include "serialization/preprocessor.hpp" +#include "config.hpp" +#include "config_cache.hpp" + +using namespace schema_validation; +int main(int argc, char *argv[]){ + std::string default_schema ("data/gui/schema.cfg"); + std::string input ; + bool test = false; + for (int arg = 1; arg != argc; ++arg) { + const std::string val(argv[arg]); + if (val.empty()) { + continue; + } + else if ((val == "--schema" || val == "-s") && arg+1 != argc) { + default_schema = argv[++arg]; + } + else if ((val == "--input" || val == "-i") && arg+1 != argc) { + input = argv[++arg]; + } + else if (val == "--test" || val == "-t") { + test = true; + } + else if (val == "--help" || val == "-h") { + std::cout << "usage: " << argv[0] + << " [-hV] [-s ] ]\n" + << " -h, --help\t\t\t" + << "Shows this usage message.\n" + << " -s, --schema \t" + <<"Select the file with schema information.\n" + << " -i, --input \t" + <<"Select the config file.\n" + << " -V, --version\t\t\t" + << "Version of tool\n"; + return 0; + } else if (val == "--version" || val == "-V") { + std::cout << "Battle for Wesnoth schema validator tool, version " + << version << "\n"; + return 0; + } + } + 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; + try { + preproc_map preproc( + game_config::config_cache::instance().get_preproc_map()); + scoped_istream stream = preprocess_file(input, + &preproc); + read(cfg, *stream, &validator); + } catch(config::error & t) { + std::cout << t.message; + return 1; + } + return 0; +}