| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <stdlib.h> |
| 24 |
|
| 25 |
static const char *code = |
| 26 |
"static bool find_embedded_file(const std::string &name, std::string &data) {\n" |
| 27 |
" const struct embedded_file *p;\n" |
| 28 |
" for (p = embedded_files; p->name != NULL; p++) {\n" |
| 29 |
" if (*p->name == name) {\n" |
| 30 |
" data = *p->data;\n" |
| 31 |
" return true;\n" |
| 32 |
" }\n" |
| 33 |
" }\n" |
| 34 |
" return false;\n" |
| 35 |
"}\n"; |
| 36 |
|
| 37 |
int main(int argc, char *argv[]) { |
| 38 |
FILE *fp, *foutput; |
| 39 |
int i, j, ch; |
| 40 |
|
| 41 |
if((foutput = fopen("translation_files.h", "w")) == NULL) { |
| 42 |
exit(EXIT_FAILURE); |
| 43 |
} |
| 44 |
|
| 45 |
fprintf(foutput, "#ifndef TRANSLATION_FILES_H\n"); |
| 46 |
fprintf(foutput, "#define TRANSLATION_FILES_H\n\n"); |
| 47 |
fprintf(foutput, "#include <string>\n\n"); |
| 48 |
|
| 49 |
for (i = 1; i < argc; i++) { |
| 50 |
if ((fp = fopen(argv[i], "rb")) == NULL) { |
| 51 |
fclose(foutput); |
| 52 |
exit(EXIT_FAILURE); |
| 53 |
} else { |
| 54 |
fprintf(foutput, "static const std::string translation_file_name_%d = \"%s\";\n", i, argv[i]); |
| 55 |
fprintf(foutput, "static const std::string translation_file_data_%d = std::string(", i); |
| 56 |
for (j = 0; (ch = fgetc(fp)) != EOF; j++) { |
| 57 |
if ((j % 16) == 0) { |
| 58 |
if (j > 0) { |
| 59 |
fprintf(foutput, "%s", "\""); |
| 60 |
} |
| 61 |
fprintf(foutput, "%s", "\n \""); |
| 62 |
} |
| 63 |
fprintf(foutput, "\\x%02x", ch); |
| 64 |
} |
| 65 |
fprintf(foutput, "\",\n %d);\n\n", j); |
| 66 |
fclose(fp); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
fprintf(foutput, "%s", "static const struct embedded_file {\n"); |
| 71 |
fprintf(foutput, "%s", " const std::string *name;\n"); |
| 72 |
fprintf(foutput, "%s", " const std::string *data;\n"); |
| 73 |
fprintf(foutput, "%s", "} embedded_files[] = {\n"); |
| 74 |
|
| 75 |
for (i = 1; i < argc; i++) { |
| 76 |
fprintf(foutput, " {&translation_file_name_%d, &translation_file_data_%d},\n", i, i); |
| 77 |
} |
| 78 |
fprintf(foutput, "%s", " {NULL, NULL}\n"); |
| 79 |
fprintf(foutput, "%s", "};\n\n"); |
| 80 |
fprintf(foutput, "%s\n", code); |
| 81 |
|
| 82 |
fprintf(foutput, "#endif /* TRANSLATION_FILES_H */\n"); |
| 83 |
|
| 84 |
fclose(foutput); |
| 85 |
|
| 86 |
return EXIT_SUCCESS; |
| 87 |
} |