summaryrefslogtreecommitdiff
path: root/apps/language.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/language.c')
-rw-r--r--apps/language.c78
1 files changed, 48 insertions, 30 deletions
diff --git a/apps/language.c b/apps/language.c
index fe9ad5e97d..70549e194d 100644
--- a/apps/language.c
+++ b/apps/language.c
@@ -37,10 +37,11 @@
37/* These defines must match the initial bytes in the binary lang file */ 37/* These defines must match the initial bytes in the binary lang file */
38/* See tools/genlang (TODO: Use common include for both) */ 38/* See tools/genlang (TODO: Use common include for both) */
39#define LANGUAGE_COOKIE 0x1a 39#define LANGUAGE_COOKIE 0x1a
40#define LANGUAGE_VERSION 0x05 40#define LANGUAGE_VERSION 0x06
41#define LANGUAGE_FLAG_RTL 0x01 41#define LANGUAGE_FLAG_RTL 0x01
42 42
43#define HEADER_SIZE 4 43#define HEADER_SIZE 4
44#define SUBHEADER_SIZE 6
44 45
45static unsigned char language_buffer[MAX_LANGUAGE_SIZE]; 46static unsigned char language_buffer[MAX_LANGUAGE_SIZE];
46static unsigned char lang_options = 0; 47static unsigned char lang_options = 0;
@@ -54,52 +55,62 @@ void lang_init(const unsigned char *builtin, unsigned char **dest, int count)
54 } 55 }
55} 56}
56 57
57int lang_load(const char *filename) 58int lang_load(const char *filename, const unsigned char *builtin,
59 unsigned char **dest, unsigned char *buffer,
60 unsigned int user_num, int max_lang_size,
61 unsigned int max_id)
58{ 62{
59 int fsize; 63 int lang_size;
60 int fd = open(filename, O_RDONLY); 64 int fd = open(filename, O_RDONLY);
61 int retcode=0; 65 int retcode=0;
62 unsigned char lang_header[HEADER_SIZE]; 66 unsigned char lang_header[HEADER_SIZE];
67 unsigned char sub_header[SUBHEADER_SIZE];
68 unsigned int id, num_strings, foffset;
69
63 if(fd < 0) 70 if(fd < 0)
64 return 1; 71 return 1;
65 fsize = filesize(fd) - HEADER_SIZE; 72 read(fd, lang_header, HEADER_SIZE);
66 if(fsize <= MAX_LANGUAGE_SIZE) { 73 if((lang_header[0] == LANGUAGE_COOKIE) &&
67 read(fd, lang_header, HEADER_SIZE); 74 (lang_header[1] == LANGUAGE_VERSION) &&
68 if((lang_header[0] == LANGUAGE_COOKIE) && 75 (lang_header[2] == TARGET_ID)) {
69 (lang_header[1] == LANGUAGE_VERSION) && 76 /* jump to the proper entry in the table of subheaders */
70 (lang_header[2] == TARGET_ID)) { 77 lseek(fd, user_num * SUBHEADER_SIZE, SEEK_CUR);
71 read(fd, language_buffer, MAX_LANGUAGE_SIZE); 78 read(fd, sub_header, SUBHEADER_SIZE);
72 unsigned char *ptr = language_buffer; 79 /* read in information about the requested lang */
73 int id; 80 num_strings = (sub_header[0]<<8) | sub_header[1];
81 lang_size = (sub_header[2]<<8) | sub_header[3];
82 foffset = (sub_header[4]<<8) | sub_header[5];
83 if(lang_size <= max_lang_size) {
74 /* initialize with builtin */ 84 /* initialize with builtin */
75 lang_init(language_builtin, language_strings, 85 lang_init(builtin, dest, num_strings);
76 LANG_LAST_INDEX_IN_ARRAY); 86 lseek(fd, foffset, SEEK_SET);
87 read(fd, buffer, lang_size);
77 88
78 while(fsize>3) { 89 while(lang_size>3) {
79 id = (ptr[0]<<8) | ptr[1]; /* get two-byte id */ 90 id = ((buffer[0]<<8) | buffer[1]); /* get two-byte id */
80 ptr+=2; /* pass the id */ 91 buffer += 2; /* pass the id */
81 if(id < LANG_LAST_INDEX_IN_ARRAY) { 92 if(id < max_id) {
82#if 0 93#if 0
83 DEBUGF("%2x New: %30s ", id, ptr); 94 DEBUGF("%2x New: %30s ", id, buffer);
84 DEBUGF("Replaces: %s\n", language_strings[id]); 95 DEBUGF("Replaces: %s\n", dest[id]);
85#endif 96#endif
86 language_strings[id] = ptr; /* point to this string */ 97 dest[id] = buffer; /* point to this string */
87 }
88 while(*ptr) { /* pass the string */
89 fsize--;
90 ptr++;
91 } 98 }
92 fsize-=3; /* the id and the terminating zero */ 99 while(*buffer) { /* pass the string */
93 ptr++; /* pass the terminating zero-byte */ 100 lang_size--;
101 buffer++;
102 }
103 lang_size-=3; /* the id and the terminating zero */
104 buffer++; /* pass the terminating zero-byte */
94 } 105 }
95 } 106 }
96 else { 107 else {
97 DEBUGF("Illegal language file\n"); 108 DEBUGF("Language %s too large: %d\n", filename, lang_size);
98 retcode = 2; 109 retcode = 2;
99 } 110 }
100 } 111 }
101 else { 112 else {
102 DEBUGF("Language %s too large: %d\n", filename, fsize); 113 DEBUGF("Illegal language file\n");
103 retcode = 3; 114 retcode = 3;
104 } 115 }
105 close(fd); 116 close(fd);
@@ -107,10 +118,17 @@ int lang_load(const char *filename)
107 return retcode; 118 return retcode;
108} 119}
109 120
121int lang_core_load(const char *filename)
122{
123 return lang_load(filename, core_language_builtin, language_strings,
124 language_buffer, 0, MAX_LANGUAGE_SIZE,
125 LANG_LAST_INDEX_IN_ARRAY);
126}
127
110int lang_english_to_id(const char *english) 128int lang_english_to_id(const char *english)
111{ 129{
112 int i; 130 int i;
113 unsigned char *ptr = (unsigned char *) language_builtin; 131 unsigned char *ptr = (unsigned char *) core_language_builtin;
114 132
115 for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) { 133 for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
116 if (!strcmp(ptr, english)) 134 if (!strcmp(ptr, english))