charset.h 33 KB
Newer Older
1
/* Header for multibyte character handler.
Richard M. Stallman's avatar
Richard M. Stallman committed
2
   Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
3
   Licensed to the Free Software Foundation.
4
   Copyright (C) 2001 Free Software Foundation, Inc.
Karl Heuer's avatar
Karl Heuer committed
5

Karl Heuer's avatar
Karl Heuer committed
6 7 8 9 10 11
This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Karl Heuer's avatar
Karl Heuer committed
12

Karl Heuer's avatar
Karl Heuer committed
13 14 15 16
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
Karl Heuer's avatar
Karl Heuer committed
17

Karl Heuer's avatar
Karl Heuer committed
18 19 20 21
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */
Karl Heuer's avatar
Karl Heuer committed
22

23 24
#ifndef EMACS_CHARSET_H
#define EMACS_CHARSET_H
Karl Heuer's avatar
Karl Heuer committed
25

26 27
/* #define BYTE_COMBINING_DEBUG */

Karl Heuer's avatar
Karl Heuer committed
28 29 30 31 32
/*** GENERAL NOTE on CHARACTER SET (CHARSET) ***

  A character set ("charset" hereafter) is a meaningful collection
  (i.e. language, culture, functionality, etc) of characters.  Emacs
  handles multiple charsets at once.  Each charset corresponds to one
Dave Love's avatar
Dave Love committed
33
  of the ISO charsets.  Emacs identifies a charset by a unique
34 35 36
  identification number, whereas ISO identifies a charset by a triplet
  of DIMENSION, CHARS and FINAL-CHAR.  So, hereafter, just saying
  "charset" means an identification number (integer value).
Karl Heuer's avatar
Karl Heuer committed
37

Dave Love's avatar
Dave Love committed
38
  The value range of charsets is 0x00, 0x81..0xFE.  There are four
Karl Heuer's avatar
Karl Heuer committed
39 40
  kinds of charset depending on DIMENSION (1 or 2) and CHARS (94 or
  96).  For instance, a charset of DIMENSION2_CHARS94 contains 94x94
41
  characters.
Karl Heuer's avatar
Karl Heuer committed
42 43 44

  Within Emacs Lisp, a charset is treated as a symbol which has a
  property `charset'.  The property value is a vector containing
Dave Love's avatar
Dave Love committed
45
  various information about the charset.  For readability of C code,
46
  we use the following convention for C variable names:
Karl Heuer's avatar
Karl Heuer committed
47 48 49 50
	charset_symbol: Emacs Lisp symbol of a charset
	charset_id: Emacs Lisp integer of an identification number of a charset
	charset: C integer of an identification number of a charset

51 52
  Each charset (except for ascii) is assigned a base leading-code
  (range 0x80..0x9E).  In addition, a charset of greater than 0xA0
Karl Heuer's avatar
Karl Heuer committed
53 54
  (whose base leading-code is 0x9A..0x9D) is assigned an extended
  leading-code (range 0xA0..0xFE).  In this case, each base
Dave Love's avatar
Dave Love committed
55 56
  leading-code specifies the allowable range of extended leading-code
  as shown in the table below.  A leading-code is used to represent a
Karl Heuer's avatar
Karl Heuer committed
57 58
  character in Emacs' buffer and string.

Dave Love's avatar
Dave Love committed
59
  We call a charset which has extended leading-code a "private
60
  charset" because those are mainly for a charset which is not yet
Karl Heuer's avatar
Karl Heuer committed
61
  registered by ISO.  On the contrary, we call a charset which does
Dave Love's avatar
Dave Love committed
62
  not have extended leading-code an "official charset".
Karl Heuer's avatar
Karl Heuer committed
63 64 65 66 67 68 69

  ---------------------------------------------------------------------------
  charset	dimension	 base leading-code	extended leading-code
  ---------------------------------------------------------------------------
  0x00		official dim1    -- none --		-- none --
		(ASCII)
  0x01..0x7F	--never used--
70 71
  0x80		official dim1	 -- none --		-- none --
		(eight-bit-graphic)
Karl Heuer's avatar
Karl Heuer committed
72 73
  0x81..0x8F	official dim1    same as charset	-- none --
  0x90..0x99	official dim2	 same as charset	-- none --
74 75 76
  0x9A..0x9D	--never used--
  0x9E		official dim1	 same as charset	-- none --
		(eight-bit-control)
77
  0x9F		--never used--
Karl Heuer's avatar
Karl Heuer committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  0xA0..0xDF	private dim1	    0x9A		same as charset
		of 1-column width
  0xE0..0xEF	private dim1	    0x9B		same as charset
		of 2-column width
  0xF0..0xF4	private dim2	    0x9C		same as charset
		of 1-column width
  0xF5..0xFE	private dim2	    0x9D		same as charset
		of 2-column width
  0xFF		--never used--
  ---------------------------------------------------------------------------

*/

/* Definition of special leading-codes.  */
/* Leading-code followed by extended leading-code.  */
#define LEADING_CODE_PRIVATE_11	0x9A /* for private DIMENSION1 of 1-column */
#define LEADING_CODE_PRIVATE_12	0x9B /* for private DIMENSION1 of 2-column */
#define LEADING_CODE_PRIVATE_21	0x9C /* for private DIMENSION2 of 1-column */
96
#define LEADING_CODE_PRIVATE_22	0x9D /* for private DIMENSION2 of 2-column */
Karl Heuer's avatar
Karl Heuer committed
97

98 99
#define LEADING_CODE_8_BIT_CONTROL 0x9E /* for `eight-bit-control' */

Karl Heuer's avatar
Karl Heuer committed
100 101 102 103 104 105 106 107 108 109
/* Extended leading-code.  */
/* Start of each extended leading-codes.  */
#define LEADING_CODE_EXT_11 0xA0 /* follows LEADING_CODE_PRIVATE_11 */
#define LEADING_CODE_EXT_12 0xE0 /* follows LEADING_CODE_PRIVATE_12 */
#define LEADING_CODE_EXT_21 0xF0 /* follows LEADING_CODE_PRIVATE_21 */
#define LEADING_CODE_EXT_22 0xF5 /* follows LEADING_CODE_PRIVATE_22 */
/* Maximum value of extended leading-codes.  */
#define LEADING_CODE_EXT_MAX 0xFE

/* Definition of minimum/maximum charset of each DIMENSION.  */
110
#define MIN_CHARSET_OFFICIAL_DIMENSION1	0x80
Karl Heuer's avatar
Karl Heuer committed
111 112 113 114 115 116
#define MAX_CHARSET_OFFICIAL_DIMENSION1	0x8F
#define MIN_CHARSET_OFFICIAL_DIMENSION2	0x90
#define MAX_CHARSET_OFFICIAL_DIMENSION2 0x99
#define MIN_CHARSET_PRIVATE_DIMENSION1	LEADING_CODE_EXT_11
#define MIN_CHARSET_PRIVATE_DIMENSION2	LEADING_CODE_EXT_21

117 118 119
/* Maximum value of overall charset identification number.  */
#define MAX_CHARSET 0xFE

Karl Heuer's avatar
Karl Heuer committed
120
/* Definition of special charsets.  */
121 122
#define CHARSET_ASCII		0	/* 0x00..0x7F */
#define CHARSET_8_BIT_CONTROL	0x9E	/* 0x80..0x9F */
123
#define CHARSET_8_BIT_GRAPHIC	0x80	/* 0xA0..0xFF */
Karl Heuer's avatar
Karl Heuer committed
124 125 126 127 128 129 130 131 132

extern int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */
extern int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */
extern int charset_jisx0208;	/* JISX0208.1983 (Japanese Kanji) */
extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */
extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */
extern int charset_big5_1;	/* Big5 Level 1 (Chinese Traditional) */
extern int charset_big5_2;	/* Big5 Level 2 (Chinese Traditional) */

133 134 135
/* Check if CH is an ASCII character or a base leading-code.
   Nowadays, any byte can be the first byte of a character in a
   multibyte buffer/string.  So this macro name is not appropriate.  */
136
#define CHAR_HEAD_P(ch) ((unsigned char) (ch) < 0xA0)
Karl Heuer's avatar
Karl Heuer committed
137 138 139

/*** GENERAL NOTE on CHARACTER REPRESENTATION ***

Dave Love's avatar
Dave Love committed
140 141
  Firstly, the term "character" or "char" is used for a multilingual
  character (of course, including ASCII characters), not for a byte in
Karl Heuer's avatar
Karl Heuer committed
142 143 144 145 146 147 148 149 150 151 152
  computer memory.  We use the term "code" or "byte" for the latter
  case.

  A character is identified by charset and one or two POSITION-CODEs.
  POSITION-CODE is the position of the character in the charset.  A
  character of DIMENSION1 charset has one POSITION-CODE: POSITION-CODE-1.
  A character of DIMENSION2 charset has two POSITION-CODE:
  POSITION-CODE-1 and POSITION-CODE-2.  The code range of
  POSITION-CODE is 0x20..0x7F.

  Emacs has two kinds of representation of a character: multi-byte
Dave Love's avatar
Dave Love committed
153 154 155 156
  form (for buffers and strings) and single-word form (for character
  objects in Emacs Lisp).  The latter is called "character code"
  hereafter.  Both representations encode the information of charset
  and POSITION-CODE but in a different way (for instance, the MSB of
Karl Heuer's avatar
Karl Heuer committed
157 158
  POSITION-CODE is set in multi-byte form).

Dave Love's avatar
Dave Love committed
159 160
  For details of the multi-byte form, see the section "2. Emacs
  internal format handlers" of `coding.c'.
Karl Heuer's avatar
Karl Heuer committed
161 162 163 164 165 166 167 168 169 170 171

  Emacs uses 19 bits for a character code.  The bits are divided into
  3 fields: FIELD1(5bits):FIELD2(7bits):FIELD3(7bits).

  A character code of DIMENSION1 character uses FIELD2 to hold charset
  and FIELD3 to hold POSITION-CODE-1.  A character code of DIMENSION2
  character uses FIELD1 to hold charset, FIELD2 and FIELD3 to hold
  POSITION-CODE-1 and POSITION-CODE-2 respectively.

  More precisely...

172 173 174 175 176
  FIELD2 of DIMENSION1 character (except for ascii, eight-bit-control,
  and eight-bit-graphic) is "charset - 0x70".  This is to make all
  character codes except for ASCII and 8-bit codes greater than 256.
  So, the range of FIELD2 of DIMENSION1 character is 0, 1, or
  0x11..0x7F.
Karl Heuer's avatar
Karl Heuer committed
177 178 179 180 181

  FIELD1 of DIMENSION2 character is "charset - 0x8F" for official
  charset and "charset - 0xE0" for private charset.  So, the range of
  FIELD1 of DIMENSION2 character is 0x01..0x1E.

182 183 184 185 186 187 188 189 190 191
  -----------------------------------------------------------------------------
  charset		FIELD1 (5-bit)	    FIELD2 (7-bit)	FIELD3 (7-bit)
  -----------------------------------------------------------------------------
  ascii			0		    0			0x00..0x7F
  eight-bit-control	0		    1			0x00..0x1F
  eight-bit-graphic	0		    1			0x20..0x7F
  DIMENSION1		0		    charset - 0x70	POSITION-CODE-1
  DIMENSION2(o)		charset - 0x8F	    POSITION-CODE-1	POSITION-CODE-2
  DIMENSION2(p)		charset - 0xE0	    POSITION-CODE-1	POSITION-CODE-2
  -----------------------------------------------------------------------------
Karl Heuer's avatar
Karl Heuer committed
192
  "(o)": official, "(p)": private
193
  -----------------------------------------------------------------------------
Karl Heuer's avatar
Karl Heuer committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207
*/

/* Masks of each field of character code.  */
#define CHAR_FIELD1_MASK (0x1F << 14)
#define CHAR_FIELD2_MASK (0x7F << 7)
#define CHAR_FIELD3_MASK 0x7F

/* Macros to access each field of character C.  */
#define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14)
#define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7)
#define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK)

/* Minimum character code of character of each DIMENSION.  */
#define MIN_CHAR_OFFICIAL_DIMENSION1 \
208
  ((0x81 - 0x70) << 7)
Karl Heuer's avatar
Karl Heuer committed
209 210 211 212 213 214
#define MIN_CHAR_PRIVATE_DIMENSION1 \
  ((MIN_CHARSET_PRIVATE_DIMENSION1 - 0x70) << 7)
#define MIN_CHAR_OFFICIAL_DIMENSION2 \
  ((MIN_CHARSET_OFFICIAL_DIMENSION2 - 0x8F) << 14)
#define MIN_CHAR_PRIVATE_DIMENSION2 \
  ((MIN_CHARSET_PRIVATE_DIMENSION2 - 0xE0) << 14)
215 216
/* Maximum character code currently used plus 1.  */
#define MAX_CHAR (0x1F << 14)
Karl Heuer's avatar
Karl Heuer committed
217

218 219
/* 1 if C is a single byte character, else 0.  */
#define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100)
Karl Heuer's avatar
Karl Heuer committed
220

221
/* 1 if BYTE is an ASCII character in itself, in multibyte mode.  */
Karl Heuer's avatar
Karl Heuer committed
222 223
#define ASCII_BYTE_P(byte) ((byte) < 0x80)

Dave Love's avatar
Dave Love committed
224
/* A char-table containing information on each character set.
Karl Heuer's avatar
Karl Heuer committed
225

Dave Love's avatar
Dave Love committed
226
   Unlike ordinary char-tables, this doesn't contain any nested tables.
Karl Heuer's avatar
Karl Heuer committed
227 228 229 230 231 232 233 234 235 236
   Only the top level elements are used.  Each element is a vector of
   the following information:
	CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION,
	LEADING-CODE-BASE, LEADING-CODE-EXT,
	ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE,
	REVERSE-CHARSET, SHORT-NAME, LONG-NAME,	DESCRIPTION,
	PLIST.

   CHARSET-ID (integer) is the identification number of the charset.

Dave Love's avatar
Dave Love committed
237 238
   BYTES (integer) is the length of the multi-byte form of a character
   in the charset: one of 1, 2, 3, and 4.
Karl Heuer's avatar
Karl Heuer committed
239 240 241 242 243 244

   DIMENSION (integer) is the number of bytes to represent a character: 1 or 2.

   CHARS (integer) is the number of characters in a dimension: 94 or 96.

   WIDTH (integer) is the number of columns a character in the charset
245
   occupies on the screen: one of 0, 1, and 2..
Karl Heuer's avatar
Karl Heuer committed
246 247

   DIRECTION (integer) is the rendering direction of characters in the
248 249
   charset when rendering.  If 0, render from left to right, else
   render from right to left.
Karl Heuer's avatar
Karl Heuer committed
250 251 252 253 254

   LEADING-CODE-BASE (integer) is the base leading-code for the
   charset.

   LEADING-CODE-EXT (integer) is the extended leading-code for the
Dave Love's avatar
Dave Love committed
255
   charset.  All charsets of less than 0xA0 have the value 0.
Karl Heuer's avatar
Karl Heuer committed
256 257

   ISO-FINAL-CHAR (character) is the final character of the
258 259
   corresponding ISO 2022 charset.  It is -1 for such a character
   that is used only internally (e.g. `eight-bit-control').
Karl Heuer's avatar
Karl Heuer committed
260 261 262

   ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked
   while encoding to variants of ISO 2022 coding system, one of the
263 264 265
   following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR).  It
   is -1 for such a character that is used only internally
   (e.g. `eight-bit-control').
Karl Heuer's avatar
Karl Heuer committed
266 267 268 269

   REVERSE-CHARSET (integer) is the charset which differs only in
   LEFT-TO-RIGHT value from the charset.  If there's no such a
   charset, the value is -1.
Dave Love's avatar
Dave Love committed
270

Karl Heuer's avatar
Karl Heuer committed
271 272 273 274 275 276 277
   SHORT-NAME (string) is the short name to refer to the charset.

   LONG-NAME (string) is the long name to refer to the charset.

   DESCRIPTION (string) is the description string of the charset.

   PLIST (property list) may contain any type of information a user
Dave Love's avatar
Dave Love committed
278
   wants to put and get by functions `put-charset-property' and
Karl Heuer's avatar
Karl Heuer committed
279 280 281 282 283 284
   `get-charset-property' respectively.  */
extern Lisp_Object Vcharset_table;

/* Macros to access various information of CHARSET in Vcharset_table.
   We provide these macros for efficiency.  No range check of CHARSET.  */

285
/* Return entry of CHARSET (C integer) in Vcharset_table.  */
286 287 288
#define CHARSET_TABLE_ENTRY(charset)					\
  XCHAR_TABLE (Vcharset_table)->contents[((charset) == CHARSET_ASCII	\
					  ? 0 : (charset) + 128)]
Karl Heuer's avatar
Karl Heuer committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

/* Return information INFO-IDX of CHARSET.  */
#define CHARSET_TABLE_INFO(charset, info_idx) \
  XVECTOR (CHARSET_TABLE_ENTRY (charset))->contents[info_idx]

#define CHARSET_ID_IDX (0)
#define CHARSET_BYTES_IDX (1)
#define CHARSET_DIMENSION_IDX (2)
#define CHARSET_CHARS_IDX (3)
#define CHARSET_WIDTH_IDX (4)
#define CHARSET_DIRECTION_IDX (5)
#define CHARSET_LEADING_CODE_BASE_IDX (6)
#define CHARSET_LEADING_CODE_EXT_IDX (7)
#define CHARSET_ISO_FINAL_CHAR_IDX (8)
#define CHARSET_ISO_GRAPHIC_PLANE_IDX (9)
#define CHARSET_REVERSE_CHARSET_IDX (10)
#define CHARSET_SHORT_NAME_IDX (11)
#define CHARSET_LONG_NAME_IDX (12)
#define CHARSET_DESCRIPTION_IDX (13)
#define CHARSET_PLIST_IDX (14)
/* Size of a vector of each entry of Vcharset_table.  */
#define CHARSET_MAX_IDX (15)

/* And several more macros to be used frequently.  */
#define CHARSET_BYTES(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX))
#define CHARSET_DIMENSION(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX))
#define CHARSET_CHARS(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX))
#define CHARSET_WIDTH(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX))
#define CHARSET_DIRECTION(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX))
#define CHARSET_LEADING_CODE_BASE(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX))
#define CHARSET_LEADING_CODE_EXT(charset) \
  XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX))
#define CHARSET_ISO_FINAL_CHAR(charset) \
328
  XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX))
Karl Heuer's avatar
Karl Heuer committed
329
#define CHARSET_ISO_GRAPHIC_PLANE(charset) \
330
  XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX))
Karl Heuer's avatar
Karl Heuer committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
#define CHARSET_REVERSE_CHARSET(charset) \
  XINT (CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX))

/* Macros to specify direction of a charset.  */
#define CHARSET_DIRECTION_LEFT_TO_RIGHT 0
#define CHARSET_DIRECTION_RIGHT_TO_LEFT 1

/* A vector of charset symbol indexed by charset-id.  This is used
   only for returning charset symbol from C functions.  */
extern Lisp_Object Vcharset_symbol_table;

/* Return symbol of CHARSET.  */
#define CHARSET_SYMBOL(charset) \
  XVECTOR (Vcharset_symbol_table)->contents[charset]

346
/* 1 if CHARSET is in valid value range, else 0.  */
Karl Heuer's avatar
Karl Heuer committed
347 348
#define CHARSET_VALID_P(charset)					 \
  ((charset) == 0							 \
349
   || ((charset) > 0x80 && (charset) <= MAX_CHARSET_OFFICIAL_DIMENSION2) \
350 351 352 353
   || ((charset) >= MIN_CHARSET_PRIVATE_DIMENSION1			 \
       && (charset) <= MAX_CHARSET)					 \
   || ((charset) == CHARSET_8_BIT_CONTROL)				 \
   || ((charset) == CHARSET_8_BIT_GRAPHIC))
Karl Heuer's avatar
Karl Heuer committed
354

355
/* 1 if CHARSET is already defined, else 0.  */
Karl Heuer's avatar
Karl Heuer committed
356
#define CHARSET_DEFINED_P(charset)			\
357
  (((charset) >= 0) && ((charset) <= MAX_CHARSET)	\
Karl Heuer's avatar
Karl Heuer committed
358 359 360
   && !NILP (CHARSET_TABLE_ENTRY (charset)))

/* Since the information CHARSET-BYTES and CHARSET-WIDTH of
361
   Vcharset_table can be retrieved only by the first byte of
Karl Heuer's avatar
Karl Heuer committed
362 363 364 365 366 367
   multi-byte form (an ASCII code or a base leading-code), we provide
   here tables to be used by macros BYTES_BY_CHAR_HEAD and
   WIDTH_BY_CHAR_HEAD for faster information retrieval.  */
extern int bytes_by_char_head[256];
extern int width_by_char_head[256];

368 369 370 371
#define BYTES_BY_CHAR_HEAD(char_head)	\
  (ASCII_BYTE_P (char_head) ? 1 : bytes_by_char_head[char_head])
#define WIDTH_BY_CHAR_HEAD(char_head)	\
  (ASCII_BYTE_P (char_head) ? 1 : width_by_char_head[char_head])
Karl Heuer's avatar
Karl Heuer committed
372 373

/* Charset of the character C.  */
374 375 376 377 378 379 380 381 382
#define CHAR_CHARSET(c)							\
  (SINGLE_BYTE_CHAR_P (c)						\
   ? (ASCII_BYTE_P (c)							\
      ? CHARSET_ASCII							\
      : (c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC)	\
   : ((c) < MIN_CHAR_OFFICIAL_DIMENSION2				\
      ? CHAR_FIELD2 (c) + 0x70						\
      : ((c) < MIN_CHAR_PRIVATE_DIMENSION2				\
	 ? CHAR_FIELD1 (c) + 0x8F					\
383
	 : CHAR_FIELD1 (c) + 0xE0)))
Karl Heuer's avatar
Karl Heuer committed
384

385
/* Check if two characters C1 and C2 belong to the same charset.  */
386 387 388 389
#define SAME_CHARSET_P(c1, c2)				\
  (c1 < MIN_CHAR_OFFICIAL_DIMENSION2			\
   ? (c1 & CHAR_FIELD2_MASK) == (c2 & CHAR_FIELD2_MASK)	\
   : (c1 & CHAR_FIELD1_MASK) == (c2 & CHAR_FIELD1_MASK))
Karl Heuer's avatar
Karl Heuer committed
390 391 392

/* Return a character of which charset is CHARSET and position-codes
   are C1 and C2.  DIMENSION1 character ignores C2.  */
393 394 395 396 397 398
#define MAKE_CHAR(charset, c1, c2)					    \
  ((charset) == CHARSET_ASCII						    \
   ? (c1) & 0x7F							    \
   : (((charset) == CHARSET_8_BIT_CONTROL				    \
       || (charset) == CHARSET_8_BIT_GRAPHIC)				    \
      ? ((c1) & 0x7F) | 0x80						    \
399 400 401
      : ((CHARSET_DEFINED_P (charset)					    \
	  ? CHARSET_DIMENSION (charset) == 1				    \
	  : (charset) < MIN_CHARSET_PRIVATE_DIMENSION2)			    \
402
	 ? (((charset) - 0x70) << 7) | ((c1) <= 0 ? 0 : ((c1) & 0x7F))	    \
403 404 405 406 407 408
	 : ((((charset)							    \
	      - ((charset) < MIN_CHARSET_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)) \
	     << 14)							    \
	    | ((c2) <= 0 ? 0 : ((c2) & 0x7F))				    \
	    | ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7))))))

Karl Heuer's avatar
Karl Heuer committed
409

410 411 412 413 414 415
/* If GENERICP is nonzero, return nonzero iff C is a valid normal or
   generic character.  If GENERICP is zero, return nonzero iff C is a
   valid normal character.  */
#define CHAR_VALID_P(c, genericp)	\
  ((c) >= 0				\
   && (SINGLE_BYTE_CHAR_P (c) || char_valid_p (c, genericp)))
Kenichi Handa's avatar
Kenichi Handa committed
416

417
/* This default value is used when nonascii-translation-table or
418 419 420 421 422
   nonascii-insert-offset fail to convert unibyte character to a valid
   multibyte character.  This makes a Latin-1 character.  */

#define DEFAULT_NONASCII_INSERT_OFFSET 0x800

423 424 425 426
/* Parse multibyte string STR of length LENGTH and set BYTES to the
   byte length of a character at STR.  */

#ifdef BYTE_COMBINING_DEBUG
427 428 429 430

#define PARSE_MULTIBYTE_SEQ(str, length, bytes)			\
  do {								\
    int i = 1;							\
431
    while (i < (length) && ! CHAR_HEAD_P ((str)[i])) i++;	\
432 433 434
    (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]);			\
    if ((bytes) > i)						\
      abort ();							\
435
  } while (0)
436

437
#else  /* not BYTE_COMBINING_DEBUG */
Richard M. Stallman's avatar
Richard M. Stallman committed
438

439
#define PARSE_MULTIBYTE_SEQ(str, length, bytes)	\
440
  ((void)(length), (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]))
Richard M. Stallman's avatar
Richard M. Stallman committed
441

442 443
#endif /* not BYTE_COMBINING_DEBUG */

444 445 446
#define VALID_LEADING_CODE_P(code)	\
  (! NILP (CHARSET_TABLE_ENTRY (code)))

447 448 449 450
/* Return 1 iff the byte sequence at unibyte string STR (LENGTH bytes)
   is valid as a multibyte form.  If valid, by a side effect, BYTES is
   set to the byte length of the multibyte form.  */

451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
#define UNIBYTE_STR_AS_MULTIBYTE_P(str, length, bytes)		\
  (((str)[0] < 0x80 || (str)[0] >= 0xA0)			\
   ? ((bytes) = 1)						\
   : (((bytes) = BYTES_BY_CHAR_HEAD ((str)[0])),		\
      ((bytes) <= (length)					\
       && !CHAR_HEAD_P ((str)[1])				\
       && ((bytes) == 2						\
	   ? (str)[0] != LEADING_CODE_8_BIT_CONTROL		\
	   : (!CHAR_HEAD_P ((str)[2])				\
	      && ((bytes) == 3					\
		  ? (((str)[0] != LEADING_CODE_PRIVATE_11	\
		      && (str)[0] != LEADING_CODE_PRIVATE_12)	\
		     || VALID_LEADING_CODE_P (str[1]))		\
		  : (!CHAR_HEAD_P ((str)[3])			\
		     && VALID_LEADING_CODE_P (str[1]))))))))

467 468 469 470 471 472 473 474

/* Return 1 iff the byte sequence at multibyte string STR is valid as
   a unibyte form.  By a side effect, BYTES is set to the byte length
   of one character at STR.  */

#define MULTIBYTE_STR_AS_UNIBYTE_P(str, bytes)	\
  ((bytes) = BYTES_BY_CHAR_HEAD ((str)[0]),	\
   (str)[0] != LEADING_CODE_8_BIT_CONTROL)
Karl Heuer's avatar
Karl Heuer committed
475

Richard M. Stallman's avatar
Richard M. Stallman committed
476 477
/* The charset of character C is stored in CHARSET, and the
   position-codes of C are stored in C1 and C2.
Kenichi Handa's avatar
Kenichi Handa committed
478
   We store -1 in C2 if the dimension of the charset is 1.  */
Richard M. Stallman's avatar
Richard M. Stallman committed
479

480 481 482 483 484 485 486 487 488 489 490 491 492 493
#define SPLIT_CHAR(c, charset, c1, c2)					    \
  (SINGLE_BYTE_CHAR_P (c)						    \
   ? ((charset								    \
       = (ASCII_BYTE_P (c)						    \
	  ? CHARSET_ASCII						    \
	  : ((c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC))), \
      c1 = (c), c2 = -1)						    \
   : ((c) & CHAR_FIELD1_MASK						    \
      ? (charset = (CHAR_FIELD1 (c)					    \
		    + ((c) < MIN_CHAR_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)),   \
	 c1 = CHAR_FIELD2 (c),						    \
	 c2 = CHAR_FIELD3 (c))						    \
      : (charset = CHAR_FIELD2 (c) + 0x70,				    \
	 c1 = CHAR_FIELD3 (c),						    \
494
	 c2 = -1)))
Karl Heuer's avatar
Karl Heuer committed
495

496
/* Return 1 iff character C has valid printable glyph.  */
497
#define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c))
498

Richard M. Stallman's avatar
Richard M. Stallman committed
499 500
/* The charset of the character at STR is stored in CHARSET, and the
   position-codes are stored in C1 and C2.
501
   We store -1 in C2 if the character is just 2 bytes.  */
Richard M. Stallman's avatar
Richard M. Stallman committed
502

503 504 505 506 507
#define SPLIT_STRING(str, len, charset, c1, c2)			\
  ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) < 2		\
    || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > len	\
    || split_string (str, len, &charset, &c1, &c2) < 0)		\
   ? c1 = *(str), charset = CHARSET_ASCII			\
Karl Heuer's avatar
Karl Heuer committed
508 509 510 511 512 513 514 515 516 517 518 519
   : charset)

/* Mapping table from ISO2022's charset (specified by DIMENSION,
   CHARS, and FINAL_CHAR) to Emacs' charset.  Should be accessed by
   macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR).  */
extern int iso_charset_table[2][2][128];

#define ISO_CHARSET_TABLE(dimension, chars, final_char) \
  iso_charset_table[XINT (dimension) - 1][XINT (chars) > 94][XINT (final_char)]

#define BASE_LEADING_CODE_P(c) (BYTES_BY_CHAR_HEAD ((unsigned char) (c)) > 1)

Kenichi Handa's avatar
Kenichi Handa committed
520
/* Return how many bytes C will occupy in a multibyte buffer.  */
521 522 523 524
#define CHAR_BYTES(c)					\
  (SINGLE_BYTE_CHAR_P (c)				\
   ? ((ASCII_BYTE_P (c) || (c) >= 0xA0) ? 1 : 2)	\
   : char_bytes (c))
Kenichi Handa's avatar
Kenichi Handa committed
525

Karl Heuer's avatar
Karl Heuer committed
526
/* The following two macros CHAR_STRING and STRING_CHAR are the main
Dave Love's avatar
Dave Love committed
527
   entry points to convert between Emacs's two types of character
Karl Heuer's avatar
Karl Heuer committed
528 529 530
   representations: multi-byte form and single-word form (character
   code).  */

531
/* Store multi-byte form of the character C in STR.  The caller should
532 533 534
   allocate at least MAX_MULTIBYTE_LENGTH bytes area at STR in
   advance.  Returns the length of the multi-byte form.  If C is an
   invalid character code, signal an error.  */
Karl Heuer's avatar
Karl Heuer committed
535

536 537 538 539 540
#define CHAR_STRING(c, str)						  \
  (SINGLE_BYTE_CHAR_P (c)						  \
   ? ((ASCII_BYTE_P (c) || c >= 0xA0)					  \
      ? (*(str) = (unsigned char)(c), 1)				  \
      : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \
541
   : char_to_string (c, (unsigned char *) str))
Karl Heuer's avatar
Karl Heuer committed
542

543 544 545 546 547 548 549 550 551 552
/* Like CHAR_STRING but don't signal an error if C is invalid.
   Value is -1 in this case.  */

#define CHAR_STRING_NO_SIGNAL(c, str)					  \
  (SINGLE_BYTE_CHAR_P (c)						  \
   ? ((ASCII_BYTE_P (c) || c >= 0xA0)					  \
      ? (*(str) = (unsigned char)(c), 1)				  \
      : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \
   : char_to_string_1 (c, (unsigned char *) str))

Karl Heuer's avatar
Karl Heuer committed
553 554 555 556
/* Return a character code of the character of which multi-byte form
   is at STR and the length is LEN.  If STR doesn't contain valid
   multi-byte form, only the first byte in STR is returned.  */

557 558 559
#define STRING_CHAR(str, len)				\
  (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1	\
   ? (unsigned char) *(str)				\
560
   : string_to_char (str, len, 0))
Karl Heuer's avatar
Karl Heuer committed
561

562 563
/* This is like STRING_CHAR but the third arg ACTUAL_LEN is set to the
   length of the multi-byte form.  Just to know the length, use
Karl Heuer's avatar
Karl Heuer committed
564 565
   MULTIBYTE_FORM_LENGTH.  */

566 567 568
#define STRING_CHAR_AND_LENGTH(str, len, actual_len)	\
  (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1	\
   ? ((actual_len) = 1), (unsigned char) *(str)		\
569
   : string_to_char (str, len, &(actual_len)))
570

571 572
/* Fetch the "next" character from Lisp string STRING at byte position
   BYTEIDX, character position CHARIDX.  Store it into OUTPUT.
573 574 575 576 577

   All the args must be side-effect-free.
   BYTEIDX and CHARIDX must be lvalues;
   we increment them past the character fetched.  */

578 579 580 581 582 583
#define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX)	   \
if (1)									   \
  {									   \
    CHARIDX++;								   \
    if (STRING_MULTIBYTE (STRING))					   \
      {									   \
584
	const unsigned char *ptr = SDATA (STRING) + BYTEIDX;		   \
585
	int space_left = SBYTES (STRING) - BYTEIDX;			   \
586 587 588 589 590 591
	int actual_len;							   \
									   \
	OUTPUT = STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len);	   \
	BYTEIDX += actual_len;						   \
      }									   \
    else								   \
592
      OUTPUT = SREF (STRING, BYTEIDX++);				   \
593 594 595 596 597 598
  }									   \
else

/* Like FETCH_STRING_CHAR_ADVANCE but assume STRING is multibyte.  */

#define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX)  \
599 600
if (1)									      \
  {									      \
601
    const unsigned char *fetch_string_char_ptr = SDATA (STRING) + BYTEIDX;    \
602
    int fetch_string_char_space_left = SBYTES (STRING) - BYTEIDX;	      \
603 604 605 606 607 608 609 610 611 612 613
    int actual_len;							      \
    									      \
    OUTPUT								      \
      = STRING_CHAR_AND_LENGTH (fetch_string_char_ptr,			      \
			        fetch_string_char_space_left, actual_len);    \
									      \
    BYTEIDX += actual_len;						      \
    CHARIDX++;								      \
  }									      \
else

614 615
/* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current
   buffer.  */
616 617 618 619 620

#define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX)			  \
if (1)									  \
  {									  \
    CHARIDX++;								  \
621 622 623 624 625 626 627 628 629 630 631 632 633 634
    if (!NILP (current_buffer->enable_multibyte_characters))		  \
      {									  \
	unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX);			  \
	int space_left = ((CHARIDX < GPT ? GPT_BYTE : Z_BYTE) - BYTEIDX); \
	int actual_len;							  \
									  \
	OUTPUT= STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len);	  \
	BYTEIDX += actual_len;						  \
      }									  \
    else								  \
      {									  \
	OUTPUT = *(BYTE_POS_ADDR (BYTEIDX));				  \
	BYTEIDX++;							  \
      }									  \
635 636 637
  }									  \
else

Karl Heuer's avatar
Karl Heuer committed
638 639
/* Return the length of the multi-byte form at string STR of length LEN.  */

640 641 642
#define MULTIBYTE_FORM_LENGTH(str, len)			\
  (BYTES_BY_CHAR_HEAD (*(unsigned char *)(str)) == 1	\
   ? 1							\
Karl Heuer's avatar
Karl Heuer committed
643 644
   : multibyte_form_length (str, len))

645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
/* If P is before LIMIT, advance P to the next character boundary.  It
   assumes that P is already at a character boundary of the sane
   mulitbyte form whose end address is LIMIT.  */

#define NEXT_CHAR_BOUNDARY(p, limit)	\
  do {					\
    if ((p) < (limit))			\
      (p) += BYTES_BY_CHAR_HEAD (*(p));	\
  } while (0)


/* If P is after LIMIT, advance P to the previous character boundary.
   It assumes that P is already at a character boundary of the sane
   mulitbyte form whose beginning address is LIMIT.  */

#define PREV_CHAR_BOUNDARY(p, limit)					\
  do {									\
    if ((p) > (limit))							\
      {									\
	const unsigned char *p0 = (p);					\
	do {								\
	  p0--;								\
	} while (p0 >= limit && ! CHAR_HEAD_P (*p0));			\
	(p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1;	\
      }									\
  } while (0)


Karl Heuer's avatar
Karl Heuer committed
673 674
#ifdef emacs

675 676 677 678
/* Increase the buffer byte position POS_BYTE of the current buffer to
   the next character boundary.  This macro relies on the fact that
   *GPT_ADDR and *Z_ADDR are always accessible and the values are
   '\0'.  No range checking of POS.  */
679 680 681

#ifdef BYTE_COMBINING_DEBUG

682 683 684 685 686 687 688 689 690 691 692 693
#define INC_POS(pos_byte)				\
  do {							\
    unsigned char *p = BYTE_POS_ADDR (pos_byte);	\
    if (BASE_LEADING_CODE_P (*p))			\
      {							\
	int len, bytes;					\
	len = Z_BYTE - pos_byte;			\
	PARSE_MULTIBYTE_SEQ (p, len, bytes);		\
	pos_byte += bytes;				\
      }							\
    else						\
      pos_byte++;					\
Karl Heuer's avatar
Karl Heuer committed
694 695
  } while (0)

696 697 698 699 700 701 702 703 704 705
#else  /* not BYTE_COMBINING_DEBUG */

#define INC_POS(pos_byte)				\
  do {							\
    unsigned char *p = BYTE_POS_ADDR (pos_byte);	\
    pos_byte += BYTES_BY_CHAR_HEAD (*p);		\
  } while (0)

#endif /* not BYTE_COMBINING_DEBUG */

706 707 708 709 710 711 712 713
/* Decrease the buffer byte position POS_BYTE of the current buffer to
   the previous character boundary.  No range checking of POS.  */
#define DEC_POS(pos_byte)						\
  do {									\
    unsigned char *p, *p_min;						\
    									\
    pos_byte--;								\
    if (pos_byte < GPT_BYTE)						\
714
      p = BEG_ADDR + pos_byte - BEG_BYTE, p_min = BEG_ADDR;		\
715
    else								\
716
      p = BEG_ADDR + GAP_SIZE + pos_byte - BEG_BYTE, p_min = GAP_END_ADDR;\
717 718 719 720
    if (p > p_min && !CHAR_HEAD_P (*p))					\
      {									\
	unsigned char *pend = p--;					\
	int len, bytes;							\
721 722
        if (p_min < p - MAX_MULTIBYTE_LENGTH)				\
          p_min = p - MAX_MULTIBYTE_LENGTH;				\
723 724 725 726 727 728
	while (p > p_min && !CHAR_HEAD_P (*p)) p--;			\
	len = pend + 1 - p;						\
	PARSE_MULTIBYTE_SEQ (p, len, bytes);				\
	if (bytes == len)						\
	  pos_byte -= len - 1;						\
      }									\
729 730 731 732
  } while (0)

/* Increment both CHARPOS and BYTEPOS, each in the appropriate way.  */

733 734 735 736 737 738 739 740 741
#define INC_BOTH(charpos, bytepos)				\
do								\
  {								\
    (charpos)++;						\
    if (NILP (current_buffer->enable_multibyte_characters))	\
      (bytepos)++;						\
    else							\
      INC_POS ((bytepos));					\
  }								\
742 743 744 745
while (0)

/* Decrement both CHARPOS and BYTEPOS, each in the appropriate way.  */

746 747 748 749 750 751 752 753 754
#define DEC_BOTH(charpos, bytepos)				\
do								\
  {								\
    (charpos)--;						\
    if (NILP (current_buffer->enable_multibyte_characters))	\
      (bytepos)--;						\
    else							\
      DEC_POS ((bytepos));					\
  }								\
755 756
while (0)

757 758 759 760
/* Increase the buffer byte position POS_BYTE of the current buffer to
   the next character boundary.  This macro relies on the fact that
   *GPT_ADDR and *Z_ADDR are always accessible and the values are
   '\0'.  No range checking of POS_BYTE.  */
761 762 763

#ifdef BYTE_COMBINING_DEBUG

764 765 766 767
#define BUF_INC_POS(buf, pos_byte)				\
  do {								\
    unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte);	\
    if (BASE_LEADING_CODE_P (*p))				\
768
      {								\
769 770 771 772
	int len, bytes;						\
	len = BUF_Z_BYTE (buf) - pos_byte;			\
	PARSE_MULTIBYTE_SEQ (p, len, bytes);			\
	pos_byte += bytes;					\
773
      }								\
774 775 776 777
    else							\
      pos_byte++;						\
  } while (0)

778 779 780 781 782 783 784 785 786 787
#else  /* not BYTE_COMBINING_DEBUG */

#define BUF_INC_POS(buf, pos_byte)				\
  do {								\
    unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte);	\
    pos_byte += BYTES_BY_CHAR_HEAD (*p);			\
  } while (0)

#endif /* not BYTE_COMBINING_DEBUG */

788 789 790 791 792 793 794 795
/* Decrease the buffer byte position POS_BYTE of the current buffer to
   the previous character boundary.  No range checking of POS_BYTE.  */
#define BUF_DEC_POS(buf, pos_byte)					\
  do {									\
    unsigned char *p, *p_min;						\
    pos_byte--;								\
    if (pos_byte < BUF_GPT_BYTE (buf))					\
      {									\
796
	p = BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE;			\
797 798 799 800
	p_min = BUF_BEG_ADDR (buf);					\
      }									\
    else								\
      {									\
801
	p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - BEG_BYTE;\
802 803 804 805 806 807
	p_min = BUF_GAP_END_ADDR (buf);					\
      }									\
    if (p > p_min && !CHAR_HEAD_P (*p))					\
      {									\
	unsigned char *pend = p--;					\
	int len, bytes;							\
808 809
        if (p_min < p - MAX_MULTIBYTE_LENGTH)				\
          p_min = p - MAX_MULTIBYTE_LENGTH;				\
810 811 812 813 814 815
	while (p > p_min && !CHAR_HEAD_P (*p)) p--;			\
	len = pend + 1 - p;						\
	PARSE_MULTIBYTE_SEQ (p, len, bytes);				\
	if (bytes == len)						\
	  pos_byte -= len - 1;						\
      }									\
Karl Heuer's avatar
Karl Heuer committed
816 817 818 819
  } while (0)

#endif /* emacs */

820 821
/* This is the maximum byte length of multi-byte sequence.  */
#define MAX_MULTIBYTE_LENGTH 4
Karl Heuer's avatar
Karl Heuer committed
822

823 824
extern void invalid_character P_ ((int));

825
extern int translate_char P_ ((Lisp_Object, int, int, int, int));
826
extern int split_string P_ ((const unsigned char *, int, int *,
827
				       unsigned char *, unsigned char *));
828
extern int char_to_string P_ ((int, unsigned char *));
829
extern int char_to_string_1 P_ ((int, unsigned char *));
830
extern int string_to_char P_ ((const unsigned char *, int, int *));
831
extern int char_printable_p P_ ((int c));
832
extern int multibyte_form_length P_ ((const unsigned char *, int));
833 834
extern void parse_str_as_multibyte P_ ((const unsigned char *, int, int *,
					int *));
835
extern int str_as_multibyte P_ ((unsigned char *, int, int, int *));
836
extern int parse_str_to_multibyte P_ ((unsigned char *, int));
837 838
extern int str_to_multibyte P_ ((unsigned char *, int, int));
extern int str_as_unibyte P_ ((unsigned char *, int));
839
extern int get_charset_id P_ ((Lisp_Object));
840
extern int find_charset_in_text P_ ((const unsigned char *, int, int, int *,
841
				    Lisp_Object));
842
extern int strwidth P_ ((unsigned char *, int));
843
extern int c_string_width P_ ((const unsigned char *, int, int, int *, int *));
844
extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *));
Kenichi Handa's avatar
Kenichi Handa committed
845
extern int char_bytes P_ ((int));
Andreas Schwab's avatar
Andreas Schwab committed
846
extern int char_valid_p P_ ((int, int));
Kenichi Handa's avatar
Kenichi Handa committed
847

848 849
EXFUN (Funibyte_char_to_multibyte, 1);

850
extern Lisp_Object Vtranslation_table_vector;
851

852
/* Return a translation table of id number ID.  */
853
#define GET_TRANSLATION_TABLE(id) \
854
  (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)]))
Kenichi Handa's avatar
Kenichi Handa committed
855

Kenichi Handa's avatar
Kenichi Handa committed
856 857 858
/* A char-table for characters which may invoke auto-filling.  */
extern Lisp_Object Vauto_fill_chars;

Kenichi Handa's avatar
Kenichi Handa committed
859 860
/* Copy LEN bytes from FROM to TO.  This macro should be used only
   when a caller knows that LEN is short and the obvious copy loop is
861 862
   faster than calling bcopy which has some overhead.  Copying a
   multibyte sequence of a multibyte character is the typical case.  */
Kenichi Handa's avatar
Kenichi Handa committed
863 864 865 866

#define BCOPY_SHORT(from, to, len)		\
  do {						\
    int i = len;				\
867 868
    const unsigned char *from_p = from;		\
    unsigned char *to_p = to;			\
869
    while (i--) *to_p++ = *from_p++;		\
Kenichi Handa's avatar
Kenichi Handa committed
870 871
  } while (0)

872
#endif /* EMACS_CHARSET_H */