2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-03-12 14:48:34 +01:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2013-03-15 11:51:35 +01:00
|
|
|
#include <string.h>
|
2013-03-12 14:48:34 +01:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
FILE *infp, *outfp;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
fprintf(stderr, "Syntax: %s <in-file> <out-file>\n", argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
infp = fopen(argv[1], "r");
|
|
|
|
|
|
|
|
if (!infp) {
|
|
|
|
perror("fopen");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
outfp = fopen(argv[2], "w");
|
|
|
|
|
|
|
|
if (!outfp) {
|
2015-03-02 07:34:11 +01:00
|
|
|
fclose(infp);
|
2013-03-12 14:48:34 +01:00
|
|
|
perror("fopen");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(outfp, "/* This file has been automatically generated\n"
|
2017-12-19 15:50:05 +01:00
|
|
|
" from the input file \"%s\". */\n\n", argv[1]);
|
2016-08-28 14:33:42 +02:00
|
|
|
fputs("#include \"config/configfragment.hpp\"\n\nnamespace {\n\nconst char *fragment = R\"CONFIG_FRAGMENT(", outfp);
|
2013-03-12 14:48:34 +01:00
|
|
|
|
2016-08-28 11:01:45 +02:00
|
|
|
while (!feof(infp)) {
|
|
|
|
char buf[1024];
|
|
|
|
size_t rc = fread(buf, 1, sizeof(buf), infp);
|
2013-03-12 14:48:34 +01:00
|
|
|
|
2016-08-28 11:01:45 +02:00
|
|
|
if (rc == 0)
|
2013-03-12 14:48:34 +01:00
|
|
|
break;
|
|
|
|
|
2016-08-28 11:01:45 +02:00
|
|
|
fwrite(buf, rc, 1, outfp);
|
2013-03-15 11:51:35 +01:00
|
|
|
}
|
|
|
|
|
2016-08-28 14:33:42 +02:00
|
|
|
fprintf(outfp, ")CONFIG_FRAGMENT\";\n\nREGISTER_CONFIG_FRAGMENT(\"%s\", fragment);\n\n}", argv[1]);
|
2013-03-12 14:48:34 +01:00
|
|
|
|
|
|
|
fclose(outfp);
|
|
|
|
fclose(infp);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|