diff options
author | Björn Stenberg <bjorn@haxx.se> | 2008-12-04 22:00:12 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2008-12-04 22:00:12 +0000 |
commit | af078b4f86cb124778073905b2c28cc2d9b7748b (patch) | |
tree | 10493ea7cbd4239f847ea10b2aa73e2c33ba9e02 | |
parent | 38e97057a9f9bf3c3f09c128266874c0cca89950 (diff) | |
download | rockbox-af078b4f86cb124778073905b2c28cc2d9b7748b.tar.gz rockbox-af078b4f86cb124778073905b2c28cc2d9b7748b.zip |
Cleaned up codepage handling, by Yoshihisa Uchida. (FS#9349)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19339 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugin.c | 1 | ||||
-rw-r--r-- | apps/plugin.h | 4 | ||||
-rw-r--r-- | apps/plugins/viewer.c | 46 | ||||
-rw-r--r-- | firmware/common/unicode.c | 71 | ||||
-rw-r--r-- | firmware/include/rbunicode.h | 46 |
5 files changed, 119 insertions, 49 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index e46e193129..de2dd3f7c7 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -620,6 +620,7 @@ static const struct plugin_api rockbox_api = { | |||
620 | /* new stuff at the end, sort into place next time | 620 | /* new stuff at the end, sort into place next time |
621 | the API gets incompatible */ | 621 | the API gets incompatible */ |
622 | get_settings_list, | 622 | get_settings_list, |
623 | get_codepage_name, | ||
623 | }; | 624 | }; |
624 | 625 | ||
625 | int plugin_load(const char* plugin, const void* parameter) | 626 | int plugin_load(const char* plugin, const void* parameter) |
diff --git a/apps/plugin.h b/apps/plugin.h index 99a76ad399..fd01e15bbd 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -131,7 +131,7 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
131 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ | 131 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ |
132 | 132 | ||
133 | /* increase this every time the api struct changes */ | 133 | /* increase this every time the api struct changes */ |
134 | #define PLUGIN_API_VERSION 127 | 134 | #define PLUGIN_API_VERSION 128 |
135 | 135 | ||
136 | /* update this to latest version if a change to the api struct breaks | 136 | /* update this to latest version if a change to the api struct breaks |
137 | backwards compatibility (and please take the opportunity to sort in any | 137 | backwards compatibility (and please take the opportunity to sort in any |
@@ -783,7 +783,7 @@ struct plugin_api { | |||
783 | /* new stuff at the end, sort into place next time | 783 | /* new stuff at the end, sort into place next time |
784 | the API gets incompatible */ | 784 | the API gets incompatible */ |
785 | const struct settings_list* (*get_settings_list)(int*count); | 785 | const struct settings_list* (*get_settings_list)(int*count); |
786 | 786 | const char* (*get_codepage_name)(int cp); | |
787 | }; | 787 | }; |
788 | 788 | ||
789 | /* plugin header */ | 789 | /* plugin header */ |
diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index 76c1d93c1c..4cef7c5879 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c | |||
@@ -348,23 +348,7 @@ struct preferences { | |||
348 | WIDE, | 348 | WIDE, |
349 | } view_mode; | 349 | } view_mode; |
350 | 350 | ||
351 | enum { | 351 | enum codepages encoding; |
352 | ISO_8859_1=0, | ||
353 | ISO_8859_7, | ||
354 | ISO_8859_8, | ||
355 | CP1251, | ||
356 | ISO_8859_11, | ||
357 | ISO_8859_6, | ||
358 | ISO_8859_9, | ||
359 | ISO_8859_2, | ||
360 | CP1250, | ||
361 | SJIS, | ||
362 | GB2312, | ||
363 | KSX1001, | ||
364 | BIG5, | ||
365 | UTF8, | ||
366 | ENCODINGS | ||
367 | } encoding; /* FIXME: What should default encoding be? */ | ||
368 | 352 | ||
369 | #ifdef HAVE_LCD_BITMAP | 353 | #ifdef HAVE_LCD_BITMAP |
370 | enum { | 354 | enum { |
@@ -433,16 +417,18 @@ unsigned char* get_ucs(const unsigned char* str, unsigned short* ch) | |||
433 | unsigned char utf8_tmp[6]; | 417 | unsigned char utf8_tmp[6]; |
434 | int count; | 418 | int count; |
435 | 419 | ||
436 | if (prefs.encoding == UTF8) | 420 | if (prefs.encoding == UTF_8) |
437 | return (unsigned char*)rb->utf8decode(str, ch); | 421 | return (unsigned char*)rb->utf8decode(str, ch); |
438 | 422 | ||
439 | count = BUFFER_OOB(str+2)? 1:2; | 423 | count = BUFFER_OOB(str+2)? 1:2; |
440 | rb->iso_decode(str, utf8_tmp, prefs.encoding, count); | 424 | rb->iso_decode(str, utf8_tmp, prefs.encoding, count); |
441 | rb->utf8decode(utf8_tmp, ch); | 425 | rb->utf8decode(utf8_tmp, ch); |
442 | 426 | ||
427 | #ifdef HAVE_LCD_BITMAP | ||
443 | if ((prefs.encoding == SJIS && *str > 0xA0 && *str < 0xE0) || prefs.encoding < SJIS) | 428 | if ((prefs.encoding == SJIS && *str > 0xA0 && *str < 0xE0) || prefs.encoding < SJIS) |
444 | return (unsigned char*)str+1; | 429 | return (unsigned char*)str+1; |
445 | else | 430 | else |
431 | #endif | ||
446 | return (unsigned char*)str+2; | 432 | return (unsigned char*)str+2; |
447 | } | 433 | } |
448 | 434 | ||
@@ -1330,22 +1316,14 @@ static int col_limit(int col) | |||
1330 | 1316 | ||
1331 | static bool encoding_setting(void) | 1317 | static bool encoding_setting(void) |
1332 | { | 1318 | { |
1333 | static const struct opt_items names[] = { | 1319 | static struct opt_items names[NUM_CODEPAGES]; |
1334 | {"ISO-8859-1", -1}, | 1320 | int idx; |
1335 | {"ISO-8859-7", -1}, | 1321 | |
1336 | {"ISO-8859-8", -1}, | 1322 | for (idx = 0; idx < NUM_CODEPAGES; idx++) |
1337 | {"CP1251", -1}, | 1323 | { |
1338 | {"ISO-8859-11", -1}, | 1324 | names[idx].string = rb->get_codepage_name(idx); |
1339 | {"ISO-8859-6", -1}, | 1325 | names[idx].voice_id = -1; |
1340 | {"ISO-8859-9", -1}, | 1326 | } |
1341 | {"ISO-8859-2", -1}, | ||
1342 | {"CP1250", -1}, | ||
1343 | {"SJIS", -1}, | ||
1344 | {"GB-2312", -1}, | ||
1345 | {"KSX-1001", -1}, | ||
1346 | {"BIG5", -1}, | ||
1347 | {"UTF-8", -1}, | ||
1348 | }; | ||
1349 | 1327 | ||
1350 | return rb->set_option("Encoding", &prefs.encoding, INT, names, | 1328 | return rb->set_option("Encoding", &prefs.encoding, INT, names, |
1351 | sizeof(names) / sizeof(names[0]), NULL); | 1329 | sizeof(names) / sizeof(names[0]), NULL); |
diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c index 6c954a59d1..713a8e70f9 100644 --- a/firmware/common/unicode.c +++ b/firmware/common/unicode.c | |||
@@ -1,6 +1,24 @@ | |||
1 | /* Some conversion functions for handling UTF-8 | 1 | /*************************************************************************** |
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (c) 2004,2005 by Marcoen Hirschberg | ||
11 | * | ||
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. | ||
2 | * | 16 | * |
3 | * copyright Marcoen Hirschberg (2004,2005) | 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | /* Some conversion functions for handling UTF-8 | ||
4 | * | 22 | * |
5 | * I got all the info from: | 23 | * I got all the info from: |
6 | * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | 24 | * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
@@ -27,11 +45,6 @@ static int loaded_cp_table = 0; | |||
27 | #define MAX_CP_TABLE_SIZE 32768 | 45 | #define MAX_CP_TABLE_SIZE 32768 |
28 | #define NUM_TABLES 5 | 46 | #define NUM_TABLES 5 |
29 | 47 | ||
30 | enum { | ||
31 | ISO_8859_1 = 0, ISO_8859_7, ISO_8859_8, WIN_1251, | ||
32 | ISO_8859_11, WIN_1256, ISO_8859_9, ISO_8859_2, WIN_1250, | ||
33 | SJIS, GB_2312, KSX_1001, BIG_5, UTF_8, NUM_CODEPAGES | ||
34 | }; | ||
35 | static const char *filename[NUM_TABLES] = | 48 | static const char *filename[NUM_TABLES] = |
36 | { | 49 | { |
37 | CODEPAGE_DIR"/iso.cp", | 50 | CODEPAGE_DIR"/iso.cp", |
@@ -40,29 +53,58 @@ static const char *filename[NUM_TABLES] = | |||
40 | CODEPAGE_DIR"/949.cp", /* KSX1001 */ | 53 | CODEPAGE_DIR"/949.cp", /* KSX1001 */ |
41 | CODEPAGE_DIR"/950.cp" /* BIG5 */ | 54 | CODEPAGE_DIR"/950.cp" /* BIG5 */ |
42 | }; | 55 | }; |
56 | |||
43 | static const char cp_2_table[NUM_CODEPAGES] = | 57 | static const char cp_2_table[NUM_CODEPAGES] = |
44 | { | 58 | { |
45 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 0 | 59 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 0 |
46 | }; | 60 | }; |
47 | 61 | ||
62 | static const char *name_codepages[NUM_CODEPAGES+1] = | ||
63 | { | ||
64 | "ISO-8859-1", | ||
65 | "ISO-8859-7", | ||
66 | "ISO-8859-8", | ||
67 | "CP1251", | ||
68 | "ISO-8859-11", | ||
69 | "CP1256", | ||
70 | "ISO-8859-9", | ||
71 | "ISO-8859-2", | ||
72 | "CP1250", | ||
73 | "SJIS", | ||
74 | "GB-2312", | ||
75 | "KSX-1001", | ||
76 | "BIG5", | ||
77 | "UTF-8", | ||
78 | "unknown" | ||
79 | }; | ||
80 | |||
48 | #else /* !HAVE_LCD_BITMAP, reduced support */ | 81 | #else /* !HAVE_LCD_BITMAP, reduced support */ |
49 | 82 | ||
50 | #define MAX_CP_TABLE_SIZE 640 | 83 | #define MAX_CP_TABLE_SIZE 640 |
51 | #define NUM_TABLES 1 | 84 | #define NUM_TABLES 1 |
52 | 85 | ||
53 | enum { | ||
54 | ISO_8859_1 = 0, ISO_8859_7, WIN_1251, ISO_8859_9, | ||
55 | ISO_8859_2, WIN_1250, UTF_8, NUM_CODEPAGES | ||
56 | }; | ||
57 | static const char *filename[NUM_TABLES] = | 86 | static const char *filename[NUM_TABLES] = |
58 | { | 87 | { |
59 | CODEPAGE_DIR"/isomini.cp", | 88 | CODEPAGE_DIR"/isomini.cp", |
60 | }; | 89 | }; |
90 | |||
61 | static const char cp_2_table[NUM_CODEPAGES] = | 91 | static const char cp_2_table[NUM_CODEPAGES] = |
62 | { | 92 | { |
63 | 0, 1, 1, 1, 1, 1, 0 | 93 | 0, 1, 1, 1, 1, 1, 0 |
64 | }; | 94 | }; |
65 | 95 | ||
96 | static const char *name_codepages[NUM_CODEPAGES+1] = | ||
97 | { | ||
98 | "ISO-8859-1", | ||
99 | "ISO-8859-7", | ||
100 | "CP1251", | ||
101 | "ISO-8859-9", | ||
102 | "ISO-8859-2", | ||
103 | "CP1250", | ||
104 | "UTF-8", | ||
105 | "unknown" | ||
106 | }; | ||
107 | |||
66 | #endif | 108 | #endif |
67 | 109 | ||
68 | static unsigned short codepage_table[MAX_CP_TABLE_SIZE]; | 110 | static unsigned short codepage_table[MAX_CP_TABLE_SIZE]; |
@@ -344,3 +386,10 @@ int utf8seek(const unsigned char* utf8, int offset) | |||
344 | } | 386 | } |
345 | return pos; | 387 | return pos; |
346 | } | 388 | } |
389 | |||
390 | const char* get_codepage_name(int cp) | ||
391 | { | ||
392 | if (cp < 0 || cp>= NUM_CODEPAGES) | ||
393 | return name_codepages[NUM_CODEPAGES]; | ||
394 | return name_codepages[cp]; | ||
395 | } | ||
diff --git a/firmware/include/rbunicode.h b/firmware/include/rbunicode.h index 6e61905685..39fe253f3d 100644 --- a/firmware/include/rbunicode.h +++ b/firmware/include/rbunicode.h | |||
@@ -1,16 +1,56 @@ | |||
1 | /* Some conversion functions for handling UTF-8 | 1 | /*************************************************************************** |
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (c) 2004,2005 by Marcoen Hirschberg | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
2 | * | 19 | * |
3 | * copyright Marcoen Hirschberg (2004,2005) | 20 | ****************************************************************************/ |
21 | /* Some conversion functions for handling UTF-8 | ||
4 | * | 22 | * |
5 | * I got all the info from: | 23 | * I got all the info from: |
6 | * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | 24 | * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
7 | * and | 25 | * and |
8 | * http://en.wikipedia.org/wiki/Unicode | 26 | * http://en.wikipedia.org/wiki/Unicode |
9 | */ | 27 | */ |
28 | #ifndef _RBUNICODE_H_ | ||
29 | #define _RBUNICODE_H_ | ||
30 | |||
31 | #ifndef __PCTOOL__ | ||
32 | #include "config.h" | ||
33 | #endif | ||
10 | 34 | ||
11 | #define MASK 0xC0 /* 11000000 */ | 35 | #define MASK 0xC0 /* 11000000 */ |
12 | #define COMP 0x80 /* 10x */ | 36 | #define COMP 0x80 /* 10x */ |
13 | 37 | ||
38 | #ifdef HAVE_LCD_BITMAP | ||
39 | |||
40 | enum codepages { | ||
41 | ISO_8859_1 = 0, ISO_8859_7, ISO_8859_8, WIN_1251, | ||
42 | ISO_8859_11, WIN_1256, ISO_8859_9, ISO_8859_2, WIN_1250, | ||
43 | SJIS, GB_2312, KSX_1001, BIG_5, UTF_8, NUM_CODEPAGES | ||
44 | }; | ||
45 | |||
46 | #else /* !HAVE_LCD_BITMAP, reduced support */ | ||
47 | |||
48 | enum codepages { | ||
49 | ISO_8859_1 = 0, ISO_8859_7, WIN_1251, ISO_8859_9, | ||
50 | ISO_8859_2, WIN_1250, UTF_8, NUM_CODEPAGES | ||
51 | }; | ||
52 | |||
53 | #endif | ||
14 | 54 | ||
15 | /* Encode a UCS value as UTF-8 and return a pointer after this UTF-8 char. */ | 55 | /* Encode a UCS value as UTF-8 and return a pointer after this UTF-8 char. */ |
16 | unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); | 56 | unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); |
@@ -21,3 +61,5 @@ unsigned long utf8length(const unsigned char *utf8); | |||
21 | const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs); | 61 | const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs); |
22 | void set_codepage(int cp); | 62 | void set_codepage(int cp); |
23 | int utf8seek(const unsigned char* utf8, int offset); | 63 | int utf8seek(const unsigned char* utf8, int offset); |
64 | const char* get_codepage_name(int cp); | ||
65 | #endif /* _RBUNICODE_H_ */ | ||