Mercurial > emacs
annotate src/character.h @ 89038:f60ed671d6e4
(BYTE8_STRING): New macro.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 21 Aug 2002 02:27:07 +0000 |
parents | a9f683a73092 |
children | 06a2cbbeaee9 |
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 | |
89018
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
71 /* If C is not ASCII, make it unibyte. */ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
72 |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
73 #define MAKE_CHAR_UNIBYTE(c) \ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
74 if (! ASCII_CHAR_P (c)) \ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
75 c = multibyte_char_to_unibyte (c, Qnil); \ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
76 else |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
77 |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
78 |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
79 /* If C is not ASCII, make it multibyte. */ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
80 |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
81 #define MAKE_CHAR_MULTIBYTE(c) \ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
82 if (! ASCII_CHAR_P (c)) \ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
83 c = unibyte_char_to_multibyte (c); \ |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
84 else |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
85 |
a9f683a73092
(MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE): New macros.
Kenichi Handa <handa@m17n.org>
parents:
88946
diff
changeset
|
86 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
87 /* This is the maximum byte length of multibyte form. */ |
88363 | 88 #define MAX_MULTIBYTE_LENGTH 5 |
89 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
90 /* Return a Lisp character whose character code is C. */ |
88363 | 91 #define make_char(c) make_number (c) |
92 | |
93 /* Nonzero iff C is an ASCII byte. */ | |
94 #define ASCII_BYTE_P(c) ((unsigned) (c) < 0x80) | |
95 | |
96 /* Nonzero iff X is a character. */ | |
97 #define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR) | |
98 | |
88832 | 99 /* 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
|
100 now. */ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
101 #define CHAR_VALID_P(c, genericp) ((unsigned) (c) <= MAX_CHAR) |
88363 | 102 |
103 /* Check if Lisp object X is a character or not. */ | |
104 #define CHECK_CHARACTER(x) \ | |
105 do { \ | |
106 if (! CHARACTERP(x)) x = wrong_type_argument (Qcharacterp, (x)); \ | |
107 } while (0) | |
108 | |
109 /* Nonzero iff C is an ASCII character. */ | |
110 #define ASCII_CHAR_P(c) ((unsigned) (c) < 0x80) | |
111 | |
112 /* Nonzero iff C is a character of code less than 0x100. */ | |
113 #define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100) | |
114 | |
115 /* Nonzero if character C has a printable glyph. */ | |
116 #define CHAR_PRINTABLE_P(c) \ | |
117 (((c) >= 32 && ((c) < 127) \ | |
118 || ! NILP (CHAR_TABLE_REF (Vprintable_chars, (c))))) | |
119 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
120 /* Return byte length of multibyte form for character C. */ |
88363 | 121 #define CHAR_BYTES(c) \ |
122 ( (c) <= MAX_1_BYTE_CHAR ? 1 \ | |
123 : (c) <= MAX_2_BYTE_CHAR ? 2 \ | |
124 : (c) <= MAX_3_BYTE_CHAR ? 3 \ | |
125 : (c) <= MAX_4_BYTE_CHAR ? 4 \ | |
126 : (c) <= MAX_5_BYTE_CHAR ? 5 \ | |
127 : 2) | |
128 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
129 /* 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
|
130 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
|
131 Returns the length of the multibyte form. */ |
88363 | 132 |
133 #define CHAR_STRING(c, p) \ | |
134 ((unsigned) (c) <= MAX_1_BYTE_CHAR \ | |
135 ? ((p)[0] = (c), \ | |
136 1) \ | |
137 : (unsigned) (c) <= MAX_2_BYTE_CHAR \ | |
138 ? ((p)[0] = (0xC0 | ((c) >> 6)), \ | |
139 (p)[1] = (0x80 | ((c) & 0x3F)), \ | |
140 2) \ | |
141 : (unsigned) (c) <= MAX_3_BYTE_CHAR \ | |
142 ? ((p)[0] = (0xE0 | ((c) >> 12)), \ | |
143 (p)[1] = (0x80 | (((c) >> 6) & 0x3F)), \ | |
144 (p)[2] = (0x80 | ((c) & 0x3F)), \ | |
145 3) \ | |
146 : (unsigned) (c) <= MAX_5_BYTE_CHAR \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
147 ? char_string_with_unification (c, p) \ |
88363 | 148 : ((p)[0] = (0xC0 | (((c) >> 6) & 0x01)), \ |
149 (p)[1] = (0x80 | ((c) & 0x3F)), \ | |
150 2)) | |
151 | |
89038
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
152 /* Store multibyte form of eight-bit char B in P. The caller should |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
153 allocate at least MAX_MULTIBYTE_LENGTH bytes area at P in advance. |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
154 Returns the length of the multibyte form. */ |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
155 |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
156 #define BYTE8_STRING(b, p) \ |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
157 ((p)[0] = (0xC0 | (((b) >> 6) & 0x01)), \ |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
158 (p)[1] = (0x80 | ((c) & 0x3F)), \ |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
159 2) |
f60ed671d6e4
(BYTE8_STRING): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89018
diff
changeset
|
160 |
88363 | 161 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
162 /* 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
|
163 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
|
164 And, advance P to the end of the multibyte form. */ |
88363 | 165 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
166 #define CHAR_STRING_ADVANCE(c, p) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
167 do { \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
168 if ((c) <= MAX_1_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
169 *(p)++ = (c); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
170 else if ((c) <= MAX_2_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
171 *(p)++ = (0xC0 | ((c) >> 6)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
172 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
173 else if ((c) <= MAX_3_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
174 *(p)++ = (0xE0 | ((c) >> 12)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
175 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
176 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
177 else if ((c) <= MAX_5_BYTE_CHAR) \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
178 (p) += char_string_with_unification ((c), (p)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
179 else \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
180 *(p)++ = (0xC0 | (((c) >> 6) & 0x01)), \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
181 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
182 } while (0) |
88363 | 183 |
184 /* Nonzero iff BYTE starts a non-ASCII character in a multibyte | |
185 form. */ | |
186 #define LEADING_CODE_P(byte) (((byte) & 0xC0) == 0xC0) | |
187 | |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
188 /* 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
|
189 multibyte form. */ |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
190 #define TRAILING_CODE_P(byte) (((byte) & 0xC0) == 0x80) |
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
191 |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
192 /* 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
|
193 This is equivalent to: |
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
194 (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
|
195 #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
|
196 |
88363 | 197 /* Just kept for backward compatibility. This macro will be removed |
198 in the future. */ | |
199 #define BASE_LEADING_CODE_P LEADING_CODE_P | |
200 | |
201 /* How many bytes a character that starts with BYTE occupies in a | |
202 multibyte form. */ | |
203 #define BYTES_BY_CHAR_HEAD(byte) \ | |
204 (!((byte) & 0x80) ? 1 \ | |
205 : !((byte) & 0x20) ? 2 \ | |
206 : !((byte) & 0x10) ? 3 \ | |
207 : !((byte) & 0x08) ? 4 \ | |
208 : 5) | |
209 | |
210 | |
211 /* Return the length of the multi-byte form at string STR of length | |
212 LEN while assuming that STR points a valid multi-byte form. As | |
213 this macro isn't necessary anymore, all callers will be changed to | |
214 use BYTES_BY_CHAR_HEAD directly in the future. */ | |
215 | |
216 #define MULTIBYTE_FORM_LENGTH(str, len) \ | |
217 BYTES_BY_CHAR_HEAD (*(str)) | |
218 | |
219 /* Parse multibyte string STR of length LENGTH and set BYTES to the | |
220 byte length of a character at STR while assuming that STR points a | |
221 valid multibyte form. As this macro isn't necessary anymore, all | |
222 callers will be changed to use BYTES_BY_CHAR_HEAD directly in the | |
223 future. */ | |
224 | |
225 #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ | |
226 (bytes) = BYTES_BY_CHAR_HEAD (*(str)) | |
227 | |
228 /* The byte length of multibyte form at unibyte string P ending at | |
229 PEND. If STR doesn't point a valid multibyte form, return 0. */ | |
230 | |
231 #define MULTIBYTE_LENGTH(p, pend) \ | |
232 (p >= pend ? 0 \ | |
233 : !((p)[0] & 0x80) ? 1 \ | |
234 : ((p + 1 >= pend) || (((p)[1] & 0xC0) != 0x80)) ? 0 \ | |
235 : ((p)[0] & 0xE0) == 0xC0 ? 2 \ | |
236 : ((p + 2 >= pend) || (((p)[2] & 0xC0) != 0x80)) ? 0 \ | |
237 : ((p)[0] & 0xF0) == 0xE0 ? 3 \ | |
238 : ((p + 3 >= pend) || (((p)[3] & 0xC0) != 0x80)) ? 0 \ | |
239 : ((p)[0] & 0xF8) == 0xF0 ? 4 \ | |
240 : ((p + 4 >= pend) || (((p)[4] & 0xC0) != 0x80)) ? 0 \ | |
241 : (p)[0] == 0xF8 && ((p)[1] & 0xF0) == 0x80 ? 5 \ | |
242 : 0) | |
243 | |
244 | |
245 /* Like MULTIBYTE_LENGTH but don't check the ending address. */ | |
246 | |
247 #define MULTIBYTE_LENGTH_NO_CHECK(p) \ | |
248 (!((p)[0] & 0x80) ? 1 \ | |
249 : ((p)[1] & 0xC0) != 0x80 ? 0 \ | |
250 : ((p)[0] & 0xE0) == 0xC0 ? 2 \ | |
251 : ((p)[2] & 0xC0) != 0x80 ? 0 \ | |
252 : ((p)[0] & 0xF0) == 0xE0 ? 3 \ | |
253 : ((p)[3] & 0xC0) != 0x80 ? 0 \ | |
254 : ((p)[0] & 0xF8) == 0xF0 ? 4 \ | |
255 : ((p)[4] & 0xC0) != 0x80 ? 0 \ | |
256 : (p)[0] == 0xF8 && ((p)[1] & 0xF0) == 0x80 ? 5 \ | |
257 : 0) | |
258 | |
259 | |
260 /* Return the character code of character whose multibyte form is at | |
261 P. The argument LEN is ignored. It will be removed in the | |
262 future. */ | |
263 | |
264 #define STRING_CHAR(p, len) \ | |
265 (!((p)[0] & 0x80) \ | |
266 ? (p)[0] \ | |
267 : ! ((p)[0] & 0x20) \ | |
268 ? (((((p)[0] & 0x1F) << 6) \ | |
269 | ((p)[1] & 0x3F)) \ | |
270 + (((unsigned char) (p)[0]) < 0xC2 ? 0x3FFF80 : 0)) \ | |
271 : ! ((p)[0] & 0x10) \ | |
272 ? ((((p)[0] & 0x0F) << 12) \ | |
273 | (((p)[1] & 0x3F) << 6) \ | |
274 | ((p)[2] & 0x3F)) \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
275 : string_char_with_unification ((p), NULL, NULL)) |
88363 | 276 |
277 | |
278 /* Like STRING_CHAR but set ACTUAL_LEN to the length of multibyte | |
279 form. The argument LEN is ignored. It will be removed in the | |
280 future. */ | |
281 | |
282 #define STRING_CHAR_AND_LENGTH(p, len, actual_len) \ | |
283 (!((p)[0] & 0x80) \ | |
284 ? ((actual_len) = 1, (p)[0]) \ | |
285 : ! ((p)[0] & 0x20) \ | |
286 ? ((actual_len) = 2, \ | |
287 (((((p)[0] & 0x1F) << 6) \ | |
288 | ((p)[1] & 0x3F)) \ | |
289 + (((unsigned char) (p)[0]) < 0xC2 ? 0x3FFF80 : 0))) \ | |
290 : ! ((p)[0] & 0x10) \ | |
291 ? ((actual_len) = 3, \ | |
292 ((((p)[0] & 0x0F) << 12) \ | |
293 | (((p)[1] & 0x3F) << 6) \ | |
294 | ((p)[2] & 0x3F))) \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
295 : string_char_with_unification ((p), NULL, &actual_len)) |
88363 | 296 |
297 | |
298 /* Like STRING_CHAR but advacen P to the end of multibyte form. */ | |
299 | |
300 #define STRING_CHAR_ADVANCE(p) \ | |
301 (!((p)[0] & 0x80) \ | |
302 ? *(p)++ \ | |
303 : ! ((p)[0] & 0x20) \ | |
304 ? ((p) += 2, \ | |
305 ((((p)[-2] & 0x1F) << 6) \ | |
306 | ((p)[-1] & 0x3F) \ | |
307 | (((unsigned char) (p)[-2]) < 0xC2 ? 0x3FFF80 : 0))) \ | |
308 : ! ((p)[0] & 0x10) \ | |
309 ? ((p) += 3, \ | |
310 ((((p)[-3] & 0x0F) << 12) \ | |
311 | (((p)[-2] & 0x3F) << 6) \ | |
312 | ((p)[-1] & 0x3F))) \ | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
313 : string_char_with_unification ((p), &(p), NULL)) |
88363 | 314 |
315 | |
316 /* Fetch the "next" character from Lisp string STRING at byte position | |
317 BYTEIDX, character position CHARIDX. Store it into OUTPUT. | |
318 | |
319 All the args must be side-effect-free. | |
320 BYTEIDX and CHARIDX must be lvalues; | |
321 we increment them past the character fetched. */ | |
322 | |
323 #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
324 if (1) \ | |
325 { \ | |
326 CHARIDX++; \ | |
327 if (STRING_MULTIBYTE (STRING)) \ | |
328 { \ | |
329 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
330 int len; \ | |
331 \ | |
332 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
333 BYTEIDX += len; \ | |
334 } \ | |
335 else \ | |
336 OUTPUT = XSTRING (STRING)->data[BYTEIDX++]; \ | |
337 } \ | |
338 else | |
339 | |
340 | |
341 /* Like FETCH_STRING_CHAR_ADVANCE but assumes STRING is multibyte. */ | |
342 | |
343 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
344 if (1) \ | |
345 { \ | |
346 unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX]; \ | |
347 int len; \ | |
348 \ | |
349 OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
350 BYTEIDX += len; \ | |
351 CHARIDX++; \ | |
352 } \ | |
353 else | |
354 | |
355 | |
356 /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current | |
357 buffer. */ | |
358 | |
359 #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX) \ | |
360 if (1) \ | |
361 { \ | |
362 CHARIDX++; \ | |
363 if (!NILP (current_buffer->enable_multibyte_characters)) \ | |
364 { \ | |
365 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
366 int len; \ | |
367 \ | |
368 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
369 BYTEIDX += len; \ | |
370 } \ | |
371 else \ | |
372 { \ | |
373 OUTPUT = *(BYTE_POS_ADDR (BYTEIDX)); \ | |
374 BYTEIDX++; \ | |
375 } \ | |
376 } \ | |
377 else | |
378 | |
379 | |
380 /* Like FETCH_CHAR_ADVANCE but assumes STRING is multibyte. */ | |
381 | |
382 #define FETCH_CHAR_ADVANCE_NO_CHECK(OUTPUT, CHARIDX, BYTEIDX) \ | |
383 if (1) \ | |
384 { \ | |
385 unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
386 int len; \ | |
387 \ | |
388 OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len); \ | |
389 BYTEIDX += len; \ | |
390 CHARIDX++; \ | |
391 } \ | |
392 else | |
393 | |
394 | |
395 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
396 the next character boundary. No range checking of POS. */ | |
397 | |
398 #define INC_POS(pos_byte) \ | |
399 do { \ | |
400 unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
401 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
402 } while (0) | |
403 | |
404 | |
405 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
406 the previous character boundary. No range checking of POS. */ | |
407 | |
408 #define DEC_POS(pos_byte) \ | |
409 do { \ | |
410 unsigned char *p; \ | |
411 \ | |
412 pos_byte--; \ | |
413 if (pos_byte < GPT_BYTE) \ | |
414 p = BEG_ADDR + pos_byte - 1; \ | |
415 else \ | |
416 p = BEG_ADDR + GAP_SIZE + pos_byte - 1; \ | |
417 while (!CHAR_HEAD_P (*p)) \ | |
418 { \ | |
419 p--; \ | |
420 pos_byte--; \ | |
421 } \ | |
422 } while (0) | |
423 | |
424 /* Increment both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
425 | |
426 #define INC_BOTH(charpos, bytepos) \ | |
427 do \ | |
428 { \ | |
429 (charpos)++; \ | |
430 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
431 (bytepos)++; \ | |
432 else \ | |
433 INC_POS ((bytepos)); \ | |
434 } \ | |
435 while (0) | |
436 | |
437 | |
438 /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
439 | |
440 #define DEC_BOTH(charpos, bytepos) \ | |
441 do \ | |
442 { \ | |
443 (charpos)--; \ | |
444 if (NILP (current_buffer->enable_multibyte_characters)) \ | |
445 (bytepos)--; \ | |
446 else \ | |
447 DEC_POS ((bytepos)); \ | |
448 } \ | |
449 while (0) | |
450 | |
451 | |
452 /* Increase the buffer byte position POS_BYTE of the current buffer to | |
453 the next character boundary. This macro relies on the fact that | |
454 *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
455 '\0'. No range checking of POS_BYTE. */ | |
456 | |
457 #define BUF_INC_POS(buf, pos_byte) \ | |
458 do { \ | |
459 unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
460 pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
461 } while (0) | |
462 | |
463 | |
464 /* Decrease the buffer byte position POS_BYTE of the current buffer to | |
465 the previous character boundary. No range checking of POS_BYTE. */ | |
466 | |
467 #define BUF_DEC_POS(buf, pos_byte) \ | |
468 do { \ | |
469 unsigned char *p; \ | |
470 pos_byte--; \ | |
471 if (pos_byte < BUF_GPT_BYTE (buf)) \ | |
472 p = BUF_BEG_ADDR (buf) + pos_byte - 1; \ | |
473 else \ | |
474 p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - 1; \ | |
475 while (!CHAR_HEAD_P (*p)) \ | |
476 { \ | |
477 p--; \ | |
478 pos_byte--; \ | |
479 } \ | |
480 } while (0) | |
481 | |
482 | |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
483 #define MAYBE_UNIFY_CHAR(c) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
484 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
|
485 { \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
486 Lisp_Object val; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
487 int unified; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
488 \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
489 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
|
490 if (! NILP (val)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
491 { \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
492 if (SYMBOLP (val)) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
493 { \ |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
494 Funify_charset (val, Qnil, Qnil); \ |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
495 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
|
496 } \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
497 if ((unified = XINT (val)) >= 0) \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
498 c = unified; \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
499 } \ |
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
500 } \ |
88363 | 501 else |
502 | |
88742
55e36a0cf0ee
(MAYBE_UNIFY_CHAR): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88545
diff
changeset
|
503 |
88363 | 504 /* Return the width of ASCII character C. The width is measured by |
505 how many columns occupied on the screen when displayed in the | |
506 current buffer. */ | |
507 | |
508 #define ASCII_CHAR_WIDTH(c) \ | |
509 (c < 0x20 \ | |
510 ? (c == '\t' \ | |
511 ? XFASTINT (current_buffer->tab_width) \ | |
512 : (c == '\n' ? 0 : (NILP (current_buffer->ctl_arrow) ? 4 : 2))) \ | |
513 : (c < 0x7f \ | |
514 ? 1 \ | |
515 : ((NILP (current_buffer->ctl_arrow) ? 4 : 2)))) | |
516 | |
517 /* Return the width of character C. The width is measured by how many | |
518 columns occupied on the screen when displayed in the current | |
519 buffer. */ | |
520 | |
521 #define CHAR_WIDTH(c) \ | |
522 (ASCII_CHAR_P (c) \ | |
523 ? ASCII_CHAR_WIDTH (c) \ | |
524 : XINT (CHAR_TABLE_REF (Vchar_width_table, c))) | |
525 | |
88428
5eaa8c11ab45
(CHAR_VALID_P): Don't call CHARACTERP.
Kenichi Handa <handa@m17n.org>
parents:
88363
diff
changeset
|
526 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
|
527 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
|
528 const unsigned char **, int *)); |
88363 | 529 |
530 extern int translate_char P_ ((Lisp_Object, int c)); | |
531 extern int char_printable_p P_ ((int c)); | |
532 extern void parse_str_as_multibyte P_ ((unsigned char *, int, int *, int *)); | |
533 extern int parse_str_to_multibyte P_ ((unsigned char *, int)); | |
534 extern int str_as_multibyte P_ ((unsigned char *, int, int, int *)); | |
535 extern int str_to_multibyte P_ ((unsigned char *, int, int)); | |
536 extern int str_as_unibyte P_ ((unsigned char *, int)); | |
537 extern int strwidth P_ ((unsigned char *, int)); | |
538 extern int c_string_width P_ ((unsigned char *, int, int, int *, int *)); | |
539 extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *)); | |
540 | |
541 extern Lisp_Object Vprintable_chars; | |
542 | |
543 extern Lisp_Object Qcharacterp, Qauto_fill_chars; | |
544 extern Lisp_Object Vtranslation_table_vector; | |
545 extern Lisp_Object Vchar_width_table; | |
546 extern Lisp_Object Vchar_direction_table; | |
547 extern Lisp_Object Vchar_unify_table; | |
548 | |
88545 | 549 extern Lisp_Object string_escape_byte8 P_ ((Lisp_Object)); |
550 | |
88363 | 551 /* Return a translation table of id number ID. */ |
552 #define GET_TRANSLATION_TABLE(id) \ | |
553 (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)])) | |
554 | |
555 /* A char-table for characters which may invoke auto-filling. */ | |
556 extern Lisp_Object Vauto_fill_chars; | |
557 | |
88915
94184802d0cc
(Vchar_script_table): Extern it.
Kenichi Handa <handa@m17n.org>
parents:
88873
diff
changeset
|
558 extern Lisp_Object Vchar_script_table; |
88873
7d441bc35e9b
(TRAILING_CODE_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
88832
diff
changeset
|
559 |
88363 | 560 /* Copy LEN bytes from FROM to TO. This macro should be used only |
561 when a caller knows that LEN is short and the obvious copy loop is | |
562 faster than calling bcopy which has some overhead. Copying a | |
563 multibyte sequence of a character is the typical case. */ | |
564 | |
565 #define BCOPY_SHORT(from, to, len) \ | |
566 do { \ | |
567 int i = len; \ | |
568 unsigned char *from_p = from, *to_p = to; \ | |
569 while (i--) *to_p++ = *from_p++; \ | |
570 } while (0) | |
571 | |
572 #define DEFSYM(sym, name) \ | |
573 do { (sym) = intern ((name)); staticpro (&(sym)); } while (0) | |
574 | |
575 #endif /* EMACS_CHARACTER_H */ |