diff options
-rw-r--r-- | plugin/Makefile.mingw32.in | 2 | ||||
-rw-r--r-- | plugingui/Makefile.am | 12 | ||||
-rw-r--r-- | plugingui/rcgen.cc | 143 | ||||
-rw-r--r-- | test/uitests/Makefile.am | 6 |
4 files changed, 133 insertions, 30 deletions
diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in index bf52e04..fad7960 100644 --- a/plugin/Makefile.mingw32.in +++ b/plugin/Makefile.mingw32.in @@ -174,7 +174,7 @@ RES = \ ../COPYING all: - g++ @top_srcdir@/plugingui/rcgen.cc -o @top_srcdir@/plugingui/rcgen + g++ -I@top_srcdir@/getoptpp @top_srcdir@/plugingui/rcgen.cc -o @top_srcdir@/plugingui/rcgen (cd @top_srcdir@/plugingui; ./rcgen $(RES) > resource_data.cc) g++ $(CXXFLAGS) @top_srcdir@/plugingui/resource_data.cc -c gcc $(CFLAGS) $(DBG_CFLAGS) @top_srcdir@/hugin/hugin.c -c diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index f208f43..cb49d53 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -37,8 +37,8 @@ rcgen_verbose = $(rcgen_verbose_@AM_V@) rcgen_verbose_ = $(rcgen_verbose_@AM_DEFAULT_V@) rcgen_verbose_0 = @echo " RCGEN "$@; -resource_data.cc: rcgen $(RES) - $(rcgen_verbose)./rcgen -d $(top_srcdir)/plugingui $(RES) > $(top_srcdir)/plugingui/resource_data.cc +$(top_builddir)/plugingui/resource_data.cc: rcgen$(EXEEXT) $(RES) + $(rcgen_verbose)./rcgen$(EXEEXT) -d $(top_srcdir)/plugingui -o $@ $(RES) libdggui_la_CPPFLAGS = \ $(DEBUG_FLAGS) \ @@ -100,7 +100,6 @@ nodist_libdggui_la_SOURCES = \ progressbar.cc \ resamplingframecontent.cc \ resource.cc \ - resource_data.cc \ sampleselectionframecontent.cc \ scrollbar.cc \ slider.cc \ @@ -119,7 +118,8 @@ nodist_libdggui_la_SOURCES = \ visualizerframecontent.cc \ widget.cc \ window.cc \ - lodepng/lodepng.cpp + lodepng/lodepng.cpp \ + $(top_builddir)/plugingui/resource_data.cc if ENABLE_X11 nodist_libdggui_la_SOURCES += \ @@ -185,7 +185,9 @@ plugingui_SOURCES = \ testmain.cc \ $(top_srcdir)/hugin/hugin.c -rcgen_SOURCES = rcgen.cc +rcgen_CXXFLAGS = -I$(top_srcdir)/getoptpp +rcgen_SOURCES = \ + rcgen.cc EXTRA_DIST = \ $(nodist_libdggui_la_SOURCES) \ diff --git a/plugingui/rcgen.cc b/plugingui/rcgen.cc index f4d7fe6..f7b5590 100644 --- a/plugingui/rcgen.cc +++ b/plugingui/rcgen.cc @@ -27,35 +27,138 @@ #include <stdio.h> #include <string> #include <unistd.h> +#include <sstream> + +#include <getoptpp.hpp> + +std::string usage(const std::string& name, bool brief = false) +{ + std::ostringstream output; + output << + "Usage: " << name << " [options]\n"; + if(!brief) + { + output << + "\n" + "Create resource file from list of input files.\n" + "\n"; + } + return output.str(); +} int main(int argc, char *argv[]) { - printf("/* This file is autogenerated by rcgen. Do not modify! */\n"); - printf("#include \"resource_data.h\"\n"); - printf("\n"); - printf("const rc_data_t rc_data[] =\n"); - printf("{\n"); + bool verbose{false}; + std::vector<std::string> stripPrefixes; + std::string dirRoot; + std::string outfile; + + dg::Options opt; + + opt.add("strip-path", required_argument, 's', + "Strip supplied path prefix from resource names.", + [&]() + { + stripPrefixes.push_back(optarg); + return 0; + }); + + opt.add("dir-root", required_argument, 'd', + "Change to supplied root dir before reading files.", + [&]() + { + dirRoot = optarg; + return 0; + }); + + opt.add("output", required_argument, 'o', + "Write output to specificed file, defaults to stdout.", + [&]() + { + outfile = optarg; + return 0; + }); + + opt.add("verbose", no_argument, 'v', + "Print verbose output during processing.", + [&]() + { + verbose = true; + return 0; + }); + + opt.add("help", no_argument, 'h', + "Print this message and exit.", + [&]() + { + std::cout << usage(argv[0]); + std::cout << "Options:\n"; + opt.help(); + exit(0); + return 0; + }); + + if(opt.process(argc, argv) != 0) + { + return 1; + } + + FILE* out = stdout; + if(!outfile.empty()) + { + out = fopen(outfile.data(), "wb"); + if(!out) + { + fprintf(stderr, "Could not write to file '%s' - quitting\n", + outfile.data()); + return 1; + + } + } - int i = 1; + fprintf(out, "/* This file is autogenerated by rcgen. Do not modify! */\n"); + fprintf(out, "#include \"resource_data.h\"\n"); + fprintf(out, "\n"); + fprintf(out, "const rc_data_t rc_data[] =\n"); + fprintf(out, "{\n"); - if(argc > 2 && std::string(argv[1]) == "-d") + if(!dirRoot.empty()) { - if(chdir(argv[2])) + if(verbose) + { + fprintf(stderr, "Change to dir: %s\n", dirRoot.data()); + } + + if(chdir(dirRoot.data())) { return 1; } - i += 2; } - while(i < argc) + for(const auto& arg : opt.arguments()) { - printf(" {\n \":%s\", ", argv[i]); + std::string resourceName = arg; + for(const auto& stripPrefix : stripPrefixes) + { + if(stripPrefix == resourceName.substr(0, stripPrefix.length())) + { + resourceName = resourceName.substr(stripPrefix.length()); + break; + } + } + + fprintf(out, " {\n \":%s\", ", resourceName.data()); + + if(verbose) + { + fprintf(stderr, "Process: %s\n", arg.data()); + } std::string data; - FILE *fp = fopen(argv[i], "rb"); + FILE *fp = fopen(arg.data(), "rb"); if(!fp) { - fprintf(stderr, "Could not read file '%s' - quitting\n", argv[i]); + fprintf(stderr, "Could not read file '%s' - quitting\n", arg.data()); return 1; } @@ -67,23 +170,21 @@ int main(int argc, char *argv[]) } fclose(fp); - printf("%d,\n \"", (int)data.length()); + fprintf(out, "%d,\n \"", (int)data.length()); for(std::size_t j = 0; j < data.length(); ++j) { if((j != 0) && (j % 16) == 0) { - printf("\"\n \""); + fprintf(out, "\"\n \""); } - printf("\\%o", (unsigned char)data[j]); + fprintf(out, "\\%o", (unsigned char)data[j]); } - printf("\"\n },\n"); - - ++i; + fprintf(out, "\"\n },\n"); } - printf(" { \"\", 0, 0 }\n"); - printf("};\n"); + fprintf(out, " { \"\", 0, 0 }\n"); + fprintf(out, "};\n"); return 0; } diff --git a/test/uitests/Makefile.am b/test/uitests/Makefile.am index 39571e2..a5e6d01 100644 --- a/test/uitests/Makefile.am +++ b/test/uitests/Makefile.am @@ -55,8 +55,8 @@ rcgen_verbose = $(rcgen_verbose_@AM_V@) rcgen_verbose_ = $(rcgen_verbose_@AM_DEFAULT_V@) rcgen_verbose_0 = @echo " RCGEN "$@; -benchmarktest_resource_data.cc: $(top_builddir)/plugingui/rcgen $(RES) - $(rcgen_verbose)$(top_builddir)/plugingui/rcgen -d $(top_srcdir)/test/uitests $(RES) > $(top_srcdir)/test/uitests/benchmarktest_resource_data.cc +$(top_builddir)/test/uitests/benchmarktest_resource_data.cc: $(top_builddir)/plugingui/rcgen $(RES) + $(rcgen_verbose)$(top_builddir)/plugingui/rcgen$(EXEEXT) -d $(top_srcdir)/test/uitests -o $@ $(RES) benchmarktest_LDADD = \ $(top_builddir)/plugingui/libdggui.la \ @@ -67,7 +67,7 @@ benchmarktest_CXXFLAGS = \ -I$(top_srcdir)/hugin benchmarktest_SOURCES = \ benchmarktest.cc \ - benchmarktest_resource_data.cc \ + $(top_builddir)/test/uitests/benchmarktest_resource_data.cc \ $(top_srcdir)/hugin/hugin.c powerwidgettest_LDADD = \ |