mail[Wesnoth-commits] r33897 - in /trunk/src: addon_checks.cpp addon_checks.hpp campaign_server/campaign_server.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on March 20, 2009 - 08:08:
Author: silene
Date: Fri Mar 20 08:08:07 2009
New Revision: 33897

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33897&view=rev
Log:
Removed config::get_children from addon_checks.cpp.

Modified:
    trunk/src/addon_checks.cpp
    trunk/src/addon_checks.hpp
    trunk/src/campaign_server/campaign_server.cpp

Modified: trunk/src/addon_checks.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_checks.cpp?rev=33897&r1=33896&r2=33897&view=diff
==============================================================================
--- trunk/src/addon_checks.cpp (original)
+++ trunk/src/addon_checks.cpp Fri Mar 20 08:08:07 2009
@@ -16,6 +16,7 @@
 #include "global.hpp"
 #include "addon_checks.hpp"
 #include "config.hpp"
+#include "foreach.hpp"
 
 #include <cstring>
 
@@ -40,16 +41,12 @@
 
 bool check_names_legal(const config& dir)
 {
-       const config::child_list& files = dir.get_children("file");
-       for(config::child_list::const_iterator i = files.begin(); i != 
files.end(); ++i) {
-                       if (!addon_name_legal((**i)["name"])) return false;
+       foreach (const config &path, dir.child_range("file")) {
+               if (!addon_name_legal(path["name"])) return false;
        }
-       const config::child_list& dirs = dir.get_children("dir");
-       {
-               for(config::child_list::const_iterator i = dirs.begin(); i != 
dirs.end(); ++i) {
-                               if (!addon_name_legal((**i)["name"])) return 
false;
-                               if (!check_names_legal(**i)) return false;
-               }
+       foreach (const config &path, dir.child_range("dir")) {
+               if (!addon_name_legal(path["name"])) return false;
+               if (!check_names_legal(path)) return false;
        }
        return true;
 }
@@ -82,29 +79,24 @@
                return ADDON_UNKNOWN;
 }
 
-std::vector<config *> find_scripts(const config &cfg, std::string extension)
+void find_scripts(config &cfg, const std::string &extension,
+                  std::vector<config *> &scripts)
 {
-       std::vector<config *> python_scripts;
-       const config::child_list& dirs = cfg.get_children("dir");
-       config::child_list::const_iterator i;
-       for(i = dirs.begin(); i != dirs.end(); ++i) {
-               const config::child_list& files = (**i).get_children("file");
-               config::child_list::const_iterator j;
-               for(j = files.begin(); j != files.end(); ++j) {
-                       std::string filename = (**j)["name"].str();
+       foreach (config &i, cfg.child_range("dir"))
+       {
+               foreach (config &j, cfg.child_range("file"))
+               {
+                       std::string filename = j["name"];
                        if (filename.length() > extension.length()) {
                                if (filename.substr(filename.length() - 
extension.length()) ==
                                        extension) {
-                                       python_scripts.push_back(*j);
+                                       scripts.push_back(&j);
                                }
                        }
                }
                // Recursively look for files in sub directories.
-               std::vector<config *> childs = find_scripts(**i, extension);
-               python_scripts.insert(python_scripts.end(),
-                       childs.begin(), childs.end());
+               find_scripts(i, extension, scripts);
        }
-       return python_scripts;
 }
 
 namespace {

Modified: trunk/src/addon_checks.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_checks.hpp?rev=33897&r1=33896&r2=33897&view=diff
==============================================================================
--- trunk/src/addon_checks.hpp (original)
+++ trunk/src/addon_checks.hpp Fri Mar 20 08:08:07 2009
@@ -64,8 +64,8 @@
 bool addon_name_legal(const std::string& name);
 /** Probes an add-on archive for illegal names. */
 bool check_names_legal(const config& dir);
-/** Return a vector of detected scripts. */
-std::vector<config *> find_scripts(const config &cfg, std::string extension);
+/** Adds detected scripts to a vector. */
+void find_scripts(config &cfg, const std::string &extension, 
std::vector<config *> &);
 
 std::string encode_binary(const std::string& str);
 std::string unencode_binary(const std::string& str);

Modified: trunk/src/campaign_server/campaign_server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/campaign_server/campaign_server.cpp?rev=33897&r1=33896&r2=33897&view=diff
==============================================================================
--- trunk/src/campaign_server/campaign_server.cpp (original)
+++ trunk/src/campaign_server/campaign_server.cpp Fri Mar 20 08:08:07 2009
@@ -20,6 +20,7 @@
  */
 
 #include "filesystem.hpp"
+#include "foreach.hpp"
 #include "log.hpp"
 #include "network_worker.hpp"
 #include "serialization/binary_or_text.hpp"
@@ -214,33 +215,35 @@
        // again.
        std::string check_python_scripts(config &data, std::string filename)
        {
-               std::vector<config *> python_scripts = find_scripts(data, 
".py");
-               if (!python_scripts.empty()) {
-                       // Campaign contains python scripts.
-                       config old_campaign;
-                       scoped_istream stream = istream_file(filename);
-                       read_gz(old_campaign, *stream);
-                       std::vector<config *> old_scripts = 
find_scripts(old_campaign, ".py");
-                       std::string script_names = "";
-                       std::vector<config *>::iterator i, j;
-                       // Go through all newly uploaded python scripts.
-                       for (i = python_scripts.begin(); i != 
python_scripts.end(); ++i) {
-                               bool already = false;
-                               // Compare to existing, approved scripts.
-                               for (j = old_scripts.begin(); j != 
old_scripts.end(); ++j) {
-                                       if ((**i)["contents"] != 
(**j)["contents"]) continue;
-                                       already = true;
-                                       break;
-                               }
-                               if (!already) {
-                                       script_names += "\n" + (**i)["name"];
-                                       (**i)["name"] += ".unchecked";
-                               }
+               std::vector<config *> python_scripts;
+               find_scripts(data, ".py", python_scripts);
+               if (python_scripts.empty()) return std::string();
+               // Campaign contains python scripts.
+               config old_campaign;
+               scoped_istream stream = istream_file(filename);
+               read_gz(old_campaign, *stream);
+               std::vector<config *> old_scripts;
+               find_scripts(old_campaign, ".py", old_scripts);
+               std::string script_names;
+               // Go through all newly uploaded python scripts.
+               foreach (config *i, python_scripts)
+               {
+                       bool already = false;
+                       // Compare to existing, approved scripts.
+                       foreach (const config *j, old_scripts)
+                       {
+                               if ((*i)["contents"] != (*j)["contents"]) 
continue;
+                               already = true;
+                               break;
                        }
-                       if (script_names != "")
-                               return "\nScripts awaiting approval:\n" + 
script_names;
-               }
-               return "";
+                       if (!already) {
+                               script_names += "\n" + (*i)["name"];
+                               (*i)["name"] += ".unchecked";
+                       }
+               }
+               if (!script_names.empty())
+                       return "\nScripts awaiting approval:\n" + 
script_names;
+               return std::string();
        }
 
        // Go through all .py.unchecked files in the given campaign, and 
rename them to
@@ -249,21 +252,19 @@
        // command.
        std::string validate_all_python_scripts(config &data)
        {
-               std::vector<config *> python_scripts = find_scripts(data, 
".py.unchecked");
-               if (!python_scripts.empty()) {
-                       // Campaign contains unchecked python scripts.
-                       std::string script_names = "";
-                       std::vector<config *>::iterator i;
-                       // Go through all unchecked python scripts.
-                       for (i = python_scripts.begin(); i != 
python_scripts.end(); ++i) {
-                               std::string name = (**i)["name"];
-                               name.resize(name.length() - 10);
-                               (**i)["name"] = name;
-                               script_names += "\n" + name;
-                       }
-                       return script_names;
-               }
-               return "";
+               std::vector<config *> python_scripts;
+               find_scripts(data, ".py.unchecked", python_scripts);
+               if (python_scripts.empty()) return std::string();
+               // Campaign contains unchecked python scripts.
+               std::string script_names;
+               foreach (config *i, python_scripts)
+               {
+                       std::string name = (*i)["name"];
+                       name.resize(name.length() - 10);
+                       (*i)["name"] = name;
+                       script_names += "\n" + name;
+               }
+               return script_names;
        }
 
        // Add a file COPYING.txt with the GPL to an uploaded campaign.




Related Messages


Powered by MHonArc, Updated Fri Mar 20 08:20:30 2009