(Vw32_system_coding_system) [WINDOWSNT]: Remove.
[bpt/emacs.git] / src / coding.h
index d226d43..69b5c69 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) */
@@ -133,7 +133,7 @@ enum iso_code_class_type
    on output.  */
 #define CODING_FLAG_ISO_DESIGNATE_AT_BOL 0x0400
 
-/* If set, do not encode unsafe charactes on output.  */
+/* If set, do not encode unsafe characters on output.  */
 #define CODING_FLAG_ISO_SAFE           0x0800
 
 /* If set, extra latin codes (128..159) are accepted as a valid code
@@ -241,7 +241,7 @@ enum coding_type
     coding_type_ccl,           /* The coding system of which decoder
                                   and encoder are written in CCL.  */
     coding_type_raw_text       /* A coding system for a text
-                                  containing ramdom 8-bit code which
+                                  containing random 8-bit code which
                                   does not require code conversion
                                   except for end-of-line format. */
   };
@@ -274,11 +274,11 @@ enum coding_type
    The encoder stores the information in this structure when it meets
    ESC sequences for composition while encoding codes, then, after all
    text codes are encoded, puts `composition' properties on the text
-   by refering the structure.
+   by referring to the structure.
 
    The decoder at first stores the information of a text to be
    decoded, then, while decoding codes, generates ESC sequences for
-   composition at proper places by refering the structure.  */
+   composition at proper places by referring to the structure.  */
 
 struct composition_data
 {
@@ -296,7 +296,7 @@ struct composition_data
        START and END are starting and ending character positions of
        the composition relative to `char_offset'.
 
-       METHOD is one of `enum cmposing_status' specifying the way of
+       METHOD is one of `enum composing_status' specifying the way of
        composition.
 
        COMPONENT is a character or an encoded composition rule.  */
@@ -307,13 +307,13 @@ struct composition_data
 
   /* Pointers to the previous and next structures.  When `data' is
      filled up, another structure is allocated and linked in `next'.
-     The new struture has backward link to this struture in `prev'.
-     The number of chaind structures depends on how many compositions
+     The new structure has backward link to this structure in `prev'.
+     The number of chained structures depends on how many compositions
      the text being encoded or decoded contains.  */
   struct composition_data *prev, *next;
 };
 
-/* Macros used for the member finish_status of the struct
+/* Macros used for the member `result' of the struct
    coding_system.  */
 #define CODING_FINISH_NORMAL           0
 #define CODING_FINISH_INSUFFICIENT_SRC 1
@@ -330,7 +330,7 @@ struct composition_data
 
 /* If set, the decoding/encoding routines treat the current data as
    the last block of the whole text to be converted, and do
-   appropriate fisishing job.  */
+   appropriate finishing job.  */
 #define CODING_MODE_LAST_BLOCK                 0x02
 
 /* If set, it means that the current source text is in a buffer which
@@ -361,12 +361,6 @@ struct coding_system
      CODING_MODE_XXX.  */
   unsigned int mode;
 
-  /* Table of safe character sets for this coding system.  If the Nth
-     element is 0, the charset of ID N is not a safe character set.
-     Such a character set is not encoded when CODING_ISO_FLAG_SAFE is
-     set.  */
-  unsigned char safe_charsets[MAX_CHARSET + 1];
-
   /* The current status of composition handling.  */
   int composing;
 
@@ -395,6 +389,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 +405,15 @@ 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;
+
+  /* If nonzero, suppress error notification.  */
+  int suppress_error;
 
   /* The following members are all Lisp symbols.  We don't have to
      protect them from GC because the current garbage collection
@@ -444,21 +449,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
@@ -577,6 +586,30 @@ 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 (Vlocale_coding_system)                                         \
+   && XFASTINT (Vlocale_coding_system) != 0                               \
+   ? code_convert_string_norecord (str, Vlocale_coding_system, 1)         \
+   : str)
+
+/* Decode the string STR using the specified coding system
+   for w32 system functions, if any.  */
+#define DECODE_SYSTEM(name)                                               \
+  (! NILP (Vlocale_coding_system)                                         \
+   && XFASTINT (Vlocale_coding_system) != 0                               \
+   ? code_convert_string_norecord (str, Vlocale_coding_system, 0)         \
+   : str)
+
+#else /* WINDOWSNT */
+
+#define ENCODE_SYSTEM(str) string_make_unibyte(str)
+#define DECODE_SYSTEM(name) name
+
+#endif /* !WINDOWSNT */
+
 /* Extern declarations.  */
 extern int decode_coding P_ ((struct coding_system *, unsigned char *,
                              unsigned char *, int, int));
@@ -587,17 +620,28 @@ 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));
 extern int encoding_buffer_size P_ ((struct coding_system *, int));
 extern void detect_coding P_ ((struct coding_system *, unsigned char *, int));
 extern void detect_eol P_ ((struct coding_system *, unsigned char *, int));
-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_string1 P_ ((Lisp_Object, Lisp_Object,
+                                            Lisp_Object, 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 decode_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;
@@ -615,6 +659,7 @@ extern Lisp_Object eol_mnemonic_undecided;
 extern Lisp_Object Qfile_coding_system;
 extern Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
 extern Lisp_Object Qstart_process, Qopen_network_stream;
+extern Lisp_Object Qwrite_region;
 
 extern char *emacs_strerror P_ ((int));
 
@@ -651,7 +696,7 @@ extern struct coding_system default_buffer_file_coding;
 /* Default coding systems used for process I/O.  */
 extern Lisp_Object Vdefault_process_coding_system;
 
-/* Function to call to force a user to force select a propert coding
+/* Function to call to force a user to force select a proper coding
    system.  */
 extern Lisp_Object Vselect_safe_coding_system_function;
 
@@ -661,6 +706,10 @@ 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;
+
 #endif
 
-#endif /* _CODING_H */
+/* Error signaled when there's a problem with detecting coding system */
+extern Lisp_Object Qcoding_system_error;
+
+#endif /* EMACS_CODING_H */