mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-15 05:00:09 +00:00
7f25cc9d4e
We don't need to shell out to Perl to generate a C array out of a text file.
22 lines
668 B
Python
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('};')
|