#include <stdio.h>
#include <strings.h>
Go to the source code of this file.
◆ _stricmp
◆ dumpHex()
Definition at line 18 of file bin2c.c.
19{
20 size_t bufLen = 0;
21 unsigned char ch;
22
24 do
25 {
26
28
29 if (
feof(inFile) && nullTerminate)
30 ch = 0x00;
31
32 if (!
feof(inFile) || nullTerminate)
33 {
34
35 if ((bufLen % 16) == 0)
37
38
39 fprintf(outCFile,
" 0x%02x,", (
unsigned int)ch);
40
41 ++bufLen;
42 }
43 }
while (!
feof(inFile));
45
46 return bufLen;
47}
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Referenced by main().
◆ dumpStr()
Definition at line 49 of file bin2c.c.
50{
51 size_t bufLen = 0;
52 unsigned char ch;
53
54
56 do
57 {
58
60
61
63 {
64
65 if ((bufLen != 0) && (bufLen % 16) == 0)
66 {
67
70 }
71
72
73 fprintf(outCFile,
"\\x%02x", (
unsigned int)ch);
74 }
75
76 else
77 {
79
80 }
81
82 ++bufLen;
83
84 }
while (!
feof(inFile));
85
86 return bufLen;
87}
Referenced by main().
◆ main()
Definition at line 94 of file bin2c.c.
95{
99 size_t bufLen;
100
101
103 {
105 return -1;
106 }
107
108
112 {
114 return -1;
115 }
116
117
119 if (!inFile)
120 {
122 return -1;
123 }
125 if (!outCFile)
126 {
129 return -1;
130 }
132 if (!outHFile)
133 {
137 return -1;
138 }
139
140
141 fprintf(outCFile,
"/* This file is autogenerated, do not edit. */\n\n");
143 {
144
146 }
148
149
151 {
152
154 }
155 fprintf(outCFile,
"unsigned char %s[] =",
argv[5]);
156
157
159 bufLen =
dumpHex(inFile, outCFile, 0);
161 bufLen =
dumpHex(inFile, outCFile, 1);
162 else
163 bufLen =
dumpStr(inFile, outCFile);
164
167
168
169 fprintf(outHFile,
"/* This file is autogenerated, do not edit. */\n\n");
170 fprintf(outHFile,
"#define %s_SIZE %lu\n" ,
argv[5], (
unsigned long)bufLen);
171 fprintf(outHFile,
"extern unsigned char %s[%lu];\n",
argv[5], (
unsigned long)bufLen);
173
174
176
177 return 0;
178}
static size_t dumpHex(FILE *inFile, FILE *outCFile, char nullTerminate)
static size_t dumpStr(FILE *inFile, FILE *outCFile)
GLsizeiptr const GLvoid GLenum usage
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
◆ usage()
Definition at line 89 of file bin2c.c.
90{
91 fprintf(
stdout,
"Usage: %s infile.bin outfile.c outfile.h [BIN|BINSTR|STR] array_name [array_attribute [header_for_attribute]]\n",
name);
92}