From 1011d89eaa2638cc34a3416fc2c6a3cc18322512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 14 Jun 2015 18:13:50 +0000 Subject: [PATCH] [TOOLS] Improve bin2c by saving in a #define the size of the generated array, and specify this size in the declaration of the array so that doing sizeof(...) becomes possible. Use "unsigned char" as the (portable) type of the contents of the array. [HAL] Add PCHAR casts where needed to take into account the previous modifications. svn path=/trunk/; revision=68139 --- reactos/hal/halx86/legacy/bussupp.c | 4 ++-- reactos/tools/bin2c.c | 32 +++++++++++++---------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/reactos/hal/halx86/legacy/bussupp.c b/reactos/hal/halx86/legacy/bussupp.c index 374603ca627..ec70b40f794 100644 --- a/reactos/hal/halx86/legacy/bussupp.c +++ b/reactos/hal/halx86/legacy/bussupp.c @@ -715,7 +715,7 @@ HalpDebugPciDumpBus(IN ULONG i, /* Isolate the class name */ sprintf(LookupString, "C %02x ", PciData->BaseClass); - ClassName = strstr(ClassTable, LookupString); + ClassName = strstr((PCHAR)ClassTable, LookupString); if (ClassName) { /* Isolate the subclass name */ @@ -736,7 +736,7 @@ HalpDebugPciDumpBus(IN ULONG i, /* Isolate the vendor name */ sprintf(LookupString, "\r\n%04x ", PciData->VendorID); - VendorName = strstr(VendorTable, LookupString); + VendorName = strstr((PCHAR)VendorTable, LookupString); if (VendorName) { /* Copy the vendor name into our buffer */ diff --git a/reactos/tools/bin2c.c b/reactos/tools/bin2c.c index 87682c1a67a..83b38e9e241 100644 --- a/reactos/tools/bin2c.c +++ b/reactos/tools/bin2c.c @@ -13,8 +13,8 @@ int main(int argc, char *argv[]) FILE* inFile; FILE* outCFile; FILE* outHFile; + size_t bufLen; unsigned char ch; - unsigned char cnt; /* Validate the arguments */ if (argc < 5) @@ -46,14 +46,6 @@ int main(int argc, char *argv[]) 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) @@ -69,26 +61,30 @@ int main(int argc, char *argv[]) /* Add the array attribute */ fprintf(outCFile, "%s ", argv[5]); } - fprintf(outCFile, "CHAR %s[] =\n{", argv[4]); + fprintf(outCFile, "unsigned char %s[] =\n{", argv[4]); - cnt = 0; - ch = fgetc(inFile); + bufLen = 0; + ch = fgetc(inFile); while (!feof(inFile)) { - if ((cnt % 16) == 0) - { + if ((bufLen % 16) == 0) fprintf(outCFile, "\n "); - cnt = 0; - } + fprintf(outCFile, " 0x%02x,", (unsigned int)ch); - ++cnt; + ++bufLen; ch = fgetc(inFile); } /* Put a final NULL terminator */ - fprintf(outCFile, "\n 0x00"); + fprintf(outCFile, "\n 0x00"); ++bufLen; fprintf(outCFile, "\n};\n"); fclose(outCFile); + /* Generate the header file and close it */ + fprintf(outHFile, "/* This file is autogenerated, do not edit. */\n\n"); + fprintf(outHFile, "#define %s_SIZE %Iu\n" , argv[4], bufLen); + fprintf(outHFile, "extern unsigned char %s[%Iu];\n", argv[4], bufLen); + fclose(outHFile); + /* Close the input file */ fclose(inFile);