(Vcharacter_attribute_table): New variable.
[chise/xemacs-chise.git-] / src / text-coding.c
index 1e12bd4..e3fe8ff 100644 (file)
@@ -869,10 +869,6 @@ if TYPE is 'ccl:
     CHECK_STRING (doc_string);
   CODING_SYSTEM_DOC_STRING (codesys) = doc_string;
 
-#ifdef UTF2000
-  if (ty == CODESYS_NO_CONVERSION)
-    codesys->fixed.size = 1;
-#endif
   EXTERNAL_PROPERTY_LIST_LOOP (rest, key, value, props)
     {
       if (EQ (key, Qmnemonic))
@@ -2562,12 +2558,15 @@ reset_encoding_stream (struct encoding_stream *str)
     case CODESYS_UTF8:
       str->encode_char = &char_encode_utf8;
       str->finish = &char_finish_utf8;
+      break;
     case CODESYS_UCS4:
       str->encode_char = &char_encode_ucs4;
       str->finish = &char_finish_ucs4;
+      break;
     case CODESYS_SHIFT_JIS:
       str->encode_char = &char_encode_shift_jis;
       str->finish = &char_finish_shift_jis;
+      break;
     default:
       break;
     }
@@ -2981,13 +2980,16 @@ char_encode_shift_jis (struct encoding_stream *str, Emchar ch,
     }
   else
     {
-      Lisp_Object charset;
+      Lisp_Object charset, value;
       unsigned int c1, c2, s1, s2;
       
 #ifdef UTF2000
-      if ( (c1 = get_byte_from_character_table (ch, ucs_to_latin_jisx0201)) )
+      if (INTP (value =
+               get_char_code_table
+               (ch, XCHARSET_ENCODING_TABLE (Vcharset_latin_jisx0201))))
        {
          charset = Vcharset_latin_jisx0201;
+         c1 = XINT (value);
          c2 = 0;
        }
       else
@@ -3426,10 +3428,10 @@ void
 char_encode_ucs4 (struct encoding_stream *str, Emchar ch,
                  unsigned_char_dynarr *dst, unsigned int *flags)
 {
-  Dynarr_add (dst,  ch >> 24);
-  Dynarr_add (dst, (ch >> 16) & 255);
-  Dynarr_add (dst, (ch >>  8) & 255);
-  Dynarr_add (dst,  ch        & 255);
+  Dynarr_add (dst, ch >> 24);
+  Dynarr_add (dst, ch >> 16);
+  Dynarr_add (dst, ch >>  8);
+  Dynarr_add (dst, ch      );
 }
 
 void
@@ -4786,23 +4788,44 @@ char_encode_iso2022 (struct encoding_stream *str, Emchar ch,
     {
       int reg;
 
-      BREAKUP_CHAR (ch, charset, byte1, byte2);
-      ensure_correct_direction (XCHARSET_DIRECTION (charset),
-                               codesys, dst, flags, 0);
-
       /* Now determine which register to use. */
       reg = -1;
       for (i = 0; i < 4; i++)
        {
-         if (EQ (charset, str->iso2022.charset[i]) ||
-             EQ (charset,
-                 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)))
+         if ((CHARSETP (charset = str->iso2022.charset[i])
+              && (byte1 = charset_get_byte1 (charset, ch))) ||
+             (CHARSETP
+              (charset
+               = CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i))
+              && (byte1 = charset_get_byte1 (charset, ch))))
            {
              reg = i;
+             byte2 = charset_get_byte2 (charset, ch);
              break;
            }
        }
-             
+      if (reg == -1)
+       {
+         Lisp_Object original_default_coded_charset_priority_list
+           = Vdefault_coded_charset_priority_list;
+
+         while (!EQ (Vdefault_coded_charset_priority_list, Qnil))
+           {
+             BREAKUP_CHAR (ch, charset, byte1, byte2);
+             if (XCHARSET_FINAL (charset))
+               goto found;
+             Vdefault_coded_charset_priority_list
+               = Fcdr (Fmemq (XCHARSET_NAME (charset),
+                              Vdefault_coded_charset_priority_list));
+           }
+         BREAKUP_CHAR (ch, charset, byte1, byte2);
+       found:
+         Vdefault_coded_charset_priority_list
+           = original_default_coded_charset_priority_list;
+       }
+      ensure_correct_direction (XCHARSET_DIRECTION (charset),
+                               codesys, dst, flags, 0);
+      
       if (reg == -1)
        {
          if (XCHARSET_GRAPHIC (charset) != 0)
@@ -4956,80 +4979,54 @@ encode_coding_no_conversion (Lstream *encoding, CONST unsigned char *src,
     {
       c = *src++;        
 #ifdef UTF2000
-      switch (char_boundary)
+      if (char_boundary == 0)
+       if ( c >= 0xfc )
+         {
+           ch = c & 0x01;
+           char_boundary = 5;
+         }
+       else if ( c >= 0xf8 )
+         {
+           ch = c & 0x03;
+           char_boundary = 4;
+         }
+       else if ( c >= 0xf0 )
+         {
+           ch = c & 0x07;
+           char_boundary = 3;
+         }
+       else if ( c >= 0xe0 )
+         {
+           ch = c & 0x0f;
+           char_boundary = 2;
+         }
+       else if ( c >= 0xc0 )
+         {
+           ch = c & 0x1f;
+           char_boundary = 1;
+         }
+       else
+         {
+           ch = 0;
+           if (c == '\n')
+             {
+               if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
+                 Dynarr_add (dst, '\r');
+               if (eol_type != EOL_CR)
+                 Dynarr_add (dst, c);
+             }
+           else
+             Dynarr_add (dst, c);
+           char_boundary = 0;
+         }
+      else if (char_boundary == 1)
        {
-       case 0:
-         if ( c >= 0xfc )
-           {
-             ch = c & 0x01;
-             char_boundary = 5;
-           }
-         else if ( c >= 0xf8 )
-           {
-             ch = c & 0x03;
-             char_boundary = 4;
-           }
-         else if ( c >= 0xf0 )
-           {
-             ch = c & 0x07;
-             char_boundary = 3;
-           }
-         else if ( c >= 0xe0 )
-           {
-             ch = c & 0x0f;
-             char_boundary = 2;
-           }
-         else if ( c >= 0xc0 )
-           {
-             ch = c & 0x1f;
-             char_boundary = 1;
-           }
-         else
-           {
-             ch = 0;
-
-             if (c == '\n')
-               {
-                 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
-                   Dynarr_add (dst, '\r');
-                 if (eol_type != EOL_CR)
-                   Dynarr_add (dst, c);
-               }
-             else
-               Dynarr_add (dst, c);
-             char_boundary = 0;
-           }
-         break;
-       case 1:
          ch = ( ch << 6 ) | ( c & 0x3f );
-         switch ( str->codesys->fixed.size )
-           {
-           case 1:
-             Dynarr_add (dst, ch & 0xff);
-             break;
-           case 2:
-             Dynarr_add (dst, (ch >> 8) & 0xff);
-             Dynarr_add (dst,  ch       & 0xff);
-             break;
-           case 3:
-             Dynarr_add (dst, (ch >> 16) & 0xff);
-             Dynarr_add (dst, (ch >>  8) & 0xff);
-             Dynarr_add (dst,  ch        & 0xff);
-             break;
-           case 4:
-             Dynarr_add (dst, (ch >> 24) & 0xff);
-             Dynarr_add (dst, (ch >> 16) & 0xff);
-             Dynarr_add (dst, (ch >>  8) & 0xff);
-             Dynarr_add (dst,  ch        & 0xff);
-             break;
-           default:
-             fprintf(stderr, "It seems %d bytes stream.\n",
-                     str->codesys->fixed.size);
-             abort ();
-           }
+         Dynarr_add (dst, ch & 0xff);
          char_boundary = 0;
-         break;
-       default:
+       }
+      else
+       {
          ch = ( ch << 6 ) | ( c & 0x3f );
          char_boundary--;
        }