2014-10-05 21:52:34 +00:00
|
|
|
#include <iostream>
|
2014-10-09 20:15:13 +00:00
|
|
|
#include "boost/program_options.hpp"
|
|
|
|
#include "boost/filesystem.hpp"
|
|
|
|
#include "boost/filesystem/fstream.hpp"
|
2014-10-05 21:52:34 +00:00
|
|
|
|
|
|
|
#include "RezParser.generated.hh"
|
|
|
|
#include "RezLexer.h"
|
2014-10-07 18:15:46 +00:00
|
|
|
#include "RezWorld.h"
|
2014-10-05 21:52:34 +00:00
|
|
|
|
2014-10-08 00:52:34 +00:00
|
|
|
#include "ResourceFiles.h"
|
|
|
|
#include "BinaryIO.h"
|
|
|
|
|
2014-10-09 20:15:13 +00:00
|
|
|
namespace po = boost::program_options;
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
|
|
|
static po::options_description desc;
|
|
|
|
|
|
|
|
static void usage()
|
|
|
|
{
|
|
|
|
std::cerr << "Usage: " << "Rez [options] input-file\n";
|
|
|
|
std::cerr << desc << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[])
|
2014-10-05 21:52:34 +00:00
|
|
|
{
|
2014-10-09 20:15:13 +00:00
|
|
|
desc.add_options()
|
|
|
|
("help,h", "show this help message")
|
|
|
|
("output,o", po::value<std::string>()->default_value("rez.output.rsrc"), "output file")
|
|
|
|
("type,t", po::value<std::string>()->default_value("rsrc"), "output file finder type code")
|
|
|
|
("creator,c", po::value<std::string>()->default_value("RSED"), "output file finder creator code")
|
2014-10-16 00:26:41 +00:00
|
|
|
("define,D", po::value<std::vector<std::string>>(), "predefine preprocessor symbol")
|
|
|
|
("include,I", po::value<std::vector<std::string>>(), "add include file path")
|
2014-10-09 20:15:13 +00:00
|
|
|
("debug,d", "debug logging")
|
|
|
|
;
|
|
|
|
po::options_description hidden, alldesc;
|
|
|
|
hidden.add_options()
|
|
|
|
("input", po::value<std::vector<std::string>>(), "input file" )
|
|
|
|
;
|
|
|
|
alldesc.add(desc).add(hidden);
|
|
|
|
|
|
|
|
po::variables_map options;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto parsed = po::command_line_parser(argc, argv)
|
|
|
|
.options(alldesc)
|
|
|
|
.positional(po::positional_options_description().add("input", -1))
|
|
|
|
.style(po::command_line_style::default_style |
|
|
|
|
po::command_line_style::allow_long_disguise)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
po::store(parsed, options);
|
|
|
|
}
|
|
|
|
catch(po::error& e)
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
po::notify(options);
|
|
|
|
|
|
|
|
if(options.count("help") || !options.count("input"))
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-07 18:15:46 +00:00
|
|
|
RezWorld world;
|
2014-10-05 21:52:34 +00:00
|
|
|
|
2014-10-09 20:15:13 +00:00
|
|
|
if(options.count("debug"))
|
|
|
|
world.verboseFlag = true;
|
|
|
|
|
|
|
|
for(std::string fn : options["input"].as<std::vector<std::string>>())
|
|
|
|
{
|
|
|
|
RezLexer lexer(fn);
|
2014-10-16 00:26:41 +00:00
|
|
|
|
|
|
|
for(std::string define : options["define"].as<std::vector<std::string>>())
|
|
|
|
lexer.addDefine(define);
|
|
|
|
for(std::string path : options["include"].as<std::vector<std::string>>())
|
|
|
|
lexer.addIncludePath(path);
|
|
|
|
|
|
|
|
|
2014-10-09 20:15:13 +00:00
|
|
|
RezParser parser(lexer, world);
|
|
|
|
parser.parse();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string outfile = options["output"].as<std::string>();
|
2014-10-08 00:52:34 +00:00
|
|
|
{
|
2014-10-09 20:15:13 +00:00
|
|
|
fs::path dataPath(outfile);
|
|
|
|
fs::create_directory(dataPath.parent_path() / ".rsrc");
|
|
|
|
fs::create_directory(dataPath.parent_path() / ".finf");
|
|
|
|
fs::ofstream dataOut(dataPath);
|
|
|
|
fs::ofstream rsrcOut(dataPath.parent_path() / ".rsrc" / dataPath.filename());
|
|
|
|
fs::ofstream finfOut(dataPath.parent_path() / ".finf" / dataPath.filename());
|
2014-10-08 00:52:34 +00:00
|
|
|
|
|
|
|
world.getResources().writeFork(rsrcOut);
|
2014-10-09 20:15:13 +00:00
|
|
|
ostype(finfOut, options["type"].as<std::string>());
|
|
|
|
ostype(finfOut, options["creator"].as<std::string>());
|
2014-10-08 00:52:34 +00:00
|
|
|
for(int i = 8; i < 32; i++)
|
|
|
|
byte(finfOut, 0);
|
|
|
|
}
|
2014-10-05 21:52:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|