[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp serialization/binary_or_te...
From: |
Philippe Plantier |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp serialization/binary_or_te... |
Date: |
Mon, 18 Apr 2005 16:51:23 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Philippe Plantier <address@hidden> 05/04/18 20:51:22
Modified files:
src : game.cpp
src/serialization: binary_or_text.cpp parser.cpp parser.hpp
preprocessor.cpp preprocessor.hpp
Log message:
Reverting silene's last changes to the preprocessor to allow releasing.
Those
will be restored after release.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.232&tr2=1.233&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_or_text.cpp.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/parser.cpp.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/parser.hpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/preprocessor.cpp.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/preprocessor.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.232 wesnoth/src/game.cpp:1.233
--- wesnoth/src/game.cpp:1.232 Mon Apr 18 19:25:04 2005
+++ wesnoth/src/game.cpp Mon Apr 18 20:51:22 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.232 2005/04/18 19:25:04 gruikya Exp $ */
+/* $Id: game.cpp,v 1.233 2005/04/18 20:51:22 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1383,7 +1383,7 @@
scoped_istream stream =
preprocess_file("data/game.cfg", &defines);
std::string error_log;
- read(cfg, *stream, &error_log);
+ read(cfg, *stream, NULL, &error_log);
if(!error_log.empty()) {
gui::show_error_message(disp(),
_("Warning: Errors
occurred while loading game configuration files: '") +
Index: wesnoth/src/serialization/binary_or_text.cpp
diff -u wesnoth/src/serialization/binary_or_text.cpp:1.9
wesnoth/src/serialization/binary_or_text.cpp:1.10
--- wesnoth/src/serialization/binary_or_text.cpp:1.9 Mon Apr 11 18:39:25 2005
+++ wesnoth/src/serialization/binary_or_text.cpp Mon Apr 18 20:51:22 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_or_text.cpp,v 1.9 2005/04/11 18:39:25 silene Exp $ */
+/* $Id: binary_or_text.cpp,v 1.10 2005/04/18 20:51:22 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -26,7 +26,7 @@
read_compressed(cfg, in);
return true;
} else {
- read(cfg, in, error_log);
+ read(cfg, in, NULL, error_log);
return false;
}
}
Index: wesnoth/src/serialization/parser.cpp
diff -u wesnoth/src/serialization/parser.cpp:1.14
wesnoth/src/serialization/parser.cpp:1.15
--- wesnoth/src/serialization/parser.cpp:1.14 Mon Apr 11 18:39:25 2005
+++ wesnoth/src/serialization/parser.cpp Mon Apr 18 20:51:22 2005
@@ -1,4 +1,4 @@
-/* $Id: parser.cpp,v 1.14 2005/04/11 18:39:25 silene Exp $ */
+/* $Id: parser.cpp,v 1.15 2005/04/18 20:51:22 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -38,12 +38,26 @@
static const size_t max_recursion_levels = 100;
+line_source get_line_source(std::vector< line_source > const &line_src, int
line)
+{
+ line_source res(line, "", 0);
+ std::vector< line_source >::const_iterator it =
+ std::upper_bound(line_src.begin(), line_src.end(), res);
+ if (it != line_src.begin()) {
+ --it;
+ res.file = it->file;
+ res.fileline = it->fileline + (line - it->linenum);
+ }
+
+ return res;
+}
+
namespace {
class parser
{
public:
- parser(config& cfg, std::istream& in);
+ parser(config& cfg, std::istream& in, std::vector<line_source> const*
line_sources);
void operator() (std::string* error_log=NULL);
private:
@@ -56,6 +70,7 @@
config& cfg_;
tokenizer tok_;
+ std::vector<line_source> const* line_sources;
struct element {
element(config* cfg, const std::string& name, size_t
start_line, const std::string& textdomain) :
@@ -74,9 +89,10 @@
std::string current_textdomain_location;
};
-parser::parser(config &cfg, std::istream &in) :
+parser::parser(config &cfg, std::istream &in, std::vector<line_source> const
*line_sources) :
cfg_(cfg),
tok_(in),
+ line_sources(line_sources),
current_textdomain_location("")
{
}
@@ -292,7 +308,6 @@
{
std::string res;
- /*
if(line_sources != NULL) {
const line_source src = get_line_source(*line_sources, lineno);
i18n_symbols["file"] = lexical_cast<std::string>(src.file);
@@ -306,7 +321,6 @@
res = vgettext(string2.c_str(), i18n_symbols);
}
- */
return res;
}
@@ -322,9 +336,10 @@
} // end anon namespace
-void read(config &cfg, std::istream &data_in, std::string* error_log)
+void read(config &cfg, std::istream &data_in, std::vector< line_source > const
*line_sources,
+ std::string* error_log)
{
- parser(cfg, data_in)(error_log);
+ parser(cfg, data_in, line_sources)(error_log);
}
static char const *AttributeEquals = "=";
Index: wesnoth/src/serialization/parser.hpp
diff -u wesnoth/src/serialization/parser.hpp:1.7
wesnoth/src/serialization/parser.hpp:1.8
--- wesnoth/src/serialization/parser.hpp:1.7 Mon Apr 11 18:39:33 2005
+++ wesnoth/src/serialization/parser.hpp Mon Apr 18 20:51:22 2005
@@ -1,4 +1,4 @@
-/* $Id: parser.hpp,v 1.7 2005/04/11 18:39:33 silene Exp $ */
+/* $Id: parser.hpp,v 1.8 2005/04/18 20:51:22 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -18,9 +18,13 @@
#include <vector>
class config;
+struct line_source;
+
+line_source get_line_source(std::vector< line_source > const &line_src, int
line);
//read data in, clobbering existing data.
-void read(config &cfg, std::istream &in, std::string* error_log = NULL);
//throws config::error
+void read(config &cfg, std::istream &in, std::vector< line_source > const
*lines = 0,
+ std::string* error_log=NULL); //throws config::error
void write(std::ostream &out, config const &cfg);
Index: wesnoth/src/serialization/preprocessor.cpp
diff -u wesnoth/src/serialization/preprocessor.cpp:1.9
wesnoth/src/serialization/preprocessor.cpp:1.10
--- wesnoth/src/serialization/preprocessor.cpp:1.9 Mon Apr 11 18:39:33 2005
+++ wesnoth/src/serialization/preprocessor.cpp Mon Apr 18 20:51:22 2005
@@ -1,4 +1,4 @@
-/* $Id: preprocessor.cpp,v 1.9 2005/04/11 18:39:33 silene Exp $ */
+/* $Id: preprocessor.cpp,v 1.10 2005/04/18 20:51:22 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -86,14 +86,13 @@
static void internal_preprocess_file(const std::string& fname,
preproc_map& defines_map,
int depth, std::ostream &out,
- std::string const &included_from);
+ std::vector<line_source>* lines_src, int&
line);
static void internal_preprocess_data(std::istream &data_in,
preproc_map& defines_map,
int depth, std::ostream &out,
- std::string const &included_from,
- bool need_linenum,
- std::string const ¤t_directory)
+ std::vector<line_source>* lines_src, int&
line,
+ const std::string& fname, int srcline)
{
std::string data_str;
{
@@ -105,8 +104,6 @@
std::string const &data = data_str;
bool in_quotes = false;
- int current_line = 1;
- bool previous_was_newline = !included_from.empty();
for(std::string::const_iterator i = data.begin(); i != data.end(); ++i)
{
const char c = *i;
@@ -173,15 +170,8 @@
}
}
- std::ostringstream from;
- if (!in_quotes && !included_from.empty()) {
- from << " {" << symbol << "} " <<
current_line << included_from;
- if (previous_was_newline)
- out << "#line 0" << from.str();
- }
std::istringstream stream(str);
- internal_preprocess_data(stream, defines_map,
depth, out, from.str(),
- !previous_was_newline,
"");
+ internal_preprocess_data(stream, defines_map,
depth, out, NULL, line, fname, srcline);
} else if(depth < 20) {
std::string prefix;
std::string nfname;
@@ -219,7 +209,7 @@
//being preprocessed
nfname = newfilename;
nfname.erase(nfname.begin(),nfname.begin()+2);
- nfname = current_directory +
nfname;
+ nfname = directory_name(fname)
+ nfname;
} else {
#ifdef USE_ZIPIOS
@@ -233,18 +223,19 @@
nfname = "data/" +
newfilename;
}
- std::ostringstream from;
- if (!in_quotes &&
!included_from.empty())
- from << ' ' << current_line <<
included_from;
- internal_preprocess_file(nfname,
defines_map, depth + 1, out, from.str());
+ internal_preprocess_file(nfname,
+ defines_map,
depth+1, out,
+
lines_src,line);
}
} else {
- scoped_istream stream =
istream_file(newfilename);
- out << stream->rdbuf();
+ const std::string& str = read_file(newfilename);
+ out.write(&*str.begin(), str.length());
+ line += std::count(str.begin(),str.end(),'\n');
}
- previous_was_newline = false;
- need_linenum = true;
+ if(lines_src != NULL) {
+
lines_src->push_back(line_source(line,fname,srcline));
+ }
} else if(c == '#' && !in_quotes) {
//we are about to skip some things, so keep track of
//the start of where we're skipping, so we can count
@@ -282,8 +273,7 @@
}
if(i > data.end() - hash_enddef.size()) {
- throw config::error("pre-processing
condition unterminated " +
- included_from + ":
'" + items + "'");
+ throw config::error("pre-processing
condition unterminated in '" + fname + "': '" + items + "'");
}
i += hash_enddef.size();
@@ -366,25 +356,17 @@
if(i == data.end())
break;
+ srcline += std::count(begin,i,'\n');
+ ++line;
+
out.put('\n');
- current_line += std::count(begin, i, '\n');
- need_linenum = true;
- goto linenum_output;
} else {
- if (c == '\n') {
- linenum_output:
- if (need_linenum && !in_quotes &&
!included_from.empty()) {
- out << "#line " << current_line <<
included_from;
- need_linenum = false;
- } else
- out.put('\n');
- ++current_line;
- previous_was_newline = true;
- } else {
- out.put(c);
- if ((unsigned)c > 32)
- previous_was_newline = false;
+ if(c == '\n') {
+ ++line;
+ ++srcline;
}
+
+ out.put(c);
}
}
}
@@ -392,7 +374,7 @@
static void internal_preprocess_file(const std::string& fname,
preproc_map& defines_map,
int depth, std::ostream &out,
- std::string const &included_from)
+ std::vector<line_source>* lines_src, int&
line)
{
//if it's a directory, we process all files in the directory
//that end in .cfg
@@ -404,31 +386,32 @@
for(std::vector<std::string>::const_iterator f = files.begin();
f != files.end(); ++f) {
if(is_directory(*f) || f->size() > 4 &&
std::equal(f->end()-4,f->end(),".cfg")) {
- internal_preprocess_file(*f, defines_map,
depth, out, included_from);
+ internal_preprocess_file(*f, defines_map,
depth, out, lines_src, line);
}
}
return;
}
- std::string from;
- if (!included_from.empty()) {
- from = " " + fname + included_from;
- out << "#line 0" << from;
+ if(lines_src != NULL) {
+ lines_src->push_back(line_source(line,fname,1));
}
+
scoped_istream stream = istream_file(fname);
- internal_preprocess_data(*stream, defines_map, depth, out, from, false,
directory_name(fname));
+ internal_preprocess_data(*stream, defines_map, depth, out, lines_src,
line, fname, 1);
}
std::istream *preprocess_file(std::string const &fname,
- preproc_map const *defines)
+ const preproc_map* defines,
+ std::vector<line_source>* line_sources)
{
log_scope("preprocessing file...");
preproc_map defines_copy;
if(defines != NULL)
defines_copy = *defines;
+ int linenum = 0;
std::stringstream *stream = new std::stringstream;
- internal_preprocess_file(fname, defines_copy, 0, *stream, "\n");
+ internal_preprocess_file(fname, defines_copy, 0, *stream, line_sources,
linenum);
return stream;
}
Index: wesnoth/src/serialization/preprocessor.hpp
diff -u wesnoth/src/serialization/preprocessor.hpp:1.4
wesnoth/src/serialization/preprocessor.hpp:1.5
--- wesnoth/src/serialization/preprocessor.hpp:1.4 Mon Apr 11 18:39:33 2005
+++ wesnoth/src/serialization/preprocessor.hpp Mon Apr 18 20:51:22 2005
@@ -1,4 +1,4 @@
-/* $Id: preprocessor.hpp,v 1.4 2005/04/11 18:39:33 silene Exp $ */
+/* $Id: preprocessor.hpp,v 1.5 2005/04/18 20:51:22 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -19,6 +19,19 @@
#include <string>
#include <vector>
+//an object which defines the location an error occurred at when
+//parsing WML files
+struct line_source
+{
+ line_source(int ln, std::string const &fname, int line)
+ : linenum(ln), file(fname), fileline(line) {}
+
+ int linenum;
+ std::string file;
+ int fileline;
+ bool operator<(line_source const &v) const { return linenum <
v.linenum; }
+};
+
struct preproc_define
{
preproc_define() {}
@@ -34,8 +47,10 @@
typedef std::map< std::string, preproc_define > preproc_map;
//function to use the WML preprocessor on a file, and returns the resulting
-//preprocessed file data. defines is a map of symbols defined.
+//preprocessed file data. defines is a map of symbols defined. src is used
+//internally and should be set to NULL
std::istream *preprocess_file(std::string const &fname,
- preproc_map const *defines = NULL);
+ preproc_map const *defines = NULL,
+ std::vector< line_source > *src = NULL);
#endif