summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/unicode.c71
-rw-r--r--firmware/include/rbunicode.h46
2 files changed, 104 insertions, 13 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
30enum {
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};
35static const char *filename[NUM_TABLES] = 48static 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
43static const char cp_2_table[NUM_CODEPAGES] = 57static 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
62static 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
53enum {
54 ISO_8859_1 = 0, ISO_8859_7, WIN_1251, ISO_8859_9,
55 ISO_8859_2, WIN_1250, UTF_8, NUM_CODEPAGES
56};
57static const char *filename[NUM_TABLES] = 86static const char *filename[NUM_TABLES] =
58{ 87{
59 CODEPAGE_DIR"/isomini.cp", 88 CODEPAGE_DIR"/isomini.cp",
60}; 89};
90
61static const char cp_2_table[NUM_CODEPAGES] = 91static 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
96static 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
68static unsigned short codepage_table[MAX_CP_TABLE_SIZE]; 110static 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
390const 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
40enum 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
48enum 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. */
16unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); 56unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8);
@@ -21,3 +61,5 @@ unsigned long utf8length(const unsigned char *utf8);
21const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs); 61const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs);
22void set_codepage(int cp); 62void set_codepage(int cp);
23int utf8seek(const unsigned char* utf8, int offset); 63int utf8seek(const unsigned char* utf8, int offset);
64const char* get_codepage_name(int cp);
65#endif /* _RBUNICODE_H_ */