aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.h
diff options
context:
space:
mode:
authorMiles Bader2008-02-01 16:01:31 +0000
committerMiles Bader2008-02-01 16:01:31 +0000
commit6cc41fb06c37234822d5aedf7ce0f77b88bb450a (patch)
treea130326faf29d4410ed126e4f0d6a13f11a19df3 /src/coding.h
parentb502217bd845bc6280fd2bb1eacce176ed4f7d90 (diff)
parentdd559368b0db67654f643320b1d84afdabe60e97 (diff)
downloademacs-6cc41fb06c37234822d5aedf7ce0f77b88bb450a.tar.gz
emacs-6cc41fb06c37234822d5aedf7ce0f77b88bb450a.zip
Merge unicode branch
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1037
Diffstat (limited to 'src/coding.h')
-rw-r--r--src/coding.h986
1 files changed, 516 insertions, 470 deletions
diff --git a/src/coding.h b/src/coding.h
index a08bbb8d966..34196082afb 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -5,6 +5,9 @@
5 2005, 2006, 2007, 2008 5 2005, 2006, 2007, 2008
6 National Institute of Advanced Industrial Science and Technology (AIST) 6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021 7 Registration Number H14PRO021
8 Copyright (C) 2003
9 National Institute of Advanced Industrial Science and Technology (AIST)
10 Registration Number H13PRO009
8 11
9This file is part of GNU Emacs. 12This file is part of GNU Emacs.
10 13
@@ -26,306 +29,253 @@ Boston, MA 02110-1301, USA. */
26#ifndef EMACS_CODING_H 29#ifndef EMACS_CODING_H
27#define EMACS_CODING_H 30#define EMACS_CODING_H
28 31
29#include "ccl.h" 32/* Index to arguments of Fdefine_coding_system_internal. */
30 33
31/*** EMACS' INTERNAL FORMAT (emacs-mule) section ***/ 34enum define_coding_system_arg_index
35 {
36 coding_arg_name,
37 coding_arg_mnemonic,
38 coding_arg_coding_type,
39 coding_arg_charset_list,
40 coding_arg_ascii_compatible_p,
41 coding_arg_decode_translation_table,
42 coding_arg_encode_translation_table,
43 coding_arg_post_read_conversion,
44 coding_arg_pre_write_conversion,
45 coding_arg_default_char,
46 coding_arg_for_unibyte,
47 coding_arg_plist,
48 coding_arg_eol_type,
49 coding_arg_max
50 };
32 51
33/* All code (1-byte) of Emacs' internal format is classified into one 52enum define_coding_iso2022_arg_index
34 of the followings. See also `charset.h'. */
35enum emacs_code_class_type
36 { 53 {
37 EMACS_control_code, /* Control codes in the range 54 coding_arg_iso2022_initial = coding_arg_max,
38 0x00..0x1F and 0x7F except for the 55 coding_arg_iso2022_reg_usage,
39 following two codes. */ 56 coding_arg_iso2022_request,
40 EMACS_linefeed_code, /* 0x0A (linefeed) to denote 57 coding_arg_iso2022_flags,
41 end-of-line. */ 58 coding_arg_iso2022_max
42 EMACS_carriage_return_code, /* 0x0D (carriage-return) to be used
43 in selective display mode. */
44 EMACS_ascii_code, /* ASCII characters. */
45 EMACS_leading_code_2, /* Base leading code of official
46 TYPE9N character. */
47 EMACS_leading_code_3, /* Base leading code of private TYPE9N
48 or official TYPE9Nx9N character. */
49 EMACS_leading_code_4, /* Base leading code of private
50 TYPE9Nx9N character. */
51 EMACS_invalid_code /* Invalid code, i.e. a base leading
52 code not yet assigned to any
53 charset, or a code of the range
54 0xA0..0xFF. */
55 }; 59 };
56 60
57extern enum emacs_code_class_type emacs_code_class[256]; 61enum define_coding_utf16_arg_index
58
59/*** ISO2022 section ***/
60
61/* Macros to define code of control characters for ISO2022's functions. */
62 /* code */ /* function */
63#define ISO_CODE_LF 0x0A /* line-feed */
64#define ISO_CODE_CR 0x0D /* carriage-return */
65#define ISO_CODE_SO 0x0E /* shift-out */
66#define ISO_CODE_SI 0x0F /* shift-in */
67#define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */
68#define ISO_CODE_ESC 0x1B /* escape */
69#define ISO_CODE_SS2 0x8E /* single-shift-2 */
70#define ISO_CODE_SS3 0x8F /* single-shift-3 */
71#define ISO_CODE_CSI 0x9B /* control-sequence-introduce */
72
73/* All code (1-byte) of ISO2022 is classified into one of the
74 followings. */
75enum iso_code_class_type
76 { 62 {
77 ISO_control_0, /* Control codes in the range 63 coding_arg_utf16_bom = coding_arg_max,
78 0x00..0x1F and 0x7F, except for the 64 coding_arg_utf16_endian,
79 following 5 codes. */ 65 coding_arg_utf16_max
80 ISO_carriage_return, /* ISO_CODE_CR (0x0D) */
81 ISO_shift_out, /* ISO_CODE_SO (0x0E) */
82 ISO_shift_in, /* ISO_CODE_SI (0x0F) */
83 ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */
84 ISO_escape, /* ISO_CODE_SO (0x1B) */
85 ISO_control_1, /* Control codes in the range
86 0x80..0x9F, except for the
87 following 3 codes. */
88 ISO_single_shift_2, /* ISO_CODE_SS2 (0x8E) */
89 ISO_single_shift_3, /* ISO_CODE_SS3 (0x8F) */
90 ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */
91 ISO_0x20_or_0x7F, /* Codes of the values 0x20 or 0x7F. */
92 ISO_graphic_plane_0, /* Graphic codes in the range 0x21..0x7E. */
93 ISO_0xA0_or_0xFF, /* Codes of the values 0xA0 or 0xFF. */
94 ISO_graphic_plane_1 /* Graphic codes in the range 0xA1..0xFE. */
95 }; 66 };
96 67
97/** The macros CODING_FLAG_ISO_XXX defines a flag bit of the `flags' 68enum define_coding_ccl_arg_index
98 element in the structure `coding_system'. This information is used 69 {
99 while encoding a text to ISO2022. **/ 70 coding_arg_ccl_decoder = coding_arg_max,
71 coding_arg_ccl_encoder,
72 coding_arg_ccl_valids,
73 coding_arg_ccl_max
74 };
100 75
101/* If set, produce short-form designation sequence (e.g. ESC $ A) 76/* Hash table for all coding systems. Keys are coding system symbols
102 instead of long-form sequence (e.g. ESC $ ( A). */ 77 and values are spec vectors of the corresponding coding system. A
103#define CODING_FLAG_ISO_SHORT_FORM 0x0001 78 spec vector has the form [ ATTRS ALIASES EOL-TYPE ]. ATTRS is a
79 vector of attribute of the coding system. ALIASES is a list of
80 aliases (symbols) of the coding system. EOL-TYPE is `unix', `dos',
81 `mac' or a vector of coding systems (symbols). */
104 82
105/* If set, reset graphic planes and registers at end-of-line to the 83extern Lisp_Object Vcoding_system_hash_table;
106 initial state. */
107#define CODING_FLAG_ISO_RESET_AT_EOL 0x0002
108 84
109/* If set, reset graphic planes and registers before any control
110 characters to the initial state. */
111#define CODING_FLAG_ISO_RESET_AT_CNTL 0x0004
112 85
113/* If set, encode by 7-bit environment. */ 86/* Enumeration of coding system type. */
114#define CODING_FLAG_ISO_SEVEN_BITS 0x0008
115 87
116/* If set, use locking-shift function. */ 88enum coding_system_type
117#define CODING_FLAG_ISO_LOCKING_SHIFT 0x0010 89 {
90 coding_type_charset,
91 coding_type_utf_8,
92 coding_type_utf_16,
93 coding_type_iso_2022,
94 coding_type_emacs_mule,
95 coding_type_sjis,
96 coding_type_ccl,
97 coding_type_raw_text,
98 coding_type_undecided,
99 coding_type_max
100 };
118 101
119/* If set, use single-shift function. Overwrite
120 CODING_FLAG_ISO_LOCKING_SHIFT. */
121#define CODING_FLAG_ISO_SINGLE_SHIFT 0x0020
122 102
123/* If set, designate JISX0201-Roman instead of ASCII. */ 103/* Enumeration of end-of-line format type. */
124#define CODING_FLAG_ISO_USE_ROMAN 0x0040
125 104
126/* If set, designate JISX0208-1978 instead of JISX0208-1983. */ 105enum end_of_line_type
127#define CODING_FLAG_ISO_USE_OLDJIS 0x0080 106 {
107 eol_lf, /* Line-feed only, same as Emacs' internal
108 format. */
109 eol_crlf, /* Sequence of carriage-return and
110 line-feed. */
111 eol_cr, /* Carriage-return only. */
112 eol_any, /* Accept any of above. Produce line-feed
113 only. */
114 eol_undecided, /* This value is used to denote that the
115 eol-type is not yet undecided. */
116 eol_type_max
117 };
128 118
129/* If set, do not produce ISO6429's direction specifying sequence. */ 119/* Enumeration of index to an attribute vector of a coding system. */
130#define CODING_FLAG_ISO_NO_DIRECTION 0x0100
131 120
132/* If set, assume designation states are reset at beginning of line on 121enum coding_attr_index
133 output. */ 122 {
134#define CODING_FLAG_ISO_INIT_AT_BOL 0x0200 123 coding_attr_base_name,
124 coding_attr_docstring,
125 coding_attr_mnemonic,
126 coding_attr_type,
127 coding_attr_charset_list,
128 coding_attr_ascii_compat,
129 coding_attr_decode_tbl,
130 coding_attr_encode_tbl,
131 coding_attr_trans_tbl,
132 coding_attr_post_read,
133 coding_attr_pre_write,
134 coding_attr_default_char,
135 coding_attr_for_unibyte,
136 coding_attr_plist,
137
138 coding_attr_category,
139 coding_attr_safe_charsets,
140
141 /* The followings are extra attributes for each type. */
142 coding_attr_charset_valids,
143
144 coding_attr_ccl_decoder,
145 coding_attr_ccl_encoder,
146 coding_attr_ccl_valids,
147
148 coding_attr_iso_initial,
149 coding_attr_iso_usage,
150 coding_attr_iso_request,
151 coding_attr_iso_flags,
152
153 coding_attr_utf_16_bom,
154 coding_attr_utf_16_endian,
155
156 coding_attr_emacs_mule_full,
157
158 coding_attr_last_index
159 };
135 160
136/* If set, designation sequence should be placed at beginning of line
137 on output. */
138#define CODING_FLAG_ISO_DESIGNATE_AT_BOL 0x0400
139 161
140/* If set, do not encode unsafe characters on output. */ 162/* Macros to access an element of an attribute vector. */
141#define CODING_FLAG_ISO_SAFE 0x0800
142 163
143/* If set, extra latin codes (128..159) are accepted as a valid code 164#define CODING_ATTR_BASE_NAME(attrs) AREF (attrs, coding_attr_base_name)
144 on input. */ 165#define CODING_ATTR_TYPE(attrs) AREF (attrs, coding_attr_type)
145#define CODING_FLAG_ISO_LATIN_EXTRA 0x1000 166#define CODING_ATTR_CHARSET_LIST(attrs) AREF (attrs, coding_attr_charset_list)
167#define CODING_ATTR_MNEMONIC(attrs) AREF (attrs, coding_attr_mnemonic)
168#define CODING_ATTR_DOCSTRING(attrs) AREF (attrs, coding_attr_docstring)
169#define CODING_ATTR_ASCII_COMPAT(attrs) AREF (attrs, coding_attr_ascii_compat)
170#define CODING_ATTR_DECODE_TBL(attrs) AREF (attrs, coding_attr_decode_tbl)
171#define CODING_ATTR_ENCODE_TBL(attrs) AREF (attrs, coding_attr_encode_tbl)
172#define CODING_ATTR_TRANS_TBL(attrs) AREF (attrs, coding_attr_trans_tbl)
173#define CODING_ATTR_POST_READ(attrs) AREF (attrs, coding_attr_post_read)
174#define CODING_ATTR_PRE_WRITE(attrs) AREF (attrs, coding_attr_pre_write)
175#define CODING_ATTR_DEFAULT_CHAR(attrs) AREF (attrs, coding_attr_default_char)
176#define CODING_ATTR_FOR_UNIBYTE(attrs) AREF (attrs, coding_attr_for_unibyte)
177#define CODING_ATTR_FLUSHING(attrs) AREF (attrs, coding_attr_flushing)
178#define CODING_ATTR_PLIST(attrs) AREF (attrs, coding_attr_plist)
179#define CODING_ATTR_CATEGORY(attrs) AREF (attrs, coding_attr_category)
180#define CODING_ATTR_SAFE_CHARSETS(attrs)AREF (attrs, coding_attr_safe_charsets)
146 181
147/* If set, use designation escape sequence. */
148#define CODING_FLAG_ISO_DESIGNATION 0x10000
149 182
150/* A character to be produced on output if encoding of the original 183/* Return the name of a coding system specified by ID. */
151 character is inhibitted by CODING_MODE_INHIBIT_UNENCODABLE_CHAR. 184#define CODING_ID_NAME(id) \
152 It must be an ASCII character. */ 185 (HASH_KEY (XHASH_TABLE (Vcoding_system_hash_table), id))
153#define CODING_REPLACEMENT_CHARACTER '?'
154 186
155/* Structure of the field `spec.iso2022' in the structure `coding_system'. */ 187/* Return the attribute vector of a coding system specified by ID. */
156struct iso2022_spec
157{
158 /* The current graphic register invoked to each graphic plane. */
159 int current_invocation[2];
160 188
161 /* The current charset designated to each graphic register. */ 189#define CODING_ID_ATTRS(id) \
162 int current_designation[4]; 190 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 0))
163 191
164 /* A charset initially designated to each graphic register. */ 192/* Return the list of aliases of a coding system specified by ID. */
165 int initial_designation[4];
166 193
167 /* If not -1, it is a graphic register specified in an invalid 194#define CODING_ID_ALIASES(id) \
168 designation sequence. */ 195 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 1))
169 int last_invalid_designation_register;
170 196
171 /* A graphic register to which each charset should be designated. */ 197/* Return the eol-type of a coding system specified by ID. */
172 unsigned char requested_designation[MAX_CHARSET + 1];
173 198
174 /* A revision number to be specified for each charset on encoding. 199#define CODING_ID_EOL_TYPE(id) \
175 The value 255 means no revision number for the corresponding 200 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 2))
176 charset. */
177 unsigned char charset_revision_number[MAX_CHARSET + 1];
178 201
179 /* Set to 1 temporarily only when graphic register 2 or 3 is invoked
180 by single-shift while encoding. */
181 int single_shifting;
182 202
183 /* Set to 1 temporarily only when processing at beginning of line. */ 203/* Return the spec vector of CODING_SYSTEM_SYMBOL. */
184 int bol; 204
185}; 205#define CODING_SYSTEM_SPEC(coding_system_symbol) \
206 (Fgethash (coding_system_symbol, Vcoding_system_hash_table, Qnil))
207
208
209/* Return the ID of CODING_SYSTEM_SYMBOL. */
210
211#define CODING_SYSTEM_ID(coding_system_symbol) \
212 hash_lookup (XHASH_TABLE (Vcoding_system_hash_table), \
213 coding_system_symbol, NULL)
214
215/* Return 1 if CODING_SYSTEM_SYMBOL is a coding system. */
216
217#define CODING_SYSTEM_P(coding_system_symbol) \
218 (CODING_SYSTEM_ID (coding_system_symbol) >= 0 \
219 || (! NILP (coding_system_symbol) \
220 && ! NILP (Fcoding_system_p (coding_system_symbol))))
221
222/* Check if X is a coding system or not. */
223
224#define CHECK_CODING_SYSTEM(x) \
225 do { \
226 if (CODING_SYSTEM_ID (x) < 0 \
227 && NILP (Fcheck_coding_system (x))) \
228 wrong_type_argument (Qcoding_system_p, (x)); \
229 } while (0)
230
231
232/* Check if X is a coding system or not. If it is, set SEPC to the
233 spec vector of the coding system. */
234
235#define CHECK_CODING_SYSTEM_GET_SPEC(x, spec) \
236 do { \
237 spec = CODING_SYSTEM_SPEC (x); \
238 if (NILP (spec)) \
239 { \
240 Fcheck_coding_system (x); \
241 spec = CODING_SYSTEM_SPEC (x); \
242 } \
243 if (NILP (spec)) \
244 x = wrong_type_argument (Qcoding_system_p, (x)); \
245 } while (0)
246
247
248/* Check if X is a coding system or not. If it is, set ID to the
249 ID of the coding system. */
250
251#define CHECK_CODING_SYSTEM_GET_ID(x, id) \
252 do \
253 { \
254 id = CODING_SYSTEM_ID (x); \
255 if (id < 0) \
256 { \
257 Fcheck_coding_system (x); \
258 id = CODING_SYSTEM_ID (x); \
259 } \
260 if (id < 0) \
261 x = wrong_type_argument (Qcoding_system_p, (x)); \
262 } while (0)
186 263
187/* Macros to access each field in the structure `spec.iso2022'. */
188#define CODING_SPEC_ISO_INVOCATION(coding, plane) \
189 (coding)->spec.iso2022.current_invocation[plane]
190#define CODING_SPEC_ISO_DESIGNATION(coding, reg) \
191 (coding)->spec.iso2022.current_designation[reg]
192#define CODING_SPEC_ISO_INITIAL_DESIGNATION(coding, reg) \
193 (coding)->spec.iso2022.initial_designation[reg]
194#define CODING_SPEC_ISO_REQUESTED_DESIGNATION(coding, charset) \
195 (coding)->spec.iso2022.requested_designation[charset]
196#define CODING_SPEC_ISO_REVISION_NUMBER(coding, charset) \
197 (coding)->spec.iso2022.charset_revision_number[charset]
198#define CODING_SPEC_ISO_SINGLE_SHIFTING(coding) \
199 (coding)->spec.iso2022.single_shifting
200#define CODING_SPEC_ISO_BOL(coding) \
201 (coding)->spec.iso2022.bol
202
203/* A value which may appear in
204 coding->spec.iso2022.requested_designation indicating that the
205 corresponding charset does not request any graphic register to be
206 designated. */
207#define CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION 4
208
209/* Return a charset which is currently designated to the graphic plane
210 PLANE in the coding-system CODING. */
211#define CODING_SPEC_ISO_PLANE_CHARSET(coding, plane) \
212 ((CODING_SPEC_ISO_INVOCATION (coding, plane) < 0) \
213 ? -1 \
214 : CODING_SPEC_ISO_DESIGNATION (coding, \
215 CODING_SPEC_ISO_INVOCATION (coding, plane)))
216
217/*** BIG5 section ***/
218
219/* Macros to denote each type of BIG5 coding system. */
220#define CODING_FLAG_BIG5_HKU 0x00 /* BIG5-HKU is one of variants of
221 BIG5 developed by Hong Kong
222 University. */
223#define CODING_FLAG_BIG5_ETEN 0x01 /* BIG5_ETen is one of variants
224 of BIG5 developed by the
225 company ETen in Taiwan. */
226 264
227/*** GENERAL section ***/ 265/*** GENERAL section ***/
228 266
229/* Types of coding system. */ 267/* Enumeration of result code of code conversion. */
230enum coding_type 268enum coding_result_code
231 { 269 {
232 coding_type_no_conversion, /* A coding system which requires no 270 CODING_RESULT_SUCCESS,
233 conversion for reading and writing 271 CODING_RESULT_INSUFFICIENT_SRC,
234 including end-of-line format. */ 272 CODING_RESULT_INSUFFICIENT_DST,
235 coding_type_emacs_mule, /* A coding system used in Emacs' 273 CODING_RESULT_INCONSISTENT_EOL,
236 buffer and string. Requires no 274 CODING_RESULT_INVALID_SRC,
237 conversion for reading and writing 275 CODING_RESULT_INTERRUPT,
238 except for end-of-line format. */ 276 CODING_RESULT_INSUFFICIENT_MEM
239 coding_type_undecided, /* A coding system which requires
240 automatic detection of a real
241 coding system. */
242 coding_type_sjis, /* SJIS coding system for Japanese. */
243 coding_type_iso2022, /* Any coding system of ISO2022
244 variants. */
245 coding_type_big5, /* BIG5 coding system for Chinese. */
246 coding_type_ccl, /* The coding system of which decoder
247 and encoder are written in CCL. */
248 coding_type_raw_text /* A coding system for a text
249 containing random 8-bit code which
250 does not require code conversion
251 except for end-of-line format. */
252 }; 277 };
253 278
254/* Formats of end-of-line. */
255#define CODING_EOL_LF 0 /* Line-feed only, same as Emacs'
256 internal format. */
257#define CODING_EOL_CRLF 1 /* Sequence of carriage-return and
258 line-feed. */
259#define CODING_EOL_CR 2 /* Carriage-return only. */
260#define CODING_EOL_UNDECIDED 3 /* This value is used to denote the
261 eol-type is not yet decided. */
262#define CODING_EOL_INCONSISTENT 4 /* This value is used to denote the
263 eol-type is not consistent
264 through the file. */
265
266/* 1 if composing. */
267#define COMPOSING_P(coding) ((int) coding->composing > (int) COMPOSITION_NO)
268
269#define COMPOSITION_DATA_SIZE 4080
270#define COMPOSITION_DATA_MAX_BUNCH_LENGTH (4 + MAX_COMPOSITION_COMPONENTS*2)
271
272/* Data structure to hold information about compositions of text that
273 is being decoded or encode. ISO 2022 base code conversion routines
274 handle special ESC sequences for composition specification. But,
275 they can't get/put such information directly from/to a buffer in
276 the deepest place. So, they store or retrieve the information
277 through this structure.
278
279 The encoder stores the information in this structure when it meets
280 ESC sequences for composition while encoding codes, then, after all
281 text codes are encoded, puts `composition' properties on the text
282 by referring to the structure.
283
284 The decoder at first stores the information of a text to be
285 decoded, then, while decoding codes, generates ESC sequences for
286 composition at proper places by referring to the structure. */
287
288struct composition_data
289{
290 /* The character position of the first character to be encoded or
291 decoded. START and END (see below) are relative to this
292 position. */
293 int char_offset;
294
295 /* The composition data. These elements are repeated for each
296 composition:
297 LENGTH START END METHOD [ COMPONENT ... ]
298 where,
299 LENGTH is the number of elements for this composition.
300
301 START and END are starting and ending character positions of
302 the composition relative to `char_offset'.
303
304 METHOD is one of `enum composing_status' specifying the way of
305 composition.
306
307 COMPONENT is a character or an encoded composition rule. */
308 int data[COMPOSITION_DATA_SIZE];
309
310 /* The number of elements in `data' currently used. */
311 int used;
312
313 /* Pointers to the previous and next structures. When `data' is
314 filled up, another structure is allocated and linked in `next'.
315 The new structure has backward link to this structure in `prev'.
316 The number of chained structures depends on how many compositions
317 the text being encoded or decoded contains. */
318 struct composition_data *prev, *next;
319};
320
321/* Macros used for the member `result' of the struct
322 coding_system. */
323#define CODING_FINISH_NORMAL 0
324#define CODING_FINISH_INSUFFICIENT_SRC 1
325#define CODING_FINISH_INSUFFICIENT_DST 2
326#define CODING_FINISH_INCONSISTENT_EOL 3
327#define CODING_FINISH_INSUFFICIENT_CMP 4
328#define CODING_FINISH_INTERRUPT 5
329 279
330/* Macros used for the member `mode' of the struct coding_system. */ 280/* Macros used for the member `mode' of the struct coding_system. */
331 281
@@ -334,7 +284,7 @@ struct composition_data
334#define CODING_MODE_INHIBIT_INCONSISTENT_EOL 0x01 284#define CODING_MODE_INHIBIT_INCONSISTENT_EOL 0x01
335 285
336/* If set, the decoding/encoding routines treat the current data as 286/* If set, the decoding/encoding routines treat the current data as
337 the last block of the whole text to be converted, and do 287 the last block of the whole text to be converted, and do the
338 appropriate finishing job. */ 288 appropriate finishing job. */
339#define CODING_MODE_LAST_BLOCK 0x02 289#define CODING_MODE_LAST_BLOCK 0x02
340 290
@@ -342,65 +292,106 @@ struct composition_data
342 enables selective display. */ 292 enables selective display. */
343#define CODING_MODE_SELECTIVE_DISPLAY 0x04 293#define CODING_MODE_SELECTIVE_DISPLAY 0x04
344 294
345/* If set, replace unencodabae characters by `?' on encoding. */
346#define CODING_MODE_INHIBIT_UNENCODABLE_CHAR 0x08
347
348/* This flag is used by the decoding/encoding routines on the fly. If 295/* This flag is used by the decoding/encoding routines on the fly. If
349 set, it means that right-to-left text is being processed. */ 296 set, it means that right-to-left text is being processed. */
350#define CODING_MODE_DIRECTION 0x10 297#define CODING_MODE_DIRECTION 0x08
351 298
352struct coding_system 299#define CODING_MODE_FIXED_DESTINATION 0x10
300
301/* If set, it means that the encoding routines produces some safe
302 ASCII characters (usually '?') for unsupported characters. */
303#define CODING_MODE_SAFE_ENCODING 0x20
304
305/* Structure of the field `spec.iso_2022' in the structure
306 `coding_system'. */
307struct iso_2022_spec
353{ 308{
354 /* Type of the coding system. */ 309 /* Bit-wise-or of CODING_ISO_FLAG_XXX. */
355 enum coding_type type; 310 unsigned flags;
356 311
357 /* Type of end-of-line format (LF, CRLF, or CR) of the coding system. */ 312 /* The current graphic register invoked to each graphic plane. */
358 int eol_type; 313 int current_invocation[2];
359 314
360 /* Flag bits of the coding system. The meaning of each bit is common 315 /* The current charset designated to each graphic register. The
361 to all types of coding systems. */ 316 value -1 means that not charset is designated, -2 means that
362 unsigned int common_flags; 317 there was an invalid designation previously. */
318 int current_designation[4];
363 319
364 /* Flag bits of the coding system. The meaning of each bit depends 320 /* Set to 1 temporarily only when graphic register 2 or 3 is invoked
365 on the type of the coding system. */ 321 by single-shift while encoding. */
366 unsigned int flags; 322 int single_shifting;
367 323
368 /* Mode bits of the coding system. See the comments of the macros 324 /* Set to 1 temporarily only when processing at beginning of line. */
369 CODING_MODE_XXX. */ 325 int bol;
370 unsigned int mode; 326};
327
328struct ccl_spec;
329
330enum utf_16_bom_type
331 {
332 utf_16_detect_bom,
333 utf_16_without_bom,
334 utf_16_with_bom
335 };
336
337enum utf_16_endian_type
338 {
339 utf_16_big_endian,
340 utf_16_little_endian
341 };
342
343struct utf_16_spec
344{
345 enum utf_16_bom_type bom;
346 enum utf_16_endian_type endian;
347 int surrogate;
348};
371 349
372 /* The current status of composition handling. */ 350struct coding_detection_info
373 int composing; 351{
352 /* Values of these members are bitwise-OR of CATEGORY_MASK_XXXs. */
353 /* Which categories are already checked. */
354 int checked;
355 /* Which categories are strongly found. */
356 int found;
357 /* Which categories are rejected. */
358 int rejected;
359};
374 360
375 /* 1 if the next character is a composition rule. */
376 int composition_rule_follows;
377 361
378 /* Information of compositions are stored here on decoding and set 362struct coding_system
379 in advance on encoding. */ 363{
380 struct composition_data *cmp_data; 364 /* ID number of the coding system. This is an index to
365 Vcoding_system_hash_table. This value is set by
366 setup_coding_system. At the early stage of building time, this
367 value is -1 in the array coding_categories to indicate that no
368 coding-system of that category is yet defined. */
369 int id;
381 370
382 /* Index to cmp_data->data for the first element for the current 371 /* Flag bits of the coding system. The meaning of each bit is common
383 composition. */ 372 to all types of coding systems. */
384 int cmp_data_start; 373 int common_flags;
385 374
386 /* Index to cmp_data->data for the current element for the current 375 /* Mode bits of the coding system. See the comments of the macros
387 composition. */ 376 CODING_MODE_XXX. */
388 int cmp_data_index; 377 unsigned int mode;
389 378
390 /* Detailed information specific to each type of coding system. */ 379 /* Detailed information specific to each type of coding system. */
391 union spec 380 union
392 { 381 {
393 struct iso2022_spec iso2022; 382 struct iso_2022_spec iso_2022;
394 struct ccl_spec ccl; /* Defined in ccl.h. */ 383 struct ccl_spec *ccl; /* Defined in ccl.h. */
384 struct utf_16_spec utf_16;
385 int emacs_mule_full_support;
395 } spec; 386 } spec;
396 387
397 /* Index number of coding category of the coding system. */ 388 int max_charset_id;
398 int category_idx; 389 char *safe_charsets;
399 390
400 /* The following two members specify how characters 128..159 are 391 /* The following two members specify how binary 8-bit code 128..255
401 represented in source and destination text respectively. 1 means 392 are represented in source and destination text respectively. 1
402 they are represented by 2-byte sequence, 0 means they are 393 means they are represented by 2-byte sequence, 0 means they are
403 represented by 1-byte as is (see the comment in charset.h). */ 394 represented by 1-byte as is (see the comment in character.h). */
404 unsigned src_multibyte : 1; 395 unsigned src_multibyte : 1;
405 unsigned dst_multibyte : 1; 396 unsigned dst_multibyte : 1;
406 397
@@ -408,173 +399,200 @@ struct coding_system
408 -1 in setup_coding_system, and updated by detect_coding. So, 399 -1 in setup_coding_system, and updated by detect_coding. So,
409 when this is equal to the byte length of the text being 400 when this is equal to the byte length of the text being
410 converted, we can skip the actual conversion process. */ 401 converted, we can skip the actual conversion process. */
411 int heading_ascii; 402 int head_ascii;
412 403
413 /* The following members are set by encoding/decoding routine. */ 404 /* The following members are set by encoding/decoding routine. */
414 int produced, produced_char, consumed, consumed_char; 405 EMACS_INT produced, produced_char, consumed, consumed_char;
415 406
416 /* Number of error source data found in a decoding routine. */ 407 /* Number of error source data found in a decoding routine. */
417 int errors; 408 int errors;
418 409
419 /* Finish status of code conversion. It should be one of macros 410 /* Store the positions of error source data. */
420 CODING_FINISH_XXXX. */ 411 EMACS_INT *error_positions;
421 int result;
422 412
423 /* If nonzero, suppress error notification. */ 413 /* Finish status of code conversion. */
424 int suppress_error; 414 enum coding_result_code result;
425 415
426 /* The following members are all Lisp symbols. We don't have to 416 EMACS_INT src_pos, src_pos_byte, src_chars, src_bytes;
427 protect them from GC because the current garbage collection 417 Lisp_Object src_object;
428 doesn't relocate Lisp symbols. But, when it is changed, we must 418 const unsigned char *source;
429 find a way to protect them. */
430 419
431 /* Backward pointer to the Lisp symbol of the coding system. */ 420 EMACS_INT dst_pos, dst_pos_byte, dst_bytes;
432 Lisp_Object symbol; 421 Lisp_Object dst_object;
422 unsigned char *destination;
433 423
434 /* Lisp function (symbol) to be called after decoding to do 424 /* Set to 1 if the source of conversion is not in the member
435 additional conversion, or nil. */ 425 `charbuf', but at `src_object'. */
436 Lisp_Object post_read_conversion; 426 int chars_at_source;
437 427
438 /* Lisp function (symbol) to be called before encoding to do 428 /* If an element is non-negative, it is a character code.
439 additional conversion, or nil. */
440 Lisp_Object pre_write_conversion;
441 429
442 /* Character translation tables to look up, or nil. */ 430 If it is in the range -128..-1, it is a 8-bit character code
443 Lisp_Object translation_table_for_decode; 431 minus 256.
444 Lisp_Object translation_table_for_encode; 432
445}; 433 If it is less than -128, it specifies the start of an annotation
434 chunk. The length of the chunk is -128 minus the value of the
435 element. The following elements are OFFSET, ANNOTATION-TYPE, and
436 a sequence of actual data for the annotation. OFFSET is a
437 character position offset from dst_pos or src_pos,
438 ANNOTATION-TYPE specfies the meaning of the annotation and how to
439 handle the following data.. */
440 int *charbuf;
441 int charbuf_size, charbuf_used;
442
443 /* Set to 1 if charbuf contains an annotation. */
444 int annotated;
445
446 unsigned char carryover[64];
447 int carryover_bytes;
448
449 int default_char;
446 450
447/* Mask bits for (struct coding_system *)->common_flags. */ 451 int (*detector) P_ ((struct coding_system *,
448#define CODING_REQUIRE_FLUSHING_MASK 0x01 452 struct coding_detection_info *));
449#define CODING_REQUIRE_DECODING_MASK 0x02 453 void (*decoder) P_ ((struct coding_system *));
450#define CODING_REQUIRE_ENCODING_MASK 0x04 454 int (*encoder) P_ ((struct coding_system *));
451#define CODING_REQUIRE_DETECTION_MASK 0x08 455};
452#define CODING_ASCII_INCOMPATIBLE_MASK 0x10
453 456
454/* Return 1 if the coding system CODING requires specific code to be 457/* Meanings of bits in the member `common_flags' of the structure
458 coding_system. The lowest 8 bits are reserved for various kind of
459 annotations (currently two of them are used). */
460#define CODING_ANNOTATION_MASK 0x00FF
461#define CODING_ANNOTATE_COMPOSITION_MASK 0x0001
462#define CODING_ANNOTATE_DIRECTION_MASK 0x0002
463#define CODING_ANNOTATE_CHARSET_MASK 0x0003
464#define CODING_FOR_UNIBYTE_MASK 0x0100
465#define CODING_REQUIRE_FLUSHING_MASK 0x0200
466#define CODING_REQUIRE_DECODING_MASK 0x0400
467#define CODING_REQUIRE_ENCODING_MASK 0x0800
468#define CODING_REQUIRE_DETECTION_MASK 0x1000
469#define CODING_RESET_AT_BOL_MASK 0x2000
470
471/* Return 1 if the coding context CODING requires annotaion
472 handling. */
473#define CODING_REQUIRE_ANNOTATION(coding) \
474 ((coding)->common_flags & CODING_ANNOTATION_MASK)
475
476/* Return 1 if the coding context CODING prefers decoding into unibyte. */
477#define CODING_FOR_UNIBYTE(coding) \
478 ((coding)->common_flags & CODING_FOR_UNIBYTE_MASK)
479
480/* Return 1 if the coding context CODING requires specific code to be
455 attached at the tail of converted text. */ 481 attached at the tail of converted text. */
456#define CODING_REQUIRE_FLUSHING(coding) \ 482#define CODING_REQUIRE_FLUSHING(coding) \
457 ((coding)->common_flags & CODING_REQUIRE_FLUSHING_MASK) 483 ((coding)->common_flags & CODING_REQUIRE_FLUSHING_MASK)
458 484
459/* Return 1 if the coding system CODING requires code conversion on 485/* Return 1 if the coding context CODING requires code conversion on
460 decoding. */ 486 decoding. */
461#define CODING_REQUIRE_DECODING(coding) \ 487#define CODING_REQUIRE_DECODING(coding) \
462 ((coding)->dst_multibyte \ 488 ((coding)->dst_multibyte \
463 || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK) 489 || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
464 490
465/* Return 1 if the coding system CODING requires code conversion on 491
492/* Return 1 if the coding context CODING requires code conversion on
466 encoding. 493 encoding.
467 The non-multibyte part of the condition is to support encoding of 494 The non-multibyte part of the condition is to support encoding of
468 unibyte strings/buffers generated by string-as-unibyte or 495 unibyte strings/buffers generated by string-as-unibyte or
469 (set-buffer-multibyte nil) from multibyte strings/buffers. */ 496 (set-buffer-multibyte nil) from multibyte strings/buffers. */
470#define CODING_REQUIRE_ENCODING(coding) \ 497#define CODING_REQUIRE_ENCODING(coding) \
471 ((coding)->src_multibyte \ 498 ((coding)->src_multibyte \
472 || (coding)->common_flags & CODING_REQUIRE_ENCODING_MASK) 499 || (coding)->common_flags & CODING_REQUIRE_ENCODING_MASK \
500 || (coding)->mode & CODING_MODE_SELECTIVE_DISPLAY)
473 501
474/* Return 1 if the coding system CODING requires some kind of code 502
503/* Return 1 if the coding context CODING requires some kind of code
475 detection. */ 504 detection. */
476#define CODING_REQUIRE_DETECTION(coding) \ 505#define CODING_REQUIRE_DETECTION(coding) \
477 ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK) 506 ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK)
478 507
479/* Return 1 if the coding system CODING requires code conversion on 508/* Return 1 if the coding context CODING requires code conversion on
480 decoding or some kind of code detection. */ 509 decoding or some kind of code detection. */
481#define CODING_MAY_REQUIRE_DECODING(coding) \ 510#define CODING_MAY_REQUIRE_DECODING(coding) \
482 (CODING_REQUIRE_DECODING (coding) \ 511 (CODING_REQUIRE_DECODING (coding) \
483 || CODING_REQUIRE_DETECTION (coding)) 512 || CODING_REQUIRE_DETECTION (coding))
484 513
485/* Index for each coding category in `coding_category_table' */
486#define CODING_CATEGORY_IDX_EMACS_MULE 0
487#define CODING_CATEGORY_IDX_SJIS 1
488#define CODING_CATEGORY_IDX_ISO_7 2
489#define CODING_CATEGORY_IDX_ISO_7_TIGHT 3
490#define CODING_CATEGORY_IDX_ISO_8_1 4
491#define CODING_CATEGORY_IDX_ISO_8_2 5
492#define CODING_CATEGORY_IDX_ISO_7_ELSE 6
493#define CODING_CATEGORY_IDX_ISO_8_ELSE 7
494#define CODING_CATEGORY_IDX_CCL 8
495#define CODING_CATEGORY_IDX_BIG5 9
496#define CODING_CATEGORY_IDX_UTF_8 10
497#define CODING_CATEGORY_IDX_UTF_16_BE 11
498#define CODING_CATEGORY_IDX_UTF_16_LE 12
499#define CODING_CATEGORY_IDX_RAW_TEXT 13
500#define CODING_CATEGORY_IDX_BINARY 14
501#define CODING_CATEGORY_IDX_MAX 15
502
503/* Definitions of flag bits returned by the function
504 detect_coding_mask (). */
505#define CODING_CATEGORY_MASK_EMACS_MULE (1 << CODING_CATEGORY_IDX_EMACS_MULE)
506#define CODING_CATEGORY_MASK_SJIS (1 << CODING_CATEGORY_IDX_SJIS)
507#define CODING_CATEGORY_MASK_ISO_7 (1 << CODING_CATEGORY_IDX_ISO_7)
508#define CODING_CATEGORY_MASK_ISO_7_TIGHT (1 << CODING_CATEGORY_IDX_ISO_7_TIGHT)
509#define CODING_CATEGORY_MASK_ISO_8_1 (1 << CODING_CATEGORY_IDX_ISO_8_1)
510#define CODING_CATEGORY_MASK_ISO_8_2 (1 << CODING_CATEGORY_IDX_ISO_8_2)
511#define CODING_CATEGORY_MASK_ISO_7_ELSE (1 << CODING_CATEGORY_IDX_ISO_7_ELSE)
512#define CODING_CATEGORY_MASK_ISO_8_ELSE (1 << CODING_CATEGORY_IDX_ISO_8_ELSE)
513#define CODING_CATEGORY_MASK_CCL (1 << CODING_CATEGORY_IDX_CCL)
514#define CODING_CATEGORY_MASK_BIG5 (1 << CODING_CATEGORY_IDX_BIG5)
515#define CODING_CATEGORY_MASK_UTF_8 (1 << CODING_CATEGORY_IDX_UTF_8)
516#define CODING_CATEGORY_MASK_UTF_16_BE (1 << CODING_CATEGORY_IDX_UTF_16_BE)
517#define CODING_CATEGORY_MASK_UTF_16_LE (1 << CODING_CATEGORY_IDX_UTF_16_LE)
518#define CODING_CATEGORY_MASK_RAW_TEXT (1 << CODING_CATEGORY_IDX_RAW_TEXT)
519#define CODING_CATEGORY_MASK_BINARY (1 << CODING_CATEGORY_IDX_BINARY)
520
521/* This value is returned if detect_coding_mask () find nothing other
522 than ASCII characters. */
523#define CODING_CATEGORY_MASK_ANY \
524 ( CODING_CATEGORY_MASK_EMACS_MULE \
525 | CODING_CATEGORY_MASK_SJIS \
526 | CODING_CATEGORY_MASK_ISO_7 \
527 | CODING_CATEGORY_MASK_ISO_7_TIGHT \
528 | CODING_CATEGORY_MASK_ISO_8_1 \
529 | CODING_CATEGORY_MASK_ISO_8_2 \
530 | CODING_CATEGORY_MASK_ISO_7_ELSE \
531 | CODING_CATEGORY_MASK_ISO_8_ELSE \
532 | CODING_CATEGORY_MASK_CCL \
533 | CODING_CATEGORY_MASK_BIG5 \
534 | CODING_CATEGORY_MASK_UTF_8 \
535 | CODING_CATEGORY_MASK_UTF_16_BE \
536 | CODING_CATEGORY_MASK_UTF_16_LE)
537
538#define CODING_CATEGORY_MASK_ISO_7BIT \
539 (CODING_CATEGORY_MASK_ISO_7 | CODING_CATEGORY_MASK_ISO_7_TIGHT)
540
541#define CODING_CATEGORY_MASK_ISO_8BIT \
542 (CODING_CATEGORY_MASK_ISO_8_1 | CODING_CATEGORY_MASK_ISO_8_2)
543
544#define CODING_CATEGORY_MASK_ISO_SHIFT \
545 (CODING_CATEGORY_MASK_ISO_7_ELSE | CODING_CATEGORY_MASK_ISO_8_ELSE)
546
547#define CODING_CATEGORY_MASK_ISO \
548 ( CODING_CATEGORY_MASK_ISO_7BIT \
549 | CODING_CATEGORY_MASK_ISO_SHIFT \
550 | CODING_CATEGORY_MASK_ISO_8BIT)
551
552#define CODING_CATEGORY_MASK_UTF_16_BE_LE \
553 (CODING_CATEGORY_MASK_UTF_16_BE | CODING_CATEGORY_MASK_UTF_16_LE)
554
555/* Macros to decode or encode a character of JISX0208 in SJIS. S1 and 514/* Macros to decode or encode a character of JISX0208 in SJIS. S1 and
556 S2 are the 1st and 2nd position-codes of JISX0208 in SJIS coding 515 S2 are the 1st and 2nd position-codes of JISX0208 in SJIS coding
557 system. C1 and C2 are the 1st and 2nd position codes of Emacs' 516 system. C1 and C2 are the 1st and 2nd position codes of Emacs'
558 internal format. */ 517 internal format. */
559 518
560#define DECODE_SJIS(s1, s2, c1, c2) \ 519#define SJIS_TO_JIS(code) \
561 do { \ 520 do { \
562 if (s2 >= 0x9F) \ 521 int s1, s2, j1, j2; \
563 c1 = s1 * 2 - (s1 >= 0xE0 ? 0x160 : 0xE0), \ 522 \
564 c2 = s2 - 0x7E; \ 523 s1 = (code) >> 8, s2 = (code) & 0xFF; \
565 else \ 524 \
566 c1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \ 525 if (s2 >= 0x9F) \
567 c2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F); \ 526 (j1 = s1 * 2 - (s1 >= 0xE0 ? 0x160 : 0xE0), \
527 j2 = s2 - 0x7E); \
528 else \
529 (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \
530 j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F)); \
531 (code) = (j1 << 8) | j2; \
532 } while (0)
533
534#define SJIS_TO_JIS2(code) \
535 do { \
536 int s1, s2, j1, j2; \
537 \
538 s1 = (code) >> 8, s2 = (code) & 0xFF; \
539 \
540 if (s2 >= 0x9F) \
541 { \
542 j1 = (s1 == 0xF0 ? 0x28 \
543 : s1 == 0xF1 ? 0x24 \
544 : s1 == 0xF2 ? 0x2C \
545 : s1 == 0xF3 ? 0x2E \
546 : 0x6E + (s1 - 0xF4) * 2); \
547 j2 = s2 - 0x7E; \
548 } \
549 else \
550 { \
551 j1 = (s1 <= 0xF2 ? 0x21 + (s1 - 0xF0) * 2 \
552 : s1 <= 0xF4 ? 0x2D + (s1 - 0xF3) * 2 \
553 : 0x6F + (s1 - 0xF5) * 2); \
554 j2 = s2 - ((s2 >= 0x7F ? 0x20 : 0x1F)); \
555 } \
556 (code) = (j1 << 8) | j2; \
557 } while (0)
558
559
560#define JIS_TO_SJIS(code) \
561 do { \
562 int s1, s2, j1, j2; \
563 \
564 j1 = (code) >> 8, j2 = (code) & 0xFF; \
565 if (j1 & 1) \
566 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x71 : 0xB1), \
567 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F)); \
568 else \
569 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \
570 s2 = j2 + 0x7E); \
571 (code) = (s1 << 8) | s2; \
568 } while (0) 572 } while (0)
569 573
570#define ENCODE_SJIS(c1, c2, s1, s2) \ 574#define JIS_TO_SJIS2(code) \
571 do { \ 575 do { \
572 if (c1 & 1) \ 576 int s1, s2, j1, j2; \
573 s1 = c1 / 2 + ((c1 < 0x5F) ? 0x71 : 0xB1), \ 577 \
574 s2 = c2 + ((c2 >= 0x60) ? 0x20 : 0x1F); \ 578 j1 = (code) >> 8, j2 = (code) & 0xFF; \
579 if (j1 & 1) \
580 { \
581 s1 = (j1 <= 0x25 ? 0xF0 + (j1 - 0x21) / 2 \
582 : j1 <= 0x27 ? 0xF3 + (j1 - 0x2D) / 2 \
583 : 0xF5 + (j1 - 0x6F) / 2); \
584 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F); \
585 } \
575 else \ 586 else \
576 s1 = c1 / 2 + ((c1 < 0x5F) ? 0x70 : 0xB0), \ 587 { \
577 s2 = c2 + 0x7E; \ 588 s1 = (j1 == 0x28 ? 0xF0 \
589 : j1 == 0x24 ? 0xF1 \
590 : j1 == 0x2C ? 0xF2 \
591 : j1 == 0x2E ? 0xF3 \
592 : 0xF4 + (j1 - 0x6E) / 2); \
593 s2 = j2 + 0x7E; \
594 } \
595 (code) = (s1 << 8) | s2; \
578 } while (0) 596 } while (0)
579 597
580/* Encode the file name NAME using the specified coding system 598/* Encode the file name NAME using the specified coding system
@@ -588,6 +606,7 @@ struct coding_system
588 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \ 606 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \
589 : name)) 607 : name))
590 608
609
591/* Decode the file name NAME using the specified coding system 610/* Decode the file name NAME using the specified coding system
592 for file names, if any. */ 611 for file names, if any. */
593#define DECODE_FILE(name) \ 612#define DECODE_FILE(name) \
@@ -599,6 +618,7 @@ struct coding_system
599 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \ 618 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
600 : name)) 619 : name))
601 620
621
602/* Encode the string STR using the specified coding system 622/* Encode the string STR using the specified coding system
603 for system functions, if any. */ 623 for system functions, if any. */
604#define ENCODE_SYSTEM(str) \ 624#define ENCODE_SYSTEM(str) \
@@ -615,54 +635,83 @@ struct coding_system
615 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \ 635 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \
616 : str) 636 : str)
617 637
638/* Used by the gtk menu code. Note that this encodes utf-8, not
639 utf-8-emacs, so it's not a no-op. */
618#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1) 640#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1)
619 641
620/* Extern declarations. */ 642/* Extern declarations. */
621extern int decode_coding P_ ((struct coding_system *, const unsigned char *, 643extern Lisp_Object code_conversion_save P_ ((int, int));
622 unsigned char *, int, int));
623extern int encode_coding P_ ((struct coding_system *, const unsigned char *,
624 unsigned char *, int, int));
625extern void coding_save_composition P_ ((struct coding_system *, int, int,
626 Lisp_Object));
627extern void coding_free_composition_data P_ ((struct coding_system *));
628extern void coding_adjust_composition_offset P_ ((struct coding_system *,
629 int));
630extern void coding_allocate_composition_data P_ ((struct coding_system *,
631 int));
632extern void coding_restore_composition P_ ((struct coding_system *,
633 Lisp_Object));
634extern int code_convert_region P_ ((int, int, int, int, struct coding_system *,
635 int, int));
636extern Lisp_Object run_pre_post_conversion_on_str P_ ((Lisp_Object,
637 struct coding_system *,
638 int));
639extern void run_pre_write_conversin_on_c_str P_ ((unsigned char **, int *,
640 int, int,
641 struct coding_system *));
642
643extern int decoding_buffer_size P_ ((struct coding_system *, int)); 644extern int decoding_buffer_size P_ ((struct coding_system *, int));
644extern int encoding_buffer_size P_ ((struct coding_system *, int)); 645extern int encoding_buffer_size P_ ((struct coding_system *, int));
645extern void detect_coding P_ ((struct coding_system *, const unsigned char *, 646extern void setup_coding_system P_ ((Lisp_Object, struct coding_system *));
646 int)); 647extern Lisp_Object coding_charset_list P_ ((struct coding_system *));
647extern void detect_eol P_ ((struct coding_system *, const unsigned char *, 648extern void detect_coding P_ ((struct coding_system *));
648 int)); 649extern Lisp_Object code_convert_region P_ ((Lisp_Object, Lisp_Object,
649extern int setup_coding_system P_ ((Lisp_Object, struct coding_system *)); 650 Lisp_Object, Lisp_Object,
650extern Lisp_Object code_convert_string P_ ((Lisp_Object, 651 int, int));
651 struct coding_system *, int, int)); 652extern Lisp_Object code_convert_string P_ ((Lisp_Object, Lisp_Object,
652extern Lisp_Object code_convert_string1 P_ ((Lisp_Object, Lisp_Object, 653 Lisp_Object, int, int, int));
653 Lisp_Object, int));
654extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object, 654extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object,
655 int)); 655 int));
656extern void setup_raw_text_coding_system P_ ((struct coding_system *)); 656extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object));
657extern Lisp_Object encode_coding_string P_ ((Lisp_Object, 657extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object));
658 struct coding_system *, int)); 658
659extern Lisp_Object decode_coding_string P_ ((Lisp_Object, 659extern int decode_coding_gap P_ ((struct coding_system *,
660 struct coding_system *, int)); 660 EMACS_INT, EMACS_INT));
661extern int encode_coding_gap P_ ((struct coding_system *,
662 EMACS_INT, EMACS_INT));
663extern void decode_coding_object P_ ((struct coding_system *,
664 Lisp_Object, EMACS_INT, EMACS_INT,
665 EMACS_INT, EMACS_INT, Lisp_Object));
666extern void encode_coding_object P_ ((struct coding_system *,
667 Lisp_Object, EMACS_INT, EMACS_INT,
668 EMACS_INT, EMACS_INT, Lisp_Object));
669
670/* Macros for backward compatibility. */
671
672#define decode_coding_region(coding, from, to) \
673 decode_coding_object (coding, Fcurrent_buffer (), \
674 from, CHAR_TO_BYTE (from), \
675 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
676
677
678#define encode_coding_region(coding, from, to) \
679 encode_coding_object (coding, Fcurrent_buffer (), \
680 from, CHAR_TO_BYTE (from), \
681 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
682
683
684#define decode_coding_string(coding, string, nocopy) \
685 decode_coding_object (coding, string, 0, 0, XSTRING (string)->size, \
686 STRING_BYTES (XSTRING (string)), Qt)
687
688#define encode_coding_string(coding, string, nocopy) \
689 (encode_coding_object (coding, string, 0, 0, XSTRING (string)->size, \
690 STRING_BYTES (XSTRING (string)), Qt), \
691 (coding)->dst_object)
692
693
694#define decode_coding_c_string(coding, src, bytes, dst_object) \
695 do { \
696 (coding)->source = (src); \
697 (coding)->src_chars = (coding)->src_bytes = (bytes); \
698 decode_coding_object ((coding), Qnil, 0, 0, (bytes), (bytes), \
699 (dst_object)); \
700 } while (0)
701
702
703extern Lisp_Object preferred_coding_system P_ (());
704
705
706extern Lisp_Object Qutf_8, Qutf_8_emacs;
707
661extern Lisp_Object Qcoding_system, Qeol_type, Qcoding_category_index; 708extern Lisp_Object Qcoding_system, Qeol_type, Qcoding_category_index;
662extern Lisp_Object Qraw_text, Qemacs_mule; 709extern Lisp_Object Qcoding_system_p;
710extern Lisp_Object Qraw_text, Qemacs_mule, Qno_conversion, Qundecided;
711extern Lisp_Object Qiso_2022;
663extern Lisp_Object Qbuffer_file_coding_system; 712extern Lisp_Object Qbuffer_file_coding_system;
664extern Lisp_Object Vcoding_category_list; 713
665extern Lisp_Object Qutf_8; 714extern Lisp_Object Qunix, Qdos, Qmac;
666 715
667extern Lisp_Object Qtranslation_table; 716extern Lisp_Object Qtranslation_table;
668extern Lisp_Object Qtranslation_table_id; 717extern Lisp_Object Qtranslation_table_id;
@@ -672,9 +721,6 @@ extern Lisp_Object eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac;
672/* Mnemonic string to indicate type of end-of-line is not yet decided. */ 721/* Mnemonic string to indicate type of end-of-line is not yet decided. */
673extern Lisp_Object eol_mnemonic_undecided; 722extern Lisp_Object eol_mnemonic_undecided;
674 723
675/* Format of end-of-line decided by system. */
676extern int system_eol_type;
677
678#ifdef emacs 724#ifdef emacs
679extern Lisp_Object Qfile_coding_system; 725extern Lisp_Object Qfile_coding_system;
680extern Lisp_Object Qcall_process, Qcall_process_region; 726extern Lisp_Object Qcall_process, Qcall_process_region;
@@ -700,13 +746,10 @@ extern int inherit_process_coding_system;
700 terminal coding system is nil. */ 746 terminal coding system is nil. */
701extern struct coding_system safe_terminal_coding; 747extern struct coding_system safe_terminal_coding;
702 748
703/* Default coding system to be used to write a file. */
704extern struct coding_system default_buffer_file_coding;
705
706/* Default coding systems used for process I/O. */ 749/* Default coding systems used for process I/O. */
707extern Lisp_Object Vdefault_process_coding_system; 750extern Lisp_Object Vdefault_process_coding_system;
708 751
709/* Function to call to force a user to force select a proper coding 752/* Function to call to force a user to force select a propert coding
710 system. */ 753 system. */
711extern Lisp_Object Vselect_safe_coding_system_function; 754extern Lisp_Object Vselect_safe_coding_system_function;
712 755
@@ -726,6 +769,9 @@ extern Lisp_Object Vdefault_file_name_coding_system;
726/* Error signaled when there's a problem with detecting coding system */ 769/* Error signaled when there's a problem with detecting coding system */
727extern Lisp_Object Qcoding_system_error; 770extern Lisp_Object Qcoding_system_error;
728 771
772extern char emacs_mule_bytes[256];
773extern int emacs_mule_string_char P_ ((unsigned char *));
774
729#endif /* EMACS_CODING_H */ 775#endif /* EMACS_CODING_H */
730 776
731/* arch-tag: 2bc3b4fa-6870-4f64-8135-b962b2d290e4 777/* arch-tag: 2bc3b4fa-6870-4f64-8135-b962b2d290e4