Commit | Line | Data |
---|---|---|
f49b37c9 | 1 | /* Header for multibyte character handler. |
aaef169d TTN |
2 | Copyright (C) 2001, 2002, 2003, 2004, 2005, |
3 | 2006 Free Software Foundation, Inc. | |
ce03bf76 KH |
4 | Copyright (C) 1995, 1997, 1998, 2003 |
5 | National Institute of Advanced Industrial Science and Technology (AIST) | |
6 | Registration Number H14PRO021 | |
4ed46869 | 7 | |
369314dc KH |
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. | |
4ed46869 | 14 | |
369314dc KH |
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. | |
4ed46869 | 19 | |
369314dc KH |
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 | |
4fc5845f LK |
22 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
4ed46869 | 24 | |
aa01a892 KH |
25 | #ifndef EMACS_CHARSET_H |
26 | #define EMACS_CHARSET_H | |
4ed46869 | 27 | |
6e4dc3e1 KH |
28 | /* #define BYTE_COMBINING_DEBUG */ |
29 | ||
4ed46869 KH |
30 | /*** GENERAL NOTE on CHARACTER SET (CHARSET) *** |
31 | ||
32 | A character set ("charset" hereafter) is a meaningful collection | |
33 | (i.e. language, culture, functionality, etc) of characters. Emacs | |
34 | handles multiple charsets at once. Each charset corresponds to one | |
d8e4f486 | 35 | of the ISO charsets. Emacs identifies a charset by a unique |
f49b37c9 KH |
36 | identification number, whereas ISO identifies a charset by a triplet |
37 | of DIMENSION, CHARS and FINAL-CHAR. So, hereafter, just saying | |
38 | "charset" means an identification number (integer value). | |
4ed46869 | 39 | |
d8e4f486 | 40 | The value range of charsets is 0x00, 0x81..0xFE. There are four |
4ed46869 KH |
41 | kinds of charset depending on DIMENSION (1 or 2) and CHARS (94 or |
42 | 96). For instance, a charset of DIMENSION2_CHARS94 contains 94x94 | |
f49b37c9 | 43 | characters. |
4ed46869 KH |
44 | |
45 | Within Emacs Lisp, a charset is treated as a symbol which has a | |
46 | property `charset'. The property value is a vector containing | |
d8e4f486 | 47 | various information about the charset. For readability of C code, |
f49b37c9 | 48 | we use the following convention for C variable names: |
4ed46869 KH |
49 | charset_symbol: Emacs Lisp symbol of a charset |
50 | charset_id: Emacs Lisp integer of an identification number of a charset | |
51 | charset: C integer of an identification number of a charset | |
52 | ||
6e4dc3e1 KH |
53 | Each charset (except for ascii) is assigned a base leading-code |
54 | (range 0x80..0x9E). In addition, a charset of greater than 0xA0 | |
4ed46869 KH |
55 | (whose base leading-code is 0x9A..0x9D) is assigned an extended |
56 | leading-code (range 0xA0..0xFE). In this case, each base | |
d8e4f486 DL |
57 | leading-code specifies the allowable range of extended leading-code |
58 | as shown in the table below. A leading-code is used to represent a | |
4ed46869 KH |
59 | character in Emacs' buffer and string. |
60 | ||
d8e4f486 | 61 | We call a charset which has extended leading-code a "private |
f49b37c9 | 62 | charset" because those are mainly for a charset which is not yet |
4ed46869 | 63 | registered by ISO. On the contrary, we call a charset which does |
d8e4f486 | 64 | not have extended leading-code an "official charset". |
4ed46869 KH |
65 | |
66 | --------------------------------------------------------------------------- | |
67 | charset dimension base leading-code extended leading-code | |
68 | --------------------------------------------------------------------------- | |
69 | 0x00 official dim1 -- none -- -- none -- | |
70 | (ASCII) | |
71 | 0x01..0x7F --never used-- | |
88b837a2 KH |
72 | 0x80 official dim1 -- none -- -- none -- |
73 | (eight-bit-graphic) | |
4ed46869 KH |
74 | 0x81..0x8F official dim1 same as charset -- none -- |
75 | 0x90..0x99 official dim2 same as charset -- none -- | |
6e4dc3e1 KH |
76 | 0x9A..0x9D --never used-- |
77 | 0x9E official dim1 same as charset -- none -- | |
78 | (eight-bit-control) | |
88b837a2 | 79 | 0x9F --never used-- |
4ed46869 KH |
80 | 0xA0..0xDF private dim1 0x9A same as charset |
81 | of 1-column width | |
82 | 0xE0..0xEF private dim1 0x9B same as charset | |
83 | of 2-column width | |
84 | 0xF0..0xF4 private dim2 0x9C same as charset | |
85 | of 1-column width | |
86 | 0xF5..0xFE private dim2 0x9D same as charset | |
87 | of 2-column width | |
88 | 0xFF --never used-- | |
89 | --------------------------------------------------------------------------- | |
90 | ||
4ed46869 KH |
91 | */ |
92 | ||
93 | /* Definition of special leading-codes. */ | |
4ed46869 KH |
94 | /* Leading-code followed by extended leading-code. */ |
95 | #define LEADING_CODE_PRIVATE_11 0x9A /* for private DIMENSION1 of 1-column */ | |
96 | #define LEADING_CODE_PRIVATE_12 0x9B /* for private DIMENSION1 of 2-column */ | |
97 | #define LEADING_CODE_PRIVATE_21 0x9C /* for private DIMENSION2 of 1-column */ | |
5c6257e5 | 98 | #define LEADING_CODE_PRIVATE_22 0x9D /* for private DIMENSION2 of 2-column */ |
4ed46869 | 99 | |
6e4dc3e1 KH |
100 | #define LEADING_CODE_8_BIT_CONTROL 0x9E /* for `eight-bit-control' */ |
101 | ||
4ed46869 KH |
102 | /* Extended leading-code. */ |
103 | /* Start of each extended leading-codes. */ | |
104 | #define LEADING_CODE_EXT_11 0xA0 /* follows LEADING_CODE_PRIVATE_11 */ | |
105 | #define LEADING_CODE_EXT_12 0xE0 /* follows LEADING_CODE_PRIVATE_12 */ | |
106 | #define LEADING_CODE_EXT_21 0xF0 /* follows LEADING_CODE_PRIVATE_21 */ | |
107 | #define LEADING_CODE_EXT_22 0xF5 /* follows LEADING_CODE_PRIVATE_22 */ | |
108 | /* Maximum value of extended leading-codes. */ | |
109 | #define LEADING_CODE_EXT_MAX 0xFE | |
110 | ||
111 | /* Definition of minimum/maximum charset of each DIMENSION. */ | |
2b9eeded | 112 | #define MIN_CHARSET_OFFICIAL_DIMENSION1 0x80 |
4ed46869 KH |
113 | #define MAX_CHARSET_OFFICIAL_DIMENSION1 0x8F |
114 | #define MIN_CHARSET_OFFICIAL_DIMENSION2 0x90 | |
115 | #define MAX_CHARSET_OFFICIAL_DIMENSION2 0x99 | |
116 | #define MIN_CHARSET_PRIVATE_DIMENSION1 LEADING_CODE_EXT_11 | |
117 | #define MIN_CHARSET_PRIVATE_DIMENSION2 LEADING_CODE_EXT_21 | |
118 | ||
03e66c53 KH |
119 | /* Maximum value of overall charset identification number. */ |
120 | #define MAX_CHARSET 0xFE | |
121 | ||
4ed46869 | 122 | /* Definition of special charsets. */ |
6e4dc3e1 KH |
123 | #define CHARSET_ASCII 0 /* 0x00..0x7F */ |
124 | #define CHARSET_8_BIT_CONTROL 0x9E /* 0x80..0x9F */ | |
88b837a2 | 125 | #define CHARSET_8_BIT_GRAPHIC 0x80 /* 0xA0..0xFF */ |
4ed46869 | 126 | |
4ed46869 KH |
127 | extern int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */ |
128 | extern int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */ | |
129 | extern int charset_jisx0208; /* JISX0208.1983 (Japanese Kanji) */ | |
130 | extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */ | |
131 | extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */ | |
132 | extern int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */ | |
133 | extern int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */ | |
bde7944b KH |
134 | extern int charset_mule_unicode_0100_24ff; |
135 | extern int charset_mule_unicode_2500_33ff; | |
136 | extern int charset_mule_unicode_e000_ffff; | |
4ed46869 | 137 | |
6e4dc3e1 KH |
138 | /* Check if CH is an ASCII character or a base leading-code. |
139 | Nowadays, any byte can be the first byte of a character in a | |
140 | multibyte buffer/string. So this macro name is not appropriate. */ | |
c399b461 | 141 | #define CHAR_HEAD_P(ch) ((unsigned char) (ch) < 0xA0) |
4ed46869 KH |
142 | |
143 | /*** GENERAL NOTE on CHARACTER REPRESENTATION *** | |
144 | ||
d8e4f486 DL |
145 | Firstly, the term "character" or "char" is used for a multilingual |
146 | character (of course, including ASCII characters), not for a byte in | |
4ed46869 KH |
147 | computer memory. We use the term "code" or "byte" for the latter |
148 | case. | |
149 | ||
150 | A character is identified by charset and one or two POSITION-CODEs. | |
151 | POSITION-CODE is the position of the character in the charset. A | |
152 | character of DIMENSION1 charset has one POSITION-CODE: POSITION-CODE-1. | |
153 | A character of DIMENSION2 charset has two POSITION-CODE: | |
154 | POSITION-CODE-1 and POSITION-CODE-2. The code range of | |
155 | POSITION-CODE is 0x20..0x7F. | |
156 | ||
157 | Emacs has two kinds of representation of a character: multi-byte | |
d8e4f486 DL |
158 | form (for buffers and strings) and single-word form (for character |
159 | objects in Emacs Lisp). The latter is called "character code" | |
160 | hereafter. Both representations encode the information of charset | |
161 | and POSITION-CODE but in a different way (for instance, the MSB of | |
4ed46869 KH |
162 | POSITION-CODE is set in multi-byte form). |
163 | ||
d8e4f486 DL |
164 | For details of the multi-byte form, see the section "2. Emacs |
165 | internal format handlers" of `coding.c'. | |
4ed46869 KH |
166 | |
167 | Emacs uses 19 bits for a character code. The bits are divided into | |
168 | 3 fields: FIELD1(5bits):FIELD2(7bits):FIELD3(7bits). | |
169 | ||
170 | A character code of DIMENSION1 character uses FIELD2 to hold charset | |
171 | and FIELD3 to hold POSITION-CODE-1. A character code of DIMENSION2 | |
172 | character uses FIELD1 to hold charset, FIELD2 and FIELD3 to hold | |
173 | POSITION-CODE-1 and POSITION-CODE-2 respectively. | |
174 | ||
175 | More precisely... | |
176 | ||
6e4dc3e1 KH |
177 | FIELD2 of DIMENSION1 character (except for ascii, eight-bit-control, |
178 | and eight-bit-graphic) is "charset - 0x70". This is to make all | |
179 | character codes except for ASCII and 8-bit codes greater than 256. | |
180 | So, the range of FIELD2 of DIMENSION1 character is 0, 1, or | |
181 | 0x11..0x7F. | |
4ed46869 KH |
182 | |
183 | FIELD1 of DIMENSION2 character is "charset - 0x8F" for official | |
184 | charset and "charset - 0xE0" for private charset. So, the range of | |
185 | FIELD1 of DIMENSION2 character is 0x01..0x1E. | |
186 | ||
6e4dc3e1 KH |
187 | ----------------------------------------------------------------------------- |
188 | charset FIELD1 (5-bit) FIELD2 (7-bit) FIELD3 (7-bit) | |
189 | ----------------------------------------------------------------------------- | |
190 | ascii 0 0 0x00..0x7F | |
191 | eight-bit-control 0 1 0x00..0x1F | |
192 | eight-bit-graphic 0 1 0x20..0x7F | |
193 | DIMENSION1 0 charset - 0x70 POSITION-CODE-1 | |
194 | DIMENSION2(o) charset - 0x8F POSITION-CODE-1 POSITION-CODE-2 | |
195 | DIMENSION2(p) charset - 0xE0 POSITION-CODE-1 POSITION-CODE-2 | |
196 | ----------------------------------------------------------------------------- | |
4ed46869 | 197 | "(o)": official, "(p)": private |
6e4dc3e1 | 198 | ----------------------------------------------------------------------------- |
4ed46869 KH |
199 | */ |
200 | ||
4ed46869 KH |
201 | /* Masks of each field of character code. */ |
202 | #define CHAR_FIELD1_MASK (0x1F << 14) | |
203 | #define CHAR_FIELD2_MASK (0x7F << 7) | |
204 | #define CHAR_FIELD3_MASK 0x7F | |
205 | ||
206 | /* Macros to access each field of character C. */ | |
207 | #define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14) | |
208 | #define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7) | |
209 | #define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK) | |
210 | ||
211 | /* Minimum character code of character of each DIMENSION. */ | |
212 | #define MIN_CHAR_OFFICIAL_DIMENSION1 \ | |
2b9eeded | 213 | ((0x81 - 0x70) << 7) |
4ed46869 KH |
214 | #define MIN_CHAR_PRIVATE_DIMENSION1 \ |
215 | ((MIN_CHARSET_PRIVATE_DIMENSION1 - 0x70) << 7) | |
216 | #define MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
217 | ((MIN_CHARSET_OFFICIAL_DIMENSION2 - 0x8F) << 14) | |
218 | #define MIN_CHAR_PRIVATE_DIMENSION2 \ | |
219 | ((MIN_CHARSET_PRIVATE_DIMENSION2 - 0xE0) << 14) | |
f49b37c9 KH |
220 | /* Maximum character code currently used plus 1. */ |
221 | #define MAX_CHAR (0x1F << 14) | |
4ed46869 | 222 | |
6e4dc3e1 | 223 | /* 1 if C is a single byte character, else 0. */ |
6f1a3d53 | 224 | #define SINGLE_BYTE_CHAR_P(c) (((unsigned)(c) & 0xFF) == (c)) |
4ed46869 | 225 | |
6e4dc3e1 | 226 | /* 1 if BYTE is an ASCII character in itself, in multibyte mode. */ |
7614f779 KH |
227 | #define ASCII_BYTE_P(byte) ((byte) < 0x80) |
228 | ||
d8e4f486 | 229 | /* A char-table containing information on each character set. |
4ed46869 | 230 | |
d8e4f486 | 231 | Unlike ordinary char-tables, this doesn't contain any nested tables. |
4ed46869 KH |
232 | Only the top level elements are used. Each element is a vector of |
233 | the following information: | |
234 | CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION, | |
235 | LEADING-CODE-BASE, LEADING-CODE-EXT, | |
236 | ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE, | |
237 | REVERSE-CHARSET, SHORT-NAME, LONG-NAME, DESCRIPTION, | |
238 | PLIST. | |
239 | ||
240 | CHARSET-ID (integer) is the identification number of the charset. | |
241 | ||
d8e4f486 DL |
242 | BYTES (integer) is the length of the multi-byte form of a character |
243 | in the charset: one of 1, 2, 3, and 4. | |
4ed46869 KH |
244 | |
245 | DIMENSION (integer) is the number of bytes to represent a character: 1 or 2. | |
246 | ||
247 | CHARS (integer) is the number of characters in a dimension: 94 or 96. | |
248 | ||
249 | WIDTH (integer) is the number of columns a character in the charset | |
6e4dc3e1 | 250 | occupies on the screen: one of 0, 1, and 2.. |
4ed46869 KH |
251 | |
252 | DIRECTION (integer) is the rendering direction of characters in the | |
28d0c844 KH |
253 | charset when rendering. If 0, render from left to right, else |
254 | render from right to left. | |
4ed46869 KH |
255 | |
256 | LEADING-CODE-BASE (integer) is the base leading-code for the | |
257 | charset. | |
258 | ||
259 | LEADING-CODE-EXT (integer) is the extended leading-code for the | |
d8e4f486 | 260 | charset. All charsets of less than 0xA0 have the value 0. |
4ed46869 KH |
261 | |
262 | ISO-FINAL-CHAR (character) is the final character of the | |
6e4dc3e1 KH |
263 | corresponding ISO 2022 charset. It is -1 for such a character |
264 | that is used only internally (e.g. `eight-bit-control'). | |
4ed46869 KH |
265 | |
266 | ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked | |
267 | while encoding to variants of ISO 2022 coding system, one of the | |
6e4dc3e1 KH |
268 | following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR). It |
269 | is -1 for such a character that is used only internally | |
270 | (e.g. `eight-bit-control'). | |
4ed46869 KH |
271 | |
272 | REVERSE-CHARSET (integer) is the charset which differs only in | |
273 | LEFT-TO-RIGHT value from the charset. If there's no such a | |
274 | charset, the value is -1. | |
d8e4f486 | 275 | |
4ed46869 KH |
276 | SHORT-NAME (string) is the short name to refer to the charset. |
277 | ||
278 | LONG-NAME (string) is the long name to refer to the charset. | |
279 | ||
280 | DESCRIPTION (string) is the description string of the charset. | |
281 | ||
282 | PLIST (property list) may contain any type of information a user | |
d8e4f486 | 283 | wants to put and get by functions `put-charset-property' and |
4ed46869 KH |
284 | `get-charset-property' respectively. */ |
285 | extern Lisp_Object Vcharset_table; | |
286 | ||
287 | /* Macros to access various information of CHARSET in Vcharset_table. | |
288 | We provide these macros for efficiency. No range check of CHARSET. */ | |
289 | ||
a3f4e3d9 | 290 | /* Return entry of CHARSET (C integer) in Vcharset_table. */ |
d6f92c04 KH |
291 | #define CHARSET_TABLE_ENTRY(charset) \ |
292 | XCHAR_TABLE (Vcharset_table)->contents[((charset) == CHARSET_ASCII \ | |
293 | ? 0 : (charset) + 128)] | |
4ed46869 KH |
294 | |
295 | /* Return information INFO-IDX of CHARSET. */ | |
296 | #define CHARSET_TABLE_INFO(charset, info_idx) \ | |
297 | XVECTOR (CHARSET_TABLE_ENTRY (charset))->contents[info_idx] | |
298 | ||
299 | #define CHARSET_ID_IDX (0) | |
300 | #define CHARSET_BYTES_IDX (1) | |
301 | #define CHARSET_DIMENSION_IDX (2) | |
302 | #define CHARSET_CHARS_IDX (3) | |
303 | #define CHARSET_WIDTH_IDX (4) | |
304 | #define CHARSET_DIRECTION_IDX (5) | |
305 | #define CHARSET_LEADING_CODE_BASE_IDX (6) | |
306 | #define CHARSET_LEADING_CODE_EXT_IDX (7) | |
307 | #define CHARSET_ISO_FINAL_CHAR_IDX (8) | |
308 | #define CHARSET_ISO_GRAPHIC_PLANE_IDX (9) | |
309 | #define CHARSET_REVERSE_CHARSET_IDX (10) | |
310 | #define CHARSET_SHORT_NAME_IDX (11) | |
311 | #define CHARSET_LONG_NAME_IDX (12) | |
312 | #define CHARSET_DESCRIPTION_IDX (13) | |
313 | #define CHARSET_PLIST_IDX (14) | |
314 | /* Size of a vector of each entry of Vcharset_table. */ | |
315 | #define CHARSET_MAX_IDX (15) | |
316 | ||
317 | /* And several more macros to be used frequently. */ | |
318 | #define CHARSET_BYTES(charset) \ | |
319 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX)) | |
320 | #define CHARSET_DIMENSION(charset) \ | |
321 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX)) | |
322 | #define CHARSET_CHARS(charset) \ | |
323 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX)) | |
324 | #define CHARSET_WIDTH(charset) \ | |
325 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX)) | |
326 | #define CHARSET_DIRECTION(charset) \ | |
327 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX)) | |
328 | #define CHARSET_LEADING_CODE_BASE(charset) \ | |
329 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX)) | |
330 | #define CHARSET_LEADING_CODE_EXT(charset) \ | |
331 | XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX)) | |
332 | #define CHARSET_ISO_FINAL_CHAR(charset) \ | |
6e4dc3e1 | 333 | XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX)) |
4ed46869 | 334 | #define CHARSET_ISO_GRAPHIC_PLANE(charset) \ |
6e4dc3e1 | 335 | XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX)) |
4ed46869 KH |
336 | #define CHARSET_REVERSE_CHARSET(charset) \ |
337 | XINT (CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX)) | |
338 | ||
339 | /* Macros to specify direction of a charset. */ | |
340 | #define CHARSET_DIRECTION_LEFT_TO_RIGHT 0 | |
341 | #define CHARSET_DIRECTION_RIGHT_TO_LEFT 1 | |
342 | ||
343 | /* A vector of charset symbol indexed by charset-id. This is used | |
344 | only for returning charset symbol from C functions. */ | |
345 | extern Lisp_Object Vcharset_symbol_table; | |
346 | ||
347 | /* Return symbol of CHARSET. */ | |
348 | #define CHARSET_SYMBOL(charset) \ | |
349 | XVECTOR (Vcharset_symbol_table)->contents[charset] | |
350 | ||
384107f2 | 351 | /* 1 if CHARSET is in valid value range, else 0. */ |
4ed46869 KH |
352 | #define CHARSET_VALID_P(charset) \ |
353 | ((charset) == 0 \ | |
f49b37c9 | 354 | || ((charset) > 0x80 && (charset) <= MAX_CHARSET_OFFICIAL_DIMENSION2) \ |
6e4dc3e1 KH |
355 | || ((charset) >= MIN_CHARSET_PRIVATE_DIMENSION1 \ |
356 | && (charset) <= MAX_CHARSET) \ | |
357 | || ((charset) == CHARSET_8_BIT_CONTROL) \ | |
358 | || ((charset) == CHARSET_8_BIT_GRAPHIC)) | |
4ed46869 | 359 | |
f49b37c9 | 360 | /* 1 if CHARSET is already defined, else 0. */ |
4ed46869 | 361 | #define CHARSET_DEFINED_P(charset) \ |
03e66c53 | 362 | (((charset) >= 0) && ((charset) <= MAX_CHARSET) \ |
4ed46869 KH |
363 | && !NILP (CHARSET_TABLE_ENTRY (charset))) |
364 | ||
365 | /* Since the information CHARSET-BYTES and CHARSET-WIDTH of | |
6e4dc3e1 | 366 | Vcharset_table can be retrieved only by the first byte of |
4ed46869 KH |
367 | multi-byte form (an ASCII code or a base leading-code), we provide |
368 | here tables to be used by macros BYTES_BY_CHAR_HEAD and | |
369 | WIDTH_BY_CHAR_HEAD for faster information retrieval. */ | |
370 | extern int bytes_by_char_head[256]; | |
371 | extern int width_by_char_head[256]; | |
372 | ||
6e4dc3e1 KH |
373 | #define BYTES_BY_CHAR_HEAD(char_head) \ |
374 | (ASCII_BYTE_P (char_head) ? 1 : bytes_by_char_head[char_head]) | |
375 | #define WIDTH_BY_CHAR_HEAD(char_head) \ | |
376 | (ASCII_BYTE_P (char_head) ? 1 : width_by_char_head[char_head]) | |
4ed46869 KH |
377 | |
378 | /* Charset of the character C. */ | |
6e4dc3e1 KH |
379 | #define CHAR_CHARSET(c) \ |
380 | (SINGLE_BYTE_CHAR_P (c) \ | |
381 | ? (ASCII_BYTE_P (c) \ | |
382 | ? CHARSET_ASCII \ | |
383 | : (c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC) \ | |
384 | : ((c) < MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
385 | ? CHAR_FIELD2 (c) + 0x70 \ | |
386 | : ((c) < MIN_CHAR_PRIVATE_DIMENSION2 \ | |
387 | ? CHAR_FIELD1 (c) + 0x8F \ | |
f49b37c9 | 388 | : CHAR_FIELD1 (c) + 0xE0))) |
4ed46869 | 389 | |
f49b37c9 | 390 | /* Check if two characters C1 and C2 belong to the same charset. */ |
6e4dc3e1 KH |
391 | #define SAME_CHARSET_P(c1, c2) \ |
392 | (c1 < MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
393 | ? (c1 & CHAR_FIELD2_MASK) == (c2 & CHAR_FIELD2_MASK) \ | |
394 | : (c1 & CHAR_FIELD1_MASK) == (c2 & CHAR_FIELD1_MASK)) | |
4ed46869 KH |
395 | |
396 | /* Return a character of which charset is CHARSET and position-codes | |
397 | are C1 and C2. DIMENSION1 character ignores C2. */ | |
6e4dc3e1 KH |
398 | #define MAKE_CHAR(charset, c1, c2) \ |
399 | ((charset) == CHARSET_ASCII \ | |
400 | ? (c1) & 0x7F \ | |
401 | : (((charset) == CHARSET_8_BIT_CONTROL \ | |
402 | || (charset) == CHARSET_8_BIT_GRAPHIC) \ | |
403 | ? ((c1) & 0x7F) | 0x80 \ | |
f164d9b5 KH |
404 | : ((CHARSET_DEFINED_P (charset) \ |
405 | ? CHARSET_DIMENSION (charset) == 1 \ | |
406 | : (charset) < MIN_CHARSET_PRIVATE_DIMENSION2) \ | |
2cd31e75 | 407 | ? (((charset) - 0x70) << 7) | ((c1) <= 0 ? 0 : ((c1) & 0x7F)) \ |
6e4dc3e1 KH |
408 | : ((((charset) \ |
409 | - ((charset) < MIN_CHARSET_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)) \ | |
410 | << 14) \ | |
411 | | ((c2) <= 0 ? 0 : ((c2) & 0x7F)) \ | |
412 | | ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7)))))) | |
413 | ||
4ed46869 | 414 | |
15979e9e KH |
415 | /* If GENERICP is nonzero, return nonzero iff C is a valid normal or |
416 | generic character. If GENERICP is zero, return nonzero iff C is a | |
417 | valid normal character. */ | |
418 | #define CHAR_VALID_P(c, genericp) \ | |
419 | ((c) >= 0 \ | |
420 | && (SINGLE_BYTE_CHAR_P (c) || char_valid_p (c, genericp))) | |
c6112b99 | 421 | |
d74d0ca5 | 422 | /* This default value is used when nonascii-translation-table or |
54e15bb9 KH |
423 | nonascii-insert-offset fail to convert unibyte character to a valid |
424 | multibyte character. This makes a Latin-1 character. */ | |
425 | ||
426 | #define DEFAULT_NONASCII_INSERT_OFFSET 0x800 | |
427 | ||
6e4dc3e1 KH |
428 | /* Parse multibyte string STR of length LENGTH and set BYTES to the |
429 | byte length of a character at STR. */ | |
430 | ||
431 | #ifdef BYTE_COMBINING_DEBUG | |
384107f2 KH |
432 | |
433 | #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ | |
434 | do { \ | |
435 | int i = 1; \ | |
f49b37c9 | 436 | while (i < (length) && ! CHAR_HEAD_P ((str)[i])) i++; \ |
6e4dc3e1 KH |
437 | (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]); \ |
438 | if ((bytes) > i) \ | |
439 | abort (); \ | |
384107f2 | 440 | } while (0) |
54e15bb9 | 441 | |
6e4dc3e1 | 442 | #else /* not BYTE_COMBINING_DEBUG */ |
feb453fa | 443 | |
6e4dc3e1 | 444 | #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \ |
304f9d2a | 445 | ((void)(length), (bytes) = BYTES_BY_CHAR_HEAD ((str)[0])) |
feb453fa | 446 | |
6e4dc3e1 KH |
447 | #endif /* not BYTE_COMBINING_DEBUG */ |
448 | ||
1efcd78f KH |
449 | #define VALID_LEADING_CODE_P(code) \ |
450 | (! NILP (CHARSET_TABLE_ENTRY (code))) | |
451 | ||
6e4dc3e1 KH |
452 | /* Return 1 iff the byte sequence at unibyte string STR (LENGTH bytes) |
453 | is valid as a multibyte form. If valid, by a side effect, BYTES is | |
454 | set to the byte length of the multibyte form. */ | |
455 | ||
1efcd78f KH |
456 | #define UNIBYTE_STR_AS_MULTIBYTE_P(str, length, bytes) \ |
457 | (((str)[0] < 0x80 || (str)[0] >= 0xA0) \ | |
458 | ? ((bytes) = 1) \ | |
459 | : (((bytes) = BYTES_BY_CHAR_HEAD ((str)[0])), \ | |
460 | ((bytes) <= (length) \ | |
461 | && !CHAR_HEAD_P ((str)[1]) \ | |
462 | && ((bytes) == 2 \ | |
463 | ? (str)[0] != LEADING_CODE_8_BIT_CONTROL \ | |
464 | : (!CHAR_HEAD_P ((str)[2]) \ | |
465 | && ((bytes) == 3 \ | |
466 | ? (((str)[0] != LEADING_CODE_PRIVATE_11 \ | |
467 | && (str)[0] != LEADING_CODE_PRIVATE_12) \ | |
468 | || VALID_LEADING_CODE_P (str[1])) \ | |
469 | : (!CHAR_HEAD_P ((str)[3]) \ | |
470 | && VALID_LEADING_CODE_P (str[1])))))))) | |
471 | ||
6e4dc3e1 KH |
472 | |
473 | /* Return 1 iff the byte sequence at multibyte string STR is valid as | |
474 | a unibyte form. By a side effect, BYTES is set to the byte length | |
475 | of one character at STR. */ | |
476 | ||
477 | #define MULTIBYTE_STR_AS_UNIBYTE_P(str, bytes) \ | |
478 | ((bytes) = BYTES_BY_CHAR_HEAD ((str)[0]), \ | |
479 | (str)[0] != LEADING_CODE_8_BIT_CONTROL) | |
4ed46869 | 480 | |
feb453fa RS |
481 | /* The charset of character C is stored in CHARSET, and the |
482 | position-codes of C are stored in C1 and C2. | |
9dd2aa1a | 483 | We store -1 in C2 if the dimension of the charset is 1. */ |
feb453fa | 484 | |
f164d9b5 KH |
485 | #define SPLIT_CHAR(c, charset, c1, c2) \ |
486 | (SINGLE_BYTE_CHAR_P (c) \ | |
487 | ? ((charset \ | |
488 | = (ASCII_BYTE_P (c) \ | |
489 | ? CHARSET_ASCII \ | |
490 | : ((c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC))), \ | |
491 | c1 = (c), c2 = -1) \ | |
492 | : ((c) & CHAR_FIELD1_MASK \ | |
493 | ? (charset = (CHAR_FIELD1 (c) \ | |
494 | + ((c) < MIN_CHAR_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)), \ | |
495 | c1 = CHAR_FIELD2 (c), \ | |
496 | c2 = CHAR_FIELD3 (c)) \ | |
497 | : (charset = CHAR_FIELD2 (c) + 0x70, \ | |
498 | c1 = CHAR_FIELD3 (c), \ | |
6e4dc3e1 | 499 | c2 = -1))) |
4ed46869 | 500 | |
384107f2 | 501 | /* Return 1 iff character C has valid printable glyph. */ |
6e4dc3e1 | 502 | #define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c)) |
384107f2 | 503 | |
feb453fa RS |
504 | /* The charset of the character at STR is stored in CHARSET, and the |
505 | position-codes are stored in C1 and C2. | |
f49b37c9 | 506 | We store -1 in C2 if the character is just 2 bytes. */ |
feb453fa | 507 | |
f49b37c9 KH |
508 | #define SPLIT_STRING(str, len, charset, c1, c2) \ |
509 | ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) < 2 \ | |
510 | || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > len \ | |
511 | || split_string (str, len, &charset, &c1, &c2) < 0) \ | |
512 | ? c1 = *(str), charset = CHARSET_ASCII \ | |
4ed46869 KH |
513 | : charset) |
514 | ||
4ed46869 KH |
515 | /* Mapping table from ISO2022's charset (specified by DIMENSION, |
516 | CHARS, and FINAL_CHAR) to Emacs' charset. Should be accessed by | |
517 | macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR). */ | |
518 | extern int iso_charset_table[2][2][128]; | |
519 | ||
520 | #define ISO_CHARSET_TABLE(dimension, chars, final_char) \ | |
521 | iso_charset_table[XINT (dimension) - 1][XINT (chars) > 94][XINT (final_char)] | |
522 | ||
523 | #define BASE_LEADING_CODE_P(c) (BYTES_BY_CHAR_HEAD ((unsigned char) (c)) > 1) | |
524 | ||
3124bc0e | 525 | /* Return how many bytes C will occupy in a multibyte buffer. */ |
6e4dc3e1 KH |
526 | #define CHAR_BYTES(c) \ |
527 | (SINGLE_BYTE_CHAR_P (c) \ | |
528 | ? ((ASCII_BYTE_P (c) || (c) >= 0xA0) ? 1 : 2) \ | |
529 | : char_bytes (c)) | |
3124bc0e | 530 | |
4ed46869 | 531 | /* The following two macros CHAR_STRING and STRING_CHAR are the main |
d8e4f486 | 532 | entry points to convert between Emacs's two types of character |
4ed46869 KH |
533 | representations: multi-byte form and single-word form (character |
534 | code). */ | |
535 | ||
f49b37c9 | 536 | /* Store multi-byte form of the character C in STR. The caller should |
6e4dc3e1 KH |
537 | allocate at least MAX_MULTIBYTE_LENGTH bytes area at STR in |
538 | advance. Returns the length of the multi-byte form. If C is an | |
539 | invalid character code, signal an error. */ | |
4ed46869 | 540 | |
e10ae834 KH |
541 | #define CHAR_STRING(c, str) \ |
542 | (SINGLE_BYTE_CHAR_P (c) \ | |
6f1a3d53 | 543 | ? ((ASCII_BYTE_P (c) || c >= 0xA0) \ |
e10ae834 KH |
544 | ? (*(str) = (unsigned char)(c), 1) \ |
545 | : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \ | |
6e4dc3e1 | 546 | : char_to_string (c, (unsigned char *) str)) |
4ed46869 | 547 | |
e06aa1f9 GM |
548 | /* Like CHAR_STRING but don't signal an error if C is invalid. |
549 | Value is -1 in this case. */ | |
550 | ||
551 | #define CHAR_STRING_NO_SIGNAL(c, str) \ | |
552 | (SINGLE_BYTE_CHAR_P (c) \ | |
553 | ? ((ASCII_BYTE_P (c) || c >= 0xA0) \ | |
554 | ? (*(str) = (unsigned char)(c), 1) \ | |
555 | : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \ | |
556 | : char_to_string_1 (c, (unsigned char *) str)) | |
557 | ||
4ed46869 KH |
558 | /* Return a character code of the character of which multi-byte form |
559 | is at STR and the length is LEN. If STR doesn't contain valid | |
560 | multi-byte form, only the first byte in STR is returned. */ | |
561 | ||
dfd57aa7 KH |
562 | #define STRING_CHAR(str, len) \ |
563 | (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1 \ | |
564 | ? (unsigned char) *(str) \ | |
f49b37c9 | 565 | : string_to_char (str, len, 0)) |
4ed46869 | 566 | |
384107f2 KH |
567 | /* This is like STRING_CHAR but the third arg ACTUAL_LEN is set to the |
568 | length of the multi-byte form. Just to know the length, use | |
4ed46869 KH |
569 | MULTIBYTE_FORM_LENGTH. */ |
570 | ||
384107f2 KH |
571 | #define STRING_CHAR_AND_LENGTH(str, len, actual_len) \ |
572 | (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1 \ | |
573 | ? ((actual_len) = 1), (unsigned char) *(str) \ | |
f49b37c9 | 574 | : string_to_char (str, len, &(actual_len))) |
d74d0ca5 | 575 | |
6e4dc3e1 KH |
576 | /* Fetch the "next" character from Lisp string STRING at byte position |
577 | BYTEIDX, character position CHARIDX. Store it into OUTPUT. | |
520afed1 RS |
578 | |
579 | All the args must be side-effect-free. | |
580 | BYTEIDX and CHARIDX must be lvalues; | |
581 | we increment them past the character fetched. */ | |
582 | ||
6e4dc3e1 KH |
583 | #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX) \ |
584 | if (1) \ | |
585 | { \ | |
586 | CHARIDX++; \ | |
587 | if (STRING_MULTIBYTE (STRING)) \ | |
588 | { \ | |
8a25217a | 589 | const unsigned char *ptr = SDATA (STRING) + BYTEIDX; \ |
9f5348e3 | 590 | int space_left = SBYTES (STRING) - BYTEIDX; \ |
6e4dc3e1 KH |
591 | int actual_len; \ |
592 | \ | |
593 | OUTPUT = STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len); \ | |
594 | BYTEIDX += actual_len; \ | |
595 | } \ | |
596 | else \ | |
d5db4077 | 597 | OUTPUT = SREF (STRING, BYTEIDX++); \ |
6e4dc3e1 KH |
598 | } \ |
599 | else | |
600 | ||
601 | /* Like FETCH_STRING_CHAR_ADVANCE but assume STRING is multibyte. */ | |
602 | ||
603 | #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX) \ | |
520afed1 RS |
604 | if (1) \ |
605 | { \ | |
8a25217a | 606 | const unsigned char *fetch_string_char_ptr = SDATA (STRING) + BYTEIDX; \ |
9f5348e3 | 607 | int fetch_string_char_space_left = SBYTES (STRING) - BYTEIDX; \ |
520afed1 RS |
608 | int actual_len; \ |
609 | \ | |
610 | OUTPUT \ | |
611 | = STRING_CHAR_AND_LENGTH (fetch_string_char_ptr, \ | |
612 | fetch_string_char_space_left, actual_len); \ | |
613 | \ | |
614 | BYTEIDX += actual_len; \ | |
615 | CHARIDX++; \ | |
616 | } \ | |
617 | else | |
618 | ||
6e4dc3e1 KH |
619 | /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current |
620 | buffer. */ | |
f49b37c9 KH |
621 | |
622 | #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX) \ | |
623 | if (1) \ | |
624 | { \ | |
f49b37c9 | 625 | CHARIDX++; \ |
6e4dc3e1 KH |
626 | if (!NILP (current_buffer->enable_multibyte_characters)) \ |
627 | { \ | |
628 | unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX); \ | |
629 | int space_left = ((CHARIDX < GPT ? GPT_BYTE : Z_BYTE) - BYTEIDX); \ | |
630 | int actual_len; \ | |
631 | \ | |
632 | OUTPUT= STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len); \ | |
633 | BYTEIDX += actual_len; \ | |
634 | } \ | |
635 | else \ | |
636 | { \ | |
637 | OUTPUT = *(BYTE_POS_ADDR (BYTEIDX)); \ | |
638 | BYTEIDX++; \ | |
639 | } \ | |
f49b37c9 KH |
640 | } \ |
641 | else | |
642 | ||
4ed46869 KH |
643 | /* Return the length of the multi-byte form at string STR of length LEN. */ |
644 | ||
d121936f KH |
645 | #define MULTIBYTE_FORM_LENGTH(str, len) \ |
646 | (BYTES_BY_CHAR_HEAD (*(unsigned char *)(str)) == 1 \ | |
647 | ? 1 \ | |
4ed46869 KH |
648 | : multibyte_form_length (str, len)) |
649 | ||
d3985b78 KH |
650 | /* If P is before LIMIT, advance P to the next character boundary. It |
651 | assumes that P is already at a character boundary of the sane | |
652 | mulitbyte form whose end address is LIMIT. */ | |
653 | ||
654 | #define NEXT_CHAR_BOUNDARY(p, limit) \ | |
655 | do { \ | |
656 | if ((p) < (limit)) \ | |
657 | (p) += BYTES_BY_CHAR_HEAD (*(p)); \ | |
658 | } while (0) | |
659 | ||
660 | ||
661 | /* If P is after LIMIT, advance P to the previous character boundary. | |
662 | It assumes that P is already at a character boundary of the sane | |
663 | mulitbyte form whose beginning address is LIMIT. */ | |
664 | ||
665 | #define PREV_CHAR_BOUNDARY(p, limit) \ | |
666 | do { \ | |
667 | if ((p) > (limit)) \ | |
668 | { \ | |
669 | const unsigned char *p0 = (p); \ | |
670 | do { \ | |
671 | p0--; \ | |
672 | } while (p0 >= limit && ! CHAR_HEAD_P (*p0)); \ | |
673 | (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1; \ | |
674 | } \ | |
675 | } while (0) | |
676 | ||
677 | ||
4ed46869 KH |
678 | #ifdef emacs |
679 | ||
384107f2 KH |
680 | /* Increase the buffer byte position POS_BYTE of the current buffer to |
681 | the next character boundary. This macro relies on the fact that | |
682 | *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
683 | '\0'. No range checking of POS. */ | |
6e4dc3e1 KH |
684 | |
685 | #ifdef BYTE_COMBINING_DEBUG | |
686 | ||
384107f2 KH |
687 | #define INC_POS(pos_byte) \ |
688 | do { \ | |
689 | unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
690 | if (BASE_LEADING_CODE_P (*p)) \ | |
691 | { \ | |
692 | int len, bytes; \ | |
693 | len = Z_BYTE - pos_byte; \ | |
694 | PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
695 | pos_byte += bytes; \ | |
696 | } \ | |
697 | else \ | |
698 | pos_byte++; \ | |
4ed46869 KH |
699 | } while (0) |
700 | ||
6e4dc3e1 KH |
701 | #else /* not BYTE_COMBINING_DEBUG */ |
702 | ||
703 | #define INC_POS(pos_byte) \ | |
704 | do { \ | |
705 | unsigned char *p = BYTE_POS_ADDR (pos_byte); \ | |
706 | pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
707 | } while (0) | |
708 | ||
709 | #endif /* not BYTE_COMBINING_DEBUG */ | |
710 | ||
384107f2 KH |
711 | /* Decrease the buffer byte position POS_BYTE of the current buffer to |
712 | the previous character boundary. No range checking of POS. */ | |
713 | #define DEC_POS(pos_byte) \ | |
714 | do { \ | |
715 | unsigned char *p, *p_min; \ | |
716 | \ | |
717 | pos_byte--; \ | |
718 | if (pos_byte < GPT_BYTE) \ | |
02dcfd84 | 719 | p = BEG_ADDR + pos_byte - BEG_BYTE, p_min = BEG_ADDR; \ |
384107f2 | 720 | else \ |
02dcfd84 | 721 | p = BEG_ADDR + GAP_SIZE + pos_byte - BEG_BYTE, p_min = GAP_END_ADDR;\ |
384107f2 KH |
722 | if (p > p_min && !CHAR_HEAD_P (*p)) \ |
723 | { \ | |
724 | unsigned char *pend = p--; \ | |
725 | int len, bytes; \ | |
02dcfd84 SM |
726 | if (p_min < p - MAX_MULTIBYTE_LENGTH) \ |
727 | p_min = p - MAX_MULTIBYTE_LENGTH; \ | |
384107f2 KH |
728 | while (p > p_min && !CHAR_HEAD_P (*p)) p--; \ |
729 | len = pend + 1 - p; \ | |
730 | PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
731 | if (bytes == len) \ | |
732 | pos_byte -= len - 1; \ | |
733 | } \ | |
c399b461 RS |
734 | } while (0) |
735 | ||
736 | /* Increment both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
737 | ||
d619ee06 RS |
738 | #define INC_BOTH(charpos, bytepos) \ |
739 | do \ | |
740 | { \ | |
741 | (charpos)++; \ | |
742 | if (NILP (current_buffer->enable_multibyte_characters)) \ | |
743 | (bytepos)++; \ | |
744 | else \ | |
745 | INC_POS ((bytepos)); \ | |
746 | } \ | |
c399b461 RS |
747 | while (0) |
748 | ||
749 | /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way. */ | |
750 | ||
d619ee06 RS |
751 | #define DEC_BOTH(charpos, bytepos) \ |
752 | do \ | |
753 | { \ | |
754 | (charpos)--; \ | |
755 | if (NILP (current_buffer->enable_multibyte_characters)) \ | |
756 | (bytepos)--; \ | |
757 | else \ | |
758 | DEC_POS ((bytepos)); \ | |
759 | } \ | |
c399b461 RS |
760 | while (0) |
761 | ||
384107f2 KH |
762 | /* Increase the buffer byte position POS_BYTE of the current buffer to |
763 | the next character boundary. This macro relies on the fact that | |
764 | *GPT_ADDR and *Z_ADDR are always accessible and the values are | |
765 | '\0'. No range checking of POS_BYTE. */ | |
6e4dc3e1 KH |
766 | |
767 | #ifdef BYTE_COMBINING_DEBUG | |
768 | ||
384107f2 KH |
769 | #define BUF_INC_POS(buf, pos_byte) \ |
770 | do { \ | |
771 | unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
772 | if (BASE_LEADING_CODE_P (*p)) \ | |
bb5999ae | 773 | { \ |
384107f2 KH |
774 | int len, bytes; \ |
775 | len = BUF_Z_BYTE (buf) - pos_byte; \ | |
776 | PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
777 | pos_byte += bytes; \ | |
bb5999ae | 778 | } \ |
384107f2 KH |
779 | else \ |
780 | pos_byte++; \ | |
781 | } while (0) | |
782 | ||
6e4dc3e1 KH |
783 | #else /* not BYTE_COMBINING_DEBUG */ |
784 | ||
785 | #define BUF_INC_POS(buf, pos_byte) \ | |
786 | do { \ | |
787 | unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte); \ | |
788 | pos_byte += BYTES_BY_CHAR_HEAD (*p); \ | |
789 | } while (0) | |
790 | ||
791 | #endif /* not BYTE_COMBINING_DEBUG */ | |
792 | ||
384107f2 KH |
793 | /* Decrease the buffer byte position POS_BYTE of the current buffer to |
794 | the previous character boundary. No range checking of POS_BYTE. */ | |
795 | #define BUF_DEC_POS(buf, pos_byte) \ | |
796 | do { \ | |
797 | unsigned char *p, *p_min; \ | |
798 | pos_byte--; \ | |
799 | if (pos_byte < BUF_GPT_BYTE (buf)) \ | |
800 | { \ | |
02dcfd84 | 801 | p = BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE; \ |
384107f2 KH |
802 | p_min = BUF_BEG_ADDR (buf); \ |
803 | } \ | |
804 | else \ | |
805 | { \ | |
02dcfd84 | 806 | p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - BEG_BYTE;\ |
384107f2 KH |
807 | p_min = BUF_GAP_END_ADDR (buf); \ |
808 | } \ | |
809 | if (p > p_min && !CHAR_HEAD_P (*p)) \ | |
810 | { \ | |
811 | unsigned char *pend = p--; \ | |
812 | int len, bytes; \ | |
02dcfd84 SM |
813 | if (p_min < p - MAX_MULTIBYTE_LENGTH) \ |
814 | p_min = p - MAX_MULTIBYTE_LENGTH; \ | |
384107f2 KH |
815 | while (p > p_min && !CHAR_HEAD_P (*p)) p--; \ |
816 | len = pend + 1 - p; \ | |
817 | PARSE_MULTIBYTE_SEQ (p, len, bytes); \ | |
818 | if (bytes == len) \ | |
819 | pos_byte -= len - 1; \ | |
820 | } \ | |
4ed46869 KH |
821 | } while (0) |
822 | ||
823 | #endif /* emacs */ | |
824 | ||
f49b37c9 KH |
825 | /* This is the maximum byte length of multi-byte sequence. */ |
826 | #define MAX_MULTIBYTE_LENGTH 4 | |
4ed46869 | 827 | |
bb5999ae KH |
828 | extern void invalid_character P_ ((int)); |
829 | ||
62c6686f | 830 | extern int translate_char P_ ((Lisp_Object, int, int, int, int)); |
f49b37c9 | 831 | extern int split_string P_ ((const unsigned char *, int, int *, |
c04809fb | 832 | unsigned char *, unsigned char *)); |
f49b37c9 | 833 | extern int char_to_string P_ ((int, unsigned char *)); |
e06aa1f9 | 834 | extern int char_to_string_1 P_ ((int, unsigned char *)); |
f49b37c9 | 835 | extern int string_to_char P_ ((const unsigned char *, int, int *)); |
384107f2 | 836 | extern int char_printable_p P_ ((int c)); |
8867de67 | 837 | extern int multibyte_form_length P_ ((const unsigned char *, int)); |
8a25217a KR |
838 | extern void parse_str_as_multibyte P_ ((const unsigned char *, int, int *, |
839 | int *)); | |
6e4dc3e1 | 840 | extern int str_as_multibyte P_ ((unsigned char *, int, int, int *)); |
347abaf7 | 841 | extern int parse_str_to_multibyte P_ ((unsigned char *, int)); |
6e4dc3e1 KH |
842 | extern int str_to_multibyte P_ ((unsigned char *, int, int)); |
843 | extern int str_as_unibyte P_ ((unsigned char *, int)); | |
c04809fb | 844 | extern int get_charset_id P_ ((Lisp_Object)); |
8a25217a | 845 | extern int find_charset_in_text P_ ((const unsigned char *, int, int, int *, |
6e4dc3e1 | 846 | Lisp_Object)); |
c04809fb | 847 | extern int strwidth P_ ((unsigned char *, int)); |
8a25217a | 848 | extern int c_string_width P_ ((const unsigned char *, int, int, int *, int *)); |
417ef8f6 | 849 | extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *)); |
3124bc0e | 850 | extern int char_bytes P_ ((int)); |
c2d1e590 | 851 | extern int char_valid_p P_ ((int, int)); |
2db95897 | 852 | |
9028b39e SM |
853 | EXFUN (Funibyte_char_to_multibyte, 1); |
854 | ||
d74d0ca5 | 855 | extern Lisp_Object Vtranslation_table_vector; |
62c6686f | 856 | |
d74d0ca5 | 857 | /* Return a translation table of id number ID. */ |
62c6686f | 858 | #define GET_TRANSLATION_TABLE(id) \ |
e35efe89 | 859 | (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)])) |
c1f6608b | 860 | |
69535a4b KH |
861 | /* A char-table for characters which may invoke auto-filling. */ |
862 | extern Lisp_Object Vauto_fill_chars; | |
863 | ||
c1f6608b KH |
864 | /* Copy LEN bytes from FROM to TO. This macro should be used only |
865 | when a caller knows that LEN is short and the obvious copy loop is | |
6e4dc3e1 KH |
866 | faster than calling bcopy which has some overhead. Copying a |
867 | multibyte sequence of a multibyte character is the typical case. */ | |
c1f6608b KH |
868 | |
869 | #define BCOPY_SHORT(from, to, len) \ | |
870 | do { \ | |
871 | int i = len; \ | |
a9fb257e KR |
872 | const unsigned char *from_p = from; \ |
873 | unsigned char *to_p = to; \ | |
6e4dc3e1 | 874 | while (i--) *to_p++ = *from_p++; \ |
c1f6608b KH |
875 | } while (0) |
876 | ||
aa01a892 | 877 | #endif /* EMACS_CHARSET_H */ |
ab5796a9 MB |
878 | |
879 | /* arch-tag: 3b96db55-4961-481d-ac3e-219f46a2b3aa | |
880 | (do not change this comment) */ |