2015-08-04 21:37:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: bintoc <in> <out> <symbol>\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
FILE* fin = fopen(argv[1], "rb");
|
|
|
|
if (!fin)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to open %s for reading\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
FILE* fout = fopen(argv[2], "wb");
|
|
|
|
if (!fout)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to open %s for writing\n", argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-12-29 07:56:31 +00:00
|
|
|
fprintf(fout, "#include <cstdint>\n#include <cstddef>\n");
|
|
|
|
fprintf(fout, "extern \"C\" const uint8_t %s[] =\n{\n", argv[3]);
|
2015-08-04 21:37:12 +00:00
|
|
|
size_t totalSz = 0;
|
|
|
|
size_t readSz;
|
|
|
|
uint8_t buf[32];
|
|
|
|
while ((readSz = fread(buf, 1, 32, fin)))
|
|
|
|
{
|
|
|
|
fprintf(fout, " ");
|
|
|
|
totalSz += readSz;
|
|
|
|
for (int b=0 ; b<readSz ; ++b)
|
|
|
|
fprintf(fout, "0x%02X, ", buf[b]);
|
|
|
|
fprintf(fout, "\n");
|
|
|
|
}
|
2017-12-29 07:56:31 +00:00
|
|
|
fprintf(fout, "0x0};\nextern \"C\" const size_t %s_SZ = %zu;\n", argv[3], totalSz);
|
2015-08-04 21:37:12 +00:00
|
|
|
fclose(fin);
|
|
|
|
fclose(fout);
|
|
|
|
return 0;
|
|
|
|
}
|