diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-09-24 12:38:00 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-09-24 12:38:00 +0000 |
commit | e770bc8be0717199e244ffe3756d866f25831e25 (patch) | |
tree | df09b6dbe92de2f0d0c50b6acab7f8bb58dec1cf /tools | |
parent | 2da8e8e1959f8949e263f47f396fbc5eee9632c1 (diff) | |
download | rockbox-e770bc8be0717199e244ffe3756d866f25831e25.tar.gz rockbox-e770bc8be0717199e244ffe3756d866f25831e25.zip |
funny little script to generate a binary language file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2386 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/binlang | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/binlang b/tools/binlang new file mode 100755 index 0000000000..284dbf738e --- /dev/null +++ b/tools/binlang | |||
@@ -0,0 +1,107 @@ | |||
1 | #!/usr/bin/perl | ||
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 | |||
43 | printf OFILE ("\x1a%c", $langversion); # magic lang file header | ||
44 | |||
45 | # | ||
46 | # We scan the english file to get the correct order of the id numbers | ||
47 | # | ||
48 | while(<ENG>) { | ||
49 | if($_ =~ / *\#/) { | ||
50 | # comment | ||
51 | next; | ||
52 | } | ||
53 | # get rid of DOS newlines | ||
54 | $_ =~ s/\r//g; | ||
55 | if($_ =~ / *([a-z]+): *(.*)/) { | ||
56 | ($var, $value) = ($1, $2); | ||
57 | $set{$var} = $value; | ||
58 | |||
59 | if($var eq "new") { | ||
60 | # the last one for a single phrase | ||
61 | $idnum{$set{'id'}}=$idnum; | ||
62 | $idnum++; | ||
63 | undef %set; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | close(ENG); | ||
68 | |||
69 | |||
70 | while(<LANG>) { | ||
71 | if($_ =~ / *\#/) { | ||
72 | # comment | ||
73 | next; | ||
74 | } | ||
75 | # get rid of DOS newlines | ||
76 | $_ =~ s/\r//g; | ||
77 | if($_ =~ / *([a-z]+): *(.*)/) { | ||
78 | ($var, $value) = ($1, $2); | ||
79 | # print "$var => $value\n"; | ||
80 | |||
81 | $set{$var} = $value; | ||
82 | |||
83 | if($var eq "new") { | ||
84 | # the last one for a single phrase | ||
85 | |||
86 | if(!$value) { | ||
87 | # if not set, get the english version | ||
88 | $value = $set{'eng'}; | ||
89 | } | ||
90 | |||
91 | $value =~ s/^\"(.*)\"/$1/g; | ||
92 | |||
93 | $idnum = $idnum{$set{'id'}}; | ||
94 | |||
95 | printf OFILE ("%c%c%s\x00", | ||
96 | ($idnum>>8), ($idnum&0xff), | ||
97 | $value); | ||
98 | |||
99 | undef %set; | ||
100 | } | ||
101 | |||
102 | } | ||
103 | |||
104 | } | ||
105 | close(LANG); | ||
106 | |||
107 | close(OFILE); | ||