wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src/serialization parser.cpp preprocess...


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src/serialization parser.cpp preprocess...
Date: Mon, 12 Sep 2005 17:33:35 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      05/09/12 21:33:34

Modified files:
        src/serialization: parser.cpp preprocessor.cpp string_utils.cpp 
                           string_utils.hpp tokenizer.cpp tokenizer.hpp 

Log message:
        (actually) fixed #14494

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/parser.cpp.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/preprocessor.cpp.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.cpp.diff?tr1=1.25&tr2=1.26&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.hpp.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/tokenizer.cpp.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/tokenizer.hpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text

Patches:
Index: wesnoth/src/serialization/parser.cpp
diff -u wesnoth/src/serialization/parser.cpp:1.21 
wesnoth/src/serialization/parser.cpp:1.22
--- wesnoth/src/serialization/parser.cpp:1.21   Sun Sep 11 14:55:44 2005
+++ wesnoth/src/serialization/parser.cpp        Mon Sep 12 21:33:34 2005
@@ -1,4 +1,4 @@
-/* $Id: parser.cpp,v 1.21 2005/09/11 14:55:44 ott Exp $ */
+/* $Id: parser.cpp,v 1.22 2005/09/12 21:33:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -280,7 +280,8 @@
 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;
Index: wesnoth/src/serialization/preprocessor.cpp
diff -u wesnoth/src/serialization/preprocessor.cpp:1.24 
wesnoth/src/serialization/preprocessor.cpp:1.25
--- wesnoth/src/serialization/preprocessor.cpp:1.24     Tue Jul 12 20:33:19 2005
+++ wesnoth/src/serialization/preprocessor.cpp  Mon Sep 12 21:33:34 2005
@@ -1,4 +1,4 @@
-/* $Id: preprocessor.cpp,v 1.24 2005/07/12 20:33:19 silene Exp $ */
+/* $Id: preprocessor.cpp,v 1.25 2005/09/12 21:33:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -187,6 +187,7 @@
        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 @@
        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 @@
 }
 
 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 @@
                                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 @@
                                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 @@
                                        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;
Index: wesnoth/src/serialization/string_utils.cpp
diff -u wesnoth/src/serialization/string_utils.cpp:1.25 
wesnoth/src/serialization/string_utils.cpp:1.26
--- wesnoth/src/serialization/string_utils.cpp:1.25     Wed Aug 24 21:21:55 2005
+++ wesnoth/src/serialization/string_utils.cpp  Mon Sep 12 21:33:34 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.cpp,v 1.25 2005/08/24 21:21:55 gruikya Exp $ */
+/* $Id: string_utils.cpp,v 1.26 2005/09/12 21:33:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -233,20 +233,27 @@
        return res;
 }
 
-//prepend all special characters with a backslash
-//special characters are:
-//address@hidden,\*=
-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("address@hidden,\\*=", pos);
+               pos = str.find_first_of(special_chars, pos);
                if (pos == std::string::npos)
                        break;
                str.insert(pos, 1, '\\');
                pos += 2;
        } while (pos < str.size());
        return str;
+}
+
+//prepend all special characters with a backslash
+//special characters are:
+//address@hidden,\*=
+std::string& escape(std::string& str)
+{
+       static const std::string special_chars("address@hidden,\\*=");
+       return escape(str, special_chars);
 }
 
 // remove all escape characters (backslash)
Index: wesnoth/src/serialization/string_utils.hpp
diff -u wesnoth/src/serialization/string_utils.hpp:1.15 
wesnoth/src/serialization/string_utils.hpp:1.16
--- wesnoth/src/serialization/string_utils.hpp:1.15     Sat Jul  2 21:37:20 2005
+++ wesnoth/src/serialization/string_utils.hpp  Mon Sep 12 21:33:34 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.hpp,v 1.15 2005/07/02 21:37:20 ott Exp $ */
+/* $Id: string_utils.hpp,v 1.16 2005/09/12 21:33:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -21,7 +21,7 @@
 
 #include "SDL_types.h"
 #include "tstring.hpp"
-
+#include "util.hpp"
 
 class variable_set
 {
@@ -54,6 +54,7 @@
                                         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);
Index: wesnoth/src/serialization/tokenizer.cpp
diff -u wesnoth/src/serialization/tokenizer.cpp:1.13 
wesnoth/src/serialization/tokenizer.cpp:1.14
--- wesnoth/src/serialization/tokenizer.cpp:1.13        Sun Sep 11 14:55:44 2005
+++ wesnoth/src/serialization/tokenizer.cpp     Mon Sep 12 21:33:34 2005
@@ -1,4 +1,4 @@
-/* $Id: tokenizer.cpp,v 1.13 2005/09/11 14:55:44 ott Exp $ */
+/* $Id: tokenizer.cpp,v 1.14 2005/09/12 21:33:34 gruikya Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -41,13 +41,20 @@
        }
 
        // 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 @@
 std::string tokenizer::get_line()
 {
        std::ostringstream s;
-       s << tokenstart_lineno_ << file_;
+       s << tokenstart_lineno_ << ' ' << file_;
        return s.str();
 }
 
Index: wesnoth/src/serialization/tokenizer.hpp
diff -u wesnoth/src/serialization/tokenizer.hpp:1.6 
wesnoth/src/serialization/tokenizer.hpp:1.7
--- wesnoth/src/serialization/tokenizer.hpp:1.6 Sun Sep 11 14:55:44 2005
+++ wesnoth/src/serialization/tokenizer.hpp     Mon Sep 12 21:33:34 2005
@@ -1,4 +1,4 @@
-/* $Id: tokenizer.hpp,v 1.6 2005/09/11 14:55:44 ott Exp $ */
+/* $Id: tokenizer.hpp,v 1.7 2005/09/12 21:33:34 gruikya Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -16,8 +16,6 @@
 
 #include <istream>
 #include <string>
-
-#define FILE_SEPARATOR '\375'
 
 class config;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]