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
This commit is contained in:
Hermès Bélusca-Maïto 2015-06-14 18:13:50 +00:00
parent 2893d3c4ad
commit 1011d89eaa
2 changed files with 16 additions and 20 deletions

View file

@ -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 */

View file

@ -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);