1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #ifdef HAVE_LCD_BITMAP
33 /* The following header is generated by the build system and only defines
34 MAX_LANGUAGE_SIZE to be the size of the largest currently available
36 #include "max_language_size.h"
38 /* These defines must match the initial bytes in the binary lang file */
39 /* See tools/genlang (TODO: Use common include for both) */
40 #define LANGUAGE_COOKIE 0x1a
41 #define LANGUAGE_VERSION 0x06
42 #define LANGUAGE_FLAG_RTL 0x01
45 #define SUBHEADER_SIZE 6
47 static unsigned char language_buffer
[MAX_LANGUAGE_SIZE
];
48 static unsigned char lang_options
= 0;
50 void lang_init(const unsigned char *builtin
, unsigned char **dest
, int count
)
53 *dest
++ = (unsigned char *)builtin
;
54 /* advance pointer to next string */
55 builtin
+= strlen((char *)builtin
) + 1;
59 int lang_load(const char *filename
, const unsigned char *builtin
,
60 unsigned char **dest
, unsigned char *buffer
,
61 unsigned int user_num
, int max_lang_size
,
65 int fd
= open(filename
, O_RDONLY
);
67 unsigned char lang_header
[HEADER_SIZE
];
68 unsigned char sub_header
[SUBHEADER_SIZE
];
69 unsigned int id
, foffset
;
73 read(fd
, lang_header
, HEADER_SIZE
);
74 if((lang_header
[0] == LANGUAGE_COOKIE
) &&
75 (lang_header
[1] == LANGUAGE_VERSION
) &&
76 (lang_header
[2] == TARGET_ID
)) {
77 /* jump to the proper entry in the table of subheaders */
78 lseek(fd
, user_num
* SUBHEADER_SIZE
, SEEK_CUR
);
79 read(fd
, sub_header
, SUBHEADER_SIZE
);
80 /* read in information about the requested lang */
82 unsigned int num_strings
= (sub_header
[0]<<8) | sub_header
[1];
84 lang_size
= (sub_header
[2]<<8) | sub_header
[3];
85 foffset
= (sub_header
[4]<<8) | sub_header
[5];
86 if(lang_size
<= max_lang_size
) {
87 /* initialize with builtin */
88 lang_init(builtin
, dest
, max_id
);
89 lseek(fd
, foffset
, SEEK_SET
);
90 read(fd
, buffer
, lang_size
);
93 id
= ((buffer
[0]<<8) | buffer
[1]); /* get two-byte id */
94 buffer
+= 2; /* pass the id */
97 DEBUGF("%2x New: %30s ", id
, buffer
);
98 DEBUGF("Replaces: %s\n", dest
[id
]);
100 dest
[id
] = buffer
; /* point to this string */
102 while(*buffer
) { /* pass the string */
106 lang_size
-=3; /* the id and the terminating zero */
107 buffer
++; /* pass the terminating zero-byte */
111 DEBUGF("Language %s too large: %d\n", filename
, lang_size
);
116 DEBUGF("Illegal language file\n");
120 lang_options
= retcode
? 0 : lang_header
[3];
124 int lang_core_load(const char *filename
)
126 return lang_load(filename
, core_language_builtin
, language_strings
,
127 language_buffer
, 0, MAX_LANGUAGE_SIZE
,
128 LANG_LAST_INDEX_IN_ARRAY
);
131 int lang_english_to_id(const char *english
)
134 unsigned char *ptr
= (unsigned char *) core_language_builtin
;
136 for (i
= 0; i
< LANG_LAST_INDEX_IN_ARRAY
; i
++) {
137 if (!strcmp(ptr
, english
))
139 ptr
+= strlen((char *)ptr
) + 1; /* advance pointer to next string */
144 int lang_is_rtl(void)
146 return (lang_options
& LANGUAGE_FLAG_RTL
) != 0;