forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
490899e271
commit
7f25cc9d4e
21
gdk/broadway/gen-c-array.py
Normal file
21
gdk/broadway/gen-c-array.py
Normal file
@ -0,0 +1,21 @@
|
||||
#!/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('};')
|
@ -28,11 +28,18 @@ gdk_broadway_public_headers = [
|
||||
|
||||
gdk_broadway_deps = [shmlib]
|
||||
|
||||
gen_c_array = find_program('gen-c-array.py')
|
||||
|
||||
clienthtml_h = custom_target('clienthtml.h',
|
||||
input : 'client.html',
|
||||
output : 'clienthtml.h',
|
||||
command : [find_program('toarray.pl'), 'client_html', '@INPUT@'],
|
||||
capture : true)
|
||||
command : [
|
||||
gen_c_array,
|
||||
'--array-name=client_html',
|
||||
'--output=@OUTPUT@',
|
||||
'@INPUT@',
|
||||
],
|
||||
)
|
||||
|
||||
libgdk_broadway = static_library('gdk-broadway',
|
||||
clienthtml_h,
|
||||
@ -52,13 +59,18 @@ broadwayd_syslib = os_win32 ? find_library('ws2_32') : shmlib
|
||||
broadwayjs_h = custom_target('broadwayjs.h',
|
||||
input : ['broadway.js'],
|
||||
output : 'broadwayjs.h',
|
||||
command : [find_program('toarray.pl'), 'broadway_js', '@INPUT0@'],
|
||||
capture : true)
|
||||
command : [
|
||||
gen_c_array,
|
||||
'--array-name=broadway_js',
|
||||
'--output=@OUTPUT@',
|
||||
'@INPUT0@',
|
||||
],
|
||||
)
|
||||
|
||||
executable('gtk4-broadwayd',
|
||||
clienthtml_h, broadwayjs_h,
|
||||
'broadwayd.c', 'broadway-server.c', 'broadway-output.c',
|
||||
include_directories: [confinc, gdkinc],
|
||||
include_directories: [confinc, gdkinc, include_directories('.')],
|
||||
c_args: ['-DGDK_COMPILATION', '-DG_LOG_DOMAIN="Gdk"', ],
|
||||
dependencies : [broadwayd_syslib, gdk_deps],
|
||||
install : true)
|
||||
|
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use warnings;
|
||||
|
||||
my $ARRAYNAME = $ARGV[0];
|
||||
my $first = 0;
|
||||
print "static const char $ARRAYNAME\[\] = {";
|
||||
|
||||
for ($i = 1; $i <= $#ARGV; $i = $i + 1) {
|
||||
my $FILENAME = $ARGV[$i];
|
||||
open FILE, $FILENAME or die "Cannot open $FILENAME";
|
||||
while (my $line = <FILE>) {
|
||||
foreach my $c (split //, $line) {
|
||||
if ($first == 1) {
|
||||
printf (",\n");
|
||||
}
|
||||
printf ("0x%02x", ord ($c));
|
||||
$first = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "};\n";
|
||||
|
Loading…
Reference in New Issue
Block a user