diff options
Diffstat (limited to 'firmware/common/unicode.c')
-rw-r--r-- | firmware/common/unicode.c | 71 |
1 files changed, 60 insertions, 11 deletions
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 | } | ||