(encode_coding_sjis): Deleted.
[chise/xemacs-chise.git-] / src / char-ucs.h
index 2db4ca3..abe9fe7 100644 (file)
@@ -24,15 +24,53 @@ Boston, MA 02111-1307, USA.  */
 #ifndef _XEMACS_CHAR_UCS_H
 #define _XEMACS_CHAR_UCS_H
 
-/* ---------------------------- */
-/* (D) For working with Emchars */
-/* ---------------------------- */
-
 #define valid_char_p(ch) 1
 
 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
 
 \f
+typedef struct
+{
+  unsigned char *base;
+  size_t  offset;
+  size_t  size;
+} Emchar_to_byte_table;
+
+unsigned char
+get_byte_from_character_table (Emchar ch, Emchar_to_byte_table* table);
+
+
+extern Lisp_Object Vcharset_ucs_bmp;
+
+extern Lisp_Object Vcharset_latin_jisx0201;
+extern Emchar latin_jisx0201_to_ucs[94];
+extern Emchar_to_byte_table* ucs_to_latin_jisx0201;
+
+extern Lisp_Object Vcharset_latin_iso8859_2;
+extern Emchar latin_iso8859_2_to_ucs[96];
+extern Emchar_to_byte_table* ucs_to_latin_iso8859_2;
+
+extern Lisp_Object Vcharset_latin_iso8859_3;
+extern Emchar latin_iso8859_3_to_ucs[96];
+extern Emchar_to_byte_table* ucs_to_latin_iso8859_3;
+
+extern Lisp_Object Vcharset_latin_iso8859_4;
+extern Emchar latin_iso8859_4_to_ucs[96];
+extern Emchar_to_byte_table* ucs_to_latin_iso8859_4;
+
+extern Lisp_Object Vcharset_latin_iso8859_9;
+extern Emchar latin_iso8859_9_to_ucs[96];
+extern Emchar_to_byte_table* ucs_to_latin_iso8859_9;
+
+extern Lisp_Object Vcharset_latin_viscii_lower;
+extern Emchar latin_viscii_lower_to_ucs[96];
+extern Emchar_to_byte_table* ucs_to_latin_viscii_lower;
+
+extern Lisp_Object Vcharset_latin_viscii_upper;
+extern Emchar latin_viscii_upper_to_ucs[96];
+extern Emchar_to_byte_table* ucs_to_latin_viscii_upper;
+
+\f
 /************************************************************************/
 /*                    Definition of leading bytes                       */
 /************************************************************************/
@@ -45,7 +83,7 @@ typedef int Charset_ID;
 #define LEADING_BYTE_CONTROL_1         0x81 /* represent normal 80-9F */
 
 
-#define CHARSET_ID_OFFSET_94           0x60
+#define CHARSET_ID_OFFSET_94           0x55
 
 #define MIN_CHARSET_ID_PRIVATE_94      (CHARSET_ID_OFFSET_94 + '0')
 #define MAX_CHARSET_ID_PRIVATE_94      (CHARSET_ID_OFFSET_94 + '?')
@@ -62,6 +100,9 @@ typedef int Charset_ID;
 
 #define CHARSET_ID_OFFSET_96           0x70
 
+#define LEADING_BYTE_LATIN_VISCII_LOWER        (CHARSET_ID_OFFSET_96 + '1')
+#define LEADING_BYTE_LATIN_VISCII_UPPER        (CHARSET_ID_OFFSET_96 + '2')
+
 /* Right half of ISO 8859-1 */
 #define LEADING_BYTE_LATIN_ISO8859_1   (CHARSET_ID_OFFSET_96 + 'A')
 
@@ -158,20 +199,6 @@ typedef int Charset_ID;
 
 \f
 /************************************************************************/
-/*                     Operations on individual bytes                   */
-/*                             of any format                            */
-/************************************************************************/
-
-/* Argument `c' should be (unsigned int) or (unsigned char). */
-/* Note that SP and DEL are not included. */
-
-#define BYTE_ASCII_P(c) ((c) < 0x80)
-#define BYTE_C0_P(c) ((c) < 0x20)
-/* Do some forced casting just to make *sure* things are gotten right. */
-#define BYTE_C1_P(c) ((unsigned int) ((unsigned int) (c) - 0x80) < 0x20)
-
-\f
-/************************************************************************/
 /*            Information about a particular character set              */
 /************************************************************************/
 
@@ -190,11 +217,6 @@ struct Lisp_Charset
   /* Final byte of this character set in ISO2022 designating escape sequence */
   Bufbyte final;
 
-  /* Number of bytes (1 - 4) required in the internal representation
-     for characters in this character set.  This is *not* the
-     same as the dimension of the character set). */
-  unsigned int rep_bytes;
-
   /* Number of columns a character in this charset takes up, on TTY
      devices.  Not used for X devices. */
   unsigned int columns;
@@ -213,6 +235,12 @@ struct Lisp_Charset
 
   /* Which half of font to be used to display this character set */
   unsigned int graphic;
+
+  /* character->byte mapping table */
+  Emchar_to_byte_table* encoding_table;
+
+  /* byte->character mapping table */
+  Emchar* decoding_table;
 };
 
 DECLARE_LRECORD (charset, struct Lisp_Charset);
@@ -239,7 +267,6 @@ DECLARE_LRECORD (charset, struct Lisp_Charset);
 #define CHARSET_NAME(cs)        ((cs)->name)
 #define CHARSET_SHORT_NAME(cs)  ((cs)->short_name)
 #define CHARSET_LONG_NAME(cs)   ((cs)->long_name)
-#define CHARSET_REP_BYTES(cs)   ((cs)->rep_bytes)
 #define CHARSET_COLUMNS(cs)     ((cs)->columns)
 #define CHARSET_GRAPHIC(cs)     ((cs)->graphic)
 #define CHARSET_TYPE(cs)        ((cs)->type)
@@ -257,8 +284,6 @@ DECLARE_LRECORD (charset, struct Lisp_Charset);
 #define XCHARSET_NAME(cs)        CHARSET_NAME         (XCHARSET (cs))
 #define XCHARSET_SHORT_NAME(cs)          CHARSET_SHORT_NAME   (XCHARSET (cs))
 #define XCHARSET_LONG_NAME(cs)   CHARSET_LONG_NAME    (XCHARSET (cs))
-#define XCHARSET_REP_BYTES(cs)   CHARSET_REP_BYTES    (XCHARSET (cs))
-#define XCHARSET_COLUMNS(cs)     CHARSET_COLUMNS      (XCHARSET (cs))
 #define XCHARSET_GRAPHIC(cs)      CHARSET_GRAPHIC      (XCHARSET (cs))
 #define XCHARSET_TYPE(cs)        CHARSET_TYPE         (XCHARSET (cs))
 #define XCHARSET_DIRECTION(cs)   CHARSET_DIRECTION    (XCHARSET (cs))
@@ -301,24 +326,6 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb)
 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \
   (charset_by_attributes[type][final])
 
-INLINE int REP_BYTES_BY_FIRST_BYTE (int fb);
-INLINE int
-REP_BYTES_BY_FIRST_BYTE (int fb)
-{
-  if ( fb < 0xc0 )
-    return 1;
-  else if ( fb < 0xe0 )
-    return 2;
-  else if ( fb < 0xf0 )
-    return 3;
-  else if ( fb < 0xf8 )
-    return 4;
-  else if ( fb < 0xfc )
-    return 5;
-  else
-    return 6;
-}
-
 \f
 /************************************************************************/
 /*                        Dealing with characters                       */
@@ -363,14 +370,24 @@ MAKE_CHAR (Lisp_Object charset, int c1, int c2)
     return c1;
   else if (EQ (charset, Vcharset_control_1))
     return c1 | 0x80;
+  else if (EQ (charset, Vcharset_ucs_bmp))
+    return (c1 << 8) | c2;
   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_latin_iso8859_2))
+    return latin_iso8859_2_to_ucs[c1 - 32];
+  else if (EQ (charset, Vcharset_latin_iso8859_3))
+    return latin_iso8859_3_to_ucs[c1 - 32];
+  else if (EQ (charset, Vcharset_latin_iso8859_4))
+    return latin_iso8859_4_to_ucs[c1 - 32];
   else if (EQ (charset, Vcharset_cyrillic_iso8859_5))
     return c1 + MIN_CHAR_CYRILLIC - 0x20;
+  else if (EQ (charset, Vcharset_greek_iso8859_7))
+    return c1 + MIN_CHAR_GREEK - 0x20;
   else if (EQ (charset, Vcharset_hebrew_iso8859_8))
     return c1 + MIN_CHAR_HEBREW - 0x20;
+  else if (EQ (charset, Vcharset_latin_iso8859_9))
+    return latin_iso8859_9_to_ucs[c1 - 32];
   else if (EQ (charset, Vcharset_thai_tis620))
     return c1 + MIN_CHAR_THAI - 0x20;
   else if (EQ (charset, Vcharset_katakana_jisx0201))
@@ -378,6 +395,12 @@ MAKE_CHAR (Lisp_Object charset, int c1, int c2)
       return c1 + MIN_CHAR_HALFWIDTH_KATAKANA - 0x20;
     else
       return 32;
+  else if (EQ (charset, Vcharset_latin_jisx0201))
+    return latin_jisx0201_to_ucs[c1 - 33];
+  else if (EQ (charset, Vcharset_latin_viscii_lower))
+    return latin_viscii_lower_to_ucs[c1 - 32];
+  else if (EQ (charset, Vcharset_latin_viscii_upper))
+    return latin_viscii_upper_to_ucs[c1 - 32];
   else if (XCHARSET_DIMENSION (charset) == 1)
     {
       switch (XCHARSET_CHARS (charset))
@@ -440,13 +463,78 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
     {
       *charset
        = CHARSET_BY_LEADING_BYTE (latin_a_char_to_charset[c - 0x100]);
-      *c1 = latin_a_char_to_byte1[c - 0x100];
-      *c2 = latin_a_char_to_byte2[c - 0x100];
+      
+      if (EQ (*charset, Vcharset_latin_iso8859_2))
+       {
+         *c1 = get_byte_from_character_table (c, ucs_to_latin_iso8859_2);
+         *c2 = 0;
+       }
+      else if (EQ (*charset, Vcharset_latin_iso8859_3))
+       {
+         *c1 = get_byte_from_character_table (c, ucs_to_latin_iso8859_3);
+         *c2 = 0;
+       }
+      else if (EQ (*charset, Vcharset_latin_iso8859_4))
+       {
+         *c1 = get_byte_from_character_table (c, ucs_to_latin_iso8859_4);
+         *c2 = 0;
+       }
+      else if (EQ (*charset, Vcharset_latin_iso8859_9))
+       {
+         *c1 = get_byte_from_character_table (c, ucs_to_latin_iso8859_9);
+         *c2 = 0;
+       }
+      else
+       {
+         *c1 = latin_a_char_to_byte1[c - 0x100];
+         *c2 = latin_a_char_to_byte2[c - 0x100];
+       }
     }
   else if (c < MIN_CHAR_GREEK)
     {
-      printf("not break up u+%x", c);
-      abort ();
+      if ( (*c1 = get_byte_from_character_table (c, ucs_to_latin_iso8859_2)) )
+       {
+         *charset = Vcharset_latin_iso8859_2;
+         *c2 = 0;
+       }
+      else if ( (*c1 =
+                get_byte_from_character_table (c, ucs_to_latin_iso8859_3)) )
+       {
+         *charset = Vcharset_latin_iso8859_3;
+         *c2 = 0;
+       }
+      else if ( (*c1 =
+                get_byte_from_character_table (c, ucs_to_latin_iso8859_4)) )
+       {
+         *charset = Vcharset_latin_iso8859_4;
+         *c2 = 0;
+       }
+      else if ( (*c1 =
+                get_byte_from_character_table (c, ucs_to_latin_iso8859_9)) )
+       {
+         *charset = Vcharset_latin_iso8859_9;
+         *c2 = 0;
+       }
+      else if ( (*c1 =
+                get_byte_from_character_table (c,
+                                               ucs_to_latin_viscii_lower)) )
+       {
+         *charset = Vcharset_latin_viscii_lower;
+         *c2 = 0;
+       }
+      else if ( (*c1 =
+                get_byte_from_character_table (c,
+                                               ucs_to_latin_viscii_upper)) )
+       {
+         *charset = Vcharset_latin_viscii_upper;
+         *c2 = 0;
+       }
+      else
+       {
+         *charset = Vcharset_ucs_bmp;
+         *c1 = c >> 8;
+         *c2 = c & 0xff;
+       }
     }
   else if (c <= MAX_CHAR_GREEK)
     {
@@ -456,8 +544,9 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
     }
   else if (c < MIN_CHAR_CYRILLIC)
     {
-      printf("not break up u+%x", c);
-      abort ();
+      *charset = Vcharset_ucs_bmp;
+      *c1 = c >> 8;
+      *c2 = c & 0xff;
     }
   else if (c <= MAX_CHAR_CYRILLIC)
     {
@@ -467,8 +556,9 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
     }
   else if (c < MIN_CHAR_HEBREW)
     {
-      printf("not break up u+%x", c);
-      abort ();
+      *charset = Vcharset_ucs_bmp;
+      *c1 = c >> 8;
+      *c2 = c & 0xff;
     }
   else if (c <= MAX_CHAR_HEBREW)
     {
@@ -478,8 +568,9 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
     }
   else if (c < MIN_CHAR_THAI)
     {
-      printf("not break up u+%x", c);
-      abort ();
+      *charset = Vcharset_ucs_bmp;
+      *c1 = c >> 8;
+      *c2 = c & 0xff;
     }
   else if (c <= MAX_CHAR_THAI)
     {
@@ -489,8 +580,29 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
     }
   else if (c < MIN_CHAR_HALFWIDTH_KATAKANA)
     {
-      printf("not break up u+%x", c);
-      abort ();
+      if ( (*c1 = get_byte_from_character_table (c, ucs_to_latin_jisx0201)) )
+       {
+         *charset = Vcharset_latin_jisx0201;
+         *c2 = 0;
+       }
+      else if ( (*c1 = get_byte_from_character_table
+                (c, ucs_to_latin_viscii_lower)) )
+       {
+         *charset = Vcharset_latin_viscii_lower;
+         *c2 = 0;
+       }
+      else if ( (*c1 = get_byte_from_character_table
+                (c, ucs_to_latin_viscii_upper)) )
+       {
+         *charset = Vcharset_latin_viscii_upper;
+         *c2 = 0;
+       }
+      else
+       {
+         *charset = Vcharset_ucs_bmp;
+         *c1 = c >> 8;
+         *c2 = c & 0xff;
+       }
     }
   else if (c <= MAX_CHAR_HALFWIDTH_KATAKANA)
     {
@@ -557,15 +669,7 @@ CHAR_CHARSET (Emchar ch)
 
 #define CHAR_LEADING_BYTE(c) (XCHARSET_LEADING_BYTE(CHAR_CHARSET(c)))
 
-\f
-#ifdef ENABLE_COMPOSITE_CHARS
-/************************************************************************/
-/*                           Composite characters                       */
-/************************************************************************/
-
-Emchar lookup_composite_char (Bufbyte *str, int len);
-Lisp_Object composite_char_string (Emchar ch);
-#endif /* ENABLE_COMPOSITE_CHARS */
+#define CHAR_COLUMNS(c)     (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
 
 \f
 /************************************************************************/
@@ -580,13 +684,4 @@ extern Lisp_Object Vcharset_chinese_big5_2;
 extern Lisp_Object Vcharset_japanese_jisx0208;
 extern Lisp_Object Vcharset_japanese_jisx0212;
 
-Emchar Lstream_get_emchar_1 (Lstream *stream, int first_char);
-int Lstream_fput_emchar (Lstream *stream, Emchar ch);
-void Lstream_funget_emchar (Lstream *stream, Emchar ch);
-
-int copy_internal_to_external (CONST Bufbyte *internal, Bytecount len,
-                              unsigned char *external);
-Bytecount copy_external_to_internal (CONST unsigned char *external,
-                                    int len, Bufbyte *internal);
-
 #endif /* _XEMACS_CHAR_UCS_H */