Author: akhaldi
Date: Fri Sep 14 11:12:40 2012
New Revision: 57296
URL:
http://svn.reactos.org/svn/reactos?rev=57296&view=rev
Log:
[HOST-TOOLS/BIN2C]: Add bin2c host tool, to be used for embedding binary files inside C
source code, by transforming them into a byte array. By Hermès Bélusca.
CORE-6653 #resolve Committed to trunk. Cheers ;)
Added:
trunk/reactos/tools/bin2c.c (with props)
Modified:
trunk/reactos/CMakeLists.txt
trunk/reactos/tools/CMakeLists.txt
Modified: trunk/reactos/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/CMakeLists.txt?rev=57296&a…
==============================================================================
--- trunk/reactos/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/CMakeLists.txt [iso-8859-1] Fri Sep 14 11:12:40 2012
@@ -69,9 +69,9 @@
add_subdirectory(lib)
if(NOT MSVC)
- export(TARGETS widl gendib cabman cdmake mkhive obj2bin spec2def geninc rsym
mkshelllink FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
- else()
- export(TARGETS widl gendib cabman cdmake mkhive obj2bin spec2def geninc
mkshelllink FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+ export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc
rsym mkshelllink FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+ else()
+ export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc
mkshelllink FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
endif()
else()
Modified: trunk/reactos/tools/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/CMakeLists.txt?rev=5…
==============================================================================
--- trunk/reactos/tools/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/tools/CMakeLists.txt [iso-8859-1] Fri Sep 14 11:12:40 2012
@@ -4,6 +4,8 @@
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
+
+add_executable(bin2c bin2c.c)
add_subdirectory(cabman)
add_subdirectory(cdmake)
Added: trunk/reactos/tools/bin2c.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/bin2c.c?rev=57296&am…
==============================================================================
--- trunk/reactos/tools/bin2c.c (added)
+++ trunk/reactos/tools/bin2c.c [iso-8859-1] Fri Sep 14 11:12:40 2012
@@ -1,0 +1,106 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS bin2c
+ * FILE: tools/bin2c/bin2c.c
+ * PURPOSE: Converts a binary file into a byte array
+ * PROGRAMMER: Hermès Bélusca - Maïto
+ */
+
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ FILE* inFile;
+ FILE* outCFile;
+ FILE* outHFile;
+ unsigned char ch;
+ unsigned char cnt;
+
+ /*
+ * Validate the arguments.
+ */
+ if (argc < 5)
+ {
+ printf("Usage: bin2c infile.bin outfile.c outfile.h array_name
[array_attribute [header_for_attribute]]\n");
+ return -1;
+ }
+
+ /*
+ * Open the input and the output files.
+ */
+ inFile = fopen(argv[1], "rb");
+ if (!inFile)
+ {
+ printf("ERROR: Couldn't open data file '%s'.\n", argv[1]);
+ return -1;
+ }
+ outCFile = fopen(argv[2], "w");
+ if (!outCFile)
+ {
+ fclose(inFile);
+ printf("ERROR: Couldn't create output source file '%s'.\n",
argv[2]);
+ return -1;
+ }
+ outHFile = fopen(argv[3], "w");
+ if (!outHFile)
+ {
+ fclose(outCFile);
+ fclose(inFile);
+ printf("ERROR: Couldn't create output header file '%s'.\n",
argv[3]);
+ return -1;
+ }
+
+ /*
+ * Generate the header file and close it.
+ */
+ fprintf(outHFile, "/* This file is autogenerated, do not edit. */\n\n");
+ fprintf(outHFile, "#ifndef CHAR\n"
+ "#define CHAR char\n"
+ "#endif\n\n");
+ fprintf(outHFile, "extern CHAR %s[];\n", argv[4]);
+ fclose(outHFile);
+
+ /*
+ * Generate the source file and close it.
+ */
+ fprintf(outCFile, "/* This file is autogenerated, do not edit. */\n\n");
+ if (argc >= 7)
+ {
+ /* There is a header to be included for defining the array attribute. */
+ fprintf(outCFile, "#include \"%s\"\n", argv[6]);
+ }
+ fprintf(outCFile, "#include \"%s\"\n\n", argv[3]);
+
+ /* Generate the array. */
+ if (argc >= 6)
+ {
+ /* There is an array attribute. */
+ fprintf(outCFile, "%s ", argv[5]);
+ }
+ fprintf(outCFile, "CHAR %s[] =\n{", argv[4]);
+
+ cnt = 0;
+ ch = fgetc(inFile);
+ while (!feof(inFile))
+ {
+ if ((cnt % 16) == 0)
+ {
+ fprintf(outCFile, "\n ");
+ cnt = 0;
+ }
+ fprintf(outCFile, " 0x%02x,", (unsigned int)ch);
+ ++cnt;
+ ch = fgetc(inFile);
+ }
+ /* Put a final NULL terminator. */
+ fprintf(outCFile, "\n 0x00");
+ fprintf(outCFile, "\n};\n");
+ fclose(outCFile);
+
+ /* Close the input file. */
+ fclose(inFile);
+
+ return 0;
+}
+
+/* EOF */
Propchange: trunk/reactos/tools/bin2c.c
------------------------------------------------------------------------------
svn:eol-style = native