summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/settings_list.c18
-rw-r--r--firmware/common/unicode.c73
-rw-r--r--firmware/include/rbunicode.h4
-rwxr-xr-xtools/buildzip.pl15
-rw-r--r--tools/codepages.c115
-rwxr-xr-xtools/configure12
6 files changed, 165 insertions, 72 deletions
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 4dce7ae157..2b9457e1b0 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -947,18 +947,28 @@ const struct settings_list settings[] = {
947 OFFON_SETTING(0,tagcache_autoupdate, 947 OFFON_SETTING(0,tagcache_autoupdate,
948 LANG_TAGCACHE_AUTOUPDATE,false,"tagcache_autoupdate",NULL), 948 LANG_TAGCACHE_AUTOUPDATE,false,"tagcache_autoupdate",NULL),
949#endif 949#endif
950#ifdef HAVE_LCD_BITMAP
950 CHOICE_SETTING(0, default_codepage, LANG_DEFAULT_CODEPAGE, 0, 951 CHOICE_SETTING(0, default_codepage, LANG_DEFAULT_CODEPAGE, 0,
951 "default codepage", 952 "default codepage", /* The order must match with that in unicode.c */
952 "iso8859-1,iso8859-7,iso8859-8,cp1251,iso8859-11,cp1256," 953 "iso8859-1,iso8859-7,iso8859-8,cp1251,iso8859-11,cp1256,"
953 "iso8859-9,iso8859-2,sjis,gb2312,ksx1001,big5,utf-8,cp1256", 954 "iso8859-9,iso8859-2,sjis,gb2312,ksx1001,big5,utf-8",
954 set_codepage, 13, 955 set_codepage, 13,
955 ID2P(LANG_CODEPAGE_LATIN1), ID2P(LANG_CODEPAGE_GREEK), 956 ID2P(LANG_CODEPAGE_LATIN1), ID2P(LANG_CODEPAGE_GREEK),
956 ID2P(LANG_CODEPAGE_HEBREW), ID2P(LANG_CODEPAGE_CYRILLIC), 957 ID2P(LANG_CODEPAGE_HEBREW), ID2P(LANG_CODEPAGE_CYRILLIC),
957 ID2P(LANG_CODEPAGE_THAI), ID2P(LANG_CODEPAGE_ARABIC), 958 ID2P(LANG_CODEPAGE_THAI), ID2P(LANG_CODEPAGE_ARABIC),
958 ID2P(LANG_CODEPAGE_TURKISH), ID2P(LANG_CODEPAGE_LATIN_EXTENDED), 959 ID2P(LANG_CODEPAGE_TURKISH), ID2P(LANG_CODEPAGE_LATIN_EXTENDED),
959 ID2P(LANG_CODEPAGE_JAPANESE), ID2P(LANG_CODEPAGE_SIMPLIFIED), 960 ID2P(LANG_CODEPAGE_JAPANESE), ID2P(LANG_CODEPAGE_SIMPLIFIED),
960 ID2P(LANG_CODEPAGE_KOREAN), 961 ID2P(LANG_CODEPAGE_KOREAN), ID2P(LANG_CODEPAGE_TRADITIONAL),
961 ID2P(LANG_CODEPAGE_TRADITIONAL), ID2P(LANG_CODEPAGE_UTF8)), 962 ID2P(LANG_CODEPAGE_UTF8)),
963#else /* !HAVE_LCD_BITMAP */
964 CHOICE_SETTING(0, default_codepage, LANG_DEFAULT_CODEPAGE, 0,
965 "default codepage", /* The order must match with that in unicode.c */
966 "iso8859-1,iso8859-7,cp1251,iso8859-9,iso8859-2,utf-8",
967 set_codepage, 6,
968 ID2P(LANG_CODEPAGE_LATIN1), ID2P(LANG_CODEPAGE_GREEK),
969 ID2P(LANG_CODEPAGE_CYRILLIC), ID2P(LANG_CODEPAGE_TURKISH),
970 ID2P(LANG_CODEPAGE_LATIN_EXTENDED), ID2P(LANG_CODEPAGE_UTF8)),
971#endif
962 972
963 OFFON_SETTING(0,warnon_erase_dynplaylist, 973 OFFON_SETTING(0,warnon_erase_dynplaylist,
964 LANG_WARN_ERASEDYNPLAYLIST_MENU,false, 974 LANG_WARN_ERASEDYNPLAYLIST_MENU,false,
diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c
index 34c11369f2..50caa55667 100644
--- a/firmware/common/unicode.c
+++ b/firmware/common/unicode.c
@@ -17,19 +17,20 @@
17#define O_BINARY 0 17#define O_BINARY 0
18#endif 18#endif
19 19
20#define NUM_TABLES 5 20#define CODEPAGE_DIR "/.rockbox/codepages"
21#define NUM_CODEPAGES 13
22
23static int default_codepage = 0; 21static int default_codepage = 0;
24static unsigned short codepage_table[MAX_CP_TABLE_SIZE];
25static int loaded_cp_table = 0; 22static int loaded_cp_table = 0;
26 23
24#ifdef HAVE_LCD_BITMAP
27 25
28static const unsigned char utf8comp[6] = 26#define MAX_CP_TABLE_SIZE 32768
29{ 27#define NUM_TABLES 5
30 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
31};
32 28
29enum {
30 ISO_8859_1 = 0, ISO_8859_7, ISO_8859_8, WIN_1251,
31 ISO_8859_11, WIN_1256, ISO_8859_9, ISO_8859_2,
32 SJIS, GB_2312, KSX_1001, BIG_5, UTF_8, NUM_CODEPAGES
33};
33static const char *filename[NUM_TABLES] = 34static const char *filename[NUM_TABLES] =
34{ 35{
35 CODEPAGE_DIR"/iso.cp", 36 CODEPAGE_DIR"/iso.cp",
@@ -38,12 +39,38 @@ static const char *filename[NUM_TABLES] =
38 CODEPAGE_DIR"/949.cp", /* KSX1001 */ 39 CODEPAGE_DIR"/949.cp", /* KSX1001 */
39 CODEPAGE_DIR"/950.cp" /* BIG5 */ 40 CODEPAGE_DIR"/950.cp" /* BIG5 */
40}; 41};
41
42static const char cp_2_table[NUM_CODEPAGES] = 42static const char cp_2_table[NUM_CODEPAGES] =
43{ 43{
44 0, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 0 44 0, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 0
45}; 45};
46 46
47#else /* !HAVE_LCD_BITMAP, reduced support */
48
49#define MAX_CP_TABLE_SIZE 512
50#define NUM_TABLES 1
51
52enum {
53 ISO_8859_1 = 0, ISO_8859_7, WIN_1251,
54 ISO_8859_9, ISO_8859_2, UTF_8, NUM_CODEPAGES
55};
56static const char *filename[NUM_TABLES] =
57{
58 CODEPAGE_DIR"/isomini.cp",
59};
60static const char cp_2_table[NUM_CODEPAGES] =
61{
62 0, 1, 1, 1, 1, 0
63};
64
65#endif
66
67static unsigned short codepage_table[MAX_CP_TABLE_SIZE];
68
69static const unsigned char utf8comp[6] =
70{
71 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
72};
73
47/* Load codepage file into memory */ 74/* Load codepage file into memory */
48static int load_cp_table(int cp) 75static int load_cp_table(int cp)
49{ 76{
@@ -113,34 +140,37 @@ unsigned char* iso_decode(const unsigned char *iso, unsigned char *utf8,
113 if (!load_cp_table(cp)) cp = 0; 140 if (!load_cp_table(cp)) cp = 0;
114 141
115 while (count--) { 142 while (count--) {
116 if (*iso < 128 || cp == 0x0C) /* Already UTF-8 */ 143 if (*iso < 128 || cp == UTF_8) /* Already UTF-8 */
117 *utf8++ = *iso++; 144 *utf8++ = *iso++;
118 145
119 else { 146 else {
120 147
121 /* cp tells us which codepage to convert from */ 148 /* cp tells us which codepage to convert from */
122 switch (cp) { 149 switch (cp) {
123 case 0x01: /* Greek (ISO-8859-7) */ 150 case ISO_8859_7: /* Greek */
124 case 0x02: /* Hebrew (ISO-8859-8) */ 151 case WIN_1251: /* Cyrillic */
125 case 0x03: /* Cyrillic (CP1251) */ 152 case ISO_8859_9: /* Turkish */
126 case 0x04: /* Thai (ISO-8859-11) */ 153 case ISO_8859_2: /* Latin Extended */
127 case 0x05: /* Arabic (CP1256) */ 154#ifdef HAVE_LCD_BITMAP
128 case 0x06: /* Turkish (ISO-8859-9) */ 155 case ISO_8859_8: /* Hebrew */
129 case 0x07: /* Latin Extended (ISO-8859-2) */ 156 case ISO_8859_11: /* Thai */
157 case WIN_1256: /* Arabic */
158#endif
130 tmp = ((cp-1)*128) + (*iso++ - 128); 159 tmp = ((cp-1)*128) + (*iso++ - 128);
131 ucs = codepage_table[tmp]; 160 ucs = codepage_table[tmp];
132 break; 161 break;
133 162
134 case 0x08: /* Japanese (SJIS) */ 163#ifdef HAVE_LCD_BITMAP
164 case SJIS: /* Japanese */
135 if (*iso > 0xA0 && *iso < 0xE0) { 165 if (*iso > 0xA0 && *iso < 0xE0) {
136 tmp = *iso++ | (0xA100 - 0x8000); 166 tmp = *iso++ | (0xA100 - 0x8000);
137 ucs = codepage_table[tmp]; 167 ucs = codepage_table[tmp];
138 break; 168 break;
139 } 169 }
140 170
141 case 0x09: /* Simplified Chinese (GB2312) */ 171 case GB_2312: /* Simplified Chinese */
142 case 0x0A: /* Korean (KSX1001) */ 172 case KSX_1001: /* Korean */
143 case 0x0B: /* Traditional Chinese (BIG5) */ 173 case BIG5: /* Traditional Chinese */
144 if (count < 1 || !iso[1]) { 174 if (count < 1 || !iso[1]) {
145 ucs = *iso++; 175 ucs = *iso++;
146 break; 176 break;
@@ -154,6 +184,7 @@ unsigned char* iso_decode(const unsigned char *iso, unsigned char *utf8,
154 ucs = codepage_table[tmp]; 184 ucs = codepage_table[tmp];
155 count--; 185 count--;
156 break; 186 break;
187#endif /* HAVE_LCD_BITMAP */
157 188
158 default: 189 default:
159 ucs = *iso++; 190 ucs = *iso++;
diff --git a/firmware/include/rbunicode.h b/firmware/include/rbunicode.h
index a9ab49f280..6e61905685 100644
--- a/firmware/include/rbunicode.h
+++ b/firmware/include/rbunicode.h
@@ -8,10 +8,6 @@
8 * http://en.wikipedia.org/wiki/Unicode 8 * http://en.wikipedia.org/wiki/Unicode
9 */ 9 */
10 10
11#define CODEPAGE_DIR "/.rockbox/codepages"
12
13#define MAX_CP_TABLE_SIZE 32768
14
15#define MASK 0xC0 /* 11000000 */ 11#define MASK 0xC0 /* 11000000 */
16#define COMP 0x80 /* 10x */ 12#define COMP 0x80 /* 10x */
17 13
diff --git a/tools/buildzip.pl b/tools/buildzip.pl
index 0463132ec4..3ddb0163d3 100755
--- a/tools/buildzip.pl
+++ b/tools/buildzip.pl
@@ -178,9 +178,18 @@ sub buildzip {
178 } 178 }
179 179
180 mkdir ".rockbox/wps", 0777; 180 mkdir ".rockbox/wps", 0777;
181 mkdir ".rockbox/codepages", 0777;
182
183 if($bitmap) {
184 system("$ROOT/tools/codepages");
185 }
186 else {
187 system("$ROOT/tools/codepages -m");
188 }
189 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
190 `$c`;
181 191
182 if($bitmap) { 192 if($bitmap) {
183 mkdir ".rockbox/codepages", 0777;
184 mkdir ".rockbox/codecs", 0777; 193 mkdir ".rockbox/codecs", 0777;
185 mkdir ".rockbox/themes", 0777; 194 mkdir ".rockbox/themes", 0777;
186 if($depth > 1) { 195 if($depth > 1) {
@@ -190,10 +199,6 @@ sub buildzip {
190 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null'; 199 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
191 `$c`; 200 `$c`;
192 201
193 system("$ROOT/tools/codepages");
194 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
195 `$c`;
196
197 my @call = `find .rockbox/codecs -type f 2>/dev/null`; 202 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
198 if(!$call[0]) { 203 if(!$call[0]) {
199 # no codec was copied, remove directory again 204 # no codec was copied, remove directory again
diff --git a/tools/codepages.c b/tools/codepages.c
index e19d39c85a..651a99c429 100644
--- a/tools/codepages.c
+++ b/tools/codepages.c
@@ -23,6 +23,10 @@
23 23
24#define MAX_TABLE_SIZE 32768 24#define MAX_TABLE_SIZE 32768
25 25
26static const int mini_index[5] = {
27 0, 1, 3, 6, 7
28};
29
26static unsigned short iso_table[MAX_TABLE_SIZE]; 30static unsigned short iso_table[MAX_TABLE_SIZE];
27 31
28unsigned short iso_decode(unsigned char *latin1, int cp, int count) 32unsigned short iso_decode(unsigned char *latin1, int cp, int count)
@@ -147,53 +151,100 @@ int writeshort(FILE *f, unsigned short s)
147 return putc(s>>8, f) != EOF; 151 return putc(s>>8, f) != EOF;
148} 152}
149 153
150int main(void) 154void print_usage(void)
151{ 155{
156 printf("Usage: codepages [-m]\n"
157 "\t-m Create isomini.cp only\n");
158 printf("build date: " __DATE__ "\n\n");
159}
152 160
161int main(int argc, char **argv)
162{
163 int mini = 0;
153 int i, j; 164 int i, j;
154 unsigned char k; 165 unsigned char k;
155 unsigned short uni; 166 unsigned short uni;
156 FILE *of; 167 FILE *of;
157 168
169 for (i = 1;i < argc;i++)
170 {
171 if (argv[i][0] == '-')
172 {
173 switch (argv[i][1])
174 {
175 case 'm': /* create isomini.cp only */
176 mini = 1;
177 break;
178
179 case 'h': /* help */
180 case '?':
181 print_usage();
182 exit(1);
183 break;
184
185 default:
186 print_usage();
187 exit(1);
188 break;
189 }
190 }
191 }
192
158 for (i=0; i < MAX_TABLE_SIZE; i++) 193 for (i=0; i < MAX_TABLE_SIZE; i++)
159 iso_table[i] = 0; 194 iso_table[i] = 0;
160 195
161 of = fopen("iso.cp", "wb"); 196 if (mini) {
162 if (!of) return 1; 197 of = fopen("isomini.cp", "wb");
198 if (!of) return 1;
163 199
164 for (i=1; i<8; i++) { 200 for (i=1; i<5; i++) {
165 201
166 for (j=0; j<128; j++) { 202 for (j=0; j<128; j++) {
167 k = (unsigned char)j + 128; 203 k = (unsigned char)j + 128;
168 uni = iso_decode(&k, i, 1); 204 uni = iso_decode(&k, mini_index[i], 1);
169 writeshort(of, uni); 205 writeshort(of, uni);
206 }
170 } 207 }
208 fclose(of);
171 } 209 }
172 fclose(of); 210 else {
211 of = fopen("iso.cp", "wb");
212 if (!of) return 1;
173 213
174 of = fopen("932.cp", "wb"); 214 for (i=1; i<8; i++) {
175 if (!of) return 1; 215
176 for (i=0; i < MAX_TABLE_SIZE; i++) 216 for (j=0; j<128; j++) {
177 writeshort(of, cp932_table[i]); 217 k = (unsigned char)j + 128;
178 fclose(of); 218 uni = iso_decode(&k, i, 1);
179 219 writeshort(of, uni);
180 of = fopen("936.cp", "wb"); 220 }
181 if (!of) return 1; 221 }
182 for (i=0; i < MAX_TABLE_SIZE; i++) 222 fclose(of);
183 writeshort(of, cp936_table[i]); 223
184 fclose(of); 224 of = fopen("932.cp", "wb");
185 225 if (!of) return 1;
186 of = fopen("949.cp", "wb"); 226 for (i=0; i < MAX_TABLE_SIZE; i++)
187 if (!of) return 1; 227 writeshort(of, cp932_table[i]);
188 for (i=0; i < MAX_TABLE_SIZE; i++) 228 fclose(of);
189 writeshort(of, cp949_table[i]); 229
190 fclose(of); 230 of = fopen("936.cp", "wb");
191 231 if (!of) return 1;
192 of = fopen("950.cp", "wb"); 232 for (i=0; i < MAX_TABLE_SIZE; i++)
193 if (!of) return 1; 233 writeshort(of, cp936_table[i]);
194 for (i=0; i < MAX_TABLE_SIZE; i++) 234 fclose(of);
195 writeshort(of, cp950_table[i]); 235
196 fclose(of); 236 of = fopen("949.cp", "wb");
237 if (!of) return 1;
238 for (i=0; i < MAX_TABLE_SIZE; i++)
239 writeshort(of, cp949_table[i]);
240 fclose(of);
241
242 of = fopen("950.cp", "wb");
243 if (!of) return 1;
244 for (i=0; i < MAX_TABLE_SIZE; i++)
245 writeshort(of, cp950_table[i]);
246 fclose(of);
247 }
197 248
198 return 0; 249 return 0;
199} 250}
diff --git a/tools/configure b/tools/configure
index 1b469c855b..0341a29e85 100755
--- a/tools/configure
+++ b/tools/configure
@@ -598,16 +598,16 @@ EOF
598 buildfor=`input`; 598 buildfor=`input`;
599 599
600 # Set of tools built for all target platforms: 600 # Set of tools built for all target platforms:
601 toolset="rdf2binary convbdf" 601 toolset="rdf2binary convbdf codepages"
602 602
603 # Toolsets for some target families: 603 # Toolsets for some target families:
604 archosbitmaptools="$toolset scramble descramble sh2d uclpack bmp2rb codepages" 604 archosbitmaptools="$toolset scramble descramble sh2d uclpack bmp2rb"
605 iriverbitmaptools="$toolset scramble descramble mkboot bmp2rb codepages" 605 iriverbitmaptools="$toolset scramble descramble mkboot bmp2rb"
606 iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb codepages" 606 iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb"
607 ipodbitmaptools="$toolset scramble ipod_fw bmp2rb codepages" 607 ipodbitmaptools="$toolset scramble ipod_fw bmp2rb codepages"
608 gigabeatbitmaptools="$toolset scramble descramble bmp2rb codepages" 608 gigabeatbitmaptools="$toolset scramble descramble bmp2rb"
609 # generic is used by IFP, H10, Sansa-e200 609 # generic is used by IFP, H10, Sansa-e200
610 genericbitmaptools="$toolset bmp2rb codepages" 610 genericbitmaptools="$toolset bmp2rb"
611 611
612 612
613 # ---- For each target ---- 613 # ---- For each target ----