]> granicus.if.org Git - icinga2/commitdiff
Use raw string literals in mkembedconfig
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 28 Aug 2016 09:01:45 +0000 (11:01 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 28 Aug 2016 09:01:45 +0000 (11:01 +0200)
fixes #12576

lib/config/configfragment.hpp
tools/mkembedconfig/mkembedconfig.c

index 2d1c466378a9030e1a83661be6b4e6d6ca2f9566..ef4f6ecef95c7e80a06beeb53b66ed1cc629f1ff 100644 (file)
@@ -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); \
index 2a3595fc4224db8875dd09c31cfcc1958069a80e..0050bc7e771511991a63a1956c8a942fb8d49cb3 100644 (file)
 
 int main(int argc, char **argv)
 {
-       int cols;
        FILE *infp, *outfp;
-       int i;
-       char id[32];
 
        if (argc < 3) {
                fprintf(stderr, "Syntax: %s <in-file> <out-file>\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++;
-       }
-
-       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] = '_';
+               fwrite(buf, rc, 1, outfp);
        }
 
-       fprintf(outfp, "0\n};\n\nREGISTER_CONFIG_FRAGMENT(%s, \"%s\", g_ConfigFragment);\n", id, argv[1]);
+       fputs(")CONFIG_FRAGMENT\");", outfp);
 
        fclose(outfp);
        fclose(infp);