-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing file from release/16.x, fixes #71
- Loading branch information
1 parent
83d2082
commit 25d7433
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
cppFileName, bufferName, bcFile = sys.argv[1:4] | ||
|
||
if (sys.version_info > (3, 0)): | ||
cbyte = lambda x: x | ||
else: | ||
cbyte = lambda x: ord(x) | ||
|
||
def bytes_from_file(filename, chunksize=8192): | ||
with open(filename, "rb") as f: | ||
while True: | ||
chunk = f.read(chunksize) | ||
if chunk: | ||
for b in chunk: | ||
yield cbyte(b) | ||
else: | ||
break | ||
|
||
with open(cppFileName, 'w') as out: | ||
# prologue | ||
out.write('#include<string>\n') | ||
out.write('extern "C" const unsigned char %s_Buffer[] = {' % bufferName) | ||
|
||
for idx, byte in enumerate(bytes_from_file(bcFile)): | ||
# transcode file | ||
if idx > 0: | ||
out.write(',') | ||
if idx % 16 == 0: | ||
out.write('\n') | ||
|
||
out.write("0x{:02X}".format(byte)) | ||
|
||
# epilogue | ||
out.write("\n") | ||
out.write("};\n") | ||
out.write('extern "C" const size_t %s_BufferLen = sizeof(%s_Buffer);\n' % (bufferName, bufferName)) |