summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-07-25 17:21:43 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-07-25 18:43:45 +0200
commit20c9cd497cef9fab46f1e24eebe5fa98dc04a444 (patch)
treeac5b15ff7354152da2eb8cb45e3fb8e494253b3a /plugingui
parenta986514d0e1ebe78677af6200172fc391e3f063c (diff)
Make rcgen use getoptpp and add strip-path argument.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/Makefile.am12
-rw-r--r--plugingui/rcgen.cc143
2 files changed, 129 insertions, 26 deletions
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;
}