Bump version to 24.2
[bpt/emacs.git] / src / coding.c
index b174307..eb89563 100644 (file)
@@ -1,5 +1,5 @@
 /* Coding system handler (conversion, detection, etc).
-   Copyright (C) 2001-2011 Free Software Foundation, Inc.
+   Copyright (C) 2001-2012 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)
@@ -855,7 +855,7 @@ static void coding_alloc_by_making_gap (struct coding_system *,
 static unsigned char *alloc_destination (struct coding_system *,
                                          EMACS_INT, unsigned char *);
 static void setup_iso_safe_charsets (Lisp_Object);
-static int encode_designation_at_bol (struct coding_system *,
+static EMACS_INT encode_designation_at_bol (struct coding_system *,
                                      int *, int *, unsigned char *);
 static int detect_eol (const unsigned char *,
                        EMACS_INT, enum coding_category);
@@ -4351,12 +4351,12 @@ encode_invocation_designation (struct charset *charset,
    If the current block ends before any end-of-line, we may fail to
    find all the necessary designations.  */
 
-static int
+static EMACS_INT
 encode_designation_at_bol (struct coding_system *coding,
                           int *charbuf, int *charbuf_end,
                           unsigned char *dst)
 {
-  unsigned char *orig;
+  unsigned char *orig = dst;
   struct charset *charset;
   /* Table of charsets to be designated to each graphic register.  */
   int r[4];
@@ -5244,7 +5244,7 @@ encode_coding_ccl (struct coding_system *coding)
       && coding->mode & CODING_MODE_LAST_BLOCK)
     ccl->last_block = 1;
 
-  while (charbuf < charbuf_end)
+  do
     {
       ccl_driver (ccl, charbuf, destination_charbuf,
                  charbuf_end - charbuf, 1024, charset_list);
@@ -5266,6 +5266,7 @@ encode_coding_ccl (struct coding_system *coding)
          || ccl->status == CCL_STAT_INVALID_CMD)
        break;
     }
+  while (charbuf < charbuf_end);
 
   switch (ccl->status)
     {
@@ -6848,7 +6849,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                          dst_end = coding->destination + coding->dst_bytes;
                          coding_set_source (coding);
                          src = coding->source + offset;
-                         src_end = coding->source + coding->src_bytes;
+                         src_end = coding->source + coding->consumed;
                          if (EQ (coding->src_object, coding->dst_object))
                            dst_end = (unsigned char *) src;
                        }
@@ -6882,7 +6883,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                        dst_end = coding->destination + coding->dst_bytes;
                        coding_set_source (coding);
                        src = coding->source + offset;
-                       src_end = coding->source + coding->src_bytes;
+                       src_end = coding->source + coding->consumed;
                        if (EQ (coding->src_object, coding->dst_object))
                          dst_end = (unsigned char *) src;
                      }
@@ -6903,7 +6904,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                  dst = alloc_destination (coding, require, dst);
                  coding_set_source (coding);
                  src = coding->source + offset;
-                 src_end = coding->source + coding->src_bytes;
+                 src_end = coding->source + coding->consumed;
                }
            }
          produced_chars = coding->consumed_char;
@@ -8755,6 +8756,7 @@ to the string.  */)
     }
 
   positions = Qnil;
+  charset_map_loaded = 0;
   while (1)
     {
       int c;
@@ -8782,6 +8784,16 @@ to the string.  */)
        }
 
       from++;
+      if (charset_map_loaded && NILP (string))
+       {
+         p = CHAR_POS_ADDR (from);
+         pend = CHAR_POS_ADDR (to);
+         if (from < GPT && to >= GPT)
+           stop = GPT_ADDR;
+         else
+           stop = pend;
+         charset_map_loaded = 0;
+       }
     }
 
   return (NILP (count) ? Fcar (positions) : Fnreverse (positions));
@@ -9987,8 +9999,6 @@ usage: (define-coding-system-internal ...)  */)
     {
       Lisp_Object bom;
 
-      CODING_ATTR_ASCII_COMPAT (attrs) = Qt;
-
       if (nargs < coding_arg_utf8_max)
        goto short_args;
 
@@ -10002,6 +10012,8 @@ usage: (define-coding-system-internal ...)  */)
          CHECK_CODING_SYSTEM (val);
        }
       ASET (attrs, coding_attr_utf_bom, bom);
+      if (NILP (bom))
+       CODING_ATTR_ASCII_COMPAT (attrs) = Qt;
 
       category = (CONSP (bom) ? coding_category_utf_8_auto
                  : NILP (bom) ? coding_category_utf_8_nosig