Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "serialization/schema_validator.hpp"
00017
00018 std::string version = "0.2.0";
00019
00020 #include <iostream>
00021
00022 #include "filesystem.hpp"
00023 #include "foreach.hpp"
00024 #include "serialization/parser.hpp"
00025 #include "serialization/preprocessor.hpp"
00026 #include "config.hpp"
00027 #include "config_cache.hpp"
00028
00029 using namespace schema_validation;
00030 int main(int argc, char *argv[]){
00031 std::string default_schema ("data/gui/schema.cfg");
00032 std::string input ;
00033 for (int arg = 1; arg != argc; ++arg) {
00034 const std::string val(argv[arg]);
00035 if (val.empty()) {
00036 continue;
00037 }
00038 else if ((val == "--schema" || val == "-s") && arg+1 != argc) {
00039 default_schema = argv[++arg];
00040 }
00041 else if ((val == "--input" || val == "-i") && arg+1 != argc) {
00042 input = argv[++arg];
00043 }
00044 else if (val == "--help" || val == "-h") {
00045 std::cout << "usage: " << argv[0]
00046 << " [-hV] [-i <input_file>] [-s <schema_file>]\n"
00047 << " -h, --help\t\t\t"
00048 << "Shows this usage message.\n"
00049 << " -s, --schema <schema_file>\t"
00050 <<"Select the file with schema information.\n"
00051 << " -i, --input <input_file>\t"
00052 <<"Select the config file.\n"
00053 << " -V, --version\t\t\t"
00054 << "Version of tool\n";
00055 return 0;
00056 } else if (val == "--version" || val == "-V") {
00057 std::cout << "Battle for Wesnoth schema validator tool, version "
00058 << version << "\n";
00059 return 0;
00060 }
00061 }
00062 schema_validator validator (default_schema);
00063 if (input.empty()) input = "./data/gui/default.cfg";
00064 std::cout << "Processing "<< input <<"\n";
00065 config cfg;
00066 try {
00067 preproc_map preproc(
00068 game_config::config_cache::instance().get_preproc_map());
00069 scoped_istream stream = preprocess_file(input,
00070 &preproc);
00071 read(cfg, *stream, &validator);
00072 } catch(config::error & t) {
00073 std::cout << t.message;
00074 return 1;
00075 }
00076 return 0;
00077 }