mirror of https://github.com/Icinga/icinga2.git
parent
69bb90403d
commit
e5af5b5dd3
|
@ -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); \
|
||||
|
|
|
@ -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++;
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue