]> code.delx.au - gnu-emacs/blobdiff - src/coding.c
* nt/config.nt: Complete rework to bring it in sync with autogen/config.in.
[gnu-emacs] / src / coding.c
index be7166e8a14869417e1133c0c7e23a15c3140420..4b2a9740121ba0f5c035f43ee80a3c628acb305d 100644 (file)
@@ -288,8 +288,8 @@ encode_coding_XXX (struct coding_system *coding)
 #include <setjmp.h>
 
 #include "lisp.h"
-#include "buffer.h"
 #include "character.h"
+#include "buffer.h"
 #include "charset.h"
 #include "ccl.h"
 #include "composite.h"
@@ -847,15 +847,17 @@ static int encode_coding_ccl (struct coding_system *);
 static void decode_coding_raw_text (struct coding_system *);
 static int encode_coding_raw_text (struct coding_system *);
 
-static ptrdiff_t coding_set_source (struct coding_system *);
-static ptrdiff_t coding_set_destination (struct coding_system *);
+static void coding_set_source (struct coding_system *);
+static ptrdiff_t coding_change_source (struct coding_system *);
+static void coding_set_destination (struct coding_system *);
+static ptrdiff_t coding_change_destination (struct coding_system *);
 static void coding_alloc_by_realloc (struct coding_system *, ptrdiff_t);
 static void coding_alloc_by_making_gap (struct coding_system *,
                                         ptrdiff_t, ptrdiff_t);
 static unsigned char *alloc_destination (struct coding_system *,
                                          ptrdiff_t, unsigned char *);
 static void setup_iso_safe_charsets (Lisp_Object);
-static int encode_designation_at_bol (struct coding_system *,
+static ptrdiff_t encode_designation_at_bol (struct coding_system *,
                                      int *, int *, unsigned char *);
 static int detect_eol (const unsigned char *,
                        ptrdiff_t, enum coding_category);
@@ -927,7 +929,7 @@ record_conversion_result (struct coding_system *coding,
     charset_map_loaded = 0;                                                 \
     c = DECODE_CHAR (charset, code);                                        \
     if (charset_map_loaded                                                  \
-       && (offset = coding_set_source (coding)))                            \
+       && (offset = coding_change_source (coding)))                         \
       {                                                                             \
        src += offset;                                                       \
        src_base += offset;                                                  \
@@ -942,7 +944,7 @@ record_conversion_result (struct coding_system *coding,
     charset_map_loaded = 0;                                            \
     code = ENCODE_CHAR (charset, c);                                   \
     if (charset_map_loaded                                             \
-       && (offset = coding_set_destination (coding)))                  \
+       && (offset = coding_change_destination (coding)))               \
       {                                                                        \
        dst += offset;                                                  \
        dst_end += offset;                                              \
@@ -956,7 +958,7 @@ record_conversion_result (struct coding_system *coding,
     charset_map_loaded = 0;                                            \
     charset = char_charset (c, charset_list, code_return);             \
     if (charset_map_loaded                                             \
-       && (offset = coding_set_destination (coding)))                  \
+       && (offset = coding_change_destination (coding)))               \
       {                                                                        \
        dst += offset;                                                  \
        dst_end += offset;                                              \
@@ -970,7 +972,7 @@ record_conversion_result (struct coding_system *coding,
     charset_map_loaded = 0;                                            \
     result = CHAR_CHARSET_P (c, charset);                              \
     if (charset_map_loaded                                             \
-       && (offset = coding_set_destination (coding)))                  \
+       && (offset = coding_change_destination (coding)))               \
       {                                                                        \
        dst += offset;                                                  \
        dst_end += offset;                                              \
@@ -1056,14 +1058,11 @@ record_conversion_result (struct coding_system *coding,
        | ((p)[-1] & 0x3F))))
 
 
-/* Update coding->source from coding->src_object, and return how many
-   bytes coding->source was changed.  */
+/* Set coding->source from coding->src_object.  */
 
-static ptrdiff_t
+static void
 coding_set_source (struct coding_system *coding)
 {
-  const unsigned char *orig = coding->source;
-
   if (BUFFERP (coding->src_object))
     {
       struct buffer *buf = XBUFFER (coding->src_object);
@@ -1082,18 +1081,26 @@ coding_set_source (struct coding_system *coding)
       /* Otherwise, the source is C string and is never relocated
         automatically.  Thus we don't have to update anything.  */
     }
-  return coding->source - orig;
 }
 
 
-/* Update coding->destination from coding->dst_object, and return how
-   many bytes coding->destination was changed.  */
+/* Set coding->source from coding->src_object, and return how many
+   bytes coding->source was changed.  */
 
 static ptrdiff_t
-coding_set_destination (struct coding_system *coding)
+coding_change_source (struct coding_system *coding)
 {
-  const unsigned char *orig = coding->destination;
+  const unsigned char *orig = coding->source;
+  coding_set_source (coding);
+  return coding->source - orig;
+}
 
+
+/* Set coding->destination from coding->dst_object.  */
+
+static void
+coding_set_destination (struct coding_system *coding)
+{
   if (BUFFERP (coding->dst_object))
     {
       if (BUFFERP (coding->src_object) && coding->src_pos < 0)
@@ -1118,6 +1125,17 @@ coding_set_destination (struct coding_system *coding)
       /* Otherwise, the destination is C string and is never relocated
         automatically.  Thus we don't have to update anything.  */
     }
+}
+
+
+/* Set coding->destination from coding->dst_object, and return how
+   many bytes coding->destination was changed.  */
+
+static ptrdiff_t
+coding_change_destination (struct coding_system *coding)
+{
+  const unsigned char *orig = coding->destination;
+  coding_set_destination (coding);
   return coding->destination - orig;
 }
 
@@ -1127,8 +1145,8 @@ coding_alloc_by_realloc (struct coding_system *coding, ptrdiff_t bytes)
 {
   if (STRING_BYTES_BOUND - coding->dst_bytes < bytes)
     string_overflow ();
-  coding->destination = (unsigned char *) xrealloc (coding->destination,
-                                                   coding->dst_bytes + bytes);
+  coding->destination = xrealloc (coding->destination,
+                                 coding->dst_bytes + bytes);
   coding->dst_bytes += bytes;
 }
 
@@ -3171,7 +3189,7 @@ detect_coding_iso_2022 (struct coding_system *coding,
            break;
        check_extra_latin:
          if (! VECTORP (Vlatin_extra_code_table)
-             || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
+             || NILP (AREF (Vlatin_extra_code_table, c)))
            {
              rejected = CATEGORY_MASK_ISO;
              break;
@@ -4351,7 +4369,7 @@ 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 ptrdiff_t
 encode_designation_at_bol (struct coding_system *coding,
                           int *charbuf, int *charbuf_end,
                           unsigned char *dst)
@@ -4452,7 +4470,7 @@ encode_coding_iso_2022 (struct coding_system *coding)
          nbytes = encode_designation_at_bol (coding, charbuf, charbuf_end,
                                              desig_buf);
          if (charset_map_loaded
-             && (offset = coding_set_destination (coding)))
+             && (offset = coding_change_destination (coding)))
            {
              dst += offset;
              dst_end += offset;
@@ -5446,7 +5464,7 @@ detect_coding_charset (struct coding_system *coding,
          if (c < 0xA0
              && check_latin_extra
              && (!VECTORP (Vlatin_extra_code_table)
-                 || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])))
+                 || NILP (AREF (Vlatin_extra_code_table, c))))
            break;
          found = CATEGORY_MASK_CHARSET;
        }
@@ -6747,7 +6765,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
 
       while (buf < buf_end)
        {
-         int c = *buf, i;
+         int c = *buf;
+         ptrdiff_t i;
 
          if (c >= 0)
            {
@@ -6849,7 +6868,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;
                        }
@@ -6883,7 +6902,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;
                      }
@@ -6904,7 +6923,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;
@@ -6991,7 +7010,7 @@ produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
     coding->charbuf = NULL;                                            \
     while (size > 1024)                                                        \
       {                                                                        \
-       coding->charbuf = (int *) alloca (sizeof (int) * size);         \
+       coding->charbuf = alloca (sizeof (int) * size);                 \
        if (coding->charbuf)                                            \
          break;                                                        \
        size >>= 1;                                                     \
@@ -7987,7 +8006,7 @@ encode_coding_object (struct coding_system *coding,
     {
       ptrdiff_t dst_bytes = max (1, coding->src_chars);
       coding->dst_object = Qnil;
-      coding->destination = (unsigned char *) xmalloc (dst_bytes);
+      coding->destination = xmalloc (dst_bytes);
       coding->dst_bytes = dst_bytes;
       coding->dst_multibyte = 0;
     }
@@ -9549,7 +9568,7 @@ make_subsidiaries (Lisp_Object base)
 {
   Lisp_Object subsidiaries;
   ptrdiff_t base_name_len = SBYTES (SYMBOL_NAME (base));
-  char *buf = (char *) alloca (base_name_len + 6);
+  char *buf = alloca (base_name_len + 6);
   int i;
 
   memcpy (buf, SDATA (SYMBOL_NAME (base)), base_name_len);
@@ -10541,7 +10560,7 @@ Don't modify this variable directly, but use `set-coding-system-priority'.  */);
     Vcoding_category_list = Qnil;
     for (i = coding_category_max - 1; i >= 0; i--)
       Vcoding_category_list
-       = Fcons (XVECTOR (Vcoding_category_table)->contents[i],
+       = Fcons (AREF (Vcoding_category_table, i),
                 Vcoding_category_list);
   }