(define-charset): New args :min-code and :max-code.
[bpt/emacs.git] / src / coding.c
index 9bdc985..1fc59a0 100644 (file)
@@ -303,7 +303,8 @@ encode_coding_XXX (coding)
 Lisp_Object Vcoding_system_hash_table;
 
 Lisp_Object Qcoding_system, Qcoding_aliases, Qeol_type;
-Lisp_Object Qunix, Qdos, Qmac;
+Lisp_Object Qunix, Qdos;
+extern Lisp_Object Qmac;       /* frame.c */
 Lisp_Object Qbuffer_file_coding_system;
 Lisp_Object Qpost_read_conversion, Qpre_write_conversion;
 Lisp_Object Qdefault_char;
@@ -764,6 +765,7 @@ static int detected_mask[coding_category_raw_text] =
          error ("Undecodable char found");     \
        c = ((c & 1) << 6) | *src++;            \
       }                                                \
+    consumed_chars++;                          \
   } while (0)
 
 
@@ -1076,6 +1078,7 @@ detect_coding_utf_8 (coding, mask)
 }
 
 
+/* Fixme: deal with surrogates?  */
 static void
 decode_coding_utf_8 (coding)
      struct coding_system *coding;
@@ -1124,23 +1127,38 @@ decode_coding_utf_8 (coding)
          if (! UTF_8_EXTRA_OCTET_P (c2))
            goto invalid_code;
          if (UTF_8_2_OCTET_LEADING_P (c1))
-           c = ((c1 & 0x1F) << 6) | (c2 & 0x3F);
+           {
+             c = ((c1 & 0x1F) << 6) | (c2 & 0x3F);
+             /* Reject overlong sequences here and below.  Encoders
+                producing them are incorrect, they can be misleading,
+                and they mess up read/write invariance.  */
+             if (c < 128)
+               goto invalid_code;
+           }
          else
            {
              ONE_MORE_BYTE (c3);
              if (! UTF_8_EXTRA_OCTET_P (c3))
                goto invalid_code;
              if (UTF_8_3_OCTET_LEADING_P (c1))
-               c = (((c1 & 0xF) << 12)
-                    | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
+               {
+                 c = (((c1 & 0xF) << 12)
+                      | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
+                 if (c < 0x800)
+                   goto invalid_code;
+               }
              else
                {
                  ONE_MORE_BYTE (c4);
                  if (! UTF_8_EXTRA_OCTET_P (c4))
                    goto invalid_code;
                  if (UTF_8_4_OCTET_LEADING_P (c1))
+                   {
                    c = (((c1 & 0x7) << 18) | ((c2 & 0x3F) << 12)
                         | ((c3 & 0x3F) << 6) | (c4 & 0x3F));
+                   if (c < 0x10000)
+                     goto invalid_code;
+                   }
                  else
                    {
                      ONE_MORE_BYTE (c5);
@@ -1151,7 +1169,7 @@ decode_coding_utf_8 (coding)
                          c = (((c1 & 0x3) << 24) | ((c2 & 0x3F) << 18)
                               | ((c3 & 0x3F) << 12) | ((c4 & 0x3F) << 6)
                               | (c5 & 0x3F));
-                         if (c > MAX_CHAR)
+                         if ((c > MAX_CHAR) || (c < 0x200000))
                            goto invalid_code;
                        }
                      else
@@ -1523,12 +1541,11 @@ char emacs_mule_bytes[256];
 
 
 int
-emacs_mule_char (coding, composition, nbytes, nchars)
+emacs_mule_char (coding, src, nbytes, nchars)
      struct coding_system *coding;
-     int composition;
+     unsigned char *src;
      int *nbytes, *nchars;
 {
-  unsigned char *src = coding->source + coding->consumed;
   unsigned char *src_end = coding->source + coding->src_bytes;
   int multibytep = coding->src_multibyte;
   unsigned char *src_base = src;
@@ -1538,20 +1555,6 @@ emacs_mule_char (coding, composition, nbytes, nchars)
   int consumed_chars = 0;
 
   ONE_MORE_BYTE (c);
-  if (composition)
-    {
-      c -= 0x20;
-      if (c == 0x80)
-       {
-         ONE_MORE_BYTE (c);
-         if (c < 0xA0)
-           goto invalid_code;
-         *nbytes = src - src_base;
-         *nchars = consumed_chars;
-         return (c - 0x80);
-       }
-    }
-
   switch (emacs_mule_bytes[c])
     {
     case 2:
@@ -1576,17 +1579,18 @@ emacs_mule_char (coding, composition, nbytes, nchars)
          if (! (charset = emacs_mule_charset[c]))
            goto invalid_code;
          ONE_MORE_BYTE (c);
-         code = (c & 0x7F) << 7;
+         code = (c & 0x7F) << 8;
          ONE_MORE_BYTE (c);
          code |= c & 0x7F;
        }
       break;
 
     case 4:
+      ONE_MORE_BYTE (c);
       if (! (charset = emacs_mule_charset[c]))
        goto invalid_code;
       ONE_MORE_BYTE (c);
-      code = (c & 0x7F) << 7;
+      code = (c & 0x7F) << 8;
       ONE_MORE_BYTE (c);
       code |= c & 0x7F;
       break;
@@ -1709,7 +1713,7 @@ detect_coding_emacs_mule (coding, mask)
                                                                \
       if (src == src_end)                                      \
        break;                                                  \
-      c = emacs_mule_char (coding, 1, &nbytes, &nchars);       \
+      c = emacs_mule_char (coding, src, &nbytes, &nchars);     \
       if (c < 0)                                               \
        {                                                       \
          if (c == -2)                                          \
@@ -1724,17 +1728,18 @@ detect_coding_emacs_mule (coding, mask)
 
 
 /* Decode a composition rule represented as a component of composition
-   sequence of Emacs 20 style at SRC.  Set C to the rule.  If SRC
-   points an invalid byte sequence, set C to -1.  */
+   sequence of Emacs 20 style at SRC.  Store the decoded rule in *BUF,
+   and increment BUF.  If SRC points an invalid byte sequence, set C
+   to -1.  */
 
-#define DECODE_EMACS_MULE_COMPOSITION_RULE(buf)                \
+#define DECODE_EMACS_MULE_COMPOSITION_RULE_20(buf)     \
   do {                                                 \
     int c, gref, nref;                                 \
                                                        \
-    if (src < src_end)                                 \
+    if (src >= src_end)                                        \
       goto invalid_code;                               \
     ONE_MORE_BYTE_NO_CHECK (c);                                \
-    c -= 0xA0;                                         \
+    c -= 0x20;                                         \
     if (c < 0 || c >= 81)                              \
       goto invalid_code;                               \
                                                        \
@@ -1743,6 +1748,28 @@ detect_coding_emacs_mule (coding, mask)
   } while (0)
 
 
+/* Decode a composition rule represented as a component of composition
+   sequence of Emacs 21 style at SRC.  Store the decoded rule in *BUF,
+   and increment BUF.  If SRC points an invalid byte sequence, set C
+   to -1.  */
+
+#define DECODE_EMACS_MULE_COMPOSITION_RULE_21(buf)     \
+  do {                                                 \
+    int gref, nref;                                    \
+                                                       \
+    if (src + 1>= src_end)                             \
+      goto invalid_code;                               \
+    ONE_MORE_BYTE_NO_CHECK (gref);                     \
+    gref -= 0x20;                                      \
+    ONE_MORE_BYTE_NO_CHECK (nref);                     \
+    nref -= 0x20;                                      \
+    if (gref < 0 || gref >= 81                         \
+       || nref < 0 || nref >= 81)                      \
+      goto invalid_code;                               \
+    *buf++ = COMPOSITION_ENCODE_RULE (gref, nref);     \
+  } while (0)
+
+
 #define ADD_COMPOSITION_DATA(buf, method, nchars)      \
   do {                                                 \
     *buf++ = -5;                                       \
@@ -1756,10 +1783,11 @@ detect_coding_emacs_mule (coding, mask)
 #define DECODE_EMACS_MULE_21_COMPOSITION(c)                            \
   do {                                                                 \
     /* Emacs 21 style format.  The first three bytes at SRC are                \
-       (METHOD - 0xF0), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is \
+       (METHOD - 0xF2), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is \
        the byte length of this composition information, CHARS is the   \
        number of characters composed by this composition.  */          \
-    enum composition_method method = c - 0xF0;                         \
+    enum composition_method method = c - 0xF2;                         \
+    int *charbuf_base = charbuf;                                       \
     int consumed_chars_limit;                                          \
     int nbytes, nchars;                                                        \
                                                                        \
@@ -1777,12 +1805,14 @@ detect_coding_emacs_mule (coding, mask)
        while (consumed_chars < consumed_chars_limit)                   \
          {                                                             \
            if (i % 2 && method != COMPOSITION_WITH_ALTCHARS)           \
-             DECODE_EMACS_MULE_COMPOSITION_RULE (charbuf);             \
+             DECODE_EMACS_MULE_COMPOSITION_RULE_21 (charbuf);          \
            else                                                        \
              DECODE_EMACS_MULE_COMPOSITION_CHAR (charbuf);             \
+           i++;                                                        \
          }                                                             \
        if (consumed_chars < consumed_chars_limit)                      \
          goto invalid_code;                                            \
+       charbuf_base[0] -= i;                                           \
       }                                                                        \
   } while (0)
 
@@ -1818,7 +1848,7 @@ detect_coding_emacs_mule (coding, mask)
     DECODE_EMACS_MULE_COMPOSITION_CHAR (buf);                  \
     for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++)           \
       {                                                                \
-       DECODE_EMACS_MULE_COMPOSITION_RULE (buf);               \
+       DECODE_EMACS_MULE_COMPOSITION_RULE_20 (buf);            \
        DECODE_EMACS_MULE_COMPOSITION_CHAR (buf);               \
       }                                                                \
     if (i < 1 || (buf - components) % 2 == 0)                  \
@@ -1883,8 +1913,8 @@ decode_coding_emacs_mule (coding)
          if (charbuf + 5 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 > charbuf_end)
            break;
          ONE_MORE_BYTE (c);
-         if (c - 0xF0 >= COMPOSITION_RELATIVE
-             && c - 0xF0 <= COMPOSITION_WITH_RULE_ALTCHARS)
+         if (c - 0xF2 >= COMPOSITION_RELATIVE
+             && c - 0xF2 <= COMPOSITION_WITH_RULE_ALTCHARS)
            DECODE_EMACS_MULE_21_COMPOSITION (c);
          else if (c < 0xC0)
            DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION (c);
@@ -1892,12 +1922,14 @@ decode_coding_emacs_mule (coding)
            DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION (c);
          else
            goto invalid_code;
+         coding->annotated = 1;
        }
       else if (c < 0xA0 && emacs_mule_bytes[c] > 1)
        {
          int nbytes, nchars;
-         src--;
-         c = emacs_mule_char (coding, 0, &nbytes, &nchars);
+         src = src_base;
+         consumed_chars = consumed_chars_base;
+         c = emacs_mule_char (coding, src, &nbytes, &nchars);
          if (c < 0)
            {
              if (c == -2)
@@ -1905,6 +1937,8 @@ decode_coding_emacs_mule (coding)
              goto invalid_code;
            }
          *charbuf++ = c;
+         src += nbytes;
+         consumed_chars += nchars;
          char_offset++;
        }
       continue;
@@ -2188,7 +2222,8 @@ enum iso_code_class_type iso_code_class[256];
   (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0)
 
 static void
-setup_iso_safe_charsets (Lisp_Object attrs)
+setup_iso_safe_charsets (attrs)
+     Lisp_Object attrs;
 {
   Lisp_Object charset_list, safe_charsets;
   Lisp_Object request;
@@ -2572,7 +2607,7 @@ detect_coding_iso_2022 (coding, mask)
 #define DECODE_COMPOSITION_START(c1)                                   \
   do {                                                                 \
     if (c1 == '0'                                                      \
-       && composition_state == COMPOSING_COMPONENT_CHAR)               \
+       && composition_state == COMPOSING_COMPONENT_RULE)               \
       {                                                                        \
        component_len = component_idx;                                  \
        composition_state = COMPOSING_CHAR;                             \
@@ -2725,27 +2760,26 @@ decode_coding_iso_2022 (coding)
                  composition_state--;
                  continue;
                }
-             else if (method == COMPOSITION_WITH_RULE)
-               composition_state = COMPOSING_RULE;
-             else if (method == COMPOSITION_WITH_RULE_ALTCHARS
-                      && composition_state == COMPOSING_COMPONENT_CHAR)
-               composition_state = COMPOSING_COMPONENT_CHAR;
            }
          if (charset_id_0 < 0
              || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_0)))
-           {
-             /* This is SPACE or DEL.  */
-             charset = CHARSET_FROM_ID (charset_ascii);
-             break;
-           }
-         /* This is a graphic character, we fall down ...  */
+           /* This is SPACE or DEL.  */
+           charset = CHARSET_FROM_ID (charset_ascii);
+         else
+           charset = CHARSET_FROM_ID (charset_id_0);
+         break;
 
        case ISO_graphic_plane_0:
-         if (composition_state == COMPOSING_RULE)
+         if (composition_state != COMPOSING_NO)
            {
-             DECODE_COMPOSITION_RULE (c1);
-             components[component_idx++] = c1;
-             composition_state = COMPOSING_CHAR;
+             if (composition_state == COMPOSING_RULE
+                 || composition_state == COMPOSING_COMPONENT_RULE)
+               {
+                 DECODE_COMPOSITION_RULE (c1);
+                 components[component_idx++] = c1;
+                 composition_state--;
+                 continue;
+               }
            }
          charset = CHARSET_FROM_ID (charset_id_0);
          break;
@@ -3009,7 +3043,13 @@ decode_coding_iso_2022 (coding)
          char_offset++;
        }
       else
-       components[component_idx++] = c;
+       {
+         components[component_idx++] = c;
+         if (method == COMPOSITION_WITH_RULE
+             || (method == COMPOSITION_WITH_RULE_ALTCHARS
+                 && composition_state == COMPOSING_COMPONENT_CHAR))
+           composition_state++;
+       }
       continue;
 
     invalid_code:
@@ -3488,8 +3528,16 @@ encode_coding_iso_2022 (coding)
 
          if (!charset)
            {
-             c = coding->default_char;
-             charset = char_charset (c, charset_list, NULL);
+             if (coding->mode & CODING_MODE_SAFE_ENCODING)
+               {
+                 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION;
+                 charset = CHARSET_FROM_ID (charset_ascii);
+               }
+             else
+               {
+                 c = coding->default_char;
+                 charset = char_charset (c, charset_list, NULL);
+               }
            }
          ENCODE_ISO_CHARACTER (charset, c);
        }
@@ -3851,8 +3899,16 @@ encode_coding_sjis (coding)
 
          if (!charset)
            {
-             c = coding->default_char;
-             charset = char_charset (c, charset_list, &code);
+             if (coding->mode & CODING_MODE_SAFE_ENCODING)
+               {
+                 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION;
+                 charset = CHARSET_FROM_ID (charset_ascii);
+               }
+             else
+               {
+                 c = coding->default_char;
+                 charset = char_charset (c, charset_list, &code);
+               }
            }
          if (code == CHARSET_INVALID_CODE (charset))
            abort ();
@@ -3911,8 +3967,16 @@ encode_coding_big5 (coding)
 
          if (! charset)
            {
-             c = coding->default_char;
-             charset = char_charset (c, charset_list, &code);
+             if (coding->mode & CODING_MODE_SAFE_ENCODING)
+               {
+                 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION;
+                 charset = CHARSET_FROM_ID (charset_ascii);
+               }
+             else
+               {
+                 c = coding->default_char;
+                 charset = char_charset (c, charset_list, &code);
+               }
            }
          if (code == CHARSET_INVALID_CODE (charset))
            abort ();
@@ -4274,6 +4338,8 @@ decode_coding_charset (coding)
       ONE_MORE_BYTE (c);
       if (c == '\r')
        {
+         /* Here we assume that no charset maps '\r' to something
+            else.  */
          if (EQ (eol_type, Qdos))
            {
              if (src < src_end
@@ -4287,28 +4353,48 @@ decode_coding_charset (coding)
        {
          Lisp_Object val;
          struct charset *charset;
-         int c1;
+         int dim;
+         int len = 1;
+         unsigned code = c;
 
          val = AREF (valids, c);
          if (NILP (val))
            goto invalid_code;
-         charset = CHARSET_FROM_ID (XFASTINT (val));
-         if (CHARSET_DIMENSION (charset) > 1)
+         if (INTEGERP (val))
            {
-             ONE_MORE_BYTE (c1);
-             c = (c << 8) | c1;
-             if (CHARSET_DIMENSION (charset) > 2)
+             charset = CHARSET_FROM_ID (XFASTINT (val));
+             dim = CHARSET_DIMENSION (charset);
+             while (len < dim)
                {
-                 ONE_MORE_BYTE (c1);
-                 c = (c << 8) | c1;
-                 if (CHARSET_DIMENSION (charset) > 3)
+                 ONE_MORE_BYTE (c);
+                 code = (code << 8) | c;
+                 len++;
+               }
+             CODING_DECODE_CHAR (coding, src, src_base, src_end,
+                                 charset, code, c);
+           }
+         else
+           {
+             /* VAL is a list of charset IDs.  It is assured that the
+                list is sorted by charset dimensions (smaller one
+                comes first).  */
+             while (CONSP (val))
+               {
+                 charset = CHARSET_FROM_ID (XFASTINT (XCAR (val)));
+                 dim = CHARSET_DIMENSION (charset);
+                 while (len < dim)
                    {
-                     ONE_MORE_BYTE (c1);
-                     c = (c << 8) | c1;
+                     ONE_MORE_BYTE (c);
+                     code = (code << 8) | c;
+                     len++;
                    }
+                 CODING_DECODE_CHAR (coding, src, src_base,
+                                     src_end, charset, code, c);
+                 if (c >= 0)
+                   break;
+                 val = XCDR (val);
                }
            }
-         CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c);
          if (c < 0)
            goto invalid_code;
        }
@@ -4372,7 +4458,13 @@ encode_coding_charset (coding)
                                 (code >> 8) & 0xFF, code & 0xFF);
            }
          else
-           EMIT_ONE_BYTE (coding->default_char);
+           {
+             if (coding->mode & CODING_MODE_SAFE_ENCODING)
+               c = CODING_INHIBIT_CHARACTER_SUBSTITUTION;
+             else
+               c = coding->default_char;
+             EMIT_ONE_BYTE (c);
+           }
        }
     }
 
@@ -7101,7 +7193,7 @@ usage: (find-operation-coding-system OPERATION ARGUMENTS ...)  */)
 
 DEFUN ("set-coding-system-priority", Fset_coding_system_priority,
        Sset_coding_system_priority, 1, MANY, 0,
-       doc: /* Assign higher priority to coding systems given as arguments.
+       doc: /* Assign higher priority to the coding systems given as arguments.
 usage: (set-coding-system-priority CODING-SYSTEM ...)  */)
      (nargs, args)
      int nargs;
@@ -7151,7 +7243,8 @@ usage: (set-coding-system-priority CODING-SYSTEM ...)  */)
 
 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list,
        Scoding_system_priority_list, 0, 1, 0,
-       doc: /* Return a list of coding systems ordered by their priorities.  */)
+       doc: /* Return a list of coding systems ordered by their priorities.
+HIGHESTP non-nil means just return the highest priority one.  */)
      (highestp)
      Lisp_Object highestp;
 {
@@ -7174,12 +7267,13 @@ DEFUN ("coding-system-priority-list", Fcoding_system_priority_list,
   return Fnreverse (val);
 }
 
+static char *suffixes[] = { "-unix", "-dos", "-mac" };
+
 static Lisp_Object
 make_subsidiaries (base)
      Lisp_Object base;
 {
   Lisp_Object subsidiaries;
-  char *suffixes[] = { "-unix", "-dos", "-mac" };
   int base_name_len = STRING_BYTES (XSYMBOL (base)->name);
   char *buf = (char *) alloca (base_name_len + 6);
   int i;
@@ -7314,20 +7408,61 @@ usage: (define-coding-system-internal ...)  */)
 
   if (EQ (coding_type, Qcharset))
     {
+      /* Generate a lisp vector of 256 elements.  Each element is nil,
+        integer, or a list of charset IDs.
+
+        If Nth element is nil, the byte code N is invalid in this
+        coding system.
+
+        If Nth element is a number NUM, N is the first byte of a
+        charset whose ID is NUM.
+
+        If Nth element is a list of charset IDs, N is the first byte
+        of one of them.  The list is sorted by dimensions of the
+        charsets.  A charset of smaller dimension comes firtst.
+      */
       val = Fmake_vector (make_number (256), Qnil);
 
       for (tail = charset_list; CONSP (tail); tail = XCDR (tail))
        {
-         struct charset *charset = CHARSET_FROM_ID (XINT (XCAR (tail)));
-         int idx = (CHARSET_DIMENSION (charset) - 1) * 4;
-
+         struct charset *charset = CHARSET_FROM_ID (XFASTINT (XCAR (tail)));
+         int dim = CHARSET_DIMENSION (charset);
+         int idx = (dim - 1) * 4;
+         
          for (i = charset->code_space[idx];
               i <= charset->code_space[idx + 1]; i++)
            {
-             if (NILP (AREF (val, i)))
-               ASET (val, i, XCAR (tail));
+             Lisp_Object tmp, tmp2;
+             int dim2;
+
+             tmp = AREF (val, i);
+             if (NILP (tmp))
+               tmp = XCAR (tail);
+             else if (NUMBERP (tmp))
+               {
+                 dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (tmp)));
+                 if (dim < dim2)
+                   tmp = Fcons (XCAR (tail), Fcons (tmp, Qnil));
+                 else
+                   tmp = Fcons (tmp, Fcons (XCAR (tail), Qnil));
+               }
              else
-               error ("Charsets conflicts in the first byte");
+               {
+                 for (tmp2 = tmp; CONSP (tmp2); tmp2 = XCDR (tmp2))
+                   {
+                     dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (XCAR (tmp2))));
+                     if (dim < dim2)
+                       break;
+                   }
+                 if (NILP (tmp2))
+                   tmp = nconc2 (tmp, Fcons (XCAR (tail), Qnil));
+                 else
+                   {
+                     XSETCDR (tmp2, Fcons (XCAR (tmp2), XCDR (tmp2)));
+                     XSETCAR (tmp2, XCAR (tail));
+                   }
+               }
+             ASET (val, i, tmp);
            }
        }
       ASET (attrs, coding_attr_charset_valids, val);
@@ -7600,6 +7735,8 @@ usage: (define-coding-system-internal ...)  */)
                         make_number (nargs)));
 }
 
+/* Fixme: should this record the alias relationships for
+   diagnostics?  */
 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias,
        Sdefine_coding_system_alias, 2, 2, 0,
        doc: /* Define ALIAS as an alias for CODING-SYSTEM.  */)
@@ -7639,7 +7776,7 @@ DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias,
 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base,
        1, 1, 0,
        doc: /* Return the base of CODING-SYSTEM.
-Any alias or subsidiary coding systems are not base coding system.  */)
+Any alias or subsidiary coding system is not a base coding system.  */)
   (coding_system)
      Lisp_Object coding_system;
 {
@@ -7670,9 +7807,7 @@ DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist,
 
 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases,
        1, 1, 0,
-       doc: /* Return the list of aliases of CODING-SYSTEM.
-A base coding system is what made by `define-coding-system'.
-Any alias nor subsidiary coding systems are not base coding system.  */)
+       doc: /* Return the list of aliases of CODING-SYSTEM.  */)
      (coding_system)
      Lisp_Object coding_system;
 {
@@ -7681,7 +7816,7 @@ Any alias nor subsidiary coding systems are not base coding system.  */)
   if (NILP (coding_system))
     coding_system = Qno_conversion;
   CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec);
-  return AREF (spec, 2);
+  return AREF (spec, 1);
 }
 
 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type,
@@ -7755,6 +7890,10 @@ init_coding_once ()
     {
       emacs_mule_bytes[i] = 1;
     }
+  emacs_mule_bytes[LEADING_CODE_PRIVATE_11] = 3;
+  emacs_mule_bytes[LEADING_CODE_PRIVATE_12] = 3;
+  emacs_mule_bytes[LEADING_CODE_PRIVATE_21] = 4;
+  emacs_mule_bytes[LEADING_CODE_PRIVATE_22] = 4;
 }
 
 #ifdef emacs
@@ -7809,7 +7948,6 @@ syms_of_coding ()
   DEFSYM (Qeol_type, "eol-type");
   DEFSYM (Qunix, "unix");
   DEFSYM (Qdos, "dos");
-  DEFSYM (Qmac, "mac");
 
   DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system");
   DEFSYM (Qpost_read_conversion, "post-read-conversion");