X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fchar-ucs.h;h=7ea200d4bc050910f87ab4ed6a5f9c0a30aeaaaf;hb=25e5d28d57dbe61cb1a5366d8e4a48c0196b3b74;hp=20359c3c56e9f29fbca686bdff8e4fd84cbc271b;hpb=16254df8eb68fb2ecb1e8c0ac7ead9a301544af7;p=chise%2Fxemacs-chise.git diff --git a/src/char-ucs.h b/src/char-ucs.h index 20359c3..7ea200d 100644 --- a/src/char-ucs.h +++ b/src/char-ucs.h @@ -1,5 +1,5 @@ /* Header for UCS-4 character representation. - Copyright (C) 1999,2000 MORIOKA Tomohiko + Copyright (C) 1999,2000,2001,2002,2003 MORIOKA Tomohiko This file is part of XEmacs. @@ -18,129 +18,98 @@ along with XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Rewritten by MORIOKA Tomohiko . */ +#ifndef INCLUDED_char_ucs_h_ +#define INCLUDED_char_ucs_h_ -#ifndef _XEMACS_CHAR_UCS_H -#define _XEMACS_CHAR_UCS_H +#include "chartab.h" +#include "elhash.h" + +extern Lisp_Object Vchar_attribute_hash_table; #define valid_char_p(ch) 1 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F) -DECLARE_LRECORD (char_byte_table, struct Lisp_Char_Byte_Table); -#define XCHAR_BYTE_TABLE(x) \ - XRECORD (x, char_byte_table, struct Lisp_Char_Byte_Table) -#define XSETCHAR_BYTE_TABLE(x, p) XSETRECORD (x, p, char_byte_table) -#define CHAR_BYTE_TABLE_P(x) RECORDP (x, char_byte_table) -#define GC_CHAR_BYTE_TABLE_P(x) GC_RECORDP (x, char_byte_table) -/* #define CHECK_CHAR_BYTE_TABLE(x) CHECK_RECORD (x, char_byte_table) - char table entries should never escape to Lisp */ - -struct Lisp_Char_Byte_Table -{ - struct lcrecord_header header; - - Lisp_Object property[256]; -}; - - -DECLARE_LRECORD (char_code_table, struct Lisp_Char_Code_Table); -#define XCHAR_CODE_TABLE(x) \ - XRECORD (x, char_code_table, struct Lisp_Char_Code_Table) -#define XSETCHAR_CODE_TABLE(x, p) XSETRECORD (x, p, char_code_table) -#define CHAR_CODE_TABLE_P(x) RECORDP (x, char_code_table) -#define GC_CHAR_CODE_TABLE_P(x) GC_RECORDP (x, char_code_table) -/* #define CHECK_CHAR_CODE_TABLE(x) CHECK_RECORD (x, char_code_table) - char table entries should never escape to Lisp */ - -struct Lisp_Char_Code_Table -{ - struct lcrecord_header header; +/************************************************************************/ +/* Exported functions */ +/************************************************************************/ - Lisp_Object table; -}; +extern Lisp_Object Vcharset_ucs; +extern Lisp_Object Vcharset_latin_jisx0201; +extern Lisp_Object Vcharset_chinese_big5; +extern Lisp_Object Vcharset_chinese_big5_1; +extern Lisp_Object Vcharset_chinese_big5_2; +extern Lisp_Object Vcharset_japanese_jisx0208; +extern Lisp_Object Vcharset_japanese_jisx0208_1990; +extern Lisp_Object Vcharset_japanese_jisx0212; -Lisp_Object get_char_code_table (Emchar ch, Lisp_Object table); +EXFUN (Fget_charset, 1); +extern Lisp_Object Qucs; -extern Lisp_Object Vcharset_mojikyo; -extern Lisp_Object Vcharset_latin_jisx0201; +Lisp_Object put_char_ccs_code_point (Lisp_Object character, + Lisp_Object ccs, Lisp_Object value); +Lisp_Object remove_char_ccs (Lisp_Object character, Lisp_Object ccs); /************************************************************************/ /* Definition of leading bytes */ /************************************************************************/ -typedef int Charset_ID; +typedef short Charset_ID; -#define MIN_LEADING_BYTE -0x60 -#define CHARSET_ID_OFFSET 0x00 +#define MIN_LEADING_BYTE -0x200 /* ISO/IEC 10646 */ -#define LEADING_BYTE_UCS (CHARSET_ID_OFFSET - 1) +#define LEADING_BYTE_UCS (MIN_LEADING_BYTE + 1) /* represent normal 80-9F */ -#define LEADING_BYTE_CONTROL_1 (CHARSET_ID_OFFSET - 2) +#define LEADING_BYTE_CONTROL_1 (MIN_LEADING_BYTE + 2) /* ISO/IEC 10646 BMP */ -#define LEADING_BYTE_UCS_BMP (CHARSET_ID_OFFSET - 3) +#define LEADING_BYTE_UCS_BMP (MIN_LEADING_BYTE + 3) -/* VISCII 1.1 */ -#define LEADING_BYTE_LATIN_VISCII (CHARSET_ID_OFFSET - 4) +/* ISO/IEC 10646 SMP */ +#define LEADING_BYTE_UCS_SMP (MIN_LEADING_BYTE + 4) -/* MULE VISCII-LOWER (CHARSET_ID_OFFSET_96 + '1') */ -#define LEADING_BYTE_LATIN_VISCII_LOWER (CHARSET_ID_OFFSET - 5) +/* ISO/IEC 10646 SIP */ +#define LEADING_BYTE_UCS_SIP (MIN_LEADING_BYTE + 5) -/* MULE VISCII-UPPER (CHARSET_ID_OFFSET_96 + '2') */ -#define LEADING_BYTE_LATIN_VISCII_UPPER (CHARSET_ID_OFFSET - 6) +/* ISO/IEC 10646 for GB */ +#define LEADING_BYTE_UCS_GB (MIN_LEADING_BYTE + 6) + +/* Japanese JIS X0208 Common 2/4 2/{(8),9,10,11} 4/2 (B) */ +#define LEADING_BYTE_JIS_X0208 (MIN_LEADING_BYTE + 11) + +/* Japanese JIS X0208-1990 2/4 2/{(8),9,10,11} 4/2 (B) */ +#define LEADING_BYTE_JAPANESE_JISX0208_1990 (MIN_LEADING_BYTE + 12) + +/* Chinese GB 12345-1990 */ +#define LEADING_BYTE_CHINESE_GB12345 (MIN_LEADING_BYTE + 13) + +#define LEADING_BYTE_CHINESE_BIG5 (MIN_LEADING_BYTE + 20) /* Big5 Level 1 2/4 2/{(8),9,10,11} 4/0 '0' */ -#define LEADING_BYTE_CHINESE_BIG5_1 (CHARSET_ID_OFFSET - 7) +#define LEADING_BYTE_CHINESE_BIG5_1 (MIN_LEADING_BYTE + 21) /* Big5 Level 2 2/4 2/{(8),9,10,11} 4/0 '1' */ -#define LEADING_BYTE_CHINESE_BIG5_2 (CHARSET_ID_OFFSET - 8) +#define LEADING_BYTE_CHINESE_BIG5_2 (MIN_LEADING_BYTE + 22) + +/* VISCII 1.1 */ +#define LEADING_BYTE_LATIN_VISCII (MIN_LEADING_BYTE + 24) -#define LEADING_BYTE_ETHIOPIC_UCS (CHARSET_ID_OFFSET - 9) +/* MULE VISCII-LOWER (CHARSET_ID_OFFSET_96 + '1') */ +#define LEADING_BYTE_LATIN_VISCII_LOWER (MIN_LEADING_BYTE + 25) -#define LEADING_BYTE_DAIKANWA (CHARSET_ID_OFFSET - 10) -#define LEADING_BYTE_DAIKANWA_EKANJI (CHARSET_ID_OFFSET - 11) -#define LEADING_BYTE_MOJIKYO (CHARSET_ID_OFFSET - 12) +/* MULE VISCII-UPPER (CHARSET_ID_OFFSET_96 + '2') */ +#define LEADING_BYTE_LATIN_VISCII_UPPER (MIN_LEADING_BYTE + 26) + +#define LEADING_BYTE_ETHIOPIC_UCS (MIN_LEADING_BYTE + 27) + +#define MIN_LEADING_BYTE_PRIVATE (MIN_LEADING_BYTE + 97) +#define MAX_LEADING_BYTE_PRIVATE -1 -/* Japanese JIS X0208-1990 2/4 2/{(8),9,10,11} 4/2 (B) */ -#define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 13) - -/* Konjaku-Mojikyo font (for pseudo-JIS X 0208 encoding) */ -#define LEADING_BYTE_MOJIKYO_PJ_1 (CHARSET_ID_OFFSET - 14) -#define LEADING_BYTE_MOJIKYO_PJ_2 (CHARSET_ID_OFFSET - 15) -#define LEADING_BYTE_MOJIKYO_PJ_3 (CHARSET_ID_OFFSET - 16) -#define LEADING_BYTE_MOJIKYO_PJ_4 (CHARSET_ID_OFFSET - 17) -#define LEADING_BYTE_MOJIKYO_PJ_5 (CHARSET_ID_OFFSET - 18) -#define LEADING_BYTE_MOJIKYO_PJ_6 (CHARSET_ID_OFFSET - 19) -#define LEADING_BYTE_MOJIKYO_PJ_7 (CHARSET_ID_OFFSET - 20) -#define LEADING_BYTE_MOJIKYO_PJ_8 (CHARSET_ID_OFFSET - 21) -#define LEADING_BYTE_MOJIKYO_PJ_9 (CHARSET_ID_OFFSET - 22) -#define LEADING_BYTE_MOJIKYO_PJ_10 (CHARSET_ID_OFFSET - 23) -#define LEADING_BYTE_MOJIKYO_PJ_11 (CHARSET_ID_OFFSET - 24) -#define LEADING_BYTE_MOJIKYO_PJ_12 (CHARSET_ID_OFFSET - 25) -#define LEADING_BYTE_MOJIKYO_PJ_13 (CHARSET_ID_OFFSET - 26) -#define LEADING_BYTE_MOJIKYO_PJ_14 (CHARSET_ID_OFFSET - 27) -#define LEADING_BYTE_MOJIKYO_PJ_15 (CHARSET_ID_OFFSET - 28) -#define LEADING_BYTE_MOJIKYO_PJ_16 (CHARSET_ID_OFFSET - 29) -#define LEADING_BYTE_MOJIKYO_PJ_17 (CHARSET_ID_OFFSET - 30) -#define LEADING_BYTE_MOJIKYO_PJ_18 (CHARSET_ID_OFFSET - 31) -#define LEADING_BYTE_MOJIKYO_PJ_19 (CHARSET_ID_OFFSET - 32) -#define LEADING_BYTE_MOJIKYO_PJ_20 (CHARSET_ID_OFFSET - 33) -#define LEADING_BYTE_MOJIKYO_PJ_21 (CHARSET_ID_OFFSET - 34) - -#define MIN_LEADING_BYTE_PRIVATE MIN_LEADING_BYTE -#define MAX_LEADING_BYTE_PRIVATE (CHARSET_ID_OFFSET - 35) - - -/* #define CHARSET_ID_OFFSET_94 (CHARSET_ID_OFFSET - '0') */ - -/* #define MIN_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '0') */ -/* #define MAX_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '?') */ /* ISO 646 IRV */ #define LEADING_BYTE_ASCII 6 /* (CHARSET_ID_OFFSET_94 + 'B') */ @@ -249,7 +218,10 @@ struct Lisp_Charset int id; Lisp_Object name; - Lisp_Object doc_string, registry, short_name, long_name; + Lisp_Object doc_string; + Lisp_Object registry; + Lisp_Object short_name; + Lisp_Object long_name; Lisp_Object reverse_direction_charset; @@ -274,36 +246,33 @@ struct Lisp_Charset /* Which half of font to be used to display this character set */ unsigned int graphic; - /* Byte->character mapping table */ + /* Code-point->character mapping table */ Lisp_Object decoding_table; + /* Base CCS */ + Lisp_Object mother; + /* Range of character code */ - Emchar ucs_min, ucs_max; + int min_code, max_code; /* Offset for external code */ - Emchar code_offset; + int code_offset; + + /* Type of conversion from mother CCS */ + unsigned char conversion; /* Offset for each byte */ - Emchar byte_offset; + int byte_offset; }; +typedef struct Lisp_Charset Lisp_Charset; -DECLARE_LRECORD (charset, struct Lisp_Charset); -#define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset) +DECLARE_LRECORD (charset, Lisp_Charset); +#define XCHARSET(x) XRECORD (x, charset, Lisp_Charset) #define XSETCHARSET(x, p) XSETRECORD (x, p, charset) #define CHARSETP(x) RECORDP (x, charset) -#define GC_CHARSETP(x) GC_RECORDP (x, charset) #define CHECK_CHARSET(x) CHECK_RECORD (x, charset) #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset) -#define CHARSET_TYPE_94 0 /* This charset includes 94 characters. */ -#define CHARSET_TYPE_94X94 1 /* This charset includes 94x94 characters. */ -#define CHARSET_TYPE_96 2 /* This charset includes 96 characters. */ -#define CHARSET_TYPE_96X96 3 /* This charset includes 96x96 characters. */ -#define CHARSET_TYPE_128 4 /* This charset includes 128 characters. */ -#define CHARSET_TYPE_128X128 5 /* This charset includes 128x128 characters. */ -#define CHARSET_TYPE_256 6 /* This charset includes 256 characters. */ -#define CHARSET_TYPE_256X256 7 /* This charset includes 256x256 characters. */ - #define CHARSET_LEFT_TO_RIGHT 0 #define CHARSET_RIGHT_TO_LEFT 1 @@ -324,11 +293,46 @@ DECLARE_LRECORD (charset, struct Lisp_Charset); #define CHARSET_CHARS(cs) ((cs)->chars) #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset) #define CHARSET_DECODING_TABLE(cs) ((cs)->decoding_table) -#define CHARSET_UCS_MIN(cs) ((cs)->ucs_min) -#define CHARSET_UCS_MAX(cs) ((cs)->ucs_max) +#define CHARSET_MIN_CODE(cs) ((cs)->min_code) +#define CHARSET_MAX_CODE(cs) ((cs)->max_code) #define CHARSET_CODE_OFFSET(cs) ((cs)->code_offset) #define CHARSET_BYTE_OFFSET(cs) ((cs)->byte_offset) +#define CHARSET_MOTHER(cs) ((cs)->mother) +#define CHARSET_CONVERSION(cs) ((cs)->conversion) +INLINE_HEADER int CHARSET_BYTE_SIZE (Lisp_Charset* cs); +INLINE_HEADER int +CHARSET_BYTE_SIZE (Lisp_Charset* cs) +{ + /* ad-hoc method for `ascii' */ + if ((CHARSET_CHARS (cs) == 94) && + (CHARSET_BYTE_OFFSET (cs) != 33)) + return 128 - CHARSET_BYTE_OFFSET (cs); + else + return CHARSET_CHARS (cs); +} + +INLINE_HEADER Lisp_Object CHARSET_ENCODING_TABLE (Lisp_Charset* cs); +INLINE_HEADER Lisp_Object +CHARSET_ENCODING_TABLE (Lisp_Charset* cs) +{ + return Fgethash (CHARSET_NAME(cs), + Vchar_attribute_hash_table, + Qnil); +} + +#define CONVERSION_IDENTICAL 0 +#define CONVERSION_94 1 +#define CONVERSION_96 2 +#define CONVERSION_94x60 3 +#define CONVERSION_94x94 4 +#define CONVERSION_96x96 5 +#define CONVERSION_94x94x60 6 +#define CONVERSION_94x94x94 7 +#define CONVERSION_96x96x96 8 +#define CONVERSION_94x94x94x60 9 +#define CONVERSION_94x94x94x94 10 +#define CONVERSION_96x96x96x96 11 #define XCHARSET_ID(cs) CHARSET_ID (XCHARSET (cs)) #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs)) @@ -343,13 +347,17 @@ DECLARE_LRECORD (charset, struct Lisp_Charset); #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs)) #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs)) #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs)) +#define XCHARSET_BYTE_SIZE(cs) CHARSET_BYTE_SIZE (XCHARSET (cs)) #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \ CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs)) #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs)) -#define XCHARSET_UCS_MIN(cs) CHARSET_UCS_MIN(XCHARSET(cs)) -#define XCHARSET_UCS_MAX(cs) CHARSET_UCS_MAX(XCHARSET(cs)) +#define XCHARSET_ENCODING_TABLE(cs) CHARSET_ENCODING_TABLE(XCHARSET(cs)) +#define XCHARSET_MIN_CODE(cs) CHARSET_MIN_CODE(XCHARSET(cs)) +#define XCHARSET_MAX_CODE(cs) CHARSET_MAX_CODE(XCHARSET(cs)) #define XCHARSET_CODE_OFFSET(cs) CHARSET_CODE_OFFSET(XCHARSET(cs)) #define XCHARSET_BYTE_OFFSET(cs) CHARSET_BYTE_OFFSET(XCHARSET(cs)) +#define XCHARSET_MOTHER(cs) CHARSET_MOTHER(XCHARSET(cs)) +#define XCHARSET_CONVERSION(cs) CHARSET_CONVERSION(XCHARSET(cs)) struct charset_lookup { /* Table of charsets indexed by (leading byte - 128). */ @@ -357,6 +365,8 @@ struct charset_lookup { /* Table of charsets indexed by type/final-byte/direction. */ Lisp_Object charset_by_attributes[4][128]; + + Charset_ID next_allocated_leading_byte; }; extern struct charset_lookup *chlook; @@ -365,8 +375,8 @@ extern struct charset_lookup *chlook; /* int not Bufbyte even though that is the actual type of a leading byte. This way, out-ot-range values will get caught rather than automatically truncated. */ -INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb); -INLINE Lisp_Object +INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb); +INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb) { assert (lb >= MIN_LEADING_BYTE && @@ -381,8 +391,22 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb) #endif -#define CHARSET_BY_ATTRIBUTES(type, final, dir) \ - (chlook->charset_by_attributes[type][final]) +INLINE_HEADER Lisp_Object +CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir); +INLINE_HEADER Lisp_Object +CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir) +{ + int type; + + if (chars == 94) + type = 0; + else if (chars == 96) + type = 1; + else + return Qnil; + type += dimension == 1 ? 0 : 2; + return chlook->charset_by_attributes[type][final]; +} /************************************************************************/ @@ -392,15 +416,9 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb) #define MAX_CHAR_BASIC_LATIN 0x007F /* -#define MIN_CHAR_GREEK 0x0370 -#define MAX_CHAR_GREEK 0x03CF - -#define MIN_CHAR_CYRILLIC 0x0400 -#define MAX_CHAR_CYRILLIC 0x045F -*/ - #define MIN_CHAR_HEBREW 0x0590 #define MAX_CHAR_HEBREW 0x05EF +*/ #define MIN_CHAR_THAI 0x0E00 #define MAX_CHAR_THAI 0x0E5F @@ -418,13 +436,24 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb) #define MAX_CHAR_BMP 0x00FFFF -#define MIN_CHAR_MOJIKYO 0xE00000 -#define MIN_CHAR_DAIKANWA MIN_CHAR_MOJIKYO -#define MAX_CHAR_DAIKANWA 0xE0FFFF -/* #define MAX_CHAR_MOJIKYO 0xE9093F */ -#define MAX_CHAR_MOJIKYO (MIN_CHAR_MOJIKYO + 94 * 60 * 22) +#define MIN_CHAR_SMP 0x010000 +#define MAX_CHAR_SMP 0x01FFFF + +#define MIN_CHAR_SIP 0x020000 +#define MAX_CHAR_SIP 0x02FFFF + +#if 0 +#define MIN_CHAR_DAIKANWA 0x00E00000 +#define MAX_CHAR_DAIKANWA (MIN_CHAR_DAIKANWA + 50100) /* 0xE0FFFF */ + +#define MIN_CHAR_CBETA 0x00E20000 +#define MAX_CHAR_CBETA 0x00E2FFFF + +#define MIN_CHAR_CHINA3_JEF 0x00E80000 +#define MAX_CHAR_CHINA3_JEF 0x00E8FFFF +#endif -#define MIN_CHAR_94 0xE90940 +#define MIN_CHAR_94 0x00E90940 #define MAX_CHAR_94 (MIN_CHAR_94 + 94 * 80 - 1) #define MIN_CHAR_96 (MIN_CHAR_94 + 94 * 80) #define MAX_CHAR_96 (MIN_CHAR_96 + 96 * 80 - 1) @@ -436,75 +465,198 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb) #define MIN_CHAR_96x96 0xF4C000 #define MAX_CHAR_96x96 (MIN_CHAR_96x96 + 96 * 96 * 80 - 1) +/* +#define MIN_CHAR_GT 0x61000000 +#define MAX_CHAR_GT (MIN_CHAR_GT + 67547) +*/ +#define MIN_CHAR_BIG5_CDP 0x62000000 +#define MAX_CHAR_BIG5_CDP 0x6200FFFF +/* +#define MIN_CHAR_HANZIKU_1 (0x62000000 + 65536 * 1) +#define MAX_CHAR_HANZIKU_1 (0x62000000 + 65536 * 1 + 65535) +#define MIN_CHAR_HANZIKU_2 (0x62000000 + 65536 * 2) +#define MAX_CHAR_HANZIKU_2 (0x62000000 + 65536 * 2 + 65535) +#define MIN_CHAR_HANZIKU_3 (0x62000000 + 65536 * 3) +#define MAX_CHAR_HANZIKU_3 (0x62000000 + 65536 * 3 + 65535) +#define MIN_CHAR_HANZIKU_4 (0x62000000 + 65536 * 4) +#define MAX_CHAR_HANZIKU_4 (0x62000000 + 65536 * 4 + 65535) +#define MIN_CHAR_HANZIKU_5 (0x62000000 + 65536 * 5) +#define MAX_CHAR_HANZIKU_5 (0x62000000 + 65536 * 5 + 65535) +#define MIN_CHAR_HANZIKU_6 (0x62000000 + 65536 * 6) +#define MAX_CHAR_HANZIKU_6 (0x62000000 + 65536 * 6 + 65535) +#define MIN_CHAR_HANZIKU_7 (0x62000000 + 65536 * 7) +#define MAX_CHAR_HANZIKU_7 (0x62000000 + 65536 * 7 + 65535) +#define MIN_CHAR_HANZIKU_8 (0x62000000 + 65536 * 8) +#define MAX_CHAR_HANZIKU_8 (0x62000000 + 65536 * 8 + 65535) +#define MIN_CHAR_HANZIKU_9 (0x62000000 + 65536 * 9) +#define MAX_CHAR_HANZIKU_9 (0x62000000 + 65536 * 9 + 65535) +#define MIN_CHAR_HANZIKU_10 (0x62000000 + 65536 * 10) +#define MAX_CHAR_HANZIKU_10 (0x62000000 + 65536 * 10 + 65535) +#define MIN_CHAR_HANZIKU_11 (0x62000000 + 65536 * 11) +#define MAX_CHAR_HANZIKU_11 (0x62000000 + 65536 * 11 + 65535) +#define MIN_CHAR_HANZIKU_12 (0x62000000 + 65536 * 12) +#define MAX_CHAR_HANZIKU_12 (0x62000000 + 65536 * 12 + 65535) +*/ -Emchar make_builtin_char (Lisp_Object charset, int c1, int c2); +Emchar decode_builtin_char (Lisp_Object charset, int code_point); -INLINE Emchar DECODE_CHAR (Lisp_Object charset, int code_point); -INLINE Emchar -DECODE_CHAR (Lisp_Object charset, int code_point) +INLINE_HEADER Lisp_Object +get_ccs_octet_table (Lisp_Object table, Lisp_Object ccs, int code); +INLINE_HEADER Lisp_Object +get_ccs_octet_table (Lisp_Object table, Lisp_Object ccs, int code) { - int dim = XCHARSET_DIMENSION (charset); - Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset); - int idx; - Lisp_Object ch; + int byte_offset = XCHARSET_BYTE_OFFSET (ccs); - while (dim > 0) + if (VECTORP (table)) { - dim--; - if ( VECTORP (decoding_table) - && ( 0 <= (idx = ((code_point >> (dim * 8)) - & 255) - XCHARSET_BYTE_OFFSET (charset)) ) - && ( idx < XVECTOR_LENGTH (decoding_table) ) - && !NILP (ch = XVECTOR_DATA(decoding_table)[idx]) ) - { - if (CHARP (ch)) - return XCHAR (ch); - else - decoding_table = ch; - } + int idx = code - byte_offset; + + if (idx < XVECTOR_LENGTH(table)) + return XVECTOR_DATA(table)[idx]; else - break; + return Qunbound; } - if (XCHARSET_DIMENSION (charset) == 1) - return make_builtin_char (charset, code_point, 0); + else + return table; +} + +INLINE_HEADER Lisp_Object +put_ccs_octet_table (Lisp_Object table, Lisp_Object ccs, int code, + Lisp_Object value); +INLINE_HEADER Lisp_Object +put_ccs_octet_table (Lisp_Object table, Lisp_Object ccs, int code, + Lisp_Object value) +{ + int byte_offset = XCHARSET_BYTE_OFFSET (ccs); + int ccs_len = XCHARSET_BYTE_SIZE (ccs); + + if (VECTORP (table)) + { + XVECTOR_DATA(table)[code - byte_offset] = value; + return table; + } + else if (EQ (table, value)) + return table; else { - int plane = LEADING_BYTE_MOJIKYO_PJ_1 - XCHARSET_ID (charset); + table = make_vector (ccs_len, table); + XVECTOR_DATA(table)[code - byte_offset] = value; + return table; + } +} - if ( (0 <= plane) && (plane <= 21) ) - { - int c1 = code_point >> 8; - int c2 = code_point & 255; - - if (c1 < 16 + 32) - return ' '; - else if (c1 < 16 + 32 + 30) - return DECODE_CHAR (Vcharset_mojikyo, - plane * (94 * 60) - + (c1 - (16 + 32)) * 94 - + (c2 - 33) - + 1); - else if (c1 < 18 + 32 + 30) - return ' '; - else if (c1 < 18 + 32 + 60) - return DECODE_CHAR (Vcharset_mojikyo, - plane * (94 * 60) - + (c1 - (18 + 32)) * 94 - + (c2 - 33) - + 1); - else - return ' '; - } - else - return make_builtin_char (charset, code_point >> 8, code_point & 255); +INLINE_HEADER void +decoding_table_put_char (Lisp_Object ccs, + int code_point, Lisp_Object character); +INLINE_HEADER void +decoding_table_put_char (Lisp_Object ccs, + int code_point, Lisp_Object character) +{ + Lisp_Object table1 = XCHARSET_DECODING_TABLE (ccs); + int dim = XCHARSET_DIMENSION (ccs); + + if (dim == 1) + XCHARSET_DECODING_TABLE (ccs) + = put_ccs_octet_table (table1, ccs, code_point, character); + else if (dim == 2) + { + Lisp_Object table2 + = get_ccs_octet_table (table1, ccs, (unsigned char)(code_point >> 8)); + + table2 = put_ccs_octet_table (table2, ccs, + (unsigned char)code_point, character); + XCHARSET_DECODING_TABLE (ccs) + = put_ccs_octet_table (table1, ccs, + (unsigned char)(code_point >> 8), table2); + } + else if (dim == 3) + { + Lisp_Object table2 + = get_ccs_octet_table (table1, ccs, (unsigned char)(code_point >> 16)); + Lisp_Object table3 + = get_ccs_octet_table (table2, ccs, (unsigned char)(code_point >> 8)); + + table3 = put_ccs_octet_table (table3, ccs, + (unsigned char)code_point, character); + table2 = put_ccs_octet_table (table2, ccs, + (unsigned char)(code_point >> 8), table3); + XCHARSET_DECODING_TABLE (ccs) + = put_ccs_octet_table (table1, ccs, + (unsigned char)(code_point >> 16), table2); + } + else /* if (dim == 4) */ + { + Lisp_Object table2 + = get_ccs_octet_table (table1, ccs, (unsigned char)(code_point >> 24)); + Lisp_Object table3 + = get_ccs_octet_table (table2, ccs, (unsigned char)(code_point >> 16)); + Lisp_Object table4 + = get_ccs_octet_table (table3, ccs, (unsigned char)(code_point >> 8)); + + table4 = put_ccs_octet_table (table4, ccs, + (unsigned char)code_point, character); + table3 = put_ccs_octet_table (table3, ccs, + (unsigned char)(code_point >> 8), table4); + table2 = put_ccs_octet_table (table2, ccs, + (unsigned char)(code_point >> 16), table3); + XCHARSET_DECODING_TABLE (ccs) + = put_ccs_octet_table (table1, ccs, + (unsigned char)(code_point >> 24), table2); + } +} + +INLINE_HEADER void +decoding_table_remove_char (Lisp_Object ccs, int code_point); +INLINE_HEADER void +decoding_table_remove_char (Lisp_Object ccs, int code_point) +{ + decoding_table_put_char (ccs, code_point, Qunbound); +} + +Emchar decode_defined_char (Lisp_Object charset, int code_point); + +INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point); +INLINE_HEADER Emchar +DECODE_CHAR (Lisp_Object charset, int code_point) +{ + Emchar char_id = decode_defined_char (charset, code_point); + + if (char_id >= 0) + return char_id; + else if (XCHARSET_DIMENSION (charset) == 1) + return decode_builtin_char (charset, code_point); + else if (EQ (charset, Vcharset_chinese_big5_1)) + { + unsigned int I + = ((code_point >> 8) - 33) * (0xFF - 0xA1) + + ((code_point & 0xFF) - 33); + unsigned char b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1; + unsigned char b2 = I % (0xFF - 0xA1 + 0x7F - 0x40); + + b2 += b2 < 0x3F ? 0x40 : 0x62; + return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2); + } + else if (EQ (charset, Vcharset_chinese_big5_2)) + { + unsigned int I + = ((code_point >> 8) - 33) * (0xFF - 0xA1) + + ((code_point & 0xFF) - 33); + unsigned char b1, b2; + + I += (0xFF - 0xA1 + 0x7F - 0x40) * (0xC9 - 0xA1); + b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1; + b2 = I % (0xFF - 0xA1 + 0x7F - 0x40); + b2 += b2 < 0x3F ? 0x40 : 0x62; + return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2); } + return decode_builtin_char (charset, code_point); } /* Return a character whose charset is CHARSET and position-codes are C1 and C2. TYPE9N character ignores C2. */ -INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2); -INLINE Emchar +INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2); +INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2) { if (XCHARSET_DIMENSION (charset) == 1) @@ -516,92 +668,43 @@ MAKE_CHAR (Lisp_Object charset, int c1, int c2) extern Lisp_Object Vcharacter_attribute_table; int encode_builtin_char_1 (Emchar c, Lisp_Object* charset); +int charset_code_point (Lisp_Object charset, Emchar ch, int defined_only); int range_charset_code_point (Lisp_Object charset, Emchar ch); -INLINE int charset_code_point (Lisp_Object charset, Emchar ch); -INLINE int -charset_code_point (Lisp_Object charset, Emchar ch) -{ - Lisp_Object cdef = get_char_code_table (ch, Vcharacter_attribute_table); - - if (!NILP (cdef)) - { - Lisp_Object field = Fassq (charset, cdef); - - if (!NILP (field)) - return XINT (Fcdr (field)); - } - return range_charset_code_point (charset, ch); -} - extern Lisp_Object Vdefault_coded_charset_priority_list; EXFUN (Ffind_charset, 1); -INLINE int encode_char_1 (Emchar c, Lisp_Object* charset); -INLINE int -encode_char_1 (Emchar c, Lisp_Object* charset) +INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset); +INLINE_HEADER int +encode_char_1 (Emchar ch, Lisp_Object* charset) { - Lisp_Object cdef = get_char_code_table (c, Vcharacter_attribute_table); + Lisp_Object charsets = Vdefault_coded_charset_priority_list; - if (!EQ (cdef, Qnil)) + while (!NILP (charsets)) { - Lisp_Object charsets = Vdefault_coded_charset_priority_list; - Lisp_Object field; - - while (!EQ (charsets, Qnil)) + *charset = Ffind_charset (Fcar (charsets)); + if (!NILP (*charset)) { - *charset = Ffind_charset (Fcar (charsets)); - if (!EQ (*charset, Qnil)) - { - int code_point; - - if (!NILP (field = Fassq (*charset, cdef))) - return XINT (Fcdr (field)); - else if ((code_point - = range_charset_code_point (*charset, c)) >= 0) - return code_point; - } - charsets = Fcdr (charsets); + int code_point = charset_code_point (*charset, ch, 0); + + if (code_point >= 0) + return code_point; } + charsets = Fcdr (charsets); } /* otherwise --- maybe for bootstrap */ - return encode_builtin_char_1 (c, charset); + return encode_builtin_char_1 (ch, charset); } -INLINE int encode_char_2 (Emchar ch, Lisp_Object* charset); -INLINE int -encode_char_2 (Emchar ch, Lisp_Object* charset) -{ - int code_point = encode_char_1 (ch, charset); - - if (EQ (*charset, Vcharset_mojikyo)) - { - int plane, byte1, byte2; +#define ENCODE_CHAR(ch, charset) encode_char_1 (ch, &(charset)) - code_point--; - plane = code_point / (94 * 60); - byte1 = (code_point % (94 * 60)) / 94; - if (byte1 < 30) - byte1 += 16 + 32; - else - byte1 += 18 + 32; - byte2 = code_point % 94 + 33; - *charset - = CHARSET_BY_LEADING_BYTE (LEADING_BYTE_MOJIKYO_PJ_1 - plane); - return (byte1 << 8) | byte2; - } - else - return code_point; -} - -#define ENCODE_CHAR(ch, charset) encode_char_2 (ch, &(charset)) - -INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2); -INLINE void +INLINE_HEADER void +breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2); +INLINE_HEADER void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2) { - int code_point = encode_char_2 (c, charset); + int code_point = encode_char_1 (c, charset); if (code_point >= 0) { @@ -626,8 +729,8 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2) #define BREAKUP_CHAR(ch, charset, b1, b2) \ breakup_char_1 (ch, &(charset), &(b1), &(b2)) -INLINE Lisp_Object CHAR_CHARSET (Emchar ch); -INLINE Lisp_Object +INLINE_HEADER Lisp_Object CHAR_CHARSET (Emchar ch); +INLINE_HEADER Lisp_Object CHAR_CHARSET (Emchar ch) { Lisp_Object charset; @@ -639,16 +742,21 @@ CHAR_CHARSET (Emchar ch) #define CHAR_CHARSET_ID(c) (XCHARSET_ID(CHAR_CHARSET(c))) #define CHAR_COLUMNS(c) (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c)))) - -/************************************************************************/ -/* Exported functions */ -/************************************************************************/ -EXFUN (Fget_charset, 1); +typedef struct Charc +{ + Lisp_Object charset; + int code_point; +} Charc; -extern Lisp_Object Vcharset_chinese_big5_1; -extern Lisp_Object Vcharset_chinese_big5_2; -extern Lisp_Object Vcharset_japanese_jisx0208; -extern Lisp_Object Vcharset_japanese_jisx0212; +INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch); +INLINE_HEADER Charc +CHAR_TO_CHARC (Emchar ch) +{ + Charc cc; + + cc.code_point = encode_char_1 (ch, &cc.charset); + return cc; +} -#endif /* _XEMACS_CHAR_UCS_H */ +#endif /* INCLUDED_char_ucs_h_ */