When we read the year from the RTC, it can be so totally messed up so that
[kugel-rb.git] / tools / binlang
blob58c4e0a0ec22b2edec4d07ffd50d0ef1fac4c835
1 #!/usr/bin/env perl
2 ############################################################################
3 # __________ __ ___.
4 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 # \/ \/ \/ \/ \/
9 # $Id$
11 # Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
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.
16 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 # KIND, either express or implied.
19 ############################################################################
21 if(!$ARGV[0] || !$ARGV[1] || !$ARGV[2]) {
22 print <<MOO
23 Usage: binlang <english file> <language file> <output file>
25 Generate a binary language file.
26 MOO
28 exit;
31 if($ARGV[0] eq "-v") {
32 shift @ARGV;
33 $debug=1;
36 my $english = $ARGV[0];
37 my $input = $ARGV[1];
38 my $output = $ARGV[2];
40 my $idnum=0;
42 open(ENG, "<$english") or die "Can't open $english";
43 open(LANG, "<$input") or die "Can't open $input";
44 open(OUTF, ">$output") or die "Can't open $output";
46 my $langversion = 1;
48 binmode OUTF;
50 printf OUTF ("\x1a%c", $langversion); # magic lang file header
53 # We scan the english file to get the correct order of the id numbers
55 my $idnum=0; # start with a true number
56 while(<ENG>) {
57 if($_ =~ / *\#/) {
58 # comment
59 next;
61 # get rid of DOS newlines
62 $_ =~ s/\r//g;
63 if($_ =~ /^ *([a-z]+): *(.*)/) {
64 ($var, $value) = ($1, $2);
65 $set{$var} = $value;
67 if($var eq "new") {
68 # the last one for a single phrase
69 $idnum{$set{'id'}}=$idnum;
70 $idnum++;
71 undef %set;
75 close(ENG);
77 while(<LANG>) {
78 if($_ =~ /^ *\#/) {
79 # comment
80 next;
82 # get rid of DOS newlines
83 $_ =~ s/\r//g;
84 if($_ =~ /^ *([a-z]+): *(.*)/) {
85 ($var, $value) = ($1, $2);
86 # print "$var => $value\n";
88 $set{$var} = $value;
90 if($var eq "new") {
91 # the last one for a single phrase
93 if(!$value) {
94 # if not set, get the english version
95 $value = $set{'eng'};
98 if($value =~ s/^\"(.*)\"\s*$/$1/g) {
100 $idnum = $idnum{$set{'id'}};
102 if($idnum eq "") {
103 warn "Found no ".$set{'id'}." in english file!\n";
105 else {
106 $idnum{$set{'id'}} = '_done_';
108 printf OUTF ("%c%c%s\x00",
109 ($idnum>>8), ($idnum&0xff),
110 $value);
111 if($debug) {
112 printf("%02x => %s\n", $idnum, $value);
116 else {
117 warn "String for ".$set{'id'}." misses quotes\n";
120 undef %set;
126 close(LANG);
128 close(OUTF);
130 foreach $k (keys(%idnum))
132 if($idnum{$k} ne '_done_')
134 warn "Missing ID in $input: $k\n";