Add a option to skip length which lets you skip 5s before the end of a song, which...
[kugel-rb.git] / apps / language.c
blobfe9ad5e97d6688e23a9402ff5c4a58e899278522
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"
28 #ifdef HAVE_LCD_BITMAP
29 #include "viewport.h"
30 #endif
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 /* 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
43 #define HEADER_SIZE 4
45 static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
46 static unsigned char lang_options = 0;
48 void lang_init(const unsigned char *builtin, unsigned char **dest, int count)
50 while(count--) {
51 *dest++ = (unsigned char *)builtin;
52 /* advance pointer to next string */
53 builtin += strlen((char *)builtin) + 1;
57 int lang_load(const char *filename)
59 int fsize;
60 int fd = open(filename, O_RDONLY);
61 int retcode=0;
62 unsigned char lang_header[HEADER_SIZE];
63 if(fd < 0)
64 return 1;
65 fsize = filesize(fd) - HEADER_SIZE;
66 if(fsize <= MAX_LANGUAGE_SIZE) {
67 read(fd, lang_header, HEADER_SIZE);
68 if((lang_header[0] == LANGUAGE_COOKIE) &&
69 (lang_header[1] == LANGUAGE_VERSION) &&
70 (lang_header[2] == TARGET_ID)) {
71 read(fd, language_buffer, MAX_LANGUAGE_SIZE);
72 unsigned char *ptr = language_buffer;
73 int id;
74 /* initialize with builtin */
75 lang_init(language_builtin, language_strings,
76 LANG_LAST_INDEX_IN_ARRAY);
78 while(fsize>3) {
79 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
80 ptr+=2; /* pass the id */
81 if(id < LANG_LAST_INDEX_IN_ARRAY) {
82 #if 0
83 DEBUGF("%2x New: %30s ", id, ptr);
84 DEBUGF("Replaces: %s\n", language_strings[id]);
85 #endif
86 language_strings[id] = ptr; /* point to this string */
88 while(*ptr) { /* pass the string */
89 fsize--;
90 ptr++;
92 fsize-=3; /* the id and the terminating zero */
93 ptr++; /* pass the terminating zero-byte */
96 else {
97 DEBUGF("Illegal language file\n");
98 retcode = 2;
101 else {
102 DEBUGF("Language %s too large: %d\n", filename, fsize);
103 retcode = 3;
105 close(fd);
106 lang_options = retcode ? 0 : lang_header[3];
107 return retcode;
110 int lang_english_to_id(const char *english)
112 int i;
113 unsigned char *ptr = (unsigned char *) language_builtin;
115 for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
116 if (!strcmp(ptr, english))
117 return i;
118 ptr += strlen((char *)ptr) + 1; /* advance pointer to next string */
120 return -1;
123 int lang_is_rtl(void)
125 return (lang_options & LANGUAGE_FLAG_RTL) != 0;