This commit was manufactured by cvs2svn to create branch 'tomo'.
[chise/xemacs-chise.git] / src / file-coding.c
index ee0da8d..0b4f6c1 100644 (file)
@@ -55,7 +55,7 @@ int coding_category_by_priority[CODING_CATEGORY_LAST + 1];
 
 Lisp_Object Qcoding_system_p;
 
-Lisp_Object Qno_conversion, Qccl, Qiso2022;
+Lisp_Object Qraw_text, Qno_conversion, Qccl, Qiso2022;
 /* Qinternal in general.c */
 
 Lisp_Object Qmnemonic, Qeol_type;
@@ -531,7 +531,7 @@ static Lisp_Coding_System *
 allocate_coding_system (enum coding_system_type type, Lisp_Object name)
 {
   Lisp_Coding_System *codesys =
-    alloc_lcrecord_type (Lisp_Coding_System, lrecord_coding_system);
+    alloc_lcrecord_type (Lisp_Coding_System, &lrecord_coding_system);
 
   zero_lcrecord (codesys);
   CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil;
@@ -949,6 +949,40 @@ be created.
   return new_coding_system;
 }
 
+DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, 2, 2, 0, /*
+Define symbol ALIAS as an alias for coding system CODING-SYSTEM.
+*/
+       (alias, coding_system))
+{
+  CHECK_SYMBOL (alias);
+  if (!NILP (Ffind_coding_system (alias)))
+    signal_simple_error ("Symbol already names a coding system", alias);
+  coding_system = Fget_coding_system (coding_system);
+  Fputhash (alias, coding_system, Vcoding_system_hash_table);
+
+  /* Set up aliases for subsidiaries. */
+  if (XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
+    {
+      Lisp_Object str;
+      XSETSTRING (str, symbol_name (XSYMBOL (alias)));
+#define FROB(type, name)                                                       \
+      do {                                                                     \
+       Lisp_Object subsidiary = XCODING_SYSTEM_EOL_##type (coding_system);     \
+       if (!NILP (subsidiary))                                                 \
+         Fdefine_coding_system_alias                                           \
+           (Fintern (concat2 (str, build_string (name)), Qnil), subsidiary);   \
+      } while (0)
+      FROB (LF,   "-unix");
+      FROB (CRLF, "-dos");
+      FROB (CR,   "-mac");
+#undef FROB
+    }
+  /* FSF return value is a vector of [ALIAS-unix ALIAS-doc ALIAS-mac],
+     but it doesn't look intentional, so I'd rather return something
+     meaningful or nothing at all. */
+  return Qnil;
+}
+
 static Lisp_Object
 subsidiary_coding_system (Lisp_Object coding_system, enum eol_type type)
 {
@@ -1497,7 +1531,7 @@ coding_system_from_mask (int mask)
            }
        }
       if (NILP (retval))
-       retval = Fget_coding_system (Qno_conversion);
+       retval = Fget_coding_system (Qraw_text);
       return retval;
     }
   else
@@ -1519,7 +1553,7 @@ coding_system_from_mask (int mask)
       if (cat >= 0)
        return coding_category_system[cat];
       else
-       return Fget_coding_system (Qno_conversion);
+       return Fget_coding_system (Qraw_text);
     }
 }
 
@@ -1718,10 +1752,12 @@ do {                                    \
 
 #define DECODE_HANDLE_END_OF_CONVERSION(flags, ch, dst)        \
 do {                                   \
-  DECODE_OUTPUT_PARTIAL_CHAR (ch);     \
-  if ((flags & CODING_STATE_END) &&    \
-      (flags & CODING_STATE_CR))       \
-    Dynarr_add (dst, '\r');            \
+  if (flags & CODING_STATE_END)                \
+    {                                  \
+      DECODE_OUTPUT_PARTIAL_CHAR (ch); \
+      if (flags & CODING_STATE_CR)     \
+       Dynarr_add (dst, '\r');         \
+    }                                  \
 } while (0)
 
 #define DECODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, decoding)
@@ -3164,7 +3200,8 @@ Return the UCS code (a positive integer) corresponding to CHARACTER.
 }
 
 /* Decode a UCS-4 character into a buffer.  If the lookup fails, use
-   JIS X 0208 double-width `=' instead.
+   <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
@@ -5379,6 +5416,7 @@ syms_of_mule_coding (void)
   DEFSUBR (Fcoding_system_name);
   DEFSUBR (Fmake_coding_system);
   DEFSUBR (Fcopy_coding_system);
+  DEFSUBR (Fdefine_coding_system_alias);
   DEFSUBR (Fsubsidiary_coding_system);
 
   DEFSUBR (Fcoding_system_type);
@@ -5409,6 +5447,7 @@ syms_of_mule_coding (void)
 #endif /* MULE */
   defsymbol (&Qcoding_system_p, "coding-system-p");
   defsymbol (&Qno_conversion, "no-conversion");
+  defsymbol (&Qraw_text, "raw-text");
 #ifdef MULE
   defsymbol (&Qbig5, "big5");
   defsymbol (&Qshift_jis, "shift-jis");
@@ -5605,15 +5644,22 @@ complex_vars_of_mule_coding (void)
   DEFINE_CODESYS_PROP (CODESYS_PROP_CCL,     Qdecode);
 #endif /* MULE */
   /* Need to create this here or we're really screwed. */
-  Fmake_coding_system (Qno_conversion, Qno_conversion, build_string ("No conversion"),
-                      list2 (Qmnemonic, build_string ("Noconv")));
+  Fmake_coding_system
+    (Qraw_text, Qno_conversion,
+     build_string ("Raw text, which means it converts only line-break-codes."),
+     list2 (Qmnemonic, build_string ("Raw")));
+
+  Fmake_coding_system
+    (Qbinary, Qno_conversion,
+     build_string ("Binary, which means it does not convert anything."),
+     list4 (Qeol_type, Qlf,
+           Qmnemonic, build_string ("Binary")));
 
-  Fcopy_coding_system (Fcoding_system_property (Qno_conversion, Qeol_lf),
-                      Qbinary);
+  Fdefine_coding_system_alias (Qno_conversion, Qraw_text);
 
   /* Need this for bootstrapping */
   coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
-    Fget_coding_system (Qno_conversion);
+    Fget_coding_system (Qraw_text);
 
 #ifdef MULE
   {