New way of handling the builtin language strings. Now the string pointers are no longer stored as initialised data, but calculated by walking one long string containing all language strings separated by \0. While this doesn't need more RAM, it fixes the problem that loading incomplete .lng files after complete ones did not reset the missing strings to the default, and it also decreases the binary size by >1700 bytes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5608 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
3c2fefdb99
commit
0f04029293
4 changed files with 29 additions and 4 deletions
|
@ -25,9 +25,21 @@ extern int printf(const char *format, ...);
|
|||
#include "language.h"
|
||||
#include "lang.h"
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
|
||||
static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
|
||||
|
||||
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;
|
||||
ptr += strlen(ptr) + 1; /* advance pointer to next string */
|
||||
}
|
||||
}
|
||||
|
||||
int lang_load(const char *filename)
|
||||
{
|
||||
int filesize;
|
||||
|
@ -39,6 +51,7 @@ int lang_load(const char *filename)
|
|||
if(filesize != MAX_LANGUAGE_SIZE) {
|
||||
if((language_buffer[0] == LANGUAGE_COOKIE) &&
|
||||
(language_buffer[1] == LANGUAGE_VERSION)) {
|
||||
lang_init(); /* initialize with builtin */
|
||||
unsigned char *ptr=&language_buffer[2];
|
||||
int id;
|
||||
filesize-=2;
|
||||
|
|
|
@ -24,5 +24,8 @@
|
|||
#define LANGUAGE_COOKIE 0x1a
|
||||
#define LANGUAGE_VERSION 0x02
|
||||
|
||||
/* Initialize language array with the builtin strings */
|
||||
void lang_init(void);
|
||||
|
||||
/* load a given language file */
|
||||
int lang_load(const char *filename);
|
||||
|
|
|
@ -126,6 +126,7 @@ void init(void)
|
|||
lcd_init();
|
||||
font_init();
|
||||
show_logo();
|
||||
lang_init();
|
||||
settings_reset();
|
||||
settings_calc_config_sector();
|
||||
settings_load(SETTINGS_ALL);
|
||||
|
@ -171,6 +172,7 @@ void init(void)
|
|||
|
||||
font_init();
|
||||
show_logo();
|
||||
lang_init();
|
||||
|
||||
set_irq_level(0);
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -30,8 +30,11 @@ print HFILE <<MOO
|
|||
*/
|
||||
#define str(x) language_strings[x]
|
||||
|
||||
/* this is the array with all the strings */
|
||||
/* this is the array for holding the string pointers.
|
||||
It will be initialized at runtime. */
|
||||
extern unsigned char *language_strings[];
|
||||
/* this contains the concatenation of all strings, separated by \0 chars */
|
||||
extern const unsigned char language_builtin[];
|
||||
|
||||
/* The enum below contains all available strings */
|
||||
enum {
|
||||
|
@ -41,8 +44,11 @@ MOO
|
|||
print CFILE <<MOO
|
||||
/* This file was automaticly generated using genlang, the strings come
|
||||
from "$input" */
|
||||
|
||||
#include "$prefix.h"
|
||||
|
||||
unsigned char *language_strings[]={
|
||||
unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY];
|
||||
const unsigned char language_builtin[] =
|
||||
MOO
|
||||
;
|
||||
|
||||
|
@ -85,7 +91,8 @@ while(<LANG>) {
|
|||
}
|
||||
else {
|
||||
push @hfile, $set{'id'};
|
||||
print CFILE " $value,\n";
|
||||
$value =~ s/\"$/\\0\"/;
|
||||
print CFILE " $value\n";
|
||||
}
|
||||
|
||||
undef %set;
|
||||
|
@ -118,7 +125,7 @@ MOO
|
|||
;
|
||||
|
||||
print CFILE <<MOO
|
||||
};
|
||||
;
|
||||
/* end of generated string list */
|
||||
MOO
|
||||
;
|
||||
|
|
Loading…
Reference in a new issue