]> granicus.if.org Git - icinga2/blob - tools/mkembedconfig/mkembedconfig.c
Docs: Add cipher analysis to troubleshooting docs
[icinga2] / tools / mkembedconfig / mkembedconfig.c
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 int main(int argc, char **argv)
8 {
9         FILE *infp, *outfp;
10
11         if (argc < 3) {
12                 fprintf(stderr, "Syntax: %s <in-file> <out-file>\n", argv[0]);
13                 return EXIT_FAILURE;
14         }
15
16         infp = fopen(argv[1], "r");
17
18         if (!infp) {
19                 perror("fopen");
20                 return EXIT_FAILURE;
21         }
22
23         outfp = fopen(argv[2], "w");
24
25         if (!outfp) {
26                 fclose(infp);
27                 perror("fopen");
28                 return EXIT_FAILURE;
29         }
30
31         fprintf(outfp, "/* This file has been automatically generated\n"
32                 "   from the input file \"%s\". */\n\n", argv[1]);
33         fputs("#include \"config/configfragment.hpp\"\n\nnamespace {\n\nconst char *fragment = R\"CONFIG_FRAGMENT(", outfp);
34
35         while (!feof(infp)) {
36                 char buf[1024];
37                 size_t rc = fread(buf, 1, sizeof(buf), infp);
38
39                 if (rc == 0)
40                         break;
41
42                 fwrite(buf, rc, 1, outfp);
43         }
44
45         fprintf(outfp, ")CONFIG_FRAGMENT\";\n\nREGISTER_CONFIG_FRAGMENT(\"%s\", fragment);\n\n}", argv[1]);
46
47         fclose(outfp);
48         fclose(infp);
49
50         return EXIT_SUCCESS;
51 }