-Lisp_Object ucs_to_mule_table[65536];
-Lisp_Object mule_to_ucs_table;
-
-DEFUN ("set-ucs-char", Fset_ucs_char, 2, 2, 0, /*
-Map UCS-4 code CODE to Mule character CHARACTER.
-
-Return T on success, NIL on failure.
-*/
- (code, character))
-{
- unsigned int c;
-
- CHECK_CHAR (character);
- CHECK_INT (code);
- c = XINT (code);
-
- if (c < sizeof (ucs_to_mule_table))
- {
- ucs_to_mule_table[c] = character;
- return Qt;
- }
- else
- return Qnil;
-}
-
-static Lisp_Object
-ucs_to_char (unsigned long code)
-{
- if (code < sizeof (ucs_to_mule_table))
- {
- return ucs_to_mule_table[code];
- }
- else if ((0xe00000 <= code) && (code <= 0xe00000 + 94 * 94 * 14))
- {
- unsigned int c;
-
- code -= 0xe00000;
- c = code % (94 * 94);
- return make_char
- (MAKE_CHAR (CHARSET_BY_ATTRIBUTES
- (CHARSET_TYPE_94X94, code / (94 * 94) + '@',
- CHARSET_LEFT_TO_RIGHT),
- c / 94 + 33, c % 94 + 33));
- }
- else
- return Qnil;
-}
-
-DEFUN ("ucs-char", Fucs_char, 1, 1, 0, /*
-Return Mule character corresponding to UCS code CODE (a positive integer).
-*/
- (code))
-{
- CHECK_NATNUM (code);
- return ucs_to_char (XINT (code));
-}
-
-DEFUN ("set-char-ucs", Fset_char_ucs, 2, 2, 0, /*
-Map Mule character CHARACTER to UCS code CODE (a positive integer).
-*/
- (character, code))
-{
- /* #### Isn't this gilding the lily? Fput_char_table checks its args.
- Fset_char_ucs is more restrictive on index arg, but should
- check code arg in a char_table method. */
- CHECK_CHAR (character);
- CHECK_NATNUM (code);
- return Fput_char_table (character, code, mule_to_ucs_table);
-}
-
-DEFUN ("char-ucs", Fchar_ucs, 1, 1, 0, /*
-Return the UCS code (a positive integer) corresponding to CHARACTER.
-*/
- (character))
-{
- return Fget_char_table (character, mule_to_ucs_table);
-}
-
-#ifdef UTF2000
-#define decode_ucs4 DECODE_ADD_UCS_CHAR
-#else
-/* Decode a UCS-4 character into a buffer. If the lookup fails, use
- <GETA MARK> (U+3013) of JIS X 0208, which means correct character
- is not found, instead.
- #### do something more appropriate (use blob?)
- Danger, Will Robinson! Data loss. Should we signal user? */
-static void
-decode_ucs4 (unsigned long ch, unsigned_char_dynarr *dst)
-{
- Lisp_Object chr = ucs_to_char (ch);
-
- if (! NILP (chr))
- {
- Bufbyte work[MAX_EMCHAR_LEN];
- int len;
-
- ch = XCHAR (chr);
- len = (ch < 128) ?
- simple_set_charptr_emchar (work, ch) :
- non_ascii_set_charptr_emchar (work, ch);
- Dynarr_add_many (dst, work, len);
- }
- else
- {
- Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
- Dynarr_add (dst, 34 + 128);
- Dynarr_add (dst, 46 + 128);
- }
-}
-#endif
-
-static unsigned long
-mule_char_to_ucs4 (Lisp_Object charset,
- unsigned char h, unsigned char l)
-{
- Lisp_Object code
- = Fget_char_table (make_char (MAKE_CHAR (charset, h & 127, l & 127)),
- mule_to_ucs_table);
-
- if (INTP (code))
- {
- return XINT (code);
- }
- else if ( (XCHARSET_DIMENSION (charset) == 2) &&
- (XCHARSET_CHARS (charset) == 94) )
- {
- unsigned char final = XCHARSET_FINAL (charset);
-
- if ( ('@' <= final) && (final < 0x7f) )
- {
- return 0xe00000 + (final - '@') * 94 * 94
- + ((h & 127) - 33) * 94 + (l & 127) - 33;
- }
- else
- {
- return '?';
- }
- }
- else
- {
- return '?';
- }
-}
-
-static void
-encode_ucs4 (Lisp_Object charset,
- unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
-{
- unsigned long code = mule_char_to_ucs4 (charset, h, l);
- Dynarr_add (dst, code >> 24);
- Dynarr_add (dst, (code >> 16) & 255);
- Dynarr_add (dst, (code >> 8) & 255);
- Dynarr_add (dst, code & 255);
-}
-