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 ****************************************************************************/
23 #if defined(SIMULATOR) && defined(__MINGW32__)
24 extern int printf(const char *format
, ...);
32 static unsigned char language_buffer
[MAX_LANGUAGE_SIZE
];
37 unsigned char *ptr
= (unsigned char *) language_builtin
;
39 for (i
= 0; i
< LANG_LAST_INDEX_IN_ARRAY
; i
++) {
40 language_strings
[i
] = ptr
;
41 ptr
+= strlen((char *)ptr
) + 1; /* advance pointer to next string */
45 int lang_load(const char *filename
)
48 int fd
= open(filename
, O_RDONLY
);
50 unsigned char lang_header
[3];
53 fsize
= filesize(fd
) - 2;
54 if(fsize
<= MAX_LANGUAGE_SIZE
) {
55 read(fd
, lang_header
, 3);
56 if((lang_header
[0] == LANGUAGE_COOKIE
) &&
57 (lang_header
[1] == LANGUAGE_VERSION
) &&
58 (lang_header
[2] == TARGET_ID
)) {
59 read(fd
, language_buffer
, MAX_LANGUAGE_SIZE
);
60 unsigned char *ptr
= language_buffer
;
62 lang_init(); /* initialize with builtin */
65 id
= (ptr
[0]<<8) | ptr
[1]; /* get two-byte id */
66 ptr
+=2; /* pass the id */
67 if(id
< LANG_LAST_INDEX_IN_ARRAY
) {
69 printf("%2x New: %30s ", id
, ptr
);
70 printf("Replaces: %s\n", language_strings
[id
]);
72 language_strings
[id
] = ptr
; /* point to this string */
74 while(*ptr
) { /* pass the string */
78 fsize
-=3; /* the id and the terminating zero */
79 ptr
++; /* pass the terminating zero-byte */
83 DEBUGF("Illegal language file\n");
88 DEBUGF("Language %s too large: %d\n", filename
, fsize
);