Correct the BBX clause (no visual changes)
[kugel-rb/myfork.git] / apps / language.c
bloba714ef7d904a2a41f5d9940d6cc0f15836fb757b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <file.h>
23 #if defined(SIMULATOR) && defined(__MINGW32__)
24 extern int printf(const char *format, ...);
25 #endif
27 #include "language.h"
28 #include "lang.h"
29 #include "debug.h"
30 #include "string.h"
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
34 language! */
35 #include "max_language_size.h"
37 /* both these must match the two initial bytes in the binary lang file */
38 #define LANGUAGE_COOKIE 0x1a
39 #define LANGUAGE_VERSION 0x04
42 static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
44 void lang_init(void)
46 int i;
47 unsigned char *ptr = (unsigned char *) language_builtin;
49 for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
50 language_strings[i] = ptr;
51 ptr += strlen((char *)ptr) + 1; /* advance pointer to next string */
55 int lang_load(const char *filename)
57 int fsize;
58 int fd = open(filename, O_RDONLY);
59 int retcode=0;
60 unsigned char lang_header[3];
61 if(fd < 0)
62 return 1;
63 fsize = filesize(fd) - 2;
64 if(fsize <= MAX_LANGUAGE_SIZE) {
65 read(fd, lang_header, 3);
66 if((lang_header[0] == LANGUAGE_COOKIE) &&
67 (lang_header[1] == LANGUAGE_VERSION) &&
68 (lang_header[2] == TARGET_ID)) {
69 read(fd, language_buffer, MAX_LANGUAGE_SIZE);
70 unsigned char *ptr = language_buffer;
71 int id;
72 lang_init(); /* initialize with builtin */
74 while(fsize>3) {
75 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
76 ptr+=2; /* pass the id */
77 if(id < LANG_LAST_INDEX_IN_ARRAY) {
78 #if 0
79 printf("%2x New: %30s ", id, ptr);
80 printf("Replaces: %s\n", language_strings[id]);
81 #endif
82 language_strings[id] = ptr; /* point to this string */
84 while(*ptr) { /* pass the string */
85 fsize--;
86 ptr++;
88 fsize-=3; /* the id and the terminating zero */
89 ptr++; /* pass the terminating zero-byte */
92 else {
93 DEBUGF("Illegal language file\n");
94 retcode = 2;
97 else {
98 DEBUGF("Language %s too large: %d\n", filename, fsize);
99 retcode = 3;
101 close(fd);
102 return retcode;