Mercurial > emacs
annotate src/character.h @ 90683:70c40ef3afa5
(mm-mime-mule-charset-alist): Add gbk and GB18030.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 27 Nov 2006 04:37:26 +0000 |
parents | 8a8e69664178 |
children | 0603ad3252c9 |
rev | line source |
---|---|
88363 | 1 /* Header for multibyte character handler. |
2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. | |
89483 | 3 Licensed to the Free Software Foundation. |
90424 | 4 Copyright (C) 2003, 2006 |
88363 | 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 |
89692 | 35 3FFF80-3FFFFF C0..C1 1100000x 10xxxxxx (for eight-bit-char) |
36 400000-... invalid | |
88363 | 37 |
89692 | 38 invalid 1st byte 80..BF 10xxxxxx |
39 F9..FF 11111xxx (xxx != 000) | |
88363 | 40 */ |
41 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
42 /* Maximum character code ((1 << CHARACTERBITS) - 1). */ |
88363 | 43 #define MAX_CHAR 0x3FFFFF |
44 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
45 /* Maximum Unicode character code. */ |
88363 | 46 #define MAX_UNICODE_CHAR 0x10FFFF |
47 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
48 /* Maximum N-byte character codes. */ |
88363 | 49 #define MAX_1_BYTE_CHAR 0x7F |
50 #define MAX_2_BYTE_CHAR 0x7FF | |
51 #define MAX_3_BYTE_CHAR 0xFFFF | |
52 #define MAX_4_BYTE_CHAR 0x1FFFFF | |
53 #define MAX_5_BYTE_CHAR 0x3FFF7F | |
54 | |
88946
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
55 /* 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
|
56 byte. */ |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
57 #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
|
58 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
59 /* Return the character code for raw 8-bit byte BYTE. */ |
88363 | 60 #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
|
61 |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
62 /* 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
|
63 #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
|
64 (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
|
65 ? (c) - 0x3FFF00 \ |
233c080b5756
(CHAR_TO_BYTE8): If C is not eight-bit char, call
Kenichi Handa <handa@m17n.org>
parents:
88915
diff
changeset
|
66 : multibyte_char_to_unibyte (c, Qnil)) |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
67 |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
68 /* 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
|
69 that corresponds to a raw 8-bit byte. */ |
88363 | 70 #define CHAR_BYTE8_HEAD_P(byte) ((byte) == 0xC0 || (byte) == 0xC1) |
71 | |
89053
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
72 /* Mapping table from unibyte chars to multibyte chars. */ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
73 extern int unibyte_to_multibyte_table[256]; |
89018
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
74 |
89053
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
75 /* Convert the unibyte character C to the corresponding multibyte |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
76 character. If C can't be converted, return C. */ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
77 #define unibyte_char_to_multibyte(c) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
78 ((c) < 256 ? unibyte_to_multibyte_table[(c)] : (c)) |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
79 |
90019
1987dfad4543
(unibyte_has_multibyte_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
89911
diff
changeset
|
80 /* Nth element is 1 iff unibyte char N can be mapped to a multibyte |
1987dfad4543
(unibyte_has_multibyte_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
89911
diff
changeset
|
81 char. */ |
1987dfad4543
(unibyte_has_multibyte_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
89911
diff
changeset
|
82 extern char unibyte_has_multibyte_table[256]; |
1987dfad4543
(unibyte_has_multibyte_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
89911
diff
changeset
|
83 |
1987dfad4543
(unibyte_has_multibyte_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
89911
diff
changeset
|
84 #define UNIBYTE_CHAR_HAS_MULTIBYTE_P(c) (unibyte_has_multibyte_table[(c)]) |
1987dfad4543
(unibyte_has_multibyte_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
89911
diff
changeset
|
85 |
89053
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
86 /* If C is not ASCII, make it unibyte. */ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
87 #define MAKE_CHAR_UNIBYTE(c) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
88 do { \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
89 if (! ASCII_CHAR_P (c)) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
90 c = CHAR_TO_BYTE8 (c); \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
91 } while (0) |
89018
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
92 |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
93 |
89053
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
94 /* If C is not ASCII, make it multibyte. It assumes C < 256. */ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
95 #define MAKE_CHAR_MULTIBYTE(c) ((c) = unibyte_to_multibyte_table[(c)]) |
89018
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
96 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
97 /* This is the maximum byte length of multibyte form. */ |
88363 | 98 #define MAX_MULTIBYTE_LENGTH 5 |
99 | |
89887
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
100 /* Return a Lisp character whose character code is C. It assumes C is |
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
101 a valid character code. */ |
88363 | 102 #define make_char(c) make_number (c) |
103 | |
104 /* Nonzero iff C is an ASCII byte. */ | |
105 #define ASCII_BYTE_P(c) ((unsigned) (c) < 0x80) | |
106 | |
107 /* Nonzero iff X is a character. */ | |
108 #define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR) | |
109 | |
88832 | 110 /* 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
|
111 now. */ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
112 #define CHAR_VALID_P(c, genericp) ((unsigned) (c) <= MAX_CHAR) |
88363 | 113 |
114 /* Check if Lisp object X is a character or not. */ | |
90533 | 115 #define CHECK_CHARACTER(x) \ |
116 CHECK_TYPE (CHARACTERP (x), Qcharacterp, x) | |
88363 | 117 |
89483 | 118 #define CHECK_CHARACTER_CAR(x) \ |
119 do { \ | |
120 Lisp_Object tmp = XCAR (x); \ | |
121 CHECK_CHARACTER (tmp); \ | |
122 XSETCAR ((x), tmp); \ | |
123 } while (0) | |
124 | |
125 #define CHECK_CHARACTER_CDR(x) \ | |
126 do { \ | |
127 Lisp_Object tmp = XCDR (x); \ | |
128 CHECK_CHARACTER (tmp); \ | |
129 XSETCDR ((x), tmp); \ | |
130 } while (0) | |
131 | |
88363 | 132 /* Nonzero iff C is an ASCII character. */ |
133 #define ASCII_CHAR_P(c) ((unsigned) (c) < 0x80) | |
134 | |
135 /* Nonzero iff C is a character of code less than 0x100. */ | |
136 #define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100) | |
137 | |
138 /* Nonzero if character C has a printable glyph. */ | |
139 #define CHAR_PRINTABLE_P(c) \ | |
140 (((c) >= 32 && ((c) < 127) \ | |
141 || ! NILP (CHAR_TABLE_REF (Vprintable_chars, (c))))) | |
142 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
143 /* Return byte length of multibyte form for character C. */ |
88363 | 144 #define CHAR_BYTES(c) \ |
145 ( (c) <= MAX_1_BYTE_CHAR ? 1 \ | |
146 : (c) <= MAX_2_BYTE_CHAR ? 2 \ | |
147 : (c) <= MAX_3_BYTE_CHAR ? 3 \ | |
148 : (c) <= MAX_4_BYTE_CHAR ? 4 \ | |
149 : (c) <= MAX_5_BYTE_CHAR ? 5 \ | |
150 : 2) | |
151 | |
89053
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
152 |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
153 /* Return the leading code of multibyte form of C. */ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
154 #define CHAR_LEADING_CODE(c) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
155 ((c) <= MAX_1_BYTE_CHAR ? c \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
156 : (c) <= MAX_2_BYTE_CHAR ? (0xC0 | ((c) >> 6)) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
157 : (c) <= MAX_3_BYTE_CHAR ? (0xE0 | ((c) >> 12)) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
158 : (c) <= MAX_4_BYTE_CHAR ? (0xF0 | ((c) >> 18)) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
159 : (c) <= MAX_5_BYTE_CHAR ? 0xF8 \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
160 : (0xC0 | (((c) >> 6) & 0x01))) |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
161 |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
162 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
163 /* 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
|
164 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
|
165 Returns the length of the multibyte form. */ |
88363 | 166 |
167 #define CHAR_STRING(c, p) \ | |
168 ((unsigned) (c) <= MAX_1_BYTE_CHAR \ | |
169 ? ((p)[0] = (c), \ | |
170 1) \ | |
171 : (unsigned) (c) <= MAX_2_BYTE_CHAR \ | |
172 ? ((p)[0] = (0xC0 | ((c) >> 6)), \ | |
173 (p)[1] = (0x80 | ((c) & 0x3F)), \ | |
174 2) \ | |
175 : (unsigned) (c) <= MAX_3_BYTE_CHAR \ | |
176 ? ((p)[0] = (0xE0 | ((c) >> 12)), \ | |
177 (p)[1] = (0x80 | (((c) >> 6) & 0x3F)), \ | |
178 (p)[2] = (0x80 | ((c) & 0x3F)), \ | |
179 3) \ | |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
180 : char_string (c, p)) |
88363 | 181 |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
182 /* Store multibyte form of byte B in P. The caller should allocate at |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
183 least MAX_MULTIBYTE_LENGTH bytes area at P in advance. Returns the |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
184 length of the multibyte form. */ |
89038
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
185 |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
186 #define BYTE8_STRING(b, p) \ |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
187 ((p)[0] = (0xC0 | (((b) >> 6) & 0x01)), \ |
90051 | 188 (p)[1] = (0x80 | ((b) & 0x3F)), \ |
89038
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
189 2) |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
190 |
88363 | 191 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
192 /* 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
|
193 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
|
194 And, advance P to the end of the multibyte form. */ |
88363 | 195 |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
196 #define CHAR_STRING_ADVANCE(c, p) \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
197 do { \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
198 if ((c) <= MAX_1_BYTE_CHAR) \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
199 *(p)++ = (c); \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
200 else if ((c) <= MAX_2_BYTE_CHAR) \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
201 *(p)++ = (0xC0 | ((c) >> 6)), \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
202 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
203 else if ((c) <= MAX_3_BYTE_CHAR) \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
204 *(p)++ = (0xE0 | ((c) >> 12)), \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
205 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
206 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
207 else \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
208 (p) += char_string ((c), (p)); \ |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
209 } while (0) |
88363 | 210 |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
211 |
88363 | 212 /* Nonzero iff BYTE starts a non-ASCII character in a multibyte |
213 form. */ | |
214 #define LEADING_CODE_P(byte) (((byte) & 0xC0) == 0xC0) | |
215 | |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
216 /* 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
|
217 multibyte form. */ |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
218 #define TRAILING_CODE_P(byte) (((byte) & 0xC0) == 0x80) |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
219 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
220 /* 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
|
221 This is equivalent to: |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
222 (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
|
223 #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
|
224 |
88363 | 225 /* Just kept for backward compatibility. This macro will be removed |
226 in the future. */ | |
227 #define BASE_LEADING_CODE_P LEADING_CODE_P | |
228 | |
229 /* How many bytes a character that starts with BYTE occupies in a | |
230 multibyte form. */ | |
231 #define BYTES_BY_CHAR_HEAD(byte) \ | |
232 (!((byte) & 0x80) ? 1 \ | |
233 : !((byte) & 0x20) ? 2 \ | |
234 : !((byte) & 0x10) ? 3 \ | |
235 : !((byte) & 0x08) ? 4 \ | |
236 : 5) | |
237 | |
238 | |
239 /* Return the length of the multi-byte form at string STR of length | |
240 LEN while assuming that STR points a valid multi-byte form. As | |
241 this macro isn't necessary anymore, all callers will be changed to | |
242 use BYTES_BY_CHAR_HEAD directly in the future. */ | |
243 | |
244 #define MULTIBYTE_FORM_LENGTH(str, len) \ | |
245 BYTES_BY_CHAR_HEAD (*(str)) | |
246 | |
247 /* Parse multibyte string STR of length LENGTH and set BYTES to the | |
248 byte length of a character at STR while assuming that STR points a | |
249 valid multibyte form. As this macro isn't necessary anymore, all | |
250 callers will be changed to use BYTES_BY_CHAR_HEAD directly in the | |
251 future. */ | |
252 | |
253 #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ | |
254 (bytes) = BYTES_BY_CHAR_HEAD (*(str)) | |
255 | |
256 /* The byte length of multibyte form at unibyte string P ending at | |
257 PEND. If STR doesn't point a valid multibyte form, return 0. */ | |
258 | |
259 #define MULTIBYTE_LENGTH(p, pend) \ | |
260 (p >= pend ? 0 \ | |
261 : !((p)[0] & 0x80) ? 1 \ | |
262 : ((p + 1 >= pend) || (((p)[1] & 0xC0) != 0x80)) ? 0 \ | |
263 : ((p)[0] & 0xE0) == 0xC0 ? 2 \ | |
264 : ((p + 2 >= pend) || (((p)[2] & 0xC0) != 0x80)) ? 0 \ | |
265 : ((p)[0] & 0xF0) == 0xE0 ? 3 \ | |
266 : ((p + 3 >= pend) || (((p)[3] & 0xC0) != 0x80)) ? 0 \ | |
267 : ((p)[0] & 0xF8) == 0xF0 ? 4 \ | |
268 : ((p + 4 >= pend) || (((p)[4] & 0xC0) != 0x80)) ? 0 \ | |
269 : (p)[0] == 0xF8 && ((p)[1] & 0xF0) == 0x80 ? 5 \ | |
270 : 0) | |
271 | |
272 | |
273 /* Like MULTIBYTE_LENGTH but don't check the ending address. */ | |
274 | |
275 #define MULTIBYTE_LENGTH_NO_CHECK(p) \ | |
276 (!((p)[0] & 0x80) ? 1 \ | |
277 : ((p)[1] & 0xC0) != 0x80 ? 0 \ | |
278 : ((p)[0] & 0xE0) == 0xC0 ? 2 \ | |
279 : ((p)[2] & 0xC0) != 0x80 ? 0 \ | |
280 : ((p)[0] & 0xF0) == 0xE0 ? 3 \ | |
281 : ((p)[3] & 0xC0) != 0x80 ? 0 \ | |
282 : ((p)[0] & 0xF8) == 0xF0 ? 4 \ | |
283 : ((p)[4] & 0xC0) != 0x80 ? 0 \ | |
284 : (p)[0] == 0xF8 && ((p)[1] & 0xF0) == 0x80 ? 5 \ | |
285 : 0) | |
286 | |
89483 | 287 /* If P is before LIMIT, advance P to the next character boundary. It |
288 assumes that P is already at a character boundary of the sane | |
289 mulitbyte form whose end address is LIMIT. */ | |
290 | |
291 #define NEXT_CHAR_BOUNDARY(p, limit) \ | |
292 do { \ | |
293 if ((p) < (limit)) \ | |
294 (p) += BYTES_BY_CHAR_HEAD (*(p)); \ | |
295 } while (0) | |
296 | |
297 | |
298 /* If P is after LIMIT, advance P to the previous character boundary. | |
299 It assumes that P is already at a character boundary of the sane | |
300 mulitbyte form whose beginning address is LIMIT. */ | |
301 | |
302 #define PREV_CHAR_BOUNDARY(p, limit) \ | |
303 do { \ | |
304 if ((p) > (limit)) \ | |
305 { \ | |
306 const unsigned char *p0 = (p); \ | |
307 do { \ | |
308 p0--; \ | |
309 } while (p0 >= limit && ! CHAR_HEAD_P (*p0)); \ | |
310 (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1; \ | |
311 } \ | |
312 } while (0) | |
88363 | 313 |
314 /* Return the character code of character whose multibyte form is at | |
315 P. The argument LEN is ignored. It will be removed in the | |
316 future. */ | |
317 | |
318 #define STRING_CHAR(p, len) \ | |
319 (!((p)[0] & 0x80) \ | |
320 ? (p)[0] \ | |
321 : ! ((p)[0] & 0x20) \ | |
322 ? (((((p)[0] & 0x1F) << 6) \ | |
323 | ((p)[1] & 0x3F)) \ | |
324 + (((unsigned char) (p)[0]) < 0xC2 ? 0x3FFF80 : 0)) \ | |
325 : ! ((p)[0] & 0x10) \ | |
326 ? ((((p)[0] & 0x0F) << 12) \ | |
327 | (((p)[1] & 0x3F) << 6) \ | |
328 | ((p)[2] & 0x3F)) \ | |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
329 : string_char ((p), NULL, NULL)) |
88363 | 330 |
331 | |
332 /* Like STRING_CHAR but set ACTUAL_LEN to the length of multibyte | |
333 form. The argument LEN is ignored. It will be removed in the | |
334 future. */ | |
335 | |
336 #define STRING_CHAR_AND_LENGTH(p, len, actual_len) \ | |
337 (!((p)[0] & 0x80) \ | |
338 ? ((actual_len) = 1, (p)[0]) \ | |
339 : ! ((p)[0] & 0x20) \ | |
340 ? ((actual_len) = 2, \ | |
341 (((((p)[0] & 0x1F) << 6) \ | |
342 | ((p)[1] & 0x3F)) \ | |
343 + (((unsigned char) (p)[0]) < 0xC2 ? 0x3FFF80 : 0))) \ | |
344 : ! ((p)[0] & 0x10) \ | |
345 ? ((actual_len) = 3, \ | |
346 ((((p)[0] & 0x0F) << 12) \ | |
347 | (((p)[1] & 0x3F) << 6) \ | |
348 | ((p)[2] & 0x3F))) \ | |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
349 : string_char ((p), NULL, &actual_len)) |
88363 | 350 |
351 | |
89887
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
352 /* Like STRING_CHAR but advance P to the end of multibyte form. */ |
88363 | 353 |
354 #define STRING_CHAR_ADVANCE(p) \ | |
355 (!((p)[0] & 0x80) \ | |
356 ? *(p)++ \ | |
357 : ! ((p)[0] & 0x20) \ | |
358 ? ((p) += 2, \ | |
359 ((((p)[-2] & 0x1F) << 6) \ | |
360 | ((p)[-1] & 0x3F) \ | |
89483 | 361 | ((unsigned char) ((p)[-2]) < 0xC2 ? 0x3FFF80 : 0))) \ |
88363 | 362 : ! ((p)[0] & 0x10) \ |
363 ? ((p) += 3, \ | |
364 ((((p)[-3] & 0x0F) << 12) \ | |
365 | (((p)[-2] & 0x3F) << 6) \ | |
366 | ((p)[-1] & 0x3F))) \ | |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
367 : string_char ((p), &(p), NULL)) |
88363 | 368 |
369 | |
370 /* Fetch the "next" character from Lisp string STRING at byte position | |
371 BYTEIDX, character position CHARIDX. Store it into OUTPUT. | |
372 | |
373 All the args must be side-effect-free. | |
374 BYTEIDX and CHARIDX must be lvalues; | |
375 we increment them past the character fetched. */ | |
376 | |
377 #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
378 if (1) \ | |
379 { \ | |
380 CHARIDX++; \ | |
381 if (STRING_MULTIBYTE (STRING)) \ | |
382 { \ | |
383 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
384 int len; \ | |
385 \ | |
386 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
387 BYTEIDX += len; \ | |
388 } \ | |
389 else \ | |
390 OUTPUT = XSTRING (STRING)->data[BYTEIDX++]; \ | |
391 } \ | |
392 else | |
393 | |
89887
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
394 /* Like FETCH_STRING_CHAR_ADVANCE but return a multibyte character eve |
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
395 if STRING is unibyte. */ |
89053
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
396 |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
397 #define FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
398 if (1) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
399 { \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
400 CHARIDX++; \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
401 if (STRING_MULTIBYTE (STRING)) \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
402 { \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
403 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
404 int len; \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
405 \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
406 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
407 BYTEIDX += len; \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
408 } \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
409 else \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
410 { \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
411 OUTPUT = XSTRING (STRING)->data[BYTEIDX++]; \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
412 MAKE_CHAR_MULTIBYTE (OUTPUT); \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
413 } \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
414 } \ |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
415 else |
06a2cbbeaee9
(LEADING_CODE_LATIN_1_MIN)
Kenichi Handa <handa@m17n.org>
parents:
89038
diff
changeset
|
416 |
88363 | 417 |
418 /* Like FETCH_STRING_CHAR_ADVANCE but assumes STRING is multibyte. */ | |
419 | |
420 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
421 if (1) \ | |
422 { \ | |
423 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
424 int len; \ | |
425 \ | |
426 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
427 BYTEIDX += len; \ | |
428 CHARIDX++; \ | |
429 } \ | |
430 else | |
431 | |
432 | |
433 /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current | |
434 buffer. */ | |
435 | |
436 #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX) \ | |
437 if (1) \ | |
438 { \ | |
439 CHARIDX++; \ | |
440 if (!NILP (current_buffer->enable_multibyte_characters)) \ | |
441 { \ | |
442 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
443 int len; \ | |
444 \ | |
445 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
446 BYTEIDX += len; \ | |
447 } \ | |
448 else \ | |
449 { \ | |
450 OUTPUT = *(BYTE_POS_ADDR (BYTEIDX)); \ | |
451 BYTEIDX++; \ | |
452 } \ | |
453 } \ | |
454 else | |
455 | |
456 | |
89887
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
457 /* Like FETCH_CHAR_ADVANCE but assumes the current buffer is multibyte. */ |
88363 | 458 |
459 #define FETCH_CHAR_ADVANCE_NO_CHECK(OUTPUT, CHARIDX, BYTEIDX) \ | |
460 if (1) \ | |
461 { \ | |
462 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
463 int len; \ | |
464 \ | |
465 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
466 BYTEIDX += len; \ | |
467 CHARIDX++; \ | |
468 } \ | |
469 else | |
470 | |
471 | |
472 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
473 the next character boundary. No range checking of POS. */ | |
474 | |
475 #define INC_POS(pos_byte) \ | |
476 do { \ | |
477 unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
478 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
479 } while (0) | |
480 | |
481 | |
482 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
483 the previous character boundary. No range checking of POS. */ | |
484 | |
485 #define DEC_POS(pos_byte) \ | |
486 do { \ | |
487 unsigned char *p; \ | |
488 \ | |
489 pos_byte--; \ | |
490 if (pos_byte < GPT_BYTE) \ | |
491 p = BEG_ADDR + pos_byte - 1; \ | |
492 else \ | |
493 p = BEG_ADDR + GAP_SIZE + pos_byte - 1; \ | |
494 while (!CHAR_HEAD_P (*p)) \ | |
495 { \ | |
496 p--; \ | |
497 pos_byte--; \ | |
498 } \ | |
499 } while (0) | |
500 | |
501 /* Increment both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
502 | |
503 #define INC_BOTH(charpos, bytepos) \ | |
504 do \ | |
505 { \ | |
506 (charpos)++; \ | |
507 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
508 (bytepos)++; \ | |
509 else \ | |
510 INC_POS ((bytepos)); \ | |
511 } \ | |
512 while (0) | |
513 | |
514 | |
515 /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
516 | |
517 #define DEC_BOTH(charpos, bytepos) \ | |
518 do \ | |
519 { \ | |
520 (charpos)--; \ | |
521 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
522 (bytepos)--; \ | |
523 else \ | |
524 DEC_POS ((bytepos)); \ | |
525 } \ | |
526 while (0) | |
527 | |
528 | |
529 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
530 the next character boundary. This macro relies on the fact that | |
531 *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
532 '\0'. No range checking of POS_BYTE. */ | |
533 | |
534 #define BUF_INC_POS(buf, pos_byte) \ | |
535 do { \ | |
536 unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
537 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
538 } while (0) | |
539 | |
540 | |
541 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
542 the previous character boundary. No range checking of POS_BYTE. */ | |
543 | |
544 #define BUF_DEC_POS(buf, pos_byte) \ | |
545 do { \ | |
546 unsigned char *p; \ | |
547 pos_byte--; \ | |
548 if (pos_byte < BUF_GPT_BYTE (buf)) \ | |
549 p = BUF_BEG_ADDR (buf) + pos_byte - 1; \ | |
550 else \ | |
551 p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - 1; \ | |
552 while (!CHAR_HEAD_P (*p)) \ | |
553 { \ | |
554 p--; \ | |
555 pos_byte--; \ | |
556 } \ | |
557 } while (0) | |
558 | |
559 | |
89887
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
560 /* If C is a character to be unified with a Unicode character, return |
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
561 the unified Unicode character. */ |
028a1f06f612
(LEADING_CODE_LATIN_1_MIN) (LEADING_CODE_LATIN_1_MAX): Delete these
Kenichi Handa <handa@m17n.org>
parents:
89692
diff
changeset
|
562 |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
563 #define MAYBE_UNIFY_CHAR(c) \ |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
564 if (c > MAX_UNICODE_CHAR \ |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
565 && CHAR_TABLE_P (Vchar_unify_table)) \ |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
566 { \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
567 Lisp_Object val; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
568 int unified; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
569 \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
570 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
|
571 if (! NILP (val)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
572 { \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
573 if (SYMBOLP (val)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
574 { \ |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
575 Funify_charset (val, Qnil, Qnil); \ |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
576 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
|
577 } \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
578 if ((unified = XINT (val)) >= 0) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
579 c = unified; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
580 } \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
581 } \ |
88363 | 582 else |
583 | |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
584 |
88363 | 585 /* Return the width of ASCII character C. The width is measured by |
586 how many columns occupied on the screen when displayed in the | |
587 current buffer. */ | |
588 | |
589 #define ASCII_CHAR_WIDTH(c) \ | |
590 (c < 0x20 \ | |
591 ? (c == '\t' \ | |
592 ? XFASTINT (current_buffer->tab_width) \ | |
593 : (c == '\n' ? 0 : (NILP (current_buffer->ctl_arrow) ? 4 : 2))) \ | |
594 : (c < 0x7f \ | |
595 ? 1 \ | |
596 : ((NILP (current_buffer->ctl_arrow) ? 4 : 2)))) | |
597 | |
598 /* Return the width of character C. The width is measured by how many | |
599 columns occupied on the screen when displayed in the current | |
600 buffer. */ | |
601 | |
602 #define CHAR_WIDTH(c) \ | |
603 (ASCII_CHAR_P (c) \ | |
604 ? ASCII_CHAR_WIDTH (c) \ | |
605 : XINT (CHAR_TABLE_REF (Vchar_width_table, c))) | |
606 | |
89180
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
607 extern int char_resolve_modifier_mask P_ ((int)); |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
608 extern int char_string P_ ((int, unsigned char *)); |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
609 extern int string_char P_ ((const unsigned char *, |
1d29c2b108e6
(CHAR_STRING): Call char_string if C is greater than
Kenichi Handa <handa@m17n.org>
parents:
89053
diff
changeset
|
610 const unsigned char **, int *)); |
88363 | 611 |
612 extern int translate_char P_ ((Lisp_Object, int c)); | |
613 extern int char_printable_p P_ ((int c)); | |
89483 | 614 extern void parse_str_as_multibyte P_ ((const unsigned char *, int, int *, |
615 int *)); | |
88363 | 616 extern int parse_str_to_multibyte P_ ((unsigned char *, int)); |
617 extern int str_as_multibyte P_ ((unsigned char *, int, int, int *)); | |
618 extern int str_to_multibyte P_ ((unsigned char *, int, int)); | |
619 extern int str_as_unibyte P_ ((unsigned char *, int)); | |
620 extern int strwidth P_ ((unsigned char *, int)); | |
89483 | 621 extern int c_string_width P_ ((const unsigned char *, int, int, int *, int *)); |
88363 | 622 extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *)); |
623 | |
624 extern Lisp_Object Vprintable_chars; | |
625 | |
626 extern Lisp_Object Qcharacterp, Qauto_fill_chars; | |
627 extern Lisp_Object Vtranslation_table_vector; | |
628 extern Lisp_Object Vchar_width_table; | |
629 extern Lisp_Object Vchar_direction_table; | |
630 extern Lisp_Object Vchar_unify_table; | |
631 | |
88545 | 632 extern Lisp_Object string_escape_byte8 P_ ((Lisp_Object)); |
633 | |
88363 | 634 /* Return a translation table of id number ID. */ |
635 #define GET_TRANSLATION_TABLE(id) \ | |
636 (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)])) | |
637 | |
638 /* A char-table for characters which may invoke auto-filling. */ | |
639 extern Lisp_Object Vauto_fill_chars; | |
640 | |
88915
94184802d0cc
(Vchar_script_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
88873
diff
changeset
|
641 extern Lisp_Object Vchar_script_table; |
90402
69ac9cbd4be5
(Vscript_representative_chars): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
90051
diff
changeset
|
642 extern Lisp_Object Vscript_representative_chars; |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
643 |
88363 | 644 /* Copy LEN bytes from FROM to TO. This macro should be used only |
645 when a caller knows that LEN is short and the obvious copy loop is | |
646 faster than calling bcopy which has some overhead. Copying a | |
647 multibyte sequence of a character is the typical case. */ | |
648 | |
649 #define BCOPY_SHORT(from, to, len) \ | |
650 do { \ | |
651 int i = len; \ | |
652 unsigned char *from_p = from, *to_p = to; \ | |
653 while (i--) *to_p++ = *from_p++; \ | |
654 } while (0) | |
655 | |
656 #define DEFSYM(sym, name) \ | |
657 do { (sym) = intern ((name)); staticpro (&(sym)); } while (0) | |
658 | |
659 #endif /* EMACS_CHARACTER_H */ | |
89911 | 660 |
661 /* arch-tag: 4ef86004-2eff-4073-8cea-cfcbcf7188ac | |
662 (do not change this comment) */ |