2021-02-27 23:19:09 +01:00
|
|
|
#!/usr/bin/env python3
|
2016-12-20 23:37:24 +01:00
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if len(sys.argv) < 4:
|
2020-11-17 16:07:09 +01:00
|
|
|
print("Usage: {0} <filename> <variable> <output>")
|
2016-12-20 23:37:24 +01:00
|
|
|
|
2021-02-27 23:19:09 +01:00
|
|
|
with open(sys.argv[1], "r", encoding="utf-8", errors="backslashreplace") as f:
|
|
|
|
in_data = f.read()
|
|
|
|
|
2020-11-17 16:07:09 +01:00
|
|
|
b = [r"\x{:02x}".format(ord(c)) for c in in_data]
|
2016-12-20 23:37:24 +01:00
|
|
|
|
2020-11-17 16:07:09 +01:00
|
|
|
out_data = 'const char {0}[] = "'.format(sys.argv[2])
|
2021-07-02 14:10:51 +02:00
|
|
|
out_data += "".join(b) + '";\n'
|
2016-12-20 23:37:24 +01:00
|
|
|
|
2020-11-17 16:07:09 +01:00
|
|
|
with open(sys.argv[3], "w") as f:
|
2016-12-20 23:37:24 +01:00
|
|
|
f.write(out_data)
|