87682c1a67a3b6a06ec0d6c7c3c07d0939a9935d
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
[])
19 /* Validate the arguments */
22 fprintf(stdout
, "Usage: bin2c infile.bin outfile.c outfile.h array_name [array_attribute [header_for_attribute]]\n");
26 /* Open the input and output files */
27 inFile
= fopen(argv
[1], "rb");
30 fprintf(stderr
, "ERROR: Couldn't open data file '%s'.\n", argv
[1]);
33 outCFile
= fopen(argv
[2], "w");
37 fprintf(stderr
, "ERROR: Couldn't create output source file '%s'.\n", argv
[2]);
40 outHFile
= fopen(argv
[3], "w");
45 fprintf(stderr
, "ERROR: Couldn't create output header file '%s'.\n", argv
[3]);
49 /* Generate the header file and close it */
50 fprintf(outHFile
, "/* This file is autogenerated, do not edit. */\n\n");
51 fprintf(outHFile
, "#ifndef CHAR\n"
54 fprintf(outHFile
, "extern CHAR %s[];\n", argv
[4]);
57 /* Generate the source file and close it */
58 fprintf(outCFile
, "/* This file is autogenerated, do not edit. */\n\n");
61 /* Include needed header for defining the array attribute */
62 fprintf(outCFile
, "#include \"%s\"\n", argv
[6]);
64 fprintf(outCFile
, "#include \"%s\"\n\n", argv
[3]);
66 /* Generate the data array */
69 /* Add the array attribute */
70 fprintf(outCFile
, "%s ", argv
[5]);
72 fprintf(outCFile
, "CHAR %s[] =\n{", argv
[4]);
80 fprintf(outCFile
, "\n ");
83 fprintf(outCFile
, " 0x%02x,", (unsigned int)ch
);
87 /* Put a final NULL terminator */
88 fprintf(outCFile
, "\n 0x00");
89 fprintf(outCFile
, "\n};\n");
92 /* Close the input file */