* lisp/emacs-lisp/gv.el (gv-deref): Move setter declaration, to fix bootstrap.
[emacs.git] / src / coding.h
blob192be58f08328c2923ac102b9c05ec978fcb3e7e
1 /* Header for coding system handler.
2 Copyright (C) 2001-2012 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
16 (at 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 /* Index to arguments of Fdefine_coding_system_internal. */
31 enum define_coding_system_arg_index
33 coding_arg_name,
34 coding_arg_mnemonic,
35 coding_arg_coding_type,
36 coding_arg_charset_list,
37 coding_arg_ascii_compatible_p,
38 coding_arg_decode_translation_table,
39 coding_arg_encode_translation_table,
40 coding_arg_post_read_conversion,
41 coding_arg_pre_write_conversion,
42 coding_arg_default_char,
43 coding_arg_for_unibyte,
44 coding_arg_plist,
45 coding_arg_eol_type,
46 coding_arg_max
49 enum define_coding_iso2022_arg_index
51 coding_arg_iso2022_initial = coding_arg_max,
52 coding_arg_iso2022_reg_usage,
53 coding_arg_iso2022_request,
54 coding_arg_iso2022_flags,
55 coding_arg_iso2022_max
58 enum define_coding_utf8_arg_index
60 coding_arg_utf8_bom = coding_arg_max,
61 coding_arg_utf8_max
64 enum define_coding_utf16_arg_index
66 coding_arg_utf16_bom = coding_arg_max,
67 coding_arg_utf16_endian,
68 coding_arg_utf16_max
71 enum define_coding_ccl_arg_index
73 coding_arg_ccl_decoder = coding_arg_max,
74 coding_arg_ccl_encoder,
75 coding_arg_ccl_valids,
76 coding_arg_ccl_max
79 /* Hash table for all coding systems. Keys are coding system symbols
80 and values are spec vectors of the corresponding coding system. A
81 spec vector has the form [ ATTRS ALIASES EOL-TYPE ]. ATTRS is a
82 vector of attribute of the coding system. ALIASES is a list of
83 aliases (symbols) of the coding system. EOL-TYPE is `unix', `dos',
84 `mac' or a vector of coding systems (symbols). */
86 extern Lisp_Object Vcoding_system_hash_table;
89 /* Enumeration of coding system type. */
91 enum coding_system_type
93 coding_type_charset,
94 coding_type_utf_8,
95 coding_type_utf_16,
96 coding_type_iso_2022,
97 coding_type_emacs_mule,
98 coding_type_sjis,
99 coding_type_ccl,
100 coding_type_raw_text,
101 coding_type_undecided,
102 coding_type_max
106 /* Enumeration of end-of-line format type. */
108 enum end_of_line_type
110 eol_lf, /* Line-feed only, same as Emacs' internal
111 format. */
112 eol_crlf, /* Sequence of carriage-return and
113 line-feed. */
114 eol_cr, /* Carriage-return only. */
115 eol_any, /* Accept any of above. Produce line-feed
116 only. */
117 eol_undecided, /* This value is used to denote that the
118 eol-type is not yet undecided. */
119 eol_type_max
122 /* Enumeration of index to an attribute vector of a coding system. */
124 enum coding_attr_index
126 coding_attr_base_name,
127 coding_attr_docstring,
128 coding_attr_mnemonic,
129 coding_attr_type,
130 coding_attr_charset_list,
131 coding_attr_ascii_compat,
132 coding_attr_decode_tbl,
133 coding_attr_encode_tbl,
134 coding_attr_trans_tbl,
135 coding_attr_post_read,
136 coding_attr_pre_write,
137 coding_attr_default_char,
138 coding_attr_for_unibyte,
139 coding_attr_plist,
141 coding_attr_category,
142 coding_attr_safe_charsets,
144 /* The followings are extra attributes for each type. */
145 coding_attr_charset_valids,
147 coding_attr_ccl_decoder,
148 coding_attr_ccl_encoder,
149 coding_attr_ccl_valids,
151 coding_attr_iso_initial,
152 coding_attr_iso_usage,
153 coding_attr_iso_request,
154 coding_attr_iso_flags,
156 coding_attr_utf_bom,
157 coding_attr_utf_16_endian,
159 coding_attr_emacs_mule_full,
161 coding_attr_last_index
165 /* Macros to access an element of an attribute vector. */
167 #define CODING_ATTR_BASE_NAME(attrs) AREF (attrs, coding_attr_base_name)
168 #define CODING_ATTR_TYPE(attrs) AREF (attrs, coding_attr_type)
169 #define CODING_ATTR_CHARSET_LIST(attrs) AREF (attrs, coding_attr_charset_list)
170 #define CODING_ATTR_MNEMONIC(attrs) AREF (attrs, coding_attr_mnemonic)
171 #define CODING_ATTR_DOCSTRING(attrs) AREF (attrs, coding_attr_docstring)
172 #define CODING_ATTR_ASCII_COMPAT(attrs) AREF (attrs, coding_attr_ascii_compat)
173 #define CODING_ATTR_DECODE_TBL(attrs) AREF (attrs, coding_attr_decode_tbl)
174 #define CODING_ATTR_ENCODE_TBL(attrs) AREF (attrs, coding_attr_encode_tbl)
175 #define CODING_ATTR_TRANS_TBL(attrs) AREF (attrs, coding_attr_trans_tbl)
176 #define CODING_ATTR_POST_READ(attrs) AREF (attrs, coding_attr_post_read)
177 #define CODING_ATTR_PRE_WRITE(attrs) AREF (attrs, coding_attr_pre_write)
178 #define CODING_ATTR_DEFAULT_CHAR(attrs) AREF (attrs, coding_attr_default_char)
179 #define CODING_ATTR_FOR_UNIBYTE(attrs) AREF (attrs, coding_attr_for_unibyte)
180 #define CODING_ATTR_PLIST(attrs) AREF (attrs, coding_attr_plist)
181 #define CODING_ATTR_CATEGORY(attrs) AREF (attrs, coding_attr_category)
182 #define CODING_ATTR_SAFE_CHARSETS(attrs)AREF (attrs, coding_attr_safe_charsets)
185 /* Return the name of a coding system specified by ID. */
186 #define CODING_ID_NAME(id) \
187 (HASH_KEY (XHASH_TABLE (Vcoding_system_hash_table), id))
189 /* Return the attribute vector of a coding system specified by ID. */
191 #define CODING_ID_ATTRS(id) \
192 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 0))
194 /* Return the list of aliases of a coding system specified by ID. */
196 #define CODING_ID_ALIASES(id) \
197 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 1))
199 /* Return the eol-type of a coding system specified by ID. */
201 #define CODING_ID_EOL_TYPE(id) \
202 (AREF (HASH_VALUE (XHASH_TABLE (Vcoding_system_hash_table), id), 2))
205 /* Return the spec vector of CODING_SYSTEM_SYMBOL. */
207 #define CODING_SYSTEM_SPEC(coding_system_symbol) \
208 (Fgethash (coding_system_symbol, Vcoding_system_hash_table, Qnil))
211 /* Return the ID of CODING_SYSTEM_SYMBOL. */
213 #define CODING_SYSTEM_ID(coding_system_symbol) \
214 hash_lookup (XHASH_TABLE (Vcoding_system_hash_table), \
215 coding_system_symbol, NULL)
217 /* Return 1 if CODING_SYSTEM_SYMBOL is a coding system. */
219 #define CODING_SYSTEM_P(coding_system_symbol) \
220 (CODING_SYSTEM_ID (coding_system_symbol) >= 0 \
221 || (! NILP (coding_system_symbol) \
222 && ! NILP (Fcoding_system_p (coding_system_symbol))))
224 /* Check if X is a coding system or not. */
226 #define CHECK_CODING_SYSTEM(x) \
227 do { \
228 if (CODING_SYSTEM_ID (x) < 0 \
229 && NILP (Fcheck_coding_system (x))) \
230 wrong_type_argument (Qcoding_system_p, (x)); \
231 } while (0)
234 /* Check if X is a coding system or not. If it is, set SEPC to the
235 spec vector of the coding system. */
237 #define CHECK_CODING_SYSTEM_GET_SPEC(x, spec) \
238 do { \
239 spec = CODING_SYSTEM_SPEC (x); \
240 if (NILP (spec)) \
242 Fcheck_coding_system (x); \
243 spec = CODING_SYSTEM_SPEC (x); \
245 if (NILP (spec)) \
246 wrong_type_argument (Qcoding_system_p, (x)); \
247 } while (0)
250 /* Check if X is a coding system or not. If it is, set ID to the
251 ID of the coding system. */
253 #define CHECK_CODING_SYSTEM_GET_ID(x, id) \
254 do \
256 id = CODING_SYSTEM_ID (x); \
257 if (id < 0) \
259 Fcheck_coding_system (x); \
260 id = CODING_SYSTEM_ID (x); \
262 if (id < 0) \
263 wrong_type_argument (Qcoding_system_p, (x)); \
264 } while (0)
267 /*** GENERAL section ***/
269 /* Enumeration of result code of code conversion. */
270 enum coding_result_code
272 CODING_RESULT_SUCCESS,
273 CODING_RESULT_INSUFFICIENT_SRC,
274 CODING_RESULT_INSUFFICIENT_DST,
275 CODING_RESULT_INCONSISTENT_EOL,
276 CODING_RESULT_INVALID_SRC,
277 CODING_RESULT_INTERRUPT,
278 CODING_RESULT_INSUFFICIENT_MEM
282 /* Macros used for the member `mode' of the struct coding_system. */
284 /* If set, recover the original CR or LF of the already decoded text
285 when the decoding routine encounters an inconsistent eol format. */
286 #define CODING_MODE_INHIBIT_INCONSISTENT_EOL 0x01
288 /* If set, the decoding/encoding routines treat the current data as
289 the last block of the whole text to be converted, and do the
290 appropriate finishing job. */
291 #define CODING_MODE_LAST_BLOCK 0x02
293 /* If set, it means that the current source text is in a buffer which
294 enables selective display. */
295 #define CODING_MODE_SELECTIVE_DISPLAY 0x04
297 /* This flag is used by the decoding/encoding routines on the fly. If
298 set, it means that right-to-left text is being processed. */
299 #define CODING_MODE_DIRECTION 0x08
301 #define CODING_MODE_FIXED_DESTINATION 0x10
303 /* If set, it means that the encoding routines produces some safe
304 ASCII characters (usually '?') for unsupported characters. */
305 #define CODING_MODE_SAFE_ENCODING 0x20
307 /* For handling composition sequence. */
308 #include "composite.h"
310 enum composition_state
312 COMPOSING_NO,
313 COMPOSING_CHAR,
314 COMPOSING_RULE,
315 COMPOSING_COMPONENT_CHAR,
316 COMPOSING_COMPONENT_RULE
319 /* Structure for the current composition status. */
320 struct composition_status
322 enum composition_state state;
323 enum composition_method method;
324 bool old_form; /* true if pre-21 form */
325 int length; /* number of elements produced in charbuf */
326 int nchars; /* number of characters composed */
327 int ncomps; /* number of composition components */
328 /* Maximum carryover is for the case of COMPOSITION_WITH_RULE_ALTCHARS.
329 See the comment in coding.c. */
330 int carryover[4 /* annotation header */
331 + MAX_COMPOSITION_COMPONENTS * 3 - 2 /* ALTs and RULEs */
332 + 2 /* intermediate -1 -1 */
333 + MAX_COMPOSITION_COMPONENTS /* CHARs */
338 /* Structure of the field `spec.iso_2022' in the structure
339 `coding_system'. */
340 struct iso_2022_spec
342 /* Bit-wise-or of CODING_ISO_FLAG_XXX. */
343 unsigned flags;
345 /* The current graphic register invoked to each graphic plane. */
346 int current_invocation[2];
348 /* The current charset designated to each graphic register. The
349 value -1 means that not charset is designated, -2 means that
350 there was an invalid designation previously. */
351 int current_designation[4];
353 /* If positive, we are now scanning CTEXT extended segment. */
354 int ctext_extended_segment_len;
356 /* True temporarily only when graphic register 2 or 3 is invoked by
357 single-shift while encoding. */
358 unsigned single_shifting : 1;
360 /* True temporarily only when processing at beginning of line. */
361 unsigned bol : 1;
363 /* If true, we are now scanning embedded UTF-8 sequence. */
364 unsigned embedded_utf_8 : 1;
366 /* The current composition. */
367 struct composition_status cmp_status;
370 struct emacs_mule_spec
372 struct composition_status cmp_status;
375 struct ccl_spec;
377 enum utf_bom_type
379 utf_detect_bom,
380 utf_without_bom,
381 utf_with_bom
384 enum utf_16_endian_type
386 utf_16_big_endian,
387 utf_16_little_endian
390 struct utf_16_spec
392 enum utf_bom_type bom;
393 enum utf_16_endian_type endian;
394 int surrogate;
397 struct coding_detection_info
399 /* Values of these members are bitwise-OR of CATEGORY_MASK_XXXs. */
400 /* Which categories are already checked. */
401 int checked;
402 /* Which categories are strongly found. */
403 int found;
404 /* Which categories are rejected. */
405 int rejected;
409 struct coding_system
411 /* ID number of the coding system. This is an index to
412 Vcoding_system_hash_table. This value is set by
413 setup_coding_system. At the early stage of building time, this
414 value is -1 in the array coding_categories to indicate that no
415 coding-system of that category is yet defined. */
416 ptrdiff_t id;
418 /* Flag bits of the coding system. The meaning of each bit is common
419 to all types of coding systems. */
420 int common_flags;
422 /* Mode bits of the coding system. See the comments of the macros
423 CODING_MODE_XXX. */
424 unsigned int mode;
426 /* Detailed information specific to each type of coding system. */
427 union
429 struct iso_2022_spec iso_2022;
430 struct ccl_spec *ccl; /* Defined in ccl.h. */
431 struct utf_16_spec utf_16;
432 enum utf_bom_type utf_8_bom;
433 struct emacs_mule_spec emacs_mule;
434 } spec;
436 int max_charset_id;
437 unsigned char *safe_charsets;
439 /* The following two members specify how binary 8-bit code 128..255
440 are represented in source and destination text respectively. 1
441 means they are represented by 2-byte sequence, 0 means they are
442 represented by 1-byte as is (see the comment in character.h). */
443 unsigned src_multibyte : 1;
444 unsigned dst_multibyte : 1;
446 /* How may heading bytes we can skip for decoding. This is set to
447 -1 in setup_coding_system, and updated by detect_coding. So,
448 when this is equal to the byte length of the text being
449 converted, we can skip the actual conversion process. */
450 ptrdiff_t head_ascii;
452 /* The following members are set by encoding/decoding routine. */
453 ptrdiff_t produced, produced_char, consumed, consumed_char;
455 /* Number of error source data found in a decoding routine. */
456 int errors;
458 /* Store the positions of error source data. */
459 ptrdiff_t *error_positions;
461 /* Finish status of code conversion. */
462 enum coding_result_code result;
464 ptrdiff_t src_pos, src_pos_byte, src_chars, src_bytes;
465 Lisp_Object src_object;
466 const unsigned char *source;
468 ptrdiff_t dst_pos, dst_pos_byte, dst_bytes;
469 Lisp_Object dst_object;
470 unsigned char *destination;
472 /* If an element is non-negative, it is a character code.
474 If it is in the range -128..-1, it is a 8-bit character code
475 minus 256.
477 If it is less than -128, it specifies the start of an annotation
478 chunk. The length of the chunk is -128 minus the value of the
479 element. The following elements are OFFSET, ANNOTATION-TYPE, and
480 a sequence of actual data for the annotation. OFFSET is a
481 character position offset from dst_pos or src_pos,
482 ANNOTATION-TYPE specifies the meaning of the annotation and how to
483 handle the following data.. */
484 int *charbuf;
485 int charbuf_size, charbuf_used;
487 /* True if the source of conversion is not in the member
488 `charbuf', but at `src_object'. */
489 unsigned chars_at_source : 1;
491 /* Set to 1 if charbuf contains an annotation. */
492 unsigned annotated : 1;
494 unsigned char carryover[64];
495 int carryover_bytes;
497 int default_char;
499 bool (*detector) (struct coding_system *, struct coding_detection_info *);
500 void (*decoder) (struct coding_system *);
501 bool (*encoder) (struct coding_system *);
504 /* Meanings of bits in the member `common_flags' of the structure
505 coding_system. The lowest 8 bits are reserved for various kind of
506 annotations (currently two of them are used). */
507 #define CODING_ANNOTATION_MASK 0x00FF
508 #define CODING_ANNOTATE_COMPOSITION_MASK 0x0001
509 #define CODING_ANNOTATE_DIRECTION_MASK 0x0002
510 #define CODING_ANNOTATE_CHARSET_MASK 0x0003
511 #define CODING_FOR_UNIBYTE_MASK 0x0100
512 #define CODING_REQUIRE_FLUSHING_MASK 0x0200
513 #define CODING_REQUIRE_DECODING_MASK 0x0400
514 #define CODING_REQUIRE_ENCODING_MASK 0x0800
515 #define CODING_REQUIRE_DETECTION_MASK 0x1000
516 #define CODING_RESET_AT_BOL_MASK 0x2000
518 /* Return 1 if the coding context CODING requires annotation
519 handling. */
520 #define CODING_REQUIRE_ANNOTATION(coding) \
521 ((coding)->common_flags & CODING_ANNOTATION_MASK)
523 /* Return 1 if the coding context CODING prefers decoding into unibyte. */
524 #define CODING_FOR_UNIBYTE(coding) \
525 ((coding)->common_flags & CODING_FOR_UNIBYTE_MASK)
527 /* Return 1 if the coding context CODING requires specific code to be
528 attached at the tail of converted text. */
529 #define CODING_REQUIRE_FLUSHING(coding) \
530 ((coding)->common_flags & CODING_REQUIRE_FLUSHING_MASK)
532 /* Return 1 if the coding context CODING requires code conversion on
533 decoding. */
534 #define CODING_REQUIRE_DECODING(coding) \
535 ((coding)->dst_multibyte \
536 || (coding)->common_flags & CODING_REQUIRE_DECODING_MASK)
539 /* Return 1 if the coding context CODING requires code conversion on
540 encoding.
541 The non-multibyte part of the condition is to support encoding of
542 unibyte strings/buffers generated by string-as-unibyte or
543 (set-buffer-multibyte nil) from multibyte strings/buffers. */
544 #define CODING_REQUIRE_ENCODING(coding) \
545 ((coding)->src_multibyte \
546 || (coding)->common_flags & CODING_REQUIRE_ENCODING_MASK \
547 || (coding)->mode & CODING_MODE_SELECTIVE_DISPLAY)
550 /* Return 1 if the coding context CODING requires some kind of code
551 detection. */
552 #define CODING_REQUIRE_DETECTION(coding) \
553 ((coding)->common_flags & CODING_REQUIRE_DETECTION_MASK)
555 /* Return 1 if the coding context CODING requires code conversion on
556 decoding or some kind of code detection. */
557 #define CODING_MAY_REQUIRE_DECODING(coding) \
558 (CODING_REQUIRE_DECODING (coding) \
559 || CODING_REQUIRE_DETECTION (coding))
561 /* Macros to decode or encode a character of JISX0208 in SJIS. S1 and
562 S2 are the 1st and 2nd position-codes of JISX0208 in SJIS coding
563 system. C1 and C2 are the 1st and 2nd position codes of Emacs'
564 internal format. */
566 #define SJIS_TO_JIS(code) \
567 do { \
568 int s1, s2, j1, j2; \
570 s1 = (code) >> 8, s2 = (code) & 0xFF; \
572 if (s2 >= 0x9F) \
573 (j1 = s1 * 2 - (s1 >= 0xE0 ? 0x160 : 0xE0), \
574 j2 = s2 - 0x7E); \
575 else \
576 (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \
577 j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F)); \
578 (code) = (j1 << 8) | j2; \
579 } while (0)
581 #define SJIS_TO_JIS2(code) \
582 do { \
583 int s1, s2, j1, j2; \
585 s1 = (code) >> 8, s2 = (code) & 0xFF; \
587 if (s2 >= 0x9F) \
589 j1 = (s1 == 0xF0 ? 0x28 \
590 : s1 == 0xF1 ? 0x24 \
591 : s1 == 0xF2 ? 0x2C \
592 : s1 == 0xF3 ? 0x2E \
593 : 0x6E + (s1 - 0xF4) * 2); \
594 j2 = s2 - 0x7E; \
596 else \
598 j1 = (s1 <= 0xF2 ? 0x21 + (s1 - 0xF0) * 2 \
599 : s1 <= 0xF4 ? 0x2D + (s1 - 0xF3) * 2 \
600 : 0x6F + (s1 - 0xF5) * 2); \
601 j2 = s2 - ((s2 >= 0x7F ? 0x20 : 0x1F)); \
603 (code) = (j1 << 8) | j2; \
604 } while (0)
607 #define JIS_TO_SJIS(code) \
608 do { \
609 int s1, s2, j1, j2; \
611 j1 = (code) >> 8, j2 = (code) & 0xFF; \
612 if (j1 & 1) \
613 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x71 : 0xB1), \
614 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F)); \
615 else \
616 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \
617 s2 = j2 + 0x7E); \
618 (code) = (s1 << 8) | s2; \
619 } while (0)
621 #define JIS_TO_SJIS2(code) \
622 do { \
623 int s1, s2, j1, j2; \
625 j1 = (code) >> 8, j2 = (code) & 0xFF; \
626 if (j1 & 1) \
628 s1 = (j1 <= 0x25 ? 0xF0 + (j1 - 0x21) / 2 \
629 : j1 <= 0x2F ? 0xF3 + (j1 - 0x2D) / 2 \
630 : 0xF5 + (j1 - 0x6F) / 2); \
631 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F); \
633 else \
635 s1 = (j1 == 0x28 ? 0xF0 \
636 : j1 == 0x24 ? 0xF1 \
637 : j1 == 0x2C ? 0xF2 \
638 : j1 == 0x2E ? 0xF3 \
639 : 0xF4 + (j1 - 0x6E) / 2); \
640 s2 = j2 + 0x7E; \
642 (code) = (s1 << 8) | s2; \
643 } while (0)
645 /* Encode the file name NAME using the specified coding system
646 for file names, if any. */
647 #define ENCODE_FILE(name) \
648 (! NILP (Vfile_name_coding_system) \
649 ? code_convert_string_norecord (name, Vfile_name_coding_system, 1) \
650 : (! NILP (Vdefault_file_name_coding_system) \
651 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \
652 : name))
655 /* Decode the file name NAME using the specified coding system
656 for file names, if any. */
657 #define DECODE_FILE(name) \
658 (! NILP (Vfile_name_coding_system) \
659 ? code_convert_string_norecord (name, Vfile_name_coding_system, 0) \
660 : (! NILP (Vdefault_file_name_coding_system) \
661 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
662 : name))
665 /* Encode the string STR using the specified coding system
666 for system functions, if any. */
667 #define ENCODE_SYSTEM(str) \
668 (! NILP (Vlocale_coding_system) \
669 ? code_convert_string_norecord (str, Vlocale_coding_system, 1) \
670 : str)
672 /* Decode the string STR using the specified coding system
673 for system functions, if any. */
674 #define DECODE_SYSTEM(str) \
675 (! NILP (Vlocale_coding_system) \
676 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \
677 : str)
679 /* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op. */
680 #define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1)
682 /* Extern declarations. */
683 extern Lisp_Object code_conversion_save (bool, bool);
684 extern void setup_coding_system (Lisp_Object, struct coding_system *);
685 extern Lisp_Object coding_charset_list (struct coding_system *);
686 extern Lisp_Object coding_system_charset_list (Lisp_Object);
687 extern Lisp_Object code_convert_string (Lisp_Object, Lisp_Object,
688 Lisp_Object, bool, bool, bool);
689 extern Lisp_Object code_convert_string_norecord (Lisp_Object, Lisp_Object,
690 bool);
691 extern Lisp_Object raw_text_coding_system (Lisp_Object);
692 extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
693 extern Lisp_Object complement_process_encoding_system (Lisp_Object);
695 extern void decode_coding_gap (struct coding_system *,
696 ptrdiff_t, ptrdiff_t);
697 extern void decode_coding_object (struct coding_system *,
698 Lisp_Object, ptrdiff_t, ptrdiff_t,
699 ptrdiff_t, ptrdiff_t, Lisp_Object);
700 extern void encode_coding_object (struct coding_system *,
701 Lisp_Object, ptrdiff_t, ptrdiff_t,
702 ptrdiff_t, ptrdiff_t, Lisp_Object);
704 #if defined (WINDOWSNT) || defined (CYGWIN)
706 /* These functions use Lisp string objects to store the UTF-16LE
707 strings that modern versions of Windows expect. These strings are
708 not particularly useful to Lisp, and all Lisp strings should be
709 native Emacs multibyte. */
711 /* Access the wide-character string stored in a Lisp string object. */
712 #define WCSDATA(x) ((wchar_t *) SDATA (x))
714 /* Convert the multi-byte string in STR to UTF-16LE encoded unibyte
715 string, and store it in *BUF. BUF may safely point to STR on entry. */
716 extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
718 /* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
719 object, to a multi-byte Emacs string and return it. This function
720 calls code_convert_string_norecord internally and has all its
721 failure modes. STR itself is not modified. */
722 extern Lisp_Object from_unicode (Lisp_Object str);
724 #endif /* WINDOWSNT || CYGWIN */
726 /* Macros for backward compatibility. */
728 #define decode_coding_region(coding, from, to) \
729 decode_coding_object (coding, Fcurrent_buffer (), \
730 from, CHAR_TO_BYTE (from), \
731 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
734 #define encode_coding_region(coding, from, to) \
735 encode_coding_object (coding, Fcurrent_buffer (), \
736 from, CHAR_TO_BYTE (from), \
737 to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
740 #define decode_coding_string(coding, string, nocopy) \
741 decode_coding_object (coding, string, 0, 0, SCHARS (string), \
742 SBYTES (string), Qt)
744 #define encode_coding_string(coding, string, nocopy) \
745 (STRING_MULTIBYTE(string) ? \
746 (encode_coding_object (coding, string, 0, 0, SCHARS (string), \
747 SBYTES (string), Qt), \
748 (coding)->dst_object) : (string))
751 #define decode_coding_c_string(coding, src, bytes, dst_object) \
752 do { \
753 (coding)->source = (src); \
754 (coding)->src_chars = (coding)->src_bytes = (bytes); \
755 decode_coding_object ((coding), Qnil, 0, 0, (bytes), (bytes), \
756 (dst_object)); \
757 } while (0)
760 extern Lisp_Object preferred_coding_system (void);
763 extern Lisp_Object Qutf_8, Qutf_8_emacs;
765 extern Lisp_Object Qcoding_category_index;
766 extern Lisp_Object Qcoding_system_p;
767 extern Lisp_Object Qraw_text, Qemacs_mule, Qno_conversion, Qundecided;
768 extern Lisp_Object Qbuffer_file_coding_system;
770 extern Lisp_Object Qunix, Qdos, Qmac;
772 extern Lisp_Object Qtranslation_table;
773 extern Lisp_Object Qtranslation_table_id;
775 #ifdef emacs
776 extern Lisp_Object Qfile_coding_system;
777 extern Lisp_Object Qcall_process, Qcall_process_region;
778 extern Lisp_Object Qstart_process, Qopen_network_stream;
779 extern Lisp_Object Qwrite_region;
781 extern char *emacs_strerror (int);
783 /* Coding system to be used to encode text for terminal display when
784 terminal coding system is nil. */
785 extern struct coding_system safe_terminal_coding;
787 #endif
789 /* Error signaled when there's a problem with detecting coding system */
790 extern Lisp_Object Qcoding_system_error;
792 extern char emacs_mule_bytes[256];
794 #endif /* EMACS_CODING_H */