Solomon Peachy | 3bd338e | 2020-09-12 00:18:44 -0400 | [diff] [blame] | 1 | #!/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 | |
| 21 | use strict; |
| 22 | use feature 'unicode_strings'; |
| 23 | binmode(STDOUT, ":utf8"); |
| 24 | |
| 25 | my @langs; |
| 26 | my @fonts; |
| 27 | |
| 28 | my %fontchars; |
| 29 | my %langchars; |
| 30 | my %missing; |
| 31 | |
| 32 | sub 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 | |
| 44 | sub 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 | |
| 70 | sub 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 |
| 96 | opendir(DIR, "rockbox/apps/lang"); |
| 97 | @langs = grep(/\.lang$/,readdir(DIR)); |
| 98 | closedir(DIR); |
| 99 | |
| 100 | opendir(DIR, "rockbox/fonts"); |
| 101 | @fonts = grep(/\.bdf$/,readdir(DIR)); |
| 102 | closedir(DIR); |
| 103 | |
| 104 | # Generate coverage maps |
| 105 | foreach my $x (@fonts) { |
| 106 | fontcoverage($x); |
| 107 | } |
| 108 | foreach my $x (@langs) { |
| 109 | langcoverage($x); |
| 110 | } |
| 111 | |
| 112 | # Geneate INI files |
| 113 | # (standard summary) |
| 114 | foreach my $lang (sort(@langs)) { |
Solomon Peachy | 085e578 | 2020-09-12 15:32:44 -0400 | [diff] [blame] | 115 | $lang =~ /(.*)\.lang/; |
| 116 | print "[$1]\n"; |
Solomon Peachy | 3bd338e | 2020-09-12 00:18:44 -0400 | [diff] [blame] | 117 | foreach my $font (sort(@fonts)) { |
| 118 | my $coverage = calccoverage($lang, $font); |
Solomon Peachy | 085e578 | 2020-09-12 15:32:44 -0400 | [diff] [blame] | 119 | $font =~/(.*).bdf/; |
| 120 | printf " $1 = %1.6f\n", $coverage; |
Solomon Peachy | 3bd338e | 2020-09-12 00:18:44 -0400 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | # (missing) |
Solomon Peachy | 085e578 | 2020-09-12 15:32:44 -0400 | [diff] [blame] | 125 | #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 | #} |