2001-05-15 03:50:25 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
FILE *in;
|
|
|
|
FILE *out;
|
|
|
|
|
2001-07-06 22:05:05 +00:00
|
|
|
int main(int argc, char *argv[])
|
2001-05-15 03:50:25 +00:00
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
int cnt = 0;
|
|
|
|
|
2001-07-06 22:05:05 +00:00
|
|
|
if (argc < 4)
|
|
|
|
{
|
|
|
|
printf("usage: bin2c infile.bin outfile.h array_name\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2001-05-15 03:50:25 +00:00
|
|
|
|
2001-07-06 22:05:05 +00:00
|
|
|
if ((in = fopen(argv[1], "rb")) == NULL)
|
2001-05-15 03:50:25 +00:00
|
|
|
{
|
|
|
|
printf("Couldn't open data file.\n");
|
2001-07-06 22:05:05 +00:00
|
|
|
return -1;
|
2001-05-15 03:50:25 +00:00
|
|
|
}
|
2001-07-06 22:05:05 +00:00
|
|
|
if ((out = fopen(argv[2], "wb")) == NULL)
|
2001-05-15 03:50:25 +00:00
|
|
|
{
|
|
|
|
printf("Couldn't open output file.\n");
|
2001-07-06 22:05:05 +00:00
|
|
|
return -1;
|
2001-05-15 03:50:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-06 22:05:05 +00:00
|
|
|
fprintf(out, "unsigned char %s[] = {\n", argv[3]);
|
2001-05-15 03:50:25 +00:00
|
|
|
|
|
|
|
ch = fgetc(in);
|
|
|
|
while (!feof(in))
|
|
|
|
{
|
|
|
|
if (cnt != 0)
|
|
|
|
fprintf(out, ", ");
|
|
|
|
if (!(cnt % 16))
|
|
|
|
fprintf(out, "\n");
|
|
|
|
fprintf(out, "0x%02x", (int)ch);
|
|
|
|
cnt++;
|
|
|
|
ch = fgetc(in);
|
|
|
|
}
|
|
|
|
|
2003-07-12 18:01:53 +00:00
|
|
|
fprintf(out, "\n};\n");
|
2001-05-15 03:50:25 +00:00
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
fclose(out);
|
|
|
|
|
|
|
|
return 0;
|
2002-04-16 06:11:08 +00:00
|
|
|
}
|