-\f
-/************************************************************************/
-/* Dealing with characters */
-/************************************************************************/
-
-/* Is this character represented by more than one byte in a string? */
-
-#define CHAR_MULTIBYTE_P(c) ((c) >= 0x80)
-
-#define CHAR_ASCII_P(c) (!CHAR_MULTIBYTE_P (c))
-
-/* The bit fields of character are divided into 3 parts:
- FIELD1(5bits):FIELD2(7bits):FIELD3(7bits) */
-
-#define CHAR_FIELD1_MASK (0x7F << 14)
-#define CHAR_FIELD2_MASK (0x7F << 7)
-#define CHAR_FIELD3_MASK 0x7F
-
-#define MIN_CHAR_GREEK 0x0370
-#define MAX_CHAR_GREEK 0x03CF
-
-#define MIN_CHAR_CYRILLIC 0x0400
-#define MAX_CHAR_CYRILLIC 0x045F
-
-#define MIN_CHAR_HEBREW 0x0590
-#define MAX_CHAR_HEBREW 0x05EF
-
-#define MIN_CHAR_THAI 0x0E00
-#define MAX_CHAR_THAI 0x0E5F
-
-#define MIN_CHAR_HALFWIDTH_KATAKANA 0xFF60
-#define MAX_CHAR_HALFWIDTH_KATAKANA 0xFF9F
-
-/* Macros to access each field of a character code of C. */
-
-#define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14)
-#define CHAR_FIELD2_INTERNAL(c) (((c) & CHAR_FIELD2_MASK) >> 7)
-#define CHAR_FIELD3_INTERNAL(c) ((c) & CHAR_FIELD3_MASK)
-
-/* Field 1, if non-zero, usually holds a leading byte for a
- dimension-2 charset. Field 2, if non-zero, usually holds a leading
- byte for a dimension-1 charset. */
-
-/* Converting between field values and leading bytes. */
-
-#define FIELD1_TO_PRIVATE_LEADING_BYTE 0x80
-#define FIELD1_TO_OFFICIAL_LEADING_BYTE 0x80
-#define FIELD2_TO_PRIVATE_LEADING_BYTE 0xb0
-#define FIELD2_TO_OFFICIAL_LEADING_BYTE 0x80
-
-/* Minimum and maximum allowed values for the fields. */
-
-#define MIN_CHAR_FIELD2_OFFICIAL \
- (MIN_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
-#define MAX_CHAR_FIELD2_OFFICIAL \
- (MAX_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
-
-#define MIN_CHAR_FIELD1_OFFICIAL \
- (MIN_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
-#define MAX_CHAR_FIELD1_OFFICIAL \
- (MAX_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
-
-#define MIN_CHAR_FIELD2_PRIVATE \
- (MIN_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
-#define MAX_CHAR_FIELD2_PRIVATE \
- (MAX_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
-
-#define MIN_CHAR_FIELD1_PRIVATE \
- (MIN_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
-#define MAX_CHAR_FIELD1_PRIVATE \
- (MAX_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
-
-/* Minimum character code of each <type> character. */
-
-#define MULE_CHAR_PRIVATE_OFFSET (0xe0 << 16)
-
-#define MIN_CHAR_OFFICIAL_TYPE9N \
- (MULE_CHAR_PRIVATE_OFFSET | (MIN_CHAR_FIELD2_OFFICIAL << 7))
-#define MIN_CHAR_PRIVATE_TYPE9N \
- (MULE_CHAR_PRIVATE_OFFSET | (MIN_CHAR_FIELD2_PRIVATE << 7))
-#define MIN_CHAR_PRIVATE_TYPE9NX9N \
- (MULE_CHAR_PRIVATE_OFFSET | (MIN_CHAR_FIELD1_PRIVATE << 14))
-#define MIN_CHAR_OFFICIAL_TYPE9NX9N \
- (MULE_CHAR_PRIVATE_OFFSET | (MIN_CHAR_FIELD1_OFFICIAL << 14))
-#define MIN_CHAR_COMPOSITION \
- (MULE_CHAR_PRIVATE_OFFSET | (0x7f << 14))
-
-/* Return a character whose charset is CHARSET and position-codes
- are C1 and C2. TYPE9N character ignores C2.
-
- NOTE: This takes advantage of the fact that
- FIELD2_TO_OFFICIAL_LEADING_BYTE and
- FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
- */
-
-INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
-INLINE Emchar
-MAKE_CHAR (Lisp_Object charset, int c1, int c2)
-{
- if (EQ (charset, Vcharset_ascii))
- return c1;
- else if (EQ (charset, Vcharset_control_1))
- return c1 | 0x80;
- else if (EQ (charset, Vcharset_latin_iso8859_1))
- return c1 | 0x80;
- else if (EQ (charset, Vcharset_greek_iso8859_7))
- return c1 + MIN_CHAR_GREEK - 0x20;
- else if (EQ (charset, Vcharset_cyrillic_iso8859_5))
- return c1 + MIN_CHAR_CYRILLIC - 0x20;
- else if (EQ (charset, Vcharset_hebrew_iso8859_8))
- return c1 + MIN_CHAR_HEBREW - 0x20;
- else if (EQ (charset, Vcharset_thai_tis620))
- return c1 + MIN_CHAR_THAI - 0x20;
- else if (EQ (charset, Vcharset_katakana_jisx0201))
- if (c1 < 0x60)
- return c1 + MIN_CHAR_HALFWIDTH_KATAKANA - 0x20;
- else
- return 32;
-#ifdef ENABLE_COMPOSITE_CHARS
- else if (EQ (charset, Vcharset_composite))
- return (0x1F << 14) | ((c1) << 7) | (c2);
-#endif
- else if (XCHARSET_DIMENSION (charset) == 1)
- return MULE_CHAR_PRIVATE_OFFSET
- | ((XCHARSET_LEADING_BYTE (charset) -
- FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) | (c1);
- else
- return MULE_CHAR_PRIVATE_OFFSET
- | ((XCHARSET_LEADING_BYTE (charset) -
- FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
-}
-
-INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
-INLINE void
-breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
-{
- if (CHAR_ASCII_P (c))
- {
- *charset = Vcharset_ascii;
- *c1 = c;
- *c2 = 0;
- }
- else if (c < 0xA0)
- {
- *charset = Vcharset_control_1;
- *c1 = CHAR_FIELD3_INTERNAL (c);
- *c2 = 0;
- }
- else if (c <= 0xff)
- {
- *charset = Vcharset_latin_iso8859_1;
- *c1 = CHAR_FIELD3_INTERNAL (c);
- *c2 = 0;
- }
- else if (c < MIN_CHAR_GREEK)
- {
- abort ();
- }
- else if (c <= MAX_CHAR_GREEK)
- {
- *charset = Vcharset_greek_iso8859_7;
- *c1 = c - MIN_CHAR_GREEK + 0x20;
- *c2 = 0;
- }
- else if (c < MIN_CHAR_CYRILLIC)
- {
- abort ();
- }
- else if (c <= MAX_CHAR_CYRILLIC)
- {
- *charset = Vcharset_cyrillic_iso8859_5;
- *c1 = c - MIN_CHAR_CYRILLIC + 0x20;
- *c2 = 0;
- }
- else if (c < MIN_CHAR_HEBREW)
- {
- abort ();
- }
- else if (c <= MAX_CHAR_HEBREW)
- {
- *charset = Vcharset_hebrew_iso8859_8;
- *c1 = c - MIN_CHAR_HEBREW + 0x20;
- *c2 = 0;
- }
- else if (c < MIN_CHAR_THAI)
- {
- abort ();
- }
- else if (c <= MAX_CHAR_THAI)
- {
- *charset = Vcharset_thai_tis620;
- *c1 = c - MIN_CHAR_THAI + 0x20;
- *c2 = 0;
- }
- else if (c < MIN_CHAR_HALFWIDTH_KATAKANA)
- {
- abort ();
- }
- else if (c <= MAX_CHAR_HALFWIDTH_KATAKANA)
- {
- *charset = Vcharset_katakana_jisx0201;
- *c1 = c - MIN_CHAR_HALFWIDTH_KATAKANA + 0x20;
- *c2 = 0;
- }
- else if (c < MIN_CHAR_PRIVATE_TYPE9NX9N)
- {
- *charset
- = CHARSET_BY_LEADING_BYTE (CHAR_FIELD2_INTERNAL (c) +
- FIELD2_TO_OFFICIAL_LEADING_BYTE);
- *c1 = CHAR_FIELD3_INTERNAL(c);
- *c2 = 0;
- }
- else if (c < MIN_CHAR_COMPOSITION)
- {
- *charset
- = CHARSET_BY_LEADING_BYTE (CHAR_FIELD1 (c) +
- FIELD1_TO_OFFICIAL_LEADING_BYTE);
- *c1 = CHAR_FIELD2_INTERNAL(c);
- *c2 = CHAR_FIELD3_INTERNAL(c);
- }
- else
- {
-#ifdef ENABLE_COMPOSITE_CHARS
- return LEADING_BYTE_COMPOSITE;