Mercurial > emacs
comparison src/charset.h @ 88364:f6557aebe110
Completely re-written. Character and multibyte
sequence handling codes are moved to character.c.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 01 Mar 2002 01:16:34 +0000 |
parents | ab30bd62a6a8 |
children | 29c4241b5418 |
comparison
equal
deleted
inserted
replaced
88363:13b9026422e0 | 88364:f6557aebe110 |
---|---|
1 /* Header for multibyte character handler. | 1 /* Header for charset handler. |
2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. | 2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. |
3 Licensed to the Free Software Foundation. | 3 Licensed to the Free Software Foundation. |
4 Copyright (C) 2001 Free Software Foundation, Inc. | 4 Copyright (C) 2001 Free Software Foundation, Inc. |
5 Copyright (C) 2001, 2002 | |
6 National Institute of Advanced Industrial Science and Technology (AIST) | |
7 Registration Number H13PRO009 | |
5 | 8 |
6 This file is part of GNU Emacs. | 9 This file is part of GNU Emacs. |
7 | 10 |
8 GNU Emacs is free software; you can redistribute it and/or modify | 11 GNU Emacs is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 12 it under the terms of the GNU General Public License as published by |
21 Boston, MA 02111-1307, USA. */ | 24 Boston, MA 02111-1307, USA. */ |
22 | 25 |
23 #ifndef EMACS_CHARSET_H | 26 #ifndef EMACS_CHARSET_H |
24 #define EMACS_CHARSET_H | 27 #define EMACS_CHARSET_H |
25 | 28 |
26 /* #define BYTE_COMBINING_DEBUG */ | 29 /* Index to arguments of Fdefine_charset_internal. */ |
27 | 30 |
28 /*** GENERAL NOTE on CHARACTER SET (CHARSET) *** | 31 enum define_charset_arg_index |
29 | 32 { |
30 A character set ("charset" hereafter) is a meaningful collection | 33 charset_arg_name, |
31 (i.e. language, culture, functionality, etc) of characters. Emacs | 34 charset_arg_dimension, |
32 handles multiple charsets at once. Each charset corresponds to one | 35 charset_arg_code_space, |
33 of the ISO charsets. Emacs identifies a charset by a unique | 36 charset_arg_iso_final, |
34 identification number, whereas ISO identifies a charset by a triplet | 37 charset_arg_iso_revision, |
35 of DIMENSION, CHARS and FINAL-CHAR. So, hereafter, just saying | 38 charset_arg_emacs_mule_id, |
36 "charset" means an identification number (integer value). | 39 charset_arg_ascii_compatible_p, |
37 | 40 charset_arg_supplementary_p, |
38 The value range of charsets is 0x00, 0x81..0xFE. There are four | 41 charset_arg_invalid_code, |
39 kinds of charset depending on DIMENSION (1 or 2) and CHARS (94 or | 42 charset_arg_code_offset, |
40 96). For instance, a charset of DIMENSION2_CHARS94 contains 94x94 | 43 charset_arg_map, |
41 characters. | 44 charset_arg_parents, |
42 | 45 charset_arg_unify_map, |
43 Within Emacs Lisp, a charset is treated as a symbol which has a | 46 charset_arg_plist, |
44 property `charset'. The property value is a vector containing | 47 charset_arg_max |
45 various information about the charset. For readability of C code, | 48 }; |
46 we use the following convention for C variable names: | 49 |
47 charset_symbol: Emacs Lisp symbol of a charset | 50 |
48 charset_id: Emacs Lisp integer of an identification number of a charset | 51 /* Indices to charset attributes vector. */ |
49 charset: C integer of an identification number of a charset | 52 |
50 | 53 enum charset_attr_index |
51 Each charset (except for ascii) is assigned a base leading-code | 54 { |
52 (range 0x80..0x9E). In addition, a charset of greater than 0xA0 | 55 /* ID number of the charset. */ |
53 (whose base leading-code is 0x9A..0x9D) is assigned an extended | 56 charset_id, |
54 leading-code (range 0xA0..0xFE). In this case, each base | 57 |
55 leading-code specifies the allowable range of extended leading-code | 58 /* Name of the charset (symbol). */ |
56 as shown in the table below. A leading-code is used to represent a | 59 charset_name, |
57 character in Emacs' buffer and string. | 60 |
58 | 61 /* Property list of the charset. */ |
59 We call a charset which has extended leading-code a "private | 62 charset_plist, |
60 charset" because those are mainly for a charset which is not yet | 63 |
61 registered by ISO. On the contrary, we call a charset which does | 64 /* If the method of the charset is `MAP_DEFERRED', the value is a |
62 not have extended leading-code an "official charset". | 65 mappint vector or a file name that contains mapping vector. |
63 | 66 Otherwise, nil. */ |
64 --------------------------------------------------------------------------- | 67 charset_map, |
65 charset dimension base leading-code extended leading-code | 68 |
66 --------------------------------------------------------------------------- | 69 /* If the method of the charset is `MAP', the value is a vector |
67 0x00 official dim1 -- none -- -- none -- | 70 that maps code points of the charset to characters. The vector |
68 (ASCII) | 71 is indexed by a character index. A character index is |
69 0x01..0x7F --never used-- | 72 calculated from a code point and the code-space table of the |
70 0x80 official dim1 -- none -- -- none -- | 73 charset. */ |
71 (eight-bit-graphic) | 74 charset_decoder, |
72 0x81..0x8F official dim1 same as charset -- none -- | 75 |
73 0x90..0x99 official dim2 same as charset -- none -- | 76 /* If the method of the charset is `MAP', the value is a |
74 0x9A..0x9D --never used-- | 77 char-table that maps characters of the charset to code |
75 0x9E official dim1 same as charset -- none -- | 78 points. */ |
76 (eight-bit-control) | 79 charset_encoder, |
77 0x9F --never used-- | 80 |
78 0xA0..0xDF private dim1 0x9A same as charset | 81 /* If the method of the charset is `INHERIT', the value is a list |
79 of 1-column width | 82 of the form (PARENT-CHARSET-ID . CODE-OFFSET). */ |
80 0xE0..0xEF private dim1 0x9B same as charset | 83 charset_parents, |
81 of 2-column width | 84 |
82 0xF0..0xF4 private dim2 0x9C same as charset | 85 /* */ |
83 of 1-column width | 86 charset_unify_map, |
84 0xF5..0xFE private dim2 0x9D same as charset | 87 |
85 of 2-column width | 88 /* */ |
86 0xFF --never used-- | 89 charset_deunifier, |
87 --------------------------------------------------------------------------- | 90 |
88 | 91 /* The length of charset attribute vector. */ |
89 */ | 92 charset_attr_max |
90 | 93 }; |
91 /* Definition of special leading-codes. */ | 94 |
92 /* Leading-code followed by extended leading-code. */ | 95 /* Methods for converting code points and characters of charsets. */ |
93 #define LEADING_CODE_PRIVATE_11 0x9A /* for private DIMENSION1 of 1-column */ | 96 |
94 #define LEADING_CODE_PRIVATE_12 0x9B /* for private DIMENSION1 of 2-column */ | 97 enum charset_method |
95 #define LEADING_CODE_PRIVATE_21 0x9C /* for private DIMENSION2 of 1-column */ | 98 { |
96 #define LEADING_CODE_PRIVATE_22 0x9D /* for private DIMENSION2 of 2-column */ | 99 /* For a charset of this method, a character code is calculated |
97 | 100 from a character index (which is calculated from a code point) |
98 #define LEADING_CODE_8_BIT_CONTROL 0x9E /* for `eight-bit-control' */ | 101 simply by adding an offset value. */ |
99 | 102 CHARSET_METHOD_OFFSET, |
100 /* Extended leading-code. */ | 103 |
101 /* Start of each extended leading-codes. */ | 104 /* For a charset of this method, a decoder vector and an encoder |
102 #define LEADING_CODE_EXT_11 0xA0 /* follows LEADING_CODE_PRIVATE_11 */ | 105 char-table is used for code point <-> character code |
103 #define LEADING_CODE_EXT_12 0xE0 /* follows LEADING_CODE_PRIVATE_12 */ | 106 conversion. */ |
104 #define LEADING_CODE_EXT_21 0xF0 /* follows LEADING_CODE_PRIVATE_21 */ | 107 CHARSET_METHOD_MAP, |
105 #define LEADING_CODE_EXT_22 0xF5 /* follows LEADING_CODE_PRIVATE_22 */ | 108 |
106 /* Maximum value of extended leading-codes. */ | 109 /* Same as above but decoder and encoder are loaded from a file on |
107 #define LEADING_CODE_EXT_MAX 0xFE | 110 demand. Once loaded, the method is changed to |
108 | 111 CHARSET_METHOD_MAP. */ |
109 /* Definition of minimum/maximum charset of each DIMENSION. */ | 112 CHARSET_METHOD_MAP_DEFERRED, |
110 #define MIN_CHARSET_OFFICIAL_DIMENSION1 0x80 | 113 |
111 #define MAX_CHARSET_OFFICIAL_DIMENSION1 0x8F | 114 /* A charset of this method inherits characters from the other |
112 #define MIN_CHARSET_OFFICIAL_DIMENSION2 0x90 | 115 charsets. */ |
113 #define MAX_CHARSET_OFFICIAL_DIMENSION2 0x99 | 116 CHARSET_METHOD_INHERIT, |
114 #define MIN_CHARSET_PRIVATE_DIMENSION1 LEADING_CODE_EXT_11 | 117 }; |
115 #define MIN_CHARSET_PRIVATE_DIMENSION2 LEADING_CODE_EXT_21 | 118 |
116 | 119 struct charset |
117 /* Maximum value of overall charset identification number. */ | 120 { |
118 #define MAX_CHARSET 0xFE | 121 int id; |
119 | 122 |
120 /* Definition of special charsets. */ | 123 int hash_index; |
121 #define CHARSET_ASCII 0 /* 0x00..0x7F */ | 124 |
122 #define CHARSET_8_BIT_CONTROL 0x9E /* 0x80..0x9F */ | 125 /* Dimension of the charset: 1, 2, 3, or 4. */ |
123 #define CHARSET_8_BIT_GRAPHIC 0x80 /* 0xA0..0xFF */ | 126 int dimension; |
124 | 127 |
125 extern int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */ | 128 /* Minimum byte code in each dimension. */ |
126 extern int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */ | 129 int code_space[16]; |
127 extern int charset_jisx0208; /* JISX0208.1983 (Japanese Kanji) */ | 130 |
128 extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */ | 131 /* 1 if there's no gap in code-points. */ |
129 extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */ | 132 int code_linear_p; |
130 extern int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */ | 133 |
131 extern int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */ | 134 /* If the charset is treated as 94-chars in ISO-2022, the value is 0. |
132 | 135 If the charset is treated as 96-chars in ISO-2022, the value is 1. */ |
133 /* Check if CH is an ASCII character or a base leading-code. | 136 int iso_chars_96; |
134 Nowadays, any byte can be the first byte of a character in a | 137 |
135 multibyte buffer/string. So this macro name is not appropriate. */ | 138 /* ISO final character code for the charset: 48..127. |
136 #define CHAR_HEAD_P(ch) ((unsigned char) (ch) < 0xA0) | 139 It may be 0 if the charset doesn't conform to ISO-2022. */ |
137 | 140 int iso_final; |
138 /*** GENERAL NOTE on CHARACTER REPRESENTATION *** | 141 |
139 | 142 int iso_revision; |
140 Firstly, the term "character" or "char" is used for a multilingual | 143 |
141 character (of course, including ASCII characters), not for a byte in | 144 /* If the charset is identical to what supported by Emacs 21 and the |
142 computer memory. We use the term "code" or "byte" for the latter | 145 priors, the identification number of the charset used in those |
143 case. | 146 version. Otherwise, -1. */ |
144 | 147 int emacs_mule_id; |
145 A character is identified by charset and one or two POSITION-CODEs. | 148 |
146 POSITION-CODE is the position of the character in the charset. A | 149 /* Nonzero iff the charset is compatible with ASCII. */ |
147 character of DIMENSION1 charset has one POSITION-CODE: POSITION-CODE-1. | 150 int ascii_compatible_p; |
148 A character of DIMENSION2 charset has two POSITION-CODE: | 151 |
149 POSITION-CODE-1 and POSITION-CODE-2. The code range of | 152 /* Nonzero iff the charset is supplementary. */ |
150 POSITION-CODE is 0x20..0x7F. | 153 int supplementary_p; |
151 | 154 |
152 Emacs has two kinds of representation of a character: multi-byte | 155 /* Nonzero iff all the code points are representable by Lisp_Int. */ |
153 form (for buffers and strings) and single-word form (for character | 156 int compact_codes_p; |
154 objects in Emacs Lisp). The latter is called "character code" | 157 |
155 hereafter. Both representations encode the information of charset | 158 /* The method for encoding/decoding characters of the charset. */ |
156 and POSITION-CODE but in a different way (for instance, the MSB of | 159 enum charset_method method; |
157 POSITION-CODE is set in multi-byte form). | 160 |
158 | 161 /* Mininum and Maximum code points of the charset. */ |
159 For details of the multi-byte form, see the section "2. Emacs | 162 unsigned min_code, max_code; |
160 internal format handlers" of `coding.c'. | 163 |
161 | 164 /* Mininum and Maximum character codes of the charset. If the |
162 Emacs uses 19 bits for a character code. The bits are divided into | 165 charset is compatible with ASCII, min_char is a minimum non-ASCII |
163 3 fields: FIELD1(5bits):FIELD2(7bits):FIELD3(7bits). | 166 character of the charset. */ |
164 | 167 int min_char, max_char; |
165 A character code of DIMENSION1 character uses FIELD2 to hold charset | 168 |
166 and FIELD3 to hold POSITION-CODE-1. A character code of DIMENSION2 | 169 /* The code returned by ENCODE_CHAR if a character is not encodable |
167 character uses FIELD1 to hold charset, FIELD2 and FIELD3 to hold | 170 by the charset. */ |
168 POSITION-CODE-1 and POSITION-CODE-2 respectively. | 171 unsigned invalid_code; |
169 | 172 |
170 More precisely... | 173 /* If the method of the charset is CHARSET_METHOD_MAP, this is a |
171 | 174 table of bits used to quickly and roughly guess if a character |
172 FIELD2 of DIMENSION1 character (except for ascii, eight-bit-control, | 175 belongs to the charset. |
173 and eight-bit-graphic) is "charset - 0x70". This is to make all | 176 |
174 character codes except for ASCII and 8-bit codes greater than 256. | 177 The first 64 elements are 512 bits for characters less than |
175 So, the range of FIELD2 of DIMENSION1 character is 0, 1, or | 178 0x10000. Each bit corresponds to 128-character block. The last |
176 0x11..0x7F. | 179 126 elements are 1008 bits for the greater characters |
177 | 180 (0x10000..0x3FFFFF). Each bit corresponds to 4096-character |
178 FIELD1 of DIMENSION2 character is "charset - 0x8F" for official | 181 block. |
179 charset and "charset - 0xE0" for private charset. So, the range of | 182 |
180 FIELD1 of DIMENSION2 character is 0x01..0x1E. | 183 If a bit is 1, at least one character in the corresponds block is |
181 | 184 in this charset. */ |
182 ----------------------------------------------------------------------------- | 185 unsigned char fast_map[190]; |
183 charset FIELD1 (5-bit) FIELD2 (7-bit) FIELD3 (7-bit) | 186 |
184 ----------------------------------------------------------------------------- | 187 /* Offset value to calculate a character code from code-point, and |
185 ascii 0 0 0x00..0x7F | 188 visa versa. */ |
186 eight-bit-control 0 1 0x00..0x1F | 189 int code_offset; |
187 eight-bit-graphic 0 1 0x20..0x7F | 190 |
188 DIMENSION1 0 charset - 0x70 POSITION-CODE-1 | 191 int unified_p; |
189 DIMENSION2(o) charset - 0x8F POSITION-CODE-1 POSITION-CODE-2 | 192 }; |
190 DIMENSION2(p) charset - 0xE0 POSITION-CODE-1 POSITION-CODE-2 | 193 |
191 ----------------------------------------------------------------------------- | 194 /* Hash table of charset symbols vs. the correponding attribute |
192 "(o)": official, "(p)": private | 195 vectors. */ |
193 ----------------------------------------------------------------------------- | 196 extern Lisp_Object Vcharset_hash_table; |
194 */ | 197 |
195 | 198 /* Table of struct charset. */ |
196 /* Masks of each field of character code. */ | 199 extern struct charset *charset_table; |
197 #define CHAR_FIELD1_MASK (0x1F << 14) | 200 extern int charset_table_used; |
198 #define CHAR_FIELD2_MASK (0x7F << 7) | 201 |
199 #define CHAR_FIELD3_MASK 0x7F | 202 #define CHARSET_FROM_ID(id) (charset_table + (id)) |
200 | 203 |
201 /* Macros to access each field of character C. */ | 204 extern Lisp_Object Vcharset_list; |
202 #define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14) | 205 extern Lisp_Object Viso_2022_charset_list; |
203 #define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7) | 206 extern Lisp_Object Vemacs_mule_charset_list; |
204 #define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK) | 207 |
205 | 208 extern struct charset *emacs_mule_charset[256]; |
206 /* Minimum character code of character of each DIMENSION. */ | 209 |
207 #define MIN_CHAR_OFFICIAL_DIMENSION1 \ | 210 |
208 ((0x81 - 0x70) << 7) | 211 /* Macros to access information about charset. */ |
209 #define MIN_CHAR_PRIVATE_DIMENSION1 \ | 212 |
210 ((MIN_CHARSET_PRIVATE_DIMENSION1 - 0x70) << 7) | 213 /* Return the attribute vector of charset whose symbol is SYMBOL. */ |
211 #define MIN_CHAR_OFFICIAL_DIMENSION2 \ | 214 #define CHARSET_SYMBOL_ATTRIBUTES(symbol) \ |
212 ((MIN_CHARSET_OFFICIAL_DIMENSION2 - 0x8F) << 14) | 215 Fgethash ((symbol), Vcharset_hash_table, Qnil) |
213 #define MIN_CHAR_PRIVATE_DIMENSION2 \ | 216 |
214 ((MIN_CHARSET_PRIVATE_DIMENSION2 - 0xE0) << 14) | 217 #define CHARSET_ATTR_ID(attrs) AREF ((attrs), charset_id) |
215 /* Maximum character code currently used plus 1. */ | 218 #define CHARSET_ATTR_NAME(attrs) AREF ((attrs), charset_name) |
216 #define MAX_CHAR (0x1F << 14) | 219 #define CHARSET_ATTR_PLIST(attrs) AREF ((attrs), charset_plist) |
217 | 220 #define CHARSET_ATTR_MAP(attrs) AREF ((attrs), charset_map) |
218 /* 1 if C is a single byte character, else 0. */ | 221 #define CHARSET_ATTR_DECODER(attrs) AREF ((attrs), charset_decoder) |
219 #define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100) | 222 #define CHARSET_ATTR_ENCODER(attrs) AREF ((attrs), charset_encoder) |
220 | 223 #define CHARSET_ATTR_PARENTS(attrs) AREF ((attrs), charset_parents) |
221 /* 1 if BYTE is an ASCII character in itself, in multibyte mode. */ | 224 #define CHARSET_ATTR_UNIFY_MAP(attrs) AREF ((attrs), charset_unify_map) |
222 #define ASCII_BYTE_P(byte) ((byte) < 0x80) | 225 #define CHARSET_ATTR_DEUNIFIER(attrs) AREF ((attrs), charset_deunifier) |
223 | 226 |
224 /* A char-table containing information on each character set. | 227 #define CHARSET_SYMBOL_ID(symbol) \ |
225 | 228 CHARSET_ATTR_ID (CHARSET_SYMBOL_ATTRIBUTES (symbol)) |
226 Unlike ordinary char-tables, this doesn't contain any nested tables. | 229 |
227 Only the top level elements are used. Each element is a vector of | 230 /* Return an index to Vcharset_hash_table of the charset whose symbol |
228 the following information: | 231 is SYMBOL. */ |
229 CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION, | 232 #define CHARSET_SYMBOL_HASH_INDEX(symbol) \ |
230 LEADING-CODE-BASE, LEADING-CODE-EXT, | 233 hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol, NULL) |
231 ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE, | 234 |
232 REVERSE-CHARSET, SHORT-NAME, LONG-NAME, DESCRIPTION, | 235 /* Return the attribute vector of CHARSET. */ |
233 PLIST. | 236 #define CHARSET_ATTRIBUTES(charset) \ |
234 | 237 (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), (charset)->hash_index)) |
235 CHARSET-ID (integer) is the identification number of the charset. | 238 |
236 | 239 #define CHARSET_ID(charset) ((charset)->id) |
237 BYTES (integer) is the length of the multi-byte form of a character | 240 #define CHARSET_HASH_INDEX(charset) ((charset)->hash_index) |
238 in the charset: one of 1, 2, 3, and 4. | 241 #define CHARSET_DIMENSION(charset) ((charset)->dimension) |
239 | 242 #define CHARSET_CODE_SPACE(charset) ((charset)->code_space) |
240 DIMENSION (integer) is the number of bytes to represent a character: 1 or 2. | 243 #define CHARSET_CODE_LINEAR_P(charset) ((charset)->code_linear_p) |
241 | 244 #define CHARSET_ISO_CHARS_96(charset) ((charset)->iso_chars_96) |
242 CHARS (integer) is the number of characters in a dimension: 94 or 96. | 245 #define CHARSET_ISO_FINAL(charset) ((charset)->iso_final) |
243 | 246 #define CHARSET_ISO_PLANE(charset) ((charset)->iso_plane) |
244 WIDTH (integer) is the number of columns a character in the charset | 247 #define CHARSET_ISO_REVISION(charset) ((charset)->iso_revision) |
245 occupies on the screen: one of 0, 1, and 2.. | 248 #define CHARSET_EMACS_MULE_ID(charset) ((charset)->emacs_mule_id) |
246 | 249 #define CHARSET_ASCII_COMPATIBLE_P(charset) ((charset)->ascii_compatible_p) |
247 DIRECTION (integer) is the rendering direction of characters in the | 250 #define CHARSET_COMPACT_CODES_P(charset) ((charset)->compact_codes_p) |
248 charset when rendering. If 0, render from left to right, else | 251 #define CHARSET_METHOD(charset) ((charset)->method) |
249 render from right to left. | 252 #define CHARSET_MIN_CODE(charset) ((charset)->min_code) |
250 | 253 #define CHARSET_MAX_CODE(charset) ((charset)->max_code) |
251 LEADING-CODE-BASE (integer) is the base leading-code for the | 254 #define CHARSET_INVALID_CODE(charset) ((charset)->invalid_code) |
252 charset. | 255 #define CHARSET_MIN_CHAR(charset) ((charset)->min_char) |
253 | 256 #define CHARSET_MAX_CHAR(charset) ((charset)->max_char) |
254 LEADING-CODE-EXT (integer) is the extended leading-code for the | 257 #define CHARSET_CODE_OFFSET(charset) ((charset)->code_offset) |
255 charset. All charsets of less than 0xA0 have the value 0. | 258 #define CHARSET_UNIFIED_P(charset) ((charset)->unified_p) |
256 | 259 |
257 ISO-FINAL-CHAR (character) is the final character of the | 260 #define CHARSET_NAME(charset) \ |
258 corresponding ISO 2022 charset. It is -1 for such a character | 261 (CHARSET_ATTR_NAME (CHARSET_ATTRIBUTES (charset))) |
259 that is used only internally (e.g. `eight-bit-control'). | 262 #define CHARSET_MAP(charset) \ |
260 | 263 (CHARSET_ATTR_MAP (CHARSET_ATTRIBUTES (charset))) |
261 ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked | 264 #define CHARSET_DECODER(charset) \ |
262 while encoding to variants of ISO 2022 coding system, one of the | 265 (CHARSET_ATTR_DECODER (CHARSET_ATTRIBUTES (charset))) |
263 following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR). It | 266 #define CHARSET_ENCODER(charset) \ |
264 is -1 for such a character that is used only internally | 267 (CHARSET_ATTR_ENCODER (CHARSET_ATTRIBUTES (charset))) |
265 (e.g. `eight-bit-control'). | 268 #define CHARSET_PARENTS(charset) \ |
266 | 269 (CHARSET_ATTR_PARENTS (CHARSET_ATTRIBUTES (charset))) |
267 REVERSE-CHARSET (integer) is the charset which differs only in | 270 #define CHARSET_UNIFY_MAP(charset) \ |
268 LEFT-TO-RIGHT value from the charset. If there's no such a | 271 (CHARSET_ATTR_UNIFY_MAP (CHARSET_ATTRIBUTES (charset))) |
269 charset, the value is -1. | 272 #define CHARSET_DEUNIFIER(charset) \ |
270 | 273 (CHARSET_ATTR_DEUNIFIER (CHARSET_ATTRIBUTES (charset))) |
271 SHORT-NAME (string) is the short name to refer to the charset. | 274 |
272 | 275 |
273 LONG-NAME (string) is the long name to refer to the charset. | 276 /* Nonzero iff OBJ is a valid charset symbol. */ |
274 | 277 #define CHARSETP(obj) (CHARSET_SYMBOL_HASH_INDEX (obj) >= 0) |
275 DESCRIPTION (string) is the description string of the charset. | 278 |
276 | 279 /* Check if X is a valid charset symbol. If not, signal an error. */ |
277 PLIST (property list) may contain any type of information a user | 280 #define CHECK_CHARSET(x) \ |
278 wants to put and get by functions `put-charset-property' and | 281 do { \ |
279 `get-charset-property' respectively. */ | 282 if (! SYMBOLP (x) || CHARSET_SYMBOL_HASH_INDEX (x) < 0) \ |
280 extern Lisp_Object Vcharset_table; | 283 x = wrong_type_argument (Qcharsetp, (x)); \ |
281 | 284 } while (0) |
282 /* Macros to access various information of CHARSET in Vcharset_table. | 285 |
283 We provide these macros for efficiency. No range check of CHARSET. */ | 286 |
284 | 287 /* Check if X is a valid charset symbol. If valid, set ID to the id |
285 /* Return entry of CHARSET (C integer) in Vcharset_table. */ | 288 number of the charset. Otherwise, signal an error. */ |
286 #define CHARSET_TABLE_ENTRY(charset) \ | 289 #define CHECK_CHARSET_GET_ID(x, id) \ |
287 XCHAR_TABLE (Vcharset_table)->contents[((charset) == CHARSET_ASCII \ | 290 do { \ |
288 ? 0 : (charset) + 128)] | 291 int idx; \ |
289 | 292 \ |
290 /* Return information INFO-IDX of CHARSET. */ | 293 if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0) \ |
291 #define CHARSET_TABLE_INFO(charset, info_idx) \ | 294 x = wrong_type_argument (Qcharsetp, (x)); \ |
292 XVECTOR (CHARSET_TABLE_ENTRY (charset))->contents[info_idx] | 295 id = AREF (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), idx), \ |
293 | 296 charset_id); \ |
294 #define CHARSET_ID_IDX (0) | 297 } while (0) |
295 #define CHARSET_BYTES_IDX (1) | 298 |
296 #define CHARSET_DIMENSION_IDX (2) | 299 |
297 #define CHARSET_CHARS_IDX (3) | 300 /* Check if X is a valid charset symbol. If valid, set ATTR to the |
298 #define CHARSET_WIDTH_IDX (4) | 301 attr vector of the charset. Otherwise, signal an error. */ |
299 #define CHARSET_DIRECTION_IDX (5) | 302 #define CHECK_CHARSET_GET_ATTR(x, attr) \ |
300 #define CHARSET_LEADING_CODE_BASE_IDX (6) | 303 do { \ |
301 #define CHARSET_LEADING_CODE_EXT_IDX (7) | 304 if (!SYMBOLP (x) || NILP (attr = CHARSET_SYMBOL_ATTRIBUTES (x))) \ |
302 #define CHARSET_ISO_FINAL_CHAR_IDX (8) | 305 x = wrong_type_argument (Qcharsetp, (x)); \ |
303 #define CHARSET_ISO_GRAPHIC_PLANE_IDX (9) | 306 } while (0) |
304 #define CHARSET_REVERSE_CHARSET_IDX (10) | 307 |
305 #define CHARSET_SHORT_NAME_IDX (11) | 308 |
306 #define CHARSET_LONG_NAME_IDX (12) | 309 #define CHECK_CHARSET_GET_CHARSET(x, charset) \ |
307 #define CHARSET_DESCRIPTION_IDX (13) | 310 do { \ |
308 #define CHARSET_PLIST_IDX (14) | 311 int id; \ |
309 /* Size of a vector of each entry of Vcharset_table. */ | 312 CHECK_CHARSET_GET_ID (x, id); \ |
310 #define CHARSET_MAX_IDX (15) | 313 charset = CHARSET_FROM_ID (id); \ |
311 | 314 } while (0) |
312 /* And several more macros to be used frequently. */ | 315 |
313 #define CHARSET_BYTES(charset) \ | 316 |
314 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX)) | 317 /* Lookup Vcharset_order_list and return the first charset that |
315 #define CHARSET_DIMENSION(charset) \ | 318 contains the character C. */ |
316 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX)) | 319 #define CHAR_CHARSET(c) \ |
317 #define CHARSET_CHARS(charset) \ | 320 char_charset ((c), Qnil, NULL) |
318 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX)) | 321 |
319 #define CHARSET_WIDTH(charset) \ | 322 #if 0 |
320 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX)) | 323 /* Char-table of charset-sets. Each element is a bool vector indexed |
321 #define CHARSET_DIRECTION(charset) \ | 324 by a charset ID. */ |
322 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX)) | 325 extern Lisp_Object Vchar_charset_set; |
323 #define CHARSET_LEADING_CODE_BASE(charset) \ | 326 |
324 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX)) | 327 /* Charset-bag of character C. */ |
325 #define CHARSET_LEADING_CODE_EXT(charset) \ | 328 #define CHAR_CHARSET_SET(c) \ |
326 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX)) | 329 CHAR_TABLE_REF (Vchar_charset_set, c) |
327 #define CHARSET_ISO_FINAL_CHAR(charset) \ | |
328 XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX)) | |
329 #define CHARSET_ISO_GRAPHIC_PLANE(charset) \ | |
330 XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX)) | |
331 #define CHARSET_REVERSE_CHARSET(charset) \ | |
332 XINT (CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX)) | |
333 | |
334 /* Macros to specify direction of a charset. */ | |
335 #define CHARSET_DIRECTION_LEFT_TO_RIGHT 0 | |
336 #define CHARSET_DIRECTION_RIGHT_TO_LEFT 1 | |
337 | |
338 /* A vector of charset symbol indexed by charset-id. This is used | |
339 only for returning charset symbol from C functions. */ | |
340 extern Lisp_Object Vcharset_symbol_table; | |
341 | |
342 /* Return symbol of CHARSET. */ | |
343 #define CHARSET_SYMBOL(charset) \ | |
344 XVECTOR (Vcharset_symbol_table)->contents[charset] | |
345 | |
346 /* 1 if CHARSET is in valid value range, else 0. */ | |
347 #define CHARSET_VALID_P(charset) \ | |
348 ((charset) == 0 \ | |
349 || ((charset) > 0x80 && (charset) <= MAX_CHARSET_OFFICIAL_DIMENSION2) \ | |
350 || ((charset) >= MIN_CHARSET_PRIVATE_DIMENSION1 \ | |
351 && (charset) <= MAX_CHARSET) \ | |
352 || ((charset) == CHARSET_8_BIT_CONTROL) \ | |
353 || ((charset) == CHARSET_8_BIT_GRAPHIC)) | |
354 | |
355 /* 1 if CHARSET is already defined, else 0. */ | |
356 #define CHARSET_DEFINED_P(charset) \ | |
357 (((charset) >= 0) && ((charset) <= MAX_CHARSET) \ | |
358 && !NILP (CHARSET_TABLE_ENTRY (charset))) | |
359 | |
360 /* Since the information CHARSET-BYTES and CHARSET-WIDTH of | |
361 Vcharset_table can be retrieved only by the first byte of | |
362 multi-byte form (an ASCII code or a base leading-code), we provide | |
363 here tables to be used by macros BYTES_BY_CHAR_HEAD and | |
364 WIDTH_BY_CHAR_HEAD for faster information retrieval. */ | |
365 extern int bytes_by_char_head[256]; | |
366 extern int width_by_char_head[256]; | |
367 | |
368 #define BYTES_BY_CHAR_HEAD(char_head) \ | |
369 (ASCII_BYTE_P (char_head) ? 1 : bytes_by_char_head[char_head]) | |
370 #define WIDTH_BY_CHAR_HEAD(char_head) \ | |
371 (ASCII_BYTE_P (char_head) ? 1 : width_by_char_head[char_head]) | |
372 | |
373 /* Charset of the character C. */ | |
374 #define CHAR_CHARSET(c) \ | |
375 (SINGLE_BYTE_CHAR_P (c) \ | |
376 ? (ASCII_BYTE_P (c) \ | |
377 ? CHARSET_ASCII \ | |
378 : (c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC) \ | |
379 : ((c) < MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
380 ? CHAR_FIELD2 (c) + 0x70 \ | |
381 : ((c) < MIN_CHAR_PRIVATE_DIMENSION2 \ | |
382 ? CHAR_FIELD1 (c) + 0x8F \ | |
383 : CHAR_FIELD1 (c) + 0xE0))) | |
384 | 330 |
385 /* Check if two characters C1 and C2 belong to the same charset. */ | 331 /* Check if two characters C1 and C2 belong to the same charset. */ |
386 #define SAME_CHARSET_P(c1, c2) \ | 332 #define SAME_CHARSET_P(c1, c2) \ |
387 (c1 < MIN_CHAR_OFFICIAL_DIMENSION2 \ | 333 intersection_p (CHAR_CHARSET_SET (c1), CHAR_CHARSET_SET (c2)) |
388 ? (c1 & CHAR_FIELD2_MASK) == (c2 & CHAR_FIELD2_MASK) \ | 334 |
389 : (c1 & CHAR_FIELD1_MASK) == (c2 & CHAR_FIELD1_MASK)) | 335 #endif |
390 | 336 |
391 /* Return a character of which charset is CHARSET and position-codes | 337 |
392 are C1 and C2. DIMENSION1 character ignores C2. */ | 338 /* Return a character correponding to the code-point CODE of CHARSET. |
393 #define MAKE_CHAR(charset, c1, c2) \ | 339 Try some optimization before calling decode_char. */ |
394 ((charset) == CHARSET_ASCII \ | 340 |
395 ? (c1) & 0x7F \ | 341 #define DECODE_CHAR(charset, code) \ |
396 : (((charset) == CHARSET_8_BIT_CONTROL \ | 342 ((ASCII_BYTE_P (code) && (charset)->ascii_compatible_p) \ |
397 || (charset) == CHARSET_8_BIT_GRAPHIC) \ | 343 ? (code) \ |
398 ? ((c1) & 0x7F) | 0x80 \ | 344 : ((code) < (charset)->min_code || (code) > (charset)->max_code) \ |
399 : ((CHARSET_DEFINED_P (charset) \ | 345 ? -1 \ |
400 ? CHARSET_DIMENSION (charset) == 1 \ | 346 : (charset)->unified_p \ |
401 : (charset) < MIN_CHARSET_PRIVATE_DIMENSION2) \ | 347 ? decode_char ((charset), (code)) \ |
402 ? (((charset) - 0x70) << 7) | ((c1) <= 0 ? 0 : ((c1) & 0x7F)) \ | 348 : (charset)->method == CHARSET_METHOD_OFFSET \ |
403 : ((((charset) \ | 349 ? ((charset)->code_linear_p \ |
404 - ((charset) < MIN_CHARSET_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)) \ | 350 ? (code) - (charset)->min_code + (charset)->code_offset \ |
405 << 14) \ | 351 : decode_char ((charset), (code))) \ |
406 | ((c2) <= 0 ? 0 : ((c2) & 0x7F)) \ | 352 : (charset)->method == CHARSET_METHOD_MAP \ |
407 | ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7)))))) | 353 ? ((charset)->code_linear_p \ |
408 | 354 ? XINT (AREF (CHARSET_DECODER (charset), \ |
409 | 355 (code) - (charset)->min_code)) \ |
410 /* If GENERICP is nonzero, return nonzero iff C is a valid normal or | 356 : decode_char ((charset), (code))) \ |
411 generic character. If GENERICP is zero, return nonzero iff C is a | 357 : decode_char ((charset), (code))) |
412 valid normal character. */ | 358 |
413 #define CHAR_VALID_P(c, genericp) \ | 359 |
414 ((c) >= 0 \ | 360 /* Return a code point of CHAR in CHARSET. |
415 && (SINGLE_BYTE_CHAR_P (c) || char_valid_p (c, genericp))) | 361 Try some optimization before calling encode_char. */ |
416 | 362 |
417 /* This default value is used when nonascii-translation-table or | 363 #define ENCODE_CHAR(charset, c) \ |
418 nonascii-insert-offset fail to convert unibyte character to a valid | 364 ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ |
419 multibyte character. This makes a Latin-1 character. */ | 365 ? (c) \ |
420 | 366 : (charset)->unified_p \ |
421 #define DEFAULT_NONASCII_INSERT_OFFSET 0x800 | 367 ? encode_char ((charset), (c)) \ |
422 | 368 : ((c) < (charset)->min_char || (c) > (charset)->max_char) \ |
423 /* Parse multibyte string STR of length LENGTH and set BYTES to the | 369 ? (charset)->invalid_code \ |
424 byte length of a character at STR. */ | 370 : (charset)->method == CHARSET_METHOD_OFFSET \ |
425 | 371 ? ((charset)->code_linear_p \ |
426 #ifdef BYTE_COMBINING_DEBUG | 372 ? (c) - (charset)->code_offset + (charset)->min_code \ |
427 | 373 : encode_char ((charset), (c))) \ |
428 #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ | 374 : (charset)->method == CHARSET_METHOD_MAP \ |
375 ? ((charset)->compact_codes_p \ | |
376 ? XFASTINT (CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c))) \ | |
377 : encode_char ((charset), (c))) \ | |
378 : encode_char ((charset), (c))) | |
379 | |
380 | |
381 /* Set to 1 when a charset map is loaded to warn that a buffer text | |
382 and a string data may be relocated. */ | |
383 extern int charset_map_loaded; | |
384 | |
385 | |
386 /* Set CHARSET to the charset highest priority of C, CODE to the | |
387 code-point of C in CHARSET. */ | |
388 #define SPLIT_CHAR(c, charset, code) \ | |
389 ((charset) = char_charset ((c), Qnil, &(code))) | |
390 | |
391 | |
392 #define ISO_MAX_DIMENSION 3 | |
393 #define ISO_MAX_CHARS 2 | |
394 #define ISO_MAX_FINAL 0x80 /* only 0x30..0xFF are used */ | |
395 | |
396 /* Mapping table from ISO2022's charset (specified by DIMENSION, | |
397 CHARS, and FINAL_CHAR) to Emacs' charset ID. Should be accessed by | |
398 macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR). */ | |
399 extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL]; | |
400 | |
401 /* A charset of type iso2022 who has DIMENSION, CHARS, and FINAL | |
402 (final character). */ | |
403 #define ISO_CHARSET_TABLE(dimension, chars_96, final) \ | |
404 iso_charset_table[(dimension) - 1][(chars_96)][(final)] | |
405 | |
406 /* Nonzero iff the charset who has FAST_MAP may contain C. */ | |
407 #define CHARSET_FAST_MAP_REF(c, fast_map) \ | |
408 ((c) < 0x10000 \ | |
409 ? fast_map[(c) >> 10] & (1 << (((c) >> 7) & 7)) \ | |
410 : fast_map[((c) >> 15) + 62] & (1 << (((c) >> 12) & 7))) | |
411 | |
412 #define CHARSET_FAST_MAP_SET(c, fast_map) \ | |
429 do { \ | 413 do { \ |
430 int i = 1; \ | 414 if ((c) < 0x10000) \ |
431 while (i < (length) && ! CHAR_HEAD_P ((str)[i])) i++; \ | 415 (fast_map)[(c) >> 10] |= 1 << (((c) >> 7) & 7); \ |
432 (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]); \ | 416 else \ |
433 if ((bytes) > i) \ | 417 (fast_map)[((c) >> 15) + 62] |= 1 << (((c) >> 12) & 7); \ |
434 abort (); \ | |
435 } while (0) | 418 } while (0) |
436 | 419 |
437 #else /* not BYTE_COMBINING_DEBUG */ | 420 |
438 | 421 |
439 #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ | 422 /* 1 iff CHARSET may contain the character C. */ |
440 (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]) | 423 #define CHAR_CHARSET_P(c, charset) \ |
441 | 424 ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ |
442 #endif /* not BYTE_COMBINING_DEBUG */ | 425 || (CHARSET_UNIFIED_P (charset) \ |
443 | 426 ? encode_char ((charset), (c)) != (charset)->invalid_code \ |
444 /* Return 1 iff the byte sequence at unibyte string STR (LENGTH bytes) | 427 : (CHARSET_FAST_MAP_REF ((c), (charset)->fast_map) \ |
445 is valid as a multibyte form. If valid, by a side effect, BYTES is | 428 && ((charset)->method == CHARSET_METHOD_OFFSET \ |
446 set to the byte length of the multibyte form. */ | 429 ? (c) >= (charset)->min_char && (c) <= (charset)->max_char \ |
447 | 430 : ((charset)->method == CHARSET_METHOD_MAP \ |
448 #define UNIBYTE_STR_AS_MULTIBYTE_P(str, length, bytes) \ | 431 && (charset)->compact_codes_p) \ |
449 (((str)[0] < 0x80 || (str)[0] >= 0xA0) \ | 432 ? (XFASTINT (CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c))) \ |
450 ? ((bytes) = 1) \ | 433 != (charset)->invalid_code) \ |
451 : (((bytes) = BYTES_BY_CHAR_HEAD ((str)[0])), \ | 434 : encode_char ((charset), (c)) != (charset)->invalid_code)))) |
452 ((bytes) > 1 && (bytes) <= (length) \ | 435 |
453 && (str)[0] != LEADING_CODE_8_BIT_CONTROL \ | 436 |
454 && !CHAR_HEAD_P ((str)[1]) \ | 437 extern Lisp_Object Qcharsetp; |
455 && ((bytes) == 2 \ | 438 |
456 || (!CHAR_HEAD_P ((str)[2]) \ | 439 extern Lisp_Object Qascii, Qunicode; |
457 && ((bytes) == 3 \ | 440 extern int charset_ascii, charset_8_bit_control, charset_8_bit_graphic; |
458 || !CHAR_HEAD_P ((str)[3]))))))) | 441 extern int charset_iso_8859_1; |
459 | 442 extern int charset_primary; |
460 /* Return 1 iff the byte sequence at multibyte string STR is valid as | 443 |
461 a unibyte form. By a side effect, BYTES is set to the byte length | 444 extern struct charset *char_charset P_ ((int, Lisp_Object, unsigned *)); |
462 of one character at STR. */ | 445 extern Lisp_Object charset_attributes P_ ((int)); |
463 | 446 |
464 #define MULTIBYTE_STR_AS_UNIBYTE_P(str, bytes) \ | 447 extern int decode_char P_ ((struct charset *, unsigned)); |
465 ((bytes) = BYTES_BY_CHAR_HEAD ((str)[0]), \ | 448 extern unsigned encode_char P_ ((struct charset *, int)); |
466 (str)[0] != LEADING_CODE_8_BIT_CONTROL) | 449 extern int string_xstring_p P_ ((Lisp_Object)); |
467 | 450 |
468 /* The charset of character C is stored in CHARSET, and the | 451 EXFUN (Funify_charset, 2); |
469 position-codes of C are stored in C1 and C2. | |
470 We store -1 in C2 if the dimension of the charset is 1. */ | |
471 | |
472 #define SPLIT_CHAR(c, charset, c1, c2) \ | |
473 (SINGLE_BYTE_CHAR_P (c) \ | |
474 ? ((charset \ | |
475 = (ASCII_BYTE_P (c) \ | |
476 ? CHARSET_ASCII \ | |
477 : ((c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC))), \ | |
478 c1 = (c), c2 = -1) \ | |
479 : ((c) & CHAR_FIELD1_MASK \ | |
480 ? (charset = (CHAR_FIELD1 (c) \ | |
481 + ((c) < MIN_CHAR_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)), \ | |
482 c1 = CHAR_FIELD2 (c), \ | |
483 c2 = CHAR_FIELD3 (c)) \ | |
484 : (charset = CHAR_FIELD2 (c) + 0x70, \ | |
485 c1 = CHAR_FIELD3 (c), \ | |
486 c2 = -1))) | |
487 | |
488 /* Return 1 iff character C has valid printable glyph. */ | |
489 #define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c)) | |
490 | |
491 /* The charset of the character at STR is stored in CHARSET, and the | |
492 position-codes are stored in C1 and C2. | |
493 We store -1 in C2 if the character is just 2 bytes. */ | |
494 | |
495 #define SPLIT_STRING(str, len, charset, c1, c2) \ | |
496 ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) < 2 \ | |
497 || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > len \ | |
498 || split_string (str, len, &charset, &c1, &c2) < 0) \ | |
499 ? c1 = *(str), charset = CHARSET_ASCII \ | |
500 : charset) | |
501 | |
502 /* Mapping table from ISO2022's charset (specified by DIMENSION, | |
503 CHARS, and FINAL_CHAR) to Emacs' charset. Should be accessed by | |
504 macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR). */ | |
505 extern int iso_charset_table[2][2][128]; | |
506 | |
507 #define ISO_CHARSET_TABLE(dimension, chars, final_char) \ | |
508 iso_charset_table[XINT (dimension) - 1][XINT (chars) > 94][XINT (final_char)] | |
509 | |
510 #define BASE_LEADING_CODE_P(c) (BYTES_BY_CHAR_HEAD ((unsigned char) (c)) > 1) | |
511 | |
512 /* Return how many bytes C will occupy in a multibyte buffer. */ | |
513 #define CHAR_BYTES(c) \ | |
514 (SINGLE_BYTE_CHAR_P (c) \ | |
515 ? ((ASCII_BYTE_P (c) || (c) >= 0xA0) ? 1 : 2) \ | |
516 : char_bytes (c)) | |
517 | |
518 /* The following two macros CHAR_STRING and STRING_CHAR are the main | |
519 entry points to convert between Emacs's two types of character | |
520 representations: multi-byte form and single-word form (character | |
521 code). */ | |
522 | |
523 /* Store multi-byte form of the character C in STR. The caller should | |
524 allocate at least MAX_MULTIBYTE_LENGTH bytes area at STR in | |
525 advance. Returns the length of the multi-byte form. If C is an | |
526 invalid character code, signal an error. */ | |
527 | |
528 #define CHAR_STRING(c, str) \ | |
529 (SINGLE_BYTE_CHAR_P (c) \ | |
530 ? ((ASCII_BYTE_P (c) || c >= 0xA0) \ | |
531 ? (*(str) = (unsigned char)(c), 1) \ | |
532 : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \ | |
533 : char_to_string (c, (unsigned char *) str)) | |
534 | |
535 /* Like CHAR_STRING but don't signal an error if C is invalid. | |
536 Value is -1 in this case. */ | |
537 | |
538 #define CHAR_STRING_NO_SIGNAL(c, str) \ | |
539 (SINGLE_BYTE_CHAR_P (c) \ | |
540 ? ((ASCII_BYTE_P (c) || c >= 0xA0) \ | |
541 ? (*(str) = (unsigned char)(c), 1) \ | |
542 : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \ | |
543 : char_to_string_1 (c, (unsigned char *) str)) | |
544 | |
545 /* Return a character code of the character of which multi-byte form | |
546 is at STR and the length is LEN. If STR doesn't contain valid | |
547 multi-byte form, only the first byte in STR is returned. */ | |
548 | |
549 #define STRING_CHAR(str, len) \ | |
550 (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1 \ | |
551 ? (unsigned char) *(str) \ | |
552 : string_to_char (str, len, 0)) | |
553 | |
554 /* This is like STRING_CHAR but the third arg ACTUAL_LEN is set to the | |
555 length of the multi-byte form. Just to know the length, use | |
556 MULTIBYTE_FORM_LENGTH. */ | |
557 | |
558 #define STRING_CHAR_AND_LENGTH(str, len, actual_len) \ | |
559 (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1 \ | |
560 ? ((actual_len) = 1), (unsigned char) *(str) \ | |
561 : string_to_char (str, len, &(actual_len))) | |
562 | |
563 /* Fetch the "next" character from Lisp string STRING at byte position | |
564 BYTEIDX, character position CHARIDX. Store it into OUTPUT. | |
565 | |
566 All the args must be side-effect-free. | |
567 BYTEIDX and CHARIDX must be lvalues; | |
568 we increment them past the character fetched. */ | |
569 | |
570 #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
571 if (1) \ | |
572 { \ | |
573 CHARIDX++; \ | |
574 if (STRING_MULTIBYTE (STRING)) \ | |
575 { \ | |
576 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
577 int space_left = XSTRING (STRING)->size_byte - BYTEIDX; \ | |
578 int actual_len; \ | |
579 \ | |
580 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len); \ | |
581 BYTEIDX += actual_len; \ | |
582 } \ | |
583 else \ | |
584 OUTPUT = XSTRING (STRING)->data[BYTEIDX++]; \ | |
585 } \ | |
586 else | |
587 | |
588 /* Like FETCH_STRING_CHAR_ADVANCE but assume STRING is multibyte. */ | |
589 | |
590 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
591 if (1) \ | |
592 { \ | |
593 unsigned char *fetch_string_char_ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
594 int fetch_string_char_space_left = XSTRING (STRING)->size_byte - BYTEIDX; \ | |
595 int actual_len; \ | |
596 \ | |
597 OUTPUT \ | |
598 = STRING_CHAR_AND_LENGTH (fetch_string_char_ptr, \ | |
599 fetch_string_char_space_left, actual_len); \ | |
600 \ | |
601 BYTEIDX += actual_len; \ | |
602 CHARIDX++; \ | |
603 } \ | |
604 else | |
605 | |
606 /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current | |
607 buffer. */ | |
608 | |
609 #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX) \ | |
610 if (1) \ | |
611 { \ | |
612 CHARIDX++; \ | |
613 if (!NILP (current_buffer->enable_multibyte_characters)) \ | |
614 { \ | |
615 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
616 int space_left = ((CHARIDX < GPT ? GPT_BYTE : Z_BYTE) - BYTEIDX); \ | |
617 int actual_len; \ | |
618 \ | |
619 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len); \ | |
620 BYTEIDX += actual_len; \ | |
621 } \ | |
622 else \ | |
623 { \ | |
624 OUTPUT = *(BYTE_POS_ADDR (BYTEIDX)); \ | |
625 BYTEIDX++; \ | |
626 } \ | |
627 } \ | |
628 else | |
629 | |
630 /* Return the length of the multi-byte form at string STR of length LEN. */ | |
631 | |
632 #define MULTIBYTE_FORM_LENGTH(str, len) \ | |
633 (BYTES_BY_CHAR_HEAD (*(unsigned char *)(str)) == 1 \ | |
634 ? 1 \ | |
635 : multibyte_form_length (str, len)) | |
636 | |
637 #ifdef emacs | |
638 | |
639 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
640 the next character boundary. This macro relies on the fact that | |
641 *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
642 '\0'. No range checking of POS. */ | |
643 | |
644 #ifdef BYTE_COMBINING_DEBUG | |
645 | |
646 #define INC_POS(pos_byte) \ | |
647 do { \ | |
648 unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
649 if (BASE_LEADING_CODE_P (*p)) \ | |
650 { \ | |
651 int len, bytes; \ | |
652 len = Z_BYTE - pos_byte; \ | |
653 PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
654 pos_byte += bytes; \ | |
655 } \ | |
656 else \ | |
657 pos_byte++; \ | |
658 } while (0) | |
659 | |
660 #else /* not BYTE_COMBINING_DEBUG */ | |
661 | |
662 #define INC_POS(pos_byte) \ | |
663 do { \ | |
664 unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
665 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
666 } while (0) | |
667 | |
668 #endif /* not BYTE_COMBINING_DEBUG */ | |
669 | |
670 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
671 the previous character boundary. No range checking of POS. */ | |
672 #define DEC_POS(pos_byte) \ | |
673 do { \ | |
674 unsigned char *p, *p_min; \ | |
675 \ | |
676 pos_byte--; \ | |
677 if (pos_byte < GPT_BYTE) \ | |
678 p = BEG_ADDR + pos_byte - 1, p_min = BEG_ADDR; \ | |
679 else \ | |
680 p = BEG_ADDR + GAP_SIZE + pos_byte - 1, p_min = GAP_END_ADDR; \ | |
681 if (p > p_min && !CHAR_HEAD_P (*p)) \ | |
682 { \ | |
683 unsigned char *pend = p--; \ | |
684 int len, bytes; \ | |
685 while (p > p_min && !CHAR_HEAD_P (*p)) p--; \ | |
686 len = pend + 1 - p; \ | |
687 PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
688 if (bytes == len) \ | |
689 pos_byte -= len - 1; \ | |
690 } \ | |
691 } while (0) | |
692 | |
693 /* Increment both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
694 | |
695 #define INC_BOTH(charpos, bytepos) \ | |
696 do \ | |
697 { \ | |
698 (charpos)++; \ | |
699 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
700 (bytepos)++; \ | |
701 else \ | |
702 INC_POS ((bytepos)); \ | |
703 } \ | |
704 while (0) | |
705 | |
706 /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
707 | |
708 #define DEC_BOTH(charpos, bytepos) \ | |
709 do \ | |
710 { \ | |
711 (charpos)--; \ | |
712 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
713 (bytepos)--; \ | |
714 else \ | |
715 DEC_POS ((bytepos)); \ | |
716 } \ | |
717 while (0) | |
718 | |
719 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
720 the next character boundary. This macro relies on the fact that | |
721 *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
722 '\0'. No range checking of POS_BYTE. */ | |
723 | |
724 #ifdef BYTE_COMBINING_DEBUG | |
725 | |
726 #define BUF_INC_POS(buf, pos_byte) \ | |
727 do { \ | |
728 unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
729 if (BASE_LEADING_CODE_P (*p)) \ | |
730 { \ | |
731 int len, bytes; \ | |
732 len = BUF_Z_BYTE (buf) - pos_byte; \ | |
733 PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
734 pos_byte += bytes; \ | |
735 } \ | |
736 else \ | |
737 pos_byte++; \ | |
738 } while (0) | |
739 | |
740 #else /* not BYTE_COMBINING_DEBUG */ | |
741 | |
742 #define BUF_INC_POS(buf, pos_byte) \ | |
743 do { \ | |
744 unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
745 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
746 } while (0) | |
747 | |
748 #endif /* not BYTE_COMBINING_DEBUG */ | |
749 | |
750 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
751 the previous character boundary. No range checking of POS_BYTE. */ | |
752 #define BUF_DEC_POS(buf, pos_byte) \ | |
753 do { \ | |
754 unsigned char *p, *p_min; \ | |
755 pos_byte--; \ | |
756 if (pos_byte < BUF_GPT_BYTE (buf)) \ | |
757 { \ | |
758 p = BUF_BEG_ADDR (buf) + pos_byte - 1; \ | |
759 p_min = BUF_BEG_ADDR (buf); \ | |
760 } \ | |
761 else \ | |
762 { \ | |
763 p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - 1; \ | |
764 p_min = BUF_GAP_END_ADDR (buf); \ | |
765 } \ | |
766 if (p > p_min && !CHAR_HEAD_P (*p)) \ | |
767 { \ | |
768 unsigned char *pend = p--; \ | |
769 int len, bytes; \ | |
770 while (p > p_min && !CHAR_HEAD_P (*p)) p--; \ | |
771 len = pend + 1 - p; \ | |
772 PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
773 if (bytes == len) \ | |
774 pos_byte -= len - 1; \ | |
775 } \ | |
776 } while (0) | |
777 | |
778 #endif /* emacs */ | |
779 | |
780 /* This is the maximum byte length of multi-byte sequence. */ | |
781 #define MAX_MULTIBYTE_LENGTH 4 | |
782 | |
783 extern void invalid_character P_ ((int)); | |
784 | |
785 extern int translate_char P_ ((Lisp_Object, int, int, int, int)); | |
786 extern int split_string P_ ((const unsigned char *, int, int *, | |
787 unsigned char *, unsigned char *)); | |
788 extern int char_to_string P_ ((int, unsigned char *)); | |
789 extern int char_to_string_1 P_ ((int, unsigned char *)); | |
790 extern int string_to_char P_ ((const unsigned char *, int, int *)); | |
791 extern int char_printable_p P_ ((int c)); | |
792 extern int multibyte_form_length P_ ((const unsigned char *, int)); | |
793 extern void parse_str_as_multibyte P_ ((unsigned char *, int, int *, int *)); | |
794 extern int str_as_multibyte P_ ((unsigned char *, int, int, int *)); | |
795 extern int parse_str_to_multibyte P_ ((unsigned char *, int)); | |
796 extern int str_to_multibyte P_ ((unsigned char *, int, int)); | |
797 extern int str_as_unibyte P_ ((unsigned char *, int)); | |
798 extern int get_charset_id P_ ((Lisp_Object)); | |
799 extern int find_charset_in_text P_ ((unsigned char *, int, int, int *, | |
800 Lisp_Object)); | |
801 extern int strwidth P_ ((unsigned char *, int)); | |
802 extern int c_string_width P_ ((unsigned char *, int, int, int *, int *)); | |
803 extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *)); | |
804 extern int char_bytes P_ ((int)); | |
805 extern int char_valid_p P_ ((int, int)); | |
806 | |
807 extern Lisp_Object Vtranslation_table_vector; | |
808 | |
809 /* Return a translation table of id number ID. */ | |
810 #define GET_TRANSLATION_TABLE(id) \ | |
811 (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)])) | |
812 | |
813 /* A char-table for characters which may invoke auto-filling. */ | |
814 extern Lisp_Object Vauto_fill_chars; | |
815 | |
816 /* Copy LEN bytes from FROM to TO. This macro should be used only | |
817 when a caller knows that LEN is short and the obvious copy loop is | |
818 faster than calling bcopy which has some overhead. Copying a | |
819 multibyte sequence of a multibyte character is the typical case. */ | |
820 | |
821 #define BCOPY_SHORT(from, to, len) \ | |
822 do { \ | |
823 int i = len; \ | |
824 unsigned char *from_p = from, *to_p = to; \ | |
825 while (i--) *to_p++ = *from_p++; \ | |
826 } while (0) | |
827 | 452 |
828 #endif /* EMACS_CHARSET_H */ | 453 #endif /* EMACS_CHARSET_H */ |