Split 8-bit-to-native conversion in bmp.c into a function, add support for plugging...
[kugel-rb.git] / apps / language.c
blob7253ec275bee83a50c63c874a45778579569f9b7
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>
24 #include "language.h"
25 #include "lang.h"
26 #include "debug.h"
27 #include "string.h"
29 /* The following header is generated by the build system and only defines
30 MAX_LANGUAGE_SIZE to be the size of the largest currently available
31 language! */
32 #include "max_language_size.h"
34 /* both these must match the two initial bytes in the binary lang file */
35 #define LANGUAGE_COOKIE 0x1a
36 #define LANGUAGE_VERSION 0x04
39 static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
41 void lang_init(void)
43 int i;
44 unsigned char *ptr = (unsigned char *) language_builtin;
46 for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
47 language_strings[i] = ptr;
48 ptr += strlen((char *)ptr) + 1; /* advance pointer to next string */
52 int lang_load(const char *filename)
54 int fsize;
55 int fd = open(filename, O_RDONLY);
56 int retcode=0;
57 unsigned char lang_header[3];
58 if(fd < 0)
59 return 1;
60 fsize = filesize(fd) - 2;
61 if(fsize <= MAX_LANGUAGE_SIZE) {
62 read(fd, lang_header, 3);
63 if((lang_header[0] == LANGUAGE_COOKIE) &&
64 (lang_header[1] == LANGUAGE_VERSION) &&
65 (lang_header[2] == TARGET_ID)) {
66 read(fd, language_buffer, MAX_LANGUAGE_SIZE);
67 unsigned char *ptr = language_buffer;
68 int id;
69 lang_init(); /* initialize with builtin */
71 while(fsize>3) {
72 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
73 ptr+=2; /* pass the id */
74 if(id < LANG_LAST_INDEX_IN_ARRAY) {
75 #if 0
76 DEBUGF("%2x New: %30s ", id, ptr);
77 DEBUGF("Replaces: %s\n", language_strings[id]);
78 #endif
79 language_strings[id] = ptr; /* point to this string */
81 while(*ptr) { /* pass the string */
82 fsize--;
83 ptr++;
85 fsize-=3; /* the id and the terminating zero */
86 ptr++; /* pass the terminating zero-byte */
89 else {
90 DEBUGF("Illegal language file\n");
91 retcode = 2;
94 else {
95 DEBUGF("Language %s too large: %d\n", filename, fsize);
96 retcode = 3;
98 close(fd);
99 return retcode;