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

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

[Wesnoth-cvs-commits] wesnoth/src config.cpp config.hpp filesystem.cp...


From: Yann Dirson
Subject: [Wesnoth-cvs-commits] wesnoth/src config.cpp config.hpp filesystem.cp...
Date: Fri, 31 Dec 2004 14:13:56 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Yann Dirson <address@hidden>    04/12/30 19:32:35

Modified files:
        src            : config.cpp config.hpp filesystem.cpp 
                         filesystem.hpp font.cpp 

Log message:
        moved basic file I/O from config.cpp to filesystem.cpp

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/config.cpp.diff?tr1=1.116&tr2=1.117&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/config.hpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.cpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.hpp.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.93&tr2=1.94&r1=text&r2=text

Patches:
Index: wesnoth/src/config.cpp
diff -u wesnoth/src/config.cpp:1.116 wesnoth/src/config.cpp:1.117
--- wesnoth/src/config.cpp:1.116        Thu Nov 25 21:39:38 2004
+++ wesnoth/src/config.cpp      Thu Dec 30 19:32:35 2004
@@ -1,4 +1,4 @@
-/* $Id: config.cpp,v 1.116 2004/11/25 21:39:38 ydirson Exp $ */
+/* $Id: config.cpp,v 1.117 2004/12/30 19:32:35 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -28,7 +28,6 @@
 #include "game_events.hpp"
 #include "gettext.hpp"
 #include "log.hpp"
-#include "scoped_resource.hpp"
 #include "util.hpp"
 #include "wesconfig.h"
 
@@ -75,108 +74,12 @@
        return res;
 }
 
-void read_file_internal(const std::string& fname, std::string& res)
-{
-       const int size = file_size(fname);
-       if(size < 0) {
-               return;
-       }
-
-       std::vector<char> v;
-       v.reserve(size);
-
-       //const util::scoped_resource<FILE*,close_FILE> 
file(fopen(fname.c_str(),"rb"));
-       const util::scoped_FILE file(fopen(fname.c_str(),"rb"));
-
-       if(file == NULL) {
-               return;
-       }
-
-       const int block_size = 65536;
-
-       while(v.size() < size) {
-               const size_t expected = minimum<size_t>(block_size,size - 
v.size());
-
-               if(expected > 0) {
-                       v.resize(v.size() + expected);
-                       const size_t nbytes = fread(&v[v.size() - 
expected],1,expected,file);
-                       if(nbytes < expected) {
-                               v.resize(v.size() - (expected - nbytes));
-                               break;
-                       }
-               }
-       }
-
-       res.resize(v.size());
-       std::copy(v.begin(),v.end(),res.begin());
-}
-
 } //end anon namespace
 
-std::string read_stdin()
-{
-       std::vector<char> v;
-       const int block_size = 65536;
-
-       size_t nbytes = 1;
-       while(nbytes > 0) {
-               v.resize(v.size() + block_size);
-               nbytes = fread(&v[v.size() - block_size],1,block_size,stdin);
-               if(nbytes < block_size) {
-                       v.resize(v.size() - (block_size - nbytes));
-                       break;
-               }
-       }
-       
-       std::string res;
-       res.resize(v.size());
-       std::copy(v.begin(),v.end(),res.begin());
-       return res;
-}
-
 const char* io_exception::what() const throw() {
        return message.c_str();
 }
 
-std::string read_file(const std::string& fname)
-{
-       //if we have a path to the data,
-       //convert any filepath which is relative
-       if(!fname.empty() && fname[0] != '/' && !game_config::path.empty()) {
-               std::string res;
-               read_file_internal(game_config::path + "/" + fname,res);
-               if(!res.empty()) {
-                       return res;
-               }
-       }
-
-       std::string res;
-       read_file_internal(fname,res);
-       return res;
-}
-
-//throws io_exception if an error occurs
-void write_file(const std::string& fname, const std::string& data)
-{
-       //const util::scoped_resource<FILE*,close_FILE> 
file(fopen(fname.c_str(),"wb"));
-       const util::scoped_FILE file(fopen(fname.c_str(),"wb"));
-       if(file.get() == NULL) {
-               throw io_exception("Could not open file for writing: '" + fname 
+ "'");
-       }
-
-       const size_t block_size = 4096;
-       char buf[block_size];
-
-       for(size_t i = 0; i < data.size(); i += block_size) {
-               const size_t bytes = minimum<size_t>(block_size,data.size() - 
i);
-               std::copy(data.begin() + i, data.begin() + i + bytes,buf);
-               const size_t res = fwrite(buf,1,bytes,file.get());
-               if(res != bytes) {
-                       throw io_exception("Error writing to file: '" + fname + 
"'");
-               }
-       }
-}
-
 namespace {
 
 //this function takes a macro and parses it into the macro followed by its
Index: wesnoth/src/config.hpp
diff -u wesnoth/src/config.hpp:1.49 wesnoth/src/config.hpp:1.50
--- wesnoth/src/config.hpp:1.49 Thu Dec 30 02:52:37 2004
+++ wesnoth/src/config.hpp      Thu Dec 30 19:32:35 2004
@@ -1,4 +1,4 @@
-/* $Id: config.hpp,v 1.49 2004/12/30 02:52:37 Sirp Exp $ */
+/* $Id: config.hpp,v 1.50 2004/12/30 19:32:35 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -53,12 +53,6 @@
        std::string message;
 };
 
-//basic disk I/O
-std::string read_file(const std::string& fname);
-//throws io_exception if an error occurs
-void write_file(const std::string& fname, const std::string& data);
-std::string read_stdin();
-
 struct preproc_define {
        preproc_define() {}
        explicit preproc_define(const std::string& val) : value(val) {}
Index: wesnoth/src/filesystem.cpp
diff -u wesnoth/src/filesystem.cpp:1.49 wesnoth/src/filesystem.cpp:1.50
--- wesnoth/src/filesystem.cpp:1.49     Thu Nov 18 22:00:12 2004
+++ wesnoth/src/filesystem.cpp  Thu Dec 30 19:32:35 2004
@@ -1,4 +1,4 @@
-/* $Id: filesystem.cpp,v 1.49 2004/11/18 22:00:12 ydirson Exp $ */
+/* $Id: filesystem.cpp,v 1.50 2004/12/30 19:32:35 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -59,6 +59,7 @@
 #include "config.hpp"
 #include "filesystem.hpp"
 #include "game_config.hpp"
+#include "scoped_resource.hpp"
 #include "util.hpp"
 
 namespace {
@@ -327,6 +328,105 @@
 #endif
 }
 
+namespace {
+void read_file_internal(const std::string& fname, std::string& res)
+{
+       const int size = file_size(fname);
+       if(size < 0) {
+               return;
+       }
+
+       std::vector<char> v;
+       v.reserve(size);
+
+       //const util::scoped_resource<FILE*,close_FILE> 
file(fopen(fname.c_str(),"rb"));
+       const util::scoped_FILE file(fopen(fname.c_str(),"rb"));
+
+       if(file == NULL) {
+               return;
+       }
+
+       const int block_size = 65536;
+
+       while(v.size() < size) {
+               const size_t expected = minimum<size_t>(block_size,size - 
v.size());
+
+               if(expected > 0) {
+                       v.resize(v.size() + expected);
+                       const size_t nbytes = fread(&v[v.size() - 
expected],1,expected,file);
+                       if(nbytes < expected) {
+                               v.resize(v.size() - (expected - nbytes));
+                               break;
+                       }
+               }
+       }
+
+       res.resize(v.size());
+       std::copy(v.begin(),v.end(),res.begin());
+}
+} //end anon namespace
+
+std::string read_stdin()
+{
+       std::vector<char> v;
+       const int block_size = 65536;
+
+       size_t nbytes = 1;
+       while(nbytes > 0) {
+               v.resize(v.size() + block_size);
+               nbytes = fread(&v[v.size() - block_size],1,block_size,stdin);
+               if(nbytes < block_size) {
+                       v.resize(v.size() - (block_size - nbytes));
+                       break;
+               }
+       }
+       
+       std::string res;
+       res.resize(v.size());
+       std::copy(v.begin(),v.end(),res.begin());
+       return res;
+}
+
+std::string read_file(const std::string& fname)
+{
+       //if we have a path to the data,
+       //convert any filepath which is relative
+       if(!fname.empty() && fname[0] != '/' && !game_config::path.empty()) {
+               std::string res;
+               read_file_internal(game_config::path + "/" + fname,res);
+               if(!res.empty()) {
+                       return res;
+               }
+       }
+
+       std::string res;
+       read_file_internal(fname,res);
+       return res;
+}
+
+//throws io_exception if an error occurs
+void write_file(const std::string& fname, const std::string& data)
+{
+       //const util::scoped_resource<FILE*,close_FILE> 
file(fopen(fname.c_str(),"wb"));
+       const util::scoped_FILE file(fopen(fname.c_str(),"wb"));
+       if(file.get() == NULL) {
+               throw io_exception("Could not open file for writing: '" + fname 
+ "'");
+       }
+
+       const size_t block_size = 4096;
+       char buf[block_size];
+
+       for(size_t i = 0; i < data.size(); i += block_size) {
+               const size_t bytes = minimum<size_t>(block_size,data.size() - 
i);
+               std::copy(data.begin() + i, data.begin() + i + bytes,buf);
+               const size_t res = fwrite(buf,1,bytes,file.get());
+               if(res != bytes) {
+                       throw io_exception("Error writing to file: '" + fname + 
"'");
+               }
+       }
+}
+
+
 std::string read_map(const std::string& name)
 {
        std::string res = read_file("data/maps/" + name);
Index: wesnoth/src/filesystem.hpp
diff -u wesnoth/src/filesystem.hpp:1.29 wesnoth/src/filesystem.hpp:1.30
--- wesnoth/src/filesystem.hpp:1.29     Sat Sep 18 21:42:13 2004
+++ wesnoth/src/filesystem.hpp  Thu Dec 30 19:32:35 2004
@@ -1,4 +1,4 @@
-/* $Id: filesystem.hpp,v 1.29 2004/09/18 21:42:13 Sirp Exp $ */
+/* $Id: filesystem.hpp,v 1.30 2004/12/30 19:32:35 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -44,6 +44,12 @@
 
 void make_directory(const std::string& dirname);
 
+//basic disk I/O
+std::string read_file(const std::string& fname);
+//throws io_exception if an error occurs
+void write_file(const std::string& fname, const std::string& data);
+std::string read_stdin();
+
 std::string read_map(const std::string& name);
 
 //function which returns true iff the given file is a directory
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.93 wesnoth/src/font.cpp:1.94
--- wesnoth/src/font.cpp:1.93   Sat Nov 27 10:24:50 2004
+++ wesnoth/src/font.cpp        Thu Dec 30 19:32:35 2004
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.93 2004/11/27 10:24:50 silene Exp $ */
+/* $Id: font.cpp,v 1.94 2004/12/30 19:32:35 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -13,8 +13,8 @@
 
 #include "global.hpp"
 
-#include "config.hpp"
 #include "font.hpp"
+#include "filesystem.hpp"
 #include "game_config.hpp"
 #include "language.hpp"
 #include "log.hpp"




reply via email to

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