(x_setup_relief_colors): Don't compute an image's
[bpt/emacs.git] / src / coding.c
index f512242..7b352d1 100644 (file)
@@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA.  */
   all variants of ISO2022.  Details are described in section 3.
 
   2. SJIS (or Shift-JIS or MS-Kanji-Code)
-   
+
   A coding system to encode character sets: ASCII, JISX0201, and
   JISX0208.  Widely used for PC's in Japan.  Details are described in
   section 4.
@@ -503,7 +503,7 @@ coding_safe_chars (coding)
      struct coding_system *coding;
 {
   Lisp_Object coding_spec, plist, safe_chars;
-  
+
   coding_spec = Fget (coding->symbol, Qcoding_system);
   plist = XVECTOR (coding_spec)->contents[3];
   safe_chars = Fplist_get (XVECTOR (coding_spec)->contents[3], Qsafe_chars);
@@ -889,7 +889,7 @@ decode_composition_emacs_mule (coding, src, src_end,
       CODING_ADD_COMPOSITION_START (coding, coding->produced_char, method);
       for (i = 0; i < ncomponent; i++)
        CODING_ADD_COMPOSITION_COMPONENT (coding, component[i]);
-      CODING_ADD_COMPOSITION_END (coding, coding->produced_char + nchars);  
+      CODING_ADD_COMPOSITION_END (coding, coding->produced_char + nchars);
       if (buf < bufp)
        {
          unsigned char *p = buf;
@@ -1055,7 +1055,7 @@ decode_coding_emacs_mule (coding, source, destination, src_bytes, dst_bytes)
        coding->cmp_data_start = 0;                                     \
       }                                                                        \
   } while (0)
-  
+
 
 static void encode_eol P_ ((struct coding_system *, unsigned char *,
                            unsigned char *, int, int));
@@ -1433,7 +1433,7 @@ detect_coding_iso2022 (src, src_end, multibytep)
              mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT;
            }
          break;
-         
+
        case ISO_CODE_SI:
          if (inhibit_iso_escape_detection)
            break;
@@ -1665,7 +1665,7 @@ coding_allocate_composition_data (coding, char_offset)
 
 #define DECODE_COMPOSITION_END(c1)                                     \
   do {                                                                 \
-    if (coding->composing == COMPOSITION_DISABLED)                     \
+    if (! COMPOSING_P (coding))                                                \
       {                                                                        \
        *dst++ = ISO_CODE_ESC;                                          \
        *dst++ = c1;                                                    \
@@ -2439,7 +2439,7 @@ encode_designation_at_bol (coding, translation_table, src, src_end, dst)
       ONE_MORE_CHAR (c);
       if (c == '\n')
        break;
-      
+
       charset = CHAR_CHARSET (c);
       reg = CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset);
       if (reg != CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION && r[reg] < 0)
@@ -2609,7 +2609,7 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
                *dst++ = ISO_CODE_CR;
              CODING_SPEC_ISO_BOL (coding) = 1;
            }
-         else 
+         else
            {
              if (coding->flags & CODING_FLAG_ISO_RESET_AT_CNTL)
                ENCODE_RESET_PLANE_AND_REGISTER;
@@ -3032,7 +3032,7 @@ encode_coding_sjis_big5 (coding, source, destination,
 
       src_base = src;
       ONE_MORE_CHAR (c);
-      
+
       /* Now encode the character C.  */
       if (SINGLE_BYTE_CHAR_P (c))
        {
@@ -3357,7 +3357,7 @@ encode_eol (coding, source, destination, src_bytes, dst_bytes)
 
        If the value is nil, graphic register N is never used on
        encoding.
-   
+
    sub-element[N] where N is 4 through 11: to be set in `coding->flags'
        Each value takes t or nil.  See the section ISO2022 of
        `coding.h' for more information.
@@ -3481,7 +3481,7 @@ setup_coding_system (coding_system, coding)
     }
   else
     goto label_invalid_coding_system;
-  
+
   /* If the coding system has non-nil `composition' property, enable
      composition handling.  */
   val = Fplist_get (plist, Qcomposition);
@@ -3576,8 +3576,8 @@ setup_coding_system (coding_system, coding)
            = CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION;
        for (i = 0; i < 4; i++)
          {
-           if (INTEGERP (flags[i])
-               && (charset = XINT (flags[i]), CHARSET_VALID_P (charset))
+           if ((INTEGERP (flags[i])
+                && (charset = XINT (flags[i]), CHARSET_VALID_P (charset)))
                || (charset = get_charset_id (flags[i])) >= 0)
              {
                CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset;
@@ -3595,9 +3595,9 @@ setup_coding_system (coding_system, coding)
                tail = flags[i];
 
                coding->flags |= CODING_FLAG_ISO_DESIGNATION;
-               if (INTEGERP (XCAR (tail))
-                   && (charset = XINT (XCAR (tail)),
-                       CHARSET_VALID_P (charset))
+               if ((INTEGERP (XCAR (tail))
+                    && (charset = XINT (XCAR (tail)),
+                        CHARSET_VALID_P (charset)))
                    || (charset = get_charset_id (XCAR (tail))) >= 0)
                  {
                    CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset;
@@ -3608,9 +3608,9 @@ setup_coding_system (coding_system, coding)
                tail = XCDR (tail);
                while (CONSP (tail))
                  {
-                   if (INTEGERP (XCAR (tail))
-                       && (charset = XINT (XCAR (tail)),
-                           CHARSET_VALID_P (charset))
+                   if ((INTEGERP (XCAR (tail))
+                        && (charset = XINT (XCAR (tail)),
+                            CHARSET_VALID_P (charset)))
                        || (charset = get_charset_id (XCAR (tail))) >= 0)
                      CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
                        = i;
@@ -3621,7 +3621,7 @@ setup_coding_system (coding_system, coding)
              }
            else
              CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1;
-           
+
            CODING_SPEC_ISO_DESIGNATION (coding, i)
              = CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i);
          }
@@ -3994,7 +3994,7 @@ detect_coding_mask (source, src_bytes, priorities, skip, multibytep)
                  | CODING_CATEGORY_MASK_UTF_16_LE);
 
          /* Or, if C is a special latin extra code,
-            or is an ISO2022 specific control code of C1 (SS2 or SS3), 
+            or is an ISO2022 specific control code of C1 (SS2 or SS3),
             or is an ISO2022 control-sequence-introducer (CSI),
             we should also consider the possibility of ISO2022 codings.  */
          if ((VECTORP (Vlatin_extra_code_table)
@@ -4037,7 +4037,7 @@ detect_coding_mask (source, src_bytes, priorities, skip, multibytep)
              if (!iso2022_examined_p
                  && (priorities[i] & try & CODING_CATEGORY_MASK_ISO))
                {
-                 mask |= detect_coding_iso2022 (src, src_end);
+                 mask |= detect_coding_iso2022 (src, src_end, multibytep);
                  iso2022_examined_p = 1;
                }
              else if (priorities[i] & try & CODING_CATEGORY_MASK_SJIS)
@@ -4827,7 +4827,6 @@ encode_coding (coding, source, destination, src_bytes, dst_bytes)
       && coding->result == CODING_FINISH_INSUFFICIENT_SRC)
     {
       unsigned char *src = source + coding->consumed;
-      unsigned char *src_end = src + src_bytes;
       unsigned char *dst = destination + coding->produced;
 
       if (coding->type == coding_type_iso2022)
@@ -4838,7 +4837,7 @@ encode_coding (coding, source, destination, src_bytes, dst_bytes)
        {
          int len = src_bytes - coding->consumed;
 
-         BCOPY_SHORT (source + coding->consumed, dst, len);
+         BCOPY_SHORT (src, dst, len);
          if (coding->src_multibyte)
            len = str_as_unibyte (dst, len);
          dst += len;
@@ -5048,7 +5047,7 @@ shrink_encoding_region (beg, end, coding, str)
   if (coding->type == coding_type_ccl
       || coding->eol_type == CODING_EOL_CRLF
       || coding->eol_type == CODING_EOL_CR
-      || coding->cmp_data && coding->cmp_data->used > 0)
+      || (coding->cmp_data && coding->cmp_data->used > 0))
     {
       /* We can't skip any data.  */
       return;
@@ -5102,7 +5101,7 @@ shrink_encoding_region (beg, end, coding, str)
        break;
       if (coding->flags & CODING_FLAG_ISO_DESIGNATE_AT_BOL)
        {
-         unsigned char *bol = begp; 
+         unsigned char *bol = begp;
          while (begp < endp && *begp < 0x80)
            {
              begp++;
@@ -5394,7 +5393,6 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
          new buffer.  */
       struct buffer *prev = current_buffer;
       Lisp_Object new;
-      int count = specpdl_ptr - specpdl;
 
       record_unwind_protect (code_convert_region_unwind, Qnil);
       /* We should not call any more pre-write/post-read-conversion
@@ -5518,7 +5516,11 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
       if (encodep)
        result = encode_coding (coding, src, dst, len_byte, 0);
       else
-       result = decode_coding (coding, src, dst, len_byte, 0);
+       {
+         if (coding->composing != COMPOSITION_DISABLED)
+           coding->cmp_data->char_offset = from + inserted;
+         result = decode_coding (coding, src, dst, len_byte, 0);
+       }
 
       /* The buffer memory is now:
         +--------+-------converted-text----+--+------original-text----+---+
@@ -5601,7 +5603,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
            coding->symbol = XVECTOR (eol_type)->contents[CODING_EOL_LF];
          else
            coding->symbol = saved_coding_symbol;
-         
+
          continue;
        }
       if (len_byte <= 0)
@@ -5619,7 +5621,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
          if (multibyte_p)
            {
              unsigned char *start = dst;
-             
+
              inserted += len_byte;
              while (len_byte--)
                {
@@ -5702,7 +5704,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
       inserted_byte = str_to_multibyte (GPT_ADDR, GAP_SIZE, inserted_byte);
     }
 
-  /* If we shrank the conversion area, adjust it now.  */ 
+  /* If we shrank the conversion area, adjust it now.  */
   if (total_skip > 0)
     {
       if (tail_skip > 0)
@@ -5728,7 +5730,6 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
       && ! encodep && ! NILP (coding->post_read_conversion))
     {
       Lisp_Object val;
-      int count = specpdl_ptr - specpdl;
 
       if (from != PT)
        TEMP_SET_PT_BOTH (from, from_byte);
@@ -5815,7 +5816,6 @@ decode_coding_string (str, coding, nocopy)
   int len;
   struct conversion_buffer buf;
   int from, to_byte;
-  struct gcpro gcpro1;
   Lisp_Object saved_coding_symbol;
   int result;
   int require_decoding;
@@ -5946,7 +5946,7 @@ decode_coding_string (str, coding, nocopy)
                }
              produced += num_eol;
              produced_char += num_eol;
-           } 
+           }
          /* Suppress eol-format conversion in the further conversion.  */
          coding->eol_type = CODING_EOL_LF;
 
@@ -6216,7 +6216,7 @@ detect_coding_system (src, src_bytes, highest, multibytep)
        }
     }
   return (highest ? XCAR (val) : val);
-}  
+}
 
 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region,
        2, 3, 0,
@@ -6412,7 +6412,7 @@ DEFUN ("find-coding-systems-region-internal",
       for (p = p1; p < p1end && ASCII_BYTE_P (*p); p++);
       if (p == p1end)
        {
-         for (p = p2; p < p2end && ASCII_BYTE_P (*p); p++);      
+         for (p = p2; p < p2end && ASCII_BYTE_P (*p); p++);
          if (p == p2end)
            return Qt;
        }
@@ -6610,7 +6610,7 @@ Return the corresponding character.  */)
     }
   else
     {
-      if ((s1 < 0x80 || s1 > 0x9F && s1 < 0xE0 || s1 > 0xEF)
+      if ((s1 < 0x80 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF)
          || (s2 < 0x40 || s2 == 0x7F || s2 > 0xFC))
        error ("Invalid Shift JIS code: %x", XFASTINT (code));
       DECODE_SJIS (s1, s2, c1, c2);
@@ -6730,7 +6730,7 @@ DEFUN ("set-terminal-coding-system-internal",
 DEFUN ("set-safe-terminal-coding-system-internal",
        Fset_safe_terminal_coding_system_internal,
        Sset_safe_terminal_coding_system_internal, 1, 1, 0,
-       doc: /* Internal use only. */)
+       doc: /* Internal use only.  */)
      (coding_system)
      Lisp_Object coding_system;
 {
@@ -6944,7 +6944,7 @@ init_coding_once ()
 {
   int i;
 
-  /* Emacs' internal format specific initialize routine.  */ 
+  /* Emacs' internal format specific initialize routine.  */
   for (i = 0; i <= 0x20; i++)
     emacs_code_class[i] = EMACS_control_code;
   emacs_code_class[0x0A] = EMACS_linefeed_code;
@@ -7111,7 +7111,7 @@ syms_of_coding ()
      But don't staticpro it here--that is done in alloc.c.  */
   Qchar_table_extra_slots = intern ("char-table-extra-slots");
   Fput (Qsafe_chars, Qchar_table_extra_slots, make_number (0));
-  Fput (Qchar_coding_system, Qchar_table_extra_slots, make_number (1));
+  Fput (Qchar_coding_system, Qchar_table_extra_slots, make_number (2));
 
   Qvalid_codes = intern ("valid-codes");
   staticpro (&Qvalid_codes);
@@ -7230,7 +7230,8 @@ the file contents.
 If VAL is a cons of coding systems, the car part is used for decoding,
 and the cdr part is used for encoding.
 If VAL is a function symbol, the function must return a coding system
-or a cons of coding systems which are used as above.
+or a cons of coding systems which are used as above.  The function gets
+the arguments with which `find-operation-coding-systems' was called.
 
 See also the function `find-operation-coding-system'
 and the variable `auto-coding-alist'.  */);
@@ -7268,8 +7269,8 @@ See also the function `find-operation-coding-system'.  */);
   Vnetwork_coding_system_alist = Qnil;
 
   DEFVAR_LISP ("locale-coding-system", &Vlocale_coding_system,
-              doc: /* Coding system to use with system messages.  Also used for decoding
-keyboard input on X Window system.  */);
+              doc: /* Coding system to use with system messages.
+Also used for decoding keyboard input on X Window system.  */);
   Vlocale_coding_system = Qnil;
 
   /* The eol mnemonics are reset in startup.el system-dependently.  */