This source file includes following definitions.
- set_charset_attr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #ifndef EMACS_CHARSET_H
28 #define EMACS_CHARSET_H
29
30 #include <verify.h>
31 #include "lisp.h"
32
33 INLINE_HEADER_BEGIN
34
35
36
37 enum define_charset_arg_index
38 {
39 charset_arg_name,
40 charset_arg_dimension,
41 charset_arg_code_space,
42 charset_arg_min_code,
43 charset_arg_max_code,
44 charset_arg_iso_final,
45 charset_arg_iso_revision,
46 charset_arg_emacs_mule_id,
47 charset_arg_ascii_compatible_p,
48 charset_arg_supplementary_p,
49 charset_arg_invalid_code,
50 charset_arg_code_offset,
51 charset_arg_map,
52 charset_arg_subset,
53 charset_arg_superset,
54 charset_arg_unify_map,
55 charset_arg_plist,
56 charset_arg_max
57 };
58
59
60
61
62 enum charset_attr_index
63 {
64
65 charset_id,
66
67
68 charset_name,
69
70
71 charset_plist,
72
73
74
75
76 charset_map,
77
78
79
80
81
82
83 charset_decoder,
84
85
86
87
88 charset_encoder,
89
90
91
92
93
94
95
96
97
98
99
100 charset_subset,
101
102
103
104
105
106
107
108
109
110 charset_superset,
111
112
113
114
115
116 charset_unify_map,
117
118
119
120
121 charset_deunifier,
122
123
124 charset_attr_max
125 };
126
127
128
129 enum charset_method
130 {
131
132
133
134 CHARSET_METHOD_OFFSET,
135
136
137
138
139 CHARSET_METHOD_MAP,
140
141
142 CHARSET_METHOD_SUBSET,
143
144
145 CHARSET_METHOD_SUPERSET
146 };
147
148 struct charset
149 {
150
151 int id;
152
153
154 ptrdiff_t hash_index;
155
156
157 int dimension;
158
159
160
161
162
163
164
165
166
167 int code_space[15];
168
169
170
171
172 unsigned char *code_space_mask;
173
174
175 bool_bf code_linear_p : 1;
176
177
178
179 bool_bf iso_chars_96 : 1;
180
181
182 bool_bf ascii_compatible_p : 1;
183
184
185 bool_bf supplementary_p : 1;
186
187
188 bool_bf compact_codes_p : 1;
189
190
191 bool_bf unified_p : 1;
192
193
194
195 int iso_final;
196
197
198 int iso_revision;
199
200
201
202
203 int emacs_mule_id;
204
205
206 enum charset_method method;
207
208
209 unsigned min_code, max_code;
210
211
212
213 unsigned char_index_offset;
214
215
216
217
218
219
220 int min_char, max_char;
221
222
223
224 unsigned invalid_code;
225
226
227
228
229
230
231
232
233
234
235
236
237
238 unsigned char fast_map[190];
239
240
241
242 int code_offset;
243 };
244
245
246
247 extern Lisp_Object Vcharset_hash_table;
248
249
250 extern struct charset *charset_table;
251 extern int charset_table_size;
252 extern int charset_table_used;
253
254 #define CHARSET_FROM_ID(id) (charset_table + (id))
255
256 extern Lisp_Object Vcharset_ordered_list;
257 extern Lisp_Object Vcharset_non_preferred_head;
258
259 extern EMACS_UINT charset_ordered_list_tick;
260
261 extern Lisp_Object Viso_2022_charset_list;
262 extern Lisp_Object Vemacs_mule_charset_list;
263
264 extern int emacs_mule_charset[256];
265
266
267
268
269 #define CHARSET_SYMBOL_ATTRIBUTES(symbol) \
270 Fgethash ((symbol), Vcharset_hash_table, Qnil)
271
272 #define CHARSET_ATTR_ID(attrs) AREF ((attrs), charset_id)
273 #define CHARSET_ATTR_NAME(attrs) AREF ((attrs), charset_name)
274 #define CHARSET_ATTR_PLIST(attrs) AREF ((attrs), charset_plist)
275 #define CHARSET_ATTR_MAP(attrs) AREF ((attrs), charset_map)
276 #define CHARSET_ATTR_DECODER(attrs) AREF ((attrs), charset_decoder)
277 #define CHARSET_ATTR_ENCODER(attrs) AREF ((attrs), charset_encoder)
278 #define CHARSET_ATTR_SUBSET(attrs) AREF ((attrs), charset_subset)
279 #define CHARSET_ATTR_SUPERSET(attrs) AREF ((attrs), charset_superset)
280 #define CHARSET_ATTR_UNIFY_MAP(attrs) AREF ((attrs), charset_unify_map)
281 #define CHARSET_ATTR_DEUNIFIER(attrs) AREF ((attrs), charset_deunifier)
282
283 #define CHARSET_SYMBOL_ID(symbol) \
284 CHARSET_ATTR_ID (CHARSET_SYMBOL_ATTRIBUTES (symbol))
285
286
287
288 #define CHARSET_SYMBOL_HASH_INDEX(symbol) \
289 hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol, NULL)
290
291
292 #define CHARSET_ATTRIBUTES(charset) \
293 (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), (charset)->hash_index))
294
295 #define CHARSET_ID(charset) ((charset)->id)
296 #define CHARSET_HASH_INDEX(charset) ((charset)->hash_index)
297 #define CHARSET_DIMENSION(charset) ((charset)->dimension)
298 #define CHARSET_CODE_SPACE(charset) ((charset)->code_space)
299 #define CHARSET_CODE_LINEAR_P(charset) ((charset)->code_linear_p)
300 #define CHARSET_ISO_CHARS_96(charset) ((charset)->iso_chars_96)
301 #define CHARSET_ISO_FINAL(charset) ((charset)->iso_final)
302 #define CHARSET_ISO_PLANE(charset) ((charset)->iso_plane)
303 #define CHARSET_ISO_REVISION(charset) ((charset)->iso_revision)
304 #define CHARSET_EMACS_MULE_ID(charset) ((charset)->emacs_mule_id)
305 #define CHARSET_ASCII_COMPATIBLE_P(charset) ((charset)->ascii_compatible_p)
306 #define CHARSET_COMPACT_CODES_P(charset) ((charset)->compact_codes_p)
307 #define CHARSET_METHOD(charset) ((charset)->method)
308 #define CHARSET_MIN_CODE(charset) ((charset)->min_code)
309 #define CHARSET_MAX_CODE(charset) ((charset)->max_code)
310 #define CHARSET_INVALID_CODE(charset) ((charset)->invalid_code)
311 #define CHARSET_MIN_CHAR(charset) ((charset)->min_char)
312 #define CHARSET_MAX_CHAR(charset) ((charset)->max_char)
313 #define CHARSET_CODE_OFFSET(charset) ((charset)->code_offset)
314 #define CHARSET_UNIFIED_P(charset) ((charset)->unified_p)
315
316 #define CHARSET_NAME(charset) \
317 (CHARSET_ATTR_NAME (CHARSET_ATTRIBUTES (charset)))
318 #define CHARSET_MAP(charset) \
319 (CHARSET_ATTR_MAP (CHARSET_ATTRIBUTES (charset)))
320 #define CHARSET_DECODER(charset) \
321 (CHARSET_ATTR_DECODER (CHARSET_ATTRIBUTES (charset)))
322 #define CHARSET_ENCODER(charset) \
323 (CHARSET_ATTR_ENCODER (CHARSET_ATTRIBUTES (charset)))
324 #define CHARSET_SUBSET(charset) \
325 (CHARSET_ATTR_SUBSET (CHARSET_ATTRIBUTES (charset)))
326 #define CHARSET_SUPERSET(charset) \
327 (CHARSET_ATTR_SUPERSET (CHARSET_ATTRIBUTES (charset)))
328 #define CHARSET_UNIFY_MAP(charset) \
329 (CHARSET_ATTR_UNIFY_MAP (CHARSET_ATTRIBUTES (charset)))
330 #define CHARSET_DEUNIFIER(charset) \
331 (CHARSET_ATTR_DEUNIFIER (CHARSET_ATTRIBUTES (charset)))
332
333 INLINE void
334 set_charset_attr (struct charset *charset, enum charset_attr_index idx,
335 Lisp_Object val)
336 {
337 ASET (CHARSET_ATTRIBUTES (charset), idx, val);
338 }
339
340
341
342 #define CHARSETP(obj) (CHARSET_SYMBOL_HASH_INDEX (obj) >= 0)
343
344
345 #define CHECK_CHARSET(x) \
346 do { \
347 if (! SYMBOLP (x) || CHARSET_SYMBOL_HASH_INDEX (x) < 0) \
348 wrong_type_argument (Qcharsetp, (x)); \
349 } while (false)
350
351
352
353
354 #define CHECK_CHARSET_GET_ID(x, id) \
355 do { \
356 ptrdiff_t idx; \
357 \
358 if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0) \
359 wrong_type_argument (Qcharsetp, (x)); \
360 id = XFIXNUM (AREF (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), idx), \
361 charset_id)); \
362 } while (false)
363
364
365
366
367 #define CHECK_CHARSET_GET_ATTR(x, attr) \
368 do { \
369 if (!SYMBOLP (x) || NILP (attr = CHARSET_SYMBOL_ATTRIBUTES (x))) \
370 wrong_type_argument (Qcharsetp, (x)); \
371 } while (false)
372
373
374 #define CHECK_CHARSET_GET_CHARSET(x, charset) \
375 do { \
376 int csid; \
377 CHECK_CHARSET_GET_ID (x, csid); \
378 charset = CHARSET_FROM_ID (csid); \
379 } while (false)
380
381
382
383
384 #define CHAR_CHARSET(c) \
385 ((c) < 0x80 ? CHARSET_FROM_ID (charset_ascii) \
386 : char_charset ((c), Qnil, NULL))
387
388 #if false
389
390
391 extern Lisp_Object Vchar_charset_set;
392
393
394 #define CHAR_CHARSET_SET(c) \
395 CHAR_TABLE_REF (Vchar_charset_set, c)
396
397
398 #define SAME_CHARSET_P(c1, c2) \
399 intersection_p (CHAR_CHARSET_SET (c1), CHAR_CHARSET_SET (c2))
400
401 #endif
402
403
404
405
406
407 #define DECODE_CHAR(charset, code) \
408 ((ASCII_CHAR_P (code) && (charset)->ascii_compatible_p) \
409 ? (code) \
410 : ((code) < (charset)->min_code || (code) > (charset)->max_code) \
411 ? -1 \
412 : (charset)->unified_p \
413 ? decode_char ((charset), (code)) \
414 : (charset)->method == CHARSET_METHOD_OFFSET \
415 ? ((charset)->code_linear_p \
416 ? (int) ((code) - (charset)->min_code) + (charset)->code_offset \
417 : decode_char ((charset), (code))) \
418 : (charset)->method == CHARSET_METHOD_MAP \
419 ? (((charset)->code_linear_p \
420 && VECTORP (CHARSET_DECODER (charset))) \
421 ? XFIXNUM (AREF (CHARSET_DECODER (charset), \
422 (code) - (charset)->min_code)) \
423 : decode_char ((charset), (code))) \
424 : decode_char ((charset), (code)))
425
426 extern Lisp_Object charset_work;
427
428
429
430
431 #define ENCODE_CHAR(charset, c) \
432 (verify_expr \
433 (sizeof (c) <= sizeof (int), \
434 (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p \
435 ? (unsigned) (c) \
436 : ((charset)->unified_p \
437 || (charset)->method == CHARSET_METHOD_SUBSET \
438 || (charset)->method == CHARSET_METHOD_SUPERSET) \
439 ? encode_char (charset, c) \
440 : (c) < (charset)->min_char || (c) > (charset)->max_char \
441 ? (charset)->invalid_code \
442 : (charset)->method == CHARSET_METHOD_OFFSET \
443 ? ((charset)->code_linear_p \
444 ? (unsigned) ((c) - (charset)->code_offset) + (charset)->min_code \
445 : encode_char (charset, c)) \
446 : (charset)->method == CHARSET_METHOD_MAP \
447 ? (((charset)->compact_codes_p \
448 && CHAR_TABLE_P (CHARSET_ENCODER (charset))) \
449 ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \
450 (NILP (charset_work) \
451 ? (charset)->invalid_code \
452 : (unsigned) XFIXNAT (charset_work))) \
453 : encode_char (charset, c)) \
454 : encode_char (charset, c))))
455
456
457
458
459 extern bool charset_map_loaded;
460
461
462
463
464 #define SPLIT_CHAR(c, charset, code) \
465 ((charset) = char_charset ((c), Qnil, &(code)))
466
467
468 #define ISO_MAX_DIMENSION 3
469 #define ISO_MAX_CHARS 2
470 #define ISO_MAX_FINAL 0x80
471
472
473
474
475 extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
476
477
478
479 #define ISO_CHARSET_TABLE(dimension, chars_96, final) \
480 iso_charset_table[(dimension) - 1][chars_96][final]
481
482
483 #define CHARSET_FAST_MAP_REF(c, fast_map) \
484 ((c) < 0x10000 \
485 ? fast_map[(c) >> 10] & (1 << (((c) >> 7) & 7)) \
486 : fast_map[((c) >> 15) + 62] & (1 << (((c) >> 12) & 7)))
487
488 #define CHARSET_FAST_MAP_SET(c, fast_map) \
489 do { \
490 if ((c) < 0x10000) \
491 (fast_map)[(c) >> 10] |= 1 << (((c) >> 7) & 7); \
492 else \
493 (fast_map)[((c) >> 15) + 62] |= 1 << (((c) >> 12) & 7); \
494 } while (false)
495
496
497
498
499 #define CHAR_CHARSET_P(c, charset) \
500 ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \
501 || ((CHARSET_UNIFIED_P (charset) \
502 || (charset)->method == CHARSET_METHOD_SUBSET \
503 || (charset)->method == CHARSET_METHOD_SUPERSET) \
504 ? encode_char ((charset), (c)) != (charset)->invalid_code \
505 : (CHARSET_FAST_MAP_REF ((c), (charset)->fast_map) \
506 && ((charset)->method == CHARSET_METHOD_OFFSET \
507 ? (c) >= (charset)->min_char && (c) <= (charset)->max_char \
508 : ((charset)->method == CHARSET_METHOD_MAP \
509 && (charset)->compact_codes_p \
510 && CHAR_TABLE_P (CHARSET_ENCODER (charset))) \
511 ? ! NILP (CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c))) \
512 : encode_char ((charset), (c)) != (charset)->invalid_code))))
513
514
515
516
517
518 #define EMACS_MULE_LEADING_CODE_PRIVATE_11 0x9A
519 #define EMACS_MULE_LEADING_CODE_PRIVATE_12 0x9B
520 #define EMACS_MULE_LEADING_CODE_PRIVATE_21 0x9C
521 #define EMACS_MULE_LEADING_CODE_PRIVATE_22 0x9D
522
523
524
525 extern int charset_ascii, charset_eight_bit;
526 extern int charset_unicode;
527 extern int charset_jisx0201_roman;
528 extern int charset_jisx0208_1978;
529 extern int charset_jisx0208;
530 extern int charset_ksc5601;
531
532 extern int charset_unibyte;
533
534 extern struct charset *char_charset (int, Lisp_Object, unsigned *);
535 extern Lisp_Object charset_attributes (int);
536
537 extern int decode_char (struct charset *, unsigned);
538 extern unsigned encode_char (struct charset *, int);
539 extern int string_xstring_p (Lisp_Object);
540
541 extern void map_charset_chars (void (*) (Lisp_Object, Lisp_Object),
542 Lisp_Object, Lisp_Object,
543 struct charset *, unsigned, unsigned);
544
545 INLINE_HEADER_END
546
547 #endif