diff --git a/src_main/core/piinit.cpp b/src_main/core/piinit.cpp index 727cc539..f747f211 100644 --- a/src_main/core/piinit.cpp +++ b/src_main/core/piinit.cpp @@ -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; diff --git a/src_main/core/piinit.h b/src_main/core/piinit.h index 2ce0c7c6..2c8313cb 100644 --- a/src_main/core/piinit.h +++ b/src_main/core/piinit.h @@ -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); diff --git a/src_main/resources/piresources.h b/src_main/resources/piresources.h index cec0c258..34b9d674 100644 --- a/src_main/resources/piresources.h +++ b/src_main/resources/piresources.h @@ -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); diff --git a/utils/resources_compiler/CMakeLists.txt b/utils/resources_compiler/CMakeLists.txt new file mode 100644 index 00000000..50f1b1eb --- /dev/null +++ b/utils/resources_compiler/CMakeLists.txt @@ -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 () diff --git a/utils/resources_compiler/generator.cpp b/utils/resources_compiler/generator.cpp new file mode 100644 index 00000000..b8864d75 --- /dev/null +++ b/utils/resources_compiler/generator.cpp @@ -0,0 +1,72 @@ +#include "generator.h" +#include "piresourcesstorage.h" + +typedef PIPair SSPair; + +bool generate(PIFile & file, const PIVector & 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 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; +} diff --git a/utils/resources_compiler/generator.h b/utils/resources_compiler/generator.h new file mode 100644 index 00000000..ecb51504 --- /dev/null +++ b/utils/resources_compiler/generator.h @@ -0,0 +1,8 @@ +#ifndef PIRC_GENERATOR_H +#define PIRC_GENERATOR_H + +#include "parser.h" + +bool generate(PIFile & file, const PIVector & files); + +#endif // PIRC_GENERATOR_H diff --git a/utils/resources_compiler/main.cpp b/utils/resources_compiler/main.cpp new file mode 100644 index 00000000..46f4b67b --- /dev/null +++ b/utils/resources_compiler/main.cpp @@ -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 -o \"" << NewLine; + piCout << Green << Bold << "Details:"; + piCout << "-h --help " << Green << "- display this message and exit"; + piCout << "-i --input " << Green << "- resources description file"; + piCout << "-o --out " << 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 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; +} + diff --git a/utils/resources_compiler/parser.cpp b/utils/resources_compiler/parser.cpp new file mode 100644 index 00000000..bcf7679c --- /dev/null +++ b/utils/resources_compiler/parser.cpp @@ -0,0 +1,40 @@ +#include "parser.h" +#include "piconfig.h" + + +PIVector parse(const PIString & path) { + PIVector 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 parseConf(PIFile & file, const PIString & dir) { + PIVector 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(line, path); + } + if (!ps.files.isEmpty()) ret << ps; + return ret; +} diff --git a/utils/resources_compiler/parser.h b/utils/resources_compiler/parser.h new file mode 100644 index 00000000..196b2551 --- /dev/null +++ b/utils/resources_compiler/parser.h @@ -0,0 +1,15 @@ +#ifndef PIRC_PARSER_H +#define PIRC_PARSER_H + +#include "pidir.h" +#include "pifile.h" + +struct ParserSection { + PIString name; + PIVector > files; // name, path +}; + +PIVector parse(const PIString & path); +PIVector parseConf(PIFile & file, const PIString & dir); + +#endif // PIRC_PARSER_H