gtk/gdk/broadway/gen-c-array.py
Emmanuele Bassi 7f25cc9d4e Rewrite toarray Perl script to Python
We don't need to shell out to Perl to generate a C array out of a text
file.
2018-02-14 15:51:45 +00:00

22 lines
668 B
Python

#!/usr/bin/env python3
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--array-name', help='The name of the array variable')
parser.add_argument('--output', metavar='FILE', help='Output file',
type=argparse.FileType('w'),
default=sys.stdout)
parser.add_argument('input', metavar='FILE', help='The input file',
type=argparse.FileType('r'))
args = parser.parse_args()
args.output.write('static const char {}[] = {{\n'.format(args.array_name))
for line in args.input:
for ch in line:
args.output.write(' 0x{:02x},\n'.format(ord(ch)))
args.output.write('};')