diff options
author | Tomer Shalev <shalev.tomer@gmail.com> | 2009-10-04 22:25:52 +0000 |
---|---|---|
committer | Tomer Shalev <shalev.tomer@gmail.com> | 2009-10-04 22:25:52 +0000 |
commit | 2a91a9a19eabbd38894bd08ac18250c97cb1f2cf (patch) | |
tree | 937261883bf713e42bb8a6ebe71dadf44c77e29e | |
parent | 32d261e3f9b986f29356f63c1b4857eb6890a1b9 (diff) | |
download | rockbox-2a91a9a19eabbd38894bd08ac18250c97cb1f2cf.tar.gz rockbox-2a91a9a19eabbd38894bd08ac18250c97cb1f2cf.zip |
Use similiar constants in genlang and language.c.
- In the future, they should be united.
- Fix bug in max size calculation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22930 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/language.c | 14 | ||||
-rwxr-xr-x | tools/genlang | 10 |
2 files changed, 14 insertions, 10 deletions
diff --git a/apps/language.c b/apps/language.c index 73ed0fe39b..bba1359616 100644 --- a/apps/language.c +++ b/apps/language.c | |||
@@ -31,10 +31,12 @@ | |||
31 | language! */ | 31 | language! */ |
32 | #include "max_language_size.h" | 32 | #include "max_language_size.h" |
33 | 33 | ||
34 | /* both these must match the two initial bytes in the binary lang file */ | 34 | /* These defines must match the initial bytes in the binary lang file */ |
35 | #define LANGUAGE_COOKIE 0x1a | 35 | /* See tools/genlang (TODO: Use common include for both) */ |
36 | #define LANGUAGE_VERSION 0x04 | 36 | #define LANGUAGE_COOKIE 0x1a |
37 | #define LANGUAGE_VERSION 0x04 | ||
37 | 38 | ||
39 | #define HEADER_SIZE 3 | ||
38 | 40 | ||
39 | static unsigned char language_buffer[MAX_LANGUAGE_SIZE]; | 41 | static unsigned char language_buffer[MAX_LANGUAGE_SIZE]; |
40 | 42 | ||
@@ -54,12 +56,12 @@ int lang_load(const char *filename) | |||
54 | int fsize; | 56 | int fsize; |
55 | int fd = open(filename, O_RDONLY); | 57 | int fd = open(filename, O_RDONLY); |
56 | int retcode=0; | 58 | int retcode=0; |
57 | unsigned char lang_header[3]; | 59 | unsigned char lang_header[HEADER_SIZE]; |
58 | if(fd < 0) | 60 | if(fd < 0) |
59 | return 1; | 61 | return 1; |
60 | fsize = filesize(fd) - 2; | 62 | fsize = filesize(fd) - HEADER_SIZE; |
61 | if(fsize <= MAX_LANGUAGE_SIZE) { | 63 | if(fsize <= MAX_LANGUAGE_SIZE) { |
62 | read(fd, lang_header, 3); | 64 | read(fd, lang_header, HEADER_SIZE); |
63 | if((lang_header[0] == LANGUAGE_COOKIE) && | 65 | if((lang_header[0] == LANGUAGE_COOKIE) && |
64 | (lang_header[1] == LANGUAGE_VERSION) && | 66 | (lang_header[1] == LANGUAGE_VERSION) && |
65 | (lang_header[2] == TARGET_ID)) { | 67 | (lang_header[2] == TARGET_ID)) { |
diff --git a/tools/genlang b/tools/genlang index 45171290d6..cedd052839 100755 --- a/tools/genlang +++ b/tools/genlang | |||
@@ -10,8 +10,10 @@ | |||
10 | # Copyright (C) 2006 - 2008 by Daniel Stenberg | 10 | # Copyright (C) 2006 - 2008 by Daniel Stenberg |
11 | # | 11 | # |
12 | 12 | ||
13 | # binary version for the binary lang file | 13 | # See apps/language.c (TODO: Use common include for both) |
14 | my $langversion = 4; # 3 was the latest one used in the v1 format | 14 | # Cookie and binary version for the binary lang file |
15 | my $LANGUAGE_COOKIE = 0x1a; | ||
16 | my $LANGUAGE_VERSION = 0x04; | ||
15 | 17 | ||
16 | # A note for future users and readers: The original v1 language system allowed | 18 | # A note for future users and readers: The original v1 language system allowed |
17 | # the build to create and use a different language than english built-in. We | 19 | # the build to create and use a different language than english built-in. We |
@@ -26,7 +28,7 @@ my %user2num = | |||
26 | 28 | ||
27 | if(!$ARGV[0]) { | 29 | if(!$ARGV[0]) { |
28 | print <<MOO | 30 | print <<MOO |
29 | Usage: genlang [options] <langv2 file> | 31 | Usage: genlang [options] <langv4 file> |
30 | 32 | ||
31 | -p=<prefix> | 33 | -p=<prefix> |
32 | Make the tool create a [prefix].c and [prefix].h file. | 34 | Make the tool create a [prefix].c and [prefix].h file. |
@@ -659,7 +661,7 @@ elsif($binary) { | |||
659 | 661 | ||
660 | open(OUTF, ">$binary") or die "Error: Can't create $binary"; | 662 | open(OUTF, ">$binary") or die "Error: Can't create $binary"; |
661 | binmode OUTF; | 663 | binmode OUTF; |
662 | printf OUTF ("\x1a%c%c", $langversion, $target_id); # magic lang file header | 664 | printf OUTF ("%c%c%c", $LANGUAGE_COOKIE, $LANGUAGE_VERSION, $target_id); # magic lang file header |
663 | 665 | ||
664 | # loop over the target phrases | 666 | # loop over the target phrases |
665 | for $i (1 .. $idcount) { | 667 | for $i (1 .. $idcount) { |