Commit | Line | Data |
---|---|---|
3263d5a2 | 1 | /* Header for charset handler. |
73b0cd50 | 2 | Copyright (C) 2001-2011 Free Software Foundation, Inc. |
7976eda0 | 3 | Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
5df4f04c | 4 | 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
ce03bf76 KH |
5 | National Institute of Advanced Industrial Science and Technology (AIST) |
6 | Registration Number H14PRO021 | |
4ed46869 | 7 | |
8f924df7 | 8 | Copyright (C) 2003 |
3263d5a2 KH |
9 | National Institute of Advanced Industrial Science and Technology (AIST) |
10 | Registration Number H13PRO009 | |
4ed46869 | 11 | |
369314dc KH |
12 | This file is part of GNU Emacs. |
13 | ||
b9b1cc14 | 14 | GNU Emacs is free software: you can redistribute it and/or modify |
369314dc | 15 | it under the terms of the GNU General Public License as published by |
b9b1cc14 GM |
16 | the Free Software Foundation, either version 3 of the License, or |
17 | (at your option) any later version. | |
4ed46869 | 18 | |
369314dc KH |
19 | GNU Emacs is distributed in the hope that it will be useful, |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | GNU General Public License for more details. | |
4ed46869 | 23 | |
369314dc | 24 | You should have received a copy of the GNU General Public License |
b9b1cc14 | 25 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
4ed46869 | 26 | |
aa01a892 KH |
27 | #ifndef EMACS_CHARSET_H |
28 | #define EMACS_CHARSET_H | |
4ed46869 | 29 | |
34206dd2 PE |
30 | #include <verify.h> |
31 | ||
3263d5a2 KH |
32 | /* Index to arguments of Fdefine_charset_internal. */ |
33 | ||
34 | enum define_charset_arg_index | |
35 | { | |
36 | charset_arg_name, | |
37 | charset_arg_dimension, | |
38 | charset_arg_code_space, | |
315c0139 KH |
39 | charset_arg_min_code, |
40 | charset_arg_max_code, | |
3263d5a2 KH |
41 | charset_arg_iso_final, |
42 | charset_arg_iso_revision, | |
43 | charset_arg_emacs_mule_id, | |
44 | charset_arg_ascii_compatible_p, | |
45 | charset_arg_supplementary_p, | |
46 | charset_arg_invalid_code, | |
47 | charset_arg_code_offset, | |
48 | charset_arg_map, | |
ec7dd615 KH |
49 | charset_arg_subset, |
50 | charset_arg_superset, | |
3263d5a2 KH |
51 | charset_arg_unify_map, |
52 | charset_arg_plist, | |
53 | charset_arg_max | |
54 | }; | |
55 | ||
56 | ||
57 | /* Indices to charset attributes vector. */ | |
58 | ||
59 | enum charset_attr_index | |
60 | { | |
61 | /* ID number of the charset. */ | |
62 | charset_id, | |
4ed46869 | 63 | |
3263d5a2 KH |
64 | /* Name of the charset (symbol). */ |
65 | charset_name, | |
66 | ||
67 | /* Property list of the charset. */ | |
68 | charset_plist, | |
69 | ||
2bc20f0b KH |
70 | /* If the method of the charset is `MAP', the value is a mapping |
71 | vector or a file name that contains mapping vector. Otherwise, | |
72 | nil. */ | |
3263d5a2 KH |
73 | charset_map, |
74 | ||
75 | /* If the method of the charset is `MAP', the value is a vector | |
76 | that maps code points of the charset to characters. The vector | |
77 | is indexed by a character index. A character index is | |
78 | calculated from a code point and the code-space table of the | |
79 | charset. */ | |
80 | charset_decoder, | |
81 | ||
82 | /* If the method of the charset is `MAP', the value is a | |
83 | char-table that maps characters of the charset to code | |
84 | points. */ | |
85 | charset_encoder, | |
86 | ||
ec7dd615 KH |
87 | /* If the method of the charset is `SUBSET', the value is a vector |
88 | that has this form: | |
89 | ||
90 | [ CHARSET-ID MIN-CODE MAX-CODE OFFSET ] | |
91 | ||
92 | CHARSET-ID is an ID number of a parent charset. MIN-CODE and | |
93 | MAX-CODE specify the range of characters inherited from the | |
94 | parent. OFFSET is an integer value to add to a code point of | |
95 | the parent charset to get the corresponding code point of this | |
96 | charset. */ | |
97 | charset_subset, | |
98 | ||
99 | /* If the method of the charset is `SUPERSET', the value is a list | |
100 | whose elements have this form: | |
101 | ||
102 | (CHARSET-ID . OFFSET) | |
103 | ||
924b41ee JB |
104 | CHARSET-IDs are ID numbers of parent charsets. OFFSET is an |
105 | integer value to add to a code point of the parent charset to | |
106 | get the corresponding code point of this charset. */ | |
ec7dd615 | 107 | charset_superset, |
3263d5a2 | 108 | |
7619dee9 DL |
109 | /* The value is a mapping vector or a file name that contains the |
110 | mapping. This defines how characters in the charset should be | |
111 | unified with Unicode. The value of the member | |
3e4abc9e | 112 | `charset_deunifier' is created from this information. */ |
3263d5a2 KH |
113 | charset_unify_map, |
114 | ||
3e4abc9e | 115 | /* If characters in the charset must be unified Unicode, the value |
1c305bc1 KH |
116 | is a char table that maps a unified Unicode character code to |
117 | the non-unified character code in the charset. */ | |
3263d5a2 KH |
118 | charset_deunifier, |
119 | ||
7619dee9 | 120 | /* The length of the charset attribute vector. */ |
3263d5a2 KH |
121 | charset_attr_max |
122 | }; | |
123 | ||
124 | /* Methods for converting code points and characters of charsets. */ | |
125 | ||
126 | enum charset_method | |
127 | { | |
128 | /* For a charset of this method, a character code is calculated | |
129 | from a character index (which is calculated from a code point) | |
130 | simply by adding an offset value. */ | |
131 | CHARSET_METHOD_OFFSET, | |
132 | ||
133 | /* For a charset of this method, a decoder vector and an encoder | |
134 | char-table is used for code point <-> character code | |
135 | conversion. */ | |
136 | CHARSET_METHOD_MAP, | |
137 | ||
7619dee9 | 138 | /* A charset of this method is a subset of another charset. */ |
ec7dd615 KH |
139 | CHARSET_METHOD_SUBSET, |
140 | ||
7619dee9 | 141 | /* A charset of this method is a superset of other charsets. */ |
ec7dd615 | 142 | CHARSET_METHOD_SUPERSET |
3263d5a2 KH |
143 | }; |
144 | ||
145 | struct charset | |
146 | { | |
3e4abc9e | 147 | /* Index to charset_table. */ |
3263d5a2 | 148 | int id; |
4ed46869 | 149 | |
3e4abc9e | 150 | /* Index to Vcharset_hash_table. */ |
0de4bb68 | 151 | EMACS_INT hash_index; |
3263d5a2 KH |
152 | |
153 | /* Dimension of the charset: 1, 2, 3, or 4. */ | |
154 | int dimension; | |
155 | ||
ac6a8028 KH |
156 | /* Byte code range of each dimension. <code_space>[4N] is a mininum |
157 | byte code of the (N+1)th dimension, <code_space>[4N+1] is a | |
158 | maximum byte code of the (N+1)th dimension, <code_space>[4N+2] is | |
159 | (<code_space>[4N+1] - <code_space>[4N] + 1), <code_space>[4N+3] | |
c032b5f8 PE |
160 | is the number of characters contained in the first through (N+1)th |
161 | dimensions, except that there is no <code_space>[15]. | |
162 | We get `char-index' of a `code-point' from this | |
ac6a8028 | 163 | information. */ |
c032b5f8 | 164 | int code_space[15]; |
54e15bb9 | 165 | |
ac6a8028 KH |
166 | /* If B is a byte of Nth dimension of a code-point, the (N-1)th bit |
167 | of code_space_mask[B] is set. This array is used to quickly | |
168 | check if a code-point is in a valid range. */ | |
169 | unsigned char *code_space_mask; | |
d3985b78 | 170 | |
3263d5a2 KH |
171 | /* 1 if there's no gap in code-points. */ |
172 | int code_linear_p; | |
d3985b78 | 173 | |
3263d5a2 KH |
174 | /* If the charset is treated as 94-chars in ISO-2022, the value is 0. |
175 | If the charset is treated as 96-chars in ISO-2022, the value is 1. */ | |
176 | int iso_chars_96; | |
d3985b78 | 177 | |
3e4abc9e KH |
178 | /* ISO final byte of the charset: 48..127. It may be -1 if the |
179 | charset doesn't conform to ISO-2022. */ | |
3263d5a2 | 180 | int iso_final; |
d3985b78 | 181 | |
3e4abc9e | 182 | /* ISO revision number of the charset. */ |
3263d5a2 | 183 | int iso_revision; |
d3985b78 | 184 | |
3263d5a2 KH |
185 | /* If the charset is identical to what supported by Emacs 21 and the |
186 | priors, the identification number of the charset used in those | |
187 | version. Otherwise, -1. */ | |
188 | int emacs_mule_id; | |
189 | ||
b2e6b10f | 190 | /* Nonzero if the charset is compatible with ASCII. */ |
3263d5a2 | 191 | int ascii_compatible_p; |
4ed46869 | 192 | |
b2e6b10f | 193 | /* Nonzero if the charset is supplementary. */ |
3263d5a2 KH |
194 | int supplementary_p; |
195 | ||
b2e6b10f | 196 | /* Nonzero if all the code points are representable by Lisp_Int. */ |
3263d5a2 KH |
197 | int compact_codes_p; |
198 | ||
199 | /* The method for encoding/decoding characters of the charset. */ | |
200 | enum charset_method method; | |
201 | ||
202 | /* Mininum and Maximum code points of the charset. */ | |
203 | unsigned min_code, max_code; | |
204 | ||
315c0139 KH |
205 | /* Offset value used by macros CODE_POINT_TO_INDEX and |
206 | INDEX_TO_CODE_POINT. . */ | |
207 | unsigned char_index_offset; | |
208 | ||
3263d5a2 KH |
209 | /* Mininum and Maximum character codes of the charset. If the |
210 | charset is compatible with ASCII, min_char is a minimum non-ASCII | |
39d992af KH |
211 | character of the charset. If the method of charset is |
212 | CHARSET_METHOD_OFFSET, even if the charset is unified, min_char | |
213 | and max_char doesn't change. */ | |
3263d5a2 KH |
214 | int min_char, max_char; |
215 | ||
216 | /* The code returned by ENCODE_CHAR if a character is not encodable | |
217 | by the charset. */ | |
218 | unsigned invalid_code; | |
219 | ||
220 | /* If the method of the charset is CHARSET_METHOD_MAP, this is a | |
221 | table of bits used to quickly and roughly guess if a character | |
222 | belongs to the charset. | |
223 | ||
224 | The first 64 elements are 512 bits for characters less than | |
225 | 0x10000. Each bit corresponds to 128-character block. The last | |
226 | 126 elements are 1008 bits for the greater characters | |
227 | (0x10000..0x3FFFFF). Each bit corresponds to 4096-character | |
228 | block. | |
229 | ||
7619dee9 | 230 | If a bit is 1, at least one character in the corresponding block is |
3263d5a2 KH |
231 | in this charset. */ |
232 | unsigned char fast_map[190]; | |
233 | ||
234 | /* Offset value to calculate a character code from code-point, and | |
235 | visa versa. */ | |
236 | int code_offset; | |
237 | ||
238 | int unified_p; | |
239 | }; | |
240 | ||
241 | /* Hash table of charset symbols vs. the correponding attribute | |
242 | vectors. */ | |
243 | extern Lisp_Object Vcharset_hash_table; | |
244 | ||
245 | /* Table of struct charset. */ | |
246 | extern struct charset *charset_table; | |
3263d5a2 KH |
247 | |
248 | #define CHARSET_FROM_ID(id) (charset_table + (id)) | |
249 | ||
39d992af | 250 | extern Lisp_Object Vcharset_ordered_list; |
370cefff | 251 | extern Lisp_Object Vcharset_non_preferred_head; |
39d992af KH |
252 | |
253 | /* Incremented everytime we change the priority of charsets. */ | |
a0b31951 | 254 | extern unsigned short charset_ordered_list_tick; |
39d992af | 255 | |
3263d5a2 KH |
256 | extern Lisp_Object Viso_2022_charset_list; |
257 | extern Lisp_Object Vemacs_mule_charset_list; | |
258 | ||
b84ae584 | 259 | extern int emacs_mule_charset[256]; |
3263d5a2 | 260 | |
3263d5a2 KH |
261 | /* Macros to access information about charset. */ |
262 | ||
263 | /* Return the attribute vector of charset whose symbol is SYMBOL. */ | |
264 | #define CHARSET_SYMBOL_ATTRIBUTES(symbol) \ | |
265 | Fgethash ((symbol), Vcharset_hash_table, Qnil) | |
266 | ||
267 | #define CHARSET_ATTR_ID(attrs) AREF ((attrs), charset_id) | |
268 | #define CHARSET_ATTR_NAME(attrs) AREF ((attrs), charset_name) | |
269 | #define CHARSET_ATTR_PLIST(attrs) AREF ((attrs), charset_plist) | |
270 | #define CHARSET_ATTR_MAP(attrs) AREF ((attrs), charset_map) | |
271 | #define CHARSET_ATTR_DECODER(attrs) AREF ((attrs), charset_decoder) | |
272 | #define CHARSET_ATTR_ENCODER(attrs) AREF ((attrs), charset_encoder) | |
ec7dd615 KH |
273 | #define CHARSET_ATTR_SUBSET(attrs) AREF ((attrs), charset_subset) |
274 | #define CHARSET_ATTR_SUPERSET(attrs) AREF ((attrs), charset_superset) | |
3263d5a2 KH |
275 | #define CHARSET_ATTR_UNIFY_MAP(attrs) AREF ((attrs), charset_unify_map) |
276 | #define CHARSET_ATTR_DEUNIFIER(attrs) AREF ((attrs), charset_deunifier) | |
277 | ||
278 | #define CHARSET_SYMBOL_ID(symbol) \ | |
279 | CHARSET_ATTR_ID (CHARSET_SYMBOL_ATTRIBUTES (symbol)) | |
280 | ||
281 | /* Return an index to Vcharset_hash_table of the charset whose symbol | |
282 | is SYMBOL. */ | |
283 | #define CHARSET_SYMBOL_HASH_INDEX(symbol) \ | |
284 | hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol, NULL) | |
285 | ||
286 | /* Return the attribute vector of CHARSET. */ | |
287 | #define CHARSET_ATTRIBUTES(charset) \ | |
288 | (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), (charset)->hash_index)) | |
289 | ||
290 | #define CHARSET_ID(charset) ((charset)->id) | |
291 | #define CHARSET_HASH_INDEX(charset) ((charset)->hash_index) | |
292 | #define CHARSET_DIMENSION(charset) ((charset)->dimension) | |
293 | #define CHARSET_CODE_SPACE(charset) ((charset)->code_space) | |
294 | #define CHARSET_CODE_LINEAR_P(charset) ((charset)->code_linear_p) | |
295 | #define CHARSET_ISO_CHARS_96(charset) ((charset)->iso_chars_96) | |
296 | #define CHARSET_ISO_FINAL(charset) ((charset)->iso_final) | |
297 | #define CHARSET_ISO_PLANE(charset) ((charset)->iso_plane) | |
298 | #define CHARSET_ISO_REVISION(charset) ((charset)->iso_revision) | |
299 | #define CHARSET_EMACS_MULE_ID(charset) ((charset)->emacs_mule_id) | |
300 | #define CHARSET_ASCII_COMPATIBLE_P(charset) ((charset)->ascii_compatible_p) | |
301 | #define CHARSET_COMPACT_CODES_P(charset) ((charset)->compact_codes_p) | |
302 | #define CHARSET_METHOD(charset) ((charset)->method) | |
303 | #define CHARSET_MIN_CODE(charset) ((charset)->min_code) | |
304 | #define CHARSET_MAX_CODE(charset) ((charset)->max_code) | |
305 | #define CHARSET_INVALID_CODE(charset) ((charset)->invalid_code) | |
306 | #define CHARSET_MIN_CHAR(charset) ((charset)->min_char) | |
307 | #define CHARSET_MAX_CHAR(charset) ((charset)->max_char) | |
308 | #define CHARSET_CODE_OFFSET(charset) ((charset)->code_offset) | |
309 | #define CHARSET_UNIFIED_P(charset) ((charset)->unified_p) | |
310 | ||
311 | #define CHARSET_NAME(charset) \ | |
312 | (CHARSET_ATTR_NAME (CHARSET_ATTRIBUTES (charset))) | |
313 | #define CHARSET_MAP(charset) \ | |
314 | (CHARSET_ATTR_MAP (CHARSET_ATTRIBUTES (charset))) | |
315 | #define CHARSET_DECODER(charset) \ | |
316 | (CHARSET_ATTR_DECODER (CHARSET_ATTRIBUTES (charset))) | |
317 | #define CHARSET_ENCODER(charset) \ | |
318 | (CHARSET_ATTR_ENCODER (CHARSET_ATTRIBUTES (charset))) | |
ec7dd615 KH |
319 | #define CHARSET_SUBSET(charset) \ |
320 | (CHARSET_ATTR_SUBSET (CHARSET_ATTRIBUTES (charset))) | |
321 | #define CHARSET_SUPERSET(charset) \ | |
322 | (CHARSET_ATTR_SUPERSET (CHARSET_ATTRIBUTES (charset))) | |
3263d5a2 KH |
323 | #define CHARSET_UNIFY_MAP(charset) \ |
324 | (CHARSET_ATTR_UNIFY_MAP (CHARSET_ATTRIBUTES (charset))) | |
325 | #define CHARSET_DEUNIFIER(charset) \ | |
326 | (CHARSET_ATTR_DEUNIFIER (CHARSET_ATTRIBUTES (charset))) | |
327 | ||
328 | ||
b2e6b10f | 329 | /* Nonzero if OBJ is a valid charset symbol. */ |
3263d5a2 KH |
330 | #define CHARSETP(obj) (CHARSET_SYMBOL_HASH_INDEX (obj) >= 0) |
331 | ||
332 | /* Check if X is a valid charset symbol. If not, signal an error. */ | |
333 | #define CHECK_CHARSET(x) \ | |
384107f2 | 334 | do { \ |
3263d5a2 | 335 | if (! SYMBOLP (x) || CHARSET_SYMBOL_HASH_INDEX (x) < 0) \ |
43d1af23 | 336 | wrong_type_argument (Qcharsetp, (x)); \ |
384107f2 | 337 | } while (0) |
6e4dc3e1 | 338 | |
6e4dc3e1 | 339 | |
3263d5a2 KH |
340 | /* Check if X is a valid charset symbol. If valid, set ID to the id |
341 | number of the charset. Otherwise, signal an error. */ | |
342 | #define CHECK_CHARSET_GET_ID(x, id) \ | |
343 | do { \ | |
344 | int idx; \ | |
345 | \ | |
346 | if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0) \ | |
43d1af23 | 347 | wrong_type_argument (Qcharsetp, (x)); \ |
73e92b8c DL |
348 | id = XINT (AREF (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), idx), \ |
349 | charset_id)); \ | |
4ed46869 KH |
350 | } while (0) |
351 | ||
6e4dc3e1 | 352 | |
3263d5a2 KH |
353 | /* Check if X is a valid charset symbol. If valid, set ATTR to the |
354 | attr vector of the charset. Otherwise, signal an error. */ | |
355 | #define CHECK_CHARSET_GET_ATTR(x, attr) \ | |
356 | do { \ | |
357 | if (!SYMBOLP (x) || NILP (attr = CHARSET_SYMBOL_ATTRIBUTES (x))) \ | |
43d1af23 | 358 | wrong_type_argument (Qcharsetp, (x)); \ |
6e4dc3e1 KH |
359 | } while (0) |
360 | ||
6e4dc3e1 | 361 | |
3263d5a2 KH |
362 | #define CHECK_CHARSET_GET_CHARSET(x, charset) \ |
363 | do { \ | |
f6095868 PE |
364 | int csid; \ |
365 | CHECK_CHARSET_GET_ID (x, csid); \ | |
366 | charset = CHARSET_FROM_ID (csid); \ | |
c399b461 RS |
367 | } while (0) |
368 | ||
c399b461 | 369 | |
924b41ee | 370 | /* Lookup Vcharset_ordered_list and return the first charset that |
3263d5a2 | 371 | contains the character C. */ |
ec91b3c9 KH |
372 | #define CHAR_CHARSET(c) \ |
373 | ((c) < 0x80 ? CHARSET_FROM_ID (charset_ascii) \ | |
374 | : char_charset ((c), Qnil, NULL)) | |
c399b461 | 375 | |
3263d5a2 KH |
376 | #if 0 |
377 | /* Char-table of charset-sets. Each element is a bool vector indexed | |
378 | by a charset ID. */ | |
379 | extern Lisp_Object Vchar_charset_set; | |
6e4dc3e1 | 380 | |
3263d5a2 KH |
381 | /* Charset-bag of character C. */ |
382 | #define CHAR_CHARSET_SET(c) \ | |
383 | CHAR_TABLE_REF (Vchar_charset_set, c) | |
6e4dc3e1 | 384 | |
3263d5a2 KH |
385 | /* Check if two characters C1 and C2 belong to the same charset. */ |
386 | #define SAME_CHARSET_P(c1, c2) \ | |
387 | intersection_p (CHAR_CHARSET_SET (c1), CHAR_CHARSET_SET (c2)) | |
388 | ||
389 | #endif | |
390 | ||
391 | ||
392 | /* Return a character correponding to the code-point CODE of CHARSET. | |
393 | Try some optimization before calling decode_char. */ | |
394 | ||
395 | #define DECODE_CHAR(charset, code) \ | |
396 | ((ASCII_BYTE_P (code) && (charset)->ascii_compatible_p) \ | |
397 | ? (code) \ | |
398 | : ((code) < (charset)->min_code || (code) > (charset)->max_code) \ | |
399 | ? -1 \ | |
400 | : (charset)->unified_p \ | |
401 | ? decode_char ((charset), (code)) \ | |
402 | : (charset)->method == CHARSET_METHOD_OFFSET \ | |
403 | ? ((charset)->code_linear_p \ | |
404 | ? (code) - (charset)->min_code + (charset)->code_offset \ | |
405 | : decode_char ((charset), (code))) \ | |
406 | : (charset)->method == CHARSET_METHOD_MAP \ | |
2bc20f0b KH |
407 | ? (((charset)->code_linear_p \ |
408 | && VECTORP (CHARSET_DECODER (charset))) \ | |
3263d5a2 | 409 | ? XINT (AREF (CHARSET_DECODER (charset), \ |
2bc20f0b | 410 | (code) - (charset)->min_code)) \ |
3263d5a2 KH |
411 | : decode_char ((charset), (code))) \ |
412 | : decode_char ((charset), (code))) | |
413 | ||
414 | ||
8cf93b6e KH |
415 | /* If CHARSET is a simple offset base charset, return it's offset, |
416 | otherwise return -1. */ | |
417 | #define CHARSET_OFFSET(charset) \ | |
418 | (((charset)->method == CHARSET_METHOD_OFFSET \ | |
419 | && (charset)->code_linear_p \ | |
420 | && ! (charset)->unified_p) \ | |
421 | ? (charset)->code_offset - (charset)->min_code \ | |
422 | : -1) | |
423 | ||
ec7dd615 KH |
424 | extern Lisp_Object charset_work; |
425 | ||
3263d5a2 KH |
426 | /* Return a code point of CHAR in CHARSET. |
427 | Try some optimization before calling encode_char. */ | |
428 | ||
a2a01861 PE |
429 | #define ENCODE_CHAR(charset, c) \ |
430 | (verify_expr \ | |
431 | (sizeof (c) <= sizeof (int), \ | |
432 | (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p \ | |
433 | ? (c) \ | |
434 | : ((charset)->unified_p \ | |
435 | || (charset)->method == CHARSET_METHOD_SUBSET \ | |
436 | || (charset)->method == CHARSET_METHOD_SUPERSET) \ | |
437 | ? encode_char (charset, c) \ | |
438 | : (c) < (charset)->min_char || (c) > (charset)->max_char \ | |
439 | ? (charset)->invalid_code \ | |
440 | : (charset)->method == CHARSET_METHOD_OFFSET \ | |
441 | ? ((charset)->code_linear_p \ | |
442 | ? (c) - (charset)->code_offset + (charset)->min_code \ | |
443 | : encode_char (charset, c)) \ | |
444 | : (charset)->method == CHARSET_METHOD_MAP \ | |
445 | ? (((charset)->compact_codes_p \ | |
446 | && CHAR_TABLE_P (CHARSET_ENCODER (charset))) \ | |
447 | ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \ | |
448 | (NILP (charset_work) \ | |
449 | ? (charset)->invalid_code \ | |
450 | : XFASTINT (charset_work))) \ | |
451 | : encode_char (charset, c)) \ | |
452 | : encode_char (charset, c)))) | |
3263d5a2 KH |
453 | |
454 | ||
455 | /* Set to 1 when a charset map is loaded to warn that a buffer text | |
456 | and a string data may be relocated. */ | |
457 | extern int charset_map_loaded; | |
458 | ||
459 | ||
460 | /* Set CHARSET to the charset highest priority of C, CODE to the | |
461 | code-point of C in CHARSET. */ | |
462 | #define SPLIT_CHAR(c, charset, code) \ | |
463 | ((charset) = char_charset ((c), Qnil, &(code))) | |
464 | ||
465 | ||
466 | #define ISO_MAX_DIMENSION 3 | |
467 | #define ISO_MAX_CHARS 2 | |
468 | #define ISO_MAX_FINAL 0x80 /* only 0x30..0xFF are used */ | |
469 | ||
470 | /* Mapping table from ISO2022's charset (specified by DIMENSION, | |
471 | CHARS, and FINAL_CHAR) to Emacs' charset ID. Should be accessed by | |
472 | macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR). */ | |
473 | extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL]; | |
c399b461 | 474 | |
3263d5a2 KH |
475 | /* A charset of type iso2022 who has DIMENSION, CHARS, and FINAL |
476 | (final character). */ | |
477 | #define ISO_CHARSET_TABLE(dimension, chars_96, final) \ | |
478 | iso_charset_table[(dimension) - 1][(chars_96)][(final)] | |
6e4dc3e1 | 479 | |
b2e6b10f | 480 | /* Nonzero if the charset who has FAST_MAP may contain C. */ |
3263d5a2 KH |
481 | #define CHARSET_FAST_MAP_REF(c, fast_map) \ |
482 | ((c) < 0x10000 \ | |
483 | ? fast_map[(c) >> 10] & (1 << (((c) >> 7) & 7)) \ | |
484 | : fast_map[((c) >> 15) + 62] & (1 << (((c) >> 12) & 7))) | |
6e4dc3e1 | 485 | |
3263d5a2 | 486 | #define CHARSET_FAST_MAP_SET(c, fast_map) \ |
384107f2 | 487 | do { \ |
3263d5a2 KH |
488 | if ((c) < 0x10000) \ |
489 | (fast_map)[(c) >> 10] |= 1 << (((c) >> 7) & 7); \ | |
384107f2 | 490 | else \ |
3263d5a2 | 491 | (fast_map)[((c) >> 15) + 62] |= 1 << (((c) >> 12) & 7); \ |
384107f2 KH |
492 | } while (0) |
493 | ||
6e4dc3e1 | 494 | |
6e4dc3e1 | 495 | |
b2e6b10f | 496 | /* 1 if CHARSET may contain the character C. */ |
ec7dd615 KH |
497 | #define CHAR_CHARSET_P(c, charset) \ |
498 | ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ | |
1c305bc1 KH |
499 | || ((CHARSET_UNIFIED_P (charset) \ |
500 | || (charset)->method == CHARSET_METHOD_SUBSET \ | |
501 | || (charset)->method == CHARSET_METHOD_SUPERSET) \ | |
ec7dd615 KH |
502 | ? encode_char ((charset), (c)) != (charset)->invalid_code \ |
503 | : (CHARSET_FAST_MAP_REF ((c), (charset)->fast_map) \ | |
504 | && ((charset)->method == CHARSET_METHOD_OFFSET \ | |
505 | ? (c) >= (charset)->min_char && (c) <= (charset)->max_char \ | |
506 | : ((charset)->method == CHARSET_METHOD_MAP \ | |
8cc53f96 KH |
507 | && (charset)->compact_codes_p \ |
508 | && CHAR_TABLE_P (CHARSET_ENCODER (charset))) \ | |
ec7dd615 | 509 | ? ! NILP (CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c))) \ |
3263d5a2 | 510 | : encode_char ((charset), (c)) != (charset)->invalid_code)))) |
6e4dc3e1 | 511 | |
39d992af KH |
512 | \f |
513 | /* Special macros for emacs-mule encoding. */ | |
4ed46869 | 514 | |
39d992af KH |
515 | /* Leading-code followed by extended leading-code. DIMENSION/COLUMN */ |
516 | #define EMACS_MULE_LEADING_CODE_PRIVATE_11 0x9A /* 1/1 */ | |
517 | #define EMACS_MULE_LEADING_CODE_PRIVATE_12 0x9B /* 1/2 */ | |
518 | #define EMACS_MULE_LEADING_CODE_PRIVATE_21 0x9C /* 2/2 */ | |
519 | #define EMACS_MULE_LEADING_CODE_PRIVATE_22 0x9D /* 2/2 */ | |
520 | ||
39d992af | 521 | \f |
4ed46869 | 522 | |
3263d5a2 KH |
523 | extern Lisp_Object Qcharsetp; |
524 | ||
955cbe7b | 525 | extern Lisp_Object Qascii; |
21f9c39d | 526 | extern int charset_ascii, charset_eight_bit; |
96f45cf0 | 527 | extern int charset_unicode; |
e73576a3 KH |
528 | extern int charset_jisx0201_roman; |
529 | extern int charset_jisx0208_1978; | |
530 | extern int charset_jisx0208; | |
3c908a57 | 531 | extern int charset_ksc5601; |
3263d5a2 | 532 | |
3fd31366 KH |
533 | extern int charset_unibyte; |
534 | ||
383e0970 J |
535 | extern struct charset *char_charset (int, Lisp_Object, unsigned *); |
536 | extern Lisp_Object charset_attributes (int); | |
3263d5a2 | 537 | |
383e0970 J |
538 | extern int maybe_unify_char (int, Lisp_Object); |
539 | extern int decode_char (struct charset *, unsigned); | |
540 | extern unsigned encode_char (struct charset *, int); | |
541 | extern int string_xstring_p (Lisp_Object); | |
3263d5a2 | 542 | |
383e0970 J |
543 | extern void map_charset_chars (void (*) (Lisp_Object, Lisp_Object), |
544 | Lisp_Object, Lisp_Object, | |
545 | struct charset *, unsigned, unsigned); | |
ec7dd615 | 546 | |
aa01a892 | 547 | #endif /* EMACS_CHARSET_H */ |