1*84e872a0SLloyd Pique#!/usr/bin/env python3 2*84e872a0SLloyd Pique 3*84e872a0SLloyd Pique""" 4*84e872a0SLloyd PiqueSimple C data embedder 5*84e872a0SLloyd Pique 6*84e872a0SLloyd PiqueLicense: MIT 7*84e872a0SLloyd Pique 8*84e872a0SLloyd PiqueCopyright (c) 2020 Simon Ser 9*84e872a0SLloyd Pique 10*84e872a0SLloyd PiquePermission is hereby granted, free of charge, to any person obtaining a copy 11*84e872a0SLloyd Piqueof this software and associated documentation files (the "Software"), to deal 12*84e872a0SLloyd Piquein the Software without restriction, including without limitation the rights 13*84e872a0SLloyd Piqueto use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14*84e872a0SLloyd Piquecopies of the Software, and to permit persons to whom the Software is 15*84e872a0SLloyd Piquefurnished to do so, subject to the following conditions: 16*84e872a0SLloyd Pique 17*84e872a0SLloyd PiqueThe above copyright notice and this permission notice shall be included in all 18*84e872a0SLloyd Piquecopies or substantial portions of the Software. 19*84e872a0SLloyd Pique 20*84e872a0SLloyd PiqueTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21*84e872a0SLloyd PiqueIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22*84e872a0SLloyd PiqueFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23*84e872a0SLloyd PiqueAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24*84e872a0SLloyd PiqueLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25*84e872a0SLloyd PiqueOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26*84e872a0SLloyd PiqueSOFTWARE. 27*84e872a0SLloyd Pique""" 28*84e872a0SLloyd Pique 29*84e872a0SLloyd Piqueimport sys 30*84e872a0SLloyd Pique 31*84e872a0SLloyd Piqueif len(sys.argv) != 3: 32*84e872a0SLloyd Pique print('usage: ' + sys.argv[0] + ' <filename> <ident>', file=sys.stderr) 33*84e872a0SLloyd Pique sys.exit(1) 34*84e872a0SLloyd Pique 35*84e872a0SLloyd Piquefilename = sys.argv[1] 36*84e872a0SLloyd Piqueident = sys.argv[2] 37*84e872a0SLloyd Pique 38*84e872a0SLloyd Piquewith open(filename, 'rb') as f: 39*84e872a0SLloyd Pique buf = f.read() 40*84e872a0SLloyd Pique 41*84e872a0SLloyd Piqueprint('static const char ' + ident + '[] = {\n\t', end='') 42*84e872a0SLloyd Piquefor i in range(len(buf)): 43*84e872a0SLloyd Pique ch = buf[i:i+1] 44*84e872a0SLloyd Pique print('0x' + ch.hex() + ', ', end='') 45*84e872a0SLloyd Piqueprint('\n};') 46