Created
November 7, 2018 21:10
-
-
Save ljmccarthy/0e15c24656349148ba3e98f2fcd3878c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import os | |
import re | |
import sys | |
def incbin(filename): | |
with open(filename, 'rb') as f: | |
data = f.read() | |
name = os.path.splitext(os.path.basename(filename))[0] | |
name = re.sub(r'(?![A-Za-z0-9_]).', '_', name) | |
print(name) | |
with open(filename + '.h', 'w') as f: | |
f.write('static const unsigned char {0}[{1}] = {{'.format(name, len(data))) | |
for x in data: | |
f.write('{:d},'.format(x)) | |
f.write('};\n') | |
if __name__ == '__main__': | |
incbin(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment