2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS bin2c
4 * FILE: tools/bin2c/bin2c.c
5 * PURPOSE: Converts a binary file into a byte array
6 * PROGRAMMER: Hermès Bélusca - Maïto
11 int main(int argc
, char *argv
[])
20 * Validate the arguments.
24 printf("Usage: bin2c infile.bin outfile.c outfile.h array_name [array_attribute [header_for_attribute]]\n");
29 * Open the input and the output files.
31 inFile
= fopen(argv
[1], "rb");
34 printf("ERROR: Couldn't open data file '%s'.\n", argv
[1]);
37 outCFile
= fopen(argv
[2], "w");
41 printf("ERROR: Couldn't create output source file '%s'.\n", argv
[2]);
44 outHFile
= fopen(argv
[3], "w");
49 printf("ERROR: Couldn't create output header file '%s'.\n", argv
[3]);
54 * Generate the header file and close it.
56 fprintf(outHFile
, "/* This file is autogenerated, do not edit. */\n\n");
57 fprintf(outHFile
, "#ifndef CHAR\n"
60 fprintf(outHFile
, "extern CHAR %s[];\n", argv
[4]);
64 * Generate the source file and close it.
66 fprintf(outCFile
, "/* This file is autogenerated, do not edit. */\n\n");
69 /* There is a header to be included for defining the array attribute. */
70 fprintf(outCFile
, "#include \"%s\"\n", argv
[6]);
72 fprintf(outCFile
, "#include \"%s\"\n\n", argv
[3]);
74 /* Generate the array. */
77 /* There is an array attribute. */
78 fprintf(outCFile
, "%s ", argv
[5]);
80 fprintf(outCFile
, "CHAR %s[] =\n{", argv
[4]);
88 fprintf(outCFile
, "\n ");
91 fprintf(outCFile
, " 0x%02x,", (unsigned int)ch
);
95 /* Put a final NULL terminator. */
96 fprintf(outCFile
, "\n 0x00");
97 fprintf(outCFile
, "\n};\n");
100 /* Close the input file. */