code format
This commit is contained in:
@@ -1,86 +1,83 @@
|
||||
#include "generator.h"
|
||||
#include "piresourcesstorage.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
|
||||
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 = 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) {
|
||||
PIFile f;
|
||||
if (!f.open(p.path, PIIODevice::ReadOnly)) continue;
|
||||
//piCout << "gen" << p.name << p.alias << p.path;
|
||||
fv << PIResourcesStorage::__RCEntry(s.name, p.name, p.alias, p.path);
|
||||
}
|
||||
}
|
||||
if (fv.isEmpty()) return false;
|
||||
PIIOTextStream ts(&file);
|
||||
ts << "#include \"piresourcesstorage.h\"\n\nstatic const uchar " << dataname << "[] = {\n";
|
||||
bool first = true;
|
||||
int rcnt = -1;
|
||||
llong curoff = 0, curfile = 0;
|
||||
piForeach (PIResourcesStorage::__RCEntry & e, fv) {
|
||||
e.offset = curoff;
|
||||
PIFile f;
|
||||
f.open(e.file, PIIODevice::ReadOnly);
|
||||
PIByteArray readed;
|
||||
curfile = 0;
|
||||
while (!f.isEnd()) {
|
||||
readed = f.read(4096);
|
||||
curfile += readed.size_s();
|
||||
for (int i = 0; i < readed.size_s(); ++i) {
|
||||
if (!first)
|
||||
ts << ',';
|
||||
first = false;
|
||||
if (++rcnt >= 32) {
|
||||
ts << '\n';
|
||||
rcnt = 0;
|
||||
}
|
||||
ts << int(readed[i]);
|
||||
}
|
||||
}
|
||||
e.size = curfile;
|
||||
curoff += curfile;
|
||||
}
|
||||
ts << "\n};\n";
|
||||
PIByteArray dba;
|
||||
dba << fv;
|
||||
ts << "\nstatic const uchar " << descname << "[] = {\n";
|
||||
first = true;
|
||||
rcnt = -1;
|
||||
for (int i = 0; i < dba.size_s(); ++i) {
|
||||
if (!first)
|
||||
ts << ',';
|
||||
first = false;
|
||||
if (++rcnt >= 32) {
|
||||
ts << '\n';
|
||||
rcnt = 0;
|
||||
}
|
||||
ts << int(dba[i]);
|
||||
}
|
||||
ts << "\n};\n";
|
||||
|
||||
ts << "\nvoid " << funcname << "() {\n";
|
||||
ts << "\tPIResourcesStorage::instance()->registerSection(" << dataname << ", " << descname << ", sizeof(" << descname << "));\n";
|
||||
ts << "}\n";
|
||||
|
||||
ts << "\nclass " << icname << " {\n";
|
||||
ts << "public:\n\t" << icname << "() {\n";
|
||||
ts << "\t\t" << funcname << "();\n";
|
||||
ts << "\t}\n";
|
||||
ts << "} _pirc_" << fcname << "_initializer_;\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "generator.h"
|
||||
|
||||
#include "piiostream.h"
|
||||
#include "piresourcesstorage.h"
|
||||
|
||||
|
||||
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 = 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) {
|
||||
PIFile f;
|
||||
if (!f.open(p.path, PIIODevice::ReadOnly)) continue;
|
||||
// piCout << "gen" << p.name << p.alias << p.path;
|
||||
fv << PIResourcesStorage::__RCEntry(s.name, p.name, p.alias, p.path);
|
||||
}
|
||||
}
|
||||
if (fv.isEmpty()) return false;
|
||||
PIIOTextStream ts(&file);
|
||||
ts << "#include \"piresourcesstorage.h\"\n\nstatic const uchar " << dataname << "[] = {\n";
|
||||
bool first = true;
|
||||
int rcnt = -1;
|
||||
llong curoff = 0, curfile = 0;
|
||||
piForeach(PIResourcesStorage::__RCEntry & e, fv) {
|
||||
e.offset = curoff;
|
||||
PIFile f;
|
||||
f.open(e.file, PIIODevice::ReadOnly);
|
||||
PIByteArray readed;
|
||||
curfile = 0;
|
||||
while (!f.isEnd()) {
|
||||
readed = f.read(4096);
|
||||
curfile += readed.size_s();
|
||||
for (int i = 0; i < readed.size_s(); ++i) {
|
||||
if (!first) ts << ',';
|
||||
first = false;
|
||||
if (++rcnt >= 32) {
|
||||
ts << '\n';
|
||||
rcnt = 0;
|
||||
}
|
||||
ts << int(readed[i]);
|
||||
}
|
||||
}
|
||||
e.size = curfile;
|
||||
curoff += curfile;
|
||||
}
|
||||
ts << "\n};\n";
|
||||
PIByteArray dba;
|
||||
dba << fv;
|
||||
ts << "\nstatic const uchar " << descname << "[] = {\n";
|
||||
first = true;
|
||||
rcnt = -1;
|
||||
for (int i = 0; i < dba.size_s(); ++i) {
|
||||
if (!first) ts << ',';
|
||||
first = false;
|
||||
if (++rcnt >= 32) {
|
||||
ts << '\n';
|
||||
rcnt = 0;
|
||||
}
|
||||
ts << int(dba[i]);
|
||||
}
|
||||
ts << "\n};\n";
|
||||
|
||||
ts << "\nvoid " << funcname << "() {\n";
|
||||
ts << "\tPIResourcesStorage::instance()->registerSection(" << dataname << ", " << descname << ", sizeof(" << descname << "));\n";
|
||||
ts << "}\n";
|
||||
|
||||
ts << "\nclass " << icname << " {\n";
|
||||
ts << "public:\n\t" << icname << "() {\n";
|
||||
ts << "\t\t" << funcname << "();\n";
|
||||
ts << "\t}\n";
|
||||
ts << "} _pirc_" << fcname << "_initializer_;\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef PIRC_GENERATOR_H
|
||||
#define PIRC_GENERATOR_H
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
PIString initName(const PIString & n);
|
||||
bool generate(const PIString & init_name, PIFile & file, const PIVector<ParserSection> & files);
|
||||
|
||||
#endif // PIRC_GENERATOR_H
|
||||
#ifndef PIRC_GENERATOR_H
|
||||
#define PIRC_GENERATOR_H
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
PIString initName(const PIString & n);
|
||||
bool generate(const PIString & init_name, PIFile & file, const PIVector<ParserSection> & files);
|
||||
|
||||
#endif // PIRC_GENERATOR_H
|
||||
|
||||
@@ -1,98 +1,95 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Resources compiller
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "parser.h"
|
||||
#include "generator.h"
|
||||
#include "picli.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
|
||||
void usage() {
|
||||
piCout << Bold << "PIP Resources Compiler";
|
||||
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
|
||||
piCout << Green << Bold << "Usage:" << Default << "\"pip_rc [-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";
|
||||
piCout << "-s --silent " << Green << "- no console output";
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
cli.addArgument("silent");
|
||||
|
||||
if (cli.hasArgument("silent"))
|
||||
piDebug = false;
|
||||
if (cli.hasArgument("help") || !cli.hasArgument("input") ||
|
||||
(!cli.hasArgument("out") && !cli.hasArgument("list"))) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
PIVector<ParserSection> files = parse(cli.argumentValue("input"));
|
||||
if (files.isEmpty()) {
|
||||
piCout << "Error: resources description file is empty";
|
||||
return 0;
|
||||
}
|
||||
if (cli.hasArgument("list")) {
|
||||
piForeachC (ParserSection & s, files) {
|
||||
piForeachC (ParserEntry & e, s.files) {
|
||||
piCout << e.path;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)) {
|
||||
outf.clear();
|
||||
} else {
|
||||
piCout << "Error: can`t open out file" << out_file;
|
||||
return 1;
|
||||
}
|
||||
PIIOTextStream ts(&outf);
|
||||
ts << "// Generated by \"PIP Resources Compiler\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
||||
ts << "// Execute command:\n";
|
||||
piForeachC (PIString & _a, cli.rawArguments())
|
||||
ts << "// \"" << _a << "\"\n";
|
||||
ts << "\n";
|
||||
if (!generate(init_name, outf, files)) {
|
||||
piCout << "Error: generate fail";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Resources compiller
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "generator.h"
|
||||
#include "parser.h"
|
||||
#include "picli.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
|
||||
void usage() {
|
||||
piCout << Bold << "PIP Resources Compiler";
|
||||
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
|
||||
piCout << Green << Bold << "Usage:" << Default << "\"pip_rc [-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";
|
||||
piCout << "-s --silent " << Green << "- no console output";
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
cli.addArgument("silent");
|
||||
|
||||
if (cli.hasArgument("silent")) piDebug = false;
|
||||
if (cli.hasArgument("help") || !cli.hasArgument("input") || (!cli.hasArgument("out") && !cli.hasArgument("list"))) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
PIVector<ParserSection> files = parse(cli.argumentValue("input"));
|
||||
if (files.isEmpty()) {
|
||||
piCout << "Error: resources description file is empty";
|
||||
return 0;
|
||||
}
|
||||
if (cli.hasArgument("list")) {
|
||||
piForeachC(ParserSection & s, files) {
|
||||
piForeachC(ParserEntry & e, s.files) {
|
||||
piCout << e.path;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)) {
|
||||
outf.clear();
|
||||
} else {
|
||||
piCout << "Error: can`t open out file" << out_file;
|
||||
return 1;
|
||||
}
|
||||
PIIOTextStream ts(&outf);
|
||||
ts << "// Generated by \"PIP Resources Compiler\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
||||
ts << "// Execute command:\n";
|
||||
piForeachC(PIString & _a, cli.rawArguments())
|
||||
ts << "// \"" << _a << "\"\n";
|
||||
ts << "\n";
|
||||
if (!generate(init_name, outf, files)) {
|
||||
piCout << "Error: generate fail";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,121 +1,119 @@
|
||||
#include "parser.h"
|
||||
#include "piconfig.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
|
||||
PIVector<ParserSection> parse(const PIString & path) {
|
||||
PIVector<ParserSection> ret;
|
||||
PIFile f;
|
||||
if (!f.open(path, PIIODevice::ReadOnly))
|
||||
return ret;
|
||||
PIString ext = f.fileInfo().extension().toLowerCase();
|
||||
PIString dir = PIDir(f.fileInfo().dir()).absolutePath() + "/";
|
||||
//piCout << dir;
|
||||
if (ext == "conf") return parseConf(f, dir);
|
||||
if (ext == "qrc") return parseQRC(f, dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ParserEntry makeEntry(PIString filename, const PIString & dir) {
|
||||
ParserEntry ret;
|
||||
ret.path = filename;
|
||||
if (!PIDir(PIFile::fileInfo(filename).dir()).isAbsolute()) {
|
||||
//piCout << "rel, add dir";
|
||||
ret.path.insert(0, dir);
|
||||
}
|
||||
//piCout << line << path;
|
||||
ret.name = filename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
||||
PIVector<ParserSection> ret;
|
||||
if (!file.isOpened()) return ret;
|
||||
PIIOTextStream ts(&file);
|
||||
ParserSection ps;
|
||||
while (!ts.isEnd()) {
|
||||
PIString line = ts.readLine().trim();
|
||||
if (line.isEmpty()) continue;
|
||||
if (line.startsWith("[") && line.endsWith("]")) {
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
ps.name = line.cutLeft(1).cutRight(1).trim();
|
||||
ps.files.clear();
|
||||
continue;
|
||||
}
|
||||
PIString alias;
|
||||
int i = line.findLast("=");
|
||||
if (i > 0) {
|
||||
alias = line.takeMid(i + 1).trim();
|
||||
line.cutRight(1).trim();
|
||||
}
|
||||
ParserEntry e = makeEntry(line, dir);
|
||||
if (!alias.isEmpty())
|
||||
e.alias = alias;
|
||||
ps.files << e;
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir) {
|
||||
PIVector<ParserSection> ret;
|
||||
if (!file.isOpened()) return ret;
|
||||
PIIOTextStream ts(&file);
|
||||
ParserSection ps;
|
||||
bool is_files = false;
|
||||
while (!ts.isEnd()) {
|
||||
PIString line = ts.readLine().trim();
|
||||
if (line.isEmpty()) continue;
|
||||
if (line.startsWith("<qresource")) {
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
ps.name.clear();
|
||||
ps.files.clear();
|
||||
line.cutLeft(10);
|
||||
if (line.endsWith(">")) line.cutRight(1);
|
||||
line.trim();
|
||||
if (line.endsWith("/")) {
|
||||
is_files = false;
|
||||
continue;
|
||||
}
|
||||
is_files = true;
|
||||
if (line.startsWith("prefix")) {
|
||||
int i = line.find("=");
|
||||
if (i > 0) {
|
||||
line.cutLeft(i + 1).trim();
|
||||
if (line.startsWith("\"")) line.cutLeft(1);
|
||||
if (line.endsWith("\"")) line.cutRight(1);
|
||||
ps.name = line;
|
||||
}
|
||||
}
|
||||
//piCout << "section \"" << ps.name << "\"";
|
||||
continue;
|
||||
}
|
||||
if (line == "</qresource>") {
|
||||
is_files = false;
|
||||
continue;
|
||||
}
|
||||
if (!is_files) continue;
|
||||
if (!line.startsWith("<file")) continue;
|
||||
PIString alias = line.takeRange('<', '>', '\0');
|
||||
alias.cutLeft(4).trim();
|
||||
if (alias.startsWith("alias")) {
|
||||
int i = alias.find("=");
|
||||
if (i > 0) {
|
||||
alias.cutLeft(i + 1).trim();
|
||||
if (alias.startsWith("\"")) alias.cutLeft(1);
|
||||
if (alias.endsWith("\"")) alias.cutRight(1);
|
||||
}
|
||||
}
|
||||
if (line.endsWith("</file>")) line.cutRight(7).trim();
|
||||
ParserEntry e = makeEntry(line, dir);
|
||||
if (!alias.isEmpty())
|
||||
e.alias = alias;
|
||||
ps.files << e;
|
||||
//piCout << "file =" << line << "alias =" << alias;
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
}
|
||||
#include "parser.h"
|
||||
|
||||
#include "piconfig.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
|
||||
PIVector<ParserSection> parse(const PIString & path) {
|
||||
PIVector<ParserSection> ret;
|
||||
PIFile f;
|
||||
if (!f.open(path, PIIODevice::ReadOnly)) return ret;
|
||||
PIString ext = f.fileInfo().extension().toLowerCase();
|
||||
PIString dir = PIDir(f.fileInfo().dir()).absolutePath() + "/";
|
||||
// piCout << dir;
|
||||
if (ext == "conf") return parseConf(f, dir);
|
||||
if (ext == "qrc") return parseQRC(f, dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ParserEntry makeEntry(PIString filename, const PIString & dir) {
|
||||
ParserEntry ret;
|
||||
ret.path = filename;
|
||||
if (!PIDir(PIFile::fileInfo(filename).dir()).isAbsolute()) {
|
||||
// piCout << "rel, add dir";
|
||||
ret.path.insert(0, dir);
|
||||
}
|
||||
// piCout << line << path;
|
||||
ret.name = filename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
||||
PIVector<ParserSection> ret;
|
||||
if (!file.isOpened()) return ret;
|
||||
PIIOTextStream ts(&file);
|
||||
ParserSection ps;
|
||||
while (!ts.isEnd()) {
|
||||
PIString line = ts.readLine().trim();
|
||||
if (line.isEmpty()) continue;
|
||||
if (line.startsWith("[") && line.endsWith("]")) {
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
ps.name = line.cutLeft(1).cutRight(1).trim();
|
||||
ps.files.clear();
|
||||
continue;
|
||||
}
|
||||
PIString alias;
|
||||
int i = line.findLast("=");
|
||||
if (i > 0) {
|
||||
alias = line.takeMid(i + 1).trim();
|
||||
line.cutRight(1).trim();
|
||||
}
|
||||
ParserEntry e = makeEntry(line, dir);
|
||||
if (!alias.isEmpty()) e.alias = alias;
|
||||
ps.files << e;
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir) {
|
||||
PIVector<ParserSection> ret;
|
||||
if (!file.isOpened()) return ret;
|
||||
PIIOTextStream ts(&file);
|
||||
ParserSection ps;
|
||||
bool is_files = false;
|
||||
while (!ts.isEnd()) {
|
||||
PIString line = ts.readLine().trim();
|
||||
if (line.isEmpty()) continue;
|
||||
if (line.startsWith("<qresource")) {
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
ps.name.clear();
|
||||
ps.files.clear();
|
||||
line.cutLeft(10);
|
||||
if (line.endsWith(">")) line.cutRight(1);
|
||||
line.trim();
|
||||
if (line.endsWith("/")) {
|
||||
is_files = false;
|
||||
continue;
|
||||
}
|
||||
is_files = true;
|
||||
if (line.startsWith("prefix")) {
|
||||
int i = line.find("=");
|
||||
if (i > 0) {
|
||||
line.cutLeft(i + 1).trim();
|
||||
if (line.startsWith("\"")) line.cutLeft(1);
|
||||
if (line.endsWith("\"")) line.cutRight(1);
|
||||
ps.name = line;
|
||||
}
|
||||
}
|
||||
// piCout << "section \"" << ps.name << "\"";
|
||||
continue;
|
||||
}
|
||||
if (line == "</qresource>") {
|
||||
is_files = false;
|
||||
continue;
|
||||
}
|
||||
if (!is_files) continue;
|
||||
if (!line.startsWith("<file")) continue;
|
||||
PIString alias = line.takeRange('<', '>', '\0');
|
||||
alias.cutLeft(4).trim();
|
||||
if (alias.startsWith("alias")) {
|
||||
int i = alias.find("=");
|
||||
if (i > 0) {
|
||||
alias.cutLeft(i + 1).trim();
|
||||
if (alias.startsWith("\"")) alias.cutLeft(1);
|
||||
if (alias.endsWith("\"")) alias.cutRight(1);
|
||||
}
|
||||
}
|
||||
if (line.endsWith("</file>")) line.cutRight(7).trim();
|
||||
ParserEntry e = makeEntry(line, dir);
|
||||
if (!alias.isEmpty()) e.alias = alias;
|
||||
ps.files << e;
|
||||
// piCout << "file =" << line << "alias =" << alias;
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#ifndef PIRC_PARSER_H
|
||||
#define PIRC_PARSER_H
|
||||
|
||||
#include "pidir.h"
|
||||
#include "pifile.h"
|
||||
|
||||
struct ParserEntry {
|
||||
ParserEntry(const PIString & n = PIString(), const PIString & a = PIString(), const PIString & p = PIString()) {
|
||||
name = n;
|
||||
alias = a;
|
||||
path = p;
|
||||
}
|
||||
PIString name;
|
||||
PIString alias;
|
||||
PIString path;
|
||||
};
|
||||
|
||||
struct ParserSection {
|
||||
PIString name;
|
||||
PIVector<ParserEntry> files;
|
||||
};
|
||||
|
||||
PIVector<ParserSection> parse(const PIString & path);
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir);
|
||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir);
|
||||
|
||||
#endif // PIRC_PARSER_H
|
||||
#ifndef PIRC_PARSER_H
|
||||
#define PIRC_PARSER_H
|
||||
|
||||
#include "pidir.h"
|
||||
#include "pifile.h"
|
||||
|
||||
struct ParserEntry {
|
||||
ParserEntry(const PIString & n = PIString(), const PIString & a = PIString(), const PIString & p = PIString()) {
|
||||
name = n;
|
||||
alias = a;
|
||||
path = p;
|
||||
}
|
||||
PIString name;
|
||||
PIString alias;
|
||||
PIString path;
|
||||
};
|
||||
|
||||
struct ParserSection {
|
||||
PIString name;
|
||||
PIVector<ParserEntry> files;
|
||||
};
|
||||
|
||||
PIVector<ParserSection> parse(const PIString & path);
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir);
|
||||
PIVector<ParserSection> parseQRC(PIFile & file, const PIString & dir);
|
||||
|
||||
#endif // PIRC_PARSER_H
|
||||
|
||||
Reference in New Issue
Block a user