]> code.delx.au - gnu-emacs/blobdiff - src/coding.h
Set maintainer to FSF, since author cannot
[gnu-emacs] / src / coding.h
index 055131942db94ad2ece111025a2295696fd9435d..7dd39ee25dd4311361270e54d157549ac52e033f 100644 (file)
@@ -19,12 +19,10 @@ along with GNU Emacs; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
-#ifndef _CODING_H
-#define _CODING_H
+#ifndef EMACS_CODING_H
+#define EMACS_CODING_H
 
-#ifndef _CCL_H
 #include "ccl.h"
-#endif
 
 /*** EMACS' INTERNAL FORMAT (emacs-mule) section ***/
 
@@ -72,15 +70,17 @@ extern enum emacs_code_class_type emacs_code_class[256];
    followings.  */
 enum iso_code_class_type
   {
-    ISO_control_code,          /* Control codes in the range
-                                  0x00..0x1F, 0x7F, and 0x80..0x9F,
-                                  except for the following seven
-                                  codes.  */
+    ISO_control_0,             /* Control codes in the range
+                                  0x00..0x1F and 0x7F, except for the
+                                  following 5 codes.  */
     ISO_carriage_return,       /* ISO_CODE_CR (0x0D) */
     ISO_shift_out,             /* ISO_CODE_SO (0x0E) */
     ISO_shift_in,              /* ISO_CODE_SI (0x0F) */
     ISO_single_shift_2_7,      /* ISO_CODE_SS2_7 (0x19) */
     ISO_escape,                        /* ISO_CODE_SO (0x1B) */
+    ISO_control_1,             /* Control codes in the range
+                                  0x80..0x9F, except for the
+                                  following 3 codes.  */
     ISO_single_shift_2,                /* ISO_CODE_SS2 (0x8E) */
     ISO_single_shift_3,                /* ISO_CODE_SS3 (0x8F) */
     ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */
@@ -395,6 +395,13 @@ struct coding_system
   /* Index number of coding category of the coding system.  */
   int category_idx;
 
+  /* The following two members specify how characters 128..159 are
+     represented in source and destination text respectively.  1 means
+     they are represented by 2-byte sequence, 0 means they are
+     represented by 1-byte as is (see the comment in charset.h).  */
+  unsigned src_multibyte : 1;
+  unsigned 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,
      when this is equal to the byte length of the text being
@@ -404,11 +411,12 @@ struct coding_system
   /* The following members are set by encoding/decoding routine.  */
   int produced, produced_char, consumed, consumed_char;
 
-  /* Encoding routines set this to 1 when they produce a byte sequence
-     which can be parsed as a multibyte character.  Decoding routines
-     set this to 1 when they encounter an invalid code and, as the
-     result, produce an unexpected multibyte character.  */
-  int fake_multibyte;
+  /* Number of error source data found in a decoding routine.  */
+  int errors;
+
+  /* Finish status of code conversion.  It should be one of macros
+     CODING_FINISH_XXXX.  */
+  int result;
 
   /* The following members are all Lisp symbols.  We don't have to
      protect them from GC because the current garbage collection
@@ -444,21 +452,25 @@ struct coding_system
 /* Return 1 if the coding system CODING requires code conversion on
    decoding.  */
 #define CODING_REQUIRE_DECODING(coding)        \
-  ((coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
+  ((coding)->dst_multibyte             \
+   || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
 
 /* Return 1 if the coding system CODING requires code conversion on
    encoding.  */
 #define CODING_REQUIRE_ENCODING(coding)        \
-  ((coding)->common_flags & CODING_REQUIRE_ENCODING_MASK)
+  ((coding)->src_multibyte             \
+   || (coding)->common_flags & CODING_REQUIRE_ENCODING_MASK)
 
 /* Return 1 if the coding system CODING requires some kind of code
    detection.  */
 #define CODING_REQUIRE_DETECTION(coding) \
   ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK)
 
+/* Return 1 if the coding system CODING requires code conversion on
+   decoding or some kind of code detection.  */
 #define CODING_MAY_REQUIRE_DECODING(coding)    \
-  ((coding)->common_flags                      \
-   & (CODING_REQUIRE_DETECTION_MASK | CODING_REQUIRE_DECODING_MASK))
+  (CODING_REQUIRE_DECODING (coding)            \
+   || CODING_REQUIRE_DETECTION (coding))
 
 /* Index for each coding category in `coding_category_table' */
 #define CODING_CATEGORY_IDX_EMACS_MULE 0
@@ -471,9 +483,12 @@ struct coding_system
 #define CODING_CATEGORY_IDX_ISO_8_ELSE 7
 #define CODING_CATEGORY_IDX_CCL                8
 #define CODING_CATEGORY_IDX_BIG5       9
-#define CODING_CATEGORY_IDX_RAW_TEXT   10
-#define CODING_CATEGORY_IDX_BINARY     11
-#define CODING_CATEGORY_IDX_MAX                12
+#define CODING_CATEGORY_IDX_UTF_8       10
+#define CODING_CATEGORY_IDX_UTF_16_BE   11
+#define CODING_CATEGORY_IDX_UTF_16_LE   12
+#define CODING_CATEGORY_IDX_RAW_TEXT   13
+#define CODING_CATEGORY_IDX_BINARY     14
+#define CODING_CATEGORY_IDX_MAX                15
 
 /* Definitions of flag bits returned by the function
    detect_coding_mask ().  */
@@ -487,6 +502,9 @@ struct coding_system
 #define CODING_CATEGORY_MASK_ISO_8_ELSE        (1 << CODING_CATEGORY_IDX_ISO_8_ELSE)
 #define CODING_CATEGORY_MASK_CCL       (1 << CODING_CATEGORY_IDX_CCL)
 #define CODING_CATEGORY_MASK_BIG5      (1 << CODING_CATEGORY_IDX_BIG5)
+#define CODING_CATEGORY_MASK_UTF_8      (1 << CODING_CATEGORY_IDX_UTF_8)
+#define CODING_CATEGORY_MASK_UTF_16_BE  (1 << CODING_CATEGORY_IDX_UTF_16_BE)
+#define CODING_CATEGORY_MASK_UTF_16_LE  (1 << CODING_CATEGORY_IDX_UTF_16_LE)
 #define CODING_CATEGORY_MASK_RAW_TEXT  (1 << CODING_CATEGORY_IDX_RAW_TEXT)
 #define CODING_CATEGORY_MASK_BINARY    (1 << CODING_CATEGORY_IDX_BINARY)
 
@@ -502,7 +520,10 @@ struct coding_system
    | CODING_CATEGORY_MASK_ISO_7_ELSE   \
    | CODING_CATEGORY_MASK_ISO_8_ELSE   \
    | CODING_CATEGORY_MASK_CCL          \
-   | CODING_CATEGORY_MASK_BIG5)
+   | CODING_CATEGORY_MASK_BIG5         \
+   | CODING_CATEGORY_MASK_UTF_8                \
+   | CODING_CATEGORY_MASK_UTF_16_BE    \
+   | CODING_CATEGORY_MASK_UTF_16_LE)
 
 #define CODING_CATEGORY_MASK_ISO_7BIT \
   (CODING_CATEGORY_MASK_ISO_7 | CODING_CATEGORY_MASK_ISO_7_TIGHT)
@@ -518,6 +539,9 @@ struct coding_system
    | CODING_CATEGORY_MASK_ISO_SHIFT    \
    | CODING_CATEGORY_MASK_ISO_8BIT)
 
+#define CODING_CATEGORY_MASK_UTF_16_BE_LE \
+   (CODING_CATEGORY_MASK_UTF_16_BE | CODING_CATEGORY_MASK_UTF_16_LE)
+
 /* Macros to decode or encode a character of JISX0208 in SJIS.  S1 and
    S2 are the 1st and 2nd position-codes of JISX0208 in SJIS coding
    system.  C1 and C2 are the 1st and 2nd position codes of Emacs'
@@ -565,6 +589,24 @@ struct coding_system
       ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
       : name))
 
+#ifdef WINDOWSNT
+/* Encode the string STR using the specified coding system
+   for w32 system functions, if any.  */
+#define ENCODE_SYSTEM(str)                                                \
+  (! NILP (Vw32_system_coding_system)                                     \
+   && XFASTINT (Vw32_system_coding_system) != 0                                   \
+   ? code_convert_string_norecord (str, Vw32_system_coding_system, 1)     \
+   : str)
+
+/* Decode the string STR using the specified coding system
+   for w32 system functions, if any.  */
+#define DECODE_SYSTEM(name)                                               \
+  (! NILP (Vw32_system_coding_system)                                     \
+   && XFASTINT (Vw32_system_coding_system) != 0                                   \
+   ? code_convert_string_norecord (str, Vw32_system_coding_system, 0)     \
+   : str)
+#endif
+
 /* Extern declarations.  */
 extern int decode_coding P_ ((struct coding_system *, unsigned char *,
                              unsigned char *, int, int));
@@ -575,6 +617,10 @@ extern void coding_save_composition P_ ((struct coding_system *, int, int,
 extern void coding_free_composition_data P_ ((struct coding_system *));
 extern void coding_adjust_composition_offset P_ ((struct coding_system *,
                                                  int));
+extern void coding_allocate_composition_data P_ ((struct coding_system *,
+                                                 int));
+extern void coding_restore_composition P_ ((struct coding_system *,
+                                           Lisp_Object));
 extern int code_convert_region P_ ((int, int, int, int, struct coding_system *,
                                    int, int));
 extern int decoding_buffer_size P_ ((struct coding_system *, int));
@@ -585,7 +631,13 @@ extern int conversion_buffer_size;
 extern char *conversion_buffer;
 extern char *get_conversion_buffer P_ ((int));
 extern int setup_coding_system P_ ((Lisp_Object, struct coding_system *));
+extern Lisp_Object code_convert_string P_ ((Lisp_Object,
+                                           struct coding_system *, int, int));
+extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object,
+                                                    int));
 extern void setup_raw_text_coding_system P_ ((struct coding_system *));
+extern Lisp_Object encode_coding_string P_ ((Lisp_Object,
+                                            struct coding_system *, int));
 extern Lisp_Object Qcoding_system, Qeol_type, Qcoding_category_index;
 extern Lisp_Object Qraw_text, Qemacs_mule;
 extern Lisp_Object Qbuffer_file_coding_system;
@@ -649,6 +701,11 @@ extern Lisp_Object Vfile_name_coding_system;
 /* Coding system for file names used only when
    Vfile_name_coding_system is nil.  */
 extern Lisp_Object Vdefault_file_name_coding_system;
+
+#ifdef WINDOWSNT
+/* Coding system for w32 system strings, or nil if none.  */
+extern Lisp_Object Vw32_system_coding_system;
+#endif
 #endif
 
-#endif /* _CODING_H */
+#endif /* EMACS_CODING_H */