glib/gio/data-to-c.py
Philip Withnall 1897e66dce build: Drop data-to-c.pl in favour of data-to-c.py
The Python version was added for the Meson build, but we might as well
use it from autotools too, since it does exactly the same thing as the
Perl version (modulo not including a trailing linebreak, but that
doesn’t matter).

Works fine with Python 2.7 or Python 3.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790147
2017-11-10 11:47:57 +00:00

17 lines
401 B
Python
Executable File

#!/usr/bin/env python
import sys
if len(sys.argv) < 4:
print('Usage: {0} <filename> <variable> <output>')
with open(sys.argv[1], 'rb') as f:
in_data = f.read().decode('utf-8', 'backslashreplace')
b = [r'\x{:02x}'.format(ord(c)) for c in in_data]
out_data = "const char {0}[] = \"".format(sys.argv[2])
out_data += "".join(b) + "\";"
with open(sys.argv[3], 'w') as f:
f.write(out_data)