git-svn-id: svn://db.shs.com.ru/pip@644 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -2,13 +2,19 @@
|
||||
#include "piresourcesstorage.h"
|
||||
|
||||
|
||||
bool generate(PIFile & file, const PIVector<ParserSection> & files) {
|
||||
PIString initName(const PIString & n) {
|
||||
return PIFile::fileInfo(n).baseName().replaceAll(".", "_").replaceAll("/", "_")
|
||||
.replaceAll(":", "_").replaceAll("-", "_");
|
||||
}
|
||||
|
||||
|
||||
bool generate(const PIString & init_name, PIFile & file, const PIVector<ParserSection> & files) {
|
||||
if (!file.isOpened()) return false;
|
||||
PIString fcname = file.fileInfo().baseName().replaceAll(".", "_").replaceAll("/", "_")
|
||||
.replaceAll(":", "_").replaceAll("-", "_");//.toUpperCase() + "_H";
|
||||
PIString fcname = initName(file.path());
|
||||
PIString icname = "_PIRC_" + fcname + "_Initializer_";
|
||||
PIString dataname = "_pirc_" + fcname + "_data_";
|
||||
PIString descname = "_pirc_" + fcname + "_desc_";
|
||||
PIString funcname = "_pirc_" + init_name + "_init_";
|
||||
PIVector<PIResourcesStorage::__RCEntry> fv;
|
||||
piForeachC (ParserSection & s, files) {
|
||||
piForeachC (ParserEntry & p, s.files) {
|
||||
@@ -63,10 +69,16 @@ bool generate(PIFile & file, const PIVector<ParserSection> & files) {
|
||||
file << int(dba[i]);
|
||||
}
|
||||
file << "\n};\n";
|
||||
|
||||
file << "\nvoid " << funcname << "() {\n";
|
||||
file << "\tPIResourcesStorage::instance()->registerSection(" << dataname << ", " << descname << ", sizeof(" << descname << "));\n";
|
||||
file << "}\n";
|
||||
|
||||
file << "\nclass " << icname << " {\n";
|
||||
file << "public:\n\t" << icname << "() {\n";
|
||||
file << "\t\tPIResourcesStorage::instance()->registerSection(" << dataname << ", " << descname << ", sizeof(" << descname << "));\n";
|
||||
file << "\t\t" << funcname << "();\n";
|
||||
file << "\t}\n";
|
||||
file << "} _pirc_" << fcname << "_initializer_;\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
bool generate(PIFile & file, const PIVector<ParserSection> & files);
|
||||
PIString initName(const PIString & n);
|
||||
bool generate(const PIString & init_name, PIFile & file, const PIVector<ParserSection> & files);
|
||||
|
||||
#endif // PIRC_GENERATOR_H
|
||||
|
||||
@@ -8,9 +8,10 @@ using namespace PICoutManipulators;
|
||||
void usage() {
|
||||
piCout << Bold << "PIP Resources Compiler";
|
||||
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
|
||||
piCout << Green << Bold << "Usage:" << Default << "\"pirc [-hl] -i <in_file> -o <out_file>\"" << NewLine;
|
||||
piCout << Green << Bold << "Usage:" << Default << "\"pirc [-hl] [-n <name>] -i <in_file> -o <out_file>\"" << NewLine;
|
||||
piCout << Green << Bold << "Details:";
|
||||
piCout << "-h --help " << Green << "- display this message and exit";
|
||||
piCout << "-n --name <name> " << Green << "- name of initialize function, by default is <out_file> base name";
|
||||
piCout << "-i --input <in_file> " << Green << "- resources description file";
|
||||
piCout << "-o --out <out_file> " << Green << "- output .cpp file";
|
||||
piCout << "-l --list " << Green << "- print readed files from description and exit";
|
||||
@@ -21,6 +22,7 @@ int main (int argc, char * argv[]) {
|
||||
PICLI cli(argc, argv);
|
||||
cli.addArgument("input", true);
|
||||
cli.addArgument("out", true);
|
||||
cli.addArgument("name", true);
|
||||
cli.addArgument("help");
|
||||
cli.addArgument("list");
|
||||
|
||||
@@ -47,6 +49,8 @@ int main (int argc, char * argv[]) {
|
||||
}
|
||||
|
||||
PIString out_file = cli.argumentValue("out");
|
||||
PIString init_name = cli.argumentValue("name");
|
||||
init_name = initName(init_name.isEmpty() ? out_file : init_name);
|
||||
PIFile outf;
|
||||
if (!out_file.isEmpty()) {
|
||||
if (outf.open(out_file, PIIODevice::ReadWrite)) {
|
||||
@@ -58,7 +62,7 @@ int main (int argc, char * argv[]) {
|
||||
outf << "// \"" << _a << "\"\n";
|
||||
outf << "\n";
|
||||
//outf << "#include \"pivariant.h\"\n#include \"picodeinfo.h\"";
|
||||
if (!generate(outf, files)) {
|
||||
if (!generate(init_name, outf, files)) {
|
||||
piCout << "Error: generate fail";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user