*** empty log message ***
[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
6e58724e
KH
482#define SJIS_TO_JIS2(code) \
483 do { \
484 int s1, s2, j1, j2; \
485 \
486 s1 = (code) >> 8, s2 = (code) & 0xFF; \
487 \
488 if (s2 >= 0x9F) \
489 { \
490 j1 = (s1 == 0xF0 ? 0x28 \
491 : s1 == 0xF1 ? 0x24 \
492 : s1 == 0xF2 ? 0x2C \
493 : s1 == 0xF3 ? 0x2E \
494 : 0x6E + (s1 - 0xF4) * 2); \
495 j2 = s2 - 0x7E; \
496 } \
497 else \
498 { \
499 j1 = (s1 <= 0xF2 ? 0x21 + (s1 - 0xF0) * 2 \
500 : s1 <= 0xF4 ? 0x2D + (s1 - 0xF3) * 2 \
501 : 0x6F + (s1 - 0xF5) * 2); \
502 j2 = s2 - ((s2 >= 0x7F ? 0x20 : 0x1F)); \
503 } \
504 (code) = (j1 << 8) | j2; \
505 } while (0)
506
df7492f9
KH
507
508#define JIS_TO_SJIS(code) \
4ed46869 509 do { \
df7492f9
KH
510 int s1, s2, j1, j2; \
511 \
512 j1 = (code) >> 8, j2 = (code) & 0xFF; \
513 if (j1 & 1) \
514 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x71 : 0xB1), \
515 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F)); \
4ed46869 516 else \
df7492f9
KH
517 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \
518 s2 = j2 + 0x7E); \
5afaefc1 519 (code) = (s1 << 8) | s2; \
4ed46869
KH
520 } while (0)
521
6e58724e
KH
522#define JIS_TO_SJIS2(code) \
523 do { \
524 int s1, s2, j1, j2; \
525 \
526 j1 = (code) >> 8, j2 = (code) & 0xFF; \
527 if (j1 & 1) \
528 { \
529 s1 = (j1 <= 0x25 ? 0xF0 + (j1 - 0x21) / 2 \
530 : j1 <= 0x27 ? 0xF3 + (j1 - 0x2D) / 2 \
531 : 0xF5 + (j1 - 0x6F) / 2); \
532 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F); \
533 } \
534 else \
535 { \
536 s1 = (j1 == 0x28 ? 0xF0 \
537 : j1 == 0x24 ? 0xF1 \
538 : j1 == 0x2C ? 0xF2 \
539 : j1 == 0x2E ? 0xF3 \
540 : 0xF4 + (j1 - 0x6E) / 2); \
541 s2 = j2 + 0x7E; \
542 } \
543 (code) = (s1 << 8) | s2; \
544 } while (0)
df7492f9 545
290591c8
KH
546/* Encode the file name NAME using the specified coding system
547 for file names, if any. */
548#define ENCODE_FILE(name) \
549 (! NILP (Vfile_name_coding_system) \
550 && XFASTINT (Vfile_name_coding_system) != 0 \
afee9150 551 ? code_convert_string_norecord (name, Vfile_name_coding_system, 1) \
290591c8 552 : (! NILP (Vdefault_file_name_coding_system) \
afee9150
KH
553 && XFASTINT (Vdefault_file_name_coding_system) != 0 \
554 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \
290591c8
KH
555 : name))
556
df7492f9 557
290591c8
KH
558/* Decode the file name NAME using the specified coding system
559 for file names, if any. */
560#define DECODE_FILE(name) \
561 (! NILP (Vfile_name_coding_system) \
562 && XFASTINT (Vfile_name_coding_system) != 0 \
afee9150 563 ? code_convert_string_norecord (name, Vfile_name_coding_system, 0) \
290591c8 564 : (! NILP (Vdefault_file_name_coding_system) \
afee9150
KH
565 && XFASTINT (Vdefault_file_name_coding_system) != 0 \
566 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
290591c8
KH
567 : name))
568
df7492f9 569
2dfda962
JR
570#ifdef WINDOWSNT
571/* Encode the string STR using the specified coding system
572 for w32 system functions, if any. */
df7492f9
KH
573#define ENCODE_SYSTEM(str) \
574 (! NILP (Vlocale_coding_system) \
575 && XFASTINT (Vlocale_coding_system) != 0 \
576 ? code_convert_string_norecord (str, Vlocale_coding_system, 1) \
2dfda962
JR
577 : str)
578
579/* Decode the string STR using the specified coding system
580 for w32 system functions, if any. */
df7492f9
KH
581#define DECODE_SYSTEM(name) \
582 (! NILP (Vlocale_coding_system) \
583 && XFASTINT (Vlocale_coding_system) != 0 \
584 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \
2dfda962 585 : str)
cf29bf99
GM
586
587#else /* WINDOWSNT */
588
589#define ENCODE_SYSTEM(str) string_make_unibyte(str)
590#define DECODE_SYSTEM(name) name
591
592#endif /* !WINDOWSNT */
2dfda962 593
b3a208b0
DL
594/* Used by the gtk menu code. Note that this encodes utf-8, not
595 utf-8-emacs, so it's not a no-op. */
596#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1)
597
4ed46869 598/* Extern declarations. */
16869d7e 599extern Lisp_Object code_conversion_save P_ ((int, int));
c04809fb
AS
600extern int decoding_buffer_size P_ ((struct coding_system *, int));
601extern int encoding_buffer_size P_ ((struct coding_system *, int));
df7492f9
KH
602extern void setup_coding_system P_ ((Lisp_Object, struct coding_system *));
603extern void detect_coding P_ ((struct coding_system *));
511dd8e7 604extern Lisp_Object code_convert_region P_ ((Lisp_Object, Lisp_Object,
df7492f9
KH
605 Lisp_Object, Lisp_Object,
606 int, int));
607extern Lisp_Object code_convert_string P_ ((Lisp_Object, Lisp_Object,
608 Lisp_Object, int, int, int));
eb545596
DL
609extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object,
610 int));
df7492f9
KH
611extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object));
612extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object));
613
614extern int decode_coding_gap P_ ((struct coding_system *,
615 EMACS_INT, EMACS_INT));
616extern int encode_coding_gap P_ ((struct coding_system *,
617 EMACS_INT, EMACS_INT));
618extern void decode_coding_object P_ ((struct coding_system *,
619 Lisp_Object, EMACS_INT, EMACS_INT,
620 EMACS_INT, EMACS_INT, Lisp_Object));
621extern void encode_coding_object P_ ((struct coding_system *,
622 Lisp_Object, EMACS_INT, EMACS_INT,
623 EMACS_INT, EMACS_INT, Lisp_Object));
624
625#define decode_coding_region(coding, from, to) \
626 decode_coding_object (coding, Fcurrent_buffer (), \
627 from, CHAR_TO_BYTE (from), \
628 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
629
630
631#define encode_coding_region(coding, from, to) \
632 encode_coding_object (coding, Fcurrent_buffer (), \
633 from, CHAR_TO_BYTE (from), \
634 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
635
636
637#define decode_coding_string(coding, string, nocopy) \
638 decode_coding_object (coding, string, 0, 0, XSTRING (string)->size, \
639 STRING_BYTES (XSTRING (string)), Qt)
640
641#define encode_coding_string(coding, string, nocopy) \
642 (encode_coding_object (coding, string, 0, 0, XSTRING (string)->size, \
643 STRING_BYTES (XSTRING (string)), Qt), \
644 (coding)->dst_object)
645
646
647#define decode_coding_c_string(coding, src, bytes, dst_object) \
648 do { \
649 (coding)->source = (src); \
650 (coding)->src_chars = (coding)->src_bytes = (bytes); \
651 decode_coding_object ((coding), Qnil, 0, 0, (bytes), (bytes), \
652 (dst_object)); \
653 } while (0)
654
655
656extern Lisp_Object preferred_coding_system P_ (());
657
658
8f924df7
KH
659extern Lisp_Object Qutf_8, Qutf_8_emacs;
660
4ed46869 661extern Lisp_Object Qcoding_system, Qeol_type, Qcoding_category_index;
df7492f9
KH
662extern Lisp_Object Qcoding_system_p;
663extern Lisp_Object Qraw_text, Qemacs_mule, Qno_conversion, Qundecided;
664extern Lisp_Object Qiso_2022;
4ed46869 665extern Lisp_Object Qbuffer_file_coding_system;
df7492f9
KH
666
667extern Lisp_Object Qunix, Qdos, Qmac;
4ed46869 668
f967223b
KH
669extern Lisp_Object Qtranslation_table;
670extern Lisp_Object Qtranslation_table_id;
ab45712c 671
20ee919e
EZ
672/* Mnemonic strings to indicate each type of end-of-line. */
673extern Lisp_Object eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac;
674/* Mnemonic string to indicate type of end-of-line is not yet decided. */
675extern Lisp_Object eol_mnemonic_undecided;
4ed46869 676
4ed46869
KH
677#ifdef emacs
678extern Lisp_Object Qfile_coding_system;
679extern Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
680extern Lisp_Object Qstart_process, Qopen_network_stream;
d008a7cc 681extern Lisp_Object Qwrite_region;
4ed46869 682
68c45bf0
PE
683extern char *emacs_strerror P_ ((int));
684
4ed46869
KH
685/* Coding-system for reading files and receiving data from process. */
686extern Lisp_Object Vcoding_system_for_read;
687/* Coding-system for writing files and sending data to process. */
688extern Lisp_Object Vcoding_system_for_write;
689/* Coding-system actually used in the latest I/O. */
690extern Lisp_Object Vlast_coding_system_used;
68c45bf0
PE
691/* Coding-system to use with system messages (e.g. strerror). */
692extern Lisp_Object Vlocale_coding_system;
4ed46869 693
77a9bc9a
EZ
694/* If non-zero, process buffer inherits the coding system used to decode
695 the subprocess output. */
696extern int inherit_process_coding_system;
697
4ed46869
KH
698/* Coding-system to be used for encoding terminal output. This
699 structure contains information of a coding-system specified by the
700 function `set-terminal-coding-system'. */
701extern struct coding_system terminal_coding;
702
fbaa2ed9
KH
703/* Coding system to be used to encode text for terminal display when
704 terminal coding system is nil. */
705extern struct coding_system safe_terminal_coding;
706
4ed46869
KH
707/* Coding-system of what is sent from terminal keyboard. This
708 structure contains information of a coding-system specified by the
709 function `set-keyboard-coding-system'. */
710extern struct coding_system keyboard_coding;
711
a5825a24
KH
712/* Default coding systems used for process I/O. */
713extern Lisp_Object Vdefault_process_coding_system;
4ed46869 714
df7492f9 715/* Function to call to force a user to force select a propert coding
658cc252
KH
716 system. */
717extern Lisp_Object Vselect_safe_coding_system_function;
718
6926d591
KH
719/* If nonzero, on writing a file, Vselect_safe_coding_system_function
720 is called even if Vcoding_system_for_write is non-nil. */
721extern int coding_system_require_warning;
722
31406df1
RS
723/* Coding system for file names, or nil if none. */
724extern Lisp_Object Vfile_name_coding_system;
725
726/* Coding system for file names used only when
727 Vfile_name_coding_system is nil. */
728extern Lisp_Object Vdefault_file_name_coding_system;
2dfda962 729
4ed46869
KH
730#endif
731
d008a7cc
GM
732/* Error signaled when there's a problem with detecting coding system */
733extern Lisp_Object Qcoding_system_error;
734
df7492f9
KH
735extern char emacs_mule_bytes[256];
736extern int emacs_mule_string_char P_ ((unsigned char *));
737
6f776e81 738#endif /* EMACS_CODING_H */