Mercurial > emacs
annotate src/character.h @ 88987:4e77456fab6c
(nonascii_insert_offset, Vnonascii_translation_table):
Extern deleted.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 15 Aug 2002 02:29:16 +0000 |
parents | 233c080b5756 |
children | a9f683a73092 |
rev | line source |
---|---|
88363 | 1 /* Header for multibyte character handler. |
2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. | |
3 Licensed to the Free Software Foundation. | |
4 Copyright (C) 2001, 2002 | |
5 National Institute of Advanced Industrial Science and Technology (AIST) | |
6 Registration Number H13PRO009 | |
7 | |
8 This file is part of GNU Emacs. | |
9 | |
10 GNU Emacs is free software; you can redistribute it and/or modify | |
11 it under the terms of the GNU General Public License as published by | |
12 the Free Software Foundation; either version 2, or (at your option) | |
13 any later version. | |
14 | |
15 GNU Emacs is distributed in the hope that it will be useful, | |
16 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 GNU General Public License for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with GNU Emacs; see the file COPYING. If not, write to | |
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 Boston, MA 02111-1307, USA. */ | |
24 | |
25 #ifndef EMACS_CHARACTER_H | |
26 #define EMACS_CHARACTER_H | |
27 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
28 /* character code 1st byte byte sequence |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
29 -------------- -------- ------------- |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
30 0-7F 00..7F 0xxxxxxx |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
31 80-7FF C2..DF 110xxxxx 10xxxxxx |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
32 800-FFFF E0..EF 1110xxxx 10xxxxxx 10xxxxxx |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
33 10000-1FFFFF F0..F7 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
34 200000-3FFF7F F8 11111000 1000xxxx 10xxxxxx 10xxxxxx 10xxxxxx |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
35 invalid F9..FF |
88363 | 36 |
37 raw-8-bit | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
38 3FFF80-3FFFFF C0..C1 1100000x 10xxxxxx |
88363 | 39 */ |
40 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
41 /* Maximum character code ((1 << CHARACTERBITS) - 1). */ |
88363 | 42 #define MAX_CHAR 0x3FFFFF |
43 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
44 /* Maximum Unicode character code. */ |
88363 | 45 #define MAX_UNICODE_CHAR 0x10FFFF |
46 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
47 /* Maximum N-byte character codes. */ |
88363 | 48 #define MAX_1_BYTE_CHAR 0x7F |
49 #define MAX_2_BYTE_CHAR 0x7FF | |
50 #define MAX_3_BYTE_CHAR 0xFFFF | |
51 #define MAX_4_BYTE_CHAR 0x1FFFFF | |
52 #define MAX_5_BYTE_CHAR 0x3FFF7F | |
53 | |
88946
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
54 /* Nonzero iff C is a character that corresponds to a raw 8-bit |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
55 byte. */ |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
56 #define CHAR_BYTE8_P(c) ((c) > MAX_5_BYTE_CHAR) |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
57 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
58 /* Return the character code for raw 8-bit byte BYTE. */ |
88363 | 59 #define BYTE8_TO_CHAR(byte) ((byte) + 0x3FFF00) |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
60 |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
61 /* Return the raw 8-bit byte for character C. */ |
88946
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
62 #define CHAR_TO_BYTE8(c) \ |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
63 (CHAR_BYTE8_P (c) \ |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
64 ? (c) - 0x3FFF00 \ |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
65 : multibyte_char_to_unibyte (c, Qnil)) |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
66 |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
67 /* Nonzero iff BYTE is the 1st byte of a multibyte form of a character |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
68 that corresponds to a raw 8-bit byte. */ |
88363 | 69 #define CHAR_BYTE8_HEAD_P(byte) ((byte) == 0xC0 || (byte) == 0xC1) |
70 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
71 /* This is the maximum byte length of multibyte form. */ |
88363 | 72 #define MAX_MULTIBYTE_LENGTH 5 |
73 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
74 /* Return a Lisp character whose character code is C. */ |
88363 | 75 #define make_char(c) make_number (c) |
76 | |
77 /* Nonzero iff C is an ASCII byte. */ | |
78 #define ASCII_BYTE_P(c) ((unsigned) (c) < 0x80) | |
79 | |
80 /* Nonzero iff X is a character. */ | |
81 #define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR) | |
82 | |
88832 | 83 /* Nonzero iff C is valid as a character code. GENERICP is not used |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
84 now. */ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
85 #define CHAR_VALID_P(c, genericp) ((unsigned) (c) <= MAX_CHAR) |
88363 | 86 |
87 /* Check if Lisp object X is a character or not. */ | |
88 #define CHECK_CHARACTER(x) \ | |
89 do { \ | |
90 if (! CHARACTERP(x)) x = wrong_type_argument (Qcharacterp, (x)); \ | |
91 } while (0) | |
92 | |
93 /* Nonzero iff C is an ASCII character. */ | |
94 #define ASCII_CHAR_P(c) ((unsigned) (c) < 0x80) | |
95 | |
96 /* Nonzero iff C is a character of code less than 0x100. */ | |
97 #define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100) | |
98 | |
99 /* Nonzero if character C has a printable glyph. */ | |
100 #define CHAR_PRINTABLE_P(c) \ | |
101 (((c) >= 32 && ((c) < 127) \ | |
102 || ! NILP (CHAR_TABLE_REF (Vprintable_chars, (c))))) | |
103 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
104 /* Return byte length of multibyte form for character C. */ |
88363 | 105 #define CHAR_BYTES(c) \ |
106 ( (c) <= MAX_1_BYTE_CHAR ? 1 \ | |
107 : (c) <= MAX_2_BYTE_CHAR ? 2 \ | |
108 : (c) <= MAX_3_BYTE_CHAR ? 3 \ | |
109 : (c) <= MAX_4_BYTE_CHAR ? 4 \ | |
110 : (c) <= MAX_5_BYTE_CHAR ? 5 \ | |
111 : 2) | |
112 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
113 /* Store multibyte form of the character C in P. The caller should |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
114 allocate at least MAX_MULTIBYTE_LENGTH bytes area at P in advance. |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
115 Returns the length of the multibyte form. */ |
88363 | 116 |
117 #define CHAR_STRING(c, p) \ | |
118 ((unsigned) (c) <= MAX_1_BYTE_CHAR \ | |
119 ? ((p)[0] = (c), \ | |
120 1) \ | |
121 : (unsigned) (c) <= MAX_2_BYTE_CHAR \ | |
122 ? ((p)[0] = (0xC0 | ((c) >> 6)), \ | |
123 (p)[1] = (0x80 | ((c) & 0x3F)), \ | |
124 2) \ | |
125 : (unsigned) (c) <= MAX_3_BYTE_CHAR \ | |
126 ? ((p)[0] = (0xE0 | ((c) >> 12)), \ | |
127 (p)[1] = (0x80 | (((c) >> 6) & 0x3F)), \ | |
128 (p)[2] = (0x80 | ((c) & 0x3F)), \ | |
129 3) \ | |
130 : (unsigned) (c) <= MAX_5_BYTE_CHAR \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
131 ? char_string_with_unification (c, p) \ |
88363 | 132 : ((p)[0] = (0xC0 | (((c) >> 6) & 0x01)), \ |
133 (p)[1] = (0x80 | ((c) & 0x3F)), \ | |
134 2)) | |
135 | |
136 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
137 /* Store multibyte form of the character C in P. The caller should |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
138 allocate at least MAX_MULTIBYTE_LENGTH bytes area at P in advance. |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
139 And, advance P to the end of the multibyte form. */ |
88363 | 140 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
141 #define CHAR_STRING_ADVANCE(c, p) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
142 do { \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
143 if ((c) <= MAX_1_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
144 *(p)++ = (c); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
145 else if ((c) <= MAX_2_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
146 *(p)++ = (0xC0 | ((c) >> 6)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
147 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
148 else if ((c) <= MAX_3_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
149 *(p)++ = (0xE0 | ((c) >> 12)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
150 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
151 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
152 else if ((c) <= MAX_5_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
153 (p) += char_string_with_unification ((c), (p)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
154 else \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
155 *(p)++ = (0xC0 | (((c) >> 6) & 0x01)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
156 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
157 } while (0) |
88363 | 158 |
159 /* Nonzero iff BYTE starts a non-ASCII character in a multibyte | |
160 form. */ | |
161 #define LEADING_CODE_P(byte) (((byte) & 0xC0) == 0xC0) | |
162 | |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
163 /* Nonzero iff BYTE is a trailing code of a non-ASCII character in a |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
164 multibyte form. */ |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
165 #define TRAILING_CODE_P(byte) (((byte) & 0xC0) == 0x80) |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
166 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
167 /* Nonzero iff BYTE starts a character in a multibyte form. |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
168 This is equivalent to: |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
169 (ASCII_BYTE_P (byte) || LEADING_CODE_P (byte)) */ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
170 #define CHAR_HEAD_P(byte) (((byte) & 0xC0) != 0x80) |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
171 |
88363 | 172 /* Just kept for backward compatibility. This macro will be removed |
173 in the future. */ | |
174 #define BASE_LEADING_CODE_P LEADING_CODE_P | |
175 | |
176 /* How many bytes a character that starts with BYTE occupies in a | |
177 multibyte form. */ | |
178 #define BYTES_BY_CHAR_HEAD(byte) \ | |
179 (!((byte) & 0x80) ? 1 \ | |
180 : !((byte) & 0x20) ? 2 \ | |
181 : !((byte) & 0x10) ? 3 \ | |
182 : !((byte) & 0x08) ? 4 \ | |
183 : 5) | |
184 | |
185 | |
186 /* Return the length of the multi-byte form at string STR of length | |
187 LEN while assuming that STR points a valid multi-byte form. As | |
188 this macro isn't necessary anymore, all callers will be changed to | |
189 use BYTES_BY_CHAR_HEAD directly in the future. */ | |
190 | |
191 #define MULTIBYTE_FORM_LENGTH(str, len) \ | |
192 BYTES_BY_CHAR_HEAD (*(str)) | |
193 | |
194 /* Parse multibyte string STR of length LENGTH and set BYTES to the | |
195 byte length of a character at STR while assuming that STR points a | |
196 valid multibyte form. As this macro isn't necessary anymore, all | |
197 callers will be changed to use BYTES_BY_CHAR_HEAD directly in the | |
198 future. */ | |
199 | |
200 #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ | |
201 (bytes) = BYTES_BY_CHAR_HEAD (*(str)) | |
202 | |
203 /* The byte length of multibyte form at unibyte string P ending at | |
204 PEND. If STR doesn't point a valid multibyte form, return 0. */ | |
205 | |
206 #define MULTIBYTE_LENGTH(p, pend) \ | |
207 (p >= pend ? 0 \ | |
208 : !((p)[0] & 0x80) ? 1 \ | |
209 : ((p + 1 >= pend) || (((p)[1] & 0xC0) != 0x80)) ? 0 \ | |
210 : ((p)[0] & 0xE0) == 0xC0 ? 2 \ | |
211 : ((p + 2 >= pend) || (((p)[2] & 0xC0) != 0x80)) ? 0 \ | |
212 : ((p)[0] & 0xF0) == 0xE0 ? 3 \ | |
213 : ((p + 3 >= pend) || (((p)[3] & 0xC0) != 0x80)) ? 0 \ | |
214 : ((p)[0] & 0xF8) == 0xF0 ? 4 \ | |
215 : ((p + 4 >= pend) || (((p)[4] & 0xC0) != 0x80)) ? 0 \ | |
216 : (p)[0] == 0xF8 && ((p)[1] & 0xF0) == 0x80 ? 5 \ | |
217 : 0) | |
218 | |
219 | |
220 /* Like MULTIBYTE_LENGTH but don't check the ending address. */ | |
221 | |
222 #define MULTIBYTE_LENGTH_NO_CHECK(p) \ | |
223 (!((p)[0] & 0x80) ? 1 \ | |
224 : ((p)[1] & 0xC0) != 0x80 ? 0 \ | |
225 : ((p)[0] & 0xE0) == 0xC0 ? 2 \ | |
226 : ((p)[2] & 0xC0) != 0x80 ? 0 \ | |
227 : ((p)[0] & 0xF0) == 0xE0 ? 3 \ | |
228 : ((p)[3] & 0xC0) != 0x80 ? 0 \ | |
229 : ((p)[0] & 0xF8) == 0xF0 ? 4 \ | |
230 : ((p)[4] & 0xC0) != 0x80 ? 0 \ | |
231 : (p)[0] == 0xF8 && ((p)[1] & 0xF0) == 0x80 ? 5 \ | |
232 : 0) | |
233 | |
234 | |
235 /* Return the character code of character whose multibyte form is at | |
236 P. The argument LEN is ignored. It will be removed in the | |
237 future. */ | |
238 | |
239 #define STRING_CHAR(p, len) \ | |
240 (!((p)[0] & 0x80) \ | |
241 ? (p)[0] \ | |
242 : ! ((p)[0] & 0x20) \ | |
243 ? (((((p)[0] & 0x1F) << 6) \ | |
244 | ((p)[1] & 0x3F)) \ | |
245 + (((unsigned char) (p)[0]) < 0xC2 ? 0x3FFF80 : 0)) \ | |
246 : ! ((p)[0] & 0x10) \ | |
247 ? ((((p)[0] & 0x0F) << 12) \ | |
248 | (((p)[1] & 0x3F) << 6) \ | |
249 | ((p)[2] & 0x3F)) \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
250 : string_char_with_unification ((p), NULL, NULL)) |
88363 | 251 |
252 | |
253 /* Like STRING_CHAR but set ACTUAL_LEN to the length of multibyte | |
254 form. The argument LEN is ignored. It will be removed in the | |
255 future. */ | |
256 | |
257 #define STRING_CHAR_AND_LENGTH(p, len, actual_len) \ | |
258 (!((p)[0] & 0x80) \ | |
259 ? ((actual_len) = 1, (p)[0]) \ | |
260 : ! ((p)[0] & 0x20) \ | |
261 ? ((actual_len) = 2, \ | |
262 (((((p)[0] & 0x1F) << 6) \ | |
263 | ((p)[1] & 0x3F)) \ | |
264 + (((unsigned char) (p)[0]) < 0xC2 ? 0x3FFF80 : 0))) \ | |
265 : ! ((p)[0] & 0x10) \ | |
266 ? ((actual_len) = 3, \ | |
267 ((((p)[0] & 0x0F) << 12) \ | |
268 | (((p)[1] & 0x3F) << 6) \ | |
269 | ((p)[2] & 0x3F))) \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
270 : string_char_with_unification ((p), NULL, &actual_len)) |
88363 | 271 |
272 | |
273 /* Like STRING_CHAR but advacen P to the end of multibyte form. */ | |
274 | |
275 #define STRING_CHAR_ADVANCE(p) \ | |
276 (!((p)[0] & 0x80) \ | |
277 ? *(p)++ \ | |
278 : ! ((p)[0] & 0x20) \ | |
279 ? ((p) += 2, \ | |
280 ((((p)[-2] & 0x1F) << 6) \ | |
281 | ((p)[-1] & 0x3F) \ | |
282 | (((unsigned char) (p)[-2]) < 0xC2 ? 0x3FFF80 : 0))) \ | |
283 : ! ((p)[0] & 0x10) \ | |
284 ? ((p) += 3, \ | |
285 ((((p)[-3] & 0x0F) << 12) \ | |
286 | (((p)[-2] & 0x3F) << 6) \ | |
287 | ((p)[-1] & 0x3F))) \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
288 : string_char_with_unification ((p), &(p), NULL)) |
88363 | 289 |
290 | |
291 /* Fetch the "next" character from Lisp string STRING at byte position | |
292 BYTEIDX, character position CHARIDX. Store it into OUTPUT. | |
293 | |
294 All the args must be side-effect-free. | |
295 BYTEIDX and CHARIDX must be lvalues; | |
296 we increment them past the character fetched. */ | |
297 | |
298 #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
299 if (1) \ | |
300 { \ | |
301 CHARIDX++; \ | |
302 if (STRING_MULTIBYTE (STRING)) \ | |
303 { \ | |
304 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
305 int len; \ | |
306 \ | |
307 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
308 BYTEIDX += len; \ | |
309 } \ | |
310 else \ | |
311 OUTPUT = XSTRING (STRING)->data[BYTEIDX++]; \ | |
312 } \ | |
313 else | |
314 | |
315 | |
316 /* Like FETCH_STRING_CHAR_ADVANCE but assumes STRING is multibyte. */ | |
317 | |
318 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
319 if (1) \ | |
320 { \ | |
321 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
322 int len; \ | |
323 \ | |
324 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
325 BYTEIDX += len; \ | |
326 CHARIDX++; \ | |
327 } \ | |
328 else | |
329 | |
330 | |
331 /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current | |
332 buffer. */ | |
333 | |
334 #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX) \ | |
335 if (1) \ | |
336 { \ | |
337 CHARIDX++; \ | |
338 if (!NILP (current_buffer->enable_multibyte_characters)) \ | |
339 { \ | |
340 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
341 int len; \ | |
342 \ | |
343 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
344 BYTEIDX += len; \ | |
345 } \ | |
346 else \ | |
347 { \ | |
348 OUTPUT = *(BYTE_POS_ADDR (BYTEIDX)); \ | |
349 BYTEIDX++; \ | |
350 } \ | |
351 } \ | |
352 else | |
353 | |
354 | |
355 /* Like FETCH_CHAR_ADVANCE but assumes STRING is multibyte. */ | |
356 | |
357 #define FETCH_CHAR_ADVANCE_NO_CHECK(OUTPUT, CHARIDX, BYTEIDX) \ | |
358 if (1) \ | |
359 { \ | |
360 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
361 int len; \ | |
362 \ | |
363 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
364 BYTEIDX += len; \ | |
365 CHARIDX++; \ | |
366 } \ | |
367 else | |
368 | |
369 | |
370 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
371 the next character boundary. No range checking of POS. */ | |
372 | |
373 #define INC_POS(pos_byte) \ | |
374 do { \ | |
375 unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
376 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
377 } while (0) | |
378 | |
379 | |
380 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
381 the previous character boundary. No range checking of POS. */ | |
382 | |
383 #define DEC_POS(pos_byte) \ | |
384 do { \ | |
385 unsigned char *p; \ | |
386 \ | |
387 pos_byte--; \ | |
388 if (pos_byte < GPT_BYTE) \ | |
389 p = BEG_ADDR + pos_byte - 1; \ | |
390 else \ | |
391 p = BEG_ADDR + GAP_SIZE + pos_byte - 1; \ | |
392 while (!CHAR_HEAD_P (*p)) \ | |
393 { \ | |
394 p--; \ | |
395 pos_byte--; \ | |
396 } \ | |
397 } while (0) | |
398 | |
399 /* Increment both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
400 | |
401 #define INC_BOTH(charpos, bytepos) \ | |
402 do \ | |
403 { \ | |
404 (charpos)++; \ | |
405 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
406 (bytepos)++; \ | |
407 else \ | |
408 INC_POS ((bytepos)); \ | |
409 } \ | |
410 while (0) | |
411 | |
412 | |
413 /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
414 | |
415 #define DEC_BOTH(charpos, bytepos) \ | |
416 do \ | |
417 { \ | |
418 (charpos)--; \ | |
419 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
420 (bytepos)--; \ | |
421 else \ | |
422 DEC_POS ((bytepos)); \ | |
423 } \ | |
424 while (0) | |
425 | |
426 | |
427 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
428 the next character boundary. This macro relies on the fact that | |
429 *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
430 '\0'. No range checking of POS_BYTE. */ | |
431 | |
432 #define BUF_INC_POS(buf, pos_byte) \ | |
433 do { \ | |
434 unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
435 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
436 } while (0) | |
437 | |
438 | |
439 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
440 the previous character boundary. No range checking of POS_BYTE. */ | |
441 | |
442 #define BUF_DEC_POS(buf, pos_byte) \ | |
443 do { \ | |
444 unsigned char *p; \ | |
445 pos_byte--; \ | |
446 if (pos_byte < BUF_GPT_BYTE (buf)) \ | |
447 p = BUF_BEG_ADDR (buf) + pos_byte - 1; \ | |
448 else \ | |
449 p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - 1; \ | |
450 while (!CHAR_HEAD_P (*p)) \ | |
451 { \ | |
452 p--; \ | |
453 pos_byte--; \ | |
454 } \ | |
455 } while (0) | |
456 | |
457 | |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
458 #define MAYBE_UNIFY_CHAR(c) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
459 if (CHAR_TABLE_P (Vchar_unify_table)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
460 { \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
461 Lisp_Object val; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
462 int unified; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
463 \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
464 val = CHAR_TABLE_REF (Vchar_unify_table, c); \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
465 if (! NILP (val)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
466 { \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
467 if (SYMBOLP (val)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
468 { \ |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
469 Funify_charset (val, Qnil, Qnil); \ |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
470 val = CHAR_TABLE_REF (Vchar_unify_table, c); \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
471 } \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
472 if ((unified = XINT (val)) >= 0) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
473 c = unified; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
474 } \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
475 } \ |
88363 | 476 else |
477 | |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
478 |
88363 | 479 /* Return the width of ASCII character C. The width is measured by |
480 how many columns occupied on the screen when displayed in the | |
481 current buffer. */ | |
482 | |
483 #define ASCII_CHAR_WIDTH(c) \ | |
484 (c < 0x20 \ | |
485 ? (c == '\t' \ | |
486 ? XFASTINT (current_buffer->tab_width) \ | |
487 : (c == '\n' ? 0 : (NILP (current_buffer->ctl_arrow) ? 4 : 2))) \ | |
488 : (c < 0x7f \ | |
489 ? 1 \ | |
490 : ((NILP (current_buffer->ctl_arrow) ? 4 : 2)))) | |
491 | |
492 /* Return the width of character C. The width is measured by how many | |
493 columns occupied on the screen when displayed in the current | |
494 buffer. */ | |
495 | |
496 #define CHAR_WIDTH(c) \ | |
497 (ASCII_CHAR_P (c) \ | |
498 ? ASCII_CHAR_WIDTH (c) \ | |
499 : XINT (CHAR_TABLE_REF (Vchar_width_table, c))) | |
500 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
501 extern int char_string_with_unification P_ ((int, unsigned char *)); |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
502 extern int string_char_with_unification P_ ((const unsigned char *, |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
503 const unsigned char **, int *)); |
88363 | 504 |
505 extern int translate_char P_ ((Lisp_Object, int c)); | |
506 extern int char_printable_p P_ ((int c)); | |
507 extern void parse_str_as_multibyte P_ ((unsigned char *, int, int *, int *)); | |
508 extern int parse_str_to_multibyte P_ ((unsigned char *, int)); | |
509 extern int str_as_multibyte P_ ((unsigned char *, int, int, int *)); | |
510 extern int str_to_multibyte P_ ((unsigned char *, int, int)); | |
511 extern int str_as_unibyte P_ ((unsigned char *, int)); | |
512 extern int strwidth P_ ((unsigned char *, int)); | |
513 extern int c_string_width P_ ((unsigned char *, int, int, int *, int *)); | |
514 extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *)); | |
515 | |
516 extern Lisp_Object Vprintable_chars; | |
517 | |
518 extern Lisp_Object Qcharacterp, Qauto_fill_chars; | |
519 extern Lisp_Object Vtranslation_table_vector; | |
520 extern Lisp_Object Vchar_width_table; | |
521 extern Lisp_Object Vchar_direction_table; | |
522 extern Lisp_Object Vchar_unify_table; | |
523 | |
88545 | 524 extern Lisp_Object string_escape_byte8 P_ ((Lisp_Object)); |
525 | |
88363 | 526 /* Return a translation table of id number ID. */ |
527 #define GET_TRANSLATION_TABLE(id) \ | |
528 (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)])) | |
529 | |
530 /* A char-table for characters which may invoke auto-filling. */ | |
531 extern Lisp_Object Vauto_fill_chars; | |
532 | |
88915
94184802d0cc
(Vchar_script_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
88873
diff
changeset
|
533 extern Lisp_Object Vchar_script_table; |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
534 |
88363 | 535 /* Copy LEN bytes from FROM to TO. This macro should be used only |
536 when a caller knows that LEN is short and the obvious copy loop is | |
537 faster than calling bcopy which has some overhead. Copying a | |
538 multibyte sequence of a character is the typical case. */ | |
539 | |
540 #define BCOPY_SHORT(from, to, len) \ | |
541 do { \ | |
542 int i = len; \ | |
543 unsigned char *from_p = from, *to_p = to; \ | |
544 while (i--) *to_p++ = *from_p++; \ | |
545 } while (0) | |
546 | |
547 #define DEFSYM(sym, name) \ | |
548 do { (sym) = intern ((name)); staticpro (&(sym)); } while (0) | |
549 | |
550 #endif /* EMACS_CHARACTER_H */ |