Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Created November 7, 2018 21:10
Show Gist options
  • Save ljmccarthy/0e15c24656349148ba3e98f2fcd3878c to your computer and use it in GitHub Desktop.
Save ljmccarthy/0e15c24656349148ba3e98f2fcd3878c to your computer and use it in GitHub Desktop.
#!/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