]> code.delx.au - gnu-emacs/blobdiff - src/coding.c
Update copyright year to 2015
[gnu-emacs] / src / coding.c
index 84b774b4355d57c93861dd23c61af1282619de55..f3f8dc1887521485e019f509b83bc88e30256692 100644 (file)
@@ -1,5 +1,5 @@
 /* Coding system handler (conversion, detection, etc).
-   Copyright (C) 2001-2014 Free Software Foundation, Inc.
+   Copyright (C) 2001-2015 Free Software Foundation, Inc.
    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
      2005, 2006, 2007, 2008, 2009, 2010, 2011
      National Institute of Advanced Industrial Science and Technology (AIST)
@@ -642,15 +642,6 @@ static enum coding_category coding_priorities[coding_category_max];
    Nth coding category.  */
 static struct coding_system coding_categories[coding_category_max];
 
-/*** Commonly used macros and functions ***/
-
-#ifndef min
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef max
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
 /* Encode a flag that can be nil, something else, or t as -1, 0, 1.  */
 
 static int
@@ -690,6 +681,14 @@ CHECK_NATNUM_CDR (Lisp_Object x)
   XSETCDR (x, tmp);
 }
 
+/* True if CODING's destination can be grown.  */
+
+static bool
+growable_destination (struct coding_system *coding)
+{
+  return STRINGP (coding->dst_object) || BUFFERP (coding->dst_object);
+}
+
 
 /* Safely get one byte from the source text pointed by SRC which ends
    at SRC_END, and set C to that byte.  If there are not enough bytes
@@ -3074,8 +3073,13 @@ detect_coding_iso_2022 (struct coding_system *coding,
                  ONE_MORE_BYTE (c1);
                  if (c1 < ' ' || c1 >= 0x80
                      || (id = iso_charset_table[0][c >= ','][c1]) < 0)
-                   /* Invalid designation sequence.  Just ignore.  */
-                   break;
+                   {
+                     /* Invalid designation sequence.  Just ignore.  */
+                     if (c1 >= 0x80)
+                       rejected |= (CATEGORY_MASK_ISO_7BIT
+                                    | CATEGORY_MASK_ISO_7_ELSE);
+                     break;
+                   }
                }
              else if (c == '$')
                {
@@ -3089,16 +3093,29 @@ detect_coding_iso_2022 (struct coding_system *coding,
                      ONE_MORE_BYTE (c1);
                      if (c1 < ' ' || c1 >= 0x80
                          || (id = iso_charset_table[1][c >= ','][c1]) < 0)
-                       /* Invalid designation sequence.  Just ignore.  */
-                       break;
+                       {
+                         /* Invalid designation sequence.  Just ignore.  */
+                         if (c1 >= 0x80)
+                           rejected |= (CATEGORY_MASK_ISO_7BIT
+                                        | CATEGORY_MASK_ISO_7_ELSE);
+                         break;
+                       }
                    }
                  else
-                   /* Invalid designation sequence.  Just ignore it.  */
-                   break;
+                   {
+                     /* Invalid designation sequence.  Just ignore it.  */
+                     if (c >= 0x80)
+                       rejected |= (CATEGORY_MASK_ISO_7BIT
+                                    | CATEGORY_MASK_ISO_7_ELSE);
+                     break;
+                   }
                }
              else
                {
                  /* Invalid escape sequence.  Just ignore it.  */
+                 if (c >= 0x80)
+                   rejected |= (CATEGORY_MASK_ISO_7BIT
+                                | CATEGORY_MASK_ISO_7_ELSE);
                  break;
                }
 
@@ -3149,7 +3166,7 @@ detect_coding_iso_2022 (struct coding_system *coding,
          if (inhibit_iso_escape_detection)
            break;
          single_shifting = 0;
-         rejected |= CATEGORY_MASK_ISO_7BIT;
+         rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE;
          if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1])
              & CODING_ISO_FLAG_SINGLE_SHIFT)
            {
@@ -3176,9 +3193,9 @@ detect_coding_iso_2022 (struct coding_system *coding,
              single_shifting = 0;
              break;
            }
+         rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE;
          if (c >= 0xA0)
            {
-             rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE;
              found |= CATEGORY_MASK_ISO_8_1;
              /* Check the length of succeeding codes of the range
                  0xA0..0FF.  If the byte length is even, we include
@@ -7019,8 +7036,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
       int *buf = coding->charbuf;
       int *buf_end = buf + coding->charbuf_used;
 
-      if (EQ (coding->src_object, coding->dst_object))
+      if (EQ (coding->src_object, coding->dst_object)
+         && ! NILP (coding->dst_object))
        {
+         eassert (growable_destination (coding));
          coding_set_source (coding);
          dst_end = ((unsigned char *) coding->source) + coding->consumed;
        }
@@ -7059,6 +7078,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
 
              if ((dst_end - dst) / MAX_MULTIBYTE_LENGTH < to_nchars)
                {
+                 eassert (growable_destination (coding));
                  if (((min (PTRDIFF_MAX, SIZE_MAX) - (buf_end - buf))
                       / MAX_MULTIBYTE_LENGTH)
                      < to_nchars)
@@ -7103,7 +7123,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
       const unsigned char *src_end = src + coding->consumed;
 
       if (EQ (coding->dst_object, coding->src_object))
-       dst_end = (unsigned char *) src;
+       {
+         eassert (growable_destination (coding));
+         dst_end = (unsigned char *) src;
+       }
       if (coding->src_multibyte != coding->dst_multibyte)
        {
          if (coding->src_multibyte)
@@ -7119,6 +7142,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                  ONE_MORE_BYTE (c);
                  if (dst == dst_end)
                    {
+                     eassert (growable_destination (coding));
                      if (EQ (coding->src_object, coding->dst_object))
                        dst_end = (unsigned char *) src;
                      if (dst == dst_end)
@@ -7149,6 +7173,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
 
                if (dst >= dst_end - 1)
                  {
+                   eassert (growable_destination (coding));
                    if (EQ (coding->src_object, coding->dst_object))
                      dst_end = (unsigned char *) src;
                    if (dst >= dst_end - 1)
@@ -9734,7 +9759,7 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern
        doc: /* Internal use only.  */)
   (Lisp_Object coding_system, Lisp_Object terminal)
 {
-  struct terminal *term = get_terminal (terminal, 1);
+  struct terminal *term = decode_live_terminal (terminal);
   struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (term);
   CHECK_SYMBOL (coding_system);
   setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
@@ -9775,7 +9800,7 @@ frame's terminal device.  */)
   (Lisp_Object terminal)
 {
   struct coding_system *terminal_coding
-    = TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1));
+    = TERMINAL_TERMINAL_CODING (decode_live_terminal (terminal));
   Lisp_Object coding_system = CODING_ID_NAME (terminal_coding->id);
 
   /* For backward compatibility, return nil if it is `undecided'.  */
@@ -9787,7 +9812,7 @@ DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_intern
        doc: /* Internal use only.  */)
   (Lisp_Object coding_system, Lisp_Object terminal)
 {
-  struct terminal *t = get_terminal (terminal, 1);
+  struct terminal *t = decode_live_terminal (terminal);
   CHECK_SYMBOL (coding_system);
   if (NILP (coding_system))
     coding_system = Qno_conversion;
@@ -9806,7 +9831,7 @@ DEFUN ("keyboard-coding-system",
   (Lisp_Object terminal)
 {
   return CODING_ID_NAME (TERMINAL_KEYBOARD_CODING
-                        (get_terminal (terminal, 1))->id);
+                        (decode_live_terminal (terminal))->id);
 }
 
 \f