Mercurial > emacs
annotate src/coding.c @ 89429:3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
coding_type is Qcharset.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 20 May 2003 13:05:14 +0000 |
parents | c3e67ce6ee0f |
children | 7349f4473e7f |
rev | line source |
---|---|
88936 | 1 /* Coding system handler (conversion, detection, etc). |
20708 | 2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. |
18269
888bfd80db2c
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18180
diff
changeset
|
3 Licensed to the Free Software Foundation. |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
4 Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
88365 | 5 Copyright (C) 2001, 2002 |
6 National Institute of Advanced Industrial Science and Technology (AIST) | |
7 Registration Number H13PRO009 | |
17052 | 8 |
17071 | 9 This file is part of GNU Emacs. |
10 | |
11 GNU Emacs is free software; you can redistribute it and/or modify | |
12 it under the terms of the GNU General Public License as published by | |
13 the Free Software Foundation; either version 2, or (at your option) | |
14 any later version. | |
15 | |
16 GNU Emacs is distributed in the hope that it will be useful, | |
17 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 GNU General Public License for more details. | |
20 | |
21 You should have received a copy of the GNU General Public License | |
22 along with GNU Emacs; see the file COPYING. If not, write to | |
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 Boston, MA 02111-1307, USA. */ | |
17052 | 25 |
26 /*** TABLE OF CONTENTS *** | |
27 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
28 0. General comments |
17052 | 29 1. Preamble |
88365 | 30 2. Emacs' internal format (emacs-utf-8) handlers |
31 3. UTF-8 handlers | |
32 4. UTF-16 handlers | |
33 5. Charset-base coding systems handlers | |
34 6. emacs-mule (old Emacs' internal format) handlers | |
35 7. ISO2022 handlers | |
36 8. Shift-JIS and BIG5 handlers | |
37 9. CCL handlers | |
38 10. C library functions | |
39 11. Emacs Lisp library functions | |
40 12. Postamble | |
17052 | 41 |
42 */ | |
43 | |
88365 | 44 /*** 0. General comments *** |
45 | |
46 | |
47 CODING SYSTEM | |
48 | |
88485 | 49 A coding system is an object for an encoding mechanism that contains |
50 information about how to convert byte sequences to character | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
51 sequences and vice versa. When we say "decode", it means converting |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
52 a byte sequence of a specific coding system into a character |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
53 sequence that is represented by Emacs' internal coding system |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
54 `emacs-utf-8', and when we say "encode", it means converting a |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
55 character sequence of emacs-utf-8 to a byte sequence of a specific |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
56 coding system. |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
57 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
58 In Emacs Lisp, a coding system is represented by a Lisp symbol. In |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
59 C level, a coding system is represented by a vector of attributes |
88485 | 60 stored in the hash table Vcharset_hash_table. The conversion from |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
61 coding system symbol to attributes vector is done by looking up |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
62 Vcharset_hash_table by the symbol. |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
63 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
64 Coding systems are classified into the following types depending on |
88485 | 65 the encoding mechanism. Here's a brief description of the types. |
88365 | 66 |
67 o UTF-8 | |
68 | |
69 o UTF-16 | |
70 | |
71 o Charset-base coding system | |
72 | |
73 A coding system defined by one or more (coded) character sets. | |
88485 | 74 Decoding and encoding are done by a code converter defined for each |
88365 | 75 character set. |
76 | |
88485 | 77 o Old Emacs internal format (emacs-mule) |
78 | |
79 The coding system adopted by old versions of Emacs (20 and 21). | |
88365 | 80 |
81 o ISO2022-base coding system | |
17052 | 82 |
83 The most famous coding system for multiple character sets. X's | |
88365 | 84 Compound Text, various EUCs (Extended Unix Code), and coding systems |
85 used in the Internet communication such as ISO-2022-JP are all | |
86 variants of ISO2022. | |
87 | |
88 o SJIS (or Shift-JIS or MS-Kanji-Code) | |
89 | |
17052 | 90 A coding system to encode character sets: ASCII, JISX0201, and |
91 JISX0208. Widely used for PC's in Japan. Details are described in | |
88365 | 92 section 8. |
93 | |
94 o BIG5 | |
95 | |
96 A coding system to encode character sets: ASCII and Big5. Widely | |
88771 | 97 used for Chinese (mainly in Taiwan and Hong Kong). Details are |
88365 | 98 described in section 8. In this file, when we write "big5" (all |
99 lowercase), we mean the coding system, and when we write "Big5" | |
100 (capitalized), we mean the character set. | |
101 | |
102 o CCL | |
103 | |
88485 | 104 If a user wants to decode/encode text encoded in a coding system |
88365 | 105 not listed above, he can supply a decoder and an encoder for it in |
106 CCL (Code Conversion Language) programs. Emacs executes the CCL | |
107 program while decoding/encoding. | |
108 | |
109 o Raw-text | |
110 | |
88771 | 111 A coding system for text containing raw eight-bit data. Emacs |
88485 | 112 treats each byte of source text as a character (except for |
88365 | 113 end-of-line conversion). |
114 | |
115 o No-conversion | |
116 | |
117 Like raw text, but don't do end-of-line conversion. | |
118 | |
119 | |
120 END-OF-LINE FORMAT | |
121 | |
88485 | 122 How text end-of-line is encoded depends on operating system. For |
88365 | 123 instance, Unix's format is just one byte of LF (line-feed) code, |
18766 | 124 whereas DOS's format is two-byte sequence of `carriage-return' and |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
125 `line-feed' codes. MacOS's format is usually one byte of |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
126 `carriage-return'. |
17052 | 127 |
88485 | 128 Since text character encoding and end-of-line encoding are |
88365 | 129 independent, any coding system described above can take any format |
130 of end-of-line (except for no-conversion). | |
17052 | 131 |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
132 STRUCT CODING_SYSTEM |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
133 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
134 Before using a coding system for code conversion (i.e. decoding and |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
135 encoding), we setup a structure of type `struct coding_system'. |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
136 This structure keeps various information about a specific code |
88485 | 137 conversion (e.g. the location of source and destination data). |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
138 |
17052 | 139 */ |
140 | |
88365 | 141 /* COMMON MACROS */ |
142 | |
143 | |
17052 | 144 /*** GENERAL NOTES on `detect_coding_XXX ()' functions *** |
145 | |
88365 | 146 These functions check if a byte sequence specified as a source in |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
147 CODING conforms to the format of XXX, and update the members of |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
148 DETECT_INFO. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
149 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
150 Return 1 if the byte sequence conforms to XXX, otherwise return 0. |
88365 | 151 |
152 Below is the template of these functions. */ | |
153 | |
17052 | 154 #if 0 |
88365 | 155 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
156 detect_coding_XXX (coding, detect_info) |
88365 | 157 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
158 struct coding_detection_info *detect_info; |
17052 | 159 { |
88365 | 160 unsigned char *src = coding->source; |
161 unsigned char *src_end = coding->source + coding->src_bytes; | |
162 int multibytep = coding->src_multibyte; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
163 int consumed_chars = 0; |
88365 | 164 int found = 0; |
165 ...; | |
166 | |
167 while (1) | |
168 { | |
169 /* Get one byte from the source. If the souce is exausted, jump | |
170 to no_more_source:. */ | |
171 ONE_MORE_BYTE (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
172 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
173 if (! __C_conforms_to_XXX___ (c)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
174 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
175 if (! __C_strongly_suggests_XXX__ (c)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
176 found = CATEGORY_MASK_XXX; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
177 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
178 /* The byte sequence is invalid for XXX. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
179 detect_info->rejected |= CATEGORY_MASK_XXX; |
88365 | 180 return 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
181 |
88365 | 182 no_more_source: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
183 /* The source exausted successfully. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
184 detect_info->found |= found; |
88365 | 185 return 1; |
17052 | 186 } |
187 #endif | |
188 | |
189 /*** GENERAL NOTES on `decode_coding_XXX ()' functions *** | |
190 | |
88365 | 191 These functions decode a byte sequence specified as a source by |
192 CODING. The resulting multibyte text goes to a place pointed to by | |
193 CODING->charbuf, the length of which should not exceed | |
194 CODING->charbuf_size; | |
195 | |
196 These functions set the information of original and decoded texts in | |
197 CODING->consumed, CODING->consumed_char, and CODING->charbuf_used. | |
198 They also set CODING->result to one of CODING_RESULT_XXX indicating | |
199 how the decoding is finished. | |
200 | |
201 Below is the template of these functions. */ | |
202 | |
17052 | 203 #if 0 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
204 static void |
88365 | 205 decode_coding_XXXX (coding) |
17052 | 206 struct coding_system *coding; |
207 { | |
88365 | 208 unsigned char *src = coding->source + coding->consumed; |
209 unsigned char *src_end = coding->source + coding->src_bytes; | |
210 /* SRC_BASE remembers the start position in source in each loop. | |
211 The loop will be exited when there's not enough source code, or | |
212 when there's no room in CHARBUF for a decoded character. */ | |
213 unsigned char *src_base; | |
214 /* A buffer to produce decoded characters. */ | |
215 int *charbuf = coding->charbuf; | |
216 int *charbuf_end = charbuf + coding->charbuf_size; | |
217 int multibytep = coding->src_multibyte; | |
218 | |
219 while (1) | |
220 { | |
221 src_base = src; | |
222 if (charbuf < charbuf_end) | |
223 /* No more room to produce a decoded character. */ | |
224 break; | |
225 ONE_MORE_BYTE (c); | |
226 /* Decode it. */ | |
227 } | |
228 | |
229 no_more_source: | |
230 if (src_base < src_end | |
231 && coding->mode & CODING_MODE_LAST_BLOCK) | |
232 /* If the source ends by partial bytes to construct a character, | |
233 treat them as eight-bit raw data. */ | |
234 while (src_base < src_end && charbuf < charbuf_end) | |
235 *charbuf++ = *src_base++; | |
236 /* Remember how many bytes and characters we consumed. If the | |
237 source is multibyte, the bytes and chars are not identical. */ | |
238 coding->consumed = coding->consumed_char = src_base - coding->source; | |
239 /* Remember how many characters we produced. */ | |
240 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 241 } |
242 #endif | |
243 | |
244 /*** GENERAL NOTES on `encode_coding_XXX ()' functions *** | |
245 | |
88365 | 246 These functions encode SRC_BYTES length text at SOURCE of Emacs' |
247 internal multibyte format by CODING. The resulting byte sequence | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
248 goes to a place pointed to by DESTINATION, the length of which |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
249 should not exceed DST_BYTES. |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
250 |
88365 | 251 These functions set the information of original and encoded texts in |
252 the members produced, produced_char, consumed, and consumed_char of | |
253 the structure *CODING. They also set the member result to one of | |
254 CODING_RESULT_XXX indicating how the encoding finished. | |
255 | |
256 DST_BYTES zero means that source area and destination area are | |
257 overlapped, which means that we can produce a encoded text until it | |
258 reaches at the head of not-yet-encoded source text. | |
259 | |
260 Below is a template of these functions. */ | |
17052 | 261 #if 0 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
262 static void |
88365 | 263 encode_coding_XXX (coding) |
17052 | 264 struct coding_system *coding; |
265 { | |
88365 | 266 int multibytep = coding->dst_multibyte; |
267 int *charbuf = coding->charbuf; | |
268 int *charbuf_end = charbuf->charbuf + coding->charbuf_used; | |
269 unsigned char *dst = coding->destination + coding->produced; | |
270 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
271 unsigned char *adjusted_dst_end = dst_end - _MAX_BYTES_PRODUCED_IN_LOOP_; | |
272 int produced_chars = 0; | |
273 | |
274 for (; charbuf < charbuf_end && dst < adjusted_dst_end; charbuf++) | |
275 { | |
276 int c = *charbuf; | |
277 /* Encode C into DST, and increment DST. */ | |
278 } | |
279 label_no_more_destination: | |
280 /* How many chars and bytes we produced. */ | |
281 coding->produced_char += produced_chars; | |
282 coding->produced = dst - coding->destination; | |
17052 | 283 } |
284 #endif | |
285 | |
286 | |
287 /*** 1. Preamble ***/ | |
288 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
289 #include <config.h> |
17052 | 290 #include <stdio.h> |
291 | |
292 #include "lisp.h" | |
293 #include "buffer.h" | |
88365 | 294 #include "character.h" |
17052 | 295 #include "charset.h" |
88365 | 296 #include "ccl.h" |
26847 | 297 #include "composite.h" |
17052 | 298 #include "coding.h" |
299 #include "window.h" | |
300 | |
88365 | 301 Lisp_Object Vcoding_system_hash_table; |
302 | |
303 Lisp_Object Qcoding_system, Qcoding_aliases, Qeol_type; | |
88646
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
304 Lisp_Object Qunix, Qdos; |
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
305 extern Lisp_Object Qmac; /* frame.c */ |
17052 | 306 Lisp_Object Qbuffer_file_coding_system; |
307 Lisp_Object Qpost_read_conversion, Qpre_write_conversion; | |
88365 | 308 Lisp_Object Qdefault_char; |
19612
783efd6c7c1e
(Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents:
19546
diff
changeset
|
309 Lisp_Object Qno_conversion, Qundecided; |
88365 | 310 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
311 Lisp_Object Qbig, Qlittle; |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
312 Lisp_Object Qcoding_system_history; |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
313 Lisp_Object Qvalid_codes; |
17052 | 314 |
315 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | |
316 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | |
317 Lisp_Object Qstart_process, Qopen_network_stream; | |
318 Lisp_Object Qtarget_idx; | |
319 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
320 Lisp_Object Vselect_safe_coding_system_function; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
321 |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
322 /* Mnemonic string for each format of end-of-line. */ |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
323 Lisp_Object eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac; |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
324 /* Mnemonic string to indicate format of end-of-line is not yet |
17052 | 325 decided. */ |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
326 Lisp_Object eol_mnemonic_undecided; |
17052 | 327 |
328 #ifdef emacs | |
329 | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
330 Lisp_Object Vcoding_system_list, Vcoding_system_alist; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
331 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
332 Lisp_Object Qcoding_system_p, Qcoding_system_error; |
17052 | 333 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
334 /* Coding system emacs-mule and raw-text are for converting only |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
335 end-of-line format. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
336 Lisp_Object Qemacs_mule, Qraw_text; |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
337 |
17052 | 338 /* Coding-systems are handed between Emacs Lisp programs and C internal |
339 routines by the following three variables. */ | |
340 /* Coding-system for reading files and receiving data from process. */ | |
341 Lisp_Object Vcoding_system_for_read; | |
342 /* Coding-system for writing files and sending data to process. */ | |
343 Lisp_Object Vcoding_system_for_write; | |
344 /* Coding-system actually used in the latest I/O. */ | |
345 Lisp_Object Vlast_coding_system_used; | |
346 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
347 /* A vector of length 256 which contains information about special |
22529 | 348 Latin codes (especially for dealing with Microsoft codes). */ |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
349 Lisp_Object Vlatin_extra_code_table; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
350 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
351 /* Flag to inhibit code conversion of end-of-line format. */ |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
352 int inhibit_eol_conversion; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
353 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
354 /* Flag to inhibit ISO2022 escape sequence detection. */ |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
355 int inhibit_iso_escape_detection; |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
356 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
357 /* Flag to make buffer-file-coding-system inherit from process-coding. */ |
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
358 int inherit_process_coding_system; |
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
359 |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
360 /* Coding system to be used to encode text for terminal display. */ |
17052 | 361 struct coding_system terminal_coding; |
362 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
363 /* Coding system to be used to encode text for terminal display when |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
364 terminal coding system is nil. */ |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
365 struct coding_system safe_terminal_coding; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
366 |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
367 /* Coding system of what is sent from terminal keyboard. */ |
17052 | 368 struct coding_system keyboard_coding; |
369 | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
370 Lisp_Object Vfile_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
371 Lisp_Object Vprocess_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
372 Lisp_Object Vnetwork_coding_system_alist; |
17052 | 373 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
374 Lisp_Object Vlocale_coding_system; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
375 |
17052 | 376 #endif /* emacs */ |
377 | |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
378 /* Flag to tell if we look up translation table on character code |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
379 conversion. */ |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
380 Lisp_Object Venable_character_translation; |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
381 /* Standard translation table to look up on decoding (reading). */ |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
382 Lisp_Object Vstandard_translation_table_for_decode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
383 /* Standard translation table to look up on encoding (writing). */ |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
384 Lisp_Object Vstandard_translation_table_for_encode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
385 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
386 Lisp_Object Qtranslation_table; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
387 Lisp_Object Qtranslation_table_id; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
388 Lisp_Object Qtranslation_table_for_decode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
389 Lisp_Object Qtranslation_table_for_encode; |
17052 | 390 |
391 /* Alist of charsets vs revision number. */ | |
88365 | 392 static Lisp_Object Vcharset_revision_table; |
17052 | 393 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
394 /* Default coding systems used for process I/O. */ |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
395 Lisp_Object Vdefault_process_coding_system; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
396 |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
397 /* Global flag to tell that we can't call post-read-conversion and |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
398 pre-write-conversion functions. Usually the value is zero, but it |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
399 is set to 1 temporarily while such functions are running. This is |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
400 to avoid infinite recursive call. */ |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
401 static int inhibit_pre_post_conversion; |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
402 |
88365 | 403 /* Two special coding systems. */ |
404 Lisp_Object Vsjis_coding_system; | |
405 Lisp_Object Vbig5_coding_system; | |
406 | |
407 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
408 static int detect_coding_utf_8 P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
409 struct coding_detection_info *info)); |
88365 | 410 static void decode_coding_utf_8 P_ ((struct coding_system *)); |
411 static int encode_coding_utf_8 P_ ((struct coding_system *)); | |
412 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
413 static int detect_coding_utf_16 P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
414 struct coding_detection_info *info)); |
88365 | 415 static void decode_coding_utf_16 P_ ((struct coding_system *)); |
416 static int encode_coding_utf_16 P_ ((struct coding_system *)); | |
417 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
418 static int detect_coding_iso_2022 P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
419 struct coding_detection_info *info)); |
88365 | 420 static void decode_coding_iso_2022 P_ ((struct coding_system *)); |
421 static int encode_coding_iso_2022 P_ ((struct coding_system *)); | |
422 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
423 static int detect_coding_emacs_mule P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
424 struct coding_detection_info *info)); |
88365 | 425 static void decode_coding_emacs_mule P_ ((struct coding_system *)); |
426 static int encode_coding_emacs_mule P_ ((struct coding_system *)); | |
427 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
428 static int detect_coding_sjis P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
429 struct coding_detection_info *info)); |
88365 | 430 static void decode_coding_sjis P_ ((struct coding_system *)); |
431 static int encode_coding_sjis P_ ((struct coding_system *)); | |
432 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
433 static int detect_coding_big5 P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
434 struct coding_detection_info *info)); |
88365 | 435 static void decode_coding_big5 P_ ((struct coding_system *)); |
436 static int encode_coding_big5 P_ ((struct coding_system *)); | |
437 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
438 static int detect_coding_ccl P_ ((struct coding_system *, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
439 struct coding_detection_info *info)); |
88365 | 440 static void decode_coding_ccl P_ ((struct coding_system *)); |
441 static int encode_coding_ccl P_ ((struct coding_system *)); | |
442 | |
443 static void decode_coding_raw_text P_ ((struct coding_system *)); | |
444 static int encode_coding_raw_text P_ ((struct coding_system *)); | |
445 | |
446 | |
447 /* ISO2022 section */ | |
448 | |
449 #define CODING_ISO_INITIAL(coding, reg) \ | |
450 (XINT (AREF (AREF (CODING_ID_ATTRS ((coding)->id), \ | |
451 coding_attr_iso_initial), \ | |
452 reg))) | |
453 | |
454 | |
455 #define CODING_ISO_REQUEST(coding, charset_id) \ | |
456 ((charset_id <= (coding)->max_charset_id \ | |
457 ? (coding)->safe_charsets[charset_id] \ | |
458 : -1)) | |
459 | |
460 | |
461 #define CODING_ISO_FLAGS(coding) \ | |
462 ((coding)->spec.iso_2022.flags) | |
463 #define CODING_ISO_DESIGNATION(coding, reg) \ | |
464 ((coding)->spec.iso_2022.current_designation[reg]) | |
465 #define CODING_ISO_INVOCATION(coding, plane) \ | |
466 ((coding)->spec.iso_2022.current_invocation[plane]) | |
467 #define CODING_ISO_SINGLE_SHIFTING(coding) \ | |
468 ((coding)->spec.iso_2022.single_shifting) | |
469 #define CODING_ISO_BOL(coding) \ | |
470 ((coding)->spec.iso_2022.bol) | |
471 #define CODING_ISO_INVOKED_CHARSET(coding, plane) \ | |
472 CODING_ISO_DESIGNATION ((coding), CODING_ISO_INVOCATION ((coding), (plane))) | |
473 | |
474 /* Control characters of ISO2022. */ | |
475 /* code */ /* function */ | |
476 #define ISO_CODE_LF 0x0A /* line-feed */ | |
477 #define ISO_CODE_CR 0x0D /* carriage-return */ | |
478 #define ISO_CODE_SO 0x0E /* shift-out */ | |
479 #define ISO_CODE_SI 0x0F /* shift-in */ | |
480 #define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */ | |
481 #define ISO_CODE_ESC 0x1B /* escape */ | |
482 #define ISO_CODE_SS2 0x8E /* single-shift-2 */ | |
483 #define ISO_CODE_SS3 0x8F /* single-shift-3 */ | |
484 #define ISO_CODE_CSI 0x9B /* control-sequence-introducer */ | |
485 | |
486 /* All code (1-byte) of ISO2022 is classified into one of the | |
487 followings. */ | |
488 enum iso_code_class_type | |
489 { | |
490 ISO_control_0, /* Control codes in the range | |
491 0x00..0x1F and 0x7F, except for the | |
492 following 5 codes. */ | |
493 ISO_carriage_return, /* ISO_CODE_CR (0x0D) */ | |
494 ISO_shift_out, /* ISO_CODE_SO (0x0E) */ | |
495 ISO_shift_in, /* ISO_CODE_SI (0x0F) */ | |
496 ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ | |
497 ISO_escape, /* ISO_CODE_SO (0x1B) */ | |
498 ISO_control_1, /* Control codes in the range | |
499 0x80..0x9F, except for the | |
500 following 3 codes. */ | |
501 ISO_single_shift_2, /* ISO_CODE_SS2 (0x8E) */ | |
502 ISO_single_shift_3, /* ISO_CODE_SS3 (0x8F) */ | |
503 ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */ | |
504 ISO_0x20_or_0x7F, /* Codes of the values 0x20 or 0x7F. */ | |
505 ISO_graphic_plane_0, /* Graphic codes in the range 0x21..0x7E. */ | |
506 ISO_0xA0_or_0xFF, /* Codes of the values 0xA0 or 0xFF. */ | |
507 ISO_graphic_plane_1 /* Graphic codes in the range 0xA1..0xFE. */ | |
508 }; | |
509 | |
510 /** The macros CODING_ISO_FLAG_XXX defines a flag bit of the | |
511 `iso-flags' attribute of an iso2022 coding system. */ | |
512 | |
513 /* If set, produce long-form designation sequence (e.g. ESC $ ( A) | |
514 instead of the correct short-form sequence (e.g. ESC $ A). */ | |
515 #define CODING_ISO_FLAG_LONG_FORM 0x0001 | |
516 | |
517 /* If set, reset graphic planes and registers at end-of-line to the | |
518 initial state. */ | |
519 #define CODING_ISO_FLAG_RESET_AT_EOL 0x0002 | |
520 | |
521 /* If set, reset graphic planes and registers before any control | |
522 characters to the initial state. */ | |
523 #define CODING_ISO_FLAG_RESET_AT_CNTL 0x0004 | |
524 | |
525 /* If set, encode by 7-bit environment. */ | |
526 #define CODING_ISO_FLAG_SEVEN_BITS 0x0008 | |
527 | |
528 /* If set, use locking-shift function. */ | |
529 #define CODING_ISO_FLAG_LOCKING_SHIFT 0x0010 | |
530 | |
531 /* If set, use single-shift function. Overwrite | |
532 CODING_ISO_FLAG_LOCKING_SHIFT. */ | |
533 #define CODING_ISO_FLAG_SINGLE_SHIFT 0x0020 | |
534 | |
535 /* If set, use designation escape sequence. */ | |
536 #define CODING_ISO_FLAG_DESIGNATION 0x0040 | |
537 | |
538 /* If set, produce revision number sequence. */ | |
539 #define CODING_ISO_FLAG_REVISION 0x0080 | |
540 | |
541 /* If set, produce ISO6429's direction specifying sequence. */ | |
542 #define CODING_ISO_FLAG_DIRECTION 0x0100 | |
543 | |
544 /* If set, assume designation states are reset at beginning of line on | |
545 output. */ | |
546 #define CODING_ISO_FLAG_INIT_AT_BOL 0x0200 | |
547 | |
548 /* If set, designation sequence should be placed at beginning of line | |
549 on output. */ | |
550 #define CODING_ISO_FLAG_DESIGNATE_AT_BOL 0x0400 | |
551 | |
552 /* If set, do not encode unsafe charactes on output. */ | |
553 #define CODING_ISO_FLAG_SAFE 0x0800 | |
554 | |
555 /* If set, extra latin codes (128..159) are accepted as a valid code | |
556 on input. */ | |
557 #define CODING_ISO_FLAG_LATIN_EXTRA 0x1000 | |
558 | |
559 #define CODING_ISO_FLAG_COMPOSITION 0x2000 | |
560 | |
561 #define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 | |
562 | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
563 #define CODING_ISO_FLAG_USE_ROMAN 0x8000 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
564 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
565 #define CODING_ISO_FLAG_USE_OLDJIS 0x10000 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
566 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
567 #define CODING_ISO_FLAG_FULL_SUPPORT 0x100000 |
88365 | 568 |
569 /* A character to be produced on output if encoding of the original | |
570 character is prohibited by CODING_ISO_FLAG_SAFE. */ | |
571 #define CODING_INHIBIT_CHARACTER_SUBSTITUTION '?' | |
572 | |
573 | |
574 /* UTF-16 section */ | |
575 #define CODING_UTF_16_BOM(coding) \ | |
576 ((coding)->spec.utf_16.bom) | |
577 | |
578 #define CODING_UTF_16_ENDIAN(coding) \ | |
579 ((coding)->spec.utf_16.endian) | |
580 | |
581 #define CODING_UTF_16_SURROGATE(coding) \ | |
582 ((coding)->spec.utf_16.surrogate) | |
583 | |
584 | |
585 /* CCL section */ | |
586 #define CODING_CCL_DECODER(coding) \ | |
587 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_decoder) | |
588 #define CODING_CCL_ENCODER(coding) \ | |
589 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_encoder) | |
590 #define CODING_CCL_VALIDS(coding) \ | |
591 (XSTRING (AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_valids)) \ | |
592 ->data) | |
593 | |
88771 | 594 /* Index for each coding category in `coding_categories' */ |
88365 | 595 |
596 enum coding_category | |
597 { | |
598 coding_category_iso_7, | |
599 coding_category_iso_7_tight, | |
600 coding_category_iso_8_1, | |
601 coding_category_iso_8_2, | |
602 coding_category_iso_7_else, | |
603 coding_category_iso_8_else, | |
604 coding_category_utf_8, | |
605 coding_category_utf_16_auto, | |
606 coding_category_utf_16_be, | |
607 coding_category_utf_16_le, | |
608 coding_category_utf_16_be_nosig, | |
609 coding_category_utf_16_le_nosig, | |
610 coding_category_charset, | |
611 coding_category_sjis, | |
612 coding_category_big5, | |
613 coding_category_ccl, | |
614 coding_category_emacs_mule, | |
615 /* All above are targets of code detection. */ | |
616 coding_category_raw_text, | |
617 coding_category_undecided, | |
618 coding_category_max | |
619 }; | |
620 | |
621 /* Definitions of flag bits used in detect_coding_XXXX. */ | |
622 #define CATEGORY_MASK_ISO_7 (1 << coding_category_iso_7) | |
623 #define CATEGORY_MASK_ISO_7_TIGHT (1 << coding_category_iso_7_tight) | |
624 #define CATEGORY_MASK_ISO_8_1 (1 << coding_category_iso_8_1) | |
625 #define CATEGORY_MASK_ISO_8_2 (1 << coding_category_iso_8_2) | |
626 #define CATEGORY_MASK_ISO_7_ELSE (1 << coding_category_iso_7_else) | |
627 #define CATEGORY_MASK_ISO_8_ELSE (1 << coding_category_iso_8_else) | |
628 #define CATEGORY_MASK_UTF_8 (1 << coding_category_utf_8) | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
629 #define CATEGORY_MASK_UTF_16_AUTO (1 << coding_category_utf_16_auto) |
88365 | 630 #define CATEGORY_MASK_UTF_16_BE (1 << coding_category_utf_16_be) |
631 #define CATEGORY_MASK_UTF_16_LE (1 << coding_category_utf_16_le) | |
632 #define CATEGORY_MASK_UTF_16_BE_NOSIG (1 << coding_category_utf_16_be_nosig) | |
633 #define CATEGORY_MASK_UTF_16_LE_NOSIG (1 << coding_category_utf_16_le_nosig) | |
634 #define CATEGORY_MASK_CHARSET (1 << coding_category_charset) | |
635 #define CATEGORY_MASK_SJIS (1 << coding_category_sjis) | |
636 #define CATEGORY_MASK_BIG5 (1 << coding_category_big5) | |
637 #define CATEGORY_MASK_CCL (1 << coding_category_ccl) | |
638 #define CATEGORY_MASK_EMACS_MULE (1 << coding_category_emacs_mule) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
639 #define CATEGORY_MASK_RAW_TEXT (1 << coding_category_raw_text) |
88365 | 640 |
641 /* This value is returned if detect_coding_mask () find nothing other | |
642 than ASCII characters. */ | |
643 #define CATEGORY_MASK_ANY \ | |
644 (CATEGORY_MASK_ISO_7 \ | |
645 | CATEGORY_MASK_ISO_7_TIGHT \ | |
646 | CATEGORY_MASK_ISO_8_1 \ | |
647 | CATEGORY_MASK_ISO_8_2 \ | |
648 | CATEGORY_MASK_ISO_7_ELSE \ | |
649 | CATEGORY_MASK_ISO_8_ELSE \ | |
650 | CATEGORY_MASK_UTF_8 \ | |
651 | CATEGORY_MASK_UTF_16_BE \ | |
652 | CATEGORY_MASK_UTF_16_LE \ | |
653 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
654 | CATEGORY_MASK_UTF_16_LE_NOSIG \ | |
655 | CATEGORY_MASK_CHARSET \ | |
656 | CATEGORY_MASK_SJIS \ | |
657 | CATEGORY_MASK_BIG5 \ | |
658 | CATEGORY_MASK_CCL \ | |
659 | CATEGORY_MASK_EMACS_MULE) | |
660 | |
661 | |
662 #define CATEGORY_MASK_ISO_7BIT \ | |
663 (CATEGORY_MASK_ISO_7 | CATEGORY_MASK_ISO_7_TIGHT) | |
664 | |
665 #define CATEGORY_MASK_ISO_8BIT \ | |
666 (CATEGORY_MASK_ISO_8_1 | CATEGORY_MASK_ISO_8_2) | |
667 | |
668 #define CATEGORY_MASK_ISO_ELSE \ | |
669 (CATEGORY_MASK_ISO_7_ELSE | CATEGORY_MASK_ISO_8_ELSE) | |
670 | |
671 #define CATEGORY_MASK_ISO_ESCAPE \ | |
672 (CATEGORY_MASK_ISO_7 \ | |
673 | CATEGORY_MASK_ISO_7_TIGHT \ | |
674 | CATEGORY_MASK_ISO_7_ELSE \ | |
675 | CATEGORY_MASK_ISO_8_ELSE) | |
676 | |
677 #define CATEGORY_MASK_ISO \ | |
678 ( CATEGORY_MASK_ISO_7BIT \ | |
679 | CATEGORY_MASK_ISO_8BIT \ | |
680 | CATEGORY_MASK_ISO_ELSE) | |
681 | |
682 #define CATEGORY_MASK_UTF_16 \ | |
683 (CATEGORY_MASK_UTF_16_BE \ | |
684 | CATEGORY_MASK_UTF_16_LE \ | |
685 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
686 | CATEGORY_MASK_UTF_16_LE_NOSIG) | |
687 | |
688 | |
689 /* List of symbols `coding-category-xxx' ordered by priority. This | |
690 variable is exposed to Emacs Lisp. */ | |
691 static Lisp_Object Vcoding_category_list; | |
692 | |
693 /* Table of coding categories (Lisp symbols). This variable is for | |
694 internal use oly. */ | |
695 static Lisp_Object Vcoding_category_table; | |
696 | |
697 /* Table of coding-categories ordered by priority. */ | |
698 static enum coding_category coding_priorities[coding_category_max]; | |
699 | |
700 /* Nth element is a coding context for the coding system bound to the | |
701 Nth coding category. */ | |
702 static struct coding_system coding_categories[coding_category_max]; | |
703 | |
704 static int detected_mask[coding_category_raw_text] = | |
705 { CATEGORY_MASK_ISO, | |
706 CATEGORY_MASK_ISO, | |
707 CATEGORY_MASK_ISO, | |
708 CATEGORY_MASK_ISO, | |
709 CATEGORY_MASK_ISO, | |
710 CATEGORY_MASK_ISO, | |
711 CATEGORY_MASK_UTF_8, | |
712 CATEGORY_MASK_UTF_16, | |
713 CATEGORY_MASK_UTF_16, | |
714 CATEGORY_MASK_UTF_16, | |
715 CATEGORY_MASK_UTF_16, | |
716 CATEGORY_MASK_UTF_16, | |
717 CATEGORY_MASK_CHARSET, | |
718 CATEGORY_MASK_SJIS, | |
719 CATEGORY_MASK_BIG5, | |
720 CATEGORY_MASK_CCL, | |
721 CATEGORY_MASK_EMACS_MULE | |
722 }; | |
723 | |
724 /*** Commonly used macros and functions ***/ | |
725 | |
726 #ifndef min | |
727 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
728 #endif | |
729 #ifndef max | |
730 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
731 #endif | |
732 | |
733 #define CODING_GET_INFO(coding, attrs, eol_type, charset_list) \ | |
734 do { \ | |
735 attrs = CODING_ID_ATTRS (coding->id); \ | |
736 eol_type = CODING_ID_EOL_TYPE (coding->id); \ | |
737 if (VECTORP (eol_type)) \ | |
738 eol_type = Qunix; \ | |
739 charset_list = CODING_ATTR_CHARSET_LIST (attrs); \ | |
740 } while (0) | |
741 | |
742 | |
743 /* Safely get one byte from the source text pointed by SRC which ends | |
744 at SRC_END, and set C to that byte. If there are not enough bytes | |
745 in the source, it jumps to `no_more_source'. The caller | |
746 should declare and set these variables appropriately in advance: | |
747 src, src_end, multibytep | |
748 */ | |
749 | |
750 #define ONE_MORE_BYTE(c) \ | |
751 do { \ | |
752 if (src == src_end) \ | |
753 { \ | |
754 if (src_base < src) \ | |
755 coding->result = CODING_RESULT_INSUFFICIENT_SRC; \ | |
756 goto no_more_source; \ | |
757 } \ | |
758 c = *src++; \ | |
759 if (multibytep && (c & 0x80)) \ | |
760 { \ | |
761 if ((c & 0xFE) != 0xC0) \ | |
762 error ("Undecodable char found"); \ | |
763 c = ((c & 1) << 6) | *src++; \ | |
764 } \ | |
765 consumed_chars++; \ | |
766 } while (0) | |
767 | |
768 | |
769 #define ONE_MORE_BYTE_NO_CHECK(c) \ | |
770 do { \ | |
771 c = *src++; \ | |
772 if (multibytep && (c & 0x80)) \ | |
773 { \ | |
774 if ((c & 0xFE) != 0xC0) \ | |
775 error ("Undecodable char found"); \ | |
776 c = ((c & 1) << 6) | *src++; \ | |
777 } \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
778 consumed_chars++; \ |
88365 | 779 } while (0) |
780 | |
781 | |
782 /* Store a byte C in the place pointed by DST and increment DST to the | |
783 next free point, and increment PRODUCED_CHARS. The caller should | |
784 assure that C is 0..127, and declare and set the variable `dst' | |
785 appropriately in advance. | |
786 */ | |
787 | |
788 | |
789 #define EMIT_ONE_ASCII_BYTE(c) \ | |
790 do { \ | |
791 produced_chars++; \ | |
792 *dst++ = (c); \ | |
793 } while (0) | |
794 | |
795 | |
796 /* Like EMIT_ONE_ASCII_BYTE byt store two bytes; C1 and C2. */ | |
797 | |
798 #define EMIT_TWO_ASCII_BYTES(c1, c2) \ | |
799 do { \ | |
800 produced_chars += 2; \ | |
801 *dst++ = (c1), *dst++ = (c2); \ | |
802 } while (0) | |
803 | |
804 | |
805 /* Store a byte C in the place pointed by DST and increment DST to the | |
806 next free point, and increment PRODUCED_CHARS. If MULTIBYTEP is | |
807 nonzero, store in an appropriate multibyte from. The caller should | |
808 declare and set the variables `dst' and `multibytep' appropriately | |
809 in advance. */ | |
810 | |
811 #define EMIT_ONE_BYTE(c) \ | |
812 do { \ | |
813 produced_chars++; \ | |
814 if (multibytep) \ | |
815 { \ | |
816 int ch = (c); \ | |
817 if (ch >= 0x80) \ | |
818 ch = BYTE8_TO_CHAR (ch); \ | |
819 CHAR_STRING_ADVANCE (ch, dst); \ | |
820 } \ | |
821 else \ | |
822 *dst++ = (c); \ | |
823 } while (0) | |
824 | |
825 | |
826 /* Like EMIT_ONE_BYTE, but emit two bytes; C1 and C2. */ | |
827 | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
828 #define EMIT_TWO_BYTES(c1, c2) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
829 do { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
830 produced_chars += 2; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
831 if (multibytep) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
832 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
833 int ch; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
834 \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
835 ch = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
836 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
837 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
838 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
839 ch = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
840 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
841 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
842 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
843 } \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
844 else \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
845 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
846 *dst++ = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
847 *dst++ = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
848 } \ |
88365 | 849 } while (0) |
850 | |
851 | |
852 #define EMIT_THREE_BYTES(c1, c2, c3) \ | |
853 do { \ | |
854 EMIT_ONE_BYTE (c1); \ | |
855 EMIT_TWO_BYTES (c2, c3); \ | |
856 } while (0) | |
857 | |
858 | |
859 #define EMIT_FOUR_BYTES(c1, c2, c3, c4) \ | |
860 do { \ | |
861 EMIT_TWO_BYTES (c1, c2); \ | |
862 EMIT_TWO_BYTES (c3, c4); \ | |
863 } while (0) | |
864 | |
865 | |
866 #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ | |
867 do { \ | |
868 charset_map_loaded = 0; \ | |
869 c = DECODE_CHAR (charset, code); \ | |
870 if (charset_map_loaded) \ | |
871 { \ | |
872 unsigned char *orig = coding->source; \ | |
873 EMACS_INT offset; \ | |
874 \ | |
875 coding_set_source (coding); \ | |
876 offset = coding->source - orig; \ | |
877 src += offset; \ | |
878 src_base += offset; \ | |
879 src_end += offset; \ | |
880 } \ | |
881 } while (0) | |
882 | |
883 | |
884 #define ASSURE_DESTINATION(bytes) \ | |
885 do { \ | |
886 if (dst + (bytes) >= dst_end) \ | |
887 { \ | |
888 int more_bytes = charbuf_end - charbuf + (bytes); \ | |
889 \ | |
890 dst = alloc_destination (coding, more_bytes, dst); \ | |
891 dst_end = coding->destination + coding->dst_bytes; \ | |
892 } \ | |
893 } while (0) | |
894 | |
895 | |
896 | |
897 static void | |
898 coding_set_source (coding) | |
899 struct coding_system *coding; | |
900 { | |
901 if (BUFFERP (coding->src_object)) | |
902 { | |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
903 struct buffer *buf = XBUFFER (coding->src_object); |
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
904 |
88365 | 905 if (coding->src_pos < 0) |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
906 coding->source = BUF_GAP_END_ADDR (buf) + coding->src_pos_byte; |
88365 | 907 else |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
908 coding->source = BUF_BYTE_ADDRESS (buf, coding->src_pos_byte); |
88365 | 909 } |
910 else if (STRINGP (coding->src_object)) | |
911 { | |
912 coding->source = (XSTRING (coding->src_object)->data | |
913 + coding->src_pos_byte); | |
914 } | |
915 else | |
916 /* Otherwise, the source is C string and is never relocated | |
917 automatically. Thus we don't have to update anything. */ | |
918 ; | |
919 } | |
920 | |
921 static void | |
922 coding_set_destination (coding) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
923 struct coding_system *coding; |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
924 { |
88365 | 925 if (BUFFERP (coding->dst_object)) |
926 { | |
927 if (coding->src_pos < 0) | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
928 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
929 coding->destination = BEG_ADDR + coding->dst_pos_byte - 1; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
930 coding->dst_bytes = (GAP_END_ADDR |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
931 - (coding->src_bytes - coding->consumed) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
932 - coding->destination); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
933 } |
88365 | 934 else |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
935 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
936 /* We are sure that coding->dst_pos_byte is before the gap |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
937 of the buffer. */ |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
938 coding->destination = (BUF_BEG_ADDR (XBUFFER (coding->dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
939 + coding->dst_pos_byte - 1); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
940 coding->dst_bytes = (BUF_GAP_END_ADDR (XBUFFER (coding->dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
941 - coding->destination); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
942 } |
88365 | 943 } |
944 else | |
945 /* Otherwise, the destination is C string and is never relocated | |
946 automatically. Thus we don't have to update anything. */ | |
947 ; | |
948 } | |
949 | |
950 | |
951 static void | |
952 coding_alloc_by_realloc (coding, bytes) | |
953 struct coding_system *coding; | |
954 EMACS_INT bytes; | |
955 { | |
956 coding->destination = (unsigned char *) xrealloc (coding->destination, | |
957 coding->dst_bytes + bytes); | |
958 coding->dst_bytes += bytes; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
959 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
960 |
88365 | 961 static void |
962 coding_alloc_by_making_gap (coding, bytes) | |
963 struct coding_system *coding; | |
964 EMACS_INT bytes; | |
965 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
966 if (BUFFERP (coding->dst_object) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
967 && EQ (coding->src_object, coding->dst_object)) |
88365 | 968 { |
969 EMACS_INT add = coding->src_bytes - coding->consumed; | |
970 | |
971 GAP_SIZE -= add; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add; | |
972 make_gap (bytes); | |
973 GAP_SIZE += add; ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add; | |
974 } | |
975 else | |
976 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
977 Lisp_Object this_buffer; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
978 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
979 this_buffer = Fcurrent_buffer (); |
88365 | 980 set_buffer_internal (XBUFFER (coding->dst_object)); |
981 make_gap (bytes); | |
982 set_buffer_internal (XBUFFER (this_buffer)); | |
983 } | |
984 } | |
985 | |
986 | |
987 static unsigned char * | |
988 alloc_destination (coding, nbytes, dst) | |
989 struct coding_system *coding; | |
990 int nbytes; | |
991 unsigned char *dst; | |
992 { | |
993 EMACS_INT offset = dst - coding->destination; | |
994 | |
995 if (BUFFERP (coding->dst_object)) | |
996 coding_alloc_by_making_gap (coding, nbytes); | |
997 else | |
998 coding_alloc_by_realloc (coding, nbytes); | |
999 coding->result = CODING_RESULT_SUCCESS; | |
1000 coding_set_destination (coding); | |
1001 dst = coding->destination + offset; | |
1002 return dst; | |
1003 } | |
1004 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1005 /** Macros for annotations. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1006 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1007 /* Maximum length of annotation data (sum of annotations for |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1008 composition and charset). */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1009 #define MAX_ANNOTATION_LENGTH (5 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 + 5) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1010 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1011 /* An annotation data is stored in the array coding->charbuf in this |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1012 format: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1013 [ -LENGTH ANNOTATION_MASK FROM TO ... ] |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1014 LENGTH is the number of elements in the annotation. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1015 ANNOTATION_MASK is one of CODING_ANNOTATE_XXX_MASK. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1016 FROM and TO specify the range of text annotated. They are relative |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1017 to coding->src_pos (on encoding) or coding->dst_pos (on decoding). |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1018 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1019 The format of the following elements depend on ANNOTATION_MASK. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1020 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1021 In the case of CODING_ANNOTATE_COMPOSITION_MASK, these elements |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1022 follows: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1023 ... METHOD [ COMPOSITION-COMPONENTS ... ] |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1024 METHOD is one of enum composition_method. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1025 Optionnal COMPOSITION-COMPONENTS are characters and composition |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1026 rules. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1027 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1028 In the case of CODING_ANNOTATE_CHARSET_MASK, one element CHARSET-ID |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1029 follows. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1030 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1031 #define ADD_ANNOTATION_DATA(buf, len, mask, from, to) \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1032 do { \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1033 *(buf)++ = -(len); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1034 *(buf)++ = (mask); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1035 *(buf)++ = (from); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1036 *(buf)++ = (to); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1037 coding->annotated = 1; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1038 } while (0); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1039 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1040 #define ADD_COMPOSITION_DATA(buf, from, to, method) \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1041 do { \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1042 ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_COMPOSITION_MASK, from, to); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1043 *buf++ = method; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1044 } while (0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1045 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1046 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1047 #define ADD_CHARSET_DATA(buf, from, to, id) \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1048 do { \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1049 ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_CHARSET_MASK, from, to); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1050 *buf++ = id; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1051 } while (0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1052 |
88365 | 1053 |
1054 /*** 2. Emacs' internal format (emacs-utf-8) ***/ | |
1055 | |
1056 | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1057 |
17052 | 1058 |
88365 | 1059 /*** 3. UTF-8 ***/ |
1060 | |
1061 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1062 Check if a text is encoded in UTF-8. If it is, return 1, else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1063 return 0. */ |
88365 | 1064 |
1065 #define UTF_8_1_OCTET_P(c) ((c) < 0x80) | |
1066 #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80) | |
1067 #define UTF_8_2_OCTET_LEADING_P(c) (((c) & 0xE0) == 0xC0) | |
1068 #define UTF_8_3_OCTET_LEADING_P(c) (((c) & 0xF0) == 0xE0) | |
1069 #define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0) | |
1070 #define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8) | |
1071 | |
1072 static int | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1073 detect_coding_utf_8 (coding, detect_info) |
88365 | 1074 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1075 struct coding_detection_info *detect_info; |
88365 | 1076 { |
1077 unsigned char *src = coding->source, *src_base = src; | |
1078 unsigned char *src_end = coding->source + coding->src_bytes; | |
1079 int multibytep = coding->src_multibyte; | |
1080 int consumed_chars = 0; | |
1081 int found = 0; | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1082 int incomplete; |
88365 | 1083 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1084 detect_info->checked |= CATEGORY_MASK_UTF_8; |
88365 | 1085 /* A coding system of this category is always ASCII compatible. */ |
1086 src += coding->head_ascii; | |
1087 | |
1088 while (1) | |
1089 { | |
1090 int c, c1, c2, c3, c4; | |
1091 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1092 incomplete = 0; |
88365 | 1093 ONE_MORE_BYTE (c); |
1094 if (UTF_8_1_OCTET_P (c)) | |
1095 continue; | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1096 incomplete = 1; |
88365 | 1097 ONE_MORE_BYTE (c1); |
1098 if (! UTF_8_EXTRA_OCTET_P (c1)) | |
1099 break; | |
1100 if (UTF_8_2_OCTET_LEADING_P (c)) | |
1101 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1102 found = CATEGORY_MASK_UTF_8; |
88365 | 1103 continue; |
1104 } | |
1105 ONE_MORE_BYTE (c2); | |
1106 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
1107 break; | |
1108 if (UTF_8_3_OCTET_LEADING_P (c)) | |
1109 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1110 found = CATEGORY_MASK_UTF_8; |
88365 | 1111 continue; |
1112 } | |
1113 ONE_MORE_BYTE (c3); | |
1114 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
1115 break; | |
1116 if (UTF_8_4_OCTET_LEADING_P (c)) | |
1117 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1118 found = CATEGORY_MASK_UTF_8; |
88365 | 1119 continue; |
1120 } | |
1121 ONE_MORE_BYTE (c4); | |
1122 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
1123 break; | |
1124 if (UTF_8_5_OCTET_LEADING_P (c)) | |
1125 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1126 found = CATEGORY_MASK_UTF_8; |
88365 | 1127 continue; |
1128 } | |
1129 break; | |
1130 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1131 detect_info->rejected |= CATEGORY_MASK_UTF_8; |
88365 | 1132 return 0; |
1133 | |
1134 no_more_source: | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1135 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1136 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1137 detect_info->rejected |= CATEGORY_MASK_UTF_8; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1138 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1139 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1140 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1141 return 1; |
88365 | 1142 } |
1143 | |
1144 | |
1145 static void | |
1146 decode_coding_utf_8 (coding) | |
1147 struct coding_system *coding; | |
1148 { | |
1149 unsigned char *src = coding->source + coding->consumed; | |
1150 unsigned char *src_end = coding->source + coding->src_bytes; | |
1151 unsigned char *src_base; | |
1152 int *charbuf = coding->charbuf; | |
1153 int *charbuf_end = charbuf + coding->charbuf_size; | |
1154 int consumed_chars = 0, consumed_chars_base; | |
1155 int multibytep = coding->src_multibyte; | |
1156 Lisp_Object attr, eol_type, charset_list; | |
1157 | |
1158 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
1159 | |
1160 while (1) | |
1161 { | |
1162 int c, c1, c2, c3, c4, c5; | |
1163 | |
1164 src_base = src; | |
1165 consumed_chars_base = consumed_chars; | |
1166 | |
1167 if (charbuf >= charbuf_end) | |
1168 break; | |
1169 | |
1170 ONE_MORE_BYTE (c1); | |
1171 if (UTF_8_1_OCTET_P(c1)) | |
1172 { | |
1173 c = c1; | |
1174 if (c == '\r') | |
1175 { | |
1176 if (EQ (eol_type, Qdos)) | |
1177 { | |
1178 if (src == src_end) | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1179 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1180 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1181 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1182 } |
88365 | 1183 if (*src == '\n') |
1184 ONE_MORE_BYTE (c); | |
1185 } | |
1186 else if (EQ (eol_type, Qmac)) | |
1187 c = '\n'; | |
1188 } | |
1189 } | |
1190 else | |
1191 { | |
1192 ONE_MORE_BYTE (c2); | |
1193 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
1194 goto invalid_code; | |
1195 if (UTF_8_2_OCTET_LEADING_P (c1)) | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1196 { |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1197 c = ((c1 & 0x1F) << 6) | (c2 & 0x3F); |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1198 /* Reject overlong sequences here and below. Encoders |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1199 producing them are incorrect, they can be misleading, |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1200 and they mess up read/write invariance. */ |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1201 if (c < 128) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1202 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1203 } |
88365 | 1204 else |
1205 { | |
1206 ONE_MORE_BYTE (c3); | |
1207 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
1208 goto invalid_code; | |
1209 if (UTF_8_3_OCTET_LEADING_P (c1)) | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1210 { |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1211 c = (((c1 & 0xF) << 12) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1212 | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
89184
88a9e962e183
(decode_coding_utf_8): Treat surrogates as invalid.
Dave Love <fx@gnu.org>
parents:
89042
diff
changeset
|
1213 if (c < 0x800 |
88a9e962e183
(decode_coding_utf_8): Treat surrogates as invalid.
Dave Love <fx@gnu.org>
parents:
89042
diff
changeset
|
1214 || (c >= 0xd800 && c < 0xe000)) /* surrogates (invalid) */ |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1215 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1216 } |
88365 | 1217 else |
1218 { | |
1219 ONE_MORE_BYTE (c4); | |
1220 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
1221 goto invalid_code; | |
1222 if (UTF_8_4_OCTET_LEADING_P (c1)) | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1223 { |
88365 | 1224 c = (((c1 & 0x7) << 18) | ((c2 & 0x3F) << 12) |
1225 | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1226 if (c < 0x10000) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1227 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1228 } |
88365 | 1229 else |
1230 { | |
1231 ONE_MORE_BYTE (c5); | |
1232 if (! UTF_8_EXTRA_OCTET_P (c5)) | |
1233 goto invalid_code; | |
1234 if (UTF_8_5_OCTET_LEADING_P (c1)) | |
1235 { | |
1236 c = (((c1 & 0x3) << 24) | ((c2 & 0x3F) << 18) | |
1237 | ((c3 & 0x3F) << 12) | ((c4 & 0x3F) << 6) | |
1238 | (c5 & 0x3F)); | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1239 if ((c > MAX_CHAR) || (c < 0x200000)) |
88365 | 1240 goto invalid_code; |
1241 } | |
1242 else | |
1243 goto invalid_code; | |
1244 } | |
1245 } | |
1246 } | |
1247 } | |
1248 | |
1249 *charbuf++ = c; | |
1250 continue; | |
1251 | |
1252 invalid_code: | |
1253 src = src_base; | |
1254 consumed_chars = consumed_chars_base; | |
1255 ONE_MORE_BYTE (c); | |
1256 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
1257 coding->errors++; | |
1258 } | |
1259 | |
1260 no_more_source: | |
1261 coding->consumed_char += consumed_chars_base; | |
1262 coding->consumed = src_base - coding->source; | |
1263 coding->charbuf_used = charbuf - coding->charbuf; | |
1264 } | |
1265 | |
1266 | |
1267 static int | |
1268 encode_coding_utf_8 (coding) | |
1269 struct coding_system *coding; | |
1270 { | |
1271 int multibytep = coding->dst_multibyte; | |
1272 int *charbuf = coding->charbuf; | |
1273 int *charbuf_end = charbuf + coding->charbuf_used; | |
1274 unsigned char *dst = coding->destination + coding->produced; | |
1275 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1276 int produced_chars = 0; |
88365 | 1277 int c; |
1278 | |
1279 if (multibytep) | |
1280 { | |
1281 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
1282 | |
1283 while (charbuf < charbuf_end) | |
1284 { | |
1285 unsigned char str[MAX_MULTIBYTE_LENGTH], *p, *pend = str; | |
1286 | |
1287 ASSURE_DESTINATION (safe_room); | |
1288 c = *charbuf++; | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1289 if (CHAR_BYTE8_P (c)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1290 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1291 c = CHAR_TO_BYTE8 (c); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1292 EMIT_ONE_BYTE (c); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1293 } |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1294 else |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1295 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1296 CHAR_STRING_ADVANCE (c, pend); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1297 for (p = str; p < pend; p++) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1298 EMIT_ONE_BYTE (*p); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1299 } |
88365 | 1300 } |
1301 } | |
1302 else | |
1303 { | |
1304 int safe_room = MAX_MULTIBYTE_LENGTH; | |
1305 | |
1306 while (charbuf < charbuf_end) | |
1307 { | |
1308 ASSURE_DESTINATION (safe_room); | |
1309 c = *charbuf++; | |
1310 dst += CHAR_STRING (c, dst); | |
1311 produced_chars++; | |
1312 } | |
1313 } | |
1314 coding->result = CODING_RESULT_SUCCESS; | |
1315 coding->produced_char += produced_chars; | |
1316 coding->produced = dst - coding->destination; | |
1317 return 0; | |
1318 } | |
1319 | |
1320 | |
1321 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1322 Check if a text is encoded in one of UTF-16 based coding systems. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1323 If it is, return 1, else return 0. */ |
88365 | 1324 |
1325 #define UTF_16_HIGH_SURROGATE_P(val) \ | |
1326 (((val) & 0xFC00) == 0xD800) | |
1327 | |
1328 #define UTF_16_LOW_SURROGATE_P(val) \ | |
1329 (((val) & 0xFC00) == 0xDC00) | |
1330 | |
1331 #define UTF_16_INVALID_P(val) \ | |
1332 (((val) == 0xFFFE) \ | |
1333 || ((val) == 0xFFFF) \ | |
1334 || UTF_16_LOW_SURROGATE_P (val)) | |
1335 | |
1336 | |
1337 static int | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1338 detect_coding_utf_16 (coding, detect_info) |
88365 | 1339 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1340 struct coding_detection_info *detect_info; |
88365 | 1341 { |
1342 unsigned char *src = coding->source, *src_base = src; | |
1343 unsigned char *src_end = coding->source + coding->src_bytes; | |
1344 int multibytep = coding->src_multibyte; | |
1345 int consumed_chars = 0; | |
1346 int c1, c2; | |
1347 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1348 detect_info->checked |= CATEGORY_MASK_UTF_16; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1349 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1350 if (coding->mode & CODING_MODE_LAST_BLOCK |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1351 && (coding->src_bytes & 1)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1352 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1353 detect_info->rejected |= CATEGORY_MASK_UTF_16; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1354 return 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1355 } |
88365 | 1356 ONE_MORE_BYTE (c1); |
1357 ONE_MORE_BYTE (c2); | |
1358 | |
1359 if ((c1 == 0xFF) && (c2 == 0xFE)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1360 { |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1361 detect_info->found |= (CATEGORY_MASK_UTF_16_LE |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1362 | CATEGORY_MASK_UTF_16_AUTO); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1363 detect_info->rejected |= CATEGORY_MASK_UTF_16_BE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1364 } |
88365 | 1365 else if ((c1 == 0xFE) && (c2 == 0xFF)) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1366 { |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1367 detect_info->found |= (CATEGORY_MASK_UTF_16_BE |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1368 | CATEGORY_MASK_UTF_16_AUTO); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1369 detect_info->rejected |= CATEGORY_MASK_UTF_16_LE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1370 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1371 no_more_source: |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1372 return 1; |
88365 | 1373 } |
1374 | |
1375 static void | |
1376 decode_coding_utf_16 (coding) | |
1377 struct coding_system *coding; | |
1378 { | |
1379 unsigned char *src = coding->source + coding->consumed; | |
1380 unsigned char *src_end = coding->source + coding->src_bytes; | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
1381 unsigned char *src_base; |
88365 | 1382 int *charbuf = coding->charbuf; |
1383 int *charbuf_end = charbuf + coding->charbuf_size; | |
1384 int consumed_chars = 0, consumed_chars_base; | |
1385 int multibytep = coding->src_multibyte; | |
1386 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
1387 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); | |
1388 int surrogate = CODING_UTF_16_SURROGATE (coding); | |
1389 Lisp_Object attr, eol_type, charset_list; | |
1390 | |
1391 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
1392 | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1393 if (bom == utf_16_with_bom) |
88365 | 1394 { |
1395 int c, c1, c2; | |
1396 | |
1397 src_base = src; | |
1398 ONE_MORE_BYTE (c1); | |
1399 ONE_MORE_BYTE (c2); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1400 c = (c1 << 8) | c2; |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1401 |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1402 if (endian == utf_16_big_endian |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1403 ? c != 0xFEFF : c != 0xFFFE) |
88365 | 1404 { |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1405 /* The first two bytes are not BOM. Treat them as bytes |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1406 for a normal character. */ |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1407 src = src_base; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1408 coding->errors++; |
88365 | 1409 } |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1410 CODING_UTF_16_BOM (coding) = utf_16_without_bom; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1411 } |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1412 else if (bom == utf_16_detect_bom) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1413 { |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1414 /* We have already tried to detect BOM and failed in |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1415 detect_coding. */ |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1416 CODING_UTF_16_BOM (coding) = utf_16_without_bom; |
88365 | 1417 } |
1418 | |
1419 while (1) | |
1420 { | |
1421 int c, c1, c2; | |
1422 | |
1423 src_base = src; | |
1424 consumed_chars_base = consumed_chars; | |
1425 | |
1426 if (charbuf + 2 >= charbuf_end) | |
1427 break; | |
1428 | |
1429 ONE_MORE_BYTE (c1); | |
1430 ONE_MORE_BYTE (c2); | |
1431 c = (endian == utf_16_big_endian | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1432 ? ((c1 << 8) | c2) : ((c2 << 8) | c1)); |
88365 | 1433 if (surrogate) |
1434 { | |
1435 if (! UTF_16_LOW_SURROGATE_P (c)) | |
1436 { | |
1437 if (endian == utf_16_big_endian) | |
1438 c1 = surrogate >> 8, c2 = surrogate & 0xFF; | |
1439 else | |
1440 c1 = surrogate & 0xFF, c2 = surrogate >> 8; | |
1441 *charbuf++ = c1; | |
1442 *charbuf++ = c2; | |
1443 coding->errors++; | |
1444 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1445 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1446 else | |
1447 *charbuf++ = c; | |
1448 } | |
1449 else | |
1450 { | |
1451 c = ((surrogate - 0xD800) << 10) | (c - 0xDC00); | |
1452 CODING_UTF_16_SURROGATE (coding) = surrogate = 0; | |
1453 *charbuf++ = c; | |
1454 } | |
1455 } | |
1456 else | |
1457 { | |
1458 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1459 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1460 else | |
1461 *charbuf++ = c; | |
1462 } | |
1463 } | |
1464 | |
1465 no_more_source: | |
1466 coding->consumed_char += consumed_chars_base; | |
1467 coding->consumed = src_base - coding->source; | |
1468 coding->charbuf_used = charbuf - coding->charbuf; | |
1469 } | |
1470 | |
1471 static int | |
1472 encode_coding_utf_16 (coding) | |
1473 struct coding_system *coding; | |
1474 { | |
1475 int multibytep = coding->dst_multibyte; | |
1476 int *charbuf = coding->charbuf; | |
1477 int *charbuf_end = charbuf + coding->charbuf_used; | |
1478 unsigned char *dst = coding->destination + coding->produced; | |
1479 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
1480 int safe_room = 8; | |
1481 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
1482 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; | |
1483 int produced_chars = 0; | |
1484 Lisp_Object attrs, eol_type, charset_list; | |
1485 int c; | |
1486 | |
1487 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1488 | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1489 if (bom != utf_16_without_bom) |
88365 | 1490 { |
1491 ASSURE_DESTINATION (safe_room); | |
1492 if (big_endian) | |
89404
3e1d187b52c3
(Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig)
Kenichi Handa <handa@m17n.org>
parents:
89394
diff
changeset
|
1493 EMIT_TWO_BYTES (0xFE, 0xFF); |
88365 | 1494 else |
89404
3e1d187b52c3
(Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig)
Kenichi Handa <handa@m17n.org>
parents:
89394
diff
changeset
|
1495 EMIT_TWO_BYTES (0xFF, 0xFE); |
88365 | 1496 CODING_UTF_16_BOM (coding) = utf_16_without_bom; |
1497 } | |
1498 | |
1499 while (charbuf < charbuf_end) | |
1500 { | |
1501 ASSURE_DESTINATION (safe_room); | |
1502 c = *charbuf++; | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1503 if (c >= MAX_UNICODE_CHAR) |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1504 c = coding->default_char; |
88365 | 1505 |
1506 if (c < 0x10000) | |
1507 { | |
1508 if (big_endian) | |
1509 EMIT_TWO_BYTES (c >> 8, c & 0xFF); | |
1510 else | |
1511 EMIT_TWO_BYTES (c & 0xFF, c >> 8); | |
1512 } | |
1513 else | |
1514 { | |
1515 int c1, c2; | |
1516 | |
1517 c -= 0x10000; | |
1518 c1 = (c >> 10) + 0xD800; | |
1519 c2 = (c & 0x3FF) + 0xDC00; | |
1520 if (big_endian) | |
1521 EMIT_FOUR_BYTES (c1 >> 8, c1 & 0xFF, c2 >> 8, c2 & 0xFF); | |
1522 else | |
1523 EMIT_FOUR_BYTES (c1 & 0xFF, c1 >> 8, c2 & 0xFF, c2 >> 8); | |
1524 } | |
1525 } | |
1526 coding->result = CODING_RESULT_SUCCESS; | |
1527 coding->produced = dst - coding->destination; | |
1528 coding->produced_char += produced_chars; | |
1529 return 0; | |
1530 } | |
1531 | |
1532 | |
1533 /*** 6. Old Emacs' internal format (emacs-mule) ***/ | |
17052 | 1534 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1535 /* Emacs' internal format for representation of multiple character |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1536 sets is a kind of multi-byte encoding, i.e. characters are |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1537 represented by variable-length sequences of one-byte codes. |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1538 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1539 ASCII characters and control characters (e.g. `tab', `newline') are |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1540 represented by one-byte sequences which are their ASCII codes, in |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1541 the range 0x00 through 0x7F. |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1542 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1543 8-bit characters of the range 0x80..0x9F are represented by |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1544 two-byte sequences of LEADING_CODE_8_BIT_CONTROL and (their 8-bit |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1545 code + 0x20). |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1546 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1547 8-bit characters of the range 0xA0..0xFF are represented by |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1548 one-byte sequences which are their 8-bit code. |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1549 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1550 The other characters are represented by a sequence of `base |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1551 leading-code', optional `extended leading-code', and one or two |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1552 `position-code's. The length of the sequence is determined by the |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1553 base leading-code. Leading-code takes the range 0x81 through 0x9D, |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1554 whereas extended leading-code and position-code take the range 0xA0 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1555 through 0xFF. See `charset.h' for more details about leading-code |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1556 and position-code. |
18766 | 1557 |
17052 | 1558 --- CODE RANGE of Emacs' internal format --- |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1559 character set range |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1560 ------------- ----- |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1561 ascii 0x00..0x7F |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1562 eight-bit-control LEADING_CODE_8_BIT_CONTROL + 0xA0..0xBF |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1563 eight-bit-graphic 0xA0..0xBF |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1564 ELSE 0x81..0x9D + [0xA0..0xFF]+ |
17052 | 1565 --------------------------------------------- |
1566 | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1567 As this is the internal character representation, the format is |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1568 usually not used externally (i.e. in a file or in a data sent to a |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1569 process). But, it is possible to have a text externally in this |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1570 format (i.e. by encoding by the coding system `emacs-mule'). |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1571 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1572 In that case, a sequence of one-byte codes has a slightly different |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1573 form. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1574 |
88365 | 1575 At first, all characters in eight-bit-control are represented by |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1576 one-byte sequences which are their 8-bit code. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1577 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1578 Next, character composition data are represented by the byte |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1579 sequence of the form: 0x80 METHOD BYTES CHARS COMPONENT ..., |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1580 where, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1581 METHOD is 0xF0 plus one of composition method (enum |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1582 composition_method), |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1583 |
88365 | 1584 BYTES is 0xA0 plus a byte length of this composition data, |
1585 | |
1586 CHARS is 0x20 plus a number of characters composed by this | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1587 data, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1588 |
88365 | 1589 COMPONENTs are characters of multibye form or composition |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1590 rules encoded by two-byte of ASCII codes. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1591 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1592 In addition, for backward compatibility, the following formats are |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1593 also recognized as composition data on decoding. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1594 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1595 0x80 MSEQ ... |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1596 0x80 0xFF MSEQ RULE MSEQ RULE ... MSEQ |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1597 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1598 Here, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1599 MSEQ is a multibyte form but in these special format: |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1600 ASCII: 0xA0 ASCII_CODE+0x80, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1601 other: LEADING_CODE+0x20 FOLLOWING-BYTE ..., |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1602 RULE is a one byte code of the range 0xA0..0xF0 that |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1603 represents a composition rule. |
17052 | 1604 */ |
1605 | |
88365 | 1606 char emacs_mule_bytes[256]; |
1607 | |
1608 int | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1609 emacs_mule_char (coding, src, nbytes, nchars, id) |
88365 | 1610 struct coding_system *coding; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1611 unsigned char *src; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1612 int *nbytes, *nchars, *id; |
88365 | 1613 { |
1614 unsigned char *src_end = coding->source + coding->src_bytes; | |
1615 int multibytep = coding->src_multibyte; | |
1616 unsigned char *src_base = src; | |
1617 struct charset *charset; | |
1618 unsigned code; | |
1619 int c; | |
1620 int consumed_chars = 0; | |
1621 | |
1622 ONE_MORE_BYTE (c); | |
1623 switch (emacs_mule_bytes[c]) | |
1624 { | |
1625 case 2: | |
1626 if (! (charset = emacs_mule_charset[c])) | |
1627 goto invalid_code; | |
1628 ONE_MORE_BYTE (c); | |
1629 code = c & 0x7F; | |
1630 break; | |
1631 | |
1632 case 3: | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
1633 if (c == EMACS_MULE_LEADING_CODE_PRIVATE_11 |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
1634 || c == EMACS_MULE_LEADING_CODE_PRIVATE_12) |
88365 | 1635 { |
1636 ONE_MORE_BYTE (c); | |
1637 if (! (charset = emacs_mule_charset[c])) | |
1638 goto invalid_code; | |
1639 ONE_MORE_BYTE (c); | |
1640 code = c & 0x7F; | |
1641 } | |
1642 else | |
1643 { | |
1644 if (! (charset = emacs_mule_charset[c])) | |
1645 goto invalid_code; | |
1646 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1647 code = (c & 0x7F) << 8; |
88365 | 1648 ONE_MORE_BYTE (c); |
1649 code |= c & 0x7F; | |
1650 } | |
1651 break; | |
1652 | |
1653 case 4: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1654 ONE_MORE_BYTE (c); |
88365 | 1655 if (! (charset = emacs_mule_charset[c])) |
1656 goto invalid_code; | |
1657 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1658 code = (c & 0x7F) << 8; |
88365 | 1659 ONE_MORE_BYTE (c); |
1660 code |= c & 0x7F; | |
1661 break; | |
1662 | |
1663 case 1: | |
1664 code = c; | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
1665 charset = CHARSET_FROM_ID (ASCII_BYTE_P (code) |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
1666 ? charset_ascii : charset_eight_bit); |
88365 | 1667 break; |
1668 | |
1669 default: | |
1670 abort (); | |
1671 } | |
1672 c = DECODE_CHAR (charset, code); | |
1673 if (c < 0) | |
1674 goto invalid_code; | |
1675 *nbytes = src - src_base; | |
1676 *nchars = consumed_chars; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1677 if (id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1678 *id = charset->id; |
88365 | 1679 return c; |
1680 | |
1681 no_more_source: | |
1682 return -2; | |
1683 | |
1684 invalid_code: | |
1685 return -1; | |
1686 } | |
1687 | |
17052 | 1688 |
1689 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1690 Check if a text is encoded in `emacs-mule'. If it is, return 1, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1691 else return 0. */ |
17052 | 1692 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
1693 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1694 detect_coding_emacs_mule (coding, detect_info) |
88365 | 1695 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1696 struct coding_detection_info *detect_info; |
17052 | 1697 { |
88365 | 1698 unsigned char *src = coding->source, *src_base = src; |
1699 unsigned char *src_end = coding->source + coding->src_bytes; | |
1700 int multibytep = coding->src_multibyte; | |
1701 int consumed_chars = 0; | |
1702 int c; | |
1703 int found = 0; | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1704 int incomplete; |
88365 | 1705 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1706 detect_info->checked |= CATEGORY_MASK_EMACS_MULE; |
88365 | 1707 /* A coding system of this category is always ASCII compatible. */ |
1708 src += coding->head_ascii; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1709 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1710 while (1) |
17052 | 1711 { |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1712 incomplete = 0; |
88365 | 1713 ONE_MORE_BYTE (c); |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1714 incomplete = 1; |
88365 | 1715 |
1716 if (c == 0x80) | |
17052 | 1717 { |
88365 | 1718 /* Perhaps the start of composite character. We simple skip |
1719 it because analyzing it is too heavy for detecting. But, | |
1720 at least, we check that the composite character | |
1721 constitues of more than 4 bytes. */ | |
1722 unsigned char *src_base; | |
1723 | |
1724 repeat: | |
1725 src_base = src; | |
1726 do | |
1727 { | |
1728 ONE_MORE_BYTE (c); | |
1729 } | |
1730 while (c >= 0xA0); | |
1731 | |
1732 if (src - src_base <= 4) | |
1733 break; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1734 found = CATEGORY_MASK_EMACS_MULE; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1735 if (c == 0x80) |
88365 | 1736 goto repeat; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1737 } |
88365 | 1738 |
1739 if (c < 0x80) | |
1740 { | |
1741 if (c < 0x20 | |
1742 && (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)) | |
1743 break; | |
1744 } | |
1745 else | |
1746 { | |
1747 unsigned char *src_base = src - 1; | |
1748 | |
1749 do | |
1750 { | |
1751 ONE_MORE_BYTE (c); | |
1752 } | |
1753 while (c >= 0xA0); | |
1754 if (src - src_base != emacs_mule_bytes[*src_base]) | |
1755 break; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1756 found = CATEGORY_MASK_EMACS_MULE; |
88365 | 1757 } |
1758 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1759 detect_info->rejected |= CATEGORY_MASK_EMACS_MULE; |
88365 | 1760 return 0; |
1761 | |
1762 no_more_source: | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1763 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1764 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1765 detect_info->rejected |= CATEGORY_MASK_EMACS_MULE; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1766 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1767 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1768 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1769 return 1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1770 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1771 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1772 |
88365 | 1773 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1774 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1775 /* Decode a character represented as a component of composition |
88365 | 1776 sequence of Emacs 20/21 style at SRC. Set C to that character and |
1777 update SRC to the head of next character (or an encoded composition | |
1778 rule). If SRC doesn't points a composition component, set C to -1. | |
1779 If SRC points an invalid byte sequence, global exit by a return | |
1780 value 0. */ | |
1781 | |
1782 #define DECODE_EMACS_MULE_COMPOSITION_CHAR(buf) \ | |
1783 if (1) \ | |
1784 { \ | |
1785 int c; \ | |
1786 int nbytes, nchars; \ | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1787 \ |
88365 | 1788 if (src == src_end) \ |
1789 break; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1790 c = emacs_mule_char (coding, src, &nbytes, &nchars, NULL);\ |
88365 | 1791 if (c < 0) \ |
1792 { \ | |
1793 if (c == -2) \ | |
1794 break; \ | |
1795 goto invalid_code; \ | |
1796 } \ | |
1797 *buf++ = c; \ | |
1798 src += nbytes; \ | |
1799 consumed_chars += nchars; \ | |
1800 } \ | |
1801 else | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1802 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1803 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1804 /* Decode a composition rule represented as a component of composition |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1805 sequence of Emacs 20 style at SRC. Store the decoded rule in *BUF, |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1806 and increment BUF. If SRC points an invalid byte sequence, set C |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1807 to -1. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1808 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1809 #define DECODE_EMACS_MULE_COMPOSITION_RULE_20(buf) \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1810 do { \ |
88365 | 1811 int c, gref, nref; \ |
1812 \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1813 if (src >= src_end) \ |
88365 | 1814 goto invalid_code; \ |
1815 ONE_MORE_BYTE_NO_CHECK (c); \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1816 c -= 0x20; \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1817 if (c < 0 || c >= 81) \ |
88365 | 1818 goto invalid_code; \ |
1819 \ | |
1820 gref = c / 9, nref = c % 9; \ | |
1821 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ | |
1822 } while (0) | |
1823 | |
1824 | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1825 /* Decode a composition rule represented as a component of composition |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1826 sequence of Emacs 21 style at SRC. Store the decoded rule in *BUF, |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1827 and increment BUF. If SRC points an invalid byte sequence, set C |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1828 to -1. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1829 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1830 #define DECODE_EMACS_MULE_COMPOSITION_RULE_21(buf) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1831 do { \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1832 int gref, nref; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1833 \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1834 if (src + 1>= src_end) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1835 goto invalid_code; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1836 ONE_MORE_BYTE_NO_CHECK (gref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1837 gref -= 0x20; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1838 ONE_MORE_BYTE_NO_CHECK (nref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1839 nref -= 0x20; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1840 if (gref < 0 || gref >= 81 \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1841 || nref < 0 || nref >= 81) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1842 goto invalid_code; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1843 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1844 } while (0) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1845 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1846 |
88365 | 1847 #define DECODE_EMACS_MULE_21_COMPOSITION(c) \ |
1848 do { \ | |
1849 /* Emacs 21 style format. The first three bytes at SRC are \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1850 (METHOD - 0xF2), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is \ |
88365 | 1851 the byte length of this composition information, CHARS is the \ |
1852 number of characters composed by this composition. */ \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1853 enum composition_method method = c - 0xF2; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1854 int *charbuf_base = charbuf; \ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1855 int from, to; \ |
88365 | 1856 int consumed_chars_limit; \ |
1857 int nbytes, nchars; \ | |
1858 \ | |
1859 ONE_MORE_BYTE (c); \ | |
1860 nbytes = c - 0xA0; \ | |
1861 if (nbytes < 3) \ | |
1862 goto invalid_code; \ | |
1863 ONE_MORE_BYTE (c); \ | |
1864 nchars = c - 0xA0; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1865 from = coding->produced + char_offset; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1866 to = from + nchars; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1867 ADD_COMPOSITION_DATA (charbuf, from, to, method); \ |
88365 | 1868 consumed_chars_limit = consumed_chars_base + nbytes; \ |
1869 if (method != COMPOSITION_RELATIVE) \ | |
1870 { \ | |
1871 int i = 0; \ | |
1872 while (consumed_chars < consumed_chars_limit) \ | |
1873 { \ | |
1874 if (i % 2 && method != COMPOSITION_WITH_ALTCHARS) \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1875 DECODE_EMACS_MULE_COMPOSITION_RULE_21 (charbuf); \ |
88365 | 1876 else \ |
1877 DECODE_EMACS_MULE_COMPOSITION_CHAR (charbuf); \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1878 i++; \ |
88365 | 1879 } \ |
1880 if (consumed_chars < consumed_chars_limit) \ | |
1881 goto invalid_code; \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1882 charbuf_base[0] -= i; \ |
88365 | 1883 } \ |
1884 } while (0) | |
1885 | |
1886 | |
1887 #define DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION(c) \ | |
1888 do { \ | |
1889 /* Emacs 20 style format for relative composition. */ \ | |
1890 /* Store multibyte form of characters to be composed. */ \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1891 enum composition_method method = COMPOSITION_RELATIVE; \ |
88365 | 1892 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ |
1893 int *buf = components; \ | |
1894 int i, j; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1895 int from, to; \ |
88365 | 1896 \ |
1897 src = src_base; \ | |
1898 ONE_MORE_BYTE (c); /* skip 0x80 */ \ | |
1899 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
1900 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
1901 if (i < 2) \ | |
1902 goto invalid_code; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1903 from = coding->produced_char + char_offset; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1904 to = from + i; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1905 ADD_COMPOSITION_DATA (charbuf, from, to, method); \ |
88365 | 1906 for (j = 0; j < i; j++) \ |
1907 *charbuf++ = components[j]; \ | |
1908 } while (0) | |
1909 | |
1910 | |
1911 #define DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION(c) \ | |
1912 do { \ | |
1913 /* Emacs 20 style format for rule-base composition. */ \ | |
1914 /* Store multibyte form of characters to be composed. */ \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1915 enum composition_method method = COMPOSITION_WITH_RULE; \ |
88365 | 1916 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ |
1917 int *buf = components; \ | |
1918 int i, j; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1919 int from, to; \ |
88365 | 1920 \ |
1921 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
1922 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
1923 { \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1924 DECODE_EMACS_MULE_COMPOSITION_RULE_20 (buf); \ |
88365 | 1925 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ |
1926 } \ | |
1927 if (i < 1 || (buf - components) % 2 == 0) \ | |
1928 goto invalid_code; \ | |
1929 if (charbuf + i + (i / 2) + 1 < charbuf_end) \ | |
1930 goto no_more_source; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1931 from = coding->produced_char + char_offset; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1932 to = from + i; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1933 ADD_COMPOSITION_DATA (buf, from, to, method); \ |
88365 | 1934 for (j = 0; j < i; j++) \ |
1935 *charbuf++ = components[j]; \ | |
1936 for (j = 0; j < i; j += 2) \ | |
1937 *charbuf++ = components[j]; \ | |
1938 } while (0) | |
1939 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1940 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1941 static void |
88365 | 1942 decode_coding_emacs_mule (coding) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1943 struct coding_system *coding; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1944 { |
88365 | 1945 unsigned char *src = coding->source + coding->consumed; |
1946 unsigned char *src_end = coding->source + coding->src_bytes; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1947 unsigned char *src_base; |
88365 | 1948 int *charbuf = coding->charbuf; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1949 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
88365 | 1950 int consumed_chars = 0, consumed_chars_base; |
1951 int multibytep = coding->src_multibyte; | |
1952 Lisp_Object attrs, eol_type, charset_list; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1953 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1954 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1955 int last_id = charset_ascii; |
88365 | 1956 |
1957 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1958 | |
1959 while (1) | |
1960 { | |
1961 int c; | |
1962 | |
1963 src_base = src; | |
1964 consumed_chars_base = consumed_chars; | |
1965 | |
1966 if (charbuf >= charbuf_end) | |
1967 break; | |
1968 | |
1969 ONE_MORE_BYTE (c); | |
1970 | |
1971 if (c < 0x80) | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1972 { |
88365 | 1973 if (c == '\r') |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1974 { |
88365 | 1975 if (EQ (eol_type, Qdos)) |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1976 { |
88365 | 1977 if (src == src_end) |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1978 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1979 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1980 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1981 } |
88365 | 1982 if (*src == '\n') |
1983 ONE_MORE_BYTE (c); | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1984 } |
88365 | 1985 else if (EQ (eol_type, Qmac)) |
1986 c = '\n'; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1987 } |
88365 | 1988 *charbuf++ = c; |
1989 char_offset++; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1990 } |
88365 | 1991 else if (c == 0x80) |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1992 { |
88365 | 1993 ONE_MORE_BYTE (c); |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1994 if (c - 0xF2 >= COMPOSITION_RELATIVE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1995 && c - 0xF2 <= COMPOSITION_WITH_RULE_ALTCHARS) |
88365 | 1996 DECODE_EMACS_MULE_21_COMPOSITION (c); |
1997 else if (c < 0xC0) | |
1998 DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION (c); | |
1999 else if (c == 0xFF) | |
2000 DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION (c); | |
2001 else | |
2002 goto invalid_code; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2003 } |
88365 | 2004 else if (c < 0xA0 && emacs_mule_bytes[c] > 1) |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2005 { |
88365 | 2006 int nbytes, nchars; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2007 int id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2008 |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2009 src = src_base; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2010 consumed_chars = consumed_chars_base; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2011 c = emacs_mule_char (coding, src, &nbytes, &nchars, &id); |
88365 | 2012 if (c < 0) |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2013 { |
88365 | 2014 if (c == -2) |
2015 break; | |
2016 goto invalid_code; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2017 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2018 if (last_id != id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2019 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2020 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2021 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2022 last_id = id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2023 last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2024 } |
88365 | 2025 *charbuf++ = c; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2026 src += nbytes; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2027 consumed_chars += nchars; |
88365 | 2028 char_offset++; |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2029 } |
88365 | 2030 continue; |
2031 | |
2032 invalid_code: | |
2033 src = src_base; | |
2034 consumed_chars = consumed_chars_base; | |
2035 ONE_MORE_BYTE (c); | |
2036 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2037 char_offset++; |
88365 | 2038 coding->errors++; |
2039 } | |
2040 | |
2041 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2042 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2043 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
88365 | 2044 coding->consumed_char += consumed_chars_base; |
2045 coding->consumed = src_base - coding->source; | |
2046 coding->charbuf_used = charbuf - coding->charbuf; | |
2047 } | |
2048 | |
2049 | |
2050 #define EMACS_MULE_LEADING_CODES(id, codes) \ | |
2051 do { \ | |
2052 if (id < 0xA0) \ | |
2053 codes[0] = id, codes[1] = 0; \ | |
2054 else if (id < 0xE0) \ | |
2055 codes[0] = 0x9A, codes[1] = id; \ | |
2056 else if (id < 0xF0) \ | |
2057 codes[0] = 0x9B, codes[1] = id; \ | |
2058 else if (id < 0xF5) \ | |
2059 codes[0] = 0x9C, codes[1] = id; \ | |
2060 else \ | |
2061 codes[0] = 0x9D, codes[1] = id; \ | |
2062 } while (0); | |
2063 | |
2064 | |
2065 static int | |
2066 encode_coding_emacs_mule (coding) | |
2067 struct coding_system *coding; | |
2068 { | |
2069 int multibytep = coding->dst_multibyte; | |
2070 int *charbuf = coding->charbuf; | |
2071 int *charbuf_end = charbuf + coding->charbuf_used; | |
2072 unsigned char *dst = coding->destination + coding->produced; | |
2073 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
2074 int safe_room = 8; | |
2075 int produced_chars = 0; | |
2076 Lisp_Object attrs, eol_type, charset_list; | |
2077 int c; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2078 int preferred_charset_id = -1; |
88365 | 2079 |
2080 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
2081 | |
2082 while (charbuf < charbuf_end) | |
2083 { | |
2084 ASSURE_DESTINATION (safe_room); | |
2085 c = *charbuf++; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2086 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2087 if (c < 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2088 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2089 /* Handle an annotation. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2090 switch (*charbuf) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2091 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2092 case CODING_ANNOTATE_COMPOSITION_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2093 /* Not yet implemented. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2094 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2095 case CODING_ANNOTATE_CHARSET_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2096 preferred_charset_id = charbuf[3]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2097 if (preferred_charset_id >= 0 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2098 && NILP (Fmemq (make_number (preferred_charset_id), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2099 charset_list))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2100 preferred_charset_id = -1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2101 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2102 default: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2103 abort (); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2104 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2105 charbuf += -c - 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2106 continue; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2107 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2108 |
88365 | 2109 if (ASCII_CHAR_P (c)) |
2110 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2111 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2112 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2113 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2114 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2115 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2116 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2117 { |
88365 | 2118 struct charset *charset; |
2119 unsigned code; | |
2120 int dimension; | |
2121 int emacs_mule_id; | |
2122 unsigned char leading_codes[2]; | |
2123 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2124 if (preferred_charset_id >= 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2125 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2126 charset = CHARSET_FROM_ID (preferred_charset_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2127 if (! CHAR_CHARSET_P (c, charset)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2128 charset = char_charset (c, charset_list, NULL); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2129 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2130 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2131 charset = char_charset (c, charset_list, &code); |
88365 | 2132 if (! charset) |
2133 { | |
2134 c = coding->default_char; | |
2135 if (ASCII_CHAR_P (c)) | |
2136 { | |
2137 EMIT_ONE_ASCII_BYTE (c); | |
2138 continue; | |
2139 } | |
2140 charset = char_charset (c, charset_list, &code); | |
2141 } | |
2142 dimension = CHARSET_DIMENSION (charset); | |
2143 emacs_mule_id = CHARSET_EMACS_MULE_ID (charset); | |
2144 EMACS_MULE_LEADING_CODES (emacs_mule_id, leading_codes); | |
2145 EMIT_ONE_BYTE (leading_codes[0]); | |
2146 if (leading_codes[1]) | |
2147 EMIT_ONE_BYTE (leading_codes[1]); | |
2148 if (dimension == 1) | |
2149 EMIT_ONE_BYTE (code); | |
2150 else | |
2151 { | |
2152 EMIT_ONE_BYTE (code >> 8); | |
2153 EMIT_ONE_BYTE (code & 0xFF); | |
2154 } | |
17052 | 2155 } |
88365 | 2156 } |
2157 coding->result = CODING_RESULT_SUCCESS; | |
2158 coding->produced_char += produced_chars; | |
2159 coding->produced = dst - coding->destination; | |
2160 return 0; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2161 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2162 |
17052 | 2163 |
88365 | 2164 /*** 7. ISO2022 handlers ***/ |
17052 | 2165 |
2166 /* The following note describes the coding system ISO2022 briefly. | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2167 Since the intention of this note is to help understand the |
88771 | 2168 functions in this file, some parts are NOT ACCURATE or are OVERLY |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2169 SIMPLIFIED. For thorough understanding, please refer to the |
88771 | 2170 original document of ISO2022. This is equivalent to the standard |
2171 ECMA-35, obtainable from <URL:http://www.ecma.ch/> (*). | |
17052 | 2172 |
2173 ISO2022 provides many mechanisms to encode several character sets | |
88771 | 2174 in 7-bit and 8-bit environments. For 7-bit environments, all text |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2175 is encoded using bytes less than 128. This may make the encoded |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2176 text a little bit longer, but the text passes more easily through |
88771 | 2177 several types of gateway, some of which strip off the MSB (Most |
2178 Significant Bit). | |
2179 | |
2180 There are two kinds of character sets: control character sets and | |
2181 graphic character sets. The former contain control characters such | |
17052 | 2182 as `newline' and `escape' to provide control functions (control |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2183 functions are also provided by escape sequences). The latter |
88771 | 2184 contain graphic characters such as 'A' and '-'. Emacs recognizes |
17052 | 2185 two control character sets and many graphic character sets. |
2186 | |
2187 Graphic character sets are classified into one of the following | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2188 four classes, according to the number of bytes (DIMENSION) and |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2189 number of characters in one dimension (CHARS) of the set: |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2190 - DIMENSION1_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2191 - DIMENSION1_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2192 - DIMENSION2_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2193 - DIMENSION2_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2194 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2195 In addition, each character set is assigned an identification tag, |
88771 | 2196 unique for each set, called the "final character" (denoted as <F> |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2197 hereafter). The <F> of each character set is decided by ECMA(*) |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2198 when it is registered in ISO. The code range of <F> is 0x30..0x7F |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2199 (0x30..0x3F are for private use only). |
17052 | 2200 |
2201 Note (*): ECMA = European Computer Manufacturers Association | |
2202 | |
88771 | 2203 Here are examples of graphic character sets [NAME(<F>)]: |
17052 | 2204 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ... |
2205 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ... | |
2206 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ... | |
2207 o DIMENSION2_CHARS96 -- none for the moment | |
2208 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2209 A code area (1 byte=8 bits) is divided into 4 areas, C0, GL, C1, and GR. |
17052 | 2210 C0 [0x00..0x1F] -- control character plane 0 |
2211 GL [0x20..0x7F] -- graphic character plane 0 | |
2212 C1 [0x80..0x9F] -- control character plane 1 | |
2213 GR [0xA0..0xFF] -- graphic character plane 1 | |
2214 | |
2215 A control character set is directly designated and invoked to C0 or | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2216 C1 by an escape sequence. The most common case is that: |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2217 - ISO646's control character set is designated/invoked to C0, and |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2218 - ISO6429's control character set is designated/invoked to C1, |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2219 and usually these designations/invocations are omitted in encoded |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2220 text. In a 7-bit environment, only C0 can be used, and a control |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2221 character for C1 is encoded by an appropriate escape sequence to |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2222 fit into the environment. All control characters for C1 are |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2223 defined to have corresponding escape sequences. |
17052 | 2224 |
2225 A graphic character set is at first designated to one of four | |
2226 graphic registers (G0 through G3), then these graphic registers are | |
2227 invoked to GL or GR. These designations and invocations can be | |
2228 done independently. The most common case is that G0 is invoked to | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2229 GL, G1 is invoked to GR, and ASCII is designated to G0. Usually |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2230 these invocations and designations are omitted in encoded text. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2231 In a 7-bit environment, only GL can be used. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2232 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2233 When a graphic character set of CHARS94 is invoked to GL, codes |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2234 0x20 and 0x7F of the GL area work as control characters SPACE and |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2235 DEL respectively, and codes 0xA0 and 0xFF of the GR area should not |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2236 be used. |
17052 | 2237 |
2238 There are two ways of invocation: locking-shift and single-shift. | |
2239 With locking-shift, the invocation lasts until the next different | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2240 invocation, whereas with single-shift, the invocation affects the |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2241 following character only and doesn't affect the locking-shift |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2242 state. Invocations are done by the following control characters or |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2243 escape sequences: |
17052 | 2244 |
2245 ---------------------------------------------------------------------- | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2246 abbrev function cntrl escape seq description |
17052 | 2247 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2248 SI/LS0 (shift-in) 0x0F none invoke G0 into GL |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2249 SO/LS1 (shift-out) 0x0E none invoke G1 into GL |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2250 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2251 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2252 LS1R (locking-shift-1 right) none ESC '~' invoke G1 into GR (*) |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2253 LS2R (locking-shift-2 right) none ESC '}' invoke G2 into GR (*) |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2254 LS3R (locking-shift 3 right) none ESC '|' invoke G3 into GR (*) |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2255 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 for one char |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2256 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char |
17052 | 2257 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2258 (*) These are not used by any known coding system. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2259 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2260 Control characters for these functions are defined by macros |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2261 ISO_CODE_XXX in `coding.h'. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2262 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2263 Designations are done by the following escape sequences: |
17052 | 2264 ---------------------------------------------------------------------- |
2265 escape sequence description | |
2266 ---------------------------------------------------------------------- | |
2267 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0 | |
2268 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1 | |
2269 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2 | |
2270 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3 | |
2271 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*) | |
2272 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1 | |
2273 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2 | |
2274 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3 | |
2275 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**) | |
2276 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1 | |
2277 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2 | |
2278 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3 | |
2279 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*) | |
2280 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1 | |
2281 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2 | |
2282 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3 | |
2283 ---------------------------------------------------------------------- | |
2284 | |
2285 In this list, "DIMENSION1_CHARS94<F>" means a graphic character set | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2286 of dimension 1, chars 94, and final character <F>, etc... |
17052 | 2287 |
2288 Note (*): Although these designations are not allowed in ISO2022, | |
2289 Emacs accepts them on decoding, and produces them on encoding | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2290 CHARS96 character sets in a coding system which is characterized as |
17052 | 2291 7-bit environment, non-locking-shift, and non-single-shift. |
2292 | |
2293 Note (**): If <F> is '@', 'A', or 'B', the intermediate character | |
88365 | 2294 '(' must be omitted. We refer to this as "short-form" hereafter. |
2295 | |
88771 | 2296 Now you may notice that there are a lot of ways of encoding the |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2297 same multilingual text in ISO2022. Actually, there exist many |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2298 coding systems such as Compound Text (used in X11's inter client |
88771 | 2299 communication, ISO-2022-JP (used in Japanese Internet), ISO-2022-KR |
2300 (used in Korean Internet), EUC (Extended UNIX Code, used in Asian | |
17052 | 2301 localized platforms), and all of these are variants of ISO2022. |
2302 | |
2303 In addition to the above, Emacs handles two more kinds of escape | |
2304 sequences: ISO6429's direction specification and Emacs' private | |
2305 sequence for specifying character composition. | |
2306 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2307 ISO6429's direction specification takes the following form: |
17052 | 2308 o CSI ']' -- end of the current direction |
2309 o CSI '0' ']' -- end of the current direction | |
2310 o CSI '1' ']' -- start of left-to-right text | |
2311 o CSI '2' ']' -- start of right-to-left text | |
2312 The control character CSI (0x9B: control sequence introducer) is | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2313 abbreviated to the escape sequence ESC '[' in a 7-bit environment. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2314 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2315 Character composition specification takes the following form: |
26847 | 2316 o ESC '0' -- start relative composition |
2317 o ESC '1' -- end composition | |
2318 o ESC '2' -- start rule-base composition (*) | |
2319 o ESC '3' -- start relative composition with alternate chars (**) | |
2320 o ESC '4' -- start rule-base composition with alternate chars (**) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2321 Since these are not standard escape sequences of any ISO standard, |
88771 | 2322 the use of them with these meanings is restricted to Emacs only. |
2323 | |
2324 (*) This form is used only in Emacs 20.7 and older versions, | |
2325 but newer versions can safely decode it. | |
2326 (**) This form is used only in Emacs 21.1 and newer versions, | |
2327 and older versions can't decode it. | |
2328 | |
2329 Here's a list of example usages of these composition escape | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2330 sequences (categorized by `enum composition_method'). |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2331 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2332 COMPOSITION_RELATIVE: |
26847 | 2333 ESC 0 CHAR [ CHAR ] ESC 1 |
88771 | 2334 COMPOSITION_WITH_RULE: |
26847 | 2335 ESC 2 CHAR [ RULE CHAR ] ESC 1 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2336 COMPOSITION_WITH_ALTCHARS: |
26847 | 2337 ESC 3 ALTCHAR [ ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2338 COMPOSITION_WITH_RULE_ALTCHARS: |
26847 | 2339 ESC 4 ALTCHAR [ RULE ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 */ |
17052 | 2340 |
2341 enum iso_code_class_type iso_code_class[256]; | |
2342 | |
88365 | 2343 #define SAFE_CHARSET_P(coding, id) \ |
2344 ((id) <= (coding)->max_charset_id \ | |
2345 && (coding)->safe_charsets[id] >= 0) | |
2346 | |
2347 | |
2348 #define SHIFT_OUT_OK(category) \ | |
2349 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0) | |
2350 | |
2351 static void | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2352 setup_iso_safe_charsets (attrs) |
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2353 Lisp_Object attrs; |
88365 | 2354 { |
2355 Lisp_Object charset_list, safe_charsets; | |
2356 Lisp_Object request; | |
2357 Lisp_Object reg_usage; | |
2358 Lisp_Object tail; | |
2359 int reg94, reg96; | |
2360 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
2361 int max_charset_id; | |
2362 | |
2363 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
2364 if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) | |
2365 && ! EQ (charset_list, Viso_2022_charset_list)) | |
2366 { | |
2367 CODING_ATTR_CHARSET_LIST (attrs) | |
2368 = charset_list = Viso_2022_charset_list; | |
2369 ASET (attrs, coding_attr_safe_charsets, Qnil); | |
2370 } | |
2371 | |
2372 if (STRINGP (AREF (attrs, coding_attr_safe_charsets))) | |
2373 return; | |
2374 | |
2375 max_charset_id = 0; | |
2376 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2377 { | |
2378 int id = XINT (XCAR (tail)); | |
2379 if (max_charset_id < id) | |
2380 max_charset_id = id; | |
2381 } | |
2382 | |
2383 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
2384 make_number (255)); | |
2385 request = AREF (attrs, coding_attr_iso_request); | |
2386 reg_usage = AREF (attrs, coding_attr_iso_usage); | |
2387 reg94 = XINT (XCAR (reg_usage)); | |
2388 reg96 = XINT (XCDR (reg_usage)); | |
2389 | |
2390 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2391 { | |
2392 Lisp_Object id; | |
2393 Lisp_Object reg; | |
2394 struct charset *charset; | |
2395 | |
2396 id = XCAR (tail); | |
2397 charset = CHARSET_FROM_ID (XINT (id)); | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2398 reg = Fcdr (Fassq (id, request)); |
88365 | 2399 if (! NILP (reg)) |
2400 XSTRING (safe_charsets)->data[XINT (id)] = XINT (reg); | |
2401 else if (charset->iso_chars_96) | |
2402 { | |
2403 if (reg96 < 4) | |
2404 XSTRING (safe_charsets)->data[XINT (id)] = reg96; | |
2405 } | |
2406 else | |
2407 { | |
2408 if (reg94 < 4) | |
2409 XSTRING (safe_charsets)->data[XINT (id)] = reg94; | |
2410 } | |
2411 } | |
2412 ASET (attrs, coding_attr_safe_charsets, safe_charsets); | |
2413 } | |
2414 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2415 |
17052 | 2416 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2417 Check if a text is encoded in one of ISO-2022 based codig systems. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2418 If it is, return 1, else return 0. */ |
17052 | 2419 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
2420 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2421 detect_coding_iso_2022 (coding, detect_info) |
88365 | 2422 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2423 struct coding_detection_info *detect_info; |
17052 | 2424 { |
88365 | 2425 unsigned char *src = coding->source, *src_base = src; |
2426 unsigned char *src_end = coding->source + coding->src_bytes; | |
2427 int multibytep = coding->src_multibyte; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2428 int single_shifting = 0; |
88365 | 2429 int id; |
2430 int c, c1; | |
2431 int consumed_chars = 0; | |
2432 int i; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2433 int rejected = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2434 int found = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2435 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2436 detect_info->checked |= CATEGORY_MASK_ISO; |
88365 | 2437 |
2438 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | |
2439 { | |
2440 struct coding_system *this = &(coding_categories[i]); | |
2441 Lisp_Object attrs, val; | |
2442 | |
2443 attrs = CODING_ID_ATTRS (this->id); | |
2444 if (CODING_ISO_FLAGS (this) & CODING_ISO_FLAG_FULL_SUPPORT | |
2445 && ! EQ (CODING_ATTR_SAFE_CHARSETS (attrs), Viso_2022_charset_list)) | |
2446 setup_iso_safe_charsets (attrs); | |
2447 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
2448 this->max_charset_id = XSTRING (val)->size - 1; | |
2449 this->safe_charsets = (char *) XSTRING (val)->data; | |
2450 } | |
2451 | |
2452 /* A coding system of this category is always ASCII compatible. */ | |
2453 src += coding->head_ascii; | |
2454 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2455 while (rejected != CATEGORY_MASK_ISO) |
88365 | 2456 { |
2457 ONE_MORE_BYTE (c); | |
17052 | 2458 switch (c) |
2459 { | |
2460 case ISO_CODE_ESC: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2461 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2462 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2463 single_shifting = 0; |
88365 | 2464 ONE_MORE_BYTE (c); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2465 if (c >= '(' && c <= '/') |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2466 { |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2467 /* Designation sequence for a charset of dimension 1. */ |
88365 | 2468 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2469 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2470 || (id = iso_charset_table[0][c >= ','][c1]) < 0) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2471 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2472 break; |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2473 } |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2474 else if (c == '$') |
17052 | 2475 { |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2476 /* Designation sequence for a charset of dimension 2. */ |
88365 | 2477 ONE_MORE_BYTE (c); |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2478 if (c >= '@' && c <= 'B') |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2479 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2480 id = iso_charset_table[1][0][c]; |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2481 else if (c >= '(' && c <= '/') |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2482 { |
88365 | 2483 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2484 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2485 || (id = iso_charset_table[1][c >= ','][c1]) < 0) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2486 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2487 break; |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2488 } |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2489 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2490 /* Invalid designation sequence. Just ignore it. */ |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2491 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2492 } |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2493 else if (c == 'N' || c == 'O') |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2494 { |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2495 /* ESC <Fe> for SS2 or SS3. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2496 single_shifting = 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2497 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2498 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2499 } |
26847 | 2500 else if (c >= '0' && c <= '4') |
2501 { | |
2502 /* ESC <Fp> for start/end composition. */ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2503 found |= CATEGORY_MASK_ISO; |
26847 | 2504 break; |
2505 } | |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2506 else |
88365 | 2507 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2508 /* Invalid escape sequence. Just ignore it. */ |
88365 | 2509 break; |
2510 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2511 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2512 /* We found a valid designation sequence for CHARSET. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2513 rejected |= CATEGORY_MASK_ISO_8BIT; |
88365 | 2514 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7], |
2515 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2516 found |= CATEGORY_MASK_ISO_7; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2517 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2518 rejected |= CATEGORY_MASK_ISO_7; |
88365 | 2519 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_tight], |
2520 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2521 found |= CATEGORY_MASK_ISO_7_TIGHT; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2522 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2523 rejected |= CATEGORY_MASK_ISO_7_TIGHT; |
88365 | 2524 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_else], |
2525 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2526 found |= CATEGORY_MASK_ISO_7_ELSE; |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2527 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2528 rejected |= CATEGORY_MASK_ISO_7_ELSE; |
88365 | 2529 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_8_else], |
2530 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2531 found |= CATEGORY_MASK_ISO_8_ELSE; |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2532 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2533 rejected |= CATEGORY_MASK_ISO_8_ELSE; |
17052 | 2534 break; |
2535 | |
2536 case ISO_CODE_SO: | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2537 case ISO_CODE_SI: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2538 /* Locking shift out/in. */ |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2539 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2540 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2541 single_shifting = 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2542 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2543 found |= CATEGORY_MASK_ISO_ELSE; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2544 break; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2545 |
17052 | 2546 case ISO_CODE_CSI: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2547 /* Control sequence introducer. */ |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2548 single_shifting = 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2549 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2550 found |= CATEGORY_MASK_ISO_8_ELSE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2551 goto check_extra_latin; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2552 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2553 |
17052 | 2554 case ISO_CODE_SS2: |
2555 case ISO_CODE_SS3: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2556 /* Single shift. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2557 if (inhibit_iso_escape_detection) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2558 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2559 single_shifting = 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2560 rejected |= CATEGORY_MASK_ISO_7BIT; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2561 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2562 & CODING_ISO_FLAG_SINGLE_SHIFT) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2563 found |= CATEGORY_MASK_ISO_8_1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2564 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2565 & CODING_ISO_FLAG_SINGLE_SHIFT) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2566 found |= CATEGORY_MASK_ISO_8_2; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2567 goto check_extra_latin; |
17052 | 2568 |
2569 default: | |
2570 if (c < 0x80) | |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2571 { |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2572 single_shifting = 0; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2573 break; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2574 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2575 if (c >= 0xA0) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2576 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2577 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2578 found |= CATEGORY_MASK_ISO_8_1; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2579 /* Check the length of succeeding codes of the range |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2580 0xA0..0FF. If the byte length is even, we include |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2581 CATEGORY_MASK_ISO_8_2 in `found'. We can check this |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2582 only when we are not single shifting. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2583 if (! single_shifting |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2584 && ! (rejected & CATEGORY_MASK_ISO_8_2)) |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2585 { |
29299
b33b38d81020
(detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents:
29275
diff
changeset
|
2586 int i = 1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2587 while (src < src_end) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2588 { |
88365 | 2589 ONE_MORE_BYTE (c); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2590 if (c < 0xA0) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2591 break; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2592 i++; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2593 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2594 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2595 if (i & 1 && src < src_end) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2596 rejected |= CATEGORY_MASK_ISO_8_2; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2597 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2598 found |= CATEGORY_MASK_ISO_8_2; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2599 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2600 break; |
17052 | 2601 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2602 check_extra_latin: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2603 single_shifting = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2604 if (! VECTORP (Vlatin_extra_code_table) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2605 || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2606 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2607 rejected = CATEGORY_MASK_ISO; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2608 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2609 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2610 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2611 & CODING_ISO_FLAG_LATIN_EXTRA) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2612 found |= CATEGORY_MASK_ISO_8_1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2613 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2614 rejected |= CATEGORY_MASK_ISO_8_1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2615 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2616 & CODING_ISO_FLAG_LATIN_EXTRA) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2617 found |= CATEGORY_MASK_ISO_8_2; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2618 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2619 rejected |= CATEGORY_MASK_ISO_8_2; |
17052 | 2620 } |
2621 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2622 detect_info->rejected |= CATEGORY_MASK_ISO; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2623 return 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2624 |
88365 | 2625 no_more_source: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2626 detect_info->rejected |= rejected; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2627 detect_info->found |= (found & ~rejected); |
88365 | 2628 return 1; |
17052 | 2629 } |
2630 | |
2631 | |
2632 /* Set designation state into CODING. */ | |
88365 | 2633 #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
2634 do { \ | |
2635 int id, prev; \ | |
2636 \ | |
2637 if (final < '0' || final >= 128 \ | |
2638 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ | |
2639 || !SAFE_CHARSET_P (coding, id)) \ | |
2640 { \ | |
2641 CODING_ISO_DESIGNATION (coding, reg) = -2; \ | |
2642 goto invalid_code; \ | |
2643 } \ | |
2644 prev = CODING_ISO_DESIGNATION (coding, reg); \ | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2645 if (id == charset_jisx0201_roman) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2646 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2647 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_ROMAN) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2648 id = charset_ascii; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2649 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2650 else if (id == charset_jisx0208_1978) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2651 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2652 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_OLDJIS) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2653 id = charset_jisx0208; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2654 } \ |
88365 | 2655 CODING_ISO_DESIGNATION (coding, reg) = id; \ |
2656 /* If there was an invalid designation to REG previously, and this \ | |
2657 designation is ASCII to REG, we should keep this designation \ | |
2658 sequence. */ \ | |
2659 if (prev == -2 && id == charset_ascii) \ | |
2660 goto invalid_code; \ | |
17052 | 2661 } while (0) |
2662 | |
88365 | 2663 |
2664 #define MAYBE_FINISH_COMPOSITION() \ | |
2665 do { \ | |
2666 int i; \ | |
2667 if (composition_state == COMPOSING_NO) \ | |
2668 break; \ | |
2669 /* It is assured that we have enough room for producing \ | |
2670 characters stored in the table `components'. */ \ | |
2671 if (charbuf + component_idx > charbuf_end) \ | |
2672 goto no_more_source; \ | |
2673 composition_state = COMPOSING_NO; \ | |
2674 if (method == COMPOSITION_RELATIVE \ | |
2675 || method == COMPOSITION_WITH_ALTCHARS) \ | |
2676 { \ | |
2677 for (i = 0; i < component_idx; i++) \ | |
2678 *charbuf++ = components[i]; \ | |
2679 char_offset += component_idx; \ | |
2680 } \ | |
2681 else \ | |
2682 { \ | |
2683 for (i = 0; i < component_idx; i += 2) \ | |
2684 *charbuf++ = components[i]; \ | |
2685 char_offset += (component_idx / 2) + 1; \ | |
2686 } \ | |
2687 } while (0) | |
2688 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2689 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2690 /* Handle composition start sequence ESC 0, ESC 2, ESC 3, or ESC 4. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2691 ESC 0 : relative composition : ESC 0 CHAR ... ESC 1 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2692 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
88365 | 2693 ESC 3 : altchar composition : ESC 3 CHAR ... ESC 0 CHAR ... ESC 1 |
2694 ESC 4 : alt&rule composition : ESC 4 CHAR RULE ... CHAR ESC 0 CHAR ... ESC 1 | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2695 */ |
26847 | 2696 |
88365 | 2697 #define DECODE_COMPOSITION_START(c1) \ |
26847 | 2698 do { \ |
88365 | 2699 if (c1 == '0' \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2700 && composition_state == COMPOSING_COMPONENT_RULE) \ |
26847 | 2701 { \ |
88365 | 2702 component_len = component_idx; \ |
2703 composition_state = COMPOSING_CHAR; \ | |
26847 | 2704 } \ |
2705 else \ | |
2706 { \ | |
88365 | 2707 unsigned char *p; \ |
2708 \ | |
2709 MAYBE_FINISH_COMPOSITION (); \ | |
2710 if (charbuf + MAX_COMPOSITION_COMPONENTS > charbuf_end) \ | |
2711 goto no_more_source; \ | |
2712 for (p = src; p < src_end - 1; p++) \ | |
2713 if (*p == ISO_CODE_ESC && p[1] == '1') \ | |
2714 break; \ | |
2715 if (p == src_end - 1) \ | |
2716 { \ | |
2717 if (coding->mode & CODING_MODE_LAST_BLOCK) \ | |
2718 goto invalid_code; \ | |
2719 goto no_more_source; \ | |
2720 } \ | |
2721 \ | |
2722 /* This is surely the start of a composition. */ \ | |
2723 method = (c1 == '0' ? COMPOSITION_RELATIVE \ | |
2724 : c1 == '2' ? COMPOSITION_WITH_RULE \ | |
2725 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \ | |
2726 : COMPOSITION_WITH_RULE_ALTCHARS); \ | |
2727 composition_state = (c1 <= '2' ? COMPOSING_CHAR \ | |
2728 : COMPOSING_COMPONENT_CHAR); \ | |
2729 component_idx = component_len = 0; \ | |
26847 | 2730 } \ |
2731 } while (0) | |
2732 | |
88365 | 2733 |
2734 /* Handle compositoin end sequence ESC 1. */ | |
2735 | |
2736 #define DECODE_COMPOSITION_END() \ | |
2737 do { \ | |
2738 int nchars = (component_len > 0 ? component_idx - component_len \ | |
2739 : method == COMPOSITION_RELATIVE ? component_idx \ | |
2740 : (component_idx + 1) / 2); \ | |
2741 int i; \ | |
2742 int *saved_charbuf = charbuf; \ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2743 int from = coding->produced_char + char_offset; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2744 int to = from + nchars; \ |
88365 | 2745 \ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2746 ADD_COMPOSITION_DATA (charbuf, from, to, method); \ |
88365 | 2747 if (method != COMPOSITION_RELATIVE) \ |
2748 { \ | |
2749 if (component_len == 0) \ | |
2750 for (i = 0; i < component_idx; i++) \ | |
2751 *charbuf++ = components[i]; \ | |
2752 else \ | |
2753 for (i = 0; i < component_len; i++) \ | |
2754 *charbuf++ = components[i]; \ | |
2755 *saved_charbuf = saved_charbuf - charbuf; \ | |
2756 } \ | |
2757 if (method == COMPOSITION_WITH_RULE) \ | |
2758 for (i = 0; i < component_idx; i += 2, char_offset++) \ | |
2759 *charbuf++ = components[i]; \ | |
2760 else \ | |
2761 for (i = component_len; i < component_idx; i++, char_offset++) \ | |
2762 *charbuf++ = components[i]; \ | |
2763 coding->annotated = 1; \ | |
2764 composition_state = COMPOSING_NO; \ | |
2765 } while (0) | |
2766 | |
2767 | |
26847 | 2768 /* Decode a composition rule from the byte C1 (and maybe one more byte |
2769 from SRC) and store one encoded composition rule in | |
2770 coding->cmp_data. */ | |
2771 | |
2772 #define DECODE_COMPOSITION_RULE(c1) \ | |
2773 do { \ | |
2774 (c1) -= 32; \ | |
2775 if (c1 < 81) /* old format (before ver.21) */ \ | |
2776 { \ | |
2777 int gref = (c1) / 9; \ | |
2778 int nref = (c1) % 9; \ | |
2779 if (gref == 4) gref = 10; \ | |
2780 if (nref == 4) nref = 10; \ | |
88365 | 2781 c1 = COMPOSITION_ENCODE_RULE (gref, nref); \ |
26847 | 2782 } \ |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2783 else if (c1 < 93) /* new format (after ver.21) */ \ |
26847 | 2784 { \ |
2785 ONE_MORE_BYTE (c2); \ | |
88365 | 2786 c1 = COMPOSITION_ENCODE_RULE (c1 - 81, c2 - 32); \ |
26847 | 2787 } \ |
88365 | 2788 else \ |
2789 c1 = 0; \ | |
26847 | 2790 } while (0) |
2791 | |
2792 | |
17052 | 2793 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
2794 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2795 static void |
88365 | 2796 decode_coding_iso_2022 (coding) |
17052 | 2797 struct coding_system *coding; |
2798 { | |
88365 | 2799 unsigned char *src = coding->source + coding->consumed; |
2800 unsigned char *src_end = coding->source + coding->src_bytes; | |
2801 unsigned char *src_base; | |
2802 int *charbuf = coding->charbuf; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2803 int *charbuf_end |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2804 = charbuf + coding->charbuf_size - 4 - MAX_ANNOTATION_LENGTH; |
88365 | 2805 int consumed_chars = 0, consumed_chars_base; |
2806 int multibytep = coding->src_multibyte; | |
17052 | 2807 /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
88365 | 2808 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2809 int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
2810 struct charset *charset; | |
2811 int c; | |
2812 /* For handling composition sequence. */ | |
2813 #define COMPOSING_NO 0 | |
2814 #define COMPOSING_CHAR 1 | |
2815 #define COMPOSING_RULE 2 | |
2816 #define COMPOSING_COMPONENT_CHAR 3 | |
2817 #define COMPOSING_COMPONENT_RULE 4 | |
2818 | |
2819 int composition_state = COMPOSING_NO; | |
2820 enum composition_method method; | |
2821 int components[MAX_COMPOSITION_COMPONENTS * 2 + 1]; | |
2822 int component_idx; | |
2823 int component_len; | |
2824 Lisp_Object attrs, eol_type, charset_list; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2825 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2826 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2827 int last_id = charset_ascii; |
88365 | 2828 |
2829 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
2830 setup_iso_safe_charsets (attrs); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2831 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2832 while (1) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2833 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2834 int c1, c2; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2835 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2836 src_base = src; |
88365 | 2837 consumed_chars_base = consumed_chars; |
2838 | |
2839 if (charbuf >= charbuf_end) | |
2840 break; | |
2841 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2842 ONE_MORE_BYTE (c1); |
17052 | 2843 |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2844 /* We produce at most one character. */ |
17052 | 2845 switch (iso_code_class [c1]) |
2846 { | |
2847 case ISO_0x20_or_0x7F: | |
88365 | 2848 if (composition_state != COMPOSING_NO) |
26847 | 2849 { |
88365 | 2850 if (composition_state == COMPOSING_RULE |
2851 || composition_state == COMPOSING_COMPONENT_RULE) | |
2852 { | |
2853 DECODE_COMPOSITION_RULE (c1); | |
2854 components[component_idx++] = c1; | |
2855 composition_state--; | |
2856 continue; | |
2857 } | |
26847 | 2858 } |
88365 | 2859 if (charset_id_0 < 0 |
2860 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_0))) | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2861 /* This is SPACE or DEL. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2862 charset = CHARSET_FROM_ID (charset_ascii); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2863 else |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2864 charset = CHARSET_FROM_ID (charset_id_0); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2865 break; |
17052 | 2866 |
2867 case ISO_graphic_plane_0: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2868 if (composition_state != COMPOSING_NO) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2869 { |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2870 if (composition_state == COMPOSING_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2871 || composition_state == COMPOSING_COMPONENT_RULE) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2872 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2873 DECODE_COMPOSITION_RULE (c1); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2874 components[component_idx++] = c1; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2875 composition_state--; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2876 continue; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2877 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2878 } |
88365 | 2879 charset = CHARSET_FROM_ID (charset_id_0); |
17052 | 2880 break; |
2881 | |
2882 case ISO_0xA0_or_0xFF: | |
88365 | 2883 if (charset_id_1 < 0 |
2884 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) | |
2885 || CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) | |
2886 goto invalid_code; | |
17052 | 2887 /* This is a graphic character, we fall down ... */ |
2888 | |
2889 case ISO_graphic_plane_1: | |
88365 | 2890 if (charset_id_1 < 0) |
2891 goto invalid_code; | |
2892 charset = CHARSET_FROM_ID (charset_id_1); | |
17052 | 2893 break; |
2894 | |
88365 | 2895 case ISO_carriage_return: |
2896 if (c1 == '\r') | |
2897 { | |
2898 if (EQ (eol_type, Qdos)) | |
2899 { | |
2900 if (src == src_end) | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2901 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2902 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2903 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2904 } |
88365 | 2905 if (*src == '\n') |
2906 ONE_MORE_BYTE (c1); | |
2907 } | |
2908 else if (EQ (eol_type, Qmac)) | |
2909 c1 = '\n'; | |
2910 } | |
2911 /* fall through */ | |
2912 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2913 case ISO_control_0: |
88365 | 2914 MAYBE_FINISH_COMPOSITION (); |
2915 charset = CHARSET_FROM_ID (charset_ascii); | |
17052 | 2916 break; |
2917 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2918 case ISO_control_1: |
88365 | 2919 MAYBE_FINISH_COMPOSITION (); |
2920 goto invalid_code; | |
17052 | 2921 |
2922 case ISO_shift_out: | |
88365 | 2923 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2924 || CODING_ISO_DESIGNATION (coding, 1) < 0) | |
2925 goto invalid_code; | |
2926 CODING_ISO_INVOCATION (coding, 0) = 1; | |
2927 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2928 continue; |
17052 | 2929 |
2930 case ISO_shift_in: | |
88365 | 2931 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)) |
2932 goto invalid_code; | |
2933 CODING_ISO_INVOCATION (coding, 0) = 0; | |
2934 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2935 continue; |
17052 | 2936 |
2937 case ISO_single_shift_2_7: | |
2938 case ISO_single_shift_2: | |
88365 | 2939 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2940 goto invalid_code; | |
17052 | 2941 /* SS2 is handled as an escape sequence of ESC 'N' */ |
2942 c1 = 'N'; | |
2943 goto label_escape_sequence; | |
2944 | |
2945 case ISO_single_shift_3: | |
88365 | 2946 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2947 goto invalid_code; | |
17052 | 2948 /* SS2 is handled as an escape sequence of ESC 'O' */ |
2949 c1 = 'O'; | |
2950 goto label_escape_sequence; | |
2951 | |
2952 case ISO_control_sequence_introducer: | |
2953 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
2954 c1 = '['; | |
2955 goto label_escape_sequence; | |
2956 | |
2957 case ISO_escape: | |
2958 ONE_MORE_BYTE (c1); | |
2959 label_escape_sequence: | |
88365 | 2960 /* Escape sequences handled here are invocation, |
17052 | 2961 designation, direction specification, and character |
2962 composition specification. */ | |
2963 switch (c1) | |
2964 { | |
2965 case '&': /* revision of following character set */ | |
2966 ONE_MORE_BYTE (c1); | |
2967 if (!(c1 >= '@' && c1 <= '~')) | |
88365 | 2968 goto invalid_code; |
17052 | 2969 ONE_MORE_BYTE (c1); |
2970 if (c1 != ISO_CODE_ESC) | |
88365 | 2971 goto invalid_code; |
17052 | 2972 ONE_MORE_BYTE (c1); |
2973 goto label_escape_sequence; | |
2974 | |
2975 case '$': /* designation of 2-byte character set */ | |
88365 | 2976 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
2977 goto invalid_code; | |
17052 | 2978 ONE_MORE_BYTE (c1); |
2979 if (c1 >= '@' && c1 <= 'B') | |
2980 { /* designation of JISX0208.1978, GB2312.1980, | |
23339
2da87b489590
(check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents:
23325
diff
changeset
|
2981 or JISX0208.1980 */ |
88365 | 2982 DECODE_DESIGNATION (0, 2, 0, c1); |
17052 | 2983 } |
2984 else if (c1 >= 0x28 && c1 <= 0x2B) | |
2985 { /* designation of DIMENSION2_CHARS94 character set */ | |
2986 ONE_MORE_BYTE (c2); | |
88365 | 2987 DECODE_DESIGNATION (c1 - 0x28, 2, 0, c2); |
17052 | 2988 } |
2989 else if (c1 >= 0x2C && c1 <= 0x2F) | |
2990 { /* designation of DIMENSION2_CHARS96 character set */ | |
2991 ONE_MORE_BYTE (c2); | |
88365 | 2992 DECODE_DESIGNATION (c1 - 0x2C, 2, 1, c2); |
17052 | 2993 } |
2994 else | |
88365 | 2995 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2996 /* We must update these variables now. */ |
88365 | 2997 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2998 charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2999 continue; |
17052 | 3000 |
3001 case 'n': /* invocation of locking-shift-2 */ | |
88365 | 3002 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
3003 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
3004 goto invalid_code; | |
3005 CODING_ISO_INVOCATION (coding, 0) = 2; | |
3006 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3007 continue; |
17052 | 3008 |
3009 case 'o': /* invocation of locking-shift-3 */ | |
88365 | 3010 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
3011 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
3012 goto invalid_code; | |
3013 CODING_ISO_INVOCATION (coding, 0) = 3; | |
3014 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3015 continue; |
17052 | 3016 |
3017 case 'N': /* invocation of single-shift-2 */ | |
88365 | 3018 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
3019 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
3020 goto invalid_code; | |
3021 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 2)); | |
17052 | 3022 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
3023 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 3024 goto invalid_code; |
17052 | 3025 break; |
3026 | |
3027 case 'O': /* invocation of single-shift-3 */ | |
88365 | 3028 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
3029 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
3030 goto invalid_code; | |
3031 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 3)); | |
17052 | 3032 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
3033 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 3034 goto invalid_code; |
17052 | 3035 break; |
3036 | |
26847 | 3037 case '0': case '2': case '3': case '4': /* start composition */ |
88365 | 3038 if (! (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK)) |
3039 goto invalid_code; | |
26847 | 3040 DECODE_COMPOSITION_START (c1); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3041 continue; |
17052 | 3042 |
26847 | 3043 case '1': /* end composition */ |
88365 | 3044 if (composition_state == COMPOSING_NO) |
3045 goto invalid_code; | |
3046 DECODE_COMPOSITION_END (); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3047 continue; |
17052 | 3048 |
3049 case '[': /* specification of direction */ | |
88365 | 3050 if (! CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DIRECTION) |
3051 goto invalid_code; | |
17052 | 3052 /* For the moment, nested direction is not supported. |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3053 So, `coding->mode & CODING_MODE_DIRECTION' zero means |
88365 | 3054 left-to-right, and nozero means right-to-left. */ |
17052 | 3055 ONE_MORE_BYTE (c1); |
3056 switch (c1) | |
3057 { | |
3058 case ']': /* end of the current direction */ | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3059 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 3060 |
3061 case '0': /* end of the current direction */ | |
3062 case '1': /* start of left-to-right direction */ | |
3063 ONE_MORE_BYTE (c1); | |
3064 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3065 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 3066 else |
88365 | 3067 goto invalid_code; |
17052 | 3068 break; |
3069 | |
3070 case '2': /* start of right-to-left direction */ | |
3071 ONE_MORE_BYTE (c1); | |
3072 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3073 coding->mode |= CODING_MODE_DIRECTION; |
17052 | 3074 else |
88365 | 3075 goto invalid_code; |
17052 | 3076 break; |
3077 | |
3078 default: | |
88365 | 3079 goto invalid_code; |
17052 | 3080 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3081 continue; |
17052 | 3082 |
3083 default: | |
88365 | 3084 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
3085 goto invalid_code; | |
17052 | 3086 if (c1 >= 0x28 && c1 <= 0x2B) |
3087 { /* designation of DIMENSION1_CHARS94 character set */ | |
3088 ONE_MORE_BYTE (c2); | |
88365 | 3089 DECODE_DESIGNATION (c1 - 0x28, 1, 0, c2); |
17052 | 3090 } |
3091 else if (c1 >= 0x2C && c1 <= 0x2F) | |
3092 { /* designation of DIMENSION1_CHARS96 character set */ | |
3093 ONE_MORE_BYTE (c2); | |
88365 | 3094 DECODE_DESIGNATION (c1 - 0x2C, 1, 1, c2); |
17052 | 3095 } |
3096 else | |
88365 | 3097 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3098 /* We must update these variables now. */ |
88365 | 3099 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
3100 charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3101 continue; |
17052 | 3102 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3103 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3104 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3105 if (charset->id != charset_ascii |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3106 && last_id != charset->id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3107 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3108 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3109 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3110 last_id = charset->id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3111 last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3112 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3113 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3114 /* Now we know CHARSET and 1st position code C1 of a character. |
88365 | 3115 Produce a decoded character while getting 2nd position code |
3116 C2 if necessary. */ | |
3117 c1 &= 0x7F; | |
3118 if (CHARSET_DIMENSION (charset) > 1) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3119 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3120 ONE_MORE_BYTE (c2); |
88365 | 3121 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3122 /* C2 is not in a valid range. */ |
88365 | 3123 goto invalid_code; |
3124 c1 = (c1 << 8) | (c2 & 0x7F); | |
3125 if (CHARSET_DIMENSION (charset) > 2) | |
3126 { | |
3127 ONE_MORE_BYTE (c2); | |
3128 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) | |
3129 /* C2 is not in a valid range. */ | |
3130 goto invalid_code; | |
3131 c1 = (c1 << 8) | (c2 & 0x7F); | |
3132 } | |
17052 | 3133 } |
88365 | 3134 |
3135 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); | |
3136 if (c < 0) | |
3137 { | |
3138 MAYBE_FINISH_COMPOSITION (); | |
3139 for (; src_base < src; src_base++, char_offset++) | |
3140 { | |
3141 if (ASCII_BYTE_P (*src_base)) | |
3142 *charbuf++ = *src_base; | |
3143 else | |
3144 *charbuf++ = BYTE8_TO_CHAR (*src_base); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3145 char_offset++; |
88365 | 3146 } |
3147 } | |
3148 else if (composition_state == COMPOSING_NO) | |
3149 { | |
3150 *charbuf++ = c; | |
3151 char_offset++; | |
3152 } | |
3153 else | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3154 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3155 components[component_idx++] = c; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3156 if (method == COMPOSITION_WITH_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3157 || (method == COMPOSITION_WITH_RULE_ALTCHARS |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3158 && composition_state == COMPOSING_COMPONENT_CHAR)) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3159 composition_state++; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3160 } |
17052 | 3161 continue; |
3162 | |
88365 | 3163 invalid_code: |
3164 MAYBE_FINISH_COMPOSITION (); | |
3165 src = src_base; | |
3166 consumed_chars = consumed_chars_base; | |
3167 ONE_MORE_BYTE (c); | |
3168 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3169 char_offset++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3170 coding->errors++; |
88365 | 3171 } |
3172 | |
3173 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3174 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3175 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
88365 | 3176 coding->consumed_char += consumed_chars_base; |
3177 coding->consumed = src_base - coding->source; | |
3178 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3179 } |
3180 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3181 |
18766 | 3182 /* ISO2022 encoding stuff. */ |
17052 | 3183 |
3184 /* | |
18766 | 3185 It is not enough to say just "ISO2022" on encoding, we have to |
88365 | 3186 specify more details. In Emacs, each coding system of ISO2022 |
17052 | 3187 variant has the following specifications: |
88365 | 3188 1. Initial designation to G0 thru G3. |
17052 | 3189 2. Allows short-form designation? |
3190 3. ASCII should be designated to G0 before control characters? | |
3191 4. ASCII should be designated to G0 at end of line? | |
3192 5. 7-bit environment or 8-bit environment? | |
3193 6. Use locking-shift? | |
3194 7. Use Single-shift? | |
3195 And the following two are only for Japanese: | |
3196 8. Use ASCII in place of JIS0201-1976-Roman? | |
3197 9. Use JISX0208-1983 in place of JISX0208-1978? | |
88365 | 3198 These specifications are encoded in CODING_ISO_FLAGS (coding) as flag bits |
3199 defined by macros CODING_ISO_FLAG_XXX. See `coding.h' for more | |
18766 | 3200 details. |
17052 | 3201 */ |
3202 | |
3203 /* Produce codes (escape sequence) for designating CHARSET to graphic | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3204 register REG at DST, and increment DST. If <final-char> of CHARSET is |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3205 '@', 'A', or 'B' and the coding system CODING allows, produce |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3206 designation sequence of short-form. */ |
17052 | 3207 |
3208 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
3209 do { \ | |
88365 | 3210 unsigned char final_char = CHARSET_ISO_FINAL (charset); \ |
17052 | 3211 char *intermediate_char_94 = "()*+"; \ |
3212 char *intermediate_char_96 = ",-./"; \ | |
88365 | 3213 int revision = -1; \ |
3214 int c; \ | |
3215 \ | |
3216 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ | |
88856 | 3217 revision = CHARSET_ISO_REVISION (charset); \ |
88365 | 3218 \ |
3219 if (revision >= 0) \ | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
3220 { \ |
88365 | 3221 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '&'); \ |
3222 EMIT_ONE_BYTE ('@' + revision); \ | |
17052 | 3223 } \ |
88365 | 3224 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ |
17052 | 3225 if (CHARSET_DIMENSION (charset) == 1) \ |
3226 { \ | |
88365 | 3227 if (! CHARSET_ISO_CHARS_96 (charset)) \ |
3228 c = intermediate_char_94[reg]; \ | |
17052 | 3229 else \ |
88365 | 3230 c = intermediate_char_96[reg]; \ |
3231 EMIT_ONE_ASCII_BYTE (c); \ | |
17052 | 3232 } \ |
3233 else \ | |
3234 { \ | |
88365 | 3235 EMIT_ONE_ASCII_BYTE ('$'); \ |
3236 if (! CHARSET_ISO_CHARS_96 (charset)) \ | |
17052 | 3237 { \ |
88365 | 3238 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LONG_FORM \ |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3239 || reg != 0 \ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3240 || final_char < '@' || final_char > 'B') \ |
88365 | 3241 EMIT_ONE_ASCII_BYTE (intermediate_char_94[reg]); \ |
17052 | 3242 } \ |
3243 else \ | |
88365 | 3244 EMIT_ONE_ASCII_BYTE (intermediate_char_96[reg]); \ |
17052 | 3245 } \ |
88365 | 3246 EMIT_ONE_ASCII_BYTE (final_char); \ |
3247 \ | |
3248 CODING_ISO_DESIGNATION (coding, reg) = CHARSET_ID (charset); \ | |
17052 | 3249 } while (0) |
3250 | |
88365 | 3251 |
17052 | 3252 /* The following two macros produce codes (control character or escape |
3253 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
3254 single-shift-3). */ | |
3255 | |
88365 | 3256 #define ENCODE_SINGLE_SHIFT_2 \ |
3257 do { \ | |
3258 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3259 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'N'); \ | |
3260 else \ | |
3261 EMIT_ONE_BYTE (ISO_CODE_SS2); \ | |
3262 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3263 } while (0) |
3264 | |
88365 | 3265 |
3266 #define ENCODE_SINGLE_SHIFT_3 \ | |
3267 do { \ | |
3268 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3269 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'O'); \ | |
3270 else \ | |
3271 EMIT_ONE_BYTE (ISO_CODE_SS3); \ | |
3272 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3273 } while (0) |
3274 | |
88365 | 3275 |
17052 | 3276 /* The following four macros produce codes (control character or |
3277 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
3278 shift-out, locking-shift-2, and locking-shift-3). */ | |
3279 | |
88365 | 3280 #define ENCODE_SHIFT_IN \ |
3281 do { \ | |
3282 EMIT_ONE_ASCII_BYTE (ISO_CODE_SI); \ | |
3283 CODING_ISO_INVOCATION (coding, 0) = 0; \ | |
17052 | 3284 } while (0) |
3285 | |
88365 | 3286 |
3287 #define ENCODE_SHIFT_OUT \ | |
3288 do { \ | |
3289 EMIT_ONE_ASCII_BYTE (ISO_CODE_SO); \ | |
3290 CODING_ISO_INVOCATION (coding, 0) = 1; \ | |
17052 | 3291 } while (0) |
3292 | |
88365 | 3293 |
3294 #define ENCODE_LOCKING_SHIFT_2 \ | |
3295 do { \ | |
3296 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3297 CODING_ISO_INVOCATION (coding, 0) = 2; \ | |
17052 | 3298 } while (0) |
3299 | |
88365 | 3300 |
3301 #define ENCODE_LOCKING_SHIFT_3 \ | |
3302 do { \ | |
3303 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3304 CODING_ISO_INVOCATION (coding, 0) = 3; \ | |
17052 | 3305 } while (0) |
3306 | |
88365 | 3307 |
18766 | 3308 /* Produce codes for a DIMENSION1 character whose character set is |
3309 CHARSET and whose position-code is C1. Designation and invocation | |
17052 | 3310 sequences are also produced in advance if necessary. */ |
3311 | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3312 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3313 do { \ |
88365 | 3314 int id = CHARSET_ID (charset); \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3315 \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3316 if ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_ROMAN) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3317 && id == charset_ascii) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3318 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3319 id = charset_jisx0201_roman; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3320 charset = CHARSET_FROM_ID (id); \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3321 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3322 \ |
88365 | 3323 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3324 { \ |
88365 | 3325 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ |
3326 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3327 else \ |
88365 | 3328 EMIT_ONE_BYTE (c1 | 0x80); \ |
3329 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3330 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3331 } \ |
88365 | 3332 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3333 { \ |
88365 | 3334 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3335 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3336 } \ |
88365 | 3337 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3338 { \ |
88365 | 3339 EMIT_ONE_BYTE (c1 | 0x80); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3340 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3341 } \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3342 else \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3343 /* Since CHARSET is not yet invoked to any graphic planes, we \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3344 must invoke it, or, at first, designate it to some graphic \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3345 register. Then repeat the loop to actually produce the \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3346 character. */ \ |
88365 | 3347 dst = encode_invocation_designation (charset, coding, dst, \ |
3348 &produced_chars); \ | |
17052 | 3349 } while (1) |
3350 | |
88365 | 3351 |
3352 /* Produce codes for a DIMENSION2 character whose character set is | |
3353 CHARSET and whose position-codes are C1 and C2. Designation and | |
3354 invocation codes are also produced in advance if necessary. */ | |
3355 | |
3356 #define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2) \ | |
24506
219c99669e4b
(ENCODE_ISO_CHARACTER): Check validity of CHARSET. If
Kenichi Handa <handa@m17n.org>
parents:
24460
diff
changeset
|
3357 do { \ |
88365 | 3358 int id = CHARSET_ID (charset); \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3359 \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3360 if ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_OLDJIS) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3361 && id == charset_jisx0208) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3362 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3363 id = charset_jisx0208_1978; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3364 charset = CHARSET_FROM_ID (id); \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3365 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3366 \ |
88365 | 3367 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
3368 { \ | |
3369 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3370 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3371 else \ | |
3372 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3373 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
3374 break; \ | |
3375 } \ | |
3376 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ | |
3377 { \ | |
3378 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3379 break; \ | |
3380 } \ | |
3381 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ | |
3382 { \ | |
3383 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3384 break; \ | |
3385 } \ | |
3386 else \ | |
3387 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
3388 must invoke it, or, at first, designate it to some graphic \ | |
3389 register. Then repeat the loop to actually produce the \ | |
3390 character. */ \ | |
3391 dst = encode_invocation_designation (charset, coding, dst, \ | |
3392 &produced_chars); \ | |
3393 } while (1) | |
3394 | |
3395 | |
3396 #define ENCODE_ISO_CHARACTER(charset, c) \ | |
3397 do { \ | |
3398 int code = ENCODE_CHAR ((charset),(c)); \ | |
3399 \ | |
3400 if (CHARSET_DIMENSION (charset) == 1) \ | |
3401 ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ | |
3402 else \ | |
3403 ENCODE_ISO_CHARACTER_DIMENSION2 ((charset), code >> 8, code & 0xFF); \ | |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
3404 } while (0) |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3405 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
3406 |
17052 | 3407 /* Produce designation and invocation codes at a place pointed by DST |
88365 | 3408 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. |
17052 | 3409 Return new DST. */ |
3410 | |
3411 unsigned char * | |
88365 | 3412 encode_invocation_designation (charset, coding, dst, p_nchars) |
3413 struct charset *charset; | |
17052 | 3414 struct coding_system *coding; |
3415 unsigned char *dst; | |
88365 | 3416 int *p_nchars; |
17052 | 3417 { |
88365 | 3418 int multibytep = coding->dst_multibyte; |
3419 int produced_chars = *p_nchars; | |
17052 | 3420 int reg; /* graphic register number */ |
88365 | 3421 int id = CHARSET_ID (charset); |
17052 | 3422 |
3423 /* At first, check designations. */ | |
3424 for (reg = 0; reg < 4; reg++) | |
88365 | 3425 if (id == CODING_ISO_DESIGNATION (coding, reg)) |
17052 | 3426 break; |
3427 | |
3428 if (reg >= 4) | |
3429 { | |
3430 /* CHARSET is not yet designated to any graphic registers. */ | |
3431 /* At first check the requested designation. */ | |
88365 | 3432 reg = CODING_ISO_REQUEST (coding, id); |
3433 if (reg < 0) | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3434 /* Since CHARSET requests no special designation, designate it |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3435 to graphic register 0. */ |
17052 | 3436 reg = 0; |
3437 | |
3438 ENCODE_DESIGNATION (charset, reg, coding); | |
3439 } | |
3440 | |
88365 | 3441 if (CODING_ISO_INVOCATION (coding, 0) != reg |
3442 && CODING_ISO_INVOCATION (coding, 1) != reg) | |
17052 | 3443 { |
3444 /* Since the graphic register REG is not invoked to any graphic | |
3445 planes, invoke it to graphic plane 0. */ | |
3446 switch (reg) | |
3447 { | |
3448 case 0: /* graphic register 0 */ | |
3449 ENCODE_SHIFT_IN; | |
3450 break; | |
3451 | |
3452 case 1: /* graphic register 1 */ | |
3453 ENCODE_SHIFT_OUT; | |
3454 break; | |
3455 | |
3456 case 2: /* graphic register 2 */ | |
88365 | 3457 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3458 ENCODE_SINGLE_SHIFT_2; |
3459 else | |
3460 ENCODE_LOCKING_SHIFT_2; | |
3461 break; | |
3462 | |
3463 case 3: /* graphic register 3 */ | |
88365 | 3464 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3465 ENCODE_SINGLE_SHIFT_3; |
3466 else | |
3467 ENCODE_LOCKING_SHIFT_3; | |
3468 break; | |
3469 } | |
3470 } | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3471 |
88365 | 3472 *p_nchars = produced_chars; |
17052 | 3473 return dst; |
3474 } | |
3475 | |
3476 /* The following three macros produce codes for indicating direction | |
3477 of text. */ | |
88365 | 3478 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ |
3479 do { \ | |
3480 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \ | |
3481 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \ | |
3482 else \ | |
3483 EMIT_ONE_BYTE (ISO_CODE_CSI); \ | |
17052 | 3484 } while (0) |
3485 | |
88365 | 3486 |
3487 #define ENCODE_DIRECTION_R2L() \ | |
3488 do { \ | |
3489 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3490 EMIT_TWO_ASCII_BYTES ('2', ']'); \ | |
3491 } while (0) | |
3492 | |
3493 | |
3494 #define ENCODE_DIRECTION_L2R() \ | |
3495 do { \ | |
3496 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3497 EMIT_TWO_ASCII_BYTES ('0', ']'); \ | |
3498 } while (0) | |
3499 | |
17052 | 3500 |
3501 /* Produce codes for designation and invocation to reset the graphic | |
3502 planes and registers to initial state. */ | |
88365 | 3503 #define ENCODE_RESET_PLANE_AND_REGISTER() \ |
3504 do { \ | |
3505 int reg; \ | |
3506 struct charset *charset; \ | |
3507 \ | |
3508 if (CODING_ISO_INVOCATION (coding, 0) != 0) \ | |
3509 ENCODE_SHIFT_IN; \ | |
3510 for (reg = 0; reg < 4; reg++) \ | |
3511 if (CODING_ISO_INITIAL (coding, reg) >= 0 \ | |
3512 && (CODING_ISO_DESIGNATION (coding, reg) \ | |
3513 != CODING_ISO_INITIAL (coding, reg))) \ | |
3514 { \ | |
3515 charset = CHARSET_FROM_ID (CODING_ISO_INITIAL (coding, reg)); \ | |
3516 ENCODE_DESIGNATION (charset, reg, coding); \ | |
3517 } \ | |
17052 | 3518 } while (0) |
3519 | |
88365 | 3520 |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3521 /* Produce designation sequences of charsets in the line started from |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3522 SRC to a place pointed by DST, and return updated DST. |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3523 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3524 If the current block ends before any end-of-line, we may fail to |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3525 find all the necessary designations. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3526 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3527 static unsigned char * |
88365 | 3528 encode_designation_at_bol (coding, charbuf, charbuf_end, dst) |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3529 struct coding_system *coding; |
88365 | 3530 int *charbuf, *charbuf_end; |
3531 unsigned char *dst; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3532 { |
88365 | 3533 struct charset *charset; |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3534 /* Table of charsets to be designated to each graphic register. */ |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3535 int r[4]; |
88365 | 3536 int c, found = 0, reg; |
3537 int produced_chars = 0; | |
3538 int multibytep = coding->dst_multibyte; | |
3539 Lisp_Object attrs; | |
3540 Lisp_Object charset_list; | |
3541 | |
3542 attrs = CODING_ID_ATTRS (coding->id); | |
3543 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
3544 if (EQ (charset_list, Qiso_2022)) | |
3545 charset_list = Viso_2022_charset_list; | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3546 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3547 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3548 r[reg] = -1; |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3549 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3550 while (found < 4) |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3551 { |
88365 | 3552 int id; |
3553 | |
3554 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3555 if (c == '\n') |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3556 break; |
88365 | 3557 charset = char_charset (c, charset_list, NULL); |
3558 id = CHARSET_ID (charset); | |
3559 reg = CODING_ISO_REQUEST (coding, id); | |
3560 if (reg >= 0 && r[reg] < 0) | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3561 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3562 found++; |
88365 | 3563 r[reg] = id; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3564 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3565 } |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3566 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3567 if (found) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3568 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3569 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3570 if (r[reg] >= 0 |
88365 | 3571 && CODING_ISO_DESIGNATION (coding, reg) != r[reg]) |
3572 ENCODE_DESIGNATION (CHARSET_FROM_ID (r[reg]), reg, coding); | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3573 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3574 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3575 return dst; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3576 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3577 |
17052 | 3578 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
3579 | |
88365 | 3580 static int |
3581 encode_coding_iso_2022 (coding) | |
17052 | 3582 struct coding_system *coding; |
3583 { | |
88365 | 3584 int multibytep = coding->dst_multibyte; |
3585 int *charbuf = coding->charbuf; | |
3586 int *charbuf_end = charbuf + coding->charbuf_used; | |
3587 unsigned char *dst = coding->destination + coding->produced; | |
3588 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3589 int safe_room = 16; | |
3590 int bol_designation | |
3591 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL | |
3592 && CODING_ISO_BOL (coding)); | |
3593 int produced_chars = 0; | |
3594 Lisp_Object attrs, eol_type, charset_list; | |
3595 int ascii_compatible; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3596 int c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3597 int preferred_charset_id = -1; |
88365 | 3598 |
3599 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3600 setup_iso_safe_charsets (attrs); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3601 /* Charset list may have been changed. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3602 charset_list = CODING_ATTR_CHARSET_LIST (attrs); \ |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3603 coding->safe_charsets |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3604 = (char *) XSTRING (CODING_ATTR_SAFE_CHARSETS(attrs))->data; |
88365 | 3605 |
3606 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3607 | |
3608 while (charbuf < charbuf_end) | |
3609 { | |
3610 ASSURE_DESTINATION (safe_room); | |
3611 | |
3612 if (bol_designation) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3613 { |
88365 | 3614 unsigned char *dst_prev = dst; |
3615 | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3616 /* We have to produce designation sequences if any now. */ |
88365 | 3617 dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); |
3618 bol_designation = 0; | |
3619 /* We are sure that designation sequences are all ASCII bytes. */ | |
3620 produced_chars += dst - dst_prev; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3621 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3622 |
88365 | 3623 c = *charbuf++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3624 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3625 if (c < 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3626 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3627 /* Handle an annotation. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3628 switch (*charbuf) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3629 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3630 case CODING_ANNOTATE_COMPOSITION_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3631 /* Not yet implemented. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3632 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3633 case CODING_ANNOTATE_CHARSET_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3634 preferred_charset_id = charbuf[3]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3635 if (preferred_charset_id >= 0 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3636 && NILP (Fmemq (make_number (preferred_charset_id), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3637 charset_list))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3638 preferred_charset_id = -1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3639 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3640 default: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3641 abort (); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3642 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3643 charbuf += -c - 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3644 continue; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3645 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3646 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3647 /* Now encode the character C. */ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3648 if (c < 0x20 || c == 0x7F) |
17052 | 3649 { |
88365 | 3650 if (c == '\n' |
3651 || (c == '\r' && EQ (eol_type, Qmac))) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3652 { |
88365 | 3653 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) |
3654 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3655 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_INIT_AT_BOL) | |
3656 { | |
3657 int i; | |
3658 | |
3659 for (i = 0; i < 4; i++) | |
3660 CODING_ISO_DESIGNATION (coding, i) | |
3661 = CODING_ISO_INITIAL (coding, i); | |
3662 } | |
3663 bol_designation | |
3664 = CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL; | |
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
3665 } |
88365 | 3666 else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) |
3667 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3668 EMIT_ONE_ASCII_BYTE (c); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3669 } |
88365 | 3670 else if (ASCII_CHAR_P (c)) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3671 { |
88365 | 3672 if (ascii_compatible) |
3673 EMIT_ONE_ASCII_BYTE (c); | |
3674 else | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3675 { |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3676 struct charset *charset = CHARSET_FROM_ID (charset_ascii); |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3677 ENCODE_ISO_CHARACTER (charset, c); |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3678 } |
17052 | 3679 } |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3680 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3681 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3682 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3683 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3684 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3685 else |
88365 | 3686 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3687 struct charset *charset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3688 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3689 if (preferred_charset_id >= 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3690 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3691 charset = CHARSET_FROM_ID (preferred_charset_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3692 if (! CHAR_CHARSET_P (c, charset)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3693 charset = char_charset (c, charset_list, NULL); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3694 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3695 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3696 charset = char_charset (c, charset_list, NULL); |
88365 | 3697 if (!charset) |
3698 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3699 if (coding->mode & CODING_MODE_SAFE_ENCODING) |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3700 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3701 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3702 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3703 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3704 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3705 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3706 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3707 charset = char_charset (c, charset_list, NULL); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3708 } |
88365 | 3709 } |
3710 ENCODE_ISO_CHARACTER (charset, c); | |
3711 } | |
3712 } | |
3713 | |
3714 if (coding->mode & CODING_MODE_LAST_BLOCK | |
3715 && CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) | |
3716 { | |
3717 ASSURE_DESTINATION (safe_room); | |
3718 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3719 } | |
3720 coding->result = CODING_RESULT_SUCCESS; | |
3721 CODING_ISO_BOL (coding) = bol_designation; | |
3722 coding->produced_char += produced_chars; | |
3723 coding->produced = dst - coding->destination; | |
3724 return 0; | |
17052 | 3725 } |
3726 | |
3727 | |
88365 | 3728 /*** 8,9. SJIS and BIG5 handlers ***/ |
3729 | |
3730 /* Although SJIS and BIG5 are not ISO's coding system, they are used | |
17052 | 3731 quite widely. So, for the moment, Emacs supports them in the bare |
3732 C code. But, in the future, they may be supported only by CCL. */ | |
3733 | |
3734 /* SJIS is a coding system encoding three character sets: ASCII, right | |
3735 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
3736 as is. A character of charset katakana-jisx0201 is encoded by | |
3737 "position-code + 0x80". A character of charset japanese-jisx0208 | |
3738 is encoded in 2-byte but two position-codes are divided and shifted | |
88365 | 3739 so that it fit in the range below. |
17052 | 3740 |
3741 --- CODE RANGE of SJIS --- | |
3742 (character set) (range) | |
3743 ASCII 0x00 .. 0x7F | |
88365 | 3744 KATAKANA-JISX0201 0xA0 .. 0xDF |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
3745 JISX0208 (1st byte) 0x81 .. 0x9F and 0xE0 .. 0xEF |
23564
6eb3e346d1fd
(DECODE_CHARACTER_ASCII): Check validity of inserted
Kenichi Handa <handa@m17n.org>
parents:
23542
diff
changeset
|
3746 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC |
17052 | 3747 ------------------------------- |
3748 | |
3749 */ | |
3750 | |
3751 /* BIG5 is a coding system encoding two character sets: ASCII and | |
3752 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
88365 | 3753 character set and is encoded in two-byte. |
17052 | 3754 |
3755 --- CODE RANGE of BIG5 --- | |
3756 (character set) (range) | |
3757 ASCII 0x00 .. 0x7F | |
3758 Big5 (1st byte) 0xA1 .. 0xFE | |
3759 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
3760 -------------------------- | |
3761 | |
88365 | 3762 */ |
17052 | 3763 |
3764 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3765 Check if a text is encoded in SJIS. If it is, return | |
88365 | 3766 CATEGORY_MASK_SJIS, else return 0. */ |
17052 | 3767 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3768 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3769 detect_coding_sjis (coding, detect_info) |
88365 | 3770 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3771 struct coding_detection_info *detect_info; |
17052 | 3772 { |
88365 | 3773 unsigned char *src = coding->source, *src_base = src; |
3774 unsigned char *src_end = coding->source + coding->src_bytes; | |
3775 int multibytep = coding->src_multibyte; | |
3776 int consumed_chars = 0; | |
3777 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3778 int c; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3779 int incomplete; |
88365 | 3780 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3781 detect_info->checked |= CATEGORY_MASK_SJIS; |
88365 | 3782 /* A coding system of this category is always ASCII compatible. */ |
3783 src += coding->head_ascii; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3784 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3785 while (1) |
17052 | 3786 { |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3787 incomplete = 0; |
88365 | 3788 ONE_MORE_BYTE (c); |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3789 incomplete = 1; |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3790 if (c < 0x80) |
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3791 continue; |
88365 | 3792 if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEF)) |
17052 | 3793 { |
88365 | 3794 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3795 if (c < 0x40 || c == 0x7F || c > 0xFC) |
88365 | 3796 break; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3797 found = CATEGORY_MASK_SJIS; |
17052 | 3798 } |
88365 | 3799 else if (c >= 0xA0 && c < 0xE0) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3800 found = CATEGORY_MASK_SJIS; |
88365 | 3801 else |
3802 break; | |
3803 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3804 detect_info->rejected |= CATEGORY_MASK_SJIS; |
88365 | 3805 return 0; |
3806 | |
3807 no_more_source: | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3808 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3809 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3810 detect_info->rejected |= CATEGORY_MASK_SJIS; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3811 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3812 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3813 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3814 return 1; |
17052 | 3815 } |
3816 | |
3817 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3818 Check if a text is encoded in BIG5. If it is, return | |
88365 | 3819 CATEGORY_MASK_BIG5, else return 0. */ |
17052 | 3820 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3821 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3822 detect_coding_big5 (coding, detect_info) |
88365 | 3823 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3824 struct coding_detection_info *detect_info; |
17052 | 3825 { |
88365 | 3826 unsigned char *src = coding->source, *src_base = src; |
3827 unsigned char *src_end = coding->source + coding->src_bytes; | |
3828 int multibytep = coding->src_multibyte; | |
3829 int consumed_chars = 0; | |
3830 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3831 int c; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3832 int incomplete; |
88365 | 3833 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3834 detect_info->checked |= CATEGORY_MASK_BIG5; |
88365 | 3835 /* A coding system of this category is always ASCII compatible. */ |
3836 src += coding->head_ascii; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3837 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3838 while (1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3839 { |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3840 incomplete = 0; |
88365 | 3841 ONE_MORE_BYTE (c); |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3842 incomplete = 1; |
88365 | 3843 if (c < 0x80) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3844 continue; |
88365 | 3845 if (c >= 0xA1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3846 { |
88365 | 3847 ONE_MORE_BYTE (c); |
3848 if (c < 0x40 || (c >= 0x7F && c <= 0xA0)) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3849 return 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3850 found = CATEGORY_MASK_BIG5; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3851 } |
88365 | 3852 else |
3853 break; | |
3854 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3855 detect_info->rejected |= CATEGORY_MASK_BIG5; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3856 return 0; |
88365 | 3857 |
3858 no_more_source: | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3859 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3860 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3861 detect_info->rejected |= CATEGORY_MASK_BIG5; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3862 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3863 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3864 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3865 return 1; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3866 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3867 |
17052 | 3868 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". |
3869 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
3870 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3871 static void |
88365 | 3872 decode_coding_sjis (coding) |
17052 | 3873 struct coding_system *coding; |
3874 { | |
88365 | 3875 unsigned char *src = coding->source + coding->consumed; |
3876 unsigned char *src_end = coding->source + coding->src_bytes; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3877 unsigned char *src_base; |
88365 | 3878 int *charbuf = coding->charbuf; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3879 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
88365 | 3880 int consumed_chars = 0, consumed_chars_base; |
3881 int multibytep = coding->src_multibyte; | |
3882 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3883 Lisp_Object attrs, eol_type, charset_list, val; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3884 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3885 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3886 int last_id = charset_ascii; |
88365 | 3887 |
3888 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3889 | |
3890 val = charset_list; | |
3891 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3892 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3893 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 3894 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3895 while (1) |
17052 | 3896 { |
88365 | 3897 int c, c1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3898 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3899 src_base = src; |
88365 | 3900 consumed_chars_base = consumed_chars; |
3901 | |
3902 if (charbuf >= charbuf_end) | |
3903 break; | |
3904 | |
3905 ONE_MORE_BYTE (c); | |
3906 | |
3907 if (c == '\r') | |
17052 | 3908 { |
88365 | 3909 if (EQ (eol_type, Qdos)) |
17052 | 3910 { |
88365 | 3911 if (src == src_end) |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3912 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3913 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3914 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3915 } |
88365 | 3916 if (*src == '\n') |
3917 ONE_MORE_BYTE (c); | |
17052 | 3918 } |
88365 | 3919 else if (EQ (eol_type, Qmac)) |
3920 c = '\n'; | |
17052 | 3921 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3922 else |
88365 | 3923 { |
3924 struct charset *charset; | |
3925 | |
3926 if (c < 0x80) | |
3927 charset = charset_roman; | |
3928 else | |
17052 | 3929 { |
88365 | 3930 if (c >= 0xF0) |
3931 goto invalid_code; | |
3932 if (c < 0xA0 || c >= 0xE0) | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3933 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3934 /* SJIS -> JISX0208 */ |
88365 | 3935 ONE_MORE_BYTE (c1); |
3936 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) | |
3937 goto invalid_code; | |
3938 c = (c << 8) | c1; | |
3939 SJIS_TO_JIS (c); | |
3940 charset = charset_kanji; | |
24870
b0f6eab5deeb
(decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents:
24822
diff
changeset
|
3941 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3942 else |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3943 { |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3944 /* SJIS -> JISX0201-Kana */ |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3945 c &= 0x7F; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3946 charset = charset_kana; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3947 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3948 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3949 if (charset->id != charset_ascii |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3950 && last_id != charset->id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3951 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3952 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3953 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3954 last_id = charset->id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3955 last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3956 } |
88365 | 3957 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
3958 } | |
3959 *charbuf++ = c; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3960 char_offset++; |
88365 | 3961 continue; |
3962 | |
3963 invalid_code: | |
3964 src = src_base; | |
3965 consumed_chars = consumed_chars_base; | |
3966 ONE_MORE_BYTE (c); | |
3967 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3968 char_offset++; |
88365 | 3969 coding->errors++; |
3970 } | |
3971 | |
3972 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3973 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3974 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
88365 | 3975 coding->consumed_char += consumed_chars_base; |
3976 coding->consumed = src_base - coding->source; | |
3977 coding->charbuf_used = charbuf - coding->charbuf; | |
3978 } | |
3979 | |
3980 static void | |
3981 decode_coding_big5 (coding) | |
3982 struct coding_system *coding; | |
3983 { | |
3984 unsigned char *src = coding->source + coding->consumed; | |
3985 unsigned char *src_end = coding->source + coding->src_bytes; | |
3986 unsigned char *src_base; | |
3987 int *charbuf = coding->charbuf; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3988 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
88365 | 3989 int consumed_chars = 0, consumed_chars_base; |
3990 int multibytep = coding->src_multibyte; | |
3991 struct charset *charset_roman, *charset_big5; | |
3992 Lisp_Object attrs, eol_type, charset_list, val; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3993 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3994 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3995 int last_id = charset_ascii; |
88365 | 3996 |
3997 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3998 val = charset_list; | |
3999 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
4000 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
4001 | |
4002 while (1) | |
4003 { | |
4004 int c, c1; | |
4005 | |
4006 src_base = src; | |
4007 consumed_chars_base = consumed_chars; | |
4008 | |
4009 if (charbuf >= charbuf_end) | |
4010 break; | |
4011 | |
4012 ONE_MORE_BYTE (c); | |
4013 | |
4014 if (c == '\r') | |
4015 { | |
4016 if (EQ (eol_type, Qdos)) | |
4017 { | |
4018 if (src == src_end) | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4019 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4020 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4021 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4022 } |
88365 | 4023 if (*src == '\n') |
4024 ONE_MORE_BYTE (c); | |
4025 } | |
4026 else if (EQ (eol_type, Qmac)) | |
4027 c = '\n'; | |
4028 } | |
4029 else | |
4030 { | |
4031 struct charset *charset; | |
4032 if (c < 0x80) | |
4033 charset = charset_roman; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4034 else |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4035 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4036 /* BIG5 -> Big5 */ |
88365 | 4037 if (c < 0xA1 || c > 0xFE) |
4038 goto invalid_code; | |
4039 ONE_MORE_BYTE (c1); | |
4040 if (c1 < 0x40 || (c1 > 0x7E && c1 < 0xA1) || c1 > 0xFE) | |
4041 goto invalid_code; | |
4042 c = c << 8 | c1; | |
4043 charset = charset_big5; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4044 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4045 if (charset->id != charset_ascii |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4046 && last_id != charset->id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4047 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4048 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4049 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4050 last_id = charset->id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4051 last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4052 } |
88365 | 4053 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4054 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4055 |
88365 | 4056 *charbuf++ = c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4057 char_offset++; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4058 continue; |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4059 |
88365 | 4060 invalid_code: |
17052 | 4061 src = src_base; |
88365 | 4062 consumed_chars = consumed_chars_base; |
4063 ONE_MORE_BYTE (c); | |
4064 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4065 char_offset++; |
88365 | 4066 coding->errors++; |
4067 } | |
4068 | |
4069 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4070 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4071 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
88365 | 4072 coding->consumed_char += consumed_chars_base; |
4073 coding->consumed = src_base - coding->source; | |
4074 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 4075 } |
4076 | |
4077 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4078 This function can encode charsets `ascii', `katakana-jisx0201', |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4079 `japanese-jisx0208', `chinese-big5-1', and `chinese-big5-2'. We |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4080 are sure that all these charsets are registered as official charset |
17052 | 4081 (i.e. do not have extended leading-codes). Characters of other |
4082 charsets are produced without any encoding. If SJIS_P is 1, encode | |
4083 SJIS text, else encode BIG5 text. */ | |
4084 | |
88365 | 4085 static int |
4086 encode_coding_sjis (coding) | |
17052 | 4087 struct coding_system *coding; |
4088 { | |
88365 | 4089 int multibytep = coding->dst_multibyte; |
4090 int *charbuf = coding->charbuf; | |
4091 int *charbuf_end = charbuf + coding->charbuf_used; | |
4092 unsigned char *dst = coding->destination + coding->produced; | |
4093 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4094 int safe_room = 4; | |
4095 int produced_chars = 0; | |
4096 Lisp_Object attrs, eol_type, charset_list, val; | |
4097 int ascii_compatible; | |
4098 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
4099 int c; | |
4100 | |
4101 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4102 val = charset_list; | |
4103 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
4104 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
4105 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); | |
4106 | |
4107 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4108 | |
4109 while (charbuf < charbuf_end) | |
4110 { | |
4111 ASSURE_DESTINATION (safe_room); | |
4112 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4113 /* Now encode the character C. */ |
88365 | 4114 if (ASCII_CHAR_P (c) && ascii_compatible) |
4115 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4116 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4117 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4118 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4119 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4120 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4121 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4122 { |
88365 | 4123 unsigned code; |
4124 struct charset *charset = char_charset (c, charset_list, &code); | |
4125 | |
4126 if (!charset) | |
4127 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4128 if (coding->mode & CODING_MODE_SAFE_ENCODING) |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4129 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4130 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4131 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4132 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4133 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4134 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4135 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4136 charset = char_charset (c, charset_list, &code); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4137 } |
88365 | 4138 } |
4139 if (code == CHARSET_INVALID_CODE (charset)) | |
4140 abort (); | |
4141 if (charset == charset_kanji) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4142 { |
88365 | 4143 int c1, c2; |
4144 JIS_TO_SJIS (code); | |
4145 c1 = code >> 8, c2 = code & 0xFF; | |
4146 EMIT_TWO_BYTES (c1, c2); | |
4147 } | |
4148 else if (charset == charset_kana) | |
4149 EMIT_ONE_BYTE (code | 0x80); | |
4150 else | |
4151 EMIT_ONE_ASCII_BYTE (code & 0x7F); | |
4152 } | |
4153 } | |
4154 coding->result = CODING_RESULT_SUCCESS; | |
4155 coding->produced_char += produced_chars; | |
4156 coding->produced = dst - coding->destination; | |
4157 return 0; | |
4158 } | |
4159 | |
4160 static int | |
4161 encode_coding_big5 (coding) | |
4162 struct coding_system *coding; | |
4163 { | |
4164 int multibytep = coding->dst_multibyte; | |
4165 int *charbuf = coding->charbuf; | |
4166 int *charbuf_end = charbuf + coding->charbuf_used; | |
4167 unsigned char *dst = coding->destination + coding->produced; | |
4168 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4169 int safe_room = 4; | |
4170 int produced_chars = 0; | |
4171 Lisp_Object attrs, eol_type, charset_list, val; | |
4172 int ascii_compatible; | |
4173 struct charset *charset_roman, *charset_big5; | |
4174 int c; | |
4175 | |
4176 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4177 val = charset_list; | |
4178 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
4179 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
4180 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4181 | |
4182 while (charbuf < charbuf_end) | |
4183 { | |
4184 ASSURE_DESTINATION (safe_room); | |
4185 c = *charbuf++; | |
4186 /* Now encode the character C. */ | |
4187 if (ASCII_CHAR_P (c) && ascii_compatible) | |
4188 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4189 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4190 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4191 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4192 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4193 } |
88365 | 4194 else |
4195 { | |
4196 unsigned code; | |
4197 struct charset *charset = char_charset (c, charset_list, &code); | |
4198 | |
4199 if (! charset) | |
4200 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4201 if (coding->mode & CODING_MODE_SAFE_ENCODING) |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4202 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4203 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4204 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4205 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4206 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4207 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4208 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4209 charset = char_charset (c, charset_list, &code); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4210 } |
88365 | 4211 } |
4212 if (code == CHARSET_INVALID_CODE (charset)) | |
4213 abort (); | |
4214 if (charset == charset_big5) | |
4215 { | |
4216 int c1, c2; | |
4217 | |
4218 c1 = code >> 8, c2 = code & 0xFF; | |
4219 EMIT_TWO_BYTES (c1, c2); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4220 } |
17052 | 4221 else |
88365 | 4222 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
17052 | 4223 } |
88365 | 4224 } |
4225 coding->result = CODING_RESULT_SUCCESS; | |
4226 coding->produced_char += produced_chars; | |
4227 coding->produced = dst - coding->destination; | |
4228 return 0; | |
17052 | 4229 } |
4230 | |
4231 | |
88365 | 4232 /*** 10. CCL handlers ***/ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4233 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4234 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4235 Check if a text is encoded in a coding system of which |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4236 encoder/decoder are written in CCL program. If it is, return |
88365 | 4237 CATEGORY_MASK_CCL, else return 0. */ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4238 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
4239 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4240 detect_coding_ccl (coding, detect_info) |
88365 | 4241 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4242 struct coding_detection_info *detect_info; |
88365 | 4243 { |
4244 unsigned char *src = coding->source, *src_base = src; | |
4245 unsigned char *src_end = coding->source + coding->src_bytes; | |
4246 int multibytep = coding->src_multibyte; | |
4247 int consumed_chars = 0; | |
4248 int found = 0; | |
4249 unsigned char *valids = CODING_CCL_VALIDS (coding); | |
4250 int head_ascii = coding->head_ascii; | |
4251 Lisp_Object attrs; | |
4252 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4253 detect_info->checked |= CATEGORY_MASK_CCL; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4254 |
88365 | 4255 coding = &coding_categories[coding_category_ccl]; |
4256 attrs = CODING_ID_ATTRS (coding->id); | |
4257 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4258 src += head_ascii; | |
4259 | |
4260 while (1) | |
4261 { | |
4262 int c; | |
4263 ONE_MORE_BYTE (c); | |
4264 if (! valids[c]) | |
4265 break; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4266 if ((valids[c] > 1)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4267 found = CATEGORY_MASK_CCL; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4268 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4269 detect_info->rejected |= CATEGORY_MASK_CCL; |
88365 | 4270 return 0; |
4271 | |
4272 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4273 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4274 return 1; |
88365 | 4275 } |
4276 | |
4277 static void | |
4278 decode_coding_ccl (coding) | |
4279 struct coding_system *coding; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4280 { |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
4281 const unsigned char *src = coding->source + coding->consumed; |
88365 | 4282 unsigned char *src_end = coding->source + coding->src_bytes; |
4283 int *charbuf = coding->charbuf; | |
4284 int *charbuf_end = charbuf + coding->charbuf_size; | |
4285 int consumed_chars = 0; | |
4286 int multibytep = coding->src_multibyte; | |
4287 struct ccl_program ccl; | |
4288 int source_charbuf[1024]; | |
4289 int source_byteidx[1024]; | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4290 Lisp_Object attrs, eol_type, charset_list, valids; |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4291 |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4292 CODING_GET_INFO (coding, attrs, eol_type, charset_list); |
88365 | 4293 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); |
4294 | |
4295 while (src < src_end) | |
4296 { | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
4297 const unsigned char *p = src; |
88365 | 4298 int *source, *source_end; |
4299 int i = 0; | |
4300 | |
4301 if (multibytep) | |
4302 while (i < 1024 && p < src_end) | |
4303 { | |
4304 source_byteidx[i] = p - src; | |
4305 source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | |
4306 } | |
4307 else | |
4308 while (i < 1024 && p < src_end) | |
4309 source_charbuf[i++] = *p++; | |
4310 | |
4311 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) | |
4312 ccl.last_block = 1; | |
4313 | |
4314 source = source_charbuf; | |
4315 source_end = source + i; | |
4316 while (source < source_end) | |
4317 { | |
4318 ccl_driver (&ccl, source, charbuf, | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4319 source_end - source, charbuf_end - charbuf, |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4320 charset_list); |
88365 | 4321 source += ccl.consumed; |
4322 charbuf += ccl.produced; | |
4323 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
4324 break; | |
4325 } | |
4326 if (source < source_end) | |
4327 src += source_byteidx[source - source_charbuf]; | |
4328 else | |
4329 src = p; | |
4330 consumed_chars += source - source_charbuf; | |
4331 | |
4332 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
4333 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
4334 break; | |
4335 } | |
4336 | |
4337 switch (ccl.status) | |
4338 { | |
4339 case CCL_STAT_SUSPEND_BY_SRC: | |
4340 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4341 break; | |
4342 case CCL_STAT_SUSPEND_BY_DST: | |
4343 break; | |
4344 case CCL_STAT_QUIT: | |
4345 case CCL_STAT_INVALID_CMD: | |
4346 coding->result = CODING_RESULT_INTERRUPT; | |
4347 break; | |
4348 default: | |
4349 coding->result = CODING_RESULT_SUCCESS; | |
4350 break; | |
4351 } | |
4352 coding->consumed_char += consumed_chars; | |
4353 coding->consumed = src - coding->source; | |
4354 coding->charbuf_used = charbuf - coding->charbuf; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4355 } |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4356 |
88365 | 4357 static int |
4358 encode_coding_ccl (coding) | |
4359 struct coding_system *coding; | |
4360 { | |
4361 struct ccl_program ccl; | |
4362 int multibytep = coding->dst_multibyte; | |
4363 int *charbuf = coding->charbuf; | |
4364 int *charbuf_end = charbuf + coding->charbuf_used; | |
4365 unsigned char *dst = coding->destination + coding->produced; | |
4366 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4367 unsigned char *adjusted_dst_end = dst_end - 1; | |
4368 int destination_charbuf[1024]; | |
4369 int i, produced_chars = 0; | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4370 Lisp_Object attrs, eol_type, charset_list; |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4371 |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4372 CODING_GET_INFO (coding, attrs, eol_type, charset_list); |
88365 | 4373 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); |
4374 | |
4375 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; | |
4376 ccl.dst_multibyte = coding->dst_multibyte; | |
4377 | |
4378 while (charbuf < charbuf_end && dst < adjusted_dst_end) | |
4379 { | |
4380 int dst_bytes = dst_end - dst; | |
4381 if (dst_bytes > 1024) | |
4382 dst_bytes = 1024; | |
4383 | |
4384 ccl_driver (&ccl, charbuf, destination_charbuf, | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
4385 charbuf_end - charbuf, dst_bytes, charset_list); |
88365 | 4386 charbuf += ccl.consumed; |
4387 if (multibytep) | |
4388 for (i = 0; i < ccl.produced; i++) | |
4389 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); | |
4390 else | |
4391 { | |
4392 for (i = 0; i < ccl.produced; i++) | |
4393 *dst++ = destination_charbuf[i] & 0xFF; | |
4394 produced_chars += ccl.produced; | |
4395 } | |
4396 } | |
4397 | |
4398 switch (ccl.status) | |
4399 { | |
4400 case CCL_STAT_SUSPEND_BY_SRC: | |
4401 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4402 break; | |
4403 case CCL_STAT_SUSPEND_BY_DST: | |
4404 coding->result = CODING_RESULT_INSUFFICIENT_DST; | |
4405 break; | |
4406 case CCL_STAT_QUIT: | |
4407 case CCL_STAT_INVALID_CMD: | |
4408 coding->result = CODING_RESULT_INTERRUPT; | |
4409 break; | |
4410 default: | |
4411 coding->result = CODING_RESULT_SUCCESS; | |
4412 break; | |
4413 } | |
4414 | |
4415 coding->produced_char += produced_chars; | |
4416 coding->produced = dst - coding->destination; | |
4417 return 0; | |
4418 } | |
4419 | |
4420 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4421 |
88365 | 4422 /*** 10, 11. no-conversion handlers ***/ |
17052 | 4423 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4424 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4425 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4426 static void |
88365 | 4427 decode_coding_raw_text (coding) |
17052 | 4428 struct coding_system *coding; |
4429 { | |
88365 | 4430 coding->chars_at_source = 1; |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4431 coding->consumed_char = 0; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4432 coding->consumed = 0; |
88365 | 4433 coding->result = CODING_RESULT_SUCCESS; |
4434 } | |
4435 | |
4436 static int | |
4437 encode_coding_raw_text (coding) | |
4438 struct coding_system *coding; | |
4439 { | |
4440 int multibytep = coding->dst_multibyte; | |
4441 int *charbuf = coding->charbuf; | |
4442 int *charbuf_end = coding->charbuf + coding->charbuf_used; | |
4443 unsigned char *dst = coding->destination + coding->produced; | |
4444 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4445 int produced_chars = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4446 int c; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4447 |
88365 | 4448 if (multibytep) |
4449 { | |
4450 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
4451 | |
4452 if (coding->src_multibyte) | |
4453 while (charbuf < charbuf_end) | |
4454 { | |
4455 ASSURE_DESTINATION (safe_room); | |
4456 c = *charbuf++; | |
4457 if (ASCII_CHAR_P (c)) | |
4458 EMIT_ONE_ASCII_BYTE (c); | |
4459 else if (CHAR_BYTE8_P (c)) | |
4460 { | |
4461 c = CHAR_TO_BYTE8 (c); | |
4462 EMIT_ONE_BYTE (c); | |
4463 } | |
4464 else | |
4465 { | |
4466 unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | |
4467 | |
4468 CHAR_STRING_ADVANCE (c, p1); | |
4469 while (p0 < p1) | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4470 { |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4471 EMIT_ONE_BYTE (*p0); |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4472 p0++; |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4473 } |
88365 | 4474 } |
4475 } | |
4476 else | |
4477 while (charbuf < charbuf_end) | |
4478 { | |
4479 ASSURE_DESTINATION (safe_room); | |
4480 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4481 EMIT_ONE_BYTE (c); |
88365 | 4482 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4483 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4484 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4485 { |
88365 | 4486 if (coding->src_multibyte) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4487 { |
88365 | 4488 int safe_room = MAX_MULTIBYTE_LENGTH; |
4489 | |
4490 while (charbuf < charbuf_end) | |
4491 { | |
4492 ASSURE_DESTINATION (safe_room); | |
4493 c = *charbuf++; | |
4494 if (ASCII_CHAR_P (c)) | |
4495 *dst++ = c; | |
4496 else if (CHAR_BYTE8_P (c)) | |
4497 *dst++ = CHAR_TO_BYTE8 (c); | |
4498 else | |
4499 CHAR_STRING_ADVANCE (c, dst); | |
4500 produced_chars++; | |
4501 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4502 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4503 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4504 { |
88365 | 4505 ASSURE_DESTINATION (charbuf_end - charbuf); |
4506 while (charbuf < charbuf_end && dst < dst_end) | |
4507 *dst++ = *charbuf++; | |
4508 produced_chars = dst - (coding->destination + coding->dst_bytes); | |
4509 } | |
4510 } | |
4511 coding->result = CODING_RESULT_SUCCESS; | |
4512 coding->produced_char += produced_chars; | |
4513 coding->produced = dst - coding->destination; | |
4514 return 0; | |
4515 } | |
4516 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4517 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4518 Check if a text is encoded in a charset-based coding system. If it |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4519 is, return 1, else return 0. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4520 |
88365 | 4521 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4522 detect_coding_charset (coding, detect_info) |
88365 | 4523 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4524 struct coding_detection_info *detect_info; |
88365 | 4525 { |
4526 unsigned char *src = coding->source, *src_base = src; | |
4527 unsigned char *src_end = coding->source + coding->src_bytes; | |
4528 int multibytep = coding->src_multibyte; | |
4529 int consumed_chars = 0; | |
4530 Lisp_Object attrs, valids; | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
4531 int found = 0; |
88365 | 4532 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4533 detect_info->checked |= CATEGORY_MASK_CHARSET; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4534 |
88365 | 4535 coding = &coding_categories[coding_category_charset]; |
4536 attrs = CODING_ID_ATTRS (coding->id); | |
4537 valids = AREF (attrs, coding_attr_charset_valids); | |
4538 | |
4539 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4540 src += coding->head_ascii; | |
4541 | |
4542 while (1) | |
4543 { | |
4544 int c; | |
4545 | |
4546 ONE_MORE_BYTE (c); | |
4547 if (NILP (AREF (valids, c))) | |
4548 break; | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
4549 if (c >= 0x80) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4550 found = CATEGORY_MASK_CHARSET; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4551 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4552 detect_info->rejected |= CATEGORY_MASK_CHARSET; |
88365 | 4553 return 0; |
4554 | |
4555 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4556 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4557 return 1; |
88365 | 4558 } |
4559 | |
4560 static void | |
4561 decode_coding_charset (coding) | |
4562 struct coding_system *coding; | |
4563 { | |
4564 unsigned char *src = coding->source + coding->consumed; | |
4565 unsigned char *src_end = coding->source + coding->src_bytes; | |
4566 unsigned char *src_base; | |
4567 int *charbuf = coding->charbuf; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4568 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
88365 | 4569 int consumed_chars = 0, consumed_chars_base; |
4570 int multibytep = coding->src_multibyte; | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4571 Lisp_Object attrs, eol_type, charset_list, valids; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4572 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4573 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4574 int last_id = charset_ascii; |
88365 | 4575 |
4576 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4577 valids = AREF (attrs, coding_attr_charset_valids); |
88365 | 4578 |
4579 while (1) | |
4580 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4581 int c; |
88365 | 4582 |
4583 src_base = src; | |
4584 consumed_chars_base = consumed_chars; | |
4585 | |
4586 if (charbuf >= charbuf_end) | |
4587 break; | |
4588 | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4589 ONE_MORE_BYTE (c); |
88365 | 4590 if (c == '\r') |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4591 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4592 /* Here we assume that no charset maps '\r' to something |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4593 else. */ |
88365 | 4594 if (EQ (eol_type, Qdos)) |
4595 { | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4596 if (src == src_end) |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4597 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4598 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4599 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4600 } |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4601 if (*src == '\n') |
88365 | 4602 ONE_MORE_BYTE (c); |
4603 } | |
4604 else if (EQ (eol_type, Qmac)) | |
4605 c = '\n'; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4606 } |
88365 | 4607 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4608 { |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4609 Lisp_Object val; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4610 struct charset *charset; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4611 int dim; |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4612 int len = 1; |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4613 unsigned code = c; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4614 |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4615 val = AREF (valids, c); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4616 if (NILP (val)) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4617 goto invalid_code; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4618 if (INTEGERP (val)) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4619 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4620 charset = CHARSET_FROM_ID (XFASTINT (val)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4621 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4622 while (len < dim) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4623 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4624 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4625 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4626 len++; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4627 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4628 CODING_DECODE_CHAR (coding, src, src_base, src_end, |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4629 charset, code, c); |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4630 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4631 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4632 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4633 /* VAL is a list of charset IDs. It is assured that the |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4634 list is sorted by charset dimensions (smaller one |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4635 comes first). */ |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4636 while (CONSP (val)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4637 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4638 charset = CHARSET_FROM_ID (XFASTINT (XCAR (val))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4639 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4640 while (len < dim) |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4641 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4642 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4643 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4644 len++; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4645 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4646 CODING_DECODE_CHAR (coding, src, src_base, |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4647 src_end, charset, code, c); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4648 if (c >= 0) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4649 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4650 val = XCDR (val); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4651 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4652 } |
88365 | 4653 if (c < 0) |
4654 goto invalid_code; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4655 if (charset->id != charset_ascii |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4656 && last_id != charset->id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4657 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4658 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4659 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4660 last_id = charset->id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4661 last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4662 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4663 } |
88365 | 4664 *charbuf++ = c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4665 char_offset++; |
88365 | 4666 continue; |
4667 | |
4668 invalid_code: | |
4669 src = src_base; | |
4670 consumed_chars = consumed_chars_base; | |
4671 ONE_MORE_BYTE (c); | |
4672 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4673 char_offset++; |
88365 | 4674 coding->errors++; |
4675 } | |
4676 | |
4677 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4678 if (last_id != charset_ascii) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4679 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
88365 | 4680 coding->consumed_char += consumed_chars_base; |
4681 coding->consumed = src_base - coding->source; | |
4682 coding->charbuf_used = charbuf - coding->charbuf; | |
4683 } | |
4684 | |
4685 static int | |
4686 encode_coding_charset (coding) | |
4687 struct coding_system *coding; | |
4688 { | |
4689 int multibytep = coding->dst_multibyte; | |
4690 int *charbuf = coding->charbuf; | |
4691 int *charbuf_end = charbuf + coding->charbuf_used; | |
4692 unsigned char *dst = coding->destination + coding->produced; | |
4693 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4694 int safe_room = MAX_MULTIBYTE_LENGTH; | |
4695 int produced_chars = 0; | |
4696 Lisp_Object attrs, eol_type, charset_list; | |
4697 int ascii_compatible; | |
4698 int c; | |
4699 | |
4700 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4701 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4702 | |
4703 while (charbuf < charbuf_end) | |
4704 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4705 struct charset *charset; |
88365 | 4706 unsigned code; |
4707 | |
4708 ASSURE_DESTINATION (safe_room); | |
4709 c = *charbuf++; | |
4710 if (ascii_compatible && ASCII_CHAR_P (c)) | |
4711 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4712 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4713 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4714 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4715 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4716 } |
88365 | 4717 else |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4718 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4719 charset = char_charset (c, charset_list, &code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4720 if (charset) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4721 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4722 if (CHARSET_DIMENSION (charset) == 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4723 EMIT_ONE_BYTE (code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4724 else if (CHARSET_DIMENSION (charset) == 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4725 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4726 else if (CHARSET_DIMENSION (charset) == 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4727 EMIT_THREE_BYTES (code >> 16, (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4728 else |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4729 EMIT_FOUR_BYTES (code >> 24, (code >> 16) & 0xFF, |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4730 (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4731 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4732 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4733 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4734 if (coding->mode & CODING_MODE_SAFE_ENCODING) |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4735 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4736 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4737 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4738 EMIT_ONE_BYTE (c); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4739 } |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4740 } |
88365 | 4741 } |
4742 | |
4743 coding->result = CODING_RESULT_SUCCESS; | |
4744 coding->produced_char += produced_chars; | |
4745 coding->produced = dst - coding->destination; | |
4746 return 0; | |
17052 | 4747 } |
4748 | |
4749 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4750 /*** 7. C library functions ***/ |
17052 | 4751 |
88365 | 4752 /* Setup coding context CODING from information about CODING_SYSTEM. |
4753 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
4754 CODING_SYSTEM is invalid, signal an error. */ | |
4755 | |
4756 void | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4757 setup_coding_system (coding_system, coding) |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4758 Lisp_Object coding_system; |
17052 | 4759 struct coding_system *coding; |
4760 { | |
88365 | 4761 Lisp_Object attrs; |
4762 Lisp_Object eol_type; | |
4763 Lisp_Object coding_type; | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
4764 Lisp_Object val; |
17052 | 4765 |
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
4766 if (NILP (coding_system)) |
88365 | 4767 coding_system = Qno_conversion; |
4768 | |
4769 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
4770 | |
4771 attrs = CODING_ID_ATTRS (coding->id); | |
4772 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4773 | |
4774 coding->mode = 0; | |
4775 coding->head_ascii = -1; | |
4776 coding->common_flags | |
4777 = (VECTORP (eol_type) ? CODING_REQUIRE_DETECTION_MASK : 0); | |
4778 | |
4779 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4780 coding->max_charset_id = XSTRING (val)->size - 1; | |
4781 coding->safe_charsets = (char *) XSTRING (val)->data; | |
4782 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); | |
4783 | |
4784 coding_type = CODING_ATTR_TYPE (attrs); | |
4785 if (EQ (coding_type, Qundecided)) | |
4786 { | |
4787 coding->detector = NULL; | |
4788 coding->decoder = decode_coding_raw_text; | |
4789 coding->encoder = encode_coding_raw_text; | |
4790 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
4791 } | |
4792 else if (EQ (coding_type, Qiso_2022)) | |
4793 { | |
4794 int i; | |
4795 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4796 enum coding_category category = XINT (CODING_ATTR_CATEGORY (attrs)); |
88365 | 4797 |
4798 /* Invoke graphic register 0 to plane 0. */ | |
4799 CODING_ISO_INVOCATION (coding, 0) = 0; | |
4800 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
4801 CODING_ISO_INVOCATION (coding, 1) | |
4802 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
4803 /* Setup the initial status of designation. */ | |
4804 for (i = 0; i < 4; i++) | |
4805 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
4806 /* Not single shifting initially. */ | |
4807 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
4808 /* Beginning of buffer should also be regarded as bol. */ | |
4809 CODING_ISO_BOL (coding) = 1; | |
4810 coding->detector = detect_coding_iso_2022; | |
4811 coding->decoder = decode_coding_iso_2022; | |
4812 coding->encoder = encode_coding_iso_2022; | |
4813 if (flags & CODING_ISO_FLAG_SAFE) | |
4814 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4815 coding->common_flags |
88365 | 4816 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4817 | CODING_REQUIRE_FLUSHING_MASK); | |
4818 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
4819 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4820 if (flags & CODING_ISO_FLAG_DESIGNATION) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4821 coding->common_flags |= CODING_ANNOTATE_CHARSET_MASK; |
88365 | 4822 if (flags & CODING_ISO_FLAG_FULL_SUPPORT) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4823 { |
88365 | 4824 setup_iso_safe_charsets (attrs); |
4825 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4826 coding->max_charset_id = XSTRING (val)->size - 1; | |
4827 coding->safe_charsets = (char *) XSTRING (val)->data; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4828 } |
88365 | 4829 CODING_ISO_FLAGS (coding) = flags; |
4830 } | |
4831 else if (EQ (coding_type, Qcharset)) | |
4832 { | |
4833 coding->detector = detect_coding_charset; | |
4834 coding->decoder = decode_coding_charset; | |
4835 coding->encoder = encode_coding_charset; | |
4836 coding->common_flags | |
4837 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4838 } | |
4839 else if (EQ (coding_type, Qutf_8)) | |
4840 { | |
4841 coding->detector = detect_coding_utf_8; | |
4842 coding->decoder = decode_coding_utf_8; | |
4843 coding->encoder = encode_coding_utf_8; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
4844 coding->common_flags |
88365 | 4845 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4846 } | |
4847 else if (EQ (coding_type, Qutf_16)) | |
4848 { | |
4849 val = AREF (attrs, coding_attr_utf_16_bom); | |
4850 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_16_detect_bom | |
4851 : EQ (val, Qt) ? utf_16_with_bom | |
4852 : utf_16_without_bom); | |
4853 val = AREF (attrs, coding_attr_utf_16_endian); | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
4854 CODING_UTF_16_ENDIAN (coding) = (EQ (val, Qbig) ? utf_16_big_endian |
88365 | 4855 : utf_16_little_endian); |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
4856 CODING_UTF_16_SURROGATE (coding) = 0; |
88365 | 4857 coding->detector = detect_coding_utf_16; |
4858 coding->decoder = decode_coding_utf_16; | |
4859 coding->encoder = encode_coding_utf_16; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4860 coding->common_flags |
88365 | 4861 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
4862 if (CODING_UTF_16_BOM (coding) == utf_16_detect_bom) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
4863 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; |
88365 | 4864 } |
4865 else if (EQ (coding_type, Qccl)) | |
4866 { | |
4867 coding->detector = detect_coding_ccl; | |
4868 coding->decoder = decode_coding_ccl; | |
4869 coding->encoder = encode_coding_ccl; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4870 coding->common_flags |
88365 | 4871 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4872 | CODING_REQUIRE_FLUSHING_MASK); | |
4873 } | |
4874 else if (EQ (coding_type, Qemacs_mule)) | |
4875 { | |
4876 coding->detector = detect_coding_emacs_mule; | |
4877 coding->decoder = decode_coding_emacs_mule; | |
4878 coding->encoder = encode_coding_emacs_mule; | |
4879 coding->common_flags | |
4880 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4881 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) | |
4882 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
4883 { | |
4884 Lisp_Object tail, safe_charsets; | |
4885 int max_charset_id = 0; | |
4886 | |
4887 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4888 tail = XCDR (tail)) | |
4889 if (max_charset_id < XFASTINT (XCAR (tail))) | |
4890 max_charset_id = XFASTINT (XCAR (tail)); | |
4891 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
4892 make_number (255)); | |
4893 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4894 tail = XCDR (tail)) | |
4895 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
4896 coding->max_charset_id = max_charset_id; | |
4897 coding->safe_charsets = (char *) XSTRING (safe_charsets)->data; | |
4898 } | |
4899 } | |
4900 else if (EQ (coding_type, Qshift_jis)) | |
4901 { | |
4902 coding->detector = detect_coding_sjis; | |
4903 coding->decoder = decode_coding_sjis; | |
4904 coding->encoder = encode_coding_sjis; | |
4905 coding->common_flags | |
4906 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4907 } | |
4908 else if (EQ (coding_type, Qbig5)) | |
4909 { | |
4910 coding->detector = detect_coding_big5; | |
4911 coding->decoder = decode_coding_big5; | |
4912 coding->encoder = encode_coding_big5; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4913 coding->common_flags |
88365 | 4914 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4915 } | |
4916 else /* EQ (coding_type, Qraw_text) */ | |
4917 { | |
4918 coding->detector = NULL; | |
4919 coding->decoder = decode_coding_raw_text; | |
4920 coding->encoder = encode_coding_raw_text; | |
4921 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
4922 } | |
4923 | |
4924 return; | |
17052 | 4925 } |
4926 | |
88365 | 4927 /* Return raw-text or one of its subsidiaries that has the same |
4928 eol_type as CODING-SYSTEM. */ | |
4929 | |
4930 Lisp_Object | |
4931 raw_text_coding_system (coding_system) | |
4932 Lisp_Object coding_system; | |
26847 | 4933 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4934 Lisp_Object spec, attrs; |
88365 | 4935 Lisp_Object eol_type, raw_text_eol_type; |
4936 | |
4937 spec = CODING_SYSTEM_SPEC (coding_system); | |
4938 attrs = AREF (spec, 0); | |
4939 | |
4940 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
4941 return coding_system; | |
4942 | |
4943 eol_type = AREF (spec, 2); | |
4944 if (VECTORP (eol_type)) | |
4945 return Qraw_text; | |
4946 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
4947 raw_text_eol_type = AREF (spec, 2); | |
4948 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
4949 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
4950 : AREF (raw_text_eol_type, 2)); | |
26847 | 4951 } |
4952 | |
88365 | 4953 |
4954 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
4955 does, return one of the subsidiary that has the same eol-spec as | |
4956 PARENT. Otherwise, return CODING_SYSTEM. */ | |
4957 | |
4958 Lisp_Object | |
4959 coding_inherit_eol_type (coding_system, parent) | |
88473 | 4960 Lisp_Object coding_system, parent; |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4961 { |
88365 | 4962 Lisp_Object spec, attrs, eol_type; |
4963 | |
4964 spec = CODING_SYSTEM_SPEC (coding_system); | |
4965 attrs = AREF (spec, 0); | |
4966 eol_type = AREF (spec, 2); | |
4967 if (VECTORP (eol_type)) | |
4968 { | |
4969 Lisp_Object parent_spec; | |
4970 Lisp_Object parent_eol_type; | |
4971 | |
4972 parent_spec | |
4973 = CODING_SYSTEM_SPEC (buffer_defaults.buffer_file_coding_system); | |
4974 parent_eol_type = AREF (parent_spec, 2); | |
4975 if (EQ (parent_eol_type, Qunix)) | |
4976 coding_system = AREF (eol_type, 0); | |
4977 else if (EQ (parent_eol_type, Qdos)) | |
4978 coding_system = AREF (eol_type, 1); | |
4979 else if (EQ (parent_eol_type, Qmac)) | |
4980 coding_system = AREF (eol_type, 2); | |
4981 } | |
4982 return coding_system; | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4983 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4984 |
17052 | 4985 /* Emacs has a mechanism to automatically detect a coding system if it |
4986 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
4987 it's impossible to distinguish some coding systems accurately | |
4988 because they use the same range of codes. So, at first, coding | |
4989 systems are categorized into 7, those are: | |
4990 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4991 o coding-category-emacs-mule |
17052 | 4992 |
4993 The category for a coding system which has the same code range | |
4994 as Emacs' internal format. Assigned the coding-system (Lisp | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4995 symbol) `emacs-mule' by default. |
17052 | 4996 |
4997 o coding-category-sjis | |
4998 | |
4999 The category for a coding system which has the same code range | |
5000 as SJIS. Assigned the coding-system (Lisp | |
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5001 symbol) `japanese-shift-jis' by default. |
17052 | 5002 |
5003 o coding-category-iso-7 | |
5004 | |
5005 The category for a coding system which has the same code range | |
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5006 as ISO2022 of 7-bit environment. This doesn't use any locking |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5007 shift and single shift functions. This can encode/decode all |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5008 charsets. Assigned the coding-system (Lisp symbol) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5009 `iso-2022-7bit' by default. |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5010 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5011 o coding-category-iso-7-tight |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5012 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5013 Same as coding-category-iso-7 except that this can |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5014 encode/decode only the specified charsets. |
17052 | 5015 |
5016 o coding-category-iso-8-1 | |
5017 | |
5018 The category for a coding system which has the same code range | |
5019 as ISO2022 of 8-bit environment and graphic plane 1 used only | |
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5020 for DIMENSION1 charset. This doesn't use any locking shift |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5021 and single shift functions. Assigned the coding-system (Lisp |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5022 symbol) `iso-latin-1' by default. |
17052 | 5023 |
5024 o coding-category-iso-8-2 | |
5025 | |
5026 The category for a coding system which has the same code range | |
5027 as ISO2022 of 8-bit environment and graphic plane 1 used only | |
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5028 for DIMENSION2 charset. This doesn't use any locking shift |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5029 and single shift functions. Assigned the coding-system (Lisp |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5030 symbol) `japanese-iso-8bit' by default. |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5031 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5032 o coding-category-iso-7-else |
17052 | 5033 |
5034 The category for a coding system which has the same code range | |
88365 | 5035 as ISO2022 of 7-bit environemnt but uses locking shift or |
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5036 single shift functions. Assigned the coding-system (Lisp |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5037 symbol) `iso-2022-7bit-lock' by default. |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5038 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5039 o coding-category-iso-8-else |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5040 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5041 The category for a coding system which has the same code range |
88365 | 5042 as ISO2022 of 8-bit environemnt but uses locking shift or |
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5043 single shift functions. Assigned the coding-system (Lisp |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5044 symbol) `iso-2022-8bit-ss2' by default. |
17052 | 5045 |
5046 o coding-category-big5 | |
5047 | |
5048 The category for a coding system which has the same code range | |
5049 as BIG5. Assigned the coding-system (Lisp symbol) | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
5050 `cn-big5' by default. |
17052 | 5051 |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5052 o coding-category-utf-8 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5053 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5054 The category for a coding system which has the same code range |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5055 as UTF-8 (cf. RFC2279). Assigned the coding-system (Lisp |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5056 symbol) `utf-8' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5057 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5058 o coding-category-utf-16-be |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5059 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5060 The category for a coding system in which a text has an |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5061 Unicode signature (cf. Unicode Standard) in the order of BIG |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5062 endian at the head. Assigned the coding-system (Lisp symbol) |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5063 `utf-16-be' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5064 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5065 o coding-category-utf-16-le |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5066 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5067 The category for a coding system in which a text has an |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5068 Unicode signature (cf. Unicode Standard) in the order of |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5069 LITTLE endian at the head. Assigned the coding-system (Lisp |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5070 symbol) `utf-16-le' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5071 |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5072 o coding-category-ccl |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5073 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5074 The category for a coding system of which encoder/decoder is |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5075 written in CCL programs. The default value is nil, i.e., no |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5076 coding system is assigned. |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5077 |
17052 | 5078 o coding-category-binary |
5079 | |
5080 The category for a coding system not categorized in any of the | |
5081 above. Assigned the coding-system (Lisp symbol) | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
5082 `no-conversion' by default. |
17052 | 5083 |
5084 Each of them is a Lisp symbol and the value is an actual | |
88365 | 5085 `coding-system's (this is also a Lisp symbol) assigned by a user. |
17052 | 5086 What Emacs does actually is to detect a category of coding system. |
5087 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
88365 | 5088 decide only one possible category, it selects a category of the |
17052 | 5089 highest priority. Priorities of categories are also specified by a |
5090 user in a Lisp variable `coding-category-list'. | |
5091 | |
5092 */ | |
5093 | |
88365 | 5094 #define EOL_SEEN_NONE 0 |
5095 #define EOL_SEEN_LF 1 | |
5096 #define EOL_SEEN_CR 2 | |
5097 #define EOL_SEEN_CRLF 4 | |
5098 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5099 /* Detect how end-of-line of a text of length SRC_BYTES pointed by |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5100 SOURCE is encoded. If CATEGORY is one of |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5101 coding_category_utf_16_XXXX, assume that CR and LF are encoded by |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5102 two-byte, else they are encoded by one-byte. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5103 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5104 Return one of EOL_SEEN_XXX. */ |
17052 | 5105 |
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
5106 #define MAX_EOL_CHECK_COUNT 3 |
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
5107 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5108 static int |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5109 detect_eol (source, src_bytes, category) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5110 unsigned char *source; |
88365 | 5111 EMACS_INT src_bytes; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5112 enum coding_category category; |
17052 | 5113 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5114 unsigned char *src = source, *src_end = src + src_bytes; |
17052 | 5115 unsigned char c; |
88365 | 5116 int total = 0; |
5117 int eol_seen = EOL_SEEN_NONE; | |
5118 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5119 if ((1 << category) & CATEGORY_MASK_UTF_16) |
88365 | 5120 { |
5121 int msb, lsb; | |
5122 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5123 msb = category == (coding_category_utf_16_le |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5124 | coding_category_utf_16_le_nosig); |
88365 | 5125 lsb = 1 - msb; |
5126 | |
5127 while (src + 1 < src_end) | |
17052 | 5128 { |
88365 | 5129 c = src[lsb]; |
5130 if (src[msb] == 0 && (c == '\n' || c == '\r')) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5131 { |
88365 | 5132 int this_eol; |
5133 | |
5134 if (c == '\n') | |
5135 this_eol = EOL_SEEN_LF; | |
5136 else if (src + 3 >= src_end | |
5137 || src[msb + 2] != 0 | |
5138 || src[lsb + 2] != '\n') | |
5139 this_eol = EOL_SEEN_CR; | |
5140 else | |
5141 this_eol = EOL_SEEN_CRLF; | |
5142 | |
5143 if (eol_seen == EOL_SEEN_NONE) | |
5144 /* This is the first end-of-line. */ | |
5145 eol_seen = this_eol; | |
5146 else if (eol_seen != this_eol) | |
5147 { | |
5148 /* The found type is different from what found before. */ | |
5149 eol_seen = EOL_SEEN_LF; | |
5150 break; | |
5151 } | |
5152 if (++total == MAX_EOL_CHECK_COUNT) | |
5153 break; | |
5154 } | |
5155 src += 2; | |
5156 } | |
5157 } | |
5158 else | |
5159 { | |
5160 while (src < src_end) | |
5161 { | |
5162 c = *src++; | |
5163 if (c == '\n' || c == '\r') | |
5164 { | |
5165 int this_eol; | |
5166 | |
5167 if (c == '\n') | |
5168 this_eol = EOL_SEEN_LF; | |
5169 else if (src >= src_end || *src != '\n') | |
5170 this_eol = EOL_SEEN_CR; | |
5171 else | |
5172 this_eol = EOL_SEEN_CRLF, src++; | |
5173 | |
5174 if (eol_seen == EOL_SEEN_NONE) | |
5175 /* This is the first end-of-line. */ | |
5176 eol_seen = this_eol; | |
5177 else if (eol_seen != this_eol) | |
5178 { | |
5179 /* The found type is different from what found before. */ | |
5180 eol_seen = EOL_SEEN_LF; | |
5181 break; | |
5182 } | |
5183 if (++total == MAX_EOL_CHECK_COUNT) | |
5184 break; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5185 } |
17052 | 5186 } |
5187 } | |
88365 | 5188 return eol_seen; |
17052 | 5189 } |
5190 | |
88365 | 5191 |
5192 static void | |
5193 adjust_coding_eol_type (coding, eol_seen) | |
5194 struct coding_system *coding; | |
5195 int eol_seen; | |
5196 { | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
5197 Lisp_Object eol_type; |
88365 | 5198 |
5199 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5200 if (eol_seen & EOL_SEEN_LF) | |
5201 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); | |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
5202 else if (eol_seen & EOL_SEEN_CRLF) |
88365 | 5203 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
5204 else if (eol_seen & EOL_SEEN_CR) |
88365 | 5205 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); |
5206 } | |
5207 | |
5208 /* Detect how a text specified in CODING is encoded. If a coding | |
5209 system is detected, update fields of CODING by the detected coding | |
5210 system. */ | |
5211 | |
5212 void | |
5213 detect_coding (coding) | |
5214 struct coding_system *coding; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5215 { |
88365 | 5216 unsigned char *src, *src_end; |
5217 Lisp_Object attrs, coding_type; | |
5218 | |
5219 coding->consumed = coding->consumed_char = 0; | |
5220 coding->produced = coding->produced_char = 0; | |
5221 coding_set_source (coding); | |
5222 | |
5223 src_end = coding->source + coding->src_bytes; | |
5224 | |
5225 /* If we have not yet decided the text encoding type, detect it | |
5226 now. */ | |
5227 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
5228 { | |
5229 int c, i; | |
5230 | |
5231 for (src = coding->source; src < src_end; src++) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5232 { |
88365 | 5233 c = *src; |
5234 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
5235 || c == ISO_CODE_SI | |
5236 || c == ISO_CODE_SO))) | |
5237 break; | |
5238 } | |
5239 coding->head_ascii = src - (coding->source + coding->consumed); | |
5240 | |
5241 if (coding->head_ascii < coding->src_bytes) | |
5242 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5243 struct coding_detection_info detect_info; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5244 enum coding_category category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5245 struct coding_system *this; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5246 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5247 detect_info.checked = detect_info.found = detect_info.rejected = 0; |
88365 | 5248 for (i = 0; i < coding_category_raw_text; i++) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5249 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5250 category = coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5251 this = coding_categories + category; |
88365 | 5252 if (this->id < 0) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5253 { |
88365 | 5254 /* No coding system of this category is defined. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5255 detect_info.rejected |= (1 << category); |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5256 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5257 else if (category >= coding_category_raw_text) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5258 continue; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5259 else if (detect_info.checked & (1 << category)) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5260 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5261 if (detect_info.found & (1 << category)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5262 break; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5263 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5264 else if ((*(this->detector)) (coding, &detect_info) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5265 && detect_info.found & (1 << category)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5266 break; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5267 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5268 if (i < coding_category_raw_text) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5269 setup_coding_system (CODING_ID_NAME (this->id), coding); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5270 else if (detect_info.rejected == CATEGORY_MASK_ANY) |
88365 | 5271 setup_coding_system (Qraw_text, coding); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5272 else if (detect_info.rejected) |
88365 | 5273 for (i = 0; i < coding_category_raw_text; i++) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5274 if (! (detect_info.rejected & (1 << coding_priorities[i]))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5275 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5276 this = coding_categories + coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5277 setup_coding_system (CODING_ID_NAME (this->id), coding); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5278 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5279 } |
88365 | 5280 } |
5281 } | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5282 else if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qutf_16)) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5283 { |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5284 Lisp_Object coding_systems; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5285 struct coding_detection_info detect_info; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5286 |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5287 coding_systems |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5288 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_16_bom); |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5289 detect_info.found = detect_info.rejected = 0; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5290 if (CONSP (coding_systems) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5291 && detect_coding_utf_16 (coding, &detect_info) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5292 && (detect_info.found & (CATEGORY_MASK_UTF_16_LE |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5293 | CATEGORY_MASK_UTF_16_BE))) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5294 { |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5295 if (detect_info.found & CATEGORY_MASK_UTF_16_LE) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5296 setup_coding_system (XCAR (coding_systems), coding); |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5297 else |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5298 setup_coding_system (XCDR (coding_systems), coding); |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5299 } |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5300 } |
88365 | 5301 |
5302 attrs = CODING_ID_ATTRS (coding->id); | |
5303 coding_type = CODING_ATTR_TYPE (attrs); | |
5304 | |
5305 /* If we have not yet decided the EOL type, detect it now. But, the | |
5306 detection is impossible for a CCL based coding system, in which | |
5307 case, we detct the EOL type after decoding. */ | |
5308 if (VECTORP (CODING_ID_EOL_TYPE (coding->id)) | |
5309 && ! EQ (coding_type, Qccl)) | |
5310 { | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5311 int eol_seen = detect_eol (coding->source, coding->src_bytes, |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5312 XINT (CODING_ATTR_CATEGORY (attrs))); |
88365 | 5313 |
5314 if (eol_seen != EOL_SEEN_NONE) | |
5315 adjust_coding_eol_type (coding, eol_seen); | |
5316 } | |
5317 } | |
5318 | |
5319 | |
5320 static void | |
5321 decode_eol (coding) | |
5322 struct coding_system *coding; | |
5323 { | |
5324 if (VECTORP (CODING_ID_EOL_TYPE (coding->id))) | |
5325 { | |
5326 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5327 unsigned char *pend = p + coding->produced; | |
5328 int eol_seen = EOL_SEEN_NONE; | |
5329 | |
5330 for (; p < pend; p++) | |
5331 { | |
5332 if (*p == '\n') | |
5333 eol_seen |= EOL_SEEN_LF; | |
5334 else if (*p == '\r') | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5335 { |
88365 | 5336 if (p + 1 < pend && *(p + 1) == '\n') |
5337 { | |
5338 eol_seen |= EOL_SEEN_CRLF; | |
5339 p++; | |
5340 } | |
5341 else | |
5342 eol_seen |= EOL_SEEN_CR; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5343 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5344 } |
88365 | 5345 if (eol_seen != EOL_SEEN_NONE) |
5346 adjust_coding_eol_type (coding, eol_seen); | |
5347 } | |
5348 | |
5349 if (EQ (CODING_ID_EOL_TYPE (coding->id), Qmac)) | |
5350 { | |
5351 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5352 unsigned char *pend = p + coding->produced; | |
5353 | |
5354 for (; p < pend; p++) | |
5355 if (*p == '\r') | |
5356 *p = '\n'; | |
5357 } | |
5358 else if (EQ (CODING_ID_EOL_TYPE (coding->id), Qdos)) | |
5359 { | |
5360 unsigned char *p, *pbeg, *pend; | |
5361 Lisp_Object undo_list; | |
5362 | |
5363 move_gap_both (coding->dst_pos + coding->produced_char, | |
5364 coding->dst_pos_byte + coding->produced); | |
5365 undo_list = current_buffer->undo_list; | |
5366 current_buffer->undo_list = Qt; | |
88856 | 5367 del_range_2 (coding->dst_pos, coding->dst_pos_byte, GPT, GPT_BYTE, 0); |
88365 | 5368 current_buffer->undo_list = undo_list; |
5369 pbeg = GPT_ADDR; | |
5370 pend = pbeg + coding->produced; | |
5371 | |
5372 for (p = pend - 1; p >= pbeg; p--) | |
5373 if (*p == '\r') | |
5374 { | |
5375 safe_bcopy ((char *) (p + 1), (char *) p, pend - p - 1); | |
5376 pend--; | |
5377 } | |
5378 coding->produced_char -= coding->produced - (pend - pbeg); | |
5379 coding->produced = pend - pbeg; | |
5380 insert_from_gap (coding->produced_char, coding->produced); | |
17052 | 5381 } |
5382 } | |
5383 | |
88365 | 5384 static void |
5385 translate_chars (coding, table) | |
17052 | 5386 struct coding_system *coding; |
88365 | 5387 Lisp_Object table; |
17052 | 5388 { |
88365 | 5389 int *charbuf = coding->charbuf; |
5390 int *charbuf_end = charbuf + coding->charbuf_used; | |
5391 int c; | |
5392 | |
5393 if (coding->chars_at_source) | |
5394 return; | |
5395 | |
5396 while (charbuf < charbuf_end) | |
5397 { | |
5398 c = *charbuf; | |
5399 if (c < 0) | |
5400 charbuf += c; | |
5401 else | |
5402 *charbuf++ = translate_char (table, c); | |
5403 } | |
17052 | 5404 } |
5405 | |
88365 | 5406 static int |
5407 produce_chars (coding) | |
5408 struct coding_system *coding; | |
17052 | 5409 { |
88365 | 5410 unsigned char *dst = coding->destination + coding->produced; |
5411 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5412 int produced; | |
5413 int produced_chars = 0; | |
5414 | |
5415 if (! coding->chars_at_source) | |
5416 { | |
5417 /* Characters are in coding->charbuf. */ | |
5418 int *buf = coding->charbuf; | |
5419 int *buf_end = buf + coding->charbuf_used; | |
5420 unsigned char *adjusted_dst_end; | |
5421 | |
5422 if (BUFFERP (coding->src_object) | |
5423 && EQ (coding->src_object, coding->dst_object)) | |
5424 dst_end = coding->source + coding->consumed; | |
5425 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5426 | |
5427 while (buf < buf_end) | |
5428 { | |
5429 int c = *buf++; | |
5430 | |
5431 if (dst >= adjusted_dst_end) | |
5432 { | |
5433 dst = alloc_destination (coding, | |
5434 buf_end - buf + MAX_MULTIBYTE_LENGTH, | |
5435 dst); | |
5436 dst_end = coding->destination + coding->dst_bytes; | |
5437 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5438 } | |
5439 if (c >= 0) | |
5440 { | |
5441 if (coding->dst_multibyte | |
5442 || ! CHAR_BYTE8_P (c)) | |
5443 CHAR_STRING_ADVANCE (c, dst); | |
5444 else | |
5445 *dst++ = CHAR_TO_BYTE8 (c); | |
5446 produced_chars++; | |
5447 } | |
5448 else | |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
5449 /* This is an annotation datum. */ |
88365 | 5450 buf -= c + 1; |
5451 } | |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5452 } |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5453 else |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5454 { |
88365 | 5455 unsigned char *src = coding->source; |
5456 unsigned char *src_end = src + coding->src_bytes; | |
5457 Lisp_Object eol_type; | |
5458 | |
5459 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5460 | |
5461 if (coding->src_multibyte != coding->dst_multibyte) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5462 { |
88365 | 5463 if (coding->src_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5464 { |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5465 int multibytep = 1; |
88365 | 5466 int consumed_chars; |
5467 | |
5468 while (1) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5469 { |
88365 | 5470 unsigned char *src_base = src; |
5471 int c; | |
5472 | |
5473 ONE_MORE_BYTE (c); | |
5474 if (c == '\r') | |
5475 { | |
5476 if (EQ (eol_type, Qdos)) | |
5477 { | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5478 if (src == src_end) |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5479 { |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5480 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5481 goto no_more_source; |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5482 } |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5483 if (*src == '\n') |
88365 | 5484 c = *src++; |
5485 } | |
5486 else if (EQ (eol_type, Qmac)) | |
5487 c = '\n'; | |
5488 } | |
5489 if (dst == dst_end) | |
5490 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5491 coding->consumed = src - coding->source; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5492 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5493 if (EQ (coding->src_object, coding->dst_object)) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5494 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5495 if (dst == dst_end) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5496 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5497 dst = alloc_destination (coding, src_end - src + 1, |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5498 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5499 dst_end = coding->destination + coding->dst_bytes; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5500 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5501 src = coding->source + coding->consumed; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5502 src_end = coding->source + coding->src_bytes; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5503 } |
88365 | 5504 } |
5505 *dst++ = c; | |
5506 produced_chars++; | |
5507 } | |
5508 no_more_source: | |
5509 ; | |
5510 } | |
5511 else | |
5512 while (src < src_end) | |
5513 { | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5514 int multibytep = 1; |
88365 | 5515 int c = *src++; |
5516 | |
5517 if (c == '\r') | |
5518 { | |
5519 if (EQ (eol_type, Qdos)) | |
5520 { | |
5521 if (src < src_end | |
5522 && *src == '\n') | |
5523 c = *src++; | |
5524 } | |
5525 else if (EQ (eol_type, Qmac)) | |
5526 c = '\n'; | |
5527 } | |
5528 if (dst >= dst_end - 1) | |
5529 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5530 coding->consumed = src - coding->source; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5531 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5532 if (EQ (coding->src_object, coding->dst_object)) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5533 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5534 if (dst >= dst_end - 1) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5535 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5536 dst = alloc_destination (coding, src_end - src + 2, |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5537 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5538 dst_end = coding->destination + coding->dst_bytes; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5539 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5540 src = coding->source + coding->consumed; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5541 src_end = coding->source + coding->src_bytes; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5542 } |
88365 | 5543 } |
5544 EMIT_ONE_BYTE (c); | |
5545 } | |
5546 } | |
5547 else | |
5548 { | |
5549 if (!EQ (coding->src_object, coding->dst_object)) | |
5550 { | |
5551 int require = coding->src_bytes - coding->dst_bytes; | |
5552 | |
5553 if (require > 0) | |
5554 { | |
5555 EMACS_INT offset = src - coding->source; | |
5556 | |
5557 dst = alloc_destination (coding, require, dst); | |
5558 coding_set_source (coding); | |
5559 src = coding->source + offset; | |
5560 src_end = coding->source + coding->src_bytes; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5561 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5562 } |
88365 | 5563 produced_chars = coding->src_chars; |
5564 while (src < src_end) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5565 { |
88365 | 5566 int c = *src++; |
5567 | |
5568 if (c == '\r') | |
5569 { | |
5570 if (EQ (eol_type, Qdos)) | |
5571 { | |
5572 if (src < src_end | |
5573 && *src == '\n') | |
5574 c = *src++; | |
5575 produced_chars--; | |
5576 } | |
5577 else if (EQ (eol_type, Qmac)) | |
5578 c = '\n'; | |
5579 } | |
5580 *dst++ = c; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5581 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5582 } |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5583 coding->consumed = coding->src_bytes; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5584 coding->consumed_char = coding->src_chars; |
88365 | 5585 } |
5586 | |
5587 produced = dst - (coding->destination + coding->produced); | |
5588 if (BUFFERP (coding->dst_object)) | |
5589 insert_from_gap (produced_chars, produced); | |
5590 coding->produced += produced; | |
5591 coding->produced_char += produced_chars; | |
5592 return produced_chars; | |
5593 } | |
5594 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5595 /* Compose text in CODING->object according to the annotation data at |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5596 CHARBUF. CHARBUF is an array: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5597 [ -LENGTH ANNOTATION_MASK FROM TO METHOD COMP_LEN [ COMPONENTS... ] ] |
88365 | 5598 */ |
5599 | |
5600 static INLINE void | |
5601 produce_composition (coding, charbuf) | |
5602 struct coding_system *coding; | |
5603 int *charbuf; | |
5604 { | |
5605 int len; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5606 EMACS_INT from, to; |
88365 | 5607 enum composition_method method; |
5608 Lisp_Object components; | |
5609 | |
5610 len = -charbuf[0]; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5611 from = coding->dst_pos + charbuf[2]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5612 to = coding->dst_pos + charbuf[3]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5613 method = (enum composition_method) (charbuf[4]); |
88365 | 5614 |
5615 if (method == COMPOSITION_RELATIVE) | |
5616 components = Qnil; | |
5617 else | |
5618 { | |
5619 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
5620 int i; | |
5621 | |
5622 len -= 5; | |
5623 charbuf += 5; | |
5624 for (i = 0; i < len; i++) | |
5625 args[i] = make_number (charbuf[i]); | |
5626 components = (method == COMPOSITION_WITH_ALTCHARS | |
5627 ? Fstring (len, args) : Fvector (len, args)); | |
5628 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5629 compose_text (from, to, components, Qnil, coding->dst_object); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5630 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5631 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5632 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5633 /* Put `charset' property on text in CODING->object according to |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5634 the annotation data at CHARBUF. CHARBUF is an array: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5635 [ -LENGTH ANNOTATION_MASK FROM TO CHARSET-ID ] |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5636 */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5637 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5638 static INLINE void |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5639 produce_charset (coding, charbuf) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5640 struct coding_system *coding; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5641 int *charbuf; |
88365 | 5642 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5643 EMACS_INT from = coding->dst_pos + charbuf[2]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5644 EMACS_INT to = coding->dst_pos + charbuf[3]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5645 struct charset *charset = CHARSET_FROM_ID (charbuf[4]); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5646 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5647 Fput_text_property (make_number (from), make_number (to), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5648 Qcharset, CHARSET_NAME (charset), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5649 coding->dst_object); |
88365 | 5650 } |
5651 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5652 |
88365 | 5653 #define CHARBUF_SIZE 0x4000 |
5654 | |
5655 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
5656 do { \ | |
5657 int size = CHARBUF_SIZE;; \ | |
5658 \ | |
5659 coding->charbuf = NULL; \ | |
5660 while (size > 1024) \ | |
5661 { \ | |
5662 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
5663 if (coding->charbuf) \ | |
5664 break; \ | |
5665 size >>= 1; \ | |
5666 } \ | |
5667 if (! coding->charbuf) \ | |
5668 { \ | |
5669 coding->result = CODING_RESULT_INSUFFICIENT_MEM; \ | |
5670 return coding->result; \ | |
5671 } \ | |
5672 coding->charbuf_size = size; \ | |
5673 } while (0) | |
5674 | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5675 |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5676 static void |
88365 | 5677 produce_annotation (coding) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5678 struct coding_system *coding; |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5679 { |
88365 | 5680 int *charbuf = coding->charbuf; |
5681 int *charbuf_end = charbuf + coding->charbuf_used; | |
5682 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5683 if (NILP (coding->dst_object)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5684 return; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5685 |
88365 | 5686 while (charbuf < charbuf_end) |
5687 { | |
5688 if (*charbuf >= 0) | |
5689 charbuf++; | |
5690 else | |
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
5691 { |
88365 | 5692 int len = -*charbuf; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5693 switch (charbuf[1]) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5694 { |
88365 | 5695 case CODING_ANNOTATE_COMPOSITION_MASK: |
5696 produce_composition (coding, charbuf); | |
5697 break; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5698 case CODING_ANNOTATE_CHARSET_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5699 produce_charset (coding, charbuf); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5700 break; |
88365 | 5701 default: |
5702 abort (); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5703 } |
88365 | 5704 charbuf += len; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5705 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5706 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5707 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5708 |
88365 | 5709 /* Decode the data at CODING->src_object into CODING->dst_object. |
5710 CODING->src_object is a buffer, a string, or nil. | |
5711 CODING->dst_object is a buffer. | |
5712 | |
5713 If CODING->src_object is a buffer, it must be the current buffer. | |
5714 In this case, if CODING->src_pos is positive, it is a position of | |
5715 the source text in the buffer, otherwise, the source text is in the | |
5716 gap area of the buffer, and CODING->src_pos specifies the offset of | |
5717 the text from GPT (which must be the same as PT). If this is the | |
5718 same buffer as CODING->dst_object, CODING->src_pos must be | |
5719 negative. | |
5720 | |
5721 If CODING->src_object is a string, CODING->src_pos in an index to | |
5722 that string. | |
5723 | |
5724 If CODING->src_object is nil, CODING->source must already point to | |
5725 the non-relocatable memory area. In this case, CODING->src_pos is | |
5726 an offset from CODING->source. | |
5727 | |
5728 The decoded data is inserted at the current point of the buffer | |
5729 CODING->dst_object. | |
5730 */ | |
5731 | |
5732 static int | |
5733 decode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5734 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5735 { |
88365 | 5736 Lisp_Object attrs; |
5737 | |
5738 if (BUFFERP (coding->src_object) | |
5739 && coding->src_pos > 0 | |
5740 && coding->src_pos < GPT | |
5741 && coding->src_pos + coding->src_chars > GPT) | |
5742 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
5743 | |
5744 if (BUFFERP (coding->dst_object)) | |
5745 { | |
5746 if (current_buffer != XBUFFER (coding->dst_object)) | |
5747 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5748 if (GPT != PT) | |
5749 move_gap_both (PT, PT_BYTE); | |
5750 } | |
5751 | |
5752 coding->consumed = coding->consumed_char = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5753 coding->produced = coding->produced_char = 0; |
88365 | 5754 coding->chars_at_source = 0; |
5755 coding->result = CODING_RESULT_SUCCESS; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5756 coding->errors = 0; |
88365 | 5757 |
5758 ALLOC_CONVERSION_WORK_AREA (coding); | |
5759 | |
5760 attrs = CODING_ID_ATTRS (coding->id); | |
5761 | |
5762 do | |
5763 { | |
5764 coding_set_source (coding); | |
5765 coding->annotated = 0; | |
5766 (*(coding->decoder)) (coding); | |
5767 if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | |
89207
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
5768 translate_chars (coding, CODING_ATTR_DECODE_TBL (attrs)); |
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
5769 else if (!NILP (Vstandard_translation_table_for_decode)) |
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
5770 translate_chars (coding, Vstandard_translation_table_for_decode); |
88365 | 5771 coding_set_destination (coding); |
5772 produce_chars (coding); | |
5773 if (coding->annotated) | |
5774 produce_annotation (coding); | |
5775 } | |
5776 while (coding->consumed < coding->src_bytes | |
5777 && ! coding->result); | |
5778 | |
5779 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qccl) | |
5780 && SYMBOLP (CODING_ID_EOL_TYPE (coding->id)) | |
5781 && ! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix)) | |
5782 decode_eol (coding); | |
5783 | |
5784 coding->carryover_bytes = 0; | |
5785 if (coding->consumed < coding->src_bytes) | |
5786 { | |
5787 int nbytes = coding->src_bytes - coding->consumed; | |
5788 unsigned char *src; | |
5789 | |
5790 coding_set_source (coding); | |
5791 coding_set_destination (coding); | |
5792 src = coding->source + coding->consumed; | |
5793 | |
5794 if (coding->mode & CODING_MODE_LAST_BLOCK) | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5795 { |
88365 | 5796 /* Flush out unprocessed data as binary chars. We are sure |
5797 that the number of data is less than the size of | |
5798 coding->charbuf. */ | |
5799 while (nbytes-- > 0) | |
5800 { | |
5801 int c = *src++; | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5802 |
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5803 coding->charbuf[coding->charbuf_used++] = (c & 0x80 ? - c : c); |
88365 | 5804 } |
5805 produce_chars (coding); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5806 } |
88365 | 5807 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5808 { |
88365 | 5809 /* Record unprocessed bytes in coding->carryover. We are |
5810 sure that the number of data is less than the size of | |
5811 coding->carryover. */ | |
5812 unsigned char *p = coding->carryover; | |
5813 | |
5814 coding->carryover_bytes = nbytes; | |
5815 while (nbytes-- > 0) | |
5816 *p++ = *src++; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5817 } |
88365 | 5818 coding->consumed = coding->src_bytes; |
5819 } | |
5820 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5821 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5822 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5823 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5824 |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
5825 /* Extract an annotation datum from a composition starting at POS and |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5826 ending before LIMIT of CODING->src_object (buffer or string), store |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5827 the data in BUF, set *STOP to a starting position of the next |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5828 composition (if any) or to LIMIT, and return the address of the |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5829 next element of BUF. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5830 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5831 If such an annotation is not found, set *STOP to a starting |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5832 position of a composition after POS (if any) or to LIMIT, and |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5833 return BUF. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5834 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5835 static INLINE int * |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5836 handle_composition_annotation (pos, limit, coding, buf, stop) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5837 EMACS_INT pos, limit; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5838 struct coding_system *coding; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5839 int *buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5840 EMACS_INT *stop; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5841 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5842 EMACS_INT start, end; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5843 Lisp_Object prop; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5844 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5845 if (! find_composition (pos, limit, &start, &end, &prop, coding->src_object) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5846 || end > limit) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5847 *stop = limit; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5848 else if (start > pos) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5849 *stop = start; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5850 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5851 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5852 if (start == pos) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5853 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5854 /* We found a composition. Store the corresponding |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5855 annotation data in BUF. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5856 int *head = buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5857 enum composition_method method = COMPOSITION_METHOD (prop); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5858 int nchars = COMPOSITION_LENGTH (prop); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5859 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5860 ADD_COMPOSITION_DATA (buf, 0, nchars, method); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5861 if (method != COMPOSITION_RELATIVE) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5862 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5863 Lisp_Object components; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5864 int len, i, i_byte; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5865 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5866 components = COMPOSITION_COMPONENTS (prop); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5867 if (VECTORP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5868 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5869 len = XVECTOR (components)->size; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5870 for (i = 0; i < len; i++) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5871 *buf++ = XINT (AREF (components, i)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5872 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5873 else if (STRINGP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5874 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5875 len = XSTRING (components)->size; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5876 i = i_byte = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5877 while (i < len) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5878 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5879 FETCH_STRING_CHAR_ADVANCE (*buf, components, i, i_byte); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5880 buf++; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5881 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5882 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5883 else if (INTEGERP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5884 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5885 len = 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5886 *buf++ = XINT (components); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5887 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5888 else if (CONSP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5889 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5890 for (len = 0; CONSP (components); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5891 len++, components = XCDR (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5892 *buf++ = XINT (XCAR (components)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5893 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5894 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5895 abort (); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5896 *head -= len; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5897 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5898 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5899 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5900 if (find_composition (end, limit, &start, &end, &prop, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5901 coding->src_object) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5902 && end <= limit) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5903 *stop = start; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5904 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5905 *stop = limit; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5906 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5907 return buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5908 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5909 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5910 |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
5911 /* Extract an annotation datum from a text property `charset' at POS of |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5912 CODING->src_object (buffer of string), store the data in BUF, set |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5913 *STOP to the position where the value of `charset' property changes |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5914 (limiting by LIMIT), and return the address of the next element of |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5915 BUF. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5916 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5917 If the property value is nil, set *STOP to the position where the |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5918 property value is non-nil (limiting by LIMIT), and return BUF. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5919 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5920 static INLINE int * |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5921 handle_charset_annotation (pos, limit, coding, buf, stop) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5922 EMACS_INT pos, limit; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5923 struct coding_system *coding; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5924 int *buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5925 EMACS_INT *stop; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5926 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5927 Lisp_Object val, next; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5928 int id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5929 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5930 val = Fget_text_property (make_number (pos), Qcharset, coding->src_object); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5931 if (! NILP (val) && CHARSETP (val)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5932 id = XINT (CHARSET_SYMBOL_ID (val)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5933 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5934 id = -1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5935 ADD_CHARSET_DATA (buf, 0, 0, id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5936 next = Fnext_single_property_change (make_number (pos), Qcharset, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5937 coding->src_object, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5938 make_number (limit)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5939 *stop = XINT (next); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5940 return buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5941 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5942 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5943 |
88365 | 5944 static void |
5945 consume_chars (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5946 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5947 { |
88365 | 5948 int *buf = coding->charbuf; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5949 int *buf_end = coding->charbuf + coding->charbuf_size; |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
5950 const unsigned char *src = coding->source + coding->consumed; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5951 EMACS_INT pos = coding->src_pos + coding->consumed_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5952 EMACS_INT end_pos = coding->src_pos + coding->src_chars; |
88365 | 5953 int multibytep = coding->src_multibyte; |
5954 Lisp_Object eol_type; | |
5955 int c; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5956 EMACS_INT stop, stop_composition, stop_charset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5957 int id; |
88365 | 5958 |
5959 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5960 if (VECTORP (eol_type)) | |
5961 eol_type = Qunix; | |
5962 | |
5963 /* Note: composition handling is not yet implemented. */ | |
5964 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
5965 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5966 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5967 stop = stop_composition = pos; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5968 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5969 stop = stop_composition = end_pos; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5970 if (coding->common_flags & CODING_ANNOTATE_CHARSET_MASK) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5971 stop = stop_charset = pos; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5972 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5973 stop_charset = end_pos; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5974 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5975 /* Compensate for CRLF and annotation. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5976 buf_end -= 1 + MAX_ANNOTATION_LENGTH; |
88365 | 5977 while (buf < buf_end) |
5978 { | |
5979 if (pos == stop) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5980 { |
88365 | 5981 int *p; |
5982 | |
5983 if (pos == end_pos) | |
5984 break; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5985 if (pos == stop_composition) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5986 buf = handle_composition_annotation (pos, end_pos, coding, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5987 buf, &stop_composition); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5988 if (pos == stop_charset) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5989 buf = handle_charset_annotation (pos, end_pos, coding, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5990 buf, &stop_charset); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5991 stop = (stop_composition < stop_charset |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5992 ? stop_composition : stop_charset); |
88365 | 5993 } |
5994 | |
5995 if (! multibytep) | |
5996 c = *src++; | |
5997 else | |
5998 c = STRING_CHAR_ADVANCE (src); | |
5999 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) | |
6000 c = '\n'; | |
6001 if (! EQ (eol_type, Qunix)) | |
6002 { | |
6003 if (c == '\n') | |
6004 { | |
6005 if (EQ (eol_type, Qdos)) | |
6006 *buf++ = '\r'; | |
6007 else | |
6008 c = '\r'; | |
6009 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6010 } |
88365 | 6011 *buf++ = c; |
6012 pos++; | |
6013 } | |
6014 | |
6015 coding->consumed = src - coding->source; | |
6016 coding->consumed_char = pos - coding->src_pos; | |
6017 coding->charbuf_used = buf - coding->charbuf; | |
6018 coding->chars_at_source = 0; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6019 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6020 |
88365 | 6021 |
6022 /* Encode the text at CODING->src_object into CODING->dst_object. | |
6023 CODING->src_object is a buffer or a string. | |
6024 CODING->dst_object is a buffer or nil. | |
6025 | |
6026 If CODING->src_object is a buffer, it must be the current buffer. | |
6027 In this case, if CODING->src_pos is positive, it is a position of | |
6028 the source text in the buffer, otherwise. the source text is in the | |
6029 gap area of the buffer, and coding->src_pos specifies the offset of | |
6030 the text from GPT (which must be the same as PT). If this is the | |
6031 same buffer as CODING->dst_object, CODING->src_pos must be | |
6032 negative and CODING should not have `pre-write-conversion'. | |
6033 | |
6034 If CODING->src_object is a string, CODING should not have | |
6035 `pre-write-conversion'. | |
6036 | |
6037 If CODING->dst_object is a buffer, the encoded data is inserted at | |
6038 the current point of that buffer. | |
6039 | |
6040 If CODING->dst_object is nil, the encoded data is placed at the | |
6041 memory area specified by CODING->destination. */ | |
6042 | |
6043 static int | |
6044 encode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6045 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6046 { |
88365 | 6047 Lisp_Object attrs; |
6048 | |
6049 attrs = CODING_ID_ATTRS (coding->id); | |
6050 | |
6051 if (BUFFERP (coding->dst_object)) | |
6052 { | |
6053 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6054 coding->dst_multibyte | |
6055 = ! NILP (current_buffer->enable_multibyte_characters); | |
6056 } | |
6057 | |
6058 coding->consumed = coding->consumed_char = 0; | |
6059 coding->produced = coding->produced_char = 0; | |
6060 coding->result = CODING_RESULT_SUCCESS; | |
6061 coding->errors = 0; | |
6062 | |
6063 ALLOC_CONVERSION_WORK_AREA (coding); | |
6064 | |
6065 do { | |
6066 coding_set_source (coding); | |
6067 consume_chars (coding); | |
6068 | |
6069 if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | |
89207
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
6070 translate_chars (coding, CODING_ATTR_ENCODE_TBL (attrs)); |
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
6071 else if (!NILP (Vstandard_translation_table_for_encode)) |
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
6072 translate_chars (coding, Vstandard_translation_table_for_encode); |
88365 | 6073 |
6074 coding_set_destination (coding); | |
6075 (*(coding->encoder)) (coding); | |
6076 } while (coding->consumed_char < coding->src_chars); | |
6077 | |
6078 if (BUFFERP (coding->dst_object)) | |
6079 insert_from_gap (coding->produced_char, coding->produced); | |
6080 | |
6081 return (coding->result); | |
6082 } | |
6083 | |
6084 /* Work buffer */ | |
6085 | |
6086 /* List of currently used working buffer. */ | |
6087 Lisp_Object Vcode_conversion_work_buf_list; | |
6088 | |
6089 /* A working buffer used by the top level conversion. */ | |
6090 Lisp_Object Vcode_conversion_reused_work_buf; | |
6091 | |
6092 | |
6093 /* Return a working buffer that can be freely used by the following | |
6094 code conversion. MULTIBYTEP specifies the multibyteness of the | |
6095 buffer. */ | |
6096 | |
6097 Lisp_Object | |
6098 make_conversion_work_buffer (multibytep) | |
6099 int multibytep; | |
6100 { | |
6101 struct buffer *current = current_buffer; | |
6102 Lisp_Object buf; | |
6103 | |
6104 if (NILP (Vcode_conversion_work_buf_list)) | |
6105 { | |
6106 if (NILP (Vcode_conversion_reused_work_buf)) | |
6107 Vcode_conversion_reused_work_buf | |
6108 = Fget_buffer_create (build_string (" *code-conversion-work*")); | |
6109 Vcode_conversion_work_buf_list | |
6110 = Fcons (Vcode_conversion_reused_work_buf, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6111 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6112 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6113 { |
88856 | 6114 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); |
88365 | 6115 char str[128]; |
6116 | |
6117 sprintf (str, " *code-conversion-work*<%d>", depth); | |
6118 Vcode_conversion_work_buf_list | |
6119 = Fcons (Fget_buffer_create (build_string (str)), | |
6120 Vcode_conversion_work_buf_list); | |
6121 } | |
6122 | |
6123 buf = XCAR (Vcode_conversion_work_buf_list); | |
6124 set_buffer_internal (XBUFFER (buf)); | |
6125 current_buffer->undo_list = Qt; | |
6126 Ferase_buffer (); | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
6127 Fset_buffer_multibyte (multibytep ? Qt : Qnil, Qnil); |
88365 | 6128 set_buffer_internal (current); |
6129 return buf; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6130 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6131 |
88365 | 6132 static struct coding_system *saved_coding; |
6133 | |
6134 Lisp_Object | |
6135 code_conversion_restore (info) | |
6136 Lisp_Object info; | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
6137 { |
88856 | 6138 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); |
88365 | 6139 Lisp_Object buf; |
6140 | |
6141 if (depth > 0) | |
6142 { | |
6143 buf = XCAR (Vcode_conversion_work_buf_list); | |
6144 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); | |
6145 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) | |
6146 Fkill_buffer (buf); | |
6147 } | |
6148 | |
88856 | 6149 if (EQ (saved_coding->dst_object, Qt) |
88365 | 6150 && saved_coding->destination) |
6151 xfree (saved_coding->destination); | |
6152 | |
6153 return save_excursion_restore (info); | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
6154 } |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
6155 |
88365 | 6156 |
6157 int | |
6158 decode_coding_gap (coding, chars, bytes) | |
26847 | 6159 struct coding_system *coding; |
88365 | 6160 EMACS_INT chars, bytes; |
6161 { | |
6162 int count = specpdl_ptr - specpdl; | |
6163 | |
6164 saved_coding = coding; | |
6165 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6166 | |
6167 coding->src_object = Fcurrent_buffer (); | |
6168 coding->src_chars = chars; | |
6169 coding->src_bytes = bytes; | |
6170 coding->src_pos = -chars; | |
6171 coding->src_pos_byte = -bytes; | |
6172 coding->src_multibyte = chars < bytes; | |
6173 coding->dst_object = coding->src_object; | |
6174 coding->dst_pos = PT; | |
6175 coding->dst_pos_byte = PT_BYTE; | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
6176 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
6177 coding->mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6178 |
6179 if (CODING_REQUIRE_DETECTION (coding)) | |
6180 detect_coding (coding); | |
6181 | |
6182 decode_coding (coding); | |
6183 | |
6184 unbind_to (count, Qnil); | |
6185 return coding->result; | |
6186 } | |
6187 | |
6188 int | |
6189 encode_coding_gap (coding, chars, bytes) | |
6190 struct coding_system *coding; | |
6191 EMACS_INT chars, bytes; | |
26847 | 6192 { |
88365 | 6193 int count = specpdl_ptr - specpdl; |
6194 Lisp_Object buffer; | |
6195 | |
6196 saved_coding = coding; | |
6197 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6198 | |
6199 buffer = Fcurrent_buffer (); | |
6200 coding->src_object = buffer; | |
6201 coding->src_chars = chars; | |
6202 coding->src_bytes = bytes; | |
6203 coding->src_pos = -chars; | |
6204 coding->src_pos_byte = -bytes; | |
6205 coding->src_multibyte = chars < bytes; | |
6206 coding->dst_object = coding->src_object; | |
6207 coding->dst_pos = PT; | |
6208 coding->dst_pos_byte = PT_BYTE; | |
6209 | |
6210 encode_coding (coding); | |
6211 | |
6212 unbind_to (count, Qnil); | |
6213 return coding->result; | |
26847 | 6214 } |
6215 | |
88365 | 6216 |
6217 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
6218 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
6219 | |
6220 SRC_OBJECT is a buffer, a string, or Qnil. | |
6221 | |
6222 If it is a buffer, the text is at point of the buffer. FROM and TO | |
6223 are positions in the buffer. | |
6224 | |
6225 If it is a string, the text is at the beginning of the string. | |
6226 FROM and TO are indices to the string. | |
6227 | |
6228 If it is nil, the text is at coding->source. FROM and TO are | |
6229 indices to coding->source. | |
6230 | |
6231 DST_OBJECT is a buffer, Qt, or Qnil. | |
6232 | |
6233 If it is a buffer, the decoded text is inserted at point of the | |
6234 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
6235 is deleted. | |
6236 | |
6237 If it is Qt, a string is made from the decoded text, and | |
6238 set in CODING->dst_object. | |
6239 | |
6240 If it is Qnil, the decoded text is stored at CODING->destination. | |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
6241 The caller must allocate CODING->dst_bytes bytes at |
88365 | 6242 CODING->destination by xmalloc. If the decoded text is longer than |
6243 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
6244 */ | |
26847 | 6245 |
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
6246 void |
88365 | 6247 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
6248 dst_object) | |
26847 | 6249 struct coding_system *coding; |
88365 | 6250 Lisp_Object src_object; |
6251 EMACS_INT from, from_byte, to, to_byte; | |
6252 Lisp_Object dst_object; | |
26847 | 6253 { |
88365 | 6254 int count = specpdl_ptr - specpdl; |
6255 unsigned char *destination; | |
6256 EMACS_INT dst_bytes; | |
6257 EMACS_INT chars = to - from; | |
6258 EMACS_INT bytes = to_byte - from_byte; | |
6259 Lisp_Object attrs; | |
6260 | |
6261 saved_coding = coding; | |
6262 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6263 | |
6264 if (NILP (dst_object)) | |
6265 { | |
6266 destination = coding->destination; | |
6267 dst_bytes = coding->dst_bytes; | |
6268 } | |
6269 | |
6270 coding->src_object = src_object; | |
6271 coding->src_chars = chars; | |
6272 coding->src_bytes = bytes; | |
6273 coding->src_multibyte = chars < bytes; | |
6274 | |
6275 if (STRINGP (src_object)) | |
6276 { | |
6277 coding->src_pos = from; | |
6278 coding->src_pos_byte = from_byte; | |
6279 } | |
6280 else if (BUFFERP (src_object)) | |
6281 { | |
6282 set_buffer_internal (XBUFFER (src_object)); | |
6283 if (from != GPT) | |
6284 move_gap_both (from, from_byte); | |
6285 if (EQ (src_object, dst_object)) | |
26847 | 6286 { |
88365 | 6287 TEMP_SET_PT_BOTH (from, from_byte); |
6288 del_range_both (from, from_byte, to, to_byte, 1); | |
6289 coding->src_pos = -chars; | |
6290 coding->src_pos_byte = -bytes; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
6291 } |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
6292 else |
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
6293 { |
88365 | 6294 coding->src_pos = from; |
6295 coding->src_pos_byte = from_byte; | |
29985
c17e78d8c720
(code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents:
29932
diff
changeset
|
6296 } |
88365 | 6297 } |
6298 | |
6299 if (CODING_REQUIRE_DETECTION (coding)) | |
6300 detect_coding (coding); | |
6301 attrs = CODING_ID_ATTRS (coding->id); | |
6302 | |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
6303 if (EQ (dst_object, Qt) |
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
6304 || (! NILP (CODING_ATTR_POST_READ (attrs)) |
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
6305 && NILP (dst_object))) |
88365 | 6306 { |
6307 coding->dst_object = make_conversion_work_buffer (1); | |
6308 coding->dst_pos = BEG; | |
6309 coding->dst_pos_byte = BEG_BYTE; | |
6310 coding->dst_multibyte = 1; | |
6311 } | |
6312 else if (BUFFERP (dst_object)) | |
6313 { | |
6314 coding->dst_object = dst_object; | |
6315 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
6316 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
6317 coding->dst_multibyte | |
6318 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
6319 } | |
6320 else | |
6321 { | |
6322 coding->dst_object = Qnil; | |
6323 coding->dst_multibyte = 1; | |
6324 } | |
6325 | |
6326 decode_coding (coding); | |
6327 | |
6328 if (BUFFERP (coding->dst_object)) | |
6329 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6330 | |
6331 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
6332 { | |
6333 struct gcpro gcpro1, gcpro2; | |
6334 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; | |
6335 Lisp_Object val; | |
6336 | |
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
6337 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
88365 | 6338 GCPRO2 (coding->src_object, coding->dst_object); |
6339 val = call1 (CODING_ATTR_POST_READ (attrs), | |
6340 make_number (coding->produced_char)); | |
6341 UNGCPRO; | |
6342 CHECK_NATNUM (val); | |
6343 coding->produced_char += Z - prev_Z; | |
6344 coding->produced += Z_BYTE - prev_Z_BYTE; | |
6345 } | |
6346 | |
6347 if (EQ (dst_object, Qt)) | |
6348 { | |
6349 coding->dst_object = Fbuffer_string (); | |
6350 } | |
6351 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
6352 { | |
6353 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6354 if (dst_bytes < coding->produced) | |
42105
09cc243e2d14
(code_convert_region): Update coding->cmp_data->char_offset
Richard M. Stallman <rms@gnu.org>
parents:
42104
diff
changeset
|
6355 { |
88365 | 6356 destination |
6357 = (unsigned char *) xrealloc (destination, coding->produced); | |
6358 if (! destination) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6359 { |
88365 | 6360 coding->result = CODING_RESULT_INSUFFICIENT_DST; |
6361 unbind_to (count, Qnil); | |
6362 return; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6363 } |
88365 | 6364 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
6365 move_gap_both (BEGV, BEGV_BYTE); | |
6366 bcopy (BEGV_ADDR, destination, coding->produced); | |
6367 coding->destination = destination; | |
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
6368 } |
88365 | 6369 } |
6370 | |
6371 unbind_to (count, Qnil); | |
6372 } | |
6373 | |
6374 | |
6375 void | |
6376 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, | |
6377 dst_object) | |
6378 struct coding_system *coding; | |
6379 Lisp_Object src_object; | |
6380 EMACS_INT from, from_byte, to, to_byte; | |
6381 Lisp_Object dst_object; | |
6382 { | |
6383 int count = specpdl_ptr - specpdl; | |
6384 EMACS_INT chars = to - from; | |
6385 EMACS_INT bytes = to_byte - from_byte; | |
6386 Lisp_Object attrs; | |
6387 | |
6388 saved_coding = coding; | |
6389 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6390 | |
6391 coding->src_object = src_object; | |
6392 coding->src_chars = chars; | |
6393 coding->src_bytes = bytes; | |
6394 coding->src_multibyte = chars < bytes; | |
6395 | |
6396 attrs = CODING_ID_ATTRS (coding->id); | |
6397 | |
6398 if (! NILP (CODING_ATTR_PRE_WRITE (attrs))) | |
21062
839b22ad1e42
(code_convert_region): Handle the case that codes
Kenichi Handa <handa@m17n.org>
parents:
20999
diff
changeset
|
6399 { |
88365 | 6400 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); |
6401 set_buffer_internal (XBUFFER (coding->src_object)); | |
6402 if (STRINGP (src_object)) | |
6403 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
6404 else if (BUFFERP (src_object)) | |
6405 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
6406 else | |
6407 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); | |
6408 | |
6409 if (EQ (src_object, dst_object)) | |
6410 { | |
6411 set_buffer_internal (XBUFFER (src_object)); | |
6412 del_range_both (from, from_byte, to, to_byte, 1); | |
6413 set_buffer_internal (XBUFFER (coding->src_object)); | |
6414 } | |
6415 | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6416 call2 (CODING_ATTR_PRE_WRITE (attrs), |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6417 make_number (BEG), make_number (Z)); |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6418 coding->src_object = Fcurrent_buffer (); |
88365 | 6419 if (BEG != GPT) |
6420 move_gap_both (BEG, BEG_BYTE); | |
6421 coding->src_chars = Z - BEG; | |
6422 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
6423 coding->src_pos = BEG; | |
6424 coding->src_pos_byte = BEG_BYTE; | |
6425 coding->src_multibyte = Z < Z_BYTE; | |
6426 } | |
6427 else if (STRINGP (src_object)) | |
6428 { | |
6429 coding->src_pos = from; | |
6430 coding->src_pos_byte = from_byte; | |
6431 } | |
6432 else if (BUFFERP (src_object)) | |
6433 { | |
6434 set_buffer_internal (XBUFFER (src_object)); | |
6435 if (EQ (src_object, dst_object)) | |
6436 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6437 coding->src_object = del_range_1 (from, to, 1, 1); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6438 coding->src_pos = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6439 coding->src_pos_byte = 0; |
88365 | 6440 } |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
6441 else |
88365 | 6442 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6443 if (from < GPT && to >= GPT) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6444 move_gap_both (from, from_byte); |
88365 | 6445 coding->src_pos = from; |
6446 coding->src_pos_byte = from_byte; | |
6447 } | |
6448 } | |
6449 | |
6450 if (BUFFERP (dst_object)) | |
6451 { | |
6452 coding->dst_object = dst_object; | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6453 if (EQ (src_object, dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6454 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6455 coding->dst_pos = from; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6456 coding->dst_pos_byte = from_byte; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6457 } |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6458 else |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6459 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6460 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6461 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6462 } |
88365 | 6463 coding->dst_multibyte |
6464 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
6465 } | |
6466 else if (EQ (dst_object, Qt)) | |
6467 { | |
6468 coding->dst_object = Qnil; | |
6469 coding->dst_bytes = coding->src_chars; | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6470 if (coding->dst_bytes == 0) |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6471 coding->dst_bytes = 1; |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6472 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
88365 | 6473 coding->dst_multibyte = 0; |
6474 } | |
6475 else | |
6476 { | |
6477 coding->dst_object = Qnil; | |
6478 coding->dst_multibyte = 0; | |
6479 } | |
6480 | |
6481 encode_coding (coding); | |
6482 | |
6483 if (EQ (dst_object, Qt)) | |
6484 { | |
6485 if (BUFFERP (coding->dst_object)) | |
6486 coding->dst_object = Fbuffer_string (); | |
6487 else | |
6488 { | |
6489 coding->dst_object | |
6490 = make_unibyte_string ((char *) coding->destination, | |
6491 coding->produced); | |
6492 xfree (coding->destination); | |
6493 } | |
6494 } | |
6495 | |
6496 unbind_to (count, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6497 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6498 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6499 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6500 Lisp_Object |
88365 | 6501 preferred_coding_system () |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6502 { |
88365 | 6503 int id = coding_categories[coding_priorities[0]].id; |
6504 | |
6505 return CODING_ID_NAME (id); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6506 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6507 |
17052 | 6508 |
6509 #ifdef emacs | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6510 /*** 8. Emacs Lisp library functions ***/ |
17052 | 6511 |
6512 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6513 doc: /* Return t if OBJECT is nil or a coding-system. |
88365 | 6514 See the documentation of `define-coding-system' for information |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6515 about coding-system objects. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6516 (obj) |
17052 | 6517 Lisp_Object obj; |
6518 { | |
88365 | 6519 return ((NILP (obj) || CODING_SYSTEM_P (obj)) ? Qt : Qnil); |
17052 | 6520 } |
6521 | |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6522 DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6523 Sread_non_nil_coding_system, 1, 1, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6524 doc: /* Read a coding system from the minibuffer, prompting with string PROMPT. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6525 (prompt) |
17052 | 6526 Lisp_Object prompt; |
6527 { | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6528 Lisp_Object val; |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6529 do |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6530 { |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6531 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6532 Qt, Qnil, Qcoding_system_history, Qnil, Qnil); |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6533 } |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6534 while (XSTRING (val)->size == 0); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6535 return (Fintern (val, Qnil)); |
17052 | 6536 } |
6537 | |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6538 DEFUN ("read-coding-system", Fread_coding_system, Sread_coding_system, 1, 2, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6539 doc: /* Read a coding system from the minibuffer, prompting with string PROMPT. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6540 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6541 (prompt, default_coding_system) |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6542 Lisp_Object prompt, default_coding_system; |
17052 | 6543 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
6544 Lisp_Object val; |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6545 if (SYMBOLP (default_coding_system)) |
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6546 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6547 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6548 Qt, Qnil, Qcoding_system_history, |
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6549 default_coding_system, Qnil); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6550 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
17052 | 6551 } |
6552 | |
6553 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
6554 1, 1, 0, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6555 doc: /* Check validity of CODING-SYSTEM. |
89218 | 6556 If valid, return CODING-SYSTEM, else signal a `coding-system-error' error. */) |
88365 | 6557 (coding_system) |
17052 | 6558 Lisp_Object coding_system; |
6559 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6560 CHECK_SYMBOL (coding_system); |
17052 | 6561 if (!NILP (Fcoding_system_p (coding_system))) |
6562 return coding_system; | |
6563 while (1) | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
6564 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
17052 | 6565 } |
88365 | 6566 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6567 |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6568 /* Detect how the bytes at SRC of length SRC_BYTES are encoded. If |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6569 HIGHEST is nonzero, return the coding system of the highest |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6570 priority among the detected coding systems. Otherwize return a |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6571 list of detected coding systems sorted by their priorities. If |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6572 MULTIBYTEP is nonzero, it is assumed that the bytes are in correct |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6573 multibyte form but contains only ASCII and eight-bit chars. |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6574 Otherwise, the bytes are raw bytes. |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6575 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6576 CODING-SYSTEM controls the detection as below: |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6577 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6578 If it is nil, detect both text-format and eol-format. If the |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6579 text-format part of CODING-SYSTEM is already specified |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6580 (e.g. `iso-latin-1'), detect only eol-format. If the eol-format |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6581 part of CODING-SYSTEM is already specified (e.g. `undecided-unix'), |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6582 detect only text-format. */ |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6583 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6584 Lisp_Object |
88365 | 6585 detect_coding_system (src, src_bytes, highest, multibytep, coding_system) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6586 unsigned char *src; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6587 int src_bytes, highest; |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6588 int multibytep; |
88365 | 6589 Lisp_Object coding_system; |
17052 | 6590 { |
88365 | 6591 unsigned char *src_end = src + src_bytes; |
6592 int mask = CATEGORY_MASK_ANY; | |
6593 Lisp_Object attrs, eol_type; | |
6594 Lisp_Object val; | |
6595 struct coding_system coding; | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6596 int id; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6597 struct coding_detection_info detect_info; |
88365 | 6598 |
6599 if (NILP (coding_system)) | |
6600 coding_system = Qundecided; | |
6601 setup_coding_system (coding_system, &coding); | |
6602 attrs = CODING_ID_ATTRS (coding.id); | |
6603 eol_type = CODING_ID_EOL_TYPE (coding.id); | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6604 coding_system = CODING_ATTR_BASE_NAME (attrs); |
88365 | 6605 |
6606 coding.source = src; | |
6607 coding.src_bytes = src_bytes; | |
6608 coding.src_multibyte = multibytep; | |
6609 coding.consumed = 0; | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6610 coding.mode |= CODING_MODE_LAST_BLOCK; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6611 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6612 detect_info.checked = detect_info.found = detect_info.rejected = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6613 |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6614 /* At first, detect text-format if necessary. */ |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6615 if (XINT (CODING_ATTR_CATEGORY (attrs)) == coding_category_undecided) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6616 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6617 enum coding_category category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6618 struct coding_system *this; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6619 int c, i; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6620 |
88365 | 6621 for (; src < src_end; src++) |
17052 | 6622 { |
88365 | 6623 c = *src; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6624 if (c & 0x80 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6625 || (c < 0x20 && (c == ISO_CODE_ESC |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6626 || c == ISO_CODE_SI |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
6627 || c == ISO_CODE_SO))) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6628 break; |
17052 | 6629 } |
88365 | 6630 coding.head_ascii = src - coding.source; |
6631 | |
6632 if (src < src_end) | |
6633 for (i = 0; i < coding_category_raw_text; i++) | |
6634 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6635 category = coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6636 this = coding_categories + category; |
88365 | 6637 |
6638 if (this->id < 0) | |
6639 { | |
6640 /* No coding system of this category is defined. */ | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6641 detect_info.rejected |= (1 << category); |
88365 | 6642 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6643 else if (category >= coding_category_raw_text) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6644 continue; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6645 else if (detect_info.checked & (1 << category)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6646 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6647 if (highest |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6648 && (detect_info.found & (1 << category))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6649 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6650 } |
88365 | 6651 else |
6652 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6653 if ((*(this->detector)) (&coding, &detect_info) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6654 && highest |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6655 && (detect_info.found & (1 << category))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6656 break; |
88365 | 6657 } |
6658 } | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6659 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6660 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6661 if (detect_info.rejected == CATEGORY_MASK_ANY) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6662 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6663 detect_info.found = CATEGORY_MASK_RAW_TEXT; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6664 id = coding_categories[coding_category_raw_text].id; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6665 val = Fcons (make_number (id), Qnil); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6666 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6667 else if (! detect_info.rejected && ! detect_info.found) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6668 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6669 detect_info.found = CATEGORY_MASK_ANY; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6670 id = coding_categories[coding_category_undecided].id; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6671 val = Fcons (make_number (id), Qnil); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6672 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6673 else if (highest) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6674 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6675 if (detect_info.found) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6676 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6677 detect_info.found = 1 << category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6678 val = Fcons (make_number (this->id), Qnil); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6679 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6680 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6681 for (i = 0; i < coding_category_raw_text; i++) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6682 if (! (detect_info.rejected & (1 << coding_priorities[i]))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6683 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6684 detect_info.found = 1 << coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6685 id = coding_categories[coding_priorities[i]].id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6686 val = Fcons (make_number (id), Qnil); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6687 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6688 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6689 } |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6690 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6691 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6692 int mask = detect_info.rejected | detect_info.found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6693 int found = 0; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6694 val = Qnil; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6695 |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6696 for (i = coding_category_raw_text - 1; i >= 0; i--) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6697 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6698 category = coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6699 if (! (mask & (1 << category))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6700 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6701 found |= 1 << category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6702 id = coding_categories[category].id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6703 val = Fcons (make_number (id), val); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6704 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6705 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6706 for (i = coding_category_raw_text - 1; i >= 0; i--) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6707 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6708 category = coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6709 if (detect_info.found & (1 << category)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6710 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6711 id = coding_categories[category].id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6712 val = Fcons (make_number (id), val); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6713 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6714 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6715 detect_info.found |= found; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6716 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6717 } |
88365 | 6718 else |
6719 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6720 detect_info.found = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6721 val = Fcons (make_number (coding.id), Qnil); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6722 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6723 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6724 /* Then, detect eol-format if necessary. */ |
88365 | 6725 { |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6726 int normal_eol = -1, utf_16_be_eol = -1, utf_16_le_eol; |
88365 | 6727 Lisp_Object tail; |
6728 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6729 if (VECTORP (eol_type)) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6730 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6731 if (detect_info.found & ~CATEGORY_MASK_UTF_16) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6732 normal_eol = detect_eol (coding.source, src_bytes, |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6733 coding_category_raw_text); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6734 if (detect_info.found & (CATEGORY_MASK_UTF_16_BE |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6735 | CATEGORY_MASK_UTF_16_BE_NOSIG)) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6736 utf_16_be_eol = detect_eol (coding.source, src_bytes, |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6737 coding_category_utf_16_be); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6738 if (detect_info.found & (CATEGORY_MASK_UTF_16_LE |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6739 | CATEGORY_MASK_UTF_16_LE_NOSIG)) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6740 utf_16_le_eol = detect_eol (coding.source, src_bytes, |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6741 coding_category_utf_16_le); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6742 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6743 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6744 { |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6745 if (EQ (eol_type, Qunix)) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6746 normal_eol = utf_16_be_eol = utf_16_le_eol = EOL_SEEN_LF; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6747 else if (EQ (eol_type, Qdos)) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6748 normal_eol = utf_16_be_eol = utf_16_le_eol = EOL_SEEN_CRLF; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6749 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6750 normal_eol = utf_16_be_eol = utf_16_le_eol = EOL_SEEN_CR; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6751 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6752 |
88365 | 6753 for (tail = val; CONSP (tail); tail = XCDR (tail)) |
6754 { | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6755 enum coding_category category; |
88365 | 6756 int this_eol; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6757 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6758 id = XINT (XCAR (tail)); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6759 attrs = CODING_ID_ATTRS (id); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6760 category = XINT (CODING_ATTR_CATEGORY (attrs)); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6761 eol_type = CODING_ID_EOL_TYPE (id); |
88365 | 6762 if (VECTORP (eol_type)) |
6763 { | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6764 if (category == coding_category_utf_16_be |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6765 || category == coding_category_utf_16_be_nosig) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6766 this_eol = utf_16_be_eol; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6767 else if (category == coding_category_utf_16_le |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6768 || category == coding_category_utf_16_le_nosig) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6769 this_eol = utf_16_le_eol; |
88365 | 6770 else |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6771 this_eol = normal_eol; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6772 |
88365 | 6773 if (this_eol == EOL_SEEN_LF) |
6774 XSETCAR (tail, AREF (eol_type, 0)); | |
6775 else if (this_eol == EOL_SEEN_CRLF) | |
6776 XSETCAR (tail, AREF (eol_type, 1)); | |
6777 else if (this_eol == EOL_SEEN_CR) | |
6778 XSETCAR (tail, AREF (eol_type, 2)); | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6779 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6780 XSETCAR (tail, CODING_ID_NAME (id)); |
88365 | 6781 } |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6782 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6783 XSETCAR (tail, CODING_ID_NAME (id)); |
88365 | 6784 } |
6785 } | |
6786 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
6787 return (highest ? XCAR (val) : val); |
42104
d69c2368e549
(DECODE_COMPOSITION_END): Fixed a typo in the last
Sam Steingold <sds@gnu.org>
parents:
42103
diff
changeset
|
6788 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6789 |
88365 | 6790 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6791 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6792 2, 3, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6793 doc: /* Detect coding system of the text in the region between START and END. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6794 Return a list of possible coding systems ordered by priority. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6795 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6796 If only ASCII characters are found, it returns a list of single element |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6797 `undecided' or its subsidiary coding system according to a detected |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6798 end-of-line format. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6799 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6800 If optional argument HIGHEST is non-nil, return the coding system of |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6801 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6802 (start, end, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6803 Lisp_Object start, end, highest; |
17052 | 6804 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6805 int from, to; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6806 int from_byte, to_byte; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6807 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6808 CHECK_NUMBER_COERCE_MARKER (start); |
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6809 CHECK_NUMBER_COERCE_MARKER (end); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6810 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6811 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6812 from = XINT (start), to = XINT (end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6813 from_byte = CHAR_TO_BYTE (from); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6814 to_byte = CHAR_TO_BYTE (to); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6815 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6816 if (from < GPT && to >= GPT) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6817 move_gap_both (to, to_byte); |
88365 | 6818 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6819 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
88365 | 6820 to_byte - from_byte, |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6821 !NILP (highest), |
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6822 !NILP (current_buffer |
88365 | 6823 ->enable_multibyte_characters), |
6824 Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6825 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6826 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6827 DEFUN ("detect-coding-string", Fdetect_coding_string, Sdetect_coding_string, |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6828 1, 2, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6829 doc: /* Detect coding system of the text in STRING. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6830 Return a list of possible coding systems ordered by priority. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6831 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6832 If only ASCII characters are found, it returns a list of single element |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6833 `undecided' or its subsidiary coding system according to a detected |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6834 end-of-line format. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6835 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6836 If optional argument HIGHEST is non-nil, return the coding system of |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6837 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6838 (string, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6839 Lisp_Object string, highest; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6840 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6841 CHECK_STRING (string); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6842 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6843 return detect_coding_system (XSTRING (string)->data, |
88365 | 6844 STRING_BYTES (XSTRING (string)), |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6845 !NILP (highest), |
88365 | 6846 STRING_MULTIBYTE (string), |
6847 Qnil); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6848 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6849 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6850 |
88365 | 6851 static INLINE int |
6852 char_encodable_p (c, attrs) | |
6853 int c; | |
6854 Lisp_Object attrs; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6855 { |
88365 | 6856 Lisp_Object tail; |
6857 struct charset *charset; | |
6858 | |
6859 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | |
6860 CONSP (tail); tail = XCDR (tail)) | |
6861 { | |
6862 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
6863 if (CHAR_CHARSET_P (c, charset)) | |
6864 break; | |
6865 } | |
6866 return (! NILP (tail)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6867 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6868 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6869 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6870 /* Return a list of coding systems that safely encode the text between |
88365 | 6871 START and END. If EXCLUDE is non-nil, it is a list of coding |
6872 systems not to check. The returned list doesn't contain any such | |
88889
4548f224c603
(Ffind_coding_systems_region_internal): Detect an
Kenichi Handa <handa@m17n.org>
parents:
88876
diff
changeset
|
6873 coding systems. In any case, if the text contains only ASCII or is |
88365 | 6874 unibyte, return t. */ |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6875 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6876 DEFUN ("find-coding-systems-region-internal", |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6877 Ffind_coding_systems_region_internal, |
88365 | 6878 Sfind_coding_systems_region_internal, 2, 3, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6879 doc: /* Internal use only. */) |
88365 | 6880 (start, end, exclude) |
6881 Lisp_Object start, end, exclude; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6882 { |
88365 | 6883 Lisp_Object coding_attrs_list, safe_codings; |
6884 EMACS_INT start_byte, end_byte; | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
6885 const unsigned char *p, *pbeg, *pend; |
88365 | 6886 int c; |
6887 Lisp_Object tail, elt; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6888 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6889 if (STRINGP (start)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6890 { |
88365 | 6891 if (!STRING_MULTIBYTE (start) |
88889
4548f224c603
(Ffind_coding_systems_region_internal): Detect an
Kenichi Handa <handa@m17n.org>
parents:
88876
diff
changeset
|
6892 || XSTRING (start)->size == STRING_BYTES (XSTRING (start))) |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6893 return Qt; |
88365 | 6894 start_byte = 0; |
6895 end_byte = STRING_BYTES (XSTRING (start)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6896 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6897 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6898 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6899 CHECK_NUMBER_COERCE_MARKER (start); |
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6900 CHECK_NUMBER_COERCE_MARKER (end); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6901 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6902 args_out_of_range (start, end); |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6903 if (NILP (current_buffer->enable_multibyte_characters)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6904 return Qt; |
88365 | 6905 start_byte = CHAR_TO_BYTE (XINT (start)); |
6906 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6907 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6908 return Qt; | |
6909 | |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
6910 if (XINT (start) < GPT && XINT (end) > GPT) |
88365 | 6911 { |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
6912 if ((GPT - XINT (start)) < (XINT (end) - GPT)) |
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
6913 move_gap_both (XINT (start), start_byte); |
88365 | 6914 else |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
6915 move_gap_both (XINT (end), end_byte); |
88365 | 6916 } |
6917 } | |
6918 | |
6919 coding_attrs_list = Qnil; | |
6920 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6921 if (NILP (exclude) | |
6922 || NILP (Fmemq (XCAR (tail), exclude))) | |
6923 { | |
6924 Lisp_Object attrs; | |
6925 | |
6926 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
6927 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
6928 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
6929 coding_attrs_list = Fcons (attrs, coding_attrs_list); | |
6930 } | |
6931 | |
6932 if (STRINGP (start)) | |
6933 p = pbeg = XSTRING (start)->data; | |
6934 else | |
6935 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6936 pend = p + (end_byte - start_byte); | |
6937 | |
6938 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
6939 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6940 | |
6941 while (p < pend) | |
6942 { | |
6943 if (ASCII_BYTE_P (*p)) | |
6944 p++; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6945 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6946 { |
88365 | 6947 c = STRING_CHAR_ADVANCE (p); |
6948 | |
6949 charset_map_loaded = 0; | |
6950 for (tail = coding_attrs_list; CONSP (tail);) | |
6951 { | |
6952 elt = XCAR (tail); | |
6953 if (NILP (elt)) | |
6954 tail = XCDR (tail); | |
6955 else if (char_encodable_p (c, elt)) | |
6956 tail = XCDR (tail); | |
6957 else if (CONSP (XCDR (tail))) | |
6958 { | |
6959 XSETCAR (tail, XCAR (XCDR (tail))); | |
6960 XSETCDR (tail, XCDR (XCDR (tail))); | |
6961 } | |
6962 else | |
6963 { | |
6964 XSETCAR (tail, Qnil); | |
6965 tail = XCDR (tail); | |
6966 } | |
6967 } | |
6968 if (charset_map_loaded) | |
6969 { | |
6970 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6971 | |
6972 if (STRINGP (start)) | |
6973 pbeg = XSTRING (start)->data; | |
6974 else | |
6975 pbeg = BYTE_POS_ADDR (start_byte); | |
6976 p = pbeg + p_offset; | |
6977 pend = pbeg + pend_offset; | |
6978 } | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6979 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6980 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6981 |
88365 | 6982 safe_codings = Qnil; |
6983 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) | |
6984 if (! NILP (XCAR (tail))) | |
6985 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
6986 | |
6987 return safe_codings; | |
6988 } | |
6989 | |
6990 | |
6991 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, | |
6992 Scheck_coding_systems_region, 3, 3, 0, | |
6993 doc: /* Check if the region is encodable by coding systems. | |
6994 | |
6995 START and END are buffer positions specifying the region. | |
6996 CODING-SYSTEM-LIST is a list of coding systems to check. | |
6997 | |
6998 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
6999 CODING-SYSTEM is a member of CODING-SYSTEM-LIst and can't encode the | |
7000 whole region, POS0, POS1, ... are buffer positions where non-encodable | |
7001 characters are found. | |
7002 | |
7003 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
7004 value is nil. | |
7005 | |
7006 START may be a string. In that case, check if the string is | |
7007 encodable, and the value contains indices to the string instead of | |
7008 buffer positions. END is ignored. */) | |
7009 (start, end, coding_system_list) | |
7010 Lisp_Object start, end, coding_system_list; | |
7011 { | |
7012 Lisp_Object list; | |
7013 EMACS_INT start_byte, end_byte; | |
7014 int pos; | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7015 const unsigned char *p, *pbeg, *pend; |
88365 | 7016 int c; |
7017 Lisp_Object tail, elt; | |
7018 | |
7019 if (STRINGP (start)) | |
7020 { | |
7021 if (!STRING_MULTIBYTE (start) | |
7022 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
7023 return Qnil; | |
7024 start_byte = 0; | |
7025 end_byte = STRING_BYTES (XSTRING (start)); | |
7026 pos = 0; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7027 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7028 else |
88365 | 7029 { |
7030 CHECK_NUMBER_COERCE_MARKER (start); | |
7031 CHECK_NUMBER_COERCE_MARKER (end); | |
7032 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
7033 args_out_of_range (start, end); | |
7034 if (NILP (current_buffer->enable_multibyte_characters)) | |
7035 return Qnil; | |
7036 start_byte = CHAR_TO_BYTE (XINT (start)); | |
7037 end_byte = CHAR_TO_BYTE (XINT (end)); | |
7038 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
7039 return Qt; | |
7040 | |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7041 if (XINT (start) < GPT && XINT (end) > GPT) |
88365 | 7042 { |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7043 if ((GPT - XINT (start)) < (XINT (end) - GPT)) |
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7044 move_gap_both (XINT (start), start_byte); |
88365 | 7045 else |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7046 move_gap_both (XINT (end), end_byte); |
88365 | 7047 } |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7048 pos = XINT (start); |
88365 | 7049 } |
7050 | |
7051 list = Qnil; | |
7052 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
7053 { | |
7054 elt = XCAR (tail); | |
7055 list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | |
7056 Qnil)), | |
7057 list); | |
7058 } | |
7059 | |
7060 if (STRINGP (start)) | |
7061 p = pbeg = XSTRING (start)->data; | |
7062 else | |
7063 p = pbeg = BYTE_POS_ADDR (start_byte); | |
7064 pend = p + (end_byte - start_byte); | |
7065 | |
7066 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
7067 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
7068 | |
7069 while (p < pend) | |
7070 { | |
7071 if (ASCII_BYTE_P (*p)) | |
7072 p++; | |
7073 else | |
7074 { | |
7075 c = STRING_CHAR_ADVANCE (p); | |
7076 | |
7077 charset_map_loaded = 0; | |
7078 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
7079 { | |
7080 elt = XCDR (XCAR (tail)); | |
7081 if (! char_encodable_p (c, XCAR (elt))) | |
7082 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
7083 } | |
7084 if (charset_map_loaded) | |
7085 { | |
7086 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
7087 | |
7088 if (STRINGP (start)) | |
7089 pbeg = XSTRING (start)->data; | |
7090 else | |
7091 pbeg = BYTE_POS_ADDR (start_byte); | |
7092 p = pbeg + p_offset; | |
7093 pend = pbeg + pend_offset; | |
7094 } | |
7095 } | |
7096 pos++; | |
7097 } | |
7098 | |
7099 tail = list; | |
7100 list = Qnil; | |
7101 for (; CONSP (tail); tail = XCDR (tail)) | |
7102 { | |
7103 elt = XCAR (tail); | |
7104 if (CONSP (XCDR (XCDR (elt)))) | |
7105 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
7106 list); | |
7107 } | |
7108 | |
7109 return list; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7110 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7111 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7112 |
88365 | 7113 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7114 Lisp_Object |
88365 | 7115 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
7116 Lisp_Object start, end, coding_system, dst_object; | |
7117 int encodep, norecord; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7118 { |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7119 struct coding_system coding; |
88365 | 7120 EMACS_INT from, from_byte, to, to_byte; |
7121 Lisp_Object src_object; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7122 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7123 CHECK_NUMBER_COERCE_MARKER (start); |
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7124 CHECK_NUMBER_COERCE_MARKER (end); |
88365 | 7125 if (NILP (coding_system)) |
7126 coding_system = Qno_conversion; | |
7127 else | |
7128 CHECK_CODING_SYSTEM (coding_system); | |
7129 src_object = Fcurrent_buffer (); | |
7130 if (NILP (dst_object)) | |
7131 dst_object = src_object; | |
7132 else if (! EQ (dst_object, Qt)) | |
7133 CHECK_BUFFER (dst_object); | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7134 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7135 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7136 from = XFASTINT (start); |
88365 | 7137 from_byte = CHAR_TO_BYTE (from); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7138 to = XFASTINT (end); |
88365 | 7139 to_byte = CHAR_TO_BYTE (to); |
7140 | |
7141 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7142 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 7143 |
7144 if (encodep) | |
7145 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
7146 dst_object); | |
7147 else | |
7148 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
7149 dst_object); | |
7150 if (! norecord) | |
7151 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
7152 | |
7153 if (coding.result != CODING_RESULT_SUCCESS) | |
7154 error ("Code conversion error: %d", coding.result); | |
7155 | |
7156 return (BUFFERP (dst_object) | |
7157 ? make_number (coding.produced_char) | |
7158 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7159 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7160 |
88365 | 7161 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7162 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
88365 | 7163 3, 4, "r\nzCoding system: ", |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7164 doc: /* Decode the current region from the specified coding system. |
88365 | 7165 When called from a program, takes four arguments: |
7166 START, END, CODING-SYSTEM, and DESTINATION. | |
7167 START and END are buffer positions. | |
7168 | |
7169 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
7170 If nil, the region between START and END is replace by the decoded text. | |
7171 If buffer, the decoded text is inserted in the buffer. | |
7172 If t, the decoded text is returned. | |
7173 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7174 This function sets `last-coding-system-used' to the precise coding system |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7175 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7176 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7177 It returns the length of the decoded text. */) |
88365 | 7178 (start, end, coding_system, destination) |
7179 Lisp_Object start, end, coding_system, destination; | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7180 { |
88365 | 7181 return code_convert_region (start, end, coding_system, destination, 0, 0); |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7182 } |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7183 |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7184 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
88365 | 7185 3, 4, "r\nzCoding system: ", |
7186 doc: /* Encode the current region by specified coding system. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7187 When called from a program, takes three arguments: |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7188 START, END, and CODING-SYSTEM. START and END are buffer positions. |
88365 | 7189 |
7190 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
7191 If nil, the region between START and END is replace by the encoded text. | |
7192 If buffer, the encoded text is inserted in the buffer. | |
7193 If t, the encoded text is returned. | |
7194 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7195 This function sets `last-coding-system-used' to the precise coding system |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7196 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7197 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7198 It returns the length of the encoded text. */) |
88365 | 7199 (start, end, coding_system, destination) |
7200 Lisp_Object start, end, coding_system, destination; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7201 { |
88365 | 7202 return code_convert_region (start, end, coding_system, destination, 1, 0); |
17052 | 7203 } |
7204 | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7205 Lisp_Object |
88365 | 7206 code_convert_string (string, coding_system, dst_object, |
7207 encodep, nocopy, norecord) | |
7208 Lisp_Object string, coding_system, dst_object; | |
7209 int encodep, nocopy, norecord; | |
17052 | 7210 { |
7211 struct coding_system coding; | |
88365 | 7212 EMACS_INT chars, bytes; |
17052 | 7213 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7214 CHECK_STRING (string); |
88365 | 7215 if (NILP (coding_system)) |
7216 { | |
7217 if (! norecord) | |
7218 Vlast_coding_system_used = Qno_conversion; | |
7219 if (NILP (dst_object)) | |
7220 return (nocopy ? Fcopy_sequence (string) : string); | |
7221 } | |
17052 | 7222 |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7223 if (NILP (coding_system)) |
88365 | 7224 coding_system = Qno_conversion; |
7225 else | |
7226 CHECK_CODING_SYSTEM (coding_system); | |
7227 if (NILP (dst_object)) | |
7228 dst_object = Qt; | |
7229 else if (! EQ (dst_object, Qt)) | |
7230 CHECK_BUFFER (dst_object); | |
7231 | |
7232 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7233 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 7234 chars = XSTRING (string)->size; |
7235 bytes = STRING_BYTES (XSTRING (string)); | |
7236 if (encodep) | |
7237 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
7238 else | |
7239 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
7240 if (! norecord) | |
7241 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
7242 | |
7243 if (coding.result != CODING_RESULT_SUCCESS) | |
7244 error ("Code conversion error: %d", coding.result); | |
7245 | |
7246 return (BUFFERP (dst_object) | |
7247 ? make_number (coding.produced_char) | |
7248 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7249 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7250 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7251 |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7252 /* Encode or decode STRING according to CODING_SYSTEM. |
26847 | 7253 Do not set Vlast_coding_system_used. |
7254 | |
7255 This function is called only from macros DECODE_FILE and | |
7256 ENCODE_FILE, thus we ignore character composition. */ | |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7257 |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7258 Lisp_Object |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7259 code_convert_string_norecord (string, coding_system, encodep) |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7260 Lisp_Object string, coding_system; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7261 int encodep; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7262 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7263 return code_convert_string (string, coding_system, Qt, encodep, 0, 1); |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7264 } |
88365 | 7265 |
7266 | |
7267 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
7268 2, 4, 0, | |
7269 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
7270 | |
7271 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
7272 if the decoding operation is trivial. | |
7273 | |
7274 Optional fourth arg BUFFER non-nil meant that the decoded text is | |
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
7275 inserted in BUFFER instead of returned as a string. In this case, |
88365 | 7276 the return value is BUFFER. |
7277 | |
7278 This function sets `last-coding-system-used' to the precise coding system | |
7279 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
7280 not fully specified. */) | |
7281 (string, coding_system, nocopy, buffer) | |
7282 Lisp_Object string, coding_system, nocopy, buffer; | |
7283 { | |
7284 return code_convert_string (string, coding_system, buffer, | |
7285 0, ! NILP (nocopy), 0); | |
7286 } | |
7287 | |
7288 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
7289 2, 4, 0, | |
7290 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
7291 | |
7292 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
7293 itself if the encoding operation is trivial. | |
7294 | |
7295 Optional fourth arg BUFFER non-nil meant that the encoded text is | |
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
7296 inserted in BUFFER instead of returned as a string. In this case, |
88365 | 7297 the return value is BUFFER. |
7298 | |
7299 This function sets `last-coding-system-used' to the precise coding system | |
7300 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
7301 not fully specified.) */) | |
7302 (string, coding_system, nocopy, buffer) | |
7303 Lisp_Object string, coding_system, nocopy, buffer; | |
7304 { | |
7305 return code_convert_string (string, coding_system, buffer, | |
88856 | 7306 1, ! NILP (nocopy), 1); |
88365 | 7307 } |
7308 | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7309 |
17052 | 7310 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7311 doc: /* Decode a Japanese character which has CODE in shift_jis encoding. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7312 Return the corresponding character. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7313 (code) |
17052 | 7314 Lisp_Object code; |
7315 { | |
88365 | 7316 Lisp_Object spec, attrs, val; |
7317 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
7318 int c; | |
7319 | |
7320 CHECK_NATNUM (code); | |
7321 c = XFASTINT (code); | |
7322 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
7323 attrs = AREF (spec, 0); | |
7324 | |
7325 if (ASCII_BYTE_P (c) | |
7326 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
7327 return code; | |
7328 | |
7329 val = CODING_ATTR_CHARSET_LIST (attrs); | |
7330 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
7331 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
7332 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 7333 |
7334 if (c <= 0x7F) | |
7335 charset = charset_roman; | |
7336 else if (c >= 0xA0 && c < 0xDF) | |
7337 { | |
7338 charset = charset_kana; | |
7339 c -= 0x80; | |
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
7340 } |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
7341 else |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
7342 { |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
7343 int s1 = c >> 8, s2 = c & 0xFF; |
88365 | 7344 |
7345 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
7346 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
7347 error ("Invalid code: %d", code); | |
7348 SJIS_TO_JIS (c); | |
7349 charset = charset_kanji; | |
7350 } | |
7351 c = DECODE_CHAR (charset, c); | |
7352 if (c < 0) | |
7353 error ("Invalid code: %d", code); | |
7354 return make_number (c); | |
17052 | 7355 } |
7356 | |
88365 | 7357 |
17052 | 7358 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7359 doc: /* Encode a Japanese character CHAR to shift_jis encoding. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7360 Return the corresponding code in SJIS. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7361 (ch) |
88365 | 7362 Lisp_Object ch; |
17052 | 7363 { |
88365 | 7364 Lisp_Object spec, attrs, charset_list; |
7365 int c; | |
7366 struct charset *charset; | |
7367 unsigned code; | |
7368 | |
7369 CHECK_CHARACTER (ch); | |
7370 c = XFASTINT (ch); | |
7371 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
7372 attrs = AREF (spec, 0); | |
7373 | |
7374 if (ASCII_CHAR_P (c) | |
7375 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
7376 return ch; | |
7377 | |
7378 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
7379 charset = char_charset (c, charset_list, &code); | |
7380 if (code == CHARSET_INVALID_CODE (charset)) | |
7381 error ("Can't encode by shift_jis encoding: %d", c); | |
7382 JIS_TO_SJIS (code); | |
7383 | |
7384 return make_number (code); | |
17052 | 7385 } |
7386 | |
7387 DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7388 doc: /* Decode a Big5 character which has CODE in BIG5 coding system. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7389 Return the corresponding character. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7390 (code) |
17052 | 7391 Lisp_Object code; |
7392 { | |
88365 | 7393 Lisp_Object spec, attrs, val; |
7394 struct charset *charset_roman, *charset_big5, *charset; | |
7395 int c; | |
7396 | |
7397 CHECK_NATNUM (code); | |
7398 c = XFASTINT (code); | |
7399 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
7400 attrs = AREF (spec, 0); | |
7401 | |
7402 if (ASCII_BYTE_P (c) | |
7403 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
7404 return code; | |
7405 | |
7406 val = CODING_ATTR_CHARSET_LIST (attrs); | |
7407 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
7408 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
7409 | |
7410 if (c <= 0x7F) | |
7411 charset = charset_roman; | |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
7412 else |
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
7413 { |
88365 | 7414 int b1 = c >> 8, b2 = c & 0x7F; |
7415 if (b1 < 0xA1 || b1 > 0xFE | |
7416 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
7417 error ("Invalid code: %d", code); | |
7418 charset = charset_big5; | |
7419 } | |
7420 c = DECODE_CHAR (charset, (unsigned )c); | |
7421 if (c < 0) | |
7422 error ("Invalid code: %d", code); | |
7423 return make_number (c); | |
17052 | 7424 } |
7425 | |
7426 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7427 doc: /* Encode the Big5 character CHAR to BIG5 coding system. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7428 Return the corresponding character code in Big5. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7429 (ch) |
17052 | 7430 Lisp_Object ch; |
7431 { | |
88365 | 7432 Lisp_Object spec, attrs, charset_list; |
7433 struct charset *charset; | |
7434 int c; | |
7435 unsigned code; | |
7436 | |
7437 CHECK_CHARACTER (ch); | |
7438 c = XFASTINT (ch); | |
7439 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
7440 attrs = AREF (spec, 0); | |
7441 if (ASCII_CHAR_P (c) | |
7442 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
7443 return ch; | |
7444 | |
7445 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
7446 charset = char_charset (c, charset_list, &code); | |
7447 if (code == CHARSET_INVALID_CODE (charset)) | |
7448 error ("Can't encode by Big5 encoding: %d", c); | |
7449 | |
7450 return make_number (code); | |
17052 | 7451 } |
88365 | 7452 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7453 |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7454 DEFUN ("set-terminal-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7455 Fset_terminal_coding_system_internal, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7456 Sset_terminal_coding_system_internal, 1, 1, 0, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7457 doc: /* Internal use only. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7458 (coding_system) |
88473 | 7459 Lisp_Object coding_system; |
17052 | 7460 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7461 CHECK_SYMBOL (coding_system); |
88365 | 7462 setup_coding_system (Fcheck_coding_system (coding_system), |
7463 &terminal_coding); | |
7464 | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
7465 /* We had better not send unsafe characters to terminal. */ |
88365 | 7466 terminal_coding.mode |= CODING_MODE_SAFE_ENCODING; |
7467 /* Characer composition should be disabled. */ | |
7468 terminal_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7469 terminal_coding.src_multibyte = 1; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7470 terminal_coding.dst_multibyte = 0; |
17052 | 7471 return Qnil; |
7472 } | |
7473 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7474 DEFUN ("set-safe-terminal-coding-system-internal", |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7475 Fset_safe_terminal_coding_system_internal, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7476 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
41006 | 7477 doc: /* Internal use only. */) |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7478 (coding_system) |
88473 | 7479 Lisp_Object coding_system; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7480 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7481 CHECK_SYMBOL (coding_system); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7482 setup_coding_system (Fcheck_coding_system (coding_system), |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7483 &safe_terminal_coding); |
88365 | 7484 /* Characer composition should be disabled. */ |
7485 safe_terminal_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7486 safe_terminal_coding.src_multibyte = 1; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7487 safe_terminal_coding.dst_multibyte = 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7488 return Qnil; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7489 } |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7490 |
17052 | 7491 DEFUN ("terminal-coding-system", |
7492 Fterminal_coding_system, Sterminal_coding_system, 0, 0, 0, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7493 doc: /* Return coding system specified for terminal output. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7494 () |
17052 | 7495 { |
88365 | 7496 return CODING_ID_NAME (terminal_coding.id); |
17052 | 7497 } |
7498 | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7499 DEFUN ("set-keyboard-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7500 Fset_keyboard_coding_system_internal, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7501 Sset_keyboard_coding_system_internal, 1, 1, 0, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7502 doc: /* Internal use only. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7503 (coding_system) |
17052 | 7504 Lisp_Object coding_system; |
7505 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7506 CHECK_SYMBOL (coding_system); |
88365 | 7507 setup_coding_system (Fcheck_coding_system (coding_system), |
7508 &keyboard_coding); | |
7509 /* Characer composition should be disabled. */ | |
7510 keyboard_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
17052 | 7511 return Qnil; |
7512 } | |
7513 | |
7514 DEFUN ("keyboard-coding-system", | |
7515 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 0, 0, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7516 doc: /* Return coding system specified for decoding keyboard input. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7517 () |
17052 | 7518 { |
88365 | 7519 return CODING_ID_NAME (keyboard_coding.id); |
17052 | 7520 } |
7521 | |
7522 | |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7523 DEFUN ("find-operation-coding-system", Ffind_operation_coding_system, |
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7524 Sfind_operation_coding_system, 1, MANY, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7525 doc: /* Choose a coding system for an operation based on the target name. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7526 The value names a pair of coding systems: (DECODING-SYSTEM . ENCODING-SYSTEM). |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7527 DECODING-SYSTEM is the coding system to use for decoding |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7528 \(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7529 for encoding (in case OPERATION does encoding). |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7530 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7531 The first argument OPERATION specifies an I/O primitive: |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7532 For file I/O, `insert-file-contents' or `write-region'. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7533 For process I/O, `call-process', `call-process-region', or `start-process'. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7534 For network I/O, `open-network-stream'. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7535 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7536 The remaining arguments should be the same arguments that were passed |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7537 to the primitive. Depending on which primitive, one of those arguments |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7538 is selected as the TARGET. For example, if OPERATION does file I/O, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7539 whichever argument specifies the file name is TARGET. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7540 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7541 TARGET has a meaning which depends on OPERATION: |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7542 For file I/O, TARGET is a file name. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7543 For process I/O, TARGET is a process name. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7544 For network I/O, TARGET is a service name or a port number |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7545 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7546 This function looks up what specified for TARGET in, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7547 `file-coding-system-alist', `process-coding-system-alist', |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7548 or `network-coding-system-alist' depending on OPERATION. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7549 They may specify a coding system, a cons of coding systems, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7550 or a function symbol to call. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7551 In the last case, we call the function with one argument, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7552 which is a list of all the arguments given to this function. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7553 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7554 usage: (find-operation-coding-system OPERATION ARGUMENTS ...) */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7555 (nargs, args) |
17052 | 7556 int nargs; |
7557 Lisp_Object *args; | |
7558 { | |
7559 Lisp_Object operation, target_idx, target, val; | |
7560 register Lisp_Object chain; | |
7561 | |
7562 if (nargs < 2) | |
7563 error ("Too few arguments"); | |
7564 operation = args[0]; | |
7565 if (!SYMBOLP (operation) | |
7566 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
88365 | 7567 error ("Invalid first arguement"); |
17052 | 7568 if (nargs < 1 + XINT (target_idx)) |
7569 error ("Too few arguments for operation: %s", | |
7570 XSYMBOL (operation)->name->data); | |
7571 target = args[XINT (target_idx) + 1]; | |
7572 if (!(STRINGP (target) | |
7573 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
88365 | 7574 error ("Invalid %dth argument", XINT (target_idx) + 1); |
17052 | 7575 |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7576 chain = ((EQ (operation, Qinsert_file_contents) |
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7577 || EQ (operation, Qwrite_region)) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7578 ? Vfile_coding_system_alist |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7579 : (EQ (operation, Qopen_network_stream) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7580 ? Vnetwork_coding_system_alist |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7581 : Vprocess_coding_system_alist)); |
17052 | 7582 if (NILP (chain)) |
7583 return Qnil; | |
7584 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7585 for (; CONSP (chain); chain = XCDR (chain)) |
17052 | 7586 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
7587 Lisp_Object elt; |
88365 | 7588 |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7589 elt = XCAR (chain); |
17052 | 7590 if (CONSP (elt) |
7591 && ((STRINGP (target) | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7592 && STRINGP (XCAR (elt)) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7593 && fast_string_match (XCAR (elt), target) >= 0) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7594 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7595 { |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7596 val = XCDR (elt); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7597 /* Here, if VAL is both a valid coding system and a valid |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7598 function symbol, we return VAL as a coding system. */ |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7599 if (CONSP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7600 return val; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7601 if (! SYMBOLP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7602 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7603 if (! NILP (Fcoding_system_p (val))) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7604 return Fcons (val, val); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7605 if (! NILP (Ffboundp (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7606 { |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7607 val = call1 (val, Flist (nargs, args)); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7608 if (CONSP (val)) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7609 return val; |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7610 if (SYMBOLP (val) && ! NILP (Fcoding_system_p (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7611 return Fcons (val, val); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7612 } |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7613 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7614 } |
17052 | 7615 } |
7616 return Qnil; | |
7617 } | |
7618 | |
88365 | 7619 DEFUN ("set-coding-system-priority", Fset_coding_system_priority, |
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
7620 Sset_coding_system_priority, 0, MANY, 0, |
88645 | 7621 doc: /* Assign higher priority to the coding systems given as arguments. |
88544
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7622 usage: (set-coding-system-priority CODING-SYSTEM ...) */) |
88365 | 7623 (nargs, args) |
7624 int nargs; | |
7625 Lisp_Object *args; | |
7626 { | |
7627 int i, j; | |
7628 int changed[coding_category_max]; | |
7629 enum coding_category priorities[coding_category_max]; | |
7630 | |
7631 bzero (changed, sizeof changed); | |
7632 | |
7633 for (i = j = 0; i < nargs; i++) | |
7634 { | |
7635 enum coding_category category; | |
7636 Lisp_Object spec, attrs; | |
7637 | |
7638 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
7639 attrs = AREF (spec, 0); | |
7640 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
7641 if (changed[category]) | |
7642 /* Ignore this coding system because a coding system of the | |
7643 same category already had a higher priority. */ | |
7644 continue; | |
7645 changed[category] = 1; | |
7646 priorities[j++] = category; | |
7647 if (coding_categories[category].id >= 0 | |
7648 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
7649 setup_coding_system (args[i], &coding_categories[category]); | |
7650 } | |
7651 | |
7652 /* Now we have decided top J priorities. Reflect the order of the | |
7653 original priorities to the remaining priorities. */ | |
7654 | |
7655 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
7656 { | |
7657 while (j < coding_category_max | |
7658 && changed[coding_priorities[j]]) | |
7659 j++; | |
7660 if (j == coding_category_max) | |
7661 abort (); | |
7662 priorities[i] = coding_priorities[j]; | |
7663 } | |
7664 | |
7665 bcopy (priorities, coding_priorities, sizeof priorities); | |
7666 return Qnil; | |
7667 } | |
7668 | |
7669 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, | |
7670 Scoding_system_priority_list, 0, 1, 0, | |
88645 | 7671 doc: /* Return a list of coding systems ordered by their priorities. |
7672 HIGHESTP non-nil means just return the highest priority one. */) | |
88365 | 7673 (highestp) |
7674 Lisp_Object highestp; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7675 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7676 int i; |
88365 | 7677 Lisp_Object val; |
7678 | |
7679 for (i = 0, val = Qnil; i < coding_category_max; i++) | |
7680 { | |
7681 enum coding_category category = coding_priorities[i]; | |
7682 int id = coding_categories[category].id; | |
7683 Lisp_Object attrs; | |
7684 | |
7685 if (id < 0) | |
7686 continue; | |
7687 attrs = CODING_ID_ATTRS (id); | |
7688 if (! NILP (highestp)) | |
7689 return CODING_ATTR_BASE_NAME (attrs); | |
7690 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
7691 } | |
7692 return Fnreverse (val); | |
7693 } | |
7694 | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7695 static char *suffixes[] = { "-unix", "-dos", "-mac" }; |
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7696 |
88365 | 7697 static Lisp_Object |
7698 make_subsidiaries (base) | |
7699 Lisp_Object base; | |
7700 { | |
7701 Lisp_Object subsidiaries; | |
7702 int base_name_len = STRING_BYTES (XSYMBOL (base)->name); | |
7703 char *buf = (char *) alloca (base_name_len + 6); | |
7704 int i; | |
7705 | |
7706 bcopy (XSYMBOL (base)->name->data, buf, base_name_len); | |
7707 subsidiaries = Fmake_vector (make_number (3), Qnil); | |
7708 for (i = 0; i < 3; i++) | |
7709 { | |
7710 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
7711 ASET (subsidiaries, i, intern (buf)); | |
7712 } | |
7713 return subsidiaries; | |
7714 } | |
7715 | |
7716 | |
7717 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, | |
7718 Sdefine_coding_system_internal, coding_arg_max, MANY, 0, | |
88544
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7719 doc: /* For internal use only. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7720 usage: (define-coding-system-internal ...) */) |
88365 | 7721 (nargs, args) |
7722 int nargs; | |
7723 Lisp_Object *args; | |
7724 { | |
7725 Lisp_Object name; | |
7726 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
7727 Lisp_Object attrs; /* Vector of attributes. */ | |
7728 Lisp_Object eol_type; | |
7729 Lisp_Object aliases; | |
7730 Lisp_Object coding_type, charset_list, safe_charsets; | |
7731 enum coding_category category; | |
7732 Lisp_Object tail, val; | |
7733 int max_charset_id = 0; | |
7734 int i; | |
7735 | |
7736 if (nargs < coding_arg_max) | |
7737 goto short_args; | |
7738 | |
7739 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
7740 | |
7741 name = args[coding_arg_name]; | |
7742 CHECK_SYMBOL (name); | |
7743 CODING_ATTR_BASE_NAME (attrs) = name; | |
7744 | |
7745 val = args[coding_arg_mnemonic]; | |
7746 if (! STRINGP (val)) | |
7747 CHECK_CHARACTER (val); | |
7748 CODING_ATTR_MNEMONIC (attrs) = val; | |
7749 | |
7750 coding_type = args[coding_arg_coding_type]; | |
7751 CHECK_SYMBOL (coding_type); | |
7752 CODING_ATTR_TYPE (attrs) = coding_type; | |
7753 | |
7754 charset_list = args[coding_arg_charset_list]; | |
7755 if (SYMBOLP (charset_list)) | |
7756 { | |
7757 if (EQ (charset_list, Qiso_2022)) | |
7758 { | |
7759 if (! EQ (coding_type, Qiso_2022)) | |
7760 error ("Invalid charset-list"); | |
7761 charset_list = Viso_2022_charset_list; | |
7762 } | |
7763 else if (EQ (charset_list, Qemacs_mule)) | |
7764 { | |
7765 if (! EQ (coding_type, Qemacs_mule)) | |
7766 error ("Invalid charset-list"); | |
7767 charset_list = Vemacs_mule_charset_list; | |
7768 } | |
7769 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7770 if (max_charset_id < XFASTINT (XCAR (tail))) | |
7771 max_charset_id = XFASTINT (XCAR (tail)); | |
7772 } | |
7773 else | |
7774 { | |
7775 charset_list = Fcopy_sequence (charset_list); | |
7776 for (tail = charset_list; !NILP (tail); tail = Fcdr (tail)) | |
7777 { | |
7778 struct charset *charset; | |
7779 | |
7780 val = Fcar (tail); | |
7781 CHECK_CHARSET_GET_CHARSET (val, charset); | |
7782 if (EQ (coding_type, Qiso_2022) | |
7783 ? CHARSET_ISO_FINAL (charset) < 0 | |
7784 : EQ (coding_type, Qemacs_mule) | |
7785 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
7786 : 0) | |
7787 error ("Can't handle charset `%s'", | |
7788 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7789 | |
7790 XCAR (tail) = make_number (charset->id); | |
7791 if (max_charset_id < charset->id) | |
7792 max_charset_id = charset->id; | |
7793 } | |
7794 } | |
7795 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
7796 | |
7797 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
7798 make_number (255)); | |
7799 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7800 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
7801 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | |
7802 | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7803 CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7804 |
88365 | 7805 val = args[coding_arg_decode_translation_table]; |
7806 if (! NILP (val)) | |
7807 CHECK_CHAR_TABLE (val); | |
7808 CODING_ATTR_DECODE_TBL (attrs) = val; | |
7809 | |
7810 val = args[coding_arg_encode_translation_table]; | |
7811 if (! NILP (val)) | |
7812 CHECK_CHAR_TABLE (val); | |
7813 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
7814 | |
7815 val = args[coding_arg_post_read_conversion]; | |
7816 CHECK_SYMBOL (val); | |
7817 CODING_ATTR_POST_READ (attrs) = val; | |
7818 | |
7819 val = args[coding_arg_pre_write_conversion]; | |
7820 CHECK_SYMBOL (val); | |
7821 CODING_ATTR_PRE_WRITE (attrs) = val; | |
7822 | |
7823 val = args[coding_arg_default_char]; | |
7824 if (NILP (val)) | |
7825 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
7826 else | |
7827 { | |
7828 CHECK_CHARACTER (val); | |
7829 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
7830 } | |
7831 | |
7832 val = args[coding_arg_plist]; | |
7833 CHECK_LIST (val); | |
7834 CODING_ATTR_PLIST (attrs) = val; | |
7835 | |
7836 if (EQ (coding_type, Qcharset)) | |
7837 { | |
89429
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7838 Lisp_Object list; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7839 /* Generate a lisp vector of 256 elements. Each element is nil, |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7840 integer, or a list of charset IDs. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7841 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7842 If Nth element is nil, the byte code N is invalid in this |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7843 coding system. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7844 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7845 If Nth element is a number NUM, N is the first byte of a |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7846 charset whose ID is NUM. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7847 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7848 If Nth element is a list of charset IDs, N is the first byte |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7849 of one of them. The list is sorted by dimensions of the |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7850 charsets. A charset of smaller dimension comes firtst. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7851 */ |
89429
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7852 for (list = Qnil, tail = charset_list; CONSP (tail); tail = XCDR (tail)) |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7853 { |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7854 struct charset *charset = CHARSET_FROM_ID (XFASTINT (XCAR (tail))); |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7855 |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7856 if (charset->method == CHARSET_METHOD_SUPERSET) |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7857 { |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7858 val = CHARSET_SUPERSET (charset); |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7859 for (; CONSP (val); val = XCDR (val)) |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7860 list = Fcons (XCAR (XCAR (val)), list); |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7861 } |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7862 else |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7863 list = Fcons (XCAR (tail), list); |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7864 } |
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7865 |
88365 | 7866 val = Fmake_vector (make_number (256), Qnil); |
7867 | |
89429
3c978149859b
(Fdefine_coding_system_internal): Fix for the case that
Kenichi Handa <handa@m17n.org>
parents:
89420
diff
changeset
|
7868 for (tail = Fnreverse (list); CONSP (tail); tail = XCDR (tail)) |
88365 | 7869 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7870 struct charset *charset = CHARSET_FROM_ID (XFASTINT (XCAR (tail))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7871 int dim = CHARSET_DIMENSION (charset); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7872 int idx = (dim - 1) * 4; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7873 |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7874 if (CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7875 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7876 |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7877 for (i = charset->code_space[idx]; |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7878 i <= charset->code_space[idx + 1]; i++) |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7879 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7880 Lisp_Object tmp, tmp2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7881 int dim2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7882 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7883 tmp = AREF (val, i); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7884 if (NILP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7885 tmp = XCAR (tail); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7886 else if (NUMBERP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7887 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7888 dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (tmp))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7889 if (dim < dim2) |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7890 tmp = Fcons (XCAR (tail), Fcons (tmp, Qnil)); |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7891 else |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7892 tmp = Fcons (tmp, Fcons (XCAR (tail), Qnil)); |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7893 } |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7894 else |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7895 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7896 for (tmp2 = tmp; CONSP (tmp2); tmp2 = XCDR (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7897 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7898 dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (XCAR (tmp2)))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7899 if (dim < dim2) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7900 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7901 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7902 if (NILP (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7903 tmp = nconc2 (tmp, Fcons (XCAR (tail), Qnil)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7904 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7905 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7906 XSETCDR (tmp2, Fcons (XCAR (tmp2), XCDR (tmp2))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7907 XSETCAR (tmp2, XCAR (tail)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7908 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7909 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7910 ASET (val, i, tmp); |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7911 } |
88365 | 7912 } |
7913 ASET (attrs, coding_attr_charset_valids, val); | |
7914 category = coding_category_charset; | |
7915 } | |
7916 else if (EQ (coding_type, Qccl)) | |
7917 { | |
7918 Lisp_Object valids; | |
7919 | |
7920 if (nargs < coding_arg_ccl_max) | |
7921 goto short_args; | |
7922 | |
7923 val = args[coding_arg_ccl_decoder]; | |
7924 CHECK_CCL_PROGRAM (val); | |
7925 if (VECTORP (val)) | |
7926 val = Fcopy_sequence (val); | |
7927 ASET (attrs, coding_attr_ccl_decoder, val); | |
7928 | |
7929 val = args[coding_arg_ccl_encoder]; | |
7930 CHECK_CCL_PROGRAM (val); | |
7931 if (VECTORP (val)) | |
7932 val = Fcopy_sequence (val); | |
7933 ASET (attrs, coding_attr_ccl_encoder, val); | |
7934 | |
7935 val = args[coding_arg_ccl_valids]; | |
7936 valids = Fmake_string (make_number (256), make_number (0)); | |
7937 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
7938 { | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7939 int from, to; |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7940 |
88365 | 7941 val = Fcar (tail); |
7942 if (INTEGERP (val)) | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7943 { |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7944 from = to = XINT (val); |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7945 if (from < 0 || from > 255) |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7946 args_out_of_range_3 (val, make_number (0), make_number (255)); |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7947 } |
88365 | 7948 else |
7949 { | |
7950 CHECK_CONS (val); | |
7951 CHECK_NUMBER (XCAR (val)); | |
7952 CHECK_NUMBER (XCDR (val)); | |
7953 from = XINT (XCAR (val)); | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7954 if (from < 0 || from > 255) |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7955 args_out_of_range_3 (XCAR (val), |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7956 make_number (0), make_number (255)); |
88365 | 7957 to = XINT (XCDR (val)); |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7958 if (to < from || to > 255) |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7959 args_out_of_range_3 (XCDR (val), |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7960 XCAR (val), make_number (255)); |
88365 | 7961 } |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7962 for (i = from; i <= to; i++) |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
7963 XSTRING (valids)->data[i] = 1; |
88365 | 7964 } |
7965 ASET (attrs, coding_attr_ccl_valids, valids); | |
7966 | |
7967 category = coding_category_ccl; | |
7968 } | |
7969 else if (EQ (coding_type, Qutf_16)) | |
7970 { | |
7971 Lisp_Object bom, endian; | |
7972 | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7973 CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7974 |
88365 | 7975 if (nargs < coding_arg_utf16_max) |
7976 goto short_args; | |
7977 | |
7978 bom = args[coding_arg_utf16_bom]; | |
7979 if (! NILP (bom) && ! EQ (bom, Qt)) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7980 { |
88365 | 7981 CHECK_CONS (bom); |
7982 CHECK_CODING_SYSTEM (XCAR (bom)); | |
7983 CHECK_CODING_SYSTEM (XCDR (bom)); | |
7984 } | |
7985 ASET (attrs, coding_attr_utf_16_bom, bom); | |
7986 | |
7987 endian = args[coding_arg_utf16_endian]; | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
7988 CHECK_SYMBOL (endian); |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
7989 if (NILP (endian)) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
7990 endian = Qbig; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
7991 else if (! EQ (endian, Qbig) && ! EQ (endian, Qlittle)) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
7992 error ("Invalid endian: %s", XSYMBOL (endian)->name->data); |
88365 | 7993 ASET (attrs, coding_attr_utf_16_endian, endian); |
7994 | |
7995 category = (CONSP (bom) | |
7996 ? coding_category_utf_16_auto | |
7997 : NILP (bom) | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
7998 ? (EQ (endian, Qbig) |
88365 | 7999 ? coding_category_utf_16_be_nosig |
8000 : coding_category_utf_16_le_nosig) | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
8001 : (EQ (endian, Qbig) |
88365 | 8002 ? coding_category_utf_16_be |
8003 : coding_category_utf_16_le)); | |
8004 } | |
8005 else if (EQ (coding_type, Qiso_2022)) | |
8006 { | |
8007 Lisp_Object initial, reg_usage, request, flags; | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
8008 int i, id; |
88365 | 8009 |
8010 if (nargs < coding_arg_iso2022_max) | |
8011 goto short_args; | |
8012 | |
8013 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
8014 CHECK_VECTOR (initial); | |
8015 for (i = 0; i < 4; i++) | |
8016 { | |
8017 val = Faref (initial, make_number (i)); | |
8018 if (! NILP (val)) | |
8019 { | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8020 struct charset *charset; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8021 |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8022 CHECK_CHARSET_GET_CHARSET (val, charset); |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8023 ASET (initial, i, make_number (CHARSET_ID (charset))); |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8024 if (i == 0 && CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8025 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 8026 } |
8027 else | |
8028 ASET (initial, i, make_number (-1)); | |
8029 } | |
8030 | |
8031 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
8032 CHECK_CONS (reg_usage); | |
8033 CHECK_NATNUM (XCAR (reg_usage)); | |
8034 CHECK_NATNUM (XCDR (reg_usage)); | |
8035 | |
8036 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
8037 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
8038 { | |
8039 int id; | |
8040 | |
8041 val = Fcar (tail); | |
8042 CHECK_CONS (val); | |
8043 CHECK_CHARSET_GET_ID (XCAR (val), id); | |
8044 CHECK_NATNUM (XCDR (val)); | |
8045 if (XINT (XCDR (val)) >= 4) | |
8046 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
8047 XCAR (val) = make_number (id); | |
8048 } | |
8049 | |
8050 flags = args[coding_arg_iso2022_flags]; | |
8051 CHECK_NATNUM (flags); | |
8052 i = XINT (flags); | |
8053 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
8054 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
8055 | |
8056 ASET (attrs, coding_attr_iso_initial, initial); | |
8057 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
8058 ASET (attrs, coding_attr_iso_request, request); | |
8059 ASET (attrs, coding_attr_iso_flags, flags); | |
8060 setup_iso_safe_charsets (attrs); | |
8061 | |
8062 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
8063 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
8064 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
8065 ? coding_category_iso_7_else | |
8066 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
8067 ? coding_category_iso_7 | |
8068 : coding_category_iso_7_tight); | |
8069 else | |
8070 { | |
8071 int id = XINT (AREF (initial, 1)); | |
8072 | |
88977
3b05c02eebf2
(Fdefine_coding_system_internal): Fix category setting
Kenichi Handa <handa@m17n.org>
parents:
88950
diff
changeset
|
8073 category = (((i & CODING_ISO_FLAG_LOCKING_SHIFT) |
88365 | 8074 || EQ (args[coding_arg_charset_list], Qiso_2022) |
8075 || id < 0) | |
8076 ? coding_category_iso_8_else | |
8077 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
8078 ? coding_category_iso_8_1 | |
8079 : coding_category_iso_8_2); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8080 } |
89227
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
8081 if (category != coding_category_iso_8_1 |
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
8082 && category != coding_category_iso_8_2) |
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
8083 CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; |
88365 | 8084 } |
8085 else if (EQ (coding_type, Qemacs_mule)) | |
8086 { | |
8087 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
8088 ASET (attrs, coding_attr_emacs_mule_full, Qt); | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8089 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 8090 category = coding_category_emacs_mule; |
8091 } | |
8092 else if (EQ (coding_type, Qshift_jis)) | |
8093 { | |
8094 | |
8095 struct charset *charset; | |
8096 | |
8097 if (XINT (Flength (charset_list)) != 3) | |
8098 error ("There should be just three charsets"); | |
8099 | |
8100 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
8101 if (CHARSET_DIMENSION (charset) != 1) | |
8102 error ("Dimension of charset %s is not one", | |
8103 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8104 if (CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8105 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 8106 |
8107 charset_list = XCDR (charset_list); | |
8108 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
8109 if (CHARSET_DIMENSION (charset) != 1) | |
8110 error ("Dimension of charset %s is not one", | |
8111 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
8112 | |
8113 charset_list = XCDR (charset_list); | |
8114 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
8115 if (CHARSET_DIMENSION (charset) != 2) | |
8116 error ("Dimension of charset %s is not two", | |
8117 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
8118 | |
8119 category = coding_category_sjis; | |
8120 Vsjis_coding_system = name; | |
8121 } | |
8122 else if (EQ (coding_type, Qbig5)) | |
8123 { | |
8124 struct charset *charset; | |
8125 | |
8126 if (XINT (Flength (charset_list)) != 2) | |
8127 error ("There should be just two charsets"); | |
8128 | |
8129 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
8130 if (CHARSET_DIMENSION (charset) != 1) | |
8131 error ("Dimension of charset %s is not one", | |
8132 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8133 if (CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8134 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 8135 |
8136 charset_list = XCDR (charset_list); | |
8137 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
8138 if (CHARSET_DIMENSION (charset) != 2) | |
8139 error ("Dimension of charset %s is not two", | |
8140 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
8141 | |
8142 category = coding_category_big5; | |
8143 Vbig5_coding_system = name; | |
8144 } | |
8145 else if (EQ (coding_type, Qraw_text)) | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8146 { |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8147 category = coding_category_raw_text; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8148 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8149 } |
88365 | 8150 else if (EQ (coding_type, Qutf_8)) |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8151 { |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8152 category = coding_category_utf_8; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8153 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8154 } |
88365 | 8155 else if (EQ (coding_type, Qundecided)) |
8156 category = coding_category_undecided; | |
8157 else | |
8158 error ("Invalid coding system type: %s", | |
8159 XSYMBOL (coding_type)->name->data); | |
8160 | |
8161 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
8162 | |
8163 eol_type = args[coding_arg_eol_type]; | |
8164 if (! NILP (eol_type) | |
8165 && ! EQ (eol_type, Qunix) | |
8166 && ! EQ (eol_type, Qdos) | |
8167 && ! EQ (eol_type, Qmac)) | |
8168 error ("Invalid eol-type"); | |
8169 | |
8170 aliases = Fcons (name, Qnil); | |
8171 | |
8172 if (NILP (eol_type)) | |
8173 { | |
8174 eol_type = make_subsidiaries (name); | |
8175 for (i = 0; i < 3; i++) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8176 { |
88365 | 8177 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
8178 | |
8179 this_name = AREF (eol_type, i); | |
8180 this_aliases = Fcons (this_name, Qnil); | |
8181 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
8182 this_spec = Fmake_vector (make_number (3), attrs); | |
8183 ASET (this_spec, 1, this_aliases); | |
8184 ASET (this_spec, 2, this_eol_type); | |
8185 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
8186 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
8187 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (this_name), Qnil), | |
8188 Vcoding_system_alist); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8189 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8190 } |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8191 |
88365 | 8192 spec_vec = Fmake_vector (make_number (3), attrs); |
8193 ASET (spec_vec, 1, aliases); | |
8194 ASET (spec_vec, 2, eol_type); | |
8195 | |
8196 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
8197 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
8198 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), | |
8199 Vcoding_system_alist); | |
8200 | |
8201 { | |
8202 int id = coding_categories[category].id; | |
8203 | |
8204 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
8205 setup_coding_system (name, &coding_categories[category]); | |
8206 } | |
8207 | |
8208 return Qnil; | |
8209 | |
8210 short_args: | |
8211 return Fsignal (Qwrong_number_of_arguments, | |
8212 Fcons (intern ("define-coding-system-internal"), | |
8213 make_number (nargs))); | |
8214 } | |
8215 | |
88645 | 8216 /* Fixme: should this record the alias relationships for |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8217 diagnostics? Should it update coding-system-list? */ |
88365 | 8218 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, |
8219 Sdefine_coding_system_alias, 2, 2, 0, | |
8220 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
8221 (alias, coding_system) | |
8222 Lisp_Object alias, coding_system; | |
8223 { | |
8224 Lisp_Object spec, aliases, eol_type; | |
8225 | |
8226 CHECK_SYMBOL (alias); | |
8227 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
8228 aliases = AREF (spec, 1); | |
8229 while (!NILP (XCDR (aliases))) | |
8230 aliases = XCDR (aliases); | |
8231 XCDR (aliases) = Fcons (alias, Qnil); | |
8232 | |
8233 eol_type = AREF (spec, 2); | |
8234 if (VECTORP (eol_type)) | |
8235 { | |
8236 Lisp_Object subsidiaries; | |
8237 int i; | |
8238 | |
8239 subsidiaries = make_subsidiaries (alias); | |
8240 for (i = 0; i < 3; i++) | |
8241 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
8242 AREF (eol_type, i)); | |
8243 | |
8244 ASET (spec, 2, subsidiaries); | |
8245 } | |
8246 | |
8247 Fputhash (alias, spec, Vcoding_system_hash_table); | |
88485 | 8248 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
8249 Vcoding_system_alist); | |
88365 | 8250 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8251 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8252 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8253 |
88365 | 8254 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
8255 1, 1, 0, | |
8256 doc: /* Return the base of CODING-SYSTEM. | |
88645 | 8257 Any alias or subsidiary coding system is not a base coding system. */) |
88365 | 8258 (coding_system) |
8259 Lisp_Object coding_system; | |
8260 { | |
8261 Lisp_Object spec, attrs; | |
8262 | |
8263 if (NILP (coding_system)) | |
8264 return (Qno_conversion); | |
8265 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
8266 attrs = AREF (spec, 0); | |
8267 return CODING_ATTR_BASE_NAME (attrs); | |
8268 } | |
8269 | |
8270 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
8271 1, 1, 0, | |
8272 doc: "Return the property list of CODING-SYSTEM.") | |
8273 (coding_system) | |
8274 Lisp_Object coding_system; | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
8275 { |
88365 | 8276 Lisp_Object spec, attrs; |
8277 | |
8278 if (NILP (coding_system)) | |
8279 coding_system = Qno_conversion; | |
8280 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
8281 attrs = AREF (spec, 0); | |
8282 return CODING_ATTR_PLIST (attrs); | |
8283 } | |
8284 | |
8285 | |
8286 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
8287 1, 1, 0, | |
88645 | 8288 doc: /* Return the list of aliases of CODING-SYSTEM. */) |
88365 | 8289 (coding_system) |
8290 Lisp_Object coding_system; | |
8291 { | |
8292 Lisp_Object spec; | |
8293 | |
8294 if (NILP (coding_system)) | |
8295 coding_system = Qno_conversion; | |
8296 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
88645 | 8297 return AREF (spec, 1); |
88365 | 8298 } |
8299 | |
8300 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
8301 Scoding_system_eol_type, 1, 1, 0, | |
8302 doc: /* Return eol-type of CODING-SYSTEM. | |
8303 An eol-type is integer 0, 1, 2, or a vector of coding systems. | |
8304 | |
8305 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
8306 and CR respectively. | |
8307 | |
8308 A vector value indicates that a format of end-of-line should be | |
8309 detected automatically. Nth element of the vector is the subsidiary | |
8310 coding system whose eol-type is N. */) | |
8311 (coding_system) | |
8312 Lisp_Object coding_system; | |
8313 { | |
8314 Lisp_Object spec, eol_type; | |
8315 int n; | |
8316 | |
8317 if (NILP (coding_system)) | |
8318 coding_system = Qno_conversion; | |
8319 if (! CODING_SYSTEM_P (coding_system)) | |
8320 return Qnil; | |
8321 spec = CODING_SYSTEM_SPEC (coding_system); | |
8322 eol_type = AREF (spec, 2); | |
8323 if (VECTORP (eol_type)) | |
8324 return Fcopy_sequence (eol_type); | |
8325 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
8326 return make_number (n); | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
8327 } |
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
8328 |
17052 | 8329 #endif /* emacs */ |
8330 | |
8331 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8332 /*** 9. Post-amble ***/ |
17052 | 8333 |
21514 | 8334 void |
17052 | 8335 init_coding_once () |
8336 { | |
8337 int i; | |
8338 | |
88365 | 8339 for (i = 0; i < coding_category_max; i++) |
8340 { | |
8341 coding_categories[i].id = -1; | |
8342 coding_priorities[i] = i; | |
8343 } | |
17052 | 8344 |
8345 /* ISO2022 specific initialize routine. */ | |
8346 for (i = 0; i < 0x20; i++) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
8347 iso_code_class[i] = ISO_control_0; |
17052 | 8348 for (i = 0x21; i < 0x7F; i++) |
8349 iso_code_class[i] = ISO_graphic_plane_0; | |
8350 for (i = 0x80; i < 0xA0; i++) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
8351 iso_code_class[i] = ISO_control_1; |
17052 | 8352 for (i = 0xA1; i < 0xFF; i++) |
8353 iso_code_class[i] = ISO_graphic_plane_1; | |
8354 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
8355 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
8356 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
8357 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
8358 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
8359 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
8360 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
8361 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
8362 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
8363 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
8364 | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
8365 inhibit_pre_post_conversion = 0; |
88365 | 8366 |
8367 for (i = 0; i < 256; i++) | |
8368 { | |
8369 emacs_mule_bytes[i] = 1; | |
8370 } | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
8371 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_11] = 3; |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
8372 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_12] = 3; |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
8373 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_21] = 4; |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
8374 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_22] = 4; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8375 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8376 |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8377 #ifdef emacs |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8378 |
21514 | 8379 void |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8380 syms_of_coding () |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8381 { |
88365 | 8382 staticpro (&Vcoding_system_hash_table); |
8383 Vcoding_system_hash_table = Fmakehash (Qeq); | |
8384 | |
8385 staticpro (&Vsjis_coding_system); | |
8386 Vsjis_coding_system = Qnil; | |
8387 | |
8388 staticpro (&Vbig5_coding_system); | |
8389 Vbig5_coding_system = Qnil; | |
8390 | |
8391 staticpro (&Vcode_conversion_work_buf_list); | |
8392 Vcode_conversion_work_buf_list = Qnil; | |
8393 | |
8394 staticpro (&Vcode_conversion_reused_work_buf); | |
8395 Vcode_conversion_reused_work_buf = Qnil; | |
8396 | |
8397 DEFSYM (Qcharset, "charset"); | |
8398 DEFSYM (Qtarget_idx, "target-idx"); | |
8399 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
8400 Fset (Qcoding_system_history, Qnil); |
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
8401 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8402 /* Target FILENAME is the first argument. */ |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8403 Fput (Qinsert_file_contents, Qtarget_idx, make_number (0)); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8404 /* Target FILENAME is the third argument. */ |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8405 Fput (Qwrite_region, Qtarget_idx, make_number (2)); |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8406 |
88365 | 8407 DEFSYM (Qcall_process, "call-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8408 /* Target PROGRAM is the first argument. */ |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8409 Fput (Qcall_process, Qtarget_idx, make_number (0)); |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8410 |
88365 | 8411 DEFSYM (Qcall_process_region, "call-process-region"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8412 /* Target PROGRAM is the third argument. */ |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8413 Fput (Qcall_process_region, Qtarget_idx, make_number (2)); |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8414 |
88365 | 8415 DEFSYM (Qstart_process, "start-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8416 /* Target PROGRAM is the third argument. */ |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8417 Fput (Qstart_process, Qtarget_idx, make_number (2)); |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8418 |
88365 | 8419 DEFSYM (Qopen_network_stream, "open-network-stream"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8420 /* Target SERVICE is the fourth argument. */ |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8421 Fput (Qopen_network_stream, Qtarget_idx, make_number (3)); |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8422 |
88365 | 8423 DEFSYM (Qcoding_system, "coding-system"); |
8424 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
8425 | |
8426 DEFSYM (Qeol_type, "eol-type"); | |
8427 DEFSYM (Qunix, "unix"); | |
8428 DEFSYM (Qdos, "dos"); | |
8429 | |
8430 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
8431 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
8432 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
8433 DEFSYM (Qdefault_char, "default-char"); | |
8434 DEFSYM (Qundecided, "undecided"); | |
8435 DEFSYM (Qno_conversion, "no-conversion"); | |
8436 DEFSYM (Qraw_text, "raw-text"); | |
8437 | |
8438 DEFSYM (Qiso_2022, "iso-2022"); | |
8439 | |
8440 DEFSYM (Qutf_8, "utf-8"); | |
8441 | |
8442 DEFSYM (Qutf_16, "utf-16"); | |
8443 DEFSYM (Qbig, "big"); | |
8444 DEFSYM (Qlittle, "little"); | |
8445 | |
8446 DEFSYM (Qshift_jis, "shift-jis"); | |
8447 DEFSYM (Qbig5, "big5"); | |
8448 | |
8449 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
8450 | |
8451 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
17052 | 8452 Fput (Qcoding_system_error, Qerror_conditions, |
8453 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
8454 Fput (Qcoding_system_error, Qerror_message, | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8455 build_string ("Invalid coding system")); |
17052 | 8456 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8457 /* Intern this now in case it isn't already done. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8458 Setting this variable twice is harmless. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8459 But don't staticpro it here--that is done in alloc.c. */ |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8460 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
88365 | 8461 |
8462 DEFSYM (Qtranslation_table, "translation-table"); | |
8463 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); | |
8464 DEFSYM (Qtranslation_table_id, "translation-table-id"); | |
8465 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
8466 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
8467 | |
8468 DEFSYM (Qvalid_codes, "valid-codes"); | |
8469 | |
8470 DEFSYM (Qemacs_mule, "emacs-mule"); | |
8471 | |
8472 Vcoding_category_table | |
8473 = Fmake_vector (make_number (coding_category_max), Qnil); | |
8474 staticpro (&Vcoding_category_table); | |
8475 /* Followings are target of code detection. */ | |
8476 ASET (Vcoding_category_table, coding_category_iso_7, | |
8477 intern ("coding-category-iso-7")); | |
8478 ASET (Vcoding_category_table, coding_category_iso_7_tight, | |
8479 intern ("coding-category-iso-7-tight")); | |
8480 ASET (Vcoding_category_table, coding_category_iso_8_1, | |
8481 intern ("coding-category-iso-8-1")); | |
8482 ASET (Vcoding_category_table, coding_category_iso_8_2, | |
8483 intern ("coding-category-iso-8-2")); | |
8484 ASET (Vcoding_category_table, coding_category_iso_7_else, | |
8485 intern ("coding-category-iso-7-else")); | |
8486 ASET (Vcoding_category_table, coding_category_iso_8_else, | |
8487 intern ("coding-category-iso-8-else")); | |
8488 ASET (Vcoding_category_table, coding_category_utf_8, | |
8489 intern ("coding-category-utf-8")); | |
8490 ASET (Vcoding_category_table, coding_category_utf_16_be, | |
8491 intern ("coding-category-utf-16-be")); | |
8492 ASET (Vcoding_category_table, coding_category_utf_16_le, | |
8493 intern ("coding-category-utf-16-le")); | |
8494 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, | |
8495 intern ("coding-category-utf-16-be-nosig")); | |
8496 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, | |
8497 intern ("coding-category-utf-16-le-nosig")); | |
8498 ASET (Vcoding_category_table, coding_category_charset, | |
8499 intern ("coding-category-charset")); | |
8500 ASET (Vcoding_category_table, coding_category_sjis, | |
8501 intern ("coding-category-sjis")); | |
8502 ASET (Vcoding_category_table, coding_category_big5, | |
8503 intern ("coding-category-big5")); | |
8504 ASET (Vcoding_category_table, coding_category_ccl, | |
8505 intern ("coding-category-ccl")); | |
8506 ASET (Vcoding_category_table, coding_category_emacs_mule, | |
8507 intern ("coding-category-emacs-mule")); | |
8508 /* Followings are NOT target of code detection. */ | |
8509 ASET (Vcoding_category_table, coding_category_raw_text, | |
8510 intern ("coding-category-raw-text")); | |
8511 ASET (Vcoding_category_table, coding_category_undecided, | |
8512 intern ("coding-category-undecided")); | |
8513 | |
17052 | 8514 defsubr (&Scoding_system_p); |
8515 defsubr (&Sread_coding_system); | |
8516 defsubr (&Sread_non_nil_coding_system); | |
8517 defsubr (&Scheck_coding_system); | |
8518 defsubr (&Sdetect_coding_region); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8519 defsubr (&Sdetect_coding_string); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8520 defsubr (&Sfind_coding_systems_region_internal); |
88365 | 8521 defsubr (&Scheck_coding_systems_region); |
17052 | 8522 defsubr (&Sdecode_coding_region); |
8523 defsubr (&Sencode_coding_region); | |
8524 defsubr (&Sdecode_coding_string); | |
8525 defsubr (&Sencode_coding_string); | |
8526 defsubr (&Sdecode_sjis_char); | |
8527 defsubr (&Sencode_sjis_char); | |
8528 defsubr (&Sdecode_big5_char); | |
8529 defsubr (&Sencode_big5_char); | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8530 defsubr (&Sset_terminal_coding_system_internal); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8531 defsubr (&Sset_safe_terminal_coding_system_internal); |
17052 | 8532 defsubr (&Sterminal_coding_system); |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8533 defsubr (&Sset_keyboard_coding_system_internal); |
17052 | 8534 defsubr (&Skeyboard_coding_system); |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
8535 defsubr (&Sfind_operation_coding_system); |
88365 | 8536 defsubr (&Sset_coding_system_priority); |
8537 defsubr (&Sdefine_coding_system_internal); | |
8538 defsubr (&Sdefine_coding_system_alias); | |
8539 defsubr (&Scoding_system_base); | |
8540 defsubr (&Scoding_system_plist); | |
8541 defsubr (&Scoding_system_aliases); | |
8542 defsubr (&Scoding_system_eol_type); | |
8543 defsubr (&Scoding_system_priority_list); | |
17052 | 8544 |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8545 DEFVAR_LISP ("coding-system-list", &Vcoding_system_list, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8546 doc: /* List of coding systems. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8547 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8548 Do not alter the value of this variable manually. This variable should be |
88365 | 8549 updated by the functions `define-coding-system' and |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8550 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8551 Vcoding_system_list = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8552 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8553 DEFVAR_LISP ("coding-system-alist", &Vcoding_system_alist, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8554 doc: /* Alist of coding system names. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8555 Each element is one element list of coding system name. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8556 This variable is given to `completing-read' as TABLE argument. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8557 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8558 Do not alter the value of this variable manually. This variable should be |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8559 updated by the functions `make-coding-system' and |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8560 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8561 Vcoding_system_alist = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8562 |
17052 | 8563 DEFVAR_LISP ("coding-category-list", &Vcoding_category_list, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8564 doc: /* List of coding-categories (symbols) ordered by priority. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8565 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8566 On detecting a coding system, Emacs tries code detection algorithms |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8567 associated with each coding-category one by one in this order. When |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8568 one algorithm agrees with a byte sequence of source text, the coding |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8569 system bound to the corresponding coding-category is selected. */); |
17052 | 8570 { |
8571 int i; | |
8572 | |
8573 Vcoding_category_list = Qnil; | |
88365 | 8574 for (i = coding_category_max - 1; i >= 0; i--) |
17052 | 8575 Vcoding_category_list |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8576 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8577 Vcoding_category_list); |
17052 | 8578 } |
8579 | |
8580 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8581 doc: /* Specify the coding system for read operations. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8582 It is useful to bind this variable with `let', but do not set it globally. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8583 If the value is a coding system, it is used for decoding on read operation. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8584 If not, an appropriate element is used from one of the coding system alists: |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8585 There are three such tables, `file-coding-system-alist', |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8586 `process-coding-system-alist', and `network-coding-system-alist'. */); |
17052 | 8587 Vcoding_system_for_read = Qnil; |
8588 | |
8589 DEFVAR_LISP ("coding-system-for-write", &Vcoding_system_for_write, | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8590 doc: /* Specify the coding system for write operations. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8591 Programs bind this variable with `let', but you should not set it globally. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8592 If the value is a coding system, it is used for encoding of output, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8593 when writing it to a file and when sending it to a file or subprocess. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8594 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8595 If this does not specify a coding system, an appropriate element |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8596 is used from one of the coding system alists: |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8597 There are three such tables, `file-coding-system-alist', |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8598 `process-coding-system-alist', and `network-coding-system-alist'. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8599 For output to files, if the above procedure does not specify a coding system, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8600 the value of `buffer-file-coding-system' is used. */); |
17052 | 8601 Vcoding_system_for_write = Qnil; |
8602 | |
8603 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
88365 | 8604 doc: /* |
8605 Coding system used in the latest file or process I/O. */); | |
17052 | 8606 Vlast_coding_system_used = Qnil; |
8607 | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8608 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
88365 | 8609 doc: /* |
8610 *Non-nil means always inhibit code conversion of end-of-line format. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8611 See info node `Coding Systems' and info node `Text and Binary' concerning |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8612 such conversion. */); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8613 inhibit_eol_conversion = 0; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8614 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8615 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
88365 | 8616 doc: /* |
8617 Non-nil means process buffer inherits coding system of process output. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8618 Bind it to t if the process output is to be treated as if it were a file |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8619 read from some filesystem. */); |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8620 inherit_process_coding_system = 0; |
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8621 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8622 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
88365 | 8623 doc: /* |
8624 Alist to decide a coding system to use for a file I/O operation. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8625 The format is ((PATTERN . VAL) ...), |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8626 where PATTERN is a regular expression matching a file name, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8627 VAL is a coding system, a cons of coding systems, or a function symbol. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8628 If VAL is a coding system, it is used for both decoding and encoding |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8629 the file contents. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8630 If VAL is a cons of coding systems, the car part is used for decoding, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8631 and the cdr part is used for encoding. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8632 If VAL is a function symbol, the function must return a coding system |
41678
5aa97e545399
(syms_of_coding) <Qchar_coding_system>: Give it an
Dave Love <fx@gnu.org>
parents:
41624
diff
changeset
|
8633 or a cons of coding systems which are used as above. The function gets |
5aa97e545399
(syms_of_coding) <Qchar_coding_system>: Give it an
Dave Love <fx@gnu.org>
parents:
41624
diff
changeset
|
8634 the arguments with which `find-operation-coding-systems' was called. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8635 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8636 See also the function `find-operation-coding-system' |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8637 and the variable `auto-coding-alist'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8638 Vfile_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8639 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8640 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
88365 | 8641 doc: /* |
8642 Alist to decide a coding system to use for a process I/O operation. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8643 The format is ((PATTERN . VAL) ...), |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8644 where PATTERN is a regular expression matching a program name, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8645 VAL is a coding system, a cons of coding systems, or a function symbol. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8646 If VAL is a coding system, it is used for both decoding what received |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8647 from the program and encoding what sent to the program. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8648 If VAL is a cons of coding systems, the car part is used for decoding, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8649 and the cdr part is used for encoding. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8650 If VAL is a function symbol, the function must return a coding system |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8651 or a cons of coding systems which are used as above. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8652 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8653 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8654 Vprocess_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8655 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8656 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
88365 | 8657 doc: /* |
8658 Alist to decide a coding system to use for a network I/O operation. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8659 The format is ((PATTERN . VAL) ...), |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8660 where PATTERN is a regular expression matching a network service name |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8661 or is a port number to connect to, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8662 VAL is a coding system, a cons of coding systems, or a function symbol. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8663 If VAL is a coding system, it is used for both decoding what received |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8664 from the network stream and encoding what sent to the network stream. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8665 If VAL is a cons of coding systems, the car part is used for decoding, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8666 and the cdr part is used for encoding. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8667 If VAL is a function symbol, the function must return a coding system |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8668 or a cons of coding systems which are used as above. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8669 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8670 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8671 Vnetwork_coding_system_alist = Qnil; |
17052 | 8672 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8673 DEFVAR_LISP ("locale-coding-system", &Vlocale_coding_system, |
41026
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8674 doc: /* Coding system to use with system messages. |
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8675 Also used for decoding keyboard input on X Window system. */); |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8676 Vlocale_coding_system = Qnil; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8677 |
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
8678 /* The eol mnemonics are reset in startup.el system-dependently. */ |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8679 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
88365 | 8680 doc: /* |
8681 *String displayed in mode line for UNIX-like (LF) end-of-line format. */); | |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8682 eol_mnemonic_unix = build_string (":"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8683 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8684 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
88365 | 8685 doc: /* |
8686 *String displayed in mode line for DOS-like (CRLF) end-of-line format. */); | |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8687 eol_mnemonic_dos = build_string ("\\"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8688 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8689 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
88365 | 8690 doc: /* |
8691 *String displayed in mode line for MAC-like (CR) end-of-line format. */); | |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8692 eol_mnemonic_mac = build_string ("/"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8693 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8694 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
88365 | 8695 doc: /* |
8696 *String displayed in mode line when end-of-line format is not yet determined. */); | |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8697 eol_mnemonic_undecided = build_string (":"); |
17052 | 8698 |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8699 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
88365 | 8700 doc: /* |
8701 *Non-nil enables character translation while encoding and decoding. */); | |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8702 Venable_character_translation = Qt; |
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8703 |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8704 DEFVAR_LISP ("standard-translation-table-for-decode", |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8705 &Vstandard_translation_table_for_decode, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8706 doc: /* Table for translating characters while decoding. */); |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8707 Vstandard_translation_table_for_decode = Qnil; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8708 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8709 DEFVAR_LISP ("standard-translation-table-for-encode", |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8710 &Vstandard_translation_table_for_encode, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8711 doc: /* Table for translating characters while encoding. */); |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8712 Vstandard_translation_table_for_encode = Qnil; |
17052 | 8713 |
88365 | 8714 DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_table, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8715 doc: /* Alist of charsets vs revision numbers. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8716 While encoding, if a charset (car part of an element) is found, |
88365 | 8717 designate it with the escape sequence identifying revision (cdr part |
8718 of the element). */); | |
8719 Vcharset_revision_table = Qnil; | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8720 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8721 DEFVAR_LISP ("default-process-coding-system", |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8722 &Vdefault_process_coding_system, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8723 doc: /* Cons of coding systems used for process I/O by default. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8724 The car part is used for decoding a process output, |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8725 the cdr part is used for encoding a text to be sent to a process. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8726 Vdefault_process_coding_system = Qnil; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8727 |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8728 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
88365 | 8729 doc: /* |
8730 Table of extra Latin codes in the range 128..159 (inclusive). | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8731 This is a vector of length 256. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8732 If Nth element is non-nil, the existence of code N in a file |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8733 \(or output of subprocess) doesn't prevent it to be detected as |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8734 a coding system of ISO 2022 variant which has a flag |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8735 `accept-latin-extra-code' t (e.g. iso-latin-1) on reading a file |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8736 or reading output of a subprocess. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8737 Only 128th through 159th elements has a meaning. */); |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8738 Vlatin_extra_code_table = Fmake_vector (make_number (256), Qnil); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8739 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8740 DEFVAR_LISP ("select-safe-coding-system-function", |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8741 &Vselect_safe_coding_system_function, |
88365 | 8742 doc: /* |
8743 Function to call to select safe coding system for encoding a text. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8744 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8745 If set, this function is called to force a user to select a proper |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8746 coding system which can encode the text in the case that a default |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8747 coding system used in each operation can't encode the text. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8748 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8749 The default value is `select-safe-coding-system' (which see). */); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8750 Vselect_safe_coding_system_function = Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8751 |
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
8752 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8753 &inhibit_iso_escape_detection, |
88365 | 8754 doc: /* |
8755 If non-nil, Emacs ignores ISO2022's escape sequence on code detection. | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8756 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8757 By default, on reading a file, Emacs tries to detect how the text is |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8758 encoded. This code detection is sensitive to escape sequences. If |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8759 the sequence is valid as ISO2022, the code is determined as one of |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8760 the ISO2022 encodings, and the file is decoded by the corresponding |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8761 coding system (e.g. `iso-2022-7bit'). |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8762 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8763 However, there may be a case that you want to read escape sequences in |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8764 a file as is. In such a case, you can set this variable to non-nil. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8765 Then, as the code detection ignores any escape sequences, no file is |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8766 detected as encoded in some ISO2022 encoding. The result is that all |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8767 escape sequences become visible in a buffer. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8768 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8769 The default value is nil, and it is strongly recommended not to change |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8770 it. That is because many Emacs Lisp source files that contain |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8771 non-ASCII characters are encoded by the coding system `iso-2022-7bit' |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8772 in Emacs's distribution, and they won't be decoded correctly on |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8773 reading if you suppress escape sequence detection. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8774 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8775 The other way to read escape sequences in a file without decoding is |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8776 to explicitly specify some coding system that doesn't use ISO2022's |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8777 escape sequence (e.g `latin-1') on reading by \\[universal-coding-system-argument]. */); |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8778 inhibit_iso_escape_detection = 0; |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8779 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8780 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8781 Lisp_Object args[coding_arg_max]; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8782 Lisp_Object plist[14]; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8783 int i; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8784 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8785 for (i = 0; i < coding_arg_max; i++) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8786 args[i] = Qnil; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8787 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8788 plist[0] = intern (":name"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8789 plist[1] = args[coding_arg_name] = Qno_conversion; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8790 plist[2] = intern (":mnemonic"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8791 plist[3] = args[coding_arg_mnemonic] = make_number ('='); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8792 plist[4] = intern (":coding-type"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8793 plist[5] = args[coding_arg_coding_type] = Qraw_text; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8794 plist[6] = intern (":ascii-compatible-p"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8795 plist[7] = args[coding_arg_ascii_compatible_p] = Qt; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8796 plist[8] = intern (":default-char"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8797 plist[9] = args[coding_arg_default_char] = make_number (0); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8798 plist[10] = intern (":docstring"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8799 plist[11] = build_string ("Do no conversion.\n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8800 \n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8801 When you visit a file with this coding, the file is read into a\n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8802 unibyte buffer as is, thus each byte of a file is treated as a\n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8803 character."); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8804 plist[12] = intern (":eol-type"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8805 plist[13] = args[coding_arg_eol_type] = Qunix; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8806 args[coding_arg_plist] = Flist (14, plist); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8807 Fdefine_coding_system_internal (coding_arg_max, args); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8808 } |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8809 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8810 setup_coding_system (Qno_conversion, &keyboard_coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8811 setup_coding_system (Qno_conversion, &terminal_coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8812 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
17052 | 8813 } |
8814 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8815 char * |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8816 emacs_strerror (error_number) |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8817 int error_number; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8818 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8819 char *str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8820 |
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
8821 synchronize_system_messages_locale (); |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8822 str = strerror (error_number); |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8823 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8824 if (! NILP (Vlocale_coding_system)) |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8825 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8826 Lisp_Object dec = code_convert_string_norecord (build_string (str), |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8827 Vlocale_coding_system, |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8828 0); |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8829 str = (char *) XSTRING (dec)->data; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8830 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8831 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8832 return str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8833 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8834 |
17052 | 8835 #endif /* emacs */ |