diff --git a/ResourceFiles/ResourceFork.h b/ResourceFiles/ResourceFork.h index ece133d6ac..a7d01fc4a7 100644 --- a/ResourceFiles/ResourceFork.h +++ b/ResourceFiles/ResourceFork.h @@ -41,6 +41,8 @@ public: void writeFork(std::ostream& out) const; void addResource(Resource res) { resources[res.getTypeAndID()] = res; } void addResources(const Resources& res); + + unsigned countResources() const { return resources.size(); } }; #endif // RESOURCEFORK_H diff --git a/Rez/Rez.cc b/Rez/Rez.cc index 06a7c1208e..09dbb4f6ed 100644 --- a/Rez/Rez.cc +++ b/Rez/Rez.cc @@ -23,6 +23,21 @@ static void usage() std::cerr << desc << std::endl; } +static void CopyBinaryResources(RezWorld& world, const std::string& fn) +{ + ResourceFile copyRsrc(fn); + if(!copyRsrc.read()) + { + world.problem(Diagnostic(Diagnostic::error, "Could not read binary resource file " + fn, yy::location())); + } + else if(world.verboseFlag) + { + std::cerr << "Read " << copyRsrc.resources.countResources() << " resources from " << fn << "\n"; + } + + world.getResources().addResources(copyRsrc.resources); +} + int main(int argc, const char *argv[]) { desc.add_options() @@ -84,13 +99,8 @@ int main(int argc, const char *argv[]) world.getResources().addResources(rsrcFile.resources); } if(options.count("copy")) - for(std::string copyFile : options["copy"].as>()) - { - ResourceFile copyRsrc(copyFile); - - copyRsrc.read(); - world.getResources().addResources(copyRsrc.resources); - } + for(std::string fn : options["copy"].as>()) + CopyBinaryResources(world, fn); if(options.count("input")) for(std::string fn : options["input"].as>()) @@ -98,10 +108,7 @@ int main(int argc, const char *argv[]) fs::path path(fn); if(path.extension() == ".rsrc" || path.extension() == ".bin") { - ResourceFile copyRsrc(fn); - - copyRsrc.read(); - world.getResources().addResources(copyRsrc.resources); + CopyBinaryResources(world, fn); } else { @@ -116,6 +123,10 @@ int main(int argc, const char *argv[]) for(std::string path : options["include"].as>()) lexer.addIncludePath(path); + if(world.verboseFlag) + { + std::cerr << "Compiling " << fn << "...\n"; + } RezParser parser(lexer, world); parser.parse(); @@ -133,6 +144,11 @@ int main(int argc, const char *argv[]) rsrcFile.resources = world.getResources(); rsrcFile.creator = options["creator"].as(); rsrcFile.type = options["type"].as(); + + if(world.verboseFlag) + { + std::cerr << "Writing " << rsrcFile.resources.countResources() << " resources.\n"; + } rsrcFile.write(); if(options.count("cc")) diff --git a/Rez/RezLexer.cc b/Rez/RezLexer.cc index 33ed300711..702bfd595d 100644 --- a/Rez/RezLexer.cc +++ b/Rez/RezLexer.cc @@ -90,11 +90,24 @@ struct RezLexer::Priv } }; +static std::string readInitial(RezWorld& world, std::string filename) +{ + std::ifstream in(filename); + if(!in.is_open()) + { + world.problem(Diagnostic(Diagnostic::error, + "could not open " + filename, yy::location())); + } + return readContents(std::move(in)); +} + RezLexer::RezLexer(RezWorld& world, std::string filename) - : RezLexer(world, filename, readContents(std::ifstream(filename))) + : RezLexer(world, filename, readInitial(world,filename)) { } + + RezLexer::RezLexer(RezWorld& world, std::string filename, const std::string &data) : world(world), curFile(filename), lastLocation(&curFile) {