From 7edb751727a176f58da886c2424d4840a0a910fd Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 17 Aug 2008 10:08:04 +0000 Subject: [PATCH] Convert all fstreams to IO::Files --- source/copy.cpp | 32 ++++++++---------- source/dependencycache.cpp | 36 +++++++++++--------- source/pkgconfigaction.cpp | 69 ++++++++++++++++++-------------------- source/sourcefile.cpp | 28 ++++++++++------ 4 files changed, 84 insertions(+), 81 deletions(-) diff --git a/source/copy.cpp b/source/copy.cpp index f8c581b..a08085d 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -6,11 +6,11 @@ Distributed under the LGPL */ #include -#include #include #include #include #include +#include #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 "< #include +#include +#include +#include #include #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<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 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 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 &) + { } } diff --git a/source/pkgconfigaction.cpp b/source/pkgconfigaction.cpp index b5678a9..23684f6 100644 --- a/source/pkgconfigaction.cpp +++ b/source/pkgconfigaction.cpp @@ -5,14 +5,16 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include #include #include +#include +#include #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="<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 "< #include #include +#include #include #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 "<=4) + cout<<"Reading includes from "<]"); + 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; -- 2.45.2