Another place to produce debugging output in etags
[emacs.git] / src / coding.h
blob8ed851d99ff68cd0d34af0441b53ce1ebffa7a8e
1 /* Header for coding system handler.
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 National Institute of Advanced Industrial Science and Technology (AIST)
6 Registration Number H14PRO021
7 Copyright (C) 2003
8 National Institute of Advanced Industrial Science and Technology (AIST)
9 Registration Number H13PRO009
11 This file is part of GNU Emacs.
13 GNU Emacs is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or (at
16 your option) any later version.
18 GNU Emacs is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26 #ifndef EMACS_CODING_H
27 #define EMACS_CODING_H
29 #include "lisp.h"
31 /* Index to arguments of Fdefine_coding_system_internal. */
33 enum define_coding_system_arg_index
35 coding_arg_name,
36 coding_arg_mnemonic,
37 coding_arg_coding_type,
38 coding_arg_charset_list,
39 coding_arg_ascii_compatible_p,
40 coding_arg_decode_translation_table,
41 coding_arg_encode_translation_table,
42 coding_arg_post_read_conversion,
43 coding_arg_pre_write_conversion,
44 coding_arg_default_char,
45 coding_arg_for_unibyte,
46 coding_arg_plist,
47 coding_arg_eol_type,
48 coding_arg_max
51 enum define_coding_iso2022_arg_index
53 coding_arg_iso2022_initial = coding_arg_max,
54 coding_arg_iso2022_reg_usage,
55 coding_arg_iso2022_request,
56 coding_arg_iso2022_flags,
57 coding_arg_iso2022_max
60 enum define_coding_utf8_arg_index
62 coding_arg_utf8_bom = coding_arg_max,
63 coding_arg_utf8_max
66 enum define_coding_utf16_arg_index
68 coding_arg_utf16_bom = coding_arg_max,
69 coding_arg_utf16_endian,
70 coding_arg_utf16_max
73 enum define_coding_ccl_arg_index
75 coding_arg_ccl_decoder = coding_arg_max,
76 coding_arg_ccl_encoder,
77 coding_arg_ccl_valids,
78 coding_arg_ccl_max
81 enum define_coding_undecided_arg_index
83 coding_arg_undecided_inhibit_null_byte_detection = coding_arg_max,
84 coding_arg_undecided_inhibit_iso_escape_detection,
85 coding_arg_undecided_prefer_utf_8,
86 coding_arg_undecided_max
89 /* Hash table for all coding systems. Keys are coding system symbols
90 and values are spec vectors of the corresponding coding system. A
91 spec vector has the form [ ATTRS ALIASES EOL-TYPE ]. ATTRS is a
92 vector of attribute of the coding system. ALIASES is a list of
93 aliases (symbols) of the coding system. EOL-TYPE is `unix', `dos',
94 `mac' or a vector of coding systems (symbols). */
96 extern Lisp_Object Vcoding_system_hash_table;
99 /* Enumeration of index to an attribute vector of a coding system. */
101 enum coding_attr_index
103 coding_attr_base_name,
104 coding_attr_docstring,
105 coding_attr_mnemonic,
106 coding_attr_type,
107 coding_attr_charset_list,
108 coding_attr_ascii_compat,
109 coding_attr_decode_tbl,
110 coding_attr_encode_tbl,
111 coding_attr_trans_tbl,
112 coding_attr_post_read,
113 coding_attr_pre_write,
114 coding_attr_default_char,
115 coding_attr_for_unibyte,
116 coding_attr_plist,
118 coding_attr_category,
119 coding_attr_safe_charsets,
121 /* The followings are extra attributes for each type. */
122 coding_attr_charset_valids,
124 coding_attr_ccl_decoder,
125 coding_attr_ccl_encoder,
126 coding_attr_ccl_valids,
128 coding_attr_iso_initial,
129 coding_attr_iso_usage,
130 coding_attr_iso_request,
131 coding_attr_iso_flags,
133 coding_attr_utf_bom,
134 coding_attr_utf_16_endian,
136 coding_attr_emacs_mule_full,
138 coding_attr_undecided_inhibit_null_byte_detection,
139 coding_attr_undecided_inhibit_iso_escape_detection,
140 coding_attr_undecided_prefer_utf_8,
142 coding_attr_last_index
146 /* Macros to access an element of an attribute vector. */
148 #define CODING_ATTR_BASE_NAME(attrs) AREF (attrs, coding_attr_base_name)
149 #define CODING_ATTR_TYPE(attrs) AREF (attrs, coding_attr_type)
150 #define CODING_ATTR_CHARSET_LIST(attrs) AREF (attrs, coding_attr_charset_list)
151 #define CODING_ATTR_MNEMONIC(attrs) AREF (attrs, coding_attr_mnemonic)
152 #define CODING_ATTR_DOCSTRING(attrs) AREF (attrs, coding_attr_docstring)
153 #define CODING_ATTR_ASCII_COMPAT(attrs) AREF (attrs, coding_attr_ascii_compat)
154 #define CODING_ATTR_DECODE_TBL(attrs) AREF (attrs, coding_attr_decode_tbl)
155 #define CODING_ATTR_ENCODE_TBL(attrs) AREF (attrs, coding_attr_encode_tbl)
156 #define CODING_ATTR_TRANS_TBL(attrs) AREF (attrs, coding_attr_trans_tbl)
157 #define CODING_ATTR_POST_READ(attrs) AREF (attrs, coding_attr_post_read)
158 #define CODING_ATTR_PRE_WRITE(attrs) AREF (attrs, coding_attr_pre_write)
159 #define CODING_ATTR_DEFAULT_CHAR(attrs) AREF (attrs, coding_attr_default_char)
160 #define CODING_ATTR_FOR_UNIBYTE(attrs) AREF (attrs, coding_attr_for_unibyte)
161 #define CODING_ATTR_PLIST(attrs) AREF (attrs, coding_attr_plist)
162 #define CODING_ATTR_CATEGORY(attrs) AREF (attrs, coding_attr_category)
163 #define CODING_ATTR_SAFE_CHARSETS(attrs)AREF (attrs, coding_attr_safe_charsets)
166 /* Return the name of a coding system specified by ID. */
167 #define CODING_ID_NAME(id) \
168 (HASH_KEY (XHASH_TABLE (Vcoding_system_hash_table), id))
170 /* Return the attribute vector of a coding system specified by ID. */
172 #define CODING_ID_ATTRS(id) \
173 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 0))
175 /* Return the list of aliases of a coding system specified by ID. */
177 #define CODING_ID_ALIASES(id) \
178 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 1))
180 /* Return the eol-type of a coding system specified by ID. */
182 #define CODING_ID_EOL_TYPE(id) \
183 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 2))
186 /* Return the spec vector of CODING_SYSTEM_SYMBOL. */
188 #define CODING_SYSTEM_SPEC(coding_system_symbol) \
189 (Fgethash (coding_system_symbol, Vcoding_system_hash_table, Qnil))
192 /* Return the ID of CODING_SYSTEM_SYMBOL. */
194 #define CODING_SYSTEM_ID(coding_system_symbol) \
195 hash_lookup (XHASH_TABLE (Vcoding_system_hash_table), \
196 coding_system_symbol, NULL)
198 /* Return true if CODING_SYSTEM_SYMBOL is a coding system. */
200 #define CODING_SYSTEM_P(coding_system_symbol) \
201 (CODING_SYSTEM_ID (coding_system_symbol) >= 0 \
202 || (! NILP (coding_system_symbol) \
203 && ! NILP (Fcoding_system_p (coding_system_symbol))))
205 /* Check if X is a coding system or not. */
207 #define CHECK_CODING_SYSTEM(x) \
208 do { \
209 if (CODING_SYSTEM_ID (x) < 0 \
210 && NILP (Fcheck_coding_system (x))) \
211 wrong_type_argument (Qcoding_system_p, (x)); \
212 } while (false)
215 /* Check if X is a coding system or not. If it is, set SEPC to the
216 spec vector of the coding system. */
218 #define CHECK_CODING_SYSTEM_GET_SPEC(x, spec) \
219 do { \
220 spec = CODING_SYSTEM_SPEC (x); \
221 if (NILP (spec)) \
223 Fcheck_coding_system (x); \
224 spec = CODING_SYSTEM_SPEC (x); \
226 if (NILP (spec)) \
227 wrong_type_argument (Qcoding_system_p, (x)); \
228 } while (false)
231 /* Check if X is a coding system or not. If it is, set ID to the
232 ID of the coding system. */
234 #define CHECK_CODING_SYSTEM_GET_ID(x, id) \
235 do \
237 id = CODING_SYSTEM_ID (x); \
238 if (id < 0) \
240 Fcheck_coding_system (x); \
241 id = CODING_SYSTEM_ID (x); \
243 if (id < 0) \
244 wrong_type_argument (Qcoding_system_p, (x)); \
245 } while (false)
248 /*** GENERAL section ***/
250 /* Enumeration of result code of code conversion. */
251 enum coding_result_code
253 CODING_RESULT_SUCCESS,
254 CODING_RESULT_INSUFFICIENT_SRC,
255 CODING_RESULT_INSUFFICIENT_DST,
256 CODING_RESULT_INVALID_SRC,
257 CODING_RESULT_INTERRUPT
261 /* Macros used for the member `mode' of the struct coding_system. */
263 /* If set, the decoding/encoding routines treat the current data as
264 the last block of the whole text to be converted, and do the
265 appropriate finishing job. */
266 #define CODING_MODE_LAST_BLOCK 0x01
268 /* If set, it means that the current source text is in a buffer which
269 enables selective display. */
270 #define CODING_MODE_SELECTIVE_DISPLAY 0x02
272 /* This flag is used by the decoding/encoding routines on the fly. If
273 set, it means that right-to-left text is being processed. */
274 #define CODING_MODE_DIRECTION 0x04
276 #define CODING_MODE_FIXED_DESTINATION 0x08
278 /* If set, it means that the encoding routines produces some safe
279 ASCII characters (usually '?') for unsupported characters. */
280 #define CODING_MODE_SAFE_ENCODING 0x10
282 /* For handling composition sequence. */
283 #include "composite.h"
285 enum composition_state
287 COMPOSING_NO,
288 COMPOSING_CHAR,
289 COMPOSING_RULE,
290 COMPOSING_COMPONENT_CHAR,
291 COMPOSING_COMPONENT_RULE
294 /* Structure for the current composition status. */
295 struct composition_status
297 enum composition_state state;
298 enum composition_method method;
299 bool old_form; /* true if pre-21 form */
300 int length; /* number of elements produced in charbuf */
301 int nchars; /* number of characters composed */
302 int ncomps; /* number of composition components */
303 /* Maximum carryover is for the case of COMPOSITION_WITH_RULE_ALTCHARS.
304 See the comment in coding.c. */
305 int carryover[4 /* annotation header */
306 + MAX_COMPOSITION_COMPONENTS * 3 - 2 /* ALTs and RULEs */
307 + 2 /* intermediate -1 -1 */
308 + MAX_COMPOSITION_COMPONENTS /* CHARs */
313 /* Structure of the field `spec.iso_2022' in the structure
314 `coding_system'. */
315 struct iso_2022_spec
317 /* Bit-wise-or of CODING_ISO_FLAG_XXX. */
318 unsigned flags;
320 /* The current graphic register invoked to each graphic plane. */
321 int current_invocation[2];
323 /* The current charset designated to each graphic register. The
324 value -1 means that not charset is designated, -2 means that
325 there was an invalid designation previously. */
326 int current_designation[4];
328 /* If positive, we are now scanning CTEXT extended segment. */
329 int ctext_extended_segment_len;
331 /* True temporarily only when graphic register 2 or 3 is invoked by
332 single-shift while encoding. */
333 bool_bf single_shifting : 1;
335 /* True temporarily only when processing at beginning of line. */
336 bool_bf bol : 1;
338 /* If true, we are now scanning embedded UTF-8 sequence. */
339 bool_bf embedded_utf_8 : 1;
341 /* The current composition. */
342 struct composition_status cmp_status;
345 struct emacs_mule_spec
347 struct composition_status cmp_status;
350 struct undecided_spec
352 /* Inhibit null byte detection. 1 means always inhibit,
353 -1 means do not inhibit, 0 means rely on user variable. */
354 int inhibit_nbd;
356 /* Inhibit ISO escape detection. -1, 0, 1 as above. */
357 int inhibit_ied;
359 /* Prefer UTF-8 when the input could be other encodings. */
360 bool prefer_utf_8;
363 enum utf_bom_type
365 utf_detect_bom,
366 utf_without_bom,
367 utf_with_bom
370 enum utf_16_endian_type
372 utf_16_big_endian,
373 utf_16_little_endian
376 struct utf_16_spec
378 enum utf_bom_type bom;
379 enum utf_16_endian_type endian;
380 int surrogate;
383 struct coding_detection_info
385 /* Values of these members are bitwise-OR of CATEGORY_MASK_XXXs. */
386 /* Which categories are already checked. */
387 int checked;
388 /* Which categories are strongly found. */
389 int found;
390 /* Which categories are rejected. */
391 int rejected;
395 struct coding_system
397 /* ID number of the coding system. This is an index to
398 Vcoding_system_hash_table. This value is set by
399 setup_coding_system. At the early stage of building time, this
400 value is -1 in the array coding_categories to indicate that no
401 coding-system of that category is yet defined. */
402 ptrdiff_t id;
404 /* Flag bits of the coding system. The meaning of each bit is common
405 to all types of coding systems. */
406 unsigned common_flags : 14;
408 /* Mode bits of the coding system. See the comments of the macros
409 CODING_MODE_XXX. */
410 unsigned mode : 5;
412 /* The following two members specify how binary 8-bit code 128..255
413 are represented in source and destination text respectively. True
414 means they are represented by 2-byte sequence, false means they are
415 represented by 1-byte as is (see the comment in character.h). */
416 bool_bf src_multibyte : 1;
417 bool_bf dst_multibyte : 1;
419 /* True if the source of conversion is not in the member
420 `charbuf', but at `src_object'. */
421 bool_bf chars_at_source : 1;
423 /* Nonzero if the result of conversion is in `destination'
424 buffer rather than in `dst_object'. */
425 bool_bf raw_destination : 1;
427 /* Set to true if charbuf contains an annotation. */
428 bool_bf annotated : 1;
430 /* Used internally in coding.c. See the comment of detect_ascii. */
431 unsigned eol_seen : 3;
433 /* Finish status of code conversion. */
434 ENUM_BF (coding_result_code) result : 3;
436 int max_charset_id;
438 /* Detailed information specific to each type of coding system. */
439 union
441 struct iso_2022_spec iso_2022;
442 struct ccl_spec *ccl; /* Defined in ccl.h. */
443 struct utf_16_spec utf_16;
444 enum utf_bom_type utf_8_bom;
445 struct emacs_mule_spec emacs_mule;
446 struct undecided_spec undecided;
447 } spec;
449 unsigned char *safe_charsets;
451 /* How may heading bytes we can skip for decoding. This is set to
452 -1 in setup_coding_system, and updated by detect_coding. So,
453 when this is equal to the byte length of the text being
454 converted, we can skip the actual conversion process except for
455 the eol format. */
456 ptrdiff_t head_ascii;
458 /* How many bytes/chars at the source are detected as valid utf-8
459 sequence. Set by detect_coding_utf_8. */
460 ptrdiff_t detected_utf8_bytes, detected_utf8_chars;
462 /* The following members are set by encoding/decoding routine. */
463 ptrdiff_t produced, produced_char, consumed, consumed_char;
465 ptrdiff_t src_pos, src_pos_byte, src_chars, src_bytes;
466 Lisp_Object src_object;
467 const unsigned char *source;
469 ptrdiff_t dst_pos, dst_pos_byte, dst_bytes;
470 Lisp_Object dst_object;
471 unsigned char *destination;
473 /* If an element is non-negative, it is a character code.
475 If it is in the range -128..-1, it is a 8-bit character code
476 minus 256.
478 If it is less than -128, it specifies the start of an annotation
479 chunk. The length of the chunk is -128 minus the value of the
480 element. The following elements are OFFSET, ANNOTATION-TYPE, and
481 a sequence of actual data for the annotation. OFFSET is a
482 character position offset from dst_pos or src_pos,
483 ANNOTATION-TYPE specifies the meaning of the annotation and how to
484 handle the following data.. */
485 int *charbuf;
486 int charbuf_size, charbuf_used;
488 unsigned char carryover[64];
489 int carryover_bytes;
491 int default_char;
493 bool (*detector) (struct coding_system *, struct coding_detection_info *);
494 void (*decoder) (struct coding_system *);
495 bool (*encoder) (struct coding_system *);
498 /* Meanings of bits in the member `common_flags' of the structure
499 coding_system. The lowest 8 bits are reserved for various kind of
500 annotations (currently two of them are used). */
501 #define CODING_ANNOTATION_MASK 0x00FF
502 #define CODING_ANNOTATE_COMPOSITION_MASK 0x0001
503 #define CODING_ANNOTATE_DIRECTION_MASK 0x0002
504 #define CODING_ANNOTATE_CHARSET_MASK 0x0003
505 #define CODING_FOR_UNIBYTE_MASK 0x0100
506 #define CODING_REQUIRE_FLUSHING_MASK 0x0200
507 #define CODING_REQUIRE_DECODING_MASK 0x0400
508 #define CODING_REQUIRE_ENCODING_MASK 0x0800
509 #define CODING_REQUIRE_DETECTION_MASK 0x1000
510 #define CODING_RESET_AT_BOL_MASK 0x2000
512 /* Return nonzero if the coding context CODING requires annotation
513 handling. */
514 #define CODING_REQUIRE_ANNOTATION(coding) \
515 ((coding)->common_flags & CODING_ANNOTATION_MASK)
517 /* Return nonzero if the coding context CODING prefers decoding into
518 unibyte. */
519 #define CODING_FOR_UNIBYTE(coding) \
520 ((coding)->common_flags & CODING_FOR_UNIBYTE_MASK)
522 /* Return nonzero if the coding context CODING requires specific code to be
523 attached at the tail of converted text. */
524 #define CODING_REQUIRE_FLUSHING(coding) \
525 ((coding)->common_flags & CODING_REQUIRE_FLUSHING_MASK)
527 /* Return nonzero if the coding context CODING requires code conversion on
528 decoding. */
529 #define CODING_REQUIRE_DECODING(coding) \
530 ((coding)->dst_multibyte \
531 || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
534 /* Return nonzero if the coding context CODING requires code conversion on
535 encoding.
536 The non-multibyte part of the condition is to support encoding of
537 unibyte strings/buffers generated by string-as-unibyte or
538 (set-buffer-multibyte nil) from multibyte strings/buffers. */
539 #define CODING_REQUIRE_ENCODING(coding) \
540 ((coding)->src_multibyte \
541 || (coding)->common_flags & CODING_REQUIRE_ENCODING_MASK \
542 || (coding)->mode & CODING_MODE_SELECTIVE_DISPLAY)
545 /* Return nonzero if the coding context CODING requires some kind of code
546 detection. */
547 #define CODING_REQUIRE_DETECTION(coding) \
548 ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK)
550 /* Return nonzero if the coding context CODING requires code conversion on
551 decoding or some kind of code detection. */
552 #define CODING_MAY_REQUIRE_DECODING(coding) \
553 (CODING_REQUIRE_DECODING (coding) \
554 || CODING_REQUIRE_DETECTION (coding))
556 /* Macros to decode or encode a character of JISX0208 in SJIS. S1 and
557 S2 are the 1st and 2nd position-codes of JISX0208 in SJIS coding
558 system. C1 and C2 are the 1st and 2nd position codes of Emacs'
559 internal format. */
561 #define SJIS_TO_JIS(code) \
562 do { \
563 int s1, s2, j1, j2; \
565 s1 = (code) >> 8, s2 = (code) & 0xFF; \
567 if (s2 >= 0x9F) \
568 (j1 = s1 * 2 - (s1 >= 0xE0 ? 0x160 : 0xE0), \
569 j2 = s2 - 0x7E); \
570 else \
571 (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \
572 j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F)); \
573 (code) = (j1 << 8) | j2; \
574 } while (false)
576 #define SJIS_TO_JIS2(code) \
577 do { \
578 int s1, s2, j1, j2; \
580 s1 = (code) >> 8, s2 = (code) & 0xFF; \
582 if (s2 >= 0x9F) \
584 j1 = (s1 == 0xF0 ? 0x28 \
585 : s1 == 0xF1 ? 0x24 \
586 : s1 == 0xF2 ? 0x2C \
587 : s1 == 0xF3 ? 0x2E \
588 : 0x6E + (s1 - 0xF4) * 2); \
589 j2 = s2 - 0x7E; \
591 else \
593 j1 = (s1 <= 0xF2 ? 0x21 + (s1 - 0xF0) * 2 \
594 : s1 <= 0xF4 ? 0x2D + (s1 - 0xF3) * 2 \
595 : 0x6F + (s1 - 0xF5) * 2); \
596 j2 = s2 - ((s2 >= 0x7F ? 0x20 : 0x1F)); \
598 (code) = (j1 << 8) | j2; \
599 } while (false)
602 #define JIS_TO_SJIS(code) \
603 do { \
604 int s1, s2, j1, j2; \
606 j1 = (code) >> 8, j2 = (code) & 0xFF; \
607 if (j1 & 1) \
608 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x71 : 0xB1), \
609 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F)); \
610 else \
611 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \
612 s2 = j2 + 0x7E); \
613 (code) = (s1 << 8) | s2; \
614 } while (false)
616 #define JIS_TO_SJIS2(code) \
617 do { \
618 int s1, s2, j1, j2; \
620 j1 = (code) >> 8, j2 = (code) & 0xFF; \
621 if (j1 & 1) \
623 s1 = (j1 <= 0x25 ? 0xF0 + (j1 - 0x21) / 2 \
624 : j1 <= 0x2F ? 0xF3 + (j1 - 0x2D) / 2 \
625 : 0xF5 + (j1 - 0x6F) / 2); \
626 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F); \
628 else \
630 s1 = (j1 == 0x28 ? 0xF0 \
631 : j1 == 0x24 ? 0xF1 \
632 : j1 == 0x2C ? 0xF2 \
633 : j1 == 0x2E ? 0xF3 \
634 : 0xF4 + (j1 - 0x6E) / 2); \
635 s2 = j2 + 0x7E; \
637 (code) = (s1 << 8) | s2; \
638 } while (false)
640 /* Encode the file name NAME using the specified coding system
641 for file names, if any. */
642 #define ENCODE_FILE(NAME) encode_file_name (NAME)
644 /* Decode the file name NAME using the specified coding system
645 for file names, if any. */
646 #define DECODE_FILE(NAME) decode_file_name (NAME)
648 /* Encode the string STR using the specified coding system
649 for system functions, if any. */
650 #define ENCODE_SYSTEM(str) \
651 (! NILP (Vlocale_coding_system) \
652 ? code_convert_string_norecord (str, Vlocale_coding_system, true) \
653 : str)
655 /* Decode the string STR using the specified coding system
656 for system functions, if any. */
657 #define DECODE_SYSTEM(str) \
658 (! NILP (Vlocale_coding_system) \
659 ? code_convert_string_norecord (str, Vlocale_coding_system, false) \
660 : str)
662 /* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op. */
663 #define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, true)
665 /* Extern declarations. */
666 extern Lisp_Object code_conversion_save (bool, bool);
667 extern bool encode_coding_utf_8 (struct coding_system *);
668 extern void setup_coding_system (Lisp_Object, struct coding_system *);
669 extern Lisp_Object coding_charset_list (struct coding_system *);
670 extern Lisp_Object coding_system_charset_list (Lisp_Object);
671 extern Lisp_Object code_convert_string (Lisp_Object, Lisp_Object,
672 Lisp_Object, bool, bool, bool);
673 extern Lisp_Object code_convert_string_norecord (Lisp_Object, Lisp_Object,
674 bool);
675 extern Lisp_Object encode_file_name (Lisp_Object);
676 extern Lisp_Object decode_file_name (Lisp_Object);
677 extern Lisp_Object raw_text_coding_system (Lisp_Object);
678 extern bool raw_text_coding_system_p (struct coding_system *);
679 extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
680 extern Lisp_Object complement_process_encoding_system (Lisp_Object);
682 extern void decode_coding_gap (struct coding_system *,
683 ptrdiff_t, ptrdiff_t);
684 extern void decode_coding_object (struct coding_system *,
685 Lisp_Object, ptrdiff_t, ptrdiff_t,
686 ptrdiff_t, ptrdiff_t, Lisp_Object);
687 extern void encode_coding_object (struct coding_system *,
688 Lisp_Object, ptrdiff_t, ptrdiff_t,
689 ptrdiff_t, ptrdiff_t, Lisp_Object);
691 #if defined (WINDOWSNT) || defined (CYGWIN)
693 /* These functions use Lisp string objects to store the UTF-16LE
694 strings that modern versions of Windows expect. These strings are
695 not particularly useful to Lisp, and all Lisp strings should be
696 native Emacs multibyte. */
698 /* Access the wide-character string stored in a Lisp string object. */
699 #define WCSDATA(x) ((wchar_t *) SDATA (x))
701 /* Convert the multi-byte string in STR to UTF-16LE encoded unibyte
702 string, and store it in *BUF. BUF may safely point to STR on entry. */
703 extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
705 /* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
706 object, to a multi-byte Emacs string and return it. This function
707 calls code_convert_string_norecord internally and has all its
708 failure modes. STR itself is not modified. */
709 extern Lisp_Object from_unicode (Lisp_Object str);
711 /* Convert WSTR to an Emacs string. */
712 extern Lisp_Object from_unicode_buffer (const wchar_t *wstr);
714 #endif /* WINDOWSNT || CYGWIN */
716 /* Macros for backward compatibility. */
718 #define encode_coding_string(coding, string, nocopy) \
719 (STRING_MULTIBYTE(string) ? \
720 (encode_coding_object (coding, string, 0, 0, SCHARS (string), \
721 SBYTES (string), Qt), \
722 (coding)->dst_object) : (string))
725 #define decode_coding_c_string(coding, src, bytes, dst_object) \
726 do { \
727 (coding)->source = (src); \
728 (coding)->src_chars = (coding)->src_bytes = (bytes); \
729 decode_coding_object ((coding), Qnil, 0, 0, (bytes), (bytes), \
730 (dst_object)); \
731 } while (false)
734 extern Lisp_Object preferred_coding_system (void);
737 #ifdef emacs
739 /* Coding system to be used to encode text for terminal display when
740 terminal coding system is nil. */
741 extern struct coding_system safe_terminal_coding;
743 #endif
745 extern char emacs_mule_bytes[256];
747 #endif /* EMACS_CODING_H */