]> code.delx.au - gnu-emacs/blobdiff - src/coding.c
(gnus-start-news-server): Use expand-file-name, not
[gnu-emacs] / src / coding.c
index fa079a749cb04ac93af6d0d31a2f510b3846792b..f44efa9415e976c1c68b314692766028ed1ad859 100644 (file)
@@ -614,7 +614,45 @@ decode_coding_emacs_mule (coding, source, destination, src_bytes, dst_bytes)
       unsigned char tmp[MAX_MULTIBYTE_LENGTH], *p;
       int bytes;
 
-      if (UNIBYTE_STR_AS_MULTIBYTE_P (src, src_end - src, bytes))
+      if (*src == '\r')
+       {
+         int c;
+
+         src++;
+         if (coding->eol_type == CODING_EOL_CR)
+           c = '\n';
+         else if (coding->eol_type == CODING_EOL_CRLF)
+           {
+             ONE_MORE_BYTE (c);
+             if (c != '\n')
+               {
+                 if (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
+                   {
+                     coding->result = CODING_FINISH_INCONSISTENT_EOL;
+                     goto label_end_of_loop;
+                   }
+                 src--;
+                 c = '\r';
+               }
+           }
+         *dst++ = c;
+         coding->produced_char++;
+         continue;
+       }
+      else if (*src == '\n')
+       {
+         if ((coding->eol_type == CODING_EOL_CR
+              || coding->eol_type == CODING_EOL_CRLF)
+             && coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
+           {
+             coding->result = CODING_FINISH_INCONSISTENT_EOL;
+             goto label_end_of_loop;
+           }
+         *dst++ = *src++;
+         coding->produced_char++;
+         continue;
+       }
+      else if (UNIBYTE_STR_AS_MULTIBYTE_P (src, src_end - src, bytes))
        {
          p = src;
          src += bytes;
@@ -633,6 +671,7 @@ decode_coding_emacs_mule (coding, source, destination, src_bytes, dst_bytes)
       while (bytes--) *dst++ = *p++;
       coding->produced_char++;
     }
+ label_end_of_loop:
   coding->consumed = coding->consumed_char = src_base - source;
   coding->produced = dst - destination;
 }
@@ -4184,6 +4223,7 @@ decode_coding (coding, source, destination, src_bytes, dst_bytes)
     }
 
   if (coding->result == CODING_FINISH_INSUFFICIENT_SRC
+      && coding->mode & CODING_MODE_LAST_BLOCK
       && coding->consumed == src_bytes)
     coding->result = CODING_FINISH_NORMAL;
 
@@ -4800,11 +4840,14 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
        {
          detect_coding (coding, BYTE_POS_ADDR (from_byte), len_byte);
          if (coding->type == coding_type_undecided)
-           /* It seems that the text contains only ASCII, but we
-              should not left it undecided because the deeper
-              decoding routine (decode_coding) tries to detect the
-              encodings again in vain.  */
-           coding->type = coding_type_emacs_mule;
+           {
+             /* It seems that the text contains only ASCII, but we
+                should not leave it undecided because the deeper
+                decoding routine (decode_coding) tries to detect the
+                encodings again in vain.  */
+             coding->type = coding_type_emacs_mule;
+             coding->category_idx = CODING_CATEGORY_IDX_EMACS_MULE;
+           }
        }
       if (coding->eol_type == CODING_EOL_UNDECIDED
          && coding->type != coding_type_ccl)
@@ -5272,6 +5315,9 @@ decode_coding_string (str, coding, nocopy)
        }
     }
 
+  coding->src_multibyte = 0;
+  coding->dst_multibyte = (coding->type != coding_type_no_conversion
+                          && coding->type != coding_type_raw_text);
   require_decoding = CODING_REQUIRE_DECODING (coding);
 
   if (STRING_MULTIBYTE (str))
@@ -5281,9 +5327,6 @@ decode_coding_string (str, coding, nocopy)
       to_byte = STRING_BYTES (XSTRING (str));
       nocopy = 1;
     }
-  coding->src_multibyte = 0;
-  coding->dst_multibyte = (coding->type != coding_type_no_conversion
-                          && coding->type != coding_type_raw_text);
 
   /* Try to skip the heading and tailing ASCIIs.  */
   if (require_decoding && coding->type != coding_type_ccl)
@@ -5417,6 +5460,11 @@ encode_coding_string (str, coding, nocopy)
   to_byte = STRING_BYTES (XSTRING (str));
 
   saved_coding_symbol = Qnil;
+
+  /* Encoding routines determine the multibyteness of the source text
+     by coding->src_multibyte.  */
+  coding->src_multibyte = STRING_MULTIBYTE (str);
+  coding->dst_multibyte = 0;
   if (! CODING_REQUIRE_ENCODING (coding))
     {
       coding->consumed = STRING_BYTES (XSTRING (str));
@@ -5431,11 +5479,6 @@ encode_coding_string (str, coding, nocopy)
       return (nocopy ? str : Fcopy_sequence (str));
     }
 
-  /* Encoding routines determine the multibyteness of the source text
-     by coding->src_multibyte.  */
-  coding->src_multibyte = STRING_MULTIBYTE (str);
-  coding->dst_multibyte = 0;
-
   if (coding->composing != COMPOSITION_DISABLED)
     coding_save_composition (coding, from, to, str);