|
|
|
@ -21,6 +21,8 @@
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
if (argc<2)
|
|
|
|
@ -29,23 +31,36 @@ int main(int argc, char* argv[])
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char sDir[256];
|
|
|
|
|
char sPath[256];
|
|
|
|
|
char sName[256];
|
|
|
|
|
char sExt[256];
|
|
|
|
|
_splitpath (argv[1], sDir, sPath, sName, sExt);
|
|
|
|
|
|
|
|
|
|
char sOutput[256];
|
|
|
|
|
if (argc>2)
|
|
|
|
|
strcpy (sOutput, argv[2]);
|
|
|
|
|
char *cExt = strrchr(argv[1], '.');
|
|
|
|
|
char *cName = max(strrchr(argv[1], '/'), strrchr(argv[1], '\\')) + 1;
|
|
|
|
|
char sName[256];
|
|
|
|
|
strcpy(sName, cName);
|
|
|
|
|
if (cExt > cName)
|
|
|
|
|
{
|
|
|
|
|
sName[cExt - cName] = '\x00';
|
|
|
|
|
}
|
|
|
|
|
if (argc > 2)
|
|
|
|
|
{
|
|
|
|
|
strcpy(sOutput, argv[2]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_makepath (sOutput, sDir, sPath, sName, ".cpp");
|
|
|
|
|
strcpy(sOutput, argv[1]);
|
|
|
|
|
if (cExt <= cName)
|
|
|
|
|
{
|
|
|
|
|
cExt = sOutput + strlen(sOutput);
|
|
|
|
|
cExt[0] = '.';
|
|
|
|
|
}
|
|
|
|
|
cExt[1] = 'c';
|
|
|
|
|
cExt[2] = '\x00';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FILE *pIn=fopen( argv[1], "rb");
|
|
|
|
|
if (pIn==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf ("Can't open %s.", argv[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FILE *pOut=fopen( sOutput, "w");
|
|
|
|
@ -53,7 +68,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
printf ("Can't open %s.", sOutput);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (pOut,
|
|
|
|
|
fprintf (pOut,
|
|
|
|
|
"/**\n"
|
|
|
|
|
" * Generated by bin2c.exe\n"
|
|
|
|
|
" * binfile: %s\n"
|
|
|
|
@ -61,7 +76,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
"\n"
|
|
|
|
|
"extern const unsigned char %s[];\n"
|
|
|
|
|
"extern const unsigned int %sSize;\n\n"
|
|
|
|
|
"static const unsigned char %s[] =\n"
|
|
|
|
|
"const unsigned char %s[] =\n"
|
|
|
|
|
"{\n", argv[1], sName, sName, sName);
|
|
|
|
|
|
|
|
|
|
unsigned int size=0;
|
|
|
|
@ -82,14 +97,14 @@ int main(int argc, char* argv[])
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fprintf (pOut, "};\n\n");
|
|
|
|
|
|
|
|
|
|
fprintf (pOut, "static const unsigned int %sSize = %d;\n\n", sName, size);
|
|
|
|
|
|
|
|
|
|
fprintf (pOut, "const unsigned int %sSize = %d;\n\n", sName, size);
|
|
|
|
|
|
|
|
|
|
fclose (pOut);
|
|
|
|
|
fclose (pIn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|