(actually) fixed #14494

This commit is contained in:
Philippe Plantier 2005-09-12 21:33:34 +00:00
parent a8f8681010
commit 46b8676598
6 changed files with 45 additions and 22 deletions

View file

@ -280,7 +280,8 @@ void parser::parse_variable()
std::string parser::lineno_string(utils::string_map &i18n_symbols, std::string const &lineno,
std::string const &error_string)
{
std::vector< std::string > pos = utils::split(lineno, FILE_SEPARATOR);
ERR_CF << lineno << std::endl;
std::vector< std::string > pos = utils::quoted_split(lineno, ' ');
std::vector< std::string >::const_iterator i = pos.begin(), end = pos.end();
std::string included_from = _(" included from ");
std::string res;

View file

@ -187,6 +187,7 @@ class preprocessor_data: preprocessor
void put(std::string const &);
public:
preprocessor_data(preprocessor_streambuf &, std::istream *,
std::string const &history,
std::string const &name, int line,
std::string const &dir, std::string const &domain);
virtual bool get_chunk();
@ -198,7 +199,7 @@ preprocessor_file::preprocessor_file(preprocessor_streambuf &t, std::string cons
if (is_directory(name))
get_files_in_dir(name, &files_, NULL, ENTIRE_FILE_PATH);
else
new preprocessor_data(t, istream_file(name), name, 1, directory_name(name), t.textdomain_);
new preprocessor_data(t, istream_file(name), "", name, 1, directory_name(name), t.textdomain_);
pos_ = files_.begin();
end_ = files_.end();
}
@ -217,12 +218,20 @@ bool preprocessor_file::get_chunk()
}
preprocessor_data::preprocessor_data(preprocessor_streambuf &t, std::istream *i,
std::string const &history,
std::string const &name, int linenum,
std::string const &directory, std::string const &domain)
: preprocessor(t), in_(i), directory_(directory), slowpath_(0), skipping_(0), linenum_(linenum)
{
std::ostringstream s;
s << name;
s << history;
if (!name.empty()) {
std::string ename(name);
if (!history.empty())
s << ' ';
s << utils::escape(ename, " \\");
}
if (!t.location_.empty())
s << ' ' << t.linenum_ << ' ' << t.location_;
t.location_ = s.str();
@ -454,7 +463,7 @@ bool preprocessor_data::get_chunk()
target_.defines_->insert(std::make_pair(
symbol, preproc_define(buffer, items, target_.textdomain_,
linenum + 1, target_.location_)));
LOG_CF << "defining macro " << symbol << '\n';
LOG_CF << "defining macro " << symbol << " (location " << target_.location_ << ")\n";
}
} else if (command == "ifdef") {
skip_spaces();
@ -616,7 +625,7 @@ bool preprocessor_data::get_chunk()
std::string const &dir = directory_name(val.location.substr(0, val.location.find(' ')));
if (!slowpath_) {
LOG_CF << "substituting macro " << symbol << '\n';
new preprocessor_data(target_, buffer, val.location,
new preprocessor_data(target_, buffer, val.location, "",
val.linenum, dir, val.textdomain);
} else {
LOG_CF << "substituting (slow) macro " << symbol << '\n';
@ -624,7 +633,7 @@ bool preprocessor_data::get_chunk()
preprocessor_streambuf *buf =
new preprocessor_streambuf(target_);
{ std::istream in(buf);
new preprocessor_data(*buf, buffer, val.location,
new preprocessor_data(*buf, buffer, val.location, "",
val.linenum, dir, val.textdomain);
res << in.rdbuf(); }
delete buf;

View file

@ -233,14 +233,12 @@ std::string interpolate_variables_into_string(const std::string &str, variable_s
return res;
}
//prepend all special characters with a backslash
//special characters are:
//#@{}+-,\*=
std::string &escape(std::string &str)
//Prepends a configurable set of characters with a backslash
std::string &escape(std::string &str, const std::string& special_chars)
{
std::string::size_type pos = 0;
do {
pos = str.find_first_of("#@{}+-,\\*=", pos);
pos = str.find_first_of(special_chars, pos);
if (pos == std::string::npos)
break;
str.insert(pos, 1, '\\');
@ -249,6 +247,15 @@ std::string &escape(std::string &str)
return str;
}
//prepend all special characters with a backslash
//special characters are:
//#@{}+-,\*=
std::string& escape(std::string& str)
{
static const std::string special_chars("#@{}+-,\\*=");
return escape(str, special_chars);
}
// remove all escape characters (backslash)
std::string &unescape(std::string &str)
{

View file

@ -21,7 +21,7 @@
#include "SDL_types.h"
#include "tstring.hpp"
#include "util.hpp"
class variable_set
{
@ -54,6 +54,7 @@ std::vector< std::string > quoted_split(std::string const &val, char c= ',',
int flags = REMOVE_EMPTY | STRIP_SPACES, char quote = '\\');
std::pair< int, int > parse_range(std::string const &str);
bool notspace(char c);
std::string &escape(std::string &str, const std::string& special_chars);
std::string &escape(std::string &str);
std::string &unescape(std::string &str);
std::string &strip(std::string &str);

View file

@ -41,13 +41,20 @@ void tokenizer::skip_comment()
}
// Identifies and processes tokenizer directives
std::vector<std::string> comment_line = utils::split(comment, ' ');
if (comment_line.size() == 2 && comment_line[0] == "textdomain")
textdomain_ = comment_line[1];
else if (comment_line.size() > 3 && comment_line[0] == "line") {
lineno_ = atoi(comment_line[1].c_str());
comment_line.erase(comment_line.begin(), comment_line.begin() + 2);
file_ = FILE_SEPARATOR + utils::join(comment_line, ' ');
std::string::size_type pos = comment.find_first_of(" \t");
if (pos != std::string::npos) {
const std::string word = comment.substr(0, pos);
if (word == "textdomain" && pos < comment.size() - 1) {
textdomain_ = comment.substr(pos + 1);
} else if (word == "line" && pos < comment.size() - 1) {
std::string::size_type pos2 = comment.find_first_of(" \t", pos + 1);
if (pos2 != std::string::npos) {
lineno_ = lexical_cast<size_t>(comment.substr(pos + 1, pos2 - pos));
file_ = comment.substr(pos2 + 1);
}
}
}
}
@ -163,7 +170,7 @@ bool tokenizer::is_alnum(int c)
std::string tokenizer::get_line()
{
std::ostringstream s;
s << tokenstart_lineno_ << file_;
s << tokenstart_lineno_ << ' ' << file_;
return s.str();
}

View file

@ -17,8 +17,6 @@
#include <istream>
#include <string>
#define FILE_SEPARATOR '\375'
class config;
struct token