6 int main(int argc, char **argv)
9 fprintf(stderr, "Usage: bin2h INFILE BASENAME OUTFILE\n");
13 string basename = argv[2];
14 for (char &ch : basename) {
15 if (!isalpha(ch) && !isdigit(ch)) {
20 FILE *infp = fopen(argv[1], "rb");
21 if (infp == nullptr) {
26 FILE *outfp = fopen(argv[3], "w");
27 if (outfp == nullptr) {
32 fprintf(outfp, "// Generated by bin2h.cpp from %s. Do not edit by hand.\n", argv[1]);
33 fprintf(outfp, "#include <stddef.h>\n");
34 fprintf(outfp, "unsigned char _binary_%s[] = {", basename.c_str());
38 if (num_bytes++ % 16 == 0) {
39 fprintf(outfp, "\n\t");
45 fprintf(outfp, "0x%02x, ", ch);
47 fprintf(outfp, "\n};\n");
48 fprintf(outfp, "unsigned char *_binary_%s_data = _binary_%s;\n", basename.c_str(), basename.c_str());
49 fprintf(outfp, "size_t _binary_%s_size = sizeof(_binary_%s);\n", basename.c_str(), basename.c_str());