The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
validator_tool.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 by Sytyi Nick <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
17 std::string version = "0.2.0";
18 
19 #include <iostream>
20 
21 #include "filesystem.hpp"
22 #include "serialization/parser.hpp"
24 #include "config.hpp"
25 #include "config_cache.hpp"
26 
27 using namespace schema_validation;
28 int main(int argc, char *argv[]){
29  std::string default_schema ("data/gui/schema.cfg");
31  for (int arg = 1; arg != argc; ++arg) {
32  const std::string val(argv[arg]);
33  if (val.empty()) {
34  continue;
35  }
36  else if ((val == "--schema" || val == "-s") && arg+1 != argc) {
37  default_schema = argv[++arg];
38  }
39  else if ((val == "--input" || val == "-i") && arg+1 != argc) {
40  input = argv[++arg];
41  }
42  else if (val == "--help" || val == "-h") {
43  std::cout << "usage: " << argv[0]
44  << " [-hV] [-i <input_file>] [-s <schema_file>]\n"
45  << " -h, --help\t\t\t"
46  << "Shows this usage message.\n"
47  << " -s, --schema <schema_file>\t"
48  <<"Select the file with schema information.\n"
49  << " -i, --input <input_file>\t"
50  <<"Select the config file.\n"
51  << " -V, --version\t\t\t"
52  << "Version of tool\n";
53  return 0;
54  } else if (val == "--version" || val == "-V") {
55  std::cout << "Battle for Wesnoth schema validator tool, version "
56  << version << "\n";
57  return 0;
58  }
59  }
60  schema_validator validator (default_schema);
61  if (input.empty()) input = "./data/gui/default.cfg";
62  std::cout << "Processing "<< input <<"\n";
63  config cfg;
64  try {
65  preproc_map preproc(
66  game_config::config_cache::instance().get_preproc_map());
68  &preproc);
69  read(cfg, *stream, &validator);
70  } catch(config::error & t) {
71  std::cout << t.message;
72  return 1;
73  }
74  return 0;
75 }
static config_cache & instance()
Get reference to the singleton object.
GLenum GLenum GLenum input
Definition: glew.h:10668
GLuint const GLfloat * val
Definition: glew.h:2614
GLdouble GLdouble t
Definition: glew.h:1366
Definitions for the interface to Wesnoth Markup Language (WML).
std::map< std::string, preproc_define > preproc_map
GLuint GLuint stream
Definition: glew.h:5239
One of the realizations of serialization/validator.hpp abstract validator.
int main(int argc, char *argv[])
std::string version
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:400
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
std::string message
Definition: exceptions.hpp:29
Realization of serialization/validator.hpp abstract validator.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503