Removed all the error logs for preprocessing,

...since they are useless now that preprocessor errors are no longer
silent.
This commit is contained in:
Guillaume Melquiond 2010-08-05 08:32:20 +00:00
parent b4faa06a7b
commit d8da47b5a0
9 changed files with 52 additions and 94 deletions

View file

@ -146,15 +146,9 @@ namespace game_config {
void config_cache::read_configs(const std::string& path, config& cfg, preproc_map& defines_map)
{
std::string error_log;
//read the file and then write to the cache
scoped_istream stream = preprocess_file(path, &defines_map, &error_log);
read(cfg, *stream, &error_log);
if (!error_log.empty())
{
throw config::error(error_log);
}
scoped_istream stream = preprocess_file(path, &defines_map);
read(cfg, *stream);
}
void config_cache::read_cache(const std::string& path, config& cfg)

View file

@ -225,13 +225,14 @@ void manager::read_save_file(const std::string& name, config& cfg, std::string*
cfg.clear();
try{
if(is_gzip_file(name)) {
read_gz(cfg, *file_stream, error_log);
read_gz(cfg, *file_stream);
} else {
detect_format_and_read(cfg, *file_stream, error_log);
detect_format_and_read(cfg, *file_stream);
}
} catch (config::error &err)
{
LOG_SAVE << err.message;
if (error_log) *error_log += err.message;
throw game::load_game_failed();
}

View file

@ -29,14 +29,14 @@
#include <boost/iostreams/filter/gzip.hpp>
bool detect_format_and_read(config &cfg, std::istream &in, std::string* error_log)
bool detect_format_and_read(config &cfg, std::istream &in)
{
unsigned char c = in.peek();
if (c < 4) {
read_compressed(cfg, in);
return true;
} else {
read(cfg, in, error_log);
read(cfg, in);
return false;
}
}

View file

@ -35,7 +35,7 @@ class config;
*
* @returns True iff the format is compressed.
*/
bool detect_format_and_read(config &cfg, std::istream &in, std::string* error_log=NULL); // Throws config::error
bool detect_format_and_read(config &cfg, std::istream &in); // Throws config::error
/** Class for writing a config out to a file in pieces. */
class config_writer

View file

@ -55,7 +55,7 @@ class parser
public:
parser(config& cfg, std::istream& in);
~parser();
void operator() (std::string* error_log=NULL);
void operator()();
private:
void parse_element();
@ -95,48 +95,35 @@ parser::~parser()
delete tok_;
}
void parser::operator()(std::string* error_log)
void parser::operator()()
{
cfg_.clear();
elements.push(element(&cfg_, ""));
do {
try {
tok_->next_token();
tok_->next_token();
switch(tok_->current_token().type) {
case token::LF:
continue;
case '[':
parse_element();
break;
case token::STRING:
parse_variable();
break;
default:
if (static_cast<unsigned char>(tok_->current_token().value[0]) == 0xEF &&
static_cast<unsigned char>(tok_->next_token().value[0]) == 0xBB &&
static_cast<unsigned char>(tok_->next_token().value[0]) == 0xBF)
{
ERR_CF << "Skipping over a utf8 BOM\n";
} else {
error(_("Unexpected characters at line start"));
}
break;
case token::END:
break;
switch(tok_->current_token().type) {
case token::LF:
continue;
case '[':
parse_element();
break;
case token::STRING:
parse_variable();
break;
default:
if (static_cast<unsigned char>(tok_->current_token().value[0]) == 0xEF &&
static_cast<unsigned char>(tok_->next_token().value[0]) == 0xBB &&
static_cast<unsigned char>(tok_->next_token().value[0]) == 0xBF)
{
ERR_CF << "Skipping over a utf8 BOM\n";
} else {
error(_("Unexpected characters at line start"));
}
} catch(config::error& e) {
if(error_log == NULL)
throw;
// On error, dump tokens to the next LF
while(tok_->current_token().type != token::LF &&
tok_->current_token().type != token::END) {
tok_->next_token();
}
*error_log += e.message + '\n';
break;
case token::END:
break;
}
increment_parser_progress();
} while (tok_->current_token().type != token::END);
@ -343,18 +330,18 @@ void parser::error(const std::string& error_type)
} // end anon namespace
void read(config &cfg, std::istream &in, std::string* error_log)
void read(config &cfg, std::istream &in)
{
parser(cfg, in)(error_log);
parser(cfg, in)();
}
void read(config &cfg, std::string &in, std::string* error_log)
void read(config &cfg, std::string &in)
{
std::stringstream ss(in);
parser(cfg, ss)(error_log);
std::istringstream ss(in);
parser(cfg, ss)();
}
void read_gz(config &cfg, std::istream &file, std::string* error_log)
void read_gz(config &cfg, std::istream &file)
{
//an empty gzip file seems to confuse boost on msvc
//so return early if this is the case
@ -365,7 +352,7 @@ void read_gz(config &cfg, std::istream &file, std::string* error_log)
filter.push(boost::iostreams::gzip_decompressor());
filter.push(file);
parser(cfg, filter)(error_log);
parser(cfg, filter)();
}
static char const *AttributeEquals = "=";

View file

@ -27,9 +27,9 @@ class config;
class t_string;
// 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::string &in, std::string* error_log = NULL); // Throws config::error
void read_gz(config &cfg, std::istream &in, std::string* error_log=NULL);
void read(config &cfg, std::istream &in); // Throws config::error
void read(config &cfg, std::string &in); // Throws config::error
void read_gz(config &cfg, std::istream &in);
void write(std::ostream &out, config const &cfg, unsigned int level=0);
void write_key_val(std::ostream &out, const std::string &key, const t_string &value, unsigned int level, std::string &textdomain);

View file

@ -217,7 +217,6 @@ class preprocessor_streambuf: public streambuf
preproc_map default_defines_;
std::string textdomain_;
std::string location_;
std::string *error_log;
int linenum_;
int depth_;
/**
@ -231,11 +230,11 @@ class preprocessor_streambuf: public streambuf
friend struct preprocessor_deleter;
preprocessor_streambuf(preprocessor_streambuf const &);
public:
preprocessor_streambuf(preproc_map *, std::string *);
preprocessor_streambuf(preproc_map *);
void error(const std::string &, int);
};
preprocessor_streambuf::preprocessor_streambuf(preproc_map *def, std::string *err_log) :
preprocessor_streambuf::preprocessor_streambuf(preproc_map *def) :
streambuf(),
out_buffer_(""),
buffer_(),
@ -244,7 +243,6 @@ preprocessor_streambuf::preprocessor_streambuf(preproc_map *def, std::string *er
default_defines_(),
textdomain_(PACKAGE),
location_(""),
error_log(err_log),
linenum_(0),
depth_(0),
quoted_(false)
@ -260,7 +258,6 @@ preprocessor_streambuf::preprocessor_streambuf(preprocessor_streambuf const &t)
default_defines_(),
textdomain_(PACKAGE),
location_(""),
error_log(t.error_log),
linenum_(0),
depth_(t.depth_),
quoted_(t.quoted_)
@ -345,9 +342,6 @@ void preprocessor_streambuf::error(const std::string& error_type, int l)
position = lineno_string(pos.str());
error = error_type + " at " + position;
ERR_CF << error << '\n';
if (error_log)
*error_log += error + '\n';
throw preproc_config::error(error);
}
@ -1026,7 +1020,6 @@ struct preprocessor_deleter: std::basic_istream<char>
{
preprocessor_streambuf *buf_;
preproc_map *defines_;
std::string *error_log;
preprocessor_deleter(preprocessor_streambuf *buf, preproc_map *defines);
~preprocessor_deleter();
};
@ -1034,7 +1027,6 @@ struct preprocessor_deleter: std::basic_istream<char>
preprocessor_deleter::preprocessor_deleter(preprocessor_streambuf *buf,
preproc_map *defines)
: std::basic_istream<char>(buf), buf_(buf), defines_(defines)
, error_log(buf->error_log)
{
}
@ -1048,8 +1040,7 @@ preprocessor_deleter::~preprocessor_deleter()
}
std::istream *preprocess_file(std::string const &fname,
preproc_map *defines, std::string *error_log)
std::istream *preprocess_file(std::string const &fname, preproc_map *defines)
{
log_scope("preprocessing file...");
preproc_map *owned_defines = NULL;
@ -1061,10 +1052,8 @@ std::istream *preprocess_file(std::string const &fname,
owned_defines = new preproc_map;
defines = owned_defines;
}
preprocessor_streambuf *buf = new preprocessor_streambuf(defines, error_log);
preprocessor_streambuf *buf = new preprocessor_streambuf(defines);
new preprocessor_file(*buf, fname);
if (error_log && !error_log->empty())
throw preproc_config::error("Error preprocessing files.");
return new preprocessor_deleter(buf, owned_defines);
}
@ -1101,22 +1090,16 @@ void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
//disable filename encoding to get clear #line in cfg.plain
encode_filename = false;
std::string error_log;
scoped_istream stream = preprocess_file(res_name, defines_map, &error_log);
scoped_istream stream = preprocess_file(res_name, defines_map);
std::stringstream ss;
ss<<(*stream).rdbuf();
std::string streamContent = ss.str();
config cfg;
if (!error_log.empty())
{
throw config::error(error_log);
}
if (write_cfg == true || write_plain_cfg == true)
{
read(cfg, streamContent, &error_log);
read(cfg, streamContent);
const std::string preproc_res_name = target_directory + "/" + file_name(res_name);
// write the processed cfg file

View file

@ -72,8 +72,7 @@ std::ostream& operator<<(std::ostream& stream, const preproc_map::value_type& de
*
* @returns The resulting preprocessed file data.
*/
std::istream *preprocess_file(std::string const &fname,
preproc_map *defines = NULL, std::string *error_log=NULL);
std::istream *preprocess_file(std::string const &fname, preproc_map *defines = NULL);
void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
bool write_cfg=false, bool write_plain_cfg=false, std::string target_directory="");

View file

@ -395,17 +395,11 @@ void server::send_password_request(network::connection sock, const char* msg,
config server::read_config() const {
config configuration;
if (config_file_ == "") return configuration;
scoped_istream stream = preprocess_file(config_file_);
std::string errors;
try {
read(configuration, *stream, &errors);
if (errors.empty()) {
LOG_SERVER << "Server configuration from file: '" << config_file_
<< "' read.\n";
} else {
ERR_CONFIG << "ERROR: Errors reading configuration file: '"
<< errors << "'.\n";
}
scoped_istream stream = preprocess_file(config_file_);
read(configuration, *stream);
LOG_SERVER << "Server configuration from file: '" << config_file_
<< "' read.\n";
} catch(config::error& e) {
ERR_CONFIG << "ERROR: Could not read configuration file: '"
<< config_file_ << "': '" << e.message << "'.\n";