summaryrefslogtreecommitdiff
path: root/tools/genlang2
diff options
context:
space:
mode:
Diffstat (limited to 'tools/genlang2')
-rwxr-xr-xtools/genlang2124
1 files changed, 86 insertions, 38 deletions
diff --git a/tools/genlang2 b/tools/genlang2
index 7d82f21b31..07c866a288 100755
--- a/tools/genlang2
+++ b/tools/genlang2
@@ -44,6 +44,9 @@ Usage: genlang2 [options] <langv2 file>
44 Specify which target you want the translations/phrases for. Required when 44 Specify which target you want the translations/phrases for. Required when
45 -b or -p is used. 45 -b or -p is used.
46 46
47 -o
48 Voice mode output. Outputs all id: and voice: lines for the given target!
49
47 -v 50 -v
48 Enables verbose (debug) output. 51 Enables verbose (debug) output.
49MOO 52MOO
@@ -69,19 +72,20 @@ my $binary = $b;
69my $update = $u; 72my $update = $u;
70 73
71my $english = $e; 74my $english = $e;
75my $voiceout = $o;
72 76
73my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0); 77my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0);
74 78
75if($check > 1) { 79if($check > 1) {
76 print "Please use only one of -p, -u and -b\n"; 80 print "Please use only one of -p, -u, -o and -b\n";
77 exit; 81 exit;
78} 82}
79if(!$check) { 83if(!$check) {
80 print "Please use at least one of -p, -u and -b\n"; 84 print "Please use at least one of -p, -u, -o and -b\n";
81 exit; 85 exit;
82} 86}
83if(($binary || $update) && !$english) { 87if(($binary || $update || $voiceout) && !$english) {
84 print "Please use -e too when you use -b or -u\n"; 88 print "Please use -e too when you use -b, -o or -u\n";
85 exit; 89 exit;
86} 90}
87 91
@@ -99,7 +103,6 @@ my %source; # id string to source phrase hash
99my %dest; # id string to dest phrase hash 103my %dest; # id string to dest phrase hash
100my %voice; # id string to voice phrase hash 104my %voice; # id string to voice phrase hash
101 105
102
103my $input = $ARGV[0]; 106my $input = $ARGV[0];
104 107
105my @m; 108my @m;
@@ -163,6 +166,7 @@ sub voice {
163 parsetarget("voice", \$voice, @_); 166 parsetarget("voice", \$voice, @_);
164} 167}
165 168
169my %idmap;
166my %english; 170my %english;
167if($english) { 171if($english) {
168 # For the cases where the english file needs to be scanned/read, we do 172 # For the cases where the english file needs to be scanned/read, we do
@@ -170,7 +174,7 @@ if($english) {
170 # -u it is convenient. 174 # -u it is convenient.
171 175
172 my $idnum=0; # start with a true number 176 my $idnum=0; # start with a true number
173 my %idmap; 177 my $vidnum=0x8000; # first voice id
174 open(ENG, "<$english") || die "can't open $english"; 178 open(ENG, "<$english") || die "can't open $english";
175 my @phrase; 179 my @phrase;
176 my $id; 180 my $id;
@@ -194,14 +198,17 @@ if($english) {
194 198
195 if($_ =~ /^ *id: ([^ \t\n]+)/i) { 199 if($_ =~ /^ *id: ([^ \t\n]+)/i) {
196 $id=$1; 200 $id=$1;
197 # Skip voice-only entries 201 # voice-only entries get a difference range
198 if($id =~ /^VOICE_/) { 202 if($id =~ /^VOICE_/) {
199 next; 203 # Assign an ID number to this entry
204 $idmap{$id}=$vidnum;
205 $vidnum++;
206 }
207 else {
208 # Assign an ID number to this entry
209 $idmap{$id}=$idnum;
210 $idnum++;
200 } 211 }
201
202 # Assign an ID number to this entry
203 $idmap{$id}=$idnum;
204 $idnum++;
205 } 212 }
206 } 213 }
207 close(ENG); 214 close(ENG);
@@ -324,7 +331,7 @@ while(<LANG>) {
324 if($dest =~ /^none\z/i) { 331 if($dest =~ /^none\z/i) {
325 # "none" as dest means that this entire phrase is to be 332 # "none" as dest means that this entire phrase is to be
326 # ignored 333 # ignored
327 print "dest is NONE!\n"; 334 #print "dest is NONE!\n";
328 } 335 }
329 else { 336 else {
330 337
@@ -432,11 +439,11 @@ extern unsigned char *language_strings[];
432extern const unsigned char language_builtin[]; 439extern const unsigned char language_builtin[];
433 440
434/* The enum below contains all available strings */ 441/* The enum below contains all available strings */
435enum { 442enum \{
436MOO 443MOO
437 ; 444 ;
438 445
439print CFILE <<MOO 446 print CFILE <<MOO
440/* This file was automaticly generated using genlang2, the strings come 447/* This file was automaticly generated using genlang2, the strings come
441 from "$input" */ 448 from "$input" */
442 449
@@ -445,21 +452,21 @@ print CFILE <<MOO
445unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY]; 452unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY];
446const unsigned char language_builtin[] = 453const unsigned char language_builtin[] =
447MOO 454MOO
448 ; 455;
449
450 # Output the ID names for the enum in the header file
451my $i;
452for $i (1 .. $idcount) {
453 my $name=$idnum[$i - 1]; # get the ID name
454
455 $name =~ s/\"//g; # cut off the quotes
456 456
457 printf HFILE (" %s,\n", $name); 457 # Output the ID names for the enum in the header file
458} 458 my $i;
459 for $i (1 .. $idcount) {
460 my $name=$idnum[$i - 1]; # get the ID name
461
462 $name =~ s/\"//g; # cut off the quotes
463
464 printf HFILE (" %s,\n", $name);
465 }
459 466
460# Output separation marker for last string ID and the upcoming voice IDs 467# Output separation marker for last string ID and the upcoming voice IDs
461 468
462print HFILE <<MOO 469 print HFILE <<MOO
463 LANG_LAST_INDEX_IN_ARRAY, /* this is not a string, this is a marker */ 470 LANG_LAST_INDEX_IN_ARRAY, /* this is not a string, this is a marker */
464 /* --- below this follows voice-only strings --- */ 471 /* --- below this follows voice-only strings --- */
465 VOICEONLY_DELIMITER = 0x8000, 472 VOICEONLY_DELIMITER = 0x8000,
@@ -467,16 +474,16 @@ MOO
467 ; 474 ;
468 475
469# Output the ID names for the enum in the header file 476# Output the ID names for the enum in the header file
470my $i; 477 my $i;
471for $i (0x8000 .. ($voiceid-1)) { 478 for $i (0x8000 .. ($voiceid-1)) {
472 my $name=$idnum[$i]; # get the ID name 479 my $name=$idnum[$i]; # get the ID name
473 480
474 $name =~ s/\"//g; # cut off the quotes 481 $name =~ s/\"//g; # cut off the quotes
475 482
476 printf HFILE (" %s,\n", $name); 483 printf HFILE (" %s,\n", $name);
477} 484 }
478 485
479# Output end of enum 486 # Output end of enum
480 print HFILE "\n};\n/* end of generated enum list */\n"; 487 print HFILE "\n};\n/* end of generated enum list */\n";
481 488
482 # Output the target phrases for the source file 489 # Output the target phrases for the source file
@@ -495,11 +502,11 @@ for $i (0x8000 .. ($voiceid-1)) {
495 } 502 }
496 503
497# Output end of string chunk 504# Output end of string chunk
498print CFILE <<MOO 505 print CFILE <<MOO
499; 506;
500/* end of generated string list */ 507/* end of generated string list */
501MOO 508MOO
502 ; 509;
503 510
504 close(HFILE); 511 close(HFILE);
505 close(CFILE); 512 close(CFILE);
@@ -534,6 +541,47 @@ elsif($binary) {
534 } 541 }
535 } 542 }
536} 543}
544elsif($voiceout) {
545 # voice output requested, display id: and voice: strings in a v1-like
546 # fashion
547
548 my @engl;
549
550 # This loops over the strings in the translated language file order
551 my @ids = ((0 .. ($idcount-1)));
552 push @ids, (0x8000 .. ($voiceid-1));
553
554 #for my $id (@ids) {
555 # print "$id\n";
556 #}
557
558 for $i (@ids) {
559 my $name=$idnum[$i]; # get the ID
560 my $dest = $voice{$name}; # get the destination voice string
561
562 if($dest) {
563 $dest =~ s/^\"(.*)\"\s*$/$1/g; # cut off quotes
564
565 # Now, make sure we get the number from the english sort order:
566 $idnum = $idmap{$name};
567
568 $engl[$idnum] = $i;
569
570 # print "Input index $i output index $idnum\n";
571
572 }
573 }
574 for my $i (@ids) {
575
576 my $o = $engl[$i];
577
578 my $name=$idnum[$o]; # get the ID
579 my $dest = $voice{$name}; # get the destination voice string
580
581 print "#$i\nid: $name\nvoice: $dest\n";
582 }
583
584}
537 585
538 586
539if($verbose) { 587if($verbose) {