* src/profiler.c: Delete.
[bpt/emacs.git] / src / coding.h
index d40209b..f3efcca 100644 (file)
@@ -1,5 +1,5 @@
 /* Header for coding system handler.
-   Copyright (C) 2001-2013 Free Software Foundation, Inc.
+   Copyright (C) 2001-2014 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)
@@ -76,6 +76,14 @@ enum define_coding_ccl_arg_index
     coding_arg_ccl_max
   };
 
+enum define_coding_undecided_arg_index
+  {
+    coding_arg_undecided_inhibit_null_byte_detection = coding_arg_max,
+    coding_arg_undecided_inhibit_iso_escape_detection,
+    coding_arg_undecided_prefer_utf_8,
+    coding_arg_undecided_max
+  };
+
 /* Hash table for all coding systems.  Keys are coding system symbols
    and values are spec vectors of the corresponding coding system.  A
    spec vector has the form [ ATTRS ALIASES EOL-TYPE ].  ATTRS is a
@@ -158,6 +166,10 @@ enum coding_attr_index
 
     coding_attr_emacs_mule_full,
 
+    coding_attr_undecided_inhibit_null_byte_detection,
+    coding_attr_undecided_inhibit_iso_escape_detection,
+    coding_attr_undecided_prefer_utf_8,
+
     coding_attr_last_index
   };
 
@@ -214,7 +226,7 @@ enum coding_attr_index
   hash_lookup (XHASH_TABLE (Vcoding_system_hash_table),                \
               coding_system_symbol, NULL)
 
-/* Return 1 if CODING_SYSTEM_SYMBOL is a coding system.  */
+/* Return true if CODING_SYSTEM_SYMBOL is a coding system.  */
 
 #define CODING_SYSTEM_P(coding_system_symbol)          \
   (CODING_SYSTEM_ID (coding_system_symbol) >= 0                \
@@ -228,7 +240,7 @@ enum coding_attr_index
     if (CODING_SYSTEM_ID (x) < 0                       \
        && NILP (Fcheck_coding_system (x)))             \
       wrong_type_argument (Qcoding_system_p, (x));     \
-  } while (0)
+  } while (false)
 
 
 /* Check if X is a coding system or not.  If it is, set SEPC to the
@@ -244,7 +256,7 @@ enum coding_attr_index
       }                                                        \
     if (NILP (spec))                                   \
       wrong_type_argument (Qcoding_system_p, (x));     \
-  } while (0)
+  } while (false)
 
 
 /* Check if X is a coding system or not.  If it is, set ID to the
@@ -261,7 +273,7 @@ enum coding_attr_index
        }                                                       \
       if (id < 0)                                              \
        wrong_type_argument (Qcoding_system_p, (x));    \
-    } while (0)
+    } while (false)
 
 
 /*** GENERAL section ***/
@@ -349,13 +361,13 @@ struct iso_2022_spec
 
   /* True temporarily only when graphic register 2 or 3 is invoked by
      single-shift while encoding.  */
-  unsigned single_shifting : 1;
+  bool_bf single_shifting : 1;
 
   /* True temporarily only when processing at beginning of line.  */
-  unsigned bol : 1;
+  bool_bf bol : 1;
 
   /* If true, we are now scanning embedded UTF-8 sequence.  */
-  unsigned embedded_utf_8 : 1;
+  bool_bf embedded_utf_8 : 1;
 
   /* The current composition.  */
   struct composition_status cmp_status;
@@ -366,7 +378,18 @@ struct emacs_mule_spec
   struct composition_status cmp_status;
 };
 
-struct ccl_spec;
+struct undecided_spec
+{
+  /* Inhibit null byte detection.  1 means always inhibit,
+     -1 means do not inhibit, 0 means rely on user variable.  */
+  int inhibit_nbd;
+
+  /* Inhibit ISO escape detection.  -1, 0, 1 as above.  */
+  int inhibit_ied;
+
+  /* Prefer UTF-8 when the input could be other encodings.  */
+  bool prefer_utf_8;
+};
 
 enum utf_bom_type
   {
@@ -425,17 +448,18 @@ struct coding_system
       struct utf_16_spec utf_16;
       enum utf_bom_type utf_8_bom;
       struct emacs_mule_spec emacs_mule;
+      struct undecided_spec undecided;
     } spec;
 
   int max_charset_id;
   unsigned char *safe_charsets;
 
   /* The following two members specify how binary 8-bit code 128..255
-     are represented in source and destination text respectively.  1
-     means they are represented by 2-byte sequence, 0 means they are
+     are represented in source and destination text respectively.  True
+     means they are represented by 2-byte sequence, false means they are
      represented by 1-byte as is (see the comment in character.h).  */
-  unsigned src_multibyte : 1;
-  unsigned dst_multibyte : 1;
+  bool_bf src_multibyte : 1;
+  bool_bf dst_multibyte : 1;
 
   /* How may heading bytes we can skip for decoding.  This is set to
      -1 in setup_coding_system, and updated by detect_coding.  So,
@@ -444,6 +468,10 @@ struct coding_system
      the eol format.  */
   ptrdiff_t head_ascii;
 
+  /* How many bytes/chars at the source are detected as valid utf-8
+     sequence.  Set by detect_coding_utf_8.  */
+  ptrdiff_t detected_utf8_bytes, detected_utf8_chars;
+
   /* Used internally in coding.c.  See the comment of detect_ascii.  */
   int eol_seen;
 
@@ -451,7 +479,7 @@ struct coding_system
   ptrdiff_t produced, produced_char, consumed, consumed_char;
 
   /* Number of error source data found in a decoding routine.  */
-  int errors;
+  ptrdiff_t errors;
 
   /* Store the positions of error source data.  */
   ptrdiff_t *error_positions;
@@ -484,10 +512,14 @@ struct coding_system
 
   /* True if the source of conversion is not in the member
      `charbuf', but at `src_object'.  */
-  unsigned chars_at_source : 1;
+  bool_bf chars_at_source : 1;
 
-  /* Set to 1 if charbuf contains an annotation.  */
-  unsigned annotated : 1;
+  /* Nonzero if the result of conversion is in `destination'
+     buffer rather than in `dst_object'.  */
+  bool_bf raw_destination : 1;
+
+  /* Set to true if charbuf contains an annotation.  */
+  bool_bf annotated : 1;
 
   unsigned char carryover[64];
   int carryover_bytes;
@@ -513,28 +545,29 @@ struct coding_system
 #define CODING_REQUIRE_DETECTION_MASK          0x1000
 #define CODING_RESET_AT_BOL_MASK               0x2000
 
-/* Return 1 if the coding context CODING requires annotation
+/* Return nonzero if the coding context CODING requires annotation
    handling.  */
 #define CODING_REQUIRE_ANNOTATION(coding) \
   ((coding)->common_flags & CODING_ANNOTATION_MASK)
 
-/* Return 1 if the coding context CODING prefers decoding into unibyte.  */
+/* Return nonzero if the coding context CODING prefers decoding into
+   unibyte.  */
 #define CODING_FOR_UNIBYTE(coding) \
   ((coding)->common_flags & CODING_FOR_UNIBYTE_MASK)
 
-/* Return 1 if the coding context CODING requires specific code to be
+/* Return nonzero if the coding context CODING requires specific code to be
    attached at the tail of converted text.  */
 #define CODING_REQUIRE_FLUSHING(coding) \
   ((coding)->common_flags & CODING_REQUIRE_FLUSHING_MASK)
 
-/* Return 1 if the coding context CODING requires code conversion on
+/* Return nonzero if the coding context CODING requires code conversion on
    decoding.  */
 #define CODING_REQUIRE_DECODING(coding)        \
   ((coding)->dst_multibyte             \
    || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
 
 
-/* Return 1 if the coding context CODING requires code conversion on
+/* Return nonzero if the coding context CODING requires code conversion on
    encoding.
    The non-multibyte part of the condition is to support encoding of
    unibyte strings/buffers generated by string-as-unibyte or
@@ -545,12 +578,12 @@ struct coding_system
    || (coding)->mode & CODING_MODE_SELECTIVE_DISPLAY)
 
 
-/* Return 1 if the coding context CODING requires some kind of code
+/* Return nonzero if the coding context CODING requires some kind of code
    detection.  */
 #define CODING_REQUIRE_DETECTION(coding) \
   ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK)
 
-/* Return 1 if the coding context CODING requires code conversion on
+/* Return nonzero if the coding context CODING requires code conversion on
    decoding or some kind of code detection.  */
 #define CODING_MAY_REQUIRE_DECODING(coding)    \
   (CODING_REQUIRE_DECODING (coding)            \
@@ -574,7 +607,7 @@ struct coding_system
       (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1),    \
        j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F));                \
     (code) = (j1 << 8) | j2;                           \
-  } while (0)
+  } while (false)
 
 #define SJIS_TO_JIS2(code)                             \
   do {                                                 \
@@ -599,7 +632,7 @@ struct coding_system
        j2 = s2 - ((s2 >= 0x7F ? 0x20 : 0x1F));         \
       }                                                        \
     (code) = (j1 << 8) | j2;                           \
-  } while (0)
+  } while (false)
 
 
 #define JIS_TO_SJIS(code)                              \
@@ -614,7 +647,7 @@ struct coding_system
       (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0),      \
        s2 = j2 + 0x7E);                                        \
     (code) = (s1 << 8) | s2;                           \
-  } while (0)
+  } while (false)
 
 #define JIS_TO_SJIS2(code)                             \
   do {                                                 \
@@ -638,44 +671,32 @@ struct coding_system
        s2 = j2 + 0x7E;                                 \
       }                                                        \
     (code) = (s1 << 8) | s2;                           \
-  } while (0)
+  } while (false)
 
 /* Encode the file name NAME using the specified coding system
    for file names, if any.  */
-#define ENCODE_FILE(name)                                                 \
-  (! NILP (Vfile_name_coding_system)                                      \
-   ? code_convert_string_norecord (name, Vfile_name_coding_system, 1)     \
-   : (! NILP (Vdefault_file_name_coding_system)                                   \
-      ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \
-      : name))
-
+#define ENCODE_FILE(NAME)  encode_file_name (NAME)
 
 /* Decode the file name NAME using the specified coding system
    for file names, if any.  */
-#define DECODE_FILE(name)                                                 \
-  (! NILP (Vfile_name_coding_system)                                      \
-   ? code_convert_string_norecord (name, Vfile_name_coding_system, 0)     \
-   : (! NILP (Vdefault_file_name_coding_system)                                   \
-      ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
-      : name))
-
+#define DECODE_FILE(NAME)  decode_file_name (NAME)
 
 /* Encode the string STR using the specified coding system
    for system functions, if any.  */
 #define ENCODE_SYSTEM(str)                                                \
   (! NILP (Vlocale_coding_system)                                         \
-   ? code_convert_string_norecord (str, Vlocale_coding_system, 1)         \
+   ? code_convert_string_norecord (str, Vlocale_coding_system, true)      \
    : str)
 
 /* Decode the string STR using the specified coding system
    for system functions, if any.  */
 #define DECODE_SYSTEM(str)                                                \
   (! NILP (Vlocale_coding_system)                                         \
-   ? code_convert_string_norecord (str, Vlocale_coding_system, 0)         \
+   ? code_convert_string_norecord (str, Vlocale_coding_system, false)     \
    : str)
 
 /* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op.  */
-#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1)
+#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, true)
 
 /* Extern declarations.  */
 extern Lisp_Object code_conversion_save (bool, bool);
@@ -686,6 +707,8 @@ extern Lisp_Object code_convert_string (Lisp_Object, Lisp_Object,
                                         Lisp_Object, bool, bool, bool);
 extern Lisp_Object code_convert_string_norecord (Lisp_Object, Lisp_Object,
                                                  bool);
+extern Lisp_Object encode_file_name (Lisp_Object);
+extern Lisp_Object decode_file_name (Lisp_Object);
 extern Lisp_Object raw_text_coding_system (Lisp_Object);
 extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
 extern Lisp_Object complement_process_encoding_system (Lisp_Object);
@@ -720,7 +743,7 @@ extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
 extern Lisp_Object from_unicode (Lisp_Object str);
 
 /* Convert WSTR to an Emacs string.  */
-extern Lisp_Object from_unicode_buffer (const wchar_twstr);
+extern Lisp_Object from_unicode_buffer (const wchar_t *wstr);
 
 #endif /* WINDOWSNT || CYGWIN */
 
@@ -739,7 +762,7 @@ extern Lisp_Object from_unicode_buffer (const wchar_t* wstr);
     (coding)->src_chars = (coding)->src_bytes = (bytes);               \
     decode_coding_object ((coding), Qnil, 0, 0, (bytes), (bytes),      \
                          (dst_object));                                \
-  } while (0)
+  } while (false)
 
 
 extern Lisp_Object preferred_coding_system (void);