*/
#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"
}
}
- 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);
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"
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 &)
+ { }
}
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)
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()
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"
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;