Mercurial > emacs
annotate src/coding.c @ 88590:ac9b0ae4c5a0
If CODE1 is nil, use the minimum code of the charset.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 21 May 2002 05:39:08 +0000 |
parents | 11186ff7ea0d |
children | 74b74f59bc09 |
rev | line source |
---|---|
17052 | 1 /* Coding system handler (conversion, detection, and 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. |
38518
883da5f3dbac
(code_convert_region): Handle the multibyte case if
Gerd Moellmann <gerd@gnu.org>
parents:
38473
diff
changeset
|
4 Copyright (C) 2001 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 | |
97 used by Chinese (mainly in Taiwan and Hong Kong). Details are | |
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 | |
111 A coding system for a 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 |
147 CODING conforms to the format of XXX. Return 1 if the data contains | |
148 a byte sequence which can be decoded into non-ASCII characters by | |
149 the coding system. Otherwize (i.e. the data contains only ASCII | |
150 characters or invalid sequence) return 0. | |
151 | |
152 It also resets some bits of an integer pointed by MASK. The macros | |
153 CATEGORY_MASK_XXX specifies each bit of this integer. | |
154 | |
155 Below is the template of these functions. */ | |
156 | |
17052 | 157 #if 0 |
88365 | 158 static int |
159 detect_coding_XXX (coding, mask) | |
160 struct coding_system *coding; | |
161 int *mask; | |
17052 | 162 { |
88365 | 163 unsigned char *src = coding->source; |
164 unsigned char *src_end = coding->source + coding->src_bytes; | |
165 int multibytep = coding->src_multibyte; | |
166 int c; | |
167 int found = 0; | |
168 ...; | |
169 | |
170 while (1) | |
171 { | |
172 /* Get one byte from the source. If the souce is exausted, jump | |
173 to no_more_source:. */ | |
174 ONE_MORE_BYTE (c); | |
175 /* Check if it conforms to XXX. If not, break the loop. */ | |
176 } | |
177 /* As the data is invalid for XXX, reset a proper bits. */ | |
178 *mask &= ~CODING_CATEGORY_XXX; | |
179 return 0; | |
180 no_more_source: | |
181 /* The source exausted. */ | |
182 if (!found) | |
183 /* ASCII characters only. */ | |
184 return 0; | |
185 /* Some data should be decoded into non-ASCII characters. */ | |
186 *mask &= CODING_CATEGORY_XXX; | |
187 return 1; | |
17052 | 188 } |
189 #endif | |
190 | |
191 /*** GENERAL NOTES on `decode_coding_XXX ()' functions *** | |
192 | |
88365 | 193 These functions decode a byte sequence specified as a source by |
194 CODING. The resulting multibyte text goes to a place pointed to by | |
195 CODING->charbuf, the length of which should not exceed | |
196 CODING->charbuf_size; | |
197 | |
198 These functions set the information of original and decoded texts in | |
199 CODING->consumed, CODING->consumed_char, and CODING->charbuf_used. | |
200 They also set CODING->result to one of CODING_RESULT_XXX indicating | |
201 how the decoding is finished. | |
202 | |
203 Below is the template of these functions. */ | |
204 | |
17052 | 205 #if 0 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
206 static void |
88365 | 207 decode_coding_XXXX (coding) |
17052 | 208 struct coding_system *coding; |
209 { | |
88365 | 210 unsigned char *src = coding->source + coding->consumed; |
211 unsigned char *src_end = coding->source + coding->src_bytes; | |
212 /* SRC_BASE remembers the start position in source in each loop. | |
213 The loop will be exited when there's not enough source code, or | |
214 when there's no room in CHARBUF for a decoded character. */ | |
215 unsigned char *src_base; | |
216 /* A buffer to produce decoded characters. */ | |
217 int *charbuf = coding->charbuf; | |
218 int *charbuf_end = charbuf + coding->charbuf_size; | |
219 int multibytep = coding->src_multibyte; | |
220 | |
221 while (1) | |
222 { | |
223 src_base = src; | |
224 if (charbuf < charbuf_end) | |
225 /* No more room to produce a decoded character. */ | |
226 break; | |
227 ONE_MORE_BYTE (c); | |
228 /* Decode it. */ | |
229 } | |
230 | |
231 no_more_source: | |
232 if (src_base < src_end | |
233 && coding->mode & CODING_MODE_LAST_BLOCK) | |
234 /* If the source ends by partial bytes to construct a character, | |
235 treat them as eight-bit raw data. */ | |
236 while (src_base < src_end && charbuf < charbuf_end) | |
237 *charbuf++ = *src_base++; | |
238 /* Remember how many bytes and characters we consumed. If the | |
239 source is multibyte, the bytes and chars are not identical. */ | |
240 coding->consumed = coding->consumed_char = src_base - coding->source; | |
241 /* Remember how many characters we produced. */ | |
242 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 243 } |
244 #endif | |
245 | |
246 /*** GENERAL NOTES on `encode_coding_XXX ()' functions *** | |
247 | |
88365 | 248 These functions encode SRC_BYTES length text at SOURCE of Emacs' |
249 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
|
250 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
|
251 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
|
252 |
88365 | 253 These functions set the information of original and encoded texts in |
254 the members produced, produced_char, consumed, and consumed_char of | |
255 the structure *CODING. They also set the member result to one of | |
256 CODING_RESULT_XXX indicating how the encoding finished. | |
257 | |
258 DST_BYTES zero means that source area and destination area are | |
259 overlapped, which means that we can produce a encoded text until it | |
260 reaches at the head of not-yet-encoded source text. | |
261 | |
262 Below is a template of these functions. */ | |
17052 | 263 #if 0 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
264 static void |
88365 | 265 encode_coding_XXX (coding) |
17052 | 266 struct coding_system *coding; |
267 { | |
88365 | 268 int multibytep = coding->dst_multibyte; |
269 int *charbuf = coding->charbuf; | |
270 int *charbuf_end = charbuf->charbuf + coding->charbuf_used; | |
271 unsigned char *dst = coding->destination + coding->produced; | |
272 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
273 unsigned char *adjusted_dst_end = dst_end - _MAX_BYTES_PRODUCED_IN_LOOP_; | |
274 int produced_chars = 0; | |
275 | |
276 for (; charbuf < charbuf_end && dst < adjusted_dst_end; charbuf++) | |
277 { | |
278 int c = *charbuf; | |
279 /* Encode C into DST, and increment DST. */ | |
280 } | |
281 label_no_more_destination: | |
282 /* How many chars and bytes we produced. */ | |
283 coding->produced_char += produced_chars; | |
284 coding->produced = dst - coding->destination; | |
17052 | 285 } |
286 #endif | |
287 | |
288 | |
289 /*** 1. Preamble ***/ | |
290 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
291 #include <config.h> |
17052 | 292 #include <stdio.h> |
293 | |
294 #include "lisp.h" | |
295 #include "buffer.h" | |
88365 | 296 #include "character.h" |
17052 | 297 #include "charset.h" |
88365 | 298 #include "ccl.h" |
26847 | 299 #include "composite.h" |
17052 | 300 #include "coding.h" |
301 #include "window.h" | |
302 | |
88365 | 303 Lisp_Object Vcoding_system_hash_table; |
304 | |
305 Lisp_Object Qcoding_system, Qcoding_aliases, Qeol_type; | |
306 Lisp_Object Qunix, Qdos, Qmac; | |
17052 | 307 Lisp_Object Qbuffer_file_coding_system; |
308 Lisp_Object Qpost_read_conversion, Qpre_write_conversion; | |
88365 | 309 Lisp_Object Qdefault_char; |
19612
783efd6c7c1e
(Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents:
19546
diff
changeset
|
310 Lisp_Object Qno_conversion, Qundecided; |
88365 | 311 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; |
312 Lisp_Object Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig, Qutf_16_le; | |
313 Lisp_Object Qsignature, Qendian, Qbig, Qlittle; | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
314 Lisp_Object Qcoding_system_history; |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
315 Lisp_Object Qvalid_codes; |
17052 | 316 |
317 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | |
318 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | |
319 Lisp_Object Qstart_process, Qopen_network_stream; | |
320 Lisp_Object Qtarget_idx; | |
321 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
322 Lisp_Object Vselect_safe_coding_system_function; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
323 |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
324 /* 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
|
325 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
|
326 /* Mnemonic string to indicate format of end-of-line is not yet |
17052 | 327 decided. */ |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
328 Lisp_Object eol_mnemonic_undecided; |
17052 | 329 |
330 #ifdef emacs | |
331 | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
332 Lisp_Object Vcoding_system_list, Vcoding_system_alist; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
333 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
334 Lisp_Object Qcoding_system_p, Qcoding_system_error; |
17052 | 335 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
336 /* 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
|
337 end-of-line format. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
338 Lisp_Object Qemacs_mule, Qraw_text; |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
339 |
17052 | 340 /* Coding-systems are handed between Emacs Lisp programs and C internal |
341 routines by the following three variables. */ | |
342 /* Coding-system for reading files and receiving data from process. */ | |
343 Lisp_Object Vcoding_system_for_read; | |
344 /* Coding-system for writing files and sending data to process. */ | |
345 Lisp_Object Vcoding_system_for_write; | |
346 /* Coding-system actually used in the latest I/O. */ | |
347 Lisp_Object Vlast_coding_system_used; | |
348 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
349 /* A vector of length 256 which contains information about special |
22529 | 350 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
|
351 Lisp_Object Vlatin_extra_code_table; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
352 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
353 /* 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
|
354 int inhibit_eol_conversion; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
355 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
356 /* Flag to inhibit ISO2022 escape sequence detection. */ |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
357 int inhibit_iso_escape_detection; |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
358 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
359 /* 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
|
360 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
|
361 |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
362 /* Coding system to be used to encode text for terminal display. */ |
17052 | 363 struct coding_system terminal_coding; |
364 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
365 /* 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
|
366 terminal coding system is nil. */ |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
367 struct coding_system safe_terminal_coding; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
368 |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
369 /* Coding system of what is sent from terminal keyboard. */ |
17052 | 370 struct coding_system keyboard_coding; |
371 | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
372 Lisp_Object Vfile_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
373 Lisp_Object Vprocess_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
374 Lisp_Object Vnetwork_coding_system_alist; |
17052 | 375 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
376 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
|
377 |
17052 | 378 #endif /* emacs */ |
379 | |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
380 /* 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
|
381 conversion. */ |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
382 Lisp_Object Venable_character_translation; |
22186
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 decoding (reading). */ |
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_decode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
385 /* 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
|
386 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
|
387 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
388 Lisp_Object Qtranslation_table; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
389 Lisp_Object Qtranslation_table_id; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
390 Lisp_Object Qtranslation_table_for_decode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
391 Lisp_Object Qtranslation_table_for_encode; |
17052 | 392 |
393 /* Alist of charsets vs revision number. */ | |
88365 | 394 static Lisp_Object Vcharset_revision_table; |
17052 | 395 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
396 /* Default coding systems used for process I/O. */ |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
397 Lisp_Object Vdefault_process_coding_system; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
398 |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
399 /* 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
|
400 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
|
401 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
|
402 to avoid infinite recursive call. */ |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
403 static int inhibit_pre_post_conversion; |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
404 |
88365 | 405 /* Two special coding systems. */ |
406 Lisp_Object Vsjis_coding_system; | |
407 Lisp_Object Vbig5_coding_system; | |
408 | |
409 | |
410 static int detect_coding_utf_8 P_ ((struct coding_system *, int *)); | |
411 static void decode_coding_utf_8 P_ ((struct coding_system *)); | |
412 static int encode_coding_utf_8 P_ ((struct coding_system *)); | |
413 | |
414 static int detect_coding_utf_16 P_ ((struct coding_system *, int *)); | |
415 static void decode_coding_utf_16 P_ ((struct coding_system *)); | |
416 static int encode_coding_utf_16 P_ ((struct coding_system *)); | |
417 | |
418 static int detect_coding_iso_2022 P_ ((struct coding_system *, int *)); | |
419 static void decode_coding_iso_2022 P_ ((struct coding_system *)); | |
420 static int encode_coding_iso_2022 P_ ((struct coding_system *)); | |
421 | |
422 static int detect_coding_emacs_mule P_ ((struct coding_system *, int *)); | |
423 static void decode_coding_emacs_mule P_ ((struct coding_system *)); | |
424 static int encode_coding_emacs_mule P_ ((struct coding_system *)); | |
425 | |
426 static int detect_coding_sjis P_ ((struct coding_system *, int *)); | |
427 static void decode_coding_sjis P_ ((struct coding_system *)); | |
428 static int encode_coding_sjis P_ ((struct coding_system *)); | |
429 | |
430 static int detect_coding_big5 P_ ((struct coding_system *, int *)); | |
431 static void decode_coding_big5 P_ ((struct coding_system *)); | |
432 static int encode_coding_big5 P_ ((struct coding_system *)); | |
433 | |
434 static int detect_coding_ccl P_ ((struct coding_system *, int *)); | |
435 static void decode_coding_ccl P_ ((struct coding_system *)); | |
436 static int encode_coding_ccl P_ ((struct coding_system *)); | |
437 | |
438 static void decode_coding_raw_text P_ ((struct coding_system *)); | |
439 static int encode_coding_raw_text P_ ((struct coding_system *)); | |
440 | |
441 | |
442 /* ISO2022 section */ | |
443 | |
444 #define CODING_ISO_INITIAL(coding, reg) \ | |
445 (XINT (AREF (AREF (CODING_ID_ATTRS ((coding)->id), \ | |
446 coding_attr_iso_initial), \ | |
447 reg))) | |
448 | |
449 | |
450 #define CODING_ISO_REQUEST(coding, charset_id) \ | |
451 ((charset_id <= (coding)->max_charset_id \ | |
452 ? (coding)->safe_charsets[charset_id] \ | |
453 : -1)) | |
454 | |
455 | |
456 #define CODING_ISO_FLAGS(coding) \ | |
457 ((coding)->spec.iso_2022.flags) | |
458 #define CODING_ISO_DESIGNATION(coding, reg) \ | |
459 ((coding)->spec.iso_2022.current_designation[reg]) | |
460 #define CODING_ISO_INVOCATION(coding, plane) \ | |
461 ((coding)->spec.iso_2022.current_invocation[plane]) | |
462 #define CODING_ISO_SINGLE_SHIFTING(coding) \ | |
463 ((coding)->spec.iso_2022.single_shifting) | |
464 #define CODING_ISO_BOL(coding) \ | |
465 ((coding)->spec.iso_2022.bol) | |
466 #define CODING_ISO_INVOKED_CHARSET(coding, plane) \ | |
467 CODING_ISO_DESIGNATION ((coding), CODING_ISO_INVOCATION ((coding), (plane))) | |
468 | |
469 /* Control characters of ISO2022. */ | |
470 /* code */ /* function */ | |
471 #define ISO_CODE_LF 0x0A /* line-feed */ | |
472 #define ISO_CODE_CR 0x0D /* carriage-return */ | |
473 #define ISO_CODE_SO 0x0E /* shift-out */ | |
474 #define ISO_CODE_SI 0x0F /* shift-in */ | |
475 #define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */ | |
476 #define ISO_CODE_ESC 0x1B /* escape */ | |
477 #define ISO_CODE_SS2 0x8E /* single-shift-2 */ | |
478 #define ISO_CODE_SS3 0x8F /* single-shift-3 */ | |
479 #define ISO_CODE_CSI 0x9B /* control-sequence-introducer */ | |
480 | |
481 /* All code (1-byte) of ISO2022 is classified into one of the | |
482 followings. */ | |
483 enum iso_code_class_type | |
484 { | |
485 ISO_control_0, /* Control codes in the range | |
486 0x00..0x1F and 0x7F, except for the | |
487 following 5 codes. */ | |
488 ISO_carriage_return, /* ISO_CODE_CR (0x0D) */ | |
489 ISO_shift_out, /* ISO_CODE_SO (0x0E) */ | |
490 ISO_shift_in, /* ISO_CODE_SI (0x0F) */ | |
491 ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ | |
492 ISO_escape, /* ISO_CODE_SO (0x1B) */ | |
493 ISO_control_1, /* Control codes in the range | |
494 0x80..0x9F, except for the | |
495 following 3 codes. */ | |
496 ISO_single_shift_2, /* ISO_CODE_SS2 (0x8E) */ | |
497 ISO_single_shift_3, /* ISO_CODE_SS3 (0x8F) */ | |
498 ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */ | |
499 ISO_0x20_or_0x7F, /* Codes of the values 0x20 or 0x7F. */ | |
500 ISO_graphic_plane_0, /* Graphic codes in the range 0x21..0x7E. */ | |
501 ISO_0xA0_or_0xFF, /* Codes of the values 0xA0 or 0xFF. */ | |
502 ISO_graphic_plane_1 /* Graphic codes in the range 0xA1..0xFE. */ | |
503 }; | |
504 | |
505 /** The macros CODING_ISO_FLAG_XXX defines a flag bit of the | |
506 `iso-flags' attribute of an iso2022 coding system. */ | |
507 | |
508 /* If set, produce long-form designation sequence (e.g. ESC $ ( A) | |
509 instead of the correct short-form sequence (e.g. ESC $ A). */ | |
510 #define CODING_ISO_FLAG_LONG_FORM 0x0001 | |
511 | |
512 /* If set, reset graphic planes and registers at end-of-line to the | |
513 initial state. */ | |
514 #define CODING_ISO_FLAG_RESET_AT_EOL 0x0002 | |
515 | |
516 /* If set, reset graphic planes and registers before any control | |
517 characters to the initial state. */ | |
518 #define CODING_ISO_FLAG_RESET_AT_CNTL 0x0004 | |
519 | |
520 /* If set, encode by 7-bit environment. */ | |
521 #define CODING_ISO_FLAG_SEVEN_BITS 0x0008 | |
522 | |
523 /* If set, use locking-shift function. */ | |
524 #define CODING_ISO_FLAG_LOCKING_SHIFT 0x0010 | |
525 | |
526 /* If set, use single-shift function. Overwrite | |
527 CODING_ISO_FLAG_LOCKING_SHIFT. */ | |
528 #define CODING_ISO_FLAG_SINGLE_SHIFT 0x0020 | |
529 | |
530 /* If set, use designation escape sequence. */ | |
531 #define CODING_ISO_FLAG_DESIGNATION 0x0040 | |
532 | |
533 /* If set, produce revision number sequence. */ | |
534 #define CODING_ISO_FLAG_REVISION 0x0080 | |
535 | |
536 /* If set, produce ISO6429's direction specifying sequence. */ | |
537 #define CODING_ISO_FLAG_DIRECTION 0x0100 | |
538 | |
539 /* If set, assume designation states are reset at beginning of line on | |
540 output. */ | |
541 #define CODING_ISO_FLAG_INIT_AT_BOL 0x0200 | |
542 | |
543 /* If set, designation sequence should be placed at beginning of line | |
544 on output. */ | |
545 #define CODING_ISO_FLAG_DESIGNATE_AT_BOL 0x0400 | |
546 | |
547 /* If set, do not encode unsafe charactes on output. */ | |
548 #define CODING_ISO_FLAG_SAFE 0x0800 | |
549 | |
550 /* If set, extra latin codes (128..159) are accepted as a valid code | |
551 on input. */ | |
552 #define CODING_ISO_FLAG_LATIN_EXTRA 0x1000 | |
553 | |
554 #define CODING_ISO_FLAG_COMPOSITION 0x2000 | |
555 | |
556 #define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 | |
557 | |
558 #define CODING_ISO_FLAG_FULL_SUPPORT 0x8000 | |
559 | |
560 /* A character to be produced on output if encoding of the original | |
561 character is prohibited by CODING_ISO_FLAG_SAFE. */ | |
562 #define CODING_INHIBIT_CHARACTER_SUBSTITUTION '?' | |
563 | |
564 | |
565 /* UTF-16 section */ | |
566 #define CODING_UTF_16_BOM(coding) \ | |
567 ((coding)->spec.utf_16.bom) | |
568 | |
569 #define CODING_UTF_16_ENDIAN(coding) \ | |
570 ((coding)->spec.utf_16.endian) | |
571 | |
572 #define CODING_UTF_16_SURROGATE(coding) \ | |
573 ((coding)->spec.utf_16.surrogate) | |
574 | |
575 | |
576 /* CCL section */ | |
577 #define CODING_CCL_DECODER(coding) \ | |
578 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_decoder) | |
579 #define CODING_CCL_ENCODER(coding) \ | |
580 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_encoder) | |
581 #define CODING_CCL_VALIDS(coding) \ | |
582 (XSTRING (AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_valids)) \ | |
583 ->data) | |
584 | |
585 /* Index for each coding category in `coding_category_table' */ | |
586 | |
587 enum coding_category | |
588 { | |
589 coding_category_iso_7, | |
590 coding_category_iso_7_tight, | |
591 coding_category_iso_8_1, | |
592 coding_category_iso_8_2, | |
593 coding_category_iso_7_else, | |
594 coding_category_iso_8_else, | |
595 coding_category_utf_8, | |
596 coding_category_utf_16_auto, | |
597 coding_category_utf_16_be, | |
598 coding_category_utf_16_le, | |
599 coding_category_utf_16_be_nosig, | |
600 coding_category_utf_16_le_nosig, | |
601 coding_category_charset, | |
602 coding_category_sjis, | |
603 coding_category_big5, | |
604 coding_category_ccl, | |
605 coding_category_emacs_mule, | |
606 /* All above are targets of code detection. */ | |
607 coding_category_raw_text, | |
608 coding_category_undecided, | |
609 coding_category_max | |
610 }; | |
611 | |
612 /* Definitions of flag bits used in detect_coding_XXXX. */ | |
613 #define CATEGORY_MASK_ISO_7 (1 << coding_category_iso_7) | |
614 #define CATEGORY_MASK_ISO_7_TIGHT (1 << coding_category_iso_7_tight) | |
615 #define CATEGORY_MASK_ISO_8_1 (1 << coding_category_iso_8_1) | |
616 #define CATEGORY_MASK_ISO_8_2 (1 << coding_category_iso_8_2) | |
617 #define CATEGORY_MASK_ISO_7_ELSE (1 << coding_category_iso_7_else) | |
618 #define CATEGORY_MASK_ISO_8_ELSE (1 << coding_category_iso_8_else) | |
619 #define CATEGORY_MASK_UTF_8 (1 << coding_category_utf_8) | |
620 #define CATEGORY_MASK_UTF_16_BE (1 << coding_category_utf_16_be) | |
621 #define CATEGORY_MASK_UTF_16_LE (1 << coding_category_utf_16_le) | |
622 #define CATEGORY_MASK_UTF_16_BE_NOSIG (1 << coding_category_utf_16_be_nosig) | |
623 #define CATEGORY_MASK_UTF_16_LE_NOSIG (1 << coding_category_utf_16_le_nosig) | |
624 #define CATEGORY_MASK_CHARSET (1 << coding_category_charset) | |
625 #define CATEGORY_MASK_SJIS (1 << coding_category_sjis) | |
626 #define CATEGORY_MASK_BIG5 (1 << coding_category_big5) | |
627 #define CATEGORY_MASK_CCL (1 << coding_category_ccl) | |
628 #define CATEGORY_MASK_EMACS_MULE (1 << coding_category_emacs_mule) | |
629 | |
630 /* This value is returned if detect_coding_mask () find nothing other | |
631 than ASCII characters. */ | |
632 #define CATEGORY_MASK_ANY \ | |
633 (CATEGORY_MASK_ISO_7 \ | |
634 | CATEGORY_MASK_ISO_7_TIGHT \ | |
635 | CATEGORY_MASK_ISO_8_1 \ | |
636 | CATEGORY_MASK_ISO_8_2 \ | |
637 | CATEGORY_MASK_ISO_7_ELSE \ | |
638 | CATEGORY_MASK_ISO_8_ELSE \ | |
639 | CATEGORY_MASK_UTF_8 \ | |
640 | CATEGORY_MASK_UTF_16_BE \ | |
641 | CATEGORY_MASK_UTF_16_LE \ | |
642 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
643 | CATEGORY_MASK_UTF_16_LE_NOSIG \ | |
644 | CATEGORY_MASK_CHARSET \ | |
645 | CATEGORY_MASK_SJIS \ | |
646 | CATEGORY_MASK_BIG5 \ | |
647 | CATEGORY_MASK_CCL \ | |
648 | CATEGORY_MASK_EMACS_MULE) | |
649 | |
650 | |
651 #define CATEGORY_MASK_ISO_7BIT \ | |
652 (CATEGORY_MASK_ISO_7 | CATEGORY_MASK_ISO_7_TIGHT) | |
653 | |
654 #define CATEGORY_MASK_ISO_8BIT \ | |
655 (CATEGORY_MASK_ISO_8_1 | CATEGORY_MASK_ISO_8_2) | |
656 | |
657 #define CATEGORY_MASK_ISO_ELSE \ | |
658 (CATEGORY_MASK_ISO_7_ELSE | CATEGORY_MASK_ISO_8_ELSE) | |
659 | |
660 #define CATEGORY_MASK_ISO_ESCAPE \ | |
661 (CATEGORY_MASK_ISO_7 \ | |
662 | CATEGORY_MASK_ISO_7_TIGHT \ | |
663 | CATEGORY_MASK_ISO_7_ELSE \ | |
664 | CATEGORY_MASK_ISO_8_ELSE) | |
665 | |
666 #define CATEGORY_MASK_ISO \ | |
667 ( CATEGORY_MASK_ISO_7BIT \ | |
668 | CATEGORY_MASK_ISO_8BIT \ | |
669 | CATEGORY_MASK_ISO_ELSE) | |
670 | |
671 #define CATEGORY_MASK_UTF_16 \ | |
672 (CATEGORY_MASK_UTF_16_BE \ | |
673 | CATEGORY_MASK_UTF_16_LE \ | |
674 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
675 | CATEGORY_MASK_UTF_16_LE_NOSIG) | |
676 | |
677 | |
678 /* List of symbols `coding-category-xxx' ordered by priority. This | |
679 variable is exposed to Emacs Lisp. */ | |
680 static Lisp_Object Vcoding_category_list; | |
681 | |
682 /* Table of coding categories (Lisp symbols). This variable is for | |
683 internal use oly. */ | |
684 static Lisp_Object Vcoding_category_table; | |
685 | |
686 /* Table of coding-categories ordered by priority. */ | |
687 static enum coding_category coding_priorities[coding_category_max]; | |
688 | |
689 /* Nth element is a coding context for the coding system bound to the | |
690 Nth coding category. */ | |
691 static struct coding_system coding_categories[coding_category_max]; | |
692 | |
693 static int detected_mask[coding_category_raw_text] = | |
694 { CATEGORY_MASK_ISO, | |
695 CATEGORY_MASK_ISO, | |
696 CATEGORY_MASK_ISO, | |
697 CATEGORY_MASK_ISO, | |
698 CATEGORY_MASK_ISO, | |
699 CATEGORY_MASK_ISO, | |
700 CATEGORY_MASK_UTF_8, | |
701 CATEGORY_MASK_UTF_16, | |
702 CATEGORY_MASK_UTF_16, | |
703 CATEGORY_MASK_UTF_16, | |
704 CATEGORY_MASK_UTF_16, | |
705 CATEGORY_MASK_UTF_16, | |
706 CATEGORY_MASK_CHARSET, | |
707 CATEGORY_MASK_SJIS, | |
708 CATEGORY_MASK_BIG5, | |
709 CATEGORY_MASK_CCL, | |
710 CATEGORY_MASK_EMACS_MULE | |
711 }; | |
712 | |
713 /*** Commonly used macros and functions ***/ | |
714 | |
715 #ifndef min | |
716 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
717 #endif | |
718 #ifndef max | |
719 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
720 #endif | |
721 | |
722 #define CODING_GET_INFO(coding, attrs, eol_type, charset_list) \ | |
723 do { \ | |
724 attrs = CODING_ID_ATTRS (coding->id); \ | |
725 eol_type = CODING_ID_EOL_TYPE (coding->id); \ | |
726 if (VECTORP (eol_type)) \ | |
727 eol_type = Qunix; \ | |
728 charset_list = CODING_ATTR_CHARSET_LIST (attrs); \ | |
729 } while (0) | |
730 | |
731 | |
732 /* Safely get one byte from the source text pointed by SRC which ends | |
733 at SRC_END, and set C to that byte. If there are not enough bytes | |
734 in the source, it jumps to `no_more_source'. The caller | |
735 should declare and set these variables appropriately in advance: | |
736 src, src_end, multibytep | |
737 */ | |
738 | |
739 #define ONE_MORE_BYTE(c) \ | |
740 do { \ | |
741 if (src == src_end) \ | |
742 { \ | |
743 if (src_base < src) \ | |
744 coding->result = CODING_RESULT_INSUFFICIENT_SRC; \ | |
745 goto no_more_source; \ | |
746 } \ | |
747 c = *src++; \ | |
748 if (multibytep && (c & 0x80)) \ | |
749 { \ | |
750 if ((c & 0xFE) != 0xC0) \ | |
751 error ("Undecodable char found"); \ | |
752 c = ((c & 1) << 6) | *src++; \ | |
753 } \ | |
754 consumed_chars++; \ | |
755 } while (0) | |
756 | |
757 | |
758 #define ONE_MORE_BYTE_NO_CHECK(c) \ | |
759 do { \ | |
760 c = *src++; \ | |
761 if (multibytep && (c & 0x80)) \ | |
762 { \ | |
763 if ((c & 0xFE) != 0xC0) \ | |
764 error ("Undecodable char found"); \ | |
765 c = ((c & 1) << 6) | *src++; \ | |
766 } \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
767 consumed_chars++; \ |
88365 | 768 } while (0) |
769 | |
770 | |
771 /* Store a byte C in the place pointed by DST and increment DST to the | |
772 next free point, and increment PRODUCED_CHARS. The caller should | |
773 assure that C is 0..127, and declare and set the variable `dst' | |
774 appropriately in advance. | |
775 */ | |
776 | |
777 | |
778 #define EMIT_ONE_ASCII_BYTE(c) \ | |
779 do { \ | |
780 produced_chars++; \ | |
781 *dst++ = (c); \ | |
782 } while (0) | |
783 | |
784 | |
785 /* Like EMIT_ONE_ASCII_BYTE byt store two bytes; C1 and C2. */ | |
786 | |
787 #define EMIT_TWO_ASCII_BYTES(c1, c2) \ | |
788 do { \ | |
789 produced_chars += 2; \ | |
790 *dst++ = (c1), *dst++ = (c2); \ | |
791 } while (0) | |
792 | |
793 | |
794 /* Store a byte C in the place pointed by DST and increment DST to the | |
795 next free point, and increment PRODUCED_CHARS. If MULTIBYTEP is | |
796 nonzero, store in an appropriate multibyte from. The caller should | |
797 declare and set the variables `dst' and `multibytep' appropriately | |
798 in advance. */ | |
799 | |
800 #define EMIT_ONE_BYTE(c) \ | |
801 do { \ | |
802 produced_chars++; \ | |
803 if (multibytep) \ | |
804 { \ | |
805 int ch = (c); \ | |
806 if (ch >= 0x80) \ | |
807 ch = BYTE8_TO_CHAR (ch); \ | |
808 CHAR_STRING_ADVANCE (ch, dst); \ | |
809 } \ | |
810 else \ | |
811 *dst++ = (c); \ | |
812 } while (0) | |
813 | |
814 | |
815 /* Like EMIT_ONE_BYTE, but emit two bytes; C1 and C2. */ | |
816 | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
817 #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
|
818 do { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
819 produced_chars += 2; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
820 if (multibytep) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
821 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
822 int ch; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
823 \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
824 ch = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
825 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
826 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
827 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
828 ch = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
829 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
830 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
831 CHAR_STRING_ADVANCE (ch, dst); \ |
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 else \ |
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 *dst++ = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
836 *dst++ = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
837 } \ |
88365 | 838 } while (0) |
839 | |
840 | |
841 #define EMIT_THREE_BYTES(c1, c2, c3) \ | |
842 do { \ | |
843 EMIT_ONE_BYTE (c1); \ | |
844 EMIT_TWO_BYTES (c2, c3); \ | |
845 } while (0) | |
846 | |
847 | |
848 #define EMIT_FOUR_BYTES(c1, c2, c3, c4) \ | |
849 do { \ | |
850 EMIT_TWO_BYTES (c1, c2); \ | |
851 EMIT_TWO_BYTES (c3, c4); \ | |
852 } while (0) | |
853 | |
854 | |
855 #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ | |
856 do { \ | |
857 charset_map_loaded = 0; \ | |
858 c = DECODE_CHAR (charset, code); \ | |
859 if (charset_map_loaded) \ | |
860 { \ | |
861 unsigned char *orig = coding->source; \ | |
862 EMACS_INT offset; \ | |
863 \ | |
864 coding_set_source (coding); \ | |
865 offset = coding->source - orig; \ | |
866 src += offset; \ | |
867 src_base += offset; \ | |
868 src_end += offset; \ | |
869 } \ | |
870 } while (0) | |
871 | |
872 | |
873 #define ASSURE_DESTINATION(bytes) \ | |
874 do { \ | |
875 if (dst + (bytes) >= dst_end) \ | |
876 { \ | |
877 int more_bytes = charbuf_end - charbuf + (bytes); \ | |
878 \ | |
879 dst = alloc_destination (coding, more_bytes, dst); \ | |
880 dst_end = coding->destination + coding->dst_bytes; \ | |
881 } \ | |
882 } while (0) | |
883 | |
884 | |
885 | |
886 static void | |
887 coding_set_source (coding) | |
888 struct coding_system *coding; | |
889 { | |
890 if (BUFFERP (coding->src_object)) | |
891 { | |
892 if (coding->src_pos < 0) | |
893 coding->source = GAP_END_ADDR + coding->src_pos_byte; | |
894 else | |
895 { | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
896 struct buffer *buf = XBUFFER (coding->src_object); |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
897 EMACS_INT gpt_byte = BUF_GPT_BYTE (buf); |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
898 unsigned char *beg_addr = BUF_BEG_ADDR (buf); |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
899 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
900 coding->source = beg_addr + coding->src_pos_byte - 1; |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
901 if (coding->src_pos_byte >= gpt_byte) |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
902 coding->source += BUF_GAP_SIZE (buf); |
88365 | 903 } |
904 } | |
905 else if (STRINGP (coding->src_object)) | |
906 { | |
907 coding->source = (XSTRING (coding->src_object)->data | |
908 + coding->src_pos_byte); | |
909 } | |
910 else | |
911 /* Otherwise, the source is C string and is never relocated | |
912 automatically. Thus we don't have to update anything. */ | |
913 ; | |
914 } | |
915 | |
916 static void | |
917 coding_set_destination (coding) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
918 struct coding_system *coding; |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
919 { |
88365 | 920 if (BUFFERP (coding->dst_object)) |
921 { | |
922 /* We are sure that coding->dst_pos_byte is before the gap of the | |
923 buffer. */ | |
924 coding->destination = (BUF_BEG_ADDR (XBUFFER (coding->dst_object)) | |
925 + coding->dst_pos_byte - 1); | |
926 if (coding->src_pos < 0) | |
927 coding->dst_bytes = (GAP_END_ADDR | |
928 - (coding->src_bytes - coding->consumed) | |
929 - coding->destination); | |
930 else | |
931 coding->dst_bytes = (BUF_GAP_END_ADDR (XBUFFER (coding->dst_object)) | |
932 - coding->destination); | |
933 } | |
934 else | |
935 /* Otherwise, the destination is C string and is never relocated | |
936 automatically. Thus we don't have to update anything. */ | |
937 ; | |
938 } | |
939 | |
940 | |
941 static void | |
942 coding_alloc_by_realloc (coding, bytes) | |
943 struct coding_system *coding; | |
944 EMACS_INT bytes; | |
945 { | |
946 coding->destination = (unsigned char *) xrealloc (coding->destination, | |
947 coding->dst_bytes + bytes); | |
948 coding->dst_bytes += bytes; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
949 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
950 |
88365 | 951 static void |
952 coding_alloc_by_making_gap (coding, bytes) | |
953 struct coding_system *coding; | |
954 EMACS_INT bytes; | |
955 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
956 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
|
957 && EQ (coding->src_object, coding->dst_object)) |
88365 | 958 { |
959 EMACS_INT add = coding->src_bytes - coding->consumed; | |
960 | |
961 GAP_SIZE -= add; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add; | |
962 make_gap (bytes); | |
963 GAP_SIZE += add; ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add; | |
964 } | |
965 else | |
966 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
967 Lisp_Object this_buffer; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
968 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
969 this_buffer = Fcurrent_buffer (); |
88365 | 970 set_buffer_internal (XBUFFER (coding->dst_object)); |
971 make_gap (bytes); | |
972 set_buffer_internal (XBUFFER (this_buffer)); | |
973 } | |
974 } | |
975 | |
976 | |
977 static unsigned char * | |
978 alloc_destination (coding, nbytes, dst) | |
979 struct coding_system *coding; | |
980 int nbytes; | |
981 unsigned char *dst; | |
982 { | |
983 EMACS_INT offset = dst - coding->destination; | |
984 | |
985 if (BUFFERP (coding->dst_object)) | |
986 coding_alloc_by_making_gap (coding, nbytes); | |
987 else | |
988 coding_alloc_by_realloc (coding, nbytes); | |
989 coding->result = CODING_RESULT_SUCCESS; | |
990 coding_set_destination (coding); | |
991 dst = coding->destination + offset; | |
992 return dst; | |
993 } | |
994 | |
995 | |
996 /*** 2. Emacs' internal format (emacs-utf-8) ***/ | |
997 | |
998 | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
999 |
17052 | 1000 |
88365 | 1001 /*** 3. UTF-8 ***/ |
1002 | |
1003 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
1004 Check if a text is encoded in UTF-8. If it is, return | |
1005 CATEGORY_MASK_UTF_8, else return 0. */ | |
1006 | |
1007 #define UTF_8_1_OCTET_P(c) ((c) < 0x80) | |
1008 #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80) | |
1009 #define UTF_8_2_OCTET_LEADING_P(c) (((c) & 0xE0) == 0xC0) | |
1010 #define UTF_8_3_OCTET_LEADING_P(c) (((c) & 0xF0) == 0xE0) | |
1011 #define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0) | |
1012 #define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8) | |
1013 | |
1014 static int | |
1015 detect_coding_utf_8 (coding, mask) | |
1016 struct coding_system *coding; | |
1017 int *mask; | |
1018 { | |
1019 unsigned char *src = coding->source, *src_base = src; | |
1020 unsigned char *src_end = coding->source + coding->src_bytes; | |
1021 int multibytep = coding->src_multibyte; | |
1022 int consumed_chars = 0; | |
1023 int found = 0; | |
1024 | |
1025 /* A coding system of this category is always ASCII compatible. */ | |
1026 src += coding->head_ascii; | |
1027 | |
1028 while (1) | |
1029 { | |
1030 int c, c1, c2, c3, c4; | |
1031 | |
1032 ONE_MORE_BYTE (c); | |
1033 if (UTF_8_1_OCTET_P (c)) | |
1034 continue; | |
1035 ONE_MORE_BYTE (c1); | |
1036 if (! UTF_8_EXTRA_OCTET_P (c1)) | |
1037 break; | |
1038 if (UTF_8_2_OCTET_LEADING_P (c)) | |
1039 { | |
1040 found++; | |
1041 continue; | |
1042 } | |
1043 ONE_MORE_BYTE (c2); | |
1044 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
1045 break; | |
1046 if (UTF_8_3_OCTET_LEADING_P (c)) | |
1047 { | |
1048 found++; | |
1049 continue; | |
1050 } | |
1051 ONE_MORE_BYTE (c3); | |
1052 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
1053 break; | |
1054 if (UTF_8_4_OCTET_LEADING_P (c)) | |
1055 { | |
1056 found++; | |
1057 continue; | |
1058 } | |
1059 ONE_MORE_BYTE (c4); | |
1060 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
1061 break; | |
1062 if (UTF_8_5_OCTET_LEADING_P (c)) | |
1063 { | |
1064 found++; | |
1065 continue; | |
1066 } | |
1067 break; | |
1068 } | |
1069 *mask &= ~CATEGORY_MASK_UTF_8; | |
1070 return 0; | |
1071 | |
1072 no_more_source: | |
1073 if (! found) | |
1074 return 0; | |
1075 *mask &= CATEGORY_MASK_UTF_8; | |
1076 return 1; | |
1077 } | |
1078 | |
1079 | |
1080 static void | |
1081 decode_coding_utf_8 (coding) | |
1082 struct coding_system *coding; | |
1083 { | |
1084 unsigned char *src = coding->source + coding->consumed; | |
1085 unsigned char *src_end = coding->source + coding->src_bytes; | |
1086 unsigned char *src_base; | |
1087 int *charbuf = coding->charbuf; | |
1088 int *charbuf_end = charbuf + coding->charbuf_size; | |
1089 int consumed_chars = 0, consumed_chars_base; | |
1090 int multibytep = coding->src_multibyte; | |
1091 Lisp_Object attr, eol_type, charset_list; | |
1092 | |
1093 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
1094 | |
1095 while (1) | |
1096 { | |
1097 int c, c1, c2, c3, c4, c5; | |
1098 | |
1099 src_base = src; | |
1100 consumed_chars_base = consumed_chars; | |
1101 | |
1102 if (charbuf >= charbuf_end) | |
1103 break; | |
1104 | |
1105 ONE_MORE_BYTE (c1); | |
1106 if (UTF_8_1_OCTET_P(c1)) | |
1107 { | |
1108 c = c1; | |
1109 if (c == '\r') | |
1110 { | |
1111 if (EQ (eol_type, Qdos)) | |
1112 { | |
1113 if (src == src_end) | |
1114 goto no_more_source; | |
1115 if (*src == '\n') | |
1116 ONE_MORE_BYTE (c); | |
1117 } | |
1118 else if (EQ (eol_type, Qmac)) | |
1119 c = '\n'; | |
1120 } | |
1121 } | |
1122 else | |
1123 { | |
1124 ONE_MORE_BYTE (c2); | |
1125 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
1126 goto invalid_code; | |
1127 if (UTF_8_2_OCTET_LEADING_P (c1)) | |
1128 c = ((c1 & 0x1F) << 6) | (c2 & 0x3F); | |
1129 else | |
1130 { | |
1131 ONE_MORE_BYTE (c3); | |
1132 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
1133 goto invalid_code; | |
1134 if (UTF_8_3_OCTET_LEADING_P (c1)) | |
1135 c = (((c1 & 0xF) << 12) | |
1136 | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); | |
1137 else | |
1138 { | |
1139 ONE_MORE_BYTE (c4); | |
1140 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
1141 goto invalid_code; | |
1142 if (UTF_8_4_OCTET_LEADING_P (c1)) | |
1143 c = (((c1 & 0x7) << 18) | ((c2 & 0x3F) << 12) | |
1144 | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); | |
1145 else | |
1146 { | |
1147 ONE_MORE_BYTE (c5); | |
1148 if (! UTF_8_EXTRA_OCTET_P (c5)) | |
1149 goto invalid_code; | |
1150 if (UTF_8_5_OCTET_LEADING_P (c1)) | |
1151 { | |
1152 c = (((c1 & 0x3) << 24) | ((c2 & 0x3F) << 18) | |
1153 | ((c3 & 0x3F) << 12) | ((c4 & 0x3F) << 6) | |
1154 | (c5 & 0x3F)); | |
1155 if (c > MAX_CHAR) | |
1156 goto invalid_code; | |
1157 } | |
1158 else | |
1159 goto invalid_code; | |
1160 } | |
1161 } | |
1162 } | |
1163 } | |
1164 | |
1165 *charbuf++ = c; | |
1166 continue; | |
1167 | |
1168 invalid_code: | |
1169 src = src_base; | |
1170 consumed_chars = consumed_chars_base; | |
1171 ONE_MORE_BYTE (c); | |
1172 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
1173 coding->errors++; | |
1174 } | |
1175 | |
1176 no_more_source: | |
1177 coding->consumed_char += consumed_chars_base; | |
1178 coding->consumed = src_base - coding->source; | |
1179 coding->charbuf_used = charbuf - coding->charbuf; | |
1180 } | |
1181 | |
1182 | |
1183 static int | |
1184 encode_coding_utf_8 (coding) | |
1185 struct coding_system *coding; | |
1186 { | |
1187 int multibytep = coding->dst_multibyte; | |
1188 int *charbuf = coding->charbuf; | |
1189 int *charbuf_end = charbuf + coding->charbuf_used; | |
1190 unsigned char *dst = coding->destination + coding->produced; | |
1191 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
|
1192 int produced_chars = 0; |
88365 | 1193 int c; |
1194 | |
1195 if (multibytep) | |
1196 { | |
1197 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
1198 | |
1199 while (charbuf < charbuf_end) | |
1200 { | |
1201 unsigned char str[MAX_MULTIBYTE_LENGTH], *p, *pend = str; | |
1202 | |
1203 ASSURE_DESTINATION (safe_room); | |
1204 c = *charbuf++; | |
1205 CHAR_STRING_ADVANCE (c, pend); | |
1206 for (p = str; p < pend; p++) | |
1207 EMIT_ONE_BYTE (*p); | |
1208 } | |
1209 } | |
1210 else | |
1211 { | |
1212 int safe_room = MAX_MULTIBYTE_LENGTH; | |
1213 | |
1214 while (charbuf < charbuf_end) | |
1215 { | |
1216 ASSURE_DESTINATION (safe_room); | |
1217 c = *charbuf++; | |
1218 dst += CHAR_STRING (c, dst); | |
1219 produced_chars++; | |
1220 } | |
1221 } | |
1222 coding->result = CODING_RESULT_SUCCESS; | |
1223 coding->produced_char += produced_chars; | |
1224 coding->produced = dst - coding->destination; | |
1225 return 0; | |
1226 } | |
1227 | |
1228 | |
1229 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
1230 Check if a text is encoded in UTF-16 Big Endian (endian == 1) or | |
1231 Little Endian (otherwise). If it is, return | |
1232 CATEGORY_MASK_UTF_16_BE or CATEGORY_MASK_UTF_16_LE, | |
1233 else return 0. */ | |
1234 | |
1235 #define UTF_16_HIGH_SURROGATE_P(val) \ | |
1236 (((val) & 0xFC00) == 0xD800) | |
1237 | |
1238 #define UTF_16_LOW_SURROGATE_P(val) \ | |
1239 (((val) & 0xFC00) == 0xDC00) | |
1240 | |
1241 #define UTF_16_INVALID_P(val) \ | |
1242 (((val) == 0xFFFE) \ | |
1243 || ((val) == 0xFFFF) \ | |
1244 || UTF_16_LOW_SURROGATE_P (val)) | |
1245 | |
1246 | |
1247 static int | |
1248 detect_coding_utf_16 (coding, mask) | |
1249 struct coding_system *coding; | |
1250 int *mask; | |
1251 { | |
1252 unsigned char *src = coding->source, *src_base = src; | |
1253 unsigned char *src_end = coding->source + coding->src_bytes; | |
1254 int multibytep = coding->src_multibyte; | |
1255 int consumed_chars = 0; | |
1256 int c1, c2; | |
1257 | |
1258 ONE_MORE_BYTE (c1); | |
1259 ONE_MORE_BYTE (c2); | |
1260 | |
1261 if ((c1 == 0xFF) && (c2 == 0xFE)) | |
1262 { | |
1263 *mask &= CATEGORY_MASK_UTF_16_LE; | |
1264 return 1; | |
1265 } | |
1266 else if ((c1 == 0xFE) && (c2 == 0xFF)) | |
1267 { | |
1268 *mask &= CATEGORY_MASK_UTF_16_BE; | |
1269 return 1; | |
1270 } | |
1271 no_more_source: | |
1272 return 0; | |
1273 } | |
1274 | |
1275 static void | |
1276 decode_coding_utf_16 (coding) | |
1277 struct coding_system *coding; | |
1278 { | |
1279 unsigned char *src = coding->source + coding->consumed; | |
1280 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
|
1281 unsigned char *src_base; |
88365 | 1282 int *charbuf = coding->charbuf; |
1283 int *charbuf_end = charbuf + coding->charbuf_size; | |
1284 int consumed_chars = 0, consumed_chars_base; | |
1285 int multibytep = coding->src_multibyte; | |
1286 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
1287 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); | |
1288 int surrogate = CODING_UTF_16_SURROGATE (coding); | |
1289 Lisp_Object attr, eol_type, charset_list; | |
1290 | |
1291 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
1292 | |
1293 if (bom != utf_16_without_bom) | |
1294 { | |
1295 int c, c1, c2; | |
1296 | |
1297 src_base = src; | |
1298 ONE_MORE_BYTE (c1); | |
1299 ONE_MORE_BYTE (c2); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1300 c = (c1 << 8) | c2; |
88365 | 1301 if (bom == utf_16_with_bom) |
1302 { | |
1303 if (endian == utf_16_big_endian | |
1304 ? c != 0xFFFE : c != 0xFEFF) | |
1305 { | |
1306 /* We are sure that there's enouph room at CHARBUF. */ | |
1307 *charbuf++ = c1; | |
1308 *charbuf++ = c2; | |
1309 coding->errors++; | |
1310 } | |
1311 } | |
1312 else | |
1313 { | |
1314 if (c == 0xFFFE) | |
1315 CODING_UTF_16_ENDIAN (coding) | |
1316 = endian = utf_16_big_endian; | |
1317 else if (c == 0xFEFF) | |
1318 CODING_UTF_16_ENDIAN (coding) | |
1319 = endian = utf_16_little_endian; | |
1320 else | |
1321 { | |
1322 CODING_UTF_16_ENDIAN (coding) | |
1323 = endian = utf_16_big_endian; | |
1324 src = src_base; | |
1325 } | |
1326 } | |
1327 CODING_UTF_16_BOM (coding) = utf_16_with_bom; | |
1328 } | |
1329 | |
1330 while (1) | |
1331 { | |
1332 int c, c1, c2; | |
1333 | |
1334 src_base = src; | |
1335 consumed_chars_base = consumed_chars; | |
1336 | |
1337 if (charbuf + 2 >= charbuf_end) | |
1338 break; | |
1339 | |
1340 ONE_MORE_BYTE (c1); | |
1341 ONE_MORE_BYTE (c2); | |
1342 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
|
1343 ? ((c1 << 8) | c2) : ((c2 << 8) | c1)); |
88365 | 1344 if (surrogate) |
1345 { | |
1346 if (! UTF_16_LOW_SURROGATE_P (c)) | |
1347 { | |
1348 if (endian == utf_16_big_endian) | |
1349 c1 = surrogate >> 8, c2 = surrogate & 0xFF; | |
1350 else | |
1351 c1 = surrogate & 0xFF, c2 = surrogate >> 8; | |
1352 *charbuf++ = c1; | |
1353 *charbuf++ = c2; | |
1354 coding->errors++; | |
1355 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1356 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1357 else | |
1358 *charbuf++ = c; | |
1359 } | |
1360 else | |
1361 { | |
1362 c = ((surrogate - 0xD800) << 10) | (c - 0xDC00); | |
1363 CODING_UTF_16_SURROGATE (coding) = surrogate = 0; | |
1364 *charbuf++ = c; | |
1365 } | |
1366 } | |
1367 else | |
1368 { | |
1369 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1370 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1371 else | |
1372 *charbuf++ = c; | |
1373 } | |
1374 } | |
1375 | |
1376 no_more_source: | |
1377 coding->consumed_char += consumed_chars_base; | |
1378 coding->consumed = src_base - coding->source; | |
1379 coding->charbuf_used = charbuf - coding->charbuf; | |
1380 } | |
1381 | |
1382 static int | |
1383 encode_coding_utf_16 (coding) | |
1384 struct coding_system *coding; | |
1385 { | |
1386 int multibytep = coding->dst_multibyte; | |
1387 int *charbuf = coding->charbuf; | |
1388 int *charbuf_end = charbuf + coding->charbuf_used; | |
1389 unsigned char *dst = coding->destination + coding->produced; | |
1390 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
1391 int safe_room = 8; | |
1392 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
1393 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; | |
1394 int produced_chars = 0; | |
1395 Lisp_Object attrs, eol_type, charset_list; | |
1396 int c; | |
1397 | |
1398 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1399 | |
1400 if (bom == utf_16_with_bom) | |
1401 { | |
1402 ASSURE_DESTINATION (safe_room); | |
1403 if (big_endian) | |
1404 EMIT_TWO_BYTES (0xFF, 0xFE); | |
1405 else | |
1406 EMIT_TWO_BYTES (0xFE, 0xFF); | |
1407 CODING_UTF_16_BOM (coding) = utf_16_without_bom; | |
1408 } | |
1409 | |
1410 while (charbuf < charbuf_end) | |
1411 { | |
1412 ASSURE_DESTINATION (safe_room); | |
1413 c = *charbuf++; | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1414 if (c >= MAX_UNICODE_CHAR) |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1415 c = coding->default_char; |
88365 | 1416 |
1417 if (c < 0x10000) | |
1418 { | |
1419 if (big_endian) | |
1420 EMIT_TWO_BYTES (c >> 8, c & 0xFF); | |
1421 else | |
1422 EMIT_TWO_BYTES (c & 0xFF, c >> 8); | |
1423 } | |
1424 else | |
1425 { | |
1426 int c1, c2; | |
1427 | |
1428 c -= 0x10000; | |
1429 c1 = (c >> 10) + 0xD800; | |
1430 c2 = (c & 0x3FF) + 0xDC00; | |
1431 if (big_endian) | |
1432 EMIT_FOUR_BYTES (c1 >> 8, c1 & 0xFF, c2 >> 8, c2 & 0xFF); | |
1433 else | |
1434 EMIT_FOUR_BYTES (c1 & 0xFF, c1 >> 8, c2 & 0xFF, c2 >> 8); | |
1435 } | |
1436 } | |
1437 coding->result = CODING_RESULT_SUCCESS; | |
1438 coding->produced = dst - coding->destination; | |
1439 coding->produced_char += produced_chars; | |
1440 return 0; | |
1441 } | |
1442 | |
1443 | |
1444 /*** 6. Old Emacs' internal format (emacs-mule) ***/ | |
17052 | 1445 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1446 /* Emacs' internal format for representation of multiple character |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1447 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
|
1448 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
|
1449 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1450 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
|
1451 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
|
1452 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
|
1453 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1454 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
|
1455 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
|
1456 code + 0x20). |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1457 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1458 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
|
1459 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
|
1460 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1461 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
|
1462 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
|
1463 `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
|
1464 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
|
1465 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
|
1466 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
|
1467 and position-code. |
18766 | 1468 |
17052 | 1469 --- 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
|
1470 character set range |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1471 ------------- ----- |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1472 ascii 0x00..0x7F |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1473 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
|
1474 eight-bit-graphic 0xA0..0xBF |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1475 ELSE 0x81..0x9D + [0xA0..0xFF]+ |
17052 | 1476 --------------------------------------------- |
1477 | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1478 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
|
1479 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
|
1480 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
|
1481 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
|
1482 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1483 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
|
1484 form. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1485 |
88365 | 1486 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
|
1487 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
|
1488 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1489 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
|
1490 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
|
1491 where, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1492 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
|
1493 composition_method), |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1494 |
88365 | 1495 BYTES is 0xA0 plus a byte length of this composition data, |
1496 | |
1497 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
|
1498 data, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1499 |
88365 | 1500 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
|
1501 rules encoded by two-byte of ASCII codes. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1502 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1503 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
|
1504 also recognized as composition data on decoding. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1505 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1506 0x80 MSEQ ... |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1507 0x80 0xFF MSEQ RULE MSEQ RULE ... MSEQ |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1508 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1509 Here, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1510 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
|
1511 ASCII: 0xA0 ASCII_CODE+0x80, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1512 other: LEADING_CODE+0x20 FOLLOWING-BYTE ..., |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1513 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
|
1514 represents a composition rule. |
17052 | 1515 */ |
1516 | |
88365 | 1517 char emacs_mule_bytes[256]; |
1518 | |
1519 /* Leading-code followed by extended leading-code. */ | |
1520 #define LEADING_CODE_PRIVATE_11 0x9A /* for private DIMENSION1 of 1-column */ | |
1521 #define LEADING_CODE_PRIVATE_12 0x9B /* for private DIMENSION1 of 2-column */ | |
1522 #define LEADING_CODE_PRIVATE_21 0x9C /* for private DIMENSION2 of 1-column */ | |
1523 #define LEADING_CODE_PRIVATE_22 0x9D /* for private DIMENSION2 of 2-column */ | |
1524 | |
1525 | |
1526 int | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1527 emacs_mule_char (coding, src, nbytes, nchars) |
88365 | 1528 struct coding_system *coding; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1529 unsigned char *src; |
88365 | 1530 int *nbytes, *nchars; |
1531 { | |
1532 unsigned char *src_end = coding->source + coding->src_bytes; | |
1533 int multibytep = coding->src_multibyte; | |
1534 unsigned char *src_base = src; | |
1535 struct charset *charset; | |
1536 unsigned code; | |
1537 int c; | |
1538 int consumed_chars = 0; | |
1539 | |
1540 ONE_MORE_BYTE (c); | |
1541 switch (emacs_mule_bytes[c]) | |
1542 { | |
1543 case 2: | |
1544 if (! (charset = emacs_mule_charset[c])) | |
1545 goto invalid_code; | |
1546 ONE_MORE_BYTE (c); | |
1547 code = c & 0x7F; | |
1548 break; | |
1549 | |
1550 case 3: | |
1551 if (c == LEADING_CODE_PRIVATE_11 | |
1552 || c == LEADING_CODE_PRIVATE_12) | |
1553 { | |
1554 ONE_MORE_BYTE (c); | |
1555 if (! (charset = emacs_mule_charset[c])) | |
1556 goto invalid_code; | |
1557 ONE_MORE_BYTE (c); | |
1558 code = c & 0x7F; | |
1559 } | |
1560 else | |
1561 { | |
1562 if (! (charset = emacs_mule_charset[c])) | |
1563 goto invalid_code; | |
1564 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1565 code = (c & 0x7F) << 8; |
88365 | 1566 ONE_MORE_BYTE (c); |
1567 code |= c & 0x7F; | |
1568 } | |
1569 break; | |
1570 | |
1571 case 4: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1572 ONE_MORE_BYTE (c); |
88365 | 1573 if (! (charset = emacs_mule_charset[c])) |
1574 goto invalid_code; | |
1575 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1576 code = (c & 0x7F) << 8; |
88365 | 1577 ONE_MORE_BYTE (c); |
1578 code |= c & 0x7F; | |
1579 break; | |
1580 | |
1581 case 1: | |
1582 code = c; | |
1583 charset = CHARSET_FROM_ID (ASCII_BYTE_P (code) ? charset_ascii | |
1584 : code < 0xA0 ? charset_8_bit_control | |
1585 : charset_8_bit_graphic); | |
1586 break; | |
1587 | |
1588 default: | |
1589 abort (); | |
1590 } | |
1591 c = DECODE_CHAR (charset, code); | |
1592 if (c < 0) | |
1593 goto invalid_code; | |
1594 *nbytes = src - src_base; | |
1595 *nchars = consumed_chars; | |
1596 return c; | |
1597 | |
1598 no_more_source: | |
1599 return -2; | |
1600 | |
1601 invalid_code: | |
1602 return -1; | |
1603 } | |
1604 | |
17052 | 1605 |
1606 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
88365 | 1607 Check if a text is encoded in `emacs-mule'. */ |
17052 | 1608 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
1609 static int |
88365 | 1610 detect_coding_emacs_mule (coding, mask) |
1611 struct coding_system *coding; | |
1612 int *mask; | |
17052 | 1613 { |
88365 | 1614 unsigned char *src = coding->source, *src_base = src; |
1615 unsigned char *src_end = coding->source + coding->src_bytes; | |
1616 int multibytep = coding->src_multibyte; | |
1617 int consumed_chars = 0; | |
1618 int c; | |
1619 int found = 0; | |
1620 | |
1621 /* A coding system of this category is always ASCII compatible. */ | |
1622 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
|
1623 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1624 while (1) |
17052 | 1625 { |
88365 | 1626 ONE_MORE_BYTE (c); |
1627 | |
1628 if (c == 0x80) | |
17052 | 1629 { |
88365 | 1630 /* Perhaps the start of composite character. We simple skip |
1631 it because analyzing it is too heavy for detecting. But, | |
1632 at least, we check that the composite character | |
1633 constitues of more than 4 bytes. */ | |
1634 unsigned char *src_base; | |
1635 | |
1636 repeat: | |
1637 src_base = src; | |
1638 do | |
1639 { | |
1640 ONE_MORE_BYTE (c); | |
1641 } | |
1642 while (c >= 0xA0); | |
1643 | |
1644 if (src - src_base <= 4) | |
1645 break; | |
1646 found = 1; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1647 if (c == 0x80) |
88365 | 1648 goto repeat; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1649 } |
88365 | 1650 |
1651 if (c < 0x80) | |
1652 { | |
1653 if (c < 0x20 | |
1654 && (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)) | |
1655 break; | |
1656 } | |
1657 else | |
1658 { | |
1659 unsigned char *src_base = src - 1; | |
1660 | |
1661 do | |
1662 { | |
1663 ONE_MORE_BYTE (c); | |
1664 } | |
1665 while (c >= 0xA0); | |
1666 if (src - src_base != emacs_mule_bytes[*src_base]) | |
1667 break; | |
1668 found = 1; | |
1669 } | |
1670 } | |
1671 *mask &= ~CATEGORY_MASK_EMACS_MULE; | |
1672 return 0; | |
1673 | |
1674 no_more_source: | |
1675 if (!found) | |
1676 return 0; | |
1677 *mask &= CATEGORY_MASK_EMACS_MULE; | |
1678 return 1; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1679 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1680 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1681 |
88365 | 1682 /* 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
|
1683 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1684 /* Decode a character represented as a component of composition |
88365 | 1685 sequence of Emacs 20/21 style at SRC. Set C to that character and |
1686 update SRC to the head of next character (or an encoded composition | |
1687 rule). If SRC doesn't points a composition component, set C to -1. | |
1688 If SRC points an invalid byte sequence, global exit by a return | |
1689 value 0. */ | |
1690 | |
1691 #define DECODE_EMACS_MULE_COMPOSITION_CHAR(buf) \ | |
1692 if (1) \ | |
1693 { \ | |
1694 int c; \ | |
1695 int nbytes, nchars; \ | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1696 \ |
88365 | 1697 if (src == src_end) \ |
1698 break; \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1699 c = emacs_mule_char (coding, src, &nbytes, &nchars); \ |
88365 | 1700 if (c < 0) \ |
1701 { \ | |
1702 if (c == -2) \ | |
1703 break; \ | |
1704 goto invalid_code; \ | |
1705 } \ | |
1706 *buf++ = c; \ | |
1707 src += nbytes; \ | |
1708 consumed_chars += nchars; \ | |
1709 } \ | |
1710 else | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1711 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1712 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1713 /* 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
|
1714 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
|
1715 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
|
1716 to -1. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1717 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1718 #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
|
1719 do { \ |
88365 | 1720 int c, gref, nref; \ |
1721 \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1722 if (src >= src_end) \ |
88365 | 1723 goto invalid_code; \ |
1724 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
|
1725 c -= 0x20; \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1726 if (c < 0 || c >= 81) \ |
88365 | 1727 goto invalid_code; \ |
1728 \ | |
1729 gref = c / 9, nref = c % 9; \ | |
1730 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ | |
1731 } while (0) | |
1732 | |
1733 | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1734 /* 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
|
1735 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
|
1736 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
|
1737 to -1. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1738 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1739 #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
|
1740 do { \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1741 int gref, nref; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1742 \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1743 if (src + 1>= src_end) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1744 goto invalid_code; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1745 ONE_MORE_BYTE_NO_CHECK (gref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1746 gref -= 0x20; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1747 ONE_MORE_BYTE_NO_CHECK (nref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1748 nref -= 0x20; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1749 if (gref < 0 || gref >= 81 \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1750 || nref < 0 || nref >= 81) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1751 goto invalid_code; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1752 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1753 } while (0) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1754 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1755 |
88365 | 1756 #define ADD_COMPOSITION_DATA(buf, method, nchars) \ |
1757 do { \ | |
1758 *buf++ = -5; \ | |
1759 *buf++ = coding->produced_char + char_offset; \ | |
1760 *buf++ = CODING_ANNOTATE_COMPOSITION_MASK; \ | |
1761 *buf++ = method; \ | |
1762 *buf++ = nchars; \ | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1763 } while (0) |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1764 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1765 |
88365 | 1766 #define DECODE_EMACS_MULE_21_COMPOSITION(c) \ |
1767 do { \ | |
1768 /* 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
|
1769 (METHOD - 0xF2), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is \ |
88365 | 1770 the byte length of this composition information, CHARS is the \ |
1771 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
|
1772 enum composition_method method = c - 0xF2; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1773 int *charbuf_base = charbuf; \ |
88365 | 1774 int consumed_chars_limit; \ |
1775 int nbytes, nchars; \ | |
1776 \ | |
1777 ONE_MORE_BYTE (c); \ | |
1778 nbytes = c - 0xA0; \ | |
1779 if (nbytes < 3) \ | |
1780 goto invalid_code; \ | |
1781 ONE_MORE_BYTE (c); \ | |
1782 nchars = c - 0xA0; \ | |
1783 ADD_COMPOSITION_DATA (charbuf, method, nchars); \ | |
1784 consumed_chars_limit = consumed_chars_base + nbytes; \ | |
1785 if (method != COMPOSITION_RELATIVE) \ | |
1786 { \ | |
1787 int i = 0; \ | |
1788 while (consumed_chars < consumed_chars_limit) \ | |
1789 { \ | |
1790 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
|
1791 DECODE_EMACS_MULE_COMPOSITION_RULE_21 (charbuf); \ |
88365 | 1792 else \ |
1793 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
|
1794 i++; \ |
88365 | 1795 } \ |
1796 if (consumed_chars < consumed_chars_limit) \ | |
1797 goto invalid_code; \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1798 charbuf_base[0] -= i; \ |
88365 | 1799 } \ |
1800 } while (0) | |
1801 | |
1802 | |
1803 #define DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION(c) \ | |
1804 do { \ | |
1805 /* Emacs 20 style format for relative composition. */ \ | |
1806 /* Store multibyte form of characters to be composed. */ \ | |
1807 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ | |
1808 int *buf = components; \ | |
1809 int i, j; \ | |
1810 \ | |
1811 src = src_base; \ | |
1812 ONE_MORE_BYTE (c); /* skip 0x80 */ \ | |
1813 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
1814 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
1815 if (i < 2) \ | |
1816 goto invalid_code; \ | |
1817 ADD_COMPOSITION_DATA (charbuf, COMPOSITION_RELATIVE, i); \ | |
1818 for (j = 0; j < i; j++) \ | |
1819 *charbuf++ = components[j]; \ | |
1820 } while (0) | |
1821 | |
1822 | |
1823 #define DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION(c) \ | |
1824 do { \ | |
1825 /* Emacs 20 style format for rule-base composition. */ \ | |
1826 /* Store multibyte form of characters to be composed. */ \ | |
1827 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ | |
1828 int *buf = components; \ | |
1829 int i, j; \ | |
1830 \ | |
1831 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
1832 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
1833 { \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1834 DECODE_EMACS_MULE_COMPOSITION_RULE_20 (buf); \ |
88365 | 1835 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ |
1836 } \ | |
1837 if (i < 1 || (buf - components) % 2 == 0) \ | |
1838 goto invalid_code; \ | |
1839 if (charbuf + i + (i / 2) + 1 < charbuf_end) \ | |
1840 goto no_more_source; \ | |
1841 ADD_COMPOSITION_DATA (buf, COMPOSITION_WITH_RULE, i); \ | |
1842 for (j = 0; j < i; j++) \ | |
1843 *charbuf++ = components[j]; \ | |
1844 for (j = 0; j < i; j += 2) \ | |
1845 *charbuf++ = components[j]; \ | |
1846 } while (0) | |
1847 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1848 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1849 static void |
88365 | 1850 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
|
1851 struct coding_system *coding; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1852 { |
88365 | 1853 unsigned char *src = coding->source + coding->consumed; |
1854 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
|
1855 unsigned char *src_base; |
88365 | 1856 int *charbuf = coding->charbuf; |
1857 int *charbuf_end = charbuf + coding->charbuf_size; | |
1858 int consumed_chars = 0, consumed_chars_base; | |
1859 int char_offset = 0; | |
1860 int multibytep = coding->src_multibyte; | |
1861 Lisp_Object attrs, eol_type, charset_list; | |
1862 | |
1863 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1864 | |
1865 while (1) | |
1866 { | |
1867 int c; | |
1868 | |
1869 src_base = src; | |
1870 consumed_chars_base = consumed_chars; | |
1871 | |
1872 if (charbuf >= charbuf_end) | |
1873 break; | |
1874 | |
1875 ONE_MORE_BYTE (c); | |
1876 | |
1877 if (c < 0x80) | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1878 { |
88365 | 1879 if (c == '\r') |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1880 { |
88365 | 1881 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
|
1882 { |
88365 | 1883 if (src == src_end) |
1884 goto no_more_source; | |
1885 if (*src == '\n') | |
1886 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
|
1887 } |
88365 | 1888 else if (EQ (eol_type, Qmac)) |
1889 c = '\n'; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1890 } |
88365 | 1891 *charbuf++ = c; |
1892 char_offset++; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1893 } |
88365 | 1894 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
|
1895 { |
88365 | 1896 if (charbuf + 5 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 > charbuf_end) |
1897 break; | |
1898 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1899 if (c - 0xF2 >= COMPOSITION_RELATIVE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1900 && c - 0xF2 <= COMPOSITION_WITH_RULE_ALTCHARS) |
88365 | 1901 DECODE_EMACS_MULE_21_COMPOSITION (c); |
1902 else if (c < 0xC0) | |
1903 DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION (c); | |
1904 else if (c == 0xFF) | |
1905 DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION (c); | |
1906 else | |
1907 goto invalid_code; | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1908 coding->annotated = 1; |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1909 } |
88365 | 1910 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
|
1911 { |
88365 | 1912 int nbytes, nchars; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1913 src = src_base; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1914 consumed_chars = consumed_chars_base; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1915 c = emacs_mule_char (coding, src, &nbytes, &nchars); |
88365 | 1916 if (c < 0) |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1917 { |
88365 | 1918 if (c == -2) |
1919 break; | |
1920 goto invalid_code; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1921 } |
88365 | 1922 *charbuf++ = c; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1923 src += nbytes; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1924 consumed_chars += nchars; |
88365 | 1925 char_offset++; |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1926 } |
88365 | 1927 continue; |
1928 | |
1929 invalid_code: | |
1930 src = src_base; | |
1931 consumed_chars = consumed_chars_base; | |
1932 ONE_MORE_BYTE (c); | |
1933 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
1934 coding->errors++; | |
1935 } | |
1936 | |
1937 no_more_source: | |
1938 coding->consumed_char += consumed_chars_base; | |
1939 coding->consumed = src_base - coding->source; | |
1940 coding->charbuf_used = charbuf - coding->charbuf; | |
1941 } | |
1942 | |
1943 | |
1944 #define EMACS_MULE_LEADING_CODES(id, codes) \ | |
1945 do { \ | |
1946 if (id < 0xA0) \ | |
1947 codes[0] = id, codes[1] = 0; \ | |
1948 else if (id < 0xE0) \ | |
1949 codes[0] = 0x9A, codes[1] = id; \ | |
1950 else if (id < 0xF0) \ | |
1951 codes[0] = 0x9B, codes[1] = id; \ | |
1952 else if (id < 0xF5) \ | |
1953 codes[0] = 0x9C, codes[1] = id; \ | |
1954 else \ | |
1955 codes[0] = 0x9D, codes[1] = id; \ | |
1956 } while (0); | |
1957 | |
1958 | |
1959 static int | |
1960 encode_coding_emacs_mule (coding) | |
1961 struct coding_system *coding; | |
1962 { | |
1963 int multibytep = coding->dst_multibyte; | |
1964 int *charbuf = coding->charbuf; | |
1965 int *charbuf_end = charbuf + coding->charbuf_used; | |
1966 unsigned char *dst = coding->destination + coding->produced; | |
1967 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
1968 int safe_room = 8; | |
1969 int produced_chars = 0; | |
1970 Lisp_Object attrs, eol_type, charset_list; | |
1971 int c; | |
1972 | |
1973 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1974 | |
1975 while (charbuf < charbuf_end) | |
1976 { | |
1977 ASSURE_DESTINATION (safe_room); | |
1978 c = *charbuf++; | |
1979 if (ASCII_CHAR_P (c)) | |
1980 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
|
1981 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1982 { |
88365 | 1983 struct charset *charset; |
1984 unsigned code; | |
1985 int dimension; | |
1986 int emacs_mule_id; | |
1987 unsigned char leading_codes[2]; | |
1988 | |
1989 charset = char_charset (c, charset_list, &code); | |
1990 if (! charset) | |
1991 { | |
1992 c = coding->default_char; | |
1993 if (ASCII_CHAR_P (c)) | |
1994 { | |
1995 EMIT_ONE_ASCII_BYTE (c); | |
1996 continue; | |
1997 } | |
1998 charset = char_charset (c, charset_list, &code); | |
1999 } | |
2000 dimension = CHARSET_DIMENSION (charset); | |
2001 emacs_mule_id = CHARSET_EMACS_MULE_ID (charset); | |
2002 EMACS_MULE_LEADING_CODES (emacs_mule_id, leading_codes); | |
2003 EMIT_ONE_BYTE (leading_codes[0]); | |
2004 if (leading_codes[1]) | |
2005 EMIT_ONE_BYTE (leading_codes[1]); | |
2006 if (dimension == 1) | |
2007 EMIT_ONE_BYTE (code); | |
2008 else | |
2009 { | |
2010 EMIT_ONE_BYTE (code >> 8); | |
2011 EMIT_ONE_BYTE (code & 0xFF); | |
2012 } | |
17052 | 2013 } |
88365 | 2014 } |
2015 coding->result = CODING_RESULT_SUCCESS; | |
2016 coding->produced_char += produced_chars; | |
2017 coding->produced = dst - coding->destination; | |
2018 return 0; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2019 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2020 |
17052 | 2021 |
88365 | 2022 /*** 7. ISO2022 handlers ***/ |
17052 | 2023 |
2024 /* 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
|
2025 Since the intention of this note is to help understand the |
88365 | 2026 functions in this file, some parts are NOT ACCURATE or OVERLY |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2027 SIMPLIFIED. For thorough understanding, please refer to the |
88365 | 2028 original document of ISO2022. |
17052 | 2029 |
2030 ISO2022 provides many mechanisms to encode several character sets | |
88365 | 2031 in 7-bit and 8-bit environments. For 7-bite environments, all text |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2032 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
|
2033 text a little bit longer, but the text passes more easily through |
88365 | 2034 several gateways, some of which strip off MSB (Most Signigant Bit). |
2035 | |
2036 There are two kinds of character sets: control character set and | |
2037 graphic character set. The former contains control characters such | |
17052 | 2038 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
|
2039 functions are also provided by escape sequences). The latter |
88365 | 2040 contains graphic characters such as 'A' and '-'. Emacs recognizes |
17052 | 2041 two control character sets and many graphic character sets. |
2042 | |
2043 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
|
2044 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
|
2045 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
|
2046 - DIMENSION1_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2047 - DIMENSION1_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2048 - DIMENSION2_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2049 - DIMENSION2_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2050 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2051 In addition, each character set is assigned an identification tag, |
88365 | 2052 unique for each set, called "final character" (denoted as <F> |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2053 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
|
2054 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
|
2055 (0x30..0x3F are for private use only). |
17052 | 2056 |
2057 Note (*): ECMA = European Computer Manufacturers Association | |
2058 | |
88365 | 2059 Here are examples of graphic character set [NAME(<F>)]: |
17052 | 2060 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ... |
2061 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ... | |
2062 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ... | |
2063 o DIMENSION2_CHARS96 -- none for the moment | |
2064 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2065 A code area (1 byte=8 bits) is divided into 4 areas, C0, GL, C1, and GR. |
17052 | 2066 C0 [0x00..0x1F] -- control character plane 0 |
2067 GL [0x20..0x7F] -- graphic character plane 0 | |
2068 C1 [0x80..0x9F] -- control character plane 1 | |
2069 GR [0xA0..0xFF] -- graphic character plane 1 | |
2070 | |
2071 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
|
2072 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
|
2073 - 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
|
2074 - 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
|
2075 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
|
2076 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
|
2077 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
|
2078 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
|
2079 defined to have corresponding escape sequences. |
17052 | 2080 |
2081 A graphic character set is at first designated to one of four | |
2082 graphic registers (G0 through G3), then these graphic registers are | |
2083 invoked to GL or GR. These designations and invocations can be | |
2084 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
|
2085 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
|
2086 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
|
2087 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
|
2088 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2089 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
|
2090 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
|
2091 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
|
2092 be used. |
17052 | 2093 |
2094 There are two ways of invocation: locking-shift and single-shift. | |
2095 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
|
2096 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
|
2097 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
|
2098 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
|
2099 escape sequences: |
17052 | 2100 |
2101 ---------------------------------------------------------------------- | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2102 abbrev function cntrl escape seq description |
17052 | 2103 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2104 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
|
2105 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
|
2106 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
|
2107 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
|
2108 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
|
2109 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
|
2110 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
|
2111 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
|
2112 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char |
17052 | 2113 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2114 (*) 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
|
2115 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2116 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
|
2117 ISO_CODE_XXX in `coding.h'. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2118 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2119 Designations are done by the following escape sequences: |
17052 | 2120 ---------------------------------------------------------------------- |
2121 escape sequence description | |
2122 ---------------------------------------------------------------------- | |
2123 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0 | |
2124 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1 | |
2125 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2 | |
2126 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3 | |
2127 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*) | |
2128 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1 | |
2129 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2 | |
2130 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3 | |
2131 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**) | |
2132 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1 | |
2133 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2 | |
2134 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3 | |
2135 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*) | |
2136 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1 | |
2137 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2 | |
2138 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3 | |
2139 ---------------------------------------------------------------------- | |
2140 | |
2141 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
|
2142 of dimension 1, chars 94, and final character <F>, etc... |
17052 | 2143 |
2144 Note (*): Although these designations are not allowed in ISO2022, | |
2145 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
|
2146 CHARS96 character sets in a coding system which is characterized as |
17052 | 2147 7-bit environment, non-locking-shift, and non-single-shift. |
2148 | |
2149 Note (**): If <F> is '@', 'A', or 'B', the intermediate character | |
88365 | 2150 '(' must be omitted. We refer to this as "short-form" hereafter. |
2151 | |
2152 Now you may notice that there are a lot of ways for encoding the | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2153 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
|
2154 coding systems such as Compound Text (used in X11's inter client |
88365 | 2155 communication, ISO-2022-JP (used in Japanese internet), ISO-2022-KR |
2156 (used in Korean internet), EUC (Extended UNIX Code, used in Asian | |
17052 | 2157 localized platforms), and all of these are variants of ISO2022. |
2158 | |
2159 In addition to the above, Emacs handles two more kinds of escape | |
2160 sequences: ISO6429's direction specification and Emacs' private | |
2161 sequence for specifying character composition. | |
2162 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2163 ISO6429's direction specification takes the following form: |
17052 | 2164 o CSI ']' -- end of the current direction |
2165 o CSI '0' ']' -- end of the current direction | |
2166 o CSI '1' ']' -- start of left-to-right text | |
2167 o CSI '2' ']' -- start of right-to-left text | |
2168 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
|
2169 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
|
2170 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2171 Character composition specification takes the following form: |
26847 | 2172 o ESC '0' -- start relative composition |
2173 o ESC '1' -- end composition | |
2174 o ESC '2' -- start rule-base composition (*) | |
2175 o ESC '3' -- start relative composition with alternate chars (**) | |
2176 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
|
2177 Since these are not standard escape sequences of any ISO standard, |
88365 | 2178 the use of them for these meaning is restricted to Emacs only. |
2179 | |
2180 (*) This form is used only in Emacs 20.5 and the older versions, | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2181 but the newer versions can safely decode it. |
88365 | 2182 (**) This form is used only in Emacs 21.1 and the newer versions, |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2183 and the older versions can't decode it. |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2184 |
88365 | 2185 Here's a list of examples 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
|
2186 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
|
2187 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2188 COMPOSITION_RELATIVE: |
26847 | 2189 ESC 0 CHAR [ CHAR ] ESC 1 |
88365 | 2190 COMPOSITOIN_WITH_RULE: |
26847 | 2191 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
|
2192 COMPOSITION_WITH_ALTCHARS: |
26847 | 2193 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
|
2194 COMPOSITION_WITH_RULE_ALTCHARS: |
26847 | 2195 ESC 4 ALTCHAR [ RULE ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 */ |
17052 | 2196 |
2197 enum iso_code_class_type iso_code_class[256]; | |
2198 | |
88365 | 2199 #define SAFE_CHARSET_P(coding, id) \ |
2200 ((id) <= (coding)->max_charset_id \ | |
2201 && (coding)->safe_charsets[id] >= 0) | |
2202 | |
2203 | |
2204 #define SHIFT_OUT_OK(category) \ | |
2205 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0) | |
2206 | |
2207 static void | |
2208 setup_iso_safe_charsets (Lisp_Object attrs) | |
2209 { | |
2210 Lisp_Object charset_list, safe_charsets; | |
2211 Lisp_Object request; | |
2212 Lisp_Object reg_usage; | |
2213 Lisp_Object tail; | |
2214 int reg94, reg96; | |
2215 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
2216 int max_charset_id; | |
2217 | |
2218 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
2219 if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) | |
2220 && ! EQ (charset_list, Viso_2022_charset_list)) | |
2221 { | |
2222 CODING_ATTR_CHARSET_LIST (attrs) | |
2223 = charset_list = Viso_2022_charset_list; | |
2224 ASET (attrs, coding_attr_safe_charsets, Qnil); | |
2225 } | |
2226 | |
2227 if (STRINGP (AREF (attrs, coding_attr_safe_charsets))) | |
2228 return; | |
2229 | |
2230 max_charset_id = 0; | |
2231 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2232 { | |
2233 int id = XINT (XCAR (tail)); | |
2234 if (max_charset_id < id) | |
2235 max_charset_id = id; | |
2236 } | |
2237 | |
2238 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
2239 make_number (255)); | |
2240 request = AREF (attrs, coding_attr_iso_request); | |
2241 reg_usage = AREF (attrs, coding_attr_iso_usage); | |
2242 reg94 = XINT (XCAR (reg_usage)); | |
2243 reg96 = XINT (XCDR (reg_usage)); | |
2244 | |
2245 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2246 { | |
2247 Lisp_Object id; | |
2248 Lisp_Object reg; | |
2249 struct charset *charset; | |
2250 | |
2251 id = XCAR (tail); | |
2252 charset = CHARSET_FROM_ID (XINT (id)); | |
2253 reg = Fcdr (Fassq (request, id)); | |
2254 if (! NILP (reg)) | |
2255 XSTRING (safe_charsets)->data[XINT (id)] = XINT (reg); | |
2256 else if (charset->iso_chars_96) | |
2257 { | |
2258 if (reg96 < 4) | |
2259 XSTRING (safe_charsets)->data[XINT (id)] = reg96; | |
2260 } | |
2261 else | |
2262 { | |
2263 if (reg94 < 4) | |
2264 XSTRING (safe_charsets)->data[XINT (id)] = reg94; | |
2265 } | |
2266 } | |
2267 ASET (attrs, coding_attr_safe_charsets, safe_charsets); | |
2268 } | |
2269 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2270 |
17052 | 2271 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
88365 | 2272 Check if a text is encoded in ISO2022. If it is, returns an |
17052 | 2273 integer in which appropriate flag bits any of: |
88365 | 2274 CATEGORY_MASK_ISO_7 |
2275 CATEGORY_MASK_ISO_7_TIGHT | |
2276 CATEGORY_MASK_ISO_8_1 | |
2277 CATEGORY_MASK_ISO_8_2 | |
2278 CATEGORY_MASK_ISO_7_ELSE | |
2279 CATEGORY_MASK_ISO_8_ELSE | |
17052 | 2280 are set. If a code which should never appear in ISO2022 is found, |
2281 returns 0. */ | |
2282 | |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
2283 static int |
88365 | 2284 detect_coding_iso_2022 (coding, mask) |
2285 struct coding_system *coding; | |
2286 int *mask; | |
17052 | 2287 { |
88365 | 2288 unsigned char *src = coding->source, *src_base = src; |
2289 unsigned char *src_end = coding->source + coding->src_bytes; | |
2290 int multibytep = coding->src_multibyte; | |
2291 int mask_iso = CATEGORY_MASK_ISO; | |
2292 int mask_found = 0, mask_8bit_found = 0; | |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2293 int reg[4], shift_out = 0, single_shifting = 0; |
88365 | 2294 int id; |
2295 int c, c1; | |
2296 int consumed_chars = 0; | |
2297 int i; | |
2298 | |
2299 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | |
2300 { | |
2301 struct coding_system *this = &(coding_categories[i]); | |
2302 Lisp_Object attrs, val; | |
2303 | |
2304 attrs = CODING_ID_ATTRS (this->id); | |
2305 if (CODING_ISO_FLAGS (this) & CODING_ISO_FLAG_FULL_SUPPORT | |
2306 && ! EQ (CODING_ATTR_SAFE_CHARSETS (attrs), Viso_2022_charset_list)) | |
2307 setup_iso_safe_charsets (attrs); | |
2308 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
2309 this->max_charset_id = XSTRING (val)->size - 1; | |
2310 this->safe_charsets = (char *) XSTRING (val)->data; | |
2311 } | |
2312 | |
2313 /* A coding system of this category is always ASCII compatible. */ | |
2314 src += coding->head_ascii; | |
2315 | |
2316 reg[0] = charset_ascii, reg[1] = reg[2] = reg[3] = -1; | |
2317 while (mask_iso && src < src_end) | |
2318 { | |
2319 ONE_MORE_BYTE (c); | |
17052 | 2320 switch (c) |
2321 { | |
2322 case ISO_CODE_ESC: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2323 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2324 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2325 single_shifting = 0; |
88365 | 2326 ONE_MORE_BYTE (c); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2327 if (c >= '(' && c <= '/') |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2328 { |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2329 /* Designation sequence for a charset of dimension 1. */ |
88365 | 2330 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2331 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2332 || (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
|
2333 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2334 break; |
88365 | 2335 reg[(c - '(') % 4] = id; |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2336 } |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2337 else if (c == '$') |
17052 | 2338 { |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2339 /* Designation sequence for a charset of dimension 2. */ |
88365 | 2340 ONE_MORE_BYTE (c); |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2341 if (c >= '@' && c <= 'B') |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2342 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
88365 | 2343 reg[0] = 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
|
2344 else if (c >= '(' && c <= '/') |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2345 { |
88365 | 2346 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2347 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2348 || (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
|
2349 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2350 break; |
88365 | 2351 reg[(c - '(') % 4] = id; |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2352 } |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2353 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2354 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2355 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2356 } |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2357 else if (c == 'N' || c == 'O') |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2358 { |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2359 /* ESC <Fe> for SS2 or SS3. */ |
88365 | 2360 mask_iso &= CATEGORY_MASK_ISO_7_ELSE; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2361 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2362 } |
26847 | 2363 else if (c >= '0' && c <= '4') |
2364 { | |
2365 /* ESC <Fp> for start/end composition. */ | |
88365 | 2366 mask_found |= CATEGORY_MASK_ISO; |
26847 | 2367 break; |
2368 } | |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2369 else |
88365 | 2370 { |
2371 /* Invalid escape sequence. */ | |
2372 mask_iso &= ~CATEGORY_MASK_ISO_ESCAPE; | |
2373 break; | |
2374 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2375 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2376 /* We found a valid designation sequence for CHARSET. */ |
88365 | 2377 mask_iso &= ~CATEGORY_MASK_ISO_8BIT; |
2378 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7], | |
2379 id)) | |
2380 mask_found |= CATEGORY_MASK_ISO_7; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2381 else |
88365 | 2382 mask_iso &= ~CATEGORY_MASK_ISO_7; |
2383 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_tight], | |
2384 id)) | |
2385 mask_found |= CATEGORY_MASK_ISO_7_TIGHT; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2386 else |
88365 | 2387 mask_iso &= ~CATEGORY_MASK_ISO_7_TIGHT; |
2388 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_else], | |
2389 id)) | |
2390 mask_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
|
2391 else |
88365 | 2392 mask_iso &= ~CATEGORY_MASK_ISO_7_ELSE; |
2393 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_8_else], | |
2394 id)) | |
2395 mask_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
|
2396 else |
88365 | 2397 mask_iso &= ~CATEGORY_MASK_ISO_8_ELSE; |
17052 | 2398 break; |
2399 | |
2400 case ISO_CODE_SO: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2401 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2402 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2403 single_shifting = 0; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2404 if (shift_out == 0 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2405 && (reg[1] >= 0 |
88365 | 2406 || SHIFT_OUT_OK (coding_category_iso_7_else) |
2407 || SHIFT_OUT_OK (coding_category_iso_8_else))) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2408 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2409 /* Locking shift out. */ |
88365 | 2410 mask_iso &= ~CATEGORY_MASK_ISO_7BIT; |
2411 mask_found |= CATEGORY_MASK_ISO_ELSE; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2412 } |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2413 break; |
88365 | 2414 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2415 case ISO_CODE_SI: |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2416 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2417 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2418 single_shifting = 0; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2419 if (shift_out == 1) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2420 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2421 /* Locking shift in. */ |
88365 | 2422 mask_iso &= ~CATEGORY_MASK_ISO_7BIT; |
2423 mask_found |= CATEGORY_MASK_ISO_ELSE; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2424 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2425 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2426 |
17052 | 2427 case ISO_CODE_CSI: |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2428 single_shifting = 0; |
17052 | 2429 case ISO_CODE_SS2: |
2430 case ISO_CODE_SS3: | |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2431 { |
88365 | 2432 int newmask = CATEGORY_MASK_ISO_8_ELSE; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2433 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2434 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2435 break; |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2436 if (c != ISO_CODE_CSI) |
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2437 { |
88365 | 2438 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2439 & CODING_ISO_FLAG_SINGLE_SHIFT) | |
2440 newmask |= CATEGORY_MASK_ISO_8_1; | |
2441 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2442 & CODING_ISO_FLAG_SINGLE_SHIFT) | |
2443 newmask |= 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
|
2444 single_shifting = 1; |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2445 } |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2446 if (VECTORP (Vlatin_extra_code_table) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2447 && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2448 { |
88365 | 2449 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2450 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2451 newmask |= CATEGORY_MASK_ISO_8_1; | |
2452 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2453 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2454 newmask |= CATEGORY_MASK_ISO_8_2; | |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2455 } |
88365 | 2456 mask_iso &= newmask; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2457 mask_found |= newmask; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2458 } |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2459 break; |
17052 | 2460 |
2461 default: | |
2462 if (c < 0x80) | |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2463 { |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2464 single_shifting = 0; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2465 break; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2466 } |
17052 | 2467 else if (c < 0xA0) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2468 { |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2469 single_shifting = 0; |
88365 | 2470 mask_8bit_found = 1; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2471 if (VECTORP (Vlatin_extra_code_table) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2472 && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2473 { |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2474 int newmask = 0; |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2475 |
88365 | 2476 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2477 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2478 newmask |= CATEGORY_MASK_ISO_8_1; | |
2479 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2480 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2481 newmask |= CATEGORY_MASK_ISO_8_2; | |
2482 mask_iso &= newmask; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2483 mask_found |= newmask; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2484 } |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2485 else |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2486 return 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2487 } |
17052 | 2488 else |
2489 { | |
88365 | 2490 mask_iso &= ~(CATEGORY_MASK_ISO_7BIT |
2491 | CATEGORY_MASK_ISO_7_ELSE); | |
2492 mask_found |= CATEGORY_MASK_ISO_8_1; | |
2493 mask_8bit_found = 1; | |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2494 /* Check the length of succeeding codes of the range |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2495 0xA0..0FF. If the byte length is odd, we exclude |
88365 | 2496 CATEGORY_MASK_ISO_8_2. We can check this only |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2497 when we are not single shifting. */ |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2498 if (!single_shifting |
88365 | 2499 && mask_iso & 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
|
2500 { |
29299
b33b38d81020
(detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents:
29275
diff
changeset
|
2501 int i = 1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2502 while (src < src_end) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2503 { |
88365 | 2504 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
|
2505 if (c < 0xA0) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2506 break; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2507 i++; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2508 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2509 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2510 if (i & 1 && src < src_end) |
88365 | 2511 mask_iso &= ~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
|
2512 else |
88365 | 2513 mask_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
|
2514 } |
17052 | 2515 } |
2516 break; | |
2517 } | |
2518 } | |
88365 | 2519 no_more_source: |
2520 if (!mask_iso) | |
2521 { | |
2522 *mask &= ~CATEGORY_MASK_ISO; | |
2523 return 0; | |
2524 } | |
2525 if (!mask_found) | |
2526 return 0; | |
2527 *mask &= mask_iso & mask_found; | |
2528 if (! mask_8bit_found) | |
2529 *mask &= ~(CATEGORY_MASK_ISO_8BIT | CATEGORY_MASK_ISO_8_ELSE); | |
2530 return 1; | |
17052 | 2531 } |
2532 | |
2533 | |
2534 /* Set designation state into CODING. */ | |
88365 | 2535 #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
2536 do { \ | |
2537 int id, prev; \ | |
2538 \ | |
2539 if (final < '0' || final >= 128 \ | |
2540 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ | |
2541 || !SAFE_CHARSET_P (coding, id)) \ | |
2542 { \ | |
2543 CODING_ISO_DESIGNATION (coding, reg) = -2; \ | |
2544 goto invalid_code; \ | |
2545 } \ | |
2546 prev = CODING_ISO_DESIGNATION (coding, reg); \ | |
2547 CODING_ISO_DESIGNATION (coding, reg) = id; \ | |
2548 /* If there was an invalid designation to REG previously, and this \ | |
2549 designation is ASCII to REG, we should keep this designation \ | |
2550 sequence. */ \ | |
2551 if (prev == -2 && id == charset_ascii) \ | |
2552 goto invalid_code; \ | |
17052 | 2553 } while (0) |
2554 | |
88365 | 2555 |
2556 #define MAYBE_FINISH_COMPOSITION() \ | |
2557 do { \ | |
2558 int i; \ | |
2559 if (composition_state == COMPOSING_NO) \ | |
2560 break; \ | |
2561 /* It is assured that we have enough room for producing \ | |
2562 characters stored in the table `components'. */ \ | |
2563 if (charbuf + component_idx > charbuf_end) \ | |
2564 goto no_more_source; \ | |
2565 composition_state = COMPOSING_NO; \ | |
2566 if (method == COMPOSITION_RELATIVE \ | |
2567 || method == COMPOSITION_WITH_ALTCHARS) \ | |
2568 { \ | |
2569 for (i = 0; i < component_idx; i++) \ | |
2570 *charbuf++ = components[i]; \ | |
2571 char_offset += component_idx; \ | |
2572 } \ | |
2573 else \ | |
2574 { \ | |
2575 for (i = 0; i < component_idx; i += 2) \ | |
2576 *charbuf++ = components[i]; \ | |
2577 char_offset += (component_idx / 2) + 1; \ | |
2578 } \ | |
2579 } while (0) | |
2580 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2581 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2582 /* 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
|
2583 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
|
2584 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
88365 | 2585 ESC 3 : altchar composition : ESC 3 CHAR ... ESC 0 CHAR ... ESC 1 |
2586 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
|
2587 */ |
26847 | 2588 |
88365 | 2589 #define DECODE_COMPOSITION_START(c1) \ |
26847 | 2590 do { \ |
88365 | 2591 if (c1 == '0' \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2592 && composition_state == COMPOSING_COMPONENT_RULE) \ |
26847 | 2593 { \ |
88365 | 2594 component_len = component_idx; \ |
2595 composition_state = COMPOSING_CHAR; \ | |
26847 | 2596 } \ |
2597 else \ | |
2598 { \ | |
88365 | 2599 unsigned char *p; \ |
2600 \ | |
2601 MAYBE_FINISH_COMPOSITION (); \ | |
2602 if (charbuf + MAX_COMPOSITION_COMPONENTS > charbuf_end) \ | |
2603 goto no_more_source; \ | |
2604 for (p = src; p < src_end - 1; p++) \ | |
2605 if (*p == ISO_CODE_ESC && p[1] == '1') \ | |
2606 break; \ | |
2607 if (p == src_end - 1) \ | |
2608 { \ | |
2609 if (coding->mode & CODING_MODE_LAST_BLOCK) \ | |
2610 goto invalid_code; \ | |
2611 goto no_more_source; \ | |
2612 } \ | |
2613 \ | |
2614 /* This is surely the start of a composition. */ \ | |
2615 method = (c1 == '0' ? COMPOSITION_RELATIVE \ | |
2616 : c1 == '2' ? COMPOSITION_WITH_RULE \ | |
2617 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \ | |
2618 : COMPOSITION_WITH_RULE_ALTCHARS); \ | |
2619 composition_state = (c1 <= '2' ? COMPOSING_CHAR \ | |
2620 : COMPOSING_COMPONENT_CHAR); \ | |
2621 component_idx = component_len = 0; \ | |
26847 | 2622 } \ |
2623 } while (0) | |
2624 | |
88365 | 2625 |
2626 /* Handle compositoin end sequence ESC 1. */ | |
2627 | |
2628 #define DECODE_COMPOSITION_END() \ | |
2629 do { \ | |
2630 int nchars = (component_len > 0 ? component_idx - component_len \ | |
2631 : method == COMPOSITION_RELATIVE ? component_idx \ | |
2632 : (component_idx + 1) / 2); \ | |
2633 int i; \ | |
2634 int *saved_charbuf = charbuf; \ | |
2635 \ | |
2636 ADD_COMPOSITION_DATA (charbuf, method, nchars); \ | |
2637 if (method != COMPOSITION_RELATIVE) \ | |
2638 { \ | |
2639 if (component_len == 0) \ | |
2640 for (i = 0; i < component_idx; i++) \ | |
2641 *charbuf++ = components[i]; \ | |
2642 else \ | |
2643 for (i = 0; i < component_len; i++) \ | |
2644 *charbuf++ = components[i]; \ | |
2645 *saved_charbuf = saved_charbuf - charbuf; \ | |
2646 } \ | |
2647 if (method == COMPOSITION_WITH_RULE) \ | |
2648 for (i = 0; i < component_idx; i += 2, char_offset++) \ | |
2649 *charbuf++ = components[i]; \ | |
2650 else \ | |
2651 for (i = component_len; i < component_idx; i++, char_offset++) \ | |
2652 *charbuf++ = components[i]; \ | |
2653 coding->annotated = 1; \ | |
2654 composition_state = COMPOSING_NO; \ | |
2655 } while (0) | |
2656 | |
2657 | |
26847 | 2658 /* Decode a composition rule from the byte C1 (and maybe one more byte |
2659 from SRC) and store one encoded composition rule in | |
2660 coding->cmp_data. */ | |
2661 | |
2662 #define DECODE_COMPOSITION_RULE(c1) \ | |
2663 do { \ | |
2664 (c1) -= 32; \ | |
2665 if (c1 < 81) /* old format (before ver.21) */ \ | |
2666 { \ | |
2667 int gref = (c1) / 9; \ | |
2668 int nref = (c1) % 9; \ | |
2669 if (gref == 4) gref = 10; \ | |
2670 if (nref == 4) nref = 10; \ | |
88365 | 2671 c1 = COMPOSITION_ENCODE_RULE (gref, nref); \ |
26847 | 2672 } \ |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2673 else if (c1 < 93) /* new format (after ver.21) */ \ |
26847 | 2674 { \ |
2675 ONE_MORE_BYTE (c2); \ | |
88365 | 2676 c1 = COMPOSITION_ENCODE_RULE (c1 - 81, c2 - 32); \ |
26847 | 2677 } \ |
88365 | 2678 else \ |
2679 c1 = 0; \ | |
26847 | 2680 } while (0) |
2681 | |
2682 | |
17052 | 2683 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
2684 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2685 static void |
88365 | 2686 decode_coding_iso_2022 (coding) |
17052 | 2687 struct coding_system *coding; |
2688 { | |
88365 | 2689 unsigned char *src = coding->source + coding->consumed; |
2690 unsigned char *src_end = coding->source + coding->src_bytes; | |
2691 unsigned char *src_base; | |
2692 int *charbuf = coding->charbuf; | |
2693 int *charbuf_end = charbuf + coding->charbuf_size - 4; | |
2694 int consumed_chars = 0, consumed_chars_base; | |
2695 int char_offset = 0; | |
2696 int multibytep = coding->src_multibyte; | |
17052 | 2697 /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
88365 | 2698 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2699 int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
2700 struct charset *charset; | |
2701 int c; | |
2702 /* For handling composition sequence. */ | |
2703 #define COMPOSING_NO 0 | |
2704 #define COMPOSING_CHAR 1 | |
2705 #define COMPOSING_RULE 2 | |
2706 #define COMPOSING_COMPONENT_CHAR 3 | |
2707 #define COMPOSING_COMPONENT_RULE 4 | |
2708 | |
2709 int composition_state = COMPOSING_NO; | |
2710 enum composition_method method; | |
2711 int components[MAX_COMPOSITION_COMPONENTS * 2 + 1]; | |
2712 int component_idx; | |
2713 int component_len; | |
2714 Lisp_Object attrs, eol_type, charset_list; | |
2715 | |
2716 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
2717 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
|
2718 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2719 while (1) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2720 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2721 int c1, c2; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2722 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2723 src_base = src; |
88365 | 2724 consumed_chars_base = consumed_chars; |
2725 | |
2726 if (charbuf >= charbuf_end) | |
2727 break; | |
2728 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2729 ONE_MORE_BYTE (c1); |
17052 | 2730 |
26847 | 2731 /* We produce no character or one character. */ |
17052 | 2732 switch (iso_code_class [c1]) |
2733 { | |
2734 case ISO_0x20_or_0x7F: | |
88365 | 2735 if (composition_state != COMPOSING_NO) |
26847 | 2736 { |
88365 | 2737 if (composition_state == COMPOSING_RULE |
2738 || composition_state == COMPOSING_COMPONENT_RULE) | |
2739 { | |
2740 DECODE_COMPOSITION_RULE (c1); | |
2741 components[component_idx++] = c1; | |
2742 composition_state--; | |
2743 continue; | |
2744 } | |
26847 | 2745 } |
88365 | 2746 if (charset_id_0 < 0 |
2747 || ! 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
|
2748 /* This is SPACE or DEL. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2749 charset = CHARSET_FROM_ID (charset_ascii); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2750 else |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2751 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
|
2752 break; |
17052 | 2753 |
2754 case ISO_graphic_plane_0: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2755 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
|
2756 { |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2757 if (composition_state == COMPOSING_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2758 || composition_state == COMPOSING_COMPONENT_RULE) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2759 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2760 DECODE_COMPOSITION_RULE (c1); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2761 components[component_idx++] = c1; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2762 composition_state--; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2763 continue; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2764 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2765 } |
88365 | 2766 charset = CHARSET_FROM_ID (charset_id_0); |
17052 | 2767 break; |
2768 | |
2769 case ISO_0xA0_or_0xFF: | |
88365 | 2770 if (charset_id_1 < 0 |
2771 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) | |
2772 || CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) | |
2773 goto invalid_code; | |
17052 | 2774 /* This is a graphic character, we fall down ... */ |
2775 | |
2776 case ISO_graphic_plane_1: | |
88365 | 2777 if (charset_id_1 < 0) |
2778 goto invalid_code; | |
2779 charset = CHARSET_FROM_ID (charset_id_1); | |
17052 | 2780 break; |
2781 | |
88365 | 2782 case ISO_carriage_return: |
2783 if (c1 == '\r') | |
2784 { | |
2785 if (EQ (eol_type, Qdos)) | |
2786 { | |
2787 if (src == src_end) | |
2788 goto no_more_source; | |
2789 if (*src == '\n') | |
2790 ONE_MORE_BYTE (c1); | |
2791 } | |
2792 else if (EQ (eol_type, Qmac)) | |
2793 c1 = '\n'; | |
2794 } | |
2795 /* fall through */ | |
2796 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2797 case ISO_control_0: |
88365 | 2798 MAYBE_FINISH_COMPOSITION (); |
2799 charset = CHARSET_FROM_ID (charset_ascii); | |
17052 | 2800 break; |
2801 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2802 case ISO_control_1: |
88365 | 2803 MAYBE_FINISH_COMPOSITION (); |
2804 goto invalid_code; | |
17052 | 2805 |
2806 case ISO_shift_out: | |
88365 | 2807 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2808 || CODING_ISO_DESIGNATION (coding, 1) < 0) | |
2809 goto invalid_code; | |
2810 CODING_ISO_INVOCATION (coding, 0) = 1; | |
2811 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
|
2812 continue; |
17052 | 2813 |
2814 case ISO_shift_in: | |
88365 | 2815 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)) |
2816 goto invalid_code; | |
2817 CODING_ISO_INVOCATION (coding, 0) = 0; | |
2818 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
|
2819 continue; |
17052 | 2820 |
2821 case ISO_single_shift_2_7: | |
2822 case ISO_single_shift_2: | |
88365 | 2823 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2824 goto invalid_code; | |
17052 | 2825 /* SS2 is handled as an escape sequence of ESC 'N' */ |
2826 c1 = 'N'; | |
2827 goto label_escape_sequence; | |
2828 | |
2829 case ISO_single_shift_3: | |
88365 | 2830 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2831 goto invalid_code; | |
17052 | 2832 /* SS2 is handled as an escape sequence of ESC 'O' */ |
2833 c1 = 'O'; | |
2834 goto label_escape_sequence; | |
2835 | |
2836 case ISO_control_sequence_introducer: | |
2837 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
2838 c1 = '['; | |
2839 goto label_escape_sequence; | |
2840 | |
2841 case ISO_escape: | |
2842 ONE_MORE_BYTE (c1); | |
2843 label_escape_sequence: | |
88365 | 2844 /* Escape sequences handled here are invocation, |
17052 | 2845 designation, direction specification, and character |
2846 composition specification. */ | |
2847 switch (c1) | |
2848 { | |
2849 case '&': /* revision of following character set */ | |
2850 ONE_MORE_BYTE (c1); | |
2851 if (!(c1 >= '@' && c1 <= '~')) | |
88365 | 2852 goto invalid_code; |
17052 | 2853 ONE_MORE_BYTE (c1); |
2854 if (c1 != ISO_CODE_ESC) | |
88365 | 2855 goto invalid_code; |
17052 | 2856 ONE_MORE_BYTE (c1); |
2857 goto label_escape_sequence; | |
2858 | |
2859 case '$': /* designation of 2-byte character set */ | |
88365 | 2860 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
2861 goto invalid_code; | |
17052 | 2862 ONE_MORE_BYTE (c1); |
2863 if (c1 >= '@' && c1 <= 'B') | |
2864 { /* 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
|
2865 or JISX0208.1980 */ |
88365 | 2866 DECODE_DESIGNATION (0, 2, 0, c1); |
17052 | 2867 } |
2868 else if (c1 >= 0x28 && c1 <= 0x2B) | |
2869 { /* designation of DIMENSION2_CHARS94 character set */ | |
2870 ONE_MORE_BYTE (c2); | |
88365 | 2871 DECODE_DESIGNATION (c1 - 0x28, 2, 0, c2); |
17052 | 2872 } |
2873 else if (c1 >= 0x2C && c1 <= 0x2F) | |
2874 { /* designation of DIMENSION2_CHARS96 character set */ | |
2875 ONE_MORE_BYTE (c2); | |
88365 | 2876 DECODE_DESIGNATION (c1 - 0x2C, 2, 1, c2); |
17052 | 2877 } |
2878 else | |
88365 | 2879 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2880 /* We must update these variables now. */ |
88365 | 2881 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2882 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
|
2883 continue; |
17052 | 2884 |
2885 case 'n': /* invocation of locking-shift-2 */ | |
88365 | 2886 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2887 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
2888 goto invalid_code; | |
2889 CODING_ISO_INVOCATION (coding, 0) = 2; | |
2890 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
|
2891 continue; |
17052 | 2892 |
2893 case 'o': /* invocation of locking-shift-3 */ | |
88365 | 2894 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2895 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
2896 goto invalid_code; | |
2897 CODING_ISO_INVOCATION (coding, 0) = 3; | |
2898 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
|
2899 continue; |
17052 | 2900 |
2901 case 'N': /* invocation of single-shift-2 */ | |
88365 | 2902 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
2903 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
2904 goto invalid_code; | |
2905 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 2)); | |
17052 | 2906 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
2907 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 2908 goto invalid_code; |
17052 | 2909 break; |
2910 | |
2911 case 'O': /* invocation of single-shift-3 */ | |
88365 | 2912 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
2913 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
2914 goto invalid_code; | |
2915 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 3)); | |
17052 | 2916 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
2917 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 2918 goto invalid_code; |
17052 | 2919 break; |
2920 | |
26847 | 2921 case '0': case '2': case '3': case '4': /* start composition */ |
88365 | 2922 if (! (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK)) |
2923 goto invalid_code; | |
26847 | 2924 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
|
2925 continue; |
17052 | 2926 |
26847 | 2927 case '1': /* end composition */ |
88365 | 2928 if (composition_state == COMPOSING_NO) |
2929 goto invalid_code; | |
2930 DECODE_COMPOSITION_END (); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2931 continue; |
17052 | 2932 |
2933 case '[': /* specification of direction */ | |
88365 | 2934 if (! CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DIRECTION) |
2935 goto invalid_code; | |
17052 | 2936 /* 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
|
2937 So, `coding->mode & CODING_MODE_DIRECTION' zero means |
88365 | 2938 left-to-right, and nozero means right-to-left. */ |
17052 | 2939 ONE_MORE_BYTE (c1); |
2940 switch (c1) | |
2941 { | |
2942 case ']': /* end of the current direction */ | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2943 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 2944 |
2945 case '0': /* end of the current direction */ | |
2946 case '1': /* start of left-to-right direction */ | |
2947 ONE_MORE_BYTE (c1); | |
2948 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2949 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 2950 else |
88365 | 2951 goto invalid_code; |
17052 | 2952 break; |
2953 | |
2954 case '2': /* start of right-to-left direction */ | |
2955 ONE_MORE_BYTE (c1); | |
2956 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2957 coding->mode |= CODING_MODE_DIRECTION; |
17052 | 2958 else |
88365 | 2959 goto invalid_code; |
17052 | 2960 break; |
2961 | |
2962 default: | |
88365 | 2963 goto invalid_code; |
17052 | 2964 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2965 continue; |
17052 | 2966 |
2967 default: | |
88365 | 2968 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
2969 goto invalid_code; | |
17052 | 2970 if (c1 >= 0x28 && c1 <= 0x2B) |
2971 { /* designation of DIMENSION1_CHARS94 character set */ | |
2972 ONE_MORE_BYTE (c2); | |
88365 | 2973 DECODE_DESIGNATION (c1 - 0x28, 1, 0, c2); |
17052 | 2974 } |
2975 else if (c1 >= 0x2C && c1 <= 0x2F) | |
2976 { /* designation of DIMENSION1_CHARS96 character set */ | |
2977 ONE_MORE_BYTE (c2); | |
88365 | 2978 DECODE_DESIGNATION (c1 - 0x2C, 1, 1, c2); |
17052 | 2979 } |
2980 else | |
88365 | 2981 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2982 /* We must update these variables now. */ |
88365 | 2983 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2984 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
|
2985 continue; |
17052 | 2986 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2987 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2988 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2989 /* Now we know CHARSET and 1st position code C1 of a character. |
88365 | 2990 Produce a decoded character while getting 2nd position code |
2991 C2 if necessary. */ | |
2992 c1 &= 0x7F; | |
2993 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
|
2994 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2995 ONE_MORE_BYTE (c2); |
88365 | 2996 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
|
2997 /* C2 is not in a valid range. */ |
88365 | 2998 goto invalid_code; |
2999 c1 = (c1 << 8) | (c2 & 0x7F); | |
3000 if (CHARSET_DIMENSION (charset) > 2) | |
3001 { | |
3002 ONE_MORE_BYTE (c2); | |
3003 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) | |
3004 /* C2 is not in a valid range. */ | |
3005 goto invalid_code; | |
3006 c1 = (c1 << 8) | (c2 & 0x7F); | |
3007 } | |
17052 | 3008 } |
88365 | 3009 |
3010 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); | |
3011 if (c < 0) | |
3012 { | |
3013 MAYBE_FINISH_COMPOSITION (); | |
3014 for (; src_base < src; src_base++, char_offset++) | |
3015 { | |
3016 if (ASCII_BYTE_P (*src_base)) | |
3017 *charbuf++ = *src_base; | |
3018 else | |
3019 *charbuf++ = BYTE8_TO_CHAR (*src_base); | |
3020 } | |
3021 } | |
3022 else if (composition_state == COMPOSING_NO) | |
3023 { | |
3024 *charbuf++ = c; | |
3025 char_offset++; | |
3026 } | |
3027 else | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3028 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3029 components[component_idx++] = c; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3030 if (method == COMPOSITION_WITH_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3031 || (method == COMPOSITION_WITH_RULE_ALTCHARS |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3032 && composition_state == COMPOSING_COMPONENT_CHAR)) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3033 composition_state++; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3034 } |
17052 | 3035 continue; |
3036 | |
88365 | 3037 invalid_code: |
3038 MAYBE_FINISH_COMPOSITION (); | |
3039 src = src_base; | |
3040 consumed_chars = consumed_chars_base; | |
3041 ONE_MORE_BYTE (c); | |
3042 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3043 coding->errors++; |
88365 | 3044 } |
3045 | |
3046 no_more_source: | |
3047 coding->consumed_char += consumed_chars_base; | |
3048 coding->consumed = src_base - coding->source; | |
3049 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3050 } |
3051 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3052 |
18766 | 3053 /* ISO2022 encoding stuff. */ |
17052 | 3054 |
3055 /* | |
18766 | 3056 It is not enough to say just "ISO2022" on encoding, we have to |
88365 | 3057 specify more details. In Emacs, each coding system of ISO2022 |
17052 | 3058 variant has the following specifications: |
88365 | 3059 1. Initial designation to G0 thru G3. |
17052 | 3060 2. Allows short-form designation? |
3061 3. ASCII should be designated to G0 before control characters? | |
3062 4. ASCII should be designated to G0 at end of line? | |
3063 5. 7-bit environment or 8-bit environment? | |
3064 6. Use locking-shift? | |
3065 7. Use Single-shift? | |
3066 And the following two are only for Japanese: | |
3067 8. Use ASCII in place of JIS0201-1976-Roman? | |
3068 9. Use JISX0208-1983 in place of JISX0208-1978? | |
88365 | 3069 These specifications are encoded in CODING_ISO_FLAGS (coding) as flag bits |
3070 defined by macros CODING_ISO_FLAG_XXX. See `coding.h' for more | |
18766 | 3071 details. |
17052 | 3072 */ |
3073 | |
3074 /* 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
|
3075 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
|
3076 '@', '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
|
3077 designation sequence of short-form. */ |
17052 | 3078 |
3079 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
3080 do { \ | |
88365 | 3081 unsigned char final_char = CHARSET_ISO_FINAL (charset); \ |
17052 | 3082 char *intermediate_char_94 = "()*+"; \ |
3083 char *intermediate_char_96 = ",-./"; \ | |
88365 | 3084 int revision = -1; \ |
3085 int c; \ | |
3086 \ | |
3087 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ | |
3088 revision = XINT (CHARSET_ISO_REVISION (charset)); \ | |
3089 \ | |
3090 if (revision >= 0) \ | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
3091 { \ |
88365 | 3092 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '&'); \ |
3093 EMIT_ONE_BYTE ('@' + revision); \ | |
17052 | 3094 } \ |
88365 | 3095 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ |
17052 | 3096 if (CHARSET_DIMENSION (charset) == 1) \ |
3097 { \ | |
88365 | 3098 if (! CHARSET_ISO_CHARS_96 (charset)) \ |
3099 c = intermediate_char_94[reg]; \ | |
17052 | 3100 else \ |
88365 | 3101 c = intermediate_char_96[reg]; \ |
3102 EMIT_ONE_ASCII_BYTE (c); \ | |
17052 | 3103 } \ |
3104 else \ | |
3105 { \ | |
88365 | 3106 EMIT_ONE_ASCII_BYTE ('$'); \ |
3107 if (! CHARSET_ISO_CHARS_96 (charset)) \ | |
17052 | 3108 { \ |
88365 | 3109 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
|
3110 || reg != 0 \ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3111 || final_char < '@' || final_char > 'B') \ |
88365 | 3112 EMIT_ONE_ASCII_BYTE (intermediate_char_94[reg]); \ |
17052 | 3113 } \ |
3114 else \ | |
88365 | 3115 EMIT_ONE_ASCII_BYTE (intermediate_char_96[reg]); \ |
17052 | 3116 } \ |
88365 | 3117 EMIT_ONE_ASCII_BYTE (final_char); \ |
3118 \ | |
3119 CODING_ISO_DESIGNATION (coding, reg) = CHARSET_ID (charset); \ | |
17052 | 3120 } while (0) |
3121 | |
88365 | 3122 |
17052 | 3123 /* The following two macros produce codes (control character or escape |
3124 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
3125 single-shift-3). */ | |
3126 | |
88365 | 3127 #define ENCODE_SINGLE_SHIFT_2 \ |
3128 do { \ | |
3129 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3130 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'N'); \ | |
3131 else \ | |
3132 EMIT_ONE_BYTE (ISO_CODE_SS2); \ | |
3133 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3134 } while (0) |
3135 | |
88365 | 3136 |
3137 #define ENCODE_SINGLE_SHIFT_3 \ | |
3138 do { \ | |
3139 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3140 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'O'); \ | |
3141 else \ | |
3142 EMIT_ONE_BYTE (ISO_CODE_SS3); \ | |
3143 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3144 } while (0) |
3145 | |
88365 | 3146 |
17052 | 3147 /* The following four macros produce codes (control character or |
3148 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
3149 shift-out, locking-shift-2, and locking-shift-3). */ | |
3150 | |
88365 | 3151 #define ENCODE_SHIFT_IN \ |
3152 do { \ | |
3153 EMIT_ONE_ASCII_BYTE (ISO_CODE_SI); \ | |
3154 CODING_ISO_INVOCATION (coding, 0) = 0; \ | |
17052 | 3155 } while (0) |
3156 | |
88365 | 3157 |
3158 #define ENCODE_SHIFT_OUT \ | |
3159 do { \ | |
3160 EMIT_ONE_ASCII_BYTE (ISO_CODE_SO); \ | |
3161 CODING_ISO_INVOCATION (coding, 0) = 1; \ | |
17052 | 3162 } while (0) |
3163 | |
88365 | 3164 |
3165 #define ENCODE_LOCKING_SHIFT_2 \ | |
3166 do { \ | |
3167 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3168 CODING_ISO_INVOCATION (coding, 0) = 2; \ | |
17052 | 3169 } while (0) |
3170 | |
88365 | 3171 |
3172 #define ENCODE_LOCKING_SHIFT_3 \ | |
3173 do { \ | |
3174 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3175 CODING_ISO_INVOCATION (coding, 0) = 3; \ | |
17052 | 3176 } while (0) |
3177 | |
88365 | 3178 |
18766 | 3179 /* Produce codes for a DIMENSION1 character whose character set is |
3180 CHARSET and whose position-code is C1. Designation and invocation | |
17052 | 3181 sequences are also produced in advance if necessary. */ |
3182 | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3183 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3184 do { \ |
88365 | 3185 int id = CHARSET_ID (charset); \ |
3186 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3187 { \ |
88365 | 3188 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ |
3189 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3190 else \ |
88365 | 3191 EMIT_ONE_BYTE (c1 | 0x80); \ |
3192 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3193 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3194 } \ |
88365 | 3195 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
|
3196 { \ |
88365 | 3197 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3198 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3199 } \ |
88365 | 3200 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
|
3201 { \ |
88365 | 3202 EMIT_ONE_BYTE (c1 | 0x80); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3203 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3204 } \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3205 else \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3206 /* 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
|
3207 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
|
3208 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
|
3209 character. */ \ |
88365 | 3210 dst = encode_invocation_designation (charset, coding, dst, \ |
3211 &produced_chars); \ | |
17052 | 3212 } while (1) |
3213 | |
88365 | 3214 |
3215 /* Produce codes for a DIMENSION2 character whose character set is | |
3216 CHARSET and whose position-codes are C1 and C2. Designation and | |
3217 invocation codes are also produced in advance if necessary. */ | |
3218 | |
3219 #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
|
3220 do { \ |
88365 | 3221 int id = CHARSET_ID (charset); \ |
3222 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ | |
3223 { \ | |
3224 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3225 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3226 else \ | |
3227 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3228 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
3229 break; \ | |
3230 } \ | |
3231 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ | |
3232 { \ | |
3233 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3234 break; \ | |
3235 } \ | |
3236 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ | |
3237 { \ | |
3238 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3239 break; \ | |
3240 } \ | |
3241 else \ | |
3242 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
3243 must invoke it, or, at first, designate it to some graphic \ | |
3244 register. Then repeat the loop to actually produce the \ | |
3245 character. */ \ | |
3246 dst = encode_invocation_designation (charset, coding, dst, \ | |
3247 &produced_chars); \ | |
3248 } while (1) | |
3249 | |
3250 | |
3251 #define ENCODE_ISO_CHARACTER(charset, c) \ | |
3252 do { \ | |
3253 int code = ENCODE_CHAR ((charset),(c)); \ | |
3254 \ | |
3255 if (CHARSET_DIMENSION (charset) == 1) \ | |
3256 ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ | |
3257 else \ | |
3258 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
|
3259 } while (0) |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3260 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
3261 |
17052 | 3262 /* Produce designation and invocation codes at a place pointed by DST |
88365 | 3263 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. |
17052 | 3264 Return new DST. */ |
3265 | |
3266 unsigned char * | |
88365 | 3267 encode_invocation_designation (charset, coding, dst, p_nchars) |
3268 struct charset *charset; | |
17052 | 3269 struct coding_system *coding; |
3270 unsigned char *dst; | |
88365 | 3271 int *p_nchars; |
17052 | 3272 { |
88365 | 3273 int multibytep = coding->dst_multibyte; |
3274 int produced_chars = *p_nchars; | |
17052 | 3275 int reg; /* graphic register number */ |
88365 | 3276 int id = CHARSET_ID (charset); |
17052 | 3277 |
3278 /* At first, check designations. */ | |
3279 for (reg = 0; reg < 4; reg++) | |
88365 | 3280 if (id == CODING_ISO_DESIGNATION (coding, reg)) |
17052 | 3281 break; |
3282 | |
3283 if (reg >= 4) | |
3284 { | |
3285 /* CHARSET is not yet designated to any graphic registers. */ | |
3286 /* At first check the requested designation. */ | |
88365 | 3287 reg = CODING_ISO_REQUEST (coding, id); |
3288 if (reg < 0) | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3289 /* Since CHARSET requests no special designation, designate it |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3290 to graphic register 0. */ |
17052 | 3291 reg = 0; |
3292 | |
3293 ENCODE_DESIGNATION (charset, reg, coding); | |
3294 } | |
3295 | |
88365 | 3296 if (CODING_ISO_INVOCATION (coding, 0) != reg |
3297 && CODING_ISO_INVOCATION (coding, 1) != reg) | |
17052 | 3298 { |
3299 /* Since the graphic register REG is not invoked to any graphic | |
3300 planes, invoke it to graphic plane 0. */ | |
3301 switch (reg) | |
3302 { | |
3303 case 0: /* graphic register 0 */ | |
3304 ENCODE_SHIFT_IN; | |
3305 break; | |
3306 | |
3307 case 1: /* graphic register 1 */ | |
3308 ENCODE_SHIFT_OUT; | |
3309 break; | |
3310 | |
3311 case 2: /* graphic register 2 */ | |
88365 | 3312 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3313 ENCODE_SINGLE_SHIFT_2; |
3314 else | |
3315 ENCODE_LOCKING_SHIFT_2; | |
3316 break; | |
3317 | |
3318 case 3: /* graphic register 3 */ | |
88365 | 3319 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3320 ENCODE_SINGLE_SHIFT_3; |
3321 else | |
3322 ENCODE_LOCKING_SHIFT_3; | |
3323 break; | |
3324 } | |
3325 } | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3326 |
88365 | 3327 *p_nchars = produced_chars; |
17052 | 3328 return dst; |
3329 } | |
3330 | |
3331 /* The following three macros produce codes for indicating direction | |
3332 of text. */ | |
88365 | 3333 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ |
3334 do { \ | |
3335 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \ | |
3336 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \ | |
3337 else \ | |
3338 EMIT_ONE_BYTE (ISO_CODE_CSI); \ | |
17052 | 3339 } while (0) |
3340 | |
88365 | 3341 |
3342 #define ENCODE_DIRECTION_R2L() \ | |
3343 do { \ | |
3344 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3345 EMIT_TWO_ASCII_BYTES ('2', ']'); \ | |
3346 } while (0) | |
3347 | |
3348 | |
3349 #define ENCODE_DIRECTION_L2R() \ | |
3350 do { \ | |
3351 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3352 EMIT_TWO_ASCII_BYTES ('0', ']'); \ | |
3353 } while (0) | |
3354 | |
17052 | 3355 |
3356 /* Produce codes for designation and invocation to reset the graphic | |
3357 planes and registers to initial state. */ | |
88365 | 3358 #define ENCODE_RESET_PLANE_AND_REGISTER() \ |
3359 do { \ | |
3360 int reg; \ | |
3361 struct charset *charset; \ | |
3362 \ | |
3363 if (CODING_ISO_INVOCATION (coding, 0) != 0) \ | |
3364 ENCODE_SHIFT_IN; \ | |
3365 for (reg = 0; reg < 4; reg++) \ | |
3366 if (CODING_ISO_INITIAL (coding, reg) >= 0 \ | |
3367 && (CODING_ISO_DESIGNATION (coding, reg) \ | |
3368 != CODING_ISO_INITIAL (coding, reg))) \ | |
3369 { \ | |
3370 charset = CHARSET_FROM_ID (CODING_ISO_INITIAL (coding, reg)); \ | |
3371 ENCODE_DESIGNATION (charset, reg, coding); \ | |
3372 } \ | |
17052 | 3373 } while (0) |
3374 | |
88365 | 3375 |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3376 /* 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
|
3377 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
|
3378 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3379 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
|
3380 find all the necessary designations. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3381 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3382 static unsigned char * |
88365 | 3383 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
|
3384 struct coding_system *coding; |
88365 | 3385 int *charbuf, *charbuf_end; |
3386 unsigned char *dst; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3387 { |
88365 | 3388 struct charset *charset; |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3389 /* 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
|
3390 int r[4]; |
88365 | 3391 int c, found = 0, reg; |
3392 int produced_chars = 0; | |
3393 int multibytep = coding->dst_multibyte; | |
3394 Lisp_Object attrs; | |
3395 Lisp_Object charset_list; | |
3396 | |
3397 attrs = CODING_ID_ATTRS (coding->id); | |
3398 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
3399 if (EQ (charset_list, Qiso_2022)) | |
3400 charset_list = Viso_2022_charset_list; | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3401 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3402 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3403 r[reg] = -1; |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3404 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3405 while (found < 4) |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3406 { |
88365 | 3407 int id; |
3408 | |
3409 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3410 if (c == '\n') |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3411 break; |
88365 | 3412 charset = char_charset (c, charset_list, NULL); |
3413 id = CHARSET_ID (charset); | |
3414 reg = CODING_ISO_REQUEST (coding, id); | |
3415 if (reg >= 0 && r[reg] < 0) | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3416 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3417 found++; |
88365 | 3418 r[reg] = id; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3419 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3420 } |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3421 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3422 if (found) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3423 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3424 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3425 if (r[reg] >= 0 |
88365 | 3426 && CODING_ISO_DESIGNATION (coding, reg) != r[reg]) |
3427 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
|
3428 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3429 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3430 return dst; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3431 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3432 |
17052 | 3433 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
3434 | |
88365 | 3435 static int |
3436 encode_coding_iso_2022 (coding) | |
17052 | 3437 struct coding_system *coding; |
3438 { | |
88365 | 3439 int multibytep = coding->dst_multibyte; |
3440 int *charbuf = coding->charbuf; | |
3441 int *charbuf_end = charbuf + coding->charbuf_used; | |
3442 unsigned char *dst = coding->destination + coding->produced; | |
3443 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3444 int safe_room = 16; | |
3445 int bol_designation | |
3446 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL | |
3447 && CODING_ISO_BOL (coding)); | |
3448 int produced_chars = 0; | |
3449 Lisp_Object attrs, eol_type, charset_list; | |
3450 int ascii_compatible; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3451 int c; |
88365 | 3452 |
3453 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
|
3454 setup_iso_safe_charsets (attrs); |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3455 coding->safe_charsets |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3456 = (char *) XSTRING (CODING_ATTR_SAFE_CHARSETS(attrs))->data; |
88365 | 3457 |
3458 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3459 | |
3460 while (charbuf < charbuf_end) | |
3461 { | |
3462 ASSURE_DESTINATION (safe_room); | |
3463 | |
3464 if (bol_designation) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3465 { |
88365 | 3466 unsigned char *dst_prev = dst; |
3467 | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3468 /* We have to produce designation sequences if any now. */ |
88365 | 3469 dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); |
3470 bol_designation = 0; | |
3471 /* We are sure that designation sequences are all ASCII bytes. */ | |
3472 produced_chars += dst - dst_prev; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3473 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3474 |
88365 | 3475 c = *charbuf++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3476 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3477 /* 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
|
3478 if (c < 0x20 || c == 0x7F) |
17052 | 3479 { |
88365 | 3480 if (c == '\n' |
3481 || (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
|
3482 { |
88365 | 3483 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) |
3484 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3485 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_INIT_AT_BOL) | |
3486 { | |
3487 int i; | |
3488 | |
3489 for (i = 0; i < 4; i++) | |
3490 CODING_ISO_DESIGNATION (coding, i) | |
3491 = CODING_ISO_INITIAL (coding, i); | |
3492 } | |
3493 bol_designation | |
3494 = 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
|
3495 } |
88365 | 3496 else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) |
3497 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3498 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
|
3499 } |
88365 | 3500 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
|
3501 { |
88365 | 3502 if (ascii_compatible) |
3503 EMIT_ONE_ASCII_BYTE (c); | |
3504 else | |
3505 ENCODE_ISO_CHARACTER (CHARSET_FROM_ID (charset_ascii), c); | |
17052 | 3506 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3507 else |
88365 | 3508 { |
3509 struct charset *charset = char_charset (c, charset_list, NULL); | |
3510 | |
3511 if (!charset) | |
3512 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3513 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
|
3514 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3515 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3516 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3517 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3518 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3519 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3520 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3521 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
|
3522 } |
88365 | 3523 } |
3524 ENCODE_ISO_CHARACTER (charset, c); | |
3525 } | |
3526 } | |
3527 | |
3528 if (coding->mode & CODING_MODE_LAST_BLOCK | |
3529 && CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) | |
3530 { | |
3531 ASSURE_DESTINATION (safe_room); | |
3532 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3533 } | |
3534 coding->result = CODING_RESULT_SUCCESS; | |
3535 CODING_ISO_BOL (coding) = bol_designation; | |
3536 coding->produced_char += produced_chars; | |
3537 coding->produced = dst - coding->destination; | |
3538 return 0; | |
17052 | 3539 } |
3540 | |
3541 | |
88365 | 3542 /*** 8,9. SJIS and BIG5 handlers ***/ |
3543 | |
3544 /* Although SJIS and BIG5 are not ISO's coding system, they are used | |
17052 | 3545 quite widely. So, for the moment, Emacs supports them in the bare |
3546 C code. But, in the future, they may be supported only by CCL. */ | |
3547 | |
3548 /* SJIS is a coding system encoding three character sets: ASCII, right | |
3549 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
3550 as is. A character of charset katakana-jisx0201 is encoded by | |
3551 "position-code + 0x80". A character of charset japanese-jisx0208 | |
3552 is encoded in 2-byte but two position-codes are divided and shifted | |
88365 | 3553 so that it fit in the range below. |
17052 | 3554 |
3555 --- CODE RANGE of SJIS --- | |
3556 (character set) (range) | |
3557 ASCII 0x00 .. 0x7F | |
88365 | 3558 KATAKANA-JISX0201 0xA0 .. 0xDF |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
3559 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
|
3560 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC |
17052 | 3561 ------------------------------- |
3562 | |
3563 */ | |
3564 | |
3565 /* BIG5 is a coding system encoding two character sets: ASCII and | |
3566 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
88365 | 3567 character set and is encoded in two-byte. |
17052 | 3568 |
3569 --- CODE RANGE of BIG5 --- | |
3570 (character set) (range) | |
3571 ASCII 0x00 .. 0x7F | |
3572 Big5 (1st byte) 0xA1 .. 0xFE | |
3573 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
3574 -------------------------- | |
3575 | |
88365 | 3576 */ |
17052 | 3577 |
3578 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3579 Check if a text is encoded in SJIS. If it is, return | |
88365 | 3580 CATEGORY_MASK_SJIS, else return 0. */ |
17052 | 3581 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3582 static int |
88365 | 3583 detect_coding_sjis (coding, mask) |
3584 struct coding_system *coding; | |
3585 int *mask; | |
17052 | 3586 { |
88365 | 3587 unsigned char *src = coding->source, *src_base = src; |
3588 unsigned char *src_end = coding->source + coding->src_bytes; | |
3589 int multibytep = coding->src_multibyte; | |
3590 int consumed_chars = 0; | |
3591 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3592 int c; |
88365 | 3593 |
3594 /* A coding system of this category is always ASCII compatible. */ | |
3595 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
|
3596 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3597 while (1) |
17052 | 3598 { |
88365 | 3599 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3600 if (c < 0x80) |
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3601 continue; |
88365 | 3602 if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEF)) |
17052 | 3603 { |
88365 | 3604 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3605 if (c < 0x40 || c == 0x7F || c > 0xFC) |
88365 | 3606 break; |
3607 found = 1; | |
17052 | 3608 } |
88365 | 3609 else if (c >= 0xA0 && c < 0xE0) |
3610 found = 1; | |
3611 else | |
3612 break; | |
3613 } | |
3614 *mask &= ~CATEGORY_MASK_SJIS; | |
3615 return 0; | |
3616 | |
3617 no_more_source: | |
3618 if (!found) | |
3619 return 0; | |
3620 *mask &= CATEGORY_MASK_SJIS; | |
3621 return 1; | |
17052 | 3622 } |
3623 | |
3624 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3625 Check if a text is encoded in BIG5. If it is, return | |
88365 | 3626 CATEGORY_MASK_BIG5, else return 0. */ |
17052 | 3627 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3628 static int |
88365 | 3629 detect_coding_big5 (coding, mask) |
3630 struct coding_system *coding; | |
3631 int *mask; | |
17052 | 3632 { |
88365 | 3633 unsigned char *src = coding->source, *src_base = src; |
3634 unsigned char *src_end = coding->source + coding->src_bytes; | |
3635 int multibytep = coding->src_multibyte; | |
3636 int consumed_chars = 0; | |
3637 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3638 int c; |
88365 | 3639 |
3640 /* A coding system of this category is always ASCII compatible. */ | |
3641 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
|
3642 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3643 while (1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3644 { |
88365 | 3645 ONE_MORE_BYTE (c); |
3646 if (c < 0x80) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3647 continue; |
88365 | 3648 if (c >= 0xA1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3649 { |
88365 | 3650 ONE_MORE_BYTE (c); |
3651 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
|
3652 return 0; |
88365 | 3653 found = 1; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3654 } |
88365 | 3655 else |
3656 break; | |
3657 } | |
3658 *mask &= ~CATEGORY_MASK_BIG5; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3659 return 0; |
88365 | 3660 |
3661 no_more_source: | |
3662 if (!found) | |
3663 return 0; | |
3664 *mask &= CATEGORY_MASK_BIG5; | |
3665 return 1; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3666 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3667 |
17052 | 3668 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". |
3669 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
3670 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3671 static void |
88365 | 3672 decode_coding_sjis (coding) |
17052 | 3673 struct coding_system *coding; |
3674 { | |
88365 | 3675 unsigned char *src = coding->source + coding->consumed; |
3676 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
|
3677 unsigned char *src_base; |
88365 | 3678 int *charbuf = coding->charbuf; |
3679 int *charbuf_end = charbuf + coding->charbuf_size; | |
3680 int consumed_chars = 0, consumed_chars_base; | |
3681 int multibytep = coding->src_multibyte; | |
3682 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3683 Lisp_Object attrs, eol_type, charset_list, val; | |
3684 | |
3685 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3686 | |
3687 val = charset_list; | |
3688 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3689 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3690 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3691 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3692 while (1) |
17052 | 3693 { |
88365 | 3694 int c, c1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3695 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3696 src_base = src; |
88365 | 3697 consumed_chars_base = consumed_chars; |
3698 | |
3699 if (charbuf >= charbuf_end) | |
3700 break; | |
3701 | |
3702 ONE_MORE_BYTE (c); | |
3703 | |
3704 if (c == '\r') | |
17052 | 3705 { |
88365 | 3706 if (EQ (eol_type, Qdos)) |
17052 | 3707 { |
88365 | 3708 if (src == src_end) |
3709 goto no_more_source; | |
3710 if (*src == '\n') | |
3711 ONE_MORE_BYTE (c); | |
17052 | 3712 } |
88365 | 3713 else if (EQ (eol_type, Qmac)) |
3714 c = '\n'; | |
17052 | 3715 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3716 else |
88365 | 3717 { |
3718 struct charset *charset; | |
3719 | |
3720 if (c < 0x80) | |
3721 charset = charset_roman; | |
3722 else | |
17052 | 3723 { |
88365 | 3724 if (c >= 0xF0) |
3725 goto invalid_code; | |
3726 if (c < 0xA0 || c >= 0xE0) | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3727 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3728 /* SJIS -> JISX0208 */ |
88365 | 3729 ONE_MORE_BYTE (c1); |
3730 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) | |
3731 goto invalid_code; | |
3732 c = (c << 8) | c1; | |
3733 SJIS_TO_JIS (c); | |
3734 charset = charset_kanji; | |
24870
b0f6eab5deeb
(decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents:
24822
diff
changeset
|
3735 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3736 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3737 /* SJIS -> JISX0201-Kana */ |
88365 | 3738 charset = charset_kana; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3739 } |
88365 | 3740 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
3741 } | |
3742 *charbuf++ = c; | |
3743 continue; | |
3744 | |
3745 invalid_code: | |
3746 src = src_base; | |
3747 consumed_chars = consumed_chars_base; | |
3748 ONE_MORE_BYTE (c); | |
3749 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
3750 coding->errors++; | |
3751 } | |
3752 | |
3753 no_more_source: | |
3754 coding->consumed_char += consumed_chars_base; | |
3755 coding->consumed = src_base - coding->source; | |
3756 coding->charbuf_used = charbuf - coding->charbuf; | |
3757 } | |
3758 | |
3759 static void | |
3760 decode_coding_big5 (coding) | |
3761 struct coding_system *coding; | |
3762 { | |
3763 unsigned char *src = coding->source + coding->consumed; | |
3764 unsigned char *src_end = coding->source + coding->src_bytes; | |
3765 unsigned char *src_base; | |
3766 int *charbuf = coding->charbuf; | |
3767 int *charbuf_end = charbuf + coding->charbuf_size; | |
3768 int consumed_chars = 0, consumed_chars_base; | |
3769 int multibytep = coding->src_multibyte; | |
3770 struct charset *charset_roman, *charset_big5; | |
3771 Lisp_Object attrs, eol_type, charset_list, val; | |
3772 | |
3773 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3774 val = charset_list; | |
3775 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3776 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3777 | |
3778 while (1) | |
3779 { | |
3780 int c, c1; | |
3781 | |
3782 src_base = src; | |
3783 consumed_chars_base = consumed_chars; | |
3784 | |
3785 if (charbuf >= charbuf_end) | |
3786 break; | |
3787 | |
3788 ONE_MORE_BYTE (c); | |
3789 | |
3790 if (c == '\r') | |
3791 { | |
3792 if (EQ (eol_type, Qdos)) | |
3793 { | |
3794 if (src == src_end) | |
3795 goto no_more_source; | |
3796 if (*src == '\n') | |
3797 ONE_MORE_BYTE (c); | |
3798 } | |
3799 else if (EQ (eol_type, Qmac)) | |
3800 c = '\n'; | |
3801 } | |
3802 else | |
3803 { | |
3804 struct charset *charset; | |
3805 if (c < 0x80) | |
3806 charset = charset_roman; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3807 else |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3808 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3809 /* BIG5 -> Big5 */ |
88365 | 3810 if (c < 0xA1 || c > 0xFE) |
3811 goto invalid_code; | |
3812 ONE_MORE_BYTE (c1); | |
3813 if (c1 < 0x40 || (c1 > 0x7E && c1 < 0xA1) || c1 > 0xFE) | |
3814 goto invalid_code; | |
3815 c = c << 8 | c1; | |
3816 charset = charset_big5; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3817 } |
88365 | 3818 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
|
3819 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3820 |
88365 | 3821 *charbuf++ = c; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3822 continue; |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3823 |
88365 | 3824 invalid_code: |
17052 | 3825 src = src_base; |
88365 | 3826 consumed_chars = consumed_chars_base; |
3827 ONE_MORE_BYTE (c); | |
3828 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
3829 coding->errors++; | |
3830 } | |
3831 | |
3832 no_more_source: | |
3833 coding->consumed_char += consumed_chars_base; | |
3834 coding->consumed = src_base - coding->source; | |
3835 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3836 } |
3837 | |
3838 /* 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
|
3839 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
|
3840 `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
|
3841 are sure that all these charsets are registered as official charset |
17052 | 3842 (i.e. do not have extended leading-codes). Characters of other |
3843 charsets are produced without any encoding. If SJIS_P is 1, encode | |
3844 SJIS text, else encode BIG5 text. */ | |
3845 | |
88365 | 3846 static int |
3847 encode_coding_sjis (coding) | |
17052 | 3848 struct coding_system *coding; |
3849 { | |
88365 | 3850 int multibytep = coding->dst_multibyte; |
3851 int *charbuf = coding->charbuf; | |
3852 int *charbuf_end = charbuf + coding->charbuf_used; | |
3853 unsigned char *dst = coding->destination + coding->produced; | |
3854 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3855 int safe_room = 4; | |
3856 int produced_chars = 0; | |
3857 Lisp_Object attrs, eol_type, charset_list, val; | |
3858 int ascii_compatible; | |
3859 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3860 int c; | |
3861 | |
3862 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3863 val = charset_list; | |
3864 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3865 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3866 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3867 | |
3868 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3869 | |
3870 while (charbuf < charbuf_end) | |
3871 { | |
3872 ASSURE_DESTINATION (safe_room); | |
3873 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3874 /* Now encode the character C. */ |
88365 | 3875 if (ASCII_CHAR_P (c) && ascii_compatible) |
3876 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
|
3877 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3878 { |
88365 | 3879 unsigned code; |
3880 struct charset *charset = char_charset (c, charset_list, &code); | |
3881 | |
3882 if (!charset) | |
3883 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3884 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
|
3885 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3886 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3887 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3888 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3889 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3890 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3891 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3892 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
|
3893 } |
88365 | 3894 } |
3895 if (code == CHARSET_INVALID_CODE (charset)) | |
3896 abort (); | |
3897 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
|
3898 { |
88365 | 3899 int c1, c2; |
3900 JIS_TO_SJIS (code); | |
3901 c1 = code >> 8, c2 = code & 0xFF; | |
3902 EMIT_TWO_BYTES (c1, c2); | |
3903 } | |
3904 else if (charset == charset_kana) | |
3905 EMIT_ONE_BYTE (code | 0x80); | |
3906 else | |
3907 EMIT_ONE_ASCII_BYTE (code & 0x7F); | |
3908 } | |
3909 } | |
3910 coding->result = CODING_RESULT_SUCCESS; | |
3911 coding->produced_char += produced_chars; | |
3912 coding->produced = dst - coding->destination; | |
3913 return 0; | |
3914 } | |
3915 | |
3916 static int | |
3917 encode_coding_big5 (coding) | |
3918 struct coding_system *coding; | |
3919 { | |
3920 int multibytep = coding->dst_multibyte; | |
3921 int *charbuf = coding->charbuf; | |
3922 int *charbuf_end = charbuf + coding->charbuf_used; | |
3923 unsigned char *dst = coding->destination + coding->produced; | |
3924 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3925 int safe_room = 4; | |
3926 int produced_chars = 0; | |
3927 Lisp_Object attrs, eol_type, charset_list, val; | |
3928 int ascii_compatible; | |
3929 struct charset *charset_roman, *charset_big5; | |
3930 int c; | |
3931 | |
3932 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3933 val = charset_list; | |
3934 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3935 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3936 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3937 | |
3938 while (charbuf < charbuf_end) | |
3939 { | |
3940 ASSURE_DESTINATION (safe_room); | |
3941 c = *charbuf++; | |
3942 /* Now encode the character C. */ | |
3943 if (ASCII_CHAR_P (c) && ascii_compatible) | |
3944 EMIT_ONE_ASCII_BYTE (c); | |
3945 else | |
3946 { | |
3947 unsigned code; | |
3948 struct charset *charset = char_charset (c, charset_list, &code); | |
3949 | |
3950 if (! charset) | |
3951 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3952 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
|
3953 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3954 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3955 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3956 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3957 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3958 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3959 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3960 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
|
3961 } |
88365 | 3962 } |
3963 if (code == CHARSET_INVALID_CODE (charset)) | |
3964 abort (); | |
3965 if (charset == charset_big5) | |
3966 { | |
3967 int c1, c2; | |
3968 | |
3969 c1 = code >> 8, c2 = code & 0xFF; | |
3970 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
|
3971 } |
17052 | 3972 else |
88365 | 3973 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
17052 | 3974 } |
88365 | 3975 } |
3976 coding->result = CODING_RESULT_SUCCESS; | |
3977 coding->produced_char += produced_chars; | |
3978 coding->produced = dst - coding->destination; | |
3979 return 0; | |
17052 | 3980 } |
3981 | |
3982 | |
88365 | 3983 /*** 10. CCL handlers ***/ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3984 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3985 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3986 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
|
3987 encoder/decoder are written in CCL program. If it is, return |
88365 | 3988 CATEGORY_MASK_CCL, else return 0. */ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3989 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3990 static int |
88365 | 3991 detect_coding_ccl (coding, mask) |
3992 struct coding_system *coding; | |
3993 int *mask; | |
3994 { | |
3995 unsigned char *src = coding->source, *src_base = src; | |
3996 unsigned char *src_end = coding->source + coding->src_bytes; | |
3997 int multibytep = coding->src_multibyte; | |
3998 int consumed_chars = 0; | |
3999 int found = 0; | |
4000 unsigned char *valids = CODING_CCL_VALIDS (coding); | |
4001 int head_ascii = coding->head_ascii; | |
4002 Lisp_Object attrs; | |
4003 | |
4004 coding = &coding_categories[coding_category_ccl]; | |
4005 attrs = CODING_ID_ATTRS (coding->id); | |
4006 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4007 src += head_ascii; | |
4008 | |
4009 while (1) | |
4010 { | |
4011 int c; | |
4012 ONE_MORE_BYTE (c); | |
4013 if (! valids[c]) | |
4014 break; | |
4015 if (!found && valids[c] > 1) | |
4016 found = 1; | |
4017 } | |
4018 *mask &= ~CATEGORY_MASK_CCL; | |
4019 return 0; | |
4020 | |
4021 no_more_source: | |
4022 if (!found) | |
4023 return 0; | |
4024 *mask &= CATEGORY_MASK_CCL; | |
4025 return 1; | |
4026 } | |
4027 | |
4028 static void | |
4029 decode_coding_ccl (coding) | |
4030 struct coding_system *coding; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4031 { |
88365 | 4032 unsigned char *src = coding->source + coding->consumed; |
4033 unsigned char *src_end = coding->source + coding->src_bytes; | |
4034 int *charbuf = coding->charbuf; | |
4035 int *charbuf_end = charbuf + coding->charbuf_size; | |
4036 int consumed_chars = 0; | |
4037 int multibytep = coding->src_multibyte; | |
4038 struct ccl_program ccl; | |
4039 int source_charbuf[1024]; | |
4040 int source_byteidx[1024]; | |
4041 | |
4042 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); | |
4043 | |
4044 while (src < src_end) | |
4045 { | |
4046 unsigned char *p = src; | |
4047 int *source, *source_end; | |
4048 int i = 0; | |
4049 | |
4050 if (multibytep) | |
4051 while (i < 1024 && p < src_end) | |
4052 { | |
4053 source_byteidx[i] = p - src; | |
4054 source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | |
4055 } | |
4056 else | |
4057 while (i < 1024 && p < src_end) | |
4058 source_charbuf[i++] = *p++; | |
4059 | |
4060 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) | |
4061 ccl.last_block = 1; | |
4062 | |
4063 source = source_charbuf; | |
4064 source_end = source + i; | |
4065 while (source < source_end) | |
4066 { | |
4067 ccl_driver (&ccl, source, charbuf, | |
4068 source_end - source, charbuf_end - charbuf); | |
4069 source += ccl.consumed; | |
4070 charbuf += ccl.produced; | |
4071 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
4072 break; | |
4073 } | |
4074 if (source < source_end) | |
4075 src += source_byteidx[source - source_charbuf]; | |
4076 else | |
4077 src = p; | |
4078 consumed_chars += source - source_charbuf; | |
4079 | |
4080 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
4081 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
4082 break; | |
4083 } | |
4084 | |
4085 switch (ccl.status) | |
4086 { | |
4087 case CCL_STAT_SUSPEND_BY_SRC: | |
4088 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4089 break; | |
4090 case CCL_STAT_SUSPEND_BY_DST: | |
4091 break; | |
4092 case CCL_STAT_QUIT: | |
4093 case CCL_STAT_INVALID_CMD: | |
4094 coding->result = CODING_RESULT_INTERRUPT; | |
4095 break; | |
4096 default: | |
4097 coding->result = CODING_RESULT_SUCCESS; | |
4098 break; | |
4099 } | |
4100 coding->consumed_char += consumed_chars; | |
4101 coding->consumed = src - coding->source; | |
4102 coding->charbuf_used = charbuf - coding->charbuf; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4103 } |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4104 |
88365 | 4105 static int |
4106 encode_coding_ccl (coding) | |
4107 struct coding_system *coding; | |
4108 { | |
4109 struct ccl_program ccl; | |
4110 int multibytep = coding->dst_multibyte; | |
4111 int *charbuf = coding->charbuf; | |
4112 int *charbuf_end = charbuf + coding->charbuf_used; | |
4113 unsigned char *dst = coding->destination + coding->produced; | |
4114 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4115 unsigned char *adjusted_dst_end = dst_end - 1; | |
4116 int destination_charbuf[1024]; | |
4117 int i, produced_chars = 0; | |
4118 | |
4119 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); | |
4120 | |
4121 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; | |
4122 ccl.dst_multibyte = coding->dst_multibyte; | |
4123 | |
4124 while (charbuf < charbuf_end && dst < adjusted_dst_end) | |
4125 { | |
4126 int dst_bytes = dst_end - dst; | |
4127 if (dst_bytes > 1024) | |
4128 dst_bytes = 1024; | |
4129 | |
4130 ccl_driver (&ccl, charbuf, destination_charbuf, | |
4131 charbuf_end - charbuf, dst_bytes); | |
4132 charbuf += ccl.consumed; | |
4133 if (multibytep) | |
4134 for (i = 0; i < ccl.produced; i++) | |
4135 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); | |
4136 else | |
4137 { | |
4138 for (i = 0; i < ccl.produced; i++) | |
4139 *dst++ = destination_charbuf[i] & 0xFF; | |
4140 produced_chars += ccl.produced; | |
4141 } | |
4142 } | |
4143 | |
4144 switch (ccl.status) | |
4145 { | |
4146 case CCL_STAT_SUSPEND_BY_SRC: | |
4147 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4148 break; | |
4149 case CCL_STAT_SUSPEND_BY_DST: | |
4150 coding->result = CODING_RESULT_INSUFFICIENT_DST; | |
4151 break; | |
4152 case CCL_STAT_QUIT: | |
4153 case CCL_STAT_INVALID_CMD: | |
4154 coding->result = CODING_RESULT_INTERRUPT; | |
4155 break; | |
4156 default: | |
4157 coding->result = CODING_RESULT_SUCCESS; | |
4158 break; | |
4159 } | |
4160 | |
4161 coding->produced_char += produced_chars; | |
4162 coding->produced = dst - coding->destination; | |
4163 return 0; | |
4164 } | |
4165 | |
4166 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4167 |
88365 | 4168 /*** 10, 11. no-conversion handlers ***/ |
17052 | 4169 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4170 /* 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
|
4171 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4172 static void |
88365 | 4173 decode_coding_raw_text (coding) |
17052 | 4174 struct coding_system *coding; |
4175 { | |
88365 | 4176 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
|
4177 coding->consumed_char = 0; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4178 coding->consumed = 0; |
88365 | 4179 coding->result = CODING_RESULT_SUCCESS; |
4180 } | |
4181 | |
4182 static int | |
4183 encode_coding_raw_text (coding) | |
4184 struct coding_system *coding; | |
4185 { | |
4186 int multibytep = coding->dst_multibyte; | |
4187 int *charbuf = coding->charbuf; | |
4188 int *charbuf_end = coding->charbuf + coding->charbuf_used; | |
4189 unsigned char *dst = coding->destination + coding->produced; | |
4190 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4191 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
|
4192 int c; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4193 |
88365 | 4194 if (multibytep) |
4195 { | |
4196 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
4197 | |
4198 if (coding->src_multibyte) | |
4199 while (charbuf < charbuf_end) | |
4200 { | |
4201 ASSURE_DESTINATION (safe_room); | |
4202 c = *charbuf++; | |
4203 if (ASCII_CHAR_P (c)) | |
4204 EMIT_ONE_ASCII_BYTE (c); | |
4205 else if (CHAR_BYTE8_P (c)) | |
4206 { | |
4207 c = CHAR_TO_BYTE8 (c); | |
4208 EMIT_ONE_BYTE (c); | |
4209 } | |
4210 else | |
4211 { | |
4212 unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | |
4213 | |
4214 CHAR_STRING_ADVANCE (c, p1); | |
4215 while (p0 < p1) | |
4216 EMIT_ONE_BYTE (*p0); | |
4217 } | |
4218 } | |
4219 else | |
4220 while (charbuf < charbuf_end) | |
4221 { | |
4222 ASSURE_DESTINATION (safe_room); | |
4223 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4224 EMIT_ONE_BYTE (c); |
88365 | 4225 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4226 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4227 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4228 { |
88365 | 4229 if (coding->src_multibyte) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4230 { |
88365 | 4231 int safe_room = MAX_MULTIBYTE_LENGTH; |
4232 | |
4233 while (charbuf < charbuf_end) | |
4234 { | |
4235 ASSURE_DESTINATION (safe_room); | |
4236 c = *charbuf++; | |
4237 if (ASCII_CHAR_P (c)) | |
4238 *dst++ = c; | |
4239 else if (CHAR_BYTE8_P (c)) | |
4240 *dst++ = CHAR_TO_BYTE8 (c); | |
4241 else | |
4242 CHAR_STRING_ADVANCE (c, dst); | |
4243 produced_chars++; | |
4244 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4245 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4246 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4247 { |
88365 | 4248 ASSURE_DESTINATION (charbuf_end - charbuf); |
4249 while (charbuf < charbuf_end && dst < dst_end) | |
4250 *dst++ = *charbuf++; | |
4251 produced_chars = dst - (coding->destination + coding->dst_bytes); | |
4252 } | |
4253 } | |
4254 coding->result = CODING_RESULT_SUCCESS; | |
4255 coding->produced_char += produced_chars; | |
4256 coding->produced = dst - coding->destination; | |
4257 return 0; | |
4258 } | |
4259 | |
4260 static int | |
4261 detect_coding_charset (coding, mask) | |
4262 struct coding_system *coding; | |
4263 int *mask; | |
4264 { | |
4265 unsigned char *src = coding->source, *src_base = src; | |
4266 unsigned char *src_end = coding->source + coding->src_bytes; | |
4267 int multibytep = coding->src_multibyte; | |
4268 int consumed_chars = 0; | |
4269 Lisp_Object attrs, valids; | |
4270 | |
4271 coding = &coding_categories[coding_category_charset]; | |
4272 attrs = CODING_ID_ATTRS (coding->id); | |
4273 valids = AREF (attrs, coding_attr_charset_valids); | |
4274 | |
4275 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4276 src += coding->head_ascii; | |
4277 | |
4278 while (1) | |
4279 { | |
4280 int c; | |
4281 | |
4282 ONE_MORE_BYTE (c); | |
4283 if (NILP (AREF (valids, c))) | |
4284 break; | |
4285 } | |
4286 *mask &= ~CATEGORY_MASK_CHARSET; | |
4287 return 0; | |
4288 | |
4289 no_more_source: | |
4290 *mask &= CATEGORY_MASK_CHARSET; | |
4291 return 1; | |
4292 } | |
4293 | |
4294 static void | |
4295 decode_coding_charset (coding) | |
4296 struct coding_system *coding; | |
4297 { | |
4298 unsigned char *src = coding->source + coding->consumed; | |
4299 unsigned char *src_end = coding->source + coding->src_bytes; | |
4300 unsigned char *src_base; | |
4301 int *charbuf = coding->charbuf; | |
4302 int *charbuf_end = charbuf + coding->charbuf_size; | |
4303 int consumed_chars = 0, consumed_chars_base; | |
4304 int multibytep = coding->src_multibyte; | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4305 Lisp_Object attrs, eol_type, charset_list, valids; |
88365 | 4306 |
4307 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
|
4308 valids = AREF (attrs, coding_attr_charset_valids); |
88365 | 4309 |
4310 while (1) | |
4311 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4312 int c; |
88365 | 4313 |
4314 src_base = src; | |
4315 consumed_chars_base = consumed_chars; | |
4316 | |
4317 if (charbuf >= charbuf_end) | |
4318 break; | |
4319 | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4320 ONE_MORE_BYTE (c); |
88365 | 4321 if (c == '\r') |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4322 { |
88365 | 4323 if (EQ (eol_type, Qdos)) |
4324 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4325 if (src < src_end |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4326 && *src == '\n') |
88365 | 4327 ONE_MORE_BYTE (c); |
4328 } | |
4329 else if (EQ (eol_type, Qmac)) | |
4330 c = '\n'; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4331 } |
88365 | 4332 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4333 { |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4334 Lisp_Object val; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4335 struct charset *charset; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4336 int c1; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4337 |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4338 val = AREF (valids, c); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4339 if (NILP (val)) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4340 goto invalid_code; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4341 charset = CHARSET_FROM_ID (XFASTINT (val)); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4342 if (CHARSET_DIMENSION (charset) > 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4343 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4344 ONE_MORE_BYTE (c1); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4345 c = (c << 8) | c1; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4346 if (CHARSET_DIMENSION (charset) > 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4347 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4348 ONE_MORE_BYTE (c1); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4349 c = (c << 8) | c1; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4350 if (CHARSET_DIMENSION (charset) > 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4351 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4352 ONE_MORE_BYTE (c1); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4353 c = (c << 8) | c1; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4354 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4355 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4356 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4357 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
88365 | 4358 if (c < 0) |
4359 goto invalid_code; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4360 } |
88365 | 4361 *charbuf++ = c; |
4362 continue; | |
4363 | |
4364 invalid_code: | |
4365 src = src_base; | |
4366 consumed_chars = consumed_chars_base; | |
4367 ONE_MORE_BYTE (c); | |
4368 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
4369 coding->errors++; | |
4370 } | |
4371 | |
4372 no_more_source: | |
4373 coding->consumed_char += consumed_chars_base; | |
4374 coding->consumed = src_base - coding->source; | |
4375 coding->charbuf_used = charbuf - coding->charbuf; | |
4376 } | |
4377 | |
4378 static int | |
4379 encode_coding_charset (coding) | |
4380 struct coding_system *coding; | |
4381 { | |
4382 int multibytep = coding->dst_multibyte; | |
4383 int *charbuf = coding->charbuf; | |
4384 int *charbuf_end = charbuf + coding->charbuf_used; | |
4385 unsigned char *dst = coding->destination + coding->produced; | |
4386 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4387 int safe_room = MAX_MULTIBYTE_LENGTH; | |
4388 int produced_chars = 0; | |
4389 Lisp_Object attrs, eol_type, charset_list; | |
4390 int ascii_compatible; | |
4391 int c; | |
4392 | |
4393 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4394 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4395 | |
4396 while (charbuf < charbuf_end) | |
4397 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4398 struct charset *charset; |
88365 | 4399 unsigned code; |
4400 | |
4401 ASSURE_DESTINATION (safe_room); | |
4402 c = *charbuf++; | |
4403 if (ascii_compatible && ASCII_CHAR_P (c)) | |
4404 EMIT_ONE_ASCII_BYTE (c); | |
4405 else | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4406 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4407 charset = char_charset (c, charset_list, &code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4408 if (charset) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4409 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4410 if (CHARSET_DIMENSION (charset) == 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4411 EMIT_ONE_BYTE (code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4412 else if (CHARSET_DIMENSION (charset) == 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4413 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4414 else if (CHARSET_DIMENSION (charset) == 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4415 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
|
4416 else |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4417 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
|
4418 (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4419 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4420 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4421 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4422 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
|
4423 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4424 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4425 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4426 EMIT_ONE_BYTE (c); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4427 } |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4428 } |
88365 | 4429 } |
4430 | |
4431 coding->result = CODING_RESULT_SUCCESS; | |
4432 coding->produced_char += produced_chars; | |
4433 coding->produced = dst - coding->destination; | |
4434 return 0; | |
17052 | 4435 } |
4436 | |
4437 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4438 /*** 7. C library functions ***/ |
17052 | 4439 |
88365 | 4440 /* In Emacs Lisp, coding system is represented by a Lisp symbol which |
17052 | 4441 has a property `coding-system'. The value of this property is a |
88365 | 4442 vector of length 5 (called as coding-vector). Among elements of |
17052 | 4443 this vector, the first (element[0]) and the fifth (element[4]) |
4444 carry important information for decoding/encoding. Before | |
4445 decoding/encoding, this information should be set in fields of a | |
4446 structure of type `coding_system'. | |
4447 | |
88365 | 4448 A value of property `coding-system' can be a symbol of another |
17052 | 4449 subsidiary coding-system. In that case, Emacs gets coding-vector |
4450 from that symbol. | |
4451 | |
4452 `element[0]' contains information to be set in `coding->type'. The | |
4453 value and its meaning is as follows: | |
4454 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4455 0 -- coding_type_emacs_mule |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4456 1 -- coding_type_sjis |
88365 | 4457 2 -- coding_type_iso_2022 |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4458 3 -- coding_type_big5 |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4459 4 -- coding_type_ccl encoder/decoder written in CCL |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4460 nil -- coding_type_no_conversion |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4461 t -- coding_type_undecided (automatic conversion on decoding, |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4462 no-conversion on encoding) |
17052 | 4463 |
4464 `element[4]' contains information to be set in `coding->flags' and | |
4465 `coding->spec'. The meaning varies by `coding->type'. | |
4466 | |
88365 | 4467 If `coding->type' is `coding_type_iso_2022', element[4] is a vector |
17052 | 4468 of length 32 (of which the first 13 sub-elements are used now). |
4469 Meanings of these sub-elements are: | |
4470 | |
88365 | 4471 sub-element[N] where N is 0 through 3: to be set in `coding->spec.iso_2022' |
17052 | 4472 If the value is an integer of valid charset, the charset is |
4473 assumed to be designated to graphic register N initially. | |
4474 | |
4475 If the value is minus, it is a minus value of charset which | |
4476 reserves graphic register N, which means that the charset is | |
4477 not designated initially but should be designated to graphic | |
4478 register N just before encoding a character in that charset. | |
4479 | |
4480 If the value is nil, graphic register N is never used on | |
4481 encoding. | |
88365 | 4482 |
17052 | 4483 sub-element[N] where N is 4 through 11: to be set in `coding->flags' |
4484 Each value takes t or nil. See the section ISO2022 of | |
4485 `coding.h' for more information. | |
4486 | |
4487 If `coding->type' is `coding_type_big5', element[4] is t to denote | |
4488 BIG5-ETen or nil to denote BIG5-HKU. | |
4489 | |
4490 If `coding->type' takes the other value, element[4] is ignored. | |
4491 | |
88365 | 4492 Emacs Lisp's coding system also carries information about format of |
17052 | 4493 end-of-line in a value of property `eol-type'. If the value is |
88365 | 4494 integer, 0 means eol_lf, 1 means eol_crlf, and 2 means eol_cr. If |
4495 it is not integer, it should be a vector of subsidiary coding | |
4496 systems of which property `eol-type' has one of above values. | |
17052 | 4497 |
4498 */ | |
4499 | |
88365 | 4500 /* Setup coding context CODING from information about CODING_SYSTEM. |
4501 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
4502 CODING_SYSTEM is invalid, signal an error. */ | |
4503 | |
4504 void | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4505 setup_coding_system (coding_system, coding) |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4506 Lisp_Object coding_system; |
17052 | 4507 struct coding_system *coding; |
4508 { | |
88365 | 4509 Lisp_Object attrs; |
4510 Lisp_Object eol_type; | |
4511 Lisp_Object coding_type; | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
4512 Lisp_Object val; |
17052 | 4513 |
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
4514 if (NILP (coding_system)) |
88365 | 4515 coding_system = Qno_conversion; |
4516 | |
4517 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
4518 | |
4519 attrs = CODING_ID_ATTRS (coding->id); | |
4520 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4521 | |
4522 coding->mode = 0; | |
4523 coding->head_ascii = -1; | |
4524 coding->common_flags | |
4525 = (VECTORP (eol_type) ? CODING_REQUIRE_DETECTION_MASK : 0); | |
4526 | |
4527 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4528 coding->max_charset_id = XSTRING (val)->size - 1; | |
4529 coding->safe_charsets = (char *) XSTRING (val)->data; | |
4530 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); | |
4531 | |
4532 coding_type = CODING_ATTR_TYPE (attrs); | |
4533 if (EQ (coding_type, Qundecided)) | |
4534 { | |
4535 coding->detector = NULL; | |
4536 coding->decoder = decode_coding_raw_text; | |
4537 coding->encoder = encode_coding_raw_text; | |
4538 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
4539 } | |
4540 else if (EQ (coding_type, Qiso_2022)) | |
4541 { | |
4542 int i; | |
4543 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
4544 | |
4545 /* Invoke graphic register 0 to plane 0. */ | |
4546 CODING_ISO_INVOCATION (coding, 0) = 0; | |
4547 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
4548 CODING_ISO_INVOCATION (coding, 1) | |
4549 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
4550 /* Setup the initial status of designation. */ | |
4551 for (i = 0; i < 4; i++) | |
4552 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
4553 /* Not single shifting initially. */ | |
4554 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
4555 /* Beginning of buffer should also be regarded as bol. */ | |
4556 CODING_ISO_BOL (coding) = 1; | |
4557 coding->detector = detect_coding_iso_2022; | |
4558 coding->decoder = decode_coding_iso_2022; | |
4559 coding->encoder = encode_coding_iso_2022; | |
4560 if (flags & CODING_ISO_FLAG_SAFE) | |
4561 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4562 coding->common_flags |
88365 | 4563 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4564 | CODING_REQUIRE_FLUSHING_MASK); | |
4565 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
4566 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
4567 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
|
4568 { |
88365 | 4569 setup_iso_safe_charsets (attrs); |
4570 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4571 coding->max_charset_id = XSTRING (val)->size - 1; | |
4572 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
|
4573 } |
88365 | 4574 CODING_ISO_FLAGS (coding) = flags; |
4575 } | |
4576 else if (EQ (coding_type, Qcharset)) | |
4577 { | |
4578 coding->detector = detect_coding_charset; | |
4579 coding->decoder = decode_coding_charset; | |
4580 coding->encoder = encode_coding_charset; | |
4581 coding->common_flags | |
4582 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4583 } | |
4584 else if (EQ (coding_type, Qutf_8)) | |
4585 { | |
4586 coding->detector = detect_coding_utf_8; | |
4587 coding->decoder = decode_coding_utf_8; | |
4588 coding->encoder = encode_coding_utf_8; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
4589 coding->common_flags |
88365 | 4590 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4591 } | |
4592 else if (EQ (coding_type, Qutf_16)) | |
4593 { | |
4594 val = AREF (attrs, coding_attr_utf_16_bom); | |
4595 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_16_detect_bom | |
4596 : EQ (val, Qt) ? utf_16_with_bom | |
4597 : utf_16_without_bom); | |
4598 val = AREF (attrs, coding_attr_utf_16_endian); | |
4599 CODING_UTF_16_ENDIAN (coding) = (NILP (val) ? utf_16_big_endian | |
4600 : utf_16_little_endian); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
4601 CODING_UTF_16_SURROGATE (coding) = 0; |
88365 | 4602 coding->detector = detect_coding_utf_16; |
4603 coding->decoder = decode_coding_utf_16; | |
4604 coding->encoder = encode_coding_utf_16; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4605 coding->common_flags |
88365 | 4606 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4607 } | |
4608 else if (EQ (coding_type, Qccl)) | |
4609 { | |
4610 coding->detector = detect_coding_ccl; | |
4611 coding->decoder = decode_coding_ccl; | |
4612 coding->encoder = encode_coding_ccl; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4613 coding->common_flags |
88365 | 4614 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4615 | CODING_REQUIRE_FLUSHING_MASK); | |
4616 } | |
4617 else if (EQ (coding_type, Qemacs_mule)) | |
4618 { | |
4619 coding->detector = detect_coding_emacs_mule; | |
4620 coding->decoder = decode_coding_emacs_mule; | |
4621 coding->encoder = encode_coding_emacs_mule; | |
4622 coding->common_flags | |
4623 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4624 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) | |
4625 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
4626 { | |
4627 Lisp_Object tail, safe_charsets; | |
4628 int max_charset_id = 0; | |
4629 | |
4630 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4631 tail = XCDR (tail)) | |
4632 if (max_charset_id < XFASTINT (XCAR (tail))) | |
4633 max_charset_id = XFASTINT (XCAR (tail)); | |
4634 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
4635 make_number (255)); | |
4636 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4637 tail = XCDR (tail)) | |
4638 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
4639 coding->max_charset_id = max_charset_id; | |
4640 coding->safe_charsets = (char *) XSTRING (safe_charsets)->data; | |
4641 } | |
4642 } | |
4643 else if (EQ (coding_type, Qshift_jis)) | |
4644 { | |
4645 coding->detector = detect_coding_sjis; | |
4646 coding->decoder = decode_coding_sjis; | |
4647 coding->encoder = encode_coding_sjis; | |
4648 coding->common_flags | |
4649 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4650 } | |
4651 else if (EQ (coding_type, Qbig5)) | |
4652 { | |
4653 coding->detector = detect_coding_big5; | |
4654 coding->decoder = decode_coding_big5; | |
4655 coding->encoder = encode_coding_big5; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4656 coding->common_flags |
88365 | 4657 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4658 } | |
4659 else /* EQ (coding_type, Qraw_text) */ | |
4660 { | |
4661 coding->detector = NULL; | |
4662 coding->decoder = decode_coding_raw_text; | |
4663 coding->encoder = encode_coding_raw_text; | |
4664 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
4665 } | |
4666 | |
4667 return; | |
17052 | 4668 } |
4669 | |
88365 | 4670 /* Return raw-text or one of its subsidiaries that has the same |
4671 eol_type as CODING-SYSTEM. */ | |
4672 | |
4673 Lisp_Object | |
4674 raw_text_coding_system (coding_system) | |
4675 Lisp_Object coding_system; | |
26847 | 4676 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4677 Lisp_Object spec, attrs; |
88365 | 4678 Lisp_Object eol_type, raw_text_eol_type; |
4679 | |
4680 spec = CODING_SYSTEM_SPEC (coding_system); | |
4681 attrs = AREF (spec, 0); | |
4682 | |
4683 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
4684 return coding_system; | |
4685 | |
4686 eol_type = AREF (spec, 2); | |
4687 if (VECTORP (eol_type)) | |
4688 return Qraw_text; | |
4689 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
4690 raw_text_eol_type = AREF (spec, 2); | |
4691 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
4692 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
4693 : AREF (raw_text_eol_type, 2)); | |
26847 | 4694 } |
4695 | |
88365 | 4696 |
4697 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
4698 does, return one of the subsidiary that has the same eol-spec as | |
4699 PARENT. Otherwise, return CODING_SYSTEM. */ | |
4700 | |
4701 Lisp_Object | |
4702 coding_inherit_eol_type (coding_system, parent) | |
88473 | 4703 Lisp_Object coding_system, parent; |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4704 { |
88365 | 4705 Lisp_Object spec, attrs, eol_type; |
4706 | |
4707 spec = CODING_SYSTEM_SPEC (coding_system); | |
4708 attrs = AREF (spec, 0); | |
4709 eol_type = AREF (spec, 2); | |
4710 if (VECTORP (eol_type)) | |
4711 { | |
4712 Lisp_Object parent_spec; | |
4713 Lisp_Object parent_eol_type; | |
4714 | |
4715 parent_spec | |
4716 = CODING_SYSTEM_SPEC (buffer_defaults.buffer_file_coding_system); | |
4717 parent_eol_type = AREF (parent_spec, 2); | |
4718 if (EQ (parent_eol_type, Qunix)) | |
4719 coding_system = AREF (eol_type, 0); | |
4720 else if (EQ (parent_eol_type, Qdos)) | |
4721 coding_system = AREF (eol_type, 1); | |
4722 else if (EQ (parent_eol_type, Qmac)) | |
4723 coding_system = AREF (eol_type, 2); | |
4724 } | |
4725 return coding_system; | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4726 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4727 |
17052 | 4728 /* Emacs has a mechanism to automatically detect a coding system if it |
4729 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
4730 it's impossible to distinguish some coding systems accurately | |
4731 because they use the same range of codes. So, at first, coding | |
4732 systems are categorized into 7, those are: | |
4733 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4734 o coding-category-emacs-mule |
17052 | 4735 |
4736 The category for a coding system which has the same code range | |
4737 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
|
4738 symbol) `emacs-mule' by default. |
17052 | 4739 |
4740 o coding-category-sjis | |
4741 | |
4742 The category for a coding system which has the same code range | |
4743 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
|
4744 symbol) `japanese-shift-jis' by default. |
17052 | 4745 |
4746 o coding-category-iso-7 | |
4747 | |
4748 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
|
4749 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
|
4750 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
|
4751 charsets. Assigned the coding-system (Lisp symbol) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4752 `iso-2022-7bit' by default. |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4753 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4754 o coding-category-iso-7-tight |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4755 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4756 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
|
4757 encode/decode only the specified charsets. |
17052 | 4758 |
4759 o coding-category-iso-8-1 | |
4760 | |
4761 The category for a coding system which has the same code range | |
4762 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
|
4763 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
|
4764 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
|
4765 symbol) `iso-latin-1' by default. |
17052 | 4766 |
4767 o coding-category-iso-8-2 | |
4768 | |
4769 The category for a coding system which has the same code range | |
4770 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
|
4771 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
|
4772 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
|
4773 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
|
4774 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4775 o coding-category-iso-7-else |
17052 | 4776 |
4777 The category for a coding system which has the same code range | |
88365 | 4778 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
|
4779 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
|
4780 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
|
4781 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4782 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
|
4783 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4784 The category for a coding system which has the same code range |
88365 | 4785 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
|
4786 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
|
4787 symbol) `iso-2022-8bit-ss2' by default. |
17052 | 4788 |
4789 o coding-category-big5 | |
4790 | |
4791 The category for a coding system which has the same code range | |
4792 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
|
4793 `cn-big5' by default. |
17052 | 4794 |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4795 o coding-category-utf-8 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4796 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4797 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
|
4798 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
|
4799 symbol) `utf-8' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4800 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4801 o coding-category-utf-16-be |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4802 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4803 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
|
4804 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
|
4805 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
|
4806 `utf-16-be' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4807 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4808 o coding-category-utf-16-le |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4809 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4810 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
|
4811 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
|
4812 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
|
4813 symbol) `utf-16-le' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4814 |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4815 o coding-category-ccl |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4816 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4817 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
|
4818 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
|
4819 coding system is assigned. |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4820 |
17052 | 4821 o coding-category-binary |
4822 | |
4823 The category for a coding system not categorized in any of the | |
4824 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
|
4825 `no-conversion' by default. |
17052 | 4826 |
4827 Each of them is a Lisp symbol and the value is an actual | |
88365 | 4828 `coding-system's (this is also a Lisp symbol) assigned by a user. |
17052 | 4829 What Emacs does actually is to detect a category of coding system. |
4830 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
88365 | 4831 decide only one possible category, it selects a category of the |
17052 | 4832 highest priority. Priorities of categories are also specified by a |
4833 user in a Lisp variable `coding-category-list'. | |
4834 | |
4835 */ | |
4836 | |
88365 | 4837 #define EOL_SEEN_NONE 0 |
4838 #define EOL_SEEN_LF 1 | |
4839 #define EOL_SEEN_CR 2 | |
4840 #define EOL_SEEN_CRLF 4 | |
4841 | |
4842 /* Detect how end-of-line of a text of length CODING->src_bytes | |
4843 pointed by CODING->source is encoded. Return one of | |
4844 EOL_SEEN_XXX. */ | |
17052 | 4845 |
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
4846 #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
|
4847 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4848 static int |
88365 | 4849 detect_eol (coding, source, src_bytes) |
4850 struct coding_system *coding; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4851 unsigned char *source; |
88365 | 4852 EMACS_INT src_bytes; |
17052 | 4853 { |
88365 | 4854 Lisp_Object attrs, coding_type; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4855 unsigned char *src = source, *src_end = src + src_bytes; |
17052 | 4856 unsigned char c; |
88365 | 4857 int total = 0; |
4858 int eol_seen = EOL_SEEN_NONE; | |
4859 | |
4860 attrs = CODING_ID_ATTRS (coding->id); | |
4861 coding_type = CODING_ATTR_TYPE (attrs); | |
4862 | |
4863 if (EQ (coding_type, Qccl)) | |
4864 { | |
4865 int msb, lsb; | |
4866 | |
4867 msb = coding->spec.utf_16.endian == utf_16_little_endian; | |
4868 lsb = 1 - msb; | |
4869 | |
4870 while (src + 1 < src_end) | |
17052 | 4871 { |
88365 | 4872 c = src[lsb]; |
4873 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
|
4874 { |
88365 | 4875 int this_eol; |
4876 | |
4877 if (c == '\n') | |
4878 this_eol = EOL_SEEN_LF; | |
4879 else if (src + 3 >= src_end | |
4880 || src[msb + 2] != 0 | |
4881 || src[lsb + 2] != '\n') | |
4882 this_eol = EOL_SEEN_CR; | |
4883 else | |
4884 this_eol = EOL_SEEN_CRLF; | |
4885 | |
4886 if (eol_seen == EOL_SEEN_NONE) | |
4887 /* This is the first end-of-line. */ | |
4888 eol_seen = this_eol; | |
4889 else if (eol_seen != this_eol) | |
4890 { | |
4891 /* The found type is different from what found before. */ | |
4892 eol_seen = EOL_SEEN_LF; | |
4893 break; | |
4894 } | |
4895 if (++total == MAX_EOL_CHECK_COUNT) | |
4896 break; | |
4897 } | |
4898 src += 2; | |
4899 } | |
4900 } | |
4901 else | |
4902 { | |
4903 while (src < src_end) | |
4904 { | |
4905 c = *src++; | |
4906 if (c == '\n' || c == '\r') | |
4907 { | |
4908 int this_eol; | |
4909 | |
4910 if (c == '\n') | |
4911 this_eol = EOL_SEEN_LF; | |
4912 else if (src >= src_end || *src != '\n') | |
4913 this_eol = EOL_SEEN_CR; | |
4914 else | |
4915 this_eol = EOL_SEEN_CRLF, src++; | |
4916 | |
4917 if (eol_seen == EOL_SEEN_NONE) | |
4918 /* This is the first end-of-line. */ | |
4919 eol_seen = this_eol; | |
4920 else if (eol_seen != this_eol) | |
4921 { | |
4922 /* The found type is different from what found before. */ | |
4923 eol_seen = EOL_SEEN_LF; | |
4924 break; | |
4925 } | |
4926 if (++total == MAX_EOL_CHECK_COUNT) | |
4927 break; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4928 } |
17052 | 4929 } |
4930 } | |
88365 | 4931 return eol_seen; |
17052 | 4932 } |
4933 | |
88365 | 4934 |
4935 static void | |
4936 adjust_coding_eol_type (coding, eol_seen) | |
4937 struct coding_system *coding; | |
4938 int eol_seen; | |
4939 { | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4940 Lisp_Object eol_type; |
88365 | 4941 |
4942 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4943 if (eol_seen & EOL_SEEN_LF) | |
4944 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); | |
4945 else if (eol_type & EOL_SEEN_CRLF) | |
4946 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); | |
4947 else if (eol_type & EOL_SEEN_CR) | |
4948 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); | |
4949 } | |
4950 | |
4951 /* Detect how a text specified in CODING is encoded. If a coding | |
4952 system is detected, update fields of CODING by the detected coding | |
4953 system. */ | |
4954 | |
4955 void | |
4956 detect_coding (coding) | |
4957 struct coding_system *coding; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4958 { |
88365 | 4959 unsigned char *src, *src_end; |
4960 Lisp_Object attrs, coding_type; | |
4961 | |
4962 coding->consumed = coding->consumed_char = 0; | |
4963 coding->produced = coding->produced_char = 0; | |
4964 coding_set_source (coding); | |
4965 | |
4966 src_end = coding->source + coding->src_bytes; | |
4967 | |
4968 /* If we have not yet decided the text encoding type, detect it | |
4969 now. */ | |
4970 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
4971 { | |
4972 int mask = CATEGORY_MASK_ANY; | |
4973 int c, i; | |
4974 | |
4975 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
|
4976 { |
88365 | 4977 c = *src; |
4978 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
4979 || c == ISO_CODE_SI | |
4980 || c == ISO_CODE_SO))) | |
4981 break; | |
4982 } | |
4983 coding->head_ascii = src - (coding->source + coding->consumed); | |
4984 | |
4985 if (coding->head_ascii < coding->src_bytes) | |
4986 { | |
4987 int detected = 0; | |
4988 | |
4989 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
|
4990 { |
88365 | 4991 enum coding_category category = coding_priorities[i]; |
4992 struct coding_system *this = coding_categories + category; | |
4993 | |
4994 if (category >= coding_category_raw_text | |
4995 || detected & (1 << category)) | |
4996 continue; | |
4997 | |
4998 if (this->id < 0) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4999 { |
88365 | 5000 /* No coding system of this category is defined. */ |
5001 mask &= ~(1 << category); | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5002 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5003 else |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5004 { |
88365 | 5005 detected |= detected_mask[category]; |
5006 if ((*(this->detector)) (coding, &mask)) | |
5007 break; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5008 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5009 } |
88365 | 5010 if (! mask) |
5011 setup_coding_system (Qraw_text, coding); | |
5012 else if (mask != CATEGORY_MASK_ANY) | |
5013 for (i = 0; i < coding_category_raw_text; i++) | |
5014 { | |
5015 enum coding_category category = coding_priorities[i]; | |
5016 struct coding_system *this = coding_categories + category; | |
5017 | |
5018 if (mask & (1 << category)) | |
5019 { | |
5020 setup_coding_system (CODING_ID_NAME (this->id), coding); | |
5021 break; | |
5022 } | |
5023 } | |
5024 } | |
5025 } | |
5026 | |
5027 attrs = CODING_ID_ATTRS (coding->id); | |
5028 coding_type = CODING_ATTR_TYPE (attrs); | |
5029 | |
5030 /* If we have not yet decided the EOL type, detect it now. But, the | |
5031 detection is impossible for a CCL based coding system, in which | |
5032 case, we detct the EOL type after decoding. */ | |
5033 if (VECTORP (CODING_ID_EOL_TYPE (coding->id)) | |
5034 && ! EQ (coding_type, Qccl)) | |
5035 { | |
5036 int eol_seen = detect_eol (coding, coding->source, coding->src_bytes); | |
5037 | |
5038 if (eol_seen != EOL_SEEN_NONE) | |
5039 adjust_coding_eol_type (coding, eol_seen); | |
5040 } | |
5041 } | |
5042 | |
5043 | |
5044 static void | |
5045 decode_eol (coding) | |
5046 struct coding_system *coding; | |
5047 { | |
5048 if (VECTORP (CODING_ID_EOL_TYPE (coding->id))) | |
5049 { | |
5050 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5051 unsigned char *pend = p + coding->produced; | |
5052 int eol_seen = EOL_SEEN_NONE; | |
5053 | |
5054 for (; p < pend; p++) | |
5055 { | |
5056 if (*p == '\n') | |
5057 eol_seen |= EOL_SEEN_LF; | |
5058 else if (*p == '\r') | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5059 { |
88365 | 5060 if (p + 1 < pend && *(p + 1) == '\n') |
5061 { | |
5062 eol_seen |= EOL_SEEN_CRLF; | |
5063 p++; | |
5064 } | |
5065 else | |
5066 eol_seen |= EOL_SEEN_CR; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5067 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5068 } |
88365 | 5069 if (eol_seen != EOL_SEEN_NONE) |
5070 adjust_coding_eol_type (coding, eol_seen); | |
5071 } | |
5072 | |
5073 if (EQ (CODING_ID_EOL_TYPE (coding->id), Qmac)) | |
5074 { | |
5075 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5076 unsigned char *pend = p + coding->produced; | |
5077 | |
5078 for (; p < pend; p++) | |
5079 if (*p == '\r') | |
5080 *p = '\n'; | |
5081 } | |
5082 else if (EQ (CODING_ID_EOL_TYPE (coding->id), Qdos)) | |
5083 { | |
5084 unsigned char *p, *pbeg, *pend; | |
5085 Lisp_Object undo_list; | |
5086 | |
5087 move_gap_both (coding->dst_pos + coding->produced_char, | |
5088 coding->dst_pos_byte + coding->produced); | |
5089 undo_list = current_buffer->undo_list; | |
5090 current_buffer->undo_list = Qt; | |
5091 del_range_2 (coding->dst_pos, coding->dst_pos_byte, GPT, GPT_BYTE, Qnil); | |
5092 current_buffer->undo_list = undo_list; | |
5093 pbeg = GPT_ADDR; | |
5094 pend = pbeg + coding->produced; | |
5095 | |
5096 for (p = pend - 1; p >= pbeg; p--) | |
5097 if (*p == '\r') | |
5098 { | |
5099 safe_bcopy ((char *) (p + 1), (char *) p, pend - p - 1); | |
5100 pend--; | |
5101 } | |
5102 coding->produced_char -= coding->produced - (pend - pbeg); | |
5103 coding->produced = pend - pbeg; | |
5104 insert_from_gap (coding->produced_char, coding->produced); | |
17052 | 5105 } |
5106 } | |
5107 | |
88365 | 5108 static void |
5109 translate_chars (coding, table) | |
17052 | 5110 struct coding_system *coding; |
88365 | 5111 Lisp_Object table; |
17052 | 5112 { |
88365 | 5113 int *charbuf = coding->charbuf; |
5114 int *charbuf_end = charbuf + coding->charbuf_used; | |
5115 int c; | |
5116 | |
5117 if (coding->chars_at_source) | |
5118 return; | |
5119 | |
5120 while (charbuf < charbuf_end) | |
5121 { | |
5122 c = *charbuf; | |
5123 if (c < 0) | |
5124 charbuf += c; | |
5125 else | |
5126 *charbuf++ = translate_char (table, c); | |
5127 } | |
17052 | 5128 } |
5129 | |
88365 | 5130 static int |
5131 produce_chars (coding) | |
5132 struct coding_system *coding; | |
17052 | 5133 { |
88365 | 5134 unsigned char *dst = coding->destination + coding->produced; |
5135 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5136 int produced; | |
5137 int produced_chars = 0; | |
5138 | |
5139 if (! coding->chars_at_source) | |
5140 { | |
5141 /* Characters are in coding->charbuf. */ | |
5142 int *buf = coding->charbuf; | |
5143 int *buf_end = buf + coding->charbuf_used; | |
5144 unsigned char *adjusted_dst_end; | |
5145 | |
5146 if (BUFFERP (coding->src_object) | |
5147 && EQ (coding->src_object, coding->dst_object)) | |
5148 dst_end = coding->source + coding->consumed; | |
5149 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5150 | |
5151 while (buf < buf_end) | |
5152 { | |
5153 int c = *buf++; | |
5154 | |
5155 if (dst >= adjusted_dst_end) | |
5156 { | |
5157 dst = alloc_destination (coding, | |
5158 buf_end - buf + MAX_MULTIBYTE_LENGTH, | |
5159 dst); | |
5160 dst_end = coding->destination + coding->dst_bytes; | |
5161 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5162 } | |
5163 if (c >= 0) | |
5164 { | |
5165 if (coding->dst_multibyte | |
5166 || ! CHAR_BYTE8_P (c)) | |
5167 CHAR_STRING_ADVANCE (c, dst); | |
5168 else | |
5169 *dst++ = CHAR_TO_BYTE8 (c); | |
5170 produced_chars++; | |
5171 } | |
5172 else | |
5173 /* This is an annotation data. */ | |
5174 buf -= c + 1; | |
5175 } | |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5176 } |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5177 else |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5178 { |
88365 | 5179 unsigned char *src = coding->source; |
5180 unsigned char *src_end = src + coding->src_bytes; | |
5181 Lisp_Object eol_type; | |
5182 | |
5183 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5184 | |
5185 if (coding->src_multibyte != coding->dst_multibyte) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5186 { |
88365 | 5187 if (coding->src_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5188 { |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5189 int multibytep = 1; |
88365 | 5190 int consumed_chars; |
5191 | |
5192 while (1) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5193 { |
88365 | 5194 unsigned char *src_base = src; |
5195 int c; | |
5196 | |
5197 ONE_MORE_BYTE (c); | |
5198 if (c == '\r') | |
5199 { | |
5200 if (EQ (eol_type, Qdos)) | |
5201 { | |
5202 if (src < src_end | |
5203 && *src == '\n') | |
5204 c = *src++; | |
5205 } | |
5206 else if (EQ (eol_type, Qmac)) | |
5207 c = '\n'; | |
5208 } | |
5209 if (dst == dst_end) | |
5210 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5211 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
|
5212 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5213 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
|
5214 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5215 if (dst == dst_end) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5216 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5217 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
|
5218 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5219 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
|
5220 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5221 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
|
5222 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
|
5223 } |
88365 | 5224 } |
5225 *dst++ = c; | |
5226 produced_chars++; | |
5227 } | |
5228 no_more_source: | |
5229 ; | |
5230 } | |
5231 else | |
5232 while (src < src_end) | |
5233 { | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5234 int multibytep = 1; |
88365 | 5235 int c = *src++; |
5236 | |
5237 if (c == '\r') | |
5238 { | |
5239 if (EQ (eol_type, Qdos)) | |
5240 { | |
5241 if (src < src_end | |
5242 && *src == '\n') | |
5243 c = *src++; | |
5244 } | |
5245 else if (EQ (eol_type, Qmac)) | |
5246 c = '\n'; | |
5247 } | |
5248 if (dst >= dst_end - 1) | |
5249 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5250 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
|
5251 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5252 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
|
5253 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5254 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
|
5255 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5256 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
|
5257 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5258 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
|
5259 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5260 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
|
5261 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
|
5262 } |
88365 | 5263 } |
5264 EMIT_ONE_BYTE (c); | |
5265 } | |
5266 } | |
5267 else | |
5268 { | |
5269 if (!EQ (coding->src_object, coding->dst_object)) | |
5270 { | |
5271 int require = coding->src_bytes - coding->dst_bytes; | |
5272 | |
5273 if (require > 0) | |
5274 { | |
5275 EMACS_INT offset = src - coding->source; | |
5276 | |
5277 dst = alloc_destination (coding, require, dst); | |
5278 coding_set_source (coding); | |
5279 src = coding->source + offset; | |
5280 src_end = coding->source + coding->src_bytes; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5281 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5282 } |
88365 | 5283 produced_chars = coding->src_chars; |
5284 while (src < src_end) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5285 { |
88365 | 5286 int c = *src++; |
5287 | |
5288 if (c == '\r') | |
5289 { | |
5290 if (EQ (eol_type, Qdos)) | |
5291 { | |
5292 if (src < src_end | |
5293 && *src == '\n') | |
5294 c = *src++; | |
5295 produced_chars--; | |
5296 } | |
5297 else if (EQ (eol_type, Qmac)) | |
5298 c = '\n'; | |
5299 } | |
5300 *dst++ = c; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5301 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5302 } |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5303 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
|
5304 coding->consumed_char = coding->src_chars; |
88365 | 5305 } |
5306 | |
5307 produced = dst - (coding->destination + coding->produced); | |
5308 if (BUFFERP (coding->dst_object)) | |
5309 insert_from_gap (produced_chars, produced); | |
5310 coding->produced += produced; | |
5311 coding->produced_char += produced_chars; | |
5312 return produced_chars; | |
5313 } | |
5314 | |
5315 /* [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN ] | |
5316 or | |
5317 [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN COMPONENTS... ] | |
5318 */ | |
5319 | |
5320 static INLINE void | |
5321 produce_composition (coding, charbuf) | |
5322 struct coding_system *coding; | |
5323 int *charbuf; | |
5324 { | |
5325 Lisp_Object buffer; | |
5326 int len; | |
5327 EMACS_INT pos; | |
5328 enum composition_method method; | |
5329 int cmp_len; | |
5330 Lisp_Object components; | |
5331 | |
5332 buffer = coding->dst_object; | |
5333 len = -charbuf[0]; | |
5334 pos = coding->dst_pos + charbuf[1]; | |
5335 method = (enum composition_method) (charbuf[3]); | |
5336 cmp_len = charbuf[4]; | |
5337 | |
5338 if (method == COMPOSITION_RELATIVE) | |
5339 components = Qnil; | |
5340 else | |
5341 { | |
5342 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
5343 int i; | |
5344 | |
5345 len -= 5; | |
5346 charbuf += 5; | |
5347 for (i = 0; i < len; i++) | |
5348 args[i] = make_number (charbuf[i]); | |
5349 components = (method == COMPOSITION_WITH_ALTCHARS | |
5350 ? Fstring (len, args) : Fvector (len, args)); | |
5351 } | |
5352 compose_text (pos, pos + cmp_len, components, Qnil, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5353 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5354 |
88365 | 5355 static int * |
5356 save_composition_data (buf, buf_end, prop) | |
5357 int *buf, *buf_end; | |
5358 Lisp_Object prop; | |
5359 { | |
5360 enum composition_method method = COMPOSITION_METHOD (prop); | |
5361 int cmp_len = COMPOSITION_LENGTH (prop); | |
5362 | |
5363 if (buf + 4 + (MAX_COMPOSITION_COMPONENTS * 2 - 1) > buf_end) | |
5364 return NULL; | |
5365 | |
5366 buf[1] = CODING_ANNOTATE_COMPOSITION_MASK; | |
5367 buf[2] = method; | |
5368 buf[3] = cmp_len; | |
5369 | |
5370 if (method == COMPOSITION_RELATIVE) | |
5371 buf[0] = 4; | |
5372 else | |
5373 { | |
5374 Lisp_Object components; | |
5375 int len, i; | |
5376 | |
5377 components = COMPOSITION_COMPONENTS (prop); | |
5378 if (VECTORP (components)) | |
5379 { | |
5380 len = XVECTOR (components)->size; | |
5381 for (i = 0; i < len; i++) | |
5382 buf[4 + i] = XINT (AREF (components, i)); | |
5383 } | |
5384 else if (STRINGP (components)) | |
5385 { | |
5386 int i_byte; | |
5387 | |
5388 len = XSTRING (components)->size; | |
5389 i = i_byte = 0; | |
5390 while (i < len) | |
5391 FETCH_STRING_CHAR_ADVANCE (buf[4 + i], components, i, i_byte); | |
5392 } | |
5393 else if (INTEGERP (components)) | |
5394 { | |
5395 len = 1; | |
5396 buf[4] = XINT (components); | |
5397 } | |
5398 else if (CONSP (components)) | |
5399 { | |
5400 for (len = 0; CONSP (components); | |
5401 len++, components = XCDR (components)) | |
5402 buf[4 + len] = XINT (XCAR (components)); | |
5403 } | |
5404 else | |
5405 abort (); | |
5406 buf[0] = 4 + len; | |
5407 } | |
5408 return (buf + buf[0]); | |
5409 } | |
5410 | |
5411 #define CHARBUF_SIZE 0x4000 | |
5412 | |
5413 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
5414 do { \ | |
5415 int size = CHARBUF_SIZE;; \ | |
5416 \ | |
5417 coding->charbuf = NULL; \ | |
5418 while (size > 1024) \ | |
5419 { \ | |
5420 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
5421 if (coding->charbuf) \ | |
5422 break; \ | |
5423 size >>= 1; \ | |
5424 } \ | |
5425 if (! coding->charbuf) \ | |
5426 { \ | |
5427 coding->result = CODING_RESULT_INSUFFICIENT_MEM; \ | |
5428 return coding->result; \ | |
5429 } \ | |
5430 coding->charbuf_size = size; \ | |
5431 } while (0) | |
5432 | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5433 |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5434 static void |
88365 | 5435 produce_annotation (coding) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5436 struct coding_system *coding; |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5437 { |
88365 | 5438 int *charbuf = coding->charbuf; |
5439 int *charbuf_end = charbuf + coding->charbuf_used; | |
5440 | |
5441 while (charbuf < charbuf_end) | |
5442 { | |
5443 if (*charbuf >= 0) | |
5444 charbuf++; | |
5445 else | |
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
5446 { |
88365 | 5447 int len = -*charbuf; |
5448 switch (charbuf[2]) | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5449 { |
88365 | 5450 case CODING_ANNOTATE_COMPOSITION_MASK: |
5451 produce_composition (coding, charbuf); | |
5452 break; | |
5453 default: | |
5454 abort (); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5455 } |
88365 | 5456 charbuf += len; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5457 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5458 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5459 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5460 |
88365 | 5461 /* Decode the data at CODING->src_object into CODING->dst_object. |
5462 CODING->src_object is a buffer, a string, or nil. | |
5463 CODING->dst_object is a buffer. | |
5464 | |
5465 If CODING->src_object is a buffer, it must be the current buffer. | |
5466 In this case, if CODING->src_pos is positive, it is a position of | |
5467 the source text in the buffer, otherwise, the source text is in the | |
5468 gap area of the buffer, and CODING->src_pos specifies the offset of | |
5469 the text from GPT (which must be the same as PT). If this is the | |
5470 same buffer as CODING->dst_object, CODING->src_pos must be | |
5471 negative. | |
5472 | |
5473 If CODING->src_object is a string, CODING->src_pos in an index to | |
5474 that string. | |
5475 | |
5476 If CODING->src_object is nil, CODING->source must already point to | |
5477 the non-relocatable memory area. In this case, CODING->src_pos is | |
5478 an offset from CODING->source. | |
5479 | |
5480 The decoded data is inserted at the current point of the buffer | |
5481 CODING->dst_object. | |
5482 */ | |
5483 | |
5484 static int | |
5485 decode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5486 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5487 { |
88365 | 5488 Lisp_Object attrs; |
5489 | |
5490 if (BUFFERP (coding->src_object) | |
5491 && coding->src_pos > 0 | |
5492 && coding->src_pos < GPT | |
5493 && coding->src_pos + coding->src_chars > GPT) | |
5494 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
5495 | |
5496 if (BUFFERP (coding->dst_object)) | |
5497 { | |
5498 if (current_buffer != XBUFFER (coding->dst_object)) | |
5499 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5500 if (GPT != PT) | |
5501 move_gap_both (PT, PT_BYTE); | |
5502 } | |
5503 | |
5504 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
|
5505 coding->produced = coding->produced_char = 0; |
88365 | 5506 coding->chars_at_source = 0; |
5507 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
|
5508 coding->errors = 0; |
88365 | 5509 |
5510 ALLOC_CONVERSION_WORK_AREA (coding); | |
5511 | |
5512 attrs = CODING_ID_ATTRS (coding->id); | |
5513 | |
5514 do | |
5515 { | |
5516 coding_set_source (coding); | |
5517 coding->annotated = 0; | |
5518 (*(coding->decoder)) (coding); | |
5519 if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | |
5520 translate_chars (CODING_ATTR_DECODE_TBL (attrs), coding); | |
5521 coding_set_destination (coding); | |
5522 produce_chars (coding); | |
5523 if (coding->annotated) | |
5524 produce_annotation (coding); | |
5525 } | |
5526 while (coding->consumed < coding->src_bytes | |
5527 && ! coding->result); | |
5528 | |
5529 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qccl) | |
5530 && SYMBOLP (CODING_ID_EOL_TYPE (coding->id)) | |
5531 && ! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix)) | |
5532 decode_eol (coding); | |
5533 | |
5534 coding->carryover_bytes = 0; | |
5535 if (coding->consumed < coding->src_bytes) | |
5536 { | |
5537 int nbytes = coding->src_bytes - coding->consumed; | |
5538 unsigned char *src; | |
5539 | |
5540 coding_set_source (coding); | |
5541 coding_set_destination (coding); | |
5542 src = coding->source + coding->consumed; | |
5543 | |
5544 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
|
5545 { |
88365 | 5546 /* Flush out unprocessed data as binary chars. We are sure |
5547 that the number of data is less than the size of | |
5548 coding->charbuf. */ | |
5549 int *charbuf = coding->charbuf; | |
5550 | |
5551 while (nbytes-- > 0) | |
5552 { | |
5553 int c = *src++; | |
5554 *charbuf++ = (c & 0x80 ? - c : c); | |
5555 } | |
5556 produce_chars (coding); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5557 } |
88365 | 5558 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5559 { |
88365 | 5560 /* Record unprocessed bytes in coding->carryover. We are |
5561 sure that the number of data is less than the size of | |
5562 coding->carryover. */ | |
5563 unsigned char *p = coding->carryover; | |
5564 | |
5565 coding->carryover_bytes = nbytes; | |
5566 while (nbytes-- > 0) | |
5567 *p++ = *src++; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5568 } |
88365 | 5569 coding->consumed = coding->src_bytes; |
5570 } | |
5571 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5572 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5573 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5574 |
88365 | 5575 static void |
5576 consume_chars (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5577 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5578 { |
88365 | 5579 int *buf = coding->charbuf; |
5580 /* -1 is to compensate for CRLF. */ | |
5581 int *buf_end = coding->charbuf + coding->charbuf_size - 1; | |
5582 unsigned char *src = coding->source + coding->consumed; | |
5583 int pos = coding->src_pos + coding->consumed_char; | |
5584 int end_pos = coding->src_pos + coding->src_chars; | |
5585 int multibytep = coding->src_multibyte; | |
5586 Lisp_Object eol_type; | |
5587 int c; | |
5588 int start, end, stop; | |
5589 Lisp_Object object, prop; | |
5590 | |
5591 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5592 if (VECTORP (eol_type)) | |
5593 eol_type = Qunix; | |
5594 | |
5595 object = coding->src_object; | |
5596 | |
5597 /* Note: composition handling is not yet implemented. */ | |
5598 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
5599 | |
5600 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK | |
5601 && find_composition (pos, end_pos, &start, &end, &prop, object) | |
5602 && end <= end_pos | |
5603 && (start >= pos | |
5604 || (find_composition (end, end_pos, &start, &end, &prop, object) | |
5605 && end <= end_pos))) | |
5606 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5607 else |
88365 | 5608 stop = end_pos; |
5609 | |
5610 while (buf < buf_end) | |
5611 { | |
5612 if (pos == stop) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5613 { |
88365 | 5614 int *p; |
5615 | |
5616 if (pos == end_pos) | |
5617 break; | |
5618 p = save_composition_data (buf, buf_end, prop); | |
5619 if (p == NULL) | |
5620 break; | |
5621 buf = p; | |
5622 if (find_composition (end, end_pos, &start, &end, &prop, object) | |
5623 && end <= end_pos) | |
5624 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5625 else |
88365 | 5626 stop = end_pos; |
5627 } | |
5628 | |
5629 if (! multibytep) | |
5630 c = *src++; | |
5631 else | |
5632 c = STRING_CHAR_ADVANCE (src); | |
5633 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) | |
5634 c = '\n'; | |
5635 if (! EQ (eol_type, Qunix)) | |
5636 { | |
5637 if (c == '\n') | |
5638 { | |
5639 if (EQ (eol_type, Qdos)) | |
5640 *buf++ = '\r'; | |
5641 else | |
5642 c = '\r'; | |
5643 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5644 } |
88365 | 5645 *buf++ = c; |
5646 pos++; | |
5647 } | |
5648 | |
5649 coding->consumed = src - coding->source; | |
5650 coding->consumed_char = pos - coding->src_pos; | |
5651 coding->charbuf_used = buf - coding->charbuf; | |
5652 coding->chars_at_source = 0; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5653 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5654 |
88365 | 5655 |
5656 /* Encode the text at CODING->src_object into CODING->dst_object. | |
5657 CODING->src_object is a buffer or a string. | |
5658 CODING->dst_object is a buffer or nil. | |
5659 | |
5660 If CODING->src_object is a buffer, it must be the current buffer. | |
5661 In this case, if CODING->src_pos is positive, it is a position of | |
5662 the source text in the buffer, otherwise. the source text is in the | |
5663 gap area of the buffer, and coding->src_pos specifies the offset of | |
5664 the text from GPT (which must be the same as PT). If this is the | |
5665 same buffer as CODING->dst_object, CODING->src_pos must be | |
5666 negative and CODING should not have `pre-write-conversion'. | |
5667 | |
5668 If CODING->src_object is a string, CODING should not have | |
5669 `pre-write-conversion'. | |
5670 | |
5671 If CODING->dst_object is a buffer, the encoded data is inserted at | |
5672 the current point of that buffer. | |
5673 | |
5674 If CODING->dst_object is nil, the encoded data is placed at the | |
5675 memory area specified by CODING->destination. */ | |
5676 | |
5677 static int | |
5678 encode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5679 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5680 { |
88365 | 5681 Lisp_Object attrs; |
5682 | |
5683 attrs = CODING_ID_ATTRS (coding->id); | |
5684 | |
5685 if (BUFFERP (coding->dst_object)) | |
5686 { | |
5687 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5688 coding->dst_multibyte | |
5689 = ! NILP (current_buffer->enable_multibyte_characters); | |
5690 } | |
5691 | |
5692 coding->consumed = coding->consumed_char = 0; | |
5693 coding->produced = coding->produced_char = 0; | |
5694 coding->result = CODING_RESULT_SUCCESS; | |
5695 coding->errors = 0; | |
5696 | |
5697 ALLOC_CONVERSION_WORK_AREA (coding); | |
5698 | |
5699 do { | |
5700 coding_set_source (coding); | |
5701 consume_chars (coding); | |
5702 | |
5703 if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | |
5704 translate_chars (CODING_ATTR_ENCODE_TBL (attrs), coding); | |
5705 | |
5706 coding_set_destination (coding); | |
5707 (*(coding->encoder)) (coding); | |
5708 } while (coding->consumed_char < coding->src_chars); | |
5709 | |
5710 if (BUFFERP (coding->dst_object)) | |
5711 insert_from_gap (coding->produced_char, coding->produced); | |
5712 | |
5713 return (coding->result); | |
5714 } | |
5715 | |
5716 /* Work buffer */ | |
5717 | |
5718 /* List of currently used working buffer. */ | |
5719 Lisp_Object Vcode_conversion_work_buf_list; | |
5720 | |
5721 /* A working buffer used by the top level conversion. */ | |
5722 Lisp_Object Vcode_conversion_reused_work_buf; | |
5723 | |
5724 | |
5725 /* Return a working buffer that can be freely used by the following | |
5726 code conversion. MULTIBYTEP specifies the multibyteness of the | |
5727 buffer. */ | |
5728 | |
5729 Lisp_Object | |
5730 make_conversion_work_buffer (multibytep) | |
5731 int multibytep; | |
5732 { | |
5733 struct buffer *current = current_buffer; | |
5734 Lisp_Object buf; | |
5735 | |
5736 if (NILP (Vcode_conversion_work_buf_list)) | |
5737 { | |
5738 if (NILP (Vcode_conversion_reused_work_buf)) | |
5739 Vcode_conversion_reused_work_buf | |
5740 = Fget_buffer_create (build_string (" *code-conversion-work*")); | |
5741 Vcode_conversion_work_buf_list | |
5742 = 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
|
5743 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5744 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5745 { |
88365 | 5746 int depth = Flength (Vcode_conversion_work_buf_list); |
5747 char str[128]; | |
5748 | |
5749 sprintf (str, " *code-conversion-work*<%d>", depth); | |
5750 Vcode_conversion_work_buf_list | |
5751 = Fcons (Fget_buffer_create (build_string (str)), | |
5752 Vcode_conversion_work_buf_list); | |
5753 } | |
5754 | |
5755 buf = XCAR (Vcode_conversion_work_buf_list); | |
5756 set_buffer_internal (XBUFFER (buf)); | |
5757 current_buffer->undo_list = Qt; | |
5758 Ferase_buffer (); | |
5759 Fset_buffer_multibyte (multibytep ? Qt : Qnil); | |
5760 set_buffer_internal (current); | |
5761 return buf; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5762 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5763 |
88365 | 5764 static struct coding_system *saved_coding; |
5765 | |
5766 Lisp_Object | |
5767 code_conversion_restore (info) | |
5768 Lisp_Object info; | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5769 { |
88365 | 5770 int depth = Flength (Vcode_conversion_work_buf_list); |
5771 Lisp_Object buf; | |
5772 | |
5773 if (depth > 0) | |
5774 { | |
5775 buf = XCAR (Vcode_conversion_work_buf_list); | |
5776 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); | |
5777 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) | |
5778 Fkill_buffer (buf); | |
5779 } | |
5780 | |
5781 if (saved_coding->dst_object == Qt | |
5782 && saved_coding->destination) | |
5783 xfree (saved_coding->destination); | |
5784 | |
5785 return save_excursion_restore (info); | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5786 } |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5787 |
88365 | 5788 |
5789 int | |
5790 decode_coding_gap (coding, chars, bytes) | |
26847 | 5791 struct coding_system *coding; |
88365 | 5792 EMACS_INT chars, bytes; |
5793 { | |
5794 int count = specpdl_ptr - specpdl; | |
5795 | |
5796 saved_coding = coding; | |
5797 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5798 | |
5799 coding->src_object = Fcurrent_buffer (); | |
5800 coding->src_chars = chars; | |
5801 coding->src_bytes = bytes; | |
5802 coding->src_pos = -chars; | |
5803 coding->src_pos_byte = -bytes; | |
5804 coding->src_multibyte = chars < bytes; | |
5805 coding->dst_object = coding->src_object; | |
5806 coding->dst_pos = PT; | |
5807 coding->dst_pos_byte = PT_BYTE; | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5808 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
88365 | 5809 |
5810 if (CODING_REQUIRE_DETECTION (coding)) | |
5811 detect_coding (coding); | |
5812 | |
5813 decode_coding (coding); | |
5814 | |
5815 unbind_to (count, Qnil); | |
5816 return coding->result; | |
5817 } | |
5818 | |
5819 int | |
5820 encode_coding_gap (coding, chars, bytes) | |
5821 struct coding_system *coding; | |
5822 EMACS_INT chars, bytes; | |
26847 | 5823 { |
88365 | 5824 int count = specpdl_ptr - specpdl; |
5825 Lisp_Object buffer; | |
5826 | |
5827 saved_coding = coding; | |
5828 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5829 | |
5830 buffer = Fcurrent_buffer (); | |
5831 coding->src_object = buffer; | |
5832 coding->src_chars = chars; | |
5833 coding->src_bytes = bytes; | |
5834 coding->src_pos = -chars; | |
5835 coding->src_pos_byte = -bytes; | |
5836 coding->src_multibyte = chars < bytes; | |
5837 coding->dst_object = coding->src_object; | |
5838 coding->dst_pos = PT; | |
5839 coding->dst_pos_byte = PT_BYTE; | |
5840 | |
5841 encode_coding (coding); | |
5842 | |
5843 unbind_to (count, Qnil); | |
5844 return coding->result; | |
26847 | 5845 } |
5846 | |
88365 | 5847 |
5848 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
5849 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
5850 | |
5851 SRC_OBJECT is a buffer, a string, or Qnil. | |
5852 | |
5853 If it is a buffer, the text is at point of the buffer. FROM and TO | |
5854 are positions in the buffer. | |
5855 | |
5856 If it is a string, the text is at the beginning of the string. | |
5857 FROM and TO are indices to the string. | |
5858 | |
5859 If it is nil, the text is at coding->source. FROM and TO are | |
5860 indices to coding->source. | |
5861 | |
5862 DST_OBJECT is a buffer, Qt, or Qnil. | |
5863 | |
5864 If it is a buffer, the decoded text is inserted at point of the | |
5865 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
5866 is deleted. | |
5867 | |
5868 If it is Qt, a string is made from the decoded text, and | |
5869 set in CODING->dst_object. | |
5870 | |
5871 If it is Qnil, the decoded text is stored at CODING->destination. | |
5872 The called must allocate CODING->dst_bytes bytes at | |
5873 CODING->destination by xmalloc. If the decoded text is longer than | |
5874 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
5875 */ | |
26847 | 5876 |
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
5877 void |
88365 | 5878 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
5879 dst_object) | |
26847 | 5880 struct coding_system *coding; |
88365 | 5881 Lisp_Object src_object; |
5882 EMACS_INT from, from_byte, to, to_byte; | |
5883 Lisp_Object dst_object; | |
26847 | 5884 { |
88365 | 5885 int count = specpdl_ptr - specpdl; |
5886 unsigned char *destination; | |
5887 EMACS_INT dst_bytes; | |
5888 EMACS_INT chars = to - from; | |
5889 EMACS_INT bytes = to_byte - from_byte; | |
5890 Lisp_Object attrs; | |
5891 | |
5892 saved_coding = coding; | |
5893 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5894 | |
5895 if (NILP (dst_object)) | |
5896 { | |
5897 destination = coding->destination; | |
5898 dst_bytes = coding->dst_bytes; | |
5899 } | |
5900 | |
5901 coding->src_object = src_object; | |
5902 coding->src_chars = chars; | |
5903 coding->src_bytes = bytes; | |
5904 coding->src_multibyte = chars < bytes; | |
5905 | |
5906 if (STRINGP (src_object)) | |
5907 { | |
5908 coding->src_pos = from; | |
5909 coding->src_pos_byte = from_byte; | |
5910 } | |
5911 else if (BUFFERP (src_object)) | |
5912 { | |
5913 set_buffer_internal (XBUFFER (src_object)); | |
5914 if (from != GPT) | |
5915 move_gap_both (from, from_byte); | |
5916 if (EQ (src_object, dst_object)) | |
26847 | 5917 { |
88365 | 5918 TEMP_SET_PT_BOTH (from, from_byte); |
5919 del_range_both (from, from_byte, to, to_byte, 1); | |
5920 coding->src_pos = -chars; | |
5921 coding->src_pos_byte = -bytes; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5922 } |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5923 else |
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5924 { |
88365 | 5925 coding->src_pos = from; |
5926 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
|
5927 } |
88365 | 5928 } |
5929 | |
5930 if (CODING_REQUIRE_DETECTION (coding)) | |
5931 detect_coding (coding); | |
5932 attrs = CODING_ID_ATTRS (coding->id); | |
5933 | |
5934 if (! NILP (CODING_ATTR_POST_READ (attrs)) | |
5935 || EQ (dst_object, Qt)) | |
5936 { | |
5937 coding->dst_object = make_conversion_work_buffer (1); | |
5938 coding->dst_pos = BEG; | |
5939 coding->dst_pos_byte = BEG_BYTE; | |
5940 coding->dst_multibyte = 1; | |
5941 } | |
5942 else if (BUFFERP (dst_object)) | |
5943 { | |
5944 coding->dst_object = dst_object; | |
5945 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
5946 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
5947 coding->dst_multibyte | |
5948 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
5949 } | |
5950 else | |
5951 { | |
5952 coding->dst_object = Qnil; | |
5953 coding->dst_multibyte = 1; | |
5954 } | |
5955 | |
5956 decode_coding (coding); | |
5957 | |
5958 if (BUFFERP (coding->dst_object)) | |
5959 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5960 | |
5961 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
5962 { | |
5963 struct gcpro gcpro1, gcpro2; | |
5964 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; | |
5965 Lisp_Object val; | |
5966 | |
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
5967 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
88365 | 5968 GCPRO2 (coding->src_object, coding->dst_object); |
5969 val = call1 (CODING_ATTR_POST_READ (attrs), | |
5970 make_number (coding->produced_char)); | |
5971 UNGCPRO; | |
5972 CHECK_NATNUM (val); | |
5973 coding->produced_char += Z - prev_Z; | |
5974 coding->produced += Z_BYTE - prev_Z_BYTE; | |
5975 } | |
5976 | |
5977 if (EQ (dst_object, Qt)) | |
5978 { | |
5979 coding->dst_object = Fbuffer_string (); | |
5980 } | |
5981 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
5982 { | |
5983 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5984 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
|
5985 { |
88365 | 5986 destination |
5987 = (unsigned char *) xrealloc (destination, coding->produced); | |
5988 if (! destination) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5989 { |
88365 | 5990 coding->result = CODING_RESULT_INSUFFICIENT_DST; |
5991 unbind_to (count, Qnil); | |
5992 return; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5993 } |
88365 | 5994 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
5995 move_gap_both (BEGV, BEGV_BYTE); | |
5996 bcopy (BEGV_ADDR, destination, coding->produced); | |
5997 coding->destination = destination; | |
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
5998 } |
88365 | 5999 } |
6000 | |
6001 unbind_to (count, Qnil); | |
6002 } | |
6003 | |
6004 | |
6005 void | |
6006 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, | |
6007 dst_object) | |
6008 struct coding_system *coding; | |
6009 Lisp_Object src_object; | |
6010 EMACS_INT from, from_byte, to, to_byte; | |
6011 Lisp_Object dst_object; | |
6012 { | |
6013 int count = specpdl_ptr - specpdl; | |
6014 EMACS_INT chars = to - from; | |
6015 EMACS_INT bytes = to_byte - from_byte; | |
6016 Lisp_Object attrs; | |
6017 | |
6018 saved_coding = coding; | |
6019 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6020 | |
6021 coding->src_object = src_object; | |
6022 coding->src_chars = chars; | |
6023 coding->src_bytes = bytes; | |
6024 coding->src_multibyte = chars < bytes; | |
6025 | |
6026 attrs = CODING_ID_ATTRS (coding->id); | |
6027 | |
6028 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
|
6029 { |
88365 | 6030 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); |
6031 set_buffer_internal (XBUFFER (coding->src_object)); | |
6032 if (STRINGP (src_object)) | |
6033 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
6034 else if (BUFFERP (src_object)) | |
6035 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
6036 else | |
6037 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); | |
6038 | |
6039 if (EQ (src_object, dst_object)) | |
6040 { | |
6041 set_buffer_internal (XBUFFER (src_object)); | |
6042 del_range_both (from, from_byte, to, to_byte, 1); | |
6043 set_buffer_internal (XBUFFER (coding->src_object)); | |
6044 } | |
6045 | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6046 call2 (CODING_ATTR_PRE_WRITE (attrs), |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6047 make_number (BEG), make_number (Z)); |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6048 coding->src_object = Fcurrent_buffer (); |
88365 | 6049 if (BEG != GPT) |
6050 move_gap_both (BEG, BEG_BYTE); | |
6051 coding->src_chars = Z - BEG; | |
6052 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
6053 coding->src_pos = BEG; | |
6054 coding->src_pos_byte = BEG_BYTE; | |
6055 coding->src_multibyte = Z < Z_BYTE; | |
6056 } | |
6057 else if (STRINGP (src_object)) | |
6058 { | |
6059 coding->src_pos = from; | |
6060 coding->src_pos_byte = from_byte; | |
6061 } | |
6062 else if (BUFFERP (src_object)) | |
6063 { | |
6064 set_buffer_internal (XBUFFER (src_object)); | |
6065 if (from != GPT) | |
6066 move_gap_both (from, from_byte); | |
6067 if (EQ (src_object, dst_object)) | |
6068 { | |
6069 del_range_both (from, from_byte, to, to_byte, 1); | |
6070 coding->src_pos = -chars; | |
6071 coding->src_pos_byte = -bytes; | |
6072 } | |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
6073 else |
88365 | 6074 { |
6075 coding->src_pos = from; | |
6076 coding->src_pos_byte = from_byte; | |
6077 } | |
6078 } | |
6079 | |
6080 if (BUFFERP (dst_object)) | |
6081 { | |
6082 coding->dst_object = dst_object; | |
6083 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
6084 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
6085 coding->dst_multibyte | |
6086 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
6087 } | |
6088 else if (EQ (dst_object, Qt)) | |
6089 { | |
6090 coding->dst_object = Qnil; | |
6091 coding->dst_bytes = coding->src_chars; | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6092 if (coding->dst_bytes == 0) |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6093 coding->dst_bytes = 1; |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6094 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
88365 | 6095 coding->dst_multibyte = 0; |
6096 } | |
6097 else | |
6098 { | |
6099 coding->dst_object = Qnil; | |
6100 coding->dst_multibyte = 0; | |
6101 } | |
6102 | |
6103 encode_coding (coding); | |
6104 | |
6105 if (EQ (dst_object, Qt)) | |
6106 { | |
6107 if (BUFFERP (coding->dst_object)) | |
6108 coding->dst_object = Fbuffer_string (); | |
6109 else | |
6110 { | |
6111 coding->dst_object | |
6112 = make_unibyte_string ((char *) coding->destination, | |
6113 coding->produced); | |
6114 xfree (coding->destination); | |
6115 } | |
6116 } | |
6117 | |
6118 unbind_to (count, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6119 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6120 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6121 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6122 Lisp_Object |
88365 | 6123 preferred_coding_system () |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6124 { |
88365 | 6125 int id = coding_categories[coding_priorities[0]].id; |
6126 | |
6127 return CODING_ID_NAME (id); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6128 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6129 |
17052 | 6130 |
6131 #ifdef emacs | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6132 /*** 8. Emacs Lisp library functions ***/ |
17052 | 6133 |
6134 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
|
6135 doc: /* Return t if OBJECT is nil or a coding-system. |
88365 | 6136 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
|
6137 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
|
6138 (obj) |
17052 | 6139 Lisp_Object obj; |
6140 { | |
88365 | 6141 return ((NILP (obj) || CODING_SYSTEM_P (obj)) ? Qt : Qnil); |
17052 | 6142 } |
6143 | |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6144 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
|
6145 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
|
6146 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
|
6147 (prompt) |
17052 | 6148 Lisp_Object prompt; |
6149 { | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6150 Lisp_Object val; |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6151 do |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6152 { |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6153 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6154 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
|
6155 } |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6156 while (XSTRING (val)->size == 0); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6157 return (Fintern (val, Qnil)); |
17052 | 6158 } |
6159 | |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6160 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
|
6161 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
|
6162 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
|
6163 (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
|
6164 Lisp_Object prompt, default_coding_system; |
17052 | 6165 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
6166 Lisp_Object val; |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6167 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
|
6168 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6169 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
|
6170 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
|
6171 default_coding_system, Qnil); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6172 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
17052 | 6173 } |
6174 | |
6175 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
6176 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
|
6177 doc: /* Check validity of CODING-SYSTEM. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6178 If valid, return CODING-SYSTEM, else signal a `coding-system-error' error. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6179 It is valid if it is a symbol with a non-nil `coding-system' property. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6180 The value of property should be a vector of length 5. */) |
88365 | 6181 (coding_system) |
17052 | 6182 Lisp_Object coding_system; |
6183 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6184 CHECK_SYMBOL (coding_system); |
17052 | 6185 if (!NILP (Fcoding_system_p (coding_system))) |
6186 return coding_system; | |
6187 while (1) | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
6188 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
17052 | 6189 } |
88365 | 6190 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6191 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6192 Lisp_Object |
88365 | 6193 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
|
6194 unsigned char *src; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6195 int src_bytes, highest; |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6196 int multibytep; |
88365 | 6197 Lisp_Object coding_system; |
17052 | 6198 { |
88365 | 6199 unsigned char *src_end = src + src_bytes; |
6200 int mask = CATEGORY_MASK_ANY; | |
6201 int detected = 0; | |
6202 int c, i; | |
6203 Lisp_Object attrs, eol_type; | |
6204 Lisp_Object val; | |
6205 struct coding_system coding; | |
6206 | |
6207 if (NILP (coding_system)) | |
6208 coding_system = Qundecided; | |
6209 setup_coding_system (coding_system, &coding); | |
6210 attrs = CODING_ID_ATTRS (coding.id); | |
6211 eol_type = CODING_ID_EOL_TYPE (coding.id); | |
6212 | |
6213 coding.source = src; | |
6214 coding.src_bytes = src_bytes; | |
6215 coding.src_multibyte = multibytep; | |
6216 coding.consumed = 0; | |
6217 | |
6218 if (XINT (CODING_ATTR_CATEGORY (attrs)) != coding_category_undecided) | |
6219 { | |
6220 mask = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); | |
6221 } | |
6222 else | |
6223 { | |
6224 coding_system = Qnil; | |
6225 for (; src < src_end; src++) | |
17052 | 6226 { |
88365 | 6227 c = *src; |
6228 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
6229 || c == ISO_CODE_SI | |
6230 || c == ISO_CODE_SO))) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6231 break; |
17052 | 6232 } |
88365 | 6233 coding.head_ascii = src - coding.source; |
6234 | |
6235 if (src < src_end) | |
6236 for (i = 0; i < coding_category_raw_text; i++) | |
6237 { | |
6238 enum coding_category category = coding_priorities[i]; | |
6239 struct coding_system *this = coding_categories + category; | |
6240 | |
6241 if (category >= coding_category_raw_text | |
6242 || detected & (1 << category)) | |
6243 continue; | |
6244 | |
6245 if (this->id < 0) | |
6246 { | |
6247 /* No coding system of this category is defined. */ | |
6248 mask &= ~(1 << category); | |
6249 } | |
6250 else | |
6251 { | |
6252 detected |= detected_mask[category]; | |
6253 if ((*(coding_categories[category].detector)) (&coding, &mask) | |
6254 && highest) | |
6255 { | |
6256 mask &= detected_mask[category]; | |
6257 break; | |
6258 } | |
6259 } | |
6260 } | |
6261 } | |
6262 | |
6263 if (!mask) | |
6264 val = Fcons (make_number (coding_category_raw_text), Qnil); | |
6265 else if (mask == CATEGORY_MASK_ANY) | |
6266 val = Fcons (make_number (coding_category_undecided), Qnil); | |
6267 else if (highest) | |
6268 { | |
6269 for (i = 0; i < coding_category_raw_text; i++) | |
6270 if (mask & (1 << coding_priorities[i])) | |
6271 { | |
6272 val = Fcons (make_number (coding_priorities[i]), Qnil); | |
6273 break; | |
6274 } | |
6275 } | |
6276 else | |
6277 { | |
6278 val = Qnil; | |
6279 for (i = coding_category_raw_text - 1; i >= 0; i--) | |
6280 if (mask & (1 << coding_priorities[i])) | |
6281 val = Fcons (make_number (coding_priorities[i]), val); | |
6282 } | |
6283 | |
6284 { | |
6285 int one_byte_eol = -1, two_byte_eol = -1; | |
6286 Lisp_Object tail; | |
6287 | |
6288 for (tail = val; CONSP (tail); tail = XCDR (tail)) | |
6289 { | |
6290 struct coding_system *this | |
6291 = (NILP (coding_system) ? coding_categories + XINT (XCAR (tail)) | |
6292 : &coding); | |
6293 int this_eol; | |
6294 | |
6295 attrs = CODING_ID_ATTRS (this->id); | |
6296 eol_type = CODING_ID_EOL_TYPE (this->id); | |
6297 XSETCAR (tail, CODING_ID_NAME (this->id)); | |
6298 if (VECTORP (eol_type)) | |
6299 { | |
6300 if (EQ (CODING_ATTR_TYPE (attrs), Qutf_16)) | |
6301 { | |
6302 if (two_byte_eol < 0) | |
6303 two_byte_eol = detect_eol (this, coding.source, src_bytes); | |
6304 this_eol = two_byte_eol; | |
6305 } | |
6306 else | |
6307 { | |
6308 if (one_byte_eol < 0) | |
6309 one_byte_eol =detect_eol (this, coding.source, src_bytes); | |
6310 this_eol = one_byte_eol; | |
6311 } | |
6312 if (this_eol == EOL_SEEN_LF) | |
6313 XSETCAR (tail, AREF (eol_type, 0)); | |
6314 else if (this_eol == EOL_SEEN_CRLF) | |
6315 XSETCAR (tail, AREF (eol_type, 1)); | |
6316 else if (this_eol == EOL_SEEN_CR) | |
6317 XSETCAR (tail, AREF (eol_type, 2)); | |
6318 } | |
6319 } | |
6320 } | |
6321 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
6322 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
|
6323 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6324 |
88365 | 6325 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6326 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
|
6327 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
|
6328 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
|
6329 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
|
6330 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6331 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
|
6332 `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
|
6333 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
|
6334 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6335 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
|
6336 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6337 (start, end, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6338 Lisp_Object start, end, highest; |
17052 | 6339 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6340 int from, to; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6341 int from_byte, to_byte; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6342 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6343 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
|
6344 CHECK_NUMBER_COERCE_MARKER (end); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6345 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6346 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6347 from = XINT (start), to = XINT (end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6348 from_byte = CHAR_TO_BYTE (from); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6349 to_byte = CHAR_TO_BYTE (to); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6350 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6351 if (from < GPT && to >= GPT) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6352 move_gap_both (to, to_byte); |
88365 | 6353 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6354 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
88365 | 6355 to_byte - from_byte, |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6356 !NILP (highest), |
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6357 !NILP (current_buffer |
88365 | 6358 ->enable_multibyte_characters), |
6359 Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6360 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6361 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6362 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
|
6363 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
|
6364 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
|
6365 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
|
6366 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6367 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
|
6368 `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
|
6369 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
|
6370 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6371 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
|
6372 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6373 (string, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6374 Lisp_Object string, highest; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6375 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6376 CHECK_STRING (string); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6377 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6378 return detect_coding_system (XSTRING (string)->data, |
88365 | 6379 STRING_BYTES (XSTRING (string)), |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6380 !NILP (highest), |
88365 | 6381 STRING_MULTIBYTE (string), |
6382 Qnil); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6383 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6384 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6385 |
88365 | 6386 static INLINE int |
6387 char_encodable_p (c, attrs) | |
6388 int c; | |
6389 Lisp_Object attrs; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6390 { |
88365 | 6391 Lisp_Object tail; |
6392 struct charset *charset; | |
6393 | |
6394 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | |
6395 CONSP (tail); tail = XCDR (tail)) | |
6396 { | |
6397 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
6398 if (CHAR_CHARSET_P (c, charset)) | |
6399 break; | |
6400 } | |
6401 return (! NILP (tail)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6402 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6403 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6404 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6405 /* Return a list of coding systems that safely encode the text between |
88365 | 6406 START and END. If EXCLUDE is non-nil, it is a list of coding |
6407 systems not to check. The returned list doesn't contain any such | |
6408 coding systems. In any case, If the text contains only ASCII or is | |
6409 unibyte, return t. */ | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6410 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6411 DEFUN ("find-coding-systems-region-internal", |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6412 Ffind_coding_systems_region_internal, |
88365 | 6413 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
|
6414 doc: /* Internal use only. */) |
88365 | 6415 (start, end, exclude) |
6416 Lisp_Object start, end, exclude; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6417 { |
88365 | 6418 Lisp_Object coding_attrs_list, safe_codings; |
6419 EMACS_INT start_byte, end_byte; | |
6420 unsigned char *p, *pbeg, *pend; | |
6421 int c; | |
6422 Lisp_Object tail, elt; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6423 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6424 if (STRINGP (start)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6425 { |
88365 | 6426 if (!STRING_MULTIBYTE (start) |
6427 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6428 return Qt; |
88365 | 6429 start_byte = 0; |
6430 end_byte = STRING_BYTES (XSTRING (start)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6431 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6432 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6433 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6434 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
|
6435 CHECK_NUMBER_COERCE_MARKER (end); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6436 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
|
6437 args_out_of_range (start, end); |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6438 if (NILP (current_buffer->enable_multibyte_characters)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6439 return Qt; |
88365 | 6440 start_byte = CHAR_TO_BYTE (XINT (start)); |
6441 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6442 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6443 return Qt; | |
6444 | |
6445 if (start < GPT && end > GPT) | |
6446 { | |
6447 if ((GPT - start) < (end - GPT)) | |
6448 move_gap_both (start, start_byte); | |
6449 else | |
6450 move_gap_both (end, end_byte); | |
6451 } | |
6452 } | |
6453 | |
6454 coding_attrs_list = Qnil; | |
6455 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6456 if (NILP (exclude) | |
6457 || NILP (Fmemq (XCAR (tail), exclude))) | |
6458 { | |
6459 Lisp_Object attrs; | |
6460 | |
6461 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
6462 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
6463 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
6464 coding_attrs_list = Fcons (attrs, coding_attrs_list); | |
6465 } | |
6466 | |
6467 if (STRINGP (start)) | |
6468 p = pbeg = XSTRING (start)->data; | |
6469 else | |
6470 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6471 pend = p + (end_byte - start_byte); | |
6472 | |
6473 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
6474 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6475 | |
6476 while (p < pend) | |
6477 { | |
6478 if (ASCII_BYTE_P (*p)) | |
6479 p++; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6480 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6481 { |
88365 | 6482 c = STRING_CHAR_ADVANCE (p); |
6483 | |
6484 charset_map_loaded = 0; | |
6485 for (tail = coding_attrs_list; CONSP (tail);) | |
6486 { | |
6487 elt = XCAR (tail); | |
6488 if (NILP (elt)) | |
6489 tail = XCDR (tail); | |
6490 else if (char_encodable_p (c, elt)) | |
6491 tail = XCDR (tail); | |
6492 else if (CONSP (XCDR (tail))) | |
6493 { | |
6494 XSETCAR (tail, XCAR (XCDR (tail))); | |
6495 XSETCDR (tail, XCDR (XCDR (tail))); | |
6496 } | |
6497 else | |
6498 { | |
6499 XSETCAR (tail, Qnil); | |
6500 tail = XCDR (tail); | |
6501 } | |
6502 } | |
6503 if (charset_map_loaded) | |
6504 { | |
6505 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6506 | |
6507 if (STRINGP (start)) | |
6508 pbeg = XSTRING (start)->data; | |
6509 else | |
6510 pbeg = BYTE_POS_ADDR (start_byte); | |
6511 p = pbeg + p_offset; | |
6512 pend = pbeg + pend_offset; | |
6513 } | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6514 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6515 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6516 |
88365 | 6517 safe_codings = Qnil; |
6518 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) | |
6519 if (! NILP (XCAR (tail))) | |
6520 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
6521 | |
6522 return safe_codings; | |
6523 } | |
6524 | |
6525 | |
6526 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, | |
6527 Scheck_coding_systems_region, 3, 3, 0, | |
6528 doc: /* Check if the region is encodable by coding systems. | |
6529 | |
6530 START and END are buffer positions specifying the region. | |
6531 CODING-SYSTEM-LIST is a list of coding systems to check. | |
6532 | |
6533 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
6534 CODING-SYSTEM is a member of CODING-SYSTEM-LIst and can't encode the | |
6535 whole region, POS0, POS1, ... are buffer positions where non-encodable | |
6536 characters are found. | |
6537 | |
6538 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
6539 value is nil. | |
6540 | |
6541 START may be a string. In that case, check if the string is | |
6542 encodable, and the value contains indices to the string instead of | |
6543 buffer positions. END is ignored. */) | |
6544 (start, end, coding_system_list) | |
6545 Lisp_Object start, end, coding_system_list; | |
6546 { | |
6547 Lisp_Object list; | |
6548 EMACS_INT start_byte, end_byte; | |
6549 int pos; | |
6550 unsigned char *p, *pbeg, *pend; | |
6551 int c; | |
6552 Lisp_Object tail, elt; | |
6553 | |
6554 if (STRINGP (start)) | |
6555 { | |
6556 if (!STRING_MULTIBYTE (start) | |
6557 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
6558 return Qnil; | |
6559 start_byte = 0; | |
6560 end_byte = STRING_BYTES (XSTRING (start)); | |
6561 pos = 0; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6562 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6563 else |
88365 | 6564 { |
6565 CHECK_NUMBER_COERCE_MARKER (start); | |
6566 CHECK_NUMBER_COERCE_MARKER (end); | |
6567 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
6568 args_out_of_range (start, end); | |
6569 if (NILP (current_buffer->enable_multibyte_characters)) | |
6570 return Qnil; | |
6571 start_byte = CHAR_TO_BYTE (XINT (start)); | |
6572 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6573 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6574 return Qt; | |
6575 | |
6576 if (start < GPT && end > GPT) | |
6577 { | |
6578 if ((GPT - start) < (end - GPT)) | |
6579 move_gap_both (start, start_byte); | |
6580 else | |
6581 move_gap_both (end, end_byte); | |
6582 } | |
6583 pos = start; | |
6584 } | |
6585 | |
6586 list = Qnil; | |
6587 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6588 { | |
6589 elt = XCAR (tail); | |
6590 list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | |
6591 Qnil)), | |
6592 list); | |
6593 } | |
6594 | |
6595 if (STRINGP (start)) | |
6596 p = pbeg = XSTRING (start)->data; | |
6597 else | |
6598 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6599 pend = p + (end_byte - start_byte); | |
6600 | |
6601 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
6602 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6603 | |
6604 while (p < pend) | |
6605 { | |
6606 if (ASCII_BYTE_P (*p)) | |
6607 p++; | |
6608 else | |
6609 { | |
6610 c = STRING_CHAR_ADVANCE (p); | |
6611 | |
6612 charset_map_loaded = 0; | |
6613 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
6614 { | |
6615 elt = XCDR (XCAR (tail)); | |
6616 if (! char_encodable_p (c, XCAR (elt))) | |
6617 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
6618 } | |
6619 if (charset_map_loaded) | |
6620 { | |
6621 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6622 | |
6623 if (STRINGP (start)) | |
6624 pbeg = XSTRING (start)->data; | |
6625 else | |
6626 pbeg = BYTE_POS_ADDR (start_byte); | |
6627 p = pbeg + p_offset; | |
6628 pend = pbeg + pend_offset; | |
6629 } | |
6630 } | |
6631 pos++; | |
6632 } | |
6633 | |
6634 tail = list; | |
6635 list = Qnil; | |
6636 for (; CONSP (tail); tail = XCDR (tail)) | |
6637 { | |
6638 elt = XCAR (tail); | |
6639 if (CONSP (XCDR (XCDR (elt)))) | |
6640 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
6641 list); | |
6642 } | |
6643 | |
6644 return list; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6645 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6646 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6647 |
88365 | 6648 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6649 Lisp_Object |
88365 | 6650 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
6651 Lisp_Object start, end, coding_system, dst_object; | |
6652 int encodep, norecord; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6653 { |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6654 struct coding_system coding; |
88365 | 6655 EMACS_INT from, from_byte, to, to_byte; |
6656 Lisp_Object src_object; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6657 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6658 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
|
6659 CHECK_NUMBER_COERCE_MARKER (end); |
88365 | 6660 if (NILP (coding_system)) |
6661 coding_system = Qno_conversion; | |
6662 else | |
6663 CHECK_CODING_SYSTEM (coding_system); | |
6664 src_object = Fcurrent_buffer (); | |
6665 if (NILP (dst_object)) | |
6666 dst_object = src_object; | |
6667 else if (! EQ (dst_object, Qt)) | |
6668 CHECK_BUFFER (dst_object); | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6669 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6670 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6671 from = XFASTINT (start); |
88365 | 6672 from_byte = CHAR_TO_BYTE (from); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6673 to = XFASTINT (end); |
88365 | 6674 to_byte = CHAR_TO_BYTE (to); |
6675 | |
6676 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6677 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6678 |
6679 if (encodep) | |
6680 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6681 dst_object); | |
6682 else | |
6683 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6684 dst_object); | |
6685 if (! norecord) | |
6686 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6687 | |
6688 if (coding.result != CODING_RESULT_SUCCESS) | |
6689 error ("Code conversion error: %d", coding.result); | |
6690 | |
6691 return (BUFFERP (dst_object) | |
6692 ? make_number (coding.produced_char) | |
6693 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6694 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6695 |
88365 | 6696 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6697 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
88365 | 6698 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
|
6699 doc: /* Decode the current region from the specified coding system. |
88365 | 6700 When called from a program, takes four arguments: |
6701 START, END, CODING-SYSTEM, and DESTINATION. | |
6702 START and END are buffer positions. | |
6703 | |
6704 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
6705 If nil, the region between START and END is replace by the decoded text. | |
6706 If buffer, the decoded text is inserted in the buffer. | |
6707 If t, the decoded text is returned. | |
6708 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6709 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
|
6710 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
|
6711 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6712 It returns the length of the decoded text. */) |
88365 | 6713 (start, end, coding_system, destination) |
6714 Lisp_Object start, end, coding_system, destination; | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6715 { |
88365 | 6716 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
|
6717 } |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6718 |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6719 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
88365 | 6720 3, 4, "r\nzCoding system: ", |
6721 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
|
6722 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
|
6723 START, END, and CODING-SYSTEM. START and END are buffer positions. |
88365 | 6724 |
6725 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
6726 If nil, the region between START and END is replace by the encoded text. | |
6727 If buffer, the encoded text is inserted in the buffer. | |
6728 If t, the encoded text is returned. | |
6729 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6730 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
|
6731 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
|
6732 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6733 It returns the length of the encoded text. */) |
88365 | 6734 (start, end, coding_system, destination) |
6735 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
|
6736 { |
88365 | 6737 return code_convert_region (start, end, coding_system, destination, 1, 0); |
17052 | 6738 } |
6739 | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6740 Lisp_Object |
88365 | 6741 code_convert_string (string, coding_system, dst_object, |
6742 encodep, nocopy, norecord) | |
6743 Lisp_Object string, coding_system, dst_object; | |
6744 int encodep, nocopy, norecord; | |
17052 | 6745 { |
6746 struct coding_system coding; | |
88365 | 6747 EMACS_INT chars, bytes; |
17052 | 6748 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6749 CHECK_STRING (string); |
88365 | 6750 if (NILP (coding_system)) |
6751 { | |
6752 if (! norecord) | |
6753 Vlast_coding_system_used = Qno_conversion; | |
6754 if (NILP (dst_object)) | |
6755 return (nocopy ? Fcopy_sequence (string) : string); | |
6756 } | |
17052 | 6757 |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6758 if (NILP (coding_system)) |
88365 | 6759 coding_system = Qno_conversion; |
6760 else | |
6761 CHECK_CODING_SYSTEM (coding_system); | |
6762 if (NILP (dst_object)) | |
6763 dst_object = Qt; | |
6764 else if (! EQ (dst_object, Qt)) | |
6765 CHECK_BUFFER (dst_object); | |
6766 | |
6767 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6768 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6769 chars = XSTRING (string)->size; |
6770 bytes = STRING_BYTES (XSTRING (string)); | |
6771 if (encodep) | |
6772 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6773 else | |
6774 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6775 if (! norecord) | |
6776 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6777 | |
6778 if (coding.result != CODING_RESULT_SUCCESS) | |
6779 error ("Code conversion error: %d", coding.result); | |
6780 | |
6781 return (BUFFERP (dst_object) | |
6782 ? make_number (coding.produced_char) | |
6783 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6784 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6785 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6786 |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6787 /* Encode or decode STRING according to CODING_SYSTEM. |
26847 | 6788 Do not set Vlast_coding_system_used. |
6789 | |
6790 This function is called only from macros DECODE_FILE and | |
6791 ENCODE_FILE, thus we ignore character composition. */ | |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6792 |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6793 Lisp_Object |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6794 code_convert_string_norecord (string, coding_system, encodep) |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6795 Lisp_Object string, coding_system; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6796 int encodep; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6797 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
6798 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
|
6799 } |
88365 | 6800 |
6801 | |
6802 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
6803 2, 4, 0, | |
6804 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
6805 | |
6806 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
6807 if the decoding operation is trivial. | |
6808 | |
6809 Optional fourth arg BUFFER non-nil meant that the decoded text is | |
6810 inserted in BUFFER instead of returned as a astring. In this case, | |
6811 the return value is BUFFER. | |
6812 | |
6813 This function sets `last-coding-system-used' to the precise coding system | |
6814 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6815 not fully specified. */) | |
6816 (string, coding_system, nocopy, buffer) | |
6817 Lisp_Object string, coding_system, nocopy, buffer; | |
6818 { | |
6819 return code_convert_string (string, coding_system, buffer, | |
6820 0, ! NILP (nocopy), 0); | |
6821 } | |
6822 | |
6823 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
6824 2, 4, 0, | |
6825 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
6826 | |
6827 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
6828 itself if the encoding operation is trivial. | |
6829 | |
6830 Optional fourth arg BUFFER non-nil meant that the encoded text is | |
6831 inserted in BUFFER instead of returned as a astring. In this case, | |
6832 the return value is BUFFER. | |
6833 | |
6834 This function sets `last-coding-system-used' to the precise coding system | |
6835 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6836 not fully specified.) */) | |
6837 (string, coding_system, nocopy, buffer) | |
6838 Lisp_Object string, coding_system, nocopy, buffer; | |
6839 { | |
6840 return code_convert_string (string, coding_system, buffer, | |
6841 nocopy, ! NILP (nocopy), 1); | |
6842 } | |
6843 | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6844 |
17052 | 6845 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
|
6846 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
|
6847 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
|
6848 (code) |
17052 | 6849 Lisp_Object code; |
6850 { | |
88365 | 6851 Lisp_Object spec, attrs, val; |
6852 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
6853 int c; | |
6854 | |
6855 CHECK_NATNUM (code); | |
6856 c = XFASTINT (code); | |
6857 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6858 attrs = AREF (spec, 0); | |
6859 | |
6860 if (ASCII_BYTE_P (c) | |
6861 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6862 return code; | |
6863 | |
6864 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6865 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
|
6866 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
|
6867 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 6868 |
6869 if (c <= 0x7F) | |
6870 charset = charset_roman; | |
6871 else if (c >= 0xA0 && c < 0xDF) | |
6872 { | |
6873 charset = charset_kana; | |
6874 c -= 0x80; | |
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6875 } |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6876 else |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6877 { |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
6878 int s1 = c >> 8, s2 = c & 0xFF; |
88365 | 6879 |
6880 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
6881 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
6882 error ("Invalid code: %d", code); | |
6883 SJIS_TO_JIS (c); | |
6884 charset = charset_kanji; | |
6885 } | |
6886 c = DECODE_CHAR (charset, c); | |
6887 if (c < 0) | |
6888 error ("Invalid code: %d", code); | |
6889 return make_number (c); | |
17052 | 6890 } |
6891 | |
88365 | 6892 |
17052 | 6893 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
|
6894 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
|
6895 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
|
6896 (ch) |
88365 | 6897 Lisp_Object ch; |
17052 | 6898 { |
88365 | 6899 Lisp_Object spec, attrs, charset_list; |
6900 int c; | |
6901 struct charset *charset; | |
6902 unsigned code; | |
6903 | |
6904 CHECK_CHARACTER (ch); | |
6905 c = XFASTINT (ch); | |
6906 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6907 attrs = AREF (spec, 0); | |
6908 | |
6909 if (ASCII_CHAR_P (c) | |
6910 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6911 return ch; | |
6912 | |
6913 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
6914 charset = char_charset (c, charset_list, &code); | |
6915 if (code == CHARSET_INVALID_CODE (charset)) | |
6916 error ("Can't encode by shift_jis encoding: %d", c); | |
6917 JIS_TO_SJIS (code); | |
6918 | |
6919 return make_number (code); | |
17052 | 6920 } |
6921 | |
6922 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
|
6923 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
|
6924 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
|
6925 (code) |
17052 | 6926 Lisp_Object code; |
6927 { | |
88365 | 6928 Lisp_Object spec, attrs, val; |
6929 struct charset *charset_roman, *charset_big5, *charset; | |
6930 int c; | |
6931 | |
6932 CHECK_NATNUM (code); | |
6933 c = XFASTINT (code); | |
6934 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6935 attrs = AREF (spec, 0); | |
6936 | |
6937 if (ASCII_BYTE_P (c) | |
6938 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6939 return code; | |
6940 | |
6941 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6942 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
6943 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
6944 | |
6945 if (c <= 0x7F) | |
6946 charset = charset_roman; | |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
6947 else |
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
6948 { |
88365 | 6949 int b1 = c >> 8, b2 = c & 0x7F; |
6950 if (b1 < 0xA1 || b1 > 0xFE | |
6951 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
6952 error ("Invalid code: %d", code); | |
6953 charset = charset_big5; | |
6954 } | |
6955 c = DECODE_CHAR (charset, (unsigned )c); | |
6956 if (c < 0) | |
6957 error ("Invalid code: %d", code); | |
6958 return make_number (c); | |
17052 | 6959 } |
6960 | |
6961 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
|
6962 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
|
6963 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
|
6964 (ch) |
17052 | 6965 Lisp_Object ch; |
6966 { | |
88365 | 6967 Lisp_Object spec, attrs, charset_list; |
6968 struct charset *charset; | |
6969 int c; | |
6970 unsigned code; | |
6971 | |
6972 CHECK_CHARACTER (ch); | |
6973 c = XFASTINT (ch); | |
6974 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6975 attrs = AREF (spec, 0); | |
6976 if (ASCII_CHAR_P (c) | |
6977 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6978 return ch; | |
6979 | |
6980 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
6981 charset = char_charset (c, charset_list, &code); | |
6982 if (code == CHARSET_INVALID_CODE (charset)) | |
6983 error ("Can't encode by Big5 encoding: %d", c); | |
6984 | |
6985 return make_number (code); | |
17052 | 6986 } |
88365 | 6987 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6988 |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
6989 DEFUN ("set-terminal-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
6990 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
|
6991 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
|
6992 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
|
6993 (coding_system) |
88473 | 6994 Lisp_Object coding_system; |
17052 | 6995 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6996 CHECK_SYMBOL (coding_system); |
88365 | 6997 setup_coding_system (Fcheck_coding_system (coding_system), |
6998 &terminal_coding); | |
6999 | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
7000 /* We had better not send unsafe characters to terminal. */ |
88365 | 7001 terminal_coding.mode |= CODING_MODE_SAFE_ENCODING; |
7002 /* Characer composition should be disabled. */ | |
7003 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
|
7004 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
|
7005 terminal_coding.dst_multibyte = 0; |
17052 | 7006 return Qnil; |
7007 } | |
7008 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7009 DEFUN ("set-safe-terminal-coding-system-internal", |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7010 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
|
7011 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
41006 | 7012 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
|
7013 (coding_system) |
88473 | 7014 Lisp_Object coding_system; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7015 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7016 CHECK_SYMBOL (coding_system); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7017 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
|
7018 &safe_terminal_coding); |
88365 | 7019 /* Characer composition should be disabled. */ |
7020 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
|
7021 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
|
7022 safe_terminal_coding.dst_multibyte = 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7023 return Qnil; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7024 } |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7025 |
17052 | 7026 DEFUN ("terminal-coding-system", |
7027 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
|
7028 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
|
7029 () |
17052 | 7030 { |
88365 | 7031 return CODING_ID_NAME (terminal_coding.id); |
17052 | 7032 } |
7033 | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7034 DEFUN ("set-keyboard-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7035 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
|
7036 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
|
7037 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
|
7038 (coding_system) |
17052 | 7039 Lisp_Object coding_system; |
7040 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7041 CHECK_SYMBOL (coding_system); |
88365 | 7042 setup_coding_system (Fcheck_coding_system (coding_system), |
7043 &keyboard_coding); | |
7044 /* Characer composition should be disabled. */ | |
7045 keyboard_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
17052 | 7046 return Qnil; |
7047 } | |
7048 | |
7049 DEFUN ("keyboard-coding-system", | |
7050 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
|
7051 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
|
7052 () |
17052 | 7053 { |
88365 | 7054 return CODING_ID_NAME (keyboard_coding.id); |
17052 | 7055 } |
7056 | |
7057 | |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7058 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
|
7059 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
|
7060 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
|
7061 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
|
7062 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
|
7063 \(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
|
7064 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
|
7065 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7066 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
|
7067 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
|
7068 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
|
7069 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
|
7070 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7071 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
|
7072 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
|
7073 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
|
7074 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
|
7075 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7076 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
|
7077 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
|
7078 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
|
7079 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
|
7080 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7081 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
|
7082 `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
|
7083 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
|
7084 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
|
7085 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
|
7086 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
|
7087 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
|
7088 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7089 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
|
7090 (nargs, args) |
17052 | 7091 int nargs; |
7092 Lisp_Object *args; | |
7093 { | |
7094 Lisp_Object operation, target_idx, target, val; | |
7095 register Lisp_Object chain; | |
7096 | |
7097 if (nargs < 2) | |
7098 error ("Too few arguments"); | |
7099 operation = args[0]; | |
7100 if (!SYMBOLP (operation) | |
7101 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
88365 | 7102 error ("Invalid first arguement"); |
17052 | 7103 if (nargs < 1 + XINT (target_idx)) |
7104 error ("Too few arguments for operation: %s", | |
7105 XSYMBOL (operation)->name->data); | |
7106 target = args[XINT (target_idx) + 1]; | |
7107 if (!(STRINGP (target) | |
7108 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
88365 | 7109 error ("Invalid %dth argument", XINT (target_idx) + 1); |
17052 | 7110 |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7111 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
|
7112 || EQ (operation, Qwrite_region)) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7113 ? 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
|
7114 : (EQ (operation, Qopen_network_stream) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7115 ? Vnetwork_coding_system_alist |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7116 : Vprocess_coding_system_alist)); |
17052 | 7117 if (NILP (chain)) |
7118 return Qnil; | |
7119 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7120 for (; CONSP (chain); chain = XCDR (chain)) |
17052 | 7121 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
7122 Lisp_Object elt; |
88365 | 7123 |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7124 elt = XCAR (chain); |
17052 | 7125 if (CONSP (elt) |
7126 && ((STRINGP (target) | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7127 && STRINGP (XCAR (elt)) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7128 && 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
|
7129 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7130 { |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7131 val = XCDR (elt); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7132 /* 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
|
7133 function symbol, we return VAL as a coding system. */ |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7134 if (CONSP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7135 return val; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7136 if (! SYMBOLP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7137 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7138 if (! NILP (Fcoding_system_p (val))) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7139 return Fcons (val, val); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7140 if (! NILP (Ffboundp (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7141 { |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7142 val = call1 (val, Flist (nargs, args)); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7143 if (CONSP (val)) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7144 return val; |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7145 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
|
7146 return Fcons (val, val); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7147 } |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7148 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7149 } |
17052 | 7150 } |
7151 return Qnil; | |
7152 } | |
7153 | |
88365 | 7154 DEFUN ("set-coding-system-priority", Fset_coding_system_priority, |
7155 Sset_coding_system_priority, 1, MANY, 0, | |
88544
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7156 doc: /* Assign higher priority to coding systems given as arguments. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7157 usage: (set-coding-system-priority CODING-SYSTEM ...) */) |
88365 | 7158 (nargs, args) |
7159 int nargs; | |
7160 Lisp_Object *args; | |
7161 { | |
7162 int i, j; | |
7163 int changed[coding_category_max]; | |
7164 enum coding_category priorities[coding_category_max]; | |
7165 | |
7166 bzero (changed, sizeof changed); | |
7167 | |
7168 for (i = j = 0; i < nargs; i++) | |
7169 { | |
7170 enum coding_category category; | |
7171 Lisp_Object spec, attrs; | |
7172 | |
7173 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
7174 attrs = AREF (spec, 0); | |
7175 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
7176 if (changed[category]) | |
7177 /* Ignore this coding system because a coding system of the | |
7178 same category already had a higher priority. */ | |
7179 continue; | |
7180 changed[category] = 1; | |
7181 priorities[j++] = category; | |
7182 if (coding_categories[category].id >= 0 | |
7183 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
7184 setup_coding_system (args[i], &coding_categories[category]); | |
7185 } | |
7186 | |
7187 /* Now we have decided top J priorities. Reflect the order of the | |
7188 original priorities to the remaining priorities. */ | |
7189 | |
7190 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
7191 { | |
7192 while (j < coding_category_max | |
7193 && changed[coding_priorities[j]]) | |
7194 j++; | |
7195 if (j == coding_category_max) | |
7196 abort (); | |
7197 priorities[i] = coding_priorities[j]; | |
7198 } | |
7199 | |
7200 bcopy (priorities, coding_priorities, sizeof priorities); | |
7201 return Qnil; | |
7202 } | |
7203 | |
7204 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, | |
7205 Scoding_system_priority_list, 0, 1, 0, | |
7206 doc: /* Return a list of coding systems ordered by their priorities. */) | |
7207 (highestp) | |
7208 Lisp_Object highestp; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7209 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7210 int i; |
88365 | 7211 Lisp_Object val; |
7212 | |
7213 for (i = 0, val = Qnil; i < coding_category_max; i++) | |
7214 { | |
7215 enum coding_category category = coding_priorities[i]; | |
7216 int id = coding_categories[category].id; | |
7217 Lisp_Object attrs; | |
7218 | |
7219 if (id < 0) | |
7220 continue; | |
7221 attrs = CODING_ID_ATTRS (id); | |
7222 if (! NILP (highestp)) | |
7223 return CODING_ATTR_BASE_NAME (attrs); | |
7224 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
7225 } | |
7226 return Fnreverse (val); | |
7227 } | |
7228 | |
7229 static Lisp_Object | |
7230 make_subsidiaries (base) | |
7231 Lisp_Object base; | |
7232 { | |
7233 Lisp_Object subsidiaries; | |
7234 char *suffixes[] = { "-unix", "-dos", "-mac" }; | |
7235 int base_name_len = STRING_BYTES (XSYMBOL (base)->name); | |
7236 char *buf = (char *) alloca (base_name_len + 6); | |
7237 int i; | |
7238 | |
7239 bcopy (XSYMBOL (base)->name->data, buf, base_name_len); | |
7240 subsidiaries = Fmake_vector (make_number (3), Qnil); | |
7241 for (i = 0; i < 3; i++) | |
7242 { | |
7243 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
7244 ASET (subsidiaries, i, intern (buf)); | |
7245 } | |
7246 return subsidiaries; | |
7247 } | |
7248 | |
7249 | |
7250 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, | |
7251 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
|
7252 doc: /* For internal use only. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7253 usage: (define-coding-system-internal ...) */) |
88365 | 7254 (nargs, args) |
7255 int nargs; | |
7256 Lisp_Object *args; | |
7257 { | |
7258 Lisp_Object name; | |
7259 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
7260 Lisp_Object attrs; /* Vector of attributes. */ | |
7261 Lisp_Object eol_type; | |
7262 Lisp_Object aliases; | |
7263 Lisp_Object coding_type, charset_list, safe_charsets; | |
7264 enum coding_category category; | |
7265 Lisp_Object tail, val; | |
7266 int max_charset_id = 0; | |
7267 int i; | |
7268 | |
7269 if (nargs < coding_arg_max) | |
7270 goto short_args; | |
7271 | |
7272 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
7273 | |
7274 name = args[coding_arg_name]; | |
7275 CHECK_SYMBOL (name); | |
7276 CODING_ATTR_BASE_NAME (attrs) = name; | |
7277 | |
7278 val = args[coding_arg_mnemonic]; | |
7279 if (! STRINGP (val)) | |
7280 CHECK_CHARACTER (val); | |
7281 CODING_ATTR_MNEMONIC (attrs) = val; | |
7282 | |
7283 coding_type = args[coding_arg_coding_type]; | |
7284 CHECK_SYMBOL (coding_type); | |
7285 CODING_ATTR_TYPE (attrs) = coding_type; | |
7286 | |
7287 charset_list = args[coding_arg_charset_list]; | |
7288 if (SYMBOLP (charset_list)) | |
7289 { | |
7290 if (EQ (charset_list, Qiso_2022)) | |
7291 { | |
7292 if (! EQ (coding_type, Qiso_2022)) | |
7293 error ("Invalid charset-list"); | |
7294 charset_list = Viso_2022_charset_list; | |
7295 } | |
7296 else if (EQ (charset_list, Qemacs_mule)) | |
7297 { | |
7298 if (! EQ (coding_type, Qemacs_mule)) | |
7299 error ("Invalid charset-list"); | |
7300 charset_list = Vemacs_mule_charset_list; | |
7301 } | |
7302 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7303 if (max_charset_id < XFASTINT (XCAR (tail))) | |
7304 max_charset_id = XFASTINT (XCAR (tail)); | |
7305 } | |
7306 else | |
7307 { | |
7308 charset_list = Fcopy_sequence (charset_list); | |
7309 for (tail = charset_list; !NILP (tail); tail = Fcdr (tail)) | |
7310 { | |
7311 struct charset *charset; | |
7312 | |
7313 val = Fcar (tail); | |
7314 CHECK_CHARSET_GET_CHARSET (val, charset); | |
7315 if (EQ (coding_type, Qiso_2022) | |
7316 ? CHARSET_ISO_FINAL (charset) < 0 | |
7317 : EQ (coding_type, Qemacs_mule) | |
7318 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
7319 : 0) | |
7320 error ("Can't handle charset `%s'", | |
7321 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7322 | |
7323 XCAR (tail) = make_number (charset->id); | |
7324 if (max_charset_id < charset->id) | |
7325 max_charset_id = charset->id; | |
7326 } | |
7327 } | |
7328 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
7329 | |
7330 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
7331 make_number (255)); | |
7332 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7333 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
7334 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | |
7335 | |
7336 val = args[coding_arg_decode_translation_table]; | |
7337 if (! NILP (val)) | |
7338 CHECK_CHAR_TABLE (val); | |
7339 CODING_ATTR_DECODE_TBL (attrs) = val; | |
7340 | |
7341 val = args[coding_arg_encode_translation_table]; | |
7342 if (! NILP (val)) | |
7343 CHECK_CHAR_TABLE (val); | |
7344 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
7345 | |
7346 val = args[coding_arg_post_read_conversion]; | |
7347 CHECK_SYMBOL (val); | |
7348 CODING_ATTR_POST_READ (attrs) = val; | |
7349 | |
7350 val = args[coding_arg_pre_write_conversion]; | |
7351 CHECK_SYMBOL (val); | |
7352 CODING_ATTR_PRE_WRITE (attrs) = val; | |
7353 | |
7354 val = args[coding_arg_default_char]; | |
7355 if (NILP (val)) | |
7356 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
7357 else | |
7358 { | |
7359 CHECK_CHARACTER (val); | |
7360 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
7361 } | |
7362 | |
7363 val = args[coding_arg_plist]; | |
7364 CHECK_LIST (val); | |
7365 CODING_ATTR_PLIST (attrs) = val; | |
7366 | |
7367 if (EQ (coding_type, Qcharset)) | |
7368 { | |
7369 val = Fmake_vector (make_number (256), Qnil); | |
7370 | |
7371 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7372 { | |
7373 struct charset *charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7374 int idx = (CHARSET_DIMENSION (charset) - 1) * 4; |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7375 |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7376 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
|
7377 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
|
7378 { |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7379 if (NILP (AREF (val, i))) |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7380 ASET (val, i, XCAR (tail)); |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7381 else |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7382 error ("Charsets conflicts in the first byte"); |
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7383 } |
88365 | 7384 } |
7385 ASET (attrs, coding_attr_charset_valids, val); | |
7386 category = coding_category_charset; | |
7387 } | |
7388 else if (EQ (coding_type, Qccl)) | |
7389 { | |
7390 Lisp_Object valids; | |
7391 | |
7392 if (nargs < coding_arg_ccl_max) | |
7393 goto short_args; | |
7394 | |
7395 val = args[coding_arg_ccl_decoder]; | |
7396 CHECK_CCL_PROGRAM (val); | |
7397 if (VECTORP (val)) | |
7398 val = Fcopy_sequence (val); | |
7399 ASET (attrs, coding_attr_ccl_decoder, val); | |
7400 | |
7401 val = args[coding_arg_ccl_encoder]; | |
7402 CHECK_CCL_PROGRAM (val); | |
7403 if (VECTORP (val)) | |
7404 val = Fcopy_sequence (val); | |
7405 ASET (attrs, coding_attr_ccl_encoder, val); | |
7406 | |
7407 val = args[coding_arg_ccl_valids]; | |
7408 valids = Fmake_string (make_number (256), make_number (0)); | |
7409 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
7410 { | |
7411 val = Fcar (tail); | |
7412 if (INTEGERP (val)) | |
7413 ASET (valids, XINT (val), 1); | |
7414 else | |
7415 { | |
7416 int from, to; | |
7417 | |
7418 CHECK_CONS (val); | |
7419 CHECK_NUMBER (XCAR (val)); | |
7420 CHECK_NUMBER (XCDR (val)); | |
7421 from = XINT (XCAR (val)); | |
7422 to = XINT (XCDR (val)); | |
7423 for (i = from; i <= to; i++) | |
7424 ASET (valids, i, 1); | |
7425 } | |
7426 } | |
7427 ASET (attrs, coding_attr_ccl_valids, valids); | |
7428 | |
7429 category = coding_category_ccl; | |
7430 } | |
7431 else if (EQ (coding_type, Qutf_16)) | |
7432 { | |
7433 Lisp_Object bom, endian; | |
7434 | |
7435 if (nargs < coding_arg_utf16_max) | |
7436 goto short_args; | |
7437 | |
7438 bom = args[coding_arg_utf16_bom]; | |
7439 if (! NILP (bom) && ! EQ (bom, Qt)) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7440 { |
88365 | 7441 CHECK_CONS (bom); |
7442 CHECK_CODING_SYSTEM (XCAR (bom)); | |
7443 CHECK_CODING_SYSTEM (XCDR (bom)); | |
7444 } | |
7445 ASET (attrs, coding_attr_utf_16_bom, bom); | |
7446 | |
7447 endian = args[coding_arg_utf16_endian]; | |
7448 ASET (attrs, coding_attr_utf_16_endian, endian); | |
7449 | |
7450 category = (CONSP (bom) | |
7451 ? coding_category_utf_16_auto | |
7452 : NILP (bom) | |
7453 ? (NILP (endian) | |
7454 ? coding_category_utf_16_be_nosig | |
7455 : coding_category_utf_16_le_nosig) | |
7456 : (NILP (endian) | |
7457 ? coding_category_utf_16_be | |
7458 : coding_category_utf_16_le)); | |
7459 } | |
7460 else if (EQ (coding_type, Qiso_2022)) | |
7461 { | |
7462 Lisp_Object initial, reg_usage, request, flags; | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7463 int i, id; |
88365 | 7464 |
7465 if (nargs < coding_arg_iso2022_max) | |
7466 goto short_args; | |
7467 | |
7468 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
7469 CHECK_VECTOR (initial); | |
7470 for (i = 0; i < 4; i++) | |
7471 { | |
7472 val = Faref (initial, make_number (i)); | |
7473 if (! NILP (val)) | |
7474 { | |
7475 CHECK_CHARSET_GET_ID (val, id); | |
7476 ASET (initial, i, make_number (id)); | |
7477 } | |
7478 else | |
7479 ASET (initial, i, make_number (-1)); | |
7480 } | |
7481 | |
7482 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
7483 CHECK_CONS (reg_usage); | |
7484 CHECK_NATNUM (XCAR (reg_usage)); | |
7485 CHECK_NATNUM (XCDR (reg_usage)); | |
7486 | |
7487 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
7488 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
7489 { | |
7490 int id; | |
7491 | |
7492 val = Fcar (tail); | |
7493 CHECK_CONS (val); | |
7494 CHECK_CHARSET_GET_ID (XCAR (val), id); | |
7495 CHECK_NATNUM (XCDR (val)); | |
7496 if (XINT (XCDR (val)) >= 4) | |
7497 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
7498 XCAR (val) = make_number (id); | |
7499 } | |
7500 | |
7501 flags = args[coding_arg_iso2022_flags]; | |
7502 CHECK_NATNUM (flags); | |
7503 i = XINT (flags); | |
7504 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
7505 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
7506 | |
7507 ASET (attrs, coding_attr_iso_initial, initial); | |
7508 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
7509 ASET (attrs, coding_attr_iso_request, request); | |
7510 ASET (attrs, coding_attr_iso_flags, flags); | |
7511 setup_iso_safe_charsets (attrs); | |
7512 | |
7513 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
7514 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7515 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7516 ? coding_category_iso_7_else | |
7517 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
7518 ? coding_category_iso_7 | |
7519 : coding_category_iso_7_tight); | |
7520 else | |
7521 { | |
7522 int id = XINT (AREF (initial, 1)); | |
7523 | |
7524 category = (((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7525 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7526 || EQ (args[coding_arg_charset_list], Qiso_2022) | |
7527 || id < 0) | |
7528 ? coding_category_iso_8_else | |
7529 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
7530 ? coding_category_iso_8_1 | |
7531 : coding_category_iso_8_2); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7532 } |
88365 | 7533 } |
7534 else if (EQ (coding_type, Qemacs_mule)) | |
7535 { | |
7536 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
7537 ASET (attrs, coding_attr_emacs_mule_full, Qt); | |
7538 | |
7539 category = coding_category_emacs_mule; | |
7540 } | |
7541 else if (EQ (coding_type, Qshift_jis)) | |
7542 { | |
7543 | |
7544 struct charset *charset; | |
7545 | |
7546 if (XINT (Flength (charset_list)) != 3) | |
7547 error ("There should be just three charsets"); | |
7548 | |
7549 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7550 if (CHARSET_DIMENSION (charset) != 1) | |
7551 error ("Dimension of charset %s is not one", | |
7552 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7553 | |
7554 charset_list = XCDR (charset_list); | |
7555 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7556 if (CHARSET_DIMENSION (charset) != 1) | |
7557 error ("Dimension of charset %s is not one", | |
7558 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7559 | |
7560 charset_list = XCDR (charset_list); | |
7561 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7562 if (CHARSET_DIMENSION (charset) != 2) | |
7563 error ("Dimension of charset %s is not two", | |
7564 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7565 | |
7566 category = coding_category_sjis; | |
7567 Vsjis_coding_system = name; | |
7568 } | |
7569 else if (EQ (coding_type, Qbig5)) | |
7570 { | |
7571 struct charset *charset; | |
7572 | |
7573 if (XINT (Flength (charset_list)) != 2) | |
7574 error ("There should be just two charsets"); | |
7575 | |
7576 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7577 if (CHARSET_DIMENSION (charset) != 1) | |
7578 error ("Dimension of charset %s is not one", | |
7579 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7580 | |
7581 charset_list = XCDR (charset_list); | |
7582 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7583 if (CHARSET_DIMENSION (charset) != 2) | |
7584 error ("Dimension of charset %s is not two", | |
7585 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7586 | |
7587 category = coding_category_big5; | |
7588 Vbig5_coding_system = name; | |
7589 } | |
7590 else if (EQ (coding_type, Qraw_text)) | |
7591 category = coding_category_raw_text; | |
7592 else if (EQ (coding_type, Qutf_8)) | |
7593 category = coding_category_utf_8; | |
7594 else if (EQ (coding_type, Qundecided)) | |
7595 category = coding_category_undecided; | |
7596 else | |
7597 error ("Invalid coding system type: %s", | |
7598 XSYMBOL (coding_type)->name->data); | |
7599 | |
7600 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
7601 | |
7602 eol_type = args[coding_arg_eol_type]; | |
7603 if (! NILP (eol_type) | |
7604 && ! EQ (eol_type, Qunix) | |
7605 && ! EQ (eol_type, Qdos) | |
7606 && ! EQ (eol_type, Qmac)) | |
7607 error ("Invalid eol-type"); | |
7608 | |
7609 aliases = Fcons (name, Qnil); | |
7610 | |
7611 if (NILP (eol_type)) | |
7612 { | |
7613 eol_type = make_subsidiaries (name); | |
7614 for (i = 0; i < 3; i++) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7615 { |
88365 | 7616 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
7617 | |
7618 this_name = AREF (eol_type, i); | |
7619 this_aliases = Fcons (this_name, Qnil); | |
7620 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
7621 this_spec = Fmake_vector (make_number (3), attrs); | |
7622 ASET (this_spec, 1, this_aliases); | |
7623 ASET (this_spec, 2, this_eol_type); | |
7624 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
7625 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
7626 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (this_name), Qnil), | |
7627 Vcoding_system_alist); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7628 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7629 } |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7630 |
88365 | 7631 spec_vec = Fmake_vector (make_number (3), attrs); |
7632 ASET (spec_vec, 1, aliases); | |
7633 ASET (spec_vec, 2, eol_type); | |
7634 | |
7635 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
7636 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
7637 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), | |
7638 Vcoding_system_alist); | |
7639 | |
7640 { | |
7641 int id = coding_categories[category].id; | |
7642 | |
7643 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
7644 setup_coding_system (name, &coding_categories[category]); | |
7645 } | |
7646 | |
7647 return Qnil; | |
7648 | |
7649 short_args: | |
7650 return Fsignal (Qwrong_number_of_arguments, | |
7651 Fcons (intern ("define-coding-system-internal"), | |
7652 make_number (nargs))); | |
7653 } | |
7654 | |
7655 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, | |
7656 Sdefine_coding_system_alias, 2, 2, 0, | |
7657 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
7658 (alias, coding_system) | |
7659 Lisp_Object alias, coding_system; | |
7660 { | |
7661 Lisp_Object spec, aliases, eol_type; | |
7662 | |
7663 CHECK_SYMBOL (alias); | |
7664 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7665 aliases = AREF (spec, 1); | |
7666 while (!NILP (XCDR (aliases))) | |
7667 aliases = XCDR (aliases); | |
7668 XCDR (aliases) = Fcons (alias, Qnil); | |
7669 | |
7670 eol_type = AREF (spec, 2); | |
7671 if (VECTORP (eol_type)) | |
7672 { | |
7673 Lisp_Object subsidiaries; | |
7674 int i; | |
7675 | |
7676 subsidiaries = make_subsidiaries (alias); | |
7677 for (i = 0; i < 3; i++) | |
7678 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
7679 AREF (eol_type, i)); | |
7680 | |
7681 ASET (spec, 2, subsidiaries); | |
7682 } | |
7683 | |
7684 Fputhash (alias, spec, Vcoding_system_hash_table); | |
88485 | 7685 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
7686 Vcoding_system_alist); | |
88365 | 7687 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7688 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7689 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7690 |
88365 | 7691 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
7692 1, 1, 0, | |
7693 doc: /* Return the base of CODING-SYSTEM. | |
7694 Any alias or subsidiary coding systems are not base coding system. */) | |
7695 (coding_system) | |
7696 Lisp_Object coding_system; | |
7697 { | |
7698 Lisp_Object spec, attrs; | |
7699 | |
7700 if (NILP (coding_system)) | |
7701 return (Qno_conversion); | |
7702 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7703 attrs = AREF (spec, 0); | |
7704 return CODING_ATTR_BASE_NAME (attrs); | |
7705 } | |
7706 | |
7707 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
7708 1, 1, 0, | |
7709 doc: "Return the property list of CODING-SYSTEM.") | |
7710 (coding_system) | |
7711 Lisp_Object coding_system; | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7712 { |
88365 | 7713 Lisp_Object spec, attrs; |
7714 | |
7715 if (NILP (coding_system)) | |
7716 coding_system = Qno_conversion; | |
7717 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7718 attrs = AREF (spec, 0); | |
7719 return CODING_ATTR_PLIST (attrs); | |
7720 } | |
7721 | |
7722 | |
7723 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
7724 1, 1, 0, | |
7725 doc: /* Return the list of aliases of CODING-SYSTEM. | |
7726 A base coding system is what made by `define-coding-system'. | |
7727 Any alias nor subsidiary coding systems are not base coding system. */) | |
7728 (coding_system) | |
7729 Lisp_Object coding_system; | |
7730 { | |
7731 Lisp_Object spec; | |
7732 | |
7733 if (NILP (coding_system)) | |
7734 coding_system = Qno_conversion; | |
7735 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7736 return AREF (spec, 2); | |
7737 } | |
7738 | |
7739 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
7740 Scoding_system_eol_type, 1, 1, 0, | |
7741 doc: /* Return eol-type of CODING-SYSTEM. | |
7742 An eol-type is integer 0, 1, 2, or a vector of coding systems. | |
7743 | |
7744 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
7745 and CR respectively. | |
7746 | |
7747 A vector value indicates that a format of end-of-line should be | |
7748 detected automatically. Nth element of the vector is the subsidiary | |
7749 coding system whose eol-type is N. */) | |
7750 (coding_system) | |
7751 Lisp_Object coding_system; | |
7752 { | |
7753 Lisp_Object spec, eol_type; | |
7754 int n; | |
7755 | |
7756 if (NILP (coding_system)) | |
7757 coding_system = Qno_conversion; | |
7758 if (! CODING_SYSTEM_P (coding_system)) | |
7759 return Qnil; | |
7760 spec = CODING_SYSTEM_SPEC (coding_system); | |
7761 eol_type = AREF (spec, 2); | |
7762 if (VECTORP (eol_type)) | |
7763 return Fcopy_sequence (eol_type); | |
7764 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
7765 return make_number (n); | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7766 } |
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7767 |
17052 | 7768 #endif /* emacs */ |
7769 | |
7770 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7771 /*** 9. Post-amble ***/ |
17052 | 7772 |
21514 | 7773 void |
17052 | 7774 init_coding_once () |
7775 { | |
7776 int i; | |
7777 | |
88365 | 7778 for (i = 0; i < coding_category_max; i++) |
7779 { | |
7780 coding_categories[i].id = -1; | |
7781 coding_priorities[i] = i; | |
7782 } | |
17052 | 7783 |
7784 /* ISO2022 specific initialize routine. */ | |
7785 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
|
7786 iso_code_class[i] = ISO_control_0; |
17052 | 7787 for (i = 0x21; i < 0x7F; i++) |
7788 iso_code_class[i] = ISO_graphic_plane_0; | |
7789 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
|
7790 iso_code_class[i] = ISO_control_1; |
17052 | 7791 for (i = 0xA1; i < 0xFF; i++) |
7792 iso_code_class[i] = ISO_graphic_plane_1; | |
7793 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
7794 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
7795 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
7796 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
7797 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
7798 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
7799 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
7800 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
7801 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
7802 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
7803 | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
7804 inhibit_pre_post_conversion = 0; |
88365 | 7805 |
7806 for (i = 0; i < 256; i++) | |
7807 { | |
7808 emacs_mule_bytes[i] = 1; | |
7809 } | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
7810 emacs_mule_bytes[LEADING_CODE_PRIVATE_11] = 3; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
7811 emacs_mule_bytes[LEADING_CODE_PRIVATE_12] = 3; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
7812 emacs_mule_bytes[LEADING_CODE_PRIVATE_21] = 4; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
7813 emacs_mule_bytes[LEADING_CODE_PRIVATE_22] = 4; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7814 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7815 |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7816 #ifdef emacs |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7817 |
21514 | 7818 void |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7819 syms_of_coding () |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7820 { |
88365 | 7821 staticpro (&Vcoding_system_hash_table); |
7822 Vcoding_system_hash_table = Fmakehash (Qeq); | |
7823 | |
7824 staticpro (&Vsjis_coding_system); | |
7825 Vsjis_coding_system = Qnil; | |
7826 | |
7827 staticpro (&Vbig5_coding_system); | |
7828 Vbig5_coding_system = Qnil; | |
7829 | |
7830 staticpro (&Vcode_conversion_work_buf_list); | |
7831 Vcode_conversion_work_buf_list = Qnil; | |
7832 | |
7833 staticpro (&Vcode_conversion_reused_work_buf); | |
7834 Vcode_conversion_reused_work_buf = Qnil; | |
7835 | |
7836 DEFSYM (Qcharset, "charset"); | |
7837 DEFSYM (Qtarget_idx, "target-idx"); | |
7838 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7839 Fset (Qcoding_system_history, Qnil); |
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7840 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7841 /* 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
|
7842 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
|
7843 /* 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
|
7844 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
|
7845 |
88365 | 7846 DEFSYM (Qcall_process, "call-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7847 /* 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
|
7848 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
|
7849 |
88365 | 7850 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
|
7851 /* 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
|
7852 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
|
7853 |
88365 | 7854 DEFSYM (Qstart_process, "start-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7855 /* 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
|
7856 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
|
7857 |
88365 | 7858 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
|
7859 /* 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
|
7860 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
|
7861 |
88365 | 7862 DEFSYM (Qcoding_system, "coding-system"); |
7863 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
7864 | |
7865 DEFSYM (Qeol_type, "eol-type"); | |
7866 DEFSYM (Qunix, "unix"); | |
7867 DEFSYM (Qdos, "dos"); | |
7868 DEFSYM (Qmac, "mac"); | |
7869 | |
7870 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
7871 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
7872 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
7873 DEFSYM (Qdefault_char, "default-char"); | |
7874 DEFSYM (Qundecided, "undecided"); | |
7875 DEFSYM (Qno_conversion, "no-conversion"); | |
7876 DEFSYM (Qraw_text, "raw-text"); | |
7877 | |
7878 DEFSYM (Qiso_2022, "iso-2022"); | |
7879 | |
7880 DEFSYM (Qutf_8, "utf-8"); | |
7881 | |
7882 DEFSYM (Qutf_16, "utf-16"); | |
7883 DEFSYM (Qutf_16_be, "utf-16-be"); | |
7884 DEFSYM (Qutf_16_be_nosig, "utf-16-be-nosig"); | |
7885 DEFSYM (Qutf_16_le, "utf-16-l3"); | |
7886 DEFSYM (Qutf_16_le_nosig, "utf-16-le-nosig"); | |
7887 DEFSYM (Qsignature, "signature"); | |
7888 DEFSYM (Qendian, "endian"); | |
7889 DEFSYM (Qbig, "big"); | |
7890 DEFSYM (Qlittle, "little"); | |
7891 | |
7892 DEFSYM (Qshift_jis, "shift-jis"); | |
7893 DEFSYM (Qbig5, "big5"); | |
7894 | |
7895 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
7896 | |
7897 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
17052 | 7898 Fput (Qcoding_system_error, Qerror_conditions, |
7899 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
7900 Fput (Qcoding_system_error, Qerror_message, | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7901 build_string ("Invalid coding system")); |
17052 | 7902 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7903 /* 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
|
7904 Setting this variable twice is harmless. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7905 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
|
7906 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
88365 | 7907 |
7908 DEFSYM (Qtranslation_table, "translation-table"); | |
7909 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); | |
7910 DEFSYM (Qtranslation_table_id, "translation-table-id"); | |
7911 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
7912 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
7913 | |
7914 DEFSYM (Qvalid_codes, "valid-codes"); | |
7915 | |
7916 DEFSYM (Qemacs_mule, "emacs-mule"); | |
7917 | |
7918 Vcoding_category_table | |
7919 = Fmake_vector (make_number (coding_category_max), Qnil); | |
7920 staticpro (&Vcoding_category_table); | |
7921 /* Followings are target of code detection. */ | |
7922 ASET (Vcoding_category_table, coding_category_iso_7, | |
7923 intern ("coding-category-iso-7")); | |
7924 ASET (Vcoding_category_table, coding_category_iso_7_tight, | |
7925 intern ("coding-category-iso-7-tight")); | |
7926 ASET (Vcoding_category_table, coding_category_iso_8_1, | |
7927 intern ("coding-category-iso-8-1")); | |
7928 ASET (Vcoding_category_table, coding_category_iso_8_2, | |
7929 intern ("coding-category-iso-8-2")); | |
7930 ASET (Vcoding_category_table, coding_category_iso_7_else, | |
7931 intern ("coding-category-iso-7-else")); | |
7932 ASET (Vcoding_category_table, coding_category_iso_8_else, | |
7933 intern ("coding-category-iso-8-else")); | |
7934 ASET (Vcoding_category_table, coding_category_utf_8, | |
7935 intern ("coding-category-utf-8")); | |
7936 ASET (Vcoding_category_table, coding_category_utf_16_be, | |
7937 intern ("coding-category-utf-16-be")); | |
7938 ASET (Vcoding_category_table, coding_category_utf_16_le, | |
7939 intern ("coding-category-utf-16-le")); | |
7940 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, | |
7941 intern ("coding-category-utf-16-be-nosig")); | |
7942 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, | |
7943 intern ("coding-category-utf-16-le-nosig")); | |
7944 ASET (Vcoding_category_table, coding_category_charset, | |
7945 intern ("coding-category-charset")); | |
7946 ASET (Vcoding_category_table, coding_category_sjis, | |
7947 intern ("coding-category-sjis")); | |
7948 ASET (Vcoding_category_table, coding_category_big5, | |
7949 intern ("coding-category-big5")); | |
7950 ASET (Vcoding_category_table, coding_category_ccl, | |
7951 intern ("coding-category-ccl")); | |
7952 ASET (Vcoding_category_table, coding_category_emacs_mule, | |
7953 intern ("coding-category-emacs-mule")); | |
7954 /* Followings are NOT target of code detection. */ | |
7955 ASET (Vcoding_category_table, coding_category_raw_text, | |
7956 intern ("coding-category-raw-text")); | |
7957 ASET (Vcoding_category_table, coding_category_undecided, | |
7958 intern ("coding-category-undecided")); | |
7959 | |
17052 | 7960 defsubr (&Scoding_system_p); |
7961 defsubr (&Sread_coding_system); | |
7962 defsubr (&Sread_non_nil_coding_system); | |
7963 defsubr (&Scheck_coding_system); | |
7964 defsubr (&Sdetect_coding_region); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7965 defsubr (&Sdetect_coding_string); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7966 defsubr (&Sfind_coding_systems_region_internal); |
88365 | 7967 defsubr (&Scheck_coding_systems_region); |
17052 | 7968 defsubr (&Sdecode_coding_region); |
7969 defsubr (&Sencode_coding_region); | |
7970 defsubr (&Sdecode_coding_string); | |
7971 defsubr (&Sencode_coding_string); | |
7972 defsubr (&Sdecode_sjis_char); | |
7973 defsubr (&Sencode_sjis_char); | |
7974 defsubr (&Sdecode_big5_char); | |
7975 defsubr (&Sencode_big5_char); | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7976 defsubr (&Sset_terminal_coding_system_internal); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7977 defsubr (&Sset_safe_terminal_coding_system_internal); |
17052 | 7978 defsubr (&Sterminal_coding_system); |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7979 defsubr (&Sset_keyboard_coding_system_internal); |
17052 | 7980 defsubr (&Skeyboard_coding_system); |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7981 defsubr (&Sfind_operation_coding_system); |
88365 | 7982 defsubr (&Sset_coding_system_priority); |
7983 defsubr (&Sdefine_coding_system_internal); | |
7984 defsubr (&Sdefine_coding_system_alias); | |
7985 defsubr (&Scoding_system_base); | |
7986 defsubr (&Scoding_system_plist); | |
7987 defsubr (&Scoding_system_aliases); | |
7988 defsubr (&Scoding_system_eol_type); | |
7989 defsubr (&Scoding_system_priority_list); | |
17052 | 7990 |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
7991 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
|
7992 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
|
7993 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7994 Do not alter the value of this variable manually. This variable should be |
88365 | 7995 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
|
7996 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
7997 Vcoding_system_list = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
7998 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
7999 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
|
8000 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
|
8001 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
|
8002 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
|
8003 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8004 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
|
8005 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
|
8006 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8007 Vcoding_system_alist = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8008 |
17052 | 8009 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
|
8010 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
|
8011 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8012 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
|
8013 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
|
8014 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
|
8015 system bound to the corresponding coding-category is selected. */); |
17052 | 8016 { |
8017 int i; | |
8018 | |
8019 Vcoding_category_list = Qnil; | |
88365 | 8020 for (i = coding_category_max - 1; i >= 0; i--) |
17052 | 8021 Vcoding_category_list |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8022 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8023 Vcoding_category_list); |
17052 | 8024 } |
8025 | |
8026 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
|
8027 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
|
8028 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
|
8029 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
|
8030 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
|
8031 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
|
8032 `process-coding-system-alist', and `network-coding-system-alist'. */); |
17052 | 8033 Vcoding_system_for_read = Qnil; |
8034 | |
8035 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
|
8036 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
|
8037 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
|
8038 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
|
8039 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
|
8040 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8041 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
|
8042 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
|
8043 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
|
8044 `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
|
8045 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
|
8046 the value of `buffer-file-coding-system' is used. */); |
17052 | 8047 Vcoding_system_for_write = Qnil; |
8048 | |
8049 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
88365 | 8050 doc: /* |
8051 Coding system used in the latest file or process I/O. */); | |
17052 | 8052 Vlast_coding_system_used = Qnil; |
8053 | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8054 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
88365 | 8055 doc: /* |
8056 *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
|
8057 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
|
8058 such conversion. */); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8059 inhibit_eol_conversion = 0; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8060 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8061 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
88365 | 8062 doc: /* |
8063 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
|
8064 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
|
8065 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
|
8066 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
|
8067 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8068 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
88365 | 8069 doc: /* |
8070 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
|
8071 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
|
8072 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
|
8073 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
|
8074 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
|
8075 the file contents. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8076 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
|
8077 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
|
8078 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
|
8079 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
|
8080 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
|
8081 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8082 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
|
8083 and the variable `auto-coding-alist'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8084 Vfile_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8085 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8086 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
88365 | 8087 doc: /* |
8088 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
|
8089 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
|
8090 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
|
8091 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
|
8092 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
|
8093 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
|
8094 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
|
8095 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
|
8096 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
|
8097 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
|
8098 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8099 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8100 Vprocess_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8101 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8102 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
88365 | 8103 doc: /* |
8104 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
|
8105 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
|
8106 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
|
8107 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
|
8108 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
|
8109 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
|
8110 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
|
8111 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
|
8112 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
|
8113 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
|
8114 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
|
8115 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8116 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8117 Vnetwork_coding_system_alist = Qnil; |
17052 | 8118 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8119 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
|
8120 doc: /* Coding system to use with system messages. |
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8121 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
|
8122 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
|
8123 |
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
8124 /* 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
|
8125 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
88365 | 8126 doc: /* |
8127 *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
|
8128 eol_mnemonic_unix = build_string (":"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8129 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8130 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
88365 | 8131 doc: /* |
8132 *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
|
8133 eol_mnemonic_dos = build_string ("\\"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8134 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8135 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
88365 | 8136 doc: /* |
8137 *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
|
8138 eol_mnemonic_mac = build_string ("/"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8139 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8140 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
88365 | 8141 doc: /* |
8142 *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
|
8143 eol_mnemonic_undecided = build_string (":"); |
17052 | 8144 |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8145 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
88365 | 8146 doc: /* |
8147 *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
|
8148 Venable_character_translation = Qt; |
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8149 |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8150 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
|
8151 &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
|
8152 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
|
8153 Vstandard_translation_table_for_decode = Qnil; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8154 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8155 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
|
8156 &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
|
8157 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
|
8158 Vstandard_translation_table_for_encode = Qnil; |
17052 | 8159 |
88365 | 8160 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
|
8161 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
|
8162 While encoding, if a charset (car part of an element) is found, |
88365 | 8163 designate it with the escape sequence identifying revision (cdr part |
8164 of the element). */); | |
8165 Vcharset_revision_table = Qnil; | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8166 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8167 DEFVAR_LISP ("default-process-coding-system", |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8168 &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
|
8169 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
|
8170 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
|
8171 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
|
8172 Vdefault_process_coding_system = Qnil; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8173 |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8174 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
88365 | 8175 doc: /* |
8176 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
|
8177 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
|
8178 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
|
8179 \(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
|
8180 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
|
8181 `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
|
8182 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
|
8183 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
|
8184 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
|
8185 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8186 DEFVAR_LISP ("select-safe-coding-system-function", |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8187 &Vselect_safe_coding_system_function, |
88365 | 8188 doc: /* |
8189 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
|
8190 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8191 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
|
8192 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
|
8193 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
|
8194 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8195 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
|
8196 Vselect_safe_coding_system_function = Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8197 |
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
8198 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8199 &inhibit_iso_escape_detection, |
88365 | 8200 doc: /* |
8201 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
|
8202 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8203 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
|
8204 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
|
8205 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
|
8206 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
|
8207 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
|
8208 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8209 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
|
8210 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
|
8211 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
|
8212 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
|
8213 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
|
8214 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8215 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
|
8216 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
|
8217 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
|
8218 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
|
8219 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
|
8220 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8221 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
|
8222 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
|
8223 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
|
8224 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
|
8225 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8226 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8227 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
|
8228 Lisp_Object plist[14]; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8229 int i; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8230 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8231 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
|
8232 args[i] = Qnil; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8233 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8234 plist[0] = intern (":name"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8235 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
|
8236 plist[2] = intern (":mnemonic"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8237 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
|
8238 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
|
8239 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
|
8240 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
|
8241 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
|
8242 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
|
8243 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
|
8244 plist[10] = intern (":docstring"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8245 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
|
8246 \n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8247 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
|
8248 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
|
8249 character."); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8250 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
|
8251 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
|
8252 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
|
8253 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
|
8254 } |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8255 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8256 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
|
8257 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
|
8258 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
17052 | 8259 } |
8260 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8261 char * |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8262 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
|
8263 int error_number; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8264 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8265 char *str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8266 |
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
8267 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
|
8268 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
|
8269 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8270 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
|
8271 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8272 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
|
8273 Vlocale_coding_system, |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8274 0); |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8275 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
|
8276 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8277 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8278 return str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8279 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8280 |
17052 | 8281 #endif /* emacs */ |