]> git.tdb.fi Git - builder.git/commitdiff
Convert all fstreams to IO::Files
authorMikko Rasa <tdb@tdb.fi>
Sun, 17 Aug 2008 10:08:04 +0000 (10:08 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 17 Aug 2008 10:08:04 +0000 (10:08 +0000)
source/copy.cpp
source/dependencycache.cpp
source/pkgconfigaction.cpp
source/sourcefile.cpp

index f8c581bd5664ca123f4f657da77883c7dff1003b..a08085da42d7c09f9014ccd8c71e1fc749e67c5f 100644 (file)
@@ -6,11 +6,11 @@ Distributed under the LGPL
 */
 
 #include <errno.h>
-#include <fstream>
 #include <iostream>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/io/file.h>
 #include "builder.h"
 #include "copy.h"
 #include "package.h"
@@ -57,30 +57,26 @@ void Copy::Worker::main()
                }
        }
 
-       ifstream in(copy.src.str().c_str());
-       if(!in)
+       try
        {
-               cerr<<"Can't open "<<copy.src<<" for reading\n";
-               done=error=true;
-               return;
-       }
+               IO::File in(copy.src.str());
+               IO::File out(copy.dest.str(), IO::M_WRITE);
 
-       ofstream out(copy.dest.str().c_str());
-       if(!out)
+               // Actual transfer loop
+               char buf[16384];
+               while(!in.eof())
+               {
+                       unsigned len=in.read(buf, sizeof(buf));
+                       out.write(buf, len);
+               }
+       }
+       catch(const Exception &e)
        {
-               cerr<<"Can't open "<<copy.dest<<" for writing\n";
+               cerr<<e.what()<<'\n';
                done=error=true;
                return;
        }
 
-       // Actual transfer loop
-       char buf[16384];
-       while(!in.eof())
-       {
-               in.read(buf, sizeof(buf));
-               out.write(buf, in.gcount());
-       }
-
        // Preserve file permissions
        struct stat st=FS::stat(copy.src);
        chmod(copy.dest.str().c_str(), st.st_mode&0777);
index 978a0e37b8ccb3bb96d7a56d43f0b9248fb3dbd2..b2ba4e8ce953e9b92bd41d4c66443bf24c749237 100644 (file)
@@ -5,8 +5,10 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
-#include <fstream>
 #include <msp/fs/stat.h>
+#include <msp/io/except.h>
+#include <msp/io/file.h>
+#include <msp/io/print.h>
 #include <msp/strings/utils.h>
 #include "builder.h"
 #include "dependencycache.h"
@@ -44,32 +46,34 @@ void DependencyCache::save() const
        if(deps.empty() || !changed || package.get_builder().get_dry_run())
                return;
 
-       ofstream out((package.get_source()/".deps").str().c_str());
-       if(!out)
-               return;
+       IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE);
 
        for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i)
        {
-               out<<i->first;
+               IO::print(out, i->first);
                for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
-                       out<<'|'<<*j;
-               out<<'\n';
+                       IO::print(out, "|%s", *j);
+               IO::print(out, "\n");
        }
 }
 
 void DependencyCache::load()
 {
        string fn=(package.get_source()/".deps").str();
-       ifstream in(fn.c_str());
-       if(!in)
-               return;
 
-       string line;
-       while(getline(in, line))
+       try
        {
-               vector<string> parts=split(line, '|');
-               deps[parts[0]]=StringList(parts.begin()+1, parts.end());
-       }
+               IO::BufferedFile in(fn);
 
-       mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
+               string line;
+               while(in.getline(line))
+               {
+                       vector<string> parts=split(line, '|');
+                       deps[parts[0]]=StringList(parts.begin()+1, parts.end());
+               }
+
+               mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
+       }
+       catch(const IO::FileNotFound &)
+       { }
 }
index b5678a962684d50290f64d7e03353872c21ecb25..23684f653348c296705cd2b62c721c97640b8a68 100644 (file)
@@ -5,14 +5,16 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
-#include <fstream>
 #include <iostream>
 #include <msp/fs/utils.h>
+#include <msp/io/file.h>
+#include <msp/io/print.h>
 #include "package.h"
 #include "pkgconfig.h"
 #include "pkgconfigaction.h"
 
 using namespace std;
+using namespace Msp;
 
 PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p):
        Action(b)
@@ -21,45 +23,40 @@ PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p):
 
        announce(spkg.get_name(), "PC", relative(p.get_name(), spkg.get_source()).str());
 
-       ofstream out(p.get_name().c_str());
-       if(out)
-       {
-               // Prefix is already included in the various paths
-               //out<<"prefix="<<pkg.get_prefix()<<"\n\n";
-               out<<"source="<<spkg.get_source()<<"\n\n";
+       IO::BufferedFile out(p.get_name(), IO::M_WRITE);
+       // Prefix is already included in the various paths
+       //IO::print(out, "prefix=%s\n", pkg.get_prefix());
+       IO::print(out, "source=%s\n\n", spkg.get_source());
 
-               out<<"Name: "<<spkg.get_name()<<'\n';
-               out<<"Description: "<<spkg.get_description()<<'\n';
-               out<<"Version: "<<spkg.get_version()<<'\n';
+       IO::print(out, "Name: %s\n", spkg.get_name());
+       IO::print(out, "Description: %s\n", spkg.get_description());
+       IO::print(out, "Version: %s\n", spkg.get_version());
 
-               out<<"Requires:";
-               const PackageList &reqs=spkg.get_requires();
-               for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
-                       if((*i)->get_use_pkgconfig())
-                               out<<' '<<(*i)->get_name();
-               out<<'\n';
+       IO::print(out, "Requires:");
+       const PackageList &reqs=spkg.get_requires();
+       for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
+               if((*i)->get_use_pkgconfig())
+                       IO::print(out, " %s", (*i)->get_name());
+       out.put('\n');
 
-               const BuildInfo &binfo=spkg.get_exported_binfo();
-               out<<"Libs:";
-               for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
-                       out<<" -L"<<*i;
-               for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
-                       out<<" -l"<<*i;
-               for(StringList::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
-                       out<<' '<<*i;
-               out<<'\n';
+       const BuildInfo &binfo=spkg.get_exported_binfo();
+       IO::print(out, "Libs:");
+       for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
+               IO::print(out, " -L%s", *i);
+       for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
+               IO::print(out, " -l%s", *i);
+       for(StringList::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
+               IO::print(out, " %s", *i);
+       out.put('\n');
 
-               out<<"Cflags:";
-               for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
-                       out<<" -I"<<*i;
-               for(StringList::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
-                       out<<" -D"<<*i;
-               for(StringList::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
-                       out<<' '<<*i;
-               out<<'\n';
-       }
-       else
-               cerr<<"Can't open "<<p.get_name()<<" for writing\n";
+       IO::print(out, "Cflags:");
+       for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
+               IO::print(out, " -I%s", *i);
+       for(StringList::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+               IO::print(out, " -D%s", *i);
+       for(StringList::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
+               IO::print(out, " %s", *i);
+       out.put('\n');
 }
 
 int PkgConfigAction::check()
index 70410355652ab34cb7d522d0100ef62e30462eff..cf74356e72331e3f1a84c68f2afabc174f518d00 100644 (file)
@@ -5,9 +5,9 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
-#include <fstream>
 #include <iostream>
 #include <msp/fs/utils.h>
+#include <msp/io/except.h>
 #include <msp/strings/regex.h>
 #include "builder.h"
 #include "component.h"
@@ -48,20 +48,26 @@ void SourceFile::find_depends()
 
        if(!deps_found)
        {
-               ifstream in(name.c_str());
-               if(!in) return;
+               try
+               {
+                       IO::BufferedFile in(name);
 
-               if(builder.get_verbose()>=4)
-                       cout<<"Reading includes from "<<name<<'\n';
+                       if(builder.get_verbose()>=4)
+                               cout<<"Reading includes from "<<name<<'\n';
 
-               Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
+                       Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
 
-               string line;
-               while(getline(in, line))
-                       if(RegMatch match=r_include.match(line))
-                               includes.push_back(match[1].str);
+                       string line;
+                       while(in.getline(line))
+                               if(RegMatch match=r_include.match(line))
+                                       includes.push_back(match[1].str);
 
-               deps_cache.set_deps(relname, includes);
+                       deps_cache.set_deps(relname, includes);
+               }
+               catch(const IO::FileNotFound &)
+               {
+                       return;
+               }
        }
 
        const StringList &incpath=comp->get_build_info().incpath;