1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD><style> A { color:black }</style>
<!-- hennerik CVSweb $Revision: 1.93 $ -->
<TITLE>code/tool/bin2c/bin2c.cpp - view - 1.1</TITLE></HEAD>
<BODY BGCOLOR="#eeeeee">
<table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="#aaaaaa"><tr valign=bottom><td><a href="bin2c.cpp"><IMG SRC="/inc/img/picto-up.gif" ALT="[BACK]" BORDER="0" WIDTH="14" HEIGHT="13"></a> <b>Return to <A HREF="bin2c.cpp">bin2c.cpp</A>
CVS log</b> <IMG SRC="/inc/img/picto-news.gif" ALT="[TXT]" BORDER="0" WIDTH="13" HEIGHT="15"></td><td align=right><IMG SRC="/inc/img/picto-dir.gif" ALT="[DIR]" BORDER="0" WIDTH="15" HEIGHT="13"> <b>Up to <a href="/cvs/cvsweb.cgi/">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/">code</a> / <a href="/cvs/cvsweb.cgi/code/tool/">tool</a> / <a href="/cvs/cvsweb.cgi/code/tool/bin2c/">bin2c</a></b></td></tr></table><HR noshade><table width="100%"><tr><td bgcolor="#ffffff">File: <a href="/cvs/cvsweb.cgi/">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/">code</a> / <a href="/cvs/cvsweb.cgi/code/tool/">tool</a> / <a href="/cvs/cvsweb.cgi/code/tool/bin2c/">bin2c</a> / <a href="/cvs/cvsweb.cgi/code/tool/bin2c/bin2c.cpp">bin2c.cpp</a> (<A HREF="/cvs/cvsweb.cgi/~checkout~/code/tool/bin2c/bin2c.cpp?rev=1.1" target="cvs_checkout" onClick="window.open('/cvs/cvsweb.cgi/~checkout~/code/tool/bin2c/bin2c.cpp?rev=1.1','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR>
Revision <B>1.1</B>, <i>Tue Dec 5 15:02:11 2000 UTC</i> (18 months, 3 weeks ago) by <i>corvazier</i>
<BR>Branch: <b>MAIN</b>
<BR>CVS Tags: <b>HEAD</b><PRE>
no message
</PRE>
</td></tr></table><HR noshade><PRE>// bin2c.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[])
{
if (argc<2)
{
printf ("bin2c [filename.bin] [filename.c]\n");
}
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]);
else
{
_makepath (sOutput, sDir, sPath, sName, ".cpp");
}
FILE *pIn=fopen( argv[1], "rb");
if (pIn==NULL)
printf ("Can't open %s.", argv[1]);
else
{
FILE *pOut=fopen( sOutput, "w");
if (pOut==NULL)
printf ("Can't open %s.", sOutput);
else
{
fprintf (pOut,
"/**\n"
" * Generated by bin2c.exe\n"
" * binfile: %s\n"
" */\n"
"\n"
"extern const unsigned char %s[];\n"
"extern const unsigned int %sSize;\n\n"
"static const unsigned char %s[] =\n"
"{\n", argv[1], sName, sName, sName);
unsigned int size=0;
while (1)
{
fprintf (pOut, "\t");
for (int i=0; i<8; i++)
{
int c=fgetc (pIn);
if (c==EOF)
break;
fprintf (pOut, "0x%02x, ", c);
size++;
}
fprintf (pOut, "\n");
if (i!=8)
break;
}
fprintf (pOut, "};\n\n");
fprintf (pOut, "static const unsigned int %sSize = %d;\n\n", sName, size);
fclose (pOut);
fclose (pIn);
}
}
}
return 0;
}
</PRE>
|