git-svn-id: svn://db.shs.com.ru/pip@557 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -335,6 +335,18 @@ bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
case FFTW: return
|
||||
#ifdef PIP_FFTW
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
case Compress: return
|
||||
#ifdef PIP_COMPRESS
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
default: return false;
|
||||
}
|
||||
@@ -342,6 +354,20 @@ bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
|
||||
}
|
||||
|
||||
|
||||
PIStringList PIInit::buildOptions() {
|
||||
PIStringList ret;
|
||||
if (isBuildOptionEnabled(ICU)) ret << "ICU";
|
||||
if (isBuildOptionEnabled(USB)) ret << "USB";
|
||||
if (isBuildOptionEnabled(STL)) ret << "STL";
|
||||
if (isBuildOptionEnabled(Crypt)) ret << "Crypt";
|
||||
if (isBuildOptionEnabled(IntrospectionContainers)) ret << "IntrospectionContainers";
|
||||
if (isBuildOptionEnabled(IntrospectionThreads)) ret << "IntrospectionThreads";
|
||||
if (isBuildOptionEnabled(FFTW)) ret << "FFTW";
|
||||
if (isBuildOptionEnabled(Compress)) ret << "Compress";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIInit::setFileCharset(const char *charset) {
|
||||
if (file_charset) delete file_charset;
|
||||
file_charset = 0;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
|
||||
class PIFile;
|
||||
class PIStringList;
|
||||
|
||||
|
||||
class __PIInit_Initializer__ {
|
||||
@@ -51,10 +52,13 @@ public:
|
||||
STL /*! STL containers implementation */ = 0x04,
|
||||
Crypt /*! Crypt support */ = 0x08,
|
||||
IntrospectionContainers /*! Containers introspection */ = 0x010,
|
||||
IntrospectionThreads /*! Threads introspection */ = 0x20
|
||||
IntrospectionThreads /*! Threads introspection */ = 0x20,
|
||||
FFTW /*! FFTW3 support */ = 0x40,
|
||||
Compress /*! Zlib compression support */ = 0x80,
|
||||
};
|
||||
static PIInit * instance() {return __PIInit_Initializer__::__instance__;}
|
||||
static bool isBuildOptionEnabled(BuildOption o);
|
||||
static PIStringList buildOptions();
|
||||
private:
|
||||
void setFileCharset(const char *charset);
|
||||
bool fileExists(const PIString & p);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
class PIResources {
|
||||
public:
|
||||
|
||||
//! Encrypt given data "data", result size will be increased by \a sizeCrypt()
|
||||
//!
|
||||
static PIByteArray get(const PIString & section, const PIString & name);
|
||||
static PIByteArray get(const PIString & name);
|
||||
|
||||
|
||||
9
utils/resources_compiler/CMakeLists.txt
Normal file
9
utils/resources_compiler/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
message(STATUS "Building pip_rc")
|
||||
file(GLOB CPPS "*.cpp")
|
||||
file(GLOB HDRS "*.h")
|
||||
add_executable(pip_rc ${CPPS} ${HDRS})
|
||||
set (PIRC_LIBS pip)
|
||||
target_link_libraries(pip_rc ${PIRC_LIBS})
|
||||
if (DEFINED LIB)
|
||||
install(TARGETS pip_rc DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
endif ()
|
||||
72
utils/resources_compiler/generator.cpp
Normal file
72
utils/resources_compiler/generator.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "generator.h"
|
||||
#include "piresourcesstorage.h"
|
||||
|
||||
typedef PIPair<PIString, PIString> SSPair;
|
||||
|
||||
bool generate(PIFile & file, const PIVector<ParserSection> & files) {
|
||||
if (!file.isOpened()) return false;
|
||||
PIString fcname = file.fileInfo().baseName().replaceAll(".", "_").replaceAll("/", "_")
|
||||
.replaceAll(":", "_").replaceAll("-", "_");//.toUpperCase() + "_H";
|
||||
PIString icname = "_PIRC_" + fcname + "_Initializer_";
|
||||
PIString dataname = "_pirc_" + fcname + "_data_";
|
||||
PIString descname = "_pirc_" + fcname + "_desc_";
|
||||
PIVector<PIResourcesStorage::__RCEntry> fv;
|
||||
piForeachC (ParserSection & s, files) {
|
||||
piForeachC (SSPair & p, s.files) {
|
||||
PIFile f;
|
||||
if (!f.open(p.second, PIIODevice::ReadOnly)) continue;
|
||||
fv << PIResourcesStorage::__RCEntry(s.name, p.first, p.second);
|
||||
}
|
||||
}
|
||||
if (fv.isEmpty()) return false;
|
||||
file << "#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)
|
||||
file << ',';
|
||||
first = false;
|
||||
if (++rcnt >= 32) {
|
||||
file << '\n';
|
||||
rcnt = 0;
|
||||
}
|
||||
file << int(readed[i]);
|
||||
}
|
||||
}
|
||||
e.size = curfile;
|
||||
curoff += curfile;
|
||||
}
|
||||
file << "\n};\n";
|
||||
PIByteArray dba;
|
||||
dba << fv;
|
||||
file << "\nstatic const uchar " << descname << "[] = {\n";
|
||||
first = true;
|
||||
rcnt = -1;
|
||||
for (int i = 0; i < dba.size_s(); ++i) {
|
||||
if (!first)
|
||||
file << ',';
|
||||
first = false;
|
||||
if (++rcnt >= 32) {
|
||||
file << '\n';
|
||||
rcnt = 0;
|
||||
}
|
||||
file << int(dba[i]);
|
||||
}
|
||||
file << "\n};\n";
|
||||
file << "\nclass " << icname << " {\n";
|
||||
file << "public:\n\t" << icname << "() {\n";
|
||||
file << "\t\tPIResourcesStorage::instance()->registerSection(" << dataname << ", " << descname << ", sizeof(" << descname << "));\n";
|
||||
file << "\t}\n";
|
||||
file << "} _pirc_" << fcname << "_initializer_;\n";
|
||||
return true;
|
||||
}
|
||||
8
utils/resources_compiler/generator.h
Normal file
8
utils/resources_compiler/generator.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef PIRC_GENERATOR_H
|
||||
#define PIRC_GENERATOR_H
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
bool generate(PIFile & file, const PIVector<ParserSection> & files);
|
||||
|
||||
#endif // PIRC_GENERATOR_H
|
||||
64
utils/resources_compiler/main.cpp
Normal file
64
utils/resources_compiler/main.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
40
utils/resources_compiler/parser.cpp
Normal file
40
utils/resources_compiler/parser.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "parser.h"
|
||||
#include "piconfig.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();
|
||||
//PIString fc = PIString::fromUTF8(f.readAll());
|
||||
if (ext == "conf") return parseConf(f, PIDir(f.fileInfo().dir()).absolutePath() + "/");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir) {
|
||||
PIVector<ParserSection> ret;
|
||||
if (!file.isOpened()) return ret;
|
||||
ParserSection ps;
|
||||
while (!file.isEnd()) {
|
||||
PIString line = file.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 path = line;
|
||||
if (!PIDir(PIFile::fileInfo(line).dir()).isAbsolute()) {
|
||||
//piCout << "rel, add dir";
|
||||
path.insert(0, dir);
|
||||
}
|
||||
//piCout << line;
|
||||
ps.files << PIPair<PIString, PIString>(line, path);
|
||||
}
|
||||
if (!ps.files.isEmpty()) ret << ps;
|
||||
return ret;
|
||||
}
|
||||
15
utils/resources_compiler/parser.h
Normal file
15
utils/resources_compiler/parser.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef PIRC_PARSER_H
|
||||
#define PIRC_PARSER_H
|
||||
|
||||
#include "pidir.h"
|
||||
#include "pifile.h"
|
||||
|
||||
struct ParserSection {
|
||||
PIString name;
|
||||
PIVector<PIPair<PIString, PIString> > files; // name, path
|
||||
};
|
||||
|
||||
PIVector<ParserSection> parse(const PIString & path);
|
||||
PIVector<ParserSection> parseConf(PIFile & file, const PIString & dir);
|
||||
|
||||
#endif // PIRC_PARSER_H
|
||||
Reference in New Issue
Block a user