summaryrefslogtreecommitdiffstats
path: root/scripts/gen-mplus-patch.pl
blob: b294ec1e29b9a8fe5f93ae62f5c71b46568f79a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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());