(char_encode_shift_jis): Use `charset_code_point' not to use
[chise/xemacs-chise.git] / src / mule-charset.c
index 98c8a59..73ad48b 100644 (file)
@@ -775,7 +775,6 @@ mark_charset (Lisp_Object obj, void (*markobj) (Lisp_Object))
   markobj (cs->ccl_program);
 #ifdef UTF2000
   markobj (cs->decoding_table);
-  markobj (cs->encoding_table);
 #endif
   return cs->name;
 }
@@ -859,7 +858,6 @@ make_charset (Charset_ID id, Lisp_Object name,
   CHARSET_REVERSE_DIRECTION_CHARSET (cs) = Qnil;
 #ifdef UTF2000
   CHARSET_DECODING_TABLE(cs) = Qnil;
-  CHARSET_ENCODING_TABLE(cs) = Qnil;
   CHARSET_UCS_MIN(cs) = ucs_min;
   CHARSET_UCS_MAX(cs) = ucs_max;
   CHARSET_CODE_OFFSET(cs) = code_offset;
@@ -981,46 +979,47 @@ get_unallocated_leading_byte (int dimension)
 }
 
 #ifdef UTF2000
-unsigned char
-charset_get_byte1 (Lisp_Object charset, Emchar ch)
+Lisp_Object
+range_charset_code_point (Lisp_Object charset, Emchar ch)
 {
-  Lisp_Object table;
   int d;
 
-  if (!EQ (table = XCHARSET_ENCODING_TABLE (charset), Qnil))
-    {
-      Lisp_Object value = get_char_code_table (ch, table);
-
-      if (INTP (value))
-       {
-         Emchar code = XINT (value);
-
-         if (code < (1 << 8))
-           return code;
-         else if (code < (1 << 16))
-           return code >> 8;
-         else if (code < (1 << 24))
-           return code >> 16;
-         else
-           return code >> 24;
-       }
-    }
   if ((XCHARSET_UCS_MIN (charset) <= ch)
       && (ch <= XCHARSET_UCS_MAX (charset)))
-    return (ch - XCHARSET_UCS_MIN (charset)
-           + XCHARSET_CODE_OFFSET (charset))
-      / (XCHARSET_DIMENSION (charset) == 1 ?
-        1
-        :
-        XCHARSET_DIMENSION (charset) == 2 ?
-        XCHARSET_CHARS (charset)
-        :
-        XCHARSET_DIMENSION (charset) == 3 ?
-        XCHARSET_CHARS (charset) * XCHARSET_CHARS (charset)
-        :
-        XCHARSET_CHARS (charset)
-        * XCHARSET_CHARS (charset) * XCHARSET_CHARS (charset))
-      + XCHARSET_BYTE_OFFSET (charset);
+    {
+      d = ch - XCHARSET_UCS_MIN (charset) + XCHARSET_CODE_OFFSET (charset);
+                      
+      if (XCHARSET_DIMENSION (charset) == 1)
+       return list1 (make_int (d + XCHARSET_BYTE_OFFSET (charset)));
+      else if (XCHARSET_DIMENSION (charset) == 2)
+       return list2 (make_int (d / XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)),
+                     make_int (d % XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)));
+      else if (XCHARSET_DIMENSION (charset) == 3)
+       return list3 (make_int (d / (XCHARSET_CHARS (charset)
+                                       * XCHARSET_CHARS (charset))
+                               + XCHARSET_BYTE_OFFSET (charset)),
+                     make_int (d / XCHARSET_CHARS (charset)
+                               % XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)),
+                     make_int (d % XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)));
+      else /* if (XCHARSET_DIMENSION (charset) == 4) */
+       return list4 (make_int (d / (XCHARSET_CHARS (charset)
+                                       * XCHARSET_CHARS (charset)
+                                       * XCHARSET_CHARS (charset))
+                               + XCHARSET_BYTE_OFFSET (charset)),
+                     make_int (d / (XCHARSET_CHARS (charset)
+                                       * XCHARSET_CHARS (charset))
+                               % XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)),
+                     make_int (d / XCHARSET_CHARS (charset)
+                               % XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)),
+                     make_int (d % XCHARSET_CHARS (charset)
+                               + XCHARSET_BYTE_OFFSET (charset)));
+    }
   else if (XCHARSET_CODE_OFFSET (charset) == 0)
     {
       if (XCHARSET_DIMENSION (charset) == 1)
@@ -1030,17 +1029,17 @@ charset_get_byte1 (Lisp_Object charset, Emchar ch)
              if (((d = ch - (MIN_CHAR_94
                              + (XCHARSET_FINAL (charset) - '0') * 94)) >= 0)
                  && (d < 94))
-               return d + 33;
+               return list1 (make_int (d + 33));
            }
          else if (XCHARSET_CHARS (charset) == 96)
            {
              if (((d = ch - (MIN_CHAR_96
                              + (XCHARSET_FINAL (charset) - '0') * 96)) >= 0)
                  && (d < 96))
-               return d + 32;
+               return list1 (make_int (d + 32));
            }
          else
-           return 0;
+           return Qnil;
        }
       else if (XCHARSET_DIMENSION (charset) == 2)
        {
@@ -1050,7 +1049,7 @@ charset_get_byte1 (Lisp_Object charset, Emchar ch)
                              + (XCHARSET_FINAL (charset) - '0') * 94 * 94))
                   >= 0)
                  && (d < 94 * 94))
-               return (d / 94) + 33;
+               return list2 ((d / 94) + 33, d % 94 + 33);
            }
          else if (XCHARSET_CHARS (charset) == 96)
            {
@@ -1058,64 +1057,26 @@ charset_get_byte1 (Lisp_Object charset, Emchar ch)
                              + (XCHARSET_FINAL (charset) - '0') * 96 * 96))
                   >= 0)
                  && (d < 96 * 96))
-               return (d / 96) + 32;
+               return list2 ((d / 96) + 32, d % 96 + 32);
            }
        }
     }
-  return 0;
+  return Qnil;
 }
 
-unsigned char
-charset_get_byte2 (Lisp_Object charset, Emchar ch)
+Lisp_Object
+charset_code_point (Lisp_Object charset, Emchar ch)
 {
-  if (XCHARSET_DIMENSION (charset) == 1)
-    return 0;
-  else
+  Lisp_Object cdef = get_char_code_table (ch, Vcharacter_attribute_table);
+
+  if (!EQ (cdef, Qnil))
     {
-      Lisp_Object table;
+      Lisp_Object field = Fassq (charset, cdef);
 
-      if (!EQ (table = XCHARSET_ENCODING_TABLE (charset), Qnil))
-       {
-         Lisp_Object value = get_char_code_table (ch, table);
-         
-         if (INTP (value))
-           {
-             Emchar code = XINT (value);
-
-             if (code < (1 << 16))
-               return (unsigned char)code;
-             else if (code < (1 << 24))
-               return (unsigned char)(code >> 16);
-             else
-               return (unsigned char)(code >> 24);
-           }
-       }
-      if ((XCHARSET_UCS_MIN (charset) <= ch)
-         && (ch <= XCHARSET_UCS_MAX (charset)))
-       return ((ch - XCHARSET_UCS_MIN (charset)
-                + XCHARSET_CODE_OFFSET (charset))
-               / (XCHARSET_DIMENSION (charset) == 2 ?
-                  1
-                  :
-                  XCHARSET_DIMENSION (charset) == 3 ?
-                  XCHARSET_CHARS (charset)
-                  :
-                  XCHARSET_CHARS (charset) * XCHARSET_CHARS (charset)))
-         % XCHARSET_CHARS (charset)
-         + XCHARSET_BYTE_OFFSET (charset);
-      else if (XCHARSET_CHARS (charset) == 94)
-       return (MIN_CHAR_94x94
-               + (XCHARSET_FINAL (charset) - '0') * 94 * 94 <= ch)
-         && (ch < MIN_CHAR_94x94
-             + (XCHARSET_FINAL (charset) - '0' + 1) * 94 * 94) ?
-         ((ch - MIN_CHAR_94x94) % 94) + 33 : 0;
-      else /* if (XCHARSET_CHARS (charset) == 96) */
-       return (MIN_CHAR_96x96
-               + (XCHARSET_FINAL (charset) - '0') * 96 * 96 <= ch)
-         && (ch < MIN_CHAR_96x96
-             + (XCHARSET_FINAL (charset) - '0' + 1) * 96 * 96) ?
-         ((ch - MIN_CHAR_96x96) % 96) + 32 : 0;
+      if (!EQ (field, Qnil))
+       return Fcdr (field);
     }
+  return range_charset_code_point (charset, ch);
 }
 
 Lisp_Object Vdefault_coded_charset_priority_list;
@@ -1268,7 +1229,6 @@ character set.  Recognized properties are:
   Lisp_Object ccl_program = Qnil;
   Lisp_Object short_name = Qnil, long_name = Qnil;
 #ifdef UTF2000
-  Emchar code_offset = 0;
   unsigned char byte_offset = 0;
 #endif
 
@@ -1690,14 +1650,13 @@ Set mapping-table of CHARSET to TABLE.
   if (EQ (table, Qnil))
     {
       CHARSET_DECODING_TABLE(cs) = table;
-      CHARSET_ENCODING_TABLE(cs) = Qnil;
       return table;
     }
   else if (VECTORP (table))
     {
       if (XVECTOR_LENGTH (table) > CHARSET_CHARS (cs))
        args_out_of_range (table, make_int (CHARSET_CHARS (cs)));
-      old_table = CHARSET_ENCODING_TABLE(cs);
+      old_table = CHARSET_DECODING_TABLE(cs);
       CHARSET_DECODING_TABLE(cs) = table;
     }
   else
@@ -1709,24 +1668,17 @@ Set mapping-table of CHARSET to TABLE.
   switch (CHARSET_DIMENSION (cs))
     {
     case 1:
-      CHARSET_ENCODING_TABLE(cs) = make_char_code_table (Qnil);
       for (i = 0; i < XVECTOR_LENGTH (table); i++)
        {
          Lisp_Object c = XVECTOR_DATA(table)[i];
 
          if (CHARP (c))
-           {
-             put_char_code_table (XCHAR (c),
-                                  make_int (i + CHARSET_BYTE_OFFSET (cs)),
-                                  CHARSET_ENCODING_TABLE(cs));
-             Fput_char_attribute (c, charset,
-                                  list1
-                                  (make_int (i + CHARSET_BYTE_OFFSET (cs))));
-           }
+           Fput_char_attribute
+             (c, charset,
+              list1 (make_int (i + CHARSET_BYTE_OFFSET (cs))));
        }
       break;
     case 2:
-      CHARSET_ENCODING_TABLE(cs) = make_char_code_table (Qnil);
       for (i = 0; i < XVECTOR_LENGTH (table); i++)
        {
          Lisp_Object v = XVECTOR_DATA(table)[i];
@@ -1745,30 +1697,18 @@ Set mapping-table of CHARSET to TABLE.
                  Lisp_Object c = XVECTOR_DATA(v)[j];
 
                  if (CHARP (c))
-                   {
-                     put_char_code_table
-                       (XCHAR (c),
-                        make_int (( (i + CHARSET_BYTE_OFFSET (cs)) << 8)
-                                  | (j + CHARSET_BYTE_OFFSET (cs))),
-                        CHARSET_ENCODING_TABLE(cs));
-                     Fput_char_attribute (c, charset,
-                                          list2
-                                          (make_int
-                                           (i + CHARSET_BYTE_OFFSET (cs)),
-                                           make_int
-                                           (j + CHARSET_BYTE_OFFSET (cs))));
-                   }
+                   Fput_char_attribute (c, charset,
+                                        list2
+                                        (make_int
+                                         (i + CHARSET_BYTE_OFFSET (cs)),
+                                         make_int
+                                         (j + CHARSET_BYTE_OFFSET (cs))));
                }
            }
          else if (CHARP (v))
-           {
-             put_char_code_table (XCHAR (v),
-                                  make_int (i + CHARSET_BYTE_OFFSET (cs)),
-                                  CHARSET_ENCODING_TABLE(cs));
-             Fput_char_attribute (v, charset,
-                                  list1
-                                  (make_int (i + CHARSET_BYTE_OFFSET (cs))));
-           }
+           Fput_char_attribute (v, charset,
+                                list1
+                                (make_int (i + CHARSET_BYTE_OFFSET (cs))));
        }
       break;
     }