summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2018-02-14 15:51:45 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2018-02-14 15:51:45 +0000
commit7f25cc9d4efab4b54ca4c1269cd9d7de70c47e70 (patch)
tree9f7d0fcfa10612b605f0ef34cc23cbb688ee502e
parent490899e271fbe223a18469eba60eefd6cbce8075 (diff)
downloadgtk+-7f25cc9d4efab4b54ca4c1269cd9d7de70c47e70.tar.gz
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.
-rw-r--r--gdk/broadway/gen-c-array.py21
-rw-r--r--gdk/broadway/meson.build22
-rwxr-xr-xgdk/broadway/toarray.pl24
3 files changed, 38 insertions, 29 deletions
diff --git a/gdk/broadway/gen-c-array.py b/gdk/broadway/gen-c-array.py
new file mode 100644
index 0000000000..afffda34e5
--- /dev/null
+++ b/gdk/broadway/gen-c-array.py
@@ -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('};')
diff --git a/gdk/broadway/meson.build b/gdk/broadway/meson.build
index 614a623784..970b6c8e6c 100644
--- a/gdk/broadway/meson.build
+++ b/gdk/broadway/meson.build
@@ -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)
diff --git a/gdk/broadway/toarray.pl b/gdk/broadway/toarray.pl
deleted file mode 100755
index 642ea8a433..0000000000
--- a/gdk/broadway/toarray.pl
+++ /dev/null
@@ -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";
-