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 ****************************************************************************/
28 #ifdef HAVE_LCD_BITMAP
32 /* The following header is generated by the build system and only defines
33 MAX_LANGUAGE_SIZE to be the size of the largest currently available
35 #include "max_language_size.h"
37 /* These defines must match the initial bytes in the binary lang file */
38 /* See tools/genlang (TODO: Use common include for both) */
39 #define LANGUAGE_COOKIE 0x1a
40 #define LANGUAGE_VERSION 0x05
41 #define LANGUAGE_FLAG_RTL 0x01
45 static unsigned char language_buffer
[MAX_LANGUAGE_SIZE
];
50 unsigned char *ptr
= (unsigned char *) language_builtin
;
52 for (i
= 0; i
< LANG_LAST_INDEX_IN_ARRAY
; i
++) {
53 language_strings
[i
] = ptr
;
54 ptr
+= strlen((char *)ptr
) + 1; /* advance pointer to next string */
58 static unsigned char lang_options
= 0;
62 return (lang_options
& LANGUAGE_FLAG_RTL
) != 0;
65 int lang_load(const char *filename
)
68 int fd
= open(filename
, O_RDONLY
);
70 unsigned char lang_header
[HEADER_SIZE
];
73 fsize
= filesize(fd
) - HEADER_SIZE
;
74 if(fsize
<= MAX_LANGUAGE_SIZE
) {
75 read(fd
, lang_header
, HEADER_SIZE
);
76 if((lang_header
[0] == LANGUAGE_COOKIE
) &&
77 (lang_header
[1] == LANGUAGE_VERSION
) &&
78 (lang_header
[2] == TARGET_ID
)) {
79 read(fd
, language_buffer
, MAX_LANGUAGE_SIZE
);
80 unsigned char *ptr
= language_buffer
;
82 lang_init(); /* initialize with builtin */
85 id
= (ptr
[0]<<8) | ptr
[1]; /* get two-byte id */
86 ptr
+=2; /* pass the id */
87 if(id
< LANG_LAST_INDEX_IN_ARRAY
) {
89 DEBUGF("%2x New: %30s ", id
, ptr
);
90 DEBUGF("Replaces: %s\n", language_strings
[id
]);
92 language_strings
[id
] = ptr
; /* point to this string */
94 while(*ptr
) { /* pass the string */
98 fsize
-=3; /* the id and the terminating zero */
99 ptr
++; /* pass the terminating zero-byte */
103 DEBUGF("Illegal language file\n");
108 DEBUGF("Language %s too large: %d\n", filename
, fsize
);
112 lang_options
= retcode
? 0 : lang_header
[3];
116 int lang_english_to_id(const char* english
)
119 unsigned char *ptr
= (unsigned char *) language_builtin
;
121 for (i
= 0; i
< LANG_LAST_INDEX_IN_ARRAY
; i
++) {
122 if (!strcmp(ptr
, english
))
124 ptr
+= strlen((char *)ptr
) + 1; /* advance pointer to next string */