Mercurial > emacs
annotate src/coding.c @ 88632:443aecffdcc5
(Ffontset_info): Doc fix. Return charset names, not
ids.
(font-encoding-alist): Doc fix.
author | Dave Love <fx@gnu.org> |
---|---|
date | Sat, 25 May 2002 12:43:42 +0000 |
parents | 780b91d4a7e5 |
children | d099a8b267fe |
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 | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2208 setup_iso_safe_charsets (attrs) |
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2209 Lisp_Object attrs; |
88365 | 2210 { |
2211 Lisp_Object charset_list, safe_charsets; | |
2212 Lisp_Object request; | |
2213 Lisp_Object reg_usage; | |
2214 Lisp_Object tail; | |
2215 int reg94, reg96; | |
2216 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
2217 int max_charset_id; | |
2218 | |
2219 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
2220 if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) | |
2221 && ! EQ (charset_list, Viso_2022_charset_list)) | |
2222 { | |
2223 CODING_ATTR_CHARSET_LIST (attrs) | |
2224 = charset_list = Viso_2022_charset_list; | |
2225 ASET (attrs, coding_attr_safe_charsets, Qnil); | |
2226 } | |
2227 | |
2228 if (STRINGP (AREF (attrs, coding_attr_safe_charsets))) | |
2229 return; | |
2230 | |
2231 max_charset_id = 0; | |
2232 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2233 { | |
2234 int id = XINT (XCAR (tail)); | |
2235 if (max_charset_id < id) | |
2236 max_charset_id = id; | |
2237 } | |
2238 | |
2239 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
2240 make_number (255)); | |
2241 request = AREF (attrs, coding_attr_iso_request); | |
2242 reg_usage = AREF (attrs, coding_attr_iso_usage); | |
2243 reg94 = XINT (XCAR (reg_usage)); | |
2244 reg96 = XINT (XCDR (reg_usage)); | |
2245 | |
2246 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2247 { | |
2248 Lisp_Object id; | |
2249 Lisp_Object reg; | |
2250 struct charset *charset; | |
2251 | |
2252 id = XCAR (tail); | |
2253 charset = CHARSET_FROM_ID (XINT (id)); | |
2254 reg = Fcdr (Fassq (request, id)); | |
2255 if (! NILP (reg)) | |
2256 XSTRING (safe_charsets)->data[XINT (id)] = XINT (reg); | |
2257 else if (charset->iso_chars_96) | |
2258 { | |
2259 if (reg96 < 4) | |
2260 XSTRING (safe_charsets)->data[XINT (id)] = reg96; | |
2261 } | |
2262 else | |
2263 { | |
2264 if (reg94 < 4) | |
2265 XSTRING (safe_charsets)->data[XINT (id)] = reg94; | |
2266 } | |
2267 } | |
2268 ASET (attrs, coding_attr_safe_charsets, safe_charsets); | |
2269 } | |
2270 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2271 |
17052 | 2272 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
88365 | 2273 Check if a text is encoded in ISO2022. If it is, returns an |
17052 | 2274 integer in which appropriate flag bits any of: |
88365 | 2275 CATEGORY_MASK_ISO_7 |
2276 CATEGORY_MASK_ISO_7_TIGHT | |
2277 CATEGORY_MASK_ISO_8_1 | |
2278 CATEGORY_MASK_ISO_8_2 | |
2279 CATEGORY_MASK_ISO_7_ELSE | |
2280 CATEGORY_MASK_ISO_8_ELSE | |
17052 | 2281 are set. If a code which should never appear in ISO2022 is found, |
2282 returns 0. */ | |
2283 | |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
2284 static int |
88365 | 2285 detect_coding_iso_2022 (coding, mask) |
2286 struct coding_system *coding; | |
2287 int *mask; | |
17052 | 2288 { |
88365 | 2289 unsigned char *src = coding->source, *src_base = src; |
2290 unsigned char *src_end = coding->source + coding->src_bytes; | |
2291 int multibytep = coding->src_multibyte; | |
2292 int mask_iso = CATEGORY_MASK_ISO; | |
2293 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
|
2294 int reg[4], shift_out = 0, single_shifting = 0; |
88365 | 2295 int id; |
2296 int c, c1; | |
2297 int consumed_chars = 0; | |
2298 int i; | |
2299 | |
2300 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | |
2301 { | |
2302 struct coding_system *this = &(coding_categories[i]); | |
2303 Lisp_Object attrs, val; | |
2304 | |
2305 attrs = CODING_ID_ATTRS (this->id); | |
2306 if (CODING_ISO_FLAGS (this) & CODING_ISO_FLAG_FULL_SUPPORT | |
2307 && ! EQ (CODING_ATTR_SAFE_CHARSETS (attrs), Viso_2022_charset_list)) | |
2308 setup_iso_safe_charsets (attrs); | |
2309 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
2310 this->max_charset_id = XSTRING (val)->size - 1; | |
2311 this->safe_charsets = (char *) XSTRING (val)->data; | |
2312 } | |
2313 | |
2314 /* A coding system of this category is always ASCII compatible. */ | |
2315 src += coding->head_ascii; | |
2316 | |
2317 reg[0] = charset_ascii, reg[1] = reg[2] = reg[3] = -1; | |
2318 while (mask_iso && src < src_end) | |
2319 { | |
2320 ONE_MORE_BYTE (c); | |
17052 | 2321 switch (c) |
2322 { | |
2323 case ISO_CODE_ESC: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2324 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2325 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2326 single_shifting = 0; |
88365 | 2327 ONE_MORE_BYTE (c); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2328 if (c >= '(' && c <= '/') |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2329 { |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2330 /* Designation sequence for a charset of dimension 1. */ |
88365 | 2331 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2332 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2333 || (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
|
2334 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2335 break; |
88365 | 2336 reg[(c - '(') % 4] = id; |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2337 } |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2338 else if (c == '$') |
17052 | 2339 { |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2340 /* Designation sequence for a charset of dimension 2. */ |
88365 | 2341 ONE_MORE_BYTE (c); |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2342 if (c >= '@' && c <= 'B') |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2343 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
88365 | 2344 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
|
2345 else if (c >= '(' && c <= '/') |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2346 { |
88365 | 2347 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2348 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2349 || (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
|
2350 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2351 break; |
88365 | 2352 reg[(c - '(') % 4] = id; |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2353 } |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2354 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2355 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2356 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2357 } |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2358 else if (c == 'N' || c == 'O') |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2359 { |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2360 /* ESC <Fe> for SS2 or SS3. */ |
88365 | 2361 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
|
2362 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2363 } |
26847 | 2364 else if (c >= '0' && c <= '4') |
2365 { | |
2366 /* ESC <Fp> for start/end composition. */ | |
88365 | 2367 mask_found |= CATEGORY_MASK_ISO; |
26847 | 2368 break; |
2369 } | |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2370 else |
88365 | 2371 { |
2372 /* Invalid escape sequence. */ | |
2373 mask_iso &= ~CATEGORY_MASK_ISO_ESCAPE; | |
2374 break; | |
2375 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2376 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2377 /* We found a valid designation sequence for CHARSET. */ |
88365 | 2378 mask_iso &= ~CATEGORY_MASK_ISO_8BIT; |
2379 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7], | |
2380 id)) | |
2381 mask_found |= CATEGORY_MASK_ISO_7; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2382 else |
88365 | 2383 mask_iso &= ~CATEGORY_MASK_ISO_7; |
2384 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_tight], | |
2385 id)) | |
2386 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
|
2387 else |
88365 | 2388 mask_iso &= ~CATEGORY_MASK_ISO_7_TIGHT; |
2389 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_else], | |
2390 id)) | |
2391 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
|
2392 else |
88365 | 2393 mask_iso &= ~CATEGORY_MASK_ISO_7_ELSE; |
2394 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_8_else], | |
2395 id)) | |
2396 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
|
2397 else |
88365 | 2398 mask_iso &= ~CATEGORY_MASK_ISO_8_ELSE; |
17052 | 2399 break; |
2400 | |
2401 case ISO_CODE_SO: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2402 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2403 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2404 single_shifting = 0; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2405 if (shift_out == 0 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2406 && (reg[1] >= 0 |
88365 | 2407 || SHIFT_OUT_OK (coding_category_iso_7_else) |
2408 || 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
|
2409 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2410 /* Locking shift out. */ |
88365 | 2411 mask_iso &= ~CATEGORY_MASK_ISO_7BIT; |
2412 mask_found |= CATEGORY_MASK_ISO_ELSE; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2413 } |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2414 break; |
88365 | 2415 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2416 case ISO_CODE_SI: |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2417 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2418 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2419 single_shifting = 0; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2420 if (shift_out == 1) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2421 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2422 /* Locking shift in. */ |
88365 | 2423 mask_iso &= ~CATEGORY_MASK_ISO_7BIT; |
2424 mask_found |= CATEGORY_MASK_ISO_ELSE; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2425 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2426 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2427 |
17052 | 2428 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
|
2429 single_shifting = 0; |
17052 | 2430 case ISO_CODE_SS2: |
2431 case ISO_CODE_SS3: | |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2432 { |
88365 | 2433 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
|
2434 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2435 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2436 break; |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2437 if (c != ISO_CODE_CSI) |
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2438 { |
88365 | 2439 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2440 & CODING_ISO_FLAG_SINGLE_SHIFT) | |
2441 newmask |= CATEGORY_MASK_ISO_8_1; | |
2442 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2443 & CODING_ISO_FLAG_SINGLE_SHIFT) | |
2444 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
|
2445 single_shifting = 1; |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2446 } |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2447 if (VECTORP (Vlatin_extra_code_table) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2448 && !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
|
2449 { |
88365 | 2450 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2451 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2452 newmask |= CATEGORY_MASK_ISO_8_1; | |
2453 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2454 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2455 newmask |= CATEGORY_MASK_ISO_8_2; | |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2456 } |
88365 | 2457 mask_iso &= newmask; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2458 mask_found |= newmask; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2459 } |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2460 break; |
17052 | 2461 |
2462 default: | |
2463 if (c < 0x80) | |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2464 { |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2465 single_shifting = 0; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2466 break; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2467 } |
17052 | 2468 else if (c < 0xA0) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2469 { |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2470 single_shifting = 0; |
88365 | 2471 mask_8bit_found = 1; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2472 if (VECTORP (Vlatin_extra_code_table) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2473 && !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
|
2474 { |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2475 int newmask = 0; |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2476 |
88365 | 2477 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2478 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2479 newmask |= CATEGORY_MASK_ISO_8_1; | |
2480 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2481 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2482 newmask |= CATEGORY_MASK_ISO_8_2; | |
2483 mask_iso &= newmask; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2484 mask_found |= newmask; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2485 } |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2486 else |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2487 return 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2488 } |
17052 | 2489 else |
2490 { | |
88365 | 2491 mask_iso &= ~(CATEGORY_MASK_ISO_7BIT |
2492 | CATEGORY_MASK_ISO_7_ELSE); | |
2493 mask_found |= CATEGORY_MASK_ISO_8_1; | |
2494 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
|
2495 /* 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
|
2496 0xA0..0FF. If the byte length is odd, we exclude |
88365 | 2497 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
|
2498 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
|
2499 if (!single_shifting |
88365 | 2500 && 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
|
2501 { |
29299
b33b38d81020
(detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents:
29275
diff
changeset
|
2502 int i = 1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2503 while (src < src_end) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2504 { |
88365 | 2505 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
|
2506 if (c < 0xA0) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2507 break; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2508 i++; |
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 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2511 if (i & 1 && src < src_end) |
88365 | 2512 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
|
2513 else |
88365 | 2514 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
|
2515 } |
17052 | 2516 } |
2517 break; | |
2518 } | |
2519 } | |
88365 | 2520 no_more_source: |
2521 if (!mask_iso) | |
2522 { | |
2523 *mask &= ~CATEGORY_MASK_ISO; | |
2524 return 0; | |
2525 } | |
2526 if (!mask_found) | |
2527 return 0; | |
2528 *mask &= mask_iso & mask_found; | |
2529 if (! mask_8bit_found) | |
2530 *mask &= ~(CATEGORY_MASK_ISO_8BIT | CATEGORY_MASK_ISO_8_ELSE); | |
2531 return 1; | |
17052 | 2532 } |
2533 | |
2534 | |
2535 /* Set designation state into CODING. */ | |
88365 | 2536 #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
2537 do { \ | |
2538 int id, prev; \ | |
2539 \ | |
2540 if (final < '0' || final >= 128 \ | |
2541 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ | |
2542 || !SAFE_CHARSET_P (coding, id)) \ | |
2543 { \ | |
2544 CODING_ISO_DESIGNATION (coding, reg) = -2; \ | |
2545 goto invalid_code; \ | |
2546 } \ | |
2547 prev = CODING_ISO_DESIGNATION (coding, reg); \ | |
2548 CODING_ISO_DESIGNATION (coding, reg) = id; \ | |
2549 /* If there was an invalid designation to REG previously, and this \ | |
2550 designation is ASCII to REG, we should keep this designation \ | |
2551 sequence. */ \ | |
2552 if (prev == -2 && id == charset_ascii) \ | |
2553 goto invalid_code; \ | |
17052 | 2554 } while (0) |
2555 | |
88365 | 2556 |
2557 #define MAYBE_FINISH_COMPOSITION() \ | |
2558 do { \ | |
2559 int i; \ | |
2560 if (composition_state == COMPOSING_NO) \ | |
2561 break; \ | |
2562 /* It is assured that we have enough room for producing \ | |
2563 characters stored in the table `components'. */ \ | |
2564 if (charbuf + component_idx > charbuf_end) \ | |
2565 goto no_more_source; \ | |
2566 composition_state = COMPOSING_NO; \ | |
2567 if (method == COMPOSITION_RELATIVE \ | |
2568 || method == COMPOSITION_WITH_ALTCHARS) \ | |
2569 { \ | |
2570 for (i = 0; i < component_idx; i++) \ | |
2571 *charbuf++ = components[i]; \ | |
2572 char_offset += component_idx; \ | |
2573 } \ | |
2574 else \ | |
2575 { \ | |
2576 for (i = 0; i < component_idx; i += 2) \ | |
2577 *charbuf++ = components[i]; \ | |
2578 char_offset += (component_idx / 2) + 1; \ | |
2579 } \ | |
2580 } while (0) | |
2581 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2582 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2583 /* 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
|
2584 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
|
2585 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
88365 | 2586 ESC 3 : altchar composition : ESC 3 CHAR ... ESC 0 CHAR ... ESC 1 |
2587 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
|
2588 */ |
26847 | 2589 |
88365 | 2590 #define DECODE_COMPOSITION_START(c1) \ |
26847 | 2591 do { \ |
88365 | 2592 if (c1 == '0' \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2593 && composition_state == COMPOSING_COMPONENT_RULE) \ |
26847 | 2594 { \ |
88365 | 2595 component_len = component_idx; \ |
2596 composition_state = COMPOSING_CHAR; \ | |
26847 | 2597 } \ |
2598 else \ | |
2599 { \ | |
88365 | 2600 unsigned char *p; \ |
2601 \ | |
2602 MAYBE_FINISH_COMPOSITION (); \ | |
2603 if (charbuf + MAX_COMPOSITION_COMPONENTS > charbuf_end) \ | |
2604 goto no_more_source; \ | |
2605 for (p = src; p < src_end - 1; p++) \ | |
2606 if (*p == ISO_CODE_ESC && p[1] == '1') \ | |
2607 break; \ | |
2608 if (p == src_end - 1) \ | |
2609 { \ | |
2610 if (coding->mode & CODING_MODE_LAST_BLOCK) \ | |
2611 goto invalid_code; \ | |
2612 goto no_more_source; \ | |
2613 } \ | |
2614 \ | |
2615 /* This is surely the start of a composition. */ \ | |
2616 method = (c1 == '0' ? COMPOSITION_RELATIVE \ | |
2617 : c1 == '2' ? COMPOSITION_WITH_RULE \ | |
2618 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \ | |
2619 : COMPOSITION_WITH_RULE_ALTCHARS); \ | |
2620 composition_state = (c1 <= '2' ? COMPOSING_CHAR \ | |
2621 : COMPOSING_COMPONENT_CHAR); \ | |
2622 component_idx = component_len = 0; \ | |
26847 | 2623 } \ |
2624 } while (0) | |
2625 | |
88365 | 2626 |
2627 /* Handle compositoin end sequence ESC 1. */ | |
2628 | |
2629 #define DECODE_COMPOSITION_END() \ | |
2630 do { \ | |
2631 int nchars = (component_len > 0 ? component_idx - component_len \ | |
2632 : method == COMPOSITION_RELATIVE ? component_idx \ | |
2633 : (component_idx + 1) / 2); \ | |
2634 int i; \ | |
2635 int *saved_charbuf = charbuf; \ | |
2636 \ | |
2637 ADD_COMPOSITION_DATA (charbuf, method, nchars); \ | |
2638 if (method != COMPOSITION_RELATIVE) \ | |
2639 { \ | |
2640 if (component_len == 0) \ | |
2641 for (i = 0; i < component_idx; i++) \ | |
2642 *charbuf++ = components[i]; \ | |
2643 else \ | |
2644 for (i = 0; i < component_len; i++) \ | |
2645 *charbuf++ = components[i]; \ | |
2646 *saved_charbuf = saved_charbuf - charbuf; \ | |
2647 } \ | |
2648 if (method == COMPOSITION_WITH_RULE) \ | |
2649 for (i = 0; i < component_idx; i += 2, char_offset++) \ | |
2650 *charbuf++ = components[i]; \ | |
2651 else \ | |
2652 for (i = component_len; i < component_idx; i++, char_offset++) \ | |
2653 *charbuf++ = components[i]; \ | |
2654 coding->annotated = 1; \ | |
2655 composition_state = COMPOSING_NO; \ | |
2656 } while (0) | |
2657 | |
2658 | |
26847 | 2659 /* Decode a composition rule from the byte C1 (and maybe one more byte |
2660 from SRC) and store one encoded composition rule in | |
2661 coding->cmp_data. */ | |
2662 | |
2663 #define DECODE_COMPOSITION_RULE(c1) \ | |
2664 do { \ | |
2665 (c1) -= 32; \ | |
2666 if (c1 < 81) /* old format (before ver.21) */ \ | |
2667 { \ | |
2668 int gref = (c1) / 9; \ | |
2669 int nref = (c1) % 9; \ | |
2670 if (gref == 4) gref = 10; \ | |
2671 if (nref == 4) nref = 10; \ | |
88365 | 2672 c1 = COMPOSITION_ENCODE_RULE (gref, nref); \ |
26847 | 2673 } \ |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2674 else if (c1 < 93) /* new format (after ver.21) */ \ |
26847 | 2675 { \ |
2676 ONE_MORE_BYTE (c2); \ | |
88365 | 2677 c1 = COMPOSITION_ENCODE_RULE (c1 - 81, c2 - 32); \ |
26847 | 2678 } \ |
88365 | 2679 else \ |
2680 c1 = 0; \ | |
26847 | 2681 } while (0) |
2682 | |
2683 | |
17052 | 2684 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
2685 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2686 static void |
88365 | 2687 decode_coding_iso_2022 (coding) |
17052 | 2688 struct coding_system *coding; |
2689 { | |
88365 | 2690 unsigned char *src = coding->source + coding->consumed; |
2691 unsigned char *src_end = coding->source + coding->src_bytes; | |
2692 unsigned char *src_base; | |
2693 int *charbuf = coding->charbuf; | |
2694 int *charbuf_end = charbuf + coding->charbuf_size - 4; | |
2695 int consumed_chars = 0, consumed_chars_base; | |
2696 int char_offset = 0; | |
2697 int multibytep = coding->src_multibyte; | |
17052 | 2698 /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
88365 | 2699 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2700 int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
2701 struct charset *charset; | |
2702 int c; | |
2703 /* For handling composition sequence. */ | |
2704 #define COMPOSING_NO 0 | |
2705 #define COMPOSING_CHAR 1 | |
2706 #define COMPOSING_RULE 2 | |
2707 #define COMPOSING_COMPONENT_CHAR 3 | |
2708 #define COMPOSING_COMPONENT_RULE 4 | |
2709 | |
2710 int composition_state = COMPOSING_NO; | |
2711 enum composition_method method; | |
2712 int components[MAX_COMPOSITION_COMPONENTS * 2 + 1]; | |
2713 int component_idx; | |
2714 int component_len; | |
2715 Lisp_Object attrs, eol_type, charset_list; | |
2716 | |
2717 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
2718 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
|
2719 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2720 while (1) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2721 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2722 int c1, c2; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2723 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2724 src_base = src; |
88365 | 2725 consumed_chars_base = consumed_chars; |
2726 | |
2727 if (charbuf >= charbuf_end) | |
2728 break; | |
2729 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2730 ONE_MORE_BYTE (c1); |
17052 | 2731 |
26847 | 2732 /* We produce no character or one character. */ |
17052 | 2733 switch (iso_code_class [c1]) |
2734 { | |
2735 case ISO_0x20_or_0x7F: | |
88365 | 2736 if (composition_state != COMPOSING_NO) |
26847 | 2737 { |
88365 | 2738 if (composition_state == COMPOSING_RULE |
2739 || composition_state == COMPOSING_COMPONENT_RULE) | |
2740 { | |
2741 DECODE_COMPOSITION_RULE (c1); | |
2742 components[component_idx++] = c1; | |
2743 composition_state--; | |
2744 continue; | |
2745 } | |
26847 | 2746 } |
88365 | 2747 if (charset_id_0 < 0 |
2748 || ! 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
|
2749 /* This is SPACE or DEL. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2750 charset = CHARSET_FROM_ID (charset_ascii); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2751 else |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2752 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
|
2753 break; |
17052 | 2754 |
2755 case ISO_graphic_plane_0: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2756 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
|
2757 { |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2758 if (composition_state == COMPOSING_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2759 || composition_state == COMPOSING_COMPONENT_RULE) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2760 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2761 DECODE_COMPOSITION_RULE (c1); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2762 components[component_idx++] = c1; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2763 composition_state--; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2764 continue; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2765 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2766 } |
88365 | 2767 charset = CHARSET_FROM_ID (charset_id_0); |
17052 | 2768 break; |
2769 | |
2770 case ISO_0xA0_or_0xFF: | |
88365 | 2771 if (charset_id_1 < 0 |
2772 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) | |
2773 || CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) | |
2774 goto invalid_code; | |
17052 | 2775 /* This is a graphic character, we fall down ... */ |
2776 | |
2777 case ISO_graphic_plane_1: | |
88365 | 2778 if (charset_id_1 < 0) |
2779 goto invalid_code; | |
2780 charset = CHARSET_FROM_ID (charset_id_1); | |
17052 | 2781 break; |
2782 | |
88365 | 2783 case ISO_carriage_return: |
2784 if (c1 == '\r') | |
2785 { | |
2786 if (EQ (eol_type, Qdos)) | |
2787 { | |
2788 if (src == src_end) | |
2789 goto no_more_source; | |
2790 if (*src == '\n') | |
2791 ONE_MORE_BYTE (c1); | |
2792 } | |
2793 else if (EQ (eol_type, Qmac)) | |
2794 c1 = '\n'; | |
2795 } | |
2796 /* fall through */ | |
2797 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2798 case ISO_control_0: |
88365 | 2799 MAYBE_FINISH_COMPOSITION (); |
2800 charset = CHARSET_FROM_ID (charset_ascii); | |
17052 | 2801 break; |
2802 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2803 case ISO_control_1: |
88365 | 2804 MAYBE_FINISH_COMPOSITION (); |
2805 goto invalid_code; | |
17052 | 2806 |
2807 case ISO_shift_out: | |
88365 | 2808 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2809 || CODING_ISO_DESIGNATION (coding, 1) < 0) | |
2810 goto invalid_code; | |
2811 CODING_ISO_INVOCATION (coding, 0) = 1; | |
2812 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
|
2813 continue; |
17052 | 2814 |
2815 case ISO_shift_in: | |
88365 | 2816 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)) |
2817 goto invalid_code; | |
2818 CODING_ISO_INVOCATION (coding, 0) = 0; | |
2819 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
|
2820 continue; |
17052 | 2821 |
2822 case ISO_single_shift_2_7: | |
2823 case ISO_single_shift_2: | |
88365 | 2824 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2825 goto invalid_code; | |
17052 | 2826 /* SS2 is handled as an escape sequence of ESC 'N' */ |
2827 c1 = 'N'; | |
2828 goto label_escape_sequence; | |
2829 | |
2830 case ISO_single_shift_3: | |
88365 | 2831 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2832 goto invalid_code; | |
17052 | 2833 /* SS2 is handled as an escape sequence of ESC 'O' */ |
2834 c1 = 'O'; | |
2835 goto label_escape_sequence; | |
2836 | |
2837 case ISO_control_sequence_introducer: | |
2838 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
2839 c1 = '['; | |
2840 goto label_escape_sequence; | |
2841 | |
2842 case ISO_escape: | |
2843 ONE_MORE_BYTE (c1); | |
2844 label_escape_sequence: | |
88365 | 2845 /* Escape sequences handled here are invocation, |
17052 | 2846 designation, direction specification, and character |
2847 composition specification. */ | |
2848 switch (c1) | |
2849 { | |
2850 case '&': /* revision of following character set */ | |
2851 ONE_MORE_BYTE (c1); | |
2852 if (!(c1 >= '@' && c1 <= '~')) | |
88365 | 2853 goto invalid_code; |
17052 | 2854 ONE_MORE_BYTE (c1); |
2855 if (c1 != ISO_CODE_ESC) | |
88365 | 2856 goto invalid_code; |
17052 | 2857 ONE_MORE_BYTE (c1); |
2858 goto label_escape_sequence; | |
2859 | |
2860 case '$': /* designation of 2-byte character set */ | |
88365 | 2861 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
2862 goto invalid_code; | |
17052 | 2863 ONE_MORE_BYTE (c1); |
2864 if (c1 >= '@' && c1 <= 'B') | |
2865 { /* 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
|
2866 or JISX0208.1980 */ |
88365 | 2867 DECODE_DESIGNATION (0, 2, 0, c1); |
17052 | 2868 } |
2869 else if (c1 >= 0x28 && c1 <= 0x2B) | |
2870 { /* designation of DIMENSION2_CHARS94 character set */ | |
2871 ONE_MORE_BYTE (c2); | |
88365 | 2872 DECODE_DESIGNATION (c1 - 0x28, 2, 0, c2); |
17052 | 2873 } |
2874 else if (c1 >= 0x2C && c1 <= 0x2F) | |
2875 { /* designation of DIMENSION2_CHARS96 character set */ | |
2876 ONE_MORE_BYTE (c2); | |
88365 | 2877 DECODE_DESIGNATION (c1 - 0x2C, 2, 1, c2); |
17052 | 2878 } |
2879 else | |
88365 | 2880 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2881 /* We must update these variables now. */ |
88365 | 2882 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2883 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
|
2884 continue; |
17052 | 2885 |
2886 case 'n': /* invocation of locking-shift-2 */ | |
88365 | 2887 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2888 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
2889 goto invalid_code; | |
2890 CODING_ISO_INVOCATION (coding, 0) = 2; | |
2891 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
|
2892 continue; |
17052 | 2893 |
2894 case 'o': /* invocation of locking-shift-3 */ | |
88365 | 2895 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2896 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
2897 goto invalid_code; | |
2898 CODING_ISO_INVOCATION (coding, 0) = 3; | |
2899 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
|
2900 continue; |
17052 | 2901 |
2902 case 'N': /* invocation of single-shift-2 */ | |
88365 | 2903 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
2904 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
2905 goto invalid_code; | |
2906 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 2)); | |
17052 | 2907 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
2908 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 2909 goto invalid_code; |
17052 | 2910 break; |
2911 | |
2912 case 'O': /* invocation of single-shift-3 */ | |
88365 | 2913 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
2914 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
2915 goto invalid_code; | |
2916 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 3)); | |
17052 | 2917 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
2918 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 2919 goto invalid_code; |
17052 | 2920 break; |
2921 | |
26847 | 2922 case '0': case '2': case '3': case '4': /* start composition */ |
88365 | 2923 if (! (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK)) |
2924 goto invalid_code; | |
26847 | 2925 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
|
2926 continue; |
17052 | 2927 |
26847 | 2928 case '1': /* end composition */ |
88365 | 2929 if (composition_state == COMPOSING_NO) |
2930 goto invalid_code; | |
2931 DECODE_COMPOSITION_END (); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2932 continue; |
17052 | 2933 |
2934 case '[': /* specification of direction */ | |
88365 | 2935 if (! CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DIRECTION) |
2936 goto invalid_code; | |
17052 | 2937 /* 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
|
2938 So, `coding->mode & CODING_MODE_DIRECTION' zero means |
88365 | 2939 left-to-right, and nozero means right-to-left. */ |
17052 | 2940 ONE_MORE_BYTE (c1); |
2941 switch (c1) | |
2942 { | |
2943 case ']': /* end of the current direction */ | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2944 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 2945 |
2946 case '0': /* end of the current direction */ | |
2947 case '1': /* start of left-to-right direction */ | |
2948 ONE_MORE_BYTE (c1); | |
2949 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2950 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 2951 else |
88365 | 2952 goto invalid_code; |
17052 | 2953 break; |
2954 | |
2955 case '2': /* start of right-to-left direction */ | |
2956 ONE_MORE_BYTE (c1); | |
2957 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2958 coding->mode |= CODING_MODE_DIRECTION; |
17052 | 2959 else |
88365 | 2960 goto invalid_code; |
17052 | 2961 break; |
2962 | |
2963 default: | |
88365 | 2964 goto invalid_code; |
17052 | 2965 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2966 continue; |
17052 | 2967 |
2968 default: | |
88365 | 2969 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
2970 goto invalid_code; | |
17052 | 2971 if (c1 >= 0x28 && c1 <= 0x2B) |
2972 { /* designation of DIMENSION1_CHARS94 character set */ | |
2973 ONE_MORE_BYTE (c2); | |
88365 | 2974 DECODE_DESIGNATION (c1 - 0x28, 1, 0, c2); |
17052 | 2975 } |
2976 else if (c1 >= 0x2C && c1 <= 0x2F) | |
2977 { /* designation of DIMENSION1_CHARS96 character set */ | |
2978 ONE_MORE_BYTE (c2); | |
88365 | 2979 DECODE_DESIGNATION (c1 - 0x2C, 1, 1, c2); |
17052 | 2980 } |
2981 else | |
88365 | 2982 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2983 /* We must update these variables now. */ |
88365 | 2984 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2985 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
|
2986 continue; |
17052 | 2987 } |
29005
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 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2990 /* Now we know CHARSET and 1st position code C1 of a character. |
88365 | 2991 Produce a decoded character while getting 2nd position code |
2992 C2 if necessary. */ | |
2993 c1 &= 0x7F; | |
2994 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
|
2995 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2996 ONE_MORE_BYTE (c2); |
88365 | 2997 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
|
2998 /* C2 is not in a valid range. */ |
88365 | 2999 goto invalid_code; |
3000 c1 = (c1 << 8) | (c2 & 0x7F); | |
3001 if (CHARSET_DIMENSION (charset) > 2) | |
3002 { | |
3003 ONE_MORE_BYTE (c2); | |
3004 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) | |
3005 /* C2 is not in a valid range. */ | |
3006 goto invalid_code; | |
3007 c1 = (c1 << 8) | (c2 & 0x7F); | |
3008 } | |
17052 | 3009 } |
88365 | 3010 |
3011 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); | |
3012 if (c < 0) | |
3013 { | |
3014 MAYBE_FINISH_COMPOSITION (); | |
3015 for (; src_base < src; src_base++, char_offset++) | |
3016 { | |
3017 if (ASCII_BYTE_P (*src_base)) | |
3018 *charbuf++ = *src_base; | |
3019 else | |
3020 *charbuf++ = BYTE8_TO_CHAR (*src_base); | |
3021 } | |
3022 } | |
3023 else if (composition_state == COMPOSING_NO) | |
3024 { | |
3025 *charbuf++ = c; | |
3026 char_offset++; | |
3027 } | |
3028 else | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3029 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3030 components[component_idx++] = c; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3031 if (method == COMPOSITION_WITH_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3032 || (method == COMPOSITION_WITH_RULE_ALTCHARS |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3033 && composition_state == COMPOSING_COMPONENT_CHAR)) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3034 composition_state++; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3035 } |
17052 | 3036 continue; |
3037 | |
88365 | 3038 invalid_code: |
3039 MAYBE_FINISH_COMPOSITION (); | |
3040 src = src_base; | |
3041 consumed_chars = consumed_chars_base; | |
3042 ONE_MORE_BYTE (c); | |
3043 *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
|
3044 coding->errors++; |
88365 | 3045 } |
3046 | |
3047 no_more_source: | |
3048 coding->consumed_char += consumed_chars_base; | |
3049 coding->consumed = src_base - coding->source; | |
3050 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3051 } |
3052 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3053 |
18766 | 3054 /* ISO2022 encoding stuff. */ |
17052 | 3055 |
3056 /* | |
18766 | 3057 It is not enough to say just "ISO2022" on encoding, we have to |
88365 | 3058 specify more details. In Emacs, each coding system of ISO2022 |
17052 | 3059 variant has the following specifications: |
88365 | 3060 1. Initial designation to G0 thru G3. |
17052 | 3061 2. Allows short-form designation? |
3062 3. ASCII should be designated to G0 before control characters? | |
3063 4. ASCII should be designated to G0 at end of line? | |
3064 5. 7-bit environment or 8-bit environment? | |
3065 6. Use locking-shift? | |
3066 7. Use Single-shift? | |
3067 And the following two are only for Japanese: | |
3068 8. Use ASCII in place of JIS0201-1976-Roman? | |
3069 9. Use JISX0208-1983 in place of JISX0208-1978? | |
88365 | 3070 These specifications are encoded in CODING_ISO_FLAGS (coding) as flag bits |
3071 defined by macros CODING_ISO_FLAG_XXX. See `coding.h' for more | |
18766 | 3072 details. |
17052 | 3073 */ |
3074 | |
3075 /* 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
|
3076 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
|
3077 '@', '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
|
3078 designation sequence of short-form. */ |
17052 | 3079 |
3080 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
3081 do { \ | |
88365 | 3082 unsigned char final_char = CHARSET_ISO_FINAL (charset); \ |
17052 | 3083 char *intermediate_char_94 = "()*+"; \ |
3084 char *intermediate_char_96 = ",-./"; \ | |
88365 | 3085 int revision = -1; \ |
3086 int c; \ | |
3087 \ | |
3088 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ | |
3089 revision = XINT (CHARSET_ISO_REVISION (charset)); \ | |
3090 \ | |
3091 if (revision >= 0) \ | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
3092 { \ |
88365 | 3093 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '&'); \ |
3094 EMIT_ONE_BYTE ('@' + revision); \ | |
17052 | 3095 } \ |
88365 | 3096 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ |
17052 | 3097 if (CHARSET_DIMENSION (charset) == 1) \ |
3098 { \ | |
88365 | 3099 if (! CHARSET_ISO_CHARS_96 (charset)) \ |
3100 c = intermediate_char_94[reg]; \ | |
17052 | 3101 else \ |
88365 | 3102 c = intermediate_char_96[reg]; \ |
3103 EMIT_ONE_ASCII_BYTE (c); \ | |
17052 | 3104 } \ |
3105 else \ | |
3106 { \ | |
88365 | 3107 EMIT_ONE_ASCII_BYTE ('$'); \ |
3108 if (! CHARSET_ISO_CHARS_96 (charset)) \ | |
17052 | 3109 { \ |
88365 | 3110 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
|
3111 || reg != 0 \ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3112 || final_char < '@' || final_char > 'B') \ |
88365 | 3113 EMIT_ONE_ASCII_BYTE (intermediate_char_94[reg]); \ |
17052 | 3114 } \ |
3115 else \ | |
88365 | 3116 EMIT_ONE_ASCII_BYTE (intermediate_char_96[reg]); \ |
17052 | 3117 } \ |
88365 | 3118 EMIT_ONE_ASCII_BYTE (final_char); \ |
3119 \ | |
3120 CODING_ISO_DESIGNATION (coding, reg) = CHARSET_ID (charset); \ | |
17052 | 3121 } while (0) |
3122 | |
88365 | 3123 |
17052 | 3124 /* The following two macros produce codes (control character or escape |
3125 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
3126 single-shift-3). */ | |
3127 | |
88365 | 3128 #define ENCODE_SINGLE_SHIFT_2 \ |
3129 do { \ | |
3130 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3131 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'N'); \ | |
3132 else \ | |
3133 EMIT_ONE_BYTE (ISO_CODE_SS2); \ | |
3134 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3135 } while (0) |
3136 | |
88365 | 3137 |
3138 #define ENCODE_SINGLE_SHIFT_3 \ | |
3139 do { \ | |
3140 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3141 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'O'); \ | |
3142 else \ | |
3143 EMIT_ONE_BYTE (ISO_CODE_SS3); \ | |
3144 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3145 } while (0) |
3146 | |
88365 | 3147 |
17052 | 3148 /* The following four macros produce codes (control character or |
3149 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
3150 shift-out, locking-shift-2, and locking-shift-3). */ | |
3151 | |
88365 | 3152 #define ENCODE_SHIFT_IN \ |
3153 do { \ | |
3154 EMIT_ONE_ASCII_BYTE (ISO_CODE_SI); \ | |
3155 CODING_ISO_INVOCATION (coding, 0) = 0; \ | |
17052 | 3156 } while (0) |
3157 | |
88365 | 3158 |
3159 #define ENCODE_SHIFT_OUT \ | |
3160 do { \ | |
3161 EMIT_ONE_ASCII_BYTE (ISO_CODE_SO); \ | |
3162 CODING_ISO_INVOCATION (coding, 0) = 1; \ | |
17052 | 3163 } while (0) |
3164 | |
88365 | 3165 |
3166 #define ENCODE_LOCKING_SHIFT_2 \ | |
3167 do { \ | |
3168 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3169 CODING_ISO_INVOCATION (coding, 0) = 2; \ | |
17052 | 3170 } while (0) |
3171 | |
88365 | 3172 |
3173 #define ENCODE_LOCKING_SHIFT_3 \ | |
3174 do { \ | |
3175 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3176 CODING_ISO_INVOCATION (coding, 0) = 3; \ | |
17052 | 3177 } while (0) |
3178 | |
88365 | 3179 |
18766 | 3180 /* Produce codes for a DIMENSION1 character whose character set is |
3181 CHARSET and whose position-code is C1. Designation and invocation | |
17052 | 3182 sequences are also produced in advance if necessary. */ |
3183 | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3184 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3185 do { \ |
88365 | 3186 int id = CHARSET_ID (charset); \ |
3187 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3188 { \ |
88365 | 3189 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ |
3190 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3191 else \ |
88365 | 3192 EMIT_ONE_BYTE (c1 | 0x80); \ |
3193 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3194 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3195 } \ |
88365 | 3196 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
|
3197 { \ |
88365 | 3198 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3199 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3200 } \ |
88365 | 3201 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
|
3202 { \ |
88365 | 3203 EMIT_ONE_BYTE (c1 | 0x80); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3204 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3205 } \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3206 else \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3207 /* 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
|
3208 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
|
3209 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
|
3210 character. */ \ |
88365 | 3211 dst = encode_invocation_designation (charset, coding, dst, \ |
3212 &produced_chars); \ | |
17052 | 3213 } while (1) |
3214 | |
88365 | 3215 |
3216 /* Produce codes for a DIMENSION2 character whose character set is | |
3217 CHARSET and whose position-codes are C1 and C2. Designation and | |
3218 invocation codes are also produced in advance if necessary. */ | |
3219 | |
3220 #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
|
3221 do { \ |
88365 | 3222 int id = CHARSET_ID (charset); \ |
3223 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ | |
3224 { \ | |
3225 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3226 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3227 else \ | |
3228 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3229 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
3230 break; \ | |
3231 } \ | |
3232 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ | |
3233 { \ | |
3234 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3235 break; \ | |
3236 } \ | |
3237 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ | |
3238 { \ | |
3239 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3240 break; \ | |
3241 } \ | |
3242 else \ | |
3243 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
3244 must invoke it, or, at first, designate it to some graphic \ | |
3245 register. Then repeat the loop to actually produce the \ | |
3246 character. */ \ | |
3247 dst = encode_invocation_designation (charset, coding, dst, \ | |
3248 &produced_chars); \ | |
3249 } while (1) | |
3250 | |
3251 | |
3252 #define ENCODE_ISO_CHARACTER(charset, c) \ | |
3253 do { \ | |
3254 int code = ENCODE_CHAR ((charset),(c)); \ | |
3255 \ | |
3256 if (CHARSET_DIMENSION (charset) == 1) \ | |
3257 ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ | |
3258 else \ | |
3259 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
|
3260 } while (0) |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3261 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
3262 |
17052 | 3263 /* Produce designation and invocation codes at a place pointed by DST |
88365 | 3264 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. |
17052 | 3265 Return new DST. */ |
3266 | |
3267 unsigned char * | |
88365 | 3268 encode_invocation_designation (charset, coding, dst, p_nchars) |
3269 struct charset *charset; | |
17052 | 3270 struct coding_system *coding; |
3271 unsigned char *dst; | |
88365 | 3272 int *p_nchars; |
17052 | 3273 { |
88365 | 3274 int multibytep = coding->dst_multibyte; |
3275 int produced_chars = *p_nchars; | |
17052 | 3276 int reg; /* graphic register number */ |
88365 | 3277 int id = CHARSET_ID (charset); |
17052 | 3278 |
3279 /* At first, check designations. */ | |
3280 for (reg = 0; reg < 4; reg++) | |
88365 | 3281 if (id == CODING_ISO_DESIGNATION (coding, reg)) |
17052 | 3282 break; |
3283 | |
3284 if (reg >= 4) | |
3285 { | |
3286 /* CHARSET is not yet designated to any graphic registers. */ | |
3287 /* At first check the requested designation. */ | |
88365 | 3288 reg = CODING_ISO_REQUEST (coding, id); |
3289 if (reg < 0) | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3290 /* Since CHARSET requests no special designation, designate it |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3291 to graphic register 0. */ |
17052 | 3292 reg = 0; |
3293 | |
3294 ENCODE_DESIGNATION (charset, reg, coding); | |
3295 } | |
3296 | |
88365 | 3297 if (CODING_ISO_INVOCATION (coding, 0) != reg |
3298 && CODING_ISO_INVOCATION (coding, 1) != reg) | |
17052 | 3299 { |
3300 /* Since the graphic register REG is not invoked to any graphic | |
3301 planes, invoke it to graphic plane 0. */ | |
3302 switch (reg) | |
3303 { | |
3304 case 0: /* graphic register 0 */ | |
3305 ENCODE_SHIFT_IN; | |
3306 break; | |
3307 | |
3308 case 1: /* graphic register 1 */ | |
3309 ENCODE_SHIFT_OUT; | |
3310 break; | |
3311 | |
3312 case 2: /* graphic register 2 */ | |
88365 | 3313 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3314 ENCODE_SINGLE_SHIFT_2; |
3315 else | |
3316 ENCODE_LOCKING_SHIFT_2; | |
3317 break; | |
3318 | |
3319 case 3: /* graphic register 3 */ | |
88365 | 3320 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3321 ENCODE_SINGLE_SHIFT_3; |
3322 else | |
3323 ENCODE_LOCKING_SHIFT_3; | |
3324 break; | |
3325 } | |
3326 } | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3327 |
88365 | 3328 *p_nchars = produced_chars; |
17052 | 3329 return dst; |
3330 } | |
3331 | |
3332 /* The following three macros produce codes for indicating direction | |
3333 of text. */ | |
88365 | 3334 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ |
3335 do { \ | |
3336 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \ | |
3337 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \ | |
3338 else \ | |
3339 EMIT_ONE_BYTE (ISO_CODE_CSI); \ | |
17052 | 3340 } while (0) |
3341 | |
88365 | 3342 |
3343 #define ENCODE_DIRECTION_R2L() \ | |
3344 do { \ | |
3345 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3346 EMIT_TWO_ASCII_BYTES ('2', ']'); \ | |
3347 } while (0) | |
3348 | |
3349 | |
3350 #define ENCODE_DIRECTION_L2R() \ | |
3351 do { \ | |
3352 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3353 EMIT_TWO_ASCII_BYTES ('0', ']'); \ | |
3354 } while (0) | |
3355 | |
17052 | 3356 |
3357 /* Produce codes for designation and invocation to reset the graphic | |
3358 planes and registers to initial state. */ | |
88365 | 3359 #define ENCODE_RESET_PLANE_AND_REGISTER() \ |
3360 do { \ | |
3361 int reg; \ | |
3362 struct charset *charset; \ | |
3363 \ | |
3364 if (CODING_ISO_INVOCATION (coding, 0) != 0) \ | |
3365 ENCODE_SHIFT_IN; \ | |
3366 for (reg = 0; reg < 4; reg++) \ | |
3367 if (CODING_ISO_INITIAL (coding, reg) >= 0 \ | |
3368 && (CODING_ISO_DESIGNATION (coding, reg) \ | |
3369 != CODING_ISO_INITIAL (coding, reg))) \ | |
3370 { \ | |
3371 charset = CHARSET_FROM_ID (CODING_ISO_INITIAL (coding, reg)); \ | |
3372 ENCODE_DESIGNATION (charset, reg, coding); \ | |
3373 } \ | |
17052 | 3374 } while (0) |
3375 | |
88365 | 3376 |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3377 /* 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
|
3378 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
|
3379 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3380 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
|
3381 find all the necessary designations. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3382 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3383 static unsigned char * |
88365 | 3384 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
|
3385 struct coding_system *coding; |
88365 | 3386 int *charbuf, *charbuf_end; |
3387 unsigned char *dst; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3388 { |
88365 | 3389 struct charset *charset; |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3390 /* 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
|
3391 int r[4]; |
88365 | 3392 int c, found = 0, reg; |
3393 int produced_chars = 0; | |
3394 int multibytep = coding->dst_multibyte; | |
3395 Lisp_Object attrs; | |
3396 Lisp_Object charset_list; | |
3397 | |
3398 attrs = CODING_ID_ATTRS (coding->id); | |
3399 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
3400 if (EQ (charset_list, Qiso_2022)) | |
3401 charset_list = Viso_2022_charset_list; | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3402 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3403 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3404 r[reg] = -1; |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3405 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3406 while (found < 4) |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3407 { |
88365 | 3408 int id; |
3409 | |
3410 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3411 if (c == '\n') |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3412 break; |
88365 | 3413 charset = char_charset (c, charset_list, NULL); |
3414 id = CHARSET_ID (charset); | |
3415 reg = CODING_ISO_REQUEST (coding, id); | |
3416 if (reg >= 0 && r[reg] < 0) | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3417 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3418 found++; |
88365 | 3419 r[reg] = id; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3420 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3421 } |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3422 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3423 if (found) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3424 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3425 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3426 if (r[reg] >= 0 |
88365 | 3427 && CODING_ISO_DESIGNATION (coding, reg) != r[reg]) |
3428 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
|
3429 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3430 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3431 return dst; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3432 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3433 |
17052 | 3434 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
3435 | |
88365 | 3436 static int |
3437 encode_coding_iso_2022 (coding) | |
17052 | 3438 struct coding_system *coding; |
3439 { | |
88365 | 3440 int multibytep = coding->dst_multibyte; |
3441 int *charbuf = coding->charbuf; | |
3442 int *charbuf_end = charbuf + coding->charbuf_used; | |
3443 unsigned char *dst = coding->destination + coding->produced; | |
3444 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3445 int safe_room = 16; | |
3446 int bol_designation | |
3447 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL | |
3448 && CODING_ISO_BOL (coding)); | |
3449 int produced_chars = 0; | |
3450 Lisp_Object attrs, eol_type, charset_list; | |
3451 int ascii_compatible; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3452 int c; |
88365 | 3453 |
3454 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
|
3455 setup_iso_safe_charsets (attrs); |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3456 coding->safe_charsets |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3457 = (char *) XSTRING (CODING_ATTR_SAFE_CHARSETS(attrs))->data; |
88365 | 3458 |
3459 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3460 | |
3461 while (charbuf < charbuf_end) | |
3462 { | |
3463 ASSURE_DESTINATION (safe_room); | |
3464 | |
3465 if (bol_designation) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3466 { |
88365 | 3467 unsigned char *dst_prev = dst; |
3468 | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3469 /* We have to produce designation sequences if any now. */ |
88365 | 3470 dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); |
3471 bol_designation = 0; | |
3472 /* We are sure that designation sequences are all ASCII bytes. */ | |
3473 produced_chars += dst - dst_prev; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3474 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3475 |
88365 | 3476 c = *charbuf++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3477 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3478 /* 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
|
3479 if (c < 0x20 || c == 0x7F) |
17052 | 3480 { |
88365 | 3481 if (c == '\n' |
3482 || (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
|
3483 { |
88365 | 3484 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) |
3485 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3486 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_INIT_AT_BOL) | |
3487 { | |
3488 int i; | |
3489 | |
3490 for (i = 0; i < 4; i++) | |
3491 CODING_ISO_DESIGNATION (coding, i) | |
3492 = CODING_ISO_INITIAL (coding, i); | |
3493 } | |
3494 bol_designation | |
3495 = 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
|
3496 } |
88365 | 3497 else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) |
3498 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3499 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
|
3500 } |
88365 | 3501 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
|
3502 { |
88365 | 3503 if (ascii_compatible) |
3504 EMIT_ONE_ASCII_BYTE (c); | |
3505 else | |
3506 ENCODE_ISO_CHARACTER (CHARSET_FROM_ID (charset_ascii), c); | |
17052 | 3507 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3508 else |
88365 | 3509 { |
3510 struct charset *charset = char_charset (c, charset_list, NULL); | |
3511 | |
3512 if (!charset) | |
3513 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3514 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
|
3515 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3516 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3517 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3518 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3519 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3520 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3521 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3522 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
|
3523 } |
88365 | 3524 } |
3525 ENCODE_ISO_CHARACTER (charset, c); | |
3526 } | |
3527 } | |
3528 | |
3529 if (coding->mode & CODING_MODE_LAST_BLOCK | |
3530 && CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) | |
3531 { | |
3532 ASSURE_DESTINATION (safe_room); | |
3533 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3534 } | |
3535 coding->result = CODING_RESULT_SUCCESS; | |
3536 CODING_ISO_BOL (coding) = bol_designation; | |
3537 coding->produced_char += produced_chars; | |
3538 coding->produced = dst - coding->destination; | |
3539 return 0; | |
17052 | 3540 } |
3541 | |
3542 | |
88365 | 3543 /*** 8,9. SJIS and BIG5 handlers ***/ |
3544 | |
3545 /* Although SJIS and BIG5 are not ISO's coding system, they are used | |
17052 | 3546 quite widely. So, for the moment, Emacs supports them in the bare |
3547 C code. But, in the future, they may be supported only by CCL. */ | |
3548 | |
3549 /* SJIS is a coding system encoding three character sets: ASCII, right | |
3550 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
3551 as is. A character of charset katakana-jisx0201 is encoded by | |
3552 "position-code + 0x80". A character of charset japanese-jisx0208 | |
3553 is encoded in 2-byte but two position-codes are divided and shifted | |
88365 | 3554 so that it fit in the range below. |
17052 | 3555 |
3556 --- CODE RANGE of SJIS --- | |
3557 (character set) (range) | |
3558 ASCII 0x00 .. 0x7F | |
88365 | 3559 KATAKANA-JISX0201 0xA0 .. 0xDF |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
3560 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
|
3561 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC |
17052 | 3562 ------------------------------- |
3563 | |
3564 */ | |
3565 | |
3566 /* BIG5 is a coding system encoding two character sets: ASCII and | |
3567 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
88365 | 3568 character set and is encoded in two-byte. |
17052 | 3569 |
3570 --- CODE RANGE of BIG5 --- | |
3571 (character set) (range) | |
3572 ASCII 0x00 .. 0x7F | |
3573 Big5 (1st byte) 0xA1 .. 0xFE | |
3574 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
3575 -------------------------- | |
3576 | |
88365 | 3577 */ |
17052 | 3578 |
3579 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3580 Check if a text is encoded in SJIS. If it is, return | |
88365 | 3581 CATEGORY_MASK_SJIS, else return 0. */ |
17052 | 3582 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3583 static int |
88365 | 3584 detect_coding_sjis (coding, mask) |
3585 struct coding_system *coding; | |
3586 int *mask; | |
17052 | 3587 { |
88365 | 3588 unsigned char *src = coding->source, *src_base = src; |
3589 unsigned char *src_end = coding->source + coding->src_bytes; | |
3590 int multibytep = coding->src_multibyte; | |
3591 int consumed_chars = 0; | |
3592 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3593 int c; |
88365 | 3594 |
3595 /* A coding system of this category is always ASCII compatible. */ | |
3596 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
|
3597 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3598 while (1) |
17052 | 3599 { |
88365 | 3600 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3601 if (c < 0x80) |
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3602 continue; |
88365 | 3603 if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEF)) |
17052 | 3604 { |
88365 | 3605 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3606 if (c < 0x40 || c == 0x7F || c > 0xFC) |
88365 | 3607 break; |
3608 found = 1; | |
17052 | 3609 } |
88365 | 3610 else if (c >= 0xA0 && c < 0xE0) |
3611 found = 1; | |
3612 else | |
3613 break; | |
3614 } | |
3615 *mask &= ~CATEGORY_MASK_SJIS; | |
3616 return 0; | |
3617 | |
3618 no_more_source: | |
3619 if (!found) | |
3620 return 0; | |
3621 *mask &= CATEGORY_MASK_SJIS; | |
3622 return 1; | |
17052 | 3623 } |
3624 | |
3625 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3626 Check if a text is encoded in BIG5. If it is, return | |
88365 | 3627 CATEGORY_MASK_BIG5, else return 0. */ |
17052 | 3628 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3629 static int |
88365 | 3630 detect_coding_big5 (coding, mask) |
3631 struct coding_system *coding; | |
3632 int *mask; | |
17052 | 3633 { |
88365 | 3634 unsigned char *src = coding->source, *src_base = src; |
3635 unsigned char *src_end = coding->source + coding->src_bytes; | |
3636 int multibytep = coding->src_multibyte; | |
3637 int consumed_chars = 0; | |
3638 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3639 int c; |
88365 | 3640 |
3641 /* A coding system of this category is always ASCII compatible. */ | |
3642 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
|
3643 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3644 while (1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3645 { |
88365 | 3646 ONE_MORE_BYTE (c); |
3647 if (c < 0x80) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3648 continue; |
88365 | 3649 if (c >= 0xA1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3650 { |
88365 | 3651 ONE_MORE_BYTE (c); |
3652 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
|
3653 return 0; |
88365 | 3654 found = 1; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3655 } |
88365 | 3656 else |
3657 break; | |
3658 } | |
3659 *mask &= ~CATEGORY_MASK_BIG5; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3660 return 0; |
88365 | 3661 |
3662 no_more_source: | |
3663 if (!found) | |
3664 return 0; | |
3665 *mask &= CATEGORY_MASK_BIG5; | |
3666 return 1; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3667 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3668 |
17052 | 3669 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". |
3670 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
3671 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3672 static void |
88365 | 3673 decode_coding_sjis (coding) |
17052 | 3674 struct coding_system *coding; |
3675 { | |
88365 | 3676 unsigned char *src = coding->source + coding->consumed; |
3677 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
|
3678 unsigned char *src_base; |
88365 | 3679 int *charbuf = coding->charbuf; |
3680 int *charbuf_end = charbuf + coding->charbuf_size; | |
3681 int consumed_chars = 0, consumed_chars_base; | |
3682 int multibytep = coding->src_multibyte; | |
3683 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3684 Lisp_Object attrs, eol_type, charset_list, val; | |
3685 | |
3686 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3687 | |
3688 val = charset_list; | |
3689 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3690 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3691 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3692 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3693 while (1) |
17052 | 3694 { |
88365 | 3695 int c, c1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3696 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3697 src_base = src; |
88365 | 3698 consumed_chars_base = consumed_chars; |
3699 | |
3700 if (charbuf >= charbuf_end) | |
3701 break; | |
3702 | |
3703 ONE_MORE_BYTE (c); | |
3704 | |
3705 if (c == '\r') | |
17052 | 3706 { |
88365 | 3707 if (EQ (eol_type, Qdos)) |
17052 | 3708 { |
88365 | 3709 if (src == src_end) |
3710 goto no_more_source; | |
3711 if (*src == '\n') | |
3712 ONE_MORE_BYTE (c); | |
17052 | 3713 } |
88365 | 3714 else if (EQ (eol_type, Qmac)) |
3715 c = '\n'; | |
17052 | 3716 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3717 else |
88365 | 3718 { |
3719 struct charset *charset; | |
3720 | |
3721 if (c < 0x80) | |
3722 charset = charset_roman; | |
3723 else | |
17052 | 3724 { |
88365 | 3725 if (c >= 0xF0) |
3726 goto invalid_code; | |
3727 if (c < 0xA0 || c >= 0xE0) | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3728 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3729 /* SJIS -> JISX0208 */ |
88365 | 3730 ONE_MORE_BYTE (c1); |
3731 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) | |
3732 goto invalid_code; | |
3733 c = (c << 8) | c1; | |
3734 SJIS_TO_JIS (c); | |
3735 charset = charset_kanji; | |
24870
b0f6eab5deeb
(decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents:
24822
diff
changeset
|
3736 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3737 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3738 /* SJIS -> JISX0201-Kana */ |
88365 | 3739 charset = charset_kana; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3740 } |
88365 | 3741 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
3742 } | |
3743 *charbuf++ = c; | |
3744 continue; | |
3745 | |
3746 invalid_code: | |
3747 src = src_base; | |
3748 consumed_chars = consumed_chars_base; | |
3749 ONE_MORE_BYTE (c); | |
3750 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
3751 coding->errors++; | |
3752 } | |
3753 | |
3754 no_more_source: | |
3755 coding->consumed_char += consumed_chars_base; | |
3756 coding->consumed = src_base - coding->source; | |
3757 coding->charbuf_used = charbuf - coding->charbuf; | |
3758 } | |
3759 | |
3760 static void | |
3761 decode_coding_big5 (coding) | |
3762 struct coding_system *coding; | |
3763 { | |
3764 unsigned char *src = coding->source + coding->consumed; | |
3765 unsigned char *src_end = coding->source + coding->src_bytes; | |
3766 unsigned char *src_base; | |
3767 int *charbuf = coding->charbuf; | |
3768 int *charbuf_end = charbuf + coding->charbuf_size; | |
3769 int consumed_chars = 0, consumed_chars_base; | |
3770 int multibytep = coding->src_multibyte; | |
3771 struct charset *charset_roman, *charset_big5; | |
3772 Lisp_Object attrs, eol_type, charset_list, val; | |
3773 | |
3774 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3775 val = charset_list; | |
3776 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3777 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3778 | |
3779 while (1) | |
3780 { | |
3781 int c, c1; | |
3782 | |
3783 src_base = src; | |
3784 consumed_chars_base = consumed_chars; | |
3785 | |
3786 if (charbuf >= charbuf_end) | |
3787 break; | |
3788 | |
3789 ONE_MORE_BYTE (c); | |
3790 | |
3791 if (c == '\r') | |
3792 { | |
3793 if (EQ (eol_type, Qdos)) | |
3794 { | |
3795 if (src == src_end) | |
3796 goto no_more_source; | |
3797 if (*src == '\n') | |
3798 ONE_MORE_BYTE (c); | |
3799 } | |
3800 else if (EQ (eol_type, Qmac)) | |
3801 c = '\n'; | |
3802 } | |
3803 else | |
3804 { | |
3805 struct charset *charset; | |
3806 if (c < 0x80) | |
3807 charset = charset_roman; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3808 else |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3809 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3810 /* BIG5 -> Big5 */ |
88365 | 3811 if (c < 0xA1 || c > 0xFE) |
3812 goto invalid_code; | |
3813 ONE_MORE_BYTE (c1); | |
3814 if (c1 < 0x40 || (c1 > 0x7E && c1 < 0xA1) || c1 > 0xFE) | |
3815 goto invalid_code; | |
3816 c = c << 8 | c1; | |
3817 charset = charset_big5; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3818 } |
88365 | 3819 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
|
3820 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3821 |
88365 | 3822 *charbuf++ = c; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3823 continue; |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3824 |
88365 | 3825 invalid_code: |
17052 | 3826 src = src_base; |
88365 | 3827 consumed_chars = consumed_chars_base; |
3828 ONE_MORE_BYTE (c); | |
3829 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
3830 coding->errors++; | |
3831 } | |
3832 | |
3833 no_more_source: | |
3834 coding->consumed_char += consumed_chars_base; | |
3835 coding->consumed = src_base - coding->source; | |
3836 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3837 } |
3838 | |
3839 /* 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
|
3840 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
|
3841 `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
|
3842 are sure that all these charsets are registered as official charset |
17052 | 3843 (i.e. do not have extended leading-codes). Characters of other |
3844 charsets are produced without any encoding. If SJIS_P is 1, encode | |
3845 SJIS text, else encode BIG5 text. */ | |
3846 | |
88365 | 3847 static int |
3848 encode_coding_sjis (coding) | |
17052 | 3849 struct coding_system *coding; |
3850 { | |
88365 | 3851 int multibytep = coding->dst_multibyte; |
3852 int *charbuf = coding->charbuf; | |
3853 int *charbuf_end = charbuf + coding->charbuf_used; | |
3854 unsigned char *dst = coding->destination + coding->produced; | |
3855 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3856 int safe_room = 4; | |
3857 int produced_chars = 0; | |
3858 Lisp_Object attrs, eol_type, charset_list, val; | |
3859 int ascii_compatible; | |
3860 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3861 int c; | |
3862 | |
3863 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3864 val = charset_list; | |
3865 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3866 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3867 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3868 | |
3869 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3870 | |
3871 while (charbuf < charbuf_end) | |
3872 { | |
3873 ASSURE_DESTINATION (safe_room); | |
3874 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3875 /* Now encode the character C. */ |
88365 | 3876 if (ASCII_CHAR_P (c) && ascii_compatible) |
3877 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
|
3878 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3879 { |
88365 | 3880 unsigned code; |
3881 struct charset *charset = char_charset (c, charset_list, &code); | |
3882 | |
3883 if (!charset) | |
3884 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3885 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
|
3886 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3887 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3888 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3889 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3890 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3891 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3892 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3893 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
|
3894 } |
88365 | 3895 } |
3896 if (code == CHARSET_INVALID_CODE (charset)) | |
3897 abort (); | |
3898 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
|
3899 { |
88365 | 3900 int c1, c2; |
3901 JIS_TO_SJIS (code); | |
3902 c1 = code >> 8, c2 = code & 0xFF; | |
3903 EMIT_TWO_BYTES (c1, c2); | |
3904 } | |
3905 else if (charset == charset_kana) | |
3906 EMIT_ONE_BYTE (code | 0x80); | |
3907 else | |
3908 EMIT_ONE_ASCII_BYTE (code & 0x7F); | |
3909 } | |
3910 } | |
3911 coding->result = CODING_RESULT_SUCCESS; | |
3912 coding->produced_char += produced_chars; | |
3913 coding->produced = dst - coding->destination; | |
3914 return 0; | |
3915 } | |
3916 | |
3917 static int | |
3918 encode_coding_big5 (coding) | |
3919 struct coding_system *coding; | |
3920 { | |
3921 int multibytep = coding->dst_multibyte; | |
3922 int *charbuf = coding->charbuf; | |
3923 int *charbuf_end = charbuf + coding->charbuf_used; | |
3924 unsigned char *dst = coding->destination + coding->produced; | |
3925 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3926 int safe_room = 4; | |
3927 int produced_chars = 0; | |
3928 Lisp_Object attrs, eol_type, charset_list, val; | |
3929 int ascii_compatible; | |
3930 struct charset *charset_roman, *charset_big5; | |
3931 int c; | |
3932 | |
3933 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3934 val = charset_list; | |
3935 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3936 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3937 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3938 | |
3939 while (charbuf < charbuf_end) | |
3940 { | |
3941 ASSURE_DESTINATION (safe_room); | |
3942 c = *charbuf++; | |
3943 /* Now encode the character C. */ | |
3944 if (ASCII_CHAR_P (c) && ascii_compatible) | |
3945 EMIT_ONE_ASCII_BYTE (c); | |
3946 else | |
3947 { | |
3948 unsigned code; | |
3949 struct charset *charset = char_charset (c, charset_list, &code); | |
3950 | |
3951 if (! charset) | |
3952 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3953 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
|
3954 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3955 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3956 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3957 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3958 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3959 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3960 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3961 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
|
3962 } |
88365 | 3963 } |
3964 if (code == CHARSET_INVALID_CODE (charset)) | |
3965 abort (); | |
3966 if (charset == charset_big5) | |
3967 { | |
3968 int c1, c2; | |
3969 | |
3970 c1 = code >> 8, c2 = code & 0xFF; | |
3971 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
|
3972 } |
17052 | 3973 else |
88365 | 3974 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
17052 | 3975 } |
88365 | 3976 } |
3977 coding->result = CODING_RESULT_SUCCESS; | |
3978 coding->produced_char += produced_chars; | |
3979 coding->produced = dst - coding->destination; | |
3980 return 0; | |
17052 | 3981 } |
3982 | |
3983 | |
88365 | 3984 /*** 10. CCL handlers ***/ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3985 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3986 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3987 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
|
3988 encoder/decoder are written in CCL program. If it is, return |
88365 | 3989 CATEGORY_MASK_CCL, else return 0. */ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
3990 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3991 static int |
88365 | 3992 detect_coding_ccl (coding, mask) |
3993 struct coding_system *coding; | |
3994 int *mask; | |
3995 { | |
3996 unsigned char *src = coding->source, *src_base = src; | |
3997 unsigned char *src_end = coding->source + coding->src_bytes; | |
3998 int multibytep = coding->src_multibyte; | |
3999 int consumed_chars = 0; | |
4000 int found = 0; | |
4001 unsigned char *valids = CODING_CCL_VALIDS (coding); | |
4002 int head_ascii = coding->head_ascii; | |
4003 Lisp_Object attrs; | |
4004 | |
4005 coding = &coding_categories[coding_category_ccl]; | |
4006 attrs = CODING_ID_ATTRS (coding->id); | |
4007 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4008 src += head_ascii; | |
4009 | |
4010 while (1) | |
4011 { | |
4012 int c; | |
4013 ONE_MORE_BYTE (c); | |
4014 if (! valids[c]) | |
4015 break; | |
4016 if (!found && valids[c] > 1) | |
4017 found = 1; | |
4018 } | |
4019 *mask &= ~CATEGORY_MASK_CCL; | |
4020 return 0; | |
4021 | |
4022 no_more_source: | |
4023 if (!found) | |
4024 return 0; | |
4025 *mask &= CATEGORY_MASK_CCL; | |
4026 return 1; | |
4027 } | |
4028 | |
4029 static void | |
4030 decode_coding_ccl (coding) | |
4031 struct coding_system *coding; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4032 { |
88365 | 4033 unsigned char *src = coding->source + coding->consumed; |
4034 unsigned char *src_end = coding->source + coding->src_bytes; | |
4035 int *charbuf = coding->charbuf; | |
4036 int *charbuf_end = charbuf + coding->charbuf_size; | |
4037 int consumed_chars = 0; | |
4038 int multibytep = coding->src_multibyte; | |
4039 struct ccl_program ccl; | |
4040 int source_charbuf[1024]; | |
4041 int source_byteidx[1024]; | |
4042 | |
4043 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); | |
4044 | |
4045 while (src < src_end) | |
4046 { | |
4047 unsigned char *p = src; | |
4048 int *source, *source_end; | |
4049 int i = 0; | |
4050 | |
4051 if (multibytep) | |
4052 while (i < 1024 && p < src_end) | |
4053 { | |
4054 source_byteidx[i] = p - src; | |
4055 source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | |
4056 } | |
4057 else | |
4058 while (i < 1024 && p < src_end) | |
4059 source_charbuf[i++] = *p++; | |
4060 | |
4061 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) | |
4062 ccl.last_block = 1; | |
4063 | |
4064 source = source_charbuf; | |
4065 source_end = source + i; | |
4066 while (source < source_end) | |
4067 { | |
4068 ccl_driver (&ccl, source, charbuf, | |
4069 source_end - source, charbuf_end - charbuf); | |
4070 source += ccl.consumed; | |
4071 charbuf += ccl.produced; | |
4072 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
4073 break; | |
4074 } | |
4075 if (source < source_end) | |
4076 src += source_byteidx[source - source_charbuf]; | |
4077 else | |
4078 src = p; | |
4079 consumed_chars += source - source_charbuf; | |
4080 | |
4081 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
4082 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
4083 break; | |
4084 } | |
4085 | |
4086 switch (ccl.status) | |
4087 { | |
4088 case CCL_STAT_SUSPEND_BY_SRC: | |
4089 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4090 break; | |
4091 case CCL_STAT_SUSPEND_BY_DST: | |
4092 break; | |
4093 case CCL_STAT_QUIT: | |
4094 case CCL_STAT_INVALID_CMD: | |
4095 coding->result = CODING_RESULT_INTERRUPT; | |
4096 break; | |
4097 default: | |
4098 coding->result = CODING_RESULT_SUCCESS; | |
4099 break; | |
4100 } | |
4101 coding->consumed_char += consumed_chars; | |
4102 coding->consumed = src - coding->source; | |
4103 coding->charbuf_used = charbuf - coding->charbuf; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4104 } |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4105 |
88365 | 4106 static int |
4107 encode_coding_ccl (coding) | |
4108 struct coding_system *coding; | |
4109 { | |
4110 struct ccl_program ccl; | |
4111 int multibytep = coding->dst_multibyte; | |
4112 int *charbuf = coding->charbuf; | |
4113 int *charbuf_end = charbuf + coding->charbuf_used; | |
4114 unsigned char *dst = coding->destination + coding->produced; | |
4115 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4116 unsigned char *adjusted_dst_end = dst_end - 1; | |
4117 int destination_charbuf[1024]; | |
4118 int i, produced_chars = 0; | |
4119 | |
4120 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); | |
4121 | |
4122 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; | |
4123 ccl.dst_multibyte = coding->dst_multibyte; | |
4124 | |
4125 while (charbuf < charbuf_end && dst < adjusted_dst_end) | |
4126 { | |
4127 int dst_bytes = dst_end - dst; | |
4128 if (dst_bytes > 1024) | |
4129 dst_bytes = 1024; | |
4130 | |
4131 ccl_driver (&ccl, charbuf, destination_charbuf, | |
4132 charbuf_end - charbuf, dst_bytes); | |
4133 charbuf += ccl.consumed; | |
4134 if (multibytep) | |
4135 for (i = 0; i < ccl.produced; i++) | |
4136 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); | |
4137 else | |
4138 { | |
4139 for (i = 0; i < ccl.produced; i++) | |
4140 *dst++ = destination_charbuf[i] & 0xFF; | |
4141 produced_chars += ccl.produced; | |
4142 } | |
4143 } | |
4144 | |
4145 switch (ccl.status) | |
4146 { | |
4147 case CCL_STAT_SUSPEND_BY_SRC: | |
4148 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4149 break; | |
4150 case CCL_STAT_SUSPEND_BY_DST: | |
4151 coding->result = CODING_RESULT_INSUFFICIENT_DST; | |
4152 break; | |
4153 case CCL_STAT_QUIT: | |
4154 case CCL_STAT_INVALID_CMD: | |
4155 coding->result = CODING_RESULT_INTERRUPT; | |
4156 break; | |
4157 default: | |
4158 coding->result = CODING_RESULT_SUCCESS; | |
4159 break; | |
4160 } | |
4161 | |
4162 coding->produced_char += produced_chars; | |
4163 coding->produced = dst - coding->destination; | |
4164 return 0; | |
4165 } | |
4166 | |
4167 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4168 |
88365 | 4169 /*** 10, 11. no-conversion handlers ***/ |
17052 | 4170 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4171 /* 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
|
4172 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4173 static void |
88365 | 4174 decode_coding_raw_text (coding) |
17052 | 4175 struct coding_system *coding; |
4176 { | |
88365 | 4177 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
|
4178 coding->consumed_char = 0; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4179 coding->consumed = 0; |
88365 | 4180 coding->result = CODING_RESULT_SUCCESS; |
4181 } | |
4182 | |
4183 static int | |
4184 encode_coding_raw_text (coding) | |
4185 struct coding_system *coding; | |
4186 { | |
4187 int multibytep = coding->dst_multibyte; | |
4188 int *charbuf = coding->charbuf; | |
4189 int *charbuf_end = coding->charbuf + coding->charbuf_used; | |
4190 unsigned char *dst = coding->destination + coding->produced; | |
4191 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4192 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
|
4193 int c; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4194 |
88365 | 4195 if (multibytep) |
4196 { | |
4197 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
4198 | |
4199 if (coding->src_multibyte) | |
4200 while (charbuf < charbuf_end) | |
4201 { | |
4202 ASSURE_DESTINATION (safe_room); | |
4203 c = *charbuf++; | |
4204 if (ASCII_CHAR_P (c)) | |
4205 EMIT_ONE_ASCII_BYTE (c); | |
4206 else if (CHAR_BYTE8_P (c)) | |
4207 { | |
4208 c = CHAR_TO_BYTE8 (c); | |
4209 EMIT_ONE_BYTE (c); | |
4210 } | |
4211 else | |
4212 { | |
4213 unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | |
4214 | |
4215 CHAR_STRING_ADVANCE (c, p1); | |
4216 while (p0 < p1) | |
4217 EMIT_ONE_BYTE (*p0); | |
4218 } | |
4219 } | |
4220 else | |
4221 while (charbuf < charbuf_end) | |
4222 { | |
4223 ASSURE_DESTINATION (safe_room); | |
4224 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4225 EMIT_ONE_BYTE (c); |
88365 | 4226 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4227 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4228 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4229 { |
88365 | 4230 if (coding->src_multibyte) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4231 { |
88365 | 4232 int safe_room = MAX_MULTIBYTE_LENGTH; |
4233 | |
4234 while (charbuf < charbuf_end) | |
4235 { | |
4236 ASSURE_DESTINATION (safe_room); | |
4237 c = *charbuf++; | |
4238 if (ASCII_CHAR_P (c)) | |
4239 *dst++ = c; | |
4240 else if (CHAR_BYTE8_P (c)) | |
4241 *dst++ = CHAR_TO_BYTE8 (c); | |
4242 else | |
4243 CHAR_STRING_ADVANCE (c, dst); | |
4244 produced_chars++; | |
4245 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4246 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4247 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4248 { |
88365 | 4249 ASSURE_DESTINATION (charbuf_end - charbuf); |
4250 while (charbuf < charbuf_end && dst < dst_end) | |
4251 *dst++ = *charbuf++; | |
4252 produced_chars = dst - (coding->destination + coding->dst_bytes); | |
4253 } | |
4254 } | |
4255 coding->result = CODING_RESULT_SUCCESS; | |
4256 coding->produced_char += produced_chars; | |
4257 coding->produced = dst - coding->destination; | |
4258 return 0; | |
4259 } | |
4260 | |
4261 static int | |
4262 detect_coding_charset (coding, mask) | |
4263 struct coding_system *coding; | |
4264 int *mask; | |
4265 { | |
4266 unsigned char *src = coding->source, *src_base = src; | |
4267 unsigned char *src_end = coding->source + coding->src_bytes; | |
4268 int multibytep = coding->src_multibyte; | |
4269 int consumed_chars = 0; | |
4270 Lisp_Object attrs, valids; | |
4271 | |
4272 coding = &coding_categories[coding_category_charset]; | |
4273 attrs = CODING_ID_ATTRS (coding->id); | |
4274 valids = AREF (attrs, coding_attr_charset_valids); | |
4275 | |
4276 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4277 src += coding->head_ascii; | |
4278 | |
4279 while (1) | |
4280 { | |
4281 int c; | |
4282 | |
4283 ONE_MORE_BYTE (c); | |
4284 if (NILP (AREF (valids, c))) | |
4285 break; | |
4286 } | |
4287 *mask &= ~CATEGORY_MASK_CHARSET; | |
4288 return 0; | |
4289 | |
4290 no_more_source: | |
4291 *mask &= CATEGORY_MASK_CHARSET; | |
4292 return 1; | |
4293 } | |
4294 | |
4295 static void | |
4296 decode_coding_charset (coding) | |
4297 struct coding_system *coding; | |
4298 { | |
4299 unsigned char *src = coding->source + coding->consumed; | |
4300 unsigned char *src_end = coding->source + coding->src_bytes; | |
4301 unsigned char *src_base; | |
4302 int *charbuf = coding->charbuf; | |
4303 int *charbuf_end = charbuf + coding->charbuf_size; | |
4304 int consumed_chars = 0, consumed_chars_base; | |
4305 int multibytep = coding->src_multibyte; | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4306 Lisp_Object attrs, eol_type, charset_list, valids; |
88365 | 4307 |
4308 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
|
4309 valids = AREF (attrs, coding_attr_charset_valids); |
88365 | 4310 |
4311 while (1) | |
4312 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4313 int c; |
88365 | 4314 |
4315 src_base = src; | |
4316 consumed_chars_base = consumed_chars; | |
4317 | |
4318 if (charbuf >= charbuf_end) | |
4319 break; | |
4320 | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4321 ONE_MORE_BYTE (c); |
88365 | 4322 if (c == '\r') |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4323 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4324 /* 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
|
4325 else. */ |
88365 | 4326 if (EQ (eol_type, Qdos)) |
4327 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4328 if (src < src_end |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4329 && *src == '\n') |
88365 | 4330 ONE_MORE_BYTE (c); |
4331 } | |
4332 else if (EQ (eol_type, Qmac)) | |
4333 c = '\n'; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4334 } |
88365 | 4335 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4336 { |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4337 Lisp_Object val; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4338 struct charset *charset; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4339 int dim; |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4340 int len = 1; |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4341 unsigned code = c; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4342 |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4343 val = AREF (valids, c); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4344 if (NILP (val)) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4345 goto invalid_code; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4346 if (INTEGERP (val)) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4347 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4348 charset = CHARSET_FROM_ID (XFASTINT (val)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4349 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4350 while (len < dim) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4351 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4352 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4353 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4354 len++; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4355 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4356 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
|
4357 charset, code, c); |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4358 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4359 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4360 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4361 /* 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
|
4362 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
|
4363 comes first). */ |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4364 while (CONSP (val)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4365 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4366 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
|
4367 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4368 while (len < dim) |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4369 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4370 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4371 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4372 len++; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4373 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4374 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
|
4375 src_end, charset, code, c); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4376 if (c >= 0) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4377 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4378 val = XCDR (val); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4379 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4380 } |
88365 | 4381 if (c < 0) |
4382 goto invalid_code; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4383 } |
88365 | 4384 *charbuf++ = c; |
4385 continue; | |
4386 | |
4387 invalid_code: | |
4388 src = src_base; | |
4389 consumed_chars = consumed_chars_base; | |
4390 ONE_MORE_BYTE (c); | |
4391 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
4392 coding->errors++; | |
4393 } | |
4394 | |
4395 no_more_source: | |
4396 coding->consumed_char += consumed_chars_base; | |
4397 coding->consumed = src_base - coding->source; | |
4398 coding->charbuf_used = charbuf - coding->charbuf; | |
4399 } | |
4400 | |
4401 static int | |
4402 encode_coding_charset (coding) | |
4403 struct coding_system *coding; | |
4404 { | |
4405 int multibytep = coding->dst_multibyte; | |
4406 int *charbuf = coding->charbuf; | |
4407 int *charbuf_end = charbuf + coding->charbuf_used; | |
4408 unsigned char *dst = coding->destination + coding->produced; | |
4409 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4410 int safe_room = MAX_MULTIBYTE_LENGTH; | |
4411 int produced_chars = 0; | |
4412 Lisp_Object attrs, eol_type, charset_list; | |
4413 int ascii_compatible; | |
4414 int c; | |
4415 | |
4416 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4417 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4418 | |
4419 while (charbuf < charbuf_end) | |
4420 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4421 struct charset *charset; |
88365 | 4422 unsigned code; |
4423 | |
4424 ASSURE_DESTINATION (safe_room); | |
4425 c = *charbuf++; | |
4426 if (ascii_compatible && ASCII_CHAR_P (c)) | |
4427 EMIT_ONE_ASCII_BYTE (c); | |
4428 else | |
88465
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 charset = char_charset (c, charset_list, &code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4431 if (charset) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4432 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4433 if (CHARSET_DIMENSION (charset) == 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4434 EMIT_ONE_BYTE (code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4435 else if (CHARSET_DIMENSION (charset) == 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4436 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4437 else if (CHARSET_DIMENSION (charset) == 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4438 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
|
4439 else |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4440 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
|
4441 (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4442 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4443 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4444 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4445 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
|
4446 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4447 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4448 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4449 EMIT_ONE_BYTE (c); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4450 } |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4451 } |
88365 | 4452 } |
4453 | |
4454 coding->result = CODING_RESULT_SUCCESS; | |
4455 coding->produced_char += produced_chars; | |
4456 coding->produced = dst - coding->destination; | |
4457 return 0; | |
17052 | 4458 } |
4459 | |
4460 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4461 /*** 7. C library functions ***/ |
17052 | 4462 |
88365 | 4463 /* In Emacs Lisp, coding system is represented by a Lisp symbol which |
17052 | 4464 has a property `coding-system'. The value of this property is a |
88365 | 4465 vector of length 5 (called as coding-vector). Among elements of |
17052 | 4466 this vector, the first (element[0]) and the fifth (element[4]) |
4467 carry important information for decoding/encoding. Before | |
4468 decoding/encoding, this information should be set in fields of a | |
4469 structure of type `coding_system'. | |
4470 | |
88365 | 4471 A value of property `coding-system' can be a symbol of another |
17052 | 4472 subsidiary coding-system. In that case, Emacs gets coding-vector |
4473 from that symbol. | |
4474 | |
4475 `element[0]' contains information to be set in `coding->type'. The | |
4476 value and its meaning is as follows: | |
4477 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4478 0 -- coding_type_emacs_mule |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4479 1 -- coding_type_sjis |
88365 | 4480 2 -- coding_type_iso_2022 |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4481 3 -- coding_type_big5 |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4482 4 -- coding_type_ccl encoder/decoder written in CCL |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4483 nil -- coding_type_no_conversion |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4484 t -- coding_type_undecided (automatic conversion on decoding, |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4485 no-conversion on encoding) |
17052 | 4486 |
4487 `element[4]' contains information to be set in `coding->flags' and | |
4488 `coding->spec'. The meaning varies by `coding->type'. | |
4489 | |
88365 | 4490 If `coding->type' is `coding_type_iso_2022', element[4] is a vector |
17052 | 4491 of length 32 (of which the first 13 sub-elements are used now). |
4492 Meanings of these sub-elements are: | |
4493 | |
88365 | 4494 sub-element[N] where N is 0 through 3: to be set in `coding->spec.iso_2022' |
17052 | 4495 If the value is an integer of valid charset, the charset is |
4496 assumed to be designated to graphic register N initially. | |
4497 | |
4498 If the value is minus, it is a minus value of charset which | |
4499 reserves graphic register N, which means that the charset is | |
4500 not designated initially but should be designated to graphic | |
4501 register N just before encoding a character in that charset. | |
4502 | |
4503 If the value is nil, graphic register N is never used on | |
4504 encoding. | |
88365 | 4505 |
17052 | 4506 sub-element[N] where N is 4 through 11: to be set in `coding->flags' |
4507 Each value takes t or nil. See the section ISO2022 of | |
4508 `coding.h' for more information. | |
4509 | |
4510 If `coding->type' is `coding_type_big5', element[4] is t to denote | |
4511 BIG5-ETen or nil to denote BIG5-HKU. | |
4512 | |
4513 If `coding->type' takes the other value, element[4] is ignored. | |
4514 | |
88365 | 4515 Emacs Lisp's coding system also carries information about format of |
17052 | 4516 end-of-line in a value of property `eol-type'. If the value is |
88365 | 4517 integer, 0 means eol_lf, 1 means eol_crlf, and 2 means eol_cr. If |
4518 it is not integer, it should be a vector of subsidiary coding | |
4519 systems of which property `eol-type' has one of above values. | |
17052 | 4520 |
4521 */ | |
4522 | |
88365 | 4523 /* Setup coding context CODING from information about CODING_SYSTEM. |
4524 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
4525 CODING_SYSTEM is invalid, signal an error. */ | |
4526 | |
4527 void | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4528 setup_coding_system (coding_system, coding) |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4529 Lisp_Object coding_system; |
17052 | 4530 struct coding_system *coding; |
4531 { | |
88365 | 4532 Lisp_Object attrs; |
4533 Lisp_Object eol_type; | |
4534 Lisp_Object coding_type; | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
4535 Lisp_Object val; |
17052 | 4536 |
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
4537 if (NILP (coding_system)) |
88365 | 4538 coding_system = Qno_conversion; |
4539 | |
4540 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
4541 | |
4542 attrs = CODING_ID_ATTRS (coding->id); | |
4543 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4544 | |
4545 coding->mode = 0; | |
4546 coding->head_ascii = -1; | |
4547 coding->common_flags | |
4548 = (VECTORP (eol_type) ? CODING_REQUIRE_DETECTION_MASK : 0); | |
4549 | |
4550 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4551 coding->max_charset_id = XSTRING (val)->size - 1; | |
4552 coding->safe_charsets = (char *) XSTRING (val)->data; | |
4553 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); | |
4554 | |
4555 coding_type = CODING_ATTR_TYPE (attrs); | |
4556 if (EQ (coding_type, Qundecided)) | |
4557 { | |
4558 coding->detector = NULL; | |
4559 coding->decoder = decode_coding_raw_text; | |
4560 coding->encoder = encode_coding_raw_text; | |
4561 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
4562 } | |
4563 else if (EQ (coding_type, Qiso_2022)) | |
4564 { | |
4565 int i; | |
4566 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
4567 | |
4568 /* Invoke graphic register 0 to plane 0. */ | |
4569 CODING_ISO_INVOCATION (coding, 0) = 0; | |
4570 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
4571 CODING_ISO_INVOCATION (coding, 1) | |
4572 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
4573 /* Setup the initial status of designation. */ | |
4574 for (i = 0; i < 4; i++) | |
4575 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
4576 /* Not single shifting initially. */ | |
4577 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
4578 /* Beginning of buffer should also be regarded as bol. */ | |
4579 CODING_ISO_BOL (coding) = 1; | |
4580 coding->detector = detect_coding_iso_2022; | |
4581 coding->decoder = decode_coding_iso_2022; | |
4582 coding->encoder = encode_coding_iso_2022; | |
4583 if (flags & CODING_ISO_FLAG_SAFE) | |
4584 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4585 coding->common_flags |
88365 | 4586 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4587 | CODING_REQUIRE_FLUSHING_MASK); | |
4588 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
4589 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
4590 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
|
4591 { |
88365 | 4592 setup_iso_safe_charsets (attrs); |
4593 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4594 coding->max_charset_id = XSTRING (val)->size - 1; | |
4595 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
|
4596 } |
88365 | 4597 CODING_ISO_FLAGS (coding) = flags; |
4598 } | |
4599 else if (EQ (coding_type, Qcharset)) | |
4600 { | |
4601 coding->detector = detect_coding_charset; | |
4602 coding->decoder = decode_coding_charset; | |
4603 coding->encoder = encode_coding_charset; | |
4604 coding->common_flags | |
4605 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4606 } | |
4607 else if (EQ (coding_type, Qutf_8)) | |
4608 { | |
4609 coding->detector = detect_coding_utf_8; | |
4610 coding->decoder = decode_coding_utf_8; | |
4611 coding->encoder = encode_coding_utf_8; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
4612 coding->common_flags |
88365 | 4613 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4614 } | |
4615 else if (EQ (coding_type, Qutf_16)) | |
4616 { | |
4617 val = AREF (attrs, coding_attr_utf_16_bom); | |
4618 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_16_detect_bom | |
4619 : EQ (val, Qt) ? utf_16_with_bom | |
4620 : utf_16_without_bom); | |
4621 val = AREF (attrs, coding_attr_utf_16_endian); | |
4622 CODING_UTF_16_ENDIAN (coding) = (NILP (val) ? utf_16_big_endian | |
4623 : utf_16_little_endian); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
4624 CODING_UTF_16_SURROGATE (coding) = 0; |
88365 | 4625 coding->detector = detect_coding_utf_16; |
4626 coding->decoder = decode_coding_utf_16; | |
4627 coding->encoder = encode_coding_utf_16; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4628 coding->common_flags |
88365 | 4629 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4630 } | |
4631 else if (EQ (coding_type, Qccl)) | |
4632 { | |
4633 coding->detector = detect_coding_ccl; | |
4634 coding->decoder = decode_coding_ccl; | |
4635 coding->encoder = encode_coding_ccl; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4636 coding->common_flags |
88365 | 4637 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4638 | CODING_REQUIRE_FLUSHING_MASK); | |
4639 } | |
4640 else if (EQ (coding_type, Qemacs_mule)) | |
4641 { | |
4642 coding->detector = detect_coding_emacs_mule; | |
4643 coding->decoder = decode_coding_emacs_mule; | |
4644 coding->encoder = encode_coding_emacs_mule; | |
4645 coding->common_flags | |
4646 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4647 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) | |
4648 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
4649 { | |
4650 Lisp_Object tail, safe_charsets; | |
4651 int max_charset_id = 0; | |
4652 | |
4653 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4654 tail = XCDR (tail)) | |
4655 if (max_charset_id < XFASTINT (XCAR (tail))) | |
4656 max_charset_id = XFASTINT (XCAR (tail)); | |
4657 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
4658 make_number (255)); | |
4659 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4660 tail = XCDR (tail)) | |
4661 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
4662 coding->max_charset_id = max_charset_id; | |
4663 coding->safe_charsets = (char *) XSTRING (safe_charsets)->data; | |
4664 } | |
4665 } | |
4666 else if (EQ (coding_type, Qshift_jis)) | |
4667 { | |
4668 coding->detector = detect_coding_sjis; | |
4669 coding->decoder = decode_coding_sjis; | |
4670 coding->encoder = encode_coding_sjis; | |
4671 coding->common_flags | |
4672 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4673 } | |
4674 else if (EQ (coding_type, Qbig5)) | |
4675 { | |
4676 coding->detector = detect_coding_big5; | |
4677 coding->decoder = decode_coding_big5; | |
4678 coding->encoder = encode_coding_big5; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4679 coding->common_flags |
88365 | 4680 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4681 } | |
4682 else /* EQ (coding_type, Qraw_text) */ | |
4683 { | |
4684 coding->detector = NULL; | |
4685 coding->decoder = decode_coding_raw_text; | |
4686 coding->encoder = encode_coding_raw_text; | |
4687 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
4688 } | |
4689 | |
4690 return; | |
17052 | 4691 } |
4692 | |
88365 | 4693 /* Return raw-text or one of its subsidiaries that has the same |
4694 eol_type as CODING-SYSTEM. */ | |
4695 | |
4696 Lisp_Object | |
4697 raw_text_coding_system (coding_system) | |
4698 Lisp_Object coding_system; | |
26847 | 4699 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4700 Lisp_Object spec, attrs; |
88365 | 4701 Lisp_Object eol_type, raw_text_eol_type; |
4702 | |
4703 spec = CODING_SYSTEM_SPEC (coding_system); | |
4704 attrs = AREF (spec, 0); | |
4705 | |
4706 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
4707 return coding_system; | |
4708 | |
4709 eol_type = AREF (spec, 2); | |
4710 if (VECTORP (eol_type)) | |
4711 return Qraw_text; | |
4712 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
4713 raw_text_eol_type = AREF (spec, 2); | |
4714 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
4715 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
4716 : AREF (raw_text_eol_type, 2)); | |
26847 | 4717 } |
4718 | |
88365 | 4719 |
4720 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
4721 does, return one of the subsidiary that has the same eol-spec as | |
4722 PARENT. Otherwise, return CODING_SYSTEM. */ | |
4723 | |
4724 Lisp_Object | |
4725 coding_inherit_eol_type (coding_system, parent) | |
88473 | 4726 Lisp_Object coding_system, parent; |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4727 { |
88365 | 4728 Lisp_Object spec, attrs, eol_type; |
4729 | |
4730 spec = CODING_SYSTEM_SPEC (coding_system); | |
4731 attrs = AREF (spec, 0); | |
4732 eol_type = AREF (spec, 2); | |
4733 if (VECTORP (eol_type)) | |
4734 { | |
4735 Lisp_Object parent_spec; | |
4736 Lisp_Object parent_eol_type; | |
4737 | |
4738 parent_spec | |
4739 = CODING_SYSTEM_SPEC (buffer_defaults.buffer_file_coding_system); | |
4740 parent_eol_type = AREF (parent_spec, 2); | |
4741 if (EQ (parent_eol_type, Qunix)) | |
4742 coding_system = AREF (eol_type, 0); | |
4743 else if (EQ (parent_eol_type, Qdos)) | |
4744 coding_system = AREF (eol_type, 1); | |
4745 else if (EQ (parent_eol_type, Qmac)) | |
4746 coding_system = AREF (eol_type, 2); | |
4747 } | |
4748 return coding_system; | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4749 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4750 |
17052 | 4751 /* Emacs has a mechanism to automatically detect a coding system if it |
4752 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
4753 it's impossible to distinguish some coding systems accurately | |
4754 because they use the same range of codes. So, at first, coding | |
4755 systems are categorized into 7, those are: | |
4756 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4757 o coding-category-emacs-mule |
17052 | 4758 |
4759 The category for a coding system which has the same code range | |
4760 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
|
4761 symbol) `emacs-mule' by default. |
17052 | 4762 |
4763 o coding-category-sjis | |
4764 | |
4765 The category for a coding system which has the same code range | |
4766 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
|
4767 symbol) `japanese-shift-jis' by default. |
17052 | 4768 |
4769 o coding-category-iso-7 | |
4770 | |
4771 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
|
4772 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
|
4773 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
|
4774 charsets. Assigned the coding-system (Lisp symbol) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4775 `iso-2022-7bit' by default. |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4776 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4777 o coding-category-iso-7-tight |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4778 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4779 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
|
4780 encode/decode only the specified charsets. |
17052 | 4781 |
4782 o coding-category-iso-8-1 | |
4783 | |
4784 The category for a coding system which has the same code range | |
4785 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
|
4786 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
|
4787 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
|
4788 symbol) `iso-latin-1' by default. |
17052 | 4789 |
4790 o coding-category-iso-8-2 | |
4791 | |
4792 The category for a coding system which has the same code range | |
4793 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
|
4794 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
|
4795 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
|
4796 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
|
4797 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4798 o coding-category-iso-7-else |
17052 | 4799 |
4800 The category for a coding system which has the same code range | |
88365 | 4801 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
|
4802 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
|
4803 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
|
4804 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4805 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
|
4806 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4807 The category for a coding system which has the same code range |
88365 | 4808 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
|
4809 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
|
4810 symbol) `iso-2022-8bit-ss2' by default. |
17052 | 4811 |
4812 o coding-category-big5 | |
4813 | |
4814 The category for a coding system which has the same code range | |
4815 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
|
4816 `cn-big5' by default. |
17052 | 4817 |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4818 o coding-category-utf-8 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4819 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4820 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
|
4821 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
|
4822 symbol) `utf-8' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4823 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4824 o coding-category-utf-16-be |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4825 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4826 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
|
4827 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
|
4828 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
|
4829 `utf-16-be' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4830 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4831 o coding-category-utf-16-le |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4832 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4833 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
|
4834 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
|
4835 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
|
4836 symbol) `utf-16-le' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4837 |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4838 o coding-category-ccl |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4839 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4840 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
|
4841 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
|
4842 coding system is assigned. |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4843 |
17052 | 4844 o coding-category-binary |
4845 | |
4846 The category for a coding system not categorized in any of the | |
4847 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
|
4848 `no-conversion' by default. |
17052 | 4849 |
4850 Each of them is a Lisp symbol and the value is an actual | |
88365 | 4851 `coding-system's (this is also a Lisp symbol) assigned by a user. |
17052 | 4852 What Emacs does actually is to detect a category of coding system. |
4853 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
88365 | 4854 decide only one possible category, it selects a category of the |
17052 | 4855 highest priority. Priorities of categories are also specified by a |
4856 user in a Lisp variable `coding-category-list'. | |
4857 | |
4858 */ | |
4859 | |
88365 | 4860 #define EOL_SEEN_NONE 0 |
4861 #define EOL_SEEN_LF 1 | |
4862 #define EOL_SEEN_CR 2 | |
4863 #define EOL_SEEN_CRLF 4 | |
4864 | |
4865 /* Detect how end-of-line of a text of length CODING->src_bytes | |
4866 pointed by CODING->source is encoded. Return one of | |
4867 EOL_SEEN_XXX. */ | |
17052 | 4868 |
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
4869 #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
|
4870 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4871 static int |
88365 | 4872 detect_eol (coding, source, src_bytes) |
4873 struct coding_system *coding; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4874 unsigned char *source; |
88365 | 4875 EMACS_INT src_bytes; |
17052 | 4876 { |
88365 | 4877 Lisp_Object attrs, coding_type; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4878 unsigned char *src = source, *src_end = src + src_bytes; |
17052 | 4879 unsigned char c; |
88365 | 4880 int total = 0; |
4881 int eol_seen = EOL_SEEN_NONE; | |
4882 | |
4883 attrs = CODING_ID_ATTRS (coding->id); | |
4884 coding_type = CODING_ATTR_TYPE (attrs); | |
4885 | |
4886 if (EQ (coding_type, Qccl)) | |
4887 { | |
4888 int msb, lsb; | |
4889 | |
4890 msb = coding->spec.utf_16.endian == utf_16_little_endian; | |
4891 lsb = 1 - msb; | |
4892 | |
4893 while (src + 1 < src_end) | |
17052 | 4894 { |
88365 | 4895 c = src[lsb]; |
4896 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
|
4897 { |
88365 | 4898 int this_eol; |
4899 | |
4900 if (c == '\n') | |
4901 this_eol = EOL_SEEN_LF; | |
4902 else if (src + 3 >= src_end | |
4903 || src[msb + 2] != 0 | |
4904 || src[lsb + 2] != '\n') | |
4905 this_eol = EOL_SEEN_CR; | |
4906 else | |
4907 this_eol = EOL_SEEN_CRLF; | |
4908 | |
4909 if (eol_seen == EOL_SEEN_NONE) | |
4910 /* This is the first end-of-line. */ | |
4911 eol_seen = this_eol; | |
4912 else if (eol_seen != this_eol) | |
4913 { | |
4914 /* The found type is different from what found before. */ | |
4915 eol_seen = EOL_SEEN_LF; | |
4916 break; | |
4917 } | |
4918 if (++total == MAX_EOL_CHECK_COUNT) | |
4919 break; | |
4920 } | |
4921 src += 2; | |
4922 } | |
4923 } | |
4924 else | |
4925 { | |
4926 while (src < src_end) | |
4927 { | |
4928 c = *src++; | |
4929 if (c == '\n' || c == '\r') | |
4930 { | |
4931 int this_eol; | |
4932 | |
4933 if (c == '\n') | |
4934 this_eol = EOL_SEEN_LF; | |
4935 else if (src >= src_end || *src != '\n') | |
4936 this_eol = EOL_SEEN_CR; | |
4937 else | |
4938 this_eol = EOL_SEEN_CRLF, src++; | |
4939 | |
4940 if (eol_seen == EOL_SEEN_NONE) | |
4941 /* This is the first end-of-line. */ | |
4942 eol_seen = this_eol; | |
4943 else if (eol_seen != this_eol) | |
4944 { | |
4945 /* The found type is different from what found before. */ | |
4946 eol_seen = EOL_SEEN_LF; | |
4947 break; | |
4948 } | |
4949 if (++total == MAX_EOL_CHECK_COUNT) | |
4950 break; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4951 } |
17052 | 4952 } |
4953 } | |
88365 | 4954 return eol_seen; |
17052 | 4955 } |
4956 | |
88365 | 4957 |
4958 static void | |
4959 adjust_coding_eol_type (coding, eol_seen) | |
4960 struct coding_system *coding; | |
4961 int eol_seen; | |
4962 { | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4963 Lisp_Object eol_type; |
88365 | 4964 |
4965 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4966 if (eol_seen & EOL_SEEN_LF) | |
4967 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); | |
4968 else if (eol_type & EOL_SEEN_CRLF) | |
4969 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); | |
4970 else if (eol_type & EOL_SEEN_CR) | |
4971 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); | |
4972 } | |
4973 | |
4974 /* Detect how a text specified in CODING is encoded. If a coding | |
4975 system is detected, update fields of CODING by the detected coding | |
4976 system. */ | |
4977 | |
4978 void | |
4979 detect_coding (coding) | |
4980 struct coding_system *coding; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4981 { |
88365 | 4982 unsigned char *src, *src_end; |
4983 Lisp_Object attrs, coding_type; | |
4984 | |
4985 coding->consumed = coding->consumed_char = 0; | |
4986 coding->produced = coding->produced_char = 0; | |
4987 coding_set_source (coding); | |
4988 | |
4989 src_end = coding->source + coding->src_bytes; | |
4990 | |
4991 /* If we have not yet decided the text encoding type, detect it | |
4992 now. */ | |
4993 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
4994 { | |
4995 int mask = CATEGORY_MASK_ANY; | |
4996 int c, i; | |
4997 | |
4998 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
|
4999 { |
88365 | 5000 c = *src; |
5001 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
5002 || c == ISO_CODE_SI | |
5003 || c == ISO_CODE_SO))) | |
5004 break; | |
5005 } | |
5006 coding->head_ascii = src - (coding->source + coding->consumed); | |
5007 | |
5008 if (coding->head_ascii < coding->src_bytes) | |
5009 { | |
5010 int detected = 0; | |
5011 | |
5012 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
|
5013 { |
88365 | 5014 enum coding_category category = coding_priorities[i]; |
5015 struct coding_system *this = coding_categories + category; | |
5016 | |
5017 if (category >= coding_category_raw_text | |
5018 || detected & (1 << category)) | |
5019 continue; | |
5020 | |
5021 if (this->id < 0) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5022 { |
88365 | 5023 /* No coding system of this category is defined. */ |
5024 mask &= ~(1 << category); | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5025 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5026 else |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5027 { |
88365 | 5028 detected |= detected_mask[category]; |
5029 if ((*(this->detector)) (coding, &mask)) | |
5030 break; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5031 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5032 } |
88365 | 5033 if (! mask) |
5034 setup_coding_system (Qraw_text, coding); | |
5035 else if (mask != CATEGORY_MASK_ANY) | |
5036 for (i = 0; i < coding_category_raw_text; i++) | |
5037 { | |
5038 enum coding_category category = coding_priorities[i]; | |
5039 struct coding_system *this = coding_categories + category; | |
5040 | |
5041 if (mask & (1 << category)) | |
5042 { | |
5043 setup_coding_system (CODING_ID_NAME (this->id), coding); | |
5044 break; | |
5045 } | |
5046 } | |
5047 } | |
5048 } | |
5049 | |
5050 attrs = CODING_ID_ATTRS (coding->id); | |
5051 coding_type = CODING_ATTR_TYPE (attrs); | |
5052 | |
5053 /* If we have not yet decided the EOL type, detect it now. But, the | |
5054 detection is impossible for a CCL based coding system, in which | |
5055 case, we detct the EOL type after decoding. */ | |
5056 if (VECTORP (CODING_ID_EOL_TYPE (coding->id)) | |
5057 && ! EQ (coding_type, Qccl)) | |
5058 { | |
5059 int eol_seen = detect_eol (coding, coding->source, coding->src_bytes); | |
5060 | |
5061 if (eol_seen != EOL_SEEN_NONE) | |
5062 adjust_coding_eol_type (coding, eol_seen); | |
5063 } | |
5064 } | |
5065 | |
5066 | |
5067 static void | |
5068 decode_eol (coding) | |
5069 struct coding_system *coding; | |
5070 { | |
5071 if (VECTORP (CODING_ID_EOL_TYPE (coding->id))) | |
5072 { | |
5073 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5074 unsigned char *pend = p + coding->produced; | |
5075 int eol_seen = EOL_SEEN_NONE; | |
5076 | |
5077 for (; p < pend; p++) | |
5078 { | |
5079 if (*p == '\n') | |
5080 eol_seen |= EOL_SEEN_LF; | |
5081 else if (*p == '\r') | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5082 { |
88365 | 5083 if (p + 1 < pend && *(p + 1) == '\n') |
5084 { | |
5085 eol_seen |= EOL_SEEN_CRLF; | |
5086 p++; | |
5087 } | |
5088 else | |
5089 eol_seen |= EOL_SEEN_CR; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5090 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5091 } |
88365 | 5092 if (eol_seen != EOL_SEEN_NONE) |
5093 adjust_coding_eol_type (coding, eol_seen); | |
5094 } | |
5095 | |
5096 if (EQ (CODING_ID_EOL_TYPE (coding->id), Qmac)) | |
5097 { | |
5098 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5099 unsigned char *pend = p + coding->produced; | |
5100 | |
5101 for (; p < pend; p++) | |
5102 if (*p == '\r') | |
5103 *p = '\n'; | |
5104 } | |
5105 else if (EQ (CODING_ID_EOL_TYPE (coding->id), Qdos)) | |
5106 { | |
5107 unsigned char *p, *pbeg, *pend; | |
5108 Lisp_Object undo_list; | |
5109 | |
5110 move_gap_both (coding->dst_pos + coding->produced_char, | |
5111 coding->dst_pos_byte + coding->produced); | |
5112 undo_list = current_buffer->undo_list; | |
5113 current_buffer->undo_list = Qt; | |
5114 del_range_2 (coding->dst_pos, coding->dst_pos_byte, GPT, GPT_BYTE, Qnil); | |
5115 current_buffer->undo_list = undo_list; | |
5116 pbeg = GPT_ADDR; | |
5117 pend = pbeg + coding->produced; | |
5118 | |
5119 for (p = pend - 1; p >= pbeg; p--) | |
5120 if (*p == '\r') | |
5121 { | |
5122 safe_bcopy ((char *) (p + 1), (char *) p, pend - p - 1); | |
5123 pend--; | |
5124 } | |
5125 coding->produced_char -= coding->produced - (pend - pbeg); | |
5126 coding->produced = pend - pbeg; | |
5127 insert_from_gap (coding->produced_char, coding->produced); | |
17052 | 5128 } |
5129 } | |
5130 | |
88365 | 5131 static void |
5132 translate_chars (coding, table) | |
17052 | 5133 struct coding_system *coding; |
88365 | 5134 Lisp_Object table; |
17052 | 5135 { |
88365 | 5136 int *charbuf = coding->charbuf; |
5137 int *charbuf_end = charbuf + coding->charbuf_used; | |
5138 int c; | |
5139 | |
5140 if (coding->chars_at_source) | |
5141 return; | |
5142 | |
5143 while (charbuf < charbuf_end) | |
5144 { | |
5145 c = *charbuf; | |
5146 if (c < 0) | |
5147 charbuf += c; | |
5148 else | |
5149 *charbuf++ = translate_char (table, c); | |
5150 } | |
17052 | 5151 } |
5152 | |
88365 | 5153 static int |
5154 produce_chars (coding) | |
5155 struct coding_system *coding; | |
17052 | 5156 { |
88365 | 5157 unsigned char *dst = coding->destination + coding->produced; |
5158 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5159 int produced; | |
5160 int produced_chars = 0; | |
5161 | |
5162 if (! coding->chars_at_source) | |
5163 { | |
5164 /* Characters are in coding->charbuf. */ | |
5165 int *buf = coding->charbuf; | |
5166 int *buf_end = buf + coding->charbuf_used; | |
5167 unsigned char *adjusted_dst_end; | |
5168 | |
5169 if (BUFFERP (coding->src_object) | |
5170 && EQ (coding->src_object, coding->dst_object)) | |
5171 dst_end = coding->source + coding->consumed; | |
5172 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5173 | |
5174 while (buf < buf_end) | |
5175 { | |
5176 int c = *buf++; | |
5177 | |
5178 if (dst >= adjusted_dst_end) | |
5179 { | |
5180 dst = alloc_destination (coding, | |
5181 buf_end - buf + MAX_MULTIBYTE_LENGTH, | |
5182 dst); | |
5183 dst_end = coding->destination + coding->dst_bytes; | |
5184 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5185 } | |
5186 if (c >= 0) | |
5187 { | |
5188 if (coding->dst_multibyte | |
5189 || ! CHAR_BYTE8_P (c)) | |
5190 CHAR_STRING_ADVANCE (c, dst); | |
5191 else | |
5192 *dst++ = CHAR_TO_BYTE8 (c); | |
5193 produced_chars++; | |
5194 } | |
5195 else | |
5196 /* This is an annotation data. */ | |
5197 buf -= c + 1; | |
5198 } | |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5199 } |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5200 else |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5201 { |
88365 | 5202 unsigned char *src = coding->source; |
5203 unsigned char *src_end = src + coding->src_bytes; | |
5204 Lisp_Object eol_type; | |
5205 | |
5206 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5207 | |
5208 if (coding->src_multibyte != coding->dst_multibyte) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5209 { |
88365 | 5210 if (coding->src_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5211 { |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5212 int multibytep = 1; |
88365 | 5213 int consumed_chars; |
5214 | |
5215 while (1) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5216 { |
88365 | 5217 unsigned char *src_base = src; |
5218 int c; | |
5219 | |
5220 ONE_MORE_BYTE (c); | |
5221 if (c == '\r') | |
5222 { | |
5223 if (EQ (eol_type, Qdos)) | |
5224 { | |
5225 if (src < src_end | |
5226 && *src == '\n') | |
5227 c = *src++; | |
5228 } | |
5229 else if (EQ (eol_type, Qmac)) | |
5230 c = '\n'; | |
5231 } | |
5232 if (dst == dst_end) | |
5233 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5234 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
|
5235 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5236 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
|
5237 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5238 if (dst == dst_end) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5239 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5240 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
|
5241 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5242 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
|
5243 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5244 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
|
5245 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
|
5246 } |
88365 | 5247 } |
5248 *dst++ = c; | |
5249 produced_chars++; | |
5250 } | |
5251 no_more_source: | |
5252 ; | |
5253 } | |
5254 else | |
5255 while (src < src_end) | |
5256 { | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5257 int multibytep = 1; |
88365 | 5258 int c = *src++; |
5259 | |
5260 if (c == '\r') | |
5261 { | |
5262 if (EQ (eol_type, Qdos)) | |
5263 { | |
5264 if (src < src_end | |
5265 && *src == '\n') | |
5266 c = *src++; | |
5267 } | |
5268 else if (EQ (eol_type, Qmac)) | |
5269 c = '\n'; | |
5270 } | |
5271 if (dst >= dst_end - 1) | |
5272 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5273 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
|
5274 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5275 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
|
5276 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5277 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
|
5278 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5279 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
|
5280 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5281 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
|
5282 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5283 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
|
5284 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
|
5285 } |
88365 | 5286 } |
5287 EMIT_ONE_BYTE (c); | |
5288 } | |
5289 } | |
5290 else | |
5291 { | |
5292 if (!EQ (coding->src_object, coding->dst_object)) | |
5293 { | |
5294 int require = coding->src_bytes - coding->dst_bytes; | |
5295 | |
5296 if (require > 0) | |
5297 { | |
5298 EMACS_INT offset = src - coding->source; | |
5299 | |
5300 dst = alloc_destination (coding, require, dst); | |
5301 coding_set_source (coding); | |
5302 src = coding->source + offset; | |
5303 src_end = coding->source + coding->src_bytes; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5304 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5305 } |
88365 | 5306 produced_chars = coding->src_chars; |
5307 while (src < src_end) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5308 { |
88365 | 5309 int c = *src++; |
5310 | |
5311 if (c == '\r') | |
5312 { | |
5313 if (EQ (eol_type, Qdos)) | |
5314 { | |
5315 if (src < src_end | |
5316 && *src == '\n') | |
5317 c = *src++; | |
5318 produced_chars--; | |
5319 } | |
5320 else if (EQ (eol_type, Qmac)) | |
5321 c = '\n'; | |
5322 } | |
5323 *dst++ = c; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5324 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5325 } |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5326 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
|
5327 coding->consumed_char = coding->src_chars; |
88365 | 5328 } |
5329 | |
5330 produced = dst - (coding->destination + coding->produced); | |
5331 if (BUFFERP (coding->dst_object)) | |
5332 insert_from_gap (produced_chars, produced); | |
5333 coding->produced += produced; | |
5334 coding->produced_char += produced_chars; | |
5335 return produced_chars; | |
5336 } | |
5337 | |
5338 /* [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN ] | |
5339 or | |
5340 [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN COMPONENTS... ] | |
5341 */ | |
5342 | |
5343 static INLINE void | |
5344 produce_composition (coding, charbuf) | |
5345 struct coding_system *coding; | |
5346 int *charbuf; | |
5347 { | |
5348 Lisp_Object buffer; | |
5349 int len; | |
5350 EMACS_INT pos; | |
5351 enum composition_method method; | |
5352 int cmp_len; | |
5353 Lisp_Object components; | |
5354 | |
5355 buffer = coding->dst_object; | |
5356 len = -charbuf[0]; | |
5357 pos = coding->dst_pos + charbuf[1]; | |
5358 method = (enum composition_method) (charbuf[3]); | |
5359 cmp_len = charbuf[4]; | |
5360 | |
5361 if (method == COMPOSITION_RELATIVE) | |
5362 components = Qnil; | |
5363 else | |
5364 { | |
5365 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
5366 int i; | |
5367 | |
5368 len -= 5; | |
5369 charbuf += 5; | |
5370 for (i = 0; i < len; i++) | |
5371 args[i] = make_number (charbuf[i]); | |
5372 components = (method == COMPOSITION_WITH_ALTCHARS | |
5373 ? Fstring (len, args) : Fvector (len, args)); | |
5374 } | |
5375 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
|
5376 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5377 |
88365 | 5378 static int * |
5379 save_composition_data (buf, buf_end, prop) | |
5380 int *buf, *buf_end; | |
5381 Lisp_Object prop; | |
5382 { | |
5383 enum composition_method method = COMPOSITION_METHOD (prop); | |
5384 int cmp_len = COMPOSITION_LENGTH (prop); | |
5385 | |
5386 if (buf + 4 + (MAX_COMPOSITION_COMPONENTS * 2 - 1) > buf_end) | |
5387 return NULL; | |
5388 | |
5389 buf[1] = CODING_ANNOTATE_COMPOSITION_MASK; | |
5390 buf[2] = method; | |
5391 buf[3] = cmp_len; | |
5392 | |
5393 if (method == COMPOSITION_RELATIVE) | |
5394 buf[0] = 4; | |
5395 else | |
5396 { | |
5397 Lisp_Object components; | |
5398 int len, i; | |
5399 | |
5400 components = COMPOSITION_COMPONENTS (prop); | |
5401 if (VECTORP (components)) | |
5402 { | |
5403 len = XVECTOR (components)->size; | |
5404 for (i = 0; i < len; i++) | |
5405 buf[4 + i] = XINT (AREF (components, i)); | |
5406 } | |
5407 else if (STRINGP (components)) | |
5408 { | |
5409 int i_byte; | |
5410 | |
5411 len = XSTRING (components)->size; | |
5412 i = i_byte = 0; | |
5413 while (i < len) | |
5414 FETCH_STRING_CHAR_ADVANCE (buf[4 + i], components, i, i_byte); | |
5415 } | |
5416 else if (INTEGERP (components)) | |
5417 { | |
5418 len = 1; | |
5419 buf[4] = XINT (components); | |
5420 } | |
5421 else if (CONSP (components)) | |
5422 { | |
5423 for (len = 0; CONSP (components); | |
5424 len++, components = XCDR (components)) | |
5425 buf[4 + len] = XINT (XCAR (components)); | |
5426 } | |
5427 else | |
5428 abort (); | |
5429 buf[0] = 4 + len; | |
5430 } | |
5431 return (buf + buf[0]); | |
5432 } | |
5433 | |
5434 #define CHARBUF_SIZE 0x4000 | |
5435 | |
5436 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
5437 do { \ | |
5438 int size = CHARBUF_SIZE;; \ | |
5439 \ | |
5440 coding->charbuf = NULL; \ | |
5441 while (size > 1024) \ | |
5442 { \ | |
5443 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
5444 if (coding->charbuf) \ | |
5445 break; \ | |
5446 size >>= 1; \ | |
5447 } \ | |
5448 if (! coding->charbuf) \ | |
5449 { \ | |
5450 coding->result = CODING_RESULT_INSUFFICIENT_MEM; \ | |
5451 return coding->result; \ | |
5452 } \ | |
5453 coding->charbuf_size = size; \ | |
5454 } while (0) | |
5455 | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5456 |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5457 static void |
88365 | 5458 produce_annotation (coding) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5459 struct coding_system *coding; |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5460 { |
88365 | 5461 int *charbuf = coding->charbuf; |
5462 int *charbuf_end = charbuf + coding->charbuf_used; | |
5463 | |
5464 while (charbuf < charbuf_end) | |
5465 { | |
5466 if (*charbuf >= 0) | |
5467 charbuf++; | |
5468 else | |
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
5469 { |
88365 | 5470 int len = -*charbuf; |
5471 switch (charbuf[2]) | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5472 { |
88365 | 5473 case CODING_ANNOTATE_COMPOSITION_MASK: |
5474 produce_composition (coding, charbuf); | |
5475 break; | |
5476 default: | |
5477 abort (); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5478 } |
88365 | 5479 charbuf += len; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5480 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5481 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5482 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5483 |
88365 | 5484 /* Decode the data at CODING->src_object into CODING->dst_object. |
5485 CODING->src_object is a buffer, a string, or nil. | |
5486 CODING->dst_object is a buffer. | |
5487 | |
5488 If CODING->src_object is a buffer, it must be the current buffer. | |
5489 In this case, if CODING->src_pos is positive, it is a position of | |
5490 the source text in the buffer, otherwise, the source text is in the | |
5491 gap area of the buffer, and CODING->src_pos specifies the offset of | |
5492 the text from GPT (which must be the same as PT). If this is the | |
5493 same buffer as CODING->dst_object, CODING->src_pos must be | |
5494 negative. | |
5495 | |
5496 If CODING->src_object is a string, CODING->src_pos in an index to | |
5497 that string. | |
5498 | |
5499 If CODING->src_object is nil, CODING->source must already point to | |
5500 the non-relocatable memory area. In this case, CODING->src_pos is | |
5501 an offset from CODING->source. | |
5502 | |
5503 The decoded data is inserted at the current point of the buffer | |
5504 CODING->dst_object. | |
5505 */ | |
5506 | |
5507 static int | |
5508 decode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5509 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5510 { |
88365 | 5511 Lisp_Object attrs; |
5512 | |
5513 if (BUFFERP (coding->src_object) | |
5514 && coding->src_pos > 0 | |
5515 && coding->src_pos < GPT | |
5516 && coding->src_pos + coding->src_chars > GPT) | |
5517 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
5518 | |
5519 if (BUFFERP (coding->dst_object)) | |
5520 { | |
5521 if (current_buffer != XBUFFER (coding->dst_object)) | |
5522 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5523 if (GPT != PT) | |
5524 move_gap_both (PT, PT_BYTE); | |
5525 } | |
5526 | |
5527 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
|
5528 coding->produced = coding->produced_char = 0; |
88365 | 5529 coding->chars_at_source = 0; |
5530 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
|
5531 coding->errors = 0; |
88365 | 5532 |
5533 ALLOC_CONVERSION_WORK_AREA (coding); | |
5534 | |
5535 attrs = CODING_ID_ATTRS (coding->id); | |
5536 | |
5537 do | |
5538 { | |
5539 coding_set_source (coding); | |
5540 coding->annotated = 0; | |
5541 (*(coding->decoder)) (coding); | |
5542 if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | |
5543 translate_chars (CODING_ATTR_DECODE_TBL (attrs), coding); | |
5544 coding_set_destination (coding); | |
5545 produce_chars (coding); | |
5546 if (coding->annotated) | |
5547 produce_annotation (coding); | |
5548 } | |
5549 while (coding->consumed < coding->src_bytes | |
5550 && ! coding->result); | |
5551 | |
5552 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qccl) | |
5553 && SYMBOLP (CODING_ID_EOL_TYPE (coding->id)) | |
5554 && ! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix)) | |
5555 decode_eol (coding); | |
5556 | |
5557 coding->carryover_bytes = 0; | |
5558 if (coding->consumed < coding->src_bytes) | |
5559 { | |
5560 int nbytes = coding->src_bytes - coding->consumed; | |
5561 unsigned char *src; | |
5562 | |
5563 coding_set_source (coding); | |
5564 coding_set_destination (coding); | |
5565 src = coding->source + coding->consumed; | |
5566 | |
5567 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
|
5568 { |
88365 | 5569 /* Flush out unprocessed data as binary chars. We are sure |
5570 that the number of data is less than the size of | |
5571 coding->charbuf. */ | |
5572 int *charbuf = coding->charbuf; | |
5573 | |
5574 while (nbytes-- > 0) | |
5575 { | |
5576 int c = *src++; | |
5577 *charbuf++ = (c & 0x80 ? - c : c); | |
5578 } | |
5579 produce_chars (coding); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5580 } |
88365 | 5581 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5582 { |
88365 | 5583 /* Record unprocessed bytes in coding->carryover. We are |
5584 sure that the number of data is less than the size of | |
5585 coding->carryover. */ | |
5586 unsigned char *p = coding->carryover; | |
5587 | |
5588 coding->carryover_bytes = nbytes; | |
5589 while (nbytes-- > 0) | |
5590 *p++ = *src++; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5591 } |
88365 | 5592 coding->consumed = coding->src_bytes; |
5593 } | |
5594 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5595 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5596 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5597 |
88365 | 5598 static void |
5599 consume_chars (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5600 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5601 { |
88365 | 5602 int *buf = coding->charbuf; |
5603 /* -1 is to compensate for CRLF. */ | |
5604 int *buf_end = coding->charbuf + coding->charbuf_size - 1; | |
5605 unsigned char *src = coding->source + coding->consumed; | |
5606 int pos = coding->src_pos + coding->consumed_char; | |
5607 int end_pos = coding->src_pos + coding->src_chars; | |
5608 int multibytep = coding->src_multibyte; | |
5609 Lisp_Object eol_type; | |
5610 int c; | |
5611 int start, end, stop; | |
5612 Lisp_Object object, prop; | |
5613 | |
5614 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5615 if (VECTORP (eol_type)) | |
5616 eol_type = Qunix; | |
5617 | |
5618 object = coding->src_object; | |
5619 | |
5620 /* Note: composition handling is not yet implemented. */ | |
5621 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
5622 | |
5623 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK | |
5624 && find_composition (pos, end_pos, &start, &end, &prop, object) | |
5625 && end <= end_pos | |
5626 && (start >= pos | |
5627 || (find_composition (end, end_pos, &start, &end, &prop, object) | |
5628 && end <= end_pos))) | |
5629 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5630 else |
88365 | 5631 stop = end_pos; |
5632 | |
5633 while (buf < buf_end) | |
5634 { | |
5635 if (pos == stop) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5636 { |
88365 | 5637 int *p; |
5638 | |
5639 if (pos == end_pos) | |
5640 break; | |
5641 p = save_composition_data (buf, buf_end, prop); | |
5642 if (p == NULL) | |
5643 break; | |
5644 buf = p; | |
5645 if (find_composition (end, end_pos, &start, &end, &prop, object) | |
5646 && end <= end_pos) | |
5647 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5648 else |
88365 | 5649 stop = end_pos; |
5650 } | |
5651 | |
5652 if (! multibytep) | |
5653 c = *src++; | |
5654 else | |
5655 c = STRING_CHAR_ADVANCE (src); | |
5656 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) | |
5657 c = '\n'; | |
5658 if (! EQ (eol_type, Qunix)) | |
5659 { | |
5660 if (c == '\n') | |
5661 { | |
5662 if (EQ (eol_type, Qdos)) | |
5663 *buf++ = '\r'; | |
5664 else | |
5665 c = '\r'; | |
5666 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5667 } |
88365 | 5668 *buf++ = c; |
5669 pos++; | |
5670 } | |
5671 | |
5672 coding->consumed = src - coding->source; | |
5673 coding->consumed_char = pos - coding->src_pos; | |
5674 coding->charbuf_used = buf - coding->charbuf; | |
5675 coding->chars_at_source = 0; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5676 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5677 |
88365 | 5678 |
5679 /* Encode the text at CODING->src_object into CODING->dst_object. | |
5680 CODING->src_object is a buffer or a string. | |
5681 CODING->dst_object is a buffer or nil. | |
5682 | |
5683 If CODING->src_object is a buffer, it must be the current buffer. | |
5684 In this case, if CODING->src_pos is positive, it is a position of | |
5685 the source text in the buffer, otherwise. the source text is in the | |
5686 gap area of the buffer, and coding->src_pos specifies the offset of | |
5687 the text from GPT (which must be the same as PT). If this is the | |
5688 same buffer as CODING->dst_object, CODING->src_pos must be | |
5689 negative and CODING should not have `pre-write-conversion'. | |
5690 | |
5691 If CODING->src_object is a string, CODING should not have | |
5692 `pre-write-conversion'. | |
5693 | |
5694 If CODING->dst_object is a buffer, the encoded data is inserted at | |
5695 the current point of that buffer. | |
5696 | |
5697 If CODING->dst_object is nil, the encoded data is placed at the | |
5698 memory area specified by CODING->destination. */ | |
5699 | |
5700 static int | |
5701 encode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5702 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5703 { |
88365 | 5704 Lisp_Object attrs; |
5705 | |
5706 attrs = CODING_ID_ATTRS (coding->id); | |
5707 | |
5708 if (BUFFERP (coding->dst_object)) | |
5709 { | |
5710 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5711 coding->dst_multibyte | |
5712 = ! NILP (current_buffer->enable_multibyte_characters); | |
5713 } | |
5714 | |
5715 coding->consumed = coding->consumed_char = 0; | |
5716 coding->produced = coding->produced_char = 0; | |
5717 coding->result = CODING_RESULT_SUCCESS; | |
5718 coding->errors = 0; | |
5719 | |
5720 ALLOC_CONVERSION_WORK_AREA (coding); | |
5721 | |
5722 do { | |
5723 coding_set_source (coding); | |
5724 consume_chars (coding); | |
5725 | |
5726 if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | |
5727 translate_chars (CODING_ATTR_ENCODE_TBL (attrs), coding); | |
5728 | |
5729 coding_set_destination (coding); | |
5730 (*(coding->encoder)) (coding); | |
5731 } while (coding->consumed_char < coding->src_chars); | |
5732 | |
5733 if (BUFFERP (coding->dst_object)) | |
5734 insert_from_gap (coding->produced_char, coding->produced); | |
5735 | |
5736 return (coding->result); | |
5737 } | |
5738 | |
5739 /* Work buffer */ | |
5740 | |
5741 /* List of currently used working buffer. */ | |
5742 Lisp_Object Vcode_conversion_work_buf_list; | |
5743 | |
5744 /* A working buffer used by the top level conversion. */ | |
5745 Lisp_Object Vcode_conversion_reused_work_buf; | |
5746 | |
5747 | |
5748 /* Return a working buffer that can be freely used by the following | |
5749 code conversion. MULTIBYTEP specifies the multibyteness of the | |
5750 buffer. */ | |
5751 | |
5752 Lisp_Object | |
5753 make_conversion_work_buffer (multibytep) | |
5754 int multibytep; | |
5755 { | |
5756 struct buffer *current = current_buffer; | |
5757 Lisp_Object buf; | |
5758 | |
5759 if (NILP (Vcode_conversion_work_buf_list)) | |
5760 { | |
5761 if (NILP (Vcode_conversion_reused_work_buf)) | |
5762 Vcode_conversion_reused_work_buf | |
5763 = Fget_buffer_create (build_string (" *code-conversion-work*")); | |
5764 Vcode_conversion_work_buf_list | |
5765 = 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
|
5766 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5767 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5768 { |
88365 | 5769 int depth = Flength (Vcode_conversion_work_buf_list); |
5770 char str[128]; | |
5771 | |
5772 sprintf (str, " *code-conversion-work*<%d>", depth); | |
5773 Vcode_conversion_work_buf_list | |
5774 = Fcons (Fget_buffer_create (build_string (str)), | |
5775 Vcode_conversion_work_buf_list); | |
5776 } | |
5777 | |
5778 buf = XCAR (Vcode_conversion_work_buf_list); | |
5779 set_buffer_internal (XBUFFER (buf)); | |
5780 current_buffer->undo_list = Qt; | |
5781 Ferase_buffer (); | |
5782 Fset_buffer_multibyte (multibytep ? Qt : Qnil); | |
5783 set_buffer_internal (current); | |
5784 return buf; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5785 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5786 |
88365 | 5787 static struct coding_system *saved_coding; |
5788 | |
5789 Lisp_Object | |
5790 code_conversion_restore (info) | |
5791 Lisp_Object info; | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5792 { |
88365 | 5793 int depth = Flength (Vcode_conversion_work_buf_list); |
5794 Lisp_Object buf; | |
5795 | |
5796 if (depth > 0) | |
5797 { | |
5798 buf = XCAR (Vcode_conversion_work_buf_list); | |
5799 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); | |
5800 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) | |
5801 Fkill_buffer (buf); | |
5802 } | |
5803 | |
5804 if (saved_coding->dst_object == Qt | |
5805 && saved_coding->destination) | |
5806 xfree (saved_coding->destination); | |
5807 | |
5808 return save_excursion_restore (info); | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5809 } |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5810 |
88365 | 5811 |
5812 int | |
5813 decode_coding_gap (coding, chars, bytes) | |
26847 | 5814 struct coding_system *coding; |
88365 | 5815 EMACS_INT chars, bytes; |
5816 { | |
5817 int count = specpdl_ptr - specpdl; | |
5818 | |
5819 saved_coding = coding; | |
5820 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5821 | |
5822 coding->src_object = Fcurrent_buffer (); | |
5823 coding->src_chars = chars; | |
5824 coding->src_bytes = bytes; | |
5825 coding->src_pos = -chars; | |
5826 coding->src_pos_byte = -bytes; | |
5827 coding->src_multibyte = chars < bytes; | |
5828 coding->dst_object = coding->src_object; | |
5829 coding->dst_pos = PT; | |
5830 coding->dst_pos_byte = PT_BYTE; | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5831 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
88365 | 5832 |
5833 if (CODING_REQUIRE_DETECTION (coding)) | |
5834 detect_coding (coding); | |
5835 | |
5836 decode_coding (coding); | |
5837 | |
5838 unbind_to (count, Qnil); | |
5839 return coding->result; | |
5840 } | |
5841 | |
5842 int | |
5843 encode_coding_gap (coding, chars, bytes) | |
5844 struct coding_system *coding; | |
5845 EMACS_INT chars, bytes; | |
26847 | 5846 { |
88365 | 5847 int count = specpdl_ptr - specpdl; |
5848 Lisp_Object buffer; | |
5849 | |
5850 saved_coding = coding; | |
5851 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5852 | |
5853 buffer = Fcurrent_buffer (); | |
5854 coding->src_object = buffer; | |
5855 coding->src_chars = chars; | |
5856 coding->src_bytes = bytes; | |
5857 coding->src_pos = -chars; | |
5858 coding->src_pos_byte = -bytes; | |
5859 coding->src_multibyte = chars < bytes; | |
5860 coding->dst_object = coding->src_object; | |
5861 coding->dst_pos = PT; | |
5862 coding->dst_pos_byte = PT_BYTE; | |
5863 | |
5864 encode_coding (coding); | |
5865 | |
5866 unbind_to (count, Qnil); | |
5867 return coding->result; | |
26847 | 5868 } |
5869 | |
88365 | 5870 |
5871 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
5872 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
5873 | |
5874 SRC_OBJECT is a buffer, a string, or Qnil. | |
5875 | |
5876 If it is a buffer, the text is at point of the buffer. FROM and TO | |
5877 are positions in the buffer. | |
5878 | |
5879 If it is a string, the text is at the beginning of the string. | |
5880 FROM and TO are indices to the string. | |
5881 | |
5882 If it is nil, the text is at coding->source. FROM and TO are | |
5883 indices to coding->source. | |
5884 | |
5885 DST_OBJECT is a buffer, Qt, or Qnil. | |
5886 | |
5887 If it is a buffer, the decoded text is inserted at point of the | |
5888 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
5889 is deleted. | |
5890 | |
5891 If it is Qt, a string is made from the decoded text, and | |
5892 set in CODING->dst_object. | |
5893 | |
5894 If it is Qnil, the decoded text is stored at CODING->destination. | |
5895 The called must allocate CODING->dst_bytes bytes at | |
5896 CODING->destination by xmalloc. If the decoded text is longer than | |
5897 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
5898 */ | |
26847 | 5899 |
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
5900 void |
88365 | 5901 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
5902 dst_object) | |
26847 | 5903 struct coding_system *coding; |
88365 | 5904 Lisp_Object src_object; |
5905 EMACS_INT from, from_byte, to, to_byte; | |
5906 Lisp_Object dst_object; | |
26847 | 5907 { |
88365 | 5908 int count = specpdl_ptr - specpdl; |
5909 unsigned char *destination; | |
5910 EMACS_INT dst_bytes; | |
5911 EMACS_INT chars = to - from; | |
5912 EMACS_INT bytes = to_byte - from_byte; | |
5913 Lisp_Object attrs; | |
5914 | |
5915 saved_coding = coding; | |
5916 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5917 | |
5918 if (NILP (dst_object)) | |
5919 { | |
5920 destination = coding->destination; | |
5921 dst_bytes = coding->dst_bytes; | |
5922 } | |
5923 | |
5924 coding->src_object = src_object; | |
5925 coding->src_chars = chars; | |
5926 coding->src_bytes = bytes; | |
5927 coding->src_multibyte = chars < bytes; | |
5928 | |
5929 if (STRINGP (src_object)) | |
5930 { | |
5931 coding->src_pos = from; | |
5932 coding->src_pos_byte = from_byte; | |
5933 } | |
5934 else if (BUFFERP (src_object)) | |
5935 { | |
5936 set_buffer_internal (XBUFFER (src_object)); | |
5937 if (from != GPT) | |
5938 move_gap_both (from, from_byte); | |
5939 if (EQ (src_object, dst_object)) | |
26847 | 5940 { |
88365 | 5941 TEMP_SET_PT_BOTH (from, from_byte); |
5942 del_range_both (from, from_byte, to, to_byte, 1); | |
5943 coding->src_pos = -chars; | |
5944 coding->src_pos_byte = -bytes; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5945 } |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5946 else |
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5947 { |
88365 | 5948 coding->src_pos = from; |
5949 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
|
5950 } |
88365 | 5951 } |
5952 | |
5953 if (CODING_REQUIRE_DETECTION (coding)) | |
5954 detect_coding (coding); | |
5955 attrs = CODING_ID_ATTRS (coding->id); | |
5956 | |
5957 if (! NILP (CODING_ATTR_POST_READ (attrs)) | |
5958 || EQ (dst_object, Qt)) | |
5959 { | |
5960 coding->dst_object = make_conversion_work_buffer (1); | |
5961 coding->dst_pos = BEG; | |
5962 coding->dst_pos_byte = BEG_BYTE; | |
5963 coding->dst_multibyte = 1; | |
5964 } | |
5965 else if (BUFFERP (dst_object)) | |
5966 { | |
5967 coding->dst_object = dst_object; | |
5968 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
5969 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
5970 coding->dst_multibyte | |
5971 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
5972 } | |
5973 else | |
5974 { | |
5975 coding->dst_object = Qnil; | |
5976 coding->dst_multibyte = 1; | |
5977 } | |
5978 | |
5979 decode_coding (coding); | |
5980 | |
5981 if (BUFFERP (coding->dst_object)) | |
5982 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5983 | |
5984 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
5985 { | |
5986 struct gcpro gcpro1, gcpro2; | |
5987 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; | |
5988 Lisp_Object val; | |
5989 | |
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
5990 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
88365 | 5991 GCPRO2 (coding->src_object, coding->dst_object); |
5992 val = call1 (CODING_ATTR_POST_READ (attrs), | |
5993 make_number (coding->produced_char)); | |
5994 UNGCPRO; | |
5995 CHECK_NATNUM (val); | |
5996 coding->produced_char += Z - prev_Z; | |
5997 coding->produced += Z_BYTE - prev_Z_BYTE; | |
5998 } | |
5999 | |
6000 if (EQ (dst_object, Qt)) | |
6001 { | |
6002 coding->dst_object = Fbuffer_string (); | |
6003 } | |
6004 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
6005 { | |
6006 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6007 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
|
6008 { |
88365 | 6009 destination |
6010 = (unsigned char *) xrealloc (destination, coding->produced); | |
6011 if (! destination) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6012 { |
88365 | 6013 coding->result = CODING_RESULT_INSUFFICIENT_DST; |
6014 unbind_to (count, Qnil); | |
6015 return; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6016 } |
88365 | 6017 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
6018 move_gap_both (BEGV, BEGV_BYTE); | |
6019 bcopy (BEGV_ADDR, destination, coding->produced); | |
6020 coding->destination = destination; | |
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
6021 } |
88365 | 6022 } |
6023 | |
6024 unbind_to (count, Qnil); | |
6025 } | |
6026 | |
6027 | |
6028 void | |
6029 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, | |
6030 dst_object) | |
6031 struct coding_system *coding; | |
6032 Lisp_Object src_object; | |
6033 EMACS_INT from, from_byte, to, to_byte; | |
6034 Lisp_Object dst_object; | |
6035 { | |
6036 int count = specpdl_ptr - specpdl; | |
6037 EMACS_INT chars = to - from; | |
6038 EMACS_INT bytes = to_byte - from_byte; | |
6039 Lisp_Object attrs; | |
6040 | |
6041 saved_coding = coding; | |
6042 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6043 | |
6044 coding->src_object = src_object; | |
6045 coding->src_chars = chars; | |
6046 coding->src_bytes = bytes; | |
6047 coding->src_multibyte = chars < bytes; | |
6048 | |
6049 attrs = CODING_ID_ATTRS (coding->id); | |
6050 | |
6051 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
|
6052 { |
88365 | 6053 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); |
6054 set_buffer_internal (XBUFFER (coding->src_object)); | |
6055 if (STRINGP (src_object)) | |
6056 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
6057 else if (BUFFERP (src_object)) | |
6058 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
6059 else | |
6060 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); | |
6061 | |
6062 if (EQ (src_object, dst_object)) | |
6063 { | |
6064 set_buffer_internal (XBUFFER (src_object)); | |
6065 del_range_both (from, from_byte, to, to_byte, 1); | |
6066 set_buffer_internal (XBUFFER (coding->src_object)); | |
6067 } | |
6068 | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6069 call2 (CODING_ATTR_PRE_WRITE (attrs), |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6070 make_number (BEG), make_number (Z)); |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6071 coding->src_object = Fcurrent_buffer (); |
88365 | 6072 if (BEG != GPT) |
6073 move_gap_both (BEG, BEG_BYTE); | |
6074 coding->src_chars = Z - BEG; | |
6075 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
6076 coding->src_pos = BEG; | |
6077 coding->src_pos_byte = BEG_BYTE; | |
6078 coding->src_multibyte = Z < Z_BYTE; | |
6079 } | |
6080 else if (STRINGP (src_object)) | |
6081 { | |
6082 coding->src_pos = from; | |
6083 coding->src_pos_byte = from_byte; | |
6084 } | |
6085 else if (BUFFERP (src_object)) | |
6086 { | |
6087 set_buffer_internal (XBUFFER (src_object)); | |
6088 if (from != GPT) | |
6089 move_gap_both (from, from_byte); | |
6090 if (EQ (src_object, dst_object)) | |
6091 { | |
6092 del_range_both (from, from_byte, to, to_byte, 1); | |
6093 coding->src_pos = -chars; | |
6094 coding->src_pos_byte = -bytes; | |
6095 } | |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
6096 else |
88365 | 6097 { |
6098 coding->src_pos = from; | |
6099 coding->src_pos_byte = from_byte; | |
6100 } | |
6101 } | |
6102 | |
6103 if (BUFFERP (dst_object)) | |
6104 { | |
6105 coding->dst_object = dst_object; | |
6106 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
6107 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
6108 coding->dst_multibyte | |
6109 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
6110 } | |
6111 else if (EQ (dst_object, Qt)) | |
6112 { | |
6113 coding->dst_object = Qnil; | |
6114 coding->dst_bytes = coding->src_chars; | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6115 if (coding->dst_bytes == 0) |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6116 coding->dst_bytes = 1; |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6117 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
88365 | 6118 coding->dst_multibyte = 0; |
6119 } | |
6120 else | |
6121 { | |
6122 coding->dst_object = Qnil; | |
6123 coding->dst_multibyte = 0; | |
6124 } | |
6125 | |
6126 encode_coding (coding); | |
6127 | |
6128 if (EQ (dst_object, Qt)) | |
6129 { | |
6130 if (BUFFERP (coding->dst_object)) | |
6131 coding->dst_object = Fbuffer_string (); | |
6132 else | |
6133 { | |
6134 coding->dst_object | |
6135 = make_unibyte_string ((char *) coding->destination, | |
6136 coding->produced); | |
6137 xfree (coding->destination); | |
6138 } | |
6139 } | |
6140 | |
6141 unbind_to (count, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6142 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6143 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6144 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6145 Lisp_Object |
88365 | 6146 preferred_coding_system () |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6147 { |
88365 | 6148 int id = coding_categories[coding_priorities[0]].id; |
6149 | |
6150 return CODING_ID_NAME (id); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6151 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6152 |
17052 | 6153 |
6154 #ifdef emacs | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6155 /*** 8. Emacs Lisp library functions ***/ |
17052 | 6156 |
6157 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
|
6158 doc: /* Return t if OBJECT is nil or a coding-system. |
88365 | 6159 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
|
6160 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
|
6161 (obj) |
17052 | 6162 Lisp_Object obj; |
6163 { | |
88365 | 6164 return ((NILP (obj) || CODING_SYSTEM_P (obj)) ? Qt : Qnil); |
17052 | 6165 } |
6166 | |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6167 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
|
6168 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
|
6169 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
|
6170 (prompt) |
17052 | 6171 Lisp_Object prompt; |
6172 { | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6173 Lisp_Object val; |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6174 do |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6175 { |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6176 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6177 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
|
6178 } |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6179 while (XSTRING (val)->size == 0); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6180 return (Fintern (val, Qnil)); |
17052 | 6181 } |
6182 | |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6183 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
|
6184 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
|
6185 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
|
6186 (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
|
6187 Lisp_Object prompt, default_coding_system; |
17052 | 6188 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
6189 Lisp_Object val; |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6190 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
|
6191 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6192 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
|
6193 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
|
6194 default_coding_system, Qnil); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6195 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
17052 | 6196 } |
6197 | |
6198 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
6199 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
|
6200 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
|
6201 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
|
6202 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
|
6203 The value of property should be a vector of length 5. */) |
88365 | 6204 (coding_system) |
17052 | 6205 Lisp_Object coding_system; |
6206 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6207 CHECK_SYMBOL (coding_system); |
17052 | 6208 if (!NILP (Fcoding_system_p (coding_system))) |
6209 return coding_system; | |
6210 while (1) | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
6211 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
17052 | 6212 } |
88365 | 6213 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6214 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6215 Lisp_Object |
88365 | 6216 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
|
6217 unsigned char *src; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6218 int src_bytes, highest; |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6219 int multibytep; |
88365 | 6220 Lisp_Object coding_system; |
17052 | 6221 { |
88365 | 6222 unsigned char *src_end = src + src_bytes; |
6223 int mask = CATEGORY_MASK_ANY; | |
6224 int detected = 0; | |
6225 int c, i; | |
6226 Lisp_Object attrs, eol_type; | |
6227 Lisp_Object val; | |
6228 struct coding_system coding; | |
6229 | |
6230 if (NILP (coding_system)) | |
6231 coding_system = Qundecided; | |
6232 setup_coding_system (coding_system, &coding); | |
6233 attrs = CODING_ID_ATTRS (coding.id); | |
6234 eol_type = CODING_ID_EOL_TYPE (coding.id); | |
6235 | |
6236 coding.source = src; | |
6237 coding.src_bytes = src_bytes; | |
6238 coding.src_multibyte = multibytep; | |
6239 coding.consumed = 0; | |
6240 | |
6241 if (XINT (CODING_ATTR_CATEGORY (attrs)) != coding_category_undecided) | |
6242 { | |
6243 mask = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); | |
6244 } | |
6245 else | |
6246 { | |
6247 coding_system = Qnil; | |
6248 for (; src < src_end; src++) | |
17052 | 6249 { |
88365 | 6250 c = *src; |
6251 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
6252 || c == ISO_CODE_SI | |
6253 || c == ISO_CODE_SO))) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6254 break; |
17052 | 6255 } |
88365 | 6256 coding.head_ascii = src - coding.source; |
6257 | |
6258 if (src < src_end) | |
6259 for (i = 0; i < coding_category_raw_text; i++) | |
6260 { | |
6261 enum coding_category category = coding_priorities[i]; | |
6262 struct coding_system *this = coding_categories + category; | |
6263 | |
6264 if (category >= coding_category_raw_text | |
6265 || detected & (1 << category)) | |
6266 continue; | |
6267 | |
6268 if (this->id < 0) | |
6269 { | |
6270 /* No coding system of this category is defined. */ | |
6271 mask &= ~(1 << category); | |
6272 } | |
6273 else | |
6274 { | |
6275 detected |= detected_mask[category]; | |
6276 if ((*(coding_categories[category].detector)) (&coding, &mask) | |
6277 && highest) | |
6278 { | |
6279 mask &= detected_mask[category]; | |
6280 break; | |
6281 } | |
6282 } | |
6283 } | |
6284 } | |
6285 | |
6286 if (!mask) | |
6287 val = Fcons (make_number (coding_category_raw_text), Qnil); | |
6288 else if (mask == CATEGORY_MASK_ANY) | |
6289 val = Fcons (make_number (coding_category_undecided), Qnil); | |
6290 else if (highest) | |
6291 { | |
6292 for (i = 0; i < coding_category_raw_text; i++) | |
6293 if (mask & (1 << coding_priorities[i])) | |
6294 { | |
6295 val = Fcons (make_number (coding_priorities[i]), Qnil); | |
6296 break; | |
6297 } | |
6298 } | |
6299 else | |
6300 { | |
6301 val = Qnil; | |
6302 for (i = coding_category_raw_text - 1; i >= 0; i--) | |
6303 if (mask & (1 << coding_priorities[i])) | |
6304 val = Fcons (make_number (coding_priorities[i]), val); | |
6305 } | |
6306 | |
6307 { | |
6308 int one_byte_eol = -1, two_byte_eol = -1; | |
6309 Lisp_Object tail; | |
6310 | |
6311 for (tail = val; CONSP (tail); tail = XCDR (tail)) | |
6312 { | |
6313 struct coding_system *this | |
6314 = (NILP (coding_system) ? coding_categories + XINT (XCAR (tail)) | |
6315 : &coding); | |
6316 int this_eol; | |
6317 | |
6318 attrs = CODING_ID_ATTRS (this->id); | |
6319 eol_type = CODING_ID_EOL_TYPE (this->id); | |
6320 XSETCAR (tail, CODING_ID_NAME (this->id)); | |
6321 if (VECTORP (eol_type)) | |
6322 { | |
6323 if (EQ (CODING_ATTR_TYPE (attrs), Qutf_16)) | |
6324 { | |
6325 if (two_byte_eol < 0) | |
6326 two_byte_eol = detect_eol (this, coding.source, src_bytes); | |
6327 this_eol = two_byte_eol; | |
6328 } | |
6329 else | |
6330 { | |
6331 if (one_byte_eol < 0) | |
6332 one_byte_eol =detect_eol (this, coding.source, src_bytes); | |
6333 this_eol = one_byte_eol; | |
6334 } | |
6335 if (this_eol == EOL_SEEN_LF) | |
6336 XSETCAR (tail, AREF (eol_type, 0)); | |
6337 else if (this_eol == EOL_SEEN_CRLF) | |
6338 XSETCAR (tail, AREF (eol_type, 1)); | |
6339 else if (this_eol == EOL_SEEN_CR) | |
6340 XSETCAR (tail, AREF (eol_type, 2)); | |
6341 } | |
6342 } | |
6343 } | |
6344 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
6345 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
|
6346 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6347 |
88365 | 6348 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6349 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
|
6350 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
|
6351 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
|
6352 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
|
6353 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6354 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
|
6355 `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
|
6356 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
|
6357 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6358 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
|
6359 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6360 (start, end, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6361 Lisp_Object start, end, highest; |
17052 | 6362 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6363 int from, to; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6364 int from_byte, to_byte; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6365 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6366 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
|
6367 CHECK_NUMBER_COERCE_MARKER (end); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6368 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6369 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6370 from = XINT (start), to = XINT (end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6371 from_byte = CHAR_TO_BYTE (from); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6372 to_byte = CHAR_TO_BYTE (to); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6373 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6374 if (from < GPT && to >= GPT) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6375 move_gap_both (to, to_byte); |
88365 | 6376 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6377 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
88365 | 6378 to_byte - from_byte, |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6379 !NILP (highest), |
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6380 !NILP (current_buffer |
88365 | 6381 ->enable_multibyte_characters), |
6382 Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6383 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6384 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6385 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
|
6386 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
|
6387 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
|
6388 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
|
6389 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6390 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
|
6391 `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
|
6392 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
|
6393 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6394 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
|
6395 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6396 (string, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6397 Lisp_Object string, highest; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6398 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6399 CHECK_STRING (string); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6400 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6401 return detect_coding_system (XSTRING (string)->data, |
88365 | 6402 STRING_BYTES (XSTRING (string)), |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6403 !NILP (highest), |
88365 | 6404 STRING_MULTIBYTE (string), |
6405 Qnil); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6406 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6407 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6408 |
88365 | 6409 static INLINE int |
6410 char_encodable_p (c, attrs) | |
6411 int c; | |
6412 Lisp_Object attrs; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6413 { |
88365 | 6414 Lisp_Object tail; |
6415 struct charset *charset; | |
6416 | |
6417 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | |
6418 CONSP (tail); tail = XCDR (tail)) | |
6419 { | |
6420 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
6421 if (CHAR_CHARSET_P (c, charset)) | |
6422 break; | |
6423 } | |
6424 return (! NILP (tail)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6425 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6426 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6427 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6428 /* Return a list of coding systems that safely encode the text between |
88365 | 6429 START and END. If EXCLUDE is non-nil, it is a list of coding |
6430 systems not to check. The returned list doesn't contain any such | |
6431 coding systems. In any case, If the text contains only ASCII or is | |
6432 unibyte, return t. */ | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6433 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6434 DEFUN ("find-coding-systems-region-internal", |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6435 Ffind_coding_systems_region_internal, |
88365 | 6436 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
|
6437 doc: /* Internal use only. */) |
88365 | 6438 (start, end, exclude) |
6439 Lisp_Object start, end, exclude; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6440 { |
88365 | 6441 Lisp_Object coding_attrs_list, safe_codings; |
6442 EMACS_INT start_byte, end_byte; | |
6443 unsigned char *p, *pbeg, *pend; | |
6444 int c; | |
6445 Lisp_Object tail, elt; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6446 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6447 if (STRINGP (start)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6448 { |
88365 | 6449 if (!STRING_MULTIBYTE (start) |
6450 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6451 return Qt; |
88365 | 6452 start_byte = 0; |
6453 end_byte = STRING_BYTES (XSTRING (start)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6454 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6455 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6456 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6457 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
|
6458 CHECK_NUMBER_COERCE_MARKER (end); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6459 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
|
6460 args_out_of_range (start, end); |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6461 if (NILP (current_buffer->enable_multibyte_characters)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6462 return Qt; |
88365 | 6463 start_byte = CHAR_TO_BYTE (XINT (start)); |
6464 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6465 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6466 return Qt; | |
6467 | |
6468 if (start < GPT && end > GPT) | |
6469 { | |
6470 if ((GPT - start) < (end - GPT)) | |
6471 move_gap_both (start, start_byte); | |
6472 else | |
6473 move_gap_both (end, end_byte); | |
6474 } | |
6475 } | |
6476 | |
6477 coding_attrs_list = Qnil; | |
6478 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6479 if (NILP (exclude) | |
6480 || NILP (Fmemq (XCAR (tail), exclude))) | |
6481 { | |
6482 Lisp_Object attrs; | |
6483 | |
6484 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
6485 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
6486 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
6487 coding_attrs_list = Fcons (attrs, coding_attrs_list); | |
6488 } | |
6489 | |
6490 if (STRINGP (start)) | |
6491 p = pbeg = XSTRING (start)->data; | |
6492 else | |
6493 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6494 pend = p + (end_byte - start_byte); | |
6495 | |
6496 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
6497 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6498 | |
6499 while (p < pend) | |
6500 { | |
6501 if (ASCII_BYTE_P (*p)) | |
6502 p++; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6503 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6504 { |
88365 | 6505 c = STRING_CHAR_ADVANCE (p); |
6506 | |
6507 charset_map_loaded = 0; | |
6508 for (tail = coding_attrs_list; CONSP (tail);) | |
6509 { | |
6510 elt = XCAR (tail); | |
6511 if (NILP (elt)) | |
6512 tail = XCDR (tail); | |
6513 else if (char_encodable_p (c, elt)) | |
6514 tail = XCDR (tail); | |
6515 else if (CONSP (XCDR (tail))) | |
6516 { | |
6517 XSETCAR (tail, XCAR (XCDR (tail))); | |
6518 XSETCDR (tail, XCDR (XCDR (tail))); | |
6519 } | |
6520 else | |
6521 { | |
6522 XSETCAR (tail, Qnil); | |
6523 tail = XCDR (tail); | |
6524 } | |
6525 } | |
6526 if (charset_map_loaded) | |
6527 { | |
6528 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6529 | |
6530 if (STRINGP (start)) | |
6531 pbeg = XSTRING (start)->data; | |
6532 else | |
6533 pbeg = BYTE_POS_ADDR (start_byte); | |
6534 p = pbeg + p_offset; | |
6535 pend = pbeg + pend_offset; | |
6536 } | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6537 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6538 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6539 |
88365 | 6540 safe_codings = Qnil; |
6541 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) | |
6542 if (! NILP (XCAR (tail))) | |
6543 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
6544 | |
6545 return safe_codings; | |
6546 } | |
6547 | |
6548 | |
6549 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, | |
6550 Scheck_coding_systems_region, 3, 3, 0, | |
6551 doc: /* Check if the region is encodable by coding systems. | |
6552 | |
6553 START and END are buffer positions specifying the region. | |
6554 CODING-SYSTEM-LIST is a list of coding systems to check. | |
6555 | |
6556 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
6557 CODING-SYSTEM is a member of CODING-SYSTEM-LIst and can't encode the | |
6558 whole region, POS0, POS1, ... are buffer positions where non-encodable | |
6559 characters are found. | |
6560 | |
6561 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
6562 value is nil. | |
6563 | |
6564 START may be a string. In that case, check if the string is | |
6565 encodable, and the value contains indices to the string instead of | |
6566 buffer positions. END is ignored. */) | |
6567 (start, end, coding_system_list) | |
6568 Lisp_Object start, end, coding_system_list; | |
6569 { | |
6570 Lisp_Object list; | |
6571 EMACS_INT start_byte, end_byte; | |
6572 int pos; | |
6573 unsigned char *p, *pbeg, *pend; | |
6574 int c; | |
6575 Lisp_Object tail, elt; | |
6576 | |
6577 if (STRINGP (start)) | |
6578 { | |
6579 if (!STRING_MULTIBYTE (start) | |
6580 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
6581 return Qnil; | |
6582 start_byte = 0; | |
6583 end_byte = STRING_BYTES (XSTRING (start)); | |
6584 pos = 0; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6585 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6586 else |
88365 | 6587 { |
6588 CHECK_NUMBER_COERCE_MARKER (start); | |
6589 CHECK_NUMBER_COERCE_MARKER (end); | |
6590 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
6591 args_out_of_range (start, end); | |
6592 if (NILP (current_buffer->enable_multibyte_characters)) | |
6593 return Qnil; | |
6594 start_byte = CHAR_TO_BYTE (XINT (start)); | |
6595 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6596 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6597 return Qt; | |
6598 | |
6599 if (start < GPT && end > GPT) | |
6600 { | |
6601 if ((GPT - start) < (end - GPT)) | |
6602 move_gap_both (start, start_byte); | |
6603 else | |
6604 move_gap_both (end, end_byte); | |
6605 } | |
6606 pos = start; | |
6607 } | |
6608 | |
6609 list = Qnil; | |
6610 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6611 { | |
6612 elt = XCAR (tail); | |
6613 list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | |
6614 Qnil)), | |
6615 list); | |
6616 } | |
6617 | |
6618 if (STRINGP (start)) | |
6619 p = pbeg = XSTRING (start)->data; | |
6620 else | |
6621 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6622 pend = p + (end_byte - start_byte); | |
6623 | |
6624 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
6625 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6626 | |
6627 while (p < pend) | |
6628 { | |
6629 if (ASCII_BYTE_P (*p)) | |
6630 p++; | |
6631 else | |
6632 { | |
6633 c = STRING_CHAR_ADVANCE (p); | |
6634 | |
6635 charset_map_loaded = 0; | |
6636 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
6637 { | |
6638 elt = XCDR (XCAR (tail)); | |
6639 if (! char_encodable_p (c, XCAR (elt))) | |
6640 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
6641 } | |
6642 if (charset_map_loaded) | |
6643 { | |
6644 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6645 | |
6646 if (STRINGP (start)) | |
6647 pbeg = XSTRING (start)->data; | |
6648 else | |
6649 pbeg = BYTE_POS_ADDR (start_byte); | |
6650 p = pbeg + p_offset; | |
6651 pend = pbeg + pend_offset; | |
6652 } | |
6653 } | |
6654 pos++; | |
6655 } | |
6656 | |
6657 tail = list; | |
6658 list = Qnil; | |
6659 for (; CONSP (tail); tail = XCDR (tail)) | |
6660 { | |
6661 elt = XCAR (tail); | |
6662 if (CONSP (XCDR (XCDR (elt)))) | |
6663 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
6664 list); | |
6665 } | |
6666 | |
6667 return list; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6668 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6669 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6670 |
88365 | 6671 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6672 Lisp_Object |
88365 | 6673 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
6674 Lisp_Object start, end, coding_system, dst_object; | |
6675 int encodep, norecord; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6676 { |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6677 struct coding_system coding; |
88365 | 6678 EMACS_INT from, from_byte, to, to_byte; |
6679 Lisp_Object src_object; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6680 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6681 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
|
6682 CHECK_NUMBER_COERCE_MARKER (end); |
88365 | 6683 if (NILP (coding_system)) |
6684 coding_system = Qno_conversion; | |
6685 else | |
6686 CHECK_CODING_SYSTEM (coding_system); | |
6687 src_object = Fcurrent_buffer (); | |
6688 if (NILP (dst_object)) | |
6689 dst_object = src_object; | |
6690 else if (! EQ (dst_object, Qt)) | |
6691 CHECK_BUFFER (dst_object); | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6692 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6693 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6694 from = XFASTINT (start); |
88365 | 6695 from_byte = CHAR_TO_BYTE (from); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6696 to = XFASTINT (end); |
88365 | 6697 to_byte = CHAR_TO_BYTE (to); |
6698 | |
6699 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6700 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6701 |
6702 if (encodep) | |
6703 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6704 dst_object); | |
6705 else | |
6706 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6707 dst_object); | |
6708 if (! norecord) | |
6709 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6710 | |
6711 if (coding.result != CODING_RESULT_SUCCESS) | |
6712 error ("Code conversion error: %d", coding.result); | |
6713 | |
6714 return (BUFFERP (dst_object) | |
6715 ? make_number (coding.produced_char) | |
6716 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6717 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6718 |
88365 | 6719 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6720 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
88365 | 6721 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
|
6722 doc: /* Decode the current region from the specified coding system. |
88365 | 6723 When called from a program, takes four arguments: |
6724 START, END, CODING-SYSTEM, and DESTINATION. | |
6725 START and END are buffer positions. | |
6726 | |
6727 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
6728 If nil, the region between START and END is replace by the decoded text. | |
6729 If buffer, the decoded text is inserted in the buffer. | |
6730 If t, the decoded text is returned. | |
6731 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6732 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
|
6733 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
|
6734 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6735 It returns the length of the decoded text. */) |
88365 | 6736 (start, end, coding_system, destination) |
6737 Lisp_Object start, end, coding_system, destination; | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6738 { |
88365 | 6739 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
|
6740 } |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6741 |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6742 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
88365 | 6743 3, 4, "r\nzCoding system: ", |
6744 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
|
6745 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
|
6746 START, END, and CODING-SYSTEM. START and END are buffer positions. |
88365 | 6747 |
6748 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
6749 If nil, the region between START and END is replace by the encoded text. | |
6750 If buffer, the encoded text is inserted in the buffer. | |
6751 If t, the encoded text is returned. | |
6752 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6753 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
|
6754 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
|
6755 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6756 It returns the length of the encoded text. */) |
88365 | 6757 (start, end, coding_system, destination) |
6758 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
|
6759 { |
88365 | 6760 return code_convert_region (start, end, coding_system, destination, 1, 0); |
17052 | 6761 } |
6762 | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6763 Lisp_Object |
88365 | 6764 code_convert_string (string, coding_system, dst_object, |
6765 encodep, nocopy, norecord) | |
6766 Lisp_Object string, coding_system, dst_object; | |
6767 int encodep, nocopy, norecord; | |
17052 | 6768 { |
6769 struct coding_system coding; | |
88365 | 6770 EMACS_INT chars, bytes; |
17052 | 6771 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6772 CHECK_STRING (string); |
88365 | 6773 if (NILP (coding_system)) |
6774 { | |
6775 if (! norecord) | |
6776 Vlast_coding_system_used = Qno_conversion; | |
6777 if (NILP (dst_object)) | |
6778 return (nocopy ? Fcopy_sequence (string) : string); | |
6779 } | |
17052 | 6780 |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6781 if (NILP (coding_system)) |
88365 | 6782 coding_system = Qno_conversion; |
6783 else | |
6784 CHECK_CODING_SYSTEM (coding_system); | |
6785 if (NILP (dst_object)) | |
6786 dst_object = Qt; | |
6787 else if (! EQ (dst_object, Qt)) | |
6788 CHECK_BUFFER (dst_object); | |
6789 | |
6790 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6791 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6792 chars = XSTRING (string)->size; |
6793 bytes = STRING_BYTES (XSTRING (string)); | |
6794 if (encodep) | |
6795 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6796 else | |
6797 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6798 if (! norecord) | |
6799 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6800 | |
6801 if (coding.result != CODING_RESULT_SUCCESS) | |
6802 error ("Code conversion error: %d", coding.result); | |
6803 | |
6804 return (BUFFERP (dst_object) | |
6805 ? make_number (coding.produced_char) | |
6806 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6807 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6808 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6809 |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6810 /* Encode or decode STRING according to CODING_SYSTEM. |
26847 | 6811 Do not set Vlast_coding_system_used. |
6812 | |
6813 This function is called only from macros DECODE_FILE and | |
6814 ENCODE_FILE, thus we ignore character composition. */ | |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6815 |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6816 Lisp_Object |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6817 code_convert_string_norecord (string, coding_system, encodep) |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6818 Lisp_Object string, coding_system; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6819 int encodep; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6820 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
6821 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
|
6822 } |
88365 | 6823 |
6824 | |
6825 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
6826 2, 4, 0, | |
6827 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
6828 | |
6829 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
6830 if the decoding operation is trivial. | |
6831 | |
6832 Optional fourth arg BUFFER non-nil meant that the decoded text is | |
6833 inserted in BUFFER instead of returned as a astring. In this case, | |
6834 the return value is BUFFER. | |
6835 | |
6836 This function sets `last-coding-system-used' to the precise coding system | |
6837 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6838 not fully specified. */) | |
6839 (string, coding_system, nocopy, buffer) | |
6840 Lisp_Object string, coding_system, nocopy, buffer; | |
6841 { | |
6842 return code_convert_string (string, coding_system, buffer, | |
6843 0, ! NILP (nocopy), 0); | |
6844 } | |
6845 | |
6846 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
6847 2, 4, 0, | |
6848 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
6849 | |
6850 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
6851 itself if the encoding operation is trivial. | |
6852 | |
6853 Optional fourth arg BUFFER non-nil meant that the encoded text is | |
6854 inserted in BUFFER instead of returned as a astring. In this case, | |
6855 the return value is BUFFER. | |
6856 | |
6857 This function sets `last-coding-system-used' to the precise coding system | |
6858 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6859 not fully specified.) */) | |
6860 (string, coding_system, nocopy, buffer) | |
6861 Lisp_Object string, coding_system, nocopy, buffer; | |
6862 { | |
6863 return code_convert_string (string, coding_system, buffer, | |
6864 nocopy, ! NILP (nocopy), 1); | |
6865 } | |
6866 | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6867 |
17052 | 6868 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
|
6869 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
|
6870 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
|
6871 (code) |
17052 | 6872 Lisp_Object code; |
6873 { | |
88365 | 6874 Lisp_Object spec, attrs, val; |
6875 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
6876 int c; | |
6877 | |
6878 CHECK_NATNUM (code); | |
6879 c = XFASTINT (code); | |
6880 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6881 attrs = AREF (spec, 0); | |
6882 | |
6883 if (ASCII_BYTE_P (c) | |
6884 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6885 return code; | |
6886 | |
6887 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6888 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
|
6889 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
|
6890 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 6891 |
6892 if (c <= 0x7F) | |
6893 charset = charset_roman; | |
6894 else if (c >= 0xA0 && c < 0xDF) | |
6895 { | |
6896 charset = charset_kana; | |
6897 c -= 0x80; | |
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6898 } |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6899 else |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6900 { |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
6901 int s1 = c >> 8, s2 = c & 0xFF; |
88365 | 6902 |
6903 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
6904 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
6905 error ("Invalid code: %d", code); | |
6906 SJIS_TO_JIS (c); | |
6907 charset = charset_kanji; | |
6908 } | |
6909 c = DECODE_CHAR (charset, c); | |
6910 if (c < 0) | |
6911 error ("Invalid code: %d", code); | |
6912 return make_number (c); | |
17052 | 6913 } |
6914 | |
88365 | 6915 |
17052 | 6916 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
|
6917 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
|
6918 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
|
6919 (ch) |
88365 | 6920 Lisp_Object ch; |
17052 | 6921 { |
88365 | 6922 Lisp_Object spec, attrs, charset_list; |
6923 int c; | |
6924 struct charset *charset; | |
6925 unsigned code; | |
6926 | |
6927 CHECK_CHARACTER (ch); | |
6928 c = XFASTINT (ch); | |
6929 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6930 attrs = AREF (spec, 0); | |
6931 | |
6932 if (ASCII_CHAR_P (c) | |
6933 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6934 return ch; | |
6935 | |
6936 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
6937 charset = char_charset (c, charset_list, &code); | |
6938 if (code == CHARSET_INVALID_CODE (charset)) | |
6939 error ("Can't encode by shift_jis encoding: %d", c); | |
6940 JIS_TO_SJIS (code); | |
6941 | |
6942 return make_number (code); | |
17052 | 6943 } |
6944 | |
6945 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
|
6946 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
|
6947 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
|
6948 (code) |
17052 | 6949 Lisp_Object code; |
6950 { | |
88365 | 6951 Lisp_Object spec, attrs, val; |
6952 struct charset *charset_roman, *charset_big5, *charset; | |
6953 int c; | |
6954 | |
6955 CHECK_NATNUM (code); | |
6956 c = XFASTINT (code); | |
6957 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6958 attrs = AREF (spec, 0); | |
6959 | |
6960 if (ASCII_BYTE_P (c) | |
6961 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6962 return code; | |
6963 | |
6964 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6965 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
6966 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
6967 | |
6968 if (c <= 0x7F) | |
6969 charset = charset_roman; | |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
6970 else |
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
6971 { |
88365 | 6972 int b1 = c >> 8, b2 = c & 0x7F; |
6973 if (b1 < 0xA1 || b1 > 0xFE | |
6974 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
6975 error ("Invalid code: %d", code); | |
6976 charset = charset_big5; | |
6977 } | |
6978 c = DECODE_CHAR (charset, (unsigned )c); | |
6979 if (c < 0) | |
6980 error ("Invalid code: %d", code); | |
6981 return make_number (c); | |
17052 | 6982 } |
6983 | |
6984 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
|
6985 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
|
6986 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
|
6987 (ch) |
17052 | 6988 Lisp_Object ch; |
6989 { | |
88365 | 6990 Lisp_Object spec, attrs, charset_list; |
6991 struct charset *charset; | |
6992 int c; | |
6993 unsigned code; | |
6994 | |
6995 CHECK_CHARACTER (ch); | |
6996 c = XFASTINT (ch); | |
6997 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6998 attrs = AREF (spec, 0); | |
6999 if (ASCII_CHAR_P (c) | |
7000 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
7001 return ch; | |
7002 | |
7003 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
7004 charset = char_charset (c, charset_list, &code); | |
7005 if (code == CHARSET_INVALID_CODE (charset)) | |
7006 error ("Can't encode by Big5 encoding: %d", c); | |
7007 | |
7008 return make_number (code); | |
17052 | 7009 } |
88365 | 7010 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7011 |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7012 DEFUN ("set-terminal-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7013 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
|
7014 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
|
7015 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
|
7016 (coding_system) |
88473 | 7017 Lisp_Object coding_system; |
17052 | 7018 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7019 CHECK_SYMBOL (coding_system); |
88365 | 7020 setup_coding_system (Fcheck_coding_system (coding_system), |
7021 &terminal_coding); | |
7022 | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
7023 /* We had better not send unsafe characters to terminal. */ |
88365 | 7024 terminal_coding.mode |= CODING_MODE_SAFE_ENCODING; |
7025 /* Characer composition should be disabled. */ | |
7026 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
|
7027 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
|
7028 terminal_coding.dst_multibyte = 0; |
17052 | 7029 return Qnil; |
7030 } | |
7031 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7032 DEFUN ("set-safe-terminal-coding-system-internal", |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7033 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
|
7034 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
41006 | 7035 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
|
7036 (coding_system) |
88473 | 7037 Lisp_Object coding_system; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7038 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7039 CHECK_SYMBOL (coding_system); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7040 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
|
7041 &safe_terminal_coding); |
88365 | 7042 /* Characer composition should be disabled. */ |
7043 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
|
7044 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
|
7045 safe_terminal_coding.dst_multibyte = 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7046 return Qnil; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7047 } |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7048 |
17052 | 7049 DEFUN ("terminal-coding-system", |
7050 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
|
7051 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
|
7052 () |
17052 | 7053 { |
88365 | 7054 return CODING_ID_NAME (terminal_coding.id); |
17052 | 7055 } |
7056 | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7057 DEFUN ("set-keyboard-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7058 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
|
7059 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
|
7060 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
|
7061 (coding_system) |
17052 | 7062 Lisp_Object coding_system; |
7063 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7064 CHECK_SYMBOL (coding_system); |
88365 | 7065 setup_coding_system (Fcheck_coding_system (coding_system), |
7066 &keyboard_coding); | |
7067 /* Characer composition should be disabled. */ | |
7068 keyboard_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
17052 | 7069 return Qnil; |
7070 } | |
7071 | |
7072 DEFUN ("keyboard-coding-system", | |
7073 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
|
7074 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
|
7075 () |
17052 | 7076 { |
88365 | 7077 return CODING_ID_NAME (keyboard_coding.id); |
17052 | 7078 } |
7079 | |
7080 | |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7081 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
|
7082 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
|
7083 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
|
7084 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
|
7085 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
|
7086 \(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
|
7087 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
|
7088 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7089 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
|
7090 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
|
7091 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
|
7092 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
|
7093 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7094 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
|
7095 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
|
7096 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
|
7097 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
|
7098 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7099 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
|
7100 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
|
7101 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
|
7102 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
|
7103 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7104 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
|
7105 `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
|
7106 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
|
7107 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
|
7108 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
|
7109 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
|
7110 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
|
7111 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7112 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
|
7113 (nargs, args) |
17052 | 7114 int nargs; |
7115 Lisp_Object *args; | |
7116 { | |
7117 Lisp_Object operation, target_idx, target, val; | |
7118 register Lisp_Object chain; | |
7119 | |
7120 if (nargs < 2) | |
7121 error ("Too few arguments"); | |
7122 operation = args[0]; | |
7123 if (!SYMBOLP (operation) | |
7124 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
88365 | 7125 error ("Invalid first arguement"); |
17052 | 7126 if (nargs < 1 + XINT (target_idx)) |
7127 error ("Too few arguments for operation: %s", | |
7128 XSYMBOL (operation)->name->data); | |
7129 target = args[XINT (target_idx) + 1]; | |
7130 if (!(STRINGP (target) | |
7131 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
88365 | 7132 error ("Invalid %dth argument", XINT (target_idx) + 1); |
17052 | 7133 |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7134 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
|
7135 || EQ (operation, Qwrite_region)) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7136 ? 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
|
7137 : (EQ (operation, Qopen_network_stream) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7138 ? Vnetwork_coding_system_alist |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7139 : Vprocess_coding_system_alist)); |
17052 | 7140 if (NILP (chain)) |
7141 return Qnil; | |
7142 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7143 for (; CONSP (chain); chain = XCDR (chain)) |
17052 | 7144 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
7145 Lisp_Object elt; |
88365 | 7146 |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7147 elt = XCAR (chain); |
17052 | 7148 if (CONSP (elt) |
7149 && ((STRINGP (target) | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7150 && STRINGP (XCAR (elt)) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7151 && 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
|
7152 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7153 { |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7154 val = XCDR (elt); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7155 /* 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
|
7156 function symbol, we return VAL as a coding system. */ |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7157 if (CONSP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7158 return val; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7159 if (! SYMBOLP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7160 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7161 if (! NILP (Fcoding_system_p (val))) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7162 return Fcons (val, val); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7163 if (! NILP (Ffboundp (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7164 { |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7165 val = call1 (val, Flist (nargs, args)); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7166 if (CONSP (val)) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7167 return val; |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7168 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
|
7169 return Fcons (val, val); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7170 } |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7171 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7172 } |
17052 | 7173 } |
7174 return Qnil; | |
7175 } | |
7176 | |
88365 | 7177 DEFUN ("set-coding-system-priority", Fset_coding_system_priority, |
7178 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
|
7179 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
|
7180 usage: (set-coding-system-priority CODING-SYSTEM ...) */) |
88365 | 7181 (nargs, args) |
7182 int nargs; | |
7183 Lisp_Object *args; | |
7184 { | |
7185 int i, j; | |
7186 int changed[coding_category_max]; | |
7187 enum coding_category priorities[coding_category_max]; | |
7188 | |
7189 bzero (changed, sizeof changed); | |
7190 | |
7191 for (i = j = 0; i < nargs; i++) | |
7192 { | |
7193 enum coding_category category; | |
7194 Lisp_Object spec, attrs; | |
7195 | |
7196 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
7197 attrs = AREF (spec, 0); | |
7198 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
7199 if (changed[category]) | |
7200 /* Ignore this coding system because a coding system of the | |
7201 same category already had a higher priority. */ | |
7202 continue; | |
7203 changed[category] = 1; | |
7204 priorities[j++] = category; | |
7205 if (coding_categories[category].id >= 0 | |
7206 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
7207 setup_coding_system (args[i], &coding_categories[category]); | |
7208 } | |
7209 | |
7210 /* Now we have decided top J priorities. Reflect the order of the | |
7211 original priorities to the remaining priorities. */ | |
7212 | |
7213 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
7214 { | |
7215 while (j < coding_category_max | |
7216 && changed[coding_priorities[j]]) | |
7217 j++; | |
7218 if (j == coding_category_max) | |
7219 abort (); | |
7220 priorities[i] = coding_priorities[j]; | |
7221 } | |
7222 | |
7223 bcopy (priorities, coding_priorities, sizeof priorities); | |
7224 return Qnil; | |
7225 } | |
7226 | |
7227 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, | |
7228 Scoding_system_priority_list, 0, 1, 0, | |
7229 doc: /* Return a list of coding systems ordered by their priorities. */) | |
7230 (highestp) | |
7231 Lisp_Object highestp; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7232 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7233 int i; |
88365 | 7234 Lisp_Object val; |
7235 | |
7236 for (i = 0, val = Qnil; i < coding_category_max; i++) | |
7237 { | |
7238 enum coding_category category = coding_priorities[i]; | |
7239 int id = coding_categories[category].id; | |
7240 Lisp_Object attrs; | |
7241 | |
7242 if (id < 0) | |
7243 continue; | |
7244 attrs = CODING_ID_ATTRS (id); | |
7245 if (! NILP (highestp)) | |
7246 return CODING_ATTR_BASE_NAME (attrs); | |
7247 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
7248 } | |
7249 return Fnreverse (val); | |
7250 } | |
7251 | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7252 static char *suffixes[] = { "-unix", "-dos", "-mac" }; |
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7253 |
88365 | 7254 static Lisp_Object |
7255 make_subsidiaries (base) | |
7256 Lisp_Object base; | |
7257 { | |
7258 Lisp_Object subsidiaries; | |
7259 int base_name_len = STRING_BYTES (XSYMBOL (base)->name); | |
7260 char *buf = (char *) alloca (base_name_len + 6); | |
7261 int i; | |
7262 | |
7263 bcopy (XSYMBOL (base)->name->data, buf, base_name_len); | |
7264 subsidiaries = Fmake_vector (make_number (3), Qnil); | |
7265 for (i = 0; i < 3; i++) | |
7266 { | |
7267 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
7268 ASET (subsidiaries, i, intern (buf)); | |
7269 } | |
7270 return subsidiaries; | |
7271 } | |
7272 | |
7273 | |
7274 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, | |
7275 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
|
7276 doc: /* For internal use only. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7277 usage: (define-coding-system-internal ...) */) |
88365 | 7278 (nargs, args) |
7279 int nargs; | |
7280 Lisp_Object *args; | |
7281 { | |
7282 Lisp_Object name; | |
7283 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
7284 Lisp_Object attrs; /* Vector of attributes. */ | |
7285 Lisp_Object eol_type; | |
7286 Lisp_Object aliases; | |
7287 Lisp_Object coding_type, charset_list, safe_charsets; | |
7288 enum coding_category category; | |
7289 Lisp_Object tail, val; | |
7290 int max_charset_id = 0; | |
7291 int i; | |
7292 | |
7293 if (nargs < coding_arg_max) | |
7294 goto short_args; | |
7295 | |
7296 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
7297 | |
7298 name = args[coding_arg_name]; | |
7299 CHECK_SYMBOL (name); | |
7300 CODING_ATTR_BASE_NAME (attrs) = name; | |
7301 | |
7302 val = args[coding_arg_mnemonic]; | |
7303 if (! STRINGP (val)) | |
7304 CHECK_CHARACTER (val); | |
7305 CODING_ATTR_MNEMONIC (attrs) = val; | |
7306 | |
7307 coding_type = args[coding_arg_coding_type]; | |
7308 CHECK_SYMBOL (coding_type); | |
7309 CODING_ATTR_TYPE (attrs) = coding_type; | |
7310 | |
7311 charset_list = args[coding_arg_charset_list]; | |
7312 if (SYMBOLP (charset_list)) | |
7313 { | |
7314 if (EQ (charset_list, Qiso_2022)) | |
7315 { | |
7316 if (! EQ (coding_type, Qiso_2022)) | |
7317 error ("Invalid charset-list"); | |
7318 charset_list = Viso_2022_charset_list; | |
7319 } | |
7320 else if (EQ (charset_list, Qemacs_mule)) | |
7321 { | |
7322 if (! EQ (coding_type, Qemacs_mule)) | |
7323 error ("Invalid charset-list"); | |
7324 charset_list = Vemacs_mule_charset_list; | |
7325 } | |
7326 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7327 if (max_charset_id < XFASTINT (XCAR (tail))) | |
7328 max_charset_id = XFASTINT (XCAR (tail)); | |
7329 } | |
7330 else | |
7331 { | |
7332 charset_list = Fcopy_sequence (charset_list); | |
7333 for (tail = charset_list; !NILP (tail); tail = Fcdr (tail)) | |
7334 { | |
7335 struct charset *charset; | |
7336 | |
7337 val = Fcar (tail); | |
7338 CHECK_CHARSET_GET_CHARSET (val, charset); | |
7339 if (EQ (coding_type, Qiso_2022) | |
7340 ? CHARSET_ISO_FINAL (charset) < 0 | |
7341 : EQ (coding_type, Qemacs_mule) | |
7342 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
7343 : 0) | |
7344 error ("Can't handle charset `%s'", | |
7345 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7346 | |
7347 XCAR (tail) = make_number (charset->id); | |
7348 if (max_charset_id < charset->id) | |
7349 max_charset_id = charset->id; | |
7350 } | |
7351 } | |
7352 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
7353 | |
7354 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
7355 make_number (255)); | |
7356 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7357 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
7358 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | |
7359 | |
7360 val = args[coding_arg_decode_translation_table]; | |
7361 if (! NILP (val)) | |
7362 CHECK_CHAR_TABLE (val); | |
7363 CODING_ATTR_DECODE_TBL (attrs) = val; | |
7364 | |
7365 val = args[coding_arg_encode_translation_table]; | |
7366 if (! NILP (val)) | |
7367 CHECK_CHAR_TABLE (val); | |
7368 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
7369 | |
7370 val = args[coding_arg_post_read_conversion]; | |
7371 CHECK_SYMBOL (val); | |
7372 CODING_ATTR_POST_READ (attrs) = val; | |
7373 | |
7374 val = args[coding_arg_pre_write_conversion]; | |
7375 CHECK_SYMBOL (val); | |
7376 CODING_ATTR_PRE_WRITE (attrs) = val; | |
7377 | |
7378 val = args[coding_arg_default_char]; | |
7379 if (NILP (val)) | |
7380 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
7381 else | |
7382 { | |
7383 CHECK_CHARACTER (val); | |
7384 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
7385 } | |
7386 | |
7387 val = args[coding_arg_plist]; | |
7388 CHECK_LIST (val); | |
7389 CODING_ATTR_PLIST (attrs) = val; | |
7390 | |
7391 if (EQ (coding_type, Qcharset)) | |
7392 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7393 /* 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
|
7394 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
|
7395 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7396 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
|
7397 coding system. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7398 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7399 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
|
7400 charset whose ID is NUM. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7401 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7402 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
|
7403 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
|
7404 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
|
7405 */ |
88365 | 7406 val = Fmake_vector (make_number (256), Qnil); |
7407 | |
7408 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7409 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7410 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
|
7411 int dim = CHARSET_DIMENSION (charset); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7412 int idx = (dim - 1) * 4; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7413 |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7414 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
|
7415 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
|
7416 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7417 Lisp_Object tmp, tmp2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7418 int dim2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7419 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7420 tmp = AREF (val, i); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7421 if (NILP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7422 tmp = XCAR (tail); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7423 else if (NUMBERP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7424 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7425 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
|
7426 if (dim < dim2) |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7427 tmp = Fcons (XCAR (tail), Fcons (tmp, Qnil)); |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7428 else |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7429 tmp = Fcons (tmp, Fcons (XCAR (tail), Qnil)); |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7430 } |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7431 else |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7432 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7433 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
|
7434 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7435 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
|
7436 if (dim < dim2) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7437 break; |
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 if (NILP (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7440 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
|
7441 else |
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 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
|
7444 XSETCAR (tmp2, XCAR (tail)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7445 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7446 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7447 ASET (val, i, tmp); |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7448 } |
88365 | 7449 } |
7450 ASET (attrs, coding_attr_charset_valids, val); | |
7451 category = coding_category_charset; | |
7452 } | |
7453 else if (EQ (coding_type, Qccl)) | |
7454 { | |
7455 Lisp_Object valids; | |
7456 | |
7457 if (nargs < coding_arg_ccl_max) | |
7458 goto short_args; | |
7459 | |
7460 val = args[coding_arg_ccl_decoder]; | |
7461 CHECK_CCL_PROGRAM (val); | |
7462 if (VECTORP (val)) | |
7463 val = Fcopy_sequence (val); | |
7464 ASET (attrs, coding_attr_ccl_decoder, val); | |
7465 | |
7466 val = args[coding_arg_ccl_encoder]; | |
7467 CHECK_CCL_PROGRAM (val); | |
7468 if (VECTORP (val)) | |
7469 val = Fcopy_sequence (val); | |
7470 ASET (attrs, coding_attr_ccl_encoder, val); | |
7471 | |
7472 val = args[coding_arg_ccl_valids]; | |
7473 valids = Fmake_string (make_number (256), make_number (0)); | |
7474 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
7475 { | |
7476 val = Fcar (tail); | |
7477 if (INTEGERP (val)) | |
7478 ASET (valids, XINT (val), 1); | |
7479 else | |
7480 { | |
7481 int from, to; | |
7482 | |
7483 CHECK_CONS (val); | |
7484 CHECK_NUMBER (XCAR (val)); | |
7485 CHECK_NUMBER (XCDR (val)); | |
7486 from = XINT (XCAR (val)); | |
7487 to = XINT (XCDR (val)); | |
7488 for (i = from; i <= to; i++) | |
7489 ASET (valids, i, 1); | |
7490 } | |
7491 } | |
7492 ASET (attrs, coding_attr_ccl_valids, valids); | |
7493 | |
7494 category = coding_category_ccl; | |
7495 } | |
7496 else if (EQ (coding_type, Qutf_16)) | |
7497 { | |
7498 Lisp_Object bom, endian; | |
7499 | |
7500 if (nargs < coding_arg_utf16_max) | |
7501 goto short_args; | |
7502 | |
7503 bom = args[coding_arg_utf16_bom]; | |
7504 if (! NILP (bom) && ! EQ (bom, Qt)) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7505 { |
88365 | 7506 CHECK_CONS (bom); |
7507 CHECK_CODING_SYSTEM (XCAR (bom)); | |
7508 CHECK_CODING_SYSTEM (XCDR (bom)); | |
7509 } | |
7510 ASET (attrs, coding_attr_utf_16_bom, bom); | |
7511 | |
7512 endian = args[coding_arg_utf16_endian]; | |
7513 ASET (attrs, coding_attr_utf_16_endian, endian); | |
7514 | |
7515 category = (CONSP (bom) | |
7516 ? coding_category_utf_16_auto | |
7517 : NILP (bom) | |
7518 ? (NILP (endian) | |
7519 ? coding_category_utf_16_be_nosig | |
7520 : coding_category_utf_16_le_nosig) | |
7521 : (NILP (endian) | |
7522 ? coding_category_utf_16_be | |
7523 : coding_category_utf_16_le)); | |
7524 } | |
7525 else if (EQ (coding_type, Qiso_2022)) | |
7526 { | |
7527 Lisp_Object initial, reg_usage, request, flags; | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7528 int i, id; |
88365 | 7529 |
7530 if (nargs < coding_arg_iso2022_max) | |
7531 goto short_args; | |
7532 | |
7533 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
7534 CHECK_VECTOR (initial); | |
7535 for (i = 0; i < 4; i++) | |
7536 { | |
7537 val = Faref (initial, make_number (i)); | |
7538 if (! NILP (val)) | |
7539 { | |
7540 CHECK_CHARSET_GET_ID (val, id); | |
7541 ASET (initial, i, make_number (id)); | |
7542 } | |
7543 else | |
7544 ASET (initial, i, make_number (-1)); | |
7545 } | |
7546 | |
7547 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
7548 CHECK_CONS (reg_usage); | |
7549 CHECK_NATNUM (XCAR (reg_usage)); | |
7550 CHECK_NATNUM (XCDR (reg_usage)); | |
7551 | |
7552 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
7553 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
7554 { | |
7555 int id; | |
7556 | |
7557 val = Fcar (tail); | |
7558 CHECK_CONS (val); | |
7559 CHECK_CHARSET_GET_ID (XCAR (val), id); | |
7560 CHECK_NATNUM (XCDR (val)); | |
7561 if (XINT (XCDR (val)) >= 4) | |
7562 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
7563 XCAR (val) = make_number (id); | |
7564 } | |
7565 | |
7566 flags = args[coding_arg_iso2022_flags]; | |
7567 CHECK_NATNUM (flags); | |
7568 i = XINT (flags); | |
7569 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
7570 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
7571 | |
7572 ASET (attrs, coding_attr_iso_initial, initial); | |
7573 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
7574 ASET (attrs, coding_attr_iso_request, request); | |
7575 ASET (attrs, coding_attr_iso_flags, flags); | |
7576 setup_iso_safe_charsets (attrs); | |
7577 | |
7578 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
7579 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7580 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7581 ? coding_category_iso_7_else | |
7582 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
7583 ? coding_category_iso_7 | |
7584 : coding_category_iso_7_tight); | |
7585 else | |
7586 { | |
7587 int id = XINT (AREF (initial, 1)); | |
7588 | |
7589 category = (((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7590 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7591 || EQ (args[coding_arg_charset_list], Qiso_2022) | |
7592 || id < 0) | |
7593 ? coding_category_iso_8_else | |
7594 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
7595 ? coding_category_iso_8_1 | |
7596 : coding_category_iso_8_2); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7597 } |
88365 | 7598 } |
7599 else if (EQ (coding_type, Qemacs_mule)) | |
7600 { | |
7601 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
7602 ASET (attrs, coding_attr_emacs_mule_full, Qt); | |
7603 | |
7604 category = coding_category_emacs_mule; | |
7605 } | |
7606 else if (EQ (coding_type, Qshift_jis)) | |
7607 { | |
7608 | |
7609 struct charset *charset; | |
7610 | |
7611 if (XINT (Flength (charset_list)) != 3) | |
7612 error ("There should be just three charsets"); | |
7613 | |
7614 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7615 if (CHARSET_DIMENSION (charset) != 1) | |
7616 error ("Dimension of charset %s is not one", | |
7617 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7618 | |
7619 charset_list = XCDR (charset_list); | |
7620 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7621 if (CHARSET_DIMENSION (charset) != 1) | |
7622 error ("Dimension of charset %s is not one", | |
7623 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7624 | |
7625 charset_list = XCDR (charset_list); | |
7626 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7627 if (CHARSET_DIMENSION (charset) != 2) | |
7628 error ("Dimension of charset %s is not two", | |
7629 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7630 | |
7631 category = coding_category_sjis; | |
7632 Vsjis_coding_system = name; | |
7633 } | |
7634 else if (EQ (coding_type, Qbig5)) | |
7635 { | |
7636 struct charset *charset; | |
7637 | |
7638 if (XINT (Flength (charset_list)) != 2) | |
7639 error ("There should be just two charsets"); | |
7640 | |
7641 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7642 if (CHARSET_DIMENSION (charset) != 1) | |
7643 error ("Dimension of charset %s is not one", | |
7644 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7645 | |
7646 charset_list = XCDR (charset_list); | |
7647 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7648 if (CHARSET_DIMENSION (charset) != 2) | |
7649 error ("Dimension of charset %s is not two", | |
7650 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7651 | |
7652 category = coding_category_big5; | |
7653 Vbig5_coding_system = name; | |
7654 } | |
7655 else if (EQ (coding_type, Qraw_text)) | |
7656 category = coding_category_raw_text; | |
7657 else if (EQ (coding_type, Qutf_8)) | |
7658 category = coding_category_utf_8; | |
7659 else if (EQ (coding_type, Qundecided)) | |
7660 category = coding_category_undecided; | |
7661 else | |
7662 error ("Invalid coding system type: %s", | |
7663 XSYMBOL (coding_type)->name->data); | |
7664 | |
7665 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
7666 | |
7667 eol_type = args[coding_arg_eol_type]; | |
7668 if (! NILP (eol_type) | |
7669 && ! EQ (eol_type, Qunix) | |
7670 && ! EQ (eol_type, Qdos) | |
7671 && ! EQ (eol_type, Qmac)) | |
7672 error ("Invalid eol-type"); | |
7673 | |
7674 aliases = Fcons (name, Qnil); | |
7675 | |
7676 if (NILP (eol_type)) | |
7677 { | |
7678 eol_type = make_subsidiaries (name); | |
7679 for (i = 0; i < 3; i++) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7680 { |
88365 | 7681 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
7682 | |
7683 this_name = AREF (eol_type, i); | |
7684 this_aliases = Fcons (this_name, Qnil); | |
7685 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
7686 this_spec = Fmake_vector (make_number (3), attrs); | |
7687 ASET (this_spec, 1, this_aliases); | |
7688 ASET (this_spec, 2, this_eol_type); | |
7689 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
7690 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
7691 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (this_name), Qnil), | |
7692 Vcoding_system_alist); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7693 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7694 } |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7695 |
88365 | 7696 spec_vec = Fmake_vector (make_number (3), attrs); |
7697 ASET (spec_vec, 1, aliases); | |
7698 ASET (spec_vec, 2, eol_type); | |
7699 | |
7700 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
7701 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
7702 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), | |
7703 Vcoding_system_alist); | |
7704 | |
7705 { | |
7706 int id = coding_categories[category].id; | |
7707 | |
7708 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
7709 setup_coding_system (name, &coding_categories[category]); | |
7710 } | |
7711 | |
7712 return Qnil; | |
7713 | |
7714 short_args: | |
7715 return Fsignal (Qwrong_number_of_arguments, | |
7716 Fcons (intern ("define-coding-system-internal"), | |
7717 make_number (nargs))); | |
7718 } | |
7719 | |
7720 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, | |
7721 Sdefine_coding_system_alias, 2, 2, 0, | |
7722 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
7723 (alias, coding_system) | |
7724 Lisp_Object alias, coding_system; | |
7725 { | |
7726 Lisp_Object spec, aliases, eol_type; | |
7727 | |
7728 CHECK_SYMBOL (alias); | |
7729 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7730 aliases = AREF (spec, 1); | |
7731 while (!NILP (XCDR (aliases))) | |
7732 aliases = XCDR (aliases); | |
7733 XCDR (aliases) = Fcons (alias, Qnil); | |
7734 | |
7735 eol_type = AREF (spec, 2); | |
7736 if (VECTORP (eol_type)) | |
7737 { | |
7738 Lisp_Object subsidiaries; | |
7739 int i; | |
7740 | |
7741 subsidiaries = make_subsidiaries (alias); | |
7742 for (i = 0; i < 3; i++) | |
7743 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
7744 AREF (eol_type, i)); | |
7745 | |
7746 ASET (spec, 2, subsidiaries); | |
7747 } | |
7748 | |
7749 Fputhash (alias, spec, Vcoding_system_hash_table); | |
88485 | 7750 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
7751 Vcoding_system_alist); | |
88365 | 7752 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7753 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7754 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7755 |
88365 | 7756 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
7757 1, 1, 0, | |
7758 doc: /* Return the base of CODING-SYSTEM. | |
7759 Any alias or subsidiary coding systems are not base coding system. */) | |
7760 (coding_system) | |
7761 Lisp_Object coding_system; | |
7762 { | |
7763 Lisp_Object spec, attrs; | |
7764 | |
7765 if (NILP (coding_system)) | |
7766 return (Qno_conversion); | |
7767 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7768 attrs = AREF (spec, 0); | |
7769 return CODING_ATTR_BASE_NAME (attrs); | |
7770 } | |
7771 | |
7772 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
7773 1, 1, 0, | |
7774 doc: "Return the property list of CODING-SYSTEM.") | |
7775 (coding_system) | |
7776 Lisp_Object coding_system; | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7777 { |
88365 | 7778 Lisp_Object spec, attrs; |
7779 | |
7780 if (NILP (coding_system)) | |
7781 coding_system = Qno_conversion; | |
7782 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7783 attrs = AREF (spec, 0); | |
7784 return CODING_ATTR_PLIST (attrs); | |
7785 } | |
7786 | |
7787 | |
7788 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
7789 1, 1, 0, | |
7790 doc: /* Return the list of aliases of CODING-SYSTEM. | |
7791 A base coding system is what made by `define-coding-system'. | |
7792 Any alias nor subsidiary coding systems are not base coding system. */) | |
7793 (coding_system) | |
7794 Lisp_Object coding_system; | |
7795 { | |
7796 Lisp_Object spec; | |
7797 | |
7798 if (NILP (coding_system)) | |
7799 coding_system = Qno_conversion; | |
7800 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7801 return AREF (spec, 2); | |
7802 } | |
7803 | |
7804 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
7805 Scoding_system_eol_type, 1, 1, 0, | |
7806 doc: /* Return eol-type of CODING-SYSTEM. | |
7807 An eol-type is integer 0, 1, 2, or a vector of coding systems. | |
7808 | |
7809 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
7810 and CR respectively. | |
7811 | |
7812 A vector value indicates that a format of end-of-line should be | |
7813 detected automatically. Nth element of the vector is the subsidiary | |
7814 coding system whose eol-type is N. */) | |
7815 (coding_system) | |
7816 Lisp_Object coding_system; | |
7817 { | |
7818 Lisp_Object spec, eol_type; | |
7819 int n; | |
7820 | |
7821 if (NILP (coding_system)) | |
7822 coding_system = Qno_conversion; | |
7823 if (! CODING_SYSTEM_P (coding_system)) | |
7824 return Qnil; | |
7825 spec = CODING_SYSTEM_SPEC (coding_system); | |
7826 eol_type = AREF (spec, 2); | |
7827 if (VECTORP (eol_type)) | |
7828 return Fcopy_sequence (eol_type); | |
7829 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
7830 return make_number (n); | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7831 } |
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7832 |
17052 | 7833 #endif /* emacs */ |
7834 | |
7835 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7836 /*** 9. Post-amble ***/ |
17052 | 7837 |
21514 | 7838 void |
17052 | 7839 init_coding_once () |
7840 { | |
7841 int i; | |
7842 | |
88365 | 7843 for (i = 0; i < coding_category_max; i++) |
7844 { | |
7845 coding_categories[i].id = -1; | |
7846 coding_priorities[i] = i; | |
7847 } | |
17052 | 7848 |
7849 /* ISO2022 specific initialize routine. */ | |
7850 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
|
7851 iso_code_class[i] = ISO_control_0; |
17052 | 7852 for (i = 0x21; i < 0x7F; i++) |
7853 iso_code_class[i] = ISO_graphic_plane_0; | |
7854 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
|
7855 iso_code_class[i] = ISO_control_1; |
17052 | 7856 for (i = 0xA1; i < 0xFF; i++) |
7857 iso_code_class[i] = ISO_graphic_plane_1; | |
7858 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
7859 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
7860 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
7861 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
7862 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
7863 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
7864 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
7865 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
7866 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
7867 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
7868 | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
7869 inhibit_pre_post_conversion = 0; |
88365 | 7870 |
7871 for (i = 0; i < 256; i++) | |
7872 { | |
7873 emacs_mule_bytes[i] = 1; | |
7874 } | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
7875 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
|
7876 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
|
7877 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
|
7878 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
|
7879 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7880 |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7881 #ifdef emacs |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7882 |
21514 | 7883 void |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7884 syms_of_coding () |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7885 { |
88365 | 7886 staticpro (&Vcoding_system_hash_table); |
7887 Vcoding_system_hash_table = Fmakehash (Qeq); | |
7888 | |
7889 staticpro (&Vsjis_coding_system); | |
7890 Vsjis_coding_system = Qnil; | |
7891 | |
7892 staticpro (&Vbig5_coding_system); | |
7893 Vbig5_coding_system = Qnil; | |
7894 | |
7895 staticpro (&Vcode_conversion_work_buf_list); | |
7896 Vcode_conversion_work_buf_list = Qnil; | |
7897 | |
7898 staticpro (&Vcode_conversion_reused_work_buf); | |
7899 Vcode_conversion_reused_work_buf = Qnil; | |
7900 | |
7901 DEFSYM (Qcharset, "charset"); | |
7902 DEFSYM (Qtarget_idx, "target-idx"); | |
7903 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7904 Fset (Qcoding_system_history, Qnil); |
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7905 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7906 /* 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
|
7907 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
|
7908 /* 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
|
7909 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
|
7910 |
88365 | 7911 DEFSYM (Qcall_process, "call-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7912 /* 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
|
7913 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
|
7914 |
88365 | 7915 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
|
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 (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
|
7918 |
88365 | 7919 DEFSYM (Qstart_process, "start-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7920 /* 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
|
7921 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
|
7922 |
88365 | 7923 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
|
7924 /* 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
|
7925 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
|
7926 |
88365 | 7927 DEFSYM (Qcoding_system, "coding-system"); |
7928 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
7929 | |
7930 DEFSYM (Qeol_type, "eol-type"); | |
7931 DEFSYM (Qunix, "unix"); | |
7932 DEFSYM (Qdos, "dos"); | |
7933 DEFSYM (Qmac, "mac"); | |
7934 | |
7935 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
7936 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
7937 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
7938 DEFSYM (Qdefault_char, "default-char"); | |
7939 DEFSYM (Qundecided, "undecided"); | |
7940 DEFSYM (Qno_conversion, "no-conversion"); | |
7941 DEFSYM (Qraw_text, "raw-text"); | |
7942 | |
7943 DEFSYM (Qiso_2022, "iso-2022"); | |
7944 | |
7945 DEFSYM (Qutf_8, "utf-8"); | |
7946 | |
7947 DEFSYM (Qutf_16, "utf-16"); | |
7948 DEFSYM (Qutf_16_be, "utf-16-be"); | |
7949 DEFSYM (Qutf_16_be_nosig, "utf-16-be-nosig"); | |
7950 DEFSYM (Qutf_16_le, "utf-16-l3"); | |
7951 DEFSYM (Qutf_16_le_nosig, "utf-16-le-nosig"); | |
7952 DEFSYM (Qsignature, "signature"); | |
7953 DEFSYM (Qendian, "endian"); | |
7954 DEFSYM (Qbig, "big"); | |
7955 DEFSYM (Qlittle, "little"); | |
7956 | |
7957 DEFSYM (Qshift_jis, "shift-jis"); | |
7958 DEFSYM (Qbig5, "big5"); | |
7959 | |
7960 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
7961 | |
7962 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
17052 | 7963 Fput (Qcoding_system_error, Qerror_conditions, |
7964 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
7965 Fput (Qcoding_system_error, Qerror_message, | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7966 build_string ("Invalid coding system")); |
17052 | 7967 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7968 /* 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
|
7969 Setting this variable twice is harmless. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7970 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
|
7971 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
88365 | 7972 |
7973 DEFSYM (Qtranslation_table, "translation-table"); | |
7974 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); | |
7975 DEFSYM (Qtranslation_table_id, "translation-table-id"); | |
7976 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
7977 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
7978 | |
7979 DEFSYM (Qvalid_codes, "valid-codes"); | |
7980 | |
7981 DEFSYM (Qemacs_mule, "emacs-mule"); | |
7982 | |
7983 Vcoding_category_table | |
7984 = Fmake_vector (make_number (coding_category_max), Qnil); | |
7985 staticpro (&Vcoding_category_table); | |
7986 /* Followings are target of code detection. */ | |
7987 ASET (Vcoding_category_table, coding_category_iso_7, | |
7988 intern ("coding-category-iso-7")); | |
7989 ASET (Vcoding_category_table, coding_category_iso_7_tight, | |
7990 intern ("coding-category-iso-7-tight")); | |
7991 ASET (Vcoding_category_table, coding_category_iso_8_1, | |
7992 intern ("coding-category-iso-8-1")); | |
7993 ASET (Vcoding_category_table, coding_category_iso_8_2, | |
7994 intern ("coding-category-iso-8-2")); | |
7995 ASET (Vcoding_category_table, coding_category_iso_7_else, | |
7996 intern ("coding-category-iso-7-else")); | |
7997 ASET (Vcoding_category_table, coding_category_iso_8_else, | |
7998 intern ("coding-category-iso-8-else")); | |
7999 ASET (Vcoding_category_table, coding_category_utf_8, | |
8000 intern ("coding-category-utf-8")); | |
8001 ASET (Vcoding_category_table, coding_category_utf_16_be, | |
8002 intern ("coding-category-utf-16-be")); | |
8003 ASET (Vcoding_category_table, coding_category_utf_16_le, | |
8004 intern ("coding-category-utf-16-le")); | |
8005 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, | |
8006 intern ("coding-category-utf-16-be-nosig")); | |
8007 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, | |
8008 intern ("coding-category-utf-16-le-nosig")); | |
8009 ASET (Vcoding_category_table, coding_category_charset, | |
8010 intern ("coding-category-charset")); | |
8011 ASET (Vcoding_category_table, coding_category_sjis, | |
8012 intern ("coding-category-sjis")); | |
8013 ASET (Vcoding_category_table, coding_category_big5, | |
8014 intern ("coding-category-big5")); | |
8015 ASET (Vcoding_category_table, coding_category_ccl, | |
8016 intern ("coding-category-ccl")); | |
8017 ASET (Vcoding_category_table, coding_category_emacs_mule, | |
8018 intern ("coding-category-emacs-mule")); | |
8019 /* Followings are NOT target of code detection. */ | |
8020 ASET (Vcoding_category_table, coding_category_raw_text, | |
8021 intern ("coding-category-raw-text")); | |
8022 ASET (Vcoding_category_table, coding_category_undecided, | |
8023 intern ("coding-category-undecided")); | |
8024 | |
17052 | 8025 defsubr (&Scoding_system_p); |
8026 defsubr (&Sread_coding_system); | |
8027 defsubr (&Sread_non_nil_coding_system); | |
8028 defsubr (&Scheck_coding_system); | |
8029 defsubr (&Sdetect_coding_region); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8030 defsubr (&Sdetect_coding_string); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8031 defsubr (&Sfind_coding_systems_region_internal); |
88365 | 8032 defsubr (&Scheck_coding_systems_region); |
17052 | 8033 defsubr (&Sdecode_coding_region); |
8034 defsubr (&Sencode_coding_region); | |
8035 defsubr (&Sdecode_coding_string); | |
8036 defsubr (&Sencode_coding_string); | |
8037 defsubr (&Sdecode_sjis_char); | |
8038 defsubr (&Sencode_sjis_char); | |
8039 defsubr (&Sdecode_big5_char); | |
8040 defsubr (&Sencode_big5_char); | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8041 defsubr (&Sset_terminal_coding_system_internal); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8042 defsubr (&Sset_safe_terminal_coding_system_internal); |
17052 | 8043 defsubr (&Sterminal_coding_system); |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8044 defsubr (&Sset_keyboard_coding_system_internal); |
17052 | 8045 defsubr (&Skeyboard_coding_system); |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
8046 defsubr (&Sfind_operation_coding_system); |
88365 | 8047 defsubr (&Sset_coding_system_priority); |
8048 defsubr (&Sdefine_coding_system_internal); | |
8049 defsubr (&Sdefine_coding_system_alias); | |
8050 defsubr (&Scoding_system_base); | |
8051 defsubr (&Scoding_system_plist); | |
8052 defsubr (&Scoding_system_aliases); | |
8053 defsubr (&Scoding_system_eol_type); | |
8054 defsubr (&Scoding_system_priority_list); | |
17052 | 8055 |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8056 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
|
8057 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
|
8058 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8059 Do not alter the value of this variable manually. This variable should be |
88365 | 8060 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
|
8061 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8062 Vcoding_system_list = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8063 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8064 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
|
8065 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
|
8066 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
|
8067 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
|
8068 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8069 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
|
8070 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
|
8071 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8072 Vcoding_system_alist = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8073 |
17052 | 8074 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
|
8075 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
|
8076 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8077 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
|
8078 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
|
8079 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
|
8080 system bound to the corresponding coding-category is selected. */); |
17052 | 8081 { |
8082 int i; | |
8083 | |
8084 Vcoding_category_list = Qnil; | |
88365 | 8085 for (i = coding_category_max - 1; i >= 0; i--) |
17052 | 8086 Vcoding_category_list |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8087 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8088 Vcoding_category_list); |
17052 | 8089 } |
8090 | |
8091 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
|
8092 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
|
8093 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
|
8094 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
|
8095 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
|
8096 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
|
8097 `process-coding-system-alist', and `network-coding-system-alist'. */); |
17052 | 8098 Vcoding_system_for_read = Qnil; |
8099 | |
8100 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
|
8101 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
|
8102 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
|
8103 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
|
8104 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
|
8105 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8106 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
|
8107 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
|
8108 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
|
8109 `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
|
8110 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
|
8111 the value of `buffer-file-coding-system' is used. */); |
17052 | 8112 Vcoding_system_for_write = Qnil; |
8113 | |
8114 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
88365 | 8115 doc: /* |
8116 Coding system used in the latest file or process I/O. */); | |
17052 | 8117 Vlast_coding_system_used = Qnil; |
8118 | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8119 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
88365 | 8120 doc: /* |
8121 *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
|
8122 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
|
8123 such conversion. */); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8124 inhibit_eol_conversion = 0; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8125 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8126 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
88365 | 8127 doc: /* |
8128 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
|
8129 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
|
8130 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
|
8131 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
|
8132 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8133 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
88365 | 8134 doc: /* |
8135 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
|
8136 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
|
8137 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
|
8138 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
|
8139 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
|
8140 the file contents. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8141 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
|
8142 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
|
8143 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
|
8144 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
|
8145 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
|
8146 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8147 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
|
8148 and the variable `auto-coding-alist'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8149 Vfile_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8150 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8151 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
88365 | 8152 doc: /* |
8153 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
|
8154 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
|
8155 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
|
8156 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
|
8157 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
|
8158 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
|
8159 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
|
8160 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
|
8161 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
|
8162 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
|
8163 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8164 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8165 Vprocess_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8166 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8167 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
88365 | 8168 doc: /* |
8169 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
|
8170 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
|
8171 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
|
8172 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
|
8173 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
|
8174 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
|
8175 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
|
8176 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
|
8177 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
|
8178 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
|
8179 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
|
8180 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8181 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8182 Vnetwork_coding_system_alist = Qnil; |
17052 | 8183 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8184 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
|
8185 doc: /* Coding system to use with system messages. |
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8186 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
|
8187 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
|
8188 |
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
8189 /* 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
|
8190 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
88365 | 8191 doc: /* |
8192 *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
|
8193 eol_mnemonic_unix = build_string (":"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8194 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8195 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
88365 | 8196 doc: /* |
8197 *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
|
8198 eol_mnemonic_dos = build_string ("\\"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8199 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8200 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
88365 | 8201 doc: /* |
8202 *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
|
8203 eol_mnemonic_mac = build_string ("/"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8204 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8205 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
88365 | 8206 doc: /* |
8207 *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
|
8208 eol_mnemonic_undecided = build_string (":"); |
17052 | 8209 |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8210 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
88365 | 8211 doc: /* |
8212 *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
|
8213 Venable_character_translation = Qt; |
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8214 |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8215 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
|
8216 &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
|
8217 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
|
8218 Vstandard_translation_table_for_decode = Qnil; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8219 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8220 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
|
8221 &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
|
8222 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
|
8223 Vstandard_translation_table_for_encode = Qnil; |
17052 | 8224 |
88365 | 8225 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
|
8226 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
|
8227 While encoding, if a charset (car part of an element) is found, |
88365 | 8228 designate it with the escape sequence identifying revision (cdr part |
8229 of the element). */); | |
8230 Vcharset_revision_table = Qnil; | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8231 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8232 DEFVAR_LISP ("default-process-coding-system", |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8233 &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
|
8234 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
|
8235 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
|
8236 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
|
8237 Vdefault_process_coding_system = Qnil; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8238 |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8239 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
88365 | 8240 doc: /* |
8241 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
|
8242 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
|
8243 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
|
8244 \(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
|
8245 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
|
8246 `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
|
8247 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
|
8248 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
|
8249 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
|
8250 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8251 DEFVAR_LISP ("select-safe-coding-system-function", |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8252 &Vselect_safe_coding_system_function, |
88365 | 8253 doc: /* |
8254 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
|
8255 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8256 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
|
8257 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
|
8258 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
|
8259 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8260 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
|
8261 Vselect_safe_coding_system_function = Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8262 |
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
8263 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8264 &inhibit_iso_escape_detection, |
88365 | 8265 doc: /* |
8266 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
|
8267 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8268 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
|
8269 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
|
8270 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
|
8271 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
|
8272 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
|
8273 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8274 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
|
8275 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
|
8276 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
|
8277 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
|
8278 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
|
8279 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8280 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
|
8281 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
|
8282 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
|
8283 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
|
8284 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
|
8285 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8286 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
|
8287 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
|
8288 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
|
8289 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
|
8290 |
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 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
|
8293 Lisp_Object plist[14]; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8294 int i; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8295 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8296 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
|
8297 args[i] = Qnil; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8298 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8299 plist[0] = intern (":name"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8300 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
|
8301 plist[2] = intern (":mnemonic"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8302 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
|
8303 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
|
8304 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
|
8305 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
|
8306 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
|
8307 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
|
8308 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
|
8309 plist[10] = intern (":docstring"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8310 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
|
8311 \n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8312 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
|
8313 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
|
8314 character."); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8315 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
|
8316 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
|
8317 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
|
8318 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
|
8319 } |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8320 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8321 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
|
8322 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
|
8323 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
17052 | 8324 } |
8325 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8326 char * |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8327 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
|
8328 int error_number; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8329 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8330 char *str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8331 |
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
8332 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
|
8333 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
|
8334 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8335 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
|
8336 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8337 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
|
8338 Vlocale_coding_system, |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8339 0); |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8340 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
|
8341 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8342 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8343 return str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8344 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8345 |
17052 | 8346 #endif /* emacs */ |