mirror of https://github.com/Icinga/icinga2.git
parent
69bb90403d
commit
e5af5b5dd3
|
@ -26,7 +26,7 @@
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
|
|
||||||
#define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \
|
#define REGISTER_CONFIG_FRAGMENT(name, fragment) \
|
||||||
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
||||||
icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
|
icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
|
||||||
VERIFY(expression); \
|
VERIFY(expression); \
|
||||||
|
|
|
@ -23,10 +23,7 @@
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int cols;
|
|
||||||
FILE *infp, *outfp;
|
FILE *infp, *outfp;
|
||||||
int i;
|
|
||||||
char id[32];
|
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr, "Syntax: %s <in-file> <out-file>\n", argv[0]);
|
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"
|
fprintf(outfp, "/* This file has been automatically generated\n"
|
||||||
" from the input file \"%s\". */\n\n", argv[1]);
|
" from the input file \"%s\". */\n\n", argv[1]);
|
||||||
fputs("#include \"config/configfragment.hpp\"\n\nstatic const char g_ConfigFragment[] = {\n", outfp);
|
fprintf(outfp, "#include \"config/configfragment.hpp\"\n\nREGISTER_CONFIG_FRAGMENT(\"%s\", R\"CONFIG_FRAGMENT(\n", argv[1]);
|
||||||
fputc('\t', outfp);
|
|
||||||
|
|
||||||
cols = 0;
|
while (!feof(infp)) {
|
||||||
for (;;) {
|
char buf[1024];
|
||||||
int c = fgetc(infp);
|
size_t rc = fread(buf, 1, sizeof(buf), infp);
|
||||||
|
|
||||||
if (c == EOF)
|
if (rc == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (cols > 16) {
|
fwrite(buf, rc, 1, outfp);
|
||||||
fputs("\n\t", outfp);
|
|
||||||
cols = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(outfp, "%d, ", c);
|
|
||||||
cols++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(id, argv[1], sizeof(id));
|
fputs(")CONFIG_FRAGMENT\");", outfp);
|
||||||
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]);
|
|
||||||
|
|
||||||
fclose(outfp);
|
fclose(outfp);
|
||||||
fclose(infp);
|
fclose(infp);
|
||||||
|
|
Loading…
Reference in New Issue