(decode_coding_sjis): Handle 4th charset (typically JISX0212).
[bpt/emacs.git] / src / coding.h
CommitLineData
4ed46869 1/* Header for coding system handler.
75c8c592 2 Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
8f924df7
KH
3 Licensed to the Free Software Foundation.
4 Copyright (C) 2003
df7492f9
KH
5 National Institute of Advanced Industrial Science and Technology (AIST)
6 Registration Number H13PRO009
4ed46869 7
369314dc
KH
8This file is part of GNU Emacs.
9
10GNU Emacs is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2, or (at your option)
13any later version.
4ed46869 14
369314dc
KH
15GNU Emacs is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
4ed46869 19
369314dc
KH
20You should have received a copy of the GNU General Public License
21along with GNU Emacs; see the file COPYING. If not, write to
22the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23Boston, MA 02111-1307, USA. */
4ed46869 24
6f776e81
KH
25#ifndef EMACS_CODING_H
26#define EMACS_CODING_H
4ed46869 27
df7492f9 28/* Index to arguments of Fdefine_coding_system_internal. */
4ed46869 29
df7492f9
KH
30enum define_coding_system_arg_index
31 {
32 coding_arg_name,
33 coding_arg_mnemonic,
34 coding_arg_coding_type,
35 coding_arg_charset_list,
36 coding_arg_ascii_compatible_p,
37 coding_arg_decode_translation_table,
38 coding_arg_encode_translation_table,
39 coding_arg_post_read_conversion,
40 coding_arg_pre_write_conversion,
41 coding_arg_default_char,
8f924df7 42 coding_arg_for_unibyte,
df7492f9
KH
43 coding_arg_plist,
44 coding_arg_eol_type,
45 coding_arg_max
46 };
4ed46869 47
df7492f9 48enum define_coding_iso2022_arg_index
4ed46869 49 {
df7492f9
KH
50 coding_arg_iso2022_initial = coding_arg_max,
51 coding_arg_iso2022_reg_usage,
52 coding_arg_iso2022_request,
53 coding_arg_iso2022_flags,
54 coding_arg_iso2022_max
4ed46869
KH
55 };
56
df7492f9 57enum define_coding_utf16_arg_index
4ed46869 58 {
df7492f9
KH
59 coding_arg_utf16_bom = coding_arg_max,
60 coding_arg_utf16_endian,
61 coding_arg_utf16_max
4ed46869
KH
62 };
63
df7492f9
KH
64enum define_coding_ccl_arg_index
65 {
35d47d18 66 coding_arg_ccl_decoder = coding_arg_max,
df7492f9
KH
67 coding_arg_ccl_encoder,
68 coding_arg_ccl_valids,
69 coding_arg_ccl_max
70 };
4ed46869 71
df7492f9 72extern Lisp_Object Vcoding_system_hash_table;
4ed46869 73
df7492f9 74/* Enumeration of coding system type. */
4ed46869 75
df7492f9
KH
76enum coding_system_type
77 {
78 coding_type_charset,
79 coding_type_utf_8,
80 coding_type_utf_16,
81 coding_type_iso_2022,
82 coding_type_emacs_mule,
83 coding_type_sjis,
84 coding_type_ccl,
85 coding_type_raw_text,
86 coding_type_undecided,
87 coding_type_max
88 };
4ed46869 89
4ed46869 90
df7492f9 91/* Enumeration of end-of-line format type. */
4ed46869 92
df7492f9
KH
93enum end_of_line_type
94 {
95 eol_lf, /* Line-feed only, same as Emacs' internal
96 format. */
97 eol_crlf, /* Sequence of carriage-return and
98 line-feed. */
99 eol_cr, /* Carriage-return only. */
100 eol_any, /* Accept any of above. Produce line-feed
101 only. */
102 eol_undecided, /* This value is used to denote that the
103 eol-type is not yet undecided. */
104 eol_type_max
105 };
4ed46869 106
df7492f9 107/* Enumeration of index to an attribute vector of a coding system. */
4ed46869 108
df7492f9
KH
109enum coding_attr_index
110 {
111 coding_attr_base_name,
112 coding_attr_docstring,
113 coding_attr_mnemonic,
114 coding_attr_type,
115 coding_attr_charset_list,
116 coding_attr_ascii_compat,
117 coding_attr_decode_tbl,
118 coding_attr_encode_tbl,
404202e7 119 coding_attr_trans_tbl,
df7492f9
KH
120 coding_attr_post_read,
121 coding_attr_pre_write,
122 coding_attr_default_char,
8f924df7 123 coding_attr_for_unibyte,
df7492f9
KH
124 coding_attr_plist,
125
126 coding_attr_category,
127 coding_attr_safe_charsets,
128
129 /* The followings are extra attributes for each type. */
130 coding_attr_charset_valids,
131
132 coding_attr_ccl_decoder,
133 coding_attr_ccl_encoder,
134 coding_attr_ccl_valids,
135
136 coding_attr_iso_initial,
137 coding_attr_iso_usage,
138 coding_attr_iso_request,
139 coding_attr_iso_flags,
140
141 coding_attr_utf_16_bom,
142 coding_attr_utf_16_endian,
143
144 coding_attr_emacs_mule_full,
145
146 coding_attr_last_index
147 };
4ed46869 148
4ed46869 149
df7492f9
KH
150#define CODING_ATTR_BASE_NAME(attrs) AREF (attrs, coding_attr_base_name)
151#define CODING_ATTR_TYPE(attrs) AREF (attrs, coding_attr_type)
152#define CODING_ATTR_CHARSET_LIST(attrs) AREF (attrs, coding_attr_charset_list)
153#define CODING_ATTR_MNEMONIC(attrs) AREF (attrs, coding_attr_mnemonic)
154#define CODING_ATTR_DOCSTRING(attrs) AREF (attrs, coding_attr_docstring)
155#define CODING_ATTR_ASCII_COMPAT(attrs) AREF (attrs, coding_attr_ascii_compat)
156#define CODING_ATTR_DECODE_TBL(attrs) AREF (attrs, coding_attr_decode_tbl)
157#define CODING_ATTR_ENCODE_TBL(attrs) AREF (attrs, coding_attr_encode_tbl)
404202e7 158#define CODING_ATTR_TRANS_TBL(attrs) AREF (attrs, coding_attr_trans_tbl)
df7492f9
KH
159#define CODING_ATTR_POST_READ(attrs) AREF (attrs, coding_attr_post_read)
160#define CODING_ATTR_PRE_WRITE(attrs) AREF (attrs, coding_attr_pre_write)
161#define CODING_ATTR_DEFAULT_CHAR(attrs) AREF (attrs, coding_attr_default_char)
8f924df7 162#define CODING_ATTR_FOR_UNIBYTE(attrs) AREF (attrs, coding_attr_for_unibyte)
df7492f9
KH
163#define CODING_ATTR_FLUSHING(attrs) AREF (attrs, coding_attr_flushing)
164#define CODING_ATTR_PLIST(attrs) AREF (attrs, coding_attr_plist)
165#define CODING_ATTR_CATEGORY(attrs) AREF (attrs, coding_attr_category)
166#define CODING_ATTR_SAFE_CHARSETS(attrs)AREF (attrs, coding_attr_safe_charsets)
8ddb35b2 167
8ddb35b2 168
df7492f9
KH
169#define CODING_ID_ATTRS(id) \
170 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 0))
fbaa2ed9 171
df7492f9
KH
172#define CODING_ID_ALIASES(id) \
173 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 1))
c0c69d45 174
df7492f9
KH
175#define CODING_ID_EOL_TYPE(id) \
176 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 2))
658cc252 177
df7492f9
KH
178#define CODING_ID_NAME(id) \
179 (HASH_KEY (XHASH_TABLE (Vcoding_system_hash_table), id))
fbaa2ed9 180
df7492f9
KH
181#define CODING_SYSTEM_SPEC(coding_system_symbol) \
182 (Fgethash (coding_system_symbol, Vcoding_system_hash_table, Qnil))
4ed46869 183
df7492f9
KH
184#define CODING_SYSTEM_ID(coding_system_symbol) \
185 hash_lookup (XHASH_TABLE (Vcoding_system_hash_table), \
186 coding_system_symbol, NULL)
4ed46869 187
df7492f9
KH
188#define CODING_SYSTEM_P(coding_system_symbol) \
189 (! NILP (CODING_SYSTEM_SPEC (coding_system_symbol)))
4ed46869 190
8f924df7 191#define CHECK_CODING_SYSTEM(x) \
df7492f9
KH
192 do { \
193 if (!CODING_SYSTEM_P (x)) \
8f924df7 194 wrong_type_argument (Qcoding_system_p, (x)); \
df7492f9 195 } while (0)
658cc252 196
4ed46869 197
df7492f9
KH
198#define CHECK_CODING_SYSTEM_GET_SPEC(x, spec) \
199 do { \
200 spec = CODING_SYSTEM_SPEC (x); \
201 if (NILP (spec)) \
202 x = wrong_type_argument (Qcoding_system_p, (x)); \
203 } while (0)
e6de76f8 204
8ddb35b2 205
df7492f9
KH
206#define CHECK_CODING_SYSTEM_GET_ID(x, id) \
207 do \
208 { \
209 id = CODING_SYSTEM_ID (x); \
210 if (id < 0) \
211 x = wrong_type_argument (Qcoding_system_p, (x)); \
212 } while (0)
4ed46869 213
4ed46869
KH
214
215/*** GENERAL section ***/
216
df7492f9
KH
217/* Enumeration of result code of code conversion. */
218enum coding_result_code
4ed46869 219 {
df7492f9
KH
220 CODING_RESULT_SUCCESS,
221 CODING_RESULT_INSUFFICIENT_SRC,
222 CODING_RESULT_INSUFFICIENT_DST,
223 CODING_RESULT_INCONSISTENT_EOL,
63e11478 224 CODING_RESULT_INVALID_SRC,
df7492f9
KH
225 CODING_RESULT_INTERRUPT,
226 CODING_RESULT_INSUFFICIENT_MEM
4ed46869
KH
227 };
228
658cc252 229
3b2d77fe 230/* Macros used for the member `mode' of the struct coding_system. */
658cc252
KH
231
232/* If set, recover the original CR or LF of the already decoded text
233 when the decoding routine encounters an inconsistent eol format. */
234#define CODING_MODE_INHIBIT_INCONSISTENT_EOL 0x01
235
236/* If set, the decoding/encoding routines treat the current data as
5998373a 237 the last block of the whole text to be converted, and do the
55496054 238 appropriate finishing job. */
658cc252
KH
239#define CODING_MODE_LAST_BLOCK 0x02
240
241/* If set, it means that the current source text is in a buffer which
242 enables selective display. */
243#define CODING_MODE_SELECTIVE_DISPLAY 0x04
244
245/* This flag is used by the decoding/encoding routines on the fly. If
246 set, it means that right-to-left text is being processed. */
247#define CODING_MODE_DIRECTION 0x08
248
df7492f9
KH
249#define CODING_MODE_FIXED_DESTINATION 0x10
250
251#define CODING_MODE_SAFE_ENCODING 0x20
252
253/* Structure of the field `spec.iso_2022' in the structure
254 `coding_system'. */
255struct iso_2022_spec
4ed46869 256{
2ec49574 257 /* Bit-wise-or of CODING_ISO_FLAG_XXX. */
df7492f9 258 unsigned flags;
4ed46869 259
df7492f9
KH
260 /* The current graphic register invoked to each graphic plane. */
261 int current_invocation[2];
658cc252 262
df7492f9
KH
263 /* The current charset designated to each graphic register. The
264 value -1 means that not charset is designated, -2 means that
265 there was an invalid designation previously. */
266 int current_designation[4];
4ed46869 267
df7492f9
KH
268 /* Set to 1 temporarily only when graphic register 2 or 3 is invoked
269 by single-shift while encoding. */
270 int single_shifting;
4ed46869 271
df7492f9
KH
272 /* Set to 1 temporarily only when processing at beginning of line. */
273 int bol;
274};
4ed46869 275
df7492f9 276struct ccl_spec;
4ed46869 277
df7492f9
KH
278enum utf_16_bom_type
279 {
280 utf_16_detect_bom,
281 utf_16_without_bom,
282 utf_16_with_bom
283 };
279d9f7b 284
df7492f9
KH
285enum utf_16_endian_type
286 {
287 utf_16_big_endian,
288 utf_16_little_endian
289 };
279d9f7b 290
df7492f9
KH
291struct utf_16_spec
292{
293 enum utf_16_bom_type bom;
294 enum utf_16_endian_type endian;
295 int surrogate;
296};
279d9f7b 297
4fecac5c
KH
298struct coding_detection_info
299{
300 /* Values of these members are bitwise-OR of CATEGORY_MASK_XXXs. */
301 /* Which categories are already checked. */
302 int checked;
303 /* Which categories are strongly found. */
304 int found;
305 /* Which categories are rejected. */
306 int rejected;
307};
279d9f7b 308
279d9f7b 309
df7492f9
KH
310struct coding_system
311{
312 /* ID number of the coding system. This is an index to
313 Vcoding_system_hash_table. This value is set by
314 setup_coding_system. At the early stage of building time, this
315 value is -1 in the array coding_categories to indicate that no
316 coding-system of that category is yet defined. */
317 int id;
318
319 /* Flag bits of the coding system. The meaning of each bit is common
320 to all types of coding systems. */
321 int common_flags;
322
323 /* Mode bits of the coding system. See the comments of the macros
324 CODING_MODE_XXX. */
325 unsigned int mode;
450c60a5 326
4ed46869 327 /* Detailed information specific to each type of coding system. */
df7492f9 328 union
4ed46869 329 {
df7492f9
KH
330 struct iso_2022_spec iso_2022;
331 struct ccl_spec *ccl; /* Defined in ccl.h. */
332 struct utf_16_spec utf_16;
333 int emacs_mule_full_support;
4ed46869
KH
334 } spec;
335
df7492f9
KH
336 int max_charset_id;
337 char *safe_charsets;
658cc252 338
df7492f9
KH
339 /* The following two members specify how binary 8-bit code 128..255
340 are represented in source and destination text respectively. 1
341 means they are represented by 2-byte sequence, 0 means they are
342 represented by 1-byte as is (see the comment in character.h). */
811ea086
KH
343 unsigned src_multibyte : 1;
344 unsigned dst_multibyte : 1;
345
a137bb00
KH
346 /* How may heading bytes we can skip for decoding. This is set to
347 -1 in setup_coding_system, and updated by detect_coding. So,
348 when this is equal to the byte length of the text being
349 converted, we can skip the actual conversion process. */
df7492f9 350 int head_ascii;
658cc252
KH
351
352 /* The following members are set by encoding/decoding routine. */
df7492f9 353 EMACS_INT produced, produced_char, consumed, consumed_char;
658cc252 354
811ea086
KH
355 /* Number of error source data found in a decoding routine. */
356 int errors;
357
df7492f9
KH
358 /* Store the positions of error source data. */
359 EMACS_INT *error_positions;
e6a9a0bc 360
df7492f9
KH
361 /* Finish status of code conversion. */
362 enum coding_result_code result;
6041c9ce 363
658cc252
KH
364 /* The following members are all Lisp symbols. We don't have to
365 protect them from GC because the current garbage collection
366 doesn't relocate Lisp symbols. But, when it is changed, we must
367 find a way to protect them. */
368
df7492f9
KH
369 EMACS_INT src_pos, src_pos_byte, src_chars, src_bytes;
370 Lisp_Object src_object;
8f924df7 371 const unsigned char *source;
4ed46869 372
df7492f9
KH
373 EMACS_INT dst_pos, dst_pos_byte, dst_bytes;
374 Lisp_Object dst_object;
375 unsigned char *destination;
4ed46869 376
df7492f9 377 int chars_at_source;
4ed46869 378
df7492f9
KH
379 /* If an element is non-negative, it is a character code.
380
381 If it is in the range -128..-1, it is a 8-bit character code
382 minus 256.
383
384 If it is less than -128, it specifies the start of an annotation
385 chunk. The length of the chunk is -128 minus the value of the
386 element. The following elements are OFFSET, ANNOTATION-TYPE, and
387 a sequence of actual data for the annotation. OFFSET is a
388 character position offset from dst_pos or src_pos,
389 ANNOTATION-TYPE specfies the meaning of the annotation and how to
390 handle the following data.. */
391 int *charbuf;
392 int charbuf_size, charbuf_used;
393
394 /* Set to 1 if charbuf contains an annotation. */
395 int annotated;
4ed46869 396
df7492f9
KH
397 unsigned char carryover[64];
398 int carryover_bytes;
a5ee738b 399
df7492f9
KH
400 int default_char;
401
4fecac5c
KH
402 int (*detector) P_ ((struct coding_system *,
403 struct coding_detection_info *));
df7492f9
KH
404 void (*decoder) P_ ((struct coding_system *));
405 int (*encoder) P_ ((struct coding_system *));
406};
407
408/* Meanings of bits in the member `common_flags' of the structure
409 coding_system. The lowest 8 bits are reserved for various kind of
410 annotations (currently two of them are used). */
411#define CODING_ANNOTATION_MASK 0x00FF
412#define CODING_ANNOTATE_COMPOSITION_MASK 0x0001
413#define CODING_ANNOTATE_DIRECTION_MASK 0x0002
4fecac5c 414#define CODING_ANNOTATE_CHARSET_MASK 0x0003
df7492f9
KH
415#define CODING_FOR_UNIBYTE_MASK 0x0100
416#define CODING_REQUIRE_FLUSHING_MASK 0x0200
417#define CODING_REQUIRE_DECODING_MASK 0x0400
418#define CODING_REQUIRE_ENCODING_MASK 0x0800
419#define CODING_REQUIRE_DETECTION_MASK 0x1000
420#define CODING_RESET_AT_BOL_MASK 0x2000
421
422/* Return 1 if the coding context CODING requires annotaion
423 handling. */
424#define CODING_REQUIRE_ANNOTATION(coding) \
425 ((coding)->common_flags & CODING_ANNOTATION_MASK)
426
427/* Return 1 if the coding context CODING prefers decoding into unibyte. */
428#define CODING_FOR_UNIBYTE(coding) \
429 ((coding)->common_flags & CODING_FOR_UNIBYTE_MASK)
430
431/* Return 1 if the coding context CODING requires specific code to be
a5ee738b
KH
432 attached at the tail of converted text. */
433#define CODING_REQUIRE_FLUSHING(coding) \
434 ((coding)->common_flags & CODING_REQUIRE_FLUSHING_MASK)
435
df7492f9 436/* Return 1 if the coding context CODING requires code conversion on
a5ee738b
KH
437 decoding. */
438#define CODING_REQUIRE_DECODING(coding) \
811ea086
KH
439 ((coding)->dst_multibyte \
440 || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
a5ee738b 441
df7492f9
KH
442
443/* Return 1 if the coding context CODING requires code conversion on
a5ee738b 444 encoding. */
df7492f9
KH
445#define CODING_REQUIRE_ENCODING(coding) \
446 ((coding)->src_multibyte \
447 || (coding)->common_flags & CODING_REQUIRE_ENCODING_MASK \
448 || (coding)->mode & CODING_MODE_SELECTIVE_DISPLAY)
449
a5ee738b 450
df7492f9 451/* Return 1 if the coding context CODING requires some kind of code
a5ee738b
KH
452 detection. */
453#define CODING_REQUIRE_DETECTION(coding) \
454 ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK)
455
df7492f9 456/* Return 1 if the coding context CODING requires code conversion on
811ea086 457 decoding or some kind of code detection. */
658cc252 458#define CODING_MAY_REQUIRE_DECODING(coding) \
811ea086
KH
459 (CODING_REQUIRE_DECODING (coding) \
460 || CODING_REQUIRE_DETECTION (coding))
4ed46869 461
4ed46869
KH
462/* Macros to decode or encode a character of JISX0208 in SJIS. S1 and
463 S2 are the 1st and 2nd position-codes of JISX0208 in SJIS coding
464 system. C1 and C2 are the 1st and 2nd position codes of Emacs'
465 internal format. */
466
df7492f9
KH
467#define SJIS_TO_JIS(code) \
468 do { \
469 int s1, s2, j1, j2; \
470 \
471 s1 = (code) >> 8, s2 = (code) & 0xFF; \
472 \
473 if (s2 >= 0x9F) \
474 (j1 = s1 * 2 - (s1 >= 0xE0 ? 0x160 : 0xE0), \
475 j2 = s2 - 0x7E); \
476 else \
477 (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \
478 j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F)); \
479 (code) = (j1 << 8) | j2; \
4ed46869
KH
480 } while (0)
481
df7492f9
KH
482
483#define JIS_TO_SJIS(code) \
4ed46869 484 do { \
df7492f9
KH
485 int s1, s2, j1, j2; \
486 \
487 j1 = (code) >> 8, j2 = (code) & 0xFF; \
488 if (j1 & 1) \
489 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x71 : 0xB1), \
490 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F)); \
4ed46869 491 else \
df7492f9
KH
492 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \
493 s2 = j2 + 0x7E); \
5afaefc1 494 (code) = (s1 << 8) | s2; \
4ed46869
KH
495 } while (0)
496
df7492f9 497
290591c8
KH
498/* Encode the file name NAME using the specified coding system
499 for file names, if any. */
500#define ENCODE_FILE(name) \
501 (! NILP (Vfile_name_coding_system) \
502 && XFASTINT (Vfile_name_coding_system) != 0 \
afee9150 503 ? code_convert_string_norecord (name, Vfile_name_coding_system, 1) \
290591c8 504 : (! NILP (Vdefault_file_name_coding_system) \
afee9150
KH
505 && XFASTINT (Vdefault_file_name_coding_system) != 0 \
506 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \
290591c8
KH
507 : name))
508
df7492f9 509
290591c8
KH
510/* Decode the file name NAME using the specified coding system
511 for file names, if any. */
512#define DECODE_FILE(name) \
513 (! NILP (Vfile_name_coding_system) \
514 && XFASTINT (Vfile_name_coding_system) != 0 \
afee9150 515 ? code_convert_string_norecord (name, Vfile_name_coding_system, 0) \
290591c8 516 : (! NILP (Vdefault_file_name_coding_system) \
afee9150
KH
517 && XFASTINT (Vdefault_file_name_coding_system) != 0 \
518 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
290591c8
KH
519 : name))
520
df7492f9 521
2dfda962
JR
522#ifdef WINDOWSNT
523/* Encode the string STR using the specified coding system
524 for w32 system functions, if any. */
df7492f9
KH
525#define ENCODE_SYSTEM(str) \
526 (! NILP (Vlocale_coding_system) \
527 && XFASTINT (Vlocale_coding_system) != 0 \
528 ? code_convert_string_norecord (str, Vlocale_coding_system, 1) \
2dfda962
JR
529 : str)
530
531/* Decode the string STR using the specified coding system
532 for w32 system functions, if any. */
df7492f9
KH
533#define DECODE_SYSTEM(name) \
534 (! NILP (Vlocale_coding_system) \
535 && XFASTINT (Vlocale_coding_system) != 0 \
536 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \
2dfda962 537 : str)
cf29bf99
GM
538
539#else /* WINDOWSNT */
540
541#define ENCODE_SYSTEM(str) string_make_unibyte(str)
542#define DECODE_SYSTEM(name) name
543
544#endif /* !WINDOWSNT */
2dfda962 545
b3a208b0
DL
546/* Used by the gtk menu code. Note that this encodes utf-8, not
547 utf-8-emacs, so it's not a no-op. */
548#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1)
549
4ed46869 550/* Extern declarations. */
16869d7e 551extern Lisp_Object code_conversion_save P_ ((int, int));
c04809fb
AS
552extern int decoding_buffer_size P_ ((struct coding_system *, int));
553extern int encoding_buffer_size P_ ((struct coding_system *, int));
df7492f9
KH
554extern void setup_coding_system P_ ((Lisp_Object, struct coding_system *));
555extern void detect_coding P_ ((struct coding_system *));
511dd8e7 556extern Lisp_Object code_convert_region P_ ((Lisp_Object, Lisp_Object,
df7492f9
KH
557 Lisp_Object, Lisp_Object,
558 int, int));
559extern Lisp_Object code_convert_string P_ ((Lisp_Object, Lisp_Object,
560 Lisp_Object, int, int, int));
eb545596
DL
561extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object,
562 int));
df7492f9
KH
563extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object));
564extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object));
565
566extern int decode_coding_gap P_ ((struct coding_system *,
567 EMACS_INT, EMACS_INT));
568extern int encode_coding_gap P_ ((struct coding_system *,
569 EMACS_INT, EMACS_INT));
570extern void decode_coding_object P_ ((struct coding_system *,
571 Lisp_Object, EMACS_INT, EMACS_INT,
572 EMACS_INT, EMACS_INT, Lisp_Object));
573extern void encode_coding_object P_ ((struct coding_system *,
574 Lisp_Object, EMACS_INT, EMACS_INT,
575 EMACS_INT, EMACS_INT, Lisp_Object));
576
577#define decode_coding_region(coding, from, to) \
578 decode_coding_object (coding, Fcurrent_buffer (), \
579 from, CHAR_TO_BYTE (from), \
580 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
581
582
583#define encode_coding_region(coding, from, to) \
584 encode_coding_object (coding, Fcurrent_buffer (), \
585 from, CHAR_TO_BYTE (from), \
586 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
587
588
589#define decode_coding_string(coding, string, nocopy) \
590 decode_coding_object (coding, string, 0, 0, XSTRING (string)->size, \
591 STRING_BYTES (XSTRING (string)), Qt)
592
593#define encode_coding_string(coding, string, nocopy) \
594 (encode_coding_object (coding, string, 0, 0, XSTRING (string)->size, \
595 STRING_BYTES (XSTRING (string)), Qt), \
596 (coding)->dst_object)
597
598
599#define decode_coding_c_string(coding, src, bytes, dst_object) \
600 do { \
601 (coding)->source = (src); \
602 (coding)->src_chars = (coding)->src_bytes = (bytes); \
603 decode_coding_object ((coding), Qnil, 0, 0, (bytes), (bytes), \
604 (dst_object)); \
605 } while (0)
606
607
608extern Lisp_Object preferred_coding_system P_ (());
609
610
8f924df7
KH
611extern Lisp_Object Qutf_8, Qutf_8_emacs;
612
4ed46869 613extern Lisp_Object Qcoding_system, Qeol_type, Qcoding_category_index;
df7492f9
KH
614extern Lisp_Object Qcoding_system_p;
615extern Lisp_Object Qraw_text, Qemacs_mule, Qno_conversion, Qundecided;
616extern Lisp_Object Qiso_2022;
4ed46869 617extern Lisp_Object Qbuffer_file_coding_system;
df7492f9
KH
618
619extern Lisp_Object Qunix, Qdos, Qmac;
4ed46869 620
f967223b
KH
621extern Lisp_Object Qtranslation_table;
622extern Lisp_Object Qtranslation_table_id;
ab45712c 623
20ee919e
EZ
624/* Mnemonic strings to indicate each type of end-of-line. */
625extern Lisp_Object eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac;
626/* Mnemonic string to indicate type of end-of-line is not yet decided. */
627extern Lisp_Object eol_mnemonic_undecided;
4ed46869 628
4ed46869
KH
629#ifdef emacs
630extern Lisp_Object Qfile_coding_system;
631extern Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
632extern Lisp_Object Qstart_process, Qopen_network_stream;
d008a7cc 633extern Lisp_Object Qwrite_region;
4ed46869 634
68c45bf0
PE
635extern char *emacs_strerror P_ ((int));
636
4ed46869
KH
637/* Coding-system for reading files and receiving data from process. */
638extern Lisp_Object Vcoding_system_for_read;
639/* Coding-system for writing files and sending data to process. */
640extern Lisp_Object Vcoding_system_for_write;
641/* Coding-system actually used in the latest I/O. */
642extern Lisp_Object Vlast_coding_system_used;
68c45bf0
PE
643/* Coding-system to use with system messages (e.g. strerror). */
644extern Lisp_Object Vlocale_coding_system;
4ed46869 645
77a9bc9a
EZ
646/* If non-zero, process buffer inherits the coding system used to decode
647 the subprocess output. */
648extern int inherit_process_coding_system;
649
4ed46869
KH
650/* Coding-system to be used for encoding terminal output. This
651 structure contains information of a coding-system specified by the
652 function `set-terminal-coding-system'. */
653extern struct coding_system terminal_coding;
654
fbaa2ed9
KH
655/* Coding system to be used to encode text for terminal display when
656 terminal coding system is nil. */
657extern struct coding_system safe_terminal_coding;
658
4ed46869
KH
659/* Coding-system of what is sent from terminal keyboard. This
660 structure contains information of a coding-system specified by the
661 function `set-keyboard-coding-system'. */
662extern struct coding_system keyboard_coding;
663
a5825a24
KH
664/* Default coding systems used for process I/O. */
665extern Lisp_Object Vdefault_process_coding_system;
4ed46869 666
df7492f9 667/* Function to call to force a user to force select a propert coding
658cc252
KH
668 system. */
669extern Lisp_Object Vselect_safe_coding_system_function;
670
6926d591
KH
671/* If nonzero, on writing a file, Vselect_safe_coding_system_function
672 is called even if Vcoding_system_for_write is non-nil. */
673extern int coding_system_require_warning;
674
31406df1
RS
675/* Coding system for file names, or nil if none. */
676extern Lisp_Object Vfile_name_coding_system;
677
678/* Coding system for file names used only when
679 Vfile_name_coding_system is nil. */
680extern Lisp_Object Vdefault_file_name_coding_system;
2dfda962 681
4ed46869
KH
682#endif
683
d008a7cc
GM
684/* Error signaled when there's a problem with detecting coding system */
685extern Lisp_Object Qcoding_system_error;
686
df7492f9
KH
687extern char emacs_mule_bytes[256];
688extern int emacs_mule_string_char P_ ((unsigned char *));
689
6f776e81 690#endif /* EMACS_CODING_H */