Fix for ff/rw in long MP3 files.
[kugel-rb.git] / apps / language.c
blob14fc7f1742704f4b98a58071bbf53a4c65daf290
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <file.h>
21 #if defined(SIMULATOR) && defined(__MINGW32__)
22 extern int printf(const char *format, ...);
23 #endif
25 #include "language.h"
26 #include "lang.h"
27 #include "debug.h"
28 #include "string.h"
30 static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
32 void lang_init(void)
34 int i;
35 unsigned char *ptr = (unsigned char *) language_builtin;
37 for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
38 language_strings[i] = ptr;
39 ptr += strlen(ptr) + 1; /* advance pointer to next string */
43 int lang_load(const char *filename)
45 int filesize;
46 int fd = open(filename, O_RDONLY);
47 int retcode=0;
48 if(fd == -1)
49 return 1;
50 filesize = read(fd, language_buffer, MAX_LANGUAGE_SIZE);
51 if(filesize != MAX_LANGUAGE_SIZE) {
52 if((language_buffer[0] == LANGUAGE_COOKIE) &&
53 (language_buffer[1] == LANGUAGE_VERSION)) {
54 unsigned char *ptr=&language_buffer[2];
55 int id;
56 lang_init(); /* initialize with builtin */
57 filesize-=2;
59 while(filesize>3) {
60 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
61 ptr+=2; /* pass the id */
62 if(id < LANG_LAST_INDEX_IN_ARRAY) {
63 #if 0
64 printf("%2x New: %30s ", id, ptr);
65 printf("Replaces: %s\n", language_strings[id]);
66 #endif
67 language_strings[id] = ptr; /* point to this string */
69 while(*ptr) { /* pass the string */
70 filesize--;
71 ptr++;
73 filesize-=3; /* the id and the terminating zero */
74 ptr++; /* pass the terminating zero-byte */
77 else {
78 DEBUGF("Illegal language file\n");
79 retcode = 2;
82 else {
83 DEBUGF("Language %s too large: %d\n", filename, filesize);
84 retcode = 3;
86 close(fd);
87 return retcode;