[icinga-checkins] icinga.org: icinga2/master: Use raw string literals in mkembedconfig

git at icinga.org git at icinga.org
Sun Aug 28 11:02:21 CEST 2016


Module: icinga2
Branch: master
Commit: e5af5b5dd374dc5e70f47b1fa5335c94949e1cb2
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=e5af5b5dd374dc5e70f47b1fa5335c94949e1cb2

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sun Aug 28 11:01:45 2016 +0200

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 2d1c466..ef4f6ec 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 2a3595f..0050bc7 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 <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);



More information about the icinga-checkins mailing list