Daniel Stenberg | 97ad4c9 | 2002-09-26 09:07:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Daniel Stenberg | e770bc8 | 2002-09-24 12:38:00 +0000 | [diff] [blame] | 2 | ############################################################################ |
| 3 | # __________ __ ___. |
| 4 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 5 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 6 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 7 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 8 | # \/ \/ \/ \/ \/ |
| 9 | # $Id$ |
| 10 | # |
| 11 | # Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> |
| 12 | # |
| 13 | # All files in this archive are subject to the GNU General Public License. |
| 14 | # See the file COPYING in the source tree root for full license agreement. |
| 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 | if(!$ARGV[0] || !$ARGV[1] || !$ARGV[2]) { |
| 22 | print <<MOO |
| 23 | Usage: binlang <english file> <language file> <output file> |
| 24 | |
| 25 | Generate a binary language file. |
| 26 | MOO |
| 27 | ; |
| 28 | exit; |
| 29 | } |
| 30 | |
| 31 | my $english = $ARGV[0]; |
| 32 | my $input = $ARGV[1]; |
| 33 | my $output = $ARGV[2]; |
| 34 | |
| 35 | my $idnum=0; |
| 36 | |
| 37 | open(ENG, "<$english"); |
| 38 | open(LANG, "<$input"); |
| 39 | open(OFILE, ">$output"); |
| 40 | |
| 41 | my $langversion = 1; |
| 42 | |
Daniel Stenberg | 869c952 | 2002-09-24 12:46:04 +0000 | [diff] [blame] | 43 | binmode OFILE; |
| 44 | |
Daniel Stenberg | e770bc8 | 2002-09-24 12:38:00 +0000 | [diff] [blame] | 45 | printf OFILE ("\x1a%c", $langversion); # magic lang file header |
| 46 | |
| 47 | # |
| 48 | # We scan the english file to get the correct order of the id numbers |
| 49 | # |
| 50 | while(<ENG>) { |
| 51 | if($_ =~ / *\#/) { |
| 52 | # comment |
| 53 | next; |
| 54 | } |
| 55 | # get rid of DOS newlines |
| 56 | $_ =~ s/\r//g; |
| 57 | if($_ =~ / *([a-z]+): *(.*)/) { |
| 58 | ($var, $value) = ($1, $2); |
| 59 | $set{$var} = $value; |
| 60 | |
| 61 | if($var eq "new") { |
| 62 | # the last one for a single phrase |
| 63 | $idnum{$set{'id'}}=$idnum; |
| 64 | $idnum++; |
| 65 | undef %set; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | close(ENG); |
| 70 | |
Daniel Stenberg | e770bc8 | 2002-09-24 12:38:00 +0000 | [diff] [blame] | 71 | while(<LANG>) { |
| 72 | if($_ =~ / *\#/) { |
| 73 | # comment |
| 74 | next; |
| 75 | } |
| 76 | # get rid of DOS newlines |
| 77 | $_ =~ s/\r//g; |
| 78 | if($_ =~ / *([a-z]+): *(.*)/) { |
| 79 | ($var, $value) = ($1, $2); |
| 80 | # print "$var => $value\n"; |
| 81 | |
| 82 | $set{$var} = $value; |
| 83 | |
| 84 | if($var eq "new") { |
| 85 | # the last one for a single phrase |
| 86 | |
| 87 | if(!$value) { |
| 88 | # if not set, get the english version |
| 89 | $value = $set{'eng'}; |
| 90 | } |
| 91 | |
Daniel Stenberg | 4aff85f | 2002-10-13 10:08:11 +0000 | [diff] [blame] | 92 | if($value =~ s/^\"(.*)\" *$/$1/g) { |
Daniel Stenberg | e770bc8 | 2002-09-24 12:38:00 +0000 | [diff] [blame] | 93 | |
Daniel Stenberg | 1017e25 | 2002-10-11 22:01:24 +0000 | [diff] [blame] | 94 | $idnum = $idnum{$set{'id'}}; |
| 95 | $idnum{$set{'id'}} = '_done_'; |
Daniel Stenberg | e770bc8 | 2002-09-24 12:38:00 +0000 | [diff] [blame] | 96 | |
Daniel Stenberg | 1017e25 | 2002-10-11 22:01:24 +0000 | [diff] [blame] | 97 | printf OFILE ("%c%c%s\x00", |
| 98 | ($idnum>>8), ($idnum&0xff), |
| 99 | $value); |
| 100 | } |
| 101 | else { |
| 102 | warn "String for ".$set{'id'}." misses quotes\n"; |
| 103 | } |
Daniel Stenberg | e770bc8 | 2002-09-24 12:38:00 +0000 | [diff] [blame] | 104 | |
| 105 | undef %set; |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | close(LANG); |
| 112 | |
| 113 | close(OFILE); |
Daniel Stenberg | 97ad4c9 | 2002-09-26 09:07:46 +0000 | [diff] [blame] | 114 | |
| 115 | foreach $k (keys(%idnum)) |
| 116 | { |
| 117 | if($idnum{$k} ne '_done_') |
| 118 | { |
| 119 | warn "Missing ID in $input: $k\n"; |
| 120 | } |
| 121 | } |