1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 int main(int argc
, char* argv
[])
25 printf ("bin2c <filename.bin> [filename.c]\n");
29 // path and filename but without extension
30 char sPathWithoutExtension
[256];
35 // copy fullpath from command-line
36 strcpy(sPathWithoutExtension
, argv
[1]);
38 char *tmpExt
= strrchr(sPathWithoutExtension
, '.');
41 if (tmpExt
) *tmpExt
= 0;
43 // look for last directory separator
44 const char *tmpName1
= strrchr(sPathWithoutExtension
, '/');
46 const char *tmpName2
= strrchr(sPathWithoutExtension
, '\\');
48 const char *tmpName2
= NULL
;
51 // take last separator
52 const char *tmpName
= tmpName1
> tmpName2
? tmpName1
:tmpName2
;
57 // computes position in path
58 size_t pos
= tmpName
- sPathWithoutExtension
;
61 strcpy(sName
, sPathWithoutExtension
+pos
+1);
68 strcpy (sOutput
, argv
[2]);
72 strcpy(sOutput
, sPathWithoutExtension
);
73 strcat(sOutput
, ".cpp");
76 FILE *pIn
=fopen( argv
[1], "rb");
78 printf ("Can't open %s.", argv
[1]);
81 FILE *pOut
=fopen( sOutput
, "w");
83 printf ("Can't open %s.", sOutput
);
88 " * Generated by bin2c.exe\n"
92 "extern const unsigned char %s[];\n"
93 "extern const unsigned int %sSize;\n\n"
94 "static const unsigned char %s[] =\n"
95 "{\n", argv
[1], sName
, sName
, sName
);
101 fprintf (pOut
, "\t");
107 fprintf (pOut
, "0x%02x, ", c
);
110 fprintf (pOut
, "\n");
114 fprintf (pOut
, "};\n\n");
116 fprintf (pOut
, "static const unsigned int %sSize = %d;\n\n", sName
, size
);