From e5af5b5dd374dc5e70f47b1fa5335c94949e1cb2 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 28 Aug 2016 11:01:45 +0200 Subject: [PATCH] Use raw string literals in mkembedconfig fixes #12576 --- lib/config/configfragment.hpp | 2 +- tools/mkembedconfig/mkembedconfig.c | 32 +++++++---------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/config/configfragment.hpp b/lib/config/configfragment.hpp index 2d1c46637..ef4f6ecef 100644 --- a/lib/config/configfragment.hpp +++ b/lib/config/configfragment.hpp @@ -26,7 +26,7 @@ #include "base/exception.hpp" #include "base/application.hpp" -#define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \ +#define REGISTER_CONFIG_FRAGMENT(name, fragment) \ INITIALIZE_ONCE_WITH_PRIORITY([]() { \ icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \ VERIFY(expression); \ diff --git a/tools/mkembedconfig/mkembedconfig.c b/tools/mkembedconfig/mkembedconfig.c index 2a3595fc4..0050bc7e7 100644 --- a/tools/mkembedconfig/mkembedconfig.c +++ b/tools/mkembedconfig/mkembedconfig.c @@ -23,10 +23,7 @@ int main(int argc, char **argv) { - int cols; FILE *infp, *outfp; - int i; - char id[32]; if (argc < 3) { fprintf(stderr, "Syntax: %s \n", argv[0]); @@ -50,34 +47,19 @@ int main(int argc, char **argv) fprintf(outfp, "/* This file has been automatically generated\n" " from the input file \"%s\". */\n\n", argv[1]); - fputs("#include \"config/configfragment.hpp\"\n\nstatic const char g_ConfigFragment[] = {\n", outfp); - fputc('\t', outfp); + fprintf(outfp, "#include \"config/configfragment.hpp\"\n\nREGISTER_CONFIG_FRAGMENT(\"%s\", R\"CONFIG_FRAGMENT(\n", argv[1]); - cols = 0; - for (;;) { - int c = fgetc(infp); + while (!feof(infp)) { + char buf[1024]; + size_t rc = fread(buf, 1, sizeof(buf), infp); - if (c == EOF) + if (rc == 0) break; - if (cols > 16) { - fputs("\n\t", outfp); - cols = 0; - } - - fprintf(outfp, "%d, ", c); - cols++; + fwrite(buf, rc, 1, outfp); } - strncpy(id, argv[1], sizeof(id)); - id[sizeof(id) - 1] = '\0'; - - for (i = 0; id[i]; i++) { - if ((id[i] < 'a' || id[i] > 'z') && (id[i] < 'A' || id[i] > 'Z')) - id[i] = '_'; - } - - fprintf(outfp, "0\n};\n\nREGISTER_CONFIG_FRAGMENT(%s, \"%s\", g_ConfigFragment);\n", id, argv[1]); + fputs(")CONFIG_FRAGMENT\");", outfp); fclose(outfp); fclose(infp);