FreeDOS/sys/bin2c.c
Jim Hall 060002c5ae Initial revision
git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@2 6ac86273-5f31-0410-b378-82cca8765d1b
2000-05-06 19:34:20 +00:00

52 lines
826 B
C

#include <stdio.h>
int main(int argc, char **argv)
{
FILE *in, *out;
int col;
int c;
if (argc < 4)
{
fprintf(stderr, "Usage: bin2c <output bin file> <output h file> <array name>\n");
return 1;
}
if ((in = fopen(argv[1], "rb")) == NULL)
{
fprintf(stderr, "Cannot open input file (%s).\n", argv[1]);
return 1;
}
if ((out = fopen(argv[2], "wt")) == NULL)
{
fprintf(stderr, "Cannot open output file (%s).\n", argv[2]);
return 1;
}
col = 0;
fprintf(out, "unsigned char %s[] = {\n ", argv[3]);
while ((c = fgetc(in)) != EOF)
{
if (col)
{
fprintf(out, ", ");
}
if (col >= 8)
{
fprintf(out, "\n ");
col = 0;
}
fprintf(out, "0x%02X", c);
col++;
}
fprintf(out, "\n};\n");
fclose(in);
fclose(out);
return 0;
}