65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#include "parser.h"
|
|
#include "generator.h"
|
|
#include "picli.h"
|
|
|
|
using namespace PICoutManipulators;
|
|
|
|
|
|
void usage() {
|
|
piCout << Bold << "PIP Resources Compiler";
|
|
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
|
|
piCout << Green << Bold << "Usage:" << Default << "\"pirc [-h] -i <in_file> -o <out_file>\"" << NewLine;
|
|
piCout << Green << Bold << "Details:";
|
|
piCout << "-h --help " << Green << "- display this message and exit";
|
|
piCout << "-i --input <in_file> " << Green << "- resources description file";
|
|
piCout << "-o --out <out_file> " << Green << "- output .cpp file";
|
|
}
|
|
|
|
|
|
int main (int argc, char * argv[]) {
|
|
PICLI cli(argc, argv);
|
|
cli.addArgument("input", true);
|
|
cli.addArgument("out", true);
|
|
cli.addArgument("help");
|
|
|
|
if (!cli.hasArgument("input") ||
|
|
!cli.hasArgument("out") ||
|
|
cli.hasArgument("help")) {
|
|
usage();
|
|
return 0;
|
|
}
|
|
|
|
//piCout << "args:" << cli.rawArguments();
|
|
|
|
PIVector<ParserSection> files = parse(cli.argumentValue("input"));
|
|
if (files.isEmpty()) {
|
|
piCout << "Error: resources description file is empty";
|
|
return 0;
|
|
}
|
|
/*piForeachC (ParserSection & s, files) {
|
|
piCout << "[" << s.name << "]";
|
|
piCout << s.files;
|
|
}*/
|
|
|
|
PIString out_file = cli.argumentValue("out");
|
|
PIFile outf;
|
|
if (!out_file.isEmpty()) {
|
|
if (outf.open(out_file, PIIODevice::ReadWrite)) {
|
|
outf.clear();
|
|
} else piCout << "Error: while open out file";
|
|
outf << "// Generated by \"PIP Resources Compiler\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
|
outf << "// Execute command:\n";
|
|
piForeachC (PIString & _a, cli.rawArguments())
|
|
outf << "// \"" << _a << "\"\n";
|
|
outf << "\n";
|
|
//outf << "#include \"pivariant.h\"\n#include \"picodeinfo.h\"";
|
|
if (!generate(outf, files)) {
|
|
piCout << "Error: generate fail";
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|