Rez: properly report file-not-found errors

This commit is contained in:
Wolfgang Thaller 2015-08-27 20:49:55 +02:00
parent bdf3be1d65
commit 6a05091d37
3 changed files with 43 additions and 12 deletions

View File

@ -41,6 +41,8 @@ public:
void writeFork(std::ostream& out) const; void writeFork(std::ostream& out) const;
void addResource(Resource res) { resources[res.getTypeAndID()] = res; } void addResource(Resource res) { resources[res.getTypeAndID()] = res; }
void addResources(const Resources& res); void addResources(const Resources& res);
unsigned countResources() const { return resources.size(); }
}; };
#endif // RESOURCEFORK_H #endif // RESOURCEFORK_H

View File

@ -23,6 +23,21 @@ static void usage()
std::cerr << desc << std::endl; 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[]) int main(int argc, const char *argv[])
{ {
desc.add_options() desc.add_options()
@ -84,13 +99,8 @@ int main(int argc, const char *argv[])
world.getResources().addResources(rsrcFile.resources); world.getResources().addResources(rsrcFile.resources);
} }
if(options.count("copy")) if(options.count("copy"))
for(std::string copyFile : options["copy"].as<std::vector<std::string>>()) for(std::string fn : options["copy"].as<std::vector<std::string>>())
{ CopyBinaryResources(world, fn);
ResourceFile copyRsrc(copyFile);
copyRsrc.read();
world.getResources().addResources(copyRsrc.resources);
}
if(options.count("input")) if(options.count("input"))
for(std::string fn : options["input"].as<std::vector<std::string>>()) for(std::string fn : options["input"].as<std::vector<std::string>>())
@ -98,10 +108,7 @@ int main(int argc, const char *argv[])
fs::path path(fn); fs::path path(fn);
if(path.extension() == ".rsrc" || path.extension() == ".bin") if(path.extension() == ".rsrc" || path.extension() == ".bin")
{ {
ResourceFile copyRsrc(fn); CopyBinaryResources(world, fn);
copyRsrc.read();
world.getResources().addResources(copyRsrc.resources);
} }
else else
{ {
@ -116,6 +123,10 @@ int main(int argc, const char *argv[])
for(std::string path : options["include"].as<std::vector<std::string>>()) for(std::string path : options["include"].as<std::vector<std::string>>())
lexer.addIncludePath(path); lexer.addIncludePath(path);
if(world.verboseFlag)
{
std::cerr << "Compiling " << fn << "...\n";
}
RezParser parser(lexer, world); RezParser parser(lexer, world);
parser.parse(); parser.parse();
@ -133,6 +144,11 @@ int main(int argc, const char *argv[])
rsrcFile.resources = world.getResources(); rsrcFile.resources = world.getResources();
rsrcFile.creator = options["creator"].as<std::string>(); rsrcFile.creator = options["creator"].as<std::string>();
rsrcFile.type = options["type"].as<std::string>(); rsrcFile.type = options["type"].as<std::string>();
if(world.verboseFlag)
{
std::cerr << "Writing " << rsrcFile.resources.countResources() << " resources.\n";
}
rsrcFile.write(); rsrcFile.write();
if(options.count("cc")) if(options.count("cc"))

View File

@ -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::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) RezLexer::RezLexer(RezWorld& world, std::string filename, const std::string &data)
: world(world), curFile(filename), lastLocation(&curFile) : world(world), curFile(filename), lastLocation(&curFile)
{ {