Mercurial > emacs
annotate src/coding.c @ 88606:1db59c97efef
(lisp): Change cyrillic.elc to cyrillic.el,
vietnamese.elc to vietnamese.el. They are not bytecompiled now.
(shortlisp): Likewise.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 23 May 2002 01:02:36 +0000 |
parents | b88195f69856 |
children | 18436bf3d6dd |
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 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4323 /* Here we assume that no charset maps '\r' to something |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4324 else. */ |
88365 | 4325 if (EQ (eol_type, Qdos)) |
4326 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4327 if (src < src_end |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4328 && *src == '\n') |
88365 | 4329 ONE_MORE_BYTE (c); |
4330 } | |
4331 else if (EQ (eol_type, Qmac)) | |
4332 c = '\n'; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4333 } |
88365 | 4334 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4335 { |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4336 Lisp_Object val; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4337 struct charset *charset; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4338 int dim; |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4339 int len = 1; |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4340 unsigned code = c; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4341 |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4342 val = AREF (valids, c); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4343 if (NILP (val)) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4344 goto invalid_code; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4345 if (INTEGERP (val)) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4346 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4347 charset = CHARSET_FROM_ID (XFASTINT (val)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4348 dim = CHARSET_DIMENSION (charset); |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4349 while (len++ < dim) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4350 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4351 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4352 code = (code << 8) | c; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4353 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4354 CODING_DECODE_CHAR (coding, src, src_base, src_end, |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4355 charset, code, c); |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4356 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4357 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4358 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4359 /* VAL is a list of charset IDs. It is assured that the |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4360 list is sorted by charset dimensions (smaller one |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4361 comes first). */ |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4362 while (CONSP (val)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4363 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4364 charset = CHARSET_FROM_ID (XFASTINT (XCAR (val))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4365 dim = CHARSET_DIMENSION (charset); |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4366 while (len++ < dim) |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4367 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4368 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4369 code = (code << 8) | c; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4370 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4371 CODING_DECODE_CHAR (coding, src, src_base, |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4372 src_end, charset, code, c); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4373 if (c >= 0) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4374 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4375 val = XCDR (val); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4376 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4377 } |
88365 | 4378 if (c < 0) |
4379 goto invalid_code; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4380 } |
88365 | 4381 *charbuf++ = c; |
4382 continue; | |
4383 | |
4384 invalid_code: | |
4385 src = src_base; | |
4386 consumed_chars = consumed_chars_base; | |
4387 ONE_MORE_BYTE (c); | |
4388 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
4389 coding->errors++; | |
4390 } | |
4391 | |
4392 no_more_source: | |
4393 coding->consumed_char += consumed_chars_base; | |
4394 coding->consumed = src_base - coding->source; | |
4395 coding->charbuf_used = charbuf - coding->charbuf; | |
4396 } | |
4397 | |
4398 static int | |
4399 encode_coding_charset (coding) | |
4400 struct coding_system *coding; | |
4401 { | |
4402 int multibytep = coding->dst_multibyte; | |
4403 int *charbuf = coding->charbuf; | |
4404 int *charbuf_end = charbuf + coding->charbuf_used; | |
4405 unsigned char *dst = coding->destination + coding->produced; | |
4406 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4407 int safe_room = MAX_MULTIBYTE_LENGTH; | |
4408 int produced_chars = 0; | |
4409 Lisp_Object attrs, eol_type, charset_list; | |
4410 int ascii_compatible; | |
4411 int c; | |
4412 | |
4413 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4414 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4415 | |
4416 while (charbuf < charbuf_end) | |
4417 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4418 struct charset *charset; |
88365 | 4419 unsigned code; |
4420 | |
4421 ASSURE_DESTINATION (safe_room); | |
4422 c = *charbuf++; | |
4423 if (ascii_compatible && ASCII_CHAR_P (c)) | |
4424 EMIT_ONE_ASCII_BYTE (c); | |
4425 else | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4426 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4427 charset = char_charset (c, charset_list, &code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4428 if (charset) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4429 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4430 if (CHARSET_DIMENSION (charset) == 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4431 EMIT_ONE_BYTE (code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4432 else if (CHARSET_DIMENSION (charset) == 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4433 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4434 else if (CHARSET_DIMENSION (charset) == 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4435 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
|
4436 else |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4437 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
|
4438 (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4439 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4440 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4441 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4442 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
|
4443 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4444 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4445 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4446 EMIT_ONE_BYTE (c); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4447 } |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4448 } |
88365 | 4449 } |
4450 | |
4451 coding->result = CODING_RESULT_SUCCESS; | |
4452 coding->produced_char += produced_chars; | |
4453 coding->produced = dst - coding->destination; | |
4454 return 0; | |
17052 | 4455 } |
4456 | |
4457 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4458 /*** 7. C library functions ***/ |
17052 | 4459 |
88365 | 4460 /* In Emacs Lisp, coding system is represented by a Lisp symbol which |
17052 | 4461 has a property `coding-system'. The value of this property is a |
88365 | 4462 vector of length 5 (called as coding-vector). Among elements of |
17052 | 4463 this vector, the first (element[0]) and the fifth (element[4]) |
4464 carry important information for decoding/encoding. Before | |
4465 decoding/encoding, this information should be set in fields of a | |
4466 structure of type `coding_system'. | |
4467 | |
88365 | 4468 A value of property `coding-system' can be a symbol of another |
17052 | 4469 subsidiary coding-system. In that case, Emacs gets coding-vector |
4470 from that symbol. | |
4471 | |
4472 `element[0]' contains information to be set in `coding->type'. The | |
4473 value and its meaning is as follows: | |
4474 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4475 0 -- coding_type_emacs_mule |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4476 1 -- coding_type_sjis |
88365 | 4477 2 -- coding_type_iso_2022 |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4478 3 -- coding_type_big5 |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4479 4 -- coding_type_ccl encoder/decoder written in CCL |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4480 nil -- coding_type_no_conversion |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4481 t -- coding_type_undecided (automatic conversion on decoding, |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4482 no-conversion on encoding) |
17052 | 4483 |
4484 `element[4]' contains information to be set in `coding->flags' and | |
4485 `coding->spec'. The meaning varies by `coding->type'. | |
4486 | |
88365 | 4487 If `coding->type' is `coding_type_iso_2022', element[4] is a vector |
17052 | 4488 of length 32 (of which the first 13 sub-elements are used now). |
4489 Meanings of these sub-elements are: | |
4490 | |
88365 | 4491 sub-element[N] where N is 0 through 3: to be set in `coding->spec.iso_2022' |
17052 | 4492 If the value is an integer of valid charset, the charset is |
4493 assumed to be designated to graphic register N initially. | |
4494 | |
4495 If the value is minus, it is a minus value of charset which | |
4496 reserves graphic register N, which means that the charset is | |
4497 not designated initially but should be designated to graphic | |
4498 register N just before encoding a character in that charset. | |
4499 | |
4500 If the value is nil, graphic register N is never used on | |
4501 encoding. | |
88365 | 4502 |
17052 | 4503 sub-element[N] where N is 4 through 11: to be set in `coding->flags' |
4504 Each value takes t or nil. See the section ISO2022 of | |
4505 `coding.h' for more information. | |
4506 | |
4507 If `coding->type' is `coding_type_big5', element[4] is t to denote | |
4508 BIG5-ETen or nil to denote BIG5-HKU. | |
4509 | |
4510 If `coding->type' takes the other value, element[4] is ignored. | |
4511 | |
88365 | 4512 Emacs Lisp's coding system also carries information about format of |
17052 | 4513 end-of-line in a value of property `eol-type'. If the value is |
88365 | 4514 integer, 0 means eol_lf, 1 means eol_crlf, and 2 means eol_cr. If |
4515 it is not integer, it should be a vector of subsidiary coding | |
4516 systems of which property `eol-type' has one of above values. | |
17052 | 4517 |
4518 */ | |
4519 | |
88365 | 4520 /* Setup coding context CODING from information about CODING_SYSTEM. |
4521 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
4522 CODING_SYSTEM is invalid, signal an error. */ | |
4523 | |
4524 void | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4525 setup_coding_system (coding_system, coding) |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4526 Lisp_Object coding_system; |
17052 | 4527 struct coding_system *coding; |
4528 { | |
88365 | 4529 Lisp_Object attrs; |
4530 Lisp_Object eol_type; | |
4531 Lisp_Object coding_type; | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
4532 Lisp_Object val; |
17052 | 4533 |
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
4534 if (NILP (coding_system)) |
88365 | 4535 coding_system = Qno_conversion; |
4536 | |
4537 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
4538 | |
4539 attrs = CODING_ID_ATTRS (coding->id); | |
4540 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4541 | |
4542 coding->mode = 0; | |
4543 coding->head_ascii = -1; | |
4544 coding->common_flags | |
4545 = (VECTORP (eol_type) ? CODING_REQUIRE_DETECTION_MASK : 0); | |
4546 | |
4547 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4548 coding->max_charset_id = XSTRING (val)->size - 1; | |
4549 coding->safe_charsets = (char *) XSTRING (val)->data; | |
4550 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); | |
4551 | |
4552 coding_type = CODING_ATTR_TYPE (attrs); | |
4553 if (EQ (coding_type, Qundecided)) | |
4554 { | |
4555 coding->detector = NULL; | |
4556 coding->decoder = decode_coding_raw_text; | |
4557 coding->encoder = encode_coding_raw_text; | |
4558 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
4559 } | |
4560 else if (EQ (coding_type, Qiso_2022)) | |
4561 { | |
4562 int i; | |
4563 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
4564 | |
4565 /* Invoke graphic register 0 to plane 0. */ | |
4566 CODING_ISO_INVOCATION (coding, 0) = 0; | |
4567 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
4568 CODING_ISO_INVOCATION (coding, 1) | |
4569 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
4570 /* Setup the initial status of designation. */ | |
4571 for (i = 0; i < 4; i++) | |
4572 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
4573 /* Not single shifting initially. */ | |
4574 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
4575 /* Beginning of buffer should also be regarded as bol. */ | |
4576 CODING_ISO_BOL (coding) = 1; | |
4577 coding->detector = detect_coding_iso_2022; | |
4578 coding->decoder = decode_coding_iso_2022; | |
4579 coding->encoder = encode_coding_iso_2022; | |
4580 if (flags & CODING_ISO_FLAG_SAFE) | |
4581 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4582 coding->common_flags |
88365 | 4583 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4584 | CODING_REQUIRE_FLUSHING_MASK); | |
4585 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
4586 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
4587 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
|
4588 { |
88365 | 4589 setup_iso_safe_charsets (attrs); |
4590 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4591 coding->max_charset_id = XSTRING (val)->size - 1; | |
4592 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
|
4593 } |
88365 | 4594 CODING_ISO_FLAGS (coding) = flags; |
4595 } | |
4596 else if (EQ (coding_type, Qcharset)) | |
4597 { | |
4598 coding->detector = detect_coding_charset; | |
4599 coding->decoder = decode_coding_charset; | |
4600 coding->encoder = encode_coding_charset; | |
4601 coding->common_flags | |
4602 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4603 } | |
4604 else if (EQ (coding_type, Qutf_8)) | |
4605 { | |
4606 coding->detector = detect_coding_utf_8; | |
4607 coding->decoder = decode_coding_utf_8; | |
4608 coding->encoder = encode_coding_utf_8; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
4609 coding->common_flags |
88365 | 4610 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4611 } | |
4612 else if (EQ (coding_type, Qutf_16)) | |
4613 { | |
4614 val = AREF (attrs, coding_attr_utf_16_bom); | |
4615 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_16_detect_bom | |
4616 : EQ (val, Qt) ? utf_16_with_bom | |
4617 : utf_16_without_bom); | |
4618 val = AREF (attrs, coding_attr_utf_16_endian); | |
4619 CODING_UTF_16_ENDIAN (coding) = (NILP (val) ? utf_16_big_endian | |
4620 : utf_16_little_endian); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
4621 CODING_UTF_16_SURROGATE (coding) = 0; |
88365 | 4622 coding->detector = detect_coding_utf_16; |
4623 coding->decoder = decode_coding_utf_16; | |
4624 coding->encoder = encode_coding_utf_16; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4625 coding->common_flags |
88365 | 4626 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4627 } | |
4628 else if (EQ (coding_type, Qccl)) | |
4629 { | |
4630 coding->detector = detect_coding_ccl; | |
4631 coding->decoder = decode_coding_ccl; | |
4632 coding->encoder = encode_coding_ccl; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4633 coding->common_flags |
88365 | 4634 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4635 | CODING_REQUIRE_FLUSHING_MASK); | |
4636 } | |
4637 else if (EQ (coding_type, Qemacs_mule)) | |
4638 { | |
4639 coding->detector = detect_coding_emacs_mule; | |
4640 coding->decoder = decode_coding_emacs_mule; | |
4641 coding->encoder = encode_coding_emacs_mule; | |
4642 coding->common_flags | |
4643 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4644 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) | |
4645 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
4646 { | |
4647 Lisp_Object tail, safe_charsets; | |
4648 int max_charset_id = 0; | |
4649 | |
4650 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4651 tail = XCDR (tail)) | |
4652 if (max_charset_id < XFASTINT (XCAR (tail))) | |
4653 max_charset_id = XFASTINT (XCAR (tail)); | |
4654 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
4655 make_number (255)); | |
4656 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4657 tail = XCDR (tail)) | |
4658 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
4659 coding->max_charset_id = max_charset_id; | |
4660 coding->safe_charsets = (char *) XSTRING (safe_charsets)->data; | |
4661 } | |
4662 } | |
4663 else if (EQ (coding_type, Qshift_jis)) | |
4664 { | |
4665 coding->detector = detect_coding_sjis; | |
4666 coding->decoder = decode_coding_sjis; | |
4667 coding->encoder = encode_coding_sjis; | |
4668 coding->common_flags | |
4669 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4670 } | |
4671 else if (EQ (coding_type, Qbig5)) | |
4672 { | |
4673 coding->detector = detect_coding_big5; | |
4674 coding->decoder = decode_coding_big5; | |
4675 coding->encoder = encode_coding_big5; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4676 coding->common_flags |
88365 | 4677 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4678 } | |
4679 else /* EQ (coding_type, Qraw_text) */ | |
4680 { | |
4681 coding->detector = NULL; | |
4682 coding->decoder = decode_coding_raw_text; | |
4683 coding->encoder = encode_coding_raw_text; | |
4684 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
4685 } | |
4686 | |
4687 return; | |
17052 | 4688 } |
4689 | |
88365 | 4690 /* Return raw-text or one of its subsidiaries that has the same |
4691 eol_type as CODING-SYSTEM. */ | |
4692 | |
4693 Lisp_Object | |
4694 raw_text_coding_system (coding_system) | |
4695 Lisp_Object coding_system; | |
26847 | 4696 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4697 Lisp_Object spec, attrs; |
88365 | 4698 Lisp_Object eol_type, raw_text_eol_type; |
4699 | |
4700 spec = CODING_SYSTEM_SPEC (coding_system); | |
4701 attrs = AREF (spec, 0); | |
4702 | |
4703 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
4704 return coding_system; | |
4705 | |
4706 eol_type = AREF (spec, 2); | |
4707 if (VECTORP (eol_type)) | |
4708 return Qraw_text; | |
4709 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
4710 raw_text_eol_type = AREF (spec, 2); | |
4711 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
4712 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
4713 : AREF (raw_text_eol_type, 2)); | |
26847 | 4714 } |
4715 | |
88365 | 4716 |
4717 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
4718 does, return one of the subsidiary that has the same eol-spec as | |
4719 PARENT. Otherwise, return CODING_SYSTEM. */ | |
4720 | |
4721 Lisp_Object | |
4722 coding_inherit_eol_type (coding_system, parent) | |
88473 | 4723 Lisp_Object coding_system, parent; |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4724 { |
88365 | 4725 Lisp_Object spec, attrs, eol_type; |
4726 | |
4727 spec = CODING_SYSTEM_SPEC (coding_system); | |
4728 attrs = AREF (spec, 0); | |
4729 eol_type = AREF (spec, 2); | |
4730 if (VECTORP (eol_type)) | |
4731 { | |
4732 Lisp_Object parent_spec; | |
4733 Lisp_Object parent_eol_type; | |
4734 | |
4735 parent_spec | |
4736 = CODING_SYSTEM_SPEC (buffer_defaults.buffer_file_coding_system); | |
4737 parent_eol_type = AREF (parent_spec, 2); | |
4738 if (EQ (parent_eol_type, Qunix)) | |
4739 coding_system = AREF (eol_type, 0); | |
4740 else if (EQ (parent_eol_type, Qdos)) | |
4741 coding_system = AREF (eol_type, 1); | |
4742 else if (EQ (parent_eol_type, Qmac)) | |
4743 coding_system = AREF (eol_type, 2); | |
4744 } | |
4745 return coding_system; | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4746 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4747 |
17052 | 4748 /* Emacs has a mechanism to automatically detect a coding system if it |
4749 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
4750 it's impossible to distinguish some coding systems accurately | |
4751 because they use the same range of codes. So, at first, coding | |
4752 systems are categorized into 7, those are: | |
4753 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4754 o coding-category-emacs-mule |
17052 | 4755 |
4756 The category for a coding system which has the same code range | |
4757 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
|
4758 symbol) `emacs-mule' by default. |
17052 | 4759 |
4760 o coding-category-sjis | |
4761 | |
4762 The category for a coding system which has the same code range | |
4763 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
|
4764 symbol) `japanese-shift-jis' by default. |
17052 | 4765 |
4766 o coding-category-iso-7 | |
4767 | |
4768 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
|
4769 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
|
4770 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
|
4771 charsets. Assigned the coding-system (Lisp symbol) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4772 `iso-2022-7bit' by default. |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4773 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4774 o coding-category-iso-7-tight |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4775 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4776 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
|
4777 encode/decode only the specified charsets. |
17052 | 4778 |
4779 o coding-category-iso-8-1 | |
4780 | |
4781 The category for a coding system which has the same code range | |
4782 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
|
4783 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
|
4784 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
|
4785 symbol) `iso-latin-1' by default. |
17052 | 4786 |
4787 o coding-category-iso-8-2 | |
4788 | |
4789 The category for a coding system which has the same code range | |
4790 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
|
4791 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
|
4792 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
|
4793 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
|
4794 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4795 o coding-category-iso-7-else |
17052 | 4796 |
4797 The category for a coding system which has the same code range | |
88365 | 4798 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
|
4799 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
|
4800 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
|
4801 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4802 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
|
4803 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4804 The category for a coding system which has the same code range |
88365 | 4805 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
|
4806 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
|
4807 symbol) `iso-2022-8bit-ss2' by default. |
17052 | 4808 |
4809 o coding-category-big5 | |
4810 | |
4811 The category for a coding system which has the same code range | |
4812 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
|
4813 `cn-big5' by default. |
17052 | 4814 |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4815 o coding-category-utf-8 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4816 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4817 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
|
4818 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
|
4819 symbol) `utf-8' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4820 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4821 o coding-category-utf-16-be |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4822 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4823 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
|
4824 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
|
4825 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
|
4826 `utf-16-be' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4827 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4828 o coding-category-utf-16-le |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4829 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4830 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
|
4831 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
|
4832 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
|
4833 symbol) `utf-16-le' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4834 |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4835 o coding-category-ccl |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4836 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4837 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
|
4838 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
|
4839 coding system is assigned. |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4840 |
17052 | 4841 o coding-category-binary |
4842 | |
4843 The category for a coding system not categorized in any of the | |
4844 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
|
4845 `no-conversion' by default. |
17052 | 4846 |
4847 Each of them is a Lisp symbol and the value is an actual | |
88365 | 4848 `coding-system's (this is also a Lisp symbol) assigned by a user. |
17052 | 4849 What Emacs does actually is to detect a category of coding system. |
4850 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
88365 | 4851 decide only one possible category, it selects a category of the |
17052 | 4852 highest priority. Priorities of categories are also specified by a |
4853 user in a Lisp variable `coding-category-list'. | |
4854 | |
4855 */ | |
4856 | |
88365 | 4857 #define EOL_SEEN_NONE 0 |
4858 #define EOL_SEEN_LF 1 | |
4859 #define EOL_SEEN_CR 2 | |
4860 #define EOL_SEEN_CRLF 4 | |
4861 | |
4862 /* Detect how end-of-line of a text of length CODING->src_bytes | |
4863 pointed by CODING->source is encoded. Return one of | |
4864 EOL_SEEN_XXX. */ | |
17052 | 4865 |
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
4866 #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
|
4867 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4868 static int |
88365 | 4869 detect_eol (coding, source, src_bytes) |
4870 struct coding_system *coding; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4871 unsigned char *source; |
88365 | 4872 EMACS_INT src_bytes; |
17052 | 4873 { |
88365 | 4874 Lisp_Object attrs, coding_type; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4875 unsigned char *src = source, *src_end = src + src_bytes; |
17052 | 4876 unsigned char c; |
88365 | 4877 int total = 0; |
4878 int eol_seen = EOL_SEEN_NONE; | |
4879 | |
4880 attrs = CODING_ID_ATTRS (coding->id); | |
4881 coding_type = CODING_ATTR_TYPE (attrs); | |
4882 | |
4883 if (EQ (coding_type, Qccl)) | |
4884 { | |
4885 int msb, lsb; | |
4886 | |
4887 msb = coding->spec.utf_16.endian == utf_16_little_endian; | |
4888 lsb = 1 - msb; | |
4889 | |
4890 while (src + 1 < src_end) | |
17052 | 4891 { |
88365 | 4892 c = src[lsb]; |
4893 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
|
4894 { |
88365 | 4895 int this_eol; |
4896 | |
4897 if (c == '\n') | |
4898 this_eol = EOL_SEEN_LF; | |
4899 else if (src + 3 >= src_end | |
4900 || src[msb + 2] != 0 | |
4901 || src[lsb + 2] != '\n') | |
4902 this_eol = EOL_SEEN_CR; | |
4903 else | |
4904 this_eol = EOL_SEEN_CRLF; | |
4905 | |
4906 if (eol_seen == EOL_SEEN_NONE) | |
4907 /* This is the first end-of-line. */ | |
4908 eol_seen = this_eol; | |
4909 else if (eol_seen != this_eol) | |
4910 { | |
4911 /* The found type is different from what found before. */ | |
4912 eol_seen = EOL_SEEN_LF; | |
4913 break; | |
4914 } | |
4915 if (++total == MAX_EOL_CHECK_COUNT) | |
4916 break; | |
4917 } | |
4918 src += 2; | |
4919 } | |
4920 } | |
4921 else | |
4922 { | |
4923 while (src < src_end) | |
4924 { | |
4925 c = *src++; | |
4926 if (c == '\n' || c == '\r') | |
4927 { | |
4928 int this_eol; | |
4929 | |
4930 if (c == '\n') | |
4931 this_eol = EOL_SEEN_LF; | |
4932 else if (src >= src_end || *src != '\n') | |
4933 this_eol = EOL_SEEN_CR; | |
4934 else | |
4935 this_eol = EOL_SEEN_CRLF, src++; | |
4936 | |
4937 if (eol_seen == EOL_SEEN_NONE) | |
4938 /* This is the first end-of-line. */ | |
4939 eol_seen = this_eol; | |
4940 else if (eol_seen != this_eol) | |
4941 { | |
4942 /* The found type is different from what found before. */ | |
4943 eol_seen = EOL_SEEN_LF; | |
4944 break; | |
4945 } | |
4946 if (++total == MAX_EOL_CHECK_COUNT) | |
4947 break; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4948 } |
17052 | 4949 } |
4950 } | |
88365 | 4951 return eol_seen; |
17052 | 4952 } |
4953 | |
88365 | 4954 |
4955 static void | |
4956 adjust_coding_eol_type (coding, eol_seen) | |
4957 struct coding_system *coding; | |
4958 int eol_seen; | |
4959 { | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4960 Lisp_Object eol_type; |
88365 | 4961 |
4962 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4963 if (eol_seen & EOL_SEEN_LF) | |
4964 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); | |
4965 else if (eol_type & EOL_SEEN_CRLF) | |
4966 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); | |
4967 else if (eol_type & EOL_SEEN_CR) | |
4968 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); | |
4969 } | |
4970 | |
4971 /* Detect how a text specified in CODING is encoded. If a coding | |
4972 system is detected, update fields of CODING by the detected coding | |
4973 system. */ | |
4974 | |
4975 void | |
4976 detect_coding (coding) | |
4977 struct coding_system *coding; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4978 { |
88365 | 4979 unsigned char *src, *src_end; |
4980 Lisp_Object attrs, coding_type; | |
4981 | |
4982 coding->consumed = coding->consumed_char = 0; | |
4983 coding->produced = coding->produced_char = 0; | |
4984 coding_set_source (coding); | |
4985 | |
4986 src_end = coding->source + coding->src_bytes; | |
4987 | |
4988 /* If we have not yet decided the text encoding type, detect it | |
4989 now. */ | |
4990 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
4991 { | |
4992 int mask = CATEGORY_MASK_ANY; | |
4993 int c, i; | |
4994 | |
4995 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
|
4996 { |
88365 | 4997 c = *src; |
4998 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
4999 || c == ISO_CODE_SI | |
5000 || c == ISO_CODE_SO))) | |
5001 break; | |
5002 } | |
5003 coding->head_ascii = src - (coding->source + coding->consumed); | |
5004 | |
5005 if (coding->head_ascii < coding->src_bytes) | |
5006 { | |
5007 int detected = 0; | |
5008 | |
5009 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
|
5010 { |
88365 | 5011 enum coding_category category = coding_priorities[i]; |
5012 struct coding_system *this = coding_categories + category; | |
5013 | |
5014 if (category >= coding_category_raw_text | |
5015 || detected & (1 << category)) | |
5016 continue; | |
5017 | |
5018 if (this->id < 0) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5019 { |
88365 | 5020 /* No coding system of this category is defined. */ |
5021 mask &= ~(1 << category); | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5022 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5023 else |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5024 { |
88365 | 5025 detected |= detected_mask[category]; |
5026 if ((*(this->detector)) (coding, &mask)) | |
5027 break; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5028 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5029 } |
88365 | 5030 if (! mask) |
5031 setup_coding_system (Qraw_text, coding); | |
5032 else if (mask != CATEGORY_MASK_ANY) | |
5033 for (i = 0; i < coding_category_raw_text; i++) | |
5034 { | |
5035 enum coding_category category = coding_priorities[i]; | |
5036 struct coding_system *this = coding_categories + category; | |
5037 | |
5038 if (mask & (1 << category)) | |
5039 { | |
5040 setup_coding_system (CODING_ID_NAME (this->id), coding); | |
5041 break; | |
5042 } | |
5043 } | |
5044 } | |
5045 } | |
5046 | |
5047 attrs = CODING_ID_ATTRS (coding->id); | |
5048 coding_type = CODING_ATTR_TYPE (attrs); | |
5049 | |
5050 /* If we have not yet decided the EOL type, detect it now. But, the | |
5051 detection is impossible for a CCL based coding system, in which | |
5052 case, we detct the EOL type after decoding. */ | |
5053 if (VECTORP (CODING_ID_EOL_TYPE (coding->id)) | |
5054 && ! EQ (coding_type, Qccl)) | |
5055 { | |
5056 int eol_seen = detect_eol (coding, coding->source, coding->src_bytes); | |
5057 | |
5058 if (eol_seen != EOL_SEEN_NONE) | |
5059 adjust_coding_eol_type (coding, eol_seen); | |
5060 } | |
5061 } | |
5062 | |
5063 | |
5064 static void | |
5065 decode_eol (coding) | |
5066 struct coding_system *coding; | |
5067 { | |
5068 if (VECTORP (CODING_ID_EOL_TYPE (coding->id))) | |
5069 { | |
5070 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5071 unsigned char *pend = p + coding->produced; | |
5072 int eol_seen = EOL_SEEN_NONE; | |
5073 | |
5074 for (; p < pend; p++) | |
5075 { | |
5076 if (*p == '\n') | |
5077 eol_seen |= EOL_SEEN_LF; | |
5078 else if (*p == '\r') | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5079 { |
88365 | 5080 if (p + 1 < pend && *(p + 1) == '\n') |
5081 { | |
5082 eol_seen |= EOL_SEEN_CRLF; | |
5083 p++; | |
5084 } | |
5085 else | |
5086 eol_seen |= EOL_SEEN_CR; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5087 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5088 } |
88365 | 5089 if (eol_seen != EOL_SEEN_NONE) |
5090 adjust_coding_eol_type (coding, eol_seen); | |
5091 } | |
5092 | |
5093 if (EQ (CODING_ID_EOL_TYPE (coding->id), Qmac)) | |
5094 { | |
5095 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5096 unsigned char *pend = p + coding->produced; | |
5097 | |
5098 for (; p < pend; p++) | |
5099 if (*p == '\r') | |
5100 *p = '\n'; | |
5101 } | |
5102 else if (EQ (CODING_ID_EOL_TYPE (coding->id), Qdos)) | |
5103 { | |
5104 unsigned char *p, *pbeg, *pend; | |
5105 Lisp_Object undo_list; | |
5106 | |
5107 move_gap_both (coding->dst_pos + coding->produced_char, | |
5108 coding->dst_pos_byte + coding->produced); | |
5109 undo_list = current_buffer->undo_list; | |
5110 current_buffer->undo_list = Qt; | |
5111 del_range_2 (coding->dst_pos, coding->dst_pos_byte, GPT, GPT_BYTE, Qnil); | |
5112 current_buffer->undo_list = undo_list; | |
5113 pbeg = GPT_ADDR; | |
5114 pend = pbeg + coding->produced; | |
5115 | |
5116 for (p = pend - 1; p >= pbeg; p--) | |
5117 if (*p == '\r') | |
5118 { | |
5119 safe_bcopy ((char *) (p + 1), (char *) p, pend - p - 1); | |
5120 pend--; | |
5121 } | |
5122 coding->produced_char -= coding->produced - (pend - pbeg); | |
5123 coding->produced = pend - pbeg; | |
5124 insert_from_gap (coding->produced_char, coding->produced); | |
17052 | 5125 } |
5126 } | |
5127 | |
88365 | 5128 static void |
5129 translate_chars (coding, table) | |
17052 | 5130 struct coding_system *coding; |
88365 | 5131 Lisp_Object table; |
17052 | 5132 { |
88365 | 5133 int *charbuf = coding->charbuf; |
5134 int *charbuf_end = charbuf + coding->charbuf_used; | |
5135 int c; | |
5136 | |
5137 if (coding->chars_at_source) | |
5138 return; | |
5139 | |
5140 while (charbuf < charbuf_end) | |
5141 { | |
5142 c = *charbuf; | |
5143 if (c < 0) | |
5144 charbuf += c; | |
5145 else | |
5146 *charbuf++ = translate_char (table, c); | |
5147 } | |
17052 | 5148 } |
5149 | |
88365 | 5150 static int |
5151 produce_chars (coding) | |
5152 struct coding_system *coding; | |
17052 | 5153 { |
88365 | 5154 unsigned char *dst = coding->destination + coding->produced; |
5155 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5156 int produced; | |
5157 int produced_chars = 0; | |
5158 | |
5159 if (! coding->chars_at_source) | |
5160 { | |
5161 /* Characters are in coding->charbuf. */ | |
5162 int *buf = coding->charbuf; | |
5163 int *buf_end = buf + coding->charbuf_used; | |
5164 unsigned char *adjusted_dst_end; | |
5165 | |
5166 if (BUFFERP (coding->src_object) | |
5167 && EQ (coding->src_object, coding->dst_object)) | |
5168 dst_end = coding->source + coding->consumed; | |
5169 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5170 | |
5171 while (buf < buf_end) | |
5172 { | |
5173 int c = *buf++; | |
5174 | |
5175 if (dst >= adjusted_dst_end) | |
5176 { | |
5177 dst = alloc_destination (coding, | |
5178 buf_end - buf + MAX_MULTIBYTE_LENGTH, | |
5179 dst); | |
5180 dst_end = coding->destination + coding->dst_bytes; | |
5181 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5182 } | |
5183 if (c >= 0) | |
5184 { | |
5185 if (coding->dst_multibyte | |
5186 || ! CHAR_BYTE8_P (c)) | |
5187 CHAR_STRING_ADVANCE (c, dst); | |
5188 else | |
5189 *dst++ = CHAR_TO_BYTE8 (c); | |
5190 produced_chars++; | |
5191 } | |
5192 else | |
5193 /* This is an annotation data. */ | |
5194 buf -= c + 1; | |
5195 } | |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5196 } |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5197 else |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5198 { |
88365 | 5199 unsigned char *src = coding->source; |
5200 unsigned char *src_end = src + coding->src_bytes; | |
5201 Lisp_Object eol_type; | |
5202 | |
5203 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5204 | |
5205 if (coding->src_multibyte != coding->dst_multibyte) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5206 { |
88365 | 5207 if (coding->src_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5208 { |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5209 int multibytep = 1; |
88365 | 5210 int consumed_chars; |
5211 | |
5212 while (1) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5213 { |
88365 | 5214 unsigned char *src_base = src; |
5215 int c; | |
5216 | |
5217 ONE_MORE_BYTE (c); | |
5218 if (c == '\r') | |
5219 { | |
5220 if (EQ (eol_type, Qdos)) | |
5221 { | |
5222 if (src < src_end | |
5223 && *src == '\n') | |
5224 c = *src++; | |
5225 } | |
5226 else if (EQ (eol_type, Qmac)) | |
5227 c = '\n'; | |
5228 } | |
5229 if (dst == dst_end) | |
5230 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5231 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
|
5232 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5233 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
|
5234 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5235 if (dst == dst_end) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5236 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5237 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
|
5238 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5239 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
|
5240 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5241 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
|
5242 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
|
5243 } |
88365 | 5244 } |
5245 *dst++ = c; | |
5246 produced_chars++; | |
5247 } | |
5248 no_more_source: | |
5249 ; | |
5250 } | |
5251 else | |
5252 while (src < src_end) | |
5253 { | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5254 int multibytep = 1; |
88365 | 5255 int c = *src++; |
5256 | |
5257 if (c == '\r') | |
5258 { | |
5259 if (EQ (eol_type, Qdos)) | |
5260 { | |
5261 if (src < src_end | |
5262 && *src == '\n') | |
5263 c = *src++; | |
5264 } | |
5265 else if (EQ (eol_type, Qmac)) | |
5266 c = '\n'; | |
5267 } | |
5268 if (dst >= dst_end - 1) | |
5269 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5270 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
|
5271 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5272 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
|
5273 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5274 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
|
5275 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5276 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
|
5277 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5278 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
|
5279 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5280 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
|
5281 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
|
5282 } |
88365 | 5283 } |
5284 EMIT_ONE_BYTE (c); | |
5285 } | |
5286 } | |
5287 else | |
5288 { | |
5289 if (!EQ (coding->src_object, coding->dst_object)) | |
5290 { | |
5291 int require = coding->src_bytes - coding->dst_bytes; | |
5292 | |
5293 if (require > 0) | |
5294 { | |
5295 EMACS_INT offset = src - coding->source; | |
5296 | |
5297 dst = alloc_destination (coding, require, dst); | |
5298 coding_set_source (coding); | |
5299 src = coding->source + offset; | |
5300 src_end = coding->source + coding->src_bytes; | |
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 } |
88365 | 5303 produced_chars = coding->src_chars; |
5304 while (src < src_end) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5305 { |
88365 | 5306 int c = *src++; |
5307 | |
5308 if (c == '\r') | |
5309 { | |
5310 if (EQ (eol_type, Qdos)) | |
5311 { | |
5312 if (src < src_end | |
5313 && *src == '\n') | |
5314 c = *src++; | |
5315 produced_chars--; | |
5316 } | |
5317 else if (EQ (eol_type, Qmac)) | |
5318 c = '\n'; | |
5319 } | |
5320 *dst++ = c; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5321 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5322 } |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5323 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
|
5324 coding->consumed_char = coding->src_chars; |
88365 | 5325 } |
5326 | |
5327 produced = dst - (coding->destination + coding->produced); | |
5328 if (BUFFERP (coding->dst_object)) | |
5329 insert_from_gap (produced_chars, produced); | |
5330 coding->produced += produced; | |
5331 coding->produced_char += produced_chars; | |
5332 return produced_chars; | |
5333 } | |
5334 | |
5335 /* [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN ] | |
5336 or | |
5337 [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN COMPONENTS... ] | |
5338 */ | |
5339 | |
5340 static INLINE void | |
5341 produce_composition (coding, charbuf) | |
5342 struct coding_system *coding; | |
5343 int *charbuf; | |
5344 { | |
5345 Lisp_Object buffer; | |
5346 int len; | |
5347 EMACS_INT pos; | |
5348 enum composition_method method; | |
5349 int cmp_len; | |
5350 Lisp_Object components; | |
5351 | |
5352 buffer = coding->dst_object; | |
5353 len = -charbuf[0]; | |
5354 pos = coding->dst_pos + charbuf[1]; | |
5355 method = (enum composition_method) (charbuf[3]); | |
5356 cmp_len = charbuf[4]; | |
5357 | |
5358 if (method == COMPOSITION_RELATIVE) | |
5359 components = Qnil; | |
5360 else | |
5361 { | |
5362 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
5363 int i; | |
5364 | |
5365 len -= 5; | |
5366 charbuf += 5; | |
5367 for (i = 0; i < len; i++) | |
5368 args[i] = make_number (charbuf[i]); | |
5369 components = (method == COMPOSITION_WITH_ALTCHARS | |
5370 ? Fstring (len, args) : Fvector (len, args)); | |
5371 } | |
5372 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
|
5373 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5374 |
88365 | 5375 static int * |
5376 save_composition_data (buf, buf_end, prop) | |
5377 int *buf, *buf_end; | |
5378 Lisp_Object prop; | |
5379 { | |
5380 enum composition_method method = COMPOSITION_METHOD (prop); | |
5381 int cmp_len = COMPOSITION_LENGTH (prop); | |
5382 | |
5383 if (buf + 4 + (MAX_COMPOSITION_COMPONENTS * 2 - 1) > buf_end) | |
5384 return NULL; | |
5385 | |
5386 buf[1] = CODING_ANNOTATE_COMPOSITION_MASK; | |
5387 buf[2] = method; | |
5388 buf[3] = cmp_len; | |
5389 | |
5390 if (method == COMPOSITION_RELATIVE) | |
5391 buf[0] = 4; | |
5392 else | |
5393 { | |
5394 Lisp_Object components; | |
5395 int len, i; | |
5396 | |
5397 components = COMPOSITION_COMPONENTS (prop); | |
5398 if (VECTORP (components)) | |
5399 { | |
5400 len = XVECTOR (components)->size; | |
5401 for (i = 0; i < len; i++) | |
5402 buf[4 + i] = XINT (AREF (components, i)); | |
5403 } | |
5404 else if (STRINGP (components)) | |
5405 { | |
5406 int i_byte; | |
5407 | |
5408 len = XSTRING (components)->size; | |
5409 i = i_byte = 0; | |
5410 while (i < len) | |
5411 FETCH_STRING_CHAR_ADVANCE (buf[4 + i], components, i, i_byte); | |
5412 } | |
5413 else if (INTEGERP (components)) | |
5414 { | |
5415 len = 1; | |
5416 buf[4] = XINT (components); | |
5417 } | |
5418 else if (CONSP (components)) | |
5419 { | |
5420 for (len = 0; CONSP (components); | |
5421 len++, components = XCDR (components)) | |
5422 buf[4 + len] = XINT (XCAR (components)); | |
5423 } | |
5424 else | |
5425 abort (); | |
5426 buf[0] = 4 + len; | |
5427 } | |
5428 return (buf + buf[0]); | |
5429 } | |
5430 | |
5431 #define CHARBUF_SIZE 0x4000 | |
5432 | |
5433 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
5434 do { \ | |
5435 int size = CHARBUF_SIZE;; \ | |
5436 \ | |
5437 coding->charbuf = NULL; \ | |
5438 while (size > 1024) \ | |
5439 { \ | |
5440 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
5441 if (coding->charbuf) \ | |
5442 break; \ | |
5443 size >>= 1; \ | |
5444 } \ | |
5445 if (! coding->charbuf) \ | |
5446 { \ | |
5447 coding->result = CODING_RESULT_INSUFFICIENT_MEM; \ | |
5448 return coding->result; \ | |
5449 } \ | |
5450 coding->charbuf_size = size; \ | |
5451 } while (0) | |
5452 | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5453 |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5454 static void |
88365 | 5455 produce_annotation (coding) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5456 struct coding_system *coding; |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5457 { |
88365 | 5458 int *charbuf = coding->charbuf; |
5459 int *charbuf_end = charbuf + coding->charbuf_used; | |
5460 | |
5461 while (charbuf < charbuf_end) | |
5462 { | |
5463 if (*charbuf >= 0) | |
5464 charbuf++; | |
5465 else | |
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
5466 { |
88365 | 5467 int len = -*charbuf; |
5468 switch (charbuf[2]) | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5469 { |
88365 | 5470 case CODING_ANNOTATE_COMPOSITION_MASK: |
5471 produce_composition (coding, charbuf); | |
5472 break; | |
5473 default: | |
5474 abort (); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5475 } |
88365 | 5476 charbuf += len; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5477 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5478 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5479 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5480 |
88365 | 5481 /* Decode the data at CODING->src_object into CODING->dst_object. |
5482 CODING->src_object is a buffer, a string, or nil. | |
5483 CODING->dst_object is a buffer. | |
5484 | |
5485 If CODING->src_object is a buffer, it must be the current buffer. | |
5486 In this case, if CODING->src_pos is positive, it is a position of | |
5487 the source text in the buffer, otherwise, the source text is in the | |
5488 gap area of the buffer, and CODING->src_pos specifies the offset of | |
5489 the text from GPT (which must be the same as PT). If this is the | |
5490 same buffer as CODING->dst_object, CODING->src_pos must be | |
5491 negative. | |
5492 | |
5493 If CODING->src_object is a string, CODING->src_pos in an index to | |
5494 that string. | |
5495 | |
5496 If CODING->src_object is nil, CODING->source must already point to | |
5497 the non-relocatable memory area. In this case, CODING->src_pos is | |
5498 an offset from CODING->source. | |
5499 | |
5500 The decoded data is inserted at the current point of the buffer | |
5501 CODING->dst_object. | |
5502 */ | |
5503 | |
5504 static int | |
5505 decode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5506 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5507 { |
88365 | 5508 Lisp_Object attrs; |
5509 | |
5510 if (BUFFERP (coding->src_object) | |
5511 && coding->src_pos > 0 | |
5512 && coding->src_pos < GPT | |
5513 && coding->src_pos + coding->src_chars > GPT) | |
5514 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
5515 | |
5516 if (BUFFERP (coding->dst_object)) | |
5517 { | |
5518 if (current_buffer != XBUFFER (coding->dst_object)) | |
5519 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5520 if (GPT != PT) | |
5521 move_gap_both (PT, PT_BYTE); | |
5522 } | |
5523 | |
5524 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
|
5525 coding->produced = coding->produced_char = 0; |
88365 | 5526 coding->chars_at_source = 0; |
5527 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
|
5528 coding->errors = 0; |
88365 | 5529 |
5530 ALLOC_CONVERSION_WORK_AREA (coding); | |
5531 | |
5532 attrs = CODING_ID_ATTRS (coding->id); | |
5533 | |
5534 do | |
5535 { | |
5536 coding_set_source (coding); | |
5537 coding->annotated = 0; | |
5538 (*(coding->decoder)) (coding); | |
5539 if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | |
5540 translate_chars (CODING_ATTR_DECODE_TBL (attrs), coding); | |
5541 coding_set_destination (coding); | |
5542 produce_chars (coding); | |
5543 if (coding->annotated) | |
5544 produce_annotation (coding); | |
5545 } | |
5546 while (coding->consumed < coding->src_bytes | |
5547 && ! coding->result); | |
5548 | |
5549 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qccl) | |
5550 && SYMBOLP (CODING_ID_EOL_TYPE (coding->id)) | |
5551 && ! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix)) | |
5552 decode_eol (coding); | |
5553 | |
5554 coding->carryover_bytes = 0; | |
5555 if (coding->consumed < coding->src_bytes) | |
5556 { | |
5557 int nbytes = coding->src_bytes - coding->consumed; | |
5558 unsigned char *src; | |
5559 | |
5560 coding_set_source (coding); | |
5561 coding_set_destination (coding); | |
5562 src = coding->source + coding->consumed; | |
5563 | |
5564 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
|
5565 { |
88365 | 5566 /* Flush out unprocessed data as binary chars. We are sure |
5567 that the number of data is less than the size of | |
5568 coding->charbuf. */ | |
5569 int *charbuf = coding->charbuf; | |
5570 | |
5571 while (nbytes-- > 0) | |
5572 { | |
5573 int c = *src++; | |
5574 *charbuf++ = (c & 0x80 ? - c : c); | |
5575 } | |
5576 produce_chars (coding); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5577 } |
88365 | 5578 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5579 { |
88365 | 5580 /* Record unprocessed bytes in coding->carryover. We are |
5581 sure that the number of data is less than the size of | |
5582 coding->carryover. */ | |
5583 unsigned char *p = coding->carryover; | |
5584 | |
5585 coding->carryover_bytes = nbytes; | |
5586 while (nbytes-- > 0) | |
5587 *p++ = *src++; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5588 } |
88365 | 5589 coding->consumed = coding->src_bytes; |
5590 } | |
5591 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5592 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5593 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5594 |
88365 | 5595 static void |
5596 consume_chars (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5597 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5598 { |
88365 | 5599 int *buf = coding->charbuf; |
5600 /* -1 is to compensate for CRLF. */ | |
5601 int *buf_end = coding->charbuf + coding->charbuf_size - 1; | |
5602 unsigned char *src = coding->source + coding->consumed; | |
5603 int pos = coding->src_pos + coding->consumed_char; | |
5604 int end_pos = coding->src_pos + coding->src_chars; | |
5605 int multibytep = coding->src_multibyte; | |
5606 Lisp_Object eol_type; | |
5607 int c; | |
5608 int start, end, stop; | |
5609 Lisp_Object object, prop; | |
5610 | |
5611 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5612 if (VECTORP (eol_type)) | |
5613 eol_type = Qunix; | |
5614 | |
5615 object = coding->src_object; | |
5616 | |
5617 /* Note: composition handling is not yet implemented. */ | |
5618 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
5619 | |
5620 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK | |
5621 && find_composition (pos, end_pos, &start, &end, &prop, object) | |
5622 && end <= end_pos | |
5623 && (start >= pos | |
5624 || (find_composition (end, end_pos, &start, &end, &prop, object) | |
5625 && end <= end_pos))) | |
5626 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5627 else |
88365 | 5628 stop = end_pos; |
5629 | |
5630 while (buf < buf_end) | |
5631 { | |
5632 if (pos == stop) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5633 { |
88365 | 5634 int *p; |
5635 | |
5636 if (pos == end_pos) | |
5637 break; | |
5638 p = save_composition_data (buf, buf_end, prop); | |
5639 if (p == NULL) | |
5640 break; | |
5641 buf = p; | |
5642 if (find_composition (end, end_pos, &start, &end, &prop, object) | |
5643 && end <= end_pos) | |
5644 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5645 else |
88365 | 5646 stop = end_pos; |
5647 } | |
5648 | |
5649 if (! multibytep) | |
5650 c = *src++; | |
5651 else | |
5652 c = STRING_CHAR_ADVANCE (src); | |
5653 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) | |
5654 c = '\n'; | |
5655 if (! EQ (eol_type, Qunix)) | |
5656 { | |
5657 if (c == '\n') | |
5658 { | |
5659 if (EQ (eol_type, Qdos)) | |
5660 *buf++ = '\r'; | |
5661 else | |
5662 c = '\r'; | |
5663 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5664 } |
88365 | 5665 *buf++ = c; |
5666 pos++; | |
5667 } | |
5668 | |
5669 coding->consumed = src - coding->source; | |
5670 coding->consumed_char = pos - coding->src_pos; | |
5671 coding->charbuf_used = buf - coding->charbuf; | |
5672 coding->chars_at_source = 0; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5673 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5674 |
88365 | 5675 |
5676 /* Encode the text at CODING->src_object into CODING->dst_object. | |
5677 CODING->src_object is a buffer or a string. | |
5678 CODING->dst_object is a buffer or nil. | |
5679 | |
5680 If CODING->src_object is a buffer, it must be the current buffer. | |
5681 In this case, if CODING->src_pos is positive, it is a position of | |
5682 the source text in the buffer, otherwise. the source text is in the | |
5683 gap area of the buffer, and coding->src_pos specifies the offset of | |
5684 the text from GPT (which must be the same as PT). If this is the | |
5685 same buffer as CODING->dst_object, CODING->src_pos must be | |
5686 negative and CODING should not have `pre-write-conversion'. | |
5687 | |
5688 If CODING->src_object is a string, CODING should not have | |
5689 `pre-write-conversion'. | |
5690 | |
5691 If CODING->dst_object is a buffer, the encoded data is inserted at | |
5692 the current point of that buffer. | |
5693 | |
5694 If CODING->dst_object is nil, the encoded data is placed at the | |
5695 memory area specified by CODING->destination. */ | |
5696 | |
5697 static int | |
5698 encode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5699 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5700 { |
88365 | 5701 Lisp_Object attrs; |
5702 | |
5703 attrs = CODING_ID_ATTRS (coding->id); | |
5704 | |
5705 if (BUFFERP (coding->dst_object)) | |
5706 { | |
5707 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5708 coding->dst_multibyte | |
5709 = ! NILP (current_buffer->enable_multibyte_characters); | |
5710 } | |
5711 | |
5712 coding->consumed = coding->consumed_char = 0; | |
5713 coding->produced = coding->produced_char = 0; | |
5714 coding->result = CODING_RESULT_SUCCESS; | |
5715 coding->errors = 0; | |
5716 | |
5717 ALLOC_CONVERSION_WORK_AREA (coding); | |
5718 | |
5719 do { | |
5720 coding_set_source (coding); | |
5721 consume_chars (coding); | |
5722 | |
5723 if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | |
5724 translate_chars (CODING_ATTR_ENCODE_TBL (attrs), coding); | |
5725 | |
5726 coding_set_destination (coding); | |
5727 (*(coding->encoder)) (coding); | |
5728 } while (coding->consumed_char < coding->src_chars); | |
5729 | |
5730 if (BUFFERP (coding->dst_object)) | |
5731 insert_from_gap (coding->produced_char, coding->produced); | |
5732 | |
5733 return (coding->result); | |
5734 } | |
5735 | |
5736 /* Work buffer */ | |
5737 | |
5738 /* List of currently used working buffer. */ | |
5739 Lisp_Object Vcode_conversion_work_buf_list; | |
5740 | |
5741 /* A working buffer used by the top level conversion. */ | |
5742 Lisp_Object Vcode_conversion_reused_work_buf; | |
5743 | |
5744 | |
5745 /* Return a working buffer that can be freely used by the following | |
5746 code conversion. MULTIBYTEP specifies the multibyteness of the | |
5747 buffer. */ | |
5748 | |
5749 Lisp_Object | |
5750 make_conversion_work_buffer (multibytep) | |
5751 int multibytep; | |
5752 { | |
5753 struct buffer *current = current_buffer; | |
5754 Lisp_Object buf; | |
5755 | |
5756 if (NILP (Vcode_conversion_work_buf_list)) | |
5757 { | |
5758 if (NILP (Vcode_conversion_reused_work_buf)) | |
5759 Vcode_conversion_reused_work_buf | |
5760 = Fget_buffer_create (build_string (" *code-conversion-work*")); | |
5761 Vcode_conversion_work_buf_list | |
5762 = 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
|
5763 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5764 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5765 { |
88365 | 5766 int depth = Flength (Vcode_conversion_work_buf_list); |
5767 char str[128]; | |
5768 | |
5769 sprintf (str, " *code-conversion-work*<%d>", depth); | |
5770 Vcode_conversion_work_buf_list | |
5771 = Fcons (Fget_buffer_create (build_string (str)), | |
5772 Vcode_conversion_work_buf_list); | |
5773 } | |
5774 | |
5775 buf = XCAR (Vcode_conversion_work_buf_list); | |
5776 set_buffer_internal (XBUFFER (buf)); | |
5777 current_buffer->undo_list = Qt; | |
5778 Ferase_buffer (); | |
5779 Fset_buffer_multibyte (multibytep ? Qt : Qnil); | |
5780 set_buffer_internal (current); | |
5781 return buf; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5782 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5783 |
88365 | 5784 static struct coding_system *saved_coding; |
5785 | |
5786 Lisp_Object | |
5787 code_conversion_restore (info) | |
5788 Lisp_Object info; | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5789 { |
88365 | 5790 int depth = Flength (Vcode_conversion_work_buf_list); |
5791 Lisp_Object buf; | |
5792 | |
5793 if (depth > 0) | |
5794 { | |
5795 buf = XCAR (Vcode_conversion_work_buf_list); | |
5796 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); | |
5797 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) | |
5798 Fkill_buffer (buf); | |
5799 } | |
5800 | |
5801 if (saved_coding->dst_object == Qt | |
5802 && saved_coding->destination) | |
5803 xfree (saved_coding->destination); | |
5804 | |
5805 return save_excursion_restore (info); | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5806 } |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5807 |
88365 | 5808 |
5809 int | |
5810 decode_coding_gap (coding, chars, bytes) | |
26847 | 5811 struct coding_system *coding; |
88365 | 5812 EMACS_INT chars, bytes; |
5813 { | |
5814 int count = specpdl_ptr - specpdl; | |
5815 | |
5816 saved_coding = coding; | |
5817 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5818 | |
5819 coding->src_object = Fcurrent_buffer (); | |
5820 coding->src_chars = chars; | |
5821 coding->src_bytes = bytes; | |
5822 coding->src_pos = -chars; | |
5823 coding->src_pos_byte = -bytes; | |
5824 coding->src_multibyte = chars < bytes; | |
5825 coding->dst_object = coding->src_object; | |
5826 coding->dst_pos = PT; | |
5827 coding->dst_pos_byte = PT_BYTE; | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5828 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
88365 | 5829 |
5830 if (CODING_REQUIRE_DETECTION (coding)) | |
5831 detect_coding (coding); | |
5832 | |
5833 decode_coding (coding); | |
5834 | |
5835 unbind_to (count, Qnil); | |
5836 return coding->result; | |
5837 } | |
5838 | |
5839 int | |
5840 encode_coding_gap (coding, chars, bytes) | |
5841 struct coding_system *coding; | |
5842 EMACS_INT chars, bytes; | |
26847 | 5843 { |
88365 | 5844 int count = specpdl_ptr - specpdl; |
5845 Lisp_Object buffer; | |
5846 | |
5847 saved_coding = coding; | |
5848 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5849 | |
5850 buffer = Fcurrent_buffer (); | |
5851 coding->src_object = buffer; | |
5852 coding->src_chars = chars; | |
5853 coding->src_bytes = bytes; | |
5854 coding->src_pos = -chars; | |
5855 coding->src_pos_byte = -bytes; | |
5856 coding->src_multibyte = chars < bytes; | |
5857 coding->dst_object = coding->src_object; | |
5858 coding->dst_pos = PT; | |
5859 coding->dst_pos_byte = PT_BYTE; | |
5860 | |
5861 encode_coding (coding); | |
5862 | |
5863 unbind_to (count, Qnil); | |
5864 return coding->result; | |
26847 | 5865 } |
5866 | |
88365 | 5867 |
5868 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
5869 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
5870 | |
5871 SRC_OBJECT is a buffer, a string, or Qnil. | |
5872 | |
5873 If it is a buffer, the text is at point of the buffer. FROM and TO | |
5874 are positions in the buffer. | |
5875 | |
5876 If it is a string, the text is at the beginning of the string. | |
5877 FROM and TO are indices to the string. | |
5878 | |
5879 If it is nil, the text is at coding->source. FROM and TO are | |
5880 indices to coding->source. | |
5881 | |
5882 DST_OBJECT is a buffer, Qt, or Qnil. | |
5883 | |
5884 If it is a buffer, the decoded text is inserted at point of the | |
5885 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
5886 is deleted. | |
5887 | |
5888 If it is Qt, a string is made from the decoded text, and | |
5889 set in CODING->dst_object. | |
5890 | |
5891 If it is Qnil, the decoded text is stored at CODING->destination. | |
5892 The called must allocate CODING->dst_bytes bytes at | |
5893 CODING->destination by xmalloc. If the decoded text is longer than | |
5894 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
5895 */ | |
26847 | 5896 |
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
5897 void |
88365 | 5898 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
5899 dst_object) | |
26847 | 5900 struct coding_system *coding; |
88365 | 5901 Lisp_Object src_object; |
5902 EMACS_INT from, from_byte, to, to_byte; | |
5903 Lisp_Object dst_object; | |
26847 | 5904 { |
88365 | 5905 int count = specpdl_ptr - specpdl; |
5906 unsigned char *destination; | |
5907 EMACS_INT dst_bytes; | |
5908 EMACS_INT chars = to - from; | |
5909 EMACS_INT bytes = to_byte - from_byte; | |
5910 Lisp_Object attrs; | |
5911 | |
5912 saved_coding = coding; | |
5913 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5914 | |
5915 if (NILP (dst_object)) | |
5916 { | |
5917 destination = coding->destination; | |
5918 dst_bytes = coding->dst_bytes; | |
5919 } | |
5920 | |
5921 coding->src_object = src_object; | |
5922 coding->src_chars = chars; | |
5923 coding->src_bytes = bytes; | |
5924 coding->src_multibyte = chars < bytes; | |
5925 | |
5926 if (STRINGP (src_object)) | |
5927 { | |
5928 coding->src_pos = from; | |
5929 coding->src_pos_byte = from_byte; | |
5930 } | |
5931 else if (BUFFERP (src_object)) | |
5932 { | |
5933 set_buffer_internal (XBUFFER (src_object)); | |
5934 if (from != GPT) | |
5935 move_gap_both (from, from_byte); | |
5936 if (EQ (src_object, dst_object)) | |
26847 | 5937 { |
88365 | 5938 TEMP_SET_PT_BOTH (from, from_byte); |
5939 del_range_both (from, from_byte, to, to_byte, 1); | |
5940 coding->src_pos = -chars; | |
5941 coding->src_pos_byte = -bytes; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5942 } |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5943 else |
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5944 { |
88365 | 5945 coding->src_pos = from; |
5946 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
|
5947 } |
88365 | 5948 } |
5949 | |
5950 if (CODING_REQUIRE_DETECTION (coding)) | |
5951 detect_coding (coding); | |
5952 attrs = CODING_ID_ATTRS (coding->id); | |
5953 | |
5954 if (! NILP (CODING_ATTR_POST_READ (attrs)) | |
5955 || EQ (dst_object, Qt)) | |
5956 { | |
5957 coding->dst_object = make_conversion_work_buffer (1); | |
5958 coding->dst_pos = BEG; | |
5959 coding->dst_pos_byte = BEG_BYTE; | |
5960 coding->dst_multibyte = 1; | |
5961 } | |
5962 else if (BUFFERP (dst_object)) | |
5963 { | |
5964 coding->dst_object = dst_object; | |
5965 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
5966 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
5967 coding->dst_multibyte | |
5968 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
5969 } | |
5970 else | |
5971 { | |
5972 coding->dst_object = Qnil; | |
5973 coding->dst_multibyte = 1; | |
5974 } | |
5975 | |
5976 decode_coding (coding); | |
5977 | |
5978 if (BUFFERP (coding->dst_object)) | |
5979 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5980 | |
5981 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
5982 { | |
5983 struct gcpro gcpro1, gcpro2; | |
5984 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; | |
5985 Lisp_Object val; | |
5986 | |
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
5987 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
88365 | 5988 GCPRO2 (coding->src_object, coding->dst_object); |
5989 val = call1 (CODING_ATTR_POST_READ (attrs), | |
5990 make_number (coding->produced_char)); | |
5991 UNGCPRO; | |
5992 CHECK_NATNUM (val); | |
5993 coding->produced_char += Z - prev_Z; | |
5994 coding->produced += Z_BYTE - prev_Z_BYTE; | |
5995 } | |
5996 | |
5997 if (EQ (dst_object, Qt)) | |
5998 { | |
5999 coding->dst_object = Fbuffer_string (); | |
6000 } | |
6001 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
6002 { | |
6003 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6004 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
|
6005 { |
88365 | 6006 destination |
6007 = (unsigned char *) xrealloc (destination, coding->produced); | |
6008 if (! destination) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6009 { |
88365 | 6010 coding->result = CODING_RESULT_INSUFFICIENT_DST; |
6011 unbind_to (count, Qnil); | |
6012 return; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6013 } |
88365 | 6014 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
6015 move_gap_both (BEGV, BEGV_BYTE); | |
6016 bcopy (BEGV_ADDR, destination, coding->produced); | |
6017 coding->destination = destination; | |
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
6018 } |
88365 | 6019 } |
6020 | |
6021 unbind_to (count, Qnil); | |
6022 } | |
6023 | |
6024 | |
6025 void | |
6026 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, | |
6027 dst_object) | |
6028 struct coding_system *coding; | |
6029 Lisp_Object src_object; | |
6030 EMACS_INT from, from_byte, to, to_byte; | |
6031 Lisp_Object dst_object; | |
6032 { | |
6033 int count = specpdl_ptr - specpdl; | |
6034 EMACS_INT chars = to - from; | |
6035 EMACS_INT bytes = to_byte - from_byte; | |
6036 Lisp_Object attrs; | |
6037 | |
6038 saved_coding = coding; | |
6039 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6040 | |
6041 coding->src_object = src_object; | |
6042 coding->src_chars = chars; | |
6043 coding->src_bytes = bytes; | |
6044 coding->src_multibyte = chars < bytes; | |
6045 | |
6046 attrs = CODING_ID_ATTRS (coding->id); | |
6047 | |
6048 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
|
6049 { |
88365 | 6050 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); |
6051 set_buffer_internal (XBUFFER (coding->src_object)); | |
6052 if (STRINGP (src_object)) | |
6053 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
6054 else if (BUFFERP (src_object)) | |
6055 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
6056 else | |
6057 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); | |
6058 | |
6059 if (EQ (src_object, dst_object)) | |
6060 { | |
6061 set_buffer_internal (XBUFFER (src_object)); | |
6062 del_range_both (from, from_byte, to, to_byte, 1); | |
6063 set_buffer_internal (XBUFFER (coding->src_object)); | |
6064 } | |
6065 | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6066 call2 (CODING_ATTR_PRE_WRITE (attrs), |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6067 make_number (BEG), make_number (Z)); |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6068 coding->src_object = Fcurrent_buffer (); |
88365 | 6069 if (BEG != GPT) |
6070 move_gap_both (BEG, BEG_BYTE); | |
6071 coding->src_chars = Z - BEG; | |
6072 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
6073 coding->src_pos = BEG; | |
6074 coding->src_pos_byte = BEG_BYTE; | |
6075 coding->src_multibyte = Z < Z_BYTE; | |
6076 } | |
6077 else if (STRINGP (src_object)) | |
6078 { | |
6079 coding->src_pos = from; | |
6080 coding->src_pos_byte = from_byte; | |
6081 } | |
6082 else if (BUFFERP (src_object)) | |
6083 { | |
6084 set_buffer_internal (XBUFFER (src_object)); | |
6085 if (from != GPT) | |
6086 move_gap_both (from, from_byte); | |
6087 if (EQ (src_object, dst_object)) | |
6088 { | |
6089 del_range_both (from, from_byte, to, to_byte, 1); | |
6090 coding->src_pos = -chars; | |
6091 coding->src_pos_byte = -bytes; | |
6092 } | |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
6093 else |
88365 | 6094 { |
6095 coding->src_pos = from; | |
6096 coding->src_pos_byte = from_byte; | |
6097 } | |
6098 } | |
6099 | |
6100 if (BUFFERP (dst_object)) | |
6101 { | |
6102 coding->dst_object = dst_object; | |
6103 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
6104 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
6105 coding->dst_multibyte | |
6106 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
6107 } | |
6108 else if (EQ (dst_object, Qt)) | |
6109 { | |
6110 coding->dst_object = Qnil; | |
6111 coding->dst_bytes = coding->src_chars; | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6112 if (coding->dst_bytes == 0) |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6113 coding->dst_bytes = 1; |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6114 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
88365 | 6115 coding->dst_multibyte = 0; |
6116 } | |
6117 else | |
6118 { | |
6119 coding->dst_object = Qnil; | |
6120 coding->dst_multibyte = 0; | |
6121 } | |
6122 | |
6123 encode_coding (coding); | |
6124 | |
6125 if (EQ (dst_object, Qt)) | |
6126 { | |
6127 if (BUFFERP (coding->dst_object)) | |
6128 coding->dst_object = Fbuffer_string (); | |
6129 else | |
6130 { | |
6131 coding->dst_object | |
6132 = make_unibyte_string ((char *) coding->destination, | |
6133 coding->produced); | |
6134 xfree (coding->destination); | |
6135 } | |
6136 } | |
6137 | |
6138 unbind_to (count, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6139 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6140 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6141 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6142 Lisp_Object |
88365 | 6143 preferred_coding_system () |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6144 { |
88365 | 6145 int id = coding_categories[coding_priorities[0]].id; |
6146 | |
6147 return CODING_ID_NAME (id); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6148 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6149 |
17052 | 6150 |
6151 #ifdef emacs | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6152 /*** 8. Emacs Lisp library functions ***/ |
17052 | 6153 |
6154 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
|
6155 doc: /* Return t if OBJECT is nil or a coding-system. |
88365 | 6156 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
|
6157 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
|
6158 (obj) |
17052 | 6159 Lisp_Object obj; |
6160 { | |
88365 | 6161 return ((NILP (obj) || CODING_SYSTEM_P (obj)) ? Qt : Qnil); |
17052 | 6162 } |
6163 | |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6164 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
|
6165 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
|
6166 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
|
6167 (prompt) |
17052 | 6168 Lisp_Object prompt; |
6169 { | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6170 Lisp_Object val; |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6171 do |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6172 { |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6173 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6174 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
|
6175 } |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6176 while (XSTRING (val)->size == 0); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6177 return (Fintern (val, Qnil)); |
17052 | 6178 } |
6179 | |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6180 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
|
6181 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
|
6182 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
|
6183 (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
|
6184 Lisp_Object prompt, default_coding_system; |
17052 | 6185 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
6186 Lisp_Object val; |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6187 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
|
6188 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6189 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
|
6190 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
|
6191 default_coding_system, Qnil); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6192 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
17052 | 6193 } |
6194 | |
6195 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
6196 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
|
6197 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
|
6198 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
|
6199 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
|
6200 The value of property should be a vector of length 5. */) |
88365 | 6201 (coding_system) |
17052 | 6202 Lisp_Object coding_system; |
6203 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6204 CHECK_SYMBOL (coding_system); |
17052 | 6205 if (!NILP (Fcoding_system_p (coding_system))) |
6206 return coding_system; | |
6207 while (1) | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
6208 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
17052 | 6209 } |
88365 | 6210 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6211 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6212 Lisp_Object |
88365 | 6213 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
|
6214 unsigned char *src; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6215 int src_bytes, highest; |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6216 int multibytep; |
88365 | 6217 Lisp_Object coding_system; |
17052 | 6218 { |
88365 | 6219 unsigned char *src_end = src + src_bytes; |
6220 int mask = CATEGORY_MASK_ANY; | |
6221 int detected = 0; | |
6222 int c, i; | |
6223 Lisp_Object attrs, eol_type; | |
6224 Lisp_Object val; | |
6225 struct coding_system coding; | |
6226 | |
6227 if (NILP (coding_system)) | |
6228 coding_system = Qundecided; | |
6229 setup_coding_system (coding_system, &coding); | |
6230 attrs = CODING_ID_ATTRS (coding.id); | |
6231 eol_type = CODING_ID_EOL_TYPE (coding.id); | |
6232 | |
6233 coding.source = src; | |
6234 coding.src_bytes = src_bytes; | |
6235 coding.src_multibyte = multibytep; | |
6236 coding.consumed = 0; | |
6237 | |
6238 if (XINT (CODING_ATTR_CATEGORY (attrs)) != coding_category_undecided) | |
6239 { | |
6240 mask = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); | |
6241 } | |
6242 else | |
6243 { | |
6244 coding_system = Qnil; | |
6245 for (; src < src_end; src++) | |
17052 | 6246 { |
88365 | 6247 c = *src; |
6248 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
6249 || c == ISO_CODE_SI | |
6250 || c == ISO_CODE_SO))) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6251 break; |
17052 | 6252 } |
88365 | 6253 coding.head_ascii = src - coding.source; |
6254 | |
6255 if (src < src_end) | |
6256 for (i = 0; i < coding_category_raw_text; i++) | |
6257 { | |
6258 enum coding_category category = coding_priorities[i]; | |
6259 struct coding_system *this = coding_categories + category; | |
6260 | |
6261 if (category >= coding_category_raw_text | |
6262 || detected & (1 << category)) | |
6263 continue; | |
6264 | |
6265 if (this->id < 0) | |
6266 { | |
6267 /* No coding system of this category is defined. */ | |
6268 mask &= ~(1 << category); | |
6269 } | |
6270 else | |
6271 { | |
6272 detected |= detected_mask[category]; | |
6273 if ((*(coding_categories[category].detector)) (&coding, &mask) | |
6274 && highest) | |
6275 { | |
6276 mask &= detected_mask[category]; | |
6277 break; | |
6278 } | |
6279 } | |
6280 } | |
6281 } | |
6282 | |
6283 if (!mask) | |
6284 val = Fcons (make_number (coding_category_raw_text), Qnil); | |
6285 else if (mask == CATEGORY_MASK_ANY) | |
6286 val = Fcons (make_number (coding_category_undecided), Qnil); | |
6287 else if (highest) | |
6288 { | |
6289 for (i = 0; i < coding_category_raw_text; i++) | |
6290 if (mask & (1 << coding_priorities[i])) | |
6291 { | |
6292 val = Fcons (make_number (coding_priorities[i]), Qnil); | |
6293 break; | |
6294 } | |
6295 } | |
6296 else | |
6297 { | |
6298 val = Qnil; | |
6299 for (i = coding_category_raw_text - 1; i >= 0; i--) | |
6300 if (mask & (1 << coding_priorities[i])) | |
6301 val = Fcons (make_number (coding_priorities[i]), val); | |
6302 } | |
6303 | |
6304 { | |
6305 int one_byte_eol = -1, two_byte_eol = -1; | |
6306 Lisp_Object tail; | |
6307 | |
6308 for (tail = val; CONSP (tail); tail = XCDR (tail)) | |
6309 { | |
6310 struct coding_system *this | |
6311 = (NILP (coding_system) ? coding_categories + XINT (XCAR (tail)) | |
6312 : &coding); | |
6313 int this_eol; | |
6314 | |
6315 attrs = CODING_ID_ATTRS (this->id); | |
6316 eol_type = CODING_ID_EOL_TYPE (this->id); | |
6317 XSETCAR (tail, CODING_ID_NAME (this->id)); | |
6318 if (VECTORP (eol_type)) | |
6319 { | |
6320 if (EQ (CODING_ATTR_TYPE (attrs), Qutf_16)) | |
6321 { | |
6322 if (two_byte_eol < 0) | |
6323 two_byte_eol = detect_eol (this, coding.source, src_bytes); | |
6324 this_eol = two_byte_eol; | |
6325 } | |
6326 else | |
6327 { | |
6328 if (one_byte_eol < 0) | |
6329 one_byte_eol =detect_eol (this, coding.source, src_bytes); | |
6330 this_eol = one_byte_eol; | |
6331 } | |
6332 if (this_eol == EOL_SEEN_LF) | |
6333 XSETCAR (tail, AREF (eol_type, 0)); | |
6334 else if (this_eol == EOL_SEEN_CRLF) | |
6335 XSETCAR (tail, AREF (eol_type, 1)); | |
6336 else if (this_eol == EOL_SEEN_CR) | |
6337 XSETCAR (tail, AREF (eol_type, 2)); | |
6338 } | |
6339 } | |
6340 } | |
6341 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
6342 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
|
6343 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6344 |
88365 | 6345 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6346 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
|
6347 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
|
6348 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
|
6349 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
|
6350 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6351 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
|
6352 `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
|
6353 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
|
6354 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6355 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
|
6356 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6357 (start, end, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6358 Lisp_Object start, end, highest; |
17052 | 6359 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6360 int from, to; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6361 int from_byte, to_byte; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6362 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6363 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
|
6364 CHECK_NUMBER_COERCE_MARKER (end); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6365 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6366 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6367 from = XINT (start), to = XINT (end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6368 from_byte = CHAR_TO_BYTE (from); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6369 to_byte = CHAR_TO_BYTE (to); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6370 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6371 if (from < GPT && to >= GPT) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6372 move_gap_both (to, to_byte); |
88365 | 6373 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6374 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
88365 | 6375 to_byte - from_byte, |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6376 !NILP (highest), |
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6377 !NILP (current_buffer |
88365 | 6378 ->enable_multibyte_characters), |
6379 Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6380 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6381 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6382 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
|
6383 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
|
6384 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
|
6385 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
|
6386 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6387 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
|
6388 `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
|
6389 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
|
6390 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6391 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
|
6392 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6393 (string, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6394 Lisp_Object string, highest; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6395 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6396 CHECK_STRING (string); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6397 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6398 return detect_coding_system (XSTRING (string)->data, |
88365 | 6399 STRING_BYTES (XSTRING (string)), |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6400 !NILP (highest), |
88365 | 6401 STRING_MULTIBYTE (string), |
6402 Qnil); | |
30487
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 |
88365 | 6406 static INLINE int |
6407 char_encodable_p (c, attrs) | |
6408 int c; | |
6409 Lisp_Object attrs; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6410 { |
88365 | 6411 Lisp_Object tail; |
6412 struct charset *charset; | |
6413 | |
6414 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | |
6415 CONSP (tail); tail = XCDR (tail)) | |
6416 { | |
6417 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
6418 if (CHAR_CHARSET_P (c, charset)) | |
6419 break; | |
6420 } | |
6421 return (! NILP (tail)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6422 } |
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 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6425 /* Return a list of coding systems that safely encode the text between |
88365 | 6426 START and END. If EXCLUDE is non-nil, it is a list of coding |
6427 systems not to check. The returned list doesn't contain any such | |
6428 coding systems. In any case, If the text contains only ASCII or is | |
6429 unibyte, return t. */ | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6430 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6431 DEFUN ("find-coding-systems-region-internal", |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6432 Ffind_coding_systems_region_internal, |
88365 | 6433 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
|
6434 doc: /* Internal use only. */) |
88365 | 6435 (start, end, exclude) |
6436 Lisp_Object start, end, exclude; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6437 { |
88365 | 6438 Lisp_Object coding_attrs_list, safe_codings; |
6439 EMACS_INT start_byte, end_byte; | |
6440 unsigned char *p, *pbeg, *pend; | |
6441 int c; | |
6442 Lisp_Object tail, elt; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6443 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6444 if (STRINGP (start)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6445 { |
88365 | 6446 if (!STRING_MULTIBYTE (start) |
6447 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6448 return Qt; |
88365 | 6449 start_byte = 0; |
6450 end_byte = STRING_BYTES (XSTRING (start)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6451 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6452 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6453 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6454 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
|
6455 CHECK_NUMBER_COERCE_MARKER (end); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6456 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
|
6457 args_out_of_range (start, end); |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6458 if (NILP (current_buffer->enable_multibyte_characters)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6459 return Qt; |
88365 | 6460 start_byte = CHAR_TO_BYTE (XINT (start)); |
6461 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6462 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6463 return Qt; | |
6464 | |
6465 if (start < GPT && end > GPT) | |
6466 { | |
6467 if ((GPT - start) < (end - GPT)) | |
6468 move_gap_both (start, start_byte); | |
6469 else | |
6470 move_gap_both (end, end_byte); | |
6471 } | |
6472 } | |
6473 | |
6474 coding_attrs_list = Qnil; | |
6475 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6476 if (NILP (exclude) | |
6477 || NILP (Fmemq (XCAR (tail), exclude))) | |
6478 { | |
6479 Lisp_Object attrs; | |
6480 | |
6481 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
6482 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
6483 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
6484 coding_attrs_list = Fcons (attrs, coding_attrs_list); | |
6485 } | |
6486 | |
6487 if (STRINGP (start)) | |
6488 p = pbeg = XSTRING (start)->data; | |
6489 else | |
6490 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6491 pend = p + (end_byte - start_byte); | |
6492 | |
6493 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
6494 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6495 | |
6496 while (p < pend) | |
6497 { | |
6498 if (ASCII_BYTE_P (*p)) | |
6499 p++; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6500 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6501 { |
88365 | 6502 c = STRING_CHAR_ADVANCE (p); |
6503 | |
6504 charset_map_loaded = 0; | |
6505 for (tail = coding_attrs_list; CONSP (tail);) | |
6506 { | |
6507 elt = XCAR (tail); | |
6508 if (NILP (elt)) | |
6509 tail = XCDR (tail); | |
6510 else if (char_encodable_p (c, elt)) | |
6511 tail = XCDR (tail); | |
6512 else if (CONSP (XCDR (tail))) | |
6513 { | |
6514 XSETCAR (tail, XCAR (XCDR (tail))); | |
6515 XSETCDR (tail, XCDR (XCDR (tail))); | |
6516 } | |
6517 else | |
6518 { | |
6519 XSETCAR (tail, Qnil); | |
6520 tail = XCDR (tail); | |
6521 } | |
6522 } | |
6523 if (charset_map_loaded) | |
6524 { | |
6525 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6526 | |
6527 if (STRINGP (start)) | |
6528 pbeg = XSTRING (start)->data; | |
6529 else | |
6530 pbeg = BYTE_POS_ADDR (start_byte); | |
6531 p = pbeg + p_offset; | |
6532 pend = pbeg + pend_offset; | |
6533 } | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6534 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6535 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6536 |
88365 | 6537 safe_codings = Qnil; |
6538 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) | |
6539 if (! NILP (XCAR (tail))) | |
6540 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
6541 | |
6542 return safe_codings; | |
6543 } | |
6544 | |
6545 | |
6546 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, | |
6547 Scheck_coding_systems_region, 3, 3, 0, | |
6548 doc: /* Check if the region is encodable by coding systems. | |
6549 | |
6550 START and END are buffer positions specifying the region. | |
6551 CODING-SYSTEM-LIST is a list of coding systems to check. | |
6552 | |
6553 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
6554 CODING-SYSTEM is a member of CODING-SYSTEM-LIst and can't encode the | |
6555 whole region, POS0, POS1, ... are buffer positions where non-encodable | |
6556 characters are found. | |
6557 | |
6558 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
6559 value is nil. | |
6560 | |
6561 START may be a string. In that case, check if the string is | |
6562 encodable, and the value contains indices to the string instead of | |
6563 buffer positions. END is ignored. */) | |
6564 (start, end, coding_system_list) | |
6565 Lisp_Object start, end, coding_system_list; | |
6566 { | |
6567 Lisp_Object list; | |
6568 EMACS_INT start_byte, end_byte; | |
6569 int pos; | |
6570 unsigned char *p, *pbeg, *pend; | |
6571 int c; | |
6572 Lisp_Object tail, elt; | |
6573 | |
6574 if (STRINGP (start)) | |
6575 { | |
6576 if (!STRING_MULTIBYTE (start) | |
6577 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
6578 return Qnil; | |
6579 start_byte = 0; | |
6580 end_byte = STRING_BYTES (XSTRING (start)); | |
6581 pos = 0; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6582 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6583 else |
88365 | 6584 { |
6585 CHECK_NUMBER_COERCE_MARKER (start); | |
6586 CHECK_NUMBER_COERCE_MARKER (end); | |
6587 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
6588 args_out_of_range (start, end); | |
6589 if (NILP (current_buffer->enable_multibyte_characters)) | |
6590 return Qnil; | |
6591 start_byte = CHAR_TO_BYTE (XINT (start)); | |
6592 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6593 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6594 return Qt; | |
6595 | |
6596 if (start < GPT && end > GPT) | |
6597 { | |
6598 if ((GPT - start) < (end - GPT)) | |
6599 move_gap_both (start, start_byte); | |
6600 else | |
6601 move_gap_both (end, end_byte); | |
6602 } | |
6603 pos = start; | |
6604 } | |
6605 | |
6606 list = Qnil; | |
6607 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6608 { | |
6609 elt = XCAR (tail); | |
6610 list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | |
6611 Qnil)), | |
6612 list); | |
6613 } | |
6614 | |
6615 if (STRINGP (start)) | |
6616 p = pbeg = XSTRING (start)->data; | |
6617 else | |
6618 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6619 pend = p + (end_byte - start_byte); | |
6620 | |
6621 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
6622 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6623 | |
6624 while (p < pend) | |
6625 { | |
6626 if (ASCII_BYTE_P (*p)) | |
6627 p++; | |
6628 else | |
6629 { | |
6630 c = STRING_CHAR_ADVANCE (p); | |
6631 | |
6632 charset_map_loaded = 0; | |
6633 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
6634 { | |
6635 elt = XCDR (XCAR (tail)); | |
6636 if (! char_encodable_p (c, XCAR (elt))) | |
6637 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
6638 } | |
6639 if (charset_map_loaded) | |
6640 { | |
6641 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6642 | |
6643 if (STRINGP (start)) | |
6644 pbeg = XSTRING (start)->data; | |
6645 else | |
6646 pbeg = BYTE_POS_ADDR (start_byte); | |
6647 p = pbeg + p_offset; | |
6648 pend = pbeg + pend_offset; | |
6649 } | |
6650 } | |
6651 pos++; | |
6652 } | |
6653 | |
6654 tail = list; | |
6655 list = Qnil; | |
6656 for (; CONSP (tail); tail = XCDR (tail)) | |
6657 { | |
6658 elt = XCAR (tail); | |
6659 if (CONSP (XCDR (XCDR (elt)))) | |
6660 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
6661 list); | |
6662 } | |
6663 | |
6664 return list; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6665 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6666 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6667 |
88365 | 6668 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6669 Lisp_Object |
88365 | 6670 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
6671 Lisp_Object start, end, coding_system, dst_object; | |
6672 int encodep, norecord; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6673 { |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6674 struct coding_system coding; |
88365 | 6675 EMACS_INT from, from_byte, to, to_byte; |
6676 Lisp_Object src_object; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6677 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6678 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
|
6679 CHECK_NUMBER_COERCE_MARKER (end); |
88365 | 6680 if (NILP (coding_system)) |
6681 coding_system = Qno_conversion; | |
6682 else | |
6683 CHECK_CODING_SYSTEM (coding_system); | |
6684 src_object = Fcurrent_buffer (); | |
6685 if (NILP (dst_object)) | |
6686 dst_object = src_object; | |
6687 else if (! EQ (dst_object, Qt)) | |
6688 CHECK_BUFFER (dst_object); | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6689 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6690 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6691 from = XFASTINT (start); |
88365 | 6692 from_byte = CHAR_TO_BYTE (from); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6693 to = XFASTINT (end); |
88365 | 6694 to_byte = CHAR_TO_BYTE (to); |
6695 | |
6696 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6697 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6698 |
6699 if (encodep) | |
6700 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6701 dst_object); | |
6702 else | |
6703 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6704 dst_object); | |
6705 if (! norecord) | |
6706 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6707 | |
6708 if (coding.result != CODING_RESULT_SUCCESS) | |
6709 error ("Code conversion error: %d", coding.result); | |
6710 | |
6711 return (BUFFERP (dst_object) | |
6712 ? make_number (coding.produced_char) | |
6713 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6714 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6715 |
88365 | 6716 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6717 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
88365 | 6718 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
|
6719 doc: /* Decode the current region from the specified coding system. |
88365 | 6720 When called from a program, takes four arguments: |
6721 START, END, CODING-SYSTEM, and DESTINATION. | |
6722 START and END are buffer positions. | |
6723 | |
6724 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
6725 If nil, the region between START and END is replace by the decoded text. | |
6726 If buffer, the decoded text is inserted in the buffer. | |
6727 If t, the decoded text is returned. | |
6728 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6729 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
|
6730 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
|
6731 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6732 It returns the length of the decoded text. */) |
88365 | 6733 (start, end, coding_system, destination) |
6734 Lisp_Object start, end, coding_system, destination; | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6735 { |
88365 | 6736 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
|
6737 } |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6738 |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6739 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
88365 | 6740 3, 4, "r\nzCoding system: ", |
6741 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
|
6742 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
|
6743 START, END, and CODING-SYSTEM. START and END are buffer positions. |
88365 | 6744 |
6745 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
6746 If nil, the region between START and END is replace by the encoded text. | |
6747 If buffer, the encoded text is inserted in the buffer. | |
6748 If t, the encoded text is returned. | |
6749 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6750 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
|
6751 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
|
6752 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6753 It returns the length of the encoded text. */) |
88365 | 6754 (start, end, coding_system, destination) |
6755 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
|
6756 { |
88365 | 6757 return code_convert_region (start, end, coding_system, destination, 1, 0); |
17052 | 6758 } |
6759 | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6760 Lisp_Object |
88365 | 6761 code_convert_string (string, coding_system, dst_object, |
6762 encodep, nocopy, norecord) | |
6763 Lisp_Object string, coding_system, dst_object; | |
6764 int encodep, nocopy, norecord; | |
17052 | 6765 { |
6766 struct coding_system coding; | |
88365 | 6767 EMACS_INT chars, bytes; |
17052 | 6768 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6769 CHECK_STRING (string); |
88365 | 6770 if (NILP (coding_system)) |
6771 { | |
6772 if (! norecord) | |
6773 Vlast_coding_system_used = Qno_conversion; | |
6774 if (NILP (dst_object)) | |
6775 return (nocopy ? Fcopy_sequence (string) : string); | |
6776 } | |
17052 | 6777 |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6778 if (NILP (coding_system)) |
88365 | 6779 coding_system = Qno_conversion; |
6780 else | |
6781 CHECK_CODING_SYSTEM (coding_system); | |
6782 if (NILP (dst_object)) | |
6783 dst_object = Qt; | |
6784 else if (! EQ (dst_object, Qt)) | |
6785 CHECK_BUFFER (dst_object); | |
6786 | |
6787 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6788 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6789 chars = XSTRING (string)->size; |
6790 bytes = STRING_BYTES (XSTRING (string)); | |
6791 if (encodep) | |
6792 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6793 else | |
6794 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6795 if (! norecord) | |
6796 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6797 | |
6798 if (coding.result != CODING_RESULT_SUCCESS) | |
6799 error ("Code conversion error: %d", coding.result); | |
6800 | |
6801 return (BUFFERP (dst_object) | |
6802 ? make_number (coding.produced_char) | |
6803 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6804 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6805 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6806 |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6807 /* Encode or decode STRING according to CODING_SYSTEM. |
26847 | 6808 Do not set Vlast_coding_system_used. |
6809 | |
6810 This function is called only from macros DECODE_FILE and | |
6811 ENCODE_FILE, thus we ignore character composition. */ | |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6812 |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6813 Lisp_Object |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6814 code_convert_string_norecord (string, coding_system, encodep) |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6815 Lisp_Object string, coding_system; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6816 int encodep; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6817 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
6818 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
|
6819 } |
88365 | 6820 |
6821 | |
6822 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
6823 2, 4, 0, | |
6824 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
6825 | |
6826 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
6827 if the decoding operation is trivial. | |
6828 | |
6829 Optional fourth arg BUFFER non-nil meant that the decoded text is | |
6830 inserted in BUFFER instead of returned as a astring. In this case, | |
6831 the return value is BUFFER. | |
6832 | |
6833 This function sets `last-coding-system-used' to the precise coding system | |
6834 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6835 not fully specified. */) | |
6836 (string, coding_system, nocopy, buffer) | |
6837 Lisp_Object string, coding_system, nocopy, buffer; | |
6838 { | |
6839 return code_convert_string (string, coding_system, buffer, | |
6840 0, ! NILP (nocopy), 0); | |
6841 } | |
6842 | |
6843 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
6844 2, 4, 0, | |
6845 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
6846 | |
6847 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
6848 itself if the encoding operation is trivial. | |
6849 | |
6850 Optional fourth arg BUFFER non-nil meant that the encoded text is | |
6851 inserted in BUFFER instead of returned as a astring. In this case, | |
6852 the return value is BUFFER. | |
6853 | |
6854 This function sets `last-coding-system-used' to the precise coding system | |
6855 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6856 not fully specified.) */) | |
6857 (string, coding_system, nocopy, buffer) | |
6858 Lisp_Object string, coding_system, nocopy, buffer; | |
6859 { | |
6860 return code_convert_string (string, coding_system, buffer, | |
6861 nocopy, ! NILP (nocopy), 1); | |
6862 } | |
6863 | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6864 |
17052 | 6865 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
|
6866 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
|
6867 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
|
6868 (code) |
17052 | 6869 Lisp_Object code; |
6870 { | |
88365 | 6871 Lisp_Object spec, attrs, val; |
6872 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
6873 int c; | |
6874 | |
6875 CHECK_NATNUM (code); | |
6876 c = XFASTINT (code); | |
6877 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6878 attrs = AREF (spec, 0); | |
6879 | |
6880 if (ASCII_BYTE_P (c) | |
6881 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6882 return code; | |
6883 | |
6884 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6885 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
|
6886 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
|
6887 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 6888 |
6889 if (c <= 0x7F) | |
6890 charset = charset_roman; | |
6891 else if (c >= 0xA0 && c < 0xDF) | |
6892 { | |
6893 charset = charset_kana; | |
6894 c -= 0x80; | |
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6895 } |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6896 else |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6897 { |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
6898 int s1 = c >> 8, s2 = c & 0xFF; |
88365 | 6899 |
6900 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
6901 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
6902 error ("Invalid code: %d", code); | |
6903 SJIS_TO_JIS (c); | |
6904 charset = charset_kanji; | |
6905 } | |
6906 c = DECODE_CHAR (charset, c); | |
6907 if (c < 0) | |
6908 error ("Invalid code: %d", code); | |
6909 return make_number (c); | |
17052 | 6910 } |
6911 | |
88365 | 6912 |
17052 | 6913 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
|
6914 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
|
6915 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
|
6916 (ch) |
88365 | 6917 Lisp_Object ch; |
17052 | 6918 { |
88365 | 6919 Lisp_Object spec, attrs, charset_list; |
6920 int c; | |
6921 struct charset *charset; | |
6922 unsigned code; | |
6923 | |
6924 CHECK_CHARACTER (ch); | |
6925 c = XFASTINT (ch); | |
6926 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6927 attrs = AREF (spec, 0); | |
6928 | |
6929 if (ASCII_CHAR_P (c) | |
6930 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6931 return ch; | |
6932 | |
6933 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
6934 charset = char_charset (c, charset_list, &code); | |
6935 if (code == CHARSET_INVALID_CODE (charset)) | |
6936 error ("Can't encode by shift_jis encoding: %d", c); | |
6937 JIS_TO_SJIS (code); | |
6938 | |
6939 return make_number (code); | |
17052 | 6940 } |
6941 | |
6942 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
|
6943 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
|
6944 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
|
6945 (code) |
17052 | 6946 Lisp_Object code; |
6947 { | |
88365 | 6948 Lisp_Object spec, attrs, val; |
6949 struct charset *charset_roman, *charset_big5, *charset; | |
6950 int c; | |
6951 | |
6952 CHECK_NATNUM (code); | |
6953 c = XFASTINT (code); | |
6954 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6955 attrs = AREF (spec, 0); | |
6956 | |
6957 if (ASCII_BYTE_P (c) | |
6958 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6959 return code; | |
6960 | |
6961 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6962 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
6963 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
6964 | |
6965 if (c <= 0x7F) | |
6966 charset = charset_roman; | |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
6967 else |
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
6968 { |
88365 | 6969 int b1 = c >> 8, b2 = c & 0x7F; |
6970 if (b1 < 0xA1 || b1 > 0xFE | |
6971 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
6972 error ("Invalid code: %d", code); | |
6973 charset = charset_big5; | |
6974 } | |
6975 c = DECODE_CHAR (charset, (unsigned )c); | |
6976 if (c < 0) | |
6977 error ("Invalid code: %d", code); | |
6978 return make_number (c); | |
17052 | 6979 } |
6980 | |
6981 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
|
6982 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
|
6983 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
|
6984 (ch) |
17052 | 6985 Lisp_Object ch; |
6986 { | |
88365 | 6987 Lisp_Object spec, attrs, charset_list; |
6988 struct charset *charset; | |
6989 int c; | |
6990 unsigned code; | |
6991 | |
6992 CHECK_CHARACTER (ch); | |
6993 c = XFASTINT (ch); | |
6994 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6995 attrs = AREF (spec, 0); | |
6996 if (ASCII_CHAR_P (c) | |
6997 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6998 return ch; | |
6999 | |
7000 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
7001 charset = char_charset (c, charset_list, &code); | |
7002 if (code == CHARSET_INVALID_CODE (charset)) | |
7003 error ("Can't encode by Big5 encoding: %d", c); | |
7004 | |
7005 return make_number (code); | |
17052 | 7006 } |
88365 | 7007 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7008 |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7009 DEFUN ("set-terminal-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7010 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
|
7011 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
|
7012 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
|
7013 (coding_system) |
88473 | 7014 Lisp_Object coding_system; |
17052 | 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); |
88365 | 7017 setup_coding_system (Fcheck_coding_system (coding_system), |
7018 &terminal_coding); | |
7019 | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
7020 /* We had better not send unsafe characters to terminal. */ |
88365 | 7021 terminal_coding.mode |= CODING_MODE_SAFE_ENCODING; |
7022 /* Characer composition should be disabled. */ | |
7023 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
|
7024 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
|
7025 terminal_coding.dst_multibyte = 0; |
17052 | 7026 return Qnil; |
7027 } | |
7028 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7029 DEFUN ("set-safe-terminal-coding-system-internal", |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7030 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
|
7031 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
41006 | 7032 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
|
7033 (coding_system) |
88473 | 7034 Lisp_Object coding_system; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7035 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7036 CHECK_SYMBOL (coding_system); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7037 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
|
7038 &safe_terminal_coding); |
88365 | 7039 /* Characer composition should be disabled. */ |
7040 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
|
7041 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
|
7042 safe_terminal_coding.dst_multibyte = 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7043 return Qnil; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7044 } |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7045 |
17052 | 7046 DEFUN ("terminal-coding-system", |
7047 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
|
7048 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
|
7049 () |
17052 | 7050 { |
88365 | 7051 return CODING_ID_NAME (terminal_coding.id); |
17052 | 7052 } |
7053 | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7054 DEFUN ("set-keyboard-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7055 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
|
7056 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
|
7057 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
|
7058 (coding_system) |
17052 | 7059 Lisp_Object coding_system; |
7060 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7061 CHECK_SYMBOL (coding_system); |
88365 | 7062 setup_coding_system (Fcheck_coding_system (coding_system), |
7063 &keyboard_coding); | |
7064 /* Characer composition should be disabled. */ | |
7065 keyboard_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
17052 | 7066 return Qnil; |
7067 } | |
7068 | |
7069 DEFUN ("keyboard-coding-system", | |
7070 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
|
7071 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
|
7072 () |
17052 | 7073 { |
88365 | 7074 return CODING_ID_NAME (keyboard_coding.id); |
17052 | 7075 } |
7076 | |
7077 | |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7078 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
|
7079 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
|
7080 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
|
7081 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
|
7082 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
|
7083 \(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
|
7084 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
|
7085 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7086 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
|
7087 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
|
7088 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
|
7089 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
|
7090 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7091 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
|
7092 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
|
7093 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
|
7094 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
|
7095 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7096 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
|
7097 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
|
7098 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
|
7099 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
|
7100 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7101 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
|
7102 `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
|
7103 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
|
7104 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
|
7105 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
|
7106 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
|
7107 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
|
7108 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7109 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
|
7110 (nargs, args) |
17052 | 7111 int nargs; |
7112 Lisp_Object *args; | |
7113 { | |
7114 Lisp_Object operation, target_idx, target, val; | |
7115 register Lisp_Object chain; | |
7116 | |
7117 if (nargs < 2) | |
7118 error ("Too few arguments"); | |
7119 operation = args[0]; | |
7120 if (!SYMBOLP (operation) | |
7121 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
88365 | 7122 error ("Invalid first arguement"); |
17052 | 7123 if (nargs < 1 + XINT (target_idx)) |
7124 error ("Too few arguments for operation: %s", | |
7125 XSYMBOL (operation)->name->data); | |
7126 target = args[XINT (target_idx) + 1]; | |
7127 if (!(STRINGP (target) | |
7128 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
88365 | 7129 error ("Invalid %dth argument", XINT (target_idx) + 1); |
17052 | 7130 |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7131 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
|
7132 || EQ (operation, Qwrite_region)) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7133 ? 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
|
7134 : (EQ (operation, Qopen_network_stream) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7135 ? Vnetwork_coding_system_alist |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7136 : Vprocess_coding_system_alist)); |
17052 | 7137 if (NILP (chain)) |
7138 return Qnil; | |
7139 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7140 for (; CONSP (chain); chain = XCDR (chain)) |
17052 | 7141 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
7142 Lisp_Object elt; |
88365 | 7143 |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7144 elt = XCAR (chain); |
17052 | 7145 if (CONSP (elt) |
7146 && ((STRINGP (target) | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7147 && STRINGP (XCAR (elt)) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7148 && 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
|
7149 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7150 { |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7151 val = XCDR (elt); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7152 /* 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
|
7153 function symbol, we return VAL as a coding system. */ |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7154 if (CONSP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7155 return val; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7156 if (! SYMBOLP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7157 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7158 if (! NILP (Fcoding_system_p (val))) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7159 return Fcons (val, val); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7160 if (! NILP (Ffboundp (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7161 { |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7162 val = call1 (val, Flist (nargs, args)); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7163 if (CONSP (val)) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7164 return val; |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7165 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
|
7166 return Fcons (val, val); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7167 } |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7168 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7169 } |
17052 | 7170 } |
7171 return Qnil; | |
7172 } | |
7173 | |
88365 | 7174 DEFUN ("set-coding-system-priority", Fset_coding_system_priority, |
7175 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
|
7176 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
|
7177 usage: (set-coding-system-priority CODING-SYSTEM ...) */) |
88365 | 7178 (nargs, args) |
7179 int nargs; | |
7180 Lisp_Object *args; | |
7181 { | |
7182 int i, j; | |
7183 int changed[coding_category_max]; | |
7184 enum coding_category priorities[coding_category_max]; | |
7185 | |
7186 bzero (changed, sizeof changed); | |
7187 | |
7188 for (i = j = 0; i < nargs; i++) | |
7189 { | |
7190 enum coding_category category; | |
7191 Lisp_Object spec, attrs; | |
7192 | |
7193 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
7194 attrs = AREF (spec, 0); | |
7195 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
7196 if (changed[category]) | |
7197 /* Ignore this coding system because a coding system of the | |
7198 same category already had a higher priority. */ | |
7199 continue; | |
7200 changed[category] = 1; | |
7201 priorities[j++] = category; | |
7202 if (coding_categories[category].id >= 0 | |
7203 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
7204 setup_coding_system (args[i], &coding_categories[category]); | |
7205 } | |
7206 | |
7207 /* Now we have decided top J priorities. Reflect the order of the | |
7208 original priorities to the remaining priorities. */ | |
7209 | |
7210 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
7211 { | |
7212 while (j < coding_category_max | |
7213 && changed[coding_priorities[j]]) | |
7214 j++; | |
7215 if (j == coding_category_max) | |
7216 abort (); | |
7217 priorities[i] = coding_priorities[j]; | |
7218 } | |
7219 | |
7220 bcopy (priorities, coding_priorities, sizeof priorities); | |
7221 return Qnil; | |
7222 } | |
7223 | |
7224 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, | |
7225 Scoding_system_priority_list, 0, 1, 0, | |
7226 doc: /* Return a list of coding systems ordered by their priorities. */) | |
7227 (highestp) | |
7228 Lisp_Object highestp; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7229 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7230 int i; |
88365 | 7231 Lisp_Object val; |
7232 | |
7233 for (i = 0, val = Qnil; i < coding_category_max; i++) | |
7234 { | |
7235 enum coding_category category = coding_priorities[i]; | |
7236 int id = coding_categories[category].id; | |
7237 Lisp_Object attrs; | |
7238 | |
7239 if (id < 0) | |
7240 continue; | |
7241 attrs = CODING_ID_ATTRS (id); | |
7242 if (! NILP (highestp)) | |
7243 return CODING_ATTR_BASE_NAME (attrs); | |
7244 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
7245 } | |
7246 return Fnreverse (val); | |
7247 } | |
7248 | |
7249 static Lisp_Object | |
7250 make_subsidiaries (base) | |
7251 Lisp_Object base; | |
7252 { | |
7253 Lisp_Object subsidiaries; | |
7254 char *suffixes[] = { "-unix", "-dos", "-mac" }; | |
7255 int base_name_len = STRING_BYTES (XSYMBOL (base)->name); | |
7256 char *buf = (char *) alloca (base_name_len + 6); | |
7257 int i; | |
7258 | |
7259 bcopy (XSYMBOL (base)->name->data, buf, base_name_len); | |
7260 subsidiaries = Fmake_vector (make_number (3), Qnil); | |
7261 for (i = 0; i < 3; i++) | |
7262 { | |
7263 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
7264 ASET (subsidiaries, i, intern (buf)); | |
7265 } | |
7266 return subsidiaries; | |
7267 } | |
7268 | |
7269 | |
7270 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, | |
7271 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
|
7272 doc: /* For internal use only. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7273 usage: (define-coding-system-internal ...) */) |
88365 | 7274 (nargs, args) |
7275 int nargs; | |
7276 Lisp_Object *args; | |
7277 { | |
7278 Lisp_Object name; | |
7279 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
7280 Lisp_Object attrs; /* Vector of attributes. */ | |
7281 Lisp_Object eol_type; | |
7282 Lisp_Object aliases; | |
7283 Lisp_Object coding_type, charset_list, safe_charsets; | |
7284 enum coding_category category; | |
7285 Lisp_Object tail, val; | |
7286 int max_charset_id = 0; | |
7287 int i; | |
7288 | |
7289 if (nargs < coding_arg_max) | |
7290 goto short_args; | |
7291 | |
7292 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
7293 | |
7294 name = args[coding_arg_name]; | |
7295 CHECK_SYMBOL (name); | |
7296 CODING_ATTR_BASE_NAME (attrs) = name; | |
7297 | |
7298 val = args[coding_arg_mnemonic]; | |
7299 if (! STRINGP (val)) | |
7300 CHECK_CHARACTER (val); | |
7301 CODING_ATTR_MNEMONIC (attrs) = val; | |
7302 | |
7303 coding_type = args[coding_arg_coding_type]; | |
7304 CHECK_SYMBOL (coding_type); | |
7305 CODING_ATTR_TYPE (attrs) = coding_type; | |
7306 | |
7307 charset_list = args[coding_arg_charset_list]; | |
7308 if (SYMBOLP (charset_list)) | |
7309 { | |
7310 if (EQ (charset_list, Qiso_2022)) | |
7311 { | |
7312 if (! EQ (coding_type, Qiso_2022)) | |
7313 error ("Invalid charset-list"); | |
7314 charset_list = Viso_2022_charset_list; | |
7315 } | |
7316 else if (EQ (charset_list, Qemacs_mule)) | |
7317 { | |
7318 if (! EQ (coding_type, Qemacs_mule)) | |
7319 error ("Invalid charset-list"); | |
7320 charset_list = Vemacs_mule_charset_list; | |
7321 } | |
7322 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7323 if (max_charset_id < XFASTINT (XCAR (tail))) | |
7324 max_charset_id = XFASTINT (XCAR (tail)); | |
7325 } | |
7326 else | |
7327 { | |
7328 charset_list = Fcopy_sequence (charset_list); | |
7329 for (tail = charset_list; !NILP (tail); tail = Fcdr (tail)) | |
7330 { | |
7331 struct charset *charset; | |
7332 | |
7333 val = Fcar (tail); | |
7334 CHECK_CHARSET_GET_CHARSET (val, charset); | |
7335 if (EQ (coding_type, Qiso_2022) | |
7336 ? CHARSET_ISO_FINAL (charset) < 0 | |
7337 : EQ (coding_type, Qemacs_mule) | |
7338 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
7339 : 0) | |
7340 error ("Can't handle charset `%s'", | |
7341 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7342 | |
7343 XCAR (tail) = make_number (charset->id); | |
7344 if (max_charset_id < charset->id) | |
7345 max_charset_id = charset->id; | |
7346 } | |
7347 } | |
7348 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
7349 | |
7350 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
7351 make_number (255)); | |
7352 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7353 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
7354 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | |
7355 | |
7356 val = args[coding_arg_decode_translation_table]; | |
7357 if (! NILP (val)) | |
7358 CHECK_CHAR_TABLE (val); | |
7359 CODING_ATTR_DECODE_TBL (attrs) = val; | |
7360 | |
7361 val = args[coding_arg_encode_translation_table]; | |
7362 if (! NILP (val)) | |
7363 CHECK_CHAR_TABLE (val); | |
7364 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
7365 | |
7366 val = args[coding_arg_post_read_conversion]; | |
7367 CHECK_SYMBOL (val); | |
7368 CODING_ATTR_POST_READ (attrs) = val; | |
7369 | |
7370 val = args[coding_arg_pre_write_conversion]; | |
7371 CHECK_SYMBOL (val); | |
7372 CODING_ATTR_PRE_WRITE (attrs) = val; | |
7373 | |
7374 val = args[coding_arg_default_char]; | |
7375 if (NILP (val)) | |
7376 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
7377 else | |
7378 { | |
7379 CHECK_CHARACTER (val); | |
7380 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
7381 } | |
7382 | |
7383 val = args[coding_arg_plist]; | |
7384 CHECK_LIST (val); | |
7385 CODING_ATTR_PLIST (attrs) = val; | |
7386 | |
7387 if (EQ (coding_type, Qcharset)) | |
7388 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7389 /* Generate a lisp vector of 256 elements. Each element is nil, |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7390 integer, or a list of charset IDs. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7391 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7392 If Nth element is nil, the byte code N is invalid in this |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7393 coding system. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7394 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7395 If Nth element is a number NUM, N is the first byte of a |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7396 charset whose ID is NUM. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7397 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7398 If Nth element is a list of charset IDs, N is the first byte |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7399 of one of them. The list is sorted by dimensions of the |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7400 charsets. A charset of smaller dimension comes firtst. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7401 */ |
88365 | 7402 val = Fmake_vector (make_number (256), Qnil); |
7403 | |
7404 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7405 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7406 struct charset *charset = CHARSET_FROM_ID (XFASTINT (XCAR (tail))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7407 int dim = CHARSET_DIMENSION (charset); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7408 int idx = (dim - 1) * 4; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7409 |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7410 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
|
7411 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
|
7412 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7413 Lisp_Object tmp, tmp2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7414 int dim2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7415 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7416 tmp = AREF (val, i); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7417 if (NILP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7418 tmp = XCAR (tail); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7419 else if (NUMBERP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7420 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7421 dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (tmp))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7422 if (dim < dim2) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7423 tmp = Fcons (tmp, Fcons (XCAR (tail), Qnil)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7424 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7425 tmp = Fcons (XCAR (tail), Fcons (tmp, Qnil)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7426 } |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7427 else |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7428 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7429 for (tmp2 = tmp; CONSP (tmp2); tmp2 = XCDR (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7430 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7431 dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (XCAR (tmp2)))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7432 if (dim < dim2) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7433 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7434 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7435 if (NILP (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7436 tmp = nconc2 (tmp, Fcons (XCAR (tail), Qnil)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7437 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7438 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7439 XSETCDR (tmp2, Fcons (XCAR (tmp2), XCDR (tmp2))); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7440 XSETCAR (tmp2, XCAR (tail)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7441 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7442 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7443 ASET (val, i, tmp); |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7444 } |
88365 | 7445 } |
7446 ASET (attrs, coding_attr_charset_valids, val); | |
7447 category = coding_category_charset; | |
7448 } | |
7449 else if (EQ (coding_type, Qccl)) | |
7450 { | |
7451 Lisp_Object valids; | |
7452 | |
7453 if (nargs < coding_arg_ccl_max) | |
7454 goto short_args; | |
7455 | |
7456 val = args[coding_arg_ccl_decoder]; | |
7457 CHECK_CCL_PROGRAM (val); | |
7458 if (VECTORP (val)) | |
7459 val = Fcopy_sequence (val); | |
7460 ASET (attrs, coding_attr_ccl_decoder, val); | |
7461 | |
7462 val = args[coding_arg_ccl_encoder]; | |
7463 CHECK_CCL_PROGRAM (val); | |
7464 if (VECTORP (val)) | |
7465 val = Fcopy_sequence (val); | |
7466 ASET (attrs, coding_attr_ccl_encoder, val); | |
7467 | |
7468 val = args[coding_arg_ccl_valids]; | |
7469 valids = Fmake_string (make_number (256), make_number (0)); | |
7470 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
7471 { | |
7472 val = Fcar (tail); | |
7473 if (INTEGERP (val)) | |
7474 ASET (valids, XINT (val), 1); | |
7475 else | |
7476 { | |
7477 int from, to; | |
7478 | |
7479 CHECK_CONS (val); | |
7480 CHECK_NUMBER (XCAR (val)); | |
7481 CHECK_NUMBER (XCDR (val)); | |
7482 from = XINT (XCAR (val)); | |
7483 to = XINT (XCDR (val)); | |
7484 for (i = from; i <= to; i++) | |
7485 ASET (valids, i, 1); | |
7486 } | |
7487 } | |
7488 ASET (attrs, coding_attr_ccl_valids, valids); | |
7489 | |
7490 category = coding_category_ccl; | |
7491 } | |
7492 else if (EQ (coding_type, Qutf_16)) | |
7493 { | |
7494 Lisp_Object bom, endian; | |
7495 | |
7496 if (nargs < coding_arg_utf16_max) | |
7497 goto short_args; | |
7498 | |
7499 bom = args[coding_arg_utf16_bom]; | |
7500 if (! NILP (bom) && ! EQ (bom, Qt)) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7501 { |
88365 | 7502 CHECK_CONS (bom); |
7503 CHECK_CODING_SYSTEM (XCAR (bom)); | |
7504 CHECK_CODING_SYSTEM (XCDR (bom)); | |
7505 } | |
7506 ASET (attrs, coding_attr_utf_16_bom, bom); | |
7507 | |
7508 endian = args[coding_arg_utf16_endian]; | |
7509 ASET (attrs, coding_attr_utf_16_endian, endian); | |
7510 | |
7511 category = (CONSP (bom) | |
7512 ? coding_category_utf_16_auto | |
7513 : NILP (bom) | |
7514 ? (NILP (endian) | |
7515 ? coding_category_utf_16_be_nosig | |
7516 : coding_category_utf_16_le_nosig) | |
7517 : (NILP (endian) | |
7518 ? coding_category_utf_16_be | |
7519 : coding_category_utf_16_le)); | |
7520 } | |
7521 else if (EQ (coding_type, Qiso_2022)) | |
7522 { | |
7523 Lisp_Object initial, reg_usage, request, flags; | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7524 int i, id; |
88365 | 7525 |
7526 if (nargs < coding_arg_iso2022_max) | |
7527 goto short_args; | |
7528 | |
7529 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
7530 CHECK_VECTOR (initial); | |
7531 for (i = 0; i < 4; i++) | |
7532 { | |
7533 val = Faref (initial, make_number (i)); | |
7534 if (! NILP (val)) | |
7535 { | |
7536 CHECK_CHARSET_GET_ID (val, id); | |
7537 ASET (initial, i, make_number (id)); | |
7538 } | |
7539 else | |
7540 ASET (initial, i, make_number (-1)); | |
7541 } | |
7542 | |
7543 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
7544 CHECK_CONS (reg_usage); | |
7545 CHECK_NATNUM (XCAR (reg_usage)); | |
7546 CHECK_NATNUM (XCDR (reg_usage)); | |
7547 | |
7548 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
7549 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
7550 { | |
7551 int id; | |
7552 | |
7553 val = Fcar (tail); | |
7554 CHECK_CONS (val); | |
7555 CHECK_CHARSET_GET_ID (XCAR (val), id); | |
7556 CHECK_NATNUM (XCDR (val)); | |
7557 if (XINT (XCDR (val)) >= 4) | |
7558 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
7559 XCAR (val) = make_number (id); | |
7560 } | |
7561 | |
7562 flags = args[coding_arg_iso2022_flags]; | |
7563 CHECK_NATNUM (flags); | |
7564 i = XINT (flags); | |
7565 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
7566 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
7567 | |
7568 ASET (attrs, coding_attr_iso_initial, initial); | |
7569 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
7570 ASET (attrs, coding_attr_iso_request, request); | |
7571 ASET (attrs, coding_attr_iso_flags, flags); | |
7572 setup_iso_safe_charsets (attrs); | |
7573 | |
7574 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
7575 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7576 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7577 ? coding_category_iso_7_else | |
7578 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
7579 ? coding_category_iso_7 | |
7580 : coding_category_iso_7_tight); | |
7581 else | |
7582 { | |
7583 int id = XINT (AREF (initial, 1)); | |
7584 | |
7585 category = (((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7586 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7587 || EQ (args[coding_arg_charset_list], Qiso_2022) | |
7588 || id < 0) | |
7589 ? coding_category_iso_8_else | |
7590 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
7591 ? coding_category_iso_8_1 | |
7592 : coding_category_iso_8_2); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7593 } |
88365 | 7594 } |
7595 else if (EQ (coding_type, Qemacs_mule)) | |
7596 { | |
7597 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
7598 ASET (attrs, coding_attr_emacs_mule_full, Qt); | |
7599 | |
7600 category = coding_category_emacs_mule; | |
7601 } | |
7602 else if (EQ (coding_type, Qshift_jis)) | |
7603 { | |
7604 | |
7605 struct charset *charset; | |
7606 | |
7607 if (XINT (Flength (charset_list)) != 3) | |
7608 error ("There should be just three charsets"); | |
7609 | |
7610 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7611 if (CHARSET_DIMENSION (charset) != 1) | |
7612 error ("Dimension of charset %s is not one", | |
7613 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7614 | |
7615 charset_list = XCDR (charset_list); | |
7616 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7617 if (CHARSET_DIMENSION (charset) != 1) | |
7618 error ("Dimension of charset %s is not one", | |
7619 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7620 | |
7621 charset_list = XCDR (charset_list); | |
7622 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7623 if (CHARSET_DIMENSION (charset) != 2) | |
7624 error ("Dimension of charset %s is not two", | |
7625 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7626 | |
7627 category = coding_category_sjis; | |
7628 Vsjis_coding_system = name; | |
7629 } | |
7630 else if (EQ (coding_type, Qbig5)) | |
7631 { | |
7632 struct charset *charset; | |
7633 | |
7634 if (XINT (Flength (charset_list)) != 2) | |
7635 error ("There should be just two charsets"); | |
7636 | |
7637 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7638 if (CHARSET_DIMENSION (charset) != 1) | |
7639 error ("Dimension of charset %s is not one", | |
7640 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7641 | |
7642 charset_list = XCDR (charset_list); | |
7643 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7644 if (CHARSET_DIMENSION (charset) != 2) | |
7645 error ("Dimension of charset %s is not two", | |
7646 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7647 | |
7648 category = coding_category_big5; | |
7649 Vbig5_coding_system = name; | |
7650 } | |
7651 else if (EQ (coding_type, Qraw_text)) | |
7652 category = coding_category_raw_text; | |
7653 else if (EQ (coding_type, Qutf_8)) | |
7654 category = coding_category_utf_8; | |
7655 else if (EQ (coding_type, Qundecided)) | |
7656 category = coding_category_undecided; | |
7657 else | |
7658 error ("Invalid coding system type: %s", | |
7659 XSYMBOL (coding_type)->name->data); | |
7660 | |
7661 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
7662 | |
7663 eol_type = args[coding_arg_eol_type]; | |
7664 if (! NILP (eol_type) | |
7665 && ! EQ (eol_type, Qunix) | |
7666 && ! EQ (eol_type, Qdos) | |
7667 && ! EQ (eol_type, Qmac)) | |
7668 error ("Invalid eol-type"); | |
7669 | |
7670 aliases = Fcons (name, Qnil); | |
7671 | |
7672 if (NILP (eol_type)) | |
7673 { | |
7674 eol_type = make_subsidiaries (name); | |
7675 for (i = 0; i < 3; i++) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7676 { |
88365 | 7677 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
7678 | |
7679 this_name = AREF (eol_type, i); | |
7680 this_aliases = Fcons (this_name, Qnil); | |
7681 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
7682 this_spec = Fmake_vector (make_number (3), attrs); | |
7683 ASET (this_spec, 1, this_aliases); | |
7684 ASET (this_spec, 2, this_eol_type); | |
7685 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
7686 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
7687 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (this_name), Qnil), | |
7688 Vcoding_system_alist); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7689 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7690 } |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7691 |
88365 | 7692 spec_vec = Fmake_vector (make_number (3), attrs); |
7693 ASET (spec_vec, 1, aliases); | |
7694 ASET (spec_vec, 2, eol_type); | |
7695 | |
7696 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
7697 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
7698 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), | |
7699 Vcoding_system_alist); | |
7700 | |
7701 { | |
7702 int id = coding_categories[category].id; | |
7703 | |
7704 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
7705 setup_coding_system (name, &coding_categories[category]); | |
7706 } | |
7707 | |
7708 return Qnil; | |
7709 | |
7710 short_args: | |
7711 return Fsignal (Qwrong_number_of_arguments, | |
7712 Fcons (intern ("define-coding-system-internal"), | |
7713 make_number (nargs))); | |
7714 } | |
7715 | |
7716 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, | |
7717 Sdefine_coding_system_alias, 2, 2, 0, | |
7718 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
7719 (alias, coding_system) | |
7720 Lisp_Object alias, coding_system; | |
7721 { | |
7722 Lisp_Object spec, aliases, eol_type; | |
7723 | |
7724 CHECK_SYMBOL (alias); | |
7725 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7726 aliases = AREF (spec, 1); | |
7727 while (!NILP (XCDR (aliases))) | |
7728 aliases = XCDR (aliases); | |
7729 XCDR (aliases) = Fcons (alias, Qnil); | |
7730 | |
7731 eol_type = AREF (spec, 2); | |
7732 if (VECTORP (eol_type)) | |
7733 { | |
7734 Lisp_Object subsidiaries; | |
7735 int i; | |
7736 | |
7737 subsidiaries = make_subsidiaries (alias); | |
7738 for (i = 0; i < 3; i++) | |
7739 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
7740 AREF (eol_type, i)); | |
7741 | |
7742 ASET (spec, 2, subsidiaries); | |
7743 } | |
7744 | |
7745 Fputhash (alias, spec, Vcoding_system_hash_table); | |
88485 | 7746 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
7747 Vcoding_system_alist); | |
88365 | 7748 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7749 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7750 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7751 |
88365 | 7752 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
7753 1, 1, 0, | |
7754 doc: /* Return the base of CODING-SYSTEM. | |
7755 Any alias or subsidiary coding systems are not base coding system. */) | |
7756 (coding_system) | |
7757 Lisp_Object coding_system; | |
7758 { | |
7759 Lisp_Object spec, attrs; | |
7760 | |
7761 if (NILP (coding_system)) | |
7762 return (Qno_conversion); | |
7763 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7764 attrs = AREF (spec, 0); | |
7765 return CODING_ATTR_BASE_NAME (attrs); | |
7766 } | |
7767 | |
7768 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
7769 1, 1, 0, | |
7770 doc: "Return the property list of CODING-SYSTEM.") | |
7771 (coding_system) | |
7772 Lisp_Object coding_system; | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7773 { |
88365 | 7774 Lisp_Object spec, attrs; |
7775 | |
7776 if (NILP (coding_system)) | |
7777 coding_system = Qno_conversion; | |
7778 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7779 attrs = AREF (spec, 0); | |
7780 return CODING_ATTR_PLIST (attrs); | |
7781 } | |
7782 | |
7783 | |
7784 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
7785 1, 1, 0, | |
7786 doc: /* Return the list of aliases of CODING-SYSTEM. | |
7787 A base coding system is what made by `define-coding-system'. | |
7788 Any alias nor subsidiary coding systems are not base coding system. */) | |
7789 (coding_system) | |
7790 Lisp_Object coding_system; | |
7791 { | |
7792 Lisp_Object spec; | |
7793 | |
7794 if (NILP (coding_system)) | |
7795 coding_system = Qno_conversion; | |
7796 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7797 return AREF (spec, 2); | |
7798 } | |
7799 | |
7800 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
7801 Scoding_system_eol_type, 1, 1, 0, | |
7802 doc: /* Return eol-type of CODING-SYSTEM. | |
7803 An eol-type is integer 0, 1, 2, or a vector of coding systems. | |
7804 | |
7805 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
7806 and CR respectively. | |
7807 | |
7808 A vector value indicates that a format of end-of-line should be | |
7809 detected automatically. Nth element of the vector is the subsidiary | |
7810 coding system whose eol-type is N. */) | |
7811 (coding_system) | |
7812 Lisp_Object coding_system; | |
7813 { | |
7814 Lisp_Object spec, eol_type; | |
7815 int n; | |
7816 | |
7817 if (NILP (coding_system)) | |
7818 coding_system = Qno_conversion; | |
7819 if (! CODING_SYSTEM_P (coding_system)) | |
7820 return Qnil; | |
7821 spec = CODING_SYSTEM_SPEC (coding_system); | |
7822 eol_type = AREF (spec, 2); | |
7823 if (VECTORP (eol_type)) | |
7824 return Fcopy_sequence (eol_type); | |
7825 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
7826 return make_number (n); | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7827 } |
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7828 |
17052 | 7829 #endif /* emacs */ |
7830 | |
7831 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7832 /*** 9. Post-amble ***/ |
17052 | 7833 |
21514 | 7834 void |
17052 | 7835 init_coding_once () |
7836 { | |
7837 int i; | |
7838 | |
88365 | 7839 for (i = 0; i < coding_category_max; i++) |
7840 { | |
7841 coding_categories[i].id = -1; | |
7842 coding_priorities[i] = i; | |
7843 } | |
17052 | 7844 |
7845 /* ISO2022 specific initialize routine. */ | |
7846 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
|
7847 iso_code_class[i] = ISO_control_0; |
17052 | 7848 for (i = 0x21; i < 0x7F; i++) |
7849 iso_code_class[i] = ISO_graphic_plane_0; | |
7850 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
|
7851 iso_code_class[i] = ISO_control_1; |
17052 | 7852 for (i = 0xA1; i < 0xFF; i++) |
7853 iso_code_class[i] = ISO_graphic_plane_1; | |
7854 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
7855 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
7856 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
7857 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
7858 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
7859 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
7860 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
7861 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
7862 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
7863 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
7864 | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
7865 inhibit_pre_post_conversion = 0; |
88365 | 7866 |
7867 for (i = 0; i < 256; i++) | |
7868 { | |
7869 emacs_mule_bytes[i] = 1; | |
7870 } | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
7871 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
|
7872 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
|
7873 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
|
7874 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
|
7875 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7876 |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7877 #ifdef emacs |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7878 |
21514 | 7879 void |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7880 syms_of_coding () |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7881 { |
88365 | 7882 staticpro (&Vcoding_system_hash_table); |
7883 Vcoding_system_hash_table = Fmakehash (Qeq); | |
7884 | |
7885 staticpro (&Vsjis_coding_system); | |
7886 Vsjis_coding_system = Qnil; | |
7887 | |
7888 staticpro (&Vbig5_coding_system); | |
7889 Vbig5_coding_system = Qnil; | |
7890 | |
7891 staticpro (&Vcode_conversion_work_buf_list); | |
7892 Vcode_conversion_work_buf_list = Qnil; | |
7893 | |
7894 staticpro (&Vcode_conversion_reused_work_buf); | |
7895 Vcode_conversion_reused_work_buf = Qnil; | |
7896 | |
7897 DEFSYM (Qcharset, "charset"); | |
7898 DEFSYM (Qtarget_idx, "target-idx"); | |
7899 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7900 Fset (Qcoding_system_history, Qnil); |
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7901 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7902 /* 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
|
7903 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
|
7904 /* 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
|
7905 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
|
7906 |
88365 | 7907 DEFSYM (Qcall_process, "call-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7908 /* 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
|
7909 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
|
7910 |
88365 | 7911 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
|
7912 /* 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
|
7913 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
|
7914 |
88365 | 7915 DEFSYM (Qstart_process, "start-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7916 /* 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
|
7917 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
|
7918 |
88365 | 7919 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
|
7920 /* 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
|
7921 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
|
7922 |
88365 | 7923 DEFSYM (Qcoding_system, "coding-system"); |
7924 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
7925 | |
7926 DEFSYM (Qeol_type, "eol-type"); | |
7927 DEFSYM (Qunix, "unix"); | |
7928 DEFSYM (Qdos, "dos"); | |
7929 DEFSYM (Qmac, "mac"); | |
7930 | |
7931 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
7932 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
7933 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
7934 DEFSYM (Qdefault_char, "default-char"); | |
7935 DEFSYM (Qundecided, "undecided"); | |
7936 DEFSYM (Qno_conversion, "no-conversion"); | |
7937 DEFSYM (Qraw_text, "raw-text"); | |
7938 | |
7939 DEFSYM (Qiso_2022, "iso-2022"); | |
7940 | |
7941 DEFSYM (Qutf_8, "utf-8"); | |
7942 | |
7943 DEFSYM (Qutf_16, "utf-16"); | |
7944 DEFSYM (Qutf_16_be, "utf-16-be"); | |
7945 DEFSYM (Qutf_16_be_nosig, "utf-16-be-nosig"); | |
7946 DEFSYM (Qutf_16_le, "utf-16-l3"); | |
7947 DEFSYM (Qutf_16_le_nosig, "utf-16-le-nosig"); | |
7948 DEFSYM (Qsignature, "signature"); | |
7949 DEFSYM (Qendian, "endian"); | |
7950 DEFSYM (Qbig, "big"); | |
7951 DEFSYM (Qlittle, "little"); | |
7952 | |
7953 DEFSYM (Qshift_jis, "shift-jis"); | |
7954 DEFSYM (Qbig5, "big5"); | |
7955 | |
7956 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
7957 | |
7958 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
17052 | 7959 Fput (Qcoding_system_error, Qerror_conditions, |
7960 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
7961 Fput (Qcoding_system_error, Qerror_message, | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7962 build_string ("Invalid coding system")); |
17052 | 7963 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7964 /* 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
|
7965 Setting this variable twice is harmless. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7966 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
|
7967 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
88365 | 7968 |
7969 DEFSYM (Qtranslation_table, "translation-table"); | |
7970 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); | |
7971 DEFSYM (Qtranslation_table_id, "translation-table-id"); | |
7972 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
7973 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
7974 | |
7975 DEFSYM (Qvalid_codes, "valid-codes"); | |
7976 | |
7977 DEFSYM (Qemacs_mule, "emacs-mule"); | |
7978 | |
7979 Vcoding_category_table | |
7980 = Fmake_vector (make_number (coding_category_max), Qnil); | |
7981 staticpro (&Vcoding_category_table); | |
7982 /* Followings are target of code detection. */ | |
7983 ASET (Vcoding_category_table, coding_category_iso_7, | |
7984 intern ("coding-category-iso-7")); | |
7985 ASET (Vcoding_category_table, coding_category_iso_7_tight, | |
7986 intern ("coding-category-iso-7-tight")); | |
7987 ASET (Vcoding_category_table, coding_category_iso_8_1, | |
7988 intern ("coding-category-iso-8-1")); | |
7989 ASET (Vcoding_category_table, coding_category_iso_8_2, | |
7990 intern ("coding-category-iso-8-2")); | |
7991 ASET (Vcoding_category_table, coding_category_iso_7_else, | |
7992 intern ("coding-category-iso-7-else")); | |
7993 ASET (Vcoding_category_table, coding_category_iso_8_else, | |
7994 intern ("coding-category-iso-8-else")); | |
7995 ASET (Vcoding_category_table, coding_category_utf_8, | |
7996 intern ("coding-category-utf-8")); | |
7997 ASET (Vcoding_category_table, coding_category_utf_16_be, | |
7998 intern ("coding-category-utf-16-be")); | |
7999 ASET (Vcoding_category_table, coding_category_utf_16_le, | |
8000 intern ("coding-category-utf-16-le")); | |
8001 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, | |
8002 intern ("coding-category-utf-16-be-nosig")); | |
8003 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, | |
8004 intern ("coding-category-utf-16-le-nosig")); | |
8005 ASET (Vcoding_category_table, coding_category_charset, | |
8006 intern ("coding-category-charset")); | |
8007 ASET (Vcoding_category_table, coding_category_sjis, | |
8008 intern ("coding-category-sjis")); | |
8009 ASET (Vcoding_category_table, coding_category_big5, | |
8010 intern ("coding-category-big5")); | |
8011 ASET (Vcoding_category_table, coding_category_ccl, | |
8012 intern ("coding-category-ccl")); | |
8013 ASET (Vcoding_category_table, coding_category_emacs_mule, | |
8014 intern ("coding-category-emacs-mule")); | |
8015 /* Followings are NOT target of code detection. */ | |
8016 ASET (Vcoding_category_table, coding_category_raw_text, | |
8017 intern ("coding-category-raw-text")); | |
8018 ASET (Vcoding_category_table, coding_category_undecided, | |
8019 intern ("coding-category-undecided")); | |
8020 | |
17052 | 8021 defsubr (&Scoding_system_p); |
8022 defsubr (&Sread_coding_system); | |
8023 defsubr (&Sread_non_nil_coding_system); | |
8024 defsubr (&Scheck_coding_system); | |
8025 defsubr (&Sdetect_coding_region); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8026 defsubr (&Sdetect_coding_string); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8027 defsubr (&Sfind_coding_systems_region_internal); |
88365 | 8028 defsubr (&Scheck_coding_systems_region); |
17052 | 8029 defsubr (&Sdecode_coding_region); |
8030 defsubr (&Sencode_coding_region); | |
8031 defsubr (&Sdecode_coding_string); | |
8032 defsubr (&Sencode_coding_string); | |
8033 defsubr (&Sdecode_sjis_char); | |
8034 defsubr (&Sencode_sjis_char); | |
8035 defsubr (&Sdecode_big5_char); | |
8036 defsubr (&Sencode_big5_char); | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8037 defsubr (&Sset_terminal_coding_system_internal); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8038 defsubr (&Sset_safe_terminal_coding_system_internal); |
17052 | 8039 defsubr (&Sterminal_coding_system); |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8040 defsubr (&Sset_keyboard_coding_system_internal); |
17052 | 8041 defsubr (&Skeyboard_coding_system); |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
8042 defsubr (&Sfind_operation_coding_system); |
88365 | 8043 defsubr (&Sset_coding_system_priority); |
8044 defsubr (&Sdefine_coding_system_internal); | |
8045 defsubr (&Sdefine_coding_system_alias); | |
8046 defsubr (&Scoding_system_base); | |
8047 defsubr (&Scoding_system_plist); | |
8048 defsubr (&Scoding_system_aliases); | |
8049 defsubr (&Scoding_system_eol_type); | |
8050 defsubr (&Scoding_system_priority_list); | |
17052 | 8051 |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8052 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
|
8053 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
|
8054 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8055 Do not alter the value of this variable manually. This variable should be |
88365 | 8056 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
|
8057 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8058 Vcoding_system_list = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8059 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8060 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
|
8061 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
|
8062 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
|
8063 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
|
8064 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8065 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
|
8066 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
|
8067 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8068 Vcoding_system_alist = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8069 |
17052 | 8070 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
|
8071 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
|
8072 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8073 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
|
8074 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
|
8075 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
|
8076 system bound to the corresponding coding-category is selected. */); |
17052 | 8077 { |
8078 int i; | |
8079 | |
8080 Vcoding_category_list = Qnil; | |
88365 | 8081 for (i = coding_category_max - 1; i >= 0; i--) |
17052 | 8082 Vcoding_category_list |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8083 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8084 Vcoding_category_list); |
17052 | 8085 } |
8086 | |
8087 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
|
8088 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
|
8089 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
|
8090 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
|
8091 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
|
8092 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
|
8093 `process-coding-system-alist', and `network-coding-system-alist'. */); |
17052 | 8094 Vcoding_system_for_read = Qnil; |
8095 | |
8096 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
|
8097 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
|
8098 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
|
8099 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
|
8100 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
|
8101 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8102 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
|
8103 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
|
8104 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
|
8105 `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
|
8106 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
|
8107 the value of `buffer-file-coding-system' is used. */); |
17052 | 8108 Vcoding_system_for_write = Qnil; |
8109 | |
8110 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
88365 | 8111 doc: /* |
8112 Coding system used in the latest file or process I/O. */); | |
17052 | 8113 Vlast_coding_system_used = Qnil; |
8114 | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8115 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
88365 | 8116 doc: /* |
8117 *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
|
8118 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
|
8119 such conversion. */); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8120 inhibit_eol_conversion = 0; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8121 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8122 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
88365 | 8123 doc: /* |
8124 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
|
8125 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
|
8126 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
|
8127 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
|
8128 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8129 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
88365 | 8130 doc: /* |
8131 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
|
8132 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
|
8133 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
|
8134 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
|
8135 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
|
8136 the file contents. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8137 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
|
8138 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
|
8139 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
|
8140 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
|
8141 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
|
8142 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8143 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
|
8144 and the variable `auto-coding-alist'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8145 Vfile_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8146 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8147 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
88365 | 8148 doc: /* |
8149 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
|
8150 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
|
8151 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
|
8152 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
|
8153 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
|
8154 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
|
8155 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
|
8156 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
|
8157 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
|
8158 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
|
8159 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8160 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8161 Vprocess_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8162 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8163 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
88365 | 8164 doc: /* |
8165 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
|
8166 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
|
8167 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
|
8168 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
|
8169 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
|
8170 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
|
8171 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
|
8172 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
|
8173 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
|
8174 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
|
8175 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
|
8176 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8177 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8178 Vnetwork_coding_system_alist = Qnil; |
17052 | 8179 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8180 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
|
8181 doc: /* Coding system to use with system messages. |
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8182 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
|
8183 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
|
8184 |
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
8185 /* 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
|
8186 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
88365 | 8187 doc: /* |
8188 *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
|
8189 eol_mnemonic_unix = build_string (":"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8190 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8191 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
88365 | 8192 doc: /* |
8193 *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
|
8194 eol_mnemonic_dos = build_string ("\\"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8195 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8196 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
88365 | 8197 doc: /* |
8198 *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
|
8199 eol_mnemonic_mac = build_string ("/"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8200 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8201 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
88365 | 8202 doc: /* |
8203 *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
|
8204 eol_mnemonic_undecided = build_string (":"); |
17052 | 8205 |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8206 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
88365 | 8207 doc: /* |
8208 *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
|
8209 Venable_character_translation = Qt; |
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8210 |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8211 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
|
8212 &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
|
8213 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
|
8214 Vstandard_translation_table_for_decode = Qnil; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8215 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8216 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
|
8217 &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
|
8218 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
|
8219 Vstandard_translation_table_for_encode = Qnil; |
17052 | 8220 |
88365 | 8221 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
|
8222 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
|
8223 While encoding, if a charset (car part of an element) is found, |
88365 | 8224 designate it with the escape sequence identifying revision (cdr part |
8225 of the element). */); | |
8226 Vcharset_revision_table = Qnil; | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8227 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8228 DEFVAR_LISP ("default-process-coding-system", |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8229 &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
|
8230 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
|
8231 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
|
8232 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
|
8233 Vdefault_process_coding_system = Qnil; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8234 |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8235 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
88365 | 8236 doc: /* |
8237 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
|
8238 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
|
8239 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
|
8240 \(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
|
8241 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
|
8242 `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
|
8243 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
|
8244 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
|
8245 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
|
8246 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8247 DEFVAR_LISP ("select-safe-coding-system-function", |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8248 &Vselect_safe_coding_system_function, |
88365 | 8249 doc: /* |
8250 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
|
8251 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8252 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
|
8253 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
|
8254 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
|
8255 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8256 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
|
8257 Vselect_safe_coding_system_function = Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8258 |
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
8259 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8260 &inhibit_iso_escape_detection, |
88365 | 8261 doc: /* |
8262 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
|
8263 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8264 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
|
8265 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
|
8266 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
|
8267 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
|
8268 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
|
8269 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8270 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
|
8271 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
|
8272 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
|
8273 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
|
8274 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
|
8275 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8276 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
|
8277 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
|
8278 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
|
8279 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
|
8280 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
|
8281 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8282 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
|
8283 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
|
8284 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
|
8285 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
|
8286 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8287 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8288 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
|
8289 Lisp_Object plist[14]; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8290 int i; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8291 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8292 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
|
8293 args[i] = Qnil; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8294 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8295 plist[0] = intern (":name"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8296 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
|
8297 plist[2] = intern (":mnemonic"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8298 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
|
8299 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
|
8300 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
|
8301 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
|
8302 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
|
8303 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
|
8304 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
|
8305 plist[10] = intern (":docstring"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8306 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
|
8307 \n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8308 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
|
8309 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
|
8310 character."); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8311 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
|
8312 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
|
8313 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
|
8314 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
|
8315 } |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8316 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8317 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
|
8318 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
|
8319 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
17052 | 8320 } |
8321 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8322 char * |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8323 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
|
8324 int error_number; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8325 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8326 char *str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8327 |
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
8328 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
|
8329 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
|
8330 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8331 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
|
8332 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8333 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
|
8334 Vlocale_coding_system, |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8335 0); |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8336 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
|
8337 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8338 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8339 return str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8340 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8341 |
17052 | 8342 #endif /* emacs */ |