771
|
1 /* Header for charsets.
|
|
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 2001, 2002 Ben Wing.
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Mule 2.3. Not in FSF. */
|
|
24
|
|
25 /* Rewritten by Ben Wing <ben@xemacs.org>. */
|
|
26
|
|
27 #ifndef INCLUDED_charset_h_
|
|
28 #define INCLUDED_charset_h_
|
|
29
|
|
30
|
|
31
|
|
32 #ifndef MULE
|
|
33
|
|
34 /************************************************************************/
|
|
35 /* fake charset defs */
|
|
36 /************************************************************************/
|
|
37
|
|
38 /* used when MULE is not defined, so that Charset-type stuff can still
|
|
39 be done */
|
|
40
|
|
41 #define Vcharset_ascii Qnil
|
|
42
|
867
|
43 #define ichar_charset(ch) Vcharset_ascii
|
|
44 #define ichar_leading_byte(ch) LEADING_BYTE_ASCII
|
|
45 #define ichar_len(ch) 1
|
|
46 #define ichar_len_fmt(ch, fmt) 1
|
771
|
47 #define LEADING_BYTE_ASCII 0x80
|
|
48 #define NUM_LEADING_BYTES 1
|
|
49 #define MIN_LEADING_BYTE 0x80
|
|
50 #define CHARSETP(cs) 1
|
826
|
51 #define charset_by_leading_byte(lb) Vcharset_ascii
|
771
|
52 #define XCHARSET_LEADING_BYTE(cs) LEADING_BYTE_ASCII
|
|
53 #define XCHARSET_GRAPHIC(cs) -1
|
|
54 #define XCHARSET_COLUMNS(cs) 1
|
|
55 #define XCHARSET_DIMENSION(cs) 1
|
867
|
56 #define BREAKUP_ICHAR(ch, charset, byte1, byte2) do { \
|
771
|
57 (charset) = Vcharset_ascii; \
|
|
58 (byte1) = (ch); \
|
|
59 (byte2) = 0; \
|
|
60 } while (0)
|
|
61
|
|
62 #else /* MULE */
|
|
63
|
|
64
|
|
65 /************************************************************************/
|
|
66 /* Definition of leading bytes */
|
|
67 /************************************************************************/
|
|
68
|
|
69 #define MIN_LEADING_BYTE 0x7F
|
|
70
|
|
71 /** The following are for 1-byte characters in an official charset. **/
|
|
72 enum LEADING_BYTE_OFFICIAL_1
|
|
73 {
|
|
74 MIN_LEADING_BYTE_OFFICIAL_1 = 0x80,
|
|
75 /* LEADING_BYTE_LATIN_ISO8859_1 *MUST* be equal to
|
|
76 MIN_LEADING_BYTE_OFFICIAL_1. */
|
|
77 LEADING_BYTE_LATIN_ISO8859_1 = /* 0x80 Right half of ISO 8859-1 */
|
|
78 MIN_LEADING_BYTE_OFFICIAL_1,
|
|
79 LEADING_BYTE_LATIN_ISO8859_2, /* 0x81 Right half of ISO 8859-2 */
|
|
80 LEADING_BYTE_LATIN_ISO8859_3, /* 0x82 Right half of ISO 8859-3 */
|
|
81 LEADING_BYTE_LATIN_ISO8859_4, /* 0x83 Right half of ISO 8859-4 */
|
|
82 LEADING_BYTE_THAI_TIS620, /* 0x84 TIS620-2533 */
|
|
83 LEADING_BYTE_GREEK_ISO8859_7, /* 0x85 Right half of ISO 8859-7 */
|
|
84 LEADING_BYTE_ARABIC_ISO8859_6, /* 0x86 Right half of ISO 8859-6 */
|
|
85 LEADING_BYTE_HEBREW_ISO8859_8, /* 0x87 Right half of ISO 8859-8 */
|
|
86 LEADING_BYTE_KATAKANA_JISX0201, /* 0x88 Right half of JIS X0201-1976 */
|
|
87 LEADING_BYTE_LATIN_JISX0201, /* 0x89 Left half of JIS X0201-1976 */
|
|
88 LEADING_BYTE_CYRILLIC_ISO8859_5,/* 0x8A Right half of ISO 8859-5 */
|
|
89 LEADING_BYTE_LATIN_ISO8859_9, /* 0x8B Right half of ISO 8859-9 */
|
|
90 LEADING_BYTE_LATIN_ISO8859_15, /* 0x8C Right half of ISO 8859-15 */
|
|
91 #ifdef ENABLE_COMPOSITE_CHARS
|
|
92 LEADING_BYTE_COMPOSITE, /* 0x8D For a composite character */
|
|
93 MAX_LEADING_BYTE_OFFICIAL_1 =
|
|
94 LEADING_BYTE_COMPOSITE - 1,
|
|
95 #else
|
|
96 /* Does not need to be the last entry, but simplifies things */
|
|
97 LEADING_BYTE_COMPOSITE_REPLACEMENT, /* 0x8D Replaces ESC 0 - ESC 4 in a
|
|
98 buffer */
|
|
99 MAX_LEADING_BYTE_OFFICIAL_1 =
|
|
100 LEADING_BYTE_COMPOSITE_REPLACEMENT,
|
|
101 #endif
|
|
102 /* 0x8E Unused */
|
|
103 };
|
|
104
|
|
105 /* These next 2 + LEADING_BYTE_COMPOSITE need special treatment in a string
|
|
106 and/or character */
|
|
107
|
|
108 #define LEADING_BYTE_ASCII 0x7F /* Not used except in arrays
|
|
109 indexed by leading byte */
|
|
110 #define LEADING_BYTE_CONTROL_1 0x8F /* represent normal 80-9F */
|
|
111
|
|
112 /** The following are for 2-byte characters in an official charset. **/
|
|
113 enum LEADING_BYTE_OFFICIAL_2
|
|
114 {
|
|
115 MIN_LEADING_BYTE_OFFICIAL_2 = 0x90,
|
|
116 LEADING_BYTE_JAPANESE_JISX0208_1978 =
|
|
117 MIN_LEADING_BYTE_OFFICIAL_2, /* 0x90 Japanese JIS X0208-1978 */
|
|
118 LEADING_BYTE_CHINESE_GB2312, /* 0x91 Chinese Hanzi GB2312-1980 */
|
|
119 LEADING_BYTE_JAPANESE_JISX0208, /* 0x92 Japanese JIS X0208-1983 */
|
|
120 LEADING_BYTE_KOREAN_KSC5601, /* 0x93 Hangul KS C5601-1987 */
|
|
121 LEADING_BYTE_JAPANESE_JISX0212, /* 0x94 Japanese JIS X0212-1990 */
|
|
122 LEADING_BYTE_CHINESE_CNS11643_1, /* 0x95 Chinese CNS11643 Set 1 */
|
|
123 LEADING_BYTE_CHINESE_CNS11643_2, /* 0x96 Chinese CNS11643 Set 2 */
|
|
124 LEADING_BYTE_CHINESE_BIG5_1, /* 0x97 Big5 Level 1 */
|
|
125 LEADING_BYTE_CHINESE_BIG5_2, /* 0x98 Big5 Level 2 */
|
|
126 MAX_LEADING_BYTE_OFFICIAL_2 =
|
|
127 LEADING_BYTE_CHINESE_BIG5_2,
|
|
128
|
|
129 /* 0x99 unused */
|
|
130 /* 0x9A unused */
|
|
131 /* 0x9B unused */
|
|
132 /* 0x9C unused */
|
|
133 /* 0x9D unused */
|
|
134 };
|
|
135
|
|
136
|
|
137 /** The following are for 1- and 2-byte characters in a private charset. **/
|
|
138
|
|
139 #define PRE_LEADING_BYTE_PRIVATE_1 0x9E /* 1-byte char-set */
|
|
140 #define PRE_LEADING_BYTE_PRIVATE_2 0x9F /* 2-byte char-set */
|
|
141
|
|
142 #define MIN_LEADING_BYTE_PRIVATE_1 0xA0
|
|
143 #define MAX_LEADING_BYTE_PRIVATE_1 0xEF
|
|
144 #define MIN_LEADING_BYTE_PRIVATE_2 0xF0
|
|
145 #define MAX_LEADING_BYTE_PRIVATE_2 0xFF
|
|
146
|
|
147 #define NUM_LEADING_BYTES 129
|
|
148
|
|
149
|
|
150 /************************************************************************/
|
|
151 /* Operations on leading bytes */
|
|
152 /************************************************************************/
|
|
153
|
|
154 /* Is this leading byte for a private charset? */
|
|
155
|
826
|
156 #define leading_byte_private_p(lb) ((lb) >= MIN_LEADING_BYTE_PRIVATE_1)
|
771
|
157
|
|
158 /* Is this a prefix for a private leading byte? */
|
|
159
|
826
|
160 DECLARE_INLINE_HEADER (
|
|
161 int
|
867
|
162 leading_byte_prefix_p (Ibyte lb)
|
826
|
163 )
|
771
|
164 {
|
|
165 return (lb == PRE_LEADING_BYTE_PRIVATE_1 ||
|
|
166 lb == PRE_LEADING_BYTE_PRIVATE_2);
|
|
167 }
|
|
168
|
|
169 /* Given a private leading byte, return the leading byte prefix stored
|
|
170 in a string. */
|
|
171
|
826
|
172 #define private_leading_byte_prefix(lb) \
|
771
|
173 ((unsigned int) (lb) < MIN_LEADING_BYTE_PRIVATE_2 ? \
|
|
174 PRE_LEADING_BYTE_PRIVATE_1 : \
|
|
175 PRE_LEADING_BYTE_PRIVATE_2)
|
|
176
|
|
177
|
|
178 /************************************************************************/
|
|
179 /* Information about a particular character set */
|
|
180 /************************************************************************/
|
|
181
|
|
182 struct Lisp_Charset
|
|
183 {
|
|
184 struct lcrecord_header header;
|
|
185
|
|
186 int id;
|
|
187 Lisp_Object name;
|
|
188 Lisp_Object doc_string;
|
|
189 Lisp_Object registry;
|
|
190 Lisp_Object short_name;
|
|
191 Lisp_Object long_name;
|
|
192
|
|
193 Lisp_Object reverse_direction_charset;
|
|
194
|
|
195 Lisp_Object ccl_program;
|
|
196
|
|
197 /* Unicode translation tables. See unicode.c for the format of these tables.
|
|
198
|
|
199 NOTE ABOUT DUMPING: We don't currently dump these tables. For one
|
|
200 thing, they're big, and it's very fast to recreate them (a fraction of
|
|
201 a second on modern processors); for another, there isn't currently
|
|
202 support in pdump for this. (At one point I started writing it, in the
|
|
203 form of XD_UNION, but thought better of it.) In order to avoid pdump
|
|
204 problems (and to make the dump data smaller), we free all the tables
|
|
205 at dump time (using the disksave finalization method), set them to
|
|
206 zero, and reinit them to blank when we start up again; they will be
|
|
207 reloaded when `init-mule-at-startup' is called.
|
|
208
|
|
209 #### This creates a problem w.r.t. user-defined charsets. It would be
|
|
210 inconvenient to require all dumped user-defined charsets to be
|
|
211 reloaded at init time, but that's what currently needs to be done.
|
|
212 The solution is either to go ahead and create pdump support for
|
|
213 dumping the tables, and use it just for these; or to copy the data in
|
|
214 them into a compressed format, write it out to pdump as a single
|
|
215 opaque block, and undo the operation at startup.
|
|
216
|
|
217 #### There's another problem, having to do with starting up in a
|
|
218 non-ISO-8859-1 directory. We don't load the tables until after we've
|
|
219 parsed the current directories, and we run into a real bootstrapping
|
|
220 problem trying to solve this. Either we'll have to dump all the
|
|
221 tables as-is or make some special provisions for writing extra binary
|
|
222 data into the pdump data, and do the compressed trick mentioned above
|
|
223 for all the tables. */
|
|
224 void *to_unicode_table;
|
|
225 void *from_unicode_table;
|
|
226 int from_unicode_levels;
|
|
227
|
|
228 unsigned char unicode_table_loaded;
|
|
229
|
|
230 /* Final byte of this character set in ISO2022 designating escape sequence */
|
867
|
231 Ibyte final;
|
771
|
232
|
|
233 /* Number of bytes (1 - 4) required in the internal representation
|
|
234 for characters in this character set. This is *not* the
|
|
235 same as the dimension of the character set). */
|
|
236 int rep_bytes;
|
|
237
|
|
238 /* Number of columns a character in this charset takes up, on TTY
|
|
239 devices. Not used for X devices. */
|
|
240 int columns;
|
|
241
|
|
242 /* Direction of this character set */
|
|
243 int direction;
|
|
244
|
|
245 /* Type of this character set (94, 96, 94x94, 96x96) */
|
|
246 int type;
|
|
247
|
|
248 /* Number of bytes used in encoding of this character set (1 or 2) */
|
|
249 int dimension;
|
|
250
|
|
251 /* Number of chars in each dimension (usually 94 or 96) */
|
|
252 int chars;
|
|
253
|
|
254 /* Which half of font to be used to display this character set */
|
|
255 int graphic;
|
|
256
|
|
257 /* If set, this is a "temporary" charset created when we encounter
|
|
258 an unknown final. This is so that we can successfully compile
|
|
259 and load such files. We allow a real charset to be created on top
|
|
260 of this temporary charset. */
|
|
261 unsigned int temporary :1;
|
|
262 };
|
|
263 typedef struct Lisp_Charset Lisp_Charset;
|
|
264
|
|
265 DECLARE_LRECORD (charset, Lisp_Charset);
|
|
266 #define XCHARSET(x) XRECORD (x, charset, Lisp_Charset)
|
|
267 #define wrap_charset(p) wrap_record (p, charset)
|
|
268 #define CHARSETP(x) RECORDP (x, charset)
|
|
269 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
|
|
270 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
|
|
271
|
|
272 #define CHARSET_TYPE_94 0 /* This charset includes 94 characters. */
|
|
273 #define CHARSET_TYPE_96 1 /* This charset includes 96 characters. */
|
|
274 #define CHARSET_TYPE_94X94 2 /* This charset includes 94x94 characters. */
|
|
275 #define CHARSET_TYPE_96X96 3 /* This charset includes 96x96 characters. */
|
|
276
|
|
277 #define CHARSET_LEFT_TO_RIGHT 0
|
|
278 #define CHARSET_RIGHT_TO_LEFT 1
|
|
279
|
|
280 /* Leading byte and id have been regrouped. -- OG */
|
|
281 #define CHARSET_ID(cs) ((cs)->id)
|
867
|
282 #define CHARSET_LEADING_BYTE(cs) ((Ibyte) CHARSET_ID (cs))
|
771
|
283 #define CHARSET_NAME(cs) ((cs)->name)
|
|
284 #define CHARSET_SHORT_NAME(cs) ((cs)->short_name)
|
|
285 #define CHARSET_LONG_NAME(cs) ((cs)->long_name)
|
|
286 #define CHARSET_REP_BYTES(cs) ((cs)->rep_bytes)
|
|
287 #define CHARSET_COLUMNS(cs) ((cs)->columns)
|
|
288 #define CHARSET_GRAPHIC(cs) ((cs)->graphic)
|
|
289 #define CHARSET_TYPE(cs) ((cs)->type)
|
|
290 #define CHARSET_DIRECTION(cs) ((cs)->direction)
|
|
291 #define CHARSET_FINAL(cs) ((cs)->final)
|
|
292 #define CHARSET_DOC_STRING(cs) ((cs)->doc_string)
|
|
293 #define CHARSET_REGISTRY(cs) ((cs)->registry)
|
|
294 #define CHARSET_CCL_PROGRAM(cs) ((cs)->ccl_program)
|
|
295 #define CHARSET_DIMENSION(cs) ((cs)->dimension)
|
|
296 #define CHARSET_CHARS(cs) ((cs)->chars)
|
|
297 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
|
|
298 #define CHARSET_TO_UNICODE_TABLE(cs) ((cs)->to_unicode_table)
|
|
299 #define CHARSET_FROM_UNICODE_TABLE(cs) ((cs)->from_unicode_table)
|
|
300 #define CHARSET_FROM_UNICODE_LEVELS(cs) ((cs)->from_unicode_levels)
|
|
301
|
|
302
|
826
|
303 #define CHARSET_PRIVATE_P(cs) leading_byte_private_p (CHARSET_LEADING_BYTE (cs))
|
771
|
304
|
|
305 #define XCHARSET_ID(cs) CHARSET_ID (XCHARSET (cs))
|
|
306 #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs))
|
|
307 #define XCHARSET_SHORT_NAME(cs) CHARSET_SHORT_NAME (XCHARSET (cs))
|
|
308 #define XCHARSET_LONG_NAME(cs) CHARSET_LONG_NAME (XCHARSET (cs))
|
|
309 #define XCHARSET_REP_BYTES(cs) CHARSET_REP_BYTES (XCHARSET (cs))
|
|
310 #define XCHARSET_COLUMNS(cs) CHARSET_COLUMNS (XCHARSET (cs))
|
|
311 #define XCHARSET_GRAPHIC(cs) CHARSET_GRAPHIC (XCHARSET (cs))
|
|
312 #define XCHARSET_TYPE(cs) CHARSET_TYPE (XCHARSET (cs))
|
|
313 #define XCHARSET_DIRECTION(cs) CHARSET_DIRECTION (XCHARSET (cs))
|
|
314 #define XCHARSET_FINAL(cs) CHARSET_FINAL (XCHARSET (cs))
|
|
315 #define XCHARSET_DOC_STRING(cs) CHARSET_DOC_STRING (XCHARSET (cs))
|
|
316 #define XCHARSET_REGISTRY(cs) CHARSET_REGISTRY (XCHARSET (cs))
|
|
317 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
|
|
318 #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs))
|
|
319 #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs))
|
|
320 #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs))
|
|
321 #define XCHARSET_PRIVATE_P(cs) CHARSET_PRIVATE_P (XCHARSET (cs))
|
|
322 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
|
|
323 CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
|
|
324 #define XCHARSET_TO_UNICODE_TABLE(cs) \
|
|
325 CHARSET_TO_UNICODE_TABLE (XCHARSET (cs))
|
|
326 #define XCHARSET_FROM_UNICODE_TABLE(cs) \
|
|
327 CHARSET_FROM_UNICODE_TABLE (XCHARSET (cs))
|
|
328 #define XCHARSET_FROM_UNICODE_LEVELS(cs) \
|
|
329 CHARSET_FROM_UNICODE_LEVELS (XCHARSET (cs))
|
|
330
|
|
331 struct charset_lookup
|
|
332 {
|
|
333 /* Table of charsets indexed by leading byte. */
|
|
334 Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
|
|
335
|
|
336 /* Table of charsets indexed by type/final-byte/direction. */
|
|
337 Lisp_Object charset_by_attributes[4][128][2];
|
867
|
338 Ibyte next_allocated_1_byte_leading_byte;
|
|
339 Ibyte next_allocated_2_byte_leading_byte;
|
771
|
340 };
|
|
341
|
1111
|
342 extern struct charset_lookup *chlook;
|
|
343
|
826
|
344 DECLARE_INLINE_HEADER (
|
|
345 Lisp_Object
|
|
346 charset_by_leading_byte (int lb)
|
|
347 )
|
771
|
348 {
|
800
|
349 #ifdef ERROR_CHECK_TEXT
|
771
|
350 /* When error-checking is on, x86 GCC 2.95.2 -O3 miscompiles the
|
|
351 following unless we introduce `tem'. */
|
|
352 int tem = lb;
|
800
|
353 text_checking_assert (tem >= MIN_LEADING_BYTE && tem <= 0xFF);
|
771
|
354 #endif
|
|
355 return chlook->charset_by_leading_byte[lb - MIN_LEADING_BYTE];
|
|
356 }
|
|
357
|
826
|
358 DECLARE_INLINE_HEADER (
|
|
359 Lisp_Object
|
|
360 charset_by_attributes (int type, int final, int dir)
|
|
361 )
|
771
|
362 {
|
|
363 type_checking_assert (type < countof (chlook->charset_by_attributes) &&
|
|
364 final < countof (chlook->charset_by_attributes[0]) &&
|
|
365 dir < countof (chlook->charset_by_attributes[0][0]));
|
|
366 return chlook->charset_by_attributes[type][final][dir];
|
|
367 }
|
|
368
|
|
369
|
|
370 /************************************************************************/
|
|
371 /* Dealing with characters */
|
|
372 /************************************************************************/
|
|
373
|
|
374 /* The bit fields of character are divided into 3 parts:
|
|
375 FIELD1(5bits):FIELD2(7bits):FIELD3(7bits) */
|
|
376
|
867
|
377 #define ICHAR_FIELD1_MASK (0x1F << 14)
|
|
378 #define ICHAR_FIELD2_MASK (0x7F << 7)
|
|
379 #define ICHAR_FIELD3_MASK 0x7F
|
771
|
380
|
|
381 /* Macros to access each field of a character code of C. */
|
|
382
|
867
|
383 #define ichar_field1(c) (((c) & ICHAR_FIELD1_MASK) >> 14)
|
|
384 #define ichar_field2(c) (((c) & ICHAR_FIELD2_MASK) >> 7)
|
|
385 #define ichar_field3(c) ((c) & ICHAR_FIELD3_MASK)
|
771
|
386
|
|
387 /* Field 1, if non-zero, usually holds a leading byte for a
|
|
388 dimension-2 charset. Field 2, if non-zero, usually holds a leading
|
|
389 byte for a dimension-1 charset. */
|
|
390
|
|
391 /* Converting between field values and leading bytes. */
|
|
392
|
|
393 #define FIELD2_TO_OFFICIAL_LEADING_BYTE (MIN_LEADING_BYTE_OFFICIAL_1 - 1)
|
|
394 #define FIELD2_TO_PRIVATE_LEADING_BYTE 0x80
|
|
395
|
|
396 #define FIELD1_TO_OFFICIAL_LEADING_BYTE (MIN_LEADING_BYTE_OFFICIAL_2 - 1)
|
|
397 #define FIELD1_TO_PRIVATE_LEADING_BYTE 0xE1
|
|
398
|
|
399 /* Minimum and maximum allowed values for the fields. */
|
|
400
|
867
|
401 #define MIN_ICHAR_FIELD2_OFFICIAL \
|
771
|
402 (MIN_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
|
867
|
403 #define MAX_ICHAR_FIELD2_OFFICIAL \
|
771
|
404 (MAX_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
|
|
405
|
867
|
406 #define MIN_ICHAR_FIELD1_OFFICIAL \
|
771
|
407 (MIN_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
|
867
|
408 #define MAX_ICHAR_FIELD1_OFFICIAL \
|
771
|
409 (MAX_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
|
|
410
|
867
|
411 #define MIN_ICHAR_FIELD2_PRIVATE \
|
771
|
412 (MIN_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
|
867
|
413 #define MAX_ICHAR_FIELD2_PRIVATE \
|
771
|
414 (MAX_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
|
|
415
|
867
|
416 #define MIN_ICHAR_FIELD1_PRIVATE \
|
771
|
417 (MIN_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
|
867
|
418 #define MAX_ICHAR_FIELD1_PRIVATE \
|
771
|
419 (MAX_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
|
|
420
|
|
421 /* Minimum character code of each <type> character. */
|
|
422
|
867
|
423 #define MIN_CHAR_OFFICIAL_TYPE9N (MIN_ICHAR_FIELD2_OFFICIAL << 7)
|
|
424 #define MIN_CHAR_PRIVATE_TYPE9N (MIN_ICHAR_FIELD2_PRIVATE << 7)
|
|
425 #define MIN_CHAR_OFFICIAL_TYPE9NX9N (MIN_ICHAR_FIELD1_OFFICIAL << 14)
|
|
426 #define MIN_CHAR_PRIVATE_TYPE9NX9N (MIN_ICHAR_FIELD1_PRIVATE << 14)
|
771
|
427 #define MIN_CHAR_COMPOSITION (0x1F << 14)
|
|
428
|
|
429 /* Leading byte of a character.
|
|
430
|
|
431 NOTE: This takes advantage of the fact that
|
|
432 FIELD2_TO_OFFICIAL_LEADING_BYTE and
|
|
433 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
|
|
434 */
|
|
435
|
826
|
436 DECLARE_INLINE_HEADER (
|
867
|
437 Ibyte
|
|
438 ichar_leading_byte (Ichar c)
|
826
|
439 )
|
771
|
440 {
|
867
|
441 if (ichar_ascii_p (c))
|
771
|
442 return LEADING_BYTE_ASCII;
|
|
443 else if (c < 0xA0)
|
|
444 return LEADING_BYTE_CONTROL_1;
|
|
445 else if (c < MIN_CHAR_OFFICIAL_TYPE9NX9N)
|
867
|
446 return ichar_field2 (c) + FIELD2_TO_OFFICIAL_LEADING_BYTE;
|
771
|
447 else if (c < MIN_CHAR_PRIVATE_TYPE9NX9N)
|
867
|
448 return ichar_field1 (c) + FIELD1_TO_OFFICIAL_LEADING_BYTE;
|
771
|
449 else if (c < MIN_CHAR_COMPOSITION)
|
867
|
450 return ichar_field1 (c) + FIELD1_TO_PRIVATE_LEADING_BYTE;
|
771
|
451 else
|
|
452 {
|
|
453 #ifdef ENABLE_COMPOSITE_CHARS
|
|
454 return LEADING_BYTE_COMPOSITE;
|
|
455 #else
|
|
456 abort();
|
|
457 return 0;
|
|
458 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
459 }
|
|
460 }
|
|
461
|
826
|
462 DECLARE_INLINE_HEADER (
|
|
463 Bytecount
|
867
|
464 ichar_len (Ichar c)
|
826
|
465 )
|
|
466 {
|
867
|
467 if (ichar_ascii_p (c))
|
826
|
468 return 1;
|
|
469 else if (c < MIN_CHAR_OFFICIAL_TYPE9NX9N)
|
|
470 return 2;
|
|
471 else if (c < MIN_CHAR_PRIVATE_TYPE9NX9N)
|
|
472 return 3; /* dimension-2 official or dimension-1 private */
|
|
473 else if (c < MIN_CHAR_COMPOSITION)
|
|
474 return 4;
|
|
475 else
|
|
476 {
|
|
477 #ifdef ENABLE_COMPOSITE_CHARS
|
|
478 #error Not yet implemented
|
|
479 #else
|
|
480 abort();
|
|
481 return 0;
|
|
482 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
483 }
|
|
484 }
|
|
485
|
|
486 DECLARE_INLINE_HEADER (
|
|
487 Bytecount
|
867
|
488 ichar_len_fmt (Ichar c, Internal_Format fmt)
|
826
|
489 )
|
|
490 {
|
|
491 switch (fmt)
|
|
492 {
|
|
493 case FORMAT_DEFAULT:
|
867
|
494 return ichar_len (c);
|
826
|
495 case FORMAT_16_BIT_FIXED:
|
|
496 return 2;
|
|
497 case FORMAT_32_BIT_FIXED:
|
|
498 return 4;
|
|
499 default:
|
|
500 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
|
501 return 1;
|
|
502 }
|
|
503 }
|
|
504
|
867
|
505 #define ichar_charset(c) charset_by_leading_byte (ichar_leading_byte (c))
|
771
|
506
|
|
507 /* Return a character whose charset is CHARSET and position-codes are C1
|
|
508 and C2. TYPE9N character ignores C2. (For typical charsets, i.e. not
|
|
509 ASCII, Control-1 or Composite, C1 and C2 will be in the range of 32 to
|
|
510 127 or 33 to 126. See `make-char'.)
|
|
511
|
|
512 NOTE: This takes advantage of the fact that
|
|
513 FIELD2_TO_OFFICIAL_LEADING_BYTE and
|
|
514 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
|
|
515 */
|
|
516
|
826
|
517 DECLARE_INLINE_HEADER (
|
867
|
518 Ichar
|
|
519 make_ichar (Lisp_Object charset, int c1, int c2)
|
826
|
520 )
|
771
|
521 {
|
867
|
522 Ichar retval;
|
771
|
523 if (EQ (charset, Vcharset_ascii))
|
826
|
524 retval = c1;
|
771
|
525 else if (EQ (charset, Vcharset_control_1))
|
826
|
526 retval = c1 | 0x80;
|
771
|
527 #ifdef ENABLE_COMPOSITE_CHARS
|
|
528 else if (EQ (charset, Vcharset_composite))
|
826
|
529 retval = (0x1F << 14) | ((c1) << 7) | (c2);
|
771
|
530 #endif
|
|
531 else if (XCHARSET_DIMENSION (charset) == 1)
|
826
|
532 retval = ((XCHARSET_LEADING_BYTE (charset) -
|
|
533 FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) | (c1);
|
771
|
534 else if (!XCHARSET_PRIVATE_P (charset))
|
826
|
535 retval = ((XCHARSET_LEADING_BYTE (charset) -
|
|
536 FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
|
771
|
537 else
|
826
|
538 retval = ((XCHARSET_LEADING_BYTE (charset) -
|
|
539 FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
|
867
|
540 text_checking_assert (valid_ichar_p (retval));
|
826
|
541 return retval;
|
771
|
542 }
|
|
543
|
867
|
544 /* BREAKUP_ICHAR_1_UNSAFE assumes that the charset has already been
|
771
|
545 calculated, and just computes c1 and c2.
|
|
546
|
867
|
547 BREAKUP_ICHAR also computes and stores the charset. */
|
771
|
548
|
867
|
549 #define BREAKUP_ICHAR_1_UNSAFE(c, charset, c1, c2) \
|
771
|
550 XCHARSET_DIMENSION (charset) == 1 \
|
867
|
551 ? ((c1) = ichar_field3 (c), (c2) = 0) \
|
|
552 : ((c1) = ichar_field2 (c), \
|
|
553 (c2) = ichar_field3 (c))
|
771
|
554
|
826
|
555 DECLARE_INLINE_HEADER (
|
|
556 void
|
867
|
557 breakup_ichar_1 (Ichar c, Lisp_Object *charset, int *c1, int *c2)
|
826
|
558 )
|
771
|
559 {
|
867
|
560 text_checking_assert (valid_ichar_p (c));
|
|
561 *charset = ichar_charset (c);
|
|
562 BREAKUP_ICHAR_1_UNSAFE (c, *charset, *c1, *c2);
|
771
|
563 }
|
|
564
|
867
|
565 /* BREAKUP_ICHAR separates an Ichar into its components. The charset of
|
771
|
566 character C is set to CHARSET, and the position-codes of C are set to C1
|
|
567 and C2. C2 of TYPE9N character is 0. */
|
|
568
|
867
|
569 #define BREAKUP_ICHAR(c, charset, c1, c2) \
|
|
570 breakup_ichar_1 (c, &(charset), &(c1), &(c2))
|
771
|
571
|
788
|
572 void get_charset_limits (Lisp_Object charset, int *low, int *high);
|
867
|
573 int ichar_to_unicode (Ichar chr);
|
788
|
574
|
771
|
575 #endif /* MULE */
|
|
576
|
|
577 #endif /* INCLUDED_charset_h_ */
|