blob: 123de3614755f5a8f982ee2c3e449d9c0f29d39f [file] [log] [blame]
Solomon Peachy3bd338e2020-09-12 00:18:44 -04001#!/usr/bin/perl -w
2##################
3# * __________ __ ___.
4# * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5# * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6# * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7# * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8# * \/ \/ \/ \/ \/
9# * Copyright (C) 2020 Solomon Peachy
10# *
11# * This program is free software; you can redistribute it and/or
12# * modify it under the terms of the GNU General Public License
13# * as published by the Free Software Foundation; either version 2
14# * of the License, or (at your option) any later version.
15# *
16# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17# * KIND, either express or implied.
18# *
19##################################
20
21use strict;
22use feature 'unicode_strings';
23binmode(STDOUT, ":utf8");
24
25my @langs;
26my @fonts;
27
28my %fontchars;
29my %langchars;
30my %missing;
31
32sub fontcoverage($) {
33 my ($font) = @_;
34
35 open(FILE, "<rockbox/fonts/$font") || die ("can't open $font!\n");
36 while(<FILE>) {
37 if (/^ENCODING\s+(\d+)\s*/) {
38 $fontchars{$font}{chr($1)} = $1;
39 }
40 }
41 close(FILE);
42}
43
44sub langcoverage($) {
45 my ($lang) = @_;
46
47 open(FILE, "<rockbox/apps/lang/$lang") || die ("can't open $lang!\n");
48 binmode(FILE, ":utf8");
49 my $indest = 0;
50 while(<FILE>) {
51 if (/^\s*<dest>\s*$/) {
52 $indest = 1;
53 } elsif (/^\s*<\/dest>\s*$/) {
54 $indest = 0;
55 } elsif ($indest) {
56 if (/\s*\S*\s*:\s*"(\S*)"\s*/u) {
57 next if ($1 eq "none");
58 foreach my $char (split(//, $1)) {
59 if (!defined($langchars{$lang}{$char})) {
60 $langchars{$lang}{$char} = 0;
61 }
62 $langchars{$lang}{$char}++;
63 }
64 }
65 }
66 }
67 close(FILE);
68}
69
70sub calccoverage($$) {
71 my ($lang, $font) = @_;
72 my $total = 0;
73 my $covered = 0;
74 my $str = "";
75
76 foreach my $l (sort(keys(%{$langchars{$lang}}))) {
77 next if ($l eq " ");
78 $str .= $l;
79 $total++;
80 #$total += $langchars{$lang}{$l};
81 if (defined($fontchars{$font}{$l})) {
82 $covered++;
83 #$covered += $langchars{$lang}{$l};
84 } else {
85 $missing{$font}{$lang}{$l} = 1;
86 }
87 }
88
89# return "$covered/$total - '$str'";
90 return $covered/$total;
91}
92
93###################
94
95# Populate font and language lists
96opendir(DIR, "rockbox/apps/lang");
97@langs = grep(/\.lang$/,readdir(DIR));
98closedir(DIR);
99
100opendir(DIR, "rockbox/fonts");
101@fonts = grep(/\.bdf$/,readdir(DIR));
102closedir(DIR);
103
104# Generate coverage maps
105foreach my $x (@fonts) {
106 fontcoverage($x);
107}
108foreach my $x (@langs) {
109 langcoverage($x);
110}
111
112# Geneate INI files
113# (standard summary)
114foreach my $lang (sort(@langs)) {
Solomon Peachy085e5782020-09-12 15:32:44 -0400115 $lang =~ /(.*)\.lang/;
116 print "[$1]\n";
Solomon Peachy3bd338e2020-09-12 00:18:44 -0400117 foreach my $font (sort(@fonts)) {
118 my $coverage = calccoverage($lang, $font);
Solomon Peachy085e5782020-09-12 15:32:44 -0400119 $font =~/(.*).bdf/;
120 printf " $1 = %1.6f\n", $coverage;
Solomon Peachy3bd338e2020-09-12 00:18:44 -0400121 }
122}
123
124# (missing)
Solomon Peachy085e5782020-09-12 15:32:44 -0400125#foreach my $lang (sort(@langs)) {
126# print "[missing|$lang]\n";
127# foreach my $font (sort(@fonts)) {
128# my $str = "";
129# foreach my $missing (keys(%{$missing{$font}{$lang}})) {
130# $str .= "'$missing' (u+".ord($missing).") ";
131# }
132# print " $font = $str\n" if ($str);
133# }
134#}