summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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());