summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-14 18:13:35 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-15 00:15:02 (EDT)
commitbb2c565feef46d2e71f6fb4ce3765a6a466dc79a (patch)
treeceba253f6f3664c7c143e7611c5920009733fb1d
parentba3e5d327b034d3e42f04ae77bf9eb571ba49962 (diff)
scripts/gen-mplus-patch.pl: WIP
-rwxr-xr-xscripts/gen-mplus-patch.pl93
1 files changed, 93 insertions, 0 deletions
diff --git a/scripts/gen-mplus-patch.pl b/scripts/gen-mplus-patch.pl
new file mode 100755
index 0000000..b294ec1
--- /dev/null
+++ b/scripts/gen-mplus-patch.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+no indirect;
+no autovivification;
+use English qw(-no_match_vars);
+
+use Text::Diff;
+
+my @FONTS = (
+ # face weight w h
+ [qw(1m regular 16 22)],
+ [qw(1m bold 16 22)],
+ [qw(1mn regular 16 22)],
+ [qw(1mn bold 16 22)],
+);
+
+sub slurp
+{
+ my ($fname) = @_;
+ my $fh;
+ my $data;
+
+ $fname = "tmp/src/$fname";
+ open($fh, '<', $fname) or die("Error opening $fname: $OS_ERROR");
+ local $INPUT_RECORD_SEPARATOR = undef;
+ $data = <$fh>;
+ close($fh) or die("Error closing $fname: $OS_ERROR");
+
+ return $data;
+}
+
+sub make_patch
+{
+ my ($fname, $old, $new) = @_;
+
+ return "diff -Naur a/$fname b/$fname\n--- a/$fname\n+++ b/$fname\n" .
+ diff(\$old, \$new);
+}
+
+sub patch_font_h
+{
+ my $old;
+ my $new;
+ my $i;
+ my $inject;
+ my $face;
+ my $weight;
+ my $width;
+ my $height;
+
+ $new = $old = slurp('include/linux/font.h');
+
+ # Inject "#define"s.
+ ($i) = $old =~ m{.*^[#]\s*define\s+[A-Za-x0-9_]+_IDX\s+(\d+)\s*$}msx;
+ $inject = '';
+ foreach my $font (@FONTS) { ($face, $weight, $width, $height) = @$font;
+ $inject .= sprintf("#define MPLUS_%s_%s_%dx%d_IDX\t%d\n",
+ uc($face), uc($weight), $width, $height, ++$i);
+ }
+ $new =~ s{\A(.*^[#]\s*define\s+[A-Za-z0-9_]+_IDX\s+\d+\s*$)}
+ {$1$inject}msx;
+
+ # Inject "struct font_desc" declarations.
+ $inject = '';
+ foreach my $font (@FONTS) { ($face, $weight, $width, $height) = @$font;
+ $inject .= sprintf(",\n\t\t\tfont_mplus_%s_%s_%dx%d",
+ $face, $weight, $width, $height);
+ }
+ $new =~ s{(extern\sconst\sstruct\sfont_desc[^;]+);}{$1$inject;}msx;
+
+ return make_patch('include/linux/font.h', $old, $new);
+}
+
+sub patch_kconfig
+{
+}
+
+sub patch_makefile
+{
+}
+
+sub patch_fonts_c
+{
+}
+
+sub main
+{
+ print(patch_font_h());
+}
+
+exit(main());