A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

genlang: Fix inconsistent rules when enumerating strings

* sort contents of generated apps/lang/english.list
* Ignore all entries with a source of 'none'
* Filter out all destination strings not present in master english list
* Always require '-e' argument

Change-Id: Ic86c0cb6c44139465cba6b6ce840131efe217c4d

+29 -47
+1 -1
apps/lang/lang.make
··· 39 39 # race conditions such as running genlang twice or worse in parallel with other things! 40 40 $(BUILDDIR)/lang/lang.h: $(APPSDIR)/lang/$(ENGLISH).lang $(BUILDDIR)/apps/genlang-features $(TOOLSDIR)/genlang 41 41 $(call PRINTS,GEN lang.h) 42 - $(SILENT)$(TOOLSDIR)/genlang -p=$(BUILDDIR)/lang -t=$(MODELNAME):`cat $(BUILDDIR)/apps/genlang-features` $< 42 + $(SILENT)$(TOOLSDIR)/genlang -e=$(APPSDIR)/lang/$(ENGLISH).lang -p=$(BUILDDIR)/lang -t=$(MODELNAME):`cat $(BUILDDIR)/apps/genlang-features` $< 43 43 $(BUILDDIR)/lang/lang_core.c: $(BUILDDIR)/lang/lang.h $(TOOLSDIR)/genlang 44 44 45 45 $(BUILDDIR)/lang_enum.h: $(BUILDDIR)/lang/lang.h $(TOOLSDIR)/genlang
+28 -46
tools/genlang
··· 38 38 39 39 -e=<english lang file> 40 40 Point out the english (original source) file, to use that as master 41 - language template. Used in combination with -b. 41 + language template. Always required. 42 42 43 43 -t=<target> 44 44 Specify which target you want the translations/phrases for. Required when ··· 64 64 my $prefix = $p; 65 65 my $binary = $b; 66 66 my $binvoice = $c; 67 - 68 - my $english = $e; 69 67 my $voiceout = $o; 70 68 71 - my $check = ($binary?.5:0) + ($prefix?1:0) + ($voiceout?1:0) + ($binvoice?.5:0); 72 - 73 - if($check > 1) { 74 - print STDERR "Please use only one of -p, -o, -b, and -c\n"; 75 - exit; 76 - } 77 - if(!$check) { 78 - print STDERR "Please use at least one of -p, -o, -c, and -e\n"; 79 - exit; 80 - } 81 - 82 - if(($binary || $voiceout) && !$english) { 83 - print STDERR "Please use -e too when you use -b, or -o\n"; 69 + my $english = $e; 70 + if (!$english) { 71 + print STDERR "Please specify the english lang source (with -e)!\n"; 84 72 exit; 85 73 } 86 74 ··· 93 81 my $target = $t; 94 82 if(!$target) { 95 83 print STDERR "Please specify a target (with -t)!\n"; 84 + exit; 85 + } 86 + 87 + my $check = ($binary?.5:0) + ($prefix?1:0) + ($voiceout?1:0) + ($binvoice?.5:0); 88 + if($check > 1) { 89 + print STDERR "Please use only one of -p, -o, -b, and -c\n"; 90 + exit; 91 + } 92 + if(!$check) { 93 + print STDERR "Please use at least one of -p, -o, -c, and -e\n"; 96 94 exit; 97 95 } 98 96 ··· 218 216 my @idnum = ((0)); # start with a true number 219 217 my @vidnum = ((0x8000)); # first voice id 220 218 221 - 222 219 if ($binary and file_is_newer("$binpath/english.list", $english)) { 223 220 open(ENG, "<$binpath/english.list") || 224 221 die "Error: can't open $binpath/english.list"; ··· 242 239 my $numusers = 1; # core is already in the users map 243 240 244 241 while(<ENG>) { 245 - 246 242 # get rid of DOS newlines 247 243 $_ =~ tr/\r//d; 248 244 249 245 if($_ =~ /^ *\<phrase\>/) { 250 246 # this is the start of a phrase 251 - } 252 - elsif($_ =~ /\<\/phrase\>/) { 253 - 247 + } elsif($_ =~ /\<\/phrase\>/) { 254 248 # if id is something, when we count and store this phrase 255 249 if($id) { 256 250 # voice-only entries get a difference range ··· 258 252 # Assign an ID number to this entry 259 253 $idmap[$user]{$id}=$vidnum[$user]; 260 254 $vidnum[$user]++; 261 - } 262 - else { 255 + } else { 263 256 # Assign an ID number to this entry 264 257 $idmap[$user]{$id}=$idnum[$user]; 265 258 $idnum[$user]++; ··· 271 264 } 272 265 undef @phrase; 273 266 $id=""; 274 - } 275 - elsif($_ ne "\n") { 267 + } elsif($_ ne "\n") { 276 268 # gather everything related to this phrase 277 269 push @phrase, $_; 278 270 if($_ =~ /^ *\<dest\>/i) { 279 271 $withindest=1; 280 272 $deststr=""; 281 - } 282 - elsif($withindest && ($_ =~ /^ *\<\/dest\>/i)) { 273 + } elsif($withindest && ($_ =~ /^ *\<\/dest\>/i)) { 283 274 $withindest=0; 284 - 285 275 if($deststr && ($deststr !~ /^none\z/i)) { 286 276 # we unconditionally always use all IDs when the "update" 287 277 # feature is used 288 278 $id = $maybeid; 289 279 # print "DEST: use this id $id\n"; 290 - } 291 - else { 280 + } else { 292 281 # print "skip $maybeid for $name\n"; 293 282 } 294 - } 295 - elsif($withindest && ($_ =~ / *([^:]+): *(.*)/)) { 283 + } elsif($withindest && ($_ =~ / *([^:]+): *(.*)/)) { 296 284 my ($name, $val)=($1, $2); 297 285 $dest=""; # in case it is left untouched for when the 298 286 # model name isn't "ours" ··· 375 363 my $idstr = $phrase{'id'}; 376 364 my $idnum; 377 365 378 - if(($binary || $binvoice || $voiceout) && !$english{$idstr}) { 379 - # $idstr doesn't exist for english, skip it\n"; 380 - # FIXME/TODO: Any reason this filter shouldn't always be enabled? 381 - } 382 - elsif($dest =~ /^none\z/i) { 366 + if($english && !$english{$idstr}) { 367 + # print STDERR "$idstr doesn't exist for english, skip it\n"; 368 + } elsif($dest =~ /^none\z/i || $src =~ /^none\z/i ) { 383 369 # "none" as dest (without quotes) means that this entire 384 370 # phrase is to be ignored 385 - } 386 - elsif($sortfile) { 371 + } elsif($sortfile) { 387 372 $allphrases{$idstr}=join('',@phrase); 388 - } 389 - else { 373 + } else { 390 374 # allow the keyword 'deprecated' to be used on dest and 391 375 # voice strings to mark that as deprecated. It will then 392 376 # be replaced with "". ··· 422 406 if($english) { 423 407 print STDERR "$input:$line:1: warning: user was not found in $english!\n"; 424 408 $user = keys %users; # set to an invalid user so it won't be added 425 - } 426 - else { 409 + } else { 427 410 # we found a new user, add it to the usermap 428 411 $user = ++$numusers; 429 412 $users{$userstr} = $user; ··· 436 419 437 420 if($idstr =~ /^VOICE/) { 438 421 $idnum = $voiceid[$user]++; 439 - } 440 - else { 422 + } else { 441 423 $idnum = $idcount[$user]++; 442 424 } 443 425 ··· 735 717 open(ENGLIST, ">$binpath/english.list") || 736 718 die "Failed creating $binpath/english.list"; 737 719 for my $user (keys %users) { 738 - for my $id (keys %{$idmap[$user]}) { 720 + for my $id (sort { $idmap[$user]{$a} <=> $idmap[$user]{$b} } keys %{$idmap[$user]}) { 739 721 print ENGLIST "$user:$id:$idmap[$user]{$id}\n"; 740 722 } 741 723 }