Mercurial > emacs
annotate src/coding.c @ 89174:df2bfefdd034
*** empty log message ***
author | Dave Love <fx@gnu.org> |
---|---|
date | Sun, 06 Oct 2002 21:18:39 +0000 |
parents | 2b9f8973f240 |
children | 88a9e962e183 |
rev | line source |
---|---|
88936 | 1 /* Coding system handler (conversion, detection, etc). |
20708 | 2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. |
18269
888bfd80db2c
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18180
diff
changeset
|
3 Licensed to the Free Software Foundation. |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
4 Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
88365 | 5 Copyright (C) 2001, 2002 |
6 National Institute of Advanced Industrial Science and Technology (AIST) | |
7 Registration Number H13PRO009 | |
17052 | 8 |
17071 | 9 This file is part of GNU Emacs. |
10 | |
11 GNU Emacs is free software; you can redistribute it and/or modify | |
12 it under the terms of the GNU General Public License as published by | |
13 the Free Software Foundation; either version 2, or (at your option) | |
14 any later version. | |
15 | |
16 GNU Emacs is distributed in the hope that it will be useful, | |
17 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 GNU General Public License for more details. | |
20 | |
21 You should have received a copy of the GNU General Public License | |
22 along with GNU Emacs; see the file COPYING. If not, write to | |
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 Boston, MA 02111-1307, USA. */ | |
17052 | 25 |
26 /*** TABLE OF CONTENTS *** | |
27 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
28 0. General comments |
17052 | 29 1. Preamble |
88365 | 30 2. Emacs' internal format (emacs-utf-8) handlers |
31 3. UTF-8 handlers | |
32 4. UTF-16 handlers | |
33 5. Charset-base coding systems handlers | |
34 6. emacs-mule (old Emacs' internal format) handlers | |
35 7. ISO2022 handlers | |
36 8. Shift-JIS and BIG5 handlers | |
37 9. CCL handlers | |
38 10. C library functions | |
39 11. Emacs Lisp library functions | |
40 12. Postamble | |
17052 | 41 |
42 */ | |
43 | |
88365 | 44 /*** 0. General comments *** |
45 | |
46 | |
47 CODING SYSTEM | |
48 | |
88485 | 49 A coding system is an object for an encoding mechanism that contains |
50 information about how to convert byte sequences to character | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
51 sequences and vice versa. When we say "decode", it means converting |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
52 a byte sequence of a specific coding system into a character |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
53 sequence that is represented by Emacs' internal coding system |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
54 `emacs-utf-8', and when we say "encode", it means converting a |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
55 character sequence of emacs-utf-8 to a byte sequence of a specific |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
56 coding system. |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
57 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
58 In Emacs Lisp, a coding system is represented by a Lisp symbol. In |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
59 C level, a coding system is represented by a vector of attributes |
88485 | 60 stored in the hash table Vcharset_hash_table. The conversion from |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
61 coding system symbol to attributes vector is done by looking up |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
62 Vcharset_hash_table by the symbol. |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
63 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
64 Coding systems are classified into the following types depending on |
88485 | 65 the encoding mechanism. Here's a brief description of the types. |
88365 | 66 |
67 o UTF-8 | |
68 | |
69 o UTF-16 | |
70 | |
71 o Charset-base coding system | |
72 | |
73 A coding system defined by one or more (coded) character sets. | |
88485 | 74 Decoding and encoding are done by a code converter defined for each |
88365 | 75 character set. |
76 | |
88485 | 77 o Old Emacs internal format (emacs-mule) |
78 | |
79 The coding system adopted by old versions of Emacs (20 and 21). | |
88365 | 80 |
81 o ISO2022-base coding system | |
17052 | 82 |
83 The most famous coding system for multiple character sets. X's | |
88365 | 84 Compound Text, various EUCs (Extended Unix Code), and coding systems |
85 used in the Internet communication such as ISO-2022-JP are all | |
86 variants of ISO2022. | |
87 | |
88 o SJIS (or Shift-JIS or MS-Kanji-Code) | |
89 | |
17052 | 90 A coding system to encode character sets: ASCII, JISX0201, and |
91 JISX0208. Widely used for PC's in Japan. Details are described in | |
88365 | 92 section 8. |
93 | |
94 o BIG5 | |
95 | |
96 A coding system to encode character sets: ASCII and Big5. Widely | |
88771 | 97 used for Chinese (mainly in Taiwan and Hong Kong). Details are |
88365 | 98 described in section 8. In this file, when we write "big5" (all |
99 lowercase), we mean the coding system, and when we write "Big5" | |
100 (capitalized), we mean the character set. | |
101 | |
102 o CCL | |
103 | |
88485 | 104 If a user wants to decode/encode text encoded in a coding system |
88365 | 105 not listed above, he can supply a decoder and an encoder for it in |
106 CCL (Code Conversion Language) programs. Emacs executes the CCL | |
107 program while decoding/encoding. | |
108 | |
109 o Raw-text | |
110 | |
88771 | 111 A coding system for text containing raw eight-bit data. Emacs |
88485 | 112 treats each byte of source text as a character (except for |
88365 | 113 end-of-line conversion). |
114 | |
115 o No-conversion | |
116 | |
117 Like raw text, but don't do end-of-line conversion. | |
118 | |
119 | |
120 END-OF-LINE FORMAT | |
121 | |
88485 | 122 How text end-of-line is encoded depends on operating system. For |
88365 | 123 instance, Unix's format is just one byte of LF (line-feed) code, |
18766 | 124 whereas DOS's format is two-byte sequence of `carriage-return' and |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
125 `line-feed' codes. MacOS's format is usually one byte of |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
126 `carriage-return'. |
17052 | 127 |
88485 | 128 Since text character encoding and end-of-line encoding are |
88365 | 129 independent, any coding system described above can take any format |
130 of end-of-line (except for no-conversion). | |
17052 | 131 |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
132 STRUCT CODING_SYSTEM |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
133 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
134 Before using a coding system for code conversion (i.e. decoding and |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
135 encoding), we setup a structure of type `struct coding_system'. |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
136 This structure keeps various information about a specific code |
88485 | 137 conversion (e.g. the location of source and destination data). |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
138 |
17052 | 139 */ |
140 | |
88365 | 141 /* COMMON MACROS */ |
142 | |
143 | |
17052 | 144 /*** GENERAL NOTES on `detect_coding_XXX ()' functions *** |
145 | |
88365 | 146 These functions check if a byte sequence specified as a source in |
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; | |
88646
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
306 Lisp_Object Qunix, Qdos; |
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
307 extern Lisp_Object Qmac; /* frame.c */ |
17052 | 308 Lisp_Object Qbuffer_file_coding_system; |
309 Lisp_Object Qpost_read_conversion, Qpre_write_conversion; | |
88365 | 310 Lisp_Object Qdefault_char; |
19612
783efd6c7c1e
(Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents:
19546
diff
changeset
|
311 Lisp_Object Qno_conversion, Qundecided; |
88365 | 312 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; |
313 Lisp_Object Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig, Qutf_16_le; | |
314 Lisp_Object Qsignature, Qendian, Qbig, Qlittle; | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
315 Lisp_Object Qcoding_system_history; |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
316 Lisp_Object Qvalid_codes; |
17052 | 317 |
318 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | |
319 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | |
320 Lisp_Object Qstart_process, Qopen_network_stream; | |
321 Lisp_Object Qtarget_idx; | |
322 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
323 Lisp_Object Vselect_safe_coding_system_function; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
324 |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
325 /* 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
|
326 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
|
327 /* Mnemonic string to indicate format of end-of-line is not yet |
17052 | 328 decided. */ |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
329 Lisp_Object eol_mnemonic_undecided; |
17052 | 330 |
331 #ifdef emacs | |
332 | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
333 Lisp_Object Vcoding_system_list, Vcoding_system_alist; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
334 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
335 Lisp_Object Qcoding_system_p, Qcoding_system_error; |
17052 | 336 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
337 /* 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
|
338 end-of-line format. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
339 Lisp_Object Qemacs_mule, Qraw_text; |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
340 |
17052 | 341 /* Coding-systems are handed between Emacs Lisp programs and C internal |
342 routines by the following three variables. */ | |
343 /* Coding-system for reading files and receiving data from process. */ | |
344 Lisp_Object Vcoding_system_for_read; | |
345 /* Coding-system for writing files and sending data to process. */ | |
346 Lisp_Object Vcoding_system_for_write; | |
347 /* Coding-system actually used in the latest I/O. */ | |
348 Lisp_Object Vlast_coding_system_used; | |
349 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
350 /* A vector of length 256 which contains information about special |
22529 | 351 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
|
352 Lisp_Object Vlatin_extra_code_table; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
353 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
354 /* 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
|
355 int inhibit_eol_conversion; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
356 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
357 /* Flag to inhibit ISO2022 escape sequence detection. */ |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
358 int inhibit_iso_escape_detection; |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
359 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
360 /* 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
|
361 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
|
362 |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
363 /* Coding system to be used to encode text for terminal display. */ |
17052 | 364 struct coding_system terminal_coding; |
365 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
366 /* 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
|
367 terminal coding system is nil. */ |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
368 struct coding_system safe_terminal_coding; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
369 |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
370 /* Coding system of what is sent from terminal keyboard. */ |
17052 | 371 struct coding_system keyboard_coding; |
372 | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
373 Lisp_Object Vfile_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
374 Lisp_Object Vprocess_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
375 Lisp_Object Vnetwork_coding_system_alist; |
17052 | 376 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
377 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
|
378 |
17052 | 379 #endif /* emacs */ |
380 | |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
381 /* 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
|
382 conversion. */ |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
383 Lisp_Object Venable_character_translation; |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
384 /* 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
|
385 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
|
386 /* 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
|
387 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
|
388 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
389 Lisp_Object Qtranslation_table; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
390 Lisp_Object Qtranslation_table_id; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
391 Lisp_Object Qtranslation_table_for_decode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
392 Lisp_Object Qtranslation_table_for_encode; |
17052 | 393 |
394 /* Alist of charsets vs revision number. */ | |
88365 | 395 static Lisp_Object Vcharset_revision_table; |
17052 | 396 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
397 /* Default coding systems used for process I/O. */ |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
398 Lisp_Object Vdefault_process_coding_system; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
399 |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
400 /* 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
|
401 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
|
402 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
|
403 to avoid infinite recursive call. */ |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
404 static int inhibit_pre_post_conversion; |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
405 |
88365 | 406 /* Two special coding systems. */ |
407 Lisp_Object Vsjis_coding_system; | |
408 Lisp_Object Vbig5_coding_system; | |
409 | |
410 | |
411 static int detect_coding_utf_8 P_ ((struct coding_system *, int *)); | |
412 static void decode_coding_utf_8 P_ ((struct coding_system *)); | |
413 static int encode_coding_utf_8 P_ ((struct coding_system *)); | |
414 | |
415 static int detect_coding_utf_16 P_ ((struct coding_system *, int *)); | |
416 static void decode_coding_utf_16 P_ ((struct coding_system *)); | |
417 static int encode_coding_utf_16 P_ ((struct coding_system *)); | |
418 | |
419 static int detect_coding_iso_2022 P_ ((struct coding_system *, int *)); | |
420 static void decode_coding_iso_2022 P_ ((struct coding_system *)); | |
421 static int encode_coding_iso_2022 P_ ((struct coding_system *)); | |
422 | |
423 static int detect_coding_emacs_mule P_ ((struct coding_system *, int *)); | |
424 static void decode_coding_emacs_mule P_ ((struct coding_system *)); | |
425 static int encode_coding_emacs_mule P_ ((struct coding_system *)); | |
426 | |
427 static int detect_coding_sjis P_ ((struct coding_system *, int *)); | |
428 static void decode_coding_sjis P_ ((struct coding_system *)); | |
429 static int encode_coding_sjis P_ ((struct coding_system *)); | |
430 | |
431 static int detect_coding_big5 P_ ((struct coding_system *, int *)); | |
432 static void decode_coding_big5 P_ ((struct coding_system *)); | |
433 static int encode_coding_big5 P_ ((struct coding_system *)); | |
434 | |
435 static int detect_coding_ccl P_ ((struct coding_system *, int *)); | |
436 static void decode_coding_ccl P_ ((struct coding_system *)); | |
437 static int encode_coding_ccl P_ ((struct coding_system *)); | |
438 | |
439 static void decode_coding_raw_text P_ ((struct coding_system *)); | |
440 static int encode_coding_raw_text P_ ((struct coding_system *)); | |
441 | |
442 | |
443 /* ISO2022 section */ | |
444 | |
445 #define CODING_ISO_INITIAL(coding, reg) \ | |
446 (XINT (AREF (AREF (CODING_ID_ATTRS ((coding)->id), \ | |
447 coding_attr_iso_initial), \ | |
448 reg))) | |
449 | |
450 | |
451 #define CODING_ISO_REQUEST(coding, charset_id) \ | |
452 ((charset_id <= (coding)->max_charset_id \ | |
453 ? (coding)->safe_charsets[charset_id] \ | |
454 : -1)) | |
455 | |
456 | |
457 #define CODING_ISO_FLAGS(coding) \ | |
458 ((coding)->spec.iso_2022.flags) | |
459 #define CODING_ISO_DESIGNATION(coding, reg) \ | |
460 ((coding)->spec.iso_2022.current_designation[reg]) | |
461 #define CODING_ISO_INVOCATION(coding, plane) \ | |
462 ((coding)->spec.iso_2022.current_invocation[plane]) | |
463 #define CODING_ISO_SINGLE_SHIFTING(coding) \ | |
464 ((coding)->spec.iso_2022.single_shifting) | |
465 #define CODING_ISO_BOL(coding) \ | |
466 ((coding)->spec.iso_2022.bol) | |
467 #define CODING_ISO_INVOKED_CHARSET(coding, plane) \ | |
468 CODING_ISO_DESIGNATION ((coding), CODING_ISO_INVOCATION ((coding), (plane))) | |
469 | |
470 /* Control characters of ISO2022. */ | |
471 /* code */ /* function */ | |
472 #define ISO_CODE_LF 0x0A /* line-feed */ | |
473 #define ISO_CODE_CR 0x0D /* carriage-return */ | |
474 #define ISO_CODE_SO 0x0E /* shift-out */ | |
475 #define ISO_CODE_SI 0x0F /* shift-in */ | |
476 #define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */ | |
477 #define ISO_CODE_ESC 0x1B /* escape */ | |
478 #define ISO_CODE_SS2 0x8E /* single-shift-2 */ | |
479 #define ISO_CODE_SS3 0x8F /* single-shift-3 */ | |
480 #define ISO_CODE_CSI 0x9B /* control-sequence-introducer */ | |
481 | |
482 /* All code (1-byte) of ISO2022 is classified into one of the | |
483 followings. */ | |
484 enum iso_code_class_type | |
485 { | |
486 ISO_control_0, /* Control codes in the range | |
487 0x00..0x1F and 0x7F, except for the | |
488 following 5 codes. */ | |
489 ISO_carriage_return, /* ISO_CODE_CR (0x0D) */ | |
490 ISO_shift_out, /* ISO_CODE_SO (0x0E) */ | |
491 ISO_shift_in, /* ISO_CODE_SI (0x0F) */ | |
492 ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ | |
493 ISO_escape, /* ISO_CODE_SO (0x1B) */ | |
494 ISO_control_1, /* Control codes in the range | |
495 0x80..0x9F, except for the | |
496 following 3 codes. */ | |
497 ISO_single_shift_2, /* ISO_CODE_SS2 (0x8E) */ | |
498 ISO_single_shift_3, /* ISO_CODE_SS3 (0x8F) */ | |
499 ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */ | |
500 ISO_0x20_or_0x7F, /* Codes of the values 0x20 or 0x7F. */ | |
501 ISO_graphic_plane_0, /* Graphic codes in the range 0x21..0x7E. */ | |
502 ISO_0xA0_or_0xFF, /* Codes of the values 0xA0 or 0xFF. */ | |
503 ISO_graphic_plane_1 /* Graphic codes in the range 0xA1..0xFE. */ | |
504 }; | |
505 | |
506 /** The macros CODING_ISO_FLAG_XXX defines a flag bit of the | |
507 `iso-flags' attribute of an iso2022 coding system. */ | |
508 | |
509 /* If set, produce long-form designation sequence (e.g. ESC $ ( A) | |
510 instead of the correct short-form sequence (e.g. ESC $ A). */ | |
511 #define CODING_ISO_FLAG_LONG_FORM 0x0001 | |
512 | |
513 /* If set, reset graphic planes and registers at end-of-line to the | |
514 initial state. */ | |
515 #define CODING_ISO_FLAG_RESET_AT_EOL 0x0002 | |
516 | |
517 /* If set, reset graphic planes and registers before any control | |
518 characters to the initial state. */ | |
519 #define CODING_ISO_FLAG_RESET_AT_CNTL 0x0004 | |
520 | |
521 /* If set, encode by 7-bit environment. */ | |
522 #define CODING_ISO_FLAG_SEVEN_BITS 0x0008 | |
523 | |
524 /* If set, use locking-shift function. */ | |
525 #define CODING_ISO_FLAG_LOCKING_SHIFT 0x0010 | |
526 | |
527 /* If set, use single-shift function. Overwrite | |
528 CODING_ISO_FLAG_LOCKING_SHIFT. */ | |
529 #define CODING_ISO_FLAG_SINGLE_SHIFT 0x0020 | |
530 | |
531 /* If set, use designation escape sequence. */ | |
532 #define CODING_ISO_FLAG_DESIGNATION 0x0040 | |
533 | |
534 /* If set, produce revision number sequence. */ | |
535 #define CODING_ISO_FLAG_REVISION 0x0080 | |
536 | |
537 /* If set, produce ISO6429's direction specifying sequence. */ | |
538 #define CODING_ISO_FLAG_DIRECTION 0x0100 | |
539 | |
540 /* If set, assume designation states are reset at beginning of line on | |
541 output. */ | |
542 #define CODING_ISO_FLAG_INIT_AT_BOL 0x0200 | |
543 | |
544 /* If set, designation sequence should be placed at beginning of line | |
545 on output. */ | |
546 #define CODING_ISO_FLAG_DESIGNATE_AT_BOL 0x0400 | |
547 | |
548 /* If set, do not encode unsafe charactes on output. */ | |
549 #define CODING_ISO_FLAG_SAFE 0x0800 | |
550 | |
551 /* If set, extra latin codes (128..159) are accepted as a valid code | |
552 on input. */ | |
553 #define CODING_ISO_FLAG_LATIN_EXTRA 0x1000 | |
554 | |
555 #define CODING_ISO_FLAG_COMPOSITION 0x2000 | |
556 | |
557 #define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 | |
558 | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
559 #define CODING_ISO_FLAG_USE_ROMAN 0x8000 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
560 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
561 #define CODING_ISO_FLAG_USE_OLDJIS 0x10000 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
562 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
563 #define CODING_ISO_FLAG_FULL_SUPPORT 0x100000 |
88365 | 564 |
565 /* A character to be produced on output if encoding of the original | |
566 character is prohibited by CODING_ISO_FLAG_SAFE. */ | |
567 #define CODING_INHIBIT_CHARACTER_SUBSTITUTION '?' | |
568 | |
569 | |
570 /* UTF-16 section */ | |
571 #define CODING_UTF_16_BOM(coding) \ | |
572 ((coding)->spec.utf_16.bom) | |
573 | |
574 #define CODING_UTF_16_ENDIAN(coding) \ | |
575 ((coding)->spec.utf_16.endian) | |
576 | |
577 #define CODING_UTF_16_SURROGATE(coding) \ | |
578 ((coding)->spec.utf_16.surrogate) | |
579 | |
580 | |
581 /* CCL section */ | |
582 #define CODING_CCL_DECODER(coding) \ | |
583 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_decoder) | |
584 #define CODING_CCL_ENCODER(coding) \ | |
585 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_encoder) | |
586 #define CODING_CCL_VALIDS(coding) \ | |
587 (XSTRING (AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_valids)) \ | |
588 ->data) | |
589 | |
88771 | 590 /* Index for each coding category in `coding_categories' */ |
88365 | 591 |
592 enum coding_category | |
593 { | |
594 coding_category_iso_7, | |
595 coding_category_iso_7_tight, | |
596 coding_category_iso_8_1, | |
597 coding_category_iso_8_2, | |
598 coding_category_iso_7_else, | |
599 coding_category_iso_8_else, | |
600 coding_category_utf_8, | |
601 coding_category_utf_16_auto, | |
602 coding_category_utf_16_be, | |
603 coding_category_utf_16_le, | |
604 coding_category_utf_16_be_nosig, | |
605 coding_category_utf_16_le_nosig, | |
606 coding_category_charset, | |
607 coding_category_sjis, | |
608 coding_category_big5, | |
609 coding_category_ccl, | |
610 coding_category_emacs_mule, | |
611 /* All above are targets of code detection. */ | |
612 coding_category_raw_text, | |
613 coding_category_undecided, | |
614 coding_category_max | |
615 }; | |
616 | |
617 /* Definitions of flag bits used in detect_coding_XXXX. */ | |
618 #define CATEGORY_MASK_ISO_7 (1 << coding_category_iso_7) | |
619 #define CATEGORY_MASK_ISO_7_TIGHT (1 << coding_category_iso_7_tight) | |
620 #define CATEGORY_MASK_ISO_8_1 (1 << coding_category_iso_8_1) | |
621 #define CATEGORY_MASK_ISO_8_2 (1 << coding_category_iso_8_2) | |
622 #define CATEGORY_MASK_ISO_7_ELSE (1 << coding_category_iso_7_else) | |
623 #define CATEGORY_MASK_ISO_8_ELSE (1 << coding_category_iso_8_else) | |
624 #define CATEGORY_MASK_UTF_8 (1 << coding_category_utf_8) | |
625 #define CATEGORY_MASK_UTF_16_BE (1 << coding_category_utf_16_be) | |
626 #define CATEGORY_MASK_UTF_16_LE (1 << coding_category_utf_16_le) | |
627 #define CATEGORY_MASK_UTF_16_BE_NOSIG (1 << coding_category_utf_16_be_nosig) | |
628 #define CATEGORY_MASK_UTF_16_LE_NOSIG (1 << coding_category_utf_16_le_nosig) | |
629 #define CATEGORY_MASK_CHARSET (1 << coding_category_charset) | |
630 #define CATEGORY_MASK_SJIS (1 << coding_category_sjis) | |
631 #define CATEGORY_MASK_BIG5 (1 << coding_category_big5) | |
632 #define CATEGORY_MASK_CCL (1 << coding_category_ccl) | |
633 #define CATEGORY_MASK_EMACS_MULE (1 << coding_category_emacs_mule) | |
634 | |
635 /* This value is returned if detect_coding_mask () find nothing other | |
636 than ASCII characters. */ | |
637 #define CATEGORY_MASK_ANY \ | |
638 (CATEGORY_MASK_ISO_7 \ | |
639 | CATEGORY_MASK_ISO_7_TIGHT \ | |
640 | CATEGORY_MASK_ISO_8_1 \ | |
641 | CATEGORY_MASK_ISO_8_2 \ | |
642 | CATEGORY_MASK_ISO_7_ELSE \ | |
643 | CATEGORY_MASK_ISO_8_ELSE \ | |
644 | CATEGORY_MASK_UTF_8 \ | |
645 | CATEGORY_MASK_UTF_16_BE \ | |
646 | CATEGORY_MASK_UTF_16_LE \ | |
647 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
648 | CATEGORY_MASK_UTF_16_LE_NOSIG \ | |
649 | CATEGORY_MASK_CHARSET \ | |
650 | CATEGORY_MASK_SJIS \ | |
651 | CATEGORY_MASK_BIG5 \ | |
652 | CATEGORY_MASK_CCL \ | |
653 | CATEGORY_MASK_EMACS_MULE) | |
654 | |
655 | |
656 #define CATEGORY_MASK_ISO_7BIT \ | |
657 (CATEGORY_MASK_ISO_7 | CATEGORY_MASK_ISO_7_TIGHT) | |
658 | |
659 #define CATEGORY_MASK_ISO_8BIT \ | |
660 (CATEGORY_MASK_ISO_8_1 | CATEGORY_MASK_ISO_8_2) | |
661 | |
662 #define CATEGORY_MASK_ISO_ELSE \ | |
663 (CATEGORY_MASK_ISO_7_ELSE | CATEGORY_MASK_ISO_8_ELSE) | |
664 | |
665 #define CATEGORY_MASK_ISO_ESCAPE \ | |
666 (CATEGORY_MASK_ISO_7 \ | |
667 | CATEGORY_MASK_ISO_7_TIGHT \ | |
668 | CATEGORY_MASK_ISO_7_ELSE \ | |
669 | CATEGORY_MASK_ISO_8_ELSE) | |
670 | |
671 #define CATEGORY_MASK_ISO \ | |
672 ( CATEGORY_MASK_ISO_7BIT \ | |
673 | CATEGORY_MASK_ISO_8BIT \ | |
674 | CATEGORY_MASK_ISO_ELSE) | |
675 | |
676 #define CATEGORY_MASK_UTF_16 \ | |
677 (CATEGORY_MASK_UTF_16_BE \ | |
678 | CATEGORY_MASK_UTF_16_LE \ | |
679 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
680 | CATEGORY_MASK_UTF_16_LE_NOSIG) | |
681 | |
682 | |
683 /* List of symbols `coding-category-xxx' ordered by priority. This | |
684 variable is exposed to Emacs Lisp. */ | |
685 static Lisp_Object Vcoding_category_list; | |
686 | |
687 /* Table of coding categories (Lisp symbols). This variable is for | |
688 internal use oly. */ | |
689 static Lisp_Object Vcoding_category_table; | |
690 | |
691 /* Table of coding-categories ordered by priority. */ | |
692 static enum coding_category coding_priorities[coding_category_max]; | |
693 | |
694 /* Nth element is a coding context for the coding system bound to the | |
695 Nth coding category. */ | |
696 static struct coding_system coding_categories[coding_category_max]; | |
697 | |
698 static int detected_mask[coding_category_raw_text] = | |
699 { CATEGORY_MASK_ISO, | |
700 CATEGORY_MASK_ISO, | |
701 CATEGORY_MASK_ISO, | |
702 CATEGORY_MASK_ISO, | |
703 CATEGORY_MASK_ISO, | |
704 CATEGORY_MASK_ISO, | |
705 CATEGORY_MASK_UTF_8, | |
706 CATEGORY_MASK_UTF_16, | |
707 CATEGORY_MASK_UTF_16, | |
708 CATEGORY_MASK_UTF_16, | |
709 CATEGORY_MASK_UTF_16, | |
710 CATEGORY_MASK_UTF_16, | |
711 CATEGORY_MASK_CHARSET, | |
712 CATEGORY_MASK_SJIS, | |
713 CATEGORY_MASK_BIG5, | |
714 CATEGORY_MASK_CCL, | |
715 CATEGORY_MASK_EMACS_MULE | |
716 }; | |
717 | |
718 /*** Commonly used macros and functions ***/ | |
719 | |
720 #ifndef min | |
721 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
722 #endif | |
723 #ifndef max | |
724 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
725 #endif | |
726 | |
727 #define CODING_GET_INFO(coding, attrs, eol_type, charset_list) \ | |
728 do { \ | |
729 attrs = CODING_ID_ATTRS (coding->id); \ | |
730 eol_type = CODING_ID_EOL_TYPE (coding->id); \ | |
731 if (VECTORP (eol_type)) \ | |
732 eol_type = Qunix; \ | |
733 charset_list = CODING_ATTR_CHARSET_LIST (attrs); \ | |
734 } while (0) | |
735 | |
736 | |
737 /* Safely get one byte from the source text pointed by SRC which ends | |
738 at SRC_END, and set C to that byte. If there are not enough bytes | |
739 in the source, it jumps to `no_more_source'. The caller | |
740 should declare and set these variables appropriately in advance: | |
741 src, src_end, multibytep | |
742 */ | |
743 | |
744 #define ONE_MORE_BYTE(c) \ | |
745 do { \ | |
746 if (src == src_end) \ | |
747 { \ | |
748 if (src_base < src) \ | |
749 coding->result = CODING_RESULT_INSUFFICIENT_SRC; \ | |
750 goto no_more_source; \ | |
751 } \ | |
752 c = *src++; \ | |
753 if (multibytep && (c & 0x80)) \ | |
754 { \ | |
755 if ((c & 0xFE) != 0xC0) \ | |
756 error ("Undecodable char found"); \ | |
757 c = ((c & 1) << 6) | *src++; \ | |
758 } \ | |
759 consumed_chars++; \ | |
760 } while (0) | |
761 | |
762 | |
763 #define ONE_MORE_BYTE_NO_CHECK(c) \ | |
764 do { \ | |
765 c = *src++; \ | |
766 if (multibytep && (c & 0x80)) \ | |
767 { \ | |
768 if ((c & 0xFE) != 0xC0) \ | |
769 error ("Undecodable char found"); \ | |
770 c = ((c & 1) << 6) | *src++; \ | |
771 } \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
772 consumed_chars++; \ |
88365 | 773 } while (0) |
774 | |
775 | |
776 /* Store a byte C in the place pointed by DST and increment DST to the | |
777 next free point, and increment PRODUCED_CHARS. The caller should | |
778 assure that C is 0..127, and declare and set the variable `dst' | |
779 appropriately in advance. | |
780 */ | |
781 | |
782 | |
783 #define EMIT_ONE_ASCII_BYTE(c) \ | |
784 do { \ | |
785 produced_chars++; \ | |
786 *dst++ = (c); \ | |
787 } while (0) | |
788 | |
789 | |
790 /* Like EMIT_ONE_ASCII_BYTE byt store two bytes; C1 and C2. */ | |
791 | |
792 #define EMIT_TWO_ASCII_BYTES(c1, c2) \ | |
793 do { \ | |
794 produced_chars += 2; \ | |
795 *dst++ = (c1), *dst++ = (c2); \ | |
796 } while (0) | |
797 | |
798 | |
799 /* Store a byte C in the place pointed by DST and increment DST to the | |
800 next free point, and increment PRODUCED_CHARS. If MULTIBYTEP is | |
801 nonzero, store in an appropriate multibyte from. The caller should | |
802 declare and set the variables `dst' and `multibytep' appropriately | |
803 in advance. */ | |
804 | |
805 #define EMIT_ONE_BYTE(c) \ | |
806 do { \ | |
807 produced_chars++; \ | |
808 if (multibytep) \ | |
809 { \ | |
810 int ch = (c); \ | |
811 if (ch >= 0x80) \ | |
812 ch = BYTE8_TO_CHAR (ch); \ | |
813 CHAR_STRING_ADVANCE (ch, dst); \ | |
814 } \ | |
815 else \ | |
816 *dst++ = (c); \ | |
817 } while (0) | |
818 | |
819 | |
820 /* Like EMIT_ONE_BYTE, but emit two bytes; C1 and C2. */ | |
821 | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
822 #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
|
823 do { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
824 produced_chars += 2; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
825 if (multibytep) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
826 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
827 int ch; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
828 \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
829 ch = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
830 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
831 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
832 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
833 ch = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
834 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
835 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
836 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
837 } \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
838 else \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
839 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
840 *dst++ = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
841 *dst++ = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
842 } \ |
88365 | 843 } while (0) |
844 | |
845 | |
846 #define EMIT_THREE_BYTES(c1, c2, c3) \ | |
847 do { \ | |
848 EMIT_ONE_BYTE (c1); \ | |
849 EMIT_TWO_BYTES (c2, c3); \ | |
850 } while (0) | |
851 | |
852 | |
853 #define EMIT_FOUR_BYTES(c1, c2, c3, c4) \ | |
854 do { \ | |
855 EMIT_TWO_BYTES (c1, c2); \ | |
856 EMIT_TWO_BYTES (c3, c4); \ | |
857 } while (0) | |
858 | |
859 | |
860 #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ | |
861 do { \ | |
862 charset_map_loaded = 0; \ | |
863 c = DECODE_CHAR (charset, code); \ | |
864 if (charset_map_loaded) \ | |
865 { \ | |
866 unsigned char *orig = coding->source; \ | |
867 EMACS_INT offset; \ | |
868 \ | |
869 coding_set_source (coding); \ | |
870 offset = coding->source - orig; \ | |
871 src += offset; \ | |
872 src_base += offset; \ | |
873 src_end += offset; \ | |
874 } \ | |
875 } while (0) | |
876 | |
877 | |
878 #define ASSURE_DESTINATION(bytes) \ | |
879 do { \ | |
880 if (dst + (bytes) >= dst_end) \ | |
881 { \ | |
882 int more_bytes = charbuf_end - charbuf + (bytes); \ | |
883 \ | |
884 dst = alloc_destination (coding, more_bytes, dst); \ | |
885 dst_end = coding->destination + coding->dst_bytes; \ | |
886 } \ | |
887 } while (0) | |
888 | |
889 | |
890 | |
891 static void | |
892 coding_set_source (coding) | |
893 struct coding_system *coding; | |
894 { | |
895 if (BUFFERP (coding->src_object)) | |
896 { | |
897 if (coding->src_pos < 0) | |
898 coding->source = GAP_END_ADDR + coding->src_pos_byte; | |
899 else | |
900 { | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
901 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
|
902 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
|
903 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
|
904 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
905 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
|
906 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
|
907 coding->source += BUF_GAP_SIZE (buf); |
88365 | 908 } |
909 } | |
910 else if (STRINGP (coding->src_object)) | |
911 { | |
912 coding->source = (XSTRING (coding->src_object)->data | |
913 + coding->src_pos_byte); | |
914 } | |
915 else | |
916 /* Otherwise, the source is C string and is never relocated | |
917 automatically. Thus we don't have to update anything. */ | |
918 ; | |
919 } | |
920 | |
921 static void | |
922 coding_set_destination (coding) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
923 struct coding_system *coding; |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
924 { |
88365 | 925 if (BUFFERP (coding->dst_object)) |
926 { | |
927 if (coding->src_pos < 0) | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
928 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
929 coding->destination = BEG_ADDR + coding->dst_pos_byte - 1; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
930 coding->dst_bytes = (GAP_END_ADDR |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
931 - (coding->src_bytes - coding->consumed) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
932 - coding->destination); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
933 } |
88365 | 934 else |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
935 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
936 /* We are sure that coding->dst_pos_byte is before the gap |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
937 of the buffer. */ |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
938 coding->destination = (BUF_BEG_ADDR (XBUFFER (coding->dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
939 + coding->dst_pos_byte - 1); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
940 coding->dst_bytes = (BUF_GAP_END_ADDR (XBUFFER (coding->dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
941 - coding->destination); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
942 } |
88365 | 943 } |
944 else | |
945 /* Otherwise, the destination is C string and is never relocated | |
946 automatically. Thus we don't have to update anything. */ | |
947 ; | |
948 } | |
949 | |
950 | |
951 static void | |
952 coding_alloc_by_realloc (coding, bytes) | |
953 struct coding_system *coding; | |
954 EMACS_INT bytes; | |
955 { | |
956 coding->destination = (unsigned char *) xrealloc (coding->destination, | |
957 coding->dst_bytes + bytes); | |
958 coding->dst_bytes += bytes; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
959 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
960 |
88365 | 961 static void |
962 coding_alloc_by_making_gap (coding, bytes) | |
963 struct coding_system *coding; | |
964 EMACS_INT bytes; | |
965 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
966 if (BUFFERP (coding->dst_object) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
967 && EQ (coding->src_object, coding->dst_object)) |
88365 | 968 { |
969 EMACS_INT add = coding->src_bytes - coding->consumed; | |
970 | |
971 GAP_SIZE -= add; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add; | |
972 make_gap (bytes); | |
973 GAP_SIZE += add; ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add; | |
974 } | |
975 else | |
976 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
977 Lisp_Object this_buffer; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
978 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
979 this_buffer = Fcurrent_buffer (); |
88365 | 980 set_buffer_internal (XBUFFER (coding->dst_object)); |
981 make_gap (bytes); | |
982 set_buffer_internal (XBUFFER (this_buffer)); | |
983 } | |
984 } | |
985 | |
986 | |
987 static unsigned char * | |
988 alloc_destination (coding, nbytes, dst) | |
989 struct coding_system *coding; | |
990 int nbytes; | |
991 unsigned char *dst; | |
992 { | |
993 EMACS_INT offset = dst - coding->destination; | |
994 | |
995 if (BUFFERP (coding->dst_object)) | |
996 coding_alloc_by_making_gap (coding, nbytes); | |
997 else | |
998 coding_alloc_by_realloc (coding, nbytes); | |
999 coding->result = CODING_RESULT_SUCCESS; | |
1000 coding_set_destination (coding); | |
1001 dst = coding->destination + offset; | |
1002 return dst; | |
1003 } | |
1004 | |
1005 | |
1006 /*** 2. Emacs' internal format (emacs-utf-8) ***/ | |
1007 | |
1008 | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1009 |
17052 | 1010 |
88365 | 1011 /*** 3. UTF-8 ***/ |
1012 | |
1013 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
1014 Check if a text is encoded in UTF-8. If it is, return | |
1015 CATEGORY_MASK_UTF_8, else return 0. */ | |
1016 | |
1017 #define UTF_8_1_OCTET_P(c) ((c) < 0x80) | |
1018 #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80) | |
1019 #define UTF_8_2_OCTET_LEADING_P(c) (((c) & 0xE0) == 0xC0) | |
1020 #define UTF_8_3_OCTET_LEADING_P(c) (((c) & 0xF0) == 0xE0) | |
1021 #define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0) | |
1022 #define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8) | |
1023 | |
1024 static int | |
1025 detect_coding_utf_8 (coding, mask) | |
1026 struct coding_system *coding; | |
1027 int *mask; | |
1028 { | |
1029 unsigned char *src = coding->source, *src_base = src; | |
1030 unsigned char *src_end = coding->source + coding->src_bytes; | |
1031 int multibytep = coding->src_multibyte; | |
1032 int consumed_chars = 0; | |
1033 int found = 0; | |
1034 | |
1035 /* A coding system of this category is always ASCII compatible. */ | |
1036 src += coding->head_ascii; | |
1037 | |
1038 while (1) | |
1039 { | |
1040 int c, c1, c2, c3, c4; | |
1041 | |
1042 ONE_MORE_BYTE (c); | |
1043 if (UTF_8_1_OCTET_P (c)) | |
1044 continue; | |
1045 ONE_MORE_BYTE (c1); | |
1046 if (! UTF_8_EXTRA_OCTET_P (c1)) | |
1047 break; | |
1048 if (UTF_8_2_OCTET_LEADING_P (c)) | |
1049 { | |
1050 found++; | |
1051 continue; | |
1052 } | |
1053 ONE_MORE_BYTE (c2); | |
1054 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
1055 break; | |
1056 if (UTF_8_3_OCTET_LEADING_P (c)) | |
1057 { | |
1058 found++; | |
1059 continue; | |
1060 } | |
1061 ONE_MORE_BYTE (c3); | |
1062 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
1063 break; | |
1064 if (UTF_8_4_OCTET_LEADING_P (c)) | |
1065 { | |
1066 found++; | |
1067 continue; | |
1068 } | |
1069 ONE_MORE_BYTE (c4); | |
1070 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
1071 break; | |
1072 if (UTF_8_5_OCTET_LEADING_P (c)) | |
1073 { | |
1074 found++; | |
1075 continue; | |
1076 } | |
1077 break; | |
1078 } | |
1079 *mask &= ~CATEGORY_MASK_UTF_8; | |
1080 return 0; | |
1081 | |
1082 no_more_source: | |
1083 if (! found) | |
1084 return 0; | |
1085 *mask &= CATEGORY_MASK_UTF_8; | |
1086 return 1; | |
1087 } | |
1088 | |
1089 | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1090 /* Fixme: deal with surrogates? */ |
88365 | 1091 static void |
1092 decode_coding_utf_8 (coding) | |
1093 struct coding_system *coding; | |
1094 { | |
1095 unsigned char *src = coding->source + coding->consumed; | |
1096 unsigned char *src_end = coding->source + coding->src_bytes; | |
1097 unsigned char *src_base; | |
1098 int *charbuf = coding->charbuf; | |
1099 int *charbuf_end = charbuf + coding->charbuf_size; | |
1100 int consumed_chars = 0, consumed_chars_base; | |
1101 int multibytep = coding->src_multibyte; | |
1102 Lisp_Object attr, eol_type, charset_list; | |
1103 | |
1104 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
1105 | |
1106 while (1) | |
1107 { | |
1108 int c, c1, c2, c3, c4, c5; | |
1109 | |
1110 src_base = src; | |
1111 consumed_chars_base = consumed_chars; | |
1112 | |
1113 if (charbuf >= charbuf_end) | |
1114 break; | |
1115 | |
1116 ONE_MORE_BYTE (c1); | |
1117 if (UTF_8_1_OCTET_P(c1)) | |
1118 { | |
1119 c = c1; | |
1120 if (c == '\r') | |
1121 { | |
1122 if (EQ (eol_type, Qdos)) | |
1123 { | |
1124 if (src == src_end) | |
1125 goto no_more_source; | |
1126 if (*src == '\n') | |
1127 ONE_MORE_BYTE (c); | |
1128 } | |
1129 else if (EQ (eol_type, Qmac)) | |
1130 c = '\n'; | |
1131 } | |
1132 } | |
1133 else | |
1134 { | |
1135 ONE_MORE_BYTE (c2); | |
1136 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
1137 goto invalid_code; | |
1138 if (UTF_8_2_OCTET_LEADING_P (c1)) | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1139 { |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1140 c = ((c1 & 0x1F) << 6) | (c2 & 0x3F); |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1141 /* Reject overlong sequences here and below. Encoders |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1142 producing them are incorrect, they can be misleading, |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1143 and they mess up read/write invariance. */ |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1144 if (c < 128) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1145 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1146 } |
88365 | 1147 else |
1148 { | |
1149 ONE_MORE_BYTE (c3); | |
1150 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
1151 goto invalid_code; | |
1152 if (UTF_8_3_OCTET_LEADING_P (c1)) | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1153 { |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1154 c = (((c1 & 0xF) << 12) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1155 | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1156 if (c < 0x800) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1157 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1158 } |
88365 | 1159 else |
1160 { | |
1161 ONE_MORE_BYTE (c4); | |
1162 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
1163 goto invalid_code; | |
1164 if (UTF_8_4_OCTET_LEADING_P (c1)) | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1165 { |
88365 | 1166 c = (((c1 & 0x7) << 18) | ((c2 & 0x3F) << 12) |
1167 | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1168 if (c < 0x10000) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1169 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1170 } |
88365 | 1171 else |
1172 { | |
1173 ONE_MORE_BYTE (c5); | |
1174 if (! UTF_8_EXTRA_OCTET_P (c5)) | |
1175 goto invalid_code; | |
1176 if (UTF_8_5_OCTET_LEADING_P (c1)) | |
1177 { | |
1178 c = (((c1 & 0x3) << 24) | ((c2 & 0x3F) << 18) | |
1179 | ((c3 & 0x3F) << 12) | ((c4 & 0x3F) << 6) | |
1180 | (c5 & 0x3F)); | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1181 if ((c > MAX_CHAR) || (c < 0x200000)) |
88365 | 1182 goto invalid_code; |
1183 } | |
1184 else | |
1185 goto invalid_code; | |
1186 } | |
1187 } | |
1188 } | |
1189 } | |
1190 | |
1191 *charbuf++ = c; | |
1192 continue; | |
1193 | |
1194 invalid_code: | |
1195 src = src_base; | |
1196 consumed_chars = consumed_chars_base; | |
1197 ONE_MORE_BYTE (c); | |
1198 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
1199 coding->errors++; | |
1200 } | |
1201 | |
1202 no_more_source: | |
1203 coding->consumed_char += consumed_chars_base; | |
1204 coding->consumed = src_base - coding->source; | |
1205 coding->charbuf_used = charbuf - coding->charbuf; | |
1206 } | |
1207 | |
1208 | |
1209 static int | |
1210 encode_coding_utf_8 (coding) | |
1211 struct coding_system *coding; | |
1212 { | |
1213 int multibytep = coding->dst_multibyte; | |
1214 int *charbuf = coding->charbuf; | |
1215 int *charbuf_end = charbuf + coding->charbuf_used; | |
1216 unsigned char *dst = coding->destination + coding->produced; | |
1217 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
|
1218 int produced_chars = 0; |
88365 | 1219 int c; |
1220 | |
1221 if (multibytep) | |
1222 { | |
1223 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
1224 | |
1225 while (charbuf < charbuf_end) | |
1226 { | |
1227 unsigned char str[MAX_MULTIBYTE_LENGTH], *p, *pend = str; | |
1228 | |
1229 ASSURE_DESTINATION (safe_room); | |
1230 c = *charbuf++; | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1231 if (CHAR_BYTE8_P (c)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1232 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1233 c = CHAR_TO_BYTE8 (c); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1234 EMIT_ONE_BYTE (c); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1235 } |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1236 else |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1237 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1238 CHAR_STRING_ADVANCE (c, pend); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1239 for (p = str; p < pend; p++) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1240 EMIT_ONE_BYTE (*p); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1241 } |
88365 | 1242 } |
1243 } | |
1244 else | |
1245 { | |
1246 int safe_room = MAX_MULTIBYTE_LENGTH; | |
1247 | |
1248 while (charbuf < charbuf_end) | |
1249 { | |
1250 ASSURE_DESTINATION (safe_room); | |
1251 c = *charbuf++; | |
1252 dst += CHAR_STRING (c, dst); | |
1253 produced_chars++; | |
1254 } | |
1255 } | |
1256 coding->result = CODING_RESULT_SUCCESS; | |
1257 coding->produced_char += produced_chars; | |
1258 coding->produced = dst - coding->destination; | |
1259 return 0; | |
1260 } | |
1261 | |
1262 | |
1263 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
1264 Check if a text is encoded in UTF-16 Big Endian (endian == 1) or | |
1265 Little Endian (otherwise). If it is, return | |
1266 CATEGORY_MASK_UTF_16_BE or CATEGORY_MASK_UTF_16_LE, | |
1267 else return 0. */ | |
1268 | |
1269 #define UTF_16_HIGH_SURROGATE_P(val) \ | |
1270 (((val) & 0xFC00) == 0xD800) | |
1271 | |
1272 #define UTF_16_LOW_SURROGATE_P(val) \ | |
1273 (((val) & 0xFC00) == 0xDC00) | |
1274 | |
1275 #define UTF_16_INVALID_P(val) \ | |
1276 (((val) == 0xFFFE) \ | |
1277 || ((val) == 0xFFFF) \ | |
1278 || UTF_16_LOW_SURROGATE_P (val)) | |
1279 | |
1280 | |
1281 static int | |
1282 detect_coding_utf_16 (coding, mask) | |
1283 struct coding_system *coding; | |
1284 int *mask; | |
1285 { | |
1286 unsigned char *src = coding->source, *src_base = src; | |
1287 unsigned char *src_end = coding->source + coding->src_bytes; | |
1288 int multibytep = coding->src_multibyte; | |
1289 int consumed_chars = 0; | |
1290 int c1, c2; | |
1291 | |
1292 ONE_MORE_BYTE (c1); | |
1293 ONE_MORE_BYTE (c2); | |
1294 | |
1295 if ((c1 == 0xFF) && (c2 == 0xFE)) | |
1296 { | |
1297 *mask &= CATEGORY_MASK_UTF_16_LE; | |
1298 return 1; | |
1299 } | |
1300 else if ((c1 == 0xFE) && (c2 == 0xFF)) | |
1301 { | |
1302 *mask &= CATEGORY_MASK_UTF_16_BE; | |
1303 return 1; | |
1304 } | |
1305 no_more_source: | |
1306 return 0; | |
1307 } | |
1308 | |
1309 static void | |
1310 decode_coding_utf_16 (coding) | |
1311 struct coding_system *coding; | |
1312 { | |
1313 unsigned char *src = coding->source + coding->consumed; | |
1314 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
|
1315 unsigned char *src_base; |
88365 | 1316 int *charbuf = coding->charbuf; |
1317 int *charbuf_end = charbuf + coding->charbuf_size; | |
1318 int consumed_chars = 0, consumed_chars_base; | |
1319 int multibytep = coding->src_multibyte; | |
1320 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
1321 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); | |
1322 int surrogate = CODING_UTF_16_SURROGATE (coding); | |
1323 Lisp_Object attr, eol_type, charset_list; | |
1324 | |
1325 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
1326 | |
1327 if (bom != utf_16_without_bom) | |
1328 { | |
1329 int c, c1, c2; | |
1330 | |
1331 src_base = src; | |
1332 ONE_MORE_BYTE (c1); | |
1333 ONE_MORE_BYTE (c2); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1334 c = (c1 << 8) | c2; |
88365 | 1335 if (bom == utf_16_with_bom) |
1336 { | |
1337 if (endian == utf_16_big_endian | |
1338 ? c != 0xFFFE : c != 0xFEFF) | |
1339 { | |
1340 /* We are sure that there's enouph room at CHARBUF. */ | |
1341 *charbuf++ = c1; | |
1342 *charbuf++ = c2; | |
1343 coding->errors++; | |
1344 } | |
1345 } | |
1346 else | |
1347 { | |
1348 if (c == 0xFFFE) | |
1349 CODING_UTF_16_ENDIAN (coding) | |
1350 = endian = utf_16_big_endian; | |
1351 else if (c == 0xFEFF) | |
1352 CODING_UTF_16_ENDIAN (coding) | |
1353 = endian = utf_16_little_endian; | |
1354 else | |
1355 { | |
1356 CODING_UTF_16_ENDIAN (coding) | |
1357 = endian = utf_16_big_endian; | |
1358 src = src_base; | |
1359 } | |
1360 } | |
1361 CODING_UTF_16_BOM (coding) = utf_16_with_bom; | |
1362 } | |
1363 | |
1364 while (1) | |
1365 { | |
1366 int c, c1, c2; | |
1367 | |
1368 src_base = src; | |
1369 consumed_chars_base = consumed_chars; | |
1370 | |
1371 if (charbuf + 2 >= charbuf_end) | |
1372 break; | |
1373 | |
1374 ONE_MORE_BYTE (c1); | |
1375 ONE_MORE_BYTE (c2); | |
1376 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
|
1377 ? ((c1 << 8) | c2) : ((c2 << 8) | c1)); |
88365 | 1378 if (surrogate) |
1379 { | |
1380 if (! UTF_16_LOW_SURROGATE_P (c)) | |
1381 { | |
1382 if (endian == utf_16_big_endian) | |
1383 c1 = surrogate >> 8, c2 = surrogate & 0xFF; | |
1384 else | |
1385 c1 = surrogate & 0xFF, c2 = surrogate >> 8; | |
1386 *charbuf++ = c1; | |
1387 *charbuf++ = c2; | |
1388 coding->errors++; | |
1389 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1390 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1391 else | |
1392 *charbuf++ = c; | |
1393 } | |
1394 else | |
1395 { | |
1396 c = ((surrogate - 0xD800) << 10) | (c - 0xDC00); | |
1397 CODING_UTF_16_SURROGATE (coding) = surrogate = 0; | |
1398 *charbuf++ = c; | |
1399 } | |
1400 } | |
1401 else | |
1402 { | |
1403 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1404 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1405 else | |
1406 *charbuf++ = c; | |
1407 } | |
1408 } | |
1409 | |
1410 no_more_source: | |
1411 coding->consumed_char += consumed_chars_base; | |
1412 coding->consumed = src_base - coding->source; | |
1413 coding->charbuf_used = charbuf - coding->charbuf; | |
1414 } | |
1415 | |
1416 static int | |
1417 encode_coding_utf_16 (coding) | |
1418 struct coding_system *coding; | |
1419 { | |
1420 int multibytep = coding->dst_multibyte; | |
1421 int *charbuf = coding->charbuf; | |
1422 int *charbuf_end = charbuf + coding->charbuf_used; | |
1423 unsigned char *dst = coding->destination + coding->produced; | |
1424 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
1425 int safe_room = 8; | |
1426 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
1427 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; | |
1428 int produced_chars = 0; | |
1429 Lisp_Object attrs, eol_type, charset_list; | |
1430 int c; | |
1431 | |
1432 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1433 | |
1434 if (bom == utf_16_with_bom) | |
1435 { | |
1436 ASSURE_DESTINATION (safe_room); | |
1437 if (big_endian) | |
1438 EMIT_TWO_BYTES (0xFF, 0xFE); | |
1439 else | |
1440 EMIT_TWO_BYTES (0xFE, 0xFF); | |
1441 CODING_UTF_16_BOM (coding) = utf_16_without_bom; | |
1442 } | |
1443 | |
1444 while (charbuf < charbuf_end) | |
1445 { | |
1446 ASSURE_DESTINATION (safe_room); | |
1447 c = *charbuf++; | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1448 if (c >= MAX_UNICODE_CHAR) |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1449 c = coding->default_char; |
88365 | 1450 |
1451 if (c < 0x10000) | |
1452 { | |
1453 if (big_endian) | |
1454 EMIT_TWO_BYTES (c >> 8, c & 0xFF); | |
1455 else | |
1456 EMIT_TWO_BYTES (c & 0xFF, c >> 8); | |
1457 } | |
1458 else | |
1459 { | |
1460 int c1, c2; | |
1461 | |
1462 c -= 0x10000; | |
1463 c1 = (c >> 10) + 0xD800; | |
1464 c2 = (c & 0x3FF) + 0xDC00; | |
1465 if (big_endian) | |
1466 EMIT_FOUR_BYTES (c1 >> 8, c1 & 0xFF, c2 >> 8, c2 & 0xFF); | |
1467 else | |
1468 EMIT_FOUR_BYTES (c1 & 0xFF, c1 >> 8, c2 & 0xFF, c2 >> 8); | |
1469 } | |
1470 } | |
1471 coding->result = CODING_RESULT_SUCCESS; | |
1472 coding->produced = dst - coding->destination; | |
1473 coding->produced_char += produced_chars; | |
1474 return 0; | |
1475 } | |
1476 | |
1477 | |
1478 /*** 6. Old Emacs' internal format (emacs-mule) ***/ | |
17052 | 1479 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1480 /* Emacs' internal format for representation of multiple character |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1481 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
|
1482 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
|
1483 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1484 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
|
1485 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
|
1486 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
|
1487 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1488 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
|
1489 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
|
1490 code + 0x20). |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1491 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1492 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
|
1493 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
|
1494 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1495 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
|
1496 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
|
1497 `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
|
1498 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
|
1499 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
|
1500 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
|
1501 and position-code. |
18766 | 1502 |
17052 | 1503 --- 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
|
1504 character set range |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1505 ------------- ----- |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1506 ascii 0x00..0x7F |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1507 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
|
1508 eight-bit-graphic 0xA0..0xBF |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1509 ELSE 0x81..0x9D + [0xA0..0xFF]+ |
17052 | 1510 --------------------------------------------- |
1511 | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1512 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
|
1513 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
|
1514 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
|
1515 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
|
1516 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1517 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
|
1518 form. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1519 |
88365 | 1520 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
|
1521 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
|
1522 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1523 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
|
1524 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
|
1525 where, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1526 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
|
1527 composition_method), |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1528 |
88365 | 1529 BYTES is 0xA0 plus a byte length of this composition data, |
1530 | |
1531 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
|
1532 data, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1533 |
88365 | 1534 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
|
1535 rules encoded by two-byte of ASCII codes. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1536 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1537 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
|
1538 also recognized as composition data on decoding. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1539 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1540 0x80 MSEQ ... |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1541 0x80 0xFF MSEQ RULE MSEQ RULE ... MSEQ |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1542 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1543 Here, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1544 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
|
1545 ASCII: 0xA0 ASCII_CODE+0x80, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1546 other: LEADING_CODE+0x20 FOLLOWING-BYTE ..., |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1547 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
|
1548 represents a composition rule. |
17052 | 1549 */ |
1550 | |
88365 | 1551 char emacs_mule_bytes[256]; |
1552 | |
1553 int | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1554 emacs_mule_char (coding, src, nbytes, nchars) |
88365 | 1555 struct coding_system *coding; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1556 unsigned char *src; |
88365 | 1557 int *nbytes, *nchars; |
1558 { | |
1559 unsigned char *src_end = coding->source + coding->src_bytes; | |
1560 int multibytep = coding->src_multibyte; | |
1561 unsigned char *src_base = src; | |
1562 struct charset *charset; | |
1563 unsigned code; | |
1564 int c; | |
1565 int consumed_chars = 0; | |
1566 | |
1567 ONE_MORE_BYTE (c); | |
1568 switch (emacs_mule_bytes[c]) | |
1569 { | |
1570 case 2: | |
1571 if (! (charset = emacs_mule_charset[c])) | |
1572 goto invalid_code; | |
1573 ONE_MORE_BYTE (c); | |
1574 code = c & 0x7F; | |
1575 break; | |
1576 | |
1577 case 3: | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
1578 if (c == EMACS_MULE_LEADING_CODE_PRIVATE_11 |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
1579 || c == EMACS_MULE_LEADING_CODE_PRIVATE_12) |
88365 | 1580 { |
1581 ONE_MORE_BYTE (c); | |
1582 if (! (charset = emacs_mule_charset[c])) | |
1583 goto invalid_code; | |
1584 ONE_MORE_BYTE (c); | |
1585 code = c & 0x7F; | |
1586 } | |
1587 else | |
1588 { | |
1589 if (! (charset = emacs_mule_charset[c])) | |
1590 goto invalid_code; | |
1591 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1592 code = (c & 0x7F) << 8; |
88365 | 1593 ONE_MORE_BYTE (c); |
1594 code |= c & 0x7F; | |
1595 } | |
1596 break; | |
1597 | |
1598 case 4: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1599 ONE_MORE_BYTE (c); |
88365 | 1600 if (! (charset = emacs_mule_charset[c])) |
1601 goto invalid_code; | |
1602 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1603 code = (c & 0x7F) << 8; |
88365 | 1604 ONE_MORE_BYTE (c); |
1605 code |= c & 0x7F; | |
1606 break; | |
1607 | |
1608 case 1: | |
1609 code = c; | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
1610 charset = CHARSET_FROM_ID (ASCII_BYTE_P (code) |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
1611 ? charset_ascii : charset_eight_bit); |
88365 | 1612 break; |
1613 | |
1614 default: | |
1615 abort (); | |
1616 } | |
1617 c = DECODE_CHAR (charset, code); | |
1618 if (c < 0) | |
1619 goto invalid_code; | |
1620 *nbytes = src - src_base; | |
1621 *nchars = consumed_chars; | |
1622 return c; | |
1623 | |
1624 no_more_source: | |
1625 return -2; | |
1626 | |
1627 invalid_code: | |
1628 return -1; | |
1629 } | |
1630 | |
17052 | 1631 |
1632 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
88365 | 1633 Check if a text is encoded in `emacs-mule'. */ |
17052 | 1634 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
1635 static int |
88365 | 1636 detect_coding_emacs_mule (coding, mask) |
1637 struct coding_system *coding; | |
1638 int *mask; | |
17052 | 1639 { |
88365 | 1640 unsigned char *src = coding->source, *src_base = src; |
1641 unsigned char *src_end = coding->source + coding->src_bytes; | |
1642 int multibytep = coding->src_multibyte; | |
1643 int consumed_chars = 0; | |
1644 int c; | |
1645 int found = 0; | |
1646 | |
1647 /* A coding system of this category is always ASCII compatible. */ | |
1648 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
|
1649 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1650 while (1) |
17052 | 1651 { |
88365 | 1652 ONE_MORE_BYTE (c); |
1653 | |
1654 if (c == 0x80) | |
17052 | 1655 { |
88365 | 1656 /* Perhaps the start of composite character. We simple skip |
1657 it because analyzing it is too heavy for detecting. But, | |
1658 at least, we check that the composite character | |
1659 constitues of more than 4 bytes. */ | |
1660 unsigned char *src_base; | |
1661 | |
1662 repeat: | |
1663 src_base = src; | |
1664 do | |
1665 { | |
1666 ONE_MORE_BYTE (c); | |
1667 } | |
1668 while (c >= 0xA0); | |
1669 | |
1670 if (src - src_base <= 4) | |
1671 break; | |
1672 found = 1; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1673 if (c == 0x80) |
88365 | 1674 goto repeat; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1675 } |
88365 | 1676 |
1677 if (c < 0x80) | |
1678 { | |
1679 if (c < 0x20 | |
1680 && (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)) | |
1681 break; | |
1682 } | |
1683 else | |
1684 { | |
1685 unsigned char *src_base = src - 1; | |
1686 | |
1687 do | |
1688 { | |
1689 ONE_MORE_BYTE (c); | |
1690 } | |
1691 while (c >= 0xA0); | |
1692 if (src - src_base != emacs_mule_bytes[*src_base]) | |
1693 break; | |
1694 found = 1; | |
1695 } | |
1696 } | |
1697 *mask &= ~CATEGORY_MASK_EMACS_MULE; | |
1698 return 0; | |
1699 | |
1700 no_more_source: | |
1701 if (!found) | |
1702 return 0; | |
1703 *mask &= CATEGORY_MASK_EMACS_MULE; | |
1704 return 1; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1705 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1706 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1707 |
88365 | 1708 /* 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
|
1709 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1710 /* Decode a character represented as a component of composition |
88365 | 1711 sequence of Emacs 20/21 style at SRC. Set C to that character and |
1712 update SRC to the head of next character (or an encoded composition | |
1713 rule). If SRC doesn't points a composition component, set C to -1. | |
1714 If SRC points an invalid byte sequence, global exit by a return | |
1715 value 0. */ | |
1716 | |
1717 #define DECODE_EMACS_MULE_COMPOSITION_CHAR(buf) \ | |
1718 if (1) \ | |
1719 { \ | |
1720 int c; \ | |
1721 int nbytes, nchars; \ | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1722 \ |
88365 | 1723 if (src == src_end) \ |
1724 break; \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1725 c = emacs_mule_char (coding, src, &nbytes, &nchars); \ |
88365 | 1726 if (c < 0) \ |
1727 { \ | |
1728 if (c == -2) \ | |
1729 break; \ | |
1730 goto invalid_code; \ | |
1731 } \ | |
1732 *buf++ = c; \ | |
1733 src += nbytes; \ | |
1734 consumed_chars += nchars; \ | |
1735 } \ | |
1736 else | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1737 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1738 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1739 /* 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
|
1740 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
|
1741 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
|
1742 to -1. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1743 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1744 #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
|
1745 do { \ |
88365 | 1746 int c, gref, nref; \ |
1747 \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1748 if (src >= src_end) \ |
88365 | 1749 goto invalid_code; \ |
1750 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
|
1751 c -= 0x20; \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1752 if (c < 0 || c >= 81) \ |
88365 | 1753 goto invalid_code; \ |
1754 \ | |
1755 gref = c / 9, nref = c % 9; \ | |
1756 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ | |
1757 } while (0) | |
1758 | |
1759 | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1760 /* 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
|
1761 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
|
1762 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
|
1763 to -1. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1764 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1765 #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
|
1766 do { \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1767 int gref, nref; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1768 \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1769 if (src + 1>= src_end) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1770 goto invalid_code; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1771 ONE_MORE_BYTE_NO_CHECK (gref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1772 gref -= 0x20; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1773 ONE_MORE_BYTE_NO_CHECK (nref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1774 nref -= 0x20; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1775 if (gref < 0 || gref >= 81 \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1776 || nref < 0 || nref >= 81) \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1777 goto invalid_code; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1778 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1779 } while (0) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1780 |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1781 |
88365 | 1782 #define ADD_COMPOSITION_DATA(buf, method, nchars) \ |
1783 do { \ | |
1784 *buf++ = -5; \ | |
1785 *buf++ = coding->produced_char + char_offset; \ | |
1786 *buf++ = CODING_ANNOTATE_COMPOSITION_MASK; \ | |
1787 *buf++ = method; \ | |
1788 *buf++ = nchars; \ | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1789 } while (0) |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1790 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1791 |
88365 | 1792 #define DECODE_EMACS_MULE_21_COMPOSITION(c) \ |
1793 do { \ | |
1794 /* 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
|
1795 (METHOD - 0xF2), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is \ |
88365 | 1796 the byte length of this composition information, CHARS is the \ |
1797 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
|
1798 enum composition_method method = c - 0xF2; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1799 int *charbuf_base = charbuf; \ |
88365 | 1800 int consumed_chars_limit; \ |
1801 int nbytes, nchars; \ | |
1802 \ | |
1803 ONE_MORE_BYTE (c); \ | |
1804 nbytes = c - 0xA0; \ | |
1805 if (nbytes < 3) \ | |
1806 goto invalid_code; \ | |
1807 ONE_MORE_BYTE (c); \ | |
1808 nchars = c - 0xA0; \ | |
1809 ADD_COMPOSITION_DATA (charbuf, method, nchars); \ | |
1810 consumed_chars_limit = consumed_chars_base + nbytes; \ | |
1811 if (method != COMPOSITION_RELATIVE) \ | |
1812 { \ | |
1813 int i = 0; \ | |
1814 while (consumed_chars < consumed_chars_limit) \ | |
1815 { \ | |
1816 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
|
1817 DECODE_EMACS_MULE_COMPOSITION_RULE_21 (charbuf); \ |
88365 | 1818 else \ |
1819 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
|
1820 i++; \ |
88365 | 1821 } \ |
1822 if (consumed_chars < consumed_chars_limit) \ | |
1823 goto invalid_code; \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1824 charbuf_base[0] -= i; \ |
88365 | 1825 } \ |
1826 } while (0) | |
1827 | |
1828 | |
1829 #define DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION(c) \ | |
1830 do { \ | |
1831 /* Emacs 20 style format for relative composition. */ \ | |
1832 /* Store multibyte form of characters to be composed. */ \ | |
1833 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ | |
1834 int *buf = components; \ | |
1835 int i, j; \ | |
1836 \ | |
1837 src = src_base; \ | |
1838 ONE_MORE_BYTE (c); /* skip 0x80 */ \ | |
1839 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
1840 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
1841 if (i < 2) \ | |
1842 goto invalid_code; \ | |
1843 ADD_COMPOSITION_DATA (charbuf, COMPOSITION_RELATIVE, i); \ | |
1844 for (j = 0; j < i; j++) \ | |
1845 *charbuf++ = components[j]; \ | |
1846 } while (0) | |
1847 | |
1848 | |
1849 #define DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION(c) \ | |
1850 do { \ | |
1851 /* Emacs 20 style format for rule-base composition. */ \ | |
1852 /* Store multibyte form of characters to be composed. */ \ | |
1853 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ | |
1854 int *buf = components; \ | |
1855 int i, j; \ | |
1856 \ | |
1857 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
1858 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
1859 { \ | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1860 DECODE_EMACS_MULE_COMPOSITION_RULE_20 (buf); \ |
88365 | 1861 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ |
1862 } \ | |
1863 if (i < 1 || (buf - components) % 2 == 0) \ | |
1864 goto invalid_code; \ | |
1865 if (charbuf + i + (i / 2) + 1 < charbuf_end) \ | |
1866 goto no_more_source; \ | |
1867 ADD_COMPOSITION_DATA (buf, COMPOSITION_WITH_RULE, i); \ | |
1868 for (j = 0; j < i; j++) \ | |
1869 *charbuf++ = components[j]; \ | |
1870 for (j = 0; j < i; j += 2) \ | |
1871 *charbuf++ = components[j]; \ | |
1872 } while (0) | |
1873 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1874 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1875 static void |
88365 | 1876 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
|
1877 struct coding_system *coding; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1878 { |
88365 | 1879 unsigned char *src = coding->source + coding->consumed; |
1880 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
|
1881 unsigned char *src_base; |
88365 | 1882 int *charbuf = coding->charbuf; |
1883 int *charbuf_end = charbuf + coding->charbuf_size; | |
1884 int consumed_chars = 0, consumed_chars_base; | |
1885 int char_offset = 0; | |
1886 int multibytep = coding->src_multibyte; | |
1887 Lisp_Object attrs, eol_type, charset_list; | |
1888 | |
1889 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
1890 | |
1891 while (1) | |
1892 { | |
1893 int c; | |
1894 | |
1895 src_base = src; | |
1896 consumed_chars_base = consumed_chars; | |
1897 | |
1898 if (charbuf >= charbuf_end) | |
1899 break; | |
1900 | |
1901 ONE_MORE_BYTE (c); | |
1902 | |
1903 if (c < 0x80) | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1904 { |
88365 | 1905 if (c == '\r') |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1906 { |
88365 | 1907 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
|
1908 { |
88365 | 1909 if (src == src_end) |
1910 goto no_more_source; | |
1911 if (*src == '\n') | |
1912 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
|
1913 } |
88365 | 1914 else if (EQ (eol_type, Qmac)) |
1915 c = '\n'; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1916 } |
88365 | 1917 *charbuf++ = c; |
1918 char_offset++; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1919 } |
88365 | 1920 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
|
1921 { |
88365 | 1922 if (charbuf + 5 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 > charbuf_end) |
1923 break; | |
1924 ONE_MORE_BYTE (c); | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1925 if (c - 0xF2 >= COMPOSITION_RELATIVE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1926 && c - 0xF2 <= COMPOSITION_WITH_RULE_ALTCHARS) |
88365 | 1927 DECODE_EMACS_MULE_21_COMPOSITION (c); |
1928 else if (c < 0xC0) | |
1929 DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION (c); | |
1930 else if (c == 0xFF) | |
1931 DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION (c); | |
1932 else | |
1933 goto invalid_code; | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1934 coding->annotated = 1; |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1935 } |
88365 | 1936 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
|
1937 { |
88365 | 1938 int nbytes, nchars; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1939 src = src_base; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1940 consumed_chars = consumed_chars_base; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1941 c = emacs_mule_char (coding, src, &nbytes, &nchars); |
88365 | 1942 if (c < 0) |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1943 { |
88365 | 1944 if (c == -2) |
1945 break; | |
1946 goto invalid_code; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1947 } |
88365 | 1948 *charbuf++ = c; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1949 src += nbytes; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1950 consumed_chars += nchars; |
88365 | 1951 char_offset++; |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1952 } |
88365 | 1953 continue; |
1954 | |
1955 invalid_code: | |
1956 src = src_base; | |
1957 consumed_chars = consumed_chars_base; | |
1958 ONE_MORE_BYTE (c); | |
1959 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
1960 coding->errors++; | |
1961 } | |
1962 | |
1963 no_more_source: | |
1964 coding->consumed_char += consumed_chars_base; | |
1965 coding->consumed = src_base - coding->source; | |
1966 coding->charbuf_used = charbuf - coding->charbuf; | |
1967 } | |
1968 | |
1969 | |
1970 #define EMACS_MULE_LEADING_CODES(id, codes) \ | |
1971 do { \ | |
1972 if (id < 0xA0) \ | |
1973 codes[0] = id, codes[1] = 0; \ | |
1974 else if (id < 0xE0) \ | |
1975 codes[0] = 0x9A, codes[1] = id; \ | |
1976 else if (id < 0xF0) \ | |
1977 codes[0] = 0x9B, codes[1] = id; \ | |
1978 else if (id < 0xF5) \ | |
1979 codes[0] = 0x9C, codes[1] = id; \ | |
1980 else \ | |
1981 codes[0] = 0x9D, codes[1] = id; \ | |
1982 } while (0); | |
1983 | |
1984 | |
1985 static int | |
1986 encode_coding_emacs_mule (coding) | |
1987 struct coding_system *coding; | |
1988 { | |
1989 int multibytep = coding->dst_multibyte; | |
1990 int *charbuf = coding->charbuf; | |
1991 int *charbuf_end = charbuf + coding->charbuf_used; | |
1992 unsigned char *dst = coding->destination + coding->produced; | |
1993 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
1994 int safe_room = 8; | |
1995 int produced_chars = 0; | |
1996 Lisp_Object attrs, eol_type, charset_list; | |
1997 int c; | |
1998 | |
1999 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
2000 | |
2001 while (charbuf < charbuf_end) | |
2002 { | |
2003 ASSURE_DESTINATION (safe_room); | |
2004 c = *charbuf++; | |
2005 if (ASCII_CHAR_P (c)) | |
2006 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2007 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2008 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2009 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2010 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2011 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2012 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2013 { |
88365 | 2014 struct charset *charset; |
2015 unsigned code; | |
2016 int dimension; | |
2017 int emacs_mule_id; | |
2018 unsigned char leading_codes[2]; | |
2019 | |
2020 charset = char_charset (c, charset_list, &code); | |
2021 if (! charset) | |
2022 { | |
2023 c = coding->default_char; | |
2024 if (ASCII_CHAR_P (c)) | |
2025 { | |
2026 EMIT_ONE_ASCII_BYTE (c); | |
2027 continue; | |
2028 } | |
2029 charset = char_charset (c, charset_list, &code); | |
2030 } | |
2031 dimension = CHARSET_DIMENSION (charset); | |
2032 emacs_mule_id = CHARSET_EMACS_MULE_ID (charset); | |
2033 EMACS_MULE_LEADING_CODES (emacs_mule_id, leading_codes); | |
2034 EMIT_ONE_BYTE (leading_codes[0]); | |
2035 if (leading_codes[1]) | |
2036 EMIT_ONE_BYTE (leading_codes[1]); | |
2037 if (dimension == 1) | |
2038 EMIT_ONE_BYTE (code); | |
2039 else | |
2040 { | |
2041 EMIT_ONE_BYTE (code >> 8); | |
2042 EMIT_ONE_BYTE (code & 0xFF); | |
2043 } | |
17052 | 2044 } |
88365 | 2045 } |
2046 coding->result = CODING_RESULT_SUCCESS; | |
2047 coding->produced_char += produced_chars; | |
2048 coding->produced = dst - coding->destination; | |
2049 return 0; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2050 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2051 |
17052 | 2052 |
88365 | 2053 /*** 7. ISO2022 handlers ***/ |
17052 | 2054 |
2055 /* 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
|
2056 Since the intention of this note is to help understand the |
88771 | 2057 functions in this file, some parts are NOT ACCURATE or are OVERLY |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2058 SIMPLIFIED. For thorough understanding, please refer to the |
88771 | 2059 original document of ISO2022. This is equivalent to the standard |
2060 ECMA-35, obtainable from <URL:http://www.ecma.ch/> (*). | |
17052 | 2061 |
2062 ISO2022 provides many mechanisms to encode several character sets | |
88771 | 2063 in 7-bit and 8-bit environments. For 7-bit environments, all text |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2064 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
|
2065 text a little bit longer, but the text passes more easily through |
88771 | 2066 several types of gateway, some of which strip off the MSB (Most |
2067 Significant Bit). | |
2068 | |
2069 There are two kinds of character sets: control character sets and | |
2070 graphic character sets. The former contain control characters such | |
17052 | 2071 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
|
2072 functions are also provided by escape sequences). The latter |
88771 | 2073 contain graphic characters such as 'A' and '-'. Emacs recognizes |
17052 | 2074 two control character sets and many graphic character sets. |
2075 | |
2076 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
|
2077 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
|
2078 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
|
2079 - DIMENSION1_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2080 - DIMENSION1_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2081 - DIMENSION2_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2082 - DIMENSION2_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2083 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2084 In addition, each character set is assigned an identification tag, |
88771 | 2085 unique for each set, called the "final character" (denoted as <F> |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2086 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
|
2087 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
|
2088 (0x30..0x3F are for private use only). |
17052 | 2089 |
2090 Note (*): ECMA = European Computer Manufacturers Association | |
2091 | |
88771 | 2092 Here are examples of graphic character sets [NAME(<F>)]: |
17052 | 2093 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ... |
2094 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ... | |
2095 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ... | |
2096 o DIMENSION2_CHARS96 -- none for the moment | |
2097 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2098 A code area (1 byte=8 bits) is divided into 4 areas, C0, GL, C1, and GR. |
17052 | 2099 C0 [0x00..0x1F] -- control character plane 0 |
2100 GL [0x20..0x7F] -- graphic character plane 0 | |
2101 C1 [0x80..0x9F] -- control character plane 1 | |
2102 GR [0xA0..0xFF] -- graphic character plane 1 | |
2103 | |
2104 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
|
2105 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
|
2106 - 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
|
2107 - 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
|
2108 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
|
2109 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
|
2110 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
|
2111 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
|
2112 defined to have corresponding escape sequences. |
17052 | 2113 |
2114 A graphic character set is at first designated to one of four | |
2115 graphic registers (G0 through G3), then these graphic registers are | |
2116 invoked to GL or GR. These designations and invocations can be | |
2117 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
|
2118 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
|
2119 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
|
2120 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
|
2121 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2122 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
|
2123 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
|
2124 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
|
2125 be used. |
17052 | 2126 |
2127 There are two ways of invocation: locking-shift and single-shift. | |
2128 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
|
2129 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
|
2130 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
|
2131 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
|
2132 escape sequences: |
17052 | 2133 |
2134 ---------------------------------------------------------------------- | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2135 abbrev function cntrl escape seq description |
17052 | 2136 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2137 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
|
2138 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
|
2139 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
|
2140 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
|
2141 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
|
2142 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
|
2143 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
|
2144 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
|
2145 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char |
17052 | 2146 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2147 (*) 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
|
2148 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2149 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
|
2150 ISO_CODE_XXX in `coding.h'. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2151 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2152 Designations are done by the following escape sequences: |
17052 | 2153 ---------------------------------------------------------------------- |
2154 escape sequence description | |
2155 ---------------------------------------------------------------------- | |
2156 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0 | |
2157 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1 | |
2158 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2 | |
2159 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3 | |
2160 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*) | |
2161 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1 | |
2162 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2 | |
2163 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3 | |
2164 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**) | |
2165 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1 | |
2166 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2 | |
2167 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3 | |
2168 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*) | |
2169 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1 | |
2170 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2 | |
2171 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3 | |
2172 ---------------------------------------------------------------------- | |
2173 | |
2174 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
|
2175 of dimension 1, chars 94, and final character <F>, etc... |
17052 | 2176 |
2177 Note (*): Although these designations are not allowed in ISO2022, | |
2178 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
|
2179 CHARS96 character sets in a coding system which is characterized as |
17052 | 2180 7-bit environment, non-locking-shift, and non-single-shift. |
2181 | |
2182 Note (**): If <F> is '@', 'A', or 'B', the intermediate character | |
88365 | 2183 '(' must be omitted. We refer to this as "short-form" hereafter. |
2184 | |
88771 | 2185 Now you may notice that there are a lot of ways of encoding the |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2186 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
|
2187 coding systems such as Compound Text (used in X11's inter client |
88771 | 2188 communication, ISO-2022-JP (used in Japanese Internet), ISO-2022-KR |
2189 (used in Korean Internet), EUC (Extended UNIX Code, used in Asian | |
17052 | 2190 localized platforms), and all of these are variants of ISO2022. |
2191 | |
2192 In addition to the above, Emacs handles two more kinds of escape | |
2193 sequences: ISO6429's direction specification and Emacs' private | |
2194 sequence for specifying character composition. | |
2195 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2196 ISO6429's direction specification takes the following form: |
17052 | 2197 o CSI ']' -- end of the current direction |
2198 o CSI '0' ']' -- end of the current direction | |
2199 o CSI '1' ']' -- start of left-to-right text | |
2200 o CSI '2' ']' -- start of right-to-left text | |
2201 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
|
2202 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
|
2203 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2204 Character composition specification takes the following form: |
26847 | 2205 o ESC '0' -- start relative composition |
2206 o ESC '1' -- end composition | |
2207 o ESC '2' -- start rule-base composition (*) | |
2208 o ESC '3' -- start relative composition with alternate chars (**) | |
2209 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
|
2210 Since these are not standard escape sequences of any ISO standard, |
88771 | 2211 the use of them with these meanings is restricted to Emacs only. |
2212 | |
2213 (*) This form is used only in Emacs 20.7 and older versions, | |
2214 but newer versions can safely decode it. | |
2215 (**) This form is used only in Emacs 21.1 and newer versions, | |
2216 and older versions can't decode it. | |
2217 | |
2218 Here's a list of example usages of these composition escape | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2219 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
|
2220 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2221 COMPOSITION_RELATIVE: |
26847 | 2222 ESC 0 CHAR [ CHAR ] ESC 1 |
88771 | 2223 COMPOSITION_WITH_RULE: |
26847 | 2224 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
|
2225 COMPOSITION_WITH_ALTCHARS: |
26847 | 2226 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
|
2227 COMPOSITION_WITH_RULE_ALTCHARS: |
26847 | 2228 ESC 4 ALTCHAR [ RULE ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 */ |
17052 | 2229 |
2230 enum iso_code_class_type iso_code_class[256]; | |
2231 | |
88365 | 2232 #define SAFE_CHARSET_P(coding, id) \ |
2233 ((id) <= (coding)->max_charset_id \ | |
2234 && (coding)->safe_charsets[id] >= 0) | |
2235 | |
2236 | |
2237 #define SHIFT_OUT_OK(category) \ | |
2238 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0) | |
2239 | |
2240 static void | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2241 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
|
2242 Lisp_Object attrs; |
88365 | 2243 { |
2244 Lisp_Object charset_list, safe_charsets; | |
2245 Lisp_Object request; | |
2246 Lisp_Object reg_usage; | |
2247 Lisp_Object tail; | |
2248 int reg94, reg96; | |
2249 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
2250 int max_charset_id; | |
2251 | |
2252 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
2253 if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) | |
2254 && ! EQ (charset_list, Viso_2022_charset_list)) | |
2255 { | |
2256 CODING_ATTR_CHARSET_LIST (attrs) | |
2257 = charset_list = Viso_2022_charset_list; | |
2258 ASET (attrs, coding_attr_safe_charsets, Qnil); | |
2259 } | |
2260 | |
2261 if (STRINGP (AREF (attrs, coding_attr_safe_charsets))) | |
2262 return; | |
2263 | |
2264 max_charset_id = 0; | |
2265 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2266 { | |
2267 int id = XINT (XCAR (tail)); | |
2268 if (max_charset_id < id) | |
2269 max_charset_id = id; | |
2270 } | |
2271 | |
2272 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
2273 make_number (255)); | |
2274 request = AREF (attrs, coding_attr_iso_request); | |
2275 reg_usage = AREF (attrs, coding_attr_iso_usage); | |
2276 reg94 = XINT (XCAR (reg_usage)); | |
2277 reg96 = XINT (XCDR (reg_usage)); | |
2278 | |
2279 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
2280 { | |
2281 Lisp_Object id; | |
2282 Lisp_Object reg; | |
2283 struct charset *charset; | |
2284 | |
2285 id = XCAR (tail); | |
2286 charset = CHARSET_FROM_ID (XINT (id)); | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2287 reg = Fcdr (Fassq (id, request)); |
88365 | 2288 if (! NILP (reg)) |
2289 XSTRING (safe_charsets)->data[XINT (id)] = XINT (reg); | |
2290 else if (charset->iso_chars_96) | |
2291 { | |
2292 if (reg96 < 4) | |
2293 XSTRING (safe_charsets)->data[XINT (id)] = reg96; | |
2294 } | |
2295 else | |
2296 { | |
2297 if (reg94 < 4) | |
2298 XSTRING (safe_charsets)->data[XINT (id)] = reg94; | |
2299 } | |
2300 } | |
2301 ASET (attrs, coding_attr_safe_charsets, safe_charsets); | |
2302 } | |
2303 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2304 |
17052 | 2305 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
88365 | 2306 Check if a text is encoded in ISO2022. If it is, returns an |
17052 | 2307 integer in which appropriate flag bits any of: |
88365 | 2308 CATEGORY_MASK_ISO_7 |
2309 CATEGORY_MASK_ISO_7_TIGHT | |
2310 CATEGORY_MASK_ISO_8_1 | |
2311 CATEGORY_MASK_ISO_8_2 | |
2312 CATEGORY_MASK_ISO_7_ELSE | |
2313 CATEGORY_MASK_ISO_8_ELSE | |
17052 | 2314 are set. If a code which should never appear in ISO2022 is found, |
2315 returns 0. */ | |
2316 | |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
2317 static int |
88365 | 2318 detect_coding_iso_2022 (coding, mask) |
2319 struct coding_system *coding; | |
2320 int *mask; | |
17052 | 2321 { |
88365 | 2322 unsigned char *src = coding->source, *src_base = src; |
2323 unsigned char *src_end = coding->source + coding->src_bytes; | |
2324 int multibytep = coding->src_multibyte; | |
2325 int mask_iso = CATEGORY_MASK_ISO; | |
2326 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
|
2327 int reg[4], shift_out = 0, single_shifting = 0; |
88365 | 2328 int id; |
2329 int c, c1; | |
2330 int consumed_chars = 0; | |
2331 int i; | |
2332 | |
2333 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | |
2334 { | |
2335 struct coding_system *this = &(coding_categories[i]); | |
2336 Lisp_Object attrs, val; | |
2337 | |
2338 attrs = CODING_ID_ATTRS (this->id); | |
2339 if (CODING_ISO_FLAGS (this) & CODING_ISO_FLAG_FULL_SUPPORT | |
2340 && ! EQ (CODING_ATTR_SAFE_CHARSETS (attrs), Viso_2022_charset_list)) | |
2341 setup_iso_safe_charsets (attrs); | |
2342 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
2343 this->max_charset_id = XSTRING (val)->size - 1; | |
2344 this->safe_charsets = (char *) XSTRING (val)->data; | |
2345 } | |
2346 | |
2347 /* A coding system of this category is always ASCII compatible. */ | |
2348 src += coding->head_ascii; | |
2349 | |
2350 reg[0] = charset_ascii, reg[1] = reg[2] = reg[3] = -1; | |
2351 while (mask_iso && src < src_end) | |
2352 { | |
2353 ONE_MORE_BYTE (c); | |
17052 | 2354 switch (c) |
2355 { | |
2356 case ISO_CODE_ESC: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2357 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2358 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2359 single_shifting = 0; |
88365 | 2360 ONE_MORE_BYTE (c); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2361 if (c >= '(' && c <= '/') |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2362 { |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2363 /* Designation sequence for a charset of dimension 1. */ |
88365 | 2364 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2365 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2366 || (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
|
2367 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2368 break; |
88365 | 2369 reg[(c - '(') % 4] = id; |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2370 } |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2371 else if (c == '$') |
17052 | 2372 { |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2373 /* Designation sequence for a charset of dimension 2. */ |
88365 | 2374 ONE_MORE_BYTE (c); |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2375 if (c >= '@' && c <= 'B') |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2376 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
88365 | 2377 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
|
2378 else if (c >= '(' && c <= '/') |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2379 { |
88365 | 2380 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2381 if (c1 < ' ' || c1 >= 0x80 |
88365 | 2382 || (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
|
2383 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2384 break; |
88365 | 2385 reg[(c - '(') % 4] = id; |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2386 } |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2387 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2388 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2389 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2390 } |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2391 else if (c == 'N' || c == 'O') |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2392 { |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2393 /* ESC <Fe> for SS2 or SS3. */ |
88365 | 2394 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
|
2395 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2396 } |
26847 | 2397 else if (c >= '0' && c <= '4') |
2398 { | |
2399 /* ESC <Fp> for start/end composition. */ | |
88365 | 2400 mask_found |= CATEGORY_MASK_ISO; |
26847 | 2401 break; |
2402 } | |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2403 else |
88365 | 2404 { |
2405 /* Invalid escape sequence. */ | |
2406 mask_iso &= ~CATEGORY_MASK_ISO_ESCAPE; | |
2407 break; | |
2408 } | |
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 /* We found a valid designation sequence for CHARSET. */ |
88365 | 2411 mask_iso &= ~CATEGORY_MASK_ISO_8BIT; |
2412 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7], | |
2413 id)) | |
2414 mask_found |= CATEGORY_MASK_ISO_7; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2415 else |
88365 | 2416 mask_iso &= ~CATEGORY_MASK_ISO_7; |
2417 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_tight], | |
2418 id)) | |
2419 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
|
2420 else |
88365 | 2421 mask_iso &= ~CATEGORY_MASK_ISO_7_TIGHT; |
2422 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_else], | |
2423 id)) | |
2424 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
|
2425 else |
88365 | 2426 mask_iso &= ~CATEGORY_MASK_ISO_7_ELSE; |
2427 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_8_else], | |
2428 id)) | |
2429 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
|
2430 else |
88365 | 2431 mask_iso &= ~CATEGORY_MASK_ISO_8_ELSE; |
17052 | 2432 break; |
2433 | |
2434 case ISO_CODE_SO: | |
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; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2437 single_shifting = 0; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2438 if (shift_out == 0 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2439 && (reg[1] >= 0 |
88365 | 2440 || SHIFT_OUT_OK (coding_category_iso_7_else) |
2441 || 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
|
2442 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2443 /* Locking shift out. */ |
88365 | 2444 mask_iso &= ~CATEGORY_MASK_ISO_7BIT; |
2445 mask_found |= CATEGORY_MASK_ISO_ELSE; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2446 } |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2447 break; |
88365 | 2448 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2449 case ISO_CODE_SI: |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2450 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2451 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2452 single_shifting = 0; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2453 if (shift_out == 1) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2454 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2455 /* Locking shift in. */ |
88365 | 2456 mask_iso &= ~CATEGORY_MASK_ISO_7BIT; |
2457 mask_found |= CATEGORY_MASK_ISO_ELSE; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2458 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2459 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2460 |
17052 | 2461 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
|
2462 single_shifting = 0; |
17052 | 2463 case ISO_CODE_SS2: |
2464 case ISO_CODE_SS3: | |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2465 { |
88365 | 2466 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
|
2467 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2468 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2469 break; |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2470 if (c != ISO_CODE_CSI) |
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2471 { |
88365 | 2472 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2473 & CODING_ISO_FLAG_SINGLE_SHIFT) | |
2474 newmask |= CATEGORY_MASK_ISO_8_1; | |
2475 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2476 & CODING_ISO_FLAG_SINGLE_SHIFT) | |
2477 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
|
2478 single_shifting = 1; |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
2479 } |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2480 if (VECTORP (Vlatin_extra_code_table) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2481 && !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
|
2482 { |
88365 | 2483 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2484 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2485 newmask |= CATEGORY_MASK_ISO_8_1; | |
2486 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2487 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2488 newmask |= CATEGORY_MASK_ISO_8_2; | |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2489 } |
88365 | 2490 mask_iso &= newmask; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2491 mask_found |= newmask; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2492 } |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2493 break; |
17052 | 2494 |
2495 default: | |
2496 if (c < 0x80) | |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2497 { |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2498 single_shifting = 0; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2499 break; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2500 } |
17052 | 2501 else if (c < 0xA0) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2502 { |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2503 single_shifting = 0; |
88365 | 2504 mask_8bit_found = 1; |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2505 if (VECTORP (Vlatin_extra_code_table) |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2506 && !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
|
2507 { |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2508 int newmask = 0; |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2509 |
88365 | 2510 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
2511 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2512 newmask |= CATEGORY_MASK_ISO_8_1; | |
2513 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) | |
2514 & CODING_ISO_FLAG_LATIN_EXTRA) | |
2515 newmask |= CATEGORY_MASK_ISO_8_2; | |
2516 mask_iso &= newmask; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2517 mask_found |= newmask; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2518 } |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2519 else |
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
2520 return 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2521 } |
17052 | 2522 else |
2523 { | |
88365 | 2524 mask_iso &= ~(CATEGORY_MASK_ISO_7BIT |
2525 | CATEGORY_MASK_ISO_7_ELSE); | |
2526 mask_found |= CATEGORY_MASK_ISO_8_1; | |
2527 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
|
2528 /* 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
|
2529 0xA0..0FF. If the byte length is odd, we exclude |
88365 | 2530 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
|
2531 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
|
2532 if (!single_shifting |
88365 | 2533 && 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
|
2534 { |
29299
b33b38d81020
(detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents:
29275
diff
changeset
|
2535 int i = 1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2536 while (src < src_end) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2537 { |
88365 | 2538 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
|
2539 if (c < 0xA0) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2540 break; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2541 i++; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2542 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2543 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2544 if (i & 1 && src < src_end) |
88365 | 2545 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
|
2546 else |
88365 | 2547 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
|
2548 } |
17052 | 2549 } |
2550 break; | |
2551 } | |
2552 } | |
88365 | 2553 no_more_source: |
2554 if (!mask_iso) | |
2555 { | |
2556 *mask &= ~CATEGORY_MASK_ISO; | |
2557 return 0; | |
2558 } | |
2559 if (!mask_found) | |
2560 return 0; | |
2561 *mask &= mask_iso & mask_found; | |
2562 if (! mask_8bit_found) | |
2563 *mask &= ~(CATEGORY_MASK_ISO_8BIT | CATEGORY_MASK_ISO_8_ELSE); | |
2564 return 1; | |
17052 | 2565 } |
2566 | |
2567 | |
2568 /* Set designation state into CODING. */ | |
88365 | 2569 #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
2570 do { \ | |
2571 int id, prev; \ | |
2572 \ | |
2573 if (final < '0' || final >= 128 \ | |
2574 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ | |
2575 || !SAFE_CHARSET_P (coding, id)) \ | |
2576 { \ | |
2577 CODING_ISO_DESIGNATION (coding, reg) = -2; \ | |
2578 goto invalid_code; \ | |
2579 } \ | |
2580 prev = CODING_ISO_DESIGNATION (coding, reg); \ | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2581 if (id == charset_jisx0201_roman) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2582 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2583 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_ROMAN) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2584 id = charset_ascii; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2585 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2586 else if (id == charset_jisx0208_1978) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2587 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2588 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_OLDJIS) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2589 id = charset_jisx0208; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2590 } \ |
88365 | 2591 CODING_ISO_DESIGNATION (coding, reg) = id; \ |
2592 /* If there was an invalid designation to REG previously, and this \ | |
2593 designation is ASCII to REG, we should keep this designation \ | |
2594 sequence. */ \ | |
2595 if (prev == -2 && id == charset_ascii) \ | |
2596 goto invalid_code; \ | |
17052 | 2597 } while (0) |
2598 | |
88365 | 2599 |
2600 #define MAYBE_FINISH_COMPOSITION() \ | |
2601 do { \ | |
2602 int i; \ | |
2603 if (composition_state == COMPOSING_NO) \ | |
2604 break; \ | |
2605 /* It is assured that we have enough room for producing \ | |
2606 characters stored in the table `components'. */ \ | |
2607 if (charbuf + component_idx > charbuf_end) \ | |
2608 goto no_more_source; \ | |
2609 composition_state = COMPOSING_NO; \ | |
2610 if (method == COMPOSITION_RELATIVE \ | |
2611 || method == COMPOSITION_WITH_ALTCHARS) \ | |
2612 { \ | |
2613 for (i = 0; i < component_idx; i++) \ | |
2614 *charbuf++ = components[i]; \ | |
2615 char_offset += component_idx; \ | |
2616 } \ | |
2617 else \ | |
2618 { \ | |
2619 for (i = 0; i < component_idx; i += 2) \ | |
2620 *charbuf++ = components[i]; \ | |
2621 char_offset += (component_idx / 2) + 1; \ | |
2622 } \ | |
2623 } while (0) | |
2624 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2625 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2626 /* 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
|
2627 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
|
2628 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
88365 | 2629 ESC 3 : altchar composition : ESC 3 CHAR ... ESC 0 CHAR ... ESC 1 |
2630 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
|
2631 */ |
26847 | 2632 |
88365 | 2633 #define DECODE_COMPOSITION_START(c1) \ |
26847 | 2634 do { \ |
88365 | 2635 if (c1 == '0' \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2636 && composition_state == COMPOSING_COMPONENT_RULE) \ |
26847 | 2637 { \ |
88365 | 2638 component_len = component_idx; \ |
2639 composition_state = COMPOSING_CHAR; \ | |
26847 | 2640 } \ |
2641 else \ | |
2642 { \ | |
88365 | 2643 unsigned char *p; \ |
2644 \ | |
2645 MAYBE_FINISH_COMPOSITION (); \ | |
2646 if (charbuf + MAX_COMPOSITION_COMPONENTS > charbuf_end) \ | |
2647 goto no_more_source; \ | |
2648 for (p = src; p < src_end - 1; p++) \ | |
2649 if (*p == ISO_CODE_ESC && p[1] == '1') \ | |
2650 break; \ | |
2651 if (p == src_end - 1) \ | |
2652 { \ | |
2653 if (coding->mode & CODING_MODE_LAST_BLOCK) \ | |
2654 goto invalid_code; \ | |
2655 goto no_more_source; \ | |
2656 } \ | |
2657 \ | |
2658 /* This is surely the start of a composition. */ \ | |
2659 method = (c1 == '0' ? COMPOSITION_RELATIVE \ | |
2660 : c1 == '2' ? COMPOSITION_WITH_RULE \ | |
2661 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \ | |
2662 : COMPOSITION_WITH_RULE_ALTCHARS); \ | |
2663 composition_state = (c1 <= '2' ? COMPOSING_CHAR \ | |
2664 : COMPOSING_COMPONENT_CHAR); \ | |
2665 component_idx = component_len = 0; \ | |
26847 | 2666 } \ |
2667 } while (0) | |
2668 | |
88365 | 2669 |
2670 /* Handle compositoin end sequence ESC 1. */ | |
2671 | |
2672 #define DECODE_COMPOSITION_END() \ | |
2673 do { \ | |
2674 int nchars = (component_len > 0 ? component_idx - component_len \ | |
2675 : method == COMPOSITION_RELATIVE ? component_idx \ | |
2676 : (component_idx + 1) / 2); \ | |
2677 int i; \ | |
2678 int *saved_charbuf = charbuf; \ | |
2679 \ | |
2680 ADD_COMPOSITION_DATA (charbuf, method, nchars); \ | |
2681 if (method != COMPOSITION_RELATIVE) \ | |
2682 { \ | |
2683 if (component_len == 0) \ | |
2684 for (i = 0; i < component_idx; i++) \ | |
2685 *charbuf++ = components[i]; \ | |
2686 else \ | |
2687 for (i = 0; i < component_len; i++) \ | |
2688 *charbuf++ = components[i]; \ | |
2689 *saved_charbuf = saved_charbuf - charbuf; \ | |
2690 } \ | |
2691 if (method == COMPOSITION_WITH_RULE) \ | |
2692 for (i = 0; i < component_idx; i += 2, char_offset++) \ | |
2693 *charbuf++ = components[i]; \ | |
2694 else \ | |
2695 for (i = component_len; i < component_idx; i++, char_offset++) \ | |
2696 *charbuf++ = components[i]; \ | |
2697 coding->annotated = 1; \ | |
2698 composition_state = COMPOSING_NO; \ | |
2699 } while (0) | |
2700 | |
2701 | |
26847 | 2702 /* Decode a composition rule from the byte C1 (and maybe one more byte |
2703 from SRC) and store one encoded composition rule in | |
2704 coding->cmp_data. */ | |
2705 | |
2706 #define DECODE_COMPOSITION_RULE(c1) \ | |
2707 do { \ | |
2708 (c1) -= 32; \ | |
2709 if (c1 < 81) /* old format (before ver.21) */ \ | |
2710 { \ | |
2711 int gref = (c1) / 9; \ | |
2712 int nref = (c1) % 9; \ | |
2713 if (gref == 4) gref = 10; \ | |
2714 if (nref == 4) nref = 10; \ | |
88365 | 2715 c1 = COMPOSITION_ENCODE_RULE (gref, nref); \ |
26847 | 2716 } \ |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2717 else if (c1 < 93) /* new format (after ver.21) */ \ |
26847 | 2718 { \ |
2719 ONE_MORE_BYTE (c2); \ | |
88365 | 2720 c1 = COMPOSITION_ENCODE_RULE (c1 - 81, c2 - 32); \ |
26847 | 2721 } \ |
88365 | 2722 else \ |
2723 c1 = 0; \ | |
26847 | 2724 } while (0) |
2725 | |
2726 | |
17052 | 2727 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
2728 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2729 static void |
88365 | 2730 decode_coding_iso_2022 (coding) |
17052 | 2731 struct coding_system *coding; |
2732 { | |
88365 | 2733 unsigned char *src = coding->source + coding->consumed; |
2734 unsigned char *src_end = coding->source + coding->src_bytes; | |
2735 unsigned char *src_base; | |
2736 int *charbuf = coding->charbuf; | |
2737 int *charbuf_end = charbuf + coding->charbuf_size - 4; | |
2738 int consumed_chars = 0, consumed_chars_base; | |
2739 int char_offset = 0; | |
2740 int multibytep = coding->src_multibyte; | |
17052 | 2741 /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
88365 | 2742 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2743 int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
2744 struct charset *charset; | |
2745 int c; | |
2746 /* For handling composition sequence. */ | |
2747 #define COMPOSING_NO 0 | |
2748 #define COMPOSING_CHAR 1 | |
2749 #define COMPOSING_RULE 2 | |
2750 #define COMPOSING_COMPONENT_CHAR 3 | |
2751 #define COMPOSING_COMPONENT_RULE 4 | |
2752 | |
2753 int composition_state = COMPOSING_NO; | |
2754 enum composition_method method; | |
2755 int components[MAX_COMPOSITION_COMPONENTS * 2 + 1]; | |
2756 int component_idx; | |
2757 int component_len; | |
2758 Lisp_Object attrs, eol_type, charset_list; | |
2759 | |
2760 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
2761 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
|
2762 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2763 while (1) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2764 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2765 int c1, c2; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2766 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2767 src_base = src; |
88365 | 2768 consumed_chars_base = consumed_chars; |
2769 | |
2770 if (charbuf >= charbuf_end) | |
2771 break; | |
2772 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2773 ONE_MORE_BYTE (c1); |
17052 | 2774 |
26847 | 2775 /* We produce no character or one character. */ |
17052 | 2776 switch (iso_code_class [c1]) |
2777 { | |
2778 case ISO_0x20_or_0x7F: | |
88365 | 2779 if (composition_state != COMPOSING_NO) |
26847 | 2780 { |
88365 | 2781 if (composition_state == COMPOSING_RULE |
2782 || composition_state == COMPOSING_COMPONENT_RULE) | |
2783 { | |
2784 DECODE_COMPOSITION_RULE (c1); | |
2785 components[component_idx++] = c1; | |
2786 composition_state--; | |
2787 continue; | |
2788 } | |
26847 | 2789 } |
88365 | 2790 if (charset_id_0 < 0 |
2791 || ! 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
|
2792 /* This is SPACE or DEL. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2793 charset = CHARSET_FROM_ID (charset_ascii); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2794 else |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2795 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
|
2796 break; |
17052 | 2797 |
2798 case ISO_graphic_plane_0: | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2799 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
|
2800 { |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2801 if (composition_state == COMPOSING_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2802 || composition_state == COMPOSING_COMPONENT_RULE) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2803 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2804 DECODE_COMPOSITION_RULE (c1); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2805 components[component_idx++] = c1; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2806 composition_state--; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2807 continue; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2808 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2809 } |
88365 | 2810 charset = CHARSET_FROM_ID (charset_id_0); |
17052 | 2811 break; |
2812 | |
2813 case ISO_0xA0_or_0xFF: | |
88365 | 2814 if (charset_id_1 < 0 |
2815 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) | |
2816 || CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) | |
2817 goto invalid_code; | |
17052 | 2818 /* This is a graphic character, we fall down ... */ |
2819 | |
2820 case ISO_graphic_plane_1: | |
88365 | 2821 if (charset_id_1 < 0) |
2822 goto invalid_code; | |
2823 charset = CHARSET_FROM_ID (charset_id_1); | |
17052 | 2824 break; |
2825 | |
88365 | 2826 case ISO_carriage_return: |
2827 if (c1 == '\r') | |
2828 { | |
2829 if (EQ (eol_type, Qdos)) | |
2830 { | |
2831 if (src == src_end) | |
2832 goto no_more_source; | |
2833 if (*src == '\n') | |
2834 ONE_MORE_BYTE (c1); | |
2835 } | |
2836 else if (EQ (eol_type, Qmac)) | |
2837 c1 = '\n'; | |
2838 } | |
2839 /* fall through */ | |
2840 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2841 case ISO_control_0: |
88365 | 2842 MAYBE_FINISH_COMPOSITION (); |
2843 charset = CHARSET_FROM_ID (charset_ascii); | |
17052 | 2844 break; |
2845 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2846 case ISO_control_1: |
88365 | 2847 MAYBE_FINISH_COMPOSITION (); |
2848 goto invalid_code; | |
17052 | 2849 |
2850 case ISO_shift_out: | |
88365 | 2851 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2852 || CODING_ISO_DESIGNATION (coding, 1) < 0) | |
2853 goto invalid_code; | |
2854 CODING_ISO_INVOCATION (coding, 0) = 1; | |
2855 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
|
2856 continue; |
17052 | 2857 |
2858 case ISO_shift_in: | |
88365 | 2859 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)) |
2860 goto invalid_code; | |
2861 CODING_ISO_INVOCATION (coding, 0) = 0; | |
2862 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
|
2863 continue; |
17052 | 2864 |
2865 case ISO_single_shift_2_7: | |
2866 case ISO_single_shift_2: | |
88365 | 2867 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2868 goto invalid_code; | |
17052 | 2869 /* SS2 is handled as an escape sequence of ESC 'N' */ |
2870 c1 = 'N'; | |
2871 goto label_escape_sequence; | |
2872 | |
2873 case ISO_single_shift_3: | |
88365 | 2874 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
2875 goto invalid_code; | |
17052 | 2876 /* SS2 is handled as an escape sequence of ESC 'O' */ |
2877 c1 = 'O'; | |
2878 goto label_escape_sequence; | |
2879 | |
2880 case ISO_control_sequence_introducer: | |
2881 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
2882 c1 = '['; | |
2883 goto label_escape_sequence; | |
2884 | |
2885 case ISO_escape: | |
2886 ONE_MORE_BYTE (c1); | |
2887 label_escape_sequence: | |
88365 | 2888 /* Escape sequences handled here are invocation, |
17052 | 2889 designation, direction specification, and character |
2890 composition specification. */ | |
2891 switch (c1) | |
2892 { | |
2893 case '&': /* revision of following character set */ | |
2894 ONE_MORE_BYTE (c1); | |
2895 if (!(c1 >= '@' && c1 <= '~')) | |
88365 | 2896 goto invalid_code; |
17052 | 2897 ONE_MORE_BYTE (c1); |
2898 if (c1 != ISO_CODE_ESC) | |
88365 | 2899 goto invalid_code; |
17052 | 2900 ONE_MORE_BYTE (c1); |
2901 goto label_escape_sequence; | |
2902 | |
2903 case '$': /* designation of 2-byte character set */ | |
88365 | 2904 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
2905 goto invalid_code; | |
17052 | 2906 ONE_MORE_BYTE (c1); |
2907 if (c1 >= '@' && c1 <= 'B') | |
2908 { /* 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
|
2909 or JISX0208.1980 */ |
88365 | 2910 DECODE_DESIGNATION (0, 2, 0, c1); |
17052 | 2911 } |
2912 else if (c1 >= 0x28 && c1 <= 0x2B) | |
2913 { /* designation of DIMENSION2_CHARS94 character set */ | |
2914 ONE_MORE_BYTE (c2); | |
88365 | 2915 DECODE_DESIGNATION (c1 - 0x28, 2, 0, c2); |
17052 | 2916 } |
2917 else if (c1 >= 0x2C && c1 <= 0x2F) | |
2918 { /* designation of DIMENSION2_CHARS96 character set */ | |
2919 ONE_MORE_BYTE (c2); | |
88365 | 2920 DECODE_DESIGNATION (c1 - 0x2C, 2, 1, c2); |
17052 | 2921 } |
2922 else | |
88365 | 2923 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2924 /* We must update these variables now. */ |
88365 | 2925 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
2926 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
|
2927 continue; |
17052 | 2928 |
2929 case 'n': /* invocation of locking-shift-2 */ | |
88365 | 2930 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2931 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
2932 goto invalid_code; | |
2933 CODING_ISO_INVOCATION (coding, 0) = 2; | |
2934 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2935 continue; |
17052 | 2936 |
2937 case 'o': /* invocation of locking-shift-3 */ | |
88365 | 2938 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
2939 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
2940 goto invalid_code; | |
2941 CODING_ISO_INVOCATION (coding, 0) = 3; | |
2942 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
|
2943 continue; |
17052 | 2944 |
2945 case 'N': /* invocation of single-shift-2 */ | |
88365 | 2946 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
2947 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
2948 goto invalid_code; | |
2949 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 2)); | |
17052 | 2950 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
2951 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 2952 goto invalid_code; |
17052 | 2953 break; |
2954 | |
2955 case 'O': /* invocation of single-shift-3 */ | |
88365 | 2956 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
2957 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
2958 goto invalid_code; | |
2959 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 3)); | |
17052 | 2960 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
2961 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 2962 goto invalid_code; |
17052 | 2963 break; |
2964 | |
26847 | 2965 case '0': case '2': case '3': case '4': /* start composition */ |
88365 | 2966 if (! (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK)) |
2967 goto invalid_code; | |
26847 | 2968 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
|
2969 continue; |
17052 | 2970 |
26847 | 2971 case '1': /* end composition */ |
88365 | 2972 if (composition_state == COMPOSING_NO) |
2973 goto invalid_code; | |
2974 DECODE_COMPOSITION_END (); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2975 continue; |
17052 | 2976 |
2977 case '[': /* specification of direction */ | |
88365 | 2978 if (! CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DIRECTION) |
2979 goto invalid_code; | |
17052 | 2980 /* 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
|
2981 So, `coding->mode & CODING_MODE_DIRECTION' zero means |
88365 | 2982 left-to-right, and nozero means right-to-left. */ |
17052 | 2983 ONE_MORE_BYTE (c1); |
2984 switch (c1) | |
2985 { | |
2986 case ']': /* end of the current direction */ | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2987 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 2988 |
2989 case '0': /* end of the current direction */ | |
2990 case '1': /* start of left-to-right direction */ | |
2991 ONE_MORE_BYTE (c1); | |
2992 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2993 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 2994 else |
88365 | 2995 goto invalid_code; |
17052 | 2996 break; |
2997 | |
2998 case '2': /* start of right-to-left direction */ | |
2999 ONE_MORE_BYTE (c1); | |
3000 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3001 coding->mode |= CODING_MODE_DIRECTION; |
17052 | 3002 else |
88365 | 3003 goto invalid_code; |
17052 | 3004 break; |
3005 | |
3006 default: | |
88365 | 3007 goto invalid_code; |
17052 | 3008 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3009 continue; |
17052 | 3010 |
3011 default: | |
88365 | 3012 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
3013 goto invalid_code; | |
17052 | 3014 if (c1 >= 0x28 && c1 <= 0x2B) |
3015 { /* designation of DIMENSION1_CHARS94 character set */ | |
3016 ONE_MORE_BYTE (c2); | |
88365 | 3017 DECODE_DESIGNATION (c1 - 0x28, 1, 0, c2); |
17052 | 3018 } |
3019 else if (c1 >= 0x2C && c1 <= 0x2F) | |
3020 { /* designation of DIMENSION1_CHARS96 character set */ | |
3021 ONE_MORE_BYTE (c2); | |
88365 | 3022 DECODE_DESIGNATION (c1 - 0x2C, 1, 1, c2); |
17052 | 3023 } |
3024 else | |
88365 | 3025 goto invalid_code; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3026 /* We must update these variables now. */ |
88365 | 3027 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
3028 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
|
3029 continue; |
17052 | 3030 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3031 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3032 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3033 /* Now we know CHARSET and 1st position code C1 of a character. |
88365 | 3034 Produce a decoded character while getting 2nd position code |
3035 C2 if necessary. */ | |
3036 c1 &= 0x7F; | |
3037 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
|
3038 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3039 ONE_MORE_BYTE (c2); |
88365 | 3040 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
|
3041 /* C2 is not in a valid range. */ |
88365 | 3042 goto invalid_code; |
3043 c1 = (c1 << 8) | (c2 & 0x7F); | |
3044 if (CHARSET_DIMENSION (charset) > 2) | |
3045 { | |
3046 ONE_MORE_BYTE (c2); | |
3047 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) | |
3048 /* C2 is not in a valid range. */ | |
3049 goto invalid_code; | |
3050 c1 = (c1 << 8) | (c2 & 0x7F); | |
3051 } | |
17052 | 3052 } |
88365 | 3053 |
3054 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); | |
3055 if (c < 0) | |
3056 { | |
3057 MAYBE_FINISH_COMPOSITION (); | |
3058 for (; src_base < src; src_base++, char_offset++) | |
3059 { | |
3060 if (ASCII_BYTE_P (*src_base)) | |
3061 *charbuf++ = *src_base; | |
3062 else | |
3063 *charbuf++ = BYTE8_TO_CHAR (*src_base); | |
3064 } | |
3065 } | |
3066 else if (composition_state == COMPOSING_NO) | |
3067 { | |
3068 *charbuf++ = c; | |
3069 char_offset++; | |
3070 } | |
3071 else | |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3072 { |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3073 components[component_idx++] = c; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3074 if (method == COMPOSITION_WITH_RULE |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3075 || (method == COMPOSITION_WITH_RULE_ALTCHARS |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3076 && composition_state == COMPOSING_COMPONENT_CHAR)) |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3077 composition_state++; |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3078 } |
17052 | 3079 continue; |
3080 | |
88365 | 3081 invalid_code: |
3082 MAYBE_FINISH_COMPOSITION (); | |
3083 src = src_base; | |
3084 consumed_chars = consumed_chars_base; | |
3085 ONE_MORE_BYTE (c); | |
3086 *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
|
3087 coding->errors++; |
88365 | 3088 } |
3089 | |
3090 no_more_source: | |
3091 coding->consumed_char += consumed_chars_base; | |
3092 coding->consumed = src_base - coding->source; | |
3093 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3094 } |
3095 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3096 |
18766 | 3097 /* ISO2022 encoding stuff. */ |
17052 | 3098 |
3099 /* | |
18766 | 3100 It is not enough to say just "ISO2022" on encoding, we have to |
88365 | 3101 specify more details. In Emacs, each coding system of ISO2022 |
17052 | 3102 variant has the following specifications: |
88365 | 3103 1. Initial designation to G0 thru G3. |
17052 | 3104 2. Allows short-form designation? |
3105 3. ASCII should be designated to G0 before control characters? | |
3106 4. ASCII should be designated to G0 at end of line? | |
3107 5. 7-bit environment or 8-bit environment? | |
3108 6. Use locking-shift? | |
3109 7. Use Single-shift? | |
3110 And the following two are only for Japanese: | |
3111 8. Use ASCII in place of JIS0201-1976-Roman? | |
3112 9. Use JISX0208-1983 in place of JISX0208-1978? | |
88365 | 3113 These specifications are encoded in CODING_ISO_FLAGS (coding) as flag bits |
3114 defined by macros CODING_ISO_FLAG_XXX. See `coding.h' for more | |
18766 | 3115 details. |
17052 | 3116 */ |
3117 | |
3118 /* 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
|
3119 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
|
3120 '@', '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
|
3121 designation sequence of short-form. */ |
17052 | 3122 |
3123 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
3124 do { \ | |
88365 | 3125 unsigned char final_char = CHARSET_ISO_FINAL (charset); \ |
17052 | 3126 char *intermediate_char_94 = "()*+"; \ |
3127 char *intermediate_char_96 = ",-./"; \ | |
88365 | 3128 int revision = -1; \ |
3129 int c; \ | |
3130 \ | |
3131 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ | |
88856 | 3132 revision = CHARSET_ISO_REVISION (charset); \ |
88365 | 3133 \ |
3134 if (revision >= 0) \ | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
3135 { \ |
88365 | 3136 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '&'); \ |
3137 EMIT_ONE_BYTE ('@' + revision); \ | |
17052 | 3138 } \ |
88365 | 3139 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ |
17052 | 3140 if (CHARSET_DIMENSION (charset) == 1) \ |
3141 { \ | |
88365 | 3142 if (! CHARSET_ISO_CHARS_96 (charset)) \ |
3143 c = intermediate_char_94[reg]; \ | |
17052 | 3144 else \ |
88365 | 3145 c = intermediate_char_96[reg]; \ |
3146 EMIT_ONE_ASCII_BYTE (c); \ | |
17052 | 3147 } \ |
3148 else \ | |
3149 { \ | |
88365 | 3150 EMIT_ONE_ASCII_BYTE ('$'); \ |
3151 if (! CHARSET_ISO_CHARS_96 (charset)) \ | |
17052 | 3152 { \ |
88365 | 3153 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
|
3154 || reg != 0 \ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3155 || final_char < '@' || final_char > 'B') \ |
88365 | 3156 EMIT_ONE_ASCII_BYTE (intermediate_char_94[reg]); \ |
17052 | 3157 } \ |
3158 else \ | |
88365 | 3159 EMIT_ONE_ASCII_BYTE (intermediate_char_96[reg]); \ |
17052 | 3160 } \ |
88365 | 3161 EMIT_ONE_ASCII_BYTE (final_char); \ |
3162 \ | |
3163 CODING_ISO_DESIGNATION (coding, reg) = CHARSET_ID (charset); \ | |
17052 | 3164 } while (0) |
3165 | |
88365 | 3166 |
17052 | 3167 /* The following two macros produce codes (control character or escape |
3168 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
3169 single-shift-3). */ | |
3170 | |
88365 | 3171 #define ENCODE_SINGLE_SHIFT_2 \ |
3172 do { \ | |
3173 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3174 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'N'); \ | |
3175 else \ | |
3176 EMIT_ONE_BYTE (ISO_CODE_SS2); \ | |
3177 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3178 } while (0) |
3179 | |
88365 | 3180 |
3181 #define ENCODE_SINGLE_SHIFT_3 \ | |
3182 do { \ | |
3183 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3184 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'O'); \ | |
3185 else \ | |
3186 EMIT_ONE_BYTE (ISO_CODE_SS3); \ | |
3187 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 3188 } while (0) |
3189 | |
88365 | 3190 |
17052 | 3191 /* The following four macros produce codes (control character or |
3192 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
3193 shift-out, locking-shift-2, and locking-shift-3). */ | |
3194 | |
88365 | 3195 #define ENCODE_SHIFT_IN \ |
3196 do { \ | |
3197 EMIT_ONE_ASCII_BYTE (ISO_CODE_SI); \ | |
3198 CODING_ISO_INVOCATION (coding, 0) = 0; \ | |
17052 | 3199 } while (0) |
3200 | |
88365 | 3201 |
3202 #define ENCODE_SHIFT_OUT \ | |
3203 do { \ | |
3204 EMIT_ONE_ASCII_BYTE (ISO_CODE_SO); \ | |
3205 CODING_ISO_INVOCATION (coding, 0) = 1; \ | |
17052 | 3206 } while (0) |
3207 | |
88365 | 3208 |
3209 #define ENCODE_LOCKING_SHIFT_2 \ | |
3210 do { \ | |
3211 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3212 CODING_ISO_INVOCATION (coding, 0) = 2; \ | |
17052 | 3213 } while (0) |
3214 | |
88365 | 3215 |
3216 #define ENCODE_LOCKING_SHIFT_3 \ | |
3217 do { \ | |
3218 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
3219 CODING_ISO_INVOCATION (coding, 0) = 3; \ | |
17052 | 3220 } while (0) |
3221 | |
88365 | 3222 |
18766 | 3223 /* Produce codes for a DIMENSION1 character whose character set is |
3224 CHARSET and whose position-code is C1. Designation and invocation | |
17052 | 3225 sequences are also produced in advance if necessary. */ |
3226 | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3227 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3228 do { \ |
88365 | 3229 int id = CHARSET_ID (charset); \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3230 \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3231 if ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_ROMAN) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3232 && id == charset_ascii) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3233 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3234 id = charset_jisx0201_roman; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3235 charset = CHARSET_FROM_ID (id); \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3236 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3237 \ |
88365 | 3238 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3239 { \ |
88365 | 3240 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ |
3241 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3242 else \ |
88365 | 3243 EMIT_ONE_BYTE (c1 | 0x80); \ |
3244 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3245 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3246 } \ |
88365 | 3247 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
|
3248 { \ |
88365 | 3249 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3250 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3251 } \ |
88365 | 3252 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
|
3253 { \ |
88365 | 3254 EMIT_ONE_BYTE (c1 | 0x80); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3255 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3256 } \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3257 else \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3258 /* 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
|
3259 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
|
3260 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
|
3261 character. */ \ |
88365 | 3262 dst = encode_invocation_designation (charset, coding, dst, \ |
3263 &produced_chars); \ | |
17052 | 3264 } while (1) |
3265 | |
88365 | 3266 |
3267 /* Produce codes for a DIMENSION2 character whose character set is | |
3268 CHARSET and whose position-codes are C1 and C2. Designation and | |
3269 invocation codes are also produced in advance if necessary. */ | |
3270 | |
3271 #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
|
3272 do { \ |
88365 | 3273 int id = CHARSET_ID (charset); \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3274 \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3275 if ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_OLDJIS) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3276 && id == charset_jisx0208) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3277 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3278 id = charset_jisx0208_1978; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3279 charset = CHARSET_FROM_ID (id); \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3280 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3281 \ |
88365 | 3282 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
3283 { \ | |
3284 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
3285 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3286 else \ | |
3287 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3288 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
3289 break; \ | |
3290 } \ | |
3291 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ | |
3292 { \ | |
3293 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
3294 break; \ | |
3295 } \ | |
3296 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ | |
3297 { \ | |
3298 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
3299 break; \ | |
3300 } \ | |
3301 else \ | |
3302 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
3303 must invoke it, or, at first, designate it to some graphic \ | |
3304 register. Then repeat the loop to actually produce the \ | |
3305 character. */ \ | |
3306 dst = encode_invocation_designation (charset, coding, dst, \ | |
3307 &produced_chars); \ | |
3308 } while (1) | |
3309 | |
3310 | |
3311 #define ENCODE_ISO_CHARACTER(charset, c) \ | |
3312 do { \ | |
3313 int code = ENCODE_CHAR ((charset),(c)); \ | |
3314 \ | |
3315 if (CHARSET_DIMENSION (charset) == 1) \ | |
3316 ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ | |
3317 else \ | |
3318 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
|
3319 } while (0) |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3320 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
3321 |
17052 | 3322 /* Produce designation and invocation codes at a place pointed by DST |
88365 | 3323 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. |
17052 | 3324 Return new DST. */ |
3325 | |
3326 unsigned char * | |
88365 | 3327 encode_invocation_designation (charset, coding, dst, p_nchars) |
3328 struct charset *charset; | |
17052 | 3329 struct coding_system *coding; |
3330 unsigned char *dst; | |
88365 | 3331 int *p_nchars; |
17052 | 3332 { |
88365 | 3333 int multibytep = coding->dst_multibyte; |
3334 int produced_chars = *p_nchars; | |
17052 | 3335 int reg; /* graphic register number */ |
88365 | 3336 int id = CHARSET_ID (charset); |
17052 | 3337 |
3338 /* At first, check designations. */ | |
3339 for (reg = 0; reg < 4; reg++) | |
88365 | 3340 if (id == CODING_ISO_DESIGNATION (coding, reg)) |
17052 | 3341 break; |
3342 | |
3343 if (reg >= 4) | |
3344 { | |
3345 /* CHARSET is not yet designated to any graphic registers. */ | |
3346 /* At first check the requested designation. */ | |
88365 | 3347 reg = CODING_ISO_REQUEST (coding, id); |
3348 if (reg < 0) | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3349 /* Since CHARSET requests no special designation, designate it |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3350 to graphic register 0. */ |
17052 | 3351 reg = 0; |
3352 | |
3353 ENCODE_DESIGNATION (charset, reg, coding); | |
3354 } | |
3355 | |
88365 | 3356 if (CODING_ISO_INVOCATION (coding, 0) != reg |
3357 && CODING_ISO_INVOCATION (coding, 1) != reg) | |
17052 | 3358 { |
3359 /* Since the graphic register REG is not invoked to any graphic | |
3360 planes, invoke it to graphic plane 0. */ | |
3361 switch (reg) | |
3362 { | |
3363 case 0: /* graphic register 0 */ | |
3364 ENCODE_SHIFT_IN; | |
3365 break; | |
3366 | |
3367 case 1: /* graphic register 1 */ | |
3368 ENCODE_SHIFT_OUT; | |
3369 break; | |
3370 | |
3371 case 2: /* graphic register 2 */ | |
88365 | 3372 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3373 ENCODE_SINGLE_SHIFT_2; |
3374 else | |
3375 ENCODE_LOCKING_SHIFT_2; | |
3376 break; | |
3377 | |
3378 case 3: /* graphic register 3 */ | |
88365 | 3379 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 3380 ENCODE_SINGLE_SHIFT_3; |
3381 else | |
3382 ENCODE_LOCKING_SHIFT_3; | |
3383 break; | |
3384 } | |
3385 } | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3386 |
88365 | 3387 *p_nchars = produced_chars; |
17052 | 3388 return dst; |
3389 } | |
3390 | |
3391 /* The following three macros produce codes for indicating direction | |
3392 of text. */ | |
88365 | 3393 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ |
3394 do { \ | |
3395 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \ | |
3396 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \ | |
3397 else \ | |
3398 EMIT_ONE_BYTE (ISO_CODE_CSI); \ | |
17052 | 3399 } while (0) |
3400 | |
88365 | 3401 |
3402 #define ENCODE_DIRECTION_R2L() \ | |
3403 do { \ | |
3404 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3405 EMIT_TWO_ASCII_BYTES ('2', ']'); \ | |
3406 } while (0) | |
3407 | |
3408 | |
3409 #define ENCODE_DIRECTION_L2R() \ | |
3410 do { \ | |
3411 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
3412 EMIT_TWO_ASCII_BYTES ('0', ']'); \ | |
3413 } while (0) | |
3414 | |
17052 | 3415 |
3416 /* Produce codes for designation and invocation to reset the graphic | |
3417 planes and registers to initial state. */ | |
88365 | 3418 #define ENCODE_RESET_PLANE_AND_REGISTER() \ |
3419 do { \ | |
3420 int reg; \ | |
3421 struct charset *charset; \ | |
3422 \ | |
3423 if (CODING_ISO_INVOCATION (coding, 0) != 0) \ | |
3424 ENCODE_SHIFT_IN; \ | |
3425 for (reg = 0; reg < 4; reg++) \ | |
3426 if (CODING_ISO_INITIAL (coding, reg) >= 0 \ | |
3427 && (CODING_ISO_DESIGNATION (coding, reg) \ | |
3428 != CODING_ISO_INITIAL (coding, reg))) \ | |
3429 { \ | |
3430 charset = CHARSET_FROM_ID (CODING_ISO_INITIAL (coding, reg)); \ | |
3431 ENCODE_DESIGNATION (charset, reg, coding); \ | |
3432 } \ | |
17052 | 3433 } while (0) |
3434 | |
88365 | 3435 |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3436 /* 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
|
3437 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
|
3438 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3439 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
|
3440 find all the necessary designations. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3441 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3442 static unsigned char * |
88365 | 3443 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
|
3444 struct coding_system *coding; |
88365 | 3445 int *charbuf, *charbuf_end; |
3446 unsigned char *dst; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3447 { |
88365 | 3448 struct charset *charset; |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3449 /* 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
|
3450 int r[4]; |
88365 | 3451 int c, found = 0, reg; |
3452 int produced_chars = 0; | |
3453 int multibytep = coding->dst_multibyte; | |
3454 Lisp_Object attrs; | |
3455 Lisp_Object charset_list; | |
3456 | |
3457 attrs = CODING_ID_ATTRS (coding->id); | |
3458 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
3459 if (EQ (charset_list, Qiso_2022)) | |
3460 charset_list = Viso_2022_charset_list; | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3461 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3462 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3463 r[reg] = -1; |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3464 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3465 while (found < 4) |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3466 { |
88365 | 3467 int id; |
3468 | |
3469 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3470 if (c == '\n') |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3471 break; |
88365 | 3472 charset = char_charset (c, charset_list, NULL); |
3473 id = CHARSET_ID (charset); | |
3474 reg = CODING_ISO_REQUEST (coding, id); | |
3475 if (reg >= 0 && r[reg] < 0) | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3476 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3477 found++; |
88365 | 3478 r[reg] = id; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3479 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3480 } |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3481 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3482 if (found) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3483 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3484 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3485 if (r[reg] >= 0 |
88365 | 3486 && CODING_ISO_DESIGNATION (coding, reg) != r[reg]) |
3487 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
|
3488 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3489 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3490 return dst; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3491 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3492 |
17052 | 3493 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
3494 | |
88365 | 3495 static int |
3496 encode_coding_iso_2022 (coding) | |
17052 | 3497 struct coding_system *coding; |
3498 { | |
88365 | 3499 int multibytep = coding->dst_multibyte; |
3500 int *charbuf = coding->charbuf; | |
3501 int *charbuf_end = charbuf + coding->charbuf_used; | |
3502 unsigned char *dst = coding->destination + coding->produced; | |
3503 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3504 int safe_room = 16; | |
3505 int bol_designation | |
3506 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL | |
3507 && CODING_ISO_BOL (coding)); | |
3508 int produced_chars = 0; | |
3509 Lisp_Object attrs, eol_type, charset_list; | |
3510 int ascii_compatible; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3511 int c; |
88365 | 3512 |
3513 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
|
3514 setup_iso_safe_charsets (attrs); |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3515 coding->safe_charsets |
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3516 = (char *) XSTRING (CODING_ATTR_SAFE_CHARSETS(attrs))->data; |
88365 | 3517 |
3518 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3519 | |
3520 while (charbuf < charbuf_end) | |
3521 { | |
3522 ASSURE_DESTINATION (safe_room); | |
3523 | |
3524 if (bol_designation) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3525 { |
88365 | 3526 unsigned char *dst_prev = dst; |
3527 | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3528 /* We have to produce designation sequences if any now. */ |
88365 | 3529 dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); |
3530 bol_designation = 0; | |
3531 /* We are sure that designation sequences are all ASCII bytes. */ | |
3532 produced_chars += dst - dst_prev; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3533 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3534 |
88365 | 3535 c = *charbuf++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3536 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3537 /* 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
|
3538 if (c < 0x20 || c == 0x7F) |
17052 | 3539 { |
88365 | 3540 if (c == '\n' |
3541 || (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
|
3542 { |
88365 | 3543 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) |
3544 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3545 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_INIT_AT_BOL) | |
3546 { | |
3547 int i; | |
3548 | |
3549 for (i = 0; i < 4; i++) | |
3550 CODING_ISO_DESIGNATION (coding, i) | |
3551 = CODING_ISO_INITIAL (coding, i); | |
3552 } | |
3553 bol_designation | |
3554 = 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
|
3555 } |
88365 | 3556 else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) |
3557 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3558 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
|
3559 } |
88365 | 3560 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
|
3561 { |
88365 | 3562 if (ascii_compatible) |
3563 EMIT_ONE_ASCII_BYTE (c); | |
3564 else | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3565 { |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3566 struct charset *charset = CHARSET_FROM_ID (charset_ascii); |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3567 ENCODE_ISO_CHARACTER (charset, c); |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3568 } |
17052 | 3569 } |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3570 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3571 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3572 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3573 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3574 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3575 else |
88365 | 3576 { |
3577 struct charset *charset = char_charset (c, charset_list, NULL); | |
3578 | |
3579 if (!charset) | |
3580 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3581 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
|
3582 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3583 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3584 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3585 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3586 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3587 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3588 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3589 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
|
3590 } |
88365 | 3591 } |
3592 ENCODE_ISO_CHARACTER (charset, c); | |
3593 } | |
3594 } | |
3595 | |
3596 if (coding->mode & CODING_MODE_LAST_BLOCK | |
3597 && CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) | |
3598 { | |
3599 ASSURE_DESTINATION (safe_room); | |
3600 ENCODE_RESET_PLANE_AND_REGISTER (); | |
3601 } | |
3602 coding->result = CODING_RESULT_SUCCESS; | |
3603 CODING_ISO_BOL (coding) = bol_designation; | |
3604 coding->produced_char += produced_chars; | |
3605 coding->produced = dst - coding->destination; | |
3606 return 0; | |
17052 | 3607 } |
3608 | |
3609 | |
88365 | 3610 /*** 8,9. SJIS and BIG5 handlers ***/ |
3611 | |
3612 /* Although SJIS and BIG5 are not ISO's coding system, they are used | |
17052 | 3613 quite widely. So, for the moment, Emacs supports them in the bare |
3614 C code. But, in the future, they may be supported only by CCL. */ | |
3615 | |
3616 /* SJIS is a coding system encoding three character sets: ASCII, right | |
3617 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
3618 as is. A character of charset katakana-jisx0201 is encoded by | |
3619 "position-code + 0x80". A character of charset japanese-jisx0208 | |
3620 is encoded in 2-byte but two position-codes are divided and shifted | |
88365 | 3621 so that it fit in the range below. |
17052 | 3622 |
3623 --- CODE RANGE of SJIS --- | |
3624 (character set) (range) | |
3625 ASCII 0x00 .. 0x7F | |
88365 | 3626 KATAKANA-JISX0201 0xA0 .. 0xDF |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
3627 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
|
3628 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC |
17052 | 3629 ------------------------------- |
3630 | |
3631 */ | |
3632 | |
3633 /* BIG5 is a coding system encoding two character sets: ASCII and | |
3634 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
88365 | 3635 character set and is encoded in two-byte. |
17052 | 3636 |
3637 --- CODE RANGE of BIG5 --- | |
3638 (character set) (range) | |
3639 ASCII 0x00 .. 0x7F | |
3640 Big5 (1st byte) 0xA1 .. 0xFE | |
3641 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
3642 -------------------------- | |
3643 | |
88365 | 3644 */ |
17052 | 3645 |
3646 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3647 Check if a text is encoded in SJIS. If it is, return | |
88365 | 3648 CATEGORY_MASK_SJIS, else return 0. */ |
17052 | 3649 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3650 static int |
88365 | 3651 detect_coding_sjis (coding, mask) |
3652 struct coding_system *coding; | |
3653 int *mask; | |
17052 | 3654 { |
88365 | 3655 unsigned char *src = coding->source, *src_base = src; |
3656 unsigned char *src_end = coding->source + coding->src_bytes; | |
3657 int multibytep = coding->src_multibyte; | |
3658 int consumed_chars = 0; | |
3659 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3660 int c; |
88365 | 3661 |
3662 /* A coding system of this category is always ASCII compatible. */ | |
3663 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
|
3664 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3665 while (1) |
17052 | 3666 { |
88365 | 3667 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3668 if (c < 0x80) |
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3669 continue; |
88365 | 3670 if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEF)) |
17052 | 3671 { |
88365 | 3672 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3673 if (c < 0x40 || c == 0x7F || c > 0xFC) |
88365 | 3674 break; |
3675 found = 1; | |
17052 | 3676 } |
88365 | 3677 else if (c >= 0xA0 && c < 0xE0) |
3678 found = 1; | |
3679 else | |
3680 break; | |
3681 } | |
3682 *mask &= ~CATEGORY_MASK_SJIS; | |
3683 return 0; | |
3684 | |
3685 no_more_source: | |
3686 if (!found) | |
3687 return 0; | |
3688 *mask &= CATEGORY_MASK_SJIS; | |
3689 return 1; | |
17052 | 3690 } |
3691 | |
3692 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
3693 Check if a text is encoded in BIG5. If it is, return | |
88365 | 3694 CATEGORY_MASK_BIG5, else return 0. */ |
17052 | 3695 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3696 static int |
88365 | 3697 detect_coding_big5 (coding, mask) |
3698 struct coding_system *coding; | |
3699 int *mask; | |
17052 | 3700 { |
88365 | 3701 unsigned char *src = coding->source, *src_base = src; |
3702 unsigned char *src_end = coding->source + coding->src_bytes; | |
3703 int multibytep = coding->src_multibyte; | |
3704 int consumed_chars = 0; | |
3705 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3706 int c; |
88365 | 3707 |
3708 /* A coding system of this category is always ASCII compatible. */ | |
3709 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
|
3710 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3711 while (1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3712 { |
88365 | 3713 ONE_MORE_BYTE (c); |
3714 if (c < 0x80) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3715 continue; |
88365 | 3716 if (c >= 0xA1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3717 { |
88365 | 3718 ONE_MORE_BYTE (c); |
3719 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
|
3720 return 0; |
88365 | 3721 found = 1; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3722 } |
88365 | 3723 else |
3724 break; | |
3725 } | |
3726 *mask &= ~CATEGORY_MASK_BIG5; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3727 return 0; |
88365 | 3728 |
3729 no_more_source: | |
3730 if (!found) | |
3731 return 0; | |
3732 *mask &= CATEGORY_MASK_BIG5; | |
3733 return 1; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3734 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3735 |
17052 | 3736 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". |
3737 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
3738 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3739 static void |
88365 | 3740 decode_coding_sjis (coding) |
17052 | 3741 struct coding_system *coding; |
3742 { | |
88365 | 3743 unsigned char *src = coding->source + coding->consumed; |
3744 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
|
3745 unsigned char *src_base; |
88365 | 3746 int *charbuf = coding->charbuf; |
3747 int *charbuf_end = charbuf + coding->charbuf_size; | |
3748 int consumed_chars = 0, consumed_chars_base; | |
3749 int multibytep = coding->src_multibyte; | |
3750 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3751 Lisp_Object attrs, eol_type, charset_list, val; | |
3752 | |
3753 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3754 | |
3755 val = charset_list; | |
3756 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3757 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3758 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3759 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3760 while (1) |
17052 | 3761 { |
88365 | 3762 int c, c1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3763 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3764 src_base = src; |
88365 | 3765 consumed_chars_base = consumed_chars; |
3766 | |
3767 if (charbuf >= charbuf_end) | |
3768 break; | |
3769 | |
3770 ONE_MORE_BYTE (c); | |
3771 | |
3772 if (c == '\r') | |
17052 | 3773 { |
88365 | 3774 if (EQ (eol_type, Qdos)) |
17052 | 3775 { |
88365 | 3776 if (src == src_end) |
3777 goto no_more_source; | |
3778 if (*src == '\n') | |
3779 ONE_MORE_BYTE (c); | |
17052 | 3780 } |
88365 | 3781 else if (EQ (eol_type, Qmac)) |
3782 c = '\n'; | |
17052 | 3783 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3784 else |
88365 | 3785 { |
3786 struct charset *charset; | |
3787 | |
3788 if (c < 0x80) | |
3789 charset = charset_roman; | |
3790 else | |
17052 | 3791 { |
88365 | 3792 if (c >= 0xF0) |
3793 goto invalid_code; | |
3794 if (c < 0xA0 || c >= 0xE0) | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3795 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3796 /* SJIS -> JISX0208 */ |
88365 | 3797 ONE_MORE_BYTE (c1); |
3798 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) | |
3799 goto invalid_code; | |
3800 c = (c << 8) | c1; | |
3801 SJIS_TO_JIS (c); | |
3802 charset = charset_kanji; | |
24870
b0f6eab5deeb
(decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents:
24822
diff
changeset
|
3803 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3804 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3805 /* SJIS -> JISX0201-Kana */ |
88365 | 3806 charset = charset_kana; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3807 } |
88365 | 3808 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
3809 } | |
3810 *charbuf++ = c; | |
3811 continue; | |
3812 | |
3813 invalid_code: | |
3814 src = src_base; | |
3815 consumed_chars = consumed_chars_base; | |
3816 ONE_MORE_BYTE (c); | |
3817 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
3818 coding->errors++; | |
3819 } | |
3820 | |
3821 no_more_source: | |
3822 coding->consumed_char += consumed_chars_base; | |
3823 coding->consumed = src_base - coding->source; | |
3824 coding->charbuf_used = charbuf - coding->charbuf; | |
3825 } | |
3826 | |
3827 static void | |
3828 decode_coding_big5 (coding) | |
3829 struct coding_system *coding; | |
3830 { | |
3831 unsigned char *src = coding->source + coding->consumed; | |
3832 unsigned char *src_end = coding->source + coding->src_bytes; | |
3833 unsigned char *src_base; | |
3834 int *charbuf = coding->charbuf; | |
3835 int *charbuf_end = charbuf + coding->charbuf_size; | |
3836 int consumed_chars = 0, consumed_chars_base; | |
3837 int multibytep = coding->src_multibyte; | |
3838 struct charset *charset_roman, *charset_big5; | |
3839 Lisp_Object attrs, eol_type, charset_list, val; | |
3840 | |
3841 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3842 val = charset_list; | |
3843 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3844 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3845 | |
3846 while (1) | |
3847 { | |
3848 int c, c1; | |
3849 | |
3850 src_base = src; | |
3851 consumed_chars_base = consumed_chars; | |
3852 | |
3853 if (charbuf >= charbuf_end) | |
3854 break; | |
3855 | |
3856 ONE_MORE_BYTE (c); | |
3857 | |
3858 if (c == '\r') | |
3859 { | |
3860 if (EQ (eol_type, Qdos)) | |
3861 { | |
3862 if (src == src_end) | |
3863 goto no_more_source; | |
3864 if (*src == '\n') | |
3865 ONE_MORE_BYTE (c); | |
3866 } | |
3867 else if (EQ (eol_type, Qmac)) | |
3868 c = '\n'; | |
3869 } | |
3870 else | |
3871 { | |
3872 struct charset *charset; | |
3873 if (c < 0x80) | |
3874 charset = charset_roman; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3875 else |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3876 { |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3877 /* BIG5 -> Big5 */ |
88365 | 3878 if (c < 0xA1 || c > 0xFE) |
3879 goto invalid_code; | |
3880 ONE_MORE_BYTE (c1); | |
3881 if (c1 < 0x40 || (c1 > 0x7E && c1 < 0xA1) || c1 > 0xFE) | |
3882 goto invalid_code; | |
3883 c = c << 8 | c1; | |
3884 charset = charset_big5; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3885 } |
88365 | 3886 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
|
3887 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3888 |
88365 | 3889 *charbuf++ = c; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3890 continue; |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3891 |
88365 | 3892 invalid_code: |
17052 | 3893 src = src_base; |
88365 | 3894 consumed_chars = consumed_chars_base; |
3895 ONE_MORE_BYTE (c); | |
3896 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
3897 coding->errors++; | |
3898 } | |
3899 | |
3900 no_more_source: | |
3901 coding->consumed_char += consumed_chars_base; | |
3902 coding->consumed = src_base - coding->source; | |
3903 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 3904 } |
3905 | |
3906 /* 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
|
3907 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
|
3908 `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
|
3909 are sure that all these charsets are registered as official charset |
17052 | 3910 (i.e. do not have extended leading-codes). Characters of other |
3911 charsets are produced without any encoding. If SJIS_P is 1, encode | |
3912 SJIS text, else encode BIG5 text. */ | |
3913 | |
88365 | 3914 static int |
3915 encode_coding_sjis (coding) | |
17052 | 3916 struct coding_system *coding; |
3917 { | |
88365 | 3918 int multibytep = coding->dst_multibyte; |
3919 int *charbuf = coding->charbuf; | |
3920 int *charbuf_end = charbuf + coding->charbuf_used; | |
3921 unsigned char *dst = coding->destination + coding->produced; | |
3922 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3923 int safe_room = 4; | |
3924 int produced_chars = 0; | |
3925 Lisp_Object attrs, eol_type, charset_list, val; | |
3926 int ascii_compatible; | |
3927 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
3928 int c; | |
3929 | |
3930 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
3931 val = charset_list; | |
3932 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3933 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
3934 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); | |
3935 | |
3936 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
3937 | |
3938 while (charbuf < charbuf_end) | |
3939 { | |
3940 ASSURE_DESTINATION (safe_room); | |
3941 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3942 /* Now encode the character C. */ |
88365 | 3943 if (ASCII_CHAR_P (c) && ascii_compatible) |
3944 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3945 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3946 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3947 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3948 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3949 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3950 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3951 { |
88365 | 3952 unsigned code; |
3953 struct charset *charset = char_charset (c, charset_list, &code); | |
3954 | |
3955 if (!charset) | |
3956 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3957 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
|
3958 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3959 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3960 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3961 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3962 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3963 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3964 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3965 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
|
3966 } |
88365 | 3967 } |
3968 if (code == CHARSET_INVALID_CODE (charset)) | |
3969 abort (); | |
3970 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
|
3971 { |
88365 | 3972 int c1, c2; |
3973 JIS_TO_SJIS (code); | |
3974 c1 = code >> 8, c2 = code & 0xFF; | |
3975 EMIT_TWO_BYTES (c1, c2); | |
3976 } | |
3977 else if (charset == charset_kana) | |
3978 EMIT_ONE_BYTE (code | 0x80); | |
3979 else | |
3980 EMIT_ONE_ASCII_BYTE (code & 0x7F); | |
3981 } | |
3982 } | |
3983 coding->result = CODING_RESULT_SUCCESS; | |
3984 coding->produced_char += produced_chars; | |
3985 coding->produced = dst - coding->destination; | |
3986 return 0; | |
3987 } | |
3988 | |
3989 static int | |
3990 encode_coding_big5 (coding) | |
3991 struct coding_system *coding; | |
3992 { | |
3993 int multibytep = coding->dst_multibyte; | |
3994 int *charbuf = coding->charbuf; | |
3995 int *charbuf_end = charbuf + coding->charbuf_used; | |
3996 unsigned char *dst = coding->destination + coding->produced; | |
3997 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
3998 int safe_room = 4; | |
3999 int produced_chars = 0; | |
4000 Lisp_Object attrs, eol_type, charset_list, val; | |
4001 int ascii_compatible; | |
4002 struct charset *charset_roman, *charset_big5; | |
4003 int c; | |
4004 | |
4005 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4006 val = charset_list; | |
4007 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
4008 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
4009 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4010 | |
4011 while (charbuf < charbuf_end) | |
4012 { | |
4013 ASSURE_DESTINATION (safe_room); | |
4014 c = *charbuf++; | |
4015 /* Now encode the character C. */ | |
4016 if (ASCII_CHAR_P (c) && ascii_compatible) | |
4017 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4018 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4019 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4020 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4021 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4022 } |
88365 | 4023 else |
4024 { | |
4025 unsigned code; | |
4026 struct charset *charset = char_charset (c, charset_list, &code); | |
4027 | |
4028 if (! charset) | |
4029 { | |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4030 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
|
4031 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4032 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4033 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4034 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4035 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4036 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4037 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4038 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
|
4039 } |
88365 | 4040 } |
4041 if (code == CHARSET_INVALID_CODE (charset)) | |
4042 abort (); | |
4043 if (charset == charset_big5) | |
4044 { | |
4045 int c1, c2; | |
4046 | |
4047 c1 = code >> 8, c2 = code & 0xFF; | |
4048 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
|
4049 } |
17052 | 4050 else |
88365 | 4051 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
17052 | 4052 } |
88365 | 4053 } |
4054 coding->result = CODING_RESULT_SUCCESS; | |
4055 coding->produced_char += produced_chars; | |
4056 coding->produced = dst - coding->destination; | |
4057 return 0; | |
17052 | 4058 } |
4059 | |
4060 | |
88365 | 4061 /*** 10. CCL handlers ***/ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4062 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4063 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4064 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
|
4065 encoder/decoder are written in CCL program. If it is, return |
88365 | 4066 CATEGORY_MASK_CCL, else return 0. */ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4067 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
4068 static int |
88365 | 4069 detect_coding_ccl (coding, mask) |
4070 struct coding_system *coding; | |
4071 int *mask; | |
4072 { | |
4073 unsigned char *src = coding->source, *src_base = src; | |
4074 unsigned char *src_end = coding->source + coding->src_bytes; | |
4075 int multibytep = coding->src_multibyte; | |
4076 int consumed_chars = 0; | |
4077 int found = 0; | |
4078 unsigned char *valids = CODING_CCL_VALIDS (coding); | |
4079 int head_ascii = coding->head_ascii; | |
4080 Lisp_Object attrs; | |
4081 | |
4082 coding = &coding_categories[coding_category_ccl]; | |
4083 attrs = CODING_ID_ATTRS (coding->id); | |
4084 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4085 src += head_ascii; | |
4086 | |
4087 while (1) | |
4088 { | |
4089 int c; | |
4090 ONE_MORE_BYTE (c); | |
4091 if (! valids[c]) | |
4092 break; | |
4093 if (!found && valids[c] > 1) | |
4094 found = 1; | |
4095 } | |
4096 *mask &= ~CATEGORY_MASK_CCL; | |
4097 return 0; | |
4098 | |
4099 no_more_source: | |
4100 if (!found) | |
4101 return 0; | |
4102 *mask &= CATEGORY_MASK_CCL; | |
4103 return 1; | |
4104 } | |
4105 | |
4106 static void | |
4107 decode_coding_ccl (coding) | |
4108 struct coding_system *coding; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4109 { |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
4110 const unsigned char *src = coding->source + coding->consumed; |
88365 | 4111 unsigned char *src_end = coding->source + coding->src_bytes; |
4112 int *charbuf = coding->charbuf; | |
4113 int *charbuf_end = charbuf + coding->charbuf_size; | |
4114 int consumed_chars = 0; | |
4115 int multibytep = coding->src_multibyte; | |
4116 struct ccl_program ccl; | |
4117 int source_charbuf[1024]; | |
4118 int source_byteidx[1024]; | |
4119 | |
4120 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); | |
4121 | |
4122 while (src < src_end) | |
4123 { | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
4124 const unsigned char *p = src; |
88365 | 4125 int *source, *source_end; |
4126 int i = 0; | |
4127 | |
4128 if (multibytep) | |
4129 while (i < 1024 && p < src_end) | |
4130 { | |
4131 source_byteidx[i] = p - src; | |
4132 source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | |
4133 } | |
4134 else | |
4135 while (i < 1024 && p < src_end) | |
4136 source_charbuf[i++] = *p++; | |
4137 | |
4138 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) | |
4139 ccl.last_block = 1; | |
4140 | |
4141 source = source_charbuf; | |
4142 source_end = source + i; | |
4143 while (source < source_end) | |
4144 { | |
4145 ccl_driver (&ccl, source, charbuf, | |
4146 source_end - source, charbuf_end - charbuf); | |
4147 source += ccl.consumed; | |
4148 charbuf += ccl.produced; | |
4149 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
4150 break; | |
4151 } | |
4152 if (source < source_end) | |
4153 src += source_byteidx[source - source_charbuf]; | |
4154 else | |
4155 src = p; | |
4156 consumed_chars += source - source_charbuf; | |
4157 | |
4158 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
4159 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
4160 break; | |
4161 } | |
4162 | |
4163 switch (ccl.status) | |
4164 { | |
4165 case CCL_STAT_SUSPEND_BY_SRC: | |
4166 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4167 break; | |
4168 case CCL_STAT_SUSPEND_BY_DST: | |
4169 break; | |
4170 case CCL_STAT_QUIT: | |
4171 case CCL_STAT_INVALID_CMD: | |
4172 coding->result = CODING_RESULT_INTERRUPT; | |
4173 break; | |
4174 default: | |
4175 coding->result = CODING_RESULT_SUCCESS; | |
4176 break; | |
4177 } | |
4178 coding->consumed_char += consumed_chars; | |
4179 coding->consumed = src - coding->source; | |
4180 coding->charbuf_used = charbuf - coding->charbuf; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4181 } |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4182 |
88365 | 4183 static int |
4184 encode_coding_ccl (coding) | |
4185 struct coding_system *coding; | |
4186 { | |
4187 struct ccl_program ccl; | |
4188 int multibytep = coding->dst_multibyte; | |
4189 int *charbuf = coding->charbuf; | |
4190 int *charbuf_end = charbuf + coding->charbuf_used; | |
4191 unsigned char *dst = coding->destination + coding->produced; | |
4192 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4193 unsigned char *adjusted_dst_end = dst_end - 1; | |
4194 int destination_charbuf[1024]; | |
4195 int i, produced_chars = 0; | |
4196 | |
4197 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); | |
4198 | |
4199 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; | |
4200 ccl.dst_multibyte = coding->dst_multibyte; | |
4201 | |
4202 while (charbuf < charbuf_end && dst < adjusted_dst_end) | |
4203 { | |
4204 int dst_bytes = dst_end - dst; | |
4205 if (dst_bytes > 1024) | |
4206 dst_bytes = 1024; | |
4207 | |
4208 ccl_driver (&ccl, charbuf, destination_charbuf, | |
4209 charbuf_end - charbuf, dst_bytes); | |
4210 charbuf += ccl.consumed; | |
4211 if (multibytep) | |
4212 for (i = 0; i < ccl.produced; i++) | |
4213 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); | |
4214 else | |
4215 { | |
4216 for (i = 0; i < ccl.produced; i++) | |
4217 *dst++ = destination_charbuf[i] & 0xFF; | |
4218 produced_chars += ccl.produced; | |
4219 } | |
4220 } | |
4221 | |
4222 switch (ccl.status) | |
4223 { | |
4224 case CCL_STAT_SUSPEND_BY_SRC: | |
4225 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
4226 break; | |
4227 case CCL_STAT_SUSPEND_BY_DST: | |
4228 coding->result = CODING_RESULT_INSUFFICIENT_DST; | |
4229 break; | |
4230 case CCL_STAT_QUIT: | |
4231 case CCL_STAT_INVALID_CMD: | |
4232 coding->result = CODING_RESULT_INTERRUPT; | |
4233 break; | |
4234 default: | |
4235 coding->result = CODING_RESULT_SUCCESS; | |
4236 break; | |
4237 } | |
4238 | |
4239 coding->produced_char += produced_chars; | |
4240 coding->produced = dst - coding->destination; | |
4241 return 0; | |
4242 } | |
4243 | |
4244 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4245 |
88365 | 4246 /*** 10, 11. no-conversion handlers ***/ |
17052 | 4247 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4248 /* 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
|
4249 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4250 static void |
88365 | 4251 decode_coding_raw_text (coding) |
17052 | 4252 struct coding_system *coding; |
4253 { | |
88365 | 4254 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
|
4255 coding->consumed_char = 0; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4256 coding->consumed = 0; |
88365 | 4257 coding->result = CODING_RESULT_SUCCESS; |
4258 } | |
4259 | |
4260 static int | |
4261 encode_coding_raw_text (coding) | |
4262 struct coding_system *coding; | |
4263 { | |
4264 int multibytep = coding->dst_multibyte; | |
4265 int *charbuf = coding->charbuf; | |
4266 int *charbuf_end = coding->charbuf + coding->charbuf_used; | |
4267 unsigned char *dst = coding->destination + coding->produced; | |
4268 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4269 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
|
4270 int c; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4271 |
88365 | 4272 if (multibytep) |
4273 { | |
4274 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
4275 | |
4276 if (coding->src_multibyte) | |
4277 while (charbuf < charbuf_end) | |
4278 { | |
4279 ASSURE_DESTINATION (safe_room); | |
4280 c = *charbuf++; | |
4281 if (ASCII_CHAR_P (c)) | |
4282 EMIT_ONE_ASCII_BYTE (c); | |
4283 else if (CHAR_BYTE8_P (c)) | |
4284 { | |
4285 c = CHAR_TO_BYTE8 (c); | |
4286 EMIT_ONE_BYTE (c); | |
4287 } | |
4288 else | |
4289 { | |
4290 unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | |
4291 | |
4292 CHAR_STRING_ADVANCE (c, p1); | |
4293 while (p0 < p1) | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4294 { |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4295 EMIT_ONE_BYTE (*p0); |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4296 p0++; |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4297 } |
88365 | 4298 } |
4299 } | |
4300 else | |
4301 while (charbuf < charbuf_end) | |
4302 { | |
4303 ASSURE_DESTINATION (safe_room); | |
4304 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4305 EMIT_ONE_BYTE (c); |
88365 | 4306 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4307 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4308 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4309 { |
88365 | 4310 if (coding->src_multibyte) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4311 { |
88365 | 4312 int safe_room = MAX_MULTIBYTE_LENGTH; |
4313 | |
4314 while (charbuf < charbuf_end) | |
4315 { | |
4316 ASSURE_DESTINATION (safe_room); | |
4317 c = *charbuf++; | |
4318 if (ASCII_CHAR_P (c)) | |
4319 *dst++ = c; | |
4320 else if (CHAR_BYTE8_P (c)) | |
4321 *dst++ = CHAR_TO_BYTE8 (c); | |
4322 else | |
4323 CHAR_STRING_ADVANCE (c, dst); | |
4324 produced_chars++; | |
4325 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4326 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4327 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4328 { |
88365 | 4329 ASSURE_DESTINATION (charbuf_end - charbuf); |
4330 while (charbuf < charbuf_end && dst < dst_end) | |
4331 *dst++ = *charbuf++; | |
4332 produced_chars = dst - (coding->destination + coding->dst_bytes); | |
4333 } | |
4334 } | |
4335 coding->result = CODING_RESULT_SUCCESS; | |
4336 coding->produced_char += produced_chars; | |
4337 coding->produced = dst - coding->destination; | |
4338 return 0; | |
4339 } | |
4340 | |
4341 static int | |
4342 detect_coding_charset (coding, mask) | |
4343 struct coding_system *coding; | |
4344 int *mask; | |
4345 { | |
4346 unsigned char *src = coding->source, *src_base = src; | |
4347 unsigned char *src_end = coding->source + coding->src_bytes; | |
4348 int multibytep = coding->src_multibyte; | |
4349 int consumed_chars = 0; | |
4350 Lisp_Object attrs, valids; | |
4351 | |
4352 coding = &coding_categories[coding_category_charset]; | |
4353 attrs = CODING_ID_ATTRS (coding->id); | |
4354 valids = AREF (attrs, coding_attr_charset_valids); | |
4355 | |
4356 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
4357 src += coding->head_ascii; | |
4358 | |
4359 while (1) | |
4360 { | |
4361 int c; | |
4362 | |
4363 ONE_MORE_BYTE (c); | |
4364 if (NILP (AREF (valids, c))) | |
4365 break; | |
4366 } | |
4367 *mask &= ~CATEGORY_MASK_CHARSET; | |
4368 return 0; | |
4369 | |
4370 no_more_source: | |
4371 *mask &= CATEGORY_MASK_CHARSET; | |
4372 return 1; | |
4373 } | |
4374 | |
4375 static void | |
4376 decode_coding_charset (coding) | |
4377 struct coding_system *coding; | |
4378 { | |
4379 unsigned char *src = coding->source + coding->consumed; | |
4380 unsigned char *src_end = coding->source + coding->src_bytes; | |
4381 unsigned char *src_base; | |
4382 int *charbuf = coding->charbuf; | |
4383 int *charbuf_end = charbuf + coding->charbuf_size; | |
4384 int consumed_chars = 0, consumed_chars_base; | |
4385 int multibytep = coding->src_multibyte; | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4386 Lisp_Object attrs, eol_type, charset_list, valids; |
88365 | 4387 |
4388 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
|
4389 valids = AREF (attrs, coding_attr_charset_valids); |
88365 | 4390 |
4391 while (1) | |
4392 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4393 int c; |
88365 | 4394 |
4395 src_base = src; | |
4396 consumed_chars_base = consumed_chars; | |
4397 | |
4398 if (charbuf >= charbuf_end) | |
4399 break; | |
4400 | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4401 ONE_MORE_BYTE (c); |
88365 | 4402 if (c == '\r') |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4403 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4404 /* 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
|
4405 else. */ |
88365 | 4406 if (EQ (eol_type, Qdos)) |
4407 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4408 if (src < src_end |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4409 && *src == '\n') |
88365 | 4410 ONE_MORE_BYTE (c); |
4411 } | |
4412 else if (EQ (eol_type, Qmac)) | |
4413 c = '\n'; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4414 } |
88365 | 4415 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4416 { |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4417 Lisp_Object val; |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4418 struct charset *charset; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4419 int dim; |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4420 int len = 1; |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4421 unsigned code = c; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4422 |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4423 val = AREF (valids, c); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4424 if (NILP (val)) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4425 goto invalid_code; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4426 if (INTEGERP (val)) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4427 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4428 charset = CHARSET_FROM_ID (XFASTINT (val)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4429 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4430 while (len < dim) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4431 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4432 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4433 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4434 len++; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4435 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4436 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
|
4437 charset, code, c); |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4438 } |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4439 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4440 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4441 /* 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
|
4442 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
|
4443 comes first). */ |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4444 while (CONSP (val)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4445 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4446 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
|
4447 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4448 while (len < dim) |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4449 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4450 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4451 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4452 len++; |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4453 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4454 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
|
4455 src_end, charset, code, c); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4456 if (c >= 0) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4457 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4458 val = XCDR (val); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4459 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4460 } |
88365 | 4461 if (c < 0) |
4462 goto invalid_code; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4463 } |
88365 | 4464 *charbuf++ = c; |
4465 continue; | |
4466 | |
4467 invalid_code: | |
4468 src = src_base; | |
4469 consumed_chars = consumed_chars_base; | |
4470 ONE_MORE_BYTE (c); | |
4471 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
4472 coding->errors++; | |
4473 } | |
4474 | |
4475 no_more_source: | |
4476 coding->consumed_char += consumed_chars_base; | |
4477 coding->consumed = src_base - coding->source; | |
4478 coding->charbuf_used = charbuf - coding->charbuf; | |
4479 } | |
4480 | |
4481 static int | |
4482 encode_coding_charset (coding) | |
4483 struct coding_system *coding; | |
4484 { | |
4485 int multibytep = coding->dst_multibyte; | |
4486 int *charbuf = coding->charbuf; | |
4487 int *charbuf_end = charbuf + coding->charbuf_used; | |
4488 unsigned char *dst = coding->destination + coding->produced; | |
4489 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4490 int safe_room = MAX_MULTIBYTE_LENGTH; | |
4491 int produced_chars = 0; | |
4492 Lisp_Object attrs, eol_type, charset_list; | |
4493 int ascii_compatible; | |
4494 int c; | |
4495 | |
4496 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
4497 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4498 | |
4499 while (charbuf < charbuf_end) | |
4500 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4501 struct charset *charset; |
88365 | 4502 unsigned code; |
4503 | |
4504 ASSURE_DESTINATION (safe_room); | |
4505 c = *charbuf++; | |
4506 if (ascii_compatible && ASCII_CHAR_P (c)) | |
4507 EMIT_ONE_ASCII_BYTE (c); | |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4508 else if (CHAR_BYTE8_P (c)) |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4509 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4510 c = CHAR_TO_BYTE8 (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4511 EMIT_ONE_BYTE (c); |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4512 } |
88365 | 4513 else |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4514 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4515 charset = char_charset (c, charset_list, &code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4516 if (charset) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4517 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4518 if (CHARSET_DIMENSION (charset) == 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4519 EMIT_ONE_BYTE (code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4520 else if (CHARSET_DIMENSION (charset) == 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4521 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4522 else if (CHARSET_DIMENSION (charset) == 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4523 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
|
4524 else |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4525 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
|
4526 (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4527 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4528 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4529 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4530 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
|
4531 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4532 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4533 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4534 EMIT_ONE_BYTE (c); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4535 } |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4536 } |
88365 | 4537 } |
4538 | |
4539 coding->result = CODING_RESULT_SUCCESS; | |
4540 coding->produced_char += produced_chars; | |
4541 coding->produced = dst - coding->destination; | |
4542 return 0; | |
17052 | 4543 } |
4544 | |
4545 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4546 /*** 7. C library functions ***/ |
17052 | 4547 |
88365 | 4548 /* Setup coding context CODING from information about CODING_SYSTEM. |
4549 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
4550 CODING_SYSTEM is invalid, signal an error. */ | |
4551 | |
4552 void | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4553 setup_coding_system (coding_system, coding) |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4554 Lisp_Object coding_system; |
17052 | 4555 struct coding_system *coding; |
4556 { | |
88365 | 4557 Lisp_Object attrs; |
4558 Lisp_Object eol_type; | |
4559 Lisp_Object coding_type; | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
4560 Lisp_Object val; |
17052 | 4561 |
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
4562 if (NILP (coding_system)) |
88365 | 4563 coding_system = Qno_conversion; |
4564 | |
4565 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
4566 | |
4567 attrs = CODING_ID_ATTRS (coding->id); | |
4568 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4569 | |
4570 coding->mode = 0; | |
4571 coding->head_ascii = -1; | |
4572 coding->common_flags | |
4573 = (VECTORP (eol_type) ? CODING_REQUIRE_DETECTION_MASK : 0); | |
4574 | |
4575 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4576 coding->max_charset_id = XSTRING (val)->size - 1; | |
4577 coding->safe_charsets = (char *) XSTRING (val)->data; | |
4578 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); | |
4579 | |
4580 coding_type = CODING_ATTR_TYPE (attrs); | |
4581 if (EQ (coding_type, Qundecided)) | |
4582 { | |
4583 coding->detector = NULL; | |
4584 coding->decoder = decode_coding_raw_text; | |
4585 coding->encoder = encode_coding_raw_text; | |
4586 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
4587 } | |
4588 else if (EQ (coding_type, Qiso_2022)) | |
4589 { | |
4590 int i; | |
4591 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
4592 | |
4593 /* Invoke graphic register 0 to plane 0. */ | |
4594 CODING_ISO_INVOCATION (coding, 0) = 0; | |
4595 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
4596 CODING_ISO_INVOCATION (coding, 1) | |
4597 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
4598 /* Setup the initial status of designation. */ | |
4599 for (i = 0; i < 4; i++) | |
4600 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
4601 /* Not single shifting initially. */ | |
4602 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
4603 /* Beginning of buffer should also be regarded as bol. */ | |
4604 CODING_ISO_BOL (coding) = 1; | |
4605 coding->detector = detect_coding_iso_2022; | |
4606 coding->decoder = decode_coding_iso_2022; | |
4607 coding->encoder = encode_coding_iso_2022; | |
4608 if (flags & CODING_ISO_FLAG_SAFE) | |
4609 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4610 coding->common_flags |
88365 | 4611 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4612 | CODING_REQUIRE_FLUSHING_MASK); | |
4613 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
4614 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
4615 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
|
4616 { |
88365 | 4617 setup_iso_safe_charsets (attrs); |
4618 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
4619 coding->max_charset_id = XSTRING (val)->size - 1; | |
4620 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
|
4621 } |
88365 | 4622 CODING_ISO_FLAGS (coding) = flags; |
4623 } | |
4624 else if (EQ (coding_type, Qcharset)) | |
4625 { | |
4626 coding->detector = detect_coding_charset; | |
4627 coding->decoder = decode_coding_charset; | |
4628 coding->encoder = encode_coding_charset; | |
4629 coding->common_flags | |
4630 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4631 } | |
4632 else if (EQ (coding_type, Qutf_8)) | |
4633 { | |
4634 coding->detector = detect_coding_utf_8; | |
4635 coding->decoder = decode_coding_utf_8; | |
4636 coding->encoder = encode_coding_utf_8; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
4637 coding->common_flags |
88365 | 4638 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4639 } | |
4640 else if (EQ (coding_type, Qutf_16)) | |
4641 { | |
4642 val = AREF (attrs, coding_attr_utf_16_bom); | |
4643 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_16_detect_bom | |
4644 : EQ (val, Qt) ? utf_16_with_bom | |
4645 : utf_16_without_bom); | |
4646 val = AREF (attrs, coding_attr_utf_16_endian); | |
4647 CODING_UTF_16_ENDIAN (coding) = (NILP (val) ? utf_16_big_endian | |
4648 : utf_16_little_endian); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
4649 CODING_UTF_16_SURROGATE (coding) = 0; |
88365 | 4650 coding->detector = detect_coding_utf_16; |
4651 coding->decoder = decode_coding_utf_16; | |
4652 coding->encoder = encode_coding_utf_16; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4653 coding->common_flags |
88365 | 4654 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4655 } | |
4656 else if (EQ (coding_type, Qccl)) | |
4657 { | |
4658 coding->detector = detect_coding_ccl; | |
4659 coding->decoder = decode_coding_ccl; | |
4660 coding->encoder = encode_coding_ccl; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4661 coding->common_flags |
88365 | 4662 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
4663 | CODING_REQUIRE_FLUSHING_MASK); | |
4664 } | |
4665 else if (EQ (coding_type, Qemacs_mule)) | |
4666 { | |
4667 coding->detector = detect_coding_emacs_mule; | |
4668 coding->decoder = decode_coding_emacs_mule; | |
4669 coding->encoder = encode_coding_emacs_mule; | |
4670 coding->common_flags | |
4671 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4672 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) | |
4673 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
4674 { | |
4675 Lisp_Object tail, safe_charsets; | |
4676 int max_charset_id = 0; | |
4677 | |
4678 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4679 tail = XCDR (tail)) | |
4680 if (max_charset_id < XFASTINT (XCAR (tail))) | |
4681 max_charset_id = XFASTINT (XCAR (tail)); | |
4682 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
4683 make_number (255)); | |
4684 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
4685 tail = XCDR (tail)) | |
4686 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
4687 coding->max_charset_id = max_charset_id; | |
4688 coding->safe_charsets = (char *) XSTRING (safe_charsets)->data; | |
4689 } | |
4690 } | |
4691 else if (EQ (coding_type, Qshift_jis)) | |
4692 { | |
4693 coding->detector = detect_coding_sjis; | |
4694 coding->decoder = decode_coding_sjis; | |
4695 coding->encoder = encode_coding_sjis; | |
4696 coding->common_flags | |
4697 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
4698 } | |
4699 else if (EQ (coding_type, Qbig5)) | |
4700 { | |
4701 coding->detector = detect_coding_big5; | |
4702 coding->decoder = decode_coding_big5; | |
4703 coding->encoder = encode_coding_big5; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4704 coding->common_flags |
88365 | 4705 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
4706 } | |
4707 else /* EQ (coding_type, Qraw_text) */ | |
4708 { | |
4709 coding->detector = NULL; | |
4710 coding->decoder = decode_coding_raw_text; | |
4711 coding->encoder = encode_coding_raw_text; | |
4712 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
4713 } | |
4714 | |
4715 return; | |
17052 | 4716 } |
4717 | |
88365 | 4718 /* Return raw-text or one of its subsidiaries that has the same |
4719 eol_type as CODING-SYSTEM. */ | |
4720 | |
4721 Lisp_Object | |
4722 raw_text_coding_system (coding_system) | |
4723 Lisp_Object coding_system; | |
26847 | 4724 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4725 Lisp_Object spec, attrs; |
88365 | 4726 Lisp_Object eol_type, raw_text_eol_type; |
4727 | |
4728 spec = CODING_SYSTEM_SPEC (coding_system); | |
4729 attrs = AREF (spec, 0); | |
4730 | |
4731 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
4732 return coding_system; | |
4733 | |
4734 eol_type = AREF (spec, 2); | |
4735 if (VECTORP (eol_type)) | |
4736 return Qraw_text; | |
4737 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
4738 raw_text_eol_type = AREF (spec, 2); | |
4739 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
4740 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
4741 : AREF (raw_text_eol_type, 2)); | |
26847 | 4742 } |
4743 | |
88365 | 4744 |
4745 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
4746 does, return one of the subsidiary that has the same eol-spec as | |
4747 PARENT. Otherwise, return CODING_SYSTEM. */ | |
4748 | |
4749 Lisp_Object | |
4750 coding_inherit_eol_type (coding_system, parent) | |
88473 | 4751 Lisp_Object coding_system, parent; |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4752 { |
88365 | 4753 Lisp_Object spec, attrs, eol_type; |
4754 | |
4755 spec = CODING_SYSTEM_SPEC (coding_system); | |
4756 attrs = AREF (spec, 0); | |
4757 eol_type = AREF (spec, 2); | |
4758 if (VECTORP (eol_type)) | |
4759 { | |
4760 Lisp_Object parent_spec; | |
4761 Lisp_Object parent_eol_type; | |
4762 | |
4763 parent_spec | |
4764 = CODING_SYSTEM_SPEC (buffer_defaults.buffer_file_coding_system); | |
4765 parent_eol_type = AREF (parent_spec, 2); | |
4766 if (EQ (parent_eol_type, Qunix)) | |
4767 coding_system = AREF (eol_type, 0); | |
4768 else if (EQ (parent_eol_type, Qdos)) | |
4769 coding_system = AREF (eol_type, 1); | |
4770 else if (EQ (parent_eol_type, Qmac)) | |
4771 coding_system = AREF (eol_type, 2); | |
4772 } | |
4773 return coding_system; | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4774 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4775 |
17052 | 4776 /* Emacs has a mechanism to automatically detect a coding system if it |
4777 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
4778 it's impossible to distinguish some coding systems accurately | |
4779 because they use the same range of codes. So, at first, coding | |
4780 systems are categorized into 7, those are: | |
4781 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4782 o coding-category-emacs-mule |
17052 | 4783 |
4784 The category for a coding system which has the same code range | |
4785 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
|
4786 symbol) `emacs-mule' by default. |
17052 | 4787 |
4788 o coding-category-sjis | |
4789 | |
4790 The category for a coding system which has the same code range | |
4791 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
|
4792 symbol) `japanese-shift-jis' by default. |
17052 | 4793 |
4794 o coding-category-iso-7 | |
4795 | |
4796 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
|
4797 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
|
4798 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
|
4799 charsets. Assigned the coding-system (Lisp symbol) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4800 `iso-2022-7bit' by default. |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4801 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4802 o coding-category-iso-7-tight |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4803 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4804 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
|
4805 encode/decode only the specified charsets. |
17052 | 4806 |
4807 o coding-category-iso-8-1 | |
4808 | |
4809 The category for a coding system which has the same code range | |
4810 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
|
4811 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
|
4812 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
|
4813 symbol) `iso-latin-1' by default. |
17052 | 4814 |
4815 o coding-category-iso-8-2 | |
4816 | |
4817 The category for a coding system which has the same code range | |
4818 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
|
4819 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
|
4820 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
|
4821 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
|
4822 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4823 o coding-category-iso-7-else |
17052 | 4824 |
4825 The category for a coding system which has the same code range | |
88365 | 4826 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
|
4827 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
|
4828 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
|
4829 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4830 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
|
4831 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
4832 The category for a coding system which has the same code range |
88365 | 4833 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
|
4834 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
|
4835 symbol) `iso-2022-8bit-ss2' by default. |
17052 | 4836 |
4837 o coding-category-big5 | |
4838 | |
4839 The category for a coding system which has the same code range | |
4840 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
|
4841 `cn-big5' by default. |
17052 | 4842 |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4843 o coding-category-utf-8 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4844 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4845 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
|
4846 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
|
4847 symbol) `utf-8' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4848 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4849 o coding-category-utf-16-be |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4850 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4851 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
|
4852 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
|
4853 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
|
4854 `utf-16-be' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4855 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4856 o coding-category-utf-16-le |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4857 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4858 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
|
4859 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
|
4860 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
|
4861 symbol) `utf-16-le' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4862 |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4863 o coding-category-ccl |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4864 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4865 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
|
4866 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
|
4867 coding system is assigned. |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4868 |
17052 | 4869 o coding-category-binary |
4870 | |
4871 The category for a coding system not categorized in any of the | |
4872 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
|
4873 `no-conversion' by default. |
17052 | 4874 |
4875 Each of them is a Lisp symbol and the value is an actual | |
88365 | 4876 `coding-system's (this is also a Lisp symbol) assigned by a user. |
17052 | 4877 What Emacs does actually is to detect a category of coding system. |
4878 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
88365 | 4879 decide only one possible category, it selects a category of the |
17052 | 4880 highest priority. Priorities of categories are also specified by a |
4881 user in a Lisp variable `coding-category-list'. | |
4882 | |
4883 */ | |
4884 | |
88365 | 4885 #define EOL_SEEN_NONE 0 |
4886 #define EOL_SEEN_LF 1 | |
4887 #define EOL_SEEN_CR 2 | |
4888 #define EOL_SEEN_CRLF 4 | |
4889 | |
4890 /* Detect how end-of-line of a text of length CODING->src_bytes | |
4891 pointed by CODING->source is encoded. Return one of | |
4892 EOL_SEEN_XXX. */ | |
17052 | 4893 |
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
4894 #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
|
4895 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4896 static int |
88365 | 4897 detect_eol (coding, source, src_bytes) |
4898 struct coding_system *coding; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4899 unsigned char *source; |
88365 | 4900 EMACS_INT src_bytes; |
17052 | 4901 { |
88365 | 4902 Lisp_Object attrs, coding_type; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4903 unsigned char *src = source, *src_end = src + src_bytes; |
17052 | 4904 unsigned char c; |
88365 | 4905 int total = 0; |
4906 int eol_seen = EOL_SEEN_NONE; | |
4907 | |
4908 attrs = CODING_ID_ATTRS (coding->id); | |
4909 coding_type = CODING_ATTR_TYPE (attrs); | |
4910 | |
4911 if (EQ (coding_type, Qccl)) | |
4912 { | |
4913 int msb, lsb; | |
4914 | |
4915 msb = coding->spec.utf_16.endian == utf_16_little_endian; | |
4916 lsb = 1 - msb; | |
4917 | |
4918 while (src + 1 < src_end) | |
17052 | 4919 { |
88365 | 4920 c = src[lsb]; |
4921 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
|
4922 { |
88365 | 4923 int this_eol; |
4924 | |
4925 if (c == '\n') | |
4926 this_eol = EOL_SEEN_LF; | |
4927 else if (src + 3 >= src_end | |
4928 || src[msb + 2] != 0 | |
4929 || src[lsb + 2] != '\n') | |
4930 this_eol = EOL_SEEN_CR; | |
4931 else | |
4932 this_eol = EOL_SEEN_CRLF; | |
4933 | |
4934 if (eol_seen == EOL_SEEN_NONE) | |
4935 /* This is the first end-of-line. */ | |
4936 eol_seen = this_eol; | |
4937 else if (eol_seen != this_eol) | |
4938 { | |
4939 /* The found type is different from what found before. */ | |
4940 eol_seen = EOL_SEEN_LF; | |
4941 break; | |
4942 } | |
4943 if (++total == MAX_EOL_CHECK_COUNT) | |
4944 break; | |
4945 } | |
4946 src += 2; | |
4947 } | |
4948 } | |
4949 else | |
4950 { | |
4951 while (src < src_end) | |
4952 { | |
4953 c = *src++; | |
4954 if (c == '\n' || c == '\r') | |
4955 { | |
4956 int this_eol; | |
4957 | |
4958 if (c == '\n') | |
4959 this_eol = EOL_SEEN_LF; | |
4960 else if (src >= src_end || *src != '\n') | |
4961 this_eol = EOL_SEEN_CR; | |
4962 else | |
4963 this_eol = EOL_SEEN_CRLF, src++; | |
4964 | |
4965 if (eol_seen == EOL_SEEN_NONE) | |
4966 /* This is the first end-of-line. */ | |
4967 eol_seen = this_eol; | |
4968 else if (eol_seen != this_eol) | |
4969 { | |
4970 /* The found type is different from what found before. */ | |
4971 eol_seen = EOL_SEEN_LF; | |
4972 break; | |
4973 } | |
4974 if (++total == MAX_EOL_CHECK_COUNT) | |
4975 break; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4976 } |
17052 | 4977 } |
4978 } | |
88365 | 4979 return eol_seen; |
17052 | 4980 } |
4981 | |
88365 | 4982 |
4983 static void | |
4984 adjust_coding_eol_type (coding, eol_seen) | |
4985 struct coding_system *coding; | |
4986 int eol_seen; | |
4987 { | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4988 Lisp_Object eol_type; |
88365 | 4989 |
4990 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
4991 if (eol_seen & EOL_SEEN_LF) | |
4992 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); | |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
4993 else if (eol_seen & EOL_SEEN_CRLF) |
88365 | 4994 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
4995 else if (eol_seen & EOL_SEEN_CR) |
88365 | 4996 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); |
4997 } | |
4998 | |
4999 /* Detect how a text specified in CODING is encoded. If a coding | |
5000 system is detected, update fields of CODING by the detected coding | |
5001 system. */ | |
5002 | |
5003 void | |
5004 detect_coding (coding) | |
5005 struct coding_system *coding; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5006 { |
88365 | 5007 unsigned char *src, *src_end; |
5008 Lisp_Object attrs, coding_type; | |
5009 | |
5010 coding->consumed = coding->consumed_char = 0; | |
5011 coding->produced = coding->produced_char = 0; | |
5012 coding_set_source (coding); | |
5013 | |
5014 src_end = coding->source + coding->src_bytes; | |
5015 | |
5016 /* If we have not yet decided the text encoding type, detect it | |
5017 now. */ | |
5018 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
5019 { | |
5020 int mask = CATEGORY_MASK_ANY; | |
5021 int c, i; | |
5022 | |
5023 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
|
5024 { |
88365 | 5025 c = *src; |
5026 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
5027 || c == ISO_CODE_SI | |
5028 || c == ISO_CODE_SO))) | |
5029 break; | |
5030 } | |
5031 coding->head_ascii = src - (coding->source + coding->consumed); | |
5032 | |
5033 if (coding->head_ascii < coding->src_bytes) | |
5034 { | |
5035 int detected = 0; | |
5036 | |
5037 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
|
5038 { |
88365 | 5039 enum coding_category category = coding_priorities[i]; |
5040 struct coding_system *this = coding_categories + category; | |
5041 | |
5042 if (category >= coding_category_raw_text | |
5043 || detected & (1 << category)) | |
5044 continue; | |
5045 | |
5046 if (this->id < 0) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5047 { |
88365 | 5048 /* No coding system of this category is defined. */ |
5049 mask &= ~(1 << category); | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5050 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5051 else |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5052 { |
88365 | 5053 detected |= detected_mask[category]; |
5054 if ((*(this->detector)) (coding, &mask)) | |
5055 break; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5056 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5057 } |
88365 | 5058 if (! mask) |
5059 setup_coding_system (Qraw_text, coding); | |
5060 else if (mask != CATEGORY_MASK_ANY) | |
5061 for (i = 0; i < coding_category_raw_text; i++) | |
5062 { | |
5063 enum coding_category category = coding_priorities[i]; | |
5064 struct coding_system *this = coding_categories + category; | |
5065 | |
5066 if (mask & (1 << category)) | |
5067 { | |
5068 setup_coding_system (CODING_ID_NAME (this->id), coding); | |
5069 break; | |
5070 } | |
5071 } | |
5072 } | |
5073 } | |
5074 | |
5075 attrs = CODING_ID_ATTRS (coding->id); | |
5076 coding_type = CODING_ATTR_TYPE (attrs); | |
5077 | |
5078 /* If we have not yet decided the EOL type, detect it now. But, the | |
5079 detection is impossible for a CCL based coding system, in which | |
5080 case, we detct the EOL type after decoding. */ | |
5081 if (VECTORP (CODING_ID_EOL_TYPE (coding->id)) | |
5082 && ! EQ (coding_type, Qccl)) | |
5083 { | |
5084 int eol_seen = detect_eol (coding, coding->source, coding->src_bytes); | |
5085 | |
5086 if (eol_seen != EOL_SEEN_NONE) | |
5087 adjust_coding_eol_type (coding, eol_seen); | |
5088 } | |
5089 } | |
5090 | |
5091 | |
5092 static void | |
5093 decode_eol (coding) | |
5094 struct coding_system *coding; | |
5095 { | |
5096 if (VECTORP (CODING_ID_EOL_TYPE (coding->id))) | |
5097 { | |
5098 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5099 unsigned char *pend = p + coding->produced; | |
5100 int eol_seen = EOL_SEEN_NONE; | |
5101 | |
5102 for (; p < pend; p++) | |
5103 { | |
5104 if (*p == '\n') | |
5105 eol_seen |= EOL_SEEN_LF; | |
5106 else if (*p == '\r') | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5107 { |
88365 | 5108 if (p + 1 < pend && *(p + 1) == '\n') |
5109 { | |
5110 eol_seen |= EOL_SEEN_CRLF; | |
5111 p++; | |
5112 } | |
5113 else | |
5114 eol_seen |= EOL_SEEN_CR; | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5115 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5116 } |
88365 | 5117 if (eol_seen != EOL_SEEN_NONE) |
5118 adjust_coding_eol_type (coding, eol_seen); | |
5119 } | |
5120 | |
5121 if (EQ (CODING_ID_EOL_TYPE (coding->id), Qmac)) | |
5122 { | |
5123 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
5124 unsigned char *pend = p + coding->produced; | |
5125 | |
5126 for (; p < pend; p++) | |
5127 if (*p == '\r') | |
5128 *p = '\n'; | |
5129 } | |
5130 else if (EQ (CODING_ID_EOL_TYPE (coding->id), Qdos)) | |
5131 { | |
5132 unsigned char *p, *pbeg, *pend; | |
5133 Lisp_Object undo_list; | |
5134 | |
5135 move_gap_both (coding->dst_pos + coding->produced_char, | |
5136 coding->dst_pos_byte + coding->produced); | |
5137 undo_list = current_buffer->undo_list; | |
5138 current_buffer->undo_list = Qt; | |
88856 | 5139 del_range_2 (coding->dst_pos, coding->dst_pos_byte, GPT, GPT_BYTE, 0); |
88365 | 5140 current_buffer->undo_list = undo_list; |
5141 pbeg = GPT_ADDR; | |
5142 pend = pbeg + coding->produced; | |
5143 | |
5144 for (p = pend - 1; p >= pbeg; p--) | |
5145 if (*p == '\r') | |
5146 { | |
5147 safe_bcopy ((char *) (p + 1), (char *) p, pend - p - 1); | |
5148 pend--; | |
5149 } | |
5150 coding->produced_char -= coding->produced - (pend - pbeg); | |
5151 coding->produced = pend - pbeg; | |
5152 insert_from_gap (coding->produced_char, coding->produced); | |
17052 | 5153 } |
5154 } | |
5155 | |
88365 | 5156 static void |
5157 translate_chars (coding, table) | |
17052 | 5158 struct coding_system *coding; |
88365 | 5159 Lisp_Object table; |
17052 | 5160 { |
88365 | 5161 int *charbuf = coding->charbuf; |
5162 int *charbuf_end = charbuf + coding->charbuf_used; | |
5163 int c; | |
5164 | |
5165 if (coding->chars_at_source) | |
5166 return; | |
5167 | |
5168 while (charbuf < charbuf_end) | |
5169 { | |
5170 c = *charbuf; | |
5171 if (c < 0) | |
5172 charbuf += c; | |
5173 else | |
5174 *charbuf++ = translate_char (table, c); | |
5175 } | |
17052 | 5176 } |
5177 | |
88365 | 5178 static int |
5179 produce_chars (coding) | |
5180 struct coding_system *coding; | |
17052 | 5181 { |
88365 | 5182 unsigned char *dst = coding->destination + coding->produced; |
5183 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5184 int produced; | |
5185 int produced_chars = 0; | |
5186 | |
5187 if (! coding->chars_at_source) | |
5188 { | |
5189 /* Characters are in coding->charbuf. */ | |
5190 int *buf = coding->charbuf; | |
5191 int *buf_end = buf + coding->charbuf_used; | |
5192 unsigned char *adjusted_dst_end; | |
5193 | |
5194 if (BUFFERP (coding->src_object) | |
5195 && EQ (coding->src_object, coding->dst_object)) | |
5196 dst_end = coding->source + coding->consumed; | |
5197 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5198 | |
5199 while (buf < buf_end) | |
5200 { | |
5201 int c = *buf++; | |
5202 | |
5203 if (dst >= adjusted_dst_end) | |
5204 { | |
5205 dst = alloc_destination (coding, | |
5206 buf_end - buf + MAX_MULTIBYTE_LENGTH, | |
5207 dst); | |
5208 dst_end = coding->destination + coding->dst_bytes; | |
5209 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
5210 } | |
5211 if (c >= 0) | |
5212 { | |
5213 if (coding->dst_multibyte | |
5214 || ! CHAR_BYTE8_P (c)) | |
5215 CHAR_STRING_ADVANCE (c, dst); | |
5216 else | |
5217 *dst++ = CHAR_TO_BYTE8 (c); | |
5218 produced_chars++; | |
5219 } | |
5220 else | |
5221 /* This is an annotation data. */ | |
5222 buf -= c + 1; | |
5223 } | |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5224 } |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5225 else |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5226 { |
88365 | 5227 unsigned char *src = coding->source; |
5228 unsigned char *src_end = src + coding->src_bytes; | |
5229 Lisp_Object eol_type; | |
5230 | |
5231 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5232 | |
5233 if (coding->src_multibyte != coding->dst_multibyte) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5234 { |
88365 | 5235 if (coding->src_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5236 { |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5237 int multibytep = 1; |
88365 | 5238 int consumed_chars; |
5239 | |
5240 while (1) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5241 { |
88365 | 5242 unsigned char *src_base = src; |
5243 int c; | |
5244 | |
5245 ONE_MORE_BYTE (c); | |
5246 if (c == '\r') | |
5247 { | |
5248 if (EQ (eol_type, Qdos)) | |
5249 { | |
5250 if (src < src_end | |
5251 && *src == '\n') | |
5252 c = *src++; | |
5253 } | |
5254 else if (EQ (eol_type, Qmac)) | |
5255 c = '\n'; | |
5256 } | |
5257 if (dst == dst_end) | |
5258 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5259 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
|
5260 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5261 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
|
5262 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5263 if (dst == dst_end) |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5264 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5265 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
|
5266 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5267 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
|
5268 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5269 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
|
5270 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
|
5271 } |
88365 | 5272 } |
5273 *dst++ = c; | |
5274 produced_chars++; | |
5275 } | |
5276 no_more_source: | |
5277 ; | |
5278 } | |
5279 else | |
5280 while (src < src_end) | |
5281 { | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5282 int multibytep = 1; |
88365 | 5283 int c = *src++; |
5284 | |
5285 if (c == '\r') | |
5286 { | |
5287 if (EQ (eol_type, Qdos)) | |
5288 { | |
5289 if (src < src_end | |
5290 && *src == '\n') | |
5291 c = *src++; | |
5292 } | |
5293 else if (EQ (eol_type, Qmac)) | |
5294 c = '\n'; | |
5295 } | |
5296 if (dst >= dst_end - 1) | |
5297 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5298 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
|
5299 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5300 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
|
5301 dst_end = src; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5302 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
|
5303 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5304 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
|
5305 dst); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5306 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
|
5307 coding_set_source (coding); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5308 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
|
5309 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
|
5310 } |
88365 | 5311 } |
5312 EMIT_ONE_BYTE (c); | |
5313 } | |
5314 } | |
5315 else | |
5316 { | |
5317 if (!EQ (coding->src_object, coding->dst_object)) | |
5318 { | |
5319 int require = coding->src_bytes - coding->dst_bytes; | |
5320 | |
5321 if (require > 0) | |
5322 { | |
5323 EMACS_INT offset = src - coding->source; | |
5324 | |
5325 dst = alloc_destination (coding, require, dst); | |
5326 coding_set_source (coding); | |
5327 src = coding->source + offset; | |
5328 src_end = coding->source + coding->src_bytes; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5329 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5330 } |
88365 | 5331 produced_chars = coding->src_chars; |
5332 while (src < src_end) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5333 { |
88365 | 5334 int c = *src++; |
5335 | |
5336 if (c == '\r') | |
5337 { | |
5338 if (EQ (eol_type, Qdos)) | |
5339 { | |
5340 if (src < src_end | |
5341 && *src == '\n') | |
5342 c = *src++; | |
5343 produced_chars--; | |
5344 } | |
5345 else if (EQ (eol_type, Qmac)) | |
5346 c = '\n'; | |
5347 } | |
5348 *dst++ = c; | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5349 } |
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5350 } |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5351 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
|
5352 coding->consumed_char = coding->src_chars; |
88365 | 5353 } |
5354 | |
5355 produced = dst - (coding->destination + coding->produced); | |
5356 if (BUFFERP (coding->dst_object)) | |
5357 insert_from_gap (produced_chars, produced); | |
5358 coding->produced += produced; | |
5359 coding->produced_char += produced_chars; | |
5360 return produced_chars; | |
5361 } | |
5362 | |
5363 /* [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN ] | |
5364 or | |
5365 [ -LENGTH CHAR_POS_OFFSET MASK METHOD COMP_LEN COMPONENTS... ] | |
5366 */ | |
5367 | |
5368 static INLINE void | |
5369 produce_composition (coding, charbuf) | |
5370 struct coding_system *coding; | |
5371 int *charbuf; | |
5372 { | |
5373 Lisp_Object buffer; | |
5374 int len; | |
5375 EMACS_INT pos; | |
5376 enum composition_method method; | |
5377 int cmp_len; | |
5378 Lisp_Object components; | |
5379 | |
5380 buffer = coding->dst_object; | |
5381 len = -charbuf[0]; | |
5382 pos = coding->dst_pos + charbuf[1]; | |
5383 method = (enum composition_method) (charbuf[3]); | |
5384 cmp_len = charbuf[4]; | |
5385 | |
5386 if (method == COMPOSITION_RELATIVE) | |
5387 components = Qnil; | |
5388 else | |
5389 { | |
5390 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
5391 int i; | |
5392 | |
5393 len -= 5; | |
5394 charbuf += 5; | |
5395 for (i = 0; i < len; i++) | |
5396 args[i] = make_number (charbuf[i]); | |
5397 components = (method == COMPOSITION_WITH_ALTCHARS | |
5398 ? Fstring (len, args) : Fvector (len, args)); | |
5399 } | |
5400 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
|
5401 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5402 |
88365 | 5403 static int * |
5404 save_composition_data (buf, buf_end, prop) | |
5405 int *buf, *buf_end; | |
5406 Lisp_Object prop; | |
5407 { | |
5408 enum composition_method method = COMPOSITION_METHOD (prop); | |
5409 int cmp_len = COMPOSITION_LENGTH (prop); | |
5410 | |
5411 if (buf + 4 + (MAX_COMPOSITION_COMPONENTS * 2 - 1) > buf_end) | |
5412 return NULL; | |
5413 | |
5414 buf[1] = CODING_ANNOTATE_COMPOSITION_MASK; | |
5415 buf[2] = method; | |
5416 buf[3] = cmp_len; | |
5417 | |
5418 if (method == COMPOSITION_RELATIVE) | |
5419 buf[0] = 4; | |
5420 else | |
5421 { | |
5422 Lisp_Object components; | |
5423 int len, i; | |
5424 | |
5425 components = COMPOSITION_COMPONENTS (prop); | |
5426 if (VECTORP (components)) | |
5427 { | |
5428 len = XVECTOR (components)->size; | |
5429 for (i = 0; i < len; i++) | |
5430 buf[4 + i] = XINT (AREF (components, i)); | |
5431 } | |
5432 else if (STRINGP (components)) | |
5433 { | |
5434 int i_byte; | |
5435 | |
5436 len = XSTRING (components)->size; | |
5437 i = i_byte = 0; | |
5438 while (i < len) | |
5439 FETCH_STRING_CHAR_ADVANCE (buf[4 + i], components, i, i_byte); | |
5440 } | |
5441 else if (INTEGERP (components)) | |
5442 { | |
5443 len = 1; | |
5444 buf[4] = XINT (components); | |
5445 } | |
5446 else if (CONSP (components)) | |
5447 { | |
5448 for (len = 0; CONSP (components); | |
5449 len++, components = XCDR (components)) | |
5450 buf[4 + len] = XINT (XCAR (components)); | |
5451 } | |
5452 else | |
5453 abort (); | |
5454 buf[0] = 4 + len; | |
5455 } | |
5456 return (buf + buf[0]); | |
5457 } | |
5458 | |
5459 #define CHARBUF_SIZE 0x4000 | |
5460 | |
5461 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
5462 do { \ | |
5463 int size = CHARBUF_SIZE;; \ | |
5464 \ | |
5465 coding->charbuf = NULL; \ | |
5466 while (size > 1024) \ | |
5467 { \ | |
5468 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
5469 if (coding->charbuf) \ | |
5470 break; \ | |
5471 size >>= 1; \ | |
5472 } \ | |
5473 if (! coding->charbuf) \ | |
5474 { \ | |
5475 coding->result = CODING_RESULT_INSUFFICIENT_MEM; \ | |
5476 return coding->result; \ | |
5477 } \ | |
5478 coding->charbuf_size = size; \ | |
5479 } while (0) | |
5480 | |
29725
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 static void |
88365 | 5483 produce_annotation (coding) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5484 struct coding_system *coding; |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5485 { |
88365 | 5486 int *charbuf = coding->charbuf; |
5487 int *charbuf_end = charbuf + coding->charbuf_used; | |
5488 | |
5489 while (charbuf < charbuf_end) | |
5490 { | |
5491 if (*charbuf >= 0) | |
5492 charbuf++; | |
5493 else | |
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
5494 { |
88365 | 5495 int len = -*charbuf; |
5496 switch (charbuf[2]) | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5497 { |
88365 | 5498 case CODING_ANNOTATE_COMPOSITION_MASK: |
5499 produce_composition (coding, charbuf); | |
5500 break; | |
5501 default: | |
5502 abort (); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5503 } |
88365 | 5504 charbuf += len; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5505 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5506 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5507 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5508 |
88365 | 5509 /* Decode the data at CODING->src_object into CODING->dst_object. |
5510 CODING->src_object is a buffer, a string, or nil. | |
5511 CODING->dst_object is a buffer. | |
5512 | |
5513 If CODING->src_object is a buffer, it must be the current buffer. | |
5514 In this case, if CODING->src_pos is positive, it is a position of | |
5515 the source text in the buffer, otherwise, the source text is in the | |
5516 gap area of the buffer, and CODING->src_pos specifies the offset of | |
5517 the text from GPT (which must be the same as PT). If this is the | |
5518 same buffer as CODING->dst_object, CODING->src_pos must be | |
5519 negative. | |
5520 | |
5521 If CODING->src_object is a string, CODING->src_pos in an index to | |
5522 that string. | |
5523 | |
5524 If CODING->src_object is nil, CODING->source must already point to | |
5525 the non-relocatable memory area. In this case, CODING->src_pos is | |
5526 an offset from CODING->source. | |
5527 | |
5528 The decoded data is inserted at the current point of the buffer | |
5529 CODING->dst_object. | |
5530 */ | |
5531 | |
5532 static int | |
5533 decode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5534 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5535 { |
88365 | 5536 Lisp_Object attrs; |
5537 | |
5538 if (BUFFERP (coding->src_object) | |
5539 && coding->src_pos > 0 | |
5540 && coding->src_pos < GPT | |
5541 && coding->src_pos + coding->src_chars > GPT) | |
5542 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
5543 | |
5544 if (BUFFERP (coding->dst_object)) | |
5545 { | |
5546 if (current_buffer != XBUFFER (coding->dst_object)) | |
5547 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5548 if (GPT != PT) | |
5549 move_gap_both (PT, PT_BYTE); | |
5550 } | |
5551 | |
5552 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
|
5553 coding->produced = coding->produced_char = 0; |
88365 | 5554 coding->chars_at_source = 0; |
5555 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
|
5556 coding->errors = 0; |
88365 | 5557 |
5558 ALLOC_CONVERSION_WORK_AREA (coding); | |
5559 | |
5560 attrs = CODING_ID_ATTRS (coding->id); | |
5561 | |
5562 do | |
5563 { | |
5564 coding_set_source (coding); | |
5565 coding->annotated = 0; | |
5566 (*(coding->decoder)) (coding); | |
5567 if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | |
5568 translate_chars (CODING_ATTR_DECODE_TBL (attrs), coding); | |
5569 coding_set_destination (coding); | |
5570 produce_chars (coding); | |
5571 if (coding->annotated) | |
5572 produce_annotation (coding); | |
5573 } | |
5574 while (coding->consumed < coding->src_bytes | |
5575 && ! coding->result); | |
5576 | |
5577 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qccl) | |
5578 && SYMBOLP (CODING_ID_EOL_TYPE (coding->id)) | |
5579 && ! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix)) | |
5580 decode_eol (coding); | |
5581 | |
5582 coding->carryover_bytes = 0; | |
5583 if (coding->consumed < coding->src_bytes) | |
5584 { | |
5585 int nbytes = coding->src_bytes - coding->consumed; | |
5586 unsigned char *src; | |
5587 | |
5588 coding_set_source (coding); | |
5589 coding_set_destination (coding); | |
5590 src = coding->source + coding->consumed; | |
5591 | |
5592 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
|
5593 { |
88365 | 5594 /* Flush out unprocessed data as binary chars. We are sure |
5595 that the number of data is less than the size of | |
5596 coding->charbuf. */ | |
5597 int *charbuf = coding->charbuf; | |
5598 | |
5599 while (nbytes-- > 0) | |
5600 { | |
5601 int c = *src++; | |
5602 *charbuf++ = (c & 0x80 ? - c : c); | |
5603 } | |
5604 produce_chars (coding); | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5605 } |
88365 | 5606 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5607 { |
88365 | 5608 /* Record unprocessed bytes in coding->carryover. We are |
5609 sure that the number of data is less than the size of | |
5610 coding->carryover. */ | |
5611 unsigned char *p = coding->carryover; | |
5612 | |
5613 coding->carryover_bytes = nbytes; | |
5614 while (nbytes-- > 0) | |
5615 *p++ = *src++; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5616 } |
88365 | 5617 coding->consumed = coding->src_bytes; |
5618 } | |
5619 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5620 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5621 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5622 |
88365 | 5623 static void |
5624 consume_chars (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5625 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5626 { |
88365 | 5627 int *buf = coding->charbuf; |
5628 /* -1 is to compensate for CRLF. */ | |
5629 int *buf_end = coding->charbuf + coding->charbuf_size - 1; | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
5630 const unsigned char *src = coding->source + coding->consumed; |
88365 | 5631 int pos = coding->src_pos + coding->consumed_char; |
5632 int end_pos = coding->src_pos + coding->src_chars; | |
5633 int multibytep = coding->src_multibyte; | |
5634 Lisp_Object eol_type; | |
5635 int c; | |
5636 int start, end, stop; | |
5637 Lisp_Object object, prop; | |
5638 | |
5639 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
5640 if (VECTORP (eol_type)) | |
5641 eol_type = Qunix; | |
5642 | |
5643 object = coding->src_object; | |
5644 | |
5645 /* Note: composition handling is not yet implemented. */ | |
5646 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
5647 | |
5648 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK | |
5649 && find_composition (pos, end_pos, &start, &end, &prop, object) | |
5650 && end <= end_pos | |
5651 && (start >= pos | |
5652 || (find_composition (end, end_pos, &start, &end, &prop, object) | |
5653 && end <= end_pos))) | |
5654 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5655 else |
88365 | 5656 stop = end_pos; |
5657 | |
5658 while (buf < buf_end) | |
5659 { | |
5660 if (pos == stop) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5661 { |
88365 | 5662 int *p; |
5663 | |
5664 if (pos == end_pos) | |
5665 break; | |
5666 p = save_composition_data (buf, buf_end, prop); | |
5667 if (p == NULL) | |
5668 break; | |
5669 buf = p; | |
5670 if (find_composition (end, end_pos, &start, &end, &prop, object) | |
5671 && end <= end_pos) | |
5672 stop = start; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5673 else |
88365 | 5674 stop = end_pos; |
5675 } | |
5676 | |
5677 if (! multibytep) | |
5678 c = *src++; | |
5679 else | |
5680 c = STRING_CHAR_ADVANCE (src); | |
5681 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) | |
5682 c = '\n'; | |
5683 if (! EQ (eol_type, Qunix)) | |
5684 { | |
5685 if (c == '\n') | |
5686 { | |
5687 if (EQ (eol_type, Qdos)) | |
5688 *buf++ = '\r'; | |
5689 else | |
5690 c = '\r'; | |
5691 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5692 } |
88365 | 5693 *buf++ = c; |
5694 pos++; | |
5695 } | |
5696 | |
5697 coding->consumed = src - coding->source; | |
5698 coding->consumed_char = pos - coding->src_pos; | |
5699 coding->charbuf_used = buf - coding->charbuf; | |
5700 coding->chars_at_source = 0; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5701 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5702 |
88365 | 5703 |
5704 /* Encode the text at CODING->src_object into CODING->dst_object. | |
5705 CODING->src_object is a buffer or a string. | |
5706 CODING->dst_object is a buffer or nil. | |
5707 | |
5708 If CODING->src_object is a buffer, it must be the current buffer. | |
5709 In this case, if CODING->src_pos is positive, it is a position of | |
5710 the source text in the buffer, otherwise. the source text is in the | |
5711 gap area of the buffer, and coding->src_pos specifies the offset of | |
5712 the text from GPT (which must be the same as PT). If this is the | |
5713 same buffer as CODING->dst_object, CODING->src_pos must be | |
5714 negative and CODING should not have `pre-write-conversion'. | |
5715 | |
5716 If CODING->src_object is a string, CODING should not have | |
5717 `pre-write-conversion'. | |
5718 | |
5719 If CODING->dst_object is a buffer, the encoded data is inserted at | |
5720 the current point of that buffer. | |
5721 | |
5722 If CODING->dst_object is nil, the encoded data is placed at the | |
5723 memory area specified by CODING->destination. */ | |
5724 | |
5725 static int | |
5726 encode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5727 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5728 { |
88365 | 5729 Lisp_Object attrs; |
5730 | |
5731 attrs = CODING_ID_ATTRS (coding->id); | |
5732 | |
5733 if (BUFFERP (coding->dst_object)) | |
5734 { | |
5735 set_buffer_internal (XBUFFER (coding->dst_object)); | |
5736 coding->dst_multibyte | |
5737 = ! NILP (current_buffer->enable_multibyte_characters); | |
5738 } | |
5739 | |
5740 coding->consumed = coding->consumed_char = 0; | |
5741 coding->produced = coding->produced_char = 0; | |
5742 coding->result = CODING_RESULT_SUCCESS; | |
5743 coding->errors = 0; | |
5744 | |
5745 ALLOC_CONVERSION_WORK_AREA (coding); | |
5746 | |
5747 do { | |
5748 coding_set_source (coding); | |
5749 consume_chars (coding); | |
5750 | |
5751 if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | |
5752 translate_chars (CODING_ATTR_ENCODE_TBL (attrs), coding); | |
5753 | |
5754 coding_set_destination (coding); | |
5755 (*(coding->encoder)) (coding); | |
5756 } while (coding->consumed_char < coding->src_chars); | |
5757 | |
5758 if (BUFFERP (coding->dst_object)) | |
5759 insert_from_gap (coding->produced_char, coding->produced); | |
5760 | |
5761 return (coding->result); | |
5762 } | |
5763 | |
5764 /* Work buffer */ | |
5765 | |
5766 /* List of currently used working buffer. */ | |
5767 Lisp_Object Vcode_conversion_work_buf_list; | |
5768 | |
5769 /* A working buffer used by the top level conversion. */ | |
5770 Lisp_Object Vcode_conversion_reused_work_buf; | |
5771 | |
5772 | |
5773 /* Return a working buffer that can be freely used by the following | |
5774 code conversion. MULTIBYTEP specifies the multibyteness of the | |
5775 buffer. */ | |
5776 | |
5777 Lisp_Object | |
5778 make_conversion_work_buffer (multibytep) | |
5779 int multibytep; | |
5780 { | |
5781 struct buffer *current = current_buffer; | |
5782 Lisp_Object buf; | |
5783 | |
5784 if (NILP (Vcode_conversion_work_buf_list)) | |
5785 { | |
5786 if (NILP (Vcode_conversion_reused_work_buf)) | |
5787 Vcode_conversion_reused_work_buf | |
5788 = Fget_buffer_create (build_string (" *code-conversion-work*")); | |
5789 Vcode_conversion_work_buf_list | |
5790 = 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
|
5791 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5792 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5793 { |
88856 | 5794 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); |
88365 | 5795 char str[128]; |
5796 | |
5797 sprintf (str, " *code-conversion-work*<%d>", depth); | |
5798 Vcode_conversion_work_buf_list | |
5799 = Fcons (Fget_buffer_create (build_string (str)), | |
5800 Vcode_conversion_work_buf_list); | |
5801 } | |
5802 | |
5803 buf = XCAR (Vcode_conversion_work_buf_list); | |
5804 set_buffer_internal (XBUFFER (buf)); | |
5805 current_buffer->undo_list = Qt; | |
5806 Ferase_buffer (); | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
5807 Fset_buffer_multibyte (multibytep ? Qt : Qnil, Qnil); |
88365 | 5808 set_buffer_internal (current); |
5809 return buf; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5810 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5811 |
88365 | 5812 static struct coding_system *saved_coding; |
5813 | |
5814 Lisp_Object | |
5815 code_conversion_restore (info) | |
5816 Lisp_Object info; | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5817 { |
88856 | 5818 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); |
88365 | 5819 Lisp_Object buf; |
5820 | |
5821 if (depth > 0) | |
5822 { | |
5823 buf = XCAR (Vcode_conversion_work_buf_list); | |
5824 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); | |
5825 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) | |
5826 Fkill_buffer (buf); | |
5827 } | |
5828 | |
88856 | 5829 if (EQ (saved_coding->dst_object, Qt) |
88365 | 5830 && saved_coding->destination) |
5831 xfree (saved_coding->destination); | |
5832 | |
5833 return save_excursion_restore (info); | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5834 } |
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
5835 |
88365 | 5836 |
5837 int | |
5838 decode_coding_gap (coding, chars, bytes) | |
26847 | 5839 struct coding_system *coding; |
88365 | 5840 EMACS_INT chars, bytes; |
5841 { | |
5842 int count = specpdl_ptr - specpdl; | |
5843 | |
5844 saved_coding = coding; | |
5845 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5846 | |
5847 coding->src_object = Fcurrent_buffer (); | |
5848 coding->src_chars = chars; | |
5849 coding->src_bytes = bytes; | |
5850 coding->src_pos = -chars; | |
5851 coding->src_pos_byte = -bytes; | |
5852 coding->src_multibyte = chars < bytes; | |
5853 coding->dst_object = coding->src_object; | |
5854 coding->dst_pos = PT; | |
5855 coding->dst_pos_byte = PT_BYTE; | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5856 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
88365 | 5857 |
5858 if (CODING_REQUIRE_DETECTION (coding)) | |
5859 detect_coding (coding); | |
5860 | |
5861 decode_coding (coding); | |
5862 | |
5863 unbind_to (count, Qnil); | |
5864 return coding->result; | |
5865 } | |
5866 | |
5867 int | |
5868 encode_coding_gap (coding, chars, bytes) | |
5869 struct coding_system *coding; | |
5870 EMACS_INT chars, bytes; | |
26847 | 5871 { |
88365 | 5872 int count = specpdl_ptr - specpdl; |
5873 Lisp_Object buffer; | |
5874 | |
5875 saved_coding = coding; | |
5876 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5877 | |
5878 buffer = Fcurrent_buffer (); | |
5879 coding->src_object = buffer; | |
5880 coding->src_chars = chars; | |
5881 coding->src_bytes = bytes; | |
5882 coding->src_pos = -chars; | |
5883 coding->src_pos_byte = -bytes; | |
5884 coding->src_multibyte = chars < bytes; | |
5885 coding->dst_object = coding->src_object; | |
5886 coding->dst_pos = PT; | |
5887 coding->dst_pos_byte = PT_BYTE; | |
5888 | |
5889 encode_coding (coding); | |
5890 | |
5891 unbind_to (count, Qnil); | |
5892 return coding->result; | |
26847 | 5893 } |
5894 | |
88365 | 5895 |
5896 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
5897 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
5898 | |
5899 SRC_OBJECT is a buffer, a string, or Qnil. | |
5900 | |
5901 If it is a buffer, the text is at point of the buffer. FROM and TO | |
5902 are positions in the buffer. | |
5903 | |
5904 If it is a string, the text is at the beginning of the string. | |
5905 FROM and TO are indices to the string. | |
5906 | |
5907 If it is nil, the text is at coding->source. FROM and TO are | |
5908 indices to coding->source. | |
5909 | |
5910 DST_OBJECT is a buffer, Qt, or Qnil. | |
5911 | |
5912 If it is a buffer, the decoded text is inserted at point of the | |
5913 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
5914 is deleted. | |
5915 | |
5916 If it is Qt, a string is made from the decoded text, and | |
5917 set in CODING->dst_object. | |
5918 | |
5919 If it is Qnil, the decoded text is stored at CODING->destination. | |
5920 The called must allocate CODING->dst_bytes bytes at | |
5921 CODING->destination by xmalloc. If the decoded text is longer than | |
5922 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
5923 */ | |
26847 | 5924 |
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
5925 void |
88365 | 5926 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
5927 dst_object) | |
26847 | 5928 struct coding_system *coding; |
88365 | 5929 Lisp_Object src_object; |
5930 EMACS_INT from, from_byte, to, to_byte; | |
5931 Lisp_Object dst_object; | |
26847 | 5932 { |
88365 | 5933 int count = specpdl_ptr - specpdl; |
5934 unsigned char *destination; | |
5935 EMACS_INT dst_bytes; | |
5936 EMACS_INT chars = to - from; | |
5937 EMACS_INT bytes = to_byte - from_byte; | |
5938 Lisp_Object attrs; | |
5939 | |
5940 saved_coding = coding; | |
5941 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
5942 | |
5943 if (NILP (dst_object)) | |
5944 { | |
5945 destination = coding->destination; | |
5946 dst_bytes = coding->dst_bytes; | |
5947 } | |
5948 | |
5949 coding->src_object = src_object; | |
5950 coding->src_chars = chars; | |
5951 coding->src_bytes = bytes; | |
5952 coding->src_multibyte = chars < bytes; | |
5953 | |
5954 if (STRINGP (src_object)) | |
5955 { | |
5956 coding->src_pos = from; | |
5957 coding->src_pos_byte = from_byte; | |
5958 } | |
5959 else if (BUFFERP (src_object)) | |
5960 { | |
5961 set_buffer_internal (XBUFFER (src_object)); | |
5962 if (from != GPT) | |
5963 move_gap_both (from, from_byte); | |
5964 if (EQ (src_object, dst_object)) | |
26847 | 5965 { |
88365 | 5966 TEMP_SET_PT_BOTH (from, from_byte); |
5967 del_range_both (from, from_byte, to, to_byte, 1); | |
5968 coding->src_pos = -chars; | |
5969 coding->src_pos_byte = -bytes; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5970 } |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5971 else |
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
5972 { |
88365 | 5973 coding->src_pos = from; |
5974 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
|
5975 } |
88365 | 5976 } |
5977 | |
5978 if (CODING_REQUIRE_DETECTION (coding)) | |
5979 detect_coding (coding); | |
5980 attrs = CODING_ID_ATTRS (coding->id); | |
5981 | |
5982 if (! NILP (CODING_ATTR_POST_READ (attrs)) | |
5983 || EQ (dst_object, Qt)) | |
5984 { | |
5985 coding->dst_object = make_conversion_work_buffer (1); | |
5986 coding->dst_pos = BEG; | |
5987 coding->dst_pos_byte = BEG_BYTE; | |
5988 coding->dst_multibyte = 1; | |
5989 } | |
5990 else if (BUFFERP (dst_object)) | |
5991 { | |
5992 coding->dst_object = dst_object; | |
5993 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
5994 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
5995 coding->dst_multibyte | |
5996 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
5997 } | |
5998 else | |
5999 { | |
6000 coding->dst_object = Qnil; | |
6001 coding->dst_multibyte = 1; | |
6002 } | |
6003 | |
6004 decode_coding (coding); | |
6005 | |
6006 if (BUFFERP (coding->dst_object)) | |
6007 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6008 | |
6009 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
6010 { | |
6011 struct gcpro gcpro1, gcpro2; | |
6012 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; | |
6013 Lisp_Object val; | |
6014 | |
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
6015 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
88365 | 6016 GCPRO2 (coding->src_object, coding->dst_object); |
6017 val = call1 (CODING_ATTR_POST_READ (attrs), | |
6018 make_number (coding->produced_char)); | |
6019 UNGCPRO; | |
6020 CHECK_NATNUM (val); | |
6021 coding->produced_char += Z - prev_Z; | |
6022 coding->produced += Z_BYTE - prev_Z_BYTE; | |
6023 } | |
6024 | |
6025 if (EQ (dst_object, Qt)) | |
6026 { | |
6027 coding->dst_object = Fbuffer_string (); | |
6028 } | |
6029 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
6030 { | |
6031 set_buffer_internal (XBUFFER (coding->dst_object)); | |
6032 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
|
6033 { |
88365 | 6034 destination |
6035 = (unsigned char *) xrealloc (destination, coding->produced); | |
6036 if (! destination) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6037 { |
88365 | 6038 coding->result = CODING_RESULT_INSUFFICIENT_DST; |
6039 unbind_to (count, Qnil); | |
6040 return; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6041 } |
88365 | 6042 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
6043 move_gap_both (BEGV, BEGV_BYTE); | |
6044 bcopy (BEGV_ADDR, destination, coding->produced); | |
6045 coding->destination = destination; | |
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
6046 } |
88365 | 6047 } |
6048 | |
6049 unbind_to (count, Qnil); | |
6050 } | |
6051 | |
6052 | |
6053 void | |
6054 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, | |
6055 dst_object) | |
6056 struct coding_system *coding; | |
6057 Lisp_Object src_object; | |
6058 EMACS_INT from, from_byte, to, to_byte; | |
6059 Lisp_Object dst_object; | |
6060 { | |
6061 int count = specpdl_ptr - specpdl; | |
6062 EMACS_INT chars = to - from; | |
6063 EMACS_INT bytes = to_byte - from_byte; | |
6064 Lisp_Object attrs; | |
6065 | |
6066 saved_coding = coding; | |
6067 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
6068 | |
6069 coding->src_object = src_object; | |
6070 coding->src_chars = chars; | |
6071 coding->src_bytes = bytes; | |
6072 coding->src_multibyte = chars < bytes; | |
6073 | |
6074 attrs = CODING_ID_ATTRS (coding->id); | |
6075 | |
6076 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
|
6077 { |
88365 | 6078 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); |
6079 set_buffer_internal (XBUFFER (coding->src_object)); | |
6080 if (STRINGP (src_object)) | |
6081 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
6082 else if (BUFFERP (src_object)) | |
6083 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
6084 else | |
6085 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); | |
6086 | |
6087 if (EQ (src_object, dst_object)) | |
6088 { | |
6089 set_buffer_internal (XBUFFER (src_object)); | |
6090 del_range_both (from, from_byte, to, to_byte, 1); | |
6091 set_buffer_internal (XBUFFER (coding->src_object)); | |
6092 } | |
6093 | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6094 call2 (CODING_ATTR_PRE_WRITE (attrs), |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6095 make_number (BEG), make_number (Z)); |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6096 coding->src_object = Fcurrent_buffer (); |
88365 | 6097 if (BEG != GPT) |
6098 move_gap_both (BEG, BEG_BYTE); | |
6099 coding->src_chars = Z - BEG; | |
6100 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
6101 coding->src_pos = BEG; | |
6102 coding->src_pos_byte = BEG_BYTE; | |
6103 coding->src_multibyte = Z < Z_BYTE; | |
6104 } | |
6105 else if (STRINGP (src_object)) | |
6106 { | |
6107 coding->src_pos = from; | |
6108 coding->src_pos_byte = from_byte; | |
6109 } | |
6110 else if (BUFFERP (src_object)) | |
6111 { | |
6112 set_buffer_internal (XBUFFER (src_object)); | |
6113 if (from != GPT) | |
6114 move_gap_both (from, from_byte); | |
6115 if (EQ (src_object, dst_object)) | |
6116 { | |
6117 del_range_both (from, from_byte, to, to_byte, 1); | |
6118 coding->src_pos = -chars; | |
6119 coding->src_pos_byte = -bytes; | |
6120 } | |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
6121 else |
88365 | 6122 { |
6123 coding->src_pos = from; | |
6124 coding->src_pos_byte = from_byte; | |
6125 } | |
6126 } | |
6127 | |
6128 if (BUFFERP (dst_object)) | |
6129 { | |
6130 coding->dst_object = dst_object; | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6131 if (EQ (src_object, dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6132 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6133 coding->dst_pos = from; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6134 coding->dst_pos_byte = from_byte; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6135 } |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6136 else |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6137 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6138 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6139 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6140 } |
88365 | 6141 coding->dst_multibyte |
6142 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
6143 } | |
6144 else if (EQ (dst_object, Qt)) | |
6145 { | |
6146 coding->dst_object = Qnil; | |
6147 coding->dst_bytes = coding->src_chars; | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6148 if (coding->dst_bytes == 0) |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6149 coding->dst_bytes = 1; |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6150 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
88365 | 6151 coding->dst_multibyte = 0; |
6152 } | |
6153 else | |
6154 { | |
6155 coding->dst_object = Qnil; | |
6156 coding->dst_multibyte = 0; | |
6157 } | |
6158 | |
6159 encode_coding (coding); | |
6160 | |
6161 if (EQ (dst_object, Qt)) | |
6162 { | |
6163 if (BUFFERP (coding->dst_object)) | |
6164 coding->dst_object = Fbuffer_string (); | |
6165 else | |
6166 { | |
6167 coding->dst_object | |
6168 = make_unibyte_string ((char *) coding->destination, | |
6169 coding->produced); | |
6170 xfree (coding->destination); | |
6171 } | |
6172 } | |
6173 | |
6174 unbind_to (count, Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6175 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6176 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6177 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6178 Lisp_Object |
88365 | 6179 preferred_coding_system () |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6180 { |
88365 | 6181 int id = coding_categories[coding_priorities[0]].id; |
6182 | |
6183 return CODING_ID_NAME (id); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6184 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6185 |
17052 | 6186 |
6187 #ifdef emacs | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6188 /*** 8. Emacs Lisp library functions ***/ |
17052 | 6189 |
6190 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
|
6191 doc: /* Return t if OBJECT is nil or a coding-system. |
88365 | 6192 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
|
6193 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
|
6194 (obj) |
17052 | 6195 Lisp_Object obj; |
6196 { | |
88365 | 6197 return ((NILP (obj) || CODING_SYSTEM_P (obj)) ? Qt : Qnil); |
17052 | 6198 } |
6199 | |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6200 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
|
6201 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
|
6202 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
|
6203 (prompt) |
17052 | 6204 Lisp_Object prompt; |
6205 { | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6206 Lisp_Object val; |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6207 do |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6208 { |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6209 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6210 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
|
6211 } |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6212 while (XSTRING (val)->size == 0); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6213 return (Fintern (val, Qnil)); |
17052 | 6214 } |
6215 | |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6216 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
|
6217 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
|
6218 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
|
6219 (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
|
6220 Lisp_Object prompt, default_coding_system; |
17052 | 6221 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
6222 Lisp_Object val; |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6223 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
|
6224 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6225 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
|
6226 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
|
6227 default_coding_system, Qnil); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6228 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
17052 | 6229 } |
6230 | |
6231 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
6232 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
|
6233 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
|
6234 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
|
6235 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
|
6236 The value of property should be a vector of length 5. */) |
88365 | 6237 (coding_system) |
17052 | 6238 Lisp_Object coding_system; |
6239 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6240 CHECK_SYMBOL (coding_system); |
17052 | 6241 if (!NILP (Fcoding_system_p (coding_system))) |
6242 return coding_system; | |
6243 while (1) | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
6244 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
17052 | 6245 } |
88365 | 6246 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6247 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6248 Lisp_Object |
88365 | 6249 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
|
6250 unsigned char *src; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6251 int src_bytes, highest; |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6252 int multibytep; |
88365 | 6253 Lisp_Object coding_system; |
17052 | 6254 { |
88365 | 6255 unsigned char *src_end = src + src_bytes; |
6256 int mask = CATEGORY_MASK_ANY; | |
6257 int detected = 0; | |
6258 int c, i; | |
6259 Lisp_Object attrs, eol_type; | |
6260 Lisp_Object val; | |
6261 struct coding_system coding; | |
6262 | |
6263 if (NILP (coding_system)) | |
6264 coding_system = Qundecided; | |
6265 setup_coding_system (coding_system, &coding); | |
6266 attrs = CODING_ID_ATTRS (coding.id); | |
6267 eol_type = CODING_ID_EOL_TYPE (coding.id); | |
6268 | |
6269 coding.source = src; | |
6270 coding.src_bytes = src_bytes; | |
6271 coding.src_multibyte = multibytep; | |
6272 coding.consumed = 0; | |
6273 | |
6274 if (XINT (CODING_ATTR_CATEGORY (attrs)) != coding_category_undecided) | |
6275 { | |
6276 mask = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); | |
6277 } | |
6278 else | |
6279 { | |
6280 coding_system = Qnil; | |
6281 for (; src < src_end; src++) | |
17052 | 6282 { |
88365 | 6283 c = *src; |
6284 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
6285 || c == ISO_CODE_SI | |
6286 || c == ISO_CODE_SO))) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6287 break; |
17052 | 6288 } |
88365 | 6289 coding.head_ascii = src - coding.source; |
6290 | |
6291 if (src < src_end) | |
6292 for (i = 0; i < coding_category_raw_text; i++) | |
6293 { | |
6294 enum coding_category category = coding_priorities[i]; | |
6295 struct coding_system *this = coding_categories + category; | |
6296 | |
6297 if (category >= coding_category_raw_text | |
6298 || detected & (1 << category)) | |
6299 continue; | |
6300 | |
6301 if (this->id < 0) | |
6302 { | |
6303 /* No coding system of this category is defined. */ | |
6304 mask &= ~(1 << category); | |
6305 } | |
6306 else | |
6307 { | |
6308 detected |= detected_mask[category]; | |
6309 if ((*(coding_categories[category].detector)) (&coding, &mask) | |
6310 && highest) | |
6311 { | |
6312 mask &= detected_mask[category]; | |
6313 break; | |
6314 } | |
6315 } | |
6316 } | |
6317 } | |
6318 | |
6319 if (!mask) | |
6320 val = Fcons (make_number (coding_category_raw_text), Qnil); | |
6321 else if (mask == CATEGORY_MASK_ANY) | |
6322 val = Fcons (make_number (coding_category_undecided), Qnil); | |
6323 else if (highest) | |
6324 { | |
6325 for (i = 0; i < coding_category_raw_text; i++) | |
6326 if (mask & (1 << coding_priorities[i])) | |
6327 { | |
6328 val = Fcons (make_number (coding_priorities[i]), Qnil); | |
6329 break; | |
6330 } | |
6331 } | |
6332 else | |
6333 { | |
6334 val = Qnil; | |
6335 for (i = coding_category_raw_text - 1; i >= 0; i--) | |
6336 if (mask & (1 << coding_priorities[i])) | |
6337 val = Fcons (make_number (coding_priorities[i]), val); | |
6338 } | |
6339 | |
6340 { | |
6341 int one_byte_eol = -1, two_byte_eol = -1; | |
6342 Lisp_Object tail; | |
6343 | |
6344 for (tail = val; CONSP (tail); tail = XCDR (tail)) | |
6345 { | |
6346 struct coding_system *this | |
6347 = (NILP (coding_system) ? coding_categories + XINT (XCAR (tail)) | |
6348 : &coding); | |
6349 int this_eol; | |
6350 | |
6351 attrs = CODING_ID_ATTRS (this->id); | |
6352 eol_type = CODING_ID_EOL_TYPE (this->id); | |
6353 XSETCAR (tail, CODING_ID_NAME (this->id)); | |
6354 if (VECTORP (eol_type)) | |
6355 { | |
6356 if (EQ (CODING_ATTR_TYPE (attrs), Qutf_16)) | |
6357 { | |
6358 if (two_byte_eol < 0) | |
6359 two_byte_eol = detect_eol (this, coding.source, src_bytes); | |
6360 this_eol = two_byte_eol; | |
6361 } | |
6362 else | |
6363 { | |
6364 if (one_byte_eol < 0) | |
6365 one_byte_eol =detect_eol (this, coding.source, src_bytes); | |
6366 this_eol = one_byte_eol; | |
6367 } | |
6368 if (this_eol == EOL_SEEN_LF) | |
6369 XSETCAR (tail, AREF (eol_type, 0)); | |
6370 else if (this_eol == EOL_SEEN_CRLF) | |
6371 XSETCAR (tail, AREF (eol_type, 1)); | |
6372 else if (this_eol == EOL_SEEN_CR) | |
6373 XSETCAR (tail, AREF (eol_type, 2)); | |
6374 } | |
6375 } | |
6376 } | |
6377 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
6378 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
|
6379 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6380 |
88365 | 6381 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6382 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
|
6383 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
|
6384 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
|
6385 Return a list of possible coding systems ordered by priority. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6386 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6387 If only ASCII characters are found, it returns a list of single element |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6388 `undecided' or its subsidiary coding system according to a detected |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6389 end-of-line format. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6390 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6391 If optional argument HIGHEST is non-nil, return the coding system of |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6392 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6393 (start, end, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6394 Lisp_Object start, end, highest; |
17052 | 6395 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6396 int from, to; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6397 int from_byte, to_byte; |
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_NUMBER_COERCE_MARKER (start); |
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6400 CHECK_NUMBER_COERCE_MARKER (end); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6401 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6402 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6403 from = XINT (start), to = XINT (end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6404 from_byte = CHAR_TO_BYTE (from); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6405 to_byte = CHAR_TO_BYTE (to); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6406 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6407 if (from < GPT && to >= GPT) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6408 move_gap_both (to, to_byte); |
88365 | 6409 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6410 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
88365 | 6411 to_byte - from_byte, |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6412 !NILP (highest), |
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6413 !NILP (current_buffer |
88365 | 6414 ->enable_multibyte_characters), |
6415 Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6416 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6417 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6418 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
|
6419 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
|
6420 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
|
6421 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
|
6422 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6423 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
|
6424 `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
|
6425 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
|
6426 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6427 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
|
6428 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6429 (string, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6430 Lisp_Object string, highest; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6431 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6432 CHECK_STRING (string); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6433 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6434 return detect_coding_system (XSTRING (string)->data, |
88365 | 6435 STRING_BYTES (XSTRING (string)), |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6436 !NILP (highest), |
88365 | 6437 STRING_MULTIBYTE (string), |
6438 Qnil); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6439 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6440 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6441 |
88365 | 6442 static INLINE int |
6443 char_encodable_p (c, attrs) | |
6444 int c; | |
6445 Lisp_Object attrs; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6446 { |
88365 | 6447 Lisp_Object tail; |
6448 struct charset *charset; | |
6449 | |
6450 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | |
6451 CONSP (tail); tail = XCDR (tail)) | |
6452 { | |
6453 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
6454 if (CHAR_CHARSET_P (c, charset)) | |
6455 break; | |
6456 } | |
6457 return (! NILP (tail)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6458 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6459 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6460 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6461 /* Return a list of coding systems that safely encode the text between |
88365 | 6462 START and END. If EXCLUDE is non-nil, it is a list of coding |
6463 systems not to check. The returned list doesn't contain any such | |
88889
4548f224c603
(Ffind_coding_systems_region_internal): Detect an
Kenichi Handa <handa@m17n.org>
parents:
88876
diff
changeset
|
6464 coding systems. In any case, if the text contains only ASCII or is |
88365 | 6465 unibyte, return t. */ |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6466 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6467 DEFUN ("find-coding-systems-region-internal", |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6468 Ffind_coding_systems_region_internal, |
88365 | 6469 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
|
6470 doc: /* Internal use only. */) |
88365 | 6471 (start, end, exclude) |
6472 Lisp_Object start, end, exclude; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6473 { |
88365 | 6474 Lisp_Object coding_attrs_list, safe_codings; |
6475 EMACS_INT start_byte, end_byte; | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
6476 const unsigned char *p, *pbeg, *pend; |
88365 | 6477 int c; |
6478 Lisp_Object tail, elt; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6479 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6480 if (STRINGP (start)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6481 { |
88365 | 6482 if (!STRING_MULTIBYTE (start) |
88889
4548f224c603
(Ffind_coding_systems_region_internal): Detect an
Kenichi Handa <handa@m17n.org>
parents:
88876
diff
changeset
|
6483 || XSTRING (start)->size == STRING_BYTES (XSTRING (start))) |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6484 return Qt; |
88365 | 6485 start_byte = 0; |
6486 end_byte = STRING_BYTES (XSTRING (start)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6487 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6488 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6489 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6490 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
|
6491 CHECK_NUMBER_COERCE_MARKER (end); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6492 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
|
6493 args_out_of_range (start, end); |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6494 if (NILP (current_buffer->enable_multibyte_characters)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6495 return Qt; |
88365 | 6496 start_byte = CHAR_TO_BYTE (XINT (start)); |
6497 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6498 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6499 return Qt; | |
6500 | |
6501 if (start < GPT && end > GPT) | |
6502 { | |
6503 if ((GPT - start) < (end - GPT)) | |
6504 move_gap_both (start, start_byte); | |
6505 else | |
6506 move_gap_both (end, end_byte); | |
6507 } | |
6508 } | |
6509 | |
6510 coding_attrs_list = Qnil; | |
6511 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6512 if (NILP (exclude) | |
6513 || NILP (Fmemq (XCAR (tail), exclude))) | |
6514 { | |
6515 Lisp_Object attrs; | |
6516 | |
6517 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
6518 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
6519 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
6520 coding_attrs_list = Fcons (attrs, coding_attrs_list); | |
6521 } | |
6522 | |
6523 if (STRINGP (start)) | |
6524 p = pbeg = XSTRING (start)->data; | |
6525 else | |
6526 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6527 pend = p + (end_byte - start_byte); | |
6528 | |
6529 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
6530 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6531 | |
6532 while (p < pend) | |
6533 { | |
6534 if (ASCII_BYTE_P (*p)) | |
6535 p++; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6536 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6537 { |
88365 | 6538 c = STRING_CHAR_ADVANCE (p); |
6539 | |
6540 charset_map_loaded = 0; | |
6541 for (tail = coding_attrs_list; CONSP (tail);) | |
6542 { | |
6543 elt = XCAR (tail); | |
6544 if (NILP (elt)) | |
6545 tail = XCDR (tail); | |
6546 else if (char_encodable_p (c, elt)) | |
6547 tail = XCDR (tail); | |
6548 else if (CONSP (XCDR (tail))) | |
6549 { | |
6550 XSETCAR (tail, XCAR (XCDR (tail))); | |
6551 XSETCDR (tail, XCDR (XCDR (tail))); | |
6552 } | |
6553 else | |
6554 { | |
6555 XSETCAR (tail, Qnil); | |
6556 tail = XCDR (tail); | |
6557 } | |
6558 } | |
6559 if (charset_map_loaded) | |
6560 { | |
6561 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6562 | |
6563 if (STRINGP (start)) | |
6564 pbeg = XSTRING (start)->data; | |
6565 else | |
6566 pbeg = BYTE_POS_ADDR (start_byte); | |
6567 p = pbeg + p_offset; | |
6568 pend = pbeg + pend_offset; | |
6569 } | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6570 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6571 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6572 |
88365 | 6573 safe_codings = Qnil; |
6574 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) | |
6575 if (! NILP (XCAR (tail))) | |
6576 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
6577 | |
6578 return safe_codings; | |
6579 } | |
6580 | |
6581 | |
6582 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, | |
6583 Scheck_coding_systems_region, 3, 3, 0, | |
6584 doc: /* Check if the region is encodable by coding systems. | |
6585 | |
6586 START and END are buffer positions specifying the region. | |
6587 CODING-SYSTEM-LIST is a list of coding systems to check. | |
6588 | |
6589 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
6590 CODING-SYSTEM is a member of CODING-SYSTEM-LIst and can't encode the | |
6591 whole region, POS0, POS1, ... are buffer positions where non-encodable | |
6592 characters are found. | |
6593 | |
6594 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
6595 value is nil. | |
6596 | |
6597 START may be a string. In that case, check if the string is | |
6598 encodable, and the value contains indices to the string instead of | |
6599 buffer positions. END is ignored. */) | |
6600 (start, end, coding_system_list) | |
6601 Lisp_Object start, end, coding_system_list; | |
6602 { | |
6603 Lisp_Object list; | |
6604 EMACS_INT start_byte, end_byte; | |
6605 int pos; | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
6606 const unsigned char *p, *pbeg, *pend; |
88365 | 6607 int c; |
6608 Lisp_Object tail, elt; | |
6609 | |
6610 if (STRINGP (start)) | |
6611 { | |
6612 if (!STRING_MULTIBYTE (start) | |
6613 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
6614 return Qnil; | |
6615 start_byte = 0; | |
6616 end_byte = STRING_BYTES (XSTRING (start)); | |
6617 pos = 0; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6618 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6619 else |
88365 | 6620 { |
6621 CHECK_NUMBER_COERCE_MARKER (start); | |
6622 CHECK_NUMBER_COERCE_MARKER (end); | |
6623 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
6624 args_out_of_range (start, end); | |
6625 if (NILP (current_buffer->enable_multibyte_characters)) | |
6626 return Qnil; | |
6627 start_byte = CHAR_TO_BYTE (XINT (start)); | |
6628 end_byte = CHAR_TO_BYTE (XINT (end)); | |
6629 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
6630 return Qt; | |
6631 | |
6632 if (start < GPT && end > GPT) | |
6633 { | |
6634 if ((GPT - start) < (end - GPT)) | |
6635 move_gap_both (start, start_byte); | |
6636 else | |
6637 move_gap_both (end, end_byte); | |
6638 } | |
6639 pos = start; | |
6640 } | |
6641 | |
6642 list = Qnil; | |
6643 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
6644 { | |
6645 elt = XCAR (tail); | |
6646 list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | |
6647 Qnil)), | |
6648 list); | |
6649 } | |
6650 | |
6651 if (STRINGP (start)) | |
6652 p = pbeg = XSTRING (start)->data; | |
6653 else | |
6654 p = pbeg = BYTE_POS_ADDR (start_byte); | |
6655 pend = p + (end_byte - start_byte); | |
6656 | |
6657 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
6658 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
6659 | |
6660 while (p < pend) | |
6661 { | |
6662 if (ASCII_BYTE_P (*p)) | |
6663 p++; | |
6664 else | |
6665 { | |
6666 c = STRING_CHAR_ADVANCE (p); | |
6667 | |
6668 charset_map_loaded = 0; | |
6669 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
6670 { | |
6671 elt = XCDR (XCAR (tail)); | |
6672 if (! char_encodable_p (c, XCAR (elt))) | |
6673 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
6674 } | |
6675 if (charset_map_loaded) | |
6676 { | |
6677 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
6678 | |
6679 if (STRINGP (start)) | |
6680 pbeg = XSTRING (start)->data; | |
6681 else | |
6682 pbeg = BYTE_POS_ADDR (start_byte); | |
6683 p = pbeg + p_offset; | |
6684 pend = pbeg + pend_offset; | |
6685 } | |
6686 } | |
6687 pos++; | |
6688 } | |
6689 | |
6690 tail = list; | |
6691 list = Qnil; | |
6692 for (; CONSP (tail); tail = XCDR (tail)) | |
6693 { | |
6694 elt = XCAR (tail); | |
6695 if (CONSP (XCDR (XCDR (elt)))) | |
6696 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
6697 list); | |
6698 } | |
6699 | |
6700 return list; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6701 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6702 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6703 |
88365 | 6704 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6705 Lisp_Object |
88365 | 6706 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
6707 Lisp_Object start, end, coding_system, dst_object; | |
6708 int encodep, norecord; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6709 { |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6710 struct coding_system coding; |
88365 | 6711 EMACS_INT from, from_byte, to, to_byte; |
6712 Lisp_Object src_object; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6713 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6714 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
|
6715 CHECK_NUMBER_COERCE_MARKER (end); |
88365 | 6716 if (NILP (coding_system)) |
6717 coding_system = Qno_conversion; | |
6718 else | |
6719 CHECK_CODING_SYSTEM (coding_system); | |
6720 src_object = Fcurrent_buffer (); | |
6721 if (NILP (dst_object)) | |
6722 dst_object = src_object; | |
6723 else if (! EQ (dst_object, Qt)) | |
6724 CHECK_BUFFER (dst_object); | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6725 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6726 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6727 from = XFASTINT (start); |
88365 | 6728 from_byte = CHAR_TO_BYTE (from); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6729 to = XFASTINT (end); |
88365 | 6730 to_byte = CHAR_TO_BYTE (to); |
6731 | |
6732 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6733 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6734 |
6735 if (encodep) | |
6736 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6737 dst_object); | |
6738 else | |
6739 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
6740 dst_object); | |
6741 if (! norecord) | |
6742 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6743 | |
6744 if (coding.result != CODING_RESULT_SUCCESS) | |
6745 error ("Code conversion error: %d", coding.result); | |
6746 | |
6747 return (BUFFERP (dst_object) | |
6748 ? make_number (coding.produced_char) | |
6749 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6750 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6751 |
88365 | 6752 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6753 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
88365 | 6754 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
|
6755 doc: /* Decode the current region from the specified coding system. |
88365 | 6756 When called from a program, takes four arguments: |
6757 START, END, CODING-SYSTEM, and DESTINATION. | |
6758 START and END are buffer positions. | |
6759 | |
6760 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
6761 If nil, the region between START and END is replace by the decoded text. | |
6762 If buffer, the decoded text is inserted in the buffer. | |
6763 If t, the decoded text is returned. | |
6764 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6765 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
|
6766 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
|
6767 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6768 It returns the length of the decoded text. */) |
88365 | 6769 (start, end, coding_system, destination) |
6770 Lisp_Object start, end, coding_system, destination; | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6771 { |
88365 | 6772 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
|
6773 } |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6774 |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6775 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
88365 | 6776 3, 4, "r\nzCoding system: ", |
6777 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
|
6778 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
|
6779 START, END, and CODING-SYSTEM. START and END are buffer positions. |
88365 | 6780 |
6781 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
6782 If nil, the region between START and END is replace by the encoded text. | |
6783 If buffer, the encoded text is inserted in the buffer. | |
6784 If t, the encoded text is returned. | |
6785 | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6786 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
|
6787 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
|
6788 not fully specified.) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6789 It returns the length of the encoded text. */) |
88365 | 6790 (start, end, coding_system, destination) |
6791 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
|
6792 { |
88365 | 6793 return code_convert_region (start, end, coding_system, destination, 1, 0); |
17052 | 6794 } |
6795 | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6796 Lisp_Object |
88365 | 6797 code_convert_string (string, coding_system, dst_object, |
6798 encodep, nocopy, norecord) | |
6799 Lisp_Object string, coding_system, dst_object; | |
6800 int encodep, nocopy, norecord; | |
17052 | 6801 { |
6802 struct coding_system coding; | |
88365 | 6803 EMACS_INT chars, bytes; |
17052 | 6804 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6805 CHECK_STRING (string); |
88365 | 6806 if (NILP (coding_system)) |
6807 { | |
6808 if (! norecord) | |
6809 Vlast_coding_system_used = Qno_conversion; | |
6810 if (NILP (dst_object)) | |
6811 return (nocopy ? Fcopy_sequence (string) : string); | |
6812 } | |
17052 | 6813 |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6814 if (NILP (coding_system)) |
88365 | 6815 coding_system = Qno_conversion; |
6816 else | |
6817 CHECK_CODING_SYSTEM (coding_system); | |
6818 if (NILP (dst_object)) | |
6819 dst_object = Qt; | |
6820 else if (! EQ (dst_object, Qt)) | |
6821 CHECK_BUFFER (dst_object); | |
6822 | |
6823 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6824 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 6825 chars = XSTRING (string)->size; |
6826 bytes = STRING_BYTES (XSTRING (string)); | |
6827 if (encodep) | |
6828 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6829 else | |
6830 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
6831 if (! norecord) | |
6832 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
6833 | |
6834 if (coding.result != CODING_RESULT_SUCCESS) | |
6835 error ("Code conversion error: %d", coding.result); | |
6836 | |
6837 return (BUFFERP (dst_object) | |
6838 ? make_number (coding.produced_char) | |
6839 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6840 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6841 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
6842 |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6843 /* Encode or decode STRING according to CODING_SYSTEM. |
26847 | 6844 Do not set Vlast_coding_system_used. |
6845 | |
6846 This function is called only from macros DECODE_FILE and | |
6847 ENCODE_FILE, thus we ignore character composition. */ | |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6848 |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6849 Lisp_Object |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6850 code_convert_string_norecord (string, coding_system, encodep) |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6851 Lisp_Object string, coding_system; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6852 int encodep; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
6853 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
6854 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
|
6855 } |
88365 | 6856 |
6857 | |
6858 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
6859 2, 4, 0, | |
6860 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
6861 | |
6862 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
6863 if the decoding operation is trivial. | |
6864 | |
6865 Optional fourth arg BUFFER non-nil meant that the decoded text is | |
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
6866 inserted in BUFFER instead of returned as a string. In this case, |
88365 | 6867 the return value is BUFFER. |
6868 | |
6869 This function sets `last-coding-system-used' to the precise coding system | |
6870 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6871 not fully specified. */) | |
6872 (string, coding_system, nocopy, buffer) | |
6873 Lisp_Object string, coding_system, nocopy, buffer; | |
6874 { | |
6875 return code_convert_string (string, coding_system, buffer, | |
6876 0, ! NILP (nocopy), 0); | |
6877 } | |
6878 | |
6879 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
6880 2, 4, 0, | |
6881 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
6882 | |
6883 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
6884 itself if the encoding operation is trivial. | |
6885 | |
6886 Optional fourth arg BUFFER non-nil meant that the encoded text is | |
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
6887 inserted in BUFFER instead of returned as a string. In this case, |
88365 | 6888 the return value is BUFFER. |
6889 | |
6890 This function sets `last-coding-system-used' to the precise coding system | |
6891 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
6892 not fully specified.) */) | |
6893 (string, coding_system, nocopy, buffer) | |
6894 Lisp_Object string, coding_system, nocopy, buffer; | |
6895 { | |
6896 return code_convert_string (string, coding_system, buffer, | |
88856 | 6897 1, ! NILP (nocopy), 1); |
88365 | 6898 } |
6899 | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6900 |
17052 | 6901 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
|
6902 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
|
6903 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
|
6904 (code) |
17052 | 6905 Lisp_Object code; |
6906 { | |
88365 | 6907 Lisp_Object spec, attrs, val; |
6908 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
6909 int c; | |
6910 | |
6911 CHECK_NATNUM (code); | |
6912 c = XFASTINT (code); | |
6913 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6914 attrs = AREF (spec, 0); | |
6915 | |
6916 if (ASCII_BYTE_P (c) | |
6917 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6918 return code; | |
6919 | |
6920 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6921 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
|
6922 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
|
6923 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 6924 |
6925 if (c <= 0x7F) | |
6926 charset = charset_roman; | |
6927 else if (c >= 0xA0 && c < 0xDF) | |
6928 { | |
6929 charset = charset_kana; | |
6930 c -= 0x80; | |
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6931 } |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6932 else |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
6933 { |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
6934 int s1 = c >> 8, s2 = c & 0xFF; |
88365 | 6935 |
6936 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
6937 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
6938 error ("Invalid code: %d", code); | |
6939 SJIS_TO_JIS (c); | |
6940 charset = charset_kanji; | |
6941 } | |
6942 c = DECODE_CHAR (charset, c); | |
6943 if (c < 0) | |
6944 error ("Invalid code: %d", code); | |
6945 return make_number (c); | |
17052 | 6946 } |
6947 | |
88365 | 6948 |
17052 | 6949 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
|
6950 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
|
6951 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
|
6952 (ch) |
88365 | 6953 Lisp_Object ch; |
17052 | 6954 { |
88365 | 6955 Lisp_Object spec, attrs, charset_list; |
6956 int c; | |
6957 struct charset *charset; | |
6958 unsigned code; | |
6959 | |
6960 CHECK_CHARACTER (ch); | |
6961 c = XFASTINT (ch); | |
6962 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
6963 attrs = AREF (spec, 0); | |
6964 | |
6965 if (ASCII_CHAR_P (c) | |
6966 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6967 return ch; | |
6968 | |
6969 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
6970 charset = char_charset (c, charset_list, &code); | |
6971 if (code == CHARSET_INVALID_CODE (charset)) | |
6972 error ("Can't encode by shift_jis encoding: %d", c); | |
6973 JIS_TO_SJIS (code); | |
6974 | |
6975 return make_number (code); | |
17052 | 6976 } |
6977 | |
6978 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
|
6979 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
|
6980 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
|
6981 (code) |
17052 | 6982 Lisp_Object code; |
6983 { | |
88365 | 6984 Lisp_Object spec, attrs, val; |
6985 struct charset *charset_roman, *charset_big5, *charset; | |
6986 int c; | |
6987 | |
6988 CHECK_NATNUM (code); | |
6989 c = XFASTINT (code); | |
6990 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
6991 attrs = AREF (spec, 0); | |
6992 | |
6993 if (ASCII_BYTE_P (c) | |
6994 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
6995 return code; | |
6996 | |
6997 val = CODING_ATTR_CHARSET_LIST (attrs); | |
6998 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
6999 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
7000 | |
7001 if (c <= 0x7F) | |
7002 charset = charset_roman; | |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
7003 else |
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
7004 { |
88365 | 7005 int b1 = c >> 8, b2 = c & 0x7F; |
7006 if (b1 < 0xA1 || b1 > 0xFE | |
7007 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
7008 error ("Invalid code: %d", code); | |
7009 charset = charset_big5; | |
7010 } | |
7011 c = DECODE_CHAR (charset, (unsigned )c); | |
7012 if (c < 0) | |
7013 error ("Invalid code: %d", code); | |
7014 return make_number (c); | |
17052 | 7015 } |
7016 | |
7017 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
|
7018 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
|
7019 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
|
7020 (ch) |
17052 | 7021 Lisp_Object ch; |
7022 { | |
88365 | 7023 Lisp_Object spec, attrs, charset_list; |
7024 struct charset *charset; | |
7025 int c; | |
7026 unsigned code; | |
7027 | |
7028 CHECK_CHARACTER (ch); | |
7029 c = XFASTINT (ch); | |
7030 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
7031 attrs = AREF (spec, 0); | |
7032 if (ASCII_CHAR_P (c) | |
7033 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
7034 return ch; | |
7035 | |
7036 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
7037 charset = char_charset (c, charset_list, &code); | |
7038 if (code == CHARSET_INVALID_CODE (charset)) | |
7039 error ("Can't encode by Big5 encoding: %d", c); | |
7040 | |
7041 return make_number (code); | |
17052 | 7042 } |
88365 | 7043 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7044 |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7045 DEFUN ("set-terminal-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7046 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
|
7047 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
|
7048 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
|
7049 (coding_system) |
88473 | 7050 Lisp_Object coding_system; |
17052 | 7051 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7052 CHECK_SYMBOL (coding_system); |
88365 | 7053 setup_coding_system (Fcheck_coding_system (coding_system), |
7054 &terminal_coding); | |
7055 | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
7056 /* We had better not send unsafe characters to terminal. */ |
88365 | 7057 terminal_coding.mode |= CODING_MODE_SAFE_ENCODING; |
7058 /* Characer composition should be disabled. */ | |
7059 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
|
7060 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
|
7061 terminal_coding.dst_multibyte = 0; |
17052 | 7062 return Qnil; |
7063 } | |
7064 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7065 DEFUN ("set-safe-terminal-coding-system-internal", |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7066 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
|
7067 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
41006 | 7068 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
|
7069 (coding_system) |
88473 | 7070 Lisp_Object coding_system; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7071 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7072 CHECK_SYMBOL (coding_system); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7073 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
|
7074 &safe_terminal_coding); |
88365 | 7075 /* Characer composition should be disabled. */ |
7076 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
|
7077 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
|
7078 safe_terminal_coding.dst_multibyte = 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7079 return Qnil; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7080 } |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7081 |
17052 | 7082 DEFUN ("terminal-coding-system", |
7083 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
|
7084 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
|
7085 () |
17052 | 7086 { |
88365 | 7087 return CODING_ID_NAME (terminal_coding.id); |
17052 | 7088 } |
7089 | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7090 DEFUN ("set-keyboard-coding-system-internal", |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7091 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
|
7092 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
|
7093 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
|
7094 (coding_system) |
17052 | 7095 Lisp_Object coding_system; |
7096 { | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7097 CHECK_SYMBOL (coding_system); |
88365 | 7098 setup_coding_system (Fcheck_coding_system (coding_system), |
7099 &keyboard_coding); | |
7100 /* Characer composition should be disabled. */ | |
7101 keyboard_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
17052 | 7102 return Qnil; |
7103 } | |
7104 | |
7105 DEFUN ("keyboard-coding-system", | |
7106 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
|
7107 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
|
7108 () |
17052 | 7109 { |
88365 | 7110 return CODING_ID_NAME (keyboard_coding.id); |
17052 | 7111 } |
7112 | |
7113 | |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7114 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
|
7115 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
|
7116 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
|
7117 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
|
7118 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
|
7119 \(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
|
7120 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
|
7121 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7122 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
|
7123 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
|
7124 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
|
7125 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
|
7126 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7127 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
|
7128 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
|
7129 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
|
7130 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
|
7131 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7132 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
|
7133 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
|
7134 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
|
7135 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
|
7136 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7137 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
|
7138 `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
|
7139 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
|
7140 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
|
7141 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
|
7142 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
|
7143 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
|
7144 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7145 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
|
7146 (nargs, args) |
17052 | 7147 int nargs; |
7148 Lisp_Object *args; | |
7149 { | |
7150 Lisp_Object operation, target_idx, target, val; | |
7151 register Lisp_Object chain; | |
7152 | |
7153 if (nargs < 2) | |
7154 error ("Too few arguments"); | |
7155 operation = args[0]; | |
7156 if (!SYMBOLP (operation) | |
7157 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
88365 | 7158 error ("Invalid first arguement"); |
17052 | 7159 if (nargs < 1 + XINT (target_idx)) |
7160 error ("Too few arguments for operation: %s", | |
7161 XSYMBOL (operation)->name->data); | |
7162 target = args[XINT (target_idx) + 1]; | |
7163 if (!(STRINGP (target) | |
7164 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
88365 | 7165 error ("Invalid %dth argument", XINT (target_idx) + 1); |
17052 | 7166 |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7167 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
|
7168 || EQ (operation, Qwrite_region)) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7169 ? 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
|
7170 : (EQ (operation, Qopen_network_stream) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7171 ? Vnetwork_coding_system_alist |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7172 : Vprocess_coding_system_alist)); |
17052 | 7173 if (NILP (chain)) |
7174 return Qnil; | |
7175 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7176 for (; CONSP (chain); chain = XCDR (chain)) |
17052 | 7177 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
7178 Lisp_Object elt; |
88365 | 7179 |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7180 elt = XCAR (chain); |
17052 | 7181 if (CONSP (elt) |
7182 && ((STRINGP (target) | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7183 && STRINGP (XCAR (elt)) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7184 && 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
|
7185 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7186 { |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7187 val = XCDR (elt); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7188 /* 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
|
7189 function symbol, we return VAL as a coding system. */ |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7190 if (CONSP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7191 return val; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7192 if (! SYMBOLP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7193 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7194 if (! NILP (Fcoding_system_p (val))) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7195 return Fcons (val, val); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7196 if (! NILP (Ffboundp (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7197 { |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7198 val = call1 (val, Flist (nargs, args)); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7199 if (CONSP (val)) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7200 return val; |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7201 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
|
7202 return Fcons (val, val); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7203 } |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7204 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7205 } |
17052 | 7206 } |
7207 return Qnil; | |
7208 } | |
7209 | |
88365 | 7210 DEFUN ("set-coding-system-priority", Fset_coding_system_priority, |
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
7211 Sset_coding_system_priority, 0, MANY, 0, |
88645 | 7212 doc: /* Assign higher priority to the coding systems given as arguments. |
88544
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7213 usage: (set-coding-system-priority CODING-SYSTEM ...) */) |
88365 | 7214 (nargs, args) |
7215 int nargs; | |
7216 Lisp_Object *args; | |
7217 { | |
7218 int i, j; | |
7219 int changed[coding_category_max]; | |
7220 enum coding_category priorities[coding_category_max]; | |
7221 | |
7222 bzero (changed, sizeof changed); | |
7223 | |
7224 for (i = j = 0; i < nargs; i++) | |
7225 { | |
7226 enum coding_category category; | |
7227 Lisp_Object spec, attrs; | |
7228 | |
7229 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
7230 attrs = AREF (spec, 0); | |
7231 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
7232 if (changed[category]) | |
7233 /* Ignore this coding system because a coding system of the | |
7234 same category already had a higher priority. */ | |
7235 continue; | |
7236 changed[category] = 1; | |
7237 priorities[j++] = category; | |
7238 if (coding_categories[category].id >= 0 | |
7239 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
7240 setup_coding_system (args[i], &coding_categories[category]); | |
7241 } | |
7242 | |
7243 /* Now we have decided top J priorities. Reflect the order of the | |
7244 original priorities to the remaining priorities. */ | |
7245 | |
7246 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
7247 { | |
7248 while (j < coding_category_max | |
7249 && changed[coding_priorities[j]]) | |
7250 j++; | |
7251 if (j == coding_category_max) | |
7252 abort (); | |
7253 priorities[i] = coding_priorities[j]; | |
7254 } | |
7255 | |
7256 bcopy (priorities, coding_priorities, sizeof priorities); | |
7257 return Qnil; | |
7258 } | |
7259 | |
7260 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, | |
7261 Scoding_system_priority_list, 0, 1, 0, | |
88645 | 7262 doc: /* Return a list of coding systems ordered by their priorities. |
7263 HIGHESTP non-nil means just return the highest priority one. */) | |
88365 | 7264 (highestp) |
7265 Lisp_Object highestp; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7266 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7267 int i; |
88365 | 7268 Lisp_Object val; |
7269 | |
7270 for (i = 0, val = Qnil; i < coding_category_max; i++) | |
7271 { | |
7272 enum coding_category category = coding_priorities[i]; | |
7273 int id = coding_categories[category].id; | |
7274 Lisp_Object attrs; | |
7275 | |
7276 if (id < 0) | |
7277 continue; | |
7278 attrs = CODING_ID_ATTRS (id); | |
7279 if (! NILP (highestp)) | |
7280 return CODING_ATTR_BASE_NAME (attrs); | |
7281 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
7282 } | |
7283 return Fnreverse (val); | |
7284 } | |
7285 | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7286 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
|
7287 |
88365 | 7288 static Lisp_Object |
7289 make_subsidiaries (base) | |
7290 Lisp_Object base; | |
7291 { | |
7292 Lisp_Object subsidiaries; | |
7293 int base_name_len = STRING_BYTES (XSYMBOL (base)->name); | |
7294 char *buf = (char *) alloca (base_name_len + 6); | |
7295 int i; | |
7296 | |
7297 bcopy (XSYMBOL (base)->name->data, buf, base_name_len); | |
7298 subsidiaries = Fmake_vector (make_number (3), Qnil); | |
7299 for (i = 0; i < 3; i++) | |
7300 { | |
7301 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
7302 ASET (subsidiaries, i, intern (buf)); | |
7303 } | |
7304 return subsidiaries; | |
7305 } | |
7306 | |
7307 | |
7308 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, | |
7309 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
|
7310 doc: /* For internal use only. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7311 usage: (define-coding-system-internal ...) */) |
88365 | 7312 (nargs, args) |
7313 int nargs; | |
7314 Lisp_Object *args; | |
7315 { | |
7316 Lisp_Object name; | |
7317 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
7318 Lisp_Object attrs; /* Vector of attributes. */ | |
7319 Lisp_Object eol_type; | |
7320 Lisp_Object aliases; | |
7321 Lisp_Object coding_type, charset_list, safe_charsets; | |
7322 enum coding_category category; | |
7323 Lisp_Object tail, val; | |
7324 int max_charset_id = 0; | |
7325 int i; | |
7326 | |
7327 if (nargs < coding_arg_max) | |
7328 goto short_args; | |
7329 | |
7330 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
7331 | |
7332 name = args[coding_arg_name]; | |
7333 CHECK_SYMBOL (name); | |
7334 CODING_ATTR_BASE_NAME (attrs) = name; | |
7335 | |
7336 val = args[coding_arg_mnemonic]; | |
7337 if (! STRINGP (val)) | |
7338 CHECK_CHARACTER (val); | |
7339 CODING_ATTR_MNEMONIC (attrs) = val; | |
7340 | |
7341 coding_type = args[coding_arg_coding_type]; | |
7342 CHECK_SYMBOL (coding_type); | |
7343 CODING_ATTR_TYPE (attrs) = coding_type; | |
7344 | |
7345 charset_list = args[coding_arg_charset_list]; | |
7346 if (SYMBOLP (charset_list)) | |
7347 { | |
7348 if (EQ (charset_list, Qiso_2022)) | |
7349 { | |
7350 if (! EQ (coding_type, Qiso_2022)) | |
7351 error ("Invalid charset-list"); | |
7352 charset_list = Viso_2022_charset_list; | |
7353 } | |
7354 else if (EQ (charset_list, Qemacs_mule)) | |
7355 { | |
7356 if (! EQ (coding_type, Qemacs_mule)) | |
7357 error ("Invalid charset-list"); | |
7358 charset_list = Vemacs_mule_charset_list; | |
7359 } | |
7360 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7361 if (max_charset_id < XFASTINT (XCAR (tail))) | |
7362 max_charset_id = XFASTINT (XCAR (tail)); | |
7363 } | |
7364 else | |
7365 { | |
7366 charset_list = Fcopy_sequence (charset_list); | |
7367 for (tail = charset_list; !NILP (tail); tail = Fcdr (tail)) | |
7368 { | |
7369 struct charset *charset; | |
7370 | |
7371 val = Fcar (tail); | |
7372 CHECK_CHARSET_GET_CHARSET (val, charset); | |
7373 if (EQ (coding_type, Qiso_2022) | |
7374 ? CHARSET_ISO_FINAL (charset) < 0 | |
7375 : EQ (coding_type, Qemacs_mule) | |
7376 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
7377 : 0) | |
7378 error ("Can't handle charset `%s'", | |
7379 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7380 | |
7381 XCAR (tail) = make_number (charset->id); | |
7382 if (max_charset_id < charset->id) | |
7383 max_charset_id = charset->id; | |
7384 } | |
7385 } | |
7386 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
7387 | |
7388 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
7389 make_number (255)); | |
7390 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7391 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
7392 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | |
7393 | |
7394 val = args[coding_arg_decode_translation_table]; | |
7395 if (! NILP (val)) | |
7396 CHECK_CHAR_TABLE (val); | |
7397 CODING_ATTR_DECODE_TBL (attrs) = val; | |
7398 | |
7399 val = args[coding_arg_encode_translation_table]; | |
7400 if (! NILP (val)) | |
7401 CHECK_CHAR_TABLE (val); | |
7402 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
7403 | |
7404 val = args[coding_arg_post_read_conversion]; | |
7405 CHECK_SYMBOL (val); | |
7406 CODING_ATTR_POST_READ (attrs) = val; | |
7407 | |
7408 val = args[coding_arg_pre_write_conversion]; | |
7409 CHECK_SYMBOL (val); | |
7410 CODING_ATTR_PRE_WRITE (attrs) = val; | |
7411 | |
7412 val = args[coding_arg_default_char]; | |
7413 if (NILP (val)) | |
7414 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
7415 else | |
7416 { | |
7417 CHECK_CHARACTER (val); | |
7418 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
7419 } | |
7420 | |
7421 val = args[coding_arg_plist]; | |
7422 CHECK_LIST (val); | |
7423 CODING_ATTR_PLIST (attrs) = val; | |
7424 | |
7425 if (EQ (coding_type, Qcharset)) | |
7426 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7427 /* 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
|
7428 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
|
7429 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7430 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
|
7431 coding system. |
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 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
|
7434 charset whose ID is NUM. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7435 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7436 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
|
7437 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
|
7438 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
|
7439 */ |
88365 | 7440 val = Fmake_vector (make_number (256), Qnil); |
7441 | |
7442 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
7443 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7444 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
|
7445 int dim = CHARSET_DIMENSION (charset); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7446 int idx = (dim - 1) * 4; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7447 |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7448 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
|
7449 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
|
7450 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7451 Lisp_Object tmp, tmp2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7452 int dim2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7453 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7454 tmp = AREF (val, i); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7455 if (NILP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7456 tmp = XCAR (tail); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7457 else if (NUMBERP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7458 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7459 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
|
7460 if (dim < dim2) |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7461 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
|
7462 else |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7463 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
|
7464 } |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7465 else |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7466 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7467 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
|
7468 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7469 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
|
7470 if (dim < dim2) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7471 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7472 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7473 if (NILP (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7474 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
|
7475 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7476 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7477 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
|
7478 XSETCAR (tmp2, XCAR (tail)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7479 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7480 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7481 ASET (val, i, tmp); |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7482 } |
88365 | 7483 } |
7484 ASET (attrs, coding_attr_charset_valids, val); | |
7485 category = coding_category_charset; | |
7486 } | |
7487 else if (EQ (coding_type, Qccl)) | |
7488 { | |
7489 Lisp_Object valids; | |
7490 | |
7491 if (nargs < coding_arg_ccl_max) | |
7492 goto short_args; | |
7493 | |
7494 val = args[coding_arg_ccl_decoder]; | |
7495 CHECK_CCL_PROGRAM (val); | |
7496 if (VECTORP (val)) | |
7497 val = Fcopy_sequence (val); | |
7498 ASET (attrs, coding_attr_ccl_decoder, val); | |
7499 | |
7500 val = args[coding_arg_ccl_encoder]; | |
7501 CHECK_CCL_PROGRAM (val); | |
7502 if (VECTORP (val)) | |
7503 val = Fcopy_sequence (val); | |
7504 ASET (attrs, coding_attr_ccl_encoder, val); | |
7505 | |
7506 val = args[coding_arg_ccl_valids]; | |
7507 valids = Fmake_string (make_number (256), make_number (0)); | |
7508 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
7509 { | |
7510 val = Fcar (tail); | |
7511 if (INTEGERP (val)) | |
88856 | 7512 ASET (valids, XINT (val), make_number (1)); |
88365 | 7513 else |
7514 { | |
7515 int from, to; | |
7516 | |
7517 CHECK_CONS (val); | |
7518 CHECK_NUMBER (XCAR (val)); | |
7519 CHECK_NUMBER (XCDR (val)); | |
7520 from = XINT (XCAR (val)); | |
7521 to = XINT (XCDR (val)); | |
7522 for (i = from; i <= to; i++) | |
88856 | 7523 ASET (valids, i, make_number (1)); |
88365 | 7524 } |
7525 } | |
7526 ASET (attrs, coding_attr_ccl_valids, valids); | |
7527 | |
7528 category = coding_category_ccl; | |
7529 } | |
7530 else if (EQ (coding_type, Qutf_16)) | |
7531 { | |
7532 Lisp_Object bom, endian; | |
7533 | |
7534 if (nargs < coding_arg_utf16_max) | |
7535 goto short_args; | |
7536 | |
7537 bom = args[coding_arg_utf16_bom]; | |
7538 if (! NILP (bom) && ! EQ (bom, Qt)) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7539 { |
88365 | 7540 CHECK_CONS (bom); |
7541 CHECK_CODING_SYSTEM (XCAR (bom)); | |
7542 CHECK_CODING_SYSTEM (XCDR (bom)); | |
7543 } | |
7544 ASET (attrs, coding_attr_utf_16_bom, bom); | |
7545 | |
7546 endian = args[coding_arg_utf16_endian]; | |
7547 ASET (attrs, coding_attr_utf_16_endian, endian); | |
7548 | |
7549 category = (CONSP (bom) | |
7550 ? coding_category_utf_16_auto | |
7551 : NILP (bom) | |
7552 ? (NILP (endian) | |
7553 ? coding_category_utf_16_be_nosig | |
7554 : coding_category_utf_16_le_nosig) | |
7555 : (NILP (endian) | |
7556 ? coding_category_utf_16_be | |
7557 : coding_category_utf_16_le)); | |
7558 } | |
7559 else if (EQ (coding_type, Qiso_2022)) | |
7560 { | |
7561 Lisp_Object initial, reg_usage, request, flags; | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7562 int i, id; |
88365 | 7563 |
7564 if (nargs < coding_arg_iso2022_max) | |
7565 goto short_args; | |
7566 | |
7567 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
7568 CHECK_VECTOR (initial); | |
7569 for (i = 0; i < 4; i++) | |
7570 { | |
7571 val = Faref (initial, make_number (i)); | |
7572 if (! NILP (val)) | |
7573 { | |
7574 CHECK_CHARSET_GET_ID (val, id); | |
7575 ASET (initial, i, make_number (id)); | |
7576 } | |
7577 else | |
7578 ASET (initial, i, make_number (-1)); | |
7579 } | |
7580 | |
7581 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
7582 CHECK_CONS (reg_usage); | |
7583 CHECK_NATNUM (XCAR (reg_usage)); | |
7584 CHECK_NATNUM (XCDR (reg_usage)); | |
7585 | |
7586 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
7587 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
7588 { | |
7589 int id; | |
7590 | |
7591 val = Fcar (tail); | |
7592 CHECK_CONS (val); | |
7593 CHECK_CHARSET_GET_ID (XCAR (val), id); | |
7594 CHECK_NATNUM (XCDR (val)); | |
7595 if (XINT (XCDR (val)) >= 4) | |
7596 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
7597 XCAR (val) = make_number (id); | |
7598 } | |
7599 | |
7600 flags = args[coding_arg_iso2022_flags]; | |
7601 CHECK_NATNUM (flags); | |
7602 i = XINT (flags); | |
7603 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
7604 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
7605 | |
7606 ASET (attrs, coding_attr_iso_initial, initial); | |
7607 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
7608 ASET (attrs, coding_attr_iso_request, request); | |
7609 ASET (attrs, coding_attr_iso_flags, flags); | |
7610 setup_iso_safe_charsets (attrs); | |
7611 | |
7612 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
7613 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
7614 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
7615 ? coding_category_iso_7_else | |
7616 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
7617 ? coding_category_iso_7 | |
7618 : coding_category_iso_7_tight); | |
7619 else | |
7620 { | |
7621 int id = XINT (AREF (initial, 1)); | |
7622 | |
88977
3b05c02eebf2
(Fdefine_coding_system_internal): Fix category setting
Kenichi Handa <handa@m17n.org>
parents:
88950
diff
changeset
|
7623 category = (((i & CODING_ISO_FLAG_LOCKING_SHIFT) |
88365 | 7624 || EQ (args[coding_arg_charset_list], Qiso_2022) |
7625 || id < 0) | |
7626 ? coding_category_iso_8_else | |
7627 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
7628 ? coding_category_iso_8_1 | |
7629 : coding_category_iso_8_2); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7630 } |
88365 | 7631 } |
7632 else if (EQ (coding_type, Qemacs_mule)) | |
7633 { | |
7634 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
7635 ASET (attrs, coding_attr_emacs_mule_full, Qt); | |
7636 | |
7637 category = coding_category_emacs_mule; | |
7638 } | |
7639 else if (EQ (coding_type, Qshift_jis)) | |
7640 { | |
7641 | |
7642 struct charset *charset; | |
7643 | |
7644 if (XINT (Flength (charset_list)) != 3) | |
7645 error ("There should be just three charsets"); | |
7646 | |
7647 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7648 if (CHARSET_DIMENSION (charset) != 1) | |
7649 error ("Dimension of charset %s is not one", | |
7650 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7651 | |
7652 charset_list = XCDR (charset_list); | |
7653 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7654 if (CHARSET_DIMENSION (charset) != 1) | |
7655 error ("Dimension of charset %s is not one", | |
7656 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7657 | |
7658 charset_list = XCDR (charset_list); | |
7659 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7660 if (CHARSET_DIMENSION (charset) != 2) | |
7661 error ("Dimension of charset %s is not two", | |
7662 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7663 | |
7664 category = coding_category_sjis; | |
7665 Vsjis_coding_system = name; | |
7666 } | |
7667 else if (EQ (coding_type, Qbig5)) | |
7668 { | |
7669 struct charset *charset; | |
7670 | |
7671 if (XINT (Flength (charset_list)) != 2) | |
7672 error ("There should be just two charsets"); | |
7673 | |
7674 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7675 if (CHARSET_DIMENSION (charset) != 1) | |
7676 error ("Dimension of charset %s is not one", | |
7677 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7678 | |
7679 charset_list = XCDR (charset_list); | |
7680 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
7681 if (CHARSET_DIMENSION (charset) != 2) | |
7682 error ("Dimension of charset %s is not two", | |
7683 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
7684 | |
7685 category = coding_category_big5; | |
7686 Vbig5_coding_system = name; | |
7687 } | |
7688 else if (EQ (coding_type, Qraw_text)) | |
7689 category = coding_category_raw_text; | |
7690 else if (EQ (coding_type, Qutf_8)) | |
7691 category = coding_category_utf_8; | |
7692 else if (EQ (coding_type, Qundecided)) | |
7693 category = coding_category_undecided; | |
7694 else | |
7695 error ("Invalid coding system type: %s", | |
7696 XSYMBOL (coding_type)->name->data); | |
7697 | |
7698 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
7699 | |
7700 eol_type = args[coding_arg_eol_type]; | |
7701 if (! NILP (eol_type) | |
7702 && ! EQ (eol_type, Qunix) | |
7703 && ! EQ (eol_type, Qdos) | |
7704 && ! EQ (eol_type, Qmac)) | |
7705 error ("Invalid eol-type"); | |
7706 | |
7707 aliases = Fcons (name, Qnil); | |
7708 | |
7709 if (NILP (eol_type)) | |
7710 { | |
7711 eol_type = make_subsidiaries (name); | |
7712 for (i = 0; i < 3; i++) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7713 { |
88365 | 7714 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
7715 | |
7716 this_name = AREF (eol_type, i); | |
7717 this_aliases = Fcons (this_name, Qnil); | |
7718 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
7719 this_spec = Fmake_vector (make_number (3), attrs); | |
7720 ASET (this_spec, 1, this_aliases); | |
7721 ASET (this_spec, 2, this_eol_type); | |
7722 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
7723 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
7724 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (this_name), Qnil), | |
7725 Vcoding_system_alist); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7726 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7727 } |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7728 |
88365 | 7729 spec_vec = Fmake_vector (make_number (3), attrs); |
7730 ASET (spec_vec, 1, aliases); | |
7731 ASET (spec_vec, 2, eol_type); | |
7732 | |
7733 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
7734 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
7735 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), | |
7736 Vcoding_system_alist); | |
7737 | |
7738 { | |
7739 int id = coding_categories[category].id; | |
7740 | |
7741 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
7742 setup_coding_system (name, &coding_categories[category]); | |
7743 } | |
7744 | |
7745 return Qnil; | |
7746 | |
7747 short_args: | |
7748 return Fsignal (Qwrong_number_of_arguments, | |
7749 Fcons (intern ("define-coding-system-internal"), | |
7750 make_number (nargs))); | |
7751 } | |
7752 | |
88645 | 7753 /* Fixme: should this record the alias relationships for |
7754 diagnostics? */ | |
88365 | 7755 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, |
7756 Sdefine_coding_system_alias, 2, 2, 0, | |
7757 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
7758 (alias, coding_system) | |
7759 Lisp_Object alias, coding_system; | |
7760 { | |
7761 Lisp_Object spec, aliases, eol_type; | |
7762 | |
7763 CHECK_SYMBOL (alias); | |
7764 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7765 aliases = AREF (spec, 1); | |
7766 while (!NILP (XCDR (aliases))) | |
7767 aliases = XCDR (aliases); | |
7768 XCDR (aliases) = Fcons (alias, Qnil); | |
7769 | |
7770 eol_type = AREF (spec, 2); | |
7771 if (VECTORP (eol_type)) | |
7772 { | |
7773 Lisp_Object subsidiaries; | |
7774 int i; | |
7775 | |
7776 subsidiaries = make_subsidiaries (alias); | |
7777 for (i = 0; i < 3; i++) | |
7778 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
7779 AREF (eol_type, i)); | |
7780 | |
7781 ASET (spec, 2, subsidiaries); | |
7782 } | |
7783 | |
7784 Fputhash (alias, spec, Vcoding_system_hash_table); | |
88485 | 7785 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
7786 Vcoding_system_alist); | |
88365 | 7787 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7788 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7789 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7790 |
88365 | 7791 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
7792 1, 1, 0, | |
7793 doc: /* Return the base of CODING-SYSTEM. | |
88645 | 7794 Any alias or subsidiary coding system is not a base coding system. */) |
88365 | 7795 (coding_system) |
7796 Lisp_Object coding_system; | |
7797 { | |
7798 Lisp_Object spec, attrs; | |
7799 | |
7800 if (NILP (coding_system)) | |
7801 return (Qno_conversion); | |
7802 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7803 attrs = AREF (spec, 0); | |
7804 return CODING_ATTR_BASE_NAME (attrs); | |
7805 } | |
7806 | |
7807 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
7808 1, 1, 0, | |
7809 doc: "Return the property list of CODING-SYSTEM.") | |
7810 (coding_system) | |
7811 Lisp_Object coding_system; | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7812 { |
88365 | 7813 Lisp_Object spec, attrs; |
7814 | |
7815 if (NILP (coding_system)) | |
7816 coding_system = Qno_conversion; | |
7817 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
7818 attrs = AREF (spec, 0); | |
7819 return CODING_ATTR_PLIST (attrs); | |
7820 } | |
7821 | |
7822 | |
7823 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
7824 1, 1, 0, | |
88645 | 7825 doc: /* Return the list of aliases of CODING-SYSTEM. */) |
88365 | 7826 (coding_system) |
7827 Lisp_Object coding_system; | |
7828 { | |
7829 Lisp_Object spec; | |
7830 | |
7831 if (NILP (coding_system)) | |
7832 coding_system = Qno_conversion; | |
7833 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
88645 | 7834 return AREF (spec, 1); |
88365 | 7835 } |
7836 | |
7837 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
7838 Scoding_system_eol_type, 1, 1, 0, | |
7839 doc: /* Return eol-type of CODING-SYSTEM. | |
7840 An eol-type is integer 0, 1, 2, or a vector of coding systems. | |
7841 | |
7842 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
7843 and CR respectively. | |
7844 | |
7845 A vector value indicates that a format of end-of-line should be | |
7846 detected automatically. Nth element of the vector is the subsidiary | |
7847 coding system whose eol-type is N. */) | |
7848 (coding_system) | |
7849 Lisp_Object coding_system; | |
7850 { | |
7851 Lisp_Object spec, eol_type; | |
7852 int n; | |
7853 | |
7854 if (NILP (coding_system)) | |
7855 coding_system = Qno_conversion; | |
7856 if (! CODING_SYSTEM_P (coding_system)) | |
7857 return Qnil; | |
7858 spec = CODING_SYSTEM_SPEC (coding_system); | |
7859 eol_type = AREF (spec, 2); | |
7860 if (VECTORP (eol_type)) | |
7861 return Fcopy_sequence (eol_type); | |
7862 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
7863 return make_number (n); | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7864 } |
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
7865 |
17052 | 7866 #endif /* emacs */ |
7867 | |
7868 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7869 /*** 9. Post-amble ***/ |
17052 | 7870 |
21514 | 7871 void |
17052 | 7872 init_coding_once () |
7873 { | |
7874 int i; | |
7875 | |
88365 | 7876 for (i = 0; i < coding_category_max; i++) |
7877 { | |
7878 coding_categories[i].id = -1; | |
7879 coding_priorities[i] = i; | |
7880 } | |
17052 | 7881 |
7882 /* ISO2022 specific initialize routine. */ | |
7883 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
|
7884 iso_code_class[i] = ISO_control_0; |
17052 | 7885 for (i = 0x21; i < 0x7F; i++) |
7886 iso_code_class[i] = ISO_graphic_plane_0; | |
7887 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
|
7888 iso_code_class[i] = ISO_control_1; |
17052 | 7889 for (i = 0xA1; i < 0xFF; i++) |
7890 iso_code_class[i] = ISO_graphic_plane_1; | |
7891 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
7892 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
7893 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
7894 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
7895 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
7896 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
7897 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
7898 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
7899 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
7900 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
7901 | |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
7902 inhibit_pre_post_conversion = 0; |
88365 | 7903 |
7904 for (i = 0; i < 256; i++) | |
7905 { | |
7906 emacs_mule_bytes[i] = 1; | |
7907 } | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7908 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_11] = 3; |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7909 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_12] = 3; |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7910 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_21] = 4; |
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7911 emacs_mule_bytes[EMACS_MULE_LEADING_CODE_PRIVATE_22] = 4; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7912 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7913 |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7914 #ifdef emacs |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7915 |
21514 | 7916 void |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7917 syms_of_coding () |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7918 { |
88365 | 7919 staticpro (&Vcoding_system_hash_table); |
7920 Vcoding_system_hash_table = Fmakehash (Qeq); | |
7921 | |
7922 staticpro (&Vsjis_coding_system); | |
7923 Vsjis_coding_system = Qnil; | |
7924 | |
7925 staticpro (&Vbig5_coding_system); | |
7926 Vbig5_coding_system = Qnil; | |
7927 | |
7928 staticpro (&Vcode_conversion_work_buf_list); | |
7929 Vcode_conversion_work_buf_list = Qnil; | |
7930 | |
7931 staticpro (&Vcode_conversion_reused_work_buf); | |
7932 Vcode_conversion_reused_work_buf = Qnil; | |
7933 | |
7934 DEFSYM (Qcharset, "charset"); | |
7935 DEFSYM (Qtarget_idx, "target-idx"); | |
7936 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7937 Fset (Qcoding_system_history, Qnil); |
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
7938 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7939 /* 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
|
7940 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
|
7941 /* 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
|
7942 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
|
7943 |
88365 | 7944 DEFSYM (Qcall_process, "call-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7945 /* 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
|
7946 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
|
7947 |
88365 | 7948 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
|
7949 /* 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
|
7950 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
|
7951 |
88365 | 7952 DEFSYM (Qstart_process, "start-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7953 /* 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
|
7954 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
|
7955 |
88365 | 7956 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
|
7957 /* 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
|
7958 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
|
7959 |
88365 | 7960 DEFSYM (Qcoding_system, "coding-system"); |
7961 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
7962 | |
7963 DEFSYM (Qeol_type, "eol-type"); | |
7964 DEFSYM (Qunix, "unix"); | |
7965 DEFSYM (Qdos, "dos"); | |
7966 | |
7967 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
7968 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
7969 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
7970 DEFSYM (Qdefault_char, "default-char"); | |
7971 DEFSYM (Qundecided, "undecided"); | |
7972 DEFSYM (Qno_conversion, "no-conversion"); | |
7973 DEFSYM (Qraw_text, "raw-text"); | |
7974 | |
7975 DEFSYM (Qiso_2022, "iso-2022"); | |
7976 | |
7977 DEFSYM (Qutf_8, "utf-8"); | |
7978 | |
7979 DEFSYM (Qutf_16, "utf-16"); | |
7980 DEFSYM (Qutf_16_be, "utf-16-be"); | |
7981 DEFSYM (Qutf_16_be_nosig, "utf-16-be-nosig"); | |
7982 DEFSYM (Qutf_16_le, "utf-16-l3"); | |
7983 DEFSYM (Qutf_16_le_nosig, "utf-16-le-nosig"); | |
7984 DEFSYM (Qsignature, "signature"); | |
7985 DEFSYM (Qendian, "endian"); | |
7986 DEFSYM (Qbig, "big"); | |
7987 DEFSYM (Qlittle, "little"); | |
7988 | |
7989 DEFSYM (Qshift_jis, "shift-jis"); | |
7990 DEFSYM (Qbig5, "big5"); | |
7991 | |
7992 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
7993 | |
7994 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
17052 | 7995 Fput (Qcoding_system_error, Qerror_conditions, |
7996 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
7997 Fput (Qcoding_system_error, Qerror_message, | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
7998 build_string ("Invalid coding system")); |
17052 | 7999 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8000 /* 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
|
8001 Setting this variable twice is harmless. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8002 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
|
8003 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
88365 | 8004 |
8005 DEFSYM (Qtranslation_table, "translation-table"); | |
8006 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); | |
8007 DEFSYM (Qtranslation_table_id, "translation-table-id"); | |
8008 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
8009 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
8010 | |
8011 DEFSYM (Qvalid_codes, "valid-codes"); | |
8012 | |
8013 DEFSYM (Qemacs_mule, "emacs-mule"); | |
8014 | |
8015 Vcoding_category_table | |
8016 = Fmake_vector (make_number (coding_category_max), Qnil); | |
8017 staticpro (&Vcoding_category_table); | |
8018 /* Followings are target of code detection. */ | |
8019 ASET (Vcoding_category_table, coding_category_iso_7, | |
8020 intern ("coding-category-iso-7")); | |
8021 ASET (Vcoding_category_table, coding_category_iso_7_tight, | |
8022 intern ("coding-category-iso-7-tight")); | |
8023 ASET (Vcoding_category_table, coding_category_iso_8_1, | |
8024 intern ("coding-category-iso-8-1")); | |
8025 ASET (Vcoding_category_table, coding_category_iso_8_2, | |
8026 intern ("coding-category-iso-8-2")); | |
8027 ASET (Vcoding_category_table, coding_category_iso_7_else, | |
8028 intern ("coding-category-iso-7-else")); | |
8029 ASET (Vcoding_category_table, coding_category_iso_8_else, | |
8030 intern ("coding-category-iso-8-else")); | |
8031 ASET (Vcoding_category_table, coding_category_utf_8, | |
8032 intern ("coding-category-utf-8")); | |
8033 ASET (Vcoding_category_table, coding_category_utf_16_be, | |
8034 intern ("coding-category-utf-16-be")); | |
8035 ASET (Vcoding_category_table, coding_category_utf_16_le, | |
8036 intern ("coding-category-utf-16-le")); | |
8037 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, | |
8038 intern ("coding-category-utf-16-be-nosig")); | |
8039 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, | |
8040 intern ("coding-category-utf-16-le-nosig")); | |
8041 ASET (Vcoding_category_table, coding_category_charset, | |
8042 intern ("coding-category-charset")); | |
8043 ASET (Vcoding_category_table, coding_category_sjis, | |
8044 intern ("coding-category-sjis")); | |
8045 ASET (Vcoding_category_table, coding_category_big5, | |
8046 intern ("coding-category-big5")); | |
8047 ASET (Vcoding_category_table, coding_category_ccl, | |
8048 intern ("coding-category-ccl")); | |
8049 ASET (Vcoding_category_table, coding_category_emacs_mule, | |
8050 intern ("coding-category-emacs-mule")); | |
8051 /* Followings are NOT target of code detection. */ | |
8052 ASET (Vcoding_category_table, coding_category_raw_text, | |
8053 intern ("coding-category-raw-text")); | |
8054 ASET (Vcoding_category_table, coding_category_undecided, | |
8055 intern ("coding-category-undecided")); | |
8056 | |
17052 | 8057 defsubr (&Scoding_system_p); |
8058 defsubr (&Sread_coding_system); | |
8059 defsubr (&Sread_non_nil_coding_system); | |
8060 defsubr (&Scheck_coding_system); | |
8061 defsubr (&Sdetect_coding_region); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8062 defsubr (&Sdetect_coding_string); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8063 defsubr (&Sfind_coding_systems_region_internal); |
88365 | 8064 defsubr (&Scheck_coding_systems_region); |
17052 | 8065 defsubr (&Sdecode_coding_region); |
8066 defsubr (&Sencode_coding_region); | |
8067 defsubr (&Sdecode_coding_string); | |
8068 defsubr (&Sencode_coding_string); | |
8069 defsubr (&Sdecode_sjis_char); | |
8070 defsubr (&Sencode_sjis_char); | |
8071 defsubr (&Sdecode_big5_char); | |
8072 defsubr (&Sencode_big5_char); | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8073 defsubr (&Sset_terminal_coding_system_internal); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8074 defsubr (&Sset_safe_terminal_coding_system_internal); |
17052 | 8075 defsubr (&Sterminal_coding_system); |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8076 defsubr (&Sset_keyboard_coding_system_internal); |
17052 | 8077 defsubr (&Skeyboard_coding_system); |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
8078 defsubr (&Sfind_operation_coding_system); |
88365 | 8079 defsubr (&Sset_coding_system_priority); |
8080 defsubr (&Sdefine_coding_system_internal); | |
8081 defsubr (&Sdefine_coding_system_alias); | |
8082 defsubr (&Scoding_system_base); | |
8083 defsubr (&Scoding_system_plist); | |
8084 defsubr (&Scoding_system_aliases); | |
8085 defsubr (&Scoding_system_eol_type); | |
8086 defsubr (&Scoding_system_priority_list); | |
17052 | 8087 |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8088 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
|
8089 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
|
8090 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8091 Do not alter the value of this variable manually. This variable should be |
88365 | 8092 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
|
8093 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8094 Vcoding_system_list = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8095 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8096 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
|
8097 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
|
8098 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
|
8099 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
|
8100 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8101 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
|
8102 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
|
8103 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8104 Vcoding_system_alist = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8105 |
17052 | 8106 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
|
8107 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
|
8108 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8109 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
|
8110 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
|
8111 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
|
8112 system bound to the corresponding coding-category is selected. */); |
17052 | 8113 { |
8114 int i; | |
8115 | |
8116 Vcoding_category_list = Qnil; | |
88365 | 8117 for (i = coding_category_max - 1; i >= 0; i--) |
17052 | 8118 Vcoding_category_list |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8119 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8120 Vcoding_category_list); |
17052 | 8121 } |
8122 | |
8123 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
|
8124 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
|
8125 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
|
8126 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
|
8127 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
|
8128 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
|
8129 `process-coding-system-alist', and `network-coding-system-alist'. */); |
17052 | 8130 Vcoding_system_for_read = Qnil; |
8131 | |
8132 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
|
8133 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
|
8134 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
|
8135 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
|
8136 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
|
8137 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8138 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
|
8139 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
|
8140 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
|
8141 `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
|
8142 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
|
8143 the value of `buffer-file-coding-system' is used. */); |
17052 | 8144 Vcoding_system_for_write = Qnil; |
8145 | |
8146 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
88365 | 8147 doc: /* |
8148 Coding system used in the latest file or process I/O. */); | |
17052 | 8149 Vlast_coding_system_used = Qnil; |
8150 | |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8151 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
88365 | 8152 doc: /* |
8153 *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
|
8154 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
|
8155 such conversion. */); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8156 inhibit_eol_conversion = 0; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8157 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8158 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
88365 | 8159 doc: /* |
8160 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
|
8161 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
|
8162 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
|
8163 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
|
8164 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8165 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
88365 | 8166 doc: /* |
8167 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
|
8168 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
|
8169 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
|
8170 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
|
8171 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
|
8172 the file contents. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8173 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
|
8174 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
|
8175 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
|
8176 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
|
8177 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
|
8178 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8179 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
|
8180 and the variable `auto-coding-alist'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8181 Vfile_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8182 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8183 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
88365 | 8184 doc: /* |
8185 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
|
8186 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
|
8187 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
|
8188 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
|
8189 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
|
8190 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
|
8191 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
|
8192 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
|
8193 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
|
8194 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
|
8195 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8196 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8197 Vprocess_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8198 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8199 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
88365 | 8200 doc: /* |
8201 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
|
8202 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
|
8203 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
|
8204 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
|
8205 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
|
8206 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
|
8207 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
|
8208 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
|
8209 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
|
8210 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
|
8211 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
|
8212 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8213 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8214 Vnetwork_coding_system_alist = Qnil; |
17052 | 8215 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8216 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
|
8217 doc: /* Coding system to use with system messages. |
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8218 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
|
8219 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
|
8220 |
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
8221 /* 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
|
8222 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
88365 | 8223 doc: /* |
8224 *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
|
8225 eol_mnemonic_unix = build_string (":"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8226 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8227 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
88365 | 8228 doc: /* |
8229 *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
|
8230 eol_mnemonic_dos = build_string ("\\"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8231 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8232 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
88365 | 8233 doc: /* |
8234 *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
|
8235 eol_mnemonic_mac = build_string ("/"); |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8236 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8237 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
88365 | 8238 doc: /* |
8239 *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
|
8240 eol_mnemonic_undecided = build_string (":"); |
17052 | 8241 |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8242 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
88365 | 8243 doc: /* |
8244 *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
|
8245 Venable_character_translation = Qt; |
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8246 |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8247 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
|
8248 &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
|
8249 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
|
8250 Vstandard_translation_table_for_decode = Qnil; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8251 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8252 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
|
8253 &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
|
8254 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
|
8255 Vstandard_translation_table_for_encode = Qnil; |
17052 | 8256 |
88365 | 8257 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
|
8258 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
|
8259 While encoding, if a charset (car part of an element) is found, |
88365 | 8260 designate it with the escape sequence identifying revision (cdr part |
8261 of the element). */); | |
8262 Vcharset_revision_table = Qnil; | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8263 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8264 DEFVAR_LISP ("default-process-coding-system", |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8265 &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
|
8266 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
|
8267 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
|
8268 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
|
8269 Vdefault_process_coding_system = Qnil; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8270 |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8271 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
88365 | 8272 doc: /* |
8273 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
|
8274 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
|
8275 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
|
8276 \(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
|
8277 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
|
8278 `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
|
8279 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
|
8280 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
|
8281 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
|
8282 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8283 DEFVAR_LISP ("select-safe-coding-system-function", |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8284 &Vselect_safe_coding_system_function, |
88365 | 8285 doc: /* |
8286 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
|
8287 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8288 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
|
8289 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
|
8290 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
|
8291 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8292 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
|
8293 Vselect_safe_coding_system_function = Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8294 |
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
8295 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8296 &inhibit_iso_escape_detection, |
88365 | 8297 doc: /* |
8298 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
|
8299 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8300 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
|
8301 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
|
8302 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
|
8303 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
|
8304 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
|
8305 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8306 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
|
8307 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
|
8308 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
|
8309 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
|
8310 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
|
8311 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8312 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
|
8313 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
|
8314 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
|
8315 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
|
8316 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
|
8317 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8318 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
|
8319 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
|
8320 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
|
8321 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
|
8322 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8323 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8324 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
|
8325 Lisp_Object plist[14]; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8326 int i; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8327 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8328 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
|
8329 args[i] = Qnil; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8330 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8331 plist[0] = intern (":name"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8332 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
|
8333 plist[2] = intern (":mnemonic"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8334 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
|
8335 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
|
8336 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
|
8337 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
|
8338 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
|
8339 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
|
8340 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
|
8341 plist[10] = intern (":docstring"); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8342 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
|
8343 \n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8344 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
|
8345 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
|
8346 character."); |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8347 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
|
8348 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
|
8349 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
|
8350 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
|
8351 } |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8352 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8353 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
|
8354 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
|
8355 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
17052 | 8356 } |
8357 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8358 char * |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8359 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
|
8360 int error_number; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8361 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8362 char *str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8363 |
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
8364 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
|
8365 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
|
8366 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8367 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
|
8368 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8369 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
|
8370 Vlocale_coding_system, |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8371 0); |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8372 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
|
8373 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8374 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8375 return str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8376 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8377 |
17052 | 8378 #endif /* emacs */ |