tools/validator/validator_tool.cpp

Go to the documentation of this file.
00001 /* $Id: validator_tool.cpp 53847 2012-04-08 00:50:12Z ejls $ */
00002 /*
00003    Copyright (C) 2011 - 2012 by Sytyi Nick <nsytyi@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:13 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs