summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2011-03-02 12:30:49 +0000
committerBjörn Stenberg <bjorn@haxx.se>2011-03-02 12:30:49 +0000
commitd0fdeca19ed4e3beefb1beefdb93eee12bd3c364 (patch)
tree15cf9b8da092290e4bb5e8737248be7fb959291f
parenta43fb47ed6a4b006de4be9b2fc5c5ae88d8c4398 (diff)
downloadrockbox-d0fdeca19ed4e3beefb1beefdb93eee12bd3c364.tar.gz
rockbox-d0fdeca19ed4e3beefb1beefdb93eee12bd3c364.zip
Added english id caching to speed up builds.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29498 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-xtools/genlang60
1 files changed, 49 insertions, 11 deletions
diff --git a/tools/genlang b/tools/genlang
index 81d5066453..c62a376d00 100755
--- a/tools/genlang
+++ b/tools/genlang
@@ -123,6 +123,11 @@ if(!$target && !$update && !$sortfile) {
123} 123}
124my @target_parts = split ':', $target; 124my @target_parts = split ':', $target;
125 125
126my $binpath = "";
127if ($binary =~ m|(.*)/[^/]+|) {
128 $binpath = $1;
129}
130
126my $verbose=$v; 131my $verbose=$v;
127 132
128my %id; # string to num hash 133my %id; # string to num hash
@@ -148,12 +153,6 @@ sub trim {
148 return $string; 153 return $string;
149} 154}
150 155
151sub match {
152 my ($string, $pattern)=@_;
153
154 return ($string =~ /^$pattern\z/);
155}
156
157sub blank { 156sub blank {
158 # nothing to do 157 # nothing to do
159} 158}
@@ -212,15 +211,44 @@ sub voice {
212 parsetarget("voice", \$voice, @_); 211 parsetarget("voice", \$voice, @_);
213} 212}
214 213
214sub file_is_newer {
215 my ($file1, $file2) = @_;
216
217 my @s1 = stat $file1;
218 my @s2 = stat $file2;
219
220 return 1 if ($s1[9] > $s2[9]);
221 return 0;
222}
223
215my %idmap; 224my %idmap;
216my %english; 225my %english;
217if($english) { 226if($english) {
227 readenglish();
228}
229
230sub readenglish {
218 # For the cases where the english file needs to be scanned/read, we do 231 # For the cases where the english file needs to be scanned/read, we do
219 # it before we read the translated file. For -b it isn't necessary, but for 232 # it before we read the translated file. For -b it isn't necessary, but for
220 # -u it is convenient. 233 # -u it is convenient.
221 234
222 my @idnum = ((0)); # start with a true number 235 my @idnum = ((0)); # start with a true number
223 my @vidnum = ((0x8000)); # first voice id 236 my @vidnum = ((0x8000)); # first voice id
237
238
239 if (!$update and file_is_newer("$binpath/english.list", $english)) {
240 open(ENG, "<$binpath/english.list") ||
241 die "Error: can't open $binpath/english.list";
242 while (<ENG>) {
243 my ($user, $id, $value) = split ':', $_;
244 $idmap[$user]{$id} = $value;
245 $english{$id} = 1;
246 }
247 close ENG;
248
249 return;
250 }
251
224 open(ENG, "<$english") || die "Error: can't open $english"; 252 open(ENG, "<$english") || die "Error: can't open $english";
225 my @phrase; 253 my @phrase;
226 my $id; 254 my $id;
@@ -233,12 +261,12 @@ if($english) {
233 while(<ENG>) { 261 while(<ENG>) {
234 262
235 # get rid of DOS newlines 263 # get rid of DOS newlines
236 $_ =~ s/\r//g; 264 $_ =~ tr/\r//d;
237 265
238 if($_ =~ /^ *\<phrase\>/) { 266 if($_ =~ /^ *\<phrase\>/) {
239 # this is the start of a phrase 267 # this is the start of a phrase
240 } 268 }
241 elsif($_ =~ /^ *\<\/phrase\>/) { 269 elsif($_ =~ /\<\/phrase\>/) {
242 270
243 # if id is something, when we count and store this phrase 271 # if id is something, when we count and store this phrase
244 if($id) { 272 if($id) {
@@ -409,7 +437,7 @@ while(<LANG>) {
409 $line++; 437 $line++;
410 438
411 # get rid of DOS newlines 439 # get rid of DOS newlines
412 $_ =~ s/\r//g; 440 $_ =~ tr/\r//d;
413 441
414 if($_ =~ /^( *\#|[ \t\n\r]*\z)/) { 442 if($_ =~ /^( *\#|[ \t\n\r]*\z)/) {
415 # comment or empty line - output it if it's part of the header 443 # comment or empty line - output it if it's part of the header
@@ -640,7 +668,7 @@ MOO
640 for $i (0 .. $idcount[$users{"core"}]-1) { 668 for $i (0 .. $idcount[$users{"core"}]-1) {
641 my $name=$idnum[$users{"core"}][$i]; # get the ID name 669 my $name=$idnum[$users{"core"}][$i]; # get the ID name
642 670
643 $name =~ s/\"//g; # cut off the quotes 671 $name =~ tr/\"//d; # cut off the quotes
644 672
645 printf HFILE_CORE (" %s, /* %d */\n", $name, $i); 673 printf HFILE_CORE (" %s, /* %d */\n", $name, $i);
646 } 674 }
@@ -658,7 +686,7 @@ MOO
658 for $i (0x8001 .. ($voiceid[$users{"core"}]-1)) { 686 for $i (0x8001 .. ($voiceid[$users{"core"}]-1)) {
659 my $name=$idnum[$users{"core"}][$i]; # get the ID name 687 my $name=$idnum[$users{"core"}][$i]; # get the ID name
660 688
661 $name =~ s/\"//g; # cut off the quotes 689 $name =~ tr/\"//d; # cut off the quotes
662 690
663 printf HFILE_CORE (" %s, /* 0x%x */\n", $name, $i); 691 printf HFILE_CORE (" %s, /* 0x%x */\n", $name, $i);
664 } 692 }
@@ -802,3 +830,13 @@ if($verbose) {
802 } 830 }
803} 831}
804 832
833if (!-r "$binpath/english.list") {
834 open(ENGLIST, ">$binpath/english.list") ||
835 die "Failed creating $binpath/english.list";
836 for my $user (keys %users) {
837 for my $id (keys %{$idmap[$user]}) {
838 print ENGLIST "$user:$id:$idmap[$user]{$id}\n";
839 }
840 }
841 close ENGLIST;
842}