2002-09-24 12:39:33 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Daniel Stenberg
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-09-24 12:39:33 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <file.h>
|
2002-11-04 22:53:22 +00:00
|
|
|
#if defined(SIMULATOR) && defined(__MINGW32__)
|
|
|
|
extern int printf(const char *format, ...);
|
|
|
|
#endif
|
2002-09-24 12:39:33 +00:00
|
|
|
|
|
|
|
#include "language.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "debug.h"
|
2005-01-19 21:43:15 +00:00
|
|
|
#include "string.h"
|
2002-09-24 12:39:33 +00:00
|
|
|
|
2008-12-03 12:14:46 +00:00
|
|
|
/* The following header is generated by the build system and only defines
|
|
|
|
MAX_LANGUAGE_SIZE to be the size of the largest currently available
|
|
|
|
language! */
|
|
|
|
#include "max_language_size.h"
|
|
|
|
|
|
|
|
/* both these must match the two initial bytes in the binary lang file */
|
|
|
|
#define LANGUAGE_COOKIE 0x1a
|
|
|
|
#define LANGUAGE_VERSION 0x04
|
|
|
|
|
|
|
|
|
2002-09-24 12:39:33 +00:00
|
|
|
static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
|
|
|
|
|
2005-01-19 21:43:15 +00:00
|
|
|
void lang_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *ptr = (unsigned char *) language_builtin;
|
|
|
|
|
|
|
|
for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
|
|
|
|
language_strings[i] = ptr;
|
2005-12-05 22:44:42 +00:00
|
|
|
ptr += strlen((char *)ptr) + 1; /* advance pointer to next string */
|
2005-01-19 21:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 01:09:31 +00:00
|
|
|
int lang_load(const char *filename)
|
2002-09-24 12:39:33 +00:00
|
|
|
{
|
2005-12-06 00:44:57 +00:00
|
|
|
int fsize;
|
2002-09-24 12:48:23 +00:00
|
|
|
int fd = open(filename, O_RDONLY);
|
2002-09-24 13:53:41 +00:00
|
|
|
int retcode=0;
|
2007-08-05 19:19:39 +00:00
|
|
|
unsigned char lang_header[3];
|
2008-04-16 19:51:43 +00:00
|
|
|
if(fd < 0)
|
2002-09-24 13:53:41 +00:00
|
|
|
return 1;
|
2005-12-06 00:44:57 +00:00
|
|
|
fsize = filesize(fd) - 2;
|
|
|
|
if(fsize <= MAX_LANGUAGE_SIZE) {
|
2007-08-05 19:19:39 +00:00
|
|
|
read(fd, lang_header, 3);
|
2005-12-06 00:44:57 +00:00
|
|
|
if((lang_header[0] == LANGUAGE_COOKIE) &&
|
2007-08-05 19:19:39 +00:00
|
|
|
(lang_header[1] == LANGUAGE_VERSION) &&
|
|
|
|
(lang_header[2] == TARGET_ID)) {
|
2005-12-06 00:44:57 +00:00
|
|
|
read(fd, language_buffer, MAX_LANGUAGE_SIZE);
|
|
|
|
unsigned char *ptr = language_buffer;
|
2002-09-24 12:48:23 +00:00
|
|
|
int id;
|
2005-01-19 22:27:48 +00:00
|
|
|
lang_init(); /* initialize with builtin */
|
2002-09-24 12:39:33 +00:00
|
|
|
|
2005-12-06 00:44:57 +00:00
|
|
|
while(fsize>3) {
|
2002-09-24 12:50:45 +00:00
|
|
|
id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */
|
|
|
|
ptr+=2; /* pass the id */
|
2002-10-29 12:31:34 +00:00
|
|
|
if(id < LANG_LAST_INDEX_IN_ARRAY) {
|
2005-02-22 12:55:21 +00:00
|
|
|
#if 0
|
2002-10-29 12:31:34 +00:00
|
|
|
printf("%2x New: %30s ", id, ptr);
|
|
|
|
printf("Replaces: %s\n", language_strings[id]);
|
|
|
|
#endif
|
2002-10-14 12:20:53 +00:00
|
|
|
language_strings[id] = ptr; /* point to this string */
|
2002-10-29 12:31:34 +00:00
|
|
|
}
|
2002-09-24 12:50:45 +00:00
|
|
|
while(*ptr) { /* pass the string */
|
2005-12-06 00:44:57 +00:00
|
|
|
fsize--;
|
2002-09-24 12:48:23 +00:00
|
|
|
ptr++;
|
|
|
|
}
|
2005-12-06 00:44:57 +00:00
|
|
|
fsize-=3; /* the id and the terminating zero */
|
2002-09-24 12:50:45 +00:00
|
|
|
ptr++; /* pass the terminating zero-byte */
|
2002-09-24 12:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEBUGF("Illegal language file\n");
|
2002-09-24 13:53:41 +00:00
|
|
|
retcode = 2;
|
2002-09-24 12:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2005-12-06 00:44:57 +00:00
|
|
|
DEBUGF("Language %s too large: %d\n", filename, fsize);
|
2002-09-24 13:53:41 +00:00
|
|
|
retcode = 3;
|
2002-09-24 12:39:33 +00:00
|
|
|
}
|
2002-09-24 12:48:23 +00:00
|
|
|
close(fd);
|
2002-09-24 13:53:41 +00:00
|
|
|
return retcode;
|
2002-09-24 12:39:33 +00:00
|
|
|
}
|