Mercurial > emacs
annotate src/coding.c @ 105972:371db60eff06
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 13 Nov 2009 06:21:38 +0000 |
parents | ba3ffbd9c422 |
children | fea46c7aca79 |
rev | line source |
---|---|
88936 | 1 /* Coding system handler (conversion, detection, etc). |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68567
diff
changeset
|
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, |
100951 | 3 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
74605
6ee41fdd69ff
Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents:
73995
diff
changeset
|
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
100951 | 5 2005, 2006, 2007, 2008, 2009 |
67658 | 6 National Institute of Advanced Industrial Science and Technology (AIST) |
7 Registration Number H14PRO021 | |
89483 | 8 Copyright (C) 2003 |
88365 | 9 National Institute of Advanced Industrial Science and Technology (AIST) |
10 Registration Number H13PRO009 | |
17052 | 11 |
17071 | 12 This file is part of GNU Emacs. |
13 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94944
diff
changeset
|
14 GNU Emacs is free software: you can redistribute it and/or modify |
17071 | 15 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94944
diff
changeset
|
16 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94944
diff
changeset
|
17 (at your option) any later version. |
17071 | 18 |
19 GNU Emacs is distributed in the hope that it will be useful, | |
20 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 GNU General Public License for more details. | |
23 | |
24 You should have received a copy of the GNU General Public License | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94944
diff
changeset
|
25 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
17052 | 26 |
27 /*** TABLE OF CONTENTS *** | |
28 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
29 0. General comments |
17052 | 30 1. Preamble |
88365 | 31 2. Emacs' internal format (emacs-utf-8) handlers |
32 3. UTF-8 handlers | |
33 4. UTF-16 handlers | |
34 5. Charset-base coding systems handlers | |
35 6. emacs-mule (old Emacs' internal format) handlers | |
36 7. ISO2022 handlers | |
37 8. Shift-JIS and BIG5 handlers | |
38 9. CCL handlers | |
39 10. C library functions | |
40 11. Emacs Lisp library functions | |
41 12. Postamble | |
17052 | 42 |
43 */ | |
44 | |
88365 | 45 /*** 0. General comments *** |
46 | |
47 | |
48 CODING SYSTEM | |
49 | |
88485 | 50 A coding system is an object for an encoding mechanism that contains |
51 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
|
52 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
|
53 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
|
54 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
|
55 `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
|
56 character sequence of emacs-utf-8 to a byte sequence of a specific |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
57 coding system. |
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
58 |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
59 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
|
60 C level, a coding system is represented by a vector of attributes |
88485 | 61 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
|
62 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
|
63 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
|
64 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
65 Coding systems are classified into the following types depending on |
88485 | 66 the encoding mechanism. Here's a brief description of the types. |
88365 | 67 |
68 o UTF-8 | |
69 | |
70 o UTF-16 | |
71 | |
72 o Charset-base coding system | |
73 | |
74 A coding system defined by one or more (coded) character sets. | |
88485 | 75 Decoding and encoding are done by a code converter defined for each |
88365 | 76 character set. |
77 | |
88485 | 78 o Old Emacs internal format (emacs-mule) |
79 | |
80 The coding system adopted by old versions of Emacs (20 and 21). | |
88365 | 81 |
82 o ISO2022-base coding system | |
17052 | 83 |
84 The most famous coding system for multiple character sets. X's | |
88365 | 85 Compound Text, various EUCs (Extended Unix Code), and coding systems |
86 used in the Internet communication such as ISO-2022-JP are all | |
87 variants of ISO2022. | |
88 | |
89 o SJIS (or Shift-JIS or MS-Kanji-Code) | |
42104
d69c2368e549
(DECODE_COMPOSITION_END): Fixed a typo in the last
Sam Steingold <sds@gnu.org>
parents:
42103
diff
changeset
|
90 |
17052 | 91 A coding system to encode character sets: ASCII, JISX0201, and |
92 JISX0208. Widely used for PC's in Japan. Details are described in | |
88365 | 93 section 8. |
94 | |
95 o BIG5 | |
96 | |
97 A coding system to encode character sets: ASCII and Big5. Widely | |
35053 | 98 used for Chinese (mainly in Taiwan and Hong Kong). Details are |
88365 | 99 described in section 8. In this file, when we write "big5" (all |
100 lowercase), we mean the coding system, and when we write "Big5" | |
101 (capitalized), we mean the character set. | |
102 | |
103 o CCL | |
104 | |
88485 | 105 If a user wants to decode/encode text encoded in a coding system |
88365 | 106 not listed above, he can supply a decoder and an encoder for it in |
107 CCL (Code Conversion Language) programs. Emacs executes the CCL | |
108 program while decoding/encoding. | |
109 | |
110 o Raw-text | |
111 | |
88771 | 112 A coding system for text containing raw eight-bit data. Emacs |
88485 | 113 treats each byte of source text as a character (except for |
88365 | 114 end-of-line conversion). |
115 | |
116 o No-conversion | |
117 | |
118 Like raw text, but don't do end-of-line conversion. | |
119 | |
120 | |
121 END-OF-LINE FORMAT | |
122 | |
88485 | 123 How text end-of-line is encoded depends on operating system. For |
88365 | 124 instance, Unix's format is just one byte of LF (line-feed) code, |
18766 | 125 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
|
126 `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
|
127 `carriage-return'. |
17052 | 128 |
35053 | 129 Since text character encoding and end-of-line encoding are |
88365 | 130 independent, any coding system described above can take any format |
131 of end-of-line (except for no-conversion). | |
17052 | 132 |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
133 STRUCT CODING_SYSTEM |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
134 |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
135 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
|
136 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
|
137 This structure keeps various information about a specific code |
88485 | 138 conversion (e.g. the location of source and destination data). |
17052 | 139 |
140 */ | |
141 | |
88365 | 142 /* COMMON MACROS */ |
143 | |
144 | |
17052 | 145 /*** GENERAL NOTES on `detect_coding_XXX ()' functions *** |
146 | |
88365 | 147 These functions check if a byte sequence specified as a source in |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
148 CODING conforms to the format of XXX, and update the members of |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
149 DETECT_INFO. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
150 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
151 Return 1 if the byte sequence conforms to XXX, otherwise return 0. |
88365 | 152 |
153 Below is the template of these functions. */ | |
154 | |
17052 | 155 #if 0 |
88365 | 156 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
157 detect_coding_XXX (coding, detect_info) |
88365 | 158 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
159 struct coding_detection_info *detect_info; |
17052 | 160 { |
90070
95879cc1ed20
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Miles Bader <miles@gnu.org>
diff
changeset
|
161 const unsigned char *src = coding->source; |
95879cc1ed20
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Miles Bader <miles@gnu.org>
diff
changeset
|
162 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 163 int multibytep = coding->src_multibyte; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
164 int consumed_chars = 0; |
88365 | 165 int found = 0; |
166 ...; | |
167 | |
168 while (1) | |
169 { | |
170 /* Get one byte from the source. If the souce is exausted, jump | |
171 to no_more_source:. */ | |
172 ONE_MORE_BYTE (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
173 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
174 if (! __C_conforms_to_XXX___ (c)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
175 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
176 if (! __C_strongly_suggests_XXX__ (c)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
177 found = CATEGORY_MASK_XXX; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
178 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
179 /* The byte sequence is invalid for XXX. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
180 detect_info->rejected |= CATEGORY_MASK_XXX; |
88365 | 181 return 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
182 |
88365 | 183 no_more_source: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
184 /* The source exausted successfully. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
185 detect_info->found |= found; |
88365 | 186 return 1; |
17052 | 187 } |
188 #endif | |
189 | |
190 /*** GENERAL NOTES on `decode_coding_XXX ()' functions *** | |
191 | |
88365 | 192 These functions decode a byte sequence specified as a source by |
193 CODING. The resulting multibyte text goes to a place pointed to by | |
194 CODING->charbuf, the length of which should not exceed | |
195 CODING->charbuf_size; | |
196 | |
197 These functions set the information of original and decoded texts in | |
198 CODING->consumed, CODING->consumed_char, and CODING->charbuf_used. | |
199 They also set CODING->result to one of CODING_RESULT_XXX indicating | |
200 how the decoding is finished. | |
201 | |
202 Below is the template of these functions. */ | |
203 | |
17052 | 204 #if 0 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
205 static void |
88365 | 206 decode_coding_XXXX (coding) |
17052 | 207 struct coding_system *coding; |
208 { | |
90070
95879cc1ed20
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Miles Bader <miles@gnu.org>
diff
changeset
|
209 const unsigned char *src = coding->source + coding->consumed; |
95879cc1ed20
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Miles Bader <miles@gnu.org>
diff
changeset
|
210 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 211 /* SRC_BASE remembers the start position in source in each loop. |
212 The loop will be exited when there's not enough source code, or | |
213 when there's no room in CHARBUF for a decoded character. */ | |
90070
95879cc1ed20
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Miles Bader <miles@gnu.org>
diff
changeset
|
214 const unsigned char *src_base; |
88365 | 215 /* A buffer to produce decoded characters. */ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
216 int *charbuf = coding->charbuf + coding->charbuf_used; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
217 int *charbuf_end = coding->charbuf + coding->charbuf_size; |
88365 | 218 int multibytep = coding->src_multibyte; |
219 | |
220 while (1) | |
221 { | |
222 src_base = src; | |
223 if (charbuf < charbuf_end) | |
224 /* No more room to produce a decoded character. */ | |
225 break; | |
226 ONE_MORE_BYTE (c); | |
227 /* Decode it. */ | |
228 } | |
229 | |
230 no_more_source: | |
231 if (src_base < src_end | |
232 && coding->mode & CODING_MODE_LAST_BLOCK) | |
233 /* If the source ends by partial bytes to construct a character, | |
234 treat them as eight-bit raw data. */ | |
235 while (src_base < src_end && charbuf < charbuf_end) | |
236 *charbuf++ = *src_base++; | |
237 /* Remember how many bytes and characters we consumed. If the | |
238 source is multibyte, the bytes and chars are not identical. */ | |
239 coding->consumed = coding->consumed_char = src_base - coding->source; | |
240 /* Remember how many characters we produced. */ | |
241 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 242 } |
243 #endif | |
244 | |
245 /*** GENERAL NOTES on `encode_coding_XXX ()' functions *** | |
246 | |
88365 | 247 These functions encode SRC_BYTES length text at SOURCE of Emacs' |
248 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
|
249 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
|
250 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
|
251 |
88365 | 252 These functions set the information of original and encoded texts in |
253 the members produced, produced_char, consumed, and consumed_char of | |
254 the structure *CODING. They also set the member result to one of | |
255 CODING_RESULT_XXX indicating how the encoding finished. | |
256 | |
257 DST_BYTES zero means that source area and destination area are | |
258 overlapped, which means that we can produce a encoded text until it | |
259 reaches at the head of not-yet-encoded source text. | |
260 | |
261 Below is a template of these functions. */ | |
17052 | 262 #if 0 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
263 static void |
88365 | 264 encode_coding_XXX (coding) |
17052 | 265 struct coding_system *coding; |
266 { | |
88365 | 267 int multibytep = coding->dst_multibyte; |
268 int *charbuf = coding->charbuf; | |
269 int *charbuf_end = charbuf->charbuf + coding->charbuf_used; | |
270 unsigned char *dst = coding->destination + coding->produced; | |
271 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
272 unsigned char *adjusted_dst_end = dst_end - _MAX_BYTES_PRODUCED_IN_LOOP_; | |
273 int produced_chars = 0; | |
274 | |
275 for (; charbuf < charbuf_end && dst < adjusted_dst_end; charbuf++) | |
276 { | |
277 int c = *charbuf; | |
278 /* Encode C into DST, and increment DST. */ | |
279 } | |
280 label_no_more_destination: | |
281 /* How many chars and bytes we produced. */ | |
282 coding->produced_char += produced_chars; | |
283 coding->produced = dst - coding->destination; | |
17052 | 284 } |
285 #endif | |
286 | |
287 | |
288 /*** 1. Preamble ***/ | |
289 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
290 #include <config.h> |
17052 | 291 #include <stdio.h> |
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105179
diff
changeset
|
292 #include <setjmp.h> |
17052 | 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" | |
83127
5182815e0ee1
Make terminal_coding and keyboard_coding display-local.
Karoly Lorentey <lorentey@elte.hu>
parents:
54320
diff
changeset
|
302 #include "frame.h" |
5182815e0ee1
Make terminal_coding and keyboard_coding display-local.
Karoly Lorentey <lorentey@elte.hu>
parents:
54320
diff
changeset
|
303 #include "termhooks.h" |
17052 | 304 |
88365 | 305 Lisp_Object Vcoding_system_hash_table; |
306 | |
307 Lisp_Object Qcoding_system, Qcoding_aliases, Qeol_type; | |
88646
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
308 Lisp_Object Qunix, Qdos; |
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
309 extern Lisp_Object Qmac; /* frame.c */ |
17052 | 310 Lisp_Object Qbuffer_file_coding_system; |
311 Lisp_Object Qpost_read_conversion, Qpre_write_conversion; | |
88365 | 312 Lisp_Object Qdefault_char; |
19612
783efd6c7c1e
(Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents:
19546
diff
changeset
|
313 Lisp_Object Qno_conversion, Qundecided; |
88365 | 314 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
315 Lisp_Object Qbig, Qlittle; |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
316 Lisp_Object Qcoding_system_history; |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
317 Lisp_Object Qvalid_codes; |
100303
3e044fa54e4f
* coding.c (QCdefault_char): Rename from QCdefalut_char.
Juanma Barranquero <lekktu@gmail.com>
parents:
100262
diff
changeset
|
318 Lisp_Object QCcategory, QCmnemonic, QCdefault_char; |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
319 Lisp_Object QCdecode_translation_table, QCencode_translation_table; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
320 Lisp_Object QCpost_read_conversion, QCpre_write_conversion; |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
321 Lisp_Object QCascii_compatible_p; |
17052 | 322 |
323 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | |
64251
3de1b955c31a
* coding.c (Qprocess_argument):
Kim F. Storm <storm@cua.dk>
parents:
64084
diff
changeset
|
324 Lisp_Object Qcall_process, Qcall_process_region; |
17052 | 325 Lisp_Object Qstart_process, Qopen_network_stream; |
326 Lisp_Object Qtarget_idx; | |
327 | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
328 Lisp_Object Qinsufficient_source, Qinconsistent_eol, Qinvalid_source; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
329 Lisp_Object Qinterrupted, Qinsufficient_memory; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
330 |
79107
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
331 extern Lisp_Object Qcompletion_ignore_case; |
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
332 |
52794
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
333 /* If a symbol has this property, evaluate the value to define the |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
334 symbol as a coding system. */ |
90272
f1df126ec7de
Sync to HEAD for handling autoload-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
90263
diff
changeset
|
335 static Lisp_Object Qcoding_system_define_form; |
f1df126ec7de
Sync to HEAD for handling autoload-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
90263
diff
changeset
|
336 |
89483 | 337 int coding_system_require_warning; |
52794
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
338 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
339 Lisp_Object Vselect_safe_coding_system_function; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
340 |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
341 /* 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
|
342 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
|
343 /* Mnemonic string to indicate format of end-of-line is not yet |
17052 | 344 decided. */ |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
345 Lisp_Object eol_mnemonic_undecided; |
17052 | 346 |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
347 /* Format of end-of-line decided by system. This is Qunix on |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
348 Unix and Mac, Qdos on DOS/Windows. |
70520
b6740a317343
(setup_coding_system): For invalid coding-system, set
Kenichi Handa <handa@m17n.org>
parents:
69995
diff
changeset
|
349 This has an effect only for external encoding (i.e. for output to |
b6740a317343
(setup_coding_system): For invalid coding-system, set
Kenichi Handa <handa@m17n.org>
parents:
69995
diff
changeset
|
350 file and process), not for in-buffer or Lisp string encoding. */ |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
351 static Lisp_Object system_eol_type; |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
352 |
17052 | 353 #ifdef emacs |
354 | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
355 Lisp_Object Vcoding_system_list, Vcoding_system_alist; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
356 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
357 Lisp_Object Qcoding_system_p, Qcoding_system_error; |
17052 | 358 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
359 /* 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
|
360 end-of-line format. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
361 Lisp_Object Qemacs_mule, Qraw_text; |
89483 | 362 Lisp_Object Qutf_8_emacs; |
51406 | 363 |
17052 | 364 /* Coding-systems are handed between Emacs Lisp programs and C internal |
365 routines by the following three variables. */ | |
366 /* Coding-system for reading files and receiving data from process. */ | |
367 Lisp_Object Vcoding_system_for_read; | |
368 /* Coding-system for writing files and sending data to process. */ | |
369 Lisp_Object Vcoding_system_for_write; | |
370 /* Coding-system actually used in the latest I/O. */ | |
371 Lisp_Object Vlast_coding_system_used; | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
372 /* Set to non-nil when an error is detected while code conversion. */ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
373 Lisp_Object Vlast_code_conversion_error; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
374 /* A vector of length 256 which contains information about special |
22529 | 375 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
|
376 Lisp_Object Vlatin_extra_code_table; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
377 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
378 /* 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
|
379 int inhibit_eol_conversion; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
380 |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
381 /* Flag to inhibit ISO2022 escape sequence detection. */ |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
382 int inhibit_iso_escape_detection; |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
383 |
101040 | 384 /* Flag to inhibit detection of binary files through null bytes. */ |
385 int inhibit_null_byte_detection; | |
386 | |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
387 /* 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
|
388 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
|
389 |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
390 /* 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
|
391 terminal coding system is nil. */ |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
392 struct coding_system safe_terminal_coding; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
393 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
394 Lisp_Object Vfile_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
395 Lisp_Object Vprocess_coding_system_alist; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
396 Lisp_Object Vnetwork_coding_system_alist; |
17052 | 397 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
398 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
|
399 |
17052 | 400 #endif /* emacs */ |
401 | |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
402 /* 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
|
403 conversion. */ |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
404 Lisp_Object Venable_character_translation; |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
405 /* 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
|
406 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
|
407 /* 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
|
408 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
|
409 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
410 Lisp_Object Qtranslation_table; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
411 Lisp_Object Qtranslation_table_id; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
412 Lisp_Object Qtranslation_table_for_decode; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
413 Lisp_Object Qtranslation_table_for_encode; |
17052 | 414 |
415 /* Alist of charsets vs revision number. */ | |
88365 | 416 static Lisp_Object Vcharset_revision_table; |
17052 | 417 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
418 /* Default coding systems used for process I/O. */ |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
419 Lisp_Object Vdefault_process_coding_system; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
420 |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
421 /* Char table for translating Quail and self-inserting input. */ |
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
422 Lisp_Object Vtranslation_table_for_input; |
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
423 |
88365 | 424 /* Two special coding systems. */ |
425 Lisp_Object Vsjis_coding_system; | |
426 Lisp_Object Vbig5_coding_system; | |
427 | |
428 /* ISO2022 section */ | |
429 | |
430 #define CODING_ISO_INITIAL(coding, reg) \ | |
431 (XINT (AREF (AREF (CODING_ID_ATTRS ((coding)->id), \ | |
432 coding_attr_iso_initial), \ | |
433 reg))) | |
434 | |
435 | |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
436 #define CODING_ISO_REQUEST(coding, charset_id) \ |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
437 (((charset_id) <= (coding)->max_charset_id \ |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
438 ? ((coding)->safe_charsets[charset_id] != 255 \ |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
439 ? (coding)->safe_charsets[charset_id] \ |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
440 : -1) \ |
88365 | 441 : -1)) |
442 | |
443 | |
444 #define CODING_ISO_FLAGS(coding) \ | |
445 ((coding)->spec.iso_2022.flags) | |
446 #define CODING_ISO_DESIGNATION(coding, reg) \ | |
447 ((coding)->spec.iso_2022.current_designation[reg]) | |
448 #define CODING_ISO_INVOCATION(coding, plane) \ | |
449 ((coding)->spec.iso_2022.current_invocation[plane]) | |
450 #define CODING_ISO_SINGLE_SHIFTING(coding) \ | |
451 ((coding)->spec.iso_2022.single_shifting) | |
452 #define CODING_ISO_BOL(coding) \ | |
453 ((coding)->spec.iso_2022.bol) | |
454 #define CODING_ISO_INVOKED_CHARSET(coding, plane) \ | |
455 CODING_ISO_DESIGNATION ((coding), CODING_ISO_INVOCATION ((coding), (plane))) | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
456 #define CODING_ISO_CMP_STATUS(coding) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
457 (&(coding)->spec.iso_2022.cmp_status) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
458 #define CODING_ISO_EXTSEGMENT_LEN(coding) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
459 ((coding)->spec.iso_2022.ctext_extended_segment_len) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
460 #define CODING_ISO_EMBEDDED_UTF_8(coding) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
461 ((coding)->spec.iso_2022.embedded_utf_8) |
88365 | 462 |
463 /* Control characters of ISO2022. */ | |
464 /* code */ /* function */ | |
465 #define ISO_CODE_LF 0x0A /* line-feed */ | |
466 #define ISO_CODE_CR 0x0D /* carriage-return */ | |
467 #define ISO_CODE_SO 0x0E /* shift-out */ | |
468 #define ISO_CODE_SI 0x0F /* shift-in */ | |
469 #define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */ | |
470 #define ISO_CODE_ESC 0x1B /* escape */ | |
471 #define ISO_CODE_SS2 0x8E /* single-shift-2 */ | |
472 #define ISO_CODE_SS3 0x8F /* single-shift-3 */ | |
473 #define ISO_CODE_CSI 0x9B /* control-sequence-introducer */ | |
474 | |
475 /* All code (1-byte) of ISO2022 is classified into one of the | |
476 followings. */ | |
477 enum iso_code_class_type | |
478 { | |
479 ISO_control_0, /* Control codes in the range | |
480 0x00..0x1F and 0x7F, except for the | |
481 following 5 codes. */ | |
482 ISO_shift_out, /* ISO_CODE_SO (0x0E) */ | |
483 ISO_shift_in, /* ISO_CODE_SI (0x0F) */ | |
484 ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ | |
485 ISO_escape, /* ISO_CODE_SO (0x1B) */ | |
486 ISO_control_1, /* Control codes in the range | |
487 0x80..0x9F, except for the | |
488 following 3 codes. */ | |
489 ISO_single_shift_2, /* ISO_CODE_SS2 (0x8E) */ | |
490 ISO_single_shift_3, /* ISO_CODE_SS3 (0x8F) */ | |
491 ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */ | |
492 ISO_0x20_or_0x7F, /* Codes of the values 0x20 or 0x7F. */ | |
493 ISO_graphic_plane_0, /* Graphic codes in the range 0x21..0x7E. */ | |
494 ISO_0xA0_or_0xFF, /* Codes of the values 0xA0 or 0xFF. */ | |
495 ISO_graphic_plane_1 /* Graphic codes in the range 0xA1..0xFE. */ | |
496 }; | |
497 | |
498 /** The macros CODING_ISO_FLAG_XXX defines a flag bit of the | |
499 `iso-flags' attribute of an iso2022 coding system. */ | |
500 | |
501 /* If set, produce long-form designation sequence (e.g. ESC $ ( A) | |
502 instead of the correct short-form sequence (e.g. ESC $ A). */ | |
503 #define CODING_ISO_FLAG_LONG_FORM 0x0001 | |
504 | |
505 /* If set, reset graphic planes and registers at end-of-line to the | |
506 initial state. */ | |
507 #define CODING_ISO_FLAG_RESET_AT_EOL 0x0002 | |
508 | |
509 /* If set, reset graphic planes and registers before any control | |
510 characters to the initial state. */ | |
511 #define CODING_ISO_FLAG_RESET_AT_CNTL 0x0004 | |
512 | |
513 /* If set, encode by 7-bit environment. */ | |
514 #define CODING_ISO_FLAG_SEVEN_BITS 0x0008 | |
515 | |
516 /* If set, use locking-shift function. */ | |
517 #define CODING_ISO_FLAG_LOCKING_SHIFT 0x0010 | |
518 | |
519 /* If set, use single-shift function. Overwrite | |
520 CODING_ISO_FLAG_LOCKING_SHIFT. */ | |
521 #define CODING_ISO_FLAG_SINGLE_SHIFT 0x0020 | |
522 | |
523 /* If set, use designation escape sequence. */ | |
524 #define CODING_ISO_FLAG_DESIGNATION 0x0040 | |
525 | |
526 /* If set, produce revision number sequence. */ | |
527 #define CODING_ISO_FLAG_REVISION 0x0080 | |
528 | |
529 /* If set, produce ISO6429's direction specifying sequence. */ | |
530 #define CODING_ISO_FLAG_DIRECTION 0x0100 | |
531 | |
532 /* If set, assume designation states are reset at beginning of line on | |
533 output. */ | |
534 #define CODING_ISO_FLAG_INIT_AT_BOL 0x0200 | |
535 | |
536 /* If set, designation sequence should be placed at beginning of line | |
537 on output. */ | |
538 #define CODING_ISO_FLAG_DESIGNATE_AT_BOL 0x0400 | |
539 | |
540 /* If set, do not encode unsafe charactes on output. */ | |
541 #define CODING_ISO_FLAG_SAFE 0x0800 | |
542 | |
543 /* If set, extra latin codes (128..159) are accepted as a valid code | |
544 on input. */ | |
545 #define CODING_ISO_FLAG_LATIN_EXTRA 0x1000 | |
546 | |
547 #define CODING_ISO_FLAG_COMPOSITION 0x2000 | |
548 | |
549 #define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 | |
550 | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
551 #define CODING_ISO_FLAG_USE_ROMAN 0x8000 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
552 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
553 #define CODING_ISO_FLAG_USE_OLDJIS 0x10000 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
554 |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
555 #define CODING_ISO_FLAG_FULL_SUPPORT 0x100000 |
88365 | 556 |
557 /* A character to be produced on output if encoding of the original | |
558 character is prohibited by CODING_ISO_FLAG_SAFE. */ | |
559 #define CODING_INHIBIT_CHARACTER_SUBSTITUTION '?' | |
560 | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
561 /* UTF-8 section */ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
562 #define CODING_UTF_8_BOM(coding) \ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
563 ((coding)->spec.utf_8_bom) |
88365 | 564 |
565 /* UTF-16 section */ | |
566 #define CODING_UTF_16_BOM(coding) \ | |
567 ((coding)->spec.utf_16.bom) | |
568 | |
569 #define CODING_UTF_16_ENDIAN(coding) \ | |
570 ((coding)->spec.utf_16.endian) | |
571 | |
572 #define CODING_UTF_16_SURROGATE(coding) \ | |
573 ((coding)->spec.utf_16.surrogate) | |
574 | |
575 | |
576 /* CCL section */ | |
577 #define CODING_CCL_DECODER(coding) \ | |
578 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_decoder) | |
579 #define CODING_CCL_ENCODER(coding) \ | |
580 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_encoder) | |
581 #define CODING_CCL_VALIDS(coding) \ | |
89483 | 582 (SDATA (AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_valids))) |
88365 | 583 |
88771 | 584 /* Index for each coding category in `coding_categories' */ |
88365 | 585 |
586 enum coding_category | |
587 { | |
588 coding_category_iso_7, | |
589 coding_category_iso_7_tight, | |
590 coding_category_iso_8_1, | |
591 coding_category_iso_8_2, | |
592 coding_category_iso_7_else, | |
593 coding_category_iso_8_else, | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
594 coding_category_utf_8_auto, |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
595 coding_category_utf_8_nosig, |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
596 coding_category_utf_8_sig, |
88365 | 597 coding_category_utf_16_auto, |
598 coding_category_utf_16_be, | |
599 coding_category_utf_16_le, | |
600 coding_category_utf_16_be_nosig, | |
601 coding_category_utf_16_le_nosig, | |
602 coding_category_charset, | |
603 coding_category_sjis, | |
604 coding_category_big5, | |
605 coding_category_ccl, | |
606 coding_category_emacs_mule, | |
607 /* All above are targets of code detection. */ | |
608 coding_category_raw_text, | |
609 coding_category_undecided, | |
610 coding_category_max | |
611 }; | |
612 | |
613 /* Definitions of flag bits used in detect_coding_XXXX. */ | |
614 #define CATEGORY_MASK_ISO_7 (1 << coding_category_iso_7) | |
615 #define CATEGORY_MASK_ISO_7_TIGHT (1 << coding_category_iso_7_tight) | |
616 #define CATEGORY_MASK_ISO_8_1 (1 << coding_category_iso_8_1) | |
617 #define CATEGORY_MASK_ISO_8_2 (1 << coding_category_iso_8_2) | |
618 #define CATEGORY_MASK_ISO_7_ELSE (1 << coding_category_iso_7_else) | |
619 #define CATEGORY_MASK_ISO_8_ELSE (1 << coding_category_iso_8_else) | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
620 #define CATEGORY_MASK_UTF_8_AUTO (1 << coding_category_utf_8_auto) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
621 #define CATEGORY_MASK_UTF_8_NOSIG (1 << coding_category_utf_8_nosig) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
622 #define CATEGORY_MASK_UTF_8_SIG (1 << coding_category_utf_8_sig) |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
623 #define CATEGORY_MASK_UTF_16_AUTO (1 << coding_category_utf_16_auto) |
88365 | 624 #define CATEGORY_MASK_UTF_16_BE (1 << coding_category_utf_16_be) |
625 #define CATEGORY_MASK_UTF_16_LE (1 << coding_category_utf_16_le) | |
626 #define CATEGORY_MASK_UTF_16_BE_NOSIG (1 << coding_category_utf_16_be_nosig) | |
627 #define CATEGORY_MASK_UTF_16_LE_NOSIG (1 << coding_category_utf_16_le_nosig) | |
628 #define CATEGORY_MASK_CHARSET (1 << coding_category_charset) | |
629 #define CATEGORY_MASK_SJIS (1 << coding_category_sjis) | |
630 #define CATEGORY_MASK_BIG5 (1 << coding_category_big5) | |
631 #define CATEGORY_MASK_CCL (1 << coding_category_ccl) | |
632 #define CATEGORY_MASK_EMACS_MULE (1 << coding_category_emacs_mule) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
633 #define CATEGORY_MASK_RAW_TEXT (1 << coding_category_raw_text) |
88365 | 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 \ | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
644 | CATEGORY_MASK_UTF_8_AUTO \ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
645 | CATEGORY_MASK_UTF_8_NOSIG \ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
646 | CATEGORY_MASK_UTF_8_SIG \ |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
647 | CATEGORY_MASK_UTF_16_AUTO \ |
88365 | 648 | CATEGORY_MASK_UTF_16_BE \ |
649 | CATEGORY_MASK_UTF_16_LE \ | |
650 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
651 | CATEGORY_MASK_UTF_16_LE_NOSIG \ | |
652 | CATEGORY_MASK_CHARSET \ | |
653 | CATEGORY_MASK_SJIS \ | |
654 | CATEGORY_MASK_BIG5 \ | |
655 | CATEGORY_MASK_CCL \ | |
656 | CATEGORY_MASK_EMACS_MULE) | |
657 | |
658 | |
659 #define CATEGORY_MASK_ISO_7BIT \ | |
660 (CATEGORY_MASK_ISO_7 | CATEGORY_MASK_ISO_7_TIGHT) | |
661 | |
662 #define CATEGORY_MASK_ISO_8BIT \ | |
663 (CATEGORY_MASK_ISO_8_1 | CATEGORY_MASK_ISO_8_2) | |
664 | |
665 #define CATEGORY_MASK_ISO_ELSE \ | |
666 (CATEGORY_MASK_ISO_7_ELSE | CATEGORY_MASK_ISO_8_ELSE) | |
667 | |
668 #define CATEGORY_MASK_ISO_ESCAPE \ | |
669 (CATEGORY_MASK_ISO_7 \ | |
670 | CATEGORY_MASK_ISO_7_TIGHT \ | |
671 | CATEGORY_MASK_ISO_7_ELSE \ | |
672 | CATEGORY_MASK_ISO_8_ELSE) | |
673 | |
674 #define CATEGORY_MASK_ISO \ | |
675 ( CATEGORY_MASK_ISO_7BIT \ | |
676 | CATEGORY_MASK_ISO_8BIT \ | |
677 | CATEGORY_MASK_ISO_ELSE) | |
678 | |
679 #define CATEGORY_MASK_UTF_16 \ | |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
680 (CATEGORY_MASK_UTF_16_AUTO \ |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
681 | CATEGORY_MASK_UTF_16_BE \ |
88365 | 682 | CATEGORY_MASK_UTF_16_LE \ |
683 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
684 | CATEGORY_MASK_UTF_16_LE_NOSIG) | |
685 | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
686 #define CATEGORY_MASK_UTF_8 \ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
687 (CATEGORY_MASK_UTF_8_AUTO \ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
688 | CATEGORY_MASK_UTF_8_NOSIG \ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
689 | CATEGORY_MASK_UTF_8_SIG) |
88365 | 690 |
691 /* List of symbols `coding-category-xxx' ordered by priority. This | |
692 variable is exposed to Emacs Lisp. */ | |
693 static Lisp_Object Vcoding_category_list; | |
694 | |
695 /* Table of coding categories (Lisp symbols). This variable is for | |
696 internal use oly. */ | |
697 static Lisp_Object Vcoding_category_table; | |
698 | |
699 /* Table of coding-categories ordered by priority. */ | |
700 static enum coding_category coding_priorities[coding_category_max]; | |
701 | |
702 /* Nth element is a coding context for the coding system bound to the | |
703 Nth coding category. */ | |
704 static struct coding_system coding_categories[coding_category_max]; | |
705 | |
706 /*** Commonly used macros and functions ***/ | |
707 | |
708 #ifndef min | |
709 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
710 #endif | |
711 #ifndef max | |
712 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
713 #endif | |
714 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
715 #define CODING_GET_INFO(coding, attrs, charset_list) \ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
716 do { \ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
717 (attrs) = CODING_ID_ATTRS ((coding)->id); \ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
718 (charset_list) = CODING_ATTR_CHARSET_LIST (attrs); \ |
88365 | 719 } while (0) |
720 | |
721 | |
722 /* Safely get one byte from the source text pointed by SRC which ends | |
723 at SRC_END, and set C to that byte. If there are not enough bytes | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
724 in the source, it jumps to `no_more_source'. If multibytep is |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
725 nonzero, and a multibyte character is found at SRC, set C to the |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
726 negative value of the character code. The caller should declare |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
727 and set these variables appropriately in advance: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
728 src, src_end, multibytep */ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
729 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
730 #define ONE_MORE_BYTE(c) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
731 do { \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
732 if (src == src_end) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
733 { \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
734 if (src_base < src) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
735 record_conversion_result \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
736 (coding, CODING_RESULT_INSUFFICIENT_SRC); \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
737 goto no_more_source; \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
738 } \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
739 c = *src++; \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
740 if (multibytep && (c & 0x80)) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
741 { \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
742 if ((c & 0xFE) == 0xC0) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
743 c = ((c & 1) << 6) | *src++; \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
744 else \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
745 { \ |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
746 src--; \ |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
747 c = - string_char (src, &src, NULL); \ |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
748 record_conversion_result \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
749 (coding, CODING_RESULT_INVALID_SRC); \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
750 } \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
751 } \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
752 consumed_chars++; \ |
88365 | 753 } while (0) |
754 | |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
755 /* Safely get two bytes from the source text pointed by SRC which ends |
101174 | 756 at SRC_END, and set C1 and C2 to those bytes while skipping the |
757 heading multibyte characters. If there are not enough bytes in the | |
758 source, it jumps to `no_more_source'. If multibytep is nonzero and | |
759 a multibyte character is found for C2, set C2 to the negative value | |
760 of the character code. The caller should declare and set these | |
761 variables appropriately in advance: | |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
762 src, src_end, multibytep |
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
763 It is intended that this macro is used in detect_coding_utf_16. */ |
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
764 |
101174 | 765 #define TWO_MORE_BYTES(c1, c2) \ |
766 do { \ | |
767 do { \ | |
768 if (src == src_end) \ | |
769 goto no_more_source; \ | |
770 c1 = *src++; \ | |
771 if (multibytep && (c1 & 0x80)) \ | |
772 { \ | |
773 if ((c1 & 0xFE) == 0xC0) \ | |
774 c1 = ((c1 & 1) << 6) | *src++; \ | |
775 else \ | |
776 { \ | |
777 src += BYTES_BY_CHAR_HEAD (c1) - 1; \ | |
778 c1 = -1; \ | |
779 } \ | |
780 } \ | |
781 } while (c1 < 0); \ | |
782 if (src == src_end) \ | |
783 goto no_more_source; \ | |
784 c2 = *src++; \ | |
785 if (multibytep && (c2 & 0x80)) \ | |
786 { \ | |
787 if ((c2 & 0xFE) == 0xC0) \ | |
788 c2 = ((c2 & 1) << 6) | *src++; \ | |
789 else \ | |
790 c2 = -1; \ | |
791 } \ | |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
792 } while (0) |
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
793 |
88365 | 794 |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
795 #define ONE_MORE_BYTE_NO_CHECK(c) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
796 do { \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
797 c = *src++; \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
798 if (multibytep && (c & 0x80)) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
799 { \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
800 if ((c & 0xFE) == 0xC0) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
801 c = ((c & 1) << 6) | *src++; \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
802 else \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
803 { \ |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
804 src--; \ |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
805 c = - string_char (src, &src, NULL); \ |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
806 record_conversion_result \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
807 (coding, CODING_RESULT_INVALID_SRC); \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
808 } \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
809 } \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
810 consumed_chars++; \ |
88365 | 811 } while (0) |
812 | |
813 | |
814 /* Store a byte C in the place pointed by DST and increment DST to the | |
815 next free point, and increment PRODUCED_CHARS. The caller should | |
816 assure that C is 0..127, and declare and set the variable `dst' | |
817 appropriately in advance. | |
818 */ | |
819 | |
820 | |
821 #define EMIT_ONE_ASCII_BYTE(c) \ | |
822 do { \ | |
823 produced_chars++; \ | |
824 *dst++ = (c); \ | |
825 } while (0) | |
826 | |
827 | |
828 /* Like EMIT_ONE_ASCII_BYTE byt store two bytes; C1 and C2. */ | |
829 | |
830 #define EMIT_TWO_ASCII_BYTES(c1, c2) \ | |
831 do { \ | |
832 produced_chars += 2; \ | |
833 *dst++ = (c1), *dst++ = (c2); \ | |
834 } while (0) | |
835 | |
836 | |
837 /* Store a byte C in the place pointed by DST and increment DST to the | |
838 next free point, and increment PRODUCED_CHARS. If MULTIBYTEP is | |
839 nonzero, store in an appropriate multibyte from. The caller should | |
840 declare and set the variables `dst' and `multibytep' appropriately | |
841 in advance. */ | |
842 | |
843 #define EMIT_ONE_BYTE(c) \ | |
844 do { \ | |
845 produced_chars++; \ | |
846 if (multibytep) \ | |
847 { \ | |
848 int ch = (c); \ | |
849 if (ch >= 0x80) \ | |
850 ch = BYTE8_TO_CHAR (ch); \ | |
851 CHAR_STRING_ADVANCE (ch, dst); \ | |
852 } \ | |
853 else \ | |
854 *dst++ = (c); \ | |
855 } while (0) | |
856 | |
857 | |
858 /* Like EMIT_ONE_BYTE, but emit two bytes; C1 and C2. */ | |
859 | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
860 #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
|
861 do { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
862 produced_chars += 2; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
863 if (multibytep) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
864 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
865 int ch; \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
866 \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
867 ch = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
868 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
869 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
870 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
871 ch = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
872 if (ch >= 0x80) \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
873 ch = BYTE8_TO_CHAR (ch); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
874 CHAR_STRING_ADVANCE (ch, dst); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
875 } \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
876 else \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
877 { \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
878 *dst++ = (c1); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
879 *dst++ = (c2); \ |
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
880 } \ |
88365 | 881 } while (0) |
882 | |
883 | |
884 #define EMIT_THREE_BYTES(c1, c2, c3) \ | |
885 do { \ | |
886 EMIT_ONE_BYTE (c1); \ | |
887 EMIT_TWO_BYTES (c2, c3); \ | |
888 } while (0) | |
889 | |
890 | |
891 #define EMIT_FOUR_BYTES(c1, c2, c3, c4) \ | |
892 do { \ | |
893 EMIT_TWO_BYTES (c1, c2); \ | |
894 EMIT_TWO_BYTES (c3, c4); \ | |
895 } while (0) | |
896 | |
897 | |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
898 /* Prototypes for static functions. */ |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
899 static void record_conversion_result P_ ((struct coding_system *coding, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
900 enum coding_result_code result)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
901 static int detect_coding_utf_8 P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
902 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
903 static void decode_coding_utf_8 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
904 static int encode_coding_utf_8 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
905 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
906 static int detect_coding_utf_16 P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
907 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
908 static void decode_coding_utf_16 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
909 static int encode_coding_utf_16 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
910 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
911 static int detect_coding_iso_2022 P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
912 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
913 static void decode_coding_iso_2022 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
914 static int encode_coding_iso_2022 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
915 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
916 static int detect_coding_emacs_mule P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
917 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
918 static void decode_coding_emacs_mule P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
919 static int encode_coding_emacs_mule P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
920 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
921 static int detect_coding_sjis P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
922 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
923 static void decode_coding_sjis P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
924 static int encode_coding_sjis P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
925 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
926 static int detect_coding_big5 P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
927 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
928 static void decode_coding_big5 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
929 static int encode_coding_big5 P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
930 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
931 static int detect_coding_ccl P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
932 struct coding_detection_info *info)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
933 static void decode_coding_ccl P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
934 static int encode_coding_ccl P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
935 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
936 static void decode_coding_raw_text P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
937 static int encode_coding_raw_text P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
938 |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
939 static void coding_set_source P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
940 static void coding_set_destination P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
941 static void coding_alloc_by_realloc P_ ((struct coding_system *, EMACS_INT)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
942 static void coding_alloc_by_making_gap P_ ((struct coding_system *, |
90772
b15334b4a9c3
(coding_alloc_by_making_gap): New arg offset.
Kenichi Handa <handa@m17n.org>
parents:
90737
diff
changeset
|
943 EMACS_INT, EMACS_INT)); |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
944 static unsigned char *alloc_destination P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
945 EMACS_INT, unsigned char *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
946 static void setup_iso_safe_charsets P_ ((Lisp_Object)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
947 static unsigned char *encode_designation_at_bol P_ ((struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
948 int *, int *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
949 unsigned char *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
950 static int detect_eol P_ ((const unsigned char *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
951 EMACS_INT, enum coding_category)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
952 static Lisp_Object adjust_coding_eol_type P_ ((struct coding_system *, int)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
953 static void decode_eol P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
954 static Lisp_Object get_translation_table P_ ((Lisp_Object, int, int *)); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
955 static Lisp_Object get_translation P_ ((Lisp_Object, int *, int *)); |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
956 static int produce_chars P_ ((struct coding_system *, Lisp_Object, int)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
957 static INLINE void produce_charset P_ ((struct coding_system *, int *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
958 EMACS_INT)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
959 static void produce_annotation P_ ((struct coding_system *, EMACS_INT)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
960 static int decode_coding P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
961 static INLINE int *handle_composition_annotation P_ ((EMACS_INT, EMACS_INT, |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
962 struct coding_system *, |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
963 int *, EMACS_INT *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
964 static INLINE int *handle_charset_annotation P_ ((EMACS_INT, EMACS_INT, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
965 struct coding_system *, |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
966 int *, EMACS_INT *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
967 static void consume_chars P_ ((struct coding_system *, Lisp_Object, int)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
968 static int encode_coding P_ ((struct coding_system *)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
969 static Lisp_Object make_conversion_work_buffer P_ ((int)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
970 static Lisp_Object code_conversion_restore P_ ((Lisp_Object)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
971 static INLINE int char_encodable_p P_ ((int, Lisp_Object)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
972 static Lisp_Object make_subsidiaries P_ ((Lisp_Object)); |
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
973 |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
974 static void |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
975 record_conversion_result (struct coding_system *coding, |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
976 enum coding_result_code result) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
977 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
978 coding->result = result; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
979 switch (result) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
980 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
981 case CODING_RESULT_INSUFFICIENT_SRC: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
982 Vlast_code_conversion_error = Qinsufficient_source; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
983 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
984 case CODING_RESULT_INCONSISTENT_EOL: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
985 Vlast_code_conversion_error = Qinconsistent_eol; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
986 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
987 case CODING_RESULT_INVALID_SRC: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
988 Vlast_code_conversion_error = Qinvalid_source; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
989 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
990 case CODING_RESULT_INTERRUPT: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
991 Vlast_code_conversion_error = Qinterrupted; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
992 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
993 case CODING_RESULT_INSUFFICIENT_MEM: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
994 Vlast_code_conversion_error = Qinsufficient_memory; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
995 break; |
103133
2f7395806731
(record_conversion_result): Don't modify
Andreas Schwab <schwab@linux-m68k.org>
parents:
103052
diff
changeset
|
996 case CODING_RESULT_SUCCESS: |
2f7395806731
(record_conversion_result): Don't modify
Andreas Schwab <schwab@linux-m68k.org>
parents:
103052
diff
changeset
|
997 break; |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
998 default: |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
999 Vlast_code_conversion_error = intern ("Unknown error"); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1000 } |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1001 } |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1002 |
88365 | 1003 #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ |
1004 do { \ | |
1005 charset_map_loaded = 0; \ | |
1006 c = DECODE_CHAR (charset, code); \ | |
1007 if (charset_map_loaded) \ | |
1008 { \ | |
89483 | 1009 const unsigned char *orig = coding->source; \ |
88365 | 1010 EMACS_INT offset; \ |
1011 \ | |
1012 coding_set_source (coding); \ | |
1013 offset = coding->source - orig; \ | |
1014 src += offset; \ | |
1015 src_base += offset; \ | |
1016 src_end += offset; \ | |
1017 } \ | |
1018 } while (0) | |
1019 | |
1020 | |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1021 /* If there are at least BYTES length of room at dst, allocate memory |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1022 for coding->destination and update dst and dst_end. We don't have |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1023 to take care of coding->source which will be relocated. It is |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1024 handled by calling coding_set_source in encode_coding. */ |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1025 |
88365 | 1026 #define ASSURE_DESTINATION(bytes) \ |
1027 do { \ | |
1028 if (dst + (bytes) >= dst_end) \ | |
1029 { \ | |
1030 int more_bytes = charbuf_end - charbuf + (bytes); \ | |
1031 \ | |
1032 dst = alloc_destination (coding, more_bytes, dst); \ | |
1033 dst_end = coding->destination + coding->dst_bytes; \ | |
1034 } \ | |
1035 } while (0) | |
1036 | |
1037 | |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1038 /* Store multibyte form of the character C in P, and advance P to the |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1039 end of the multibyte form. This is like CHAR_STRING_ADVANCE but it |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1040 never calls MAYBE_UNIFY_CHAR. */ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1041 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1042 #define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1043 do { \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1044 if ((c) <= MAX_1_BYTE_CHAR) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1045 *(p)++ = (c); \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1046 else if ((c) <= MAX_2_BYTE_CHAR) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1047 *(p)++ = (0xC0 | ((c) >> 6)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1048 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1049 else if ((c) <= MAX_3_BYTE_CHAR) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1050 *(p)++ = (0xE0 | ((c) >> 12)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1051 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1052 *(p)++ = (0x80 | ((c) & 0x3F)); \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1053 else if ((c) <= MAX_4_BYTE_CHAR) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1054 *(p)++ = (0xF0 | (c >> 18)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1055 *(p)++ = (0x80 | ((c >> 12) & 0x3F)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1056 *(p)++ = (0x80 | ((c >> 6) & 0x3F)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1057 *(p)++ = (0x80 | (c & 0x3F)); \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1058 else if ((c) <= MAX_5_BYTE_CHAR) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1059 *(p)++ = 0xF8, \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1060 *(p)++ = (0x80 | ((c >> 18) & 0x0F)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1061 *(p)++ = (0x80 | ((c >> 12) & 0x3F)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1062 *(p)++ = (0x80 | ((c >> 6) & 0x3F)), \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1063 *(p)++ = (0x80 | (c & 0x3F)); \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1064 else \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1065 (p) += BYTE8_STRING ((c) - 0x3FFF80, p); \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1066 } while (0) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1067 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1068 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1069 /* Return the character code of character whose multibyte form is at |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1070 P, and advance P to the end of the multibyte form. This is like |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1071 STRING_CHAR_ADVANCE, but it never calls MAYBE_UNIFY_CHAR. */ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1072 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1073 #define STRING_CHAR_ADVANCE_NO_UNIFY(p) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1074 (!((p)[0] & 0x80) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1075 ? *(p)++ \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1076 : ! ((p)[0] & 0x20) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1077 ? ((p) += 2, \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1078 ((((p)[-2] & 0x1F) << 6) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1079 | ((p)[-1] & 0x3F) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1080 | ((unsigned char) ((p)[-2]) < 0xC2 ? 0x3FFF80 : 0))) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1081 : ! ((p)[0] & 0x10) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1082 ? ((p) += 3, \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1083 ((((p)[-3] & 0x0F) << 12) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1084 | (((p)[-2] & 0x3F) << 6) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1085 | ((p)[-1] & 0x3F))) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1086 : ! ((p)[0] & 0x08) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1087 ? ((p) += 4, \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1088 ((((p)[-4] & 0xF) << 18) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1089 | (((p)[-3] & 0x3F) << 12) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1090 | (((p)[-2] & 0x3F) << 6) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1091 | ((p)[-1] & 0x3F))) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1092 : ((p) += 5, \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1093 ((((p)[-4] & 0x3F) << 18) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1094 | (((p)[-3] & 0x3F) << 12) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1095 | (((p)[-2] & 0x3F) << 6) \ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1096 | ((p)[-1] & 0x3F)))) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1097 |
88365 | 1098 |
1099 static void | |
1100 coding_set_source (coding) | |
1101 struct coding_system *coding; | |
1102 { | |
1103 if (BUFFERP (coding->src_object)) | |
1104 { | |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
1105 struct buffer *buf = XBUFFER (coding->src_object); |
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
1106 |
88365 | 1107 if (coding->src_pos < 0) |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
1108 coding->source = BUF_GAP_END_ADDR (buf) + coding->src_pos_byte; |
88365 | 1109 else |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
1110 coding->source = BUF_BYTE_ADDRESS (buf, coding->src_pos_byte); |
88365 | 1111 } |
1112 else if (STRINGP (coding->src_object)) | |
1113 { | |
89483 | 1114 coding->source = SDATA (coding->src_object) + coding->src_pos_byte; |
88365 | 1115 } |
1116 else | |
1117 /* Otherwise, the source is C string and is never relocated | |
1118 automatically. Thus we don't have to update anything. */ | |
1119 ; | |
1120 } | |
1121 | |
1122 static void | |
1123 coding_set_destination (coding) | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1124 struct coding_system *coding; |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1125 { |
88365 | 1126 if (BUFFERP (coding->dst_object)) |
1127 { | |
1128 if (coding->src_pos < 0) | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1129 { |
91807
507bcfb4342c
* coding.c (coding_set_destination): Use BEG_BYTE rather than hardcoding 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91622
diff
changeset
|
1130 coding->destination = BEG_ADDR + coding->dst_pos_byte - BEG_BYTE; |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1131 coding->dst_bytes = (GAP_END_ADDR |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1132 - (coding->src_bytes - coding->consumed) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1133 - coding->destination); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1134 } |
88365 | 1135 else |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1136 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1137 /* 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
|
1138 of the buffer. */ |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1139 coding->destination = (BUF_BEG_ADDR (XBUFFER (coding->dst_object)) |
91807
507bcfb4342c
* coding.c (coding_set_destination): Use BEG_BYTE rather than hardcoding 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91622
diff
changeset
|
1140 + coding->dst_pos_byte - BEG_BYTE); |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1141 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
|
1142 - coding->destination); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1143 } |
88365 | 1144 } |
1145 else | |
1146 /* Otherwise, the destination is C string and is never relocated | |
1147 automatically. Thus we don't have to update anything. */ | |
1148 ; | |
1149 } | |
1150 | |
1151 | |
1152 static void | |
1153 coding_alloc_by_realloc (coding, bytes) | |
1154 struct coding_system *coding; | |
1155 EMACS_INT bytes; | |
1156 { | |
1157 coding->destination = (unsigned char *) xrealloc (coding->destination, | |
1158 coding->dst_bytes + bytes); | |
1159 coding->dst_bytes += bytes; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1160 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1161 |
88365 | 1162 static void |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1163 coding_alloc_by_making_gap (coding, gap_head_used, bytes) |
88365 | 1164 struct coding_system *coding; |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1165 EMACS_INT gap_head_used, bytes; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1166 { |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1167 if (EQ (coding->src_object, coding->dst_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1168 { |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1169 /* The gap may contain the produced data at the head and not-yet |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1170 consumed data at the tail. To preserve those data, we at |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1171 first make the gap size to zero, then increase the gap |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1172 size. */ |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1173 EMACS_INT add = GAP_SIZE; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1174 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1175 GPT += gap_head_used, GPT_BYTE += gap_head_used; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1176 GAP_SIZE = 0; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add; |
88365 | 1177 make_gap (bytes); |
1178 GAP_SIZE += add; ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add; | |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1179 GPT -= gap_head_used, GPT_BYTE -= gap_head_used; |
88365 | 1180 } |
90292
697c08d95af7
Cancel incorrect synching with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90291
diff
changeset
|
1181 else |
88365 | 1182 { |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
1183 Lisp_Object this_buffer; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
1184 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
1185 this_buffer = Fcurrent_buffer (); |
88365 | 1186 set_buffer_internal (XBUFFER (coding->dst_object)); |
1187 make_gap (bytes); | |
1188 set_buffer_internal (XBUFFER (this_buffer)); | |
1189 } | |
1190 } | |
89483 | 1191 |
88365 | 1192 |
1193 static unsigned char * | |
1194 alloc_destination (coding, nbytes, dst) | |
1195 struct coding_system *coding; | |
89545
4f394eed6ff2
(inhibit_pre_post_conversion): Removed (unused).
Dave Love <fx@gnu.org>
parents:
89519
diff
changeset
|
1196 EMACS_INT nbytes; |
88365 | 1197 unsigned char *dst; |
1198 { | |
1199 EMACS_INT offset = dst - coding->destination; | |
1200 | |
1201 if (BUFFERP (coding->dst_object)) | |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1202 { |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1203 struct buffer *buf = XBUFFER (coding->dst_object); |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1204 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1205 coding_alloc_by_making_gap (coding, dst - BUF_GPT_ADDR (buf), nbytes); |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1206 } |
88365 | 1207 else |
1208 coding_alloc_by_realloc (coding, nbytes); | |
1209 coding_set_destination (coding); | |
1210 dst = coding->destination + offset; | |
1211 return dst; | |
1212 } | |
1213 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1214 /** Macros for annotations. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1215 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1216 /* An annotation data is stored in the array coding->charbuf in this |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1217 format: |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1218 [ -LENGTH ANNOTATION_MASK NCHARS ... ] |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1219 LENGTH is the number of elements in the annotation. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1220 ANNOTATION_MASK is one of CODING_ANNOTATE_XXX_MASK. |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1221 NCHARS is the number of characters in the text annotated. |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1222 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1223 The format of the following elements depend on ANNOTATION_MASK. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1224 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1225 In the case of CODING_ANNOTATE_COMPOSITION_MASK, these elements |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1226 follows: |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1227 ... NBYTES METHOD [ COMPOSITION-COMPONENTS ... ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1228 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1229 NBYTES is the number of bytes specified in the header part of |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1230 old-style emacs-mule encoding, or 0 for the other kind of |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1231 composition. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1232 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1233 METHOD is one of enum composition_method. |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1234 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1235 Optionnal COMPOSITION-COMPONENTS are characters and composition |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1236 rules. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1237 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1238 In the case of CODING_ANNOTATE_CHARSET_MASK, one element CHARSET-ID |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1239 follows. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1240 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1241 If ANNOTATION_MASK is 0, this annotation is just a space holder to |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1242 recover from an invalid annotation, and should be skipped by |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1243 produce_annotation. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1244 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1245 /* Maximum length of the header of annotation data. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1246 #define MAX_ANNOTATION_LENGTH 5 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1247 |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1248 #define ADD_ANNOTATION_DATA(buf, len, mask, nchars) \ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1249 do { \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1250 *(buf)++ = -(len); \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1251 *(buf)++ = (mask); \ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1252 *(buf)++ = (nchars); \ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1253 coding->annotated = 1; \ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1254 } while (0); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1255 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1256 #define ADD_COMPOSITION_DATA(buf, nchars, nbytes, method) \ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1257 do { \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1258 ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_COMPOSITION_MASK, nchars); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1259 *buf++ = nbytes; \ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1260 *buf++ = method; \ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1261 } while (0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1262 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1263 |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1264 #define ADD_CHARSET_DATA(buf, nchars, id) \ |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1265 do { \ |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1266 ADD_ANNOTATION_DATA (buf, 4, CODING_ANNOTATE_CHARSET_MASK, nchars); \ |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1267 *buf++ = id; \ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1268 } while (0) |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1269 |
17052 | 1270 |
88365 | 1271 /*** 2. Emacs' internal format (emacs-utf-8) ***/ |
1272 | |
1273 | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1274 |
17052 | 1275 |
88365 | 1276 /*** 3. UTF-8 ***/ |
1277 | |
1278 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1279 Check if a text is encoded in UTF-8. If it is, return 1, else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1280 return 0. */ |
88365 | 1281 |
1282 #define UTF_8_1_OCTET_P(c) ((c) < 0x80) | |
1283 #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80) | |
1284 #define UTF_8_2_OCTET_LEADING_P(c) (((c) & 0xE0) == 0xC0) | |
1285 #define UTF_8_3_OCTET_LEADING_P(c) (((c) & 0xF0) == 0xE0) | |
1286 #define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0) | |
1287 #define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8) | |
1288 | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1289 #define UTF_BOM 0xFEFF |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1290 #define UTF_8_BOM_1 0xEF |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1291 #define UTF_8_BOM_2 0xBB |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1292 #define UTF_8_BOM_3 0xBF |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1293 |
88365 | 1294 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1295 detect_coding_utf_8 (coding, detect_info) |
88365 | 1296 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1297 struct coding_detection_info *detect_info; |
88365 | 1298 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1299 const unsigned char *src = coding->source, *src_base; |
89483 | 1300 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 1301 int multibytep = coding->src_multibyte; |
1302 int consumed_chars = 0; | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1303 int bom_found = 0; |
88365 | 1304 int found = 0; |
1305 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1306 detect_info->checked |= CATEGORY_MASK_UTF_8; |
88365 | 1307 /* A coding system of this category is always ASCII compatible. */ |
1308 src += coding->head_ascii; | |
1309 | |
1310 while (1) | |
1311 { | |
1312 int c, c1, c2, c3, c4; | |
1313 | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1314 src_base = src; |
88365 | 1315 ONE_MORE_BYTE (c); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1316 if (c < 0 || UTF_8_1_OCTET_P (c)) |
88365 | 1317 continue; |
1318 ONE_MORE_BYTE (c1); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1319 if (c1 < 0 || ! UTF_8_EXTRA_OCTET_P (c1)) |
88365 | 1320 break; |
1321 if (UTF_8_2_OCTET_LEADING_P (c)) | |
1322 { | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1323 found = 1; |
88365 | 1324 continue; |
1325 } | |
1326 ONE_MORE_BYTE (c2); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1327 if (c2 < 0 || ! UTF_8_EXTRA_OCTET_P (c2)) |
88365 | 1328 break; |
1329 if (UTF_8_3_OCTET_LEADING_P (c)) | |
1330 { | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1331 found = 1; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1332 if (src_base == coding->source |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1333 && c == UTF_8_BOM_1 && c1 == UTF_8_BOM_2 && c2 == UTF_8_BOM_3) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1334 bom_found = 1; |
88365 | 1335 continue; |
1336 } | |
1337 ONE_MORE_BYTE (c3); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1338 if (c3 < 0 || ! UTF_8_EXTRA_OCTET_P (c3)) |
88365 | 1339 break; |
1340 if (UTF_8_4_OCTET_LEADING_P (c)) | |
1341 { | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1342 found = 1; |
88365 | 1343 continue; |
1344 } | |
1345 ONE_MORE_BYTE (c4); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1346 if (c4 < 0 || ! UTF_8_EXTRA_OCTET_P (c4)) |
88365 | 1347 break; |
1348 if (UTF_8_5_OCTET_LEADING_P (c)) | |
1349 { | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1350 found = 1; |
88365 | 1351 continue; |
1352 } | |
1353 break; | |
1354 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1355 detect_info->rejected |= CATEGORY_MASK_UTF_8; |
88365 | 1356 return 0; |
1357 | |
1358 no_more_source: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1359 if (src_base < src && coding->mode & CODING_MODE_LAST_BLOCK) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1360 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1361 detect_info->rejected |= CATEGORY_MASK_UTF_8; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1362 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1363 } |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1364 if (bom_found) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1365 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1366 /* The first character 0xFFFE doesn't necessarily mean a BOM. */ |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1367 detect_info->found |= CATEGORY_MASK_UTF_8_SIG | CATEGORY_MASK_UTF_8_NOSIG; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1368 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1369 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1370 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1371 detect_info->rejected |= CATEGORY_MASK_UTF_8_SIG; |
96571
a3f2a5a4b492
(detect_coding_utf_8): Set detect_info->found only when
Kenichi Handa <handa@m17n.org>
parents:
95585
diff
changeset
|
1372 if (found) |
a3f2a5a4b492
(detect_coding_utf_8): Set detect_info->found only when
Kenichi Handa <handa@m17n.org>
parents:
95585
diff
changeset
|
1373 detect_info->found |= CATEGORY_MASK_UTF_8_NOSIG; |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1374 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1375 return 1; |
88365 | 1376 } |
1377 | |
1378 | |
1379 static void | |
1380 decode_coding_utf_8 (coding) | |
1381 struct coding_system *coding; | |
1382 { | |
89483 | 1383 const unsigned char *src = coding->source + coding->consumed; |
1384 const unsigned char *src_end = coding->source + coding->src_bytes; | |
1385 const unsigned char *src_base; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1386 int *charbuf = coding->charbuf + coding->charbuf_used; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1387 int *charbuf_end = coding->charbuf + coding->charbuf_size; |
100133
bca35d7cb3ac
(decode_coding_utf_8): Likewise.
Kenichi Handa <handa@m17n.org>
parents:
100131
diff
changeset
|
1388 int consumed_chars = 0, consumed_chars_base = 0; |
88365 | 1389 int multibytep = coding->src_multibyte; |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1390 enum utf_bom_type bom = CODING_UTF_8_BOM (coding); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1391 Lisp_Object attr, charset_list; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
1392 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
1393 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1394 int byte_after_cr = -1; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1395 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1396 CODING_GET_INFO (coding, attr, charset_list); |
88365 | 1397 |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1398 if (bom != utf_without_bom) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1399 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1400 int c1, c2, c3; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1401 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1402 src_base = src; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1403 ONE_MORE_BYTE (c1); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1404 if (! UTF_8_3_OCTET_LEADING_P (c1)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1405 src = src_base; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1406 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1407 { |
99074
10cd979d05ca
(make_conversion_work_buffer): Check that Vcode_conversion_reused_workbuf
Noah Friedman <friedman@splode.com>
parents:
98992
diff
changeset
|
1408 ONE_MORE_BYTE (c2); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1409 if (! UTF_8_EXTRA_OCTET_P (c2)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1410 src = src_base; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1411 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1412 { |
99074
10cd979d05ca
(make_conversion_work_buffer): Check that Vcode_conversion_reused_workbuf
Noah Friedman <friedman@splode.com>
parents:
98992
diff
changeset
|
1413 ONE_MORE_BYTE (c3); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1414 if (! UTF_8_EXTRA_OCTET_P (c3)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1415 src = src_base; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1416 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1417 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1418 if ((c1 != UTF_8_BOM_1) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1419 || (c2 != UTF_8_BOM_2) || (c3 != UTF_8_BOM_3)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1420 src = src_base; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1421 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1422 CODING_UTF_8_BOM (coding) = utf_without_bom; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1423 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1424 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1425 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1426 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1427 CODING_UTF_8_BOM (coding) = utf_without_bom; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1428 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1429 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1430 |
88365 | 1431 while (1) |
1432 { | |
1433 int c, c1, c2, c3, c4, c5; | |
1434 | |
1435 src_base = src; | |
1436 consumed_chars_base = consumed_chars; | |
1437 | |
1438 if (charbuf >= charbuf_end) | |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1439 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1440 if (byte_after_cr >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1441 src_base--; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1442 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1443 } |
88365 | 1444 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1445 if (byte_after_cr >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1446 c1 = byte_after_cr, byte_after_cr = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1447 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1448 ONE_MORE_BYTE (c1); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1449 if (c1 < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1450 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1451 c = - c1; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1452 } |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1453 else if (UTF_8_1_OCTET_P(c1)) |
88365 | 1454 { |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1455 if (eol_crlf && c1 == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1456 ONE_MORE_BYTE (byte_after_cr); |
88365 | 1457 c = c1; |
1458 } | |
1459 else | |
1460 { | |
1461 ONE_MORE_BYTE (c2); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1462 if (c2 < 0 || ! UTF_8_EXTRA_OCTET_P (c2)) |
88365 | 1463 goto invalid_code; |
1464 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
|
1465 { |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1466 c = ((c1 & 0x1F) << 6) | (c2 & 0x3F); |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1467 /* Reject overlong sequences here and below. Encoders |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1468 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
|
1469 and they mess up read/write invariance. */ |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1470 if (c < 128) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1471 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1472 } |
88365 | 1473 else |
1474 { | |
1475 ONE_MORE_BYTE (c3); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1476 if (c3 < 0 || ! UTF_8_EXTRA_OCTET_P (c3)) |
88365 | 1477 goto invalid_code; |
1478 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
|
1479 { |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1480 c = (((c1 & 0xF) << 12) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1481 | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
89184
88a9e962e183
(decode_coding_utf_8): Treat surrogates as invalid.
Dave Love <fx@gnu.org>
parents:
89042
diff
changeset
|
1482 if (c < 0x800 |
88a9e962e183
(decode_coding_utf_8): Treat surrogates as invalid.
Dave Love <fx@gnu.org>
parents:
89042
diff
changeset
|
1483 || (c >= 0xd800 && c < 0xe000)) /* surrogates (invalid) */ |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1484 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1485 } |
88365 | 1486 else |
1487 { | |
1488 ONE_MORE_BYTE (c4); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1489 if (c4 < 0 || ! UTF_8_EXTRA_OCTET_P (c4)) |
88365 | 1490 goto invalid_code; |
1491 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
|
1492 { |
88365 | 1493 c = (((c1 & 0x7) << 18) | ((c2 & 0x3F) << 12) |
1494 | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1495 if (c < 0x10000) |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1496 goto invalid_code; |
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1497 } |
88365 | 1498 else |
1499 { | |
1500 ONE_MORE_BYTE (c5); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1501 if (c5 < 0 || ! UTF_8_EXTRA_OCTET_P (c5)) |
88365 | 1502 goto invalid_code; |
1503 if (UTF_8_5_OCTET_LEADING_P (c1)) | |
1504 { | |
1505 c = (((c1 & 0x3) << 24) | ((c2 & 0x3F) << 18) | |
1506 | ((c3 & 0x3F) << 12) | ((c4 & 0x3F) << 6) | |
1507 | (c5 & 0x3F)); | |
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1508 if ((c > MAX_CHAR) || (c < 0x200000)) |
88365 | 1509 goto invalid_code; |
1510 } | |
1511 else | |
1512 goto invalid_code; | |
1513 } | |
1514 } | |
1515 } | |
1516 } | |
1517 | |
1518 *charbuf++ = c; | |
1519 continue; | |
1520 | |
1521 invalid_code: | |
1522 src = src_base; | |
1523 consumed_chars = consumed_chars_base; | |
1524 ONE_MORE_BYTE (c); | |
1525 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
1526 coding->errors++; | |
1527 } | |
1528 | |
1529 no_more_source: | |
1530 coding->consumed_char += consumed_chars_base; | |
1531 coding->consumed = src_base - coding->source; | |
1532 coding->charbuf_used = charbuf - coding->charbuf; | |
1533 } | |
1534 | |
1535 | |
1536 static int | |
1537 encode_coding_utf_8 (coding) | |
1538 struct coding_system *coding; | |
1539 { | |
1540 int multibytep = coding->dst_multibyte; | |
1541 int *charbuf = coding->charbuf; | |
1542 int *charbuf_end = charbuf + coding->charbuf_used; | |
1543 unsigned char *dst = coding->destination + coding->produced; | |
1544 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
|
1545 int produced_chars = 0; |
88365 | 1546 int c; |
1547 | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1548 if (CODING_UTF_8_BOM (coding) == utf_with_bom) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1549 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1550 ASSURE_DESTINATION (3); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1551 EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1552 CODING_UTF_8_BOM (coding) = utf_without_bom; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1553 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1554 |
88365 | 1555 if (multibytep) |
1556 { | |
1557 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
1558 | |
1559 while (charbuf < charbuf_end) | |
1560 { | |
1561 unsigned char str[MAX_MULTIBYTE_LENGTH], *p, *pend = str; | |
89483 | 1562 |
88365 | 1563 ASSURE_DESTINATION (safe_room); |
1564 c = *charbuf++; | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1565 if (CHAR_BYTE8_P (c)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1566 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1567 c = CHAR_TO_BYTE8 (c); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1568 EMIT_ONE_BYTE (c); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1569 } |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1570 else |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1571 { |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1572 CHAR_STRING_ADVANCE_NO_UNIFY (c, pend); |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1573 for (p = str; p < pend; p++) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1574 EMIT_ONE_BYTE (*p); |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1575 } |
88365 | 1576 } |
1577 } | |
1578 else | |
1579 { | |
1580 int safe_room = MAX_MULTIBYTE_LENGTH; | |
1581 | |
1582 while (charbuf < charbuf_end) | |
1583 { | |
1584 ASSURE_DESTINATION (safe_room); | |
1585 c = *charbuf++; | |
89917
1763eef5ad02
(encode_coding_utf_8): Fix handling of raw-byte char.
Kenichi Handa <handa@m17n.org>
parents:
89905
diff
changeset
|
1586 if (CHAR_BYTE8_P (c)) |
1763eef5ad02
(encode_coding_utf_8): Fix handling of raw-byte char.
Kenichi Handa <handa@m17n.org>
parents:
89905
diff
changeset
|
1587 *dst++ = CHAR_TO_BYTE8 (c); |
1763eef5ad02
(encode_coding_utf_8): Fix handling of raw-byte char.
Kenichi Handa <handa@m17n.org>
parents:
89905
diff
changeset
|
1588 else |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
1589 CHAR_STRING_ADVANCE_NO_UNIFY (c, dst); |
88365 | 1590 produced_chars++; |
1591 } | |
1592 } | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1593 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 1594 coding->produced_char += produced_chars; |
1595 coding->produced = dst - coding->destination; | |
1596 return 0; | |
1597 } | |
1598 | |
1599 | |
1600 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1601 Check if a text is encoded in one of UTF-16 based coding systems. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1602 If it is, return 1, else return 0. */ |
88365 | 1603 |
1604 #define UTF_16_HIGH_SURROGATE_P(val) \ | |
1605 (((val) & 0xFC00) == 0xD800) | |
1606 | |
1607 #define UTF_16_LOW_SURROGATE_P(val) \ | |
1608 (((val) & 0xFC00) == 0xDC00) | |
1609 | |
1610 #define UTF_16_INVALID_P(val) \ | |
1611 (((val) == 0xFFFE) \ | |
1612 || ((val) == 0xFFFF) \ | |
1613 || UTF_16_LOW_SURROGATE_P (val)) | |
1614 | |
1615 | |
1616 static int | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1617 detect_coding_utf_16 (coding, detect_info) |
88365 | 1618 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1619 struct coding_detection_info *detect_info; |
88365 | 1620 { |
89483 | 1621 const unsigned char *src = coding->source, *src_base = src; |
1622 const unsigned char *src_end = coding->source + coding->src_bytes; | |
88365 | 1623 int multibytep = coding->src_multibyte; |
1624 int consumed_chars = 0; | |
1625 int c1, c2; | |
1626 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1627 detect_info->checked |= CATEGORY_MASK_UTF_16; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1628 if (coding->mode & CODING_MODE_LAST_BLOCK |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1629 && (coding->src_chars & 1)) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1630 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1631 detect_info->rejected |= CATEGORY_MASK_UTF_16; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1632 return 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1633 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1634 |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1635 TWO_MORE_BYTES (c1, c2); |
88365 | 1636 if ((c1 == 0xFF) && (c2 == 0xFE)) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1637 { |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1638 detect_info->found |= (CATEGORY_MASK_UTF_16_LE |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1639 | CATEGORY_MASK_UTF_16_AUTO); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1640 detect_info->rejected |= (CATEGORY_MASK_UTF_16_BE |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1641 | CATEGORY_MASK_UTF_16_BE_NOSIG |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1642 | CATEGORY_MASK_UTF_16_LE_NOSIG); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1643 } |
88365 | 1644 else if ((c1 == 0xFE) && (c2 == 0xFF)) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1645 { |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1646 detect_info->found |= (CATEGORY_MASK_UTF_16_BE |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1647 | CATEGORY_MASK_UTF_16_AUTO); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1648 detect_info->rejected |= (CATEGORY_MASK_UTF_16_LE |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1649 | CATEGORY_MASK_UTF_16_BE_NOSIG |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1650 | CATEGORY_MASK_UTF_16_LE_NOSIG); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1651 } |
101174 | 1652 else if (c2 < 0) |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1653 { |
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1654 detect_info->rejected |= CATEGORY_MASK_UTF_16; |
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1655 return 0; |
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1656 } |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1657 else |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1658 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1659 /* We check the dispersion of Eth and Oth bytes where E is even and |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1660 O is odd. If both are high, we assume binary data.*/ |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1661 unsigned char e[256], o[256]; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1662 unsigned e_num = 1, o_num = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1663 |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1664 memset (e, 0, 256); |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1665 memset (o, 0, 256); |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1666 e[c1] = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1667 o[c2] = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1668 |
103442
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1669 detect_info->rejected |= (CATEGORY_MASK_UTF_16_AUTO |
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1670 |CATEGORY_MASK_UTF_16_BE |
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1671 | CATEGORY_MASK_UTF_16_LE); |
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1672 |
103448
73e7271dee09
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103442
diff
changeset
|
1673 while ((detect_info->rejected & CATEGORY_MASK_UTF_16) |
73e7271dee09
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103442
diff
changeset
|
1674 != CATEGORY_MASK_UTF_16) |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1675 { |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1676 TWO_MORE_BYTES (c1, c2); |
101174 | 1677 if (c2 < 0) |
101172
674e67257137
(TWO_MORE_BYTES): New macro.
Kenichi Handa <handa@m17n.org>
parents:
101040
diff
changeset
|
1678 break; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1679 if (! e[c1]) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1680 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1681 e[c1] = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1682 e_num++; |
103442
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1683 if (e_num >= 128) |
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1684 detect_info->rejected |= CATEGORY_MASK_UTF_16_BE_NOSIG; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1685 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1686 if (! o[c2]) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1687 { |
103435
45564d023acc
(detect_coding_utf_16): Fix typo counting odd bytes.
Andreas Schwab <schwab@linux-m68k.org>
parents:
103306
diff
changeset
|
1688 o[c2] = 1; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1689 o_num++; |
103442
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1690 if (o_num >= 128) |
db4ec1a977bd
(detect_coding_utf_16): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103441
diff
changeset
|
1691 detect_info->rejected |= CATEGORY_MASK_UTF_16_LE_NOSIG; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1692 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1693 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1694 return 0; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1695 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
1696 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1697 no_more_source: |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1698 return 1; |
88365 | 1699 } |
1700 | |
1701 static void | |
1702 decode_coding_utf_16 (coding) | |
1703 struct coding_system *coding; | |
1704 { | |
89483 | 1705 const unsigned char *src = coding->source + coding->consumed; |
1706 const unsigned char *src_end = coding->source + coding->src_bytes; | |
1707 const unsigned char *src_base; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
1708 int *charbuf = coding->charbuf + coding->charbuf_used; |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
1709 /* We may produces at most 3 chars in one loop. */ |
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
1710 int *charbuf_end = coding->charbuf + coding->charbuf_size - 2; |
100131
0e4115b39b5d
(decode_coding_utf_16): Initialize consumed_chars_base
Kenichi Handa <handa@m17n.org>
parents:
99753
diff
changeset
|
1711 int consumed_chars = 0, consumed_chars_base = 0; |
88365 | 1712 int multibytep = coding->src_multibyte; |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1713 enum utf_bom_type bom = CODING_UTF_16_BOM (coding); |
88365 | 1714 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); |
1715 int surrogate = CODING_UTF_16_SURROGATE (coding); | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1716 Lisp_Object attr, charset_list; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
1717 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
1718 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1719 int byte_after_cr1 = -1, byte_after_cr2 = -1; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1720 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1721 CODING_GET_INFO (coding, attr, charset_list); |
88365 | 1722 |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1723 if (bom == utf_with_bom) |
88365 | 1724 { |
1725 int c, c1, c2; | |
1726 | |
1727 src_base = src; | |
1728 ONE_MORE_BYTE (c1); | |
1729 ONE_MORE_BYTE (c2); | |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1730 c = (c1 << 8) | c2; |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1731 |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1732 if (endian == utf_16_big_endian |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1733 ? c != 0xFEFF : c != 0xFFFE) |
88365 | 1734 { |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1735 /* The first two bytes are not BOM. Treat them as bytes |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1736 for a normal character. */ |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1737 src = src_base; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1738 coding->errors++; |
88365 | 1739 } |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1740 CODING_UTF_16_BOM (coding) = utf_without_bom; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1741 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1742 else if (bom == utf_detect_bom) |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1743 { |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1744 /* We have already tried to detect BOM and failed in |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
1745 detect_coding. */ |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1746 CODING_UTF_16_BOM (coding) = utf_without_bom; |
88365 | 1747 } |
1748 | |
1749 while (1) | |
1750 { | |
1751 int c, c1, c2; | |
1752 | |
1753 src_base = src; | |
1754 consumed_chars_base = consumed_chars; | |
1755 | |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
1756 if (charbuf >= charbuf_end) |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1757 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1758 if (byte_after_cr1 >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1759 src_base -= 2; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1760 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
1761 } |
88365 | 1762 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1763 if (byte_after_cr1 >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1764 c1 = byte_after_cr1, byte_after_cr1 = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1765 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1766 ONE_MORE_BYTE (c1); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1767 if (c1 < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1768 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1769 *charbuf++ = -c1; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1770 continue; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1771 } |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1772 if (byte_after_cr2 >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1773 c2 = byte_after_cr2, byte_after_cr2 = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1774 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1775 ONE_MORE_BYTE (c2); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1776 if (c2 < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1777 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1778 *charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1779 *charbuf++ = -c2; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1780 continue; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1781 } |
88365 | 1782 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
|
1783 ? ((c1 << 8) | c2) : ((c2 << 8) | c1)); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1784 |
88365 | 1785 if (surrogate) |
1786 { | |
1787 if (! UTF_16_LOW_SURROGATE_P (c)) | |
1788 { | |
1789 if (endian == utf_16_big_endian) | |
1790 c1 = surrogate >> 8, c2 = surrogate & 0xFF; | |
1791 else | |
1792 c1 = surrogate & 0xFF, c2 = surrogate >> 8; | |
1793 *charbuf++ = c1; | |
1794 *charbuf++ = c2; | |
1795 coding->errors++; | |
1796 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1797 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1798 else | |
1799 *charbuf++ = c; | |
1800 } | |
1801 else | |
1802 { | |
1803 c = ((surrogate - 0xD800) << 10) | (c - 0xDC00); | |
1804 CODING_UTF_16_SURROGATE (coding) = surrogate = 0; | |
89842
b5f22f538c1f
(decode_coding_utf_16): Fix handling of surrogate pare.
Kenichi Handa <handa@m17n.org>
parents:
89780
diff
changeset
|
1805 *charbuf++ = 0x10000 + c; |
88365 | 1806 } |
1807 } | |
1808 else | |
1809 { | |
1810 if (UTF_16_HIGH_SURROGATE_P (c)) | |
1811 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
1812 else | |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1813 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1814 if (eol_crlf && c == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1815 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1816 ONE_MORE_BYTE (byte_after_cr1); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1817 ONE_MORE_BYTE (byte_after_cr2); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1818 } |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1819 *charbuf++ = c; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
1820 } |
89483 | 1821 } |
88365 | 1822 } |
1823 | |
1824 no_more_source: | |
1825 coding->consumed_char += consumed_chars_base; | |
1826 coding->consumed = src_base - coding->source; | |
1827 coding->charbuf_used = charbuf - coding->charbuf; | |
1828 } | |
1829 | |
1830 static int | |
1831 encode_coding_utf_16 (coding) | |
1832 struct coding_system *coding; | |
1833 { | |
1834 int multibytep = coding->dst_multibyte; | |
1835 int *charbuf = coding->charbuf; | |
1836 int *charbuf_end = charbuf + coding->charbuf_used; | |
1837 unsigned char *dst = coding->destination + coding->produced; | |
1838 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
1839 int safe_room = 8; | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1840 enum utf_bom_type bom = CODING_UTF_16_BOM (coding); |
88365 | 1841 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; |
1842 int produced_chars = 0; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1843 Lisp_Object attrs, charset_list; |
88365 | 1844 int c; |
1845 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
1846 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 1847 |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1848 if (bom != utf_without_bom) |
88365 | 1849 { |
1850 ASSURE_DESTINATION (safe_room); | |
1851 if (big_endian) | |
89404
3e1d187b52c3
(Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig)
Kenichi Handa <handa@m17n.org>
parents:
89394
diff
changeset
|
1852 EMIT_TWO_BYTES (0xFE, 0xFF); |
88365 | 1853 else |
89404
3e1d187b52c3
(Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig)
Kenichi Handa <handa@m17n.org>
parents:
89394
diff
changeset
|
1854 EMIT_TWO_BYTES (0xFF, 0xFE); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
1855 CODING_UTF_16_BOM (coding) = utf_without_bom; |
88365 | 1856 } |
1857 | |
1858 while (charbuf < charbuf_end) | |
1859 { | |
1860 ASSURE_DESTINATION (safe_room); | |
1861 c = *charbuf++; | |
104636
bc74846b9a54
(encode_coding_utf_16): Fix checking of an Unicode character.
Kenichi Handa <handa@m17n.org>
parents:
103762
diff
changeset
|
1862 if (c > MAX_UNICODE_CHAR) |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1863 c = coding->default_char; |
88365 | 1864 |
1865 if (c < 0x10000) | |
1866 { | |
1867 if (big_endian) | |
1868 EMIT_TWO_BYTES (c >> 8, c & 0xFF); | |
1869 else | |
1870 EMIT_TWO_BYTES (c & 0xFF, c >> 8); | |
1871 } | |
1872 else | |
1873 { | |
1874 int c1, c2; | |
1875 | |
1876 c -= 0x10000; | |
1877 c1 = (c >> 10) + 0xD800; | |
1878 c2 = (c & 0x3FF) + 0xDC00; | |
1879 if (big_endian) | |
1880 EMIT_FOUR_BYTES (c1 >> 8, c1 & 0xFF, c2 >> 8, c2 & 0xFF); | |
1881 else | |
1882 EMIT_FOUR_BYTES (c1 & 0xFF, c1 >> 8, c2 & 0xFF, c2 >> 8); | |
1883 } | |
1884 } | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
1885 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 1886 coding->produced = dst - coding->destination; |
1887 coding->produced_char += produced_chars; | |
1888 return 0; | |
1889 } | |
1890 | |
1891 | |
1892 /*** 6. Old Emacs' internal format (emacs-mule) ***/ | |
17052 | 1893 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1894 /* Emacs' internal format for representation of multiple character |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1895 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
|
1896 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
|
1897 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1898 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
|
1899 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
|
1900 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
|
1901 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1902 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
|
1903 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
|
1904 code + 0x20). |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1905 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1906 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
|
1907 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
|
1908 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1909 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
|
1910 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
|
1911 `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
|
1912 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
|
1913 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
|
1914 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
|
1915 and position-code. |
18766 | 1916 |
17052 | 1917 --- 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
|
1918 character set range |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1919 ------------- ----- |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1920 ascii 0x00..0x7F |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1921 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
|
1922 eight-bit-graphic 0xA0..0xBF |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1923 ELSE 0x81..0x9D + [0xA0..0xFF]+ |
17052 | 1924 --------------------------------------------- |
1925 | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1926 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
|
1927 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
|
1928 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
|
1929 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
|
1930 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1931 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
|
1932 form. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1933 |
88365 | 1934 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
|
1935 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
|
1936 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1937 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
|
1938 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
|
1939 where, |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1940 METHOD is 0xF2 plus one of composition method (enum |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1941 composition_method), |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1942 |
88365 | 1943 BYTES is 0xA0 plus a byte length of this composition data, |
1944 | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1945 CHARS is 0xA0 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
|
1946 data, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1947 |
88365 | 1948 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
|
1949 rules encoded by two-byte of ASCII codes. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1950 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1951 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
|
1952 also recognized as composition data on decoding. |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1953 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1954 0x80 MSEQ ... |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1955 0x80 0xFF MSEQ RULE MSEQ RULE ... MSEQ |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1956 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1957 Here, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1958 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
|
1959 ASCII: 0xA0 ASCII_CODE+0x80, |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1960 other: LEADING_CODE+0x20 FOLLOWING-BYTE ..., |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1961 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
|
1962 represents a composition rule. |
17052 | 1963 */ |
1964 | |
88365 | 1965 char emacs_mule_bytes[256]; |
1966 | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1967 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1968 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1969 Check if a text is encoded in `emacs-mule'. If it is, return 1, |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1970 else return 0. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1971 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1972 static int |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1973 detect_coding_emacs_mule (coding, detect_info) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1974 struct coding_system *coding; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1975 struct coding_detection_info *detect_info; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1976 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1977 const unsigned char *src = coding->source, *src_base; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1978 const unsigned char *src_end = coding->source + coding->src_bytes; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1979 int multibytep = coding->src_multibyte; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1980 int consumed_chars = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1981 int c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1982 int found = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1983 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1984 detect_info->checked |= CATEGORY_MASK_EMACS_MULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1985 /* A coding system of this category is always ASCII compatible. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1986 src += coding->head_ascii; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1987 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1988 while (1) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1989 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1990 src_base = src; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1991 ONE_MORE_BYTE (c); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1992 if (c < 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1993 continue; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1994 if (c == 0x80) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1995 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1996 /* Perhaps the start of composite character. We simply skip |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1997 it because analyzing it is too heavy for detecting. But, |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1998 at least, we check that the composite character |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
1999 constitutes of more than 4 bytes. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2000 const unsigned char *src_base; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2001 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2002 repeat: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2003 src_base = src; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2004 do |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2005 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2006 ONE_MORE_BYTE (c); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2007 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2008 while (c >= 0xA0); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2009 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2010 if (src - src_base <= 4) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2011 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2012 found = CATEGORY_MASK_EMACS_MULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2013 if (c == 0x80) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2014 goto repeat; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2015 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2016 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2017 if (c < 0x80) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2018 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2019 if (c < 0x20 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2020 && (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2021 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2022 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2023 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2024 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2025 int more_bytes = emacs_mule_bytes[*src_base] - 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2026 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2027 while (more_bytes > 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2028 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2029 ONE_MORE_BYTE (c); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2030 if (c < 0xA0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2031 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2032 src--; /* Unread the last byte. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2033 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2034 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2035 more_bytes--; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2036 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2037 if (more_bytes != 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2038 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2039 found = CATEGORY_MASK_EMACS_MULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2040 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2041 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2042 detect_info->rejected |= CATEGORY_MASK_EMACS_MULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2043 return 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2044 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2045 no_more_source: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2046 if (src_base < src && coding->mode & CODING_MODE_LAST_BLOCK) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2047 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2048 detect_info->rejected |= CATEGORY_MASK_EMACS_MULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2049 return 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2050 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2051 detect_info->found |= found; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2052 return 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2053 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2054 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2055 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2056 /* Parse emacs-mule multibyte sequence at SRC and return the decoded |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2057 character. If CMP_STATUS indicates that we must expect MSEQ or |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2058 RULE described above, decode it and return the negative value of |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2059 the deocded character or rule. If an invalid byte is found, return |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2060 -1. If SRC is too short, return -2. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2061 |
88365 | 2062 int |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2063 emacs_mule_char (coding, src, nbytes, nchars, id, cmp_status) |
88365 | 2064 struct coding_system *coding; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2065 const unsigned char *src; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2066 int *nbytes, *nchars, *id; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2067 struct composition_status *cmp_status; |
88365 | 2068 { |
89483 | 2069 const unsigned char *src_end = coding->source + coding->src_bytes; |
2070 const unsigned char *src_base = src; | |
88365 | 2071 int multibytep = coding->src_multibyte; |
2072 struct charset *charset; | |
2073 unsigned code; | |
2074 int c; | |
2075 int consumed_chars = 0; | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2076 int mseq_found = 0; |
88365 | 2077 |
2078 ONE_MORE_BYTE (c); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2079 if (c < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2080 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2081 c = -c; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2082 charset = emacs_mule_charset[0]; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2083 } |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2084 else |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2085 { |
90354
450fb16a4bf4
(DECODE_COMPOSITION_START): If the source is short, set
Kenichi Handa <handa@m17n.org>
parents:
90350
diff
changeset
|
2086 if (c >= 0xA0) |
450fb16a4bf4
(DECODE_COMPOSITION_START): If the source is short, set
Kenichi Handa <handa@m17n.org>
parents:
90350
diff
changeset
|
2087 { |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2088 if (cmp_status->state != COMPOSING_NO |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2089 && cmp_status->old_form) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2090 { |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2091 if (cmp_status->state == COMPOSING_CHAR) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2092 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2093 if (c == 0xA0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2094 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2095 ONE_MORE_BYTE (c); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2096 c -= 0x80; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2097 if (c < 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2098 goto invalid_code; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2099 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2100 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2101 c -= 0x20; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2102 mseq_found = 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2103 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2104 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2105 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2106 *nbytes = src - src_base; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2107 *nchars = consumed_chars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2108 return -c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2109 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2110 } |
17052 | 2111 else |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2112 goto invalid_code; |
17052 | 2113 } |
2114 | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2115 switch (emacs_mule_bytes[c]) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2116 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2117 case 2: |
88365 | 2118 if (! (charset = emacs_mule_charset[c])) |
2119 goto invalid_code; | |
2120 ONE_MORE_BYTE (c); | |
17052 | 2121 if (c < 0xA0) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2122 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2123 code = c & 0x7F; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2124 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2125 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2126 case 3: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2127 if (c == EMACS_MULE_LEADING_CODE_PRIVATE_11 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2128 || c == EMACS_MULE_LEADING_CODE_PRIVATE_12) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2129 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2130 ONE_MORE_BYTE (c); |
89892 | 2131 if (c < 0xA0 || ! (charset = emacs_mule_charset[c])) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2132 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2133 ONE_MORE_BYTE (c); |
89892 | 2134 if (c < 0xA0) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2135 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2136 code = c & 0x7F; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2137 } |
26847 | 2138 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2139 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2140 if (! (charset = emacs_mule_charset[c])) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2141 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2142 ONE_MORE_BYTE (c); |
89892 | 2143 if (c < 0xA0) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2144 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2145 code = (c & 0x7F) << 8; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2146 ONE_MORE_BYTE (c); |
89892 | 2147 if (c < 0xA0) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2148 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2149 code |= c & 0x7F; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2150 } |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2151 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2152 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2153 case 4: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2154 ONE_MORE_BYTE (c); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2155 if (c < 0 || ! (charset = emacs_mule_charset[c])) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2156 goto invalid_code; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2157 ONE_MORE_BYTE (c); |
89892 | 2158 if (c < 0xA0) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2159 goto invalid_code; |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2160 code = (c & 0x7F) << 8; |
88365 | 2161 ONE_MORE_BYTE (c); |
89892 | 2162 if (c < 0xA0) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2163 goto invalid_code; |
88365 | 2164 code |= c & 0x7F; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2165 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2166 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2167 case 1: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2168 code = c; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2169 charset = CHARSET_FROM_ID (ASCII_BYTE_P (code) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2170 ? charset_ascii : charset_eight_bit); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2171 break; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2172 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2173 default: |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2174 abort (); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2175 } |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2176 c = DECODE_CHAR (charset, code); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2177 if (c < 0) |
88365 | 2178 goto invalid_code; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2179 } |
88365 | 2180 *nbytes = src - src_base; |
2181 *nchars = consumed_chars; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2182 if (id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2183 *id = charset->id; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2184 return (mseq_found ? -c : c); |
88365 | 2185 |
2186 no_more_source: | |
2187 return -2; | |
2188 | |
2189 invalid_code: | |
2190 return -1; | |
2191 } | |
2192 | |
17052 | 2193 |
88365 | 2194 /* 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
|
2195 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2196 /* Handle these composition sequence ('|': the end of header elements, |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2197 BYTES and CHARS >= 0xA0): |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2198 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2199 (1) relative composition: 0x80 0xF2 BYTES CHARS | CHAR ... |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2200 (2) altchar composition: 0x80 0xF4 BYTES CHARS | ALT ... ALT CHAR ... |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2201 (3) alt&rule composition: 0x80 0xF5 BYTES CHARS | ALT RULE ... ALT CHAR ... |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2202 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2203 and these old form: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2204 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2205 (4) relative composition: 0x80 | MSEQ ... MSEQ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2206 (5) rulebase composition: 0x80 0xFF | MSEQ MRULE ... MSEQ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2207 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2208 When the starter 0x80 and the following header elements are found, |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2209 this annotation header is produced. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2210 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2211 [ -LENGTH(==-5) CODING_ANNOTATE_COMPOSITION_MASK NCHARS NBYTES METHOD ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2212 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2213 NCHARS is CHARS - 0xA0 for (1), (2), (3), and 0 for (4), (5). |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2214 NBYTES is BYTES - 0xA0 for (1), (2), (3), and 0 for (4), (5). |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2215 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2216 Then, upon reading the following elements, these codes are produced |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2217 until the composition end is found: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2218 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2219 (1) CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2220 (2) ALT ... ALT CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2221 (3) ALT -2 DECODED-RULE ALT -2 DECODED-RULE ... ALT CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2222 (4) CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2223 (5) CHAR -2 DECODED-RULE CHAR -2 DECODED-RULE ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2224 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2225 When the composition end is found, LENGTH and NCHARS in the |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2226 annotation header is updated as below: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2227 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2228 (1) LENGTH: unchanged, NCHARS: unchanged |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2229 (2) LENGTH: length of the whole sequence minus NCHARS, NCHARS: unchanged |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2230 (3) LENGTH: length of the whole sequence minus NCHARS, NCHARS: unchanged |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2231 (4) LENGTH: unchanged, NCHARS: number of CHARs |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2232 (5) LENGTH: unchanged, NCHARS: number of CHARs |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2233 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2234 If an error is found while composing, the annotation header is |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2235 changed to the original composition header (plus filler -1s) as |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2236 below: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2237 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2238 (1),(2),(3) [ 0x80 0xF2+METHOD BYTES CHARS -1 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2239 (5) [ 0x80 0xFF -1 -1- -1 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2240 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2241 and the sequence [ -2 DECODED-RULE ] is changed to the original |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2242 byte sequence as below: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2243 o the original byte sequence is B: [ B -1 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2244 o the original byte sequence is B1 B2: [ B1 B2 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2245 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2246 Most of the routines are implemented by macros because many |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2247 variables and labels in the caller decode_coding_emacs_mule must be |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2248 accessible, and they are usually called just once (thus doesn't |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2249 increase the size of compiled object). */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2250 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2251 /* Decode a composition rule represented by C as a component of |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2252 composition sequence of Emacs 20 style. Set RULE to the decoded |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2253 rule. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2254 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2255 #define DECODE_EMACS_MULE_COMPOSITION_RULE_20(c, rule) \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2256 do { \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2257 int gref, nref; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2258 \ |
90354
450fb16a4bf4
(DECODE_COMPOSITION_START): If the source is short, set
Kenichi Handa <handa@m17n.org>
parents:
90350
diff
changeset
|
2259 c -= 0xA0; \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2260 if (c < 0 || c >= 81) \ |
88365 | 2261 goto invalid_code; \ |
2262 gref = c / 9, nref = c % 9; \ | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2263 if (gref == 4) gref = 10; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2264 if (nref == 4) nref = 10; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2265 rule = COMPOSITION_ENCODE_RULE (gref, nref); \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2266 } while (0) |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2267 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2268 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2269 /* Decode a composition rule represented by C and the following byte |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2270 at SRC as a component of composition sequence of Emacs 21 style. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2271 Set RULE to the decoded rule. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2272 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2273 #define DECODE_EMACS_MULE_COMPOSITION_RULE_21(c, rule) \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2274 do { \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2275 int gref, nref; \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2276 \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2277 gref = c - 0x20; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2278 if (gref < 0 || gref >= 81) \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2279 goto invalid_code; \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2280 ONE_MORE_BYTE (c); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2281 nref = c - 0x20; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2282 if (nref < 0 || nref >= 81) \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2283 goto invalid_code; \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2284 rule = COMPOSITION_ENCODE_RULE (gref, nref); \ |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2285 } while (0) |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2286 |
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2287 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2288 /* Start of Emacs 21 style format. The first three bytes at SRC are |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2289 (METHOD - 0xF2), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is the |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2290 byte length of this composition information, CHARS is the number of |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2291 characters composed by this composition. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2292 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2293 #define DECODE_EMACS_MULE_21_COMPOSITION() \ |
88365 | 2294 do { \ |
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2295 enum composition_method method = c - 0xF2; \ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2296 int *charbuf_base = charbuf; \ |
88365 | 2297 int nbytes, nchars; \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2298 \ |
88365 | 2299 ONE_MORE_BYTE (c); \ |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2300 if (c < 0) \ |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2301 goto invalid_code; \ |
88365 | 2302 nbytes = c - 0xA0; \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2303 if (nbytes < 3 || (method == COMPOSITION_RELATIVE && nbytes != 4)) \ |
88365 | 2304 goto invalid_code; \ |
2305 ONE_MORE_BYTE (c); \ | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2306 nchars = c - 0xA0; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2307 if (nchars <= 0 || nchars >= MAX_COMPOSITION_COMPONENTS) \ |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2308 goto invalid_code; \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2309 cmp_status->old_form = 0; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2310 cmp_status->method = method; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2311 if (method == COMPOSITION_RELATIVE) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2312 cmp_status->state = COMPOSING_CHAR; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2313 else \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2314 cmp_status->state = COMPOSING_COMPONENT_CHAR; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2315 cmp_status->length = MAX_ANNOTATION_LENGTH; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2316 cmp_status->nchars = nchars; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2317 cmp_status->ncomps = nbytes - 4; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2318 ADD_COMPOSITION_DATA (charbuf, nchars, nbytes, method); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2319 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2320 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2321 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2322 /* Start of Emacs 20 style format for relative composition. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2323 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2324 #define DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION() \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2325 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2326 cmp_status->old_form = 1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2327 cmp_status->method = COMPOSITION_RELATIVE; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2328 cmp_status->state = COMPOSING_CHAR; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2329 cmp_status->length = MAX_ANNOTATION_LENGTH; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2330 cmp_status->nchars = cmp_status->ncomps = 0; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2331 ADD_COMPOSITION_DATA (charbuf, 0, 0, cmp_status->method); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2332 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2333 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2334 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2335 /* Start of Emacs 20 style format for rule-base composition. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2336 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2337 #define DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION() \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2338 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2339 cmp_status->old_form = 1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2340 cmp_status->method = COMPOSITION_WITH_RULE; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2341 cmp_status->state = COMPOSING_CHAR; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2342 cmp_status->length = MAX_ANNOTATION_LENGTH; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2343 cmp_status->nchars = cmp_status->ncomps = 0; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2344 ADD_COMPOSITION_DATA (charbuf, 0, 0, cmp_status->method); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2345 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2346 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2347 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2348 #define DECODE_EMACS_MULE_COMPOSITION_START() \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2349 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2350 const unsigned char *current_src = src; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2351 \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2352 ONE_MORE_BYTE (c); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2353 if (c < 0) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2354 goto invalid_code; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2355 if (c - 0xF2 >= COMPOSITION_RELATIVE \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2356 && c - 0xF2 <= COMPOSITION_WITH_RULE_ALTCHARS) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2357 DECODE_EMACS_MULE_21_COMPOSITION (); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2358 else if (c < 0xA0) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2359 goto invalid_code; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2360 else if (c < 0xC0) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2361 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2362 DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION (); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2363 /* Re-read C as a composition component. */ \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2364 src = current_src; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2365 } \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2366 else if (c == 0xFF) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2367 DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION (); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2368 else \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2369 goto invalid_code; \ |
88365 | 2370 } while (0) |
2371 | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2372 #define EMACS_MULE_COMPOSITION_END() \ |
88365 | 2373 do { \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2374 int idx = - cmp_status->length; \ |
90354
450fb16a4bf4
(DECODE_COMPOSITION_START): If the source is short, set
Kenichi Handa <handa@m17n.org>
parents:
90350
diff
changeset
|
2375 \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2376 if (cmp_status->old_form) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2377 charbuf[idx + 2] = cmp_status->nchars; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2378 else if (cmp_status->method > COMPOSITION_RELATIVE) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2379 charbuf[idx] = charbuf[idx + 2] - cmp_status->length; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2380 cmp_status->state = COMPOSING_NO; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2381 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2382 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2383 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2384 static int |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2385 emacs_mule_finish_composition (charbuf, cmp_status) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2386 int *charbuf; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2387 struct composition_status *cmp_status; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2388 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2389 int idx = - cmp_status->length; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2390 int new_chars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2391 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2392 if (cmp_status->old_form && cmp_status->nchars > 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2393 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2394 charbuf[idx + 2] = cmp_status->nchars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2395 new_chars = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2396 if (cmp_status->method == COMPOSITION_WITH_RULE |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2397 && cmp_status->state == COMPOSING_CHAR) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2398 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2399 /* The last rule was invalid. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2400 int rule = charbuf[-1] + 0xA0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2401 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2402 charbuf[-2] = BYTE8_TO_CHAR (rule); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2403 charbuf[-1] = -1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2404 new_chars = 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2405 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2406 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2407 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2408 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2409 charbuf[idx++] = BYTE8_TO_CHAR (0x80); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2410 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2411 if (cmp_status->method == COMPOSITION_WITH_RULE) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2412 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2413 charbuf[idx++] = BYTE8_TO_CHAR (0xFF); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2414 charbuf[idx++] = -3; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2415 charbuf[idx++] = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2416 new_chars = 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2417 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2418 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2419 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2420 int nchars = charbuf[idx + 1] + 0xA0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2421 int nbytes = charbuf[idx + 2] + 0xA0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2422 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2423 charbuf[idx++] = BYTE8_TO_CHAR (0xF2 + cmp_status->method); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2424 charbuf[idx++] = BYTE8_TO_CHAR (nbytes); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2425 charbuf[idx++] = BYTE8_TO_CHAR (nchars); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2426 charbuf[idx++] = -1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2427 new_chars = 4; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2428 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2429 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2430 cmp_status->state = COMPOSING_NO; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2431 return new_chars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2432 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2433 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2434 #define EMACS_MULE_MAYBE_FINISH_COMPOSITION() \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2435 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2436 if (cmp_status->state != COMPOSING_NO) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2437 char_offset += emacs_mule_finish_composition (charbuf, cmp_status); \ |
88365 | 2438 } while (0) |
2439 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2440 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2441 static void |
88365 | 2442 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
|
2443 struct coding_system *coding; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2444 { |
89483 | 2445 const unsigned char *src = coding->source + coding->consumed; |
2446 const unsigned char *src_end = coding->source + coding->src_bytes; | |
59168
0345f2b10f1d
(decode_coding_XXX, decode_composition_emacs_mule)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
59095
diff
changeset
|
2447 const unsigned char *src_base; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
2448 int *charbuf = coding->charbuf + coding->charbuf_used; |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
2449 /* We may produce two annocations (charset and composition) in one |
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
2450 loop and one more charset annocation at the end. */ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
2451 int *charbuf_end |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
2452 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); |
88365 | 2453 int consumed_chars = 0, consumed_chars_base; |
2454 int multibytep = coding->src_multibyte; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
2455 Lisp_Object attrs, charset_list; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2456 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2457 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2458 int last_id = charset_ascii; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
2459 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
2460 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2461 int byte_after_cr = -1; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2462 struct composition_status *cmp_status = &coding->spec.emacs_mule.cmp_status; |
88365 | 2463 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
2464 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 2465 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2466 if (cmp_status->state != COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2467 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2468 int i; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2469 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2470 for (i = 0; i < cmp_status->length; i++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2471 *charbuf++ = cmp_status->carryover[i]; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2472 coding->annotated = 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2473 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2474 |
88365 | 2475 while (1) |
2476 { | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2477 int c, id; |
88365 | 2478 |
2479 src_base = src; | |
2480 consumed_chars_base = consumed_chars; | |
2481 | |
2482 if (charbuf >= charbuf_end) | |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
2483 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
2484 if (byte_after_cr >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
2485 src_base--; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
2486 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
2487 } |
88365 | 2488 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2489 if (byte_after_cr >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2490 c = byte_after_cr, byte_after_cr = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2491 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2492 ONE_MORE_BYTE (c); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2493 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2494 if (c < 0 || c == 0x80) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2495 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2496 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2497 if (c < 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2498 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2499 *charbuf++ = -c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2500 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2501 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2502 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2503 DECODE_EMACS_MULE_COMPOSITION_START (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2504 continue; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2505 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2506 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2507 if (c < 0x80) |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2508 { |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2509 if (eol_crlf && c == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
2510 ONE_MORE_BYTE (byte_after_cr); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2511 id = charset_ascii; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2512 if (cmp_status->state != COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2513 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2514 if (cmp_status->old_form) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2515 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2516 else if (cmp_status->state >= COMPOSING_COMPONENT_CHAR) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2517 cmp_status->ncomps--; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2518 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2519 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2520 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2521 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2522 int nchars, nbytes; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2523 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2524 c = emacs_mule_char (coding, src_base, &nbytes, &nchars, &id, |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2525 cmp_status); |
88365 | 2526 if (c < 0) |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2527 { |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2528 if (c == -1) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2529 goto invalid_code; |
88365 | 2530 if (c == -2) |
2531 break; | |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2532 } |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2533 src = src_base + nbytes; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2534 consumed_chars = consumed_chars_base + nchars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2535 if (cmp_status->state >= COMPOSING_COMPONENT_CHAR) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2536 cmp_status->ncomps -= nchars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2537 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2538 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2539 /* Now if C >= 0, we found a normally encoded characer, if C < |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2540 0, we found an old-style composition component character or |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2541 rule. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2542 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2543 if (cmp_status->state == COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2544 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2545 if (last_id != id) |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2546 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2547 if (last_id != charset_ascii) |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2548 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2549 last_id); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2550 last_id = id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2551 last_offset = char_offset; |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2552 } |
88365 | 2553 *charbuf++ = c; |
2554 char_offset++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2555 } |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2556 else if (cmp_status->state == COMPOSING_CHAR) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2557 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2558 if (cmp_status->old_form) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2559 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2560 if (c >= 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2561 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2562 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2563 *charbuf++ = c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2564 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2565 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2566 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2567 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2568 *charbuf++ = -c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2569 cmp_status->nchars++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2570 cmp_status->length++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2571 if (cmp_status->nchars == MAX_COMPOSITION_COMPONENTS) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2572 EMACS_MULE_COMPOSITION_END (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2573 else if (cmp_status->method == COMPOSITION_WITH_RULE) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2574 cmp_status->state = COMPOSING_RULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2575 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2576 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2577 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2578 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2579 *charbuf++ = c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2580 cmp_status->length++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2581 cmp_status->nchars--; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2582 if (cmp_status->nchars == 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2583 EMACS_MULE_COMPOSITION_END (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2584 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2585 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2586 else if (cmp_status->state == COMPOSING_RULE) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2587 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2588 int rule; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2589 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2590 if (c >= 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2591 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2592 EMACS_MULE_COMPOSITION_END (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2593 *charbuf++ = c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2594 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2595 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2596 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2597 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2598 c = -c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2599 DECODE_EMACS_MULE_COMPOSITION_RULE_20 (c, rule); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2600 if (rule < 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2601 goto invalid_code; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2602 *charbuf++ = -2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2603 *charbuf++ = rule; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2604 cmp_status->length += 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2605 cmp_status->state = COMPOSING_CHAR; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2606 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2607 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2608 else if (cmp_status->state == COMPOSING_COMPONENT_CHAR) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2609 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2610 *charbuf++ = c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2611 cmp_status->length++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2612 if (cmp_status->ncomps == 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2613 cmp_status->state = COMPOSING_CHAR; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2614 else if (cmp_status->ncomps > 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2615 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2616 if (cmp_status->method == COMPOSITION_WITH_RULE_ALTCHARS) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2617 cmp_status->state = COMPOSING_COMPONENT_RULE; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2618 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2619 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2620 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2621 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2622 else /* COMPOSING_COMPONENT_RULE */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2623 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2624 int rule; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2625 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2626 DECODE_EMACS_MULE_COMPOSITION_RULE_21 (c, rule); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2627 if (rule < 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2628 goto invalid_code; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2629 *charbuf++ = -2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2630 *charbuf++ = rule; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2631 cmp_status->length += 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2632 cmp_status->ncomps--; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2633 if (cmp_status->ncomps > 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2634 cmp_status->state = COMPOSING_COMPONENT_CHAR; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2635 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2636 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2637 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2638 continue; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2639 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2640 retry: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2641 src = src_base; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2642 consumed_chars = consumed_chars_base; |
88365 | 2643 continue; |
2644 | |
2645 invalid_code: | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2646 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
88365 | 2647 src = src_base; |
2648 consumed_chars = consumed_chars_base; | |
2649 ONE_MORE_BYTE (c); | |
2650 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2651 char_offset++; |
88365 | 2652 coding->errors++; |
2653 } | |
2654 | |
2655 no_more_source: | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2656 if (cmp_status->state != COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2657 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2658 if (coding->mode & CODING_MODE_LAST_BLOCK) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2659 EMACS_MULE_MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2660 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2661 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2662 int i; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2663 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2664 charbuf -= cmp_status->length; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2665 for (i = 0; i < cmp_status->length; i++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2666 cmp_status->carryover[i] = charbuf[i]; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2667 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
2668 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2669 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
2670 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
88365 | 2671 coding->consumed_char += consumed_chars_base; |
2672 coding->consumed = src_base - coding->source; | |
2673 coding->charbuf_used = charbuf - coding->charbuf; | |
2674 } | |
2675 | |
2676 | |
2677 #define EMACS_MULE_LEADING_CODES(id, codes) \ | |
2678 do { \ | |
2679 if (id < 0xA0) \ | |
2680 codes[0] = id, codes[1] = 0; \ | |
2681 else if (id < 0xE0) \ | |
2682 codes[0] = 0x9A, codes[1] = id; \ | |
2683 else if (id < 0xF0) \ | |
2684 codes[0] = 0x9B, codes[1] = id; \ | |
2685 else if (id < 0xF5) \ | |
2686 codes[0] = 0x9C, codes[1] = id; \ | |
2687 else \ | |
2688 codes[0] = 0x9D, codes[1] = id; \ | |
2689 } while (0); | |
2690 | |
2691 | |
2692 static int | |
2693 encode_coding_emacs_mule (coding) | |
2694 struct coding_system *coding; | |
2695 { | |
2696 int multibytep = coding->dst_multibyte; | |
2697 int *charbuf = coding->charbuf; | |
2698 int *charbuf_end = charbuf + coding->charbuf_used; | |
2699 unsigned char *dst = coding->destination + coding->produced; | |
2700 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
2701 int safe_room = 8; | |
2702 int produced_chars = 0; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
2703 Lisp_Object attrs, charset_list; |
88365 | 2704 int c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2705 int preferred_charset_id = -1; |
88365 | 2706 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
2707 CODING_GET_INFO (coding, attrs, charset_list); |
89644
fc9cda144ffc
(encode_coding_emacs_mule): Resync charset_list to
Kenichi Handa <handa@m17n.org>
parents:
89642
diff
changeset
|
2708 if (! EQ (charset_list, Vemacs_mule_charset_list)) |
fc9cda144ffc
(encode_coding_emacs_mule): Resync charset_list to
Kenichi Handa <handa@m17n.org>
parents:
89642
diff
changeset
|
2709 { |
fc9cda144ffc
(encode_coding_emacs_mule): Resync charset_list to
Kenichi Handa <handa@m17n.org>
parents:
89642
diff
changeset
|
2710 CODING_ATTR_CHARSET_LIST (attrs) |
fc9cda144ffc
(encode_coding_emacs_mule): Resync charset_list to
Kenichi Handa <handa@m17n.org>
parents:
89642
diff
changeset
|
2711 = charset_list = Vemacs_mule_charset_list; |
fc9cda144ffc
(encode_coding_emacs_mule): Resync charset_list to
Kenichi Handa <handa@m17n.org>
parents:
89642
diff
changeset
|
2712 } |
88365 | 2713 |
2714 while (charbuf < charbuf_end) | |
2715 { | |
2716 ASSURE_DESTINATION (safe_room); | |
2717 c = *charbuf++; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2718 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2719 if (c < 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2720 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2721 /* Handle an annotation. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2722 switch (*charbuf) |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2723 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2724 case CODING_ANNOTATE_COMPOSITION_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2725 /* Not yet implemented. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2726 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2727 case CODING_ANNOTATE_CHARSET_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2728 preferred_charset_id = charbuf[3]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2729 if (preferred_charset_id >= 0 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2730 && NILP (Fmemq (make_number (preferred_charset_id), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2731 charset_list))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2732 preferred_charset_id = -1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2733 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2734 default: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2735 abort (); |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2736 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2737 charbuf += -c - 1; |
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2738 continue; |
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2739 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2740 |
88365 | 2741 if (ASCII_CHAR_P (c)) |
2742 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
|
2743 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
|
2744 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2745 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
|
2746 EMIT_ONE_BYTE (c); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2747 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2748 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2749 { |
88365 | 2750 struct charset *charset; |
2751 unsigned code; | |
2752 int dimension; | |
2753 int emacs_mule_id; | |
2754 unsigned char leading_codes[2]; | |
2755 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2756 if (preferred_charset_id >= 0) |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2757 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2758 charset = CHARSET_FROM_ID (preferred_charset_id); |
100176
5706ca7c3d02
(encode_coding_emacs_mule): Be sure to set `code'.
Kenichi Handa <handa@m17n.org>
parents:
100170
diff
changeset
|
2759 if (CHAR_CHARSET_P (c, charset)) |
5706ca7c3d02
(encode_coding_emacs_mule): Be sure to set `code'.
Kenichi Handa <handa@m17n.org>
parents:
100170
diff
changeset
|
2760 code = ENCODE_CHAR (charset, c); |
5706ca7c3d02
(encode_coding_emacs_mule): Be sure to set `code'.
Kenichi Handa <handa@m17n.org>
parents:
100170
diff
changeset
|
2761 else |
5706ca7c3d02
(encode_coding_emacs_mule): Be sure to set `code'.
Kenichi Handa <handa@m17n.org>
parents:
100170
diff
changeset
|
2762 charset = char_charset (c, charset_list, &code); |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2763 } |
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2764 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2765 charset = char_charset (c, charset_list, &code); |
88365 | 2766 if (! charset) |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2767 { |
88365 | 2768 c = coding->default_char; |
2769 if (ASCII_CHAR_P (c)) | |
2770 { | |
2771 EMIT_ONE_ASCII_BYTE (c); | |
2772 continue; | |
2773 } | |
2774 charset = char_charset (c, charset_list, &code); | |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2775 } |
88365 | 2776 dimension = CHARSET_DIMENSION (charset); |
2777 emacs_mule_id = CHARSET_EMACS_MULE_ID (charset); | |
2778 EMACS_MULE_LEADING_CODES (emacs_mule_id, leading_codes); | |
2779 EMIT_ONE_BYTE (leading_codes[0]); | |
2780 if (leading_codes[1]) | |
2781 EMIT_ONE_BYTE (leading_codes[1]); | |
2782 if (dimension == 1) | |
89642
e97441b6244b
(encode_coding_emacs_mule): Emit bytes with MSB.
Kenichi Handa <handa@m17n.org>
parents:
89575
diff
changeset
|
2783 EMIT_ONE_BYTE (code | 0x80); |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2784 else |
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2785 { |
89642
e97441b6244b
(encode_coding_emacs_mule): Emit bytes with MSB.
Kenichi Handa <handa@m17n.org>
parents:
89575
diff
changeset
|
2786 code |= 0x8080; |
88365 | 2787 EMIT_ONE_BYTE (code >> 8); |
2788 EMIT_ONE_BYTE (code & 0xFF); | |
54320
a7e59b39de35
(decode_coding_emacs_mule): Handle insufficent source correctly.
Kenichi Handa <handa@m17n.org>
parents:
54303
diff
changeset
|
2789 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2790 } |
88365 | 2791 } |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
2792 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 2793 coding->produced_char += produced_chars; |
2794 coding->produced = dst - coding->destination; | |
2795 return 0; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2796 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2797 |
17052 | 2798 |
88365 | 2799 /*** 7. ISO2022 handlers ***/ |
17052 | 2800 |
2801 /* 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
|
2802 Since the intention of this note is to help understand the |
35053 | 2803 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
|
2804 SIMPLIFIED. For thorough understanding, please refer to the |
35053 | 2805 original document of ISO2022. This is equivalent to the standard |
2806 ECMA-35, obtainable from <URL:http://www.ecma.ch/> (*). | |
17052 | 2807 |
2808 ISO2022 provides many mechanisms to encode several character sets | |
35053 | 2809 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
|
2810 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
|
2811 text a little bit longer, but the text passes more easily through |
35053 | 2812 several types of gateway, some of which strip off the MSB (Most |
36087 | 2813 Significant Bit). |
35053 | 2814 |
2815 There are two kinds of character sets: control character sets and | |
2816 graphic character sets. The former contain control characters such | |
17052 | 2817 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
|
2818 functions are also provided by escape sequences). The latter |
35053 | 2819 contain graphic characters such as 'A' and '-'. Emacs recognizes |
17052 | 2820 two control character sets and many graphic character sets. |
2821 | |
2822 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
|
2823 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
|
2824 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
|
2825 - DIMENSION1_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2826 - DIMENSION1_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2827 - DIMENSION2_CHARS94 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2828 - DIMENSION2_CHARS96 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2829 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2830 In addition, each character set is assigned an identification tag, |
35053 | 2831 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
|
2832 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
|
2833 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
|
2834 (0x30..0x3F are for private use only). |
17052 | 2835 |
2836 Note (*): ECMA = European Computer Manufacturers Association | |
2837 | |
35053 | 2838 Here are examples of graphic character sets [NAME(<F>)]: |
17052 | 2839 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ... |
2840 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ... | |
2841 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ... | |
2842 o DIMENSION2_CHARS96 -- none for the moment | |
2843 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2844 A code area (1 byte=8 bits) is divided into 4 areas, C0, GL, C1, and GR. |
17052 | 2845 C0 [0x00..0x1F] -- control character plane 0 |
2846 GL [0x20..0x7F] -- graphic character plane 0 | |
2847 C1 [0x80..0x9F] -- control character plane 1 | |
2848 GR [0xA0..0xFF] -- graphic character plane 1 | |
2849 | |
2850 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
|
2851 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
|
2852 - 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
|
2853 - 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
|
2854 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
|
2855 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
|
2856 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
|
2857 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
|
2858 defined to have corresponding escape sequences. |
17052 | 2859 |
2860 A graphic character set is at first designated to one of four | |
2861 graphic registers (G0 through G3), then these graphic registers are | |
2862 invoked to GL or GR. These designations and invocations can be | |
2863 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
|
2864 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
|
2865 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
|
2866 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
|
2867 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2868 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
|
2869 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
|
2870 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
|
2871 be used. |
17052 | 2872 |
2873 There are two ways of invocation: locking-shift and single-shift. | |
2874 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
|
2875 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
|
2876 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
|
2877 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
|
2878 escape sequences: |
17052 | 2879 |
2880 ---------------------------------------------------------------------- | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2881 abbrev function cntrl escape seq description |
17052 | 2882 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2883 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
|
2884 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
|
2885 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
|
2886 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
|
2887 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
|
2888 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
|
2889 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
|
2890 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
|
2891 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char |
17052 | 2892 ---------------------------------------------------------------------- |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2893 (*) 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
|
2894 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2895 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
|
2896 ISO_CODE_XXX in `coding.h'. |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2897 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2898 Designations are done by the following escape sequences: |
17052 | 2899 ---------------------------------------------------------------------- |
2900 escape sequence description | |
2901 ---------------------------------------------------------------------- | |
2902 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0 | |
2903 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1 | |
2904 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2 | |
2905 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3 | |
2906 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*) | |
2907 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1 | |
2908 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2 | |
2909 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3 | |
2910 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**) | |
2911 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1 | |
2912 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2 | |
2913 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3 | |
2914 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*) | |
2915 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1 | |
2916 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2 | |
2917 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3 | |
2918 ---------------------------------------------------------------------- | |
2919 | |
2920 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
|
2921 of dimension 1, chars 94, and final character <F>, etc... |
17052 | 2922 |
2923 Note (*): Although these designations are not allowed in ISO2022, | |
2924 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
|
2925 CHARS96 character sets in a coding system which is characterized as |
17052 | 2926 7-bit environment, non-locking-shift, and non-single-shift. |
2927 | |
2928 Note (**): If <F> is '@', 'A', or 'B', the intermediate character | |
88365 | 2929 '(' must be omitted. We refer to this as "short-form" hereafter. |
17052 | 2930 |
35053 | 2931 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
|
2932 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
|
2933 coding systems such as Compound Text (used in X11's inter client |
36087 | 2934 communication, ISO-2022-JP (used in Japanese Internet), ISO-2022-KR |
2935 (used in Korean Internet), EUC (Extended UNIX Code, used in Asian | |
17052 | 2936 localized platforms), and all of these are variants of ISO2022. |
2937 | |
2938 In addition to the above, Emacs handles two more kinds of escape | |
2939 sequences: ISO6429's direction specification and Emacs' private | |
2940 sequence for specifying character composition. | |
2941 | |
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2942 ISO6429's direction specification takes the following form: |
17052 | 2943 o CSI ']' -- end of the current direction |
2944 o CSI '0' ']' -- end of the current direction | |
2945 o CSI '1' ']' -- start of left-to-right text | |
2946 o CSI '2' ']' -- start of right-to-left text | |
2947 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
|
2948 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
|
2949 |
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2950 Character composition specification takes the following form: |
26847 | 2951 o ESC '0' -- start relative composition |
2952 o ESC '1' -- end composition | |
2953 o ESC '2' -- start rule-base composition (*) | |
2954 o ESC '3' -- start relative composition with alternate chars (**) | |
2955 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
|
2956 Since these are not standard escape sequences of any ISO standard, |
35053 | 2957 the use of them with these meanings is restricted to Emacs only. |
2958 | |
88771 | 2959 (*) This form is used only in Emacs 20.7 and older versions, |
2960 but newer versions can safely decode it. | |
35053 | 2961 (**) This form is used only in Emacs 21.1 and newer versions, |
88771 | 2962 and older versions can't decode it. |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2963 |
35053 | 2964 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
|
2965 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
|
2966 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2967 COMPOSITION_RELATIVE: |
26847 | 2968 ESC 0 CHAR [ CHAR ] ESC 1 |
36087 | 2969 COMPOSITION_WITH_RULE: |
26847 | 2970 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
|
2971 COMPOSITION_WITH_ALTCHARS: |
26847 | 2972 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
|
2973 COMPOSITION_WITH_RULE_ALTCHARS: |
26847 | 2974 ESC 4 ALTCHAR [ RULE ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 */ |
17052 | 2975 |
2976 enum iso_code_class_type iso_code_class[256]; | |
2977 | |
88365 | 2978 #define SAFE_CHARSET_P(coding, id) \ |
2979 ((id) <= (coding)->max_charset_id \ | |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
2980 && (coding)->safe_charsets[id] != 255) |
88365 | 2981 |
2982 | |
2983 #define SHIFT_OUT_OK(category) \ | |
2984 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0) | |
2985 | |
2986 static void | |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2987 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
|
2988 Lisp_Object attrs; |
88365 | 2989 { |
2990 Lisp_Object charset_list, safe_charsets; | |
2991 Lisp_Object request; | |
2992 Lisp_Object reg_usage; | |
2993 Lisp_Object tail; | |
2994 int reg94, reg96; | |
2995 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
2996 int max_charset_id; | |
2997 | |
2998 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
2999 if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) | |
3000 && ! EQ (charset_list, Viso_2022_charset_list)) | |
3001 { | |
3002 CODING_ATTR_CHARSET_LIST (attrs) | |
3003 = charset_list = Viso_2022_charset_list; | |
3004 ASET (attrs, coding_attr_safe_charsets, Qnil); | |
3005 } | |
3006 | |
3007 if (STRINGP (AREF (attrs, coding_attr_safe_charsets))) | |
3008 return; | |
3009 | |
3010 max_charset_id = 0; | |
3011 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
3012 { | |
3013 int id = XINT (XCAR (tail)); | |
3014 if (max_charset_id < id) | |
3015 max_charset_id = id; | |
3016 } | |
3017 | |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
3018 safe_charsets = make_uninit_string (max_charset_id + 1); |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
3019 memset (SDATA (safe_charsets), 255, max_charset_id + 1); |
88365 | 3020 request = AREF (attrs, coding_attr_iso_request); |
3021 reg_usage = AREF (attrs, coding_attr_iso_usage); | |
3022 reg94 = XINT (XCAR (reg_usage)); | |
3023 reg96 = XINT (XCDR (reg_usage)); | |
3024 | |
3025 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
3026 { | |
3027 Lisp_Object id; | |
3028 Lisp_Object reg; | |
3029 struct charset *charset; | |
3030 | |
3031 id = XCAR (tail); | |
3032 charset = CHARSET_FROM_ID (XINT (id)); | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3033 reg = Fcdr (Fassq (id, request)); |
88365 | 3034 if (! NILP (reg)) |
89483 | 3035 SSET (safe_charsets, XINT (id), XINT (reg)); |
88365 | 3036 else if (charset->iso_chars_96) |
3037 { | |
3038 if (reg96 < 4) | |
89483 | 3039 SSET (safe_charsets, XINT (id), reg96); |
88365 | 3040 } |
3041 else | |
3042 { | |
3043 if (reg94 < 4) | |
89483 | 3044 SSET (safe_charsets, XINT (id), reg94); |
88365 | 3045 } |
3046 } | |
3047 ASET (attrs, coding_attr_safe_charsets, safe_charsets); | |
3048 } | |
3049 | |
50047
8e17fbb2ac77
(CODING_ADD_COMPOSITION_COMPONENT): If the number of
Kenichi Handa <handa@m17n.org>
parents:
49600
diff
changeset
|
3050 |
17052 | 3051 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3052 Check if a text is encoded in one of ISO-2022 based codig systems. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3053 If it is, return 1, else return 0. */ |
17052 | 3054 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3055 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3056 detect_coding_iso_2022 (coding, detect_info) |
88365 | 3057 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3058 struct coding_detection_info *detect_info; |
17052 | 3059 { |
89483 | 3060 const unsigned char *src = coding->source, *src_base = src; |
3061 const unsigned char *src_end = coding->source + coding->src_bytes; | |
88365 | 3062 int multibytep = coding->src_multibyte; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3063 int single_shifting = 0; |
88365 | 3064 int id; |
3065 int c, c1; | |
3066 int consumed_chars = 0; | |
3067 int i; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3068 int rejected = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3069 int found = 0; |
99753
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3070 int composition_count = -1; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3071 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3072 detect_info->checked |= CATEGORY_MASK_ISO; |
88365 | 3073 |
3074 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | |
3075 { | |
3076 struct coding_system *this = &(coding_categories[i]); | |
3077 Lisp_Object attrs, val; | |
3078 | |
94944
c16046e21b90
(detect_coding_iso_2022): Ignore a coding category that
Kenichi Handa <handa@m17n.org>
parents:
93877
diff
changeset
|
3079 if (this->id < 0) |
c16046e21b90
(detect_coding_iso_2022): Ignore a coding category that
Kenichi Handa <handa@m17n.org>
parents:
93877
diff
changeset
|
3080 continue; |
88365 | 3081 attrs = CODING_ID_ATTRS (this->id); |
3082 if (CODING_ISO_FLAGS (this) & CODING_ISO_FLAG_FULL_SUPPORT | |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
3083 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Viso_2022_charset_list)) |
88365 | 3084 setup_iso_safe_charsets (attrs); |
3085 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
89483 | 3086 this->max_charset_id = SCHARS (val) - 1; |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
3087 this->safe_charsets = SDATA (val); |
88365 | 3088 } |
3089 | |
3090 /* A coding system of this category is always ASCII compatible. */ | |
3091 src += coding->head_ascii; | |
3092 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3093 while (rejected != CATEGORY_MASK_ISO) |
88365 | 3094 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
3095 src_base = src; |
88365 | 3096 ONE_MORE_BYTE (c); |
17052 | 3097 switch (c) |
3098 { | |
3099 case ISO_CODE_ESC: | |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
3100 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
3101 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3102 single_shifting = 0; |
88365 | 3103 ONE_MORE_BYTE (c); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3104 if (c >= '(' && c <= '/') |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3105 { |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3106 /* Designation sequence for a charset of dimension 1. */ |
88365 | 3107 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3108 if (c1 < ' ' || c1 >= 0x80 |
88365 | 3109 || (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
|
3110 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3111 break; |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3112 } |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3113 else if (c == '$') |
17052 | 3114 { |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3115 /* Designation sequence for a charset of dimension 2. */ |
88365 | 3116 ONE_MORE_BYTE (c); |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3117 if (c >= '@' && c <= 'B') |
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3118 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3119 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
|
3120 else if (c >= '(' && c <= '/') |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
3121 { |
88365 | 3122 ONE_MORE_BYTE (c1); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3123 if (c1 < ' ' || c1 >= 0x80 |
88365 | 3124 || (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
|
3125 /* Invalid designation sequence. Just ignore. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3126 break; |
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
3127 } |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3128 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3129 /* Invalid designation sequence. Just ignore it. */ |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3130 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3131 } |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
3132 else if (c == 'N' || c == 'O') |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3133 { |
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
3134 /* ESC <Fe> for SS2 or SS3. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3135 single_shifting = 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3136 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3137 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3138 } |
99753
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3139 else if (c == '1') |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3140 { |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3141 /* End of composition. */ |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3142 if (composition_count < 0 |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3143 || composition_count > MAX_COMPOSITION_COMPONENTS) |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3144 /* Invalid */ |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3145 break; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3146 composition_count = -1; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3147 found |= CATEGORY_MASK_ISO; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3148 } |
26847 | 3149 else if (c >= '0' && c <= '4') |
3150 { | |
3151 /* ESC <Fp> for start/end composition. */ | |
99753
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3152 composition_count = 0; |
26847 | 3153 break; |
3154 } | |
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3155 else |
88365 | 3156 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3157 /* Invalid escape sequence. Just ignore it. */ |
88365 | 3158 break; |
3159 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3160 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3161 /* We found a valid designation sequence for CHARSET. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3162 rejected |= CATEGORY_MASK_ISO_8BIT; |
88365 | 3163 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7], |
3164 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3165 found |= CATEGORY_MASK_ISO_7; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3166 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3167 rejected |= CATEGORY_MASK_ISO_7; |
88365 | 3168 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_tight], |
3169 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3170 found |= CATEGORY_MASK_ISO_7_TIGHT; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3171 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3172 rejected |= CATEGORY_MASK_ISO_7_TIGHT; |
88365 | 3173 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_else], |
3174 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3175 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
|
3176 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3177 rejected |= CATEGORY_MASK_ISO_7_ELSE; |
88365 | 3178 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_8_else], |
3179 id)) | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3180 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
|
3181 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3182 rejected |= CATEGORY_MASK_ISO_8_ELSE; |
17052 | 3183 break; |
3184 | |
3185 case ISO_CODE_SO: | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3186 case ISO_CODE_SI: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3187 /* Locking shift out/in. */ |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
3188 if (inhibit_iso_escape_detection) |
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
3189 break; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3190 single_shifting = 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3191 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3192 break; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3193 |
17052 | 3194 case ISO_CODE_CSI: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3195 /* Control sequence introducer. */ |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3196 single_shifting = 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3197 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3198 found |= CATEGORY_MASK_ISO_8_ELSE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3199 goto check_extra_latin; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3200 |
17052 | 3201 case ISO_CODE_SS2: |
3202 case ISO_CODE_SS3: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3203 /* Single shift. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3204 if (inhibit_iso_escape_detection) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3205 break; |
89780
a53cb5864a40
(detect_coding_iso_2022): Fix handling of SS2 and SS3.
Kenichi Handa <handa@m17n.org>
parents:
89779
diff
changeset
|
3206 single_shifting = 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3207 rejected |= CATEGORY_MASK_ISO_7BIT; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3208 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3209 & CODING_ISO_FLAG_SINGLE_SHIFT) |
89780
a53cb5864a40
(detect_coding_iso_2022): Fix handling of SS2 and SS3.
Kenichi Handa <handa@m17n.org>
parents:
89779
diff
changeset
|
3210 found |= CATEGORY_MASK_ISO_8_1, single_shifting = 1; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3211 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_2]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3212 & CODING_ISO_FLAG_SINGLE_SHIFT) |
89780
a53cb5864a40
(detect_coding_iso_2022): Fix handling of SS2 and SS3.
Kenichi Handa <handa@m17n.org>
parents:
89779
diff
changeset
|
3213 found |= CATEGORY_MASK_ISO_8_2, single_shifting = 1; |
a53cb5864a40
(detect_coding_iso_2022): Fix handling of SS2 and SS3.
Kenichi Handa <handa@m17n.org>
parents:
89779
diff
changeset
|
3214 if (single_shifting) |
a53cb5864a40
(detect_coding_iso_2022): Fix handling of SS2 and SS3.
Kenichi Handa <handa@m17n.org>
parents:
89779
diff
changeset
|
3215 break; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3216 goto check_extra_latin; |
17052 | 3217 |
3218 default: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
3219 if (c < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
3220 continue; |
17052 | 3221 if (c < 0x80) |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3222 { |
99753
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3223 if (composition_count >= 0) |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3224 composition_count++; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3225 single_shifting = 0; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3226 break; |
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3227 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3228 if (c >= 0xA0) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
3229 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3230 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_7_ELSE; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3231 found |= CATEGORY_MASK_ISO_8_1; |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3232 /* Check the length of succeeding codes of the range |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3233 0xA0..0FF. If the byte length is even, we include |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3234 CATEGORY_MASK_ISO_8_2 in `found'. We can check this |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3235 only when we are not single shifting. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3236 if (! single_shifting |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3237 && ! (rejected & CATEGORY_MASK_ISO_8_2)) |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3238 { |
29299
b33b38d81020
(detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents:
29275
diff
changeset
|
3239 int i = 1; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3240 while (src < src_end) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3241 { |
88365 | 3242 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
|
3243 if (c < 0xA0) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3244 break; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3245 i++; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3246 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3247 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3248 if (i & 1 && src < src_end) |
99753
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3249 { |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3250 rejected |= CATEGORY_MASK_ISO_8_2; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3251 if (composition_count >= 0) |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3252 composition_count += i; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3253 } |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3254 else |
99753
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3255 { |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3256 found |= CATEGORY_MASK_ISO_8_2; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3257 if (composition_count >= 0) |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3258 composition_count += i / 2; |
c457d1e5edff
(detect_coding_iso_2022): Reject invalid composition
Kenichi Handa <handa@m17n.org>
parents:
99074
diff
changeset
|
3259 } |
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
3260 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3261 break; |
17052 | 3262 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3263 check_extra_latin: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3264 single_shifting = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3265 if (! VECTORP (Vlatin_extra_code_table) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3266 || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3267 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3268 rejected = CATEGORY_MASK_ISO; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3269 break; |
17052 | 3270 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3271 if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3272 & CODING_ISO_FLAG_LATIN_EXTRA) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3273 found |= CATEGORY_MASK_ISO_8_1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3274 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3275 rejected |= CATEGORY_MASK_ISO_8_1; |
89780
a53cb5864a40
(detect_coding_iso_2022): Fix handling of SS2 and SS3.
Kenichi Handa <handa@m17n.org>
parents:
89779
diff
changeset
|
3276 rejected |= CATEGORY_MASK_ISO_8_2; |
17052 | 3277 } |
3278 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3279 detect_info->rejected |= CATEGORY_MASK_ISO; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3280 return 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3281 |
88365 | 3282 no_more_source: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3283 detect_info->rejected |= rejected; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3284 detect_info->found |= (found & ~rejected); |
88365 | 3285 return 1; |
17052 | 3286 } |
3287 | |
3288 | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3289 /* Set designation state into CODING. Set CHARS_96 to -1 if the |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3290 escape sequence should be kept. */ |
88365 | 3291 #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
3292 do { \ | |
3293 int id, prev; \ | |
3294 \ | |
3295 if (final < '0' || final >= 128 \ | |
3296 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ | |
3297 || !SAFE_CHARSET_P (coding, id)) \ | |
3298 { \ | |
3299 CODING_ISO_DESIGNATION (coding, reg) = -2; \ | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3300 chars_96 = -1; \ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3301 break; \ |
88365 | 3302 } \ |
3303 prev = CODING_ISO_DESIGNATION (coding, reg); \ | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3304 if (id == charset_jisx0201_roman) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3305 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3306 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
|
3307 id = charset_ascii; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3308 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3309 else if (id == charset_jisx0208_1978) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3310 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3311 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
|
3312 id = charset_jisx0208; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3313 } \ |
88365 | 3314 CODING_ISO_DESIGNATION (coding, reg) = id; \ |
3315 /* If there was an invalid designation to REG previously, and this \ | |
3316 designation is ASCII to REG, we should keep this designation \ | |
3317 sequence. */ \ | |
3318 if (prev == -2 && id == charset_ascii) \ | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3319 chars_96 = -1; \ |
17052 | 3320 } while (0) |
3321 | |
88365 | 3322 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3323 /* Handle these composition sequence (ALT: alternate char): |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3324 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3325 (1) relative composition: ESC 0 CHAR ... ESC 1 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3326 (2) rulebase composition: ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3327 (3) altchar composition: ESC 3 ALT ... ALT ESC 0 CHAR ... ESC 1 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3328 (4) alt&rule composition: ESC 4 ALT RULE ... ALT ESC 0 CHAR ... ESC 1 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3329 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3330 When the start sequence (ESC 0/2/3/4) is found, this annotation |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3331 header is produced. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3332 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3333 [ -LENGTH(==-5) CODING_ANNOTATE_COMPOSITION_MASK NCHARS(==0) 0 METHOD ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3334 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3335 Then, upon reading CHAR or RULE (one or two bytes), these codes are |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3336 produced until the end sequence (ESC 1) is found: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3337 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3338 (1) CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3339 (2) CHAR -2 DECODED-RULE CHAR -2 DECODED-RULE ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3340 (3) ALT ... ALT -1 -1 CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3341 (4) ALT -2 DECODED-RULE ALT -2 DECODED-RULE ... ALT -1 -1 CHAR ... CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3342 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3343 When the end sequence (ESC 1) is found, LENGTH and NCHARS in the |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3344 annotation header is updated as below: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3345 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3346 (1) LENGTH: unchanged, NCHARS: number of CHARs |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3347 (2) LENGTH: unchanged, NCHARS: number of CHARs |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3348 (3) LENGTH: += number of ALTs + 2, NCHARS: number of CHARs |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3349 (4) LENGTH: += number of ALTs * 3, NCHARS: number of CHARs |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3350 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3351 If an error is found while composing, the annotation header is |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3352 changed to: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3353 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3354 [ ESC '0'/'2'/'3'/'4' -2 0 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3355 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3356 and the sequence [ -2 DECODED-RULE ] is changed to the original |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3357 byte sequence as below: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3358 o the original byte sequence is B: [ B -1 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3359 o the original byte sequence is B1 B2: [ B1 B2 ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3360 and the sequence [ -1 -1 ] is changed to the original byte |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3361 sequence: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3362 [ ESC '0' ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3363 */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3364 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3365 /* Decode a composition rule C1 and maybe one more byte from the |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3366 source, and set RULE to the encoded composition rule, NBYTES to the |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3367 length of the composition rule. If the rule is invalid, set RULE |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3368 to some negative value. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3369 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3370 #define DECODE_COMPOSITION_RULE(rule, nbytes) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3371 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3372 rule = c1 - 32; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3373 if (rule < 0) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3374 break; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3375 if (rule < 81) /* old format (before ver.21) */ \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3376 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3377 int gref = (rule) / 9; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3378 int nref = (rule) % 9; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3379 if (gref == 4) gref = 10; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3380 if (nref == 4) nref = 10; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3381 rule = COMPOSITION_ENCODE_RULE (gref, nref); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3382 nbytes = 1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3383 } \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3384 else /* new format (after ver.21) */ \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3385 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3386 int c; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3387 \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3388 ONE_MORE_BYTE (c); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3389 rule = COMPOSITION_ENCODE_RULE (rule - 81, c - 32); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3390 if (rule >= 0) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3391 rule += 0x100; /* to destinguish it from the old format */ \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3392 nbytes = 2; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3393 } \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3394 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3395 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3396 #define ENCODE_COMPOSITION_RULE(rule) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3397 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3398 int gref = (rule % 0x100) / 12, nref = (rule % 0x100) % 12; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3399 \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3400 if (rule < 0x100) /* old format */ \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3401 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3402 if (gref == 10) gref = 4; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3403 if (nref == 10) nref = 4; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3404 charbuf[idx] = 32 + gref * 9 + nref; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3405 charbuf[idx + 1] = -1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3406 new_chars++; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3407 } \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3408 else /* new format */ \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3409 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3410 charbuf[idx] = 32 + 81 + gref; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3411 charbuf[idx + 1] = 32 + nref; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3412 new_chars += 2; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3413 } \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3414 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3415 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3416 /* Finish the current composition as invalid. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3417 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3418 static int finish_composition P_ ((int *, struct composition_status *)); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3419 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3420 static int |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3421 finish_composition (charbuf, cmp_status) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3422 int *charbuf; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3423 struct composition_status *cmp_status; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3424 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3425 int idx = - cmp_status->length; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3426 int new_chars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3427 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3428 /* Recover the original ESC sequence */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3429 charbuf[idx++] = ISO_CODE_ESC; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3430 charbuf[idx++] = (cmp_status->method == COMPOSITION_RELATIVE ? '0' |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3431 : cmp_status->method == COMPOSITION_WITH_RULE ? '2' |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3432 : cmp_status->method == COMPOSITION_WITH_ALTCHARS ? '3' |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3433 /* cmp_status->method == COMPOSITION_WITH_RULE_ALTCHARS */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3434 : '4'); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3435 charbuf[idx++] = -2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3436 charbuf[idx++] = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3437 charbuf[idx++] = -1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3438 new_chars = cmp_status->nchars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3439 if (cmp_status->method >= COMPOSITION_WITH_RULE) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3440 for (; idx < 0; idx++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3441 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3442 int elt = charbuf[idx]; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3443 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3444 if (elt == -2) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3445 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3446 ENCODE_COMPOSITION_RULE (charbuf[idx + 1]); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3447 idx++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3448 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3449 else if (elt == -1) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3450 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3451 charbuf[idx++] = ISO_CODE_ESC; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3452 charbuf[idx] = '0'; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3453 new_chars += 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3454 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3455 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3456 cmp_status->state = COMPOSING_NO; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3457 return new_chars; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3458 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3459 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3460 /* If characers are under composition, finish the composition. */ |
88365 | 3461 #define MAYBE_FINISH_COMPOSITION() \ |
3462 do { \ | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3463 if (cmp_status->state != COMPOSING_NO) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3464 char_offset += finish_composition (charbuf, cmp_status); \ |
88365 | 3465 } while (0) |
3466 | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
3467 /* Handle composition start sequence ESC 0, ESC 2, ESC 3, or ESC 4. |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3468 |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
3469 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
|
3470 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
88365 | 3471 ESC 3 : altchar composition : ESC 3 CHAR ... ESC 0 CHAR ... ESC 1 |
3472 ESC 4 : alt&rule composition : ESC 4 CHAR RULE ... CHAR ESC 0 CHAR ... ESC 1 | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3473 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3474 Produce this annotation sequence now: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3475 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3476 [ -LENGTH(==-4) CODING_ANNOTATE_COMPOSITION_MASK NCHARS(==0) METHOD ] |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3477 */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3478 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3479 #define DECODE_COMPOSITION_START(c1) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3480 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3481 if (c1 == '0' \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3482 && ((cmp_status->state == COMPOSING_COMPONENT_CHAR \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3483 && cmp_status->method == COMPOSITION_WITH_ALTCHARS) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3484 || (cmp_status->state == COMPOSING_COMPONENT_RULE \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3485 && cmp_status->method == COMPOSITION_WITH_RULE_ALTCHARS))) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3486 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3487 *charbuf++ = -1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3488 *charbuf++= -1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3489 cmp_status->state = COMPOSING_CHAR; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3490 cmp_status->length += 2; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3491 } \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3492 else \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3493 { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3494 MAYBE_FINISH_COMPOSITION (); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3495 cmp_status->method = (c1 == '0' ? COMPOSITION_RELATIVE \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3496 : c1 == '2' ? COMPOSITION_WITH_RULE \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3497 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3498 : COMPOSITION_WITH_RULE_ALTCHARS); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3499 cmp_status->state \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3500 = (c1 <= '2' ? COMPOSING_CHAR : COMPOSING_COMPONENT_CHAR); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3501 ADD_COMPOSITION_DATA (charbuf, 0, 0, cmp_status->method); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3502 cmp_status->length = MAX_ANNOTATION_LENGTH; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3503 cmp_status->nchars = cmp_status->ncomps = 0; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3504 coding->annotated = 1; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3505 } \ |
26847 | 3506 } while (0) |
3507 | |
88365 | 3508 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3509 /* Handle composition end sequence ESC 1. */ |
88365 | 3510 |
3511 #define DECODE_COMPOSITION_END() \ | |
3512 do { \ | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3513 if (cmp_status->nchars == 0 \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3514 || ((cmp_status->state == COMPOSING_CHAR) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3515 == (cmp_status->method == COMPOSITION_WITH_RULE))) \ |
88365 | 3516 { \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3517 MAYBE_FINISH_COMPOSITION (); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3518 goto invalid_code; \ |
88365 | 3519 } \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3520 if (cmp_status->method == COMPOSITION_WITH_ALTCHARS) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3521 charbuf[- cmp_status->length] -= cmp_status->ncomps + 2; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3522 else if (cmp_status->method == COMPOSITION_WITH_RULE_ALTCHARS) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3523 charbuf[- cmp_status->length] -= cmp_status->ncomps * 3; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3524 charbuf[- cmp_status->length + 2] = cmp_status->nchars; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3525 char_offset += cmp_status->nchars; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3526 cmp_status->state = COMPOSING_NO; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3527 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3528 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3529 /* Store a composition rule RULE in charbuf, and update cmp_status. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3530 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3531 #define STORE_COMPOSITION_RULE(rule) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3532 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3533 *charbuf++ = -2; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3534 *charbuf++ = rule; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3535 cmp_status->length += 2; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3536 cmp_status->state--; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3537 } while (0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3538 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3539 /* Store a composed char or a component char C in charbuf, and update |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3540 cmp_status. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3541 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3542 #define STORE_COMPOSITION_CHAR(c) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3543 do { \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3544 *charbuf++ = (c); \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3545 cmp_status->length++; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3546 if (cmp_status->state == COMPOSING_CHAR) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3547 cmp_status->nchars++; \ |
88365 | 3548 else \ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3549 cmp_status->ncomps++; \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3550 if (cmp_status->method == COMPOSITION_WITH_RULE \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3551 || (cmp_status->method == COMPOSITION_WITH_RULE_ALTCHARS \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3552 && cmp_status->state == COMPOSING_COMPONENT_CHAR)) \ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3553 cmp_status->state++; \ |
26847 | 3554 } while (0) |
3555 | |
3556 | |
17052 | 3557 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
3558 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3559 static void |
88365 | 3560 decode_coding_iso_2022 (coding) |
17052 | 3561 struct coding_system *coding; |
3562 { | |
89483 | 3563 const unsigned char *src = coding->source + coding->consumed; |
3564 const unsigned char *src_end = coding->source + coding->src_bytes; | |
3565 const unsigned char *src_base; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
3566 int *charbuf = coding->charbuf + coding->charbuf_used; |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
3567 /* We may produce two annocations (charset and composition) in one |
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
3568 loop and one more charset annocation at the end. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3569 int *charbuf_end |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
3570 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); |
88365 | 3571 int consumed_chars = 0, consumed_chars_base; |
3572 int multibytep = coding->src_multibyte; | |
17052 | 3573 /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
88365 | 3574 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
3575 int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3576 int charset_id_2, charset_id_3; |
88365 | 3577 struct charset *charset; |
3578 int c; | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3579 struct composition_status *cmp_status = CODING_ISO_CMP_STATUS (coding); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
3580 Lisp_Object attrs, charset_list; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3581 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3582 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3583 int last_id = charset_ascii; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
3584 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
3585 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3586 int byte_after_cr = -1; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3587 int i; |
88365 | 3588 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
3589 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 3590 setup_iso_safe_charsets (attrs); |
90772
b15334b4a9c3
(coding_alloc_by_making_gap): New arg offset.
Kenichi Handa <handa@m17n.org>
parents:
90737
diff
changeset
|
3591 /* Charset list may have been changed. */ |
b15334b4a9c3
(coding_alloc_by_making_gap): New arg offset.
Kenichi Handa <handa@m17n.org>
parents:
90737
diff
changeset
|
3592 charset_list = CODING_ATTR_CHARSET_LIST (attrs); |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
3593 coding->safe_charsets = SDATA (CODING_ATTR_SAFE_CHARSETS (attrs)); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3594 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3595 if (cmp_status->state != COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3596 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3597 for (i = 0; i < cmp_status->length; i++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3598 *charbuf++ = cmp_status->carryover[i]; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3599 coding->annotated = 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3600 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3601 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3602 while (1) |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3603 { |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3604 int c1, c2, c3; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3605 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3606 src_base = src; |
88365 | 3607 consumed_chars_base = consumed_chars; |
3608 | |
3609 if (charbuf >= charbuf_end) | |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
3610 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
3611 if (byte_after_cr >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
3612 src_base--; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
3613 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
3614 } |
88365 | 3615 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3616 if (byte_after_cr >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3617 c1 = byte_after_cr, byte_after_cr = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3618 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3619 ONE_MORE_BYTE (c1); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
3620 if (c1 < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
3621 goto invalid_code; |
17052 | 3622 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3623 if (CODING_ISO_EXTSEGMENT_LEN (coding) > 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3624 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3625 *charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3626 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3627 CODING_ISO_EXTSEGMENT_LEN (coding)--; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3628 continue; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3629 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3630 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3631 if (CODING_ISO_EMBEDDED_UTF_8 (coding)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3632 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3633 if (c1 == ISO_CODE_ESC) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3634 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3635 if (src + 1 >= src_end) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3636 goto no_more_source; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3637 *charbuf++ = ISO_CODE_ESC; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3638 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3639 if (src[0] == '%' && src[1] == '@') |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3640 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3641 src += 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3642 consumed_chars += 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3643 char_offset += 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3644 /* We are sure charbuf can contain two more chars. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3645 *charbuf++ = '%'; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3646 *charbuf++ = '@'; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3647 CODING_ISO_EMBEDDED_UTF_8 (coding) = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3648 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3649 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3650 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3651 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3652 *charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3653 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3654 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3655 continue; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3656 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3657 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3658 if ((cmp_status->state == COMPOSING_RULE |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3659 || cmp_status->state == COMPOSING_COMPONENT_RULE) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3660 && c1 != ISO_CODE_ESC) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3661 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3662 int rule, nbytes; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3663 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3664 DECODE_COMPOSITION_RULE (rule, nbytes); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3665 if (rule < 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3666 goto invalid_code; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3667 STORE_COMPOSITION_RULE (rule); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3668 continue; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3669 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3670 |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3671 /* We produce at most one character. */ |
17052 | 3672 switch (iso_code_class [c1]) |
3673 { | |
3674 case ISO_0x20_or_0x7F: | |
88365 | 3675 if (charset_id_0 < 0 |
3676 || ! 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
|
3677 /* This is SPACE or DEL. */ |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3678 charset = CHARSET_FROM_ID (charset_ascii); |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3679 else |
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3680 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
|
3681 break; |
17052 | 3682 |
3683 case ISO_graphic_plane_0: | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3684 if (charset_id_0 < 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3685 charset = CHARSET_FROM_ID (charset_ascii); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3686 else |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3687 charset = CHARSET_FROM_ID (charset_id_0); |
17052 | 3688 break; |
3689 | |
3690 case ISO_0xA0_or_0xFF: | |
88365 | 3691 if (charset_id_1 < 0 |
3692 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) | |
3693 || CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) | |
3694 goto invalid_code; | |
17052 | 3695 /* This is a graphic character, we fall down ... */ |
3696 | |
3697 case ISO_graphic_plane_1: | |
88365 | 3698 if (charset_id_1 < 0) |
3699 goto invalid_code; | |
3700 charset = CHARSET_FROM_ID (charset_id_1); | |
17052 | 3701 break; |
3702 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3703 case ISO_control_0: |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3704 if (eol_crlf && c1 == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
3705 ONE_MORE_BYTE (byte_after_cr); |
88365 | 3706 MAYBE_FINISH_COMPOSITION (); |
3707 charset = CHARSET_FROM_ID (charset_ascii); | |
17052 | 3708 break; |
3709 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3710 case ISO_control_1: |
88365 | 3711 goto invalid_code; |
17052 | 3712 |
3713 case ISO_shift_out: | |
88365 | 3714 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
3715 || CODING_ISO_DESIGNATION (coding, 1) < 0) | |
3716 goto invalid_code; | |
3717 CODING_ISO_INVOCATION (coding, 0) = 1; | |
3718 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
|
3719 continue; |
17052 | 3720 |
3721 case ISO_shift_in: | |
88365 | 3722 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)) |
3723 goto invalid_code; | |
3724 CODING_ISO_INVOCATION (coding, 0) = 0; | |
3725 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
|
3726 continue; |
17052 | 3727 |
3728 case ISO_single_shift_2_7: | |
3729 case ISO_single_shift_2: | |
88365 | 3730 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
3731 goto invalid_code; | |
17052 | 3732 /* SS2 is handled as an escape sequence of ESC 'N' */ |
3733 c1 = 'N'; | |
3734 goto label_escape_sequence; | |
3735 | |
3736 case ISO_single_shift_3: | |
88365 | 3737 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
3738 goto invalid_code; | |
17052 | 3739 /* SS2 is handled as an escape sequence of ESC 'O' */ |
3740 c1 = 'O'; | |
3741 goto label_escape_sequence; | |
3742 | |
3743 case ISO_control_sequence_introducer: | |
3744 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
3745 c1 = '['; | |
3746 goto label_escape_sequence; | |
3747 | |
3748 case ISO_escape: | |
3749 ONE_MORE_BYTE (c1); | |
3750 label_escape_sequence: | |
88365 | 3751 /* Escape sequences handled here are invocation, |
17052 | 3752 designation, direction specification, and character |
3753 composition specification. */ | |
3754 switch (c1) | |
3755 { | |
3756 case '&': /* revision of following character set */ | |
3757 ONE_MORE_BYTE (c1); | |
3758 if (!(c1 >= '@' && c1 <= '~')) | |
88365 | 3759 goto invalid_code; |
17052 | 3760 ONE_MORE_BYTE (c1); |
3761 if (c1 != ISO_CODE_ESC) | |
88365 | 3762 goto invalid_code; |
17052 | 3763 ONE_MORE_BYTE (c1); |
3764 goto label_escape_sequence; | |
3765 | |
3766 case '$': /* designation of 2-byte character set */ | |
88365 | 3767 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
3768 goto invalid_code; | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3769 { |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3770 int reg, chars96; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3771 |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3772 ONE_MORE_BYTE (c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3773 if (c1 >= '@' && c1 <= 'B') |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3774 { /* 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
|
3775 or JISX0208.1980 */ |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3776 reg = 0, chars96 = 0; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3777 } |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3778 else if (c1 >= 0x28 && c1 <= 0x2B) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3779 { /* designation of DIMENSION2_CHARS94 character set */ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3780 reg = c1 - 0x28, chars96 = 0; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3781 ONE_MORE_BYTE (c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3782 } |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3783 else if (c1 >= 0x2C && c1 <= 0x2F) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3784 { /* designation of DIMENSION2_CHARS96 character set */ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3785 reg = c1 - 0x2C, chars96 = 1; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3786 ONE_MORE_BYTE (c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3787 } |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3788 else |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3789 goto invalid_code; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3790 DECODE_DESIGNATION (reg, 2, chars96, c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3791 /* We must update these variables now. */ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3792 if (reg == 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3793 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3794 else if (reg == 1) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3795 charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3796 if (chars96 < 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3797 goto invalid_code; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3798 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3799 continue; |
17052 | 3800 |
3801 case 'n': /* invocation of locking-shift-2 */ | |
88365 | 3802 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
3803 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
3804 goto invalid_code; | |
3805 CODING_ISO_INVOCATION (coding, 0) = 2; | |
3806 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
|
3807 continue; |
17052 | 3808 |
3809 case 'o': /* invocation of locking-shift-3 */ | |
88365 | 3810 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
3811 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
3812 goto invalid_code; | |
3813 CODING_ISO_INVOCATION (coding, 0) = 3; | |
3814 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
|
3815 continue; |
17052 | 3816 |
3817 case 'N': /* invocation of single-shift-2 */ | |
88365 | 3818 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
3819 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
3820 goto invalid_code; | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3821 charset_id_2 = CODING_ISO_DESIGNATION (coding, 2); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3822 if (charset_id_2 < 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3823 charset = CHARSET_FROM_ID (charset_ascii); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3824 else |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3825 charset = CHARSET_FROM_ID (charset_id_2); |
17052 | 3826 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
3827 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 3828 goto invalid_code; |
17052 | 3829 break; |
3830 | |
3831 case 'O': /* invocation of single-shift-3 */ | |
88365 | 3832 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
3833 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
3834 goto invalid_code; | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3835 charset_id_3 = CODING_ISO_DESIGNATION (coding, 3); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3836 if (charset_id_3 < 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3837 charset = CHARSET_FROM_ID (charset_ascii); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3838 else |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3839 charset = CHARSET_FROM_ID (charset_id_3); |
17052 | 3840 ONE_MORE_BYTE (c1); |
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
3841 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
88365 | 3842 goto invalid_code; |
17052 | 3843 break; |
3844 | |
26847 | 3845 case '0': case '2': case '3': case '4': /* start composition */ |
88365 | 3846 if (! (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK)) |
3847 goto invalid_code; | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3848 if (last_id != charset_ascii) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3849 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3850 ADD_CHARSET_DATA (charbuf, char_offset- last_offset, last_id); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3851 last_id = charset_ascii; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3852 last_offset = char_offset; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3853 } |
26847 | 3854 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
|
3855 continue; |
17052 | 3856 |
26847 | 3857 case '1': /* end composition */ |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3858 if (cmp_status->state == COMPOSING_NO) |
88365 | 3859 goto invalid_code; |
3860 DECODE_COMPOSITION_END (); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3861 continue; |
17052 | 3862 |
3863 case '[': /* specification of direction */ | |
105179
8143cdf4806f
(decode_coding_iso_2022): Fix operator precedence.
Andreas Schwab <schwab@linux-m68k.org>
parents:
104636
diff
changeset
|
3864 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DIRECTION)) |
88365 | 3865 goto invalid_code; |
17052 | 3866 /* 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
|
3867 So, `coding->mode & CODING_MODE_DIRECTION' zero means |
88365 | 3868 left-to-right, and nozero means right-to-left. */ |
17052 | 3869 ONE_MORE_BYTE (c1); |
3870 switch (c1) | |
3871 { | |
3872 case ']': /* end of the current direction */ | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3873 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 3874 |
3875 case '0': /* end of the current direction */ | |
3876 case '1': /* start of left-to-right direction */ | |
3877 ONE_MORE_BYTE (c1); | |
3878 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3879 coding->mode &= ~CODING_MODE_DIRECTION; |
17052 | 3880 else |
88365 | 3881 goto invalid_code; |
17052 | 3882 break; |
3883 | |
3884 case '2': /* start of right-to-left direction */ | |
3885 ONE_MORE_BYTE (c1); | |
3886 if (c1 == ']') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3887 coding->mode |= CODING_MODE_DIRECTION; |
17052 | 3888 else |
88365 | 3889 goto invalid_code; |
17052 | 3890 break; |
3891 | |
3892 default: | |
88365 | 3893 goto invalid_code; |
17052 | 3894 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3895 continue; |
17052 | 3896 |
51311 | 3897 case '%': |
3898 ONE_MORE_BYTE (c1); | |
3899 if (c1 == '/') | |
3900 { | |
3901 /* CTEXT extended segment: | |
3902 ESC % / [0-4] M L --ENCODING-NAME-- \002 --BYTES-- | |
3903 We keep these bytes as is for the moment. | |
3904 They may be decoded by post-read-conversion. */ | |
3905 int dim, M, L; | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3906 int size; |
56191 | 3907 |
51311 | 3908 ONE_MORE_BYTE (dim); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3909 if (dim < 0 || dim > 4) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3910 goto invalid_code; |
51311 | 3911 ONE_MORE_BYTE (M); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3912 if (M < 128) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3913 goto invalid_code; |
51311 | 3914 ONE_MORE_BYTE (L); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3915 if (L < 128) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3916 goto invalid_code; |
51311 | 3917 size = ((M - 128) * 128) + (L - 128); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3918 if (charbuf + 6 > charbuf_end) |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3919 goto break_loop; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3920 *charbuf++ = ISO_CODE_ESC; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3921 *charbuf++ = '%'; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3922 *charbuf++ = '/'; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3923 *charbuf++ = dim; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3924 *charbuf++ = BYTE8_TO_CHAR (M); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3925 *charbuf++ = BYTE8_TO_CHAR (L); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3926 CODING_ISO_EXTSEGMENT_LEN (coding) = size; |
51311 | 3927 } |
3928 else if (c1 == 'G') | |
3929 { | |
3930 /* XFree86 extension for embedding UTF-8 in CTEXT: | |
3931 ESC % G --UTF-8-BYTES-- ESC % @ | |
3932 We keep these bytes as is for the moment. | |
3933 They may be decoded by post-read-conversion. */ | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3934 if (charbuf + 3 > charbuf_end) |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3935 goto break_loop; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3936 *charbuf++ = ISO_CODE_ESC; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3937 *charbuf++ = '%'; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3938 *charbuf++ = 'G'; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3939 CODING_ISO_EMBEDDED_UTF_8 (coding) = 1; |
51311 | 3940 } |
3941 else | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3942 goto invalid_code; |
51311 | 3943 continue; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
3944 break; |
51311 | 3945 |
17052 | 3946 default: |
88365 | 3947 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
3948 goto invalid_code; | |
89873
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3949 { |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3950 int reg, chars96; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3951 |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3952 if (c1 >= 0x28 && c1 <= 0x2B) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3953 { /* designation of DIMENSION1_CHARS94 character set */ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3954 reg = c1 - 0x28, chars96 = 0; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3955 ONE_MORE_BYTE (c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3956 } |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3957 else if (c1 >= 0x2C && c1 <= 0x2F) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3958 { /* designation of DIMENSION1_CHARS96 character set */ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3959 reg = c1 - 0x2C, chars96 = 1; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3960 ONE_MORE_BYTE (c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3961 } |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3962 else |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3963 goto invalid_code; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3964 DECODE_DESIGNATION (reg, 1, chars96, c1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3965 /* We must update these variables now. */ |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3966 if (reg == 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3967 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3968 else if (reg == 1) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3969 charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3970 if (chars96 < 0) |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3971 goto invalid_code; |
9a279ff9d245
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
Kenichi Handa <handa@m17n.org>
parents:
89863
diff
changeset
|
3972 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3973 continue; |
17052 | 3974 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3975 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3976 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3977 if (cmp_status->state == COMPOSING_NO |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
3978 && charset->id != charset_ascii |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3979 && last_id != charset->id) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3980 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3981 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
3982 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3983 last_id = charset->id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3984 last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3985 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3986 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3987 /* Now we know CHARSET and 1st position code C1 of a character. |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3988 Produce a decoded character while getting 2nd and 3rd |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3989 position codes C2, C3 if necessary. */ |
88365 | 3990 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
|
3991 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3992 ONE_MORE_BYTE (c2); |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3993 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0) |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3994 || ((c1 & 0x80) != (c2 & 0x80))) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3995 /* C2 is not in a valid range. */ |
88365 | 3996 goto invalid_code; |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3997 if (CHARSET_DIMENSION (charset) == 2) |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3998 c1 = (c1 << 8) | c2; |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
3999 else |
88365 | 4000 { |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
4001 ONE_MORE_BYTE (c3); |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
4002 if (c3 < 0x20 || (c3 >= 0x80 && c3 < 0xA0) |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
4003 || ((c1 & 0x80) != (c3 & 0x80))) |
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
4004 /* C3 is not in a valid range. */ |
88365 | 4005 goto invalid_code; |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
4006 c1 = (c1 << 16) | (c2 << 8) | c2; |
88365 | 4007 } |
17052 | 4008 } |
103474
7ead50363544
(decode_coding_iso_2022): Check MSB of bytes more rigidly.
Kenichi Handa <handa@m17n.org>
parents:
103448
diff
changeset
|
4009 c1 &= 0x7F7F7F; |
88365 | 4010 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); |
4011 if (c < 0) | |
4012 { | |
4013 MAYBE_FINISH_COMPOSITION (); | |
4014 for (; src_base < src; src_base++, char_offset++) | |
4015 { | |
4016 if (ASCII_BYTE_P (*src_base)) | |
4017 *charbuf++ = *src_base; | |
4018 else | |
4019 *charbuf++ = BYTE8_TO_CHAR (*src_base); | |
4020 } | |
4021 } | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4022 else if (cmp_status->state == COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4023 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4024 *charbuf++ = c; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4025 char_offset++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4026 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4027 else if ((cmp_status->state == COMPOSING_CHAR |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4028 ? cmp_status->nchars |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4029 : cmp_status->ncomps) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4030 >= MAX_COMPOSITION_COMPONENTS) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4031 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4032 /* Too long composition. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4033 MAYBE_FINISH_COMPOSITION (); |
88365 | 4034 *charbuf++ = c; |
4035 char_offset++; | |
4036 } | |
4037 else | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4038 STORE_COMPOSITION_CHAR (c); |
17052 | 4039 continue; |
4040 | |
88365 | 4041 invalid_code: |
4042 MAYBE_FINISH_COMPOSITION (); | |
4043 src = src_base; | |
4044 consumed_chars = consumed_chars_base; | |
4045 ONE_MORE_BYTE (c); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4046 *charbuf++ = c < 0 ? -c : ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4047 char_offset++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4048 coding->errors++; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
4049 continue; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
4050 |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
4051 break_loop: |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
4052 break; |
88365 | 4053 } |
4054 | |
4055 no_more_source: | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4056 if (cmp_status->state != COMPOSING_NO) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4057 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4058 if (coding->mode & CODING_MODE_LAST_BLOCK) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4059 MAYBE_FINISH_COMPOSITION (); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4060 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4061 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4062 charbuf -= cmp_status->length; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4063 for (i = 0; i < cmp_status->length; i++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4064 cmp_status->carryover[i] = charbuf[i]; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4065 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4066 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
4067 else if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4068 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
88365 | 4069 coding->consumed_char += consumed_chars_base; |
4070 coding->consumed = src_base - coding->source; | |
4071 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 4072 } |
4073 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4074 |
18766 | 4075 /* ISO2022 encoding stuff. */ |
17052 | 4076 |
4077 /* | |
18766 | 4078 It is not enough to say just "ISO2022" on encoding, we have to |
88365 | 4079 specify more details. In Emacs, each coding system of ISO2022 |
17052 | 4080 variant has the following specifications: |
88365 | 4081 1. Initial designation to G0 thru G3. |
17052 | 4082 2. Allows short-form designation? |
4083 3. ASCII should be designated to G0 before control characters? | |
4084 4. ASCII should be designated to G0 at end of line? | |
4085 5. 7-bit environment or 8-bit environment? | |
4086 6. Use locking-shift? | |
4087 7. Use Single-shift? | |
4088 And the following two are only for Japanese: | |
4089 8. Use ASCII in place of JIS0201-1976-Roman? | |
4090 9. Use JISX0208-1983 in place of JISX0208-1978? | |
88365 | 4091 These specifications are encoded in CODING_ISO_FLAGS (coding) as flag bits |
4092 defined by macros CODING_ISO_FLAG_XXX. See `coding.h' for more | |
18766 | 4093 details. |
17052 | 4094 */ |
4095 | |
4096 /* 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
|
4097 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
|
4098 '@', '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
|
4099 designation sequence of short-form. */ |
17052 | 4100 |
4101 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
4102 do { \ | |
88365 | 4103 unsigned char final_char = CHARSET_ISO_FINAL (charset); \ |
17052 | 4104 char *intermediate_char_94 = "()*+"; \ |
4105 char *intermediate_char_96 = ",-./"; \ | |
88365 | 4106 int revision = -1; \ |
4107 int c; \ | |
4108 \ | |
4109 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ | |
88856 | 4110 revision = CHARSET_ISO_REVISION (charset); \ |
88365 | 4111 \ |
4112 if (revision >= 0) \ | |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
4113 { \ |
88365 | 4114 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '&'); \ |
4115 EMIT_ONE_BYTE ('@' + revision); \ | |
17052 | 4116 } \ |
88365 | 4117 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ |
17052 | 4118 if (CHARSET_DIMENSION (charset) == 1) \ |
4119 { \ | |
88365 | 4120 if (! CHARSET_ISO_CHARS_96 (charset)) \ |
4121 c = intermediate_char_94[reg]; \ | |
17052 | 4122 else \ |
88365 | 4123 c = intermediate_char_96[reg]; \ |
4124 EMIT_ONE_ASCII_BYTE (c); \ | |
17052 | 4125 } \ |
4126 else \ | |
4127 { \ | |
88365 | 4128 EMIT_ONE_ASCII_BYTE ('$'); \ |
4129 if (! CHARSET_ISO_CHARS_96 (charset)) \ | |
17052 | 4130 { \ |
88365 | 4131 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
|
4132 || reg != 0 \ |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4133 || final_char < '@' || final_char > 'B') \ |
88365 | 4134 EMIT_ONE_ASCII_BYTE (intermediate_char_94[reg]); \ |
17052 | 4135 } \ |
4136 else \ | |
88365 | 4137 EMIT_ONE_ASCII_BYTE (intermediate_char_96[reg]); \ |
17052 | 4138 } \ |
88365 | 4139 EMIT_ONE_ASCII_BYTE (final_char); \ |
4140 \ | |
4141 CODING_ISO_DESIGNATION (coding, reg) = CHARSET_ID (charset); \ | |
17052 | 4142 } while (0) |
4143 | |
88365 | 4144 |
17052 | 4145 /* The following two macros produce codes (control character or escape |
4146 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
4147 single-shift-3). */ | |
4148 | |
88365 | 4149 #define ENCODE_SINGLE_SHIFT_2 \ |
4150 do { \ | |
4151 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
4152 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'N'); \ | |
4153 else \ | |
4154 EMIT_ONE_BYTE (ISO_CODE_SS2); \ | |
4155 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 4156 } while (0) |
4157 | |
88365 | 4158 |
4159 #define ENCODE_SINGLE_SHIFT_3 \ | |
4160 do { \ | |
4161 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
4162 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'O'); \ | |
4163 else \ | |
4164 EMIT_ONE_BYTE (ISO_CODE_SS3); \ | |
4165 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
17052 | 4166 } while (0) |
4167 | |
88365 | 4168 |
17052 | 4169 /* The following four macros produce codes (control character or |
4170 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
4171 shift-out, locking-shift-2, and locking-shift-3). */ | |
4172 | |
88365 | 4173 #define ENCODE_SHIFT_IN \ |
4174 do { \ | |
4175 EMIT_ONE_ASCII_BYTE (ISO_CODE_SI); \ | |
4176 CODING_ISO_INVOCATION (coding, 0) = 0; \ | |
17052 | 4177 } while (0) |
4178 | |
88365 | 4179 |
4180 #define ENCODE_SHIFT_OUT \ | |
4181 do { \ | |
4182 EMIT_ONE_ASCII_BYTE (ISO_CODE_SO); \ | |
4183 CODING_ISO_INVOCATION (coding, 0) = 1; \ | |
17052 | 4184 } while (0) |
4185 | |
88365 | 4186 |
4187 #define ENCODE_LOCKING_SHIFT_2 \ | |
4188 do { \ | |
4189 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
4190 CODING_ISO_INVOCATION (coding, 0) = 2; \ | |
17052 | 4191 } while (0) |
4192 | |
88365 | 4193 |
4194 #define ENCODE_LOCKING_SHIFT_3 \ | |
4195 do { \ | |
4196 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
4197 CODING_ISO_INVOCATION (coding, 0) = 3; \ | |
17052 | 4198 } while (0) |
4199 | |
88365 | 4200 |
18766 | 4201 /* Produce codes for a DIMENSION1 character whose character set is |
4202 CHARSET and whose position-code is C1. Designation and invocation | |
17052 | 4203 sequences are also produced in advance if necessary. */ |
4204 | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4205 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4206 do { \ |
88365 | 4207 int id = CHARSET_ID (charset); \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4208 \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4209 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
|
4210 && id == charset_ascii) \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4211 { \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4212 id = charset_jisx0201_roman; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4213 charset = CHARSET_FROM_ID (id); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4214 } \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4215 \ |
88365 | 4216 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4217 { \ |
88365 | 4218 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ |
4219 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4220 else \ |
88365 | 4221 EMIT_ONE_BYTE (c1 | 0x80); \ |
4222 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4223 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4224 } \ |
88365 | 4225 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
|
4226 { \ |
88365 | 4227 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4228 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4229 } \ |
88365 | 4230 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
|
4231 { \ |
88365 | 4232 EMIT_ONE_BYTE (c1 | 0x80); \ |
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4233 break; \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4234 } \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4235 else \ |
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
4236 /* 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
|
4237 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
|
4238 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
|
4239 character. */ \ |
88365 | 4240 dst = encode_invocation_designation (charset, coding, dst, \ |
4241 &produced_chars); \ | |
17052 | 4242 } while (1) |
4243 | |
88365 | 4244 |
4245 /* Produce codes for a DIMENSION2 character whose character set is | |
4246 CHARSET and whose position-codes are C1 and C2. Designation and | |
4247 invocation codes are also produced in advance if necessary. */ | |
4248 | |
4249 #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
|
4250 do { \ |
88365 | 4251 int id = CHARSET_ID (charset); \ |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4252 \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4253 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
|
4254 && id == charset_jisx0208) \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4255 { \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4256 id = charset_jisx0208_1978; \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4257 charset = CHARSET_FROM_ID (id); \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4258 } \ |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4259 \ |
88365 | 4260 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
4261 { \ | |
4262 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
4263 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
4264 else \ | |
4265 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
4266 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
4267 break; \ | |
4268 } \ | |
4269 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ | |
4270 { \ | |
4271 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
4272 break; \ | |
4273 } \ | |
4274 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ | |
4275 { \ | |
4276 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
4277 break; \ | |
4278 } \ | |
4279 else \ | |
4280 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
4281 must invoke it, or, at first, designate it to some graphic \ | |
4282 register. Then repeat the loop to actually produce the \ | |
4283 character. */ \ | |
4284 dst = encode_invocation_designation (charset, coding, dst, \ | |
4285 &produced_chars); \ | |
4286 } while (1) | |
4287 | |
4288 | |
4289 #define ENCODE_ISO_CHARACTER(charset, c) \ | |
4290 do { \ | |
4291 int code = ENCODE_CHAR ((charset),(c)); \ | |
4292 \ | |
4293 if (CHARSET_DIMENSION (charset) == 1) \ | |
4294 ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ | |
4295 else \ | |
4296 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
|
4297 } while (0) |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4298 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
4299 |
17052 | 4300 /* Produce designation and invocation codes at a place pointed by DST |
88365 | 4301 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. |
17052 | 4302 Return new DST. */ |
4303 | |
4304 unsigned char * | |
88365 | 4305 encode_invocation_designation (charset, coding, dst, p_nchars) |
4306 struct charset *charset; | |
17052 | 4307 struct coding_system *coding; |
4308 unsigned char *dst; | |
88365 | 4309 int *p_nchars; |
17052 | 4310 { |
88365 | 4311 int multibytep = coding->dst_multibyte; |
4312 int produced_chars = *p_nchars; | |
17052 | 4313 int reg; /* graphic register number */ |
88365 | 4314 int id = CHARSET_ID (charset); |
17052 | 4315 |
4316 /* At first, check designations. */ | |
4317 for (reg = 0; reg < 4; reg++) | |
88365 | 4318 if (id == CODING_ISO_DESIGNATION (coding, reg)) |
17052 | 4319 break; |
4320 | |
4321 if (reg >= 4) | |
4322 { | |
4323 /* CHARSET is not yet designated to any graphic registers. */ | |
4324 /* At first check the requested designation. */ | |
88365 | 4325 reg = CODING_ISO_REQUEST (coding, id); |
4326 if (reg < 0) | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
4327 /* Since CHARSET requests no special designation, designate it |
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
4328 to graphic register 0. */ |
17052 | 4329 reg = 0; |
4330 | |
4331 ENCODE_DESIGNATION (charset, reg, coding); | |
4332 } | |
4333 | |
88365 | 4334 if (CODING_ISO_INVOCATION (coding, 0) != reg |
4335 && CODING_ISO_INVOCATION (coding, 1) != reg) | |
17052 | 4336 { |
4337 /* Since the graphic register REG is not invoked to any graphic | |
4338 planes, invoke it to graphic plane 0. */ | |
4339 switch (reg) | |
4340 { | |
4341 case 0: /* graphic register 0 */ | |
4342 ENCODE_SHIFT_IN; | |
4343 break; | |
4344 | |
4345 case 1: /* graphic register 1 */ | |
4346 ENCODE_SHIFT_OUT; | |
4347 break; | |
4348 | |
4349 case 2: /* graphic register 2 */ | |
88365 | 4350 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 4351 ENCODE_SINGLE_SHIFT_2; |
4352 else | |
4353 ENCODE_LOCKING_SHIFT_2; | |
4354 break; | |
4355 | |
4356 case 3: /* graphic register 3 */ | |
88365 | 4357 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
17052 | 4358 ENCODE_SINGLE_SHIFT_3; |
4359 else | |
4360 ENCODE_LOCKING_SHIFT_3; | |
4361 break; | |
4362 } | |
4363 } | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4364 |
88365 | 4365 *p_nchars = produced_chars; |
17052 | 4366 return dst; |
4367 } | |
4368 | |
4369 /* The following three macros produce codes for indicating direction | |
4370 of text. */ | |
88365 | 4371 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ |
4372 do { \ | |
4373 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \ | |
4374 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \ | |
4375 else \ | |
4376 EMIT_ONE_BYTE (ISO_CODE_CSI); \ | |
17052 | 4377 } while (0) |
4378 | |
88365 | 4379 |
4380 #define ENCODE_DIRECTION_R2L() \ | |
4381 do { \ | |
4382 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
4383 EMIT_TWO_ASCII_BYTES ('2', ']'); \ | |
4384 } while (0) | |
4385 | |
4386 | |
4387 #define ENCODE_DIRECTION_L2R() \ | |
4388 do { \ | |
4389 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
4390 EMIT_TWO_ASCII_BYTES ('0', ']'); \ | |
4391 } while (0) | |
4392 | |
17052 | 4393 |
4394 /* Produce codes for designation and invocation to reset the graphic | |
4395 planes and registers to initial state. */ | |
88365 | 4396 #define ENCODE_RESET_PLANE_AND_REGISTER() \ |
4397 do { \ | |
4398 int reg; \ | |
4399 struct charset *charset; \ | |
4400 \ | |
4401 if (CODING_ISO_INVOCATION (coding, 0) != 0) \ | |
4402 ENCODE_SHIFT_IN; \ | |
4403 for (reg = 0; reg < 4; reg++) \ | |
4404 if (CODING_ISO_INITIAL (coding, reg) >= 0 \ | |
4405 && (CODING_ISO_DESIGNATION (coding, reg) \ | |
4406 != CODING_ISO_INITIAL (coding, reg))) \ | |
4407 { \ | |
4408 charset = CHARSET_FROM_ID (CODING_ISO_INITIAL (coding, reg)); \ | |
4409 ENCODE_DESIGNATION (charset, reg, coding); \ | |
4410 } \ | |
17052 | 4411 } while (0) |
4412 | |
88365 | 4413 |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4414 /* 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
|
4415 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
|
4416 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4417 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
|
4418 find all the necessary designations. */ |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4419 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4420 static unsigned char * |
88365 | 4421 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
|
4422 struct coding_system *coding; |
88365 | 4423 int *charbuf, *charbuf_end; |
59168
0345f2b10f1d
(decode_coding_XXX, decode_composition_emacs_mule)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
59095
diff
changeset
|
4424 unsigned char *dst; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4425 { |
88365 | 4426 struct charset *charset; |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4427 /* 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
|
4428 int r[4]; |
88365 | 4429 int c, found = 0, reg; |
4430 int produced_chars = 0; | |
4431 int multibytep = coding->dst_multibyte; | |
4432 Lisp_Object attrs; | |
4433 Lisp_Object charset_list; | |
4434 | |
4435 attrs = CODING_ID_ATTRS (coding->id); | |
4436 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
4437 if (EQ (charset_list, Qiso_2022)) | |
4438 charset_list = Viso_2022_charset_list; | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4439 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4440 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4441 r[reg] = -1; |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4442 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4443 while (found < 4) |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4444 { |
88365 | 4445 int id; |
4446 | |
4447 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4448 if (c == '\n') |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4449 break; |
88365 | 4450 charset = char_charset (c, charset_list, NULL); |
4451 id = CHARSET_ID (charset); | |
4452 reg = CODING_ISO_REQUEST (coding, id); | |
4453 if (reg >= 0 && r[reg] < 0) | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4454 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4455 found++; |
88365 | 4456 r[reg] = id; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4457 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4458 } |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4459 |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4460 if (found) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4461 { |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4462 for (reg = 0; reg < 4; reg++) |
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4463 if (r[reg] >= 0 |
88365 | 4464 && CODING_ISO_DESIGNATION (coding, reg) != r[reg]) |
4465 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
|
4466 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4467 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4468 return dst; |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4469 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4470 |
17052 | 4471 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
4472 | |
88365 | 4473 static int |
4474 encode_coding_iso_2022 (coding) | |
17052 | 4475 struct coding_system *coding; |
4476 { | |
88365 | 4477 int multibytep = coding->dst_multibyte; |
4478 int *charbuf = coding->charbuf; | |
4479 int *charbuf_end = charbuf + coding->charbuf_used; | |
4480 unsigned char *dst = coding->destination + coding->produced; | |
4481 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
4482 int safe_room = 16; | |
4483 int bol_designation | |
4484 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL | |
4485 && CODING_ISO_BOL (coding)); | |
4486 int produced_chars = 0; | |
4487 Lisp_Object attrs, eol_type, charset_list; | |
4488 int ascii_compatible; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4489 int c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4490 int preferred_charset_id = -1; |
88365 | 4491 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4492 CODING_GET_INFO (coding, attrs, charset_list); |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
4493 eol_type = inhibit_eol_conversion ? Qunix : CODING_ID_EOL_TYPE (coding->id); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4494 if (VECTORP (eol_type)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4495 eol_type = Qunix; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4496 |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
4497 setup_iso_safe_charsets (attrs); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4498 /* Charset list may have been changed. */ |
90772
b15334b4a9c3
(coding_alloc_by_making_gap): New arg offset.
Kenichi Handa <handa@m17n.org>
parents:
90737
diff
changeset
|
4499 charset_list = CODING_ATTR_CHARSET_LIST (attrs); |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
4500 coding->safe_charsets = SDATA (CODING_ATTR_SAFE_CHARSETS (attrs)); |
88365 | 4501 |
4502 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
4503 | |
4504 while (charbuf < charbuf_end) | |
4505 { | |
4506 ASSURE_DESTINATION (safe_room); | |
4507 | |
4508 if (bol_designation) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4509 { |
88365 | 4510 unsigned char *dst_prev = dst; |
4511 | |
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
4512 /* We have to produce designation sequences if any now. */ |
88365 | 4513 dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); |
4514 bol_designation = 0; | |
4515 /* We are sure that designation sequences are all ASCII bytes. */ | |
4516 produced_chars += dst - dst_prev; | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4517 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4518 |
88365 | 4519 c = *charbuf++; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4520 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4521 if (c < 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4522 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4523 /* Handle an annotation. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4524 switch (*charbuf) |
17052 | 4525 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4526 case CODING_ANNOTATE_COMPOSITION_MASK: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4527 /* Not yet implemented. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4528 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4529 case CODING_ANNOTATE_CHARSET_MASK: |
90014
ade0c9a12f99
(encode_coding_iso_2022): Fix handling of charset
Kenichi Handa <handa@m17n.org>
parents:
90011
diff
changeset
|
4530 preferred_charset_id = charbuf[2]; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4531 if (preferred_charset_id >= 0 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4532 && NILP (Fmemq (make_number (preferred_charset_id), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4533 charset_list))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4534 preferred_charset_id = -1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4535 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4536 default: |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4537 abort (); |
26847 | 4538 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4539 charbuf += -c - 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4540 continue; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4541 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4542 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4543 /* 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
|
4544 if (c < 0x20 || c == 0x7F) |
17052 | 4545 { |
88365 | 4546 if (c == '\n' |
4547 || (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
|
4548 { |
88365 | 4549 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) |
4550 ENCODE_RESET_PLANE_AND_REGISTER (); | |
4551 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_INIT_AT_BOL) | |
4552 { | |
4553 int i; | |
4554 | |
4555 for (i = 0; i < 4; i++) | |
4556 CODING_ISO_DESIGNATION (coding, i) | |
4557 = CODING_ISO_INITIAL (coding, i); | |
4558 } | |
4559 bol_designation | |
4560 = 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
|
4561 } |
88365 | 4562 else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) |
4563 ENCODE_RESET_PLANE_AND_REGISTER (); | |
4564 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
|
4565 } |
88365 | 4566 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
|
4567 { |
88365 | 4568 if (ascii_compatible) |
4569 EMIT_ONE_ASCII_BYTE (c); | |
4570 else | |
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4571 { |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4572 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
|
4573 ENCODE_ISO_CHARACTER (charset, c); |
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
4574 } |
17052 | 4575 } |
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4576 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
|
4577 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4578 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
|
4579 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
|
4580 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4581 else |
88365 | 4582 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4583 struct charset *charset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4584 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4585 if (preferred_charset_id >= 0) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4586 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4587 charset = CHARSET_FROM_ID (preferred_charset_id); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4588 if (! CHAR_CHARSET_P (c, charset)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4589 charset = char_charset (c, charset_list, NULL); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4590 } |
42104
d69c2368e549
(DECODE_COMPOSITION_END): Fixed a typo in the last
Sam Steingold <sds@gnu.org>
parents:
42103
diff
changeset
|
4591 else |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4592 charset = char_charset (c, charset_list, NULL); |
88365 | 4593 if (!charset) |
17052 | 4594 { |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4595 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
|
4596 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4597 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4598 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4599 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4600 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4601 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4602 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4603 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
|
4604 } |
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
4605 } |
88365 | 4606 ENCODE_ISO_CHARACTER (charset, c); |
4607 } | |
4608 } | |
4609 | |
4610 if (coding->mode & CODING_MODE_LAST_BLOCK | |
4611 && CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) | |
4612 { | |
4613 ASSURE_DESTINATION (safe_room); | |
4614 ENCODE_RESET_PLANE_AND_REGISTER (); | |
4615 } | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4616 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 4617 CODING_ISO_BOL (coding) = bol_designation; |
4618 coding->produced_char += produced_chars; | |
4619 coding->produced = dst - coding->destination; | |
4620 return 0; | |
17052 | 4621 } |
4622 | |
4623 | |
88365 | 4624 /*** 8,9. SJIS and BIG5 handlers ***/ |
4625 | |
4626 /* Although SJIS and BIG5 are not ISO's coding system, they are used | |
17052 | 4627 quite widely. So, for the moment, Emacs supports them in the bare |
4628 C code. But, in the future, they may be supported only by CCL. */ | |
4629 | |
4630 /* SJIS is a coding system encoding three character sets: ASCII, right | |
4631 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
4632 as is. A character of charset katakana-jisx0201 is encoded by | |
4633 "position-code + 0x80". A character of charset japanese-jisx0208 | |
4634 is encoded in 2-byte but two position-codes are divided and shifted | |
88365 | 4635 so that it fit in the range below. |
17052 | 4636 |
4637 --- CODE RANGE of SJIS --- | |
4638 (character set) (range) | |
4639 ASCII 0x00 .. 0x7F | |
88365 | 4640 KATAKANA-JISX0201 0xA0 .. 0xDF |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
4641 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
|
4642 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC |
17052 | 4643 ------------------------------- |
4644 | |
4645 */ | |
4646 | |
4647 /* BIG5 is a coding system encoding two character sets: ASCII and | |
4648 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
88365 | 4649 character set and is encoded in two-byte. |
17052 | 4650 |
4651 --- CODE RANGE of BIG5 --- | |
4652 (character set) (range) | |
4653 ASCII 0x00 .. 0x7F | |
4654 Big5 (1st byte) 0xA1 .. 0xFE | |
4655 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
4656 -------------------------- | |
4657 | |
88365 | 4658 */ |
17052 | 4659 |
4660 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
4661 Check if a text is encoded in SJIS. If it is, return | |
88365 | 4662 CATEGORY_MASK_SJIS, else return 0. */ |
17052 | 4663 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
4664 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4665 detect_coding_sjis (coding, detect_info) |
88365 | 4666 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4667 struct coding_detection_info *detect_info; |
17052 | 4668 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4669 const unsigned char *src = coding->source, *src_base; |
89483 | 4670 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 4671 int multibytep = coding->src_multibyte; |
4672 int consumed_chars = 0; | |
4673 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4674 int c; |
103762
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4675 Lisp_Object attrs, charset_list; |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4676 int max_first_byte_of_2_byte_code; |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4677 |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4678 CODING_GET_INFO (coding, attrs, charset_list); |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4679 max_first_byte_of_2_byte_code |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4680 = (XINT (Flength (charset_list)) > 3 ? 0xFC : 0xEF); |
88365 | 4681 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4682 detect_info->checked |= CATEGORY_MASK_SJIS; |
88365 | 4683 /* A coding system of this category is always ASCII compatible. */ |
4684 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
|
4685 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4686 while (1) |
17052 | 4687 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4688 src_base = src; |
88365 | 4689 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
4690 if (c < 0x80) |
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
4691 continue; |
103762
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4692 if ((c >= 0x81 && c <= 0x9F) |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
4693 || (c >= 0xE0 && c <= max_first_byte_of_2_byte_code)) |
17052 | 4694 { |
88365 | 4695 ONE_MORE_BYTE (c); |
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
4696 if (c < 0x40 || c == 0x7F || c > 0xFC) |
88365 | 4697 break; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4698 found = CATEGORY_MASK_SJIS; |
17052 | 4699 } |
88365 | 4700 else if (c >= 0xA0 && c < 0xE0) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4701 found = CATEGORY_MASK_SJIS; |
88365 | 4702 else |
4703 break; | |
4704 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4705 detect_info->rejected |= CATEGORY_MASK_SJIS; |
88365 | 4706 return 0; |
4707 | |
4708 no_more_source: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4709 if (src_base < src && coding->mode & CODING_MODE_LAST_BLOCK) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4710 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4711 detect_info->rejected |= CATEGORY_MASK_SJIS; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4712 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4713 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4714 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4715 return 1; |
17052 | 4716 } |
4717 | |
4718 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
4719 Check if a text is encoded in BIG5. If it is, return | |
88365 | 4720 CATEGORY_MASK_BIG5, else return 0. */ |
17052 | 4721 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
4722 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4723 detect_coding_big5 (coding, detect_info) |
88365 | 4724 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4725 struct coding_detection_info *detect_info; |
17052 | 4726 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4727 const unsigned char *src = coding->source, *src_base; |
89483 | 4728 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 4729 int multibytep = coding->src_multibyte; |
4730 int consumed_chars = 0; | |
4731 int found = 0; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4732 int c; |
88365 | 4733 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4734 detect_info->checked |= CATEGORY_MASK_BIG5; |
88365 | 4735 /* A coding system of this category is always ASCII compatible. */ |
4736 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
|
4737 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4738 while (1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4739 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4740 src_base = src; |
88365 | 4741 ONE_MORE_BYTE (c); |
4742 if (c < 0x80) | |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4743 continue; |
88365 | 4744 if (c >= 0xA1) |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4745 { |
88365 | 4746 ONE_MORE_BYTE (c); |
4747 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
|
4748 return 0; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4749 found = CATEGORY_MASK_BIG5; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4750 } |
88365 | 4751 else |
4752 break; | |
4753 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4754 detect_info->rejected |= CATEGORY_MASK_BIG5; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4755 return 0; |
88365 | 4756 |
4757 no_more_source: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4758 if (src_base < src && coding->mode & CODING_MODE_LAST_BLOCK) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4759 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4760 detect_info->rejected |= CATEGORY_MASK_BIG5; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4761 return 0; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4762 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4763 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4764 return 1; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4765 } |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
4766 |
17052 | 4767 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". |
4768 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
4769 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4770 static void |
88365 | 4771 decode_coding_sjis (coding) |
17052 | 4772 struct coding_system *coding; |
4773 { | |
89483 | 4774 const unsigned char *src = coding->source + coding->consumed; |
4775 const unsigned char *src_end = coding->source + coding->src_bytes; | |
59168
0345f2b10f1d
(decode_coding_XXX, decode_composition_emacs_mule)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
59095
diff
changeset
|
4776 const unsigned char *src_base; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4777 int *charbuf = coding->charbuf + coding->charbuf_used; |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
4778 /* We may produce one charset annocation in one loop and one more at |
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
4779 the end. */ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4780 int *charbuf_end |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
4781 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); |
88365 | 4782 int consumed_chars = 0, consumed_chars_base; |
4783 int multibytep = coding->src_multibyte; | |
4784 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4785 struct charset *charset_kanji2; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4786 Lisp_Object attrs, charset_list, val; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4787 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4788 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4789 int last_id = charset_ascii; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
4790 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
4791 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4792 int byte_after_cr = -1; |
88365 | 4793 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4794 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 4795 |
4796 val = charset_list; | |
4797 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
4798 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4799 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4800 charset_kanji2 = NILP (val) ? NULL : CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 4801 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4802 while (1) |
17052 | 4803 { |
88365 | 4804 int c, c1; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4805 struct charset *charset; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4806 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4807 src_base = src; |
88365 | 4808 consumed_chars_base = consumed_chars; |
4809 | |
4810 if (charbuf >= charbuf_end) | |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4811 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4812 if (byte_after_cr >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4813 src_base--; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4814 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4815 } |
88365 | 4816 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4817 if (byte_after_cr >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4818 c = byte_after_cr, byte_after_cr = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4819 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4820 ONE_MORE_BYTE (c); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4821 if (c < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4822 goto invalid_code; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4823 if (c < 0x80) |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4824 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4825 if (eol_crlf && c == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4826 ONE_MORE_BYTE (byte_after_cr); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4827 charset = charset_roman; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4828 } |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4829 else if (c == 0x80 || c == 0xA0) |
89730
d8fcefca5cf6
(decode_coding_sjis): Check the first byte rigidly.
Kenichi Handa <handa@m17n.org>
parents:
89686
diff
changeset
|
4830 goto invalid_code; |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4831 else if (c >= 0xA1 && c <= 0xDF) |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4832 { |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4833 /* SJIS -> JISX0201-Kana */ |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4834 c &= 0x7F; |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4835 charset = charset_kana; |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4836 } |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4837 else if (c <= 0xEF) |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4838 { |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4839 /* SJIS -> JISX0208 */ |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4840 ONE_MORE_BYTE (c1); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4841 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4842 goto invalid_code; |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4843 c = (c << 8) | c1; |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4844 SJIS_TO_JIS (c); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4845 charset = charset_kanji; |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4846 } |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4847 else if (c <= 0xFC && charset_kanji2) |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4848 { |
89779
74c503490829
(decode_coding_sjis): Fix comment.
Kenichi Handa <handa@m17n.org>
parents:
89764
diff
changeset
|
4849 /* SJIS -> JISX0213-2 */ |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4850 ONE_MORE_BYTE (c1); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4851 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4852 goto invalid_code; |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4853 c = (c << 8) | c1; |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4854 SJIS_TO_JIS2 (c); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4855 charset = charset_kanji2; |
17052 | 4856 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4857 else |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
4858 goto invalid_code; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4859 if (charset->id != charset_ascii |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4860 && last_id != charset->id) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4861 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4862 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4863 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4864 last_id = charset->id; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4865 last_offset = char_offset; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4866 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4867 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
88365 | 4868 *charbuf++ = c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4869 char_offset++; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4870 continue; |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4871 |
88365 | 4872 invalid_code: |
17052 | 4873 src = src_base; |
88365 | 4874 consumed_chars = consumed_chars_base; |
4875 ONE_MORE_BYTE (c); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4876 *charbuf++ = c < 0 ? -c : BYTE8_TO_CHAR (c); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4877 char_offset++; |
88365 | 4878 coding->errors++; |
4879 } | |
4880 | |
4881 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4882 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4883 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
88365 | 4884 coding->consumed_char += consumed_chars_base; |
4885 coding->consumed = src_base - coding->source; | |
4886 coding->charbuf_used = charbuf - coding->charbuf; | |
4887 } | |
4888 | |
4889 static void | |
4890 decode_coding_big5 (coding) | |
4891 struct coding_system *coding; | |
4892 { | |
89483 | 4893 const unsigned char *src = coding->source + coding->consumed; |
4894 const unsigned char *src_end = coding->source + coding->src_bytes; | |
4895 const unsigned char *src_base; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4896 int *charbuf = coding->charbuf + coding->charbuf_used; |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
4897 /* We may produce one charset annocation in one loop and one more at |
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
4898 the end. */ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4899 int *charbuf_end |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
4900 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); |
88365 | 4901 int consumed_chars = 0, consumed_chars_base; |
4902 int multibytep = coding->src_multibyte; | |
4903 struct charset *charset_roman, *charset_big5; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4904 Lisp_Object attrs, charset_list, val; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4905 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4906 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4907 int last_id = charset_ascii; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
4908 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
4909 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4910 int byte_after_cr = -1; |
88365 | 4911 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4912 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 4913 val = charset_list; |
4914 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
4915 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
4916 | |
4917 while (1) | |
4918 { | |
4919 int c, c1; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4920 struct charset *charset; |
88365 | 4921 |
4922 src_base = src; | |
4923 consumed_chars_base = consumed_chars; | |
4924 | |
4925 if (charbuf >= charbuf_end) | |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4926 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4927 if (byte_after_cr >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4928 src_base--; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4929 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
4930 } |
88365 | 4931 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4932 if (byte_after_cr >= 0) |
92406
c36bda0a03cc
(decode_coding_big5, produce_chars): Fix typos in last
Andreas Schwab <schwab@suse.de>
parents:
92399
diff
changeset
|
4933 c = byte_after_cr, byte_after_cr = -1; |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4934 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4935 ONE_MORE_BYTE (c); |
88365 | 4936 |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4937 if (c < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4938 goto invalid_code; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4939 if (c < 0x80) |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4940 { |
92406
c36bda0a03cc
(decode_coding_big5, produce_chars): Fix typos in last
Andreas Schwab <schwab@suse.de>
parents:
92399
diff
changeset
|
4941 if (eol_crlf && c == '\r') |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4942 ONE_MORE_BYTE (byte_after_cr); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4943 charset = charset_roman; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
4944 } |
88365 | 4945 else |
4946 { | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4947 /* BIG5 -> Big5 */ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4948 if (c < 0xA1 || c > 0xFE) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4949 goto invalid_code; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4950 ONE_MORE_BYTE (c1); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4951 if (c1 < 0x40 || (c1 > 0x7E && c1 < 0xA1) || c1 > 0xFE) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4952 goto invalid_code; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4953 c = c << 8 | c1; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4954 charset = charset_big5; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4955 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4956 if (charset->id != charset_ascii |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4957 && last_id != charset->id) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4958 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4959 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4960 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4961 last_id = charset->id; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4962 last_offset = char_offset; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4963 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
4964 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
88365 | 4965 *charbuf++ = c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4966 char_offset++; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4967 continue; |
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4968 |
88365 | 4969 invalid_code: |
17052 | 4970 src = src_base; |
88365 | 4971 consumed_chars = consumed_chars_base; |
4972 ONE_MORE_BYTE (c); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
4973 *charbuf++ = c < 0 ? -c : BYTE8_TO_CHAR (c); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4974 char_offset++; |
88365 | 4975 coding->errors++; |
4976 } | |
4977 | |
4978 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4979 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
4980 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
88365 | 4981 coding->consumed_char += consumed_chars_base; |
4982 coding->consumed = src_base - coding->source; | |
4983 coding->charbuf_used = charbuf - coding->charbuf; | |
17052 | 4984 } |
4985 | |
4986 /* 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
|
4987 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
|
4988 `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
|
4989 are sure that all these charsets are registered as official charset |
17052 | 4990 (i.e. do not have extended leading-codes). Characters of other |
4991 charsets are produced without any encoding. If SJIS_P is 1, encode | |
4992 SJIS text, else encode BIG5 text. */ | |
4993 | |
88365 | 4994 static int |
4995 encode_coding_sjis (coding) | |
17052 | 4996 struct coding_system *coding; |
4997 { | |
88365 | 4998 int multibytep = coding->dst_multibyte; |
4999 int *charbuf = coding->charbuf; | |
5000 int *charbuf_end = charbuf + coding->charbuf_used; | |
5001 unsigned char *dst = coding->destination + coding->produced; | |
5002 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5003 int safe_room = 4; | |
5004 int produced_chars = 0; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5005 Lisp_Object attrs, charset_list, val; |
88365 | 5006 int ascii_compatible; |
5007 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5008 struct charset *charset_kanji2; |
88365 | 5009 int c; |
5010 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5011 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 5012 val = charset_list; |
5013 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
5014 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5015 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5016 charset_kanji2 = NILP (val) ? NULL : CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 5017 |
5018 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
5019 | |
5020 while (charbuf < charbuf_end) | |
5021 { | |
5022 ASSURE_DESTINATION (safe_room); | |
5023 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5024 /* Now encode the character C. */ |
88365 | 5025 if (ASCII_CHAR_P (c) && ascii_compatible) |
5026 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
|
5027 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
|
5028 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
5029 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
|
5030 EMIT_ONE_BYTE (c); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5031 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5032 else |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5033 { |
88365 | 5034 unsigned code; |
5035 struct charset *charset = char_charset (c, charset_list, &code); | |
5036 | |
5037 if (!charset) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5038 { |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5039 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
|
5040 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5041 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5042 charset = CHARSET_FROM_ID (charset_ascii); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5043 } |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5044 else |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5045 { |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5046 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5047 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
|
5048 } |
88365 | 5049 } |
5050 if (code == CHARSET_INVALID_CODE (charset)) | |
5051 abort (); | |
5052 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
|
5053 { |
88365 | 5054 int c1, c2; |
5055 JIS_TO_SJIS (code); | |
5056 c1 = code >> 8, c2 = code & 0xFF; | |
5057 EMIT_TWO_BYTES (c1, c2); | |
5058 } | |
5059 else if (charset == charset_kana) | |
5060 EMIT_ONE_BYTE (code | 0x80); | |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5061 else if (charset_kanji2 && charset == charset_kanji2) |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5062 { |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5063 int c1, c2; |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5064 |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5065 c1 = code >> 8; |
103762
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
5066 if (c1 == 0x21 || (c1 >= 0x23 && c1 <= 0x25) |
e72df94a89ca
(detect_coding_sjis): Handle shift_jis-2004 correctly.
Kenichi Handa <handa@m17n.org>
parents:
103655
diff
changeset
|
5067 || c1 == 0x28 |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5068 || (c1 >= 0x2C && c1 <= 0x2F) || c1 >= 0x6E) |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5069 { |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5070 JIS_TO_SJIS2 (code); |
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5071 c1 = code >> 8, c2 = code & 0xFF; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5072 EMIT_TWO_BYTES (c1, c2); |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5073 } |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5074 else |
89764
e3d26232ab78
(decode_coding_sjis): Handle 4th charset (typically JISX0212).
Kenichi Handa <handa@m17n.org>
parents:
89759
diff
changeset
|
5075 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5076 } |
17052 | 5077 else |
88365 | 5078 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
5079 } | |
5080 } | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5081 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 5082 coding->produced_char += produced_chars; |
5083 coding->produced = dst - coding->destination; | |
5084 return 0; | |
5085 } | |
5086 | |
5087 static int | |
5088 encode_coding_big5 (coding) | |
5089 struct coding_system *coding; | |
5090 { | |
5091 int multibytep = coding->dst_multibyte; | |
5092 int *charbuf = coding->charbuf; | |
5093 int *charbuf_end = charbuf + coding->charbuf_used; | |
5094 unsigned char *dst = coding->destination + coding->produced; | |
5095 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5096 int safe_room = 4; | |
5097 int produced_chars = 0; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5098 Lisp_Object attrs, charset_list, val; |
88365 | 5099 int ascii_compatible; |
5100 struct charset *charset_roman, *charset_big5; | |
5101 int c; | |
5102 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5103 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 5104 val = charset_list; |
5105 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
5106 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
5107 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
5108 | |
5109 while (charbuf < charbuf_end) | |
5110 { | |
5111 ASSURE_DESTINATION (safe_room); | |
5112 c = *charbuf++; | |
5113 /* Now encode the character C. */ | |
5114 if (ASCII_CHAR_P (c) && ascii_compatible) | |
5115 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
|
5116 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
|
5117 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
5118 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
|
5119 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
|
5120 } |
88365 | 5121 else |
5122 { | |
5123 unsigned code; | |
5124 struct charset *charset = char_charset (c, charset_list, &code); | |
5125 | |
5126 if (! charset) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5127 { |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5128 if (coding->mode & CODING_MODE_SAFE_ENCODING) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5129 { |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5130 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5131 charset = CHARSET_FROM_ID (charset_ascii); |
51140
94d903190cee
(ENCODE_UNSAFE_CHARACTER): Adjusted for the name change
Kenichi Handa <handa@m17n.org>
parents:
51090
diff
changeset
|
5132 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5133 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5134 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5135 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5136 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
|
5137 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5138 } |
88365 | 5139 if (code == CHARSET_INVALID_CODE (charset)) |
5140 abort (); | |
5141 if (charset == charset_big5) | |
5142 { | |
5143 int c1, c2; | |
5144 | |
5145 c1 = code >> 8, c2 = code & 0xFF; | |
5146 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
|
5147 } |
17052 | 5148 else |
88365 | 5149 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
17052 | 5150 } |
88365 | 5151 } |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5152 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 5153 coding->produced_char += produced_chars; |
5154 coding->produced = dst - coding->destination; | |
5155 return 0; | |
17052 | 5156 } |
5157 | |
5158 | |
88365 | 5159 /*** 10. CCL handlers ***/ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5160 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5161 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5162 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
|
5163 encoder/decoder are written in CCL program. If it is, return |
88365 | 5164 CATEGORY_MASK_CCL, else return 0. */ |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5165 |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
5166 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5167 detect_coding_ccl (coding, detect_info) |
88365 | 5168 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5169 struct coding_detection_info *detect_info; |
88365 | 5170 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5171 const unsigned char *src = coding->source, *src_base; |
89483 | 5172 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 5173 int multibytep = coding->src_multibyte; |
5174 int consumed_chars = 0; | |
5175 int found = 0; | |
89848
3edfa038a435
(detect_coding_emacs_mule): Fix counting of encoded
Kenichi Handa <handa@m17n.org>
parents:
89842
diff
changeset
|
5176 unsigned char *valids; |
88365 | 5177 int head_ascii = coding->head_ascii; |
5178 Lisp_Object attrs; | |
5179 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5180 detect_info->checked |= CATEGORY_MASK_CCL; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5181 |
88365 | 5182 coding = &coding_categories[coding_category_ccl]; |
89848
3edfa038a435
(detect_coding_emacs_mule): Fix counting of encoded
Kenichi Handa <handa@m17n.org>
parents:
89842
diff
changeset
|
5183 valids = CODING_CCL_VALIDS (coding); |
88365 | 5184 attrs = CODING_ID_ATTRS (coding->id); |
5185 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
5186 src += head_ascii; | |
5187 | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5188 while (1) |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5189 { |
88365 | 5190 int c; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5191 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5192 src_base = src; |
88365 | 5193 ONE_MORE_BYTE (c); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5194 if (c < 0 || ! valids[c]) |
88365 | 5195 break; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5196 if ((valids[c] > 1)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5197 found = CATEGORY_MASK_CCL; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5198 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5199 detect_info->rejected |= CATEGORY_MASK_CCL; |
88365 | 5200 return 0; |
5201 | |
5202 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5203 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5204 return 1; |
88365 | 5205 } |
5206 | |
5207 static void | |
5208 decode_coding_ccl (coding) | |
5209 struct coding_system *coding; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5210 { |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
5211 const unsigned char *src = coding->source + coding->consumed; |
89483 | 5212 const unsigned char *src_end = coding->source + coding->src_bytes; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
5213 int *charbuf = coding->charbuf + coding->charbuf_used; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
5214 int *charbuf_end = coding->charbuf + coding->charbuf_size; |
88365 | 5215 int consumed_chars = 0; |
5216 int multibytep = coding->src_multibyte; | |
5217 struct ccl_program ccl; | |
5218 int source_charbuf[1024]; | |
5219 int source_byteidx[1024]; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5220 Lisp_Object attrs, charset_list; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5221 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5222 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 5223 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); |
5224 | |
5225 while (src < src_end) | |
5226 { | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
5227 const unsigned char *p = src; |
88365 | 5228 int *source, *source_end; |
5229 int i = 0; | |
5230 | |
5231 if (multibytep) | |
5232 while (i < 1024 && p < src_end) | |
5233 { | |
5234 source_byteidx[i] = p - src; | |
5235 source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | |
5236 } | |
5237 else | |
5238 while (i < 1024 && p < src_end) | |
5239 source_charbuf[i++] = *p++; | |
89483 | 5240 |
88365 | 5241 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) |
5242 ccl.last_block = 1; | |
5243 | |
5244 source = source_charbuf; | |
5245 source_end = source + i; | |
5246 while (source < source_end) | |
5247 { | |
5248 ccl_driver (&ccl, source, charbuf, | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
5249 source_end - source, charbuf_end - charbuf, |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
5250 charset_list); |
88365 | 5251 source += ccl.consumed; |
5252 charbuf += ccl.produced; | |
5253 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
5254 break; | |
5255 } | |
5256 if (source < source_end) | |
5257 src += source_byteidx[source - source_charbuf]; | |
5258 else | |
5259 src = p; | |
5260 consumed_chars += source - source_charbuf; | |
5261 | |
5262 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
5263 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
5264 break; | |
5265 } | |
5266 | |
5267 switch (ccl.status) | |
5268 { | |
5269 case CCL_STAT_SUSPEND_BY_SRC: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5270 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_SRC); |
88365 | 5271 break; |
5272 case CCL_STAT_SUSPEND_BY_DST: | |
5273 break; | |
5274 case CCL_STAT_QUIT: | |
5275 case CCL_STAT_INVALID_CMD: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5276 record_conversion_result (coding, CODING_RESULT_INTERRUPT); |
88365 | 5277 break; |
5278 default: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5279 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 5280 break; |
5281 } | |
5282 coding->consumed_char += consumed_chars; | |
5283 coding->consumed = src - coding->source; | |
5284 coding->charbuf_used = charbuf - coding->charbuf; | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5285 } |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5286 |
88365 | 5287 static int |
5288 encode_coding_ccl (coding) | |
5289 struct coding_system *coding; | |
5290 { | |
5291 struct ccl_program ccl; | |
5292 int multibytep = coding->dst_multibyte; | |
5293 int *charbuf = coding->charbuf; | |
5294 int *charbuf_end = charbuf + coding->charbuf_used; | |
5295 unsigned char *dst = coding->destination + coding->produced; | |
5296 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5297 int destination_charbuf[1024]; | |
5298 int i, produced_chars = 0; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5299 Lisp_Object attrs, charset_list; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5300 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5301 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 5302 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); |
5303 | |
5304 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; | |
5305 ccl.dst_multibyte = coding->dst_multibyte; | |
5306 | |
90346
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5307 while (charbuf < charbuf_end) |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5308 { |
88365 | 5309 ccl_driver (&ccl, charbuf, destination_charbuf, |
90346
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5310 charbuf_end - charbuf, 1024, charset_list); |
88365 | 5311 if (multibytep) |
90346
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5312 { |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5313 ASSURE_DESTINATION (ccl.produced * 2); |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5314 for (i = 0; i < ccl.produced; i++) |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5315 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5316 } |
88365 | 5317 else |
5318 { | |
90346
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5319 ASSURE_DESTINATION (ccl.produced); |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
5320 for (i = 0; i < ccl.produced; i++) |
88365 | 5321 *dst++ = destination_charbuf[i] & 0xFF; |
5322 produced_chars += ccl.produced; | |
5323 } | |
90346
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5324 charbuf += ccl.consumed; |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5325 if (ccl.status == CCL_STAT_QUIT |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5326 || ccl.status == CCL_STAT_INVALID_CMD) |
bba59a8cdae0
(encode_coding_ccl): Allocate destination dynamically
Kenichi Handa <handa@m17n.org>
parents:
90336
diff
changeset
|
5327 break; |
88365 | 5328 } |
5329 | |
5330 switch (ccl.status) | |
5331 { | |
5332 case CCL_STAT_SUSPEND_BY_SRC: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5333 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_SRC); |
88365 | 5334 break; |
5335 case CCL_STAT_SUSPEND_BY_DST: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5336 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_DST); |
88365 | 5337 break; |
5338 case CCL_STAT_QUIT: | |
5339 case CCL_STAT_INVALID_CMD: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5340 record_conversion_result (coding, CODING_RESULT_INTERRUPT); |
88365 | 5341 break; |
5342 default: | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5343 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 5344 break; |
5345 } | |
5346 | |
5347 coding->produced_char += produced_chars; | |
5348 coding->produced = dst - coding->destination; | |
5349 return 0; | |
5350 } | |
5351 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5352 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5353 |
88365 | 5354 /*** 10, 11. no-conversion handlers ***/ |
17052 | 5355 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5356 /* 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
|
5357 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5358 static void |
88365 | 5359 decode_coding_raw_text (coding) |
17052 | 5360 struct coding_system *coding; |
5361 { | |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
5362 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
5363 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5364 |
88365 | 5365 coding->chars_at_source = 1; |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5366 coding->consumed_char = coding->src_chars; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5367 coding->consumed = coding->src_bytes; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5368 if (eol_crlf && coding->source[coding->src_bytes - 1] == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5369 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5370 coding->consumed_char--; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5371 coding->consumed--; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5372 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_SRC); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5373 } |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5374 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5375 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 5376 } |
5377 | |
5378 static int | |
5379 encode_coding_raw_text (coding) | |
17052 | 5380 struct coding_system *coding; |
88365 | 5381 { |
5382 int multibytep = coding->dst_multibyte; | |
5383 int *charbuf = coding->charbuf; | |
5384 int *charbuf_end = coding->charbuf + coding->charbuf_used; | |
5385 unsigned char *dst = coding->destination + coding->produced; | |
5386 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
95345
0350e5efb8f7
(encode_coding_raw_text): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95344
diff
changeset
|
5387 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
|
5388 int c; |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5389 |
88365 | 5390 if (multibytep) |
5391 { | |
5392 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
5393 | |
5394 if (coding->src_multibyte) | |
5395 while (charbuf < charbuf_end) | |
5396 { | |
5397 ASSURE_DESTINATION (safe_room); | |
5398 c = *charbuf++; | |
5399 if (ASCII_CHAR_P (c)) | |
5400 EMIT_ONE_ASCII_BYTE (c); | |
5401 else if (CHAR_BYTE8_P (c)) | |
5402 { | |
5403 c = CHAR_TO_BYTE8 (c); | |
5404 EMIT_ONE_BYTE (c); | |
5405 } | |
5406 else | |
5407 { | |
5408 unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | |
5409 | |
5410 CHAR_STRING_ADVANCE (c, p1); | |
5411 while (p0 < p1) | |
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
5412 { |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
5413 EMIT_ONE_BYTE (*p0); |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
5414 p0++; |
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
5415 } |
88365 | 5416 } |
5417 } | |
5418 else | |
5419 while (charbuf < charbuf_end) | |
5420 { | |
5421 ASSURE_DESTINATION (safe_room); | |
5422 c = *charbuf++; | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5423 EMIT_ONE_BYTE (c); |
88365 | 5424 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5425 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5426 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5427 { |
88365 | 5428 if (coding->src_multibyte) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5429 { |
88365 | 5430 int safe_room = MAX_MULTIBYTE_LENGTH; |
5431 | |
5432 while (charbuf < charbuf_end) | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5433 { |
88365 | 5434 ASSURE_DESTINATION (safe_room); |
5435 c = *charbuf++; | |
5436 if (ASCII_CHAR_P (c)) | |
5437 *dst++ = c; | |
5438 else if (CHAR_BYTE8_P (c)) | |
5439 *dst++ = CHAR_TO_BYTE8 (c); | |
5440 else | |
5441 CHAR_STRING_ADVANCE (c, dst); | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5442 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5443 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5444 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5445 { |
88365 | 5446 ASSURE_DESTINATION (charbuf_end - charbuf); |
5447 while (charbuf < charbuf_end && dst < dst_end) | |
5448 *dst++ = *charbuf++; | |
89483 | 5449 } |
95353
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
5450 produced_chars = dst - (coding->destination + coding->produced); |
88365 | 5451 } |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5452 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
95345
0350e5efb8f7
(encode_coding_raw_text): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95344
diff
changeset
|
5453 coding->produced_char += produced_chars; |
88365 | 5454 coding->produced = dst - coding->destination; |
5455 return 0; | |
5456 } | |
5457 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5458 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5459 Check if a text is encoded in a charset-based coding system. If it |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5460 is, return 1, else return 0. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5461 |
88365 | 5462 static int |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5463 detect_coding_charset (coding, detect_info) |
88365 | 5464 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5465 struct coding_detection_info *detect_info; |
88365 | 5466 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5467 const unsigned char *src = coding->source, *src_base; |
89483 | 5468 const unsigned char *src_end = coding->source + coding->src_bytes; |
88365 | 5469 int multibytep = coding->src_multibyte; |
5470 int consumed_chars = 0; | |
98951
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5471 Lisp_Object attrs, valids, name; |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
5472 int found = 0; |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5473 int head_ascii = coding->head_ascii; |
98951
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5474 int check_latin_extra = 0; |
88365 | 5475 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5476 detect_info->checked |= CATEGORY_MASK_CHARSET; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5477 |
88365 | 5478 coding = &coding_categories[coding_category_charset]; |
5479 attrs = CODING_ID_ATTRS (coding->id); | |
5480 valids = AREF (attrs, coding_attr_charset_valids); | |
98951
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5481 name = CODING_ID_NAME (coding->id); |
102327
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5482 if (strncmp ((char *) SDATA (SYMBOL_NAME (name)), |
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5483 "iso-8859-", sizeof ("iso-8859-") - 1) == 0 |
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5484 || strncmp ((char *) SDATA (SYMBOL_NAME (name)), |
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5485 "iso-latin-", sizeof ("iso-latin-") - 1) == 0) |
98951
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5486 check_latin_extra = 1; |
102327
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5487 |
88365 | 5488 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5489 src += head_ascii; |
88365 | 5490 |
5491 while (1) | |
5492 { | |
5493 int c; | |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5494 Lisp_Object val; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5495 struct charset *charset; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5496 int dim, idx; |
88365 | 5497 |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5498 src_base = src; |
88365 | 5499 ONE_MORE_BYTE (c); |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5500 if (c < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5501 continue; |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5502 val = AREF (valids, c); |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5503 if (NILP (val)) |
88365 | 5504 break; |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
5505 if (c >= 0x80) |
98951
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5506 { |
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5507 if (c < 0xA0 |
102327
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5508 && check_latin_extra |
a1f0d8fadbb1
(detect_coding_charset): Fix last change for non-latin charsets.
Jason Rumney <jasonr@gnu.org>
parents:
102325
diff
changeset
|
5509 && (!VECTORP (Vlatin_extra_code_table) |
102325
2c693a021d83
(detect_coding_charset): If not checking latin extra,
Jason Rumney <jasonr@gnu.org>
parents:
102320
diff
changeset
|
5510 || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))) |
98951
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5511 break; |
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5512 found = CATEGORY_MASK_CHARSET; |
71becd1e9707
(detect_coding_charset): For iso-8859-* coding systems,
Kenichi Handa <handa@m17n.org>
parents:
98186
diff
changeset
|
5513 } |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5514 if (INTEGERP (val)) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5515 { |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5516 charset = CHARSET_FROM_ID (XFASTINT (val)); |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5517 dim = CHARSET_DIMENSION (charset); |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5518 for (idx = 1; idx < dim; idx++) |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5519 { |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5520 if (src == src_end) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5521 goto too_short; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5522 ONE_MORE_BYTE (c); |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
5523 if (c < charset->code_space[(dim - 1 - idx) * 2] |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5524 || c > charset->code_space[(dim - 1 - idx) * 2 + 1]) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5525 break; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5526 } |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5527 if (idx < dim) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5528 break; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5529 } |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5530 else |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5531 { |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5532 idx = 1; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5533 for (; CONSP (val); val = XCDR (val)) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5534 { |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5535 charset = CHARSET_FROM_ID (XFASTINT (XCAR (val))); |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5536 dim = CHARSET_DIMENSION (charset); |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5537 while (idx < dim) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5538 { |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5539 if (src == src_end) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5540 goto too_short; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5541 ONE_MORE_BYTE (c); |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5542 if (c < charset->code_space[(dim - 1 - idx) * 4] |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5543 || c > charset->code_space[(dim - 1 - idx) * 4 + 1]) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5544 break; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5545 idx++; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5546 } |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5547 if (idx == dim) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5548 { |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5549 val = Qnil; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5550 break; |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5551 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5552 } |
90651
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5553 if (CONSP (val)) |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5554 break; |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5555 } |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5556 } |
23c1467f8640
(detect_coding_charset): Fix detection of multi-byte
Kenichi Handa <handa@m17n.org>
parents:
90599
diff
changeset
|
5557 too_short: |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5558 detect_info->rejected |= CATEGORY_MASK_CHARSET; |
88365 | 5559 return 0; |
5560 | |
5561 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5562 detect_info->found |= found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5563 return 1; |
88365 | 5564 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5565 |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5566 static void |
88365 | 5567 decode_coding_charset (coding) |
17052 | 5568 struct coding_system *coding; |
88365 | 5569 { |
89483 | 5570 const unsigned char *src = coding->source + coding->consumed; |
5571 const unsigned char *src_end = coding->source + coding->src_bytes; | |
46548
cb1914307488
(encode_eol, detect_coding, detect_eol):
Ken Raeburn <raeburn@raeburn.org>
parents:
46462
diff
changeset
|
5572 const unsigned char *src_base; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
5573 int *charbuf = coding->charbuf + coding->charbuf_used; |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
5574 /* We may produce one charset annocation in one loop and one more at |
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
5575 the end. */ |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
5576 int *charbuf_end |
103035
6e443d717c7b
(decode_coding_utf_16): Reduce charbuf_end for the
Kenichi Handa <handa@m17n.org>
parents:
102738
diff
changeset
|
5577 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); |
88365 | 5578 int consumed_chars = 0, consumed_chars_base; |
5579 int multibytep = coding->src_multibyte; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5580 Lisp_Object attrs, charset_list, valids; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5581 int char_offset = coding->produced_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5582 int last_offset = char_offset; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5583 int last_id = charset_ascii; |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
5584 int eol_crlf = |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
5585 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5586 int byte_after_cr = -1; |
88365 | 5587 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5588 CODING_GET_INFO (coding, attrs, charset_list); |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5589 valids = AREF (attrs, coding_attr_charset_valids); |
88365 | 5590 |
5591 while (1) | |
5592 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5593 int c; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5594 Lisp_Object val; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5595 struct charset *charset; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5596 int dim; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5597 int len = 1; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5598 unsigned code; |
88365 | 5599 |
29093
176708661b08
(encode_eol): Fix a bug of DOS style EOL encoding.
Kenichi Handa <handa@m17n.org>
parents:
29005
diff
changeset
|
5600 src_base = src; |
88365 | 5601 consumed_chars_base = consumed_chars; |
5602 | |
5603 if (charbuf >= charbuf_end) | |
100936
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
5604 { |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
5605 if (byte_after_cr >= 0) |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
5606 src_base--; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
5607 break; |
5c5e6d041634
(decode_coding_utf_8): Check byte_after_cr before breaking the loop.
Kenichi Handa <handa@m17n.org>
parents:
100587
diff
changeset
|
5608 } |
88365 | 5609 |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5610 if (byte_after_cr >= 0) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5611 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5612 c = byte_after_cr; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5613 byte_after_cr = -1; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5614 } |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5615 else |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5616 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5617 ONE_MORE_BYTE (c); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5618 if (eol_crlf && c == '\r') |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5619 ONE_MORE_BYTE (byte_after_cr); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
5620 } |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5621 if (c < 0) |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5622 goto invalid_code; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5623 code = c; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5624 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5625 val = AREF (valids, c); |
100170
86455974b971
(decode_coding_charset): Check type of an element of
Kenichi Handa <handa@m17n.org>
parents:
100135
diff
changeset
|
5626 if (! INTEGERP (val) && ! CONSP (val)) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5627 goto invalid_code; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5628 if (INTEGERP (val)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5629 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5630 charset = CHARSET_FROM_ID (XFASTINT (val)); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5631 dim = CHARSET_DIMENSION (charset); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5632 while (len < dim) |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5633 { |
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5634 ONE_MORE_BYTE (c); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5635 code = (code << 8) | c; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5636 len++; |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5637 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5638 CODING_DECODE_CHAR (coding, src, src_base, src_end, |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5639 charset, code, c); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5640 } |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
5641 else |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5642 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5643 /* VAL is a list of charset IDs. It is assured that the |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5644 list is sorted by charset dimensions (smaller one |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5645 comes first). */ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5646 while (CONSP (val)) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5647 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5648 charset = CHARSET_FROM_ID (XFASTINT (XCAR (val))); |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
5649 dim = CHARSET_DIMENSION (charset); |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
5650 while (len < dim) |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5651 { |
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
5652 ONE_MORE_BYTE (c); |
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
5653 code = (code << 8) | c; |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
5654 len++; |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5655 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5656 CODING_DECODE_CHAR (coding, src, src_base, |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5657 src_end, charset, code, c); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5658 if (c >= 0) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5659 break; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5660 val = XCDR (val); |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5661 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5662 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5663 if (c < 0) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5664 goto invalid_code; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5665 if (charset->id != charset_ascii |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5666 && last_id != charset->id) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5667 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5668 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
5669 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5670 last_id = charset->id; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5671 last_offset = char_offset; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5672 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5673 |
88365 | 5674 *charbuf++ = c; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5675 char_offset++; |
88365 | 5676 continue; |
5677 | |
5678 invalid_code: | |
5679 src = src_base; | |
5680 consumed_chars = consumed_chars_base; | |
5681 ONE_MORE_BYTE (c); | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5682 *charbuf++ = c < 0 ? -c : ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5683 char_offset++; |
88365 | 5684 coding->errors++; |
5685 } | |
5686 | |
5687 no_more_source: | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5688 if (last_id != charset_ascii) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
5689 ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id); |
88365 | 5690 coding->consumed_char += consumed_chars_base; |
5691 coding->consumed = src_base - coding->source; | |
5692 coding->charbuf_used = charbuf - coding->charbuf; | |
5693 } | |
5694 | |
5695 static int | |
5696 encode_coding_charset (coding) | |
5697 struct coding_system *coding; | |
5698 { | |
5699 int multibytep = coding->dst_multibyte; | |
5700 int *charbuf = coding->charbuf; | |
5701 int *charbuf_end = charbuf + coding->charbuf_used; | |
5702 unsigned char *dst = coding->destination + coding->produced; | |
5703 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
5704 int safe_room = MAX_MULTIBYTE_LENGTH; | |
5705 int produced_chars = 0; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5706 Lisp_Object attrs, charset_list; |
88365 | 5707 int ascii_compatible; |
5708 int c; | |
5709 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
5710 CODING_GET_INFO (coding, attrs, charset_list); |
88365 | 5711 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); |
5712 | |
5713 while (charbuf < charbuf_end) | |
5714 { | |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5715 struct charset *charset; |
88365 | 5716 unsigned code; |
89483 | 5717 |
88365 | 5718 ASSURE_DESTINATION (safe_room); |
5719 c = *charbuf++; | |
5720 if (ascii_compatible && ASCII_CHAR_P (c)) | |
5721 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
|
5722 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
|
5723 { |
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
5724 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
|
5725 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
|
5726 } |
88365 | 5727 else |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5728 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5729 charset = char_charset (c, charset_list, &code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5730 if (charset) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5731 { |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5732 if (CHARSET_DIMENSION (charset) == 1) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5733 EMIT_ONE_BYTE (code); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5734 else if (CHARSET_DIMENSION (charset) == 2) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5735 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5736 else if (CHARSET_DIMENSION (charset) == 3) |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5737 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
|
5738 else |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5739 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
|
5740 (code >> 8) & 0xFF, code & 0xFF); |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5741 } |
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5742 else |
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5743 { |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5744 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
|
5745 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5746 else |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5747 c = coding->default_char; |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5748 EMIT_ONE_BYTE (c); |
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
5749 } |
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
5750 } |
88365 | 5751 } |
5752 | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
5753 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 5754 coding->produced_char += produced_chars; |
5755 coding->produced = dst - coding->destination; | |
5756 return 0; | |
17052 | 5757 } |
5758 | |
5759 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5760 /*** 7. C library functions ***/ |
17052 | 5761 |
88365 | 5762 /* Setup coding context CODING from information about CODING_SYSTEM. |
5763 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
5764 CODING_SYSTEM is invalid, signal an error. */ | |
5765 | |
5766 void | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
5767 setup_coding_system (coding_system, coding) |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
5768 Lisp_Object coding_system; |
17052 | 5769 struct coding_system *coding; |
5770 { | |
88365 | 5771 Lisp_Object attrs; |
5772 Lisp_Object eol_type; | |
5773 Lisp_Object coding_type; | |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
5774 Lisp_Object val; |
17052 | 5775 |
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
5776 if (NILP (coding_system)) |
90011
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
5777 coding_system = Qundecided; |
88365 | 5778 |
5779 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
5780 | |
5781 attrs = CODING_ID_ATTRS (coding->id); | |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
5782 eol_type = inhibit_eol_conversion ? Qunix : CODING_ID_EOL_TYPE (coding->id); |
88365 | 5783 |
5784 coding->mode = 0; | |
5785 coding->head_ascii = -1; | |
17052 | 5786 if (VECTORP (eol_type)) |
90587
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5787 coding->common_flags = (CODING_REQUIRE_DECODING_MASK |
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5788 | CODING_REQUIRE_DETECTION_MASK); |
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5789 else if (! EQ (eol_type, Qunix)) |
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5790 coding->common_flags = (CODING_REQUIRE_DECODING_MASK |
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5791 | CODING_REQUIRE_ENCODING_MASK); |
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5792 else |
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
5793 coding->common_flags = 0; |
89448
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
5794 if (! NILP (CODING_ATTR_POST_READ (attrs))) |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
5795 coding->common_flags |= CODING_REQUIRE_DECODING_MASK; |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
5796 if (! NILP (CODING_ATTR_PRE_WRITE (attrs))) |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
5797 coding->common_flags |= CODING_REQUIRE_ENCODING_MASK; |
89483 | 5798 if (! NILP (CODING_ATTR_FOR_UNIBYTE (attrs))) |
5799 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
88365 | 5800 |
5801 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
89483 | 5802 coding->max_charset_id = SCHARS (val) - 1; |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
5803 coding->safe_charsets = SDATA (val); |
88365 | 5804 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); |
103655
e2d67c929da2
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
103486
diff
changeset
|
5805 coding->carryover_bytes = 0; |
88365 | 5806 |
5807 coding_type = CODING_ATTR_TYPE (attrs); | |
5808 if (EQ (coding_type, Qundecided)) | |
5809 { | |
5810 coding->detector = NULL; | |
5811 coding->decoder = decode_coding_raw_text; | |
5812 coding->encoder = encode_coding_raw_text; | |
5813 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
5814 } | |
5815 else if (EQ (coding_type, Qiso_2022)) | |
5816 { | |
5817 int i; | |
5818 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
5819 | |
5820 /* Invoke graphic register 0 to plane 0. */ | |
5821 CODING_ISO_INVOCATION (coding, 0) = 0; | |
5822 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
5823 CODING_ISO_INVOCATION (coding, 1) | |
5824 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
5825 /* Setup the initial status of designation. */ | |
5826 for (i = 0; i < 4; i++) | |
5827 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
5828 /* Not single shifting initially. */ | |
5829 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
5830 /* Beginning of buffer should also be regarded as bol. */ | |
5831 CODING_ISO_BOL (coding) = 1; | |
5832 coding->detector = detect_coding_iso_2022; | |
5833 coding->decoder = decode_coding_iso_2022; | |
5834 coding->encoder = encode_coding_iso_2022; | |
5835 if (flags & CODING_ISO_FLAG_SAFE) | |
5836 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
5837 coding->common_flags |
88365 | 5838 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
5839 | CODING_REQUIRE_FLUSHING_MASK); | |
5840 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
5841 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5842 if (flags & CODING_ISO_FLAG_DESIGNATION) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5843 coding->common_flags |= CODING_ANNOTATE_CHARSET_MASK; |
88365 | 5844 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
|
5845 { |
88365 | 5846 setup_iso_safe_charsets (attrs); |
5847 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
89483 | 5848 coding->max_charset_id = SCHARS (val) - 1; |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
5849 coding->safe_charsets = SDATA (val); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5850 } |
88365 | 5851 CODING_ISO_FLAGS (coding) = flags; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5852 CODING_ISO_CMP_STATUS (coding)->state = COMPOSING_NO; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5853 CODING_ISO_CMP_STATUS (coding)->method = COMPOSITION_NO; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5854 CODING_ISO_EXTSEGMENT_LEN (coding) = 0; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5855 CODING_ISO_EMBEDDED_UTF_8 (coding) = 0; |
88365 | 5856 } |
5857 else if (EQ (coding_type, Qcharset)) | |
5858 { | |
5859 coding->detector = detect_coding_charset; | |
5860 coding->decoder = decode_coding_charset; | |
5861 coding->encoder = encode_coding_charset; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
5862 coding->common_flags |
88365 | 5863 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
5864 } | |
5865 else if (EQ (coding_type, Qutf_8)) | |
5866 { | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5867 val = AREF (attrs, coding_attr_utf_bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5868 CODING_UTF_8_BOM (coding) = (CONSP (val) ? utf_detect_bom |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5869 : EQ (val, Qt) ? utf_with_bom |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5870 : utf_without_bom); |
88365 | 5871 coding->detector = detect_coding_utf_8; |
5872 coding->decoder = decode_coding_utf_8; | |
5873 coding->encoder = encode_coding_utf_8; | |
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
5874 coding->common_flags |
88365 | 5875 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5876 if (CODING_UTF_8_BOM (coding) == utf_detect_bom) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5877 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; |
88365 | 5878 } |
5879 else if (EQ (coding_type, Qutf_16)) | |
5880 { | |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5881 val = AREF (attrs, coding_attr_utf_bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5882 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_detect_bom |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5883 : EQ (val, Qt) ? utf_with_bom |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5884 : utf_without_bom); |
88365 | 5885 val = AREF (attrs, coding_attr_utf_16_endian); |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5886 CODING_UTF_16_ENDIAN (coding) = (EQ (val, Qbig) ? utf_16_big_endian |
88365 | 5887 : utf_16_little_endian); |
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
5888 CODING_UTF_16_SURROGATE (coding) = 0; |
88365 | 5889 coding->detector = detect_coding_utf_16; |
5890 coding->decoder = decode_coding_utf_16; | |
5891 coding->encoder = encode_coding_utf_16; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
5892 coding->common_flags |
88365 | 5893 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
5894 if (CODING_UTF_16_BOM (coding) == utf_detect_bom) |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
5895 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; |
88365 | 5896 } |
5897 else if (EQ (coding_type, Qccl)) | |
5898 { | |
5899 coding->detector = detect_coding_ccl; | |
5900 coding->decoder = decode_coding_ccl; | |
5901 coding->encoder = encode_coding_ccl; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
5902 coding->common_flags |
88365 | 5903 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
5904 | CODING_REQUIRE_FLUSHING_MASK); | |
5905 } | |
5906 else if (EQ (coding_type, Qemacs_mule)) | |
5907 { | |
5908 coding->detector = detect_coding_emacs_mule; | |
5909 coding->decoder = decode_coding_emacs_mule; | |
5910 coding->encoder = encode_coding_emacs_mule; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
5911 coding->common_flags |
88365 | 5912 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5913 coding->spec.emacs_mule.full_support = 1; |
88365 | 5914 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) |
5915 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
5916 { | |
5917 Lisp_Object tail, safe_charsets; | |
5918 int max_charset_id = 0; | |
5919 | |
5920 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
5921 tail = XCDR (tail)) | |
5922 if (max_charset_id < XFASTINT (XCAR (tail))) | |
5923 max_charset_id = XFASTINT (XCAR (tail)); | |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
5924 safe_charsets = make_uninit_string (max_charset_id + 1); |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
5925 memset (SDATA (safe_charsets), 255, max_charset_id + 1); |
88365 | 5926 for (tail = Vemacs_mule_charset_list; CONSP (tail); |
5927 tail = XCDR (tail)) | |
89483 | 5928 SSET (safe_charsets, XFASTINT (XCAR (tail)), 0); |
88365 | 5929 coding->max_charset_id = max_charset_id; |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
5930 coding->safe_charsets = SDATA (safe_charsets); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5931 coding->spec.emacs_mule.full_support = 1; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5932 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5933 coding->spec.emacs_mule.cmp_status.state = COMPOSING_NO; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
5934 coding->spec.emacs_mule.cmp_status.method = COMPOSITION_NO; |
88365 | 5935 } |
5936 else if (EQ (coding_type, Qshift_jis)) | |
5937 { | |
5938 coding->detector = detect_coding_sjis; | |
5939 coding->decoder = decode_coding_sjis; | |
5940 coding->encoder = encode_coding_sjis; | |
5941 coding->common_flags | |
5942 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
5943 } | |
5944 else if (EQ (coding_type, Qbig5)) | |
5945 { | |
5946 coding->detector = detect_coding_big5; | |
5947 coding->decoder = decode_coding_big5; | |
5948 coding->encoder = encode_coding_big5; | |
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
5949 coding->common_flags |
88365 | 5950 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
5951 } | |
5952 else /* EQ (coding_type, Qraw_text) */ | |
5953 { | |
5954 coding->detector = NULL; | |
5955 coding->decoder = decode_coding_raw_text; | |
5956 coding->encoder = encode_coding_raw_text; | |
89933
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5957 if (! EQ (eol_type, Qunix)) |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5958 { |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5959 coding->common_flags |= CODING_REQUIRE_DECODING_MASK; |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5960 if (! VECTORP (eol_type)) |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5961 coding->common_flags |= CODING_REQUIRE_ENCODING_MASK; |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5962 } |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
5963 |
88365 | 5964 } |
5965 | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
5966 return; |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
5967 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
5968 |
90061
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5969 /* Return a list of charsets supported by CODING. */ |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5970 |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5971 Lisp_Object |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5972 coding_charset_list (coding) |
26847 | 5973 struct coding_system *coding; |
5974 { | |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
5975 Lisp_Object attrs, charset_list; |
90061
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5976 |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5977 CODING_GET_INFO (coding, attrs, charset_list); |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5978 if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022)) |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5979 { |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5980 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5981 |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5982 if (flags & CODING_ISO_FLAG_FULL_SUPPORT) |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5983 charset_list = Viso_2022_charset_list; |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5984 } |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5985 else if (EQ (CODING_ATTR_TYPE (attrs), Qemacs_mule)) |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5986 { |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5987 charset_list = Vemacs_mule_charset_list; |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5988 } |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5989 return charset_list; |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5990 } |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5991 |
48210be97b12
Cancel the change done in HEAD on 2004-11-30.
Kenichi Handa <handa@m17n.org>
parents:
90054
diff
changeset
|
5992 |
101776
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5993 /* Return a list of charsets supported by CODING-SYSTEM. */ |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5994 |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5995 Lisp_Object |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5996 coding_system_charset_list (coding_system) |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5997 Lisp_Object coding_system; |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5998 { |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
5999 int id; |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6000 Lisp_Object attrs, charset_list; |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6001 |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6002 CHECK_CODING_SYSTEM_GET_ID (coding_system, id); |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6003 attrs = CODING_ID_ATTRS (id); |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6004 |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6005 if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022)) |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6006 { |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6007 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6008 |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6009 if (flags & CODING_ISO_FLAG_FULL_SUPPORT) |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6010 charset_list = Viso_2022_charset_list; |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6011 else |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6012 charset_list = CODING_ATTR_CHARSET_LIST (attrs); |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6013 } |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6014 else if (EQ (CODING_ATTR_TYPE (attrs), Qemacs_mule)) |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6015 { |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6016 charset_list = Vemacs_mule_charset_list; |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6017 } |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6018 else |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6019 { |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6020 charset_list = CODING_ATTR_CHARSET_LIST (attrs); |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6021 } |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6022 return charset_list; |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6023 } |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6024 |
11ba351ce12b
(coding_system_charset_list): New function.
Kenichi Handa <handa@m17n.org>
parents:
101678
diff
changeset
|
6025 |
88365 | 6026 /* Return raw-text or one of its subsidiaries that has the same |
6027 eol_type as CODING-SYSTEM. */ | |
6028 | |
6029 Lisp_Object | |
6030 raw_text_coding_system (coding_system) | |
6031 Lisp_Object coding_system; | |
26847 | 6032 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
6033 Lisp_Object spec, attrs; |
88365 | 6034 Lisp_Object eol_type, raw_text_eol_type; |
6035 | |
89462
4e359ebf3984
(decode_coding_iso_2022): Fix handling of invalid
Kenichi Handa <handa@m17n.org>
parents:
89448
diff
changeset
|
6036 if (NILP (coding_system)) |
4e359ebf3984
(decode_coding_iso_2022): Fix handling of invalid
Kenichi Handa <handa@m17n.org>
parents:
89448
diff
changeset
|
6037 return Qraw_text; |
88365 | 6038 spec = CODING_SYSTEM_SPEC (coding_system); |
6039 attrs = AREF (spec, 0); | |
89483 | 6040 |
88365 | 6041 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) |
6042 return coding_system; | |
6043 | |
6044 eol_type = AREF (spec, 2); | |
6045 if (VECTORP (eol_type)) | |
6046 return Qraw_text; | |
6047 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
6048 raw_text_eol_type = AREF (spec, 2); | |
6049 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
6050 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
6051 : AREF (raw_text_eol_type, 2)); | |
26847 | 6052 } |
6053 | |
88365 | 6054 |
6055 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
6056 does, return one of the subsidiary that has the same eol-spec as | |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6057 PARENT. Otherwise, return CODING_SYSTEM. If PARENT is nil, |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6058 inherit end-of-line format from the system's setting |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6059 (system_eol_type). */ |
88365 | 6060 |
6061 Lisp_Object | |
6062 coding_inherit_eol_type (coding_system, parent) | |
88473 | 6063 Lisp_Object coding_system, parent; |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
6064 { |
89545
4f394eed6ff2
(inhibit_pre_post_conversion): Removed (unused).
Dave Love <fx@gnu.org>
parents:
89519
diff
changeset
|
6065 Lisp_Object spec, eol_type; |
88365 | 6066 |
89462
4e359ebf3984
(decode_coding_iso_2022): Fix handling of invalid
Kenichi Handa <handa@m17n.org>
parents:
89448
diff
changeset
|
6067 if (NILP (coding_system)) |
4e359ebf3984
(decode_coding_iso_2022): Fix handling of invalid
Kenichi Handa <handa@m17n.org>
parents:
89448
diff
changeset
|
6068 coding_system = Qraw_text; |
88365 | 6069 spec = CODING_SYSTEM_SPEC (coding_system); |
6070 eol_type = AREF (spec, 2); | |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6071 if (VECTORP (eol_type)) |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6072 { |
88365 | 6073 Lisp_Object parent_eol_type; |
6074 | |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6075 if (! NILP (parent)) |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6076 { |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6077 Lisp_Object parent_spec; |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6078 |
90587
fe721cfad011
(setup_coding_system): Fix setting of
Kenichi Handa <handa@m17n.org>
parents:
90573
diff
changeset
|
6079 parent_spec = CODING_SYSTEM_SPEC (parent); |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6080 parent_eol_type = AREF (parent_spec, 2); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6081 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6082 else |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
6083 parent_eol_type = system_eol_type; |
88365 | 6084 if (EQ (parent_eol_type, Qunix)) |
6085 coding_system = AREF (eol_type, 0); | |
6086 else if (EQ (parent_eol_type, Qdos)) | |
6087 coding_system = AREF (eol_type, 1); | |
6088 else if (EQ (parent_eol_type, Qmac)) | |
6089 coding_system = AREF (eol_type, 2); | |
6090 } | |
6091 return coding_system; | |
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
6092 } |
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
6093 |
17052 | 6094 /* Emacs has a mechanism to automatically detect a coding system if it |
6095 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
6096 it's impossible to distinguish some coding systems accurately | |
6097 because they use the same range of codes. So, at first, coding | |
6098 systems are categorized into 7, those are: | |
6099 | |
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
6100 o coding-category-emacs-mule |
17052 | 6101 |
6102 The category for a coding system which has the same code range | |
6103 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
|
6104 symbol) `emacs-mule' by default. |
17052 | 6105 |
6106 o coding-category-sjis | |
6107 | |
6108 The category for a coding system which has the same code range | |
6109 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
|
6110 symbol) `japanese-shift-jis' by default. |
17052 | 6111 |
6112 o coding-category-iso-7 | |
6113 | |
6114 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
|
6115 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
|
6116 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
|
6117 charsets. Assigned the coding-system (Lisp symbol) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6118 `iso-2022-7bit' by default. |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6119 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6120 o coding-category-iso-7-tight |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6121 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6122 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
|
6123 encode/decode only the specified charsets. |
17052 | 6124 |
6125 o coding-category-iso-8-1 | |
6126 | |
6127 The category for a coding system which has the same code range | |
6128 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
|
6129 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
|
6130 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
|
6131 symbol) `iso-latin-1' by default. |
17052 | 6132 |
6133 o coding-category-iso-8-2 | |
6134 | |
6135 The category for a coding system which has the same code range | |
6136 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
|
6137 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
|
6138 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
|
6139 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
|
6140 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
6141 o coding-category-iso-7-else |
17052 | 6142 |
6143 The category for a coding system which has the same code range | |
88365 | 6144 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
|
6145 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
|
6146 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
|
6147 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
6148 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
|
6149 |
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
6150 The category for a coding system which has the same code range |
88365 | 6151 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
|
6152 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
|
6153 symbol) `iso-2022-8bit-ss2' by default. |
17052 | 6154 |
6155 o coding-category-big5 | |
6156 | |
6157 The category for a coding system which has the same code range | |
6158 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
|
6159 `cn-big5' by default. |
17052 | 6160 |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6161 o coding-category-utf-8 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6162 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6163 The category for a coding system which has the same code range |
54303 | 6164 as UTF-8 (cf. RFC3629). Assigned the coding-system (Lisp |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6165 symbol) `utf-8' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6166 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6167 o coding-category-utf-16-be |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6168 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6169 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
|
6170 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
|
6171 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
|
6172 `utf-16-be' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6173 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6174 o coding-category-utf-16-le |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6175 |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6176 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
|
6177 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
|
6178 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
|
6179 symbol) `utf-16-le' by default. |
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6180 |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6181 o coding-category-ccl |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6182 |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6183 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
|
6184 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
|
6185 coding system is assigned. |
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6186 |
17052 | 6187 o coding-category-binary |
6188 | |
6189 The category for a coding system not categorized in any of the | |
6190 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
|
6191 `no-conversion' by default. |
17052 | 6192 |
6193 Each of them is a Lisp symbol and the value is an actual | |
88365 | 6194 `coding-system's (this is also a Lisp symbol) assigned by a user. |
17052 | 6195 What Emacs does actually is to detect a category of coding system. |
6196 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
88365 | 6197 decide only one possible category, it selects a category of the |
17052 | 6198 highest priority. Priorities of categories are also specified by a |
6199 user in a Lisp variable `coding-category-list'. | |
6200 | |
6201 */ | |
6202 | |
88365 | 6203 #define EOL_SEEN_NONE 0 |
6204 #define EOL_SEEN_LF 1 | |
6205 #define EOL_SEEN_CR 2 | |
6206 #define EOL_SEEN_CRLF 4 | |
17052 | 6207 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6208 /* Detect how end-of-line of a text of length SRC_BYTES pointed by |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6209 SOURCE is encoded. If CATEGORY is one of |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6210 coding_category_utf_16_XXXX, assume that CR and LF are encoded by |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6211 two-byte, else they are encoded by one-byte. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6212 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6213 Return one of EOL_SEEN_XXX. */ |
17052 | 6214 |
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
6215 #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
|
6216 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6217 static int |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6218 detect_eol (source, src_bytes, category) |
84646
922a7e3b7383
(detect_eol_type, detect_eol_type_in_2_octet_form):
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
83648
diff
changeset
|
6219 const unsigned char *source; |
88365 | 6220 EMACS_INT src_bytes; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6221 enum coding_category category; |
17052 | 6222 { |
84646
922a7e3b7383
(detect_eol_type, detect_eol_type_in_2_octet_form):
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
83648
diff
changeset
|
6223 const unsigned char *src = source, *src_end = src + src_bytes; |
17052 | 6224 unsigned char c; |
88365 | 6225 int total = 0; |
6226 int eol_seen = EOL_SEEN_NONE; | |
6227 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6228 if ((1 << category) & CATEGORY_MASK_UTF_16) |
88365 | 6229 { |
6230 int msb, lsb; | |
6231 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6232 msb = category == (coding_category_utf_16_le |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6233 | coding_category_utf_16_le_nosig); |
88365 | 6234 lsb = 1 - msb; |
6235 | |
6236 while (src + 1 < src_end) | |
17052 | 6237 { |
88365 | 6238 c = src[lsb]; |
6239 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
|
6240 { |
88365 | 6241 int this_eol; |
6242 | |
6243 if (c == '\n') | |
6244 this_eol = EOL_SEEN_LF; | |
6245 else if (src + 3 >= src_end | |
6246 || src[msb + 2] != 0 | |
6247 || src[lsb + 2] != '\n') | |
6248 this_eol = EOL_SEEN_CR; | |
6249 else | |
101678
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6250 { |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6251 this_eol = EOL_SEEN_CRLF; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6252 src += 2; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6253 } |
88365 | 6254 |
6255 if (eol_seen == EOL_SEEN_NONE) | |
6256 /* This is the first end-of-line. */ | |
6257 eol_seen = this_eol; | |
6258 else if (eol_seen != this_eol) | |
6259 { | |
101678
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6260 /* The found type is different from what found before. |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6261 Allow for stray ^M characters in DOS EOL files. */ |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6262 if (eol_seen == EOL_SEEN_CR && this_eol == EOL_SEEN_CRLF |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6263 || eol_seen == EOL_SEEN_CRLF && this_eol == EOL_SEEN_CR) |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6264 eol_seen = EOL_SEEN_CRLF; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6265 else |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6266 { |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6267 eol_seen = EOL_SEEN_LF; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6268 break; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6269 } |
88365 | 6270 } |
6271 if (++total == MAX_EOL_CHECK_COUNT) | |
6272 break; | |
6273 } | |
6274 src += 2; | |
6275 } | |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
6276 } |
88365 | 6277 else |
6278 { | |
6279 while (src < src_end) | |
6280 { | |
6281 c = *src++; | |
6282 if (c == '\n' || c == '\r') | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6283 { |
88365 | 6284 int this_eol; |
6285 | |
6286 if (c == '\n') | |
6287 this_eol = EOL_SEEN_LF; | |
6288 else if (src >= src_end || *src != '\n') | |
6289 this_eol = EOL_SEEN_CR; | |
6290 else | |
6291 this_eol = EOL_SEEN_CRLF, src++; | |
6292 | |
6293 if (eol_seen == EOL_SEEN_NONE) | |
6294 /* This is the first end-of-line. */ | |
6295 eol_seen = this_eol; | |
6296 else if (eol_seen != this_eol) | |
6297 { | |
101678
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6298 /* The found type is different from what found before. |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6299 Allow for stray ^M characters in DOS EOL files. */ |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6300 if (eol_seen == EOL_SEEN_CR && this_eol == EOL_SEEN_CRLF |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6301 || eol_seen == EOL_SEEN_CRLF && this_eol == EOL_SEEN_CR) |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6302 eol_seen = EOL_SEEN_CRLF; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6303 else |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6304 { |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6305 eol_seen = EOL_SEEN_LF; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6306 break; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6307 } |
88365 | 6308 } |
6309 if (++total == MAX_EOL_CHECK_COUNT) | |
6310 break; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6311 } |
17052 | 6312 } |
6313 } | |
88365 | 6314 return eol_seen; |
17052 | 6315 } |
6316 | |
88365 | 6317 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6318 static Lisp_Object |
88365 | 6319 adjust_coding_eol_type (coding, eol_seen) |
6320 struct coding_system *coding; | |
6321 int eol_seen; | |
6322 { | |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
6323 Lisp_Object eol_type; |
89483 | 6324 |
88365 | 6325 eol_type = CODING_ID_EOL_TYPE (coding->id); |
6326 if (eol_seen & EOL_SEEN_LF) | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6327 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6328 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6329 eol_type = Qunix; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6330 } |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
6331 else if (eol_seen & EOL_SEEN_CRLF) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6332 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6333 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6334 eol_type = Qdos; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6335 } |
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
6336 else if (eol_seen & EOL_SEEN_CR) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6337 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6338 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6339 eol_type = Qmac; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6340 } |
19181
917138730635
(detect_eol_type): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
19173
diff
changeset
|
6341 return eol_type; |
17052 | 6342 } |
6343 | |
88365 | 6344 /* Detect how a text specified in CODING is encoded. If a coding |
6345 system is detected, update fields of CODING by the detected coding | |
6346 system. */ | |
17052 | 6347 |
6348 void | |
88365 | 6349 detect_coding (coding) |
17052 | 6350 struct coding_system *coding; |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6351 { |
89483 | 6352 const unsigned char *src, *src_end; |
102105
a5023e8bbb1e
(detect_coding): Preserve coding->mode.
Kenichi Handa <handa@m17n.org>
parents:
102058
diff
changeset
|
6353 int saved_mode = coding->mode; |
88365 | 6354 |
6355 coding->consumed = coding->consumed_char = 0; | |
6356 coding->produced = coding->produced_char = 0; | |
6357 coding_set_source (coding); | |
6358 | |
6359 src_end = coding->source + coding->src_bytes; | |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6360 coding->head_ascii = 0; |
88365 | 6361 |
6362 /* If we have not yet decided the text encoding type, detect it | |
6363 now. */ | |
6364 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
6365 { | |
6366 int c, i; | |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6367 struct coding_detection_info detect_info; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6368 int null_byte_found = 0, eight_bit_found = 0; |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6369 |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6370 detect_info.checked = detect_info.found = detect_info.rejected = 0; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6371 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
|
6372 { |
88365 | 6373 c = *src; |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6374 if (c & 0x80) |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6375 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6376 eight_bit_found = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6377 if (null_byte_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6378 break; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6379 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6380 else if (c < 0x20) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6381 { |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6382 if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6383 && ! inhibit_iso_escape_detection |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6384 && ! detect_info.checked) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6385 { |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6386 if (detect_coding_iso_2022 (coding, &detect_info)) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6387 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6388 /* We have scanned the whole data. */ |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6389 if (! (detect_info.rejected & CATEGORY_MASK_ISO_7_ELSE)) |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6390 { |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6391 /* We didn't find an 8-bit code. We may |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6392 have found a null-byte, but it's very |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6393 rare that a binary file confirm to |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6394 ISO-2022. */ |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6395 src = src_end; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6396 coding->head_ascii = src - coding->source; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6397 } |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6398 detect_info.rejected |= ~CATEGORY_MASK_ISO_ESCAPE; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6399 break; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6400 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6401 } |
101040 | 6402 else if (! c && !inhibit_null_byte_detection) |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6403 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6404 null_byte_found = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6405 if (eight_bit_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6406 break; |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6407 } |
95585
862c7386145c
(detect_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95533
diff
changeset
|
6408 if (! eight_bit_found) |
862c7386145c
(detect_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95533
diff
changeset
|
6409 coding->head_ascii++; |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6410 } |
95585
862c7386145c
(detect_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95533
diff
changeset
|
6411 else if (! eight_bit_found) |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6412 coding->head_ascii++; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6413 } |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6414 |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6415 if (null_byte_found || eight_bit_found |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6416 || coding->head_ascii < coding->src_bytes |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6417 || detect_info.found) |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6418 { |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6419 enum coding_category category; |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6420 struct coding_system *this; |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6421 |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6422 if (coding->head_ascii == coding->src_bytes) |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6423 /* As all bytes are 7-bit, we can ignore non-ISO-2022 codings. */ |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6424 for (i = 0; i < coding_category_raw_text; i++) |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6425 { |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6426 category = coding_priorities[i]; |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6427 this = coding_categories + category; |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6428 if (detect_info.found & (1 << category)) |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6429 break; |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6430 } |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6431 else |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6432 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6433 if (null_byte_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6434 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6435 detect_info.checked |= ~CATEGORY_MASK_UTF_16; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6436 detect_info.rejected |= ~CATEGORY_MASK_UTF_16; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6437 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6438 for (i = 0; i < coding_category_raw_text; i++) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6439 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6440 category = coding_priorities[i]; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6441 this = coding_categories + category; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6442 if (this->id < 0) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6443 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6444 /* No coding system of this category is defined. */ |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6445 detect_info.rejected |= (1 << category); |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6446 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6447 else if (category >= coding_category_raw_text) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6448 continue; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6449 else if (detect_info.checked & (1 << category)) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6450 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6451 if (detect_info.found & (1 << category)) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6452 break; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6453 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6454 else if ((*(this->detector)) (coding, &detect_info) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6455 && detect_info.found & (1 << category)) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6456 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6457 if (category == coding_category_utf_16_auto) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6458 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6459 if (detect_info.found & CATEGORY_MASK_UTF_16_LE) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6460 category = coding_category_utf_16_le; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6461 else |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6462 category = coding_category_utf_16_be; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6463 } |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
6464 break; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6465 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6466 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
6467 } |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6468 |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6469 if (i < coding_category_raw_text) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6470 setup_coding_system (CODING_ID_NAME (this->id), coding); |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6471 else if (null_byte_found) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6472 setup_coding_system (Qno_conversion, coding); |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6473 else if ((detect_info.rejected & CATEGORY_MASK_ANY) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6474 == CATEGORY_MASK_ANY) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6475 setup_coding_system (Qraw_text, coding); |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6476 else if (detect_info.rejected) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6477 for (i = 0; i < coding_category_raw_text; i++) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6478 if (! (detect_info.rejected & (1 << coding_priorities[i]))) |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6479 { |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6480 this = coding_categories + coding_priorities[i]; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6481 setup_coding_system (CODING_ID_NAME (this->id), coding); |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6482 break; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
6483 } |
88365 | 6484 } |
6485 } | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6486 else if (XINT (CODING_ATTR_CATEGORY (CODING_ID_ATTRS (coding->id))) |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6487 == coding_category_utf_8_auto) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6488 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6489 Lisp_Object coding_systems; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6490 struct coding_detection_info detect_info; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6491 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6492 coding_systems |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6493 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6494 detect_info.found = detect_info.rejected = 0; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6495 coding->head_ascii = 0; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6496 if (CONSP (coding_systems) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6497 && detect_coding_utf_8 (coding, &detect_info)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6498 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6499 if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6500 setup_coding_system (XCAR (coding_systems), coding); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6501 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6502 setup_coding_system (XCDR (coding_systems), coding); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6503 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6504 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6505 else if (XINT (CODING_ATTR_CATEGORY (CODING_ID_ATTRS (coding->id))) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6506 == coding_category_utf_16_auto) |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6507 { |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6508 Lisp_Object coding_systems; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6509 struct coding_detection_info detect_info; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6510 |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6511 coding_systems |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6512 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6513 detect_info.found = detect_info.rejected = 0; |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
6514 coding->head_ascii = 0; |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6515 if (CONSP (coding_systems) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6516 && detect_coding_utf_16 (coding, &detect_info)) |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6517 { |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6518 if (detect_info.found & CATEGORY_MASK_UTF_16_LE) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6519 setup_coding_system (XCAR (coding_systems), coding); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6520 else if (detect_info.found & CATEGORY_MASK_UTF_16_BE) |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6521 setup_coding_system (XCDR (coding_systems), coding); |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6522 } |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
6523 } |
102105
a5023e8bbb1e
(detect_coding): Preserve coding->mode.
Kenichi Handa <handa@m17n.org>
parents:
102058
diff
changeset
|
6524 coding->mode = saved_mode; |
88365 | 6525 } |
6526 | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6527 |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6528 static void |
88365 | 6529 decode_eol (coding) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6530 struct coding_system *coding; |
88365 | 6531 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6532 Lisp_Object eol_type; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6533 unsigned char *p, *pbeg, *pend; |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
6534 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6535 eol_type = CODING_ID_EOL_TYPE (coding->id); |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
6536 if (EQ (eol_type, Qunix) || inhibit_eol_conversion) |
17052 | 6537 return; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6538 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6539 if (NILP (coding->dst_object)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6540 pbeg = coding->destination; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6541 else |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6542 pbeg = BYTE_POS_ADDR (coding->dst_pos_byte); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6543 pend = pbeg + coding->produced; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6544 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6545 if (VECTORP (eol_type)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6546 { |
88365 | 6547 int eol_seen = EOL_SEEN_NONE; |
6548 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6549 for (p = pbeg; p < pend; p++) |
88365 | 6550 { |
6551 if (*p == '\n') | |
6552 eol_seen |= EOL_SEEN_LF; | |
6553 else if (*p == '\r') | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6554 { |
88365 | 6555 if (p + 1 < pend && *(p + 1) == '\n') |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6556 { |
88365 | 6557 eol_seen |= EOL_SEEN_CRLF; |
6558 p++; | |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6559 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6560 else |
88365 | 6561 eol_seen |= EOL_SEEN_CR; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
6562 } |
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
6563 } |
101678
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6564 /* Handle DOS-style EOLs in a file with stray ^M characters. */ |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6565 if ((eol_seen & EOL_SEEN_CRLF) != 0 |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6566 && (eol_seen & EOL_SEEN_CR) != 0 |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6567 && (eol_seen & EOL_SEEN_LF) == 0) |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6568 eol_seen = EOL_SEEN_CRLF; |
589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
Eli Zaretskii <eliz@gnu.org>
parents:
101197
diff
changeset
|
6569 else if (eol_seen != EOL_SEEN_NONE |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6570 && eol_seen != EOL_SEEN_LF |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6571 && eol_seen != EOL_SEEN_CRLF |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6572 && eol_seen != EOL_SEEN_CR) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6573 eol_seen = EOL_SEEN_LF; |
88365 | 6574 if (eol_seen != EOL_SEEN_NONE) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6575 eol_type = adjust_coding_eol_type (coding, eol_seen); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6576 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6577 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6578 if (EQ (eol_type, Qmac)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6579 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6580 for (p = pbeg; p < pend; p++) |
88365 | 6581 if (*p == '\r') |
6582 *p = '\n'; | |
6583 } | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6584 else if (EQ (eol_type, Qdos)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6585 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6586 int n = 0; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6587 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6588 if (NILP (coding->dst_object)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6589 { |
90378
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6590 /* Start deleting '\r' from the tail to minimize the memory |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6591 movement. */ |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6592 for (p = pend - 2; p >= pbeg; p--) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6593 if (*p == '\r') |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6594 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6595 safe_bcopy ((char *) (p + 1), (char *) p, pend-- - p - 1); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6596 n++; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6597 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6598 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6599 else |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6600 { |
90378
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6601 int pos_byte = coding->dst_pos_byte; |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6602 int pos = coding->dst_pos; |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6603 int pos_end = pos + coding->produced_char - 1; |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6604 |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6605 while (pos < pos_end) |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6606 { |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6607 p = BYTE_POS_ADDR (pos_byte); |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6608 if (*p == '\r' && p[1] == '\n') |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6609 { |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6610 del_range_2 (pos, pos_byte, pos + 1, pos_byte + 1, 0); |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6611 n++; |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6612 pos_end--; |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6613 } |
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6614 pos++; |
91535
419a669bc4f2
(decode_eol): Pay attention to coding->dst_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
91367
diff
changeset
|
6615 if (coding->dst_multibyte) |
419a669bc4f2
(decode_eol): Pay attention to coding->dst_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
91367
diff
changeset
|
6616 pos_byte += BYTES_BY_CHAR_HEAD (*p); |
419a669bc4f2
(decode_eol): Pay attention to coding->dst_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
91367
diff
changeset
|
6617 else |
419a669bc4f2
(decode_eol): Pay attention to coding->dst_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
91367
diff
changeset
|
6618 pos_byte++; |
90378
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
6619 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6620 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6621 coding->produced -= n; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
6622 coding->produced_char -= n; |
17052 | 6623 } |
6624 } | |
6625 | |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6626 |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
6627 /* Return a translation table (or list of them) from coding system |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
6628 attribute vector ATTRS for encoding (ENCODEP is nonzero) or |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
6629 decoding (ENCODEP is zero). */ |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6630 |
89858
23cb9ed79225
(get_translation_table): Declare it as Lisp_Object.
Kenichi Handa <handa@m17n.org>
parents:
89856
diff
changeset
|
6631 static Lisp_Object |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6632 get_translation_table (attrs, encodep, max_lookup) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6633 Lisp_Object attrs; |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6634 int encodep, *max_lookup; |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6635 { |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6636 Lisp_Object standard, translation_table; |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6637 Lisp_Object val; |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6638 |
103306
3680b4fe0f79
* coding.c (get_translation_table): Check Venable_character_translation.
Chong Yidong <cyd@stupidchicken.com>
parents:
103133
diff
changeset
|
6639 if (NILP (Venable_character_translation)) |
3680b4fe0f79
* coding.c (get_translation_table): Check Venable_character_translation.
Chong Yidong <cyd@stupidchicken.com>
parents:
103133
diff
changeset
|
6640 { |
3680b4fe0f79
* coding.c (get_translation_table): Check Venable_character_translation.
Chong Yidong <cyd@stupidchicken.com>
parents:
103133
diff
changeset
|
6641 if (max_lookup) |
3680b4fe0f79
* coding.c (get_translation_table): Check Venable_character_translation.
Chong Yidong <cyd@stupidchicken.com>
parents:
103133
diff
changeset
|
6642 *max_lookup = 0; |
3680b4fe0f79
* coding.c (get_translation_table): Check Venable_character_translation.
Chong Yidong <cyd@stupidchicken.com>
parents:
103133
diff
changeset
|
6643 return Qnil; |
3680b4fe0f79
* coding.c (get_translation_table): Check Venable_character_translation.
Chong Yidong <cyd@stupidchicken.com>
parents:
103133
diff
changeset
|
6644 } |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6645 if (encodep) |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6646 translation_table = CODING_ATTR_ENCODE_TBL (attrs), |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6647 standard = Vstandard_translation_table_for_encode; |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6648 else |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6649 translation_table = CODING_ATTR_DECODE_TBL (attrs), |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6650 standard = Vstandard_translation_table_for_decode; |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
6651 if (NILP (translation_table)) |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6652 translation_table = standard; |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6653 else |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6654 { |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6655 if (SYMBOLP (translation_table)) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6656 translation_table = Fget (translation_table, Qtranslation_table); |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6657 else if (CONSP (translation_table)) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6658 { |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6659 translation_table = Fcopy_sequence (translation_table); |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6660 for (val = translation_table; CONSP (val); val = XCDR (val)) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6661 if (SYMBOLP (XCAR (val))) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6662 XSETCAR (val, Fget (XCAR (val), Qtranslation_table)); |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6663 } |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6664 if (CHAR_TABLE_P (standard)) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6665 { |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6666 if (CONSP (translation_table)) |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6667 translation_table = nconc2 (translation_table, |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6668 Fcons (standard, Qnil)); |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6669 else |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6670 translation_table = Fcons (translation_table, |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6671 Fcons (standard, Qnil)); |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6672 } |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6673 } |
89861
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6674 |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6675 if (max_lookup) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6676 { |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6677 *max_lookup = 1; |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6678 if (CHAR_TABLE_P (translation_table) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6679 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (translation_table)) > 1) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6680 { |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6681 val = XCHAR_TABLE (translation_table)->extras[1]; |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6682 if (NATNUMP (val) && *max_lookup < XFASTINT (val)) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6683 *max_lookup = XFASTINT (val); |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6684 } |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6685 else if (CONSP (translation_table)) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6686 { |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6687 Lisp_Object tail, val; |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6688 |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6689 for (tail = translation_table; CONSP (tail); tail = XCDR (tail)) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6690 if (CHAR_TABLE_P (XCAR (tail)) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6691 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (XCAR (tail))) > 1) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6692 { |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6693 val = XCHAR_TABLE (XCAR (tail))->extras[1]; |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6694 if (NATNUMP (val) && *max_lookup < XFASTINT (val)) |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6695 *max_lookup = XFASTINT (val); |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6696 } |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
6697 } |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
6698 } |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6699 return translation_table; |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6700 } |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6701 |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6702 #define LOOKUP_TRANSLATION_TABLE(table, c, trans) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6703 do { \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6704 trans = Qnil; \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6705 if (CHAR_TABLE_P (table)) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6706 { \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6707 trans = CHAR_TABLE_REF (table, c); \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6708 if (CHARACTERP (trans)) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6709 c = XFASTINT (trans), trans = Qnil; \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6710 } \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6711 else if (CONSP (table)) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6712 { \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6713 Lisp_Object tail; \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6714 \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6715 for (tail = table; CONSP (tail); tail = XCDR (tail)) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6716 if (CHAR_TABLE_P (XCAR (tail))) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6717 { \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6718 trans = CHAR_TABLE_REF (XCAR (tail), c); \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6719 if (CHARACTERP (trans)) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6720 c = XFASTINT (trans), trans = Qnil; \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6721 else if (! NILP (trans)) \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6722 break; \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6723 } \ |
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6724 } \ |
89858
23cb9ed79225
(get_translation_table): Declare it as Lisp_Object.
Kenichi Handa <handa@m17n.org>
parents:
89856
diff
changeset
|
6725 } while (0) |
23cb9ed79225
(get_translation_table): Declare it as Lisp_Object.
Kenichi Handa <handa@m17n.org>
parents:
89856
diff
changeset
|
6726 |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
6727 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6728 /* Return a translation of character(s) at BUF according to TRANS. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6729 TRANS is TO-CHAR or ((FROM . TO) ...) where |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6730 FROM = [FROM-CHAR ...], TO is TO-CHAR or [TO-CHAR ...]. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6731 The return value is TO-CHAR or ([FROM-CHAR ...] . TO) if a |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6732 translation is found, and Qnil if not found.. |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6733 If BUF is too short to lookup characters in FROM, return Qt. */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6734 |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6735 static Lisp_Object |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6736 get_translation (trans, buf, buf_end) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6737 Lisp_Object trans; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6738 int *buf, *buf_end; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6739 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6740 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6741 if (INTEGERP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6742 return trans; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6743 for (; CONSP (trans); trans = XCDR (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6744 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6745 Lisp_Object val = XCAR (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6746 Lisp_Object from = XCAR (val); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6747 int len = ASIZE (from); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6748 int i; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6749 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6750 for (i = 0; i < len; i++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6751 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6752 if (buf + i == buf_end) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6753 return Qt; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6754 if (XINT (AREF (from, i)) != buf[i]) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6755 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6756 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6757 if (i == len) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6758 return val; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6759 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6760 return Qnil; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6761 } |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6762 |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6763 |
88365 | 6764 static int |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6765 produce_chars (coding, translation_table, last_block) |
17052 | 6766 struct coding_system *coding; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6767 Lisp_Object translation_table; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6768 int last_block; |
17052 | 6769 { |
88365 | 6770 unsigned char *dst = coding->destination + coding->produced; |
6771 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6772 EMACS_INT produced; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6773 EMACS_INT produced_chars = 0; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6774 int carryover = 0; |
88365 | 6775 |
6776 if (! coding->chars_at_source) | |
6777 { | |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6778 /* Source characters are in coding->charbuf. */ |
89575
59d10ebd2a0b
(produce_chars): Revert last change.
Andreas Schwab <schwab@suse.de>
parents:
89571
diff
changeset
|
6779 int *buf = coding->charbuf; |
59d10ebd2a0b
(produce_chars): Revert last change.
Andreas Schwab <schwab@suse.de>
parents:
89571
diff
changeset
|
6780 int *buf_end = buf + coding->charbuf_used; |
88365 | 6781 |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6782 if (EQ (coding->src_object, coding->dst_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6783 { |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6784 coding_set_source (coding); |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6785 dst_end = ((unsigned char *) coding->source) + coding->consumed; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6786 } |
88365 | 6787 |
6788 while (buf < buf_end) | |
6789 { | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6790 int c = *buf, i; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6791 |
88365 | 6792 if (c >= 0) |
6793 { | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6794 int from_nchars = 1, to_nchars = 1; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6795 Lisp_Object trans = Qnil; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6796 |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
6797 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans); |
89858
23cb9ed79225
(get_translation_table): Declare it as Lisp_Object.
Kenichi Handa <handa@m17n.org>
parents:
89856
diff
changeset
|
6798 if (! NILP (trans)) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6799 { |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6800 trans = get_translation (trans, buf, buf_end); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6801 if (INTEGERP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6802 c = XINT (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6803 else if (CONSP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6804 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6805 from_nchars = ASIZE (XCAR (trans)); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6806 trans = XCDR (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6807 if (INTEGERP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6808 c = XINT (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6809 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6810 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6811 to_nchars = ASIZE (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6812 c = XINT (AREF (trans, 0)); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6813 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6814 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6815 else if (EQ (trans, Qt) && ! last_block) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6816 break; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6817 } |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6818 |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6819 if (dst + MAX_MULTIBYTE_LENGTH * to_nchars > dst_end) |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6820 { |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6821 dst = alloc_destination (coding, |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6822 buf_end - buf |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6823 + MAX_MULTIBYTE_LENGTH * to_nchars, |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6824 dst); |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6825 if (EQ (coding->src_object, coding->dst_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6826 { |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6827 coding_set_source (coding); |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6828 dst_end = (((unsigned char *) coding->source) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6829 + coding->consumed); |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6830 } |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6831 else |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6832 dst_end = coding->destination + coding->dst_bytes; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6833 } |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6834 |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
6835 for (i = 0; i < to_nchars; i++) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6836 { |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
6837 if (i > 0) |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
6838 c = XINT (AREF (trans, i)); |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6839 if (coding->dst_multibyte |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6840 || ! CHAR_BYTE8_P (c)) |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6841 CHAR_STRING_ADVANCE_NO_UNIFY (c, dst); |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6842 else |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6843 *dst++ = CHAR_TO_BYTE8 (c); |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6844 } |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6845 produced_chars += to_nchars; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6846 buf += from_nchars; |
88365 | 6847 } |
6848 else | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6849 /* This is an annotation datum. (-C) is the length. */ |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6850 buf += -c; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6851 } |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6852 carryover = buf_end - buf; |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
6853 } |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
6854 else |
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
6855 { |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6856 /* Source characters are at coding->source. */ |
89483 | 6857 const unsigned char *src = coding->source; |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6858 const unsigned char *src_end = src + coding->consumed; |
88365 | 6859 |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6860 if (EQ (coding->dst_object, coding->src_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6861 dst_end = (unsigned char *) src; |
88365 | 6862 if (coding->src_multibyte != coding->dst_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6863 { |
88365 | 6864 if (coding->src_multibyte) |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6865 { |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
6866 int multibytep = 1; |
100135
0e17542db552
(detect_coding_system): Initialize utf_16_le_eol to -1, val to
Kenichi Handa <handa@m17n.org>
parents:
100133
diff
changeset
|
6867 EMACS_INT consumed_chars = 0; |
88365 | 6868 |
6869 while (1) | |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6870 { |
89483 | 6871 const unsigned char *src_base = src; |
88365 | 6872 int c; |
6873 | |
6874 ONE_MORE_BYTE (c); | |
6875 if (dst == dst_end) | |
6876 { | |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6877 if (EQ (coding->src_object, coding->dst_object)) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6878 dst_end = (unsigned char *) src; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6879 if (dst == dst_end) |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6880 { |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6881 EMACS_INT offset = src - coding->source; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6882 |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6883 dst = alloc_destination (coding, src_end - src + 1, |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6884 dst); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6885 dst_end = coding->destination + coding->dst_bytes; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6886 coding_set_source (coding); |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6887 src = coding->source + offset; |
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6888 src_end = coding->source + coding->src_bytes; |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6889 if (EQ (coding->src_object, coding->dst_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6890 dst_end = (unsigned char *) src; |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6891 } |
88365 | 6892 } |
6893 *dst++ = c; | |
6894 produced_chars++; | |
6895 } | |
6896 no_more_source: | |
6897 ; | |
6898 } | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6899 else |
88365 | 6900 while (src < src_end) |
6901 { | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
6902 int multibytep = 1; |
88365 | 6903 int c = *src++; |
6904 | |
6905 if (dst >= dst_end - 1) | |
6906 { | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
6907 if (EQ (coding->src_object, coding->dst_object)) |
89483 | 6908 dst_end = (unsigned char *) src; |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
6909 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
|
6910 { |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6911 EMACS_INT offset = src - coding->source; |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6912 EMACS_INT more_bytes; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6913 |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6914 if (EQ (coding->src_object, coding->dst_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6915 more_bytes = ((src_end - src) / 2) + 2; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6916 else |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6917 more_bytes = src_end - src + 2; |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6918 dst = alloc_destination (coding, more_bytes, dst); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
6919 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
|
6920 coding_set_source (coding); |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6921 src = coding->source + offset; |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
6922 src_end = coding->source + coding->src_bytes; |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6923 if (EQ (coding->src_object, coding->dst_object)) |
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
6924 dst_end = (unsigned char *) src; |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
6925 } |
88365 | 6926 } |
6927 EMIT_ONE_BYTE (c); | |
6928 } | |
6929 } | |
6930 else | |
6931 { | |
6932 if (!EQ (coding->src_object, coding->dst_object)) | |
6933 { | |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6934 EMACS_INT require = coding->src_bytes - coding->dst_bytes; |
88365 | 6935 |
6936 if (require > 0) | |
23325
bbd06336cd0c
(check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents:
23315
diff
changeset
|
6937 { |
88365 | 6938 EMACS_INT offset = src - coding->source; |
6939 | |
6940 dst = alloc_destination (coding, require, dst); | |
6941 coding_set_source (coding); | |
6942 src = coding->source + offset; | |
6943 src_end = coding->source + coding->src_bytes; | |
23325
bbd06336cd0c
(check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents:
23315
diff
changeset
|
6944 } |
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
6945 } |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6946 produced_chars = coding->consumed_char; |
88365 | 6947 while (src < src_end) |
92406
c36bda0a03cc
(decode_coding_big5, produce_chars): Fix typos in last
Andreas Schwab <schwab@suse.de>
parents:
92399
diff
changeset
|
6948 *dst++ = *src++; |
92399
fbc07b3a6baf
(decode_coding_utf_8): When eol-type of CODING is
Kenichi Handa <handa@m17n.org>
parents:
92030
diff
changeset
|
6949 } |
88365 | 6950 } |
6951 | |
6952 produced = dst - (coding->destination + coding->produced); | |
90809
3c52757d5f6e
(produce_chars): Don't call insert_from_gap if no
Kenichi Handa <handa@m17n.org>
parents:
90772
diff
changeset
|
6953 if (BUFFERP (coding->dst_object) && produced_chars > 0) |
88365 | 6954 insert_from_gap (produced_chars, produced); |
6955 coding->produced += produced; | |
6956 coding->produced_char += produced_chars; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6957 return carryover; |
88365 | 6958 } |
6959 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6960 /* Compose text in CODING->object according to the annotation data at |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6961 CHARBUF. CHARBUF is an array: |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6962 [ -LENGTH ANNOTATION_MASK NCHARS NBYTES METHOD [ COMPONENTS... ] ] |
88365 | 6963 */ |
6964 | |
6965 static INLINE void | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6966 produce_composition (coding, charbuf, pos) |
88365 | 6967 struct coding_system *coding; |
6968 int *charbuf; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6969 EMACS_INT pos; |
88365 | 6970 { |
6971 int len; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6972 EMACS_INT to; |
88365 | 6973 enum composition_method method; |
6974 Lisp_Object components; | |
6975 | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6976 len = -charbuf[0] - MAX_ANNOTATION_LENGTH; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
6977 to = pos + charbuf[2]; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6978 method = (enum composition_method) (charbuf[4]); |
88365 | 6979 |
6980 if (method == COMPOSITION_RELATIVE) | |
6981 components = Qnil; | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6982 else |
88365 | 6983 { |
6984 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6985 int i, j; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6986 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6987 if (method == COMPOSITION_WITH_RULE) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6988 len = charbuf[2] * 3 - 2; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6989 charbuf += MAX_ANNOTATION_LENGTH; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6990 /* charbuf = [ CHRA ... CHAR] or [ CHAR -2 RULE ... CHAR ] */ |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6991 for (i = j = 0; i < len && charbuf[i] != -1; i++, j++) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6992 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6993 if (charbuf[i] >= 0) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6994 args[j] = make_number (charbuf[i]); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6995 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6996 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6997 i++; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6998 args[j] = make_number (charbuf[i] % 0x100); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
6999 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7000 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7001 components = (i == j ? Fstring (j, args) : Fvector (j, args)); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7002 } |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7003 compose_text (pos, to, components, Qnil, coding->dst_object); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7004 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7005 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7006 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7007 /* Put `charset' property on text in CODING->object according to |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7008 the annotation data at CHARBUF. CHARBUF is an array: |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7009 [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ] |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7010 */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7011 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7012 static INLINE void |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7013 produce_charset (coding, charbuf, pos) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7014 struct coding_system *coding; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7015 int *charbuf; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7016 EMACS_INT pos; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7017 { |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7018 EMACS_INT from = pos - charbuf[2]; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7019 struct charset *charset = CHARSET_FROM_ID (charbuf[3]); |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7020 |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7021 Fput_text_property (make_number (from), make_number (pos), |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7022 Qcharset, CHARSET_NAME (charset), |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7023 coding->dst_object); |
88365 | 7024 } |
7025 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7026 |
88365 | 7027 #define CHARBUF_SIZE 0x4000 |
7028 | |
7029 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
7030 do { \ | |
101943
97c9e9322753
Remove spurious semicolons.
Juanma Barranquero <lekktu@gmail.com>
parents:
101904
diff
changeset
|
7031 int size = CHARBUF_SIZE; \ |
88365 | 7032 \ |
7033 coding->charbuf = NULL; \ | |
7034 while (size > 1024) \ | |
7035 { \ | |
7036 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
7037 if (coding->charbuf) \ | |
7038 break; \ | |
7039 size >>= 1; \ | |
7040 } \ | |
7041 if (! coding->charbuf) \ | |
7042 { \ | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7043 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_MEM); \ |
88365 | 7044 return coding->result; \ |
7045 } \ | |
7046 coding->charbuf_size = size; \ | |
7047 } while (0) | |
7048 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7049 |
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
7050 static void |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7051 produce_annotation (coding, pos) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7052 struct coding_system *coding; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7053 EMACS_INT pos; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7054 { |
88365 | 7055 int *charbuf = coding->charbuf; |
7056 int *charbuf_end = charbuf + coding->charbuf_used; | |
7057 | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7058 if (NILP (coding->dst_object)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7059 return; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7060 |
88365 | 7061 while (charbuf < charbuf_end) |
7062 { | |
7063 if (*charbuf >= 0) | |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7064 pos++, charbuf++; |
88365 | 7065 else |
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
7066 { |
88365 | 7067 int len = -*charbuf; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7068 |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7069 if (len > 2) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7070 switch (charbuf[1]) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7071 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7072 case CODING_ANNOTATE_COMPOSITION_MASK: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7073 produce_composition (coding, charbuf, pos); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7074 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7075 case CODING_ANNOTATE_CHARSET_MASK: |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7076 produce_charset (coding, charbuf, pos); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7077 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7078 } |
88365 | 7079 charbuf += len; |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7080 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7081 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7082 } |
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7083 |
88365 | 7084 /* Decode the data at CODING->src_object into CODING->dst_object. |
7085 CODING->src_object is a buffer, a string, or nil. | |
7086 CODING->dst_object is a buffer. | |
7087 | |
7088 If CODING->src_object is a buffer, it must be the current buffer. | |
7089 In this case, if CODING->src_pos is positive, it is a position of | |
7090 the source text in the buffer, otherwise, the source text is in the | |
7091 gap area of the buffer, and CODING->src_pos specifies the offset of | |
7092 the text from GPT (which must be the same as PT). If this is the | |
7093 same buffer as CODING->dst_object, CODING->src_pos must be | |
7094 negative. | |
7095 | |
90380
4bf7966e0788
(decode_coding): Typo in comment fixed.
Kenichi Handa <handa@m17n.org>
parents:
90378
diff
changeset
|
7096 If CODING->src_object is a string, CODING->src_pos is an index to |
88365 | 7097 that string. |
7098 | |
7099 If CODING->src_object is nil, CODING->source must already point to | |
7100 the non-relocatable memory area. In this case, CODING->src_pos is | |
7101 an offset from CODING->source. | |
7102 | |
7103 The decoded data is inserted at the current point of the buffer | |
7104 CODING->dst_object. | |
7105 */ | |
7106 | |
7107 static int | |
7108 decode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7109 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7110 { |
88365 | 7111 Lisp_Object attrs; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7112 Lisp_Object undo_list; |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
7113 Lisp_Object translation_table; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7114 int carryover; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7115 int i; |
88365 | 7116 |
7117 if (BUFFERP (coding->src_object) | |
7118 && coding->src_pos > 0 | |
7119 && coding->src_pos < GPT | |
7120 && coding->src_pos + coding->src_chars > GPT) | |
7121 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
7122 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7123 undo_list = Qt; |
88365 | 7124 if (BUFFERP (coding->dst_object)) |
7125 { | |
7126 if (current_buffer != XBUFFER (coding->dst_object)) | |
7127 set_buffer_internal (XBUFFER (coding->dst_object)); | |
7128 if (GPT != PT) | |
7129 move_gap_both (PT, PT_BYTE); | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7130 undo_list = current_buffer->undo_list; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7131 current_buffer->undo_list = Qt; |
88365 | 7132 } |
7133 | |
7134 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
|
7135 coding->produced = coding->produced_char = 0; |
88365 | 7136 coding->chars_at_source = 0; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7137 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7138 coding->errors = 0; |
88365 | 7139 |
7140 ALLOC_CONVERSION_WORK_AREA (coding); | |
7141 | |
7142 attrs = CODING_ID_ATTRS (coding->id); | |
89861
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
7143 translation_table = get_translation_table (attrs, 0, NULL); |
88365 | 7144 |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7145 carryover = 0; |
88365 | 7146 do |
7147 { | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7148 EMACS_INT pos = coding->dst_pos + coding->produced_char; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7149 |
88365 | 7150 coding_set_source (coding); |
7151 coding->annotated = 0; | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7152 coding->charbuf_used = carryover; |
88365 | 7153 (*(coding->decoder)) (coding); |
7154 coding_set_destination (coding); | |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7155 carryover = produce_chars (coding, translation_table, 0); |
88365 | 7156 if (coding->annotated) |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7157 produce_annotation (coding, pos); |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7158 for (i = 0; i < carryover; i++) |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7159 coding->charbuf[i] |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7160 = coding->charbuf[coding->charbuf_used - carryover + i]; |
88365 | 7161 } |
7162 while (coding->consumed < coding->src_bytes | |
90336
f0338dbf2276
(decode_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
90327
diff
changeset
|
7163 && (coding->result == CODING_RESULT_SUCCESS |
f0338dbf2276
(decode_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
90327
diff
changeset
|
7164 || coding->result == CODING_RESULT_INVALID_SRC)); |
88365 | 7165 |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7166 if (carryover > 0) |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7167 { |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7168 coding_set_destination (coding); |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7169 coding->charbuf_used = carryover; |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7170 produce_chars (coding, translation_table, 1); |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7171 } |
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7172 |
88365 | 7173 coding->carryover_bytes = 0; |
7174 if (coding->consumed < coding->src_bytes) | |
7175 { | |
7176 int nbytes = coding->src_bytes - coding->consumed; | |
89483 | 7177 const unsigned char *src; |
88365 | 7178 |
7179 coding_set_source (coding); | |
7180 coding_set_destination (coding); | |
7181 src = coding->source + coding->consumed; | |
7182 | |
7183 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
|
7184 { |
88365 | 7185 /* Flush out unprocessed data as binary chars. We are sure |
7186 that the number of data is less than the size of | |
7187 coding->charbuf. */ | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7188 coding->charbuf_used = 0; |
100587
d91e3320dd81
(decode_coding): Clear chars_at_source flag when using charbuf.
Jason Rumney <jasonr@gnu.org>
parents:
100303
diff
changeset
|
7189 coding->chars_at_source = 0; |
d91e3320dd81
(decode_coding): Clear chars_at_source flag when using charbuf.
Jason Rumney <jasonr@gnu.org>
parents:
100303
diff
changeset
|
7190 |
88365 | 7191 while (nbytes-- > 0) |
7192 { | |
7193 int c = *src++; | |
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
7194 |
90243
c59afb15f5c6
(decode_coding): Fix handling of invalid bytes.
Kenichi Handa <handa@m17n.org>
parents:
90231
diff
changeset
|
7195 if (c & 0x80) |
c59afb15f5c6
(decode_coding): Fix handling of invalid bytes.
Kenichi Handa <handa@m17n.org>
parents:
90231
diff
changeset
|
7196 c = BYTE8_TO_CHAR (c); |
c59afb15f5c6
(decode_coding): Fix handling of invalid bytes.
Kenichi Handa <handa@m17n.org>
parents:
90231
diff
changeset
|
7197 coding->charbuf[coding->charbuf_used++] = c; |
88365 | 7198 } |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
7199 produce_chars (coding, Qnil, 1); |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7200 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7201 else |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7202 { |
88365 | 7203 /* Record unprocessed bytes in coding->carryover. We are |
7204 sure that the number of data is less than the size of | |
7205 coding->carryover. */ | |
7206 unsigned char *p = coding->carryover; | |
7207 | |
102115
db1f94e25359
(detect_coding): Don't overflow coding->carryover.
Kenichi Handa <handa@m17n.org>
parents:
102105
diff
changeset
|
7208 if (nbytes > sizeof coding->carryover) |
db1f94e25359
(detect_coding): Don't overflow coding->carryover.
Kenichi Handa <handa@m17n.org>
parents:
102105
diff
changeset
|
7209 nbytes = sizeof coding->carryover; |
88365 | 7210 coding->carryover_bytes = nbytes; |
7211 while (nbytes-- > 0) | |
7212 *p++ = *src++; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7213 } |
88365 | 7214 coding->consumed = coding->src_bytes; |
7215 } | |
7216 | |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
7217 if (! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix) |
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
7218 && !inhibit_eol_conversion) |
90378
0aec08f4c729
(decode_eol): Pay attention to buffer relocation in
Kenichi Handa <handa@m17n.org>
parents:
90363
diff
changeset
|
7219 decode_eol (coding); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7220 if (BUFFERP (coding->dst_object)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7221 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7222 current_buffer->undo_list = undo_list; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7223 record_insert (coding->dst_pos, coding->produced_char); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7224 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7225 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7226 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7227 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7228 |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7229 /* Extract an annotation datum from a composition starting at POS and |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7230 ending before LIMIT of CODING->src_object (buffer or string), store |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7231 the data in BUF, set *STOP to a starting position of the next |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7232 composition (if any) or to LIMIT, and return the address of the |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7233 next element of BUF. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7234 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7235 If such an annotation is not found, set *STOP to a starting |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7236 position of a composition after POS (if any) or to LIMIT, and |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7237 return BUF. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7238 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7239 static INLINE int * |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7240 handle_composition_annotation (pos, limit, coding, buf, stop) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7241 EMACS_INT pos, limit; |
26847 | 7242 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7243 int *buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7244 EMACS_INT *stop; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7245 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7246 EMACS_INT start, end; |
26847 | 7247 Lisp_Object prop; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7248 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7249 if (! find_composition (pos, limit, &start, &end, &prop, coding->src_object) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7250 || end > limit) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7251 *stop = limit; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7252 else if (start > pos) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7253 *stop = start; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7254 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7255 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7256 if (start == pos) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7257 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7258 /* We found a composition. Store the corresponding |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7259 annotation data in BUF. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7260 int *head = buf; |
26847 | 7261 enum composition_method method = COMPOSITION_METHOD (prop); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7262 int nchars = COMPOSITION_LENGTH (prop); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7263 |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7264 ADD_COMPOSITION_DATA (buf, nchars, 0, method); |
26847 | 7265 if (method != COMPOSITION_RELATIVE) |
7266 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7267 Lisp_Object components; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7268 int len, i, i_byte; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7269 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7270 components = COMPOSITION_COMPONENTS (prop); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7271 if (VECTORP (components)) |
26847 | 7272 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7273 len = XVECTOR (components)->size; |
26847 | 7274 for (i = 0; i < len; i++) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7275 *buf++ = XINT (AREF (components, i)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7276 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7277 else if (STRINGP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7278 { |
89483 | 7279 len = SCHARS (components); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7280 i = i_byte = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7281 while (i < len) |
26847 | 7282 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7283 FETCH_STRING_CHAR_ADVANCE (*buf, components, i, i_byte); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7284 buf++; |
26847 | 7285 } |
7286 } | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7287 else if (INTEGERP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7288 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7289 len = 1; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7290 *buf++ = XINT (components); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7291 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7292 else if (CONSP (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7293 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7294 for (len = 0; CONSP (components); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7295 len++, components = XCDR (components)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7296 *buf++ = XINT (XCAR (components)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7297 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7298 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7299 abort (); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7300 *head -= len; |
26847 | 7301 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7302 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7303 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7304 if (find_composition (end, limit, &start, &end, &prop, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7305 coding->src_object) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7306 && end <= limit) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7307 *stop = start; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7308 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7309 *stop = limit; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7310 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7311 return buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7312 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7313 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7314 |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
7315 /* Extract an annotation datum from a text property `charset' at POS of |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7316 CODING->src_object (buffer of string), store the data in BUF, set |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7317 *STOP to the position where the value of `charset' property changes |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7318 (limiting by LIMIT), and return the address of the next element of |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7319 BUF. |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7320 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7321 If the property value is nil, set *STOP to the position where the |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7322 property value is non-nil (limiting by LIMIT), and return BUF. */ |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7323 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7324 static INLINE int * |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7325 handle_charset_annotation (pos, limit, coding, buf, stop) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7326 EMACS_INT pos, limit; |
26847 | 7327 struct coding_system *coding; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7328 int *buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7329 EMACS_INT *stop; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7330 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7331 Lisp_Object val, next; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7332 int id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7333 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7334 val = Fget_text_property (make_number (pos), Qcharset, coding->src_object); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7335 if (! NILP (val) && CHARSETP (val)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7336 id = XINT (CHARSET_SYMBOL_ID (val)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7337 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7338 id = -1; |
89852
b636ae1109c6
(MAX_ANNOTATION_LENGTH): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
89851
diff
changeset
|
7339 ADD_CHARSET_DATA (buf, 0, id); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7340 next = Fnext_single_property_change (make_number (pos), Qcharset, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7341 coding->src_object, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7342 make_number (limit)); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7343 *stop = XINT (next); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7344 return buf; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7345 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7346 |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7347 |
88365 | 7348 static void |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7349 consume_chars (coding, translation_table, max_lookup) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7350 struct coding_system *coding; |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7351 Lisp_Object translation_table; |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7352 int max_lookup; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7353 { |
88365 | 7354 int *buf = coding->charbuf; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7355 int *buf_end = coding->charbuf + coding->charbuf_size; |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7356 const unsigned char *src = coding->source + coding->consumed; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7357 const unsigned char *src_end = coding->source + coding->src_bytes; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7358 EMACS_INT pos = coding->src_pos + coding->consumed_char; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7359 EMACS_INT end_pos = coding->src_pos + coding->src_chars; |
88365 | 7360 int multibytep = coding->src_multibyte; |
7361 Lisp_Object eol_type; | |
7362 int c; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7363 EMACS_INT stop, stop_composition, stop_charset; |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7364 int *lookup_buf = NULL; |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7365 |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7366 if (! NILP (translation_table)) |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7367 lookup_buf = alloca (sizeof (int) * max_lookup); |
88365 | 7368 |
102334
7baaea85626e
(decode_coding_utf_8, decode_coding_utf_16, decode_coding_emacs_mule,
Eli Zaretskii <eliz@gnu.org>
parents:
102327
diff
changeset
|
7369 eol_type = inhibit_eol_conversion ? Qunix : CODING_ID_EOL_TYPE (coding->id); |
88365 | 7370 if (VECTORP (eol_type)) |
7371 eol_type = Qunix; | |
7372 | |
7373 /* Note: composition handling is not yet implemented. */ | |
7374 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
7375 | |
89562
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7376 if (NILP (coding->src_object)) |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7377 stop = stop_composition = stop_charset = end_pos; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7378 else |
89562
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7379 { |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7380 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK) |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7381 stop = stop_composition = pos; |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7382 else |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7383 stop = stop_composition = end_pos; |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7384 if (coding->common_flags & CODING_ANNOTATE_CHARSET_MASK) |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7385 stop = stop_charset = pos; |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7386 else |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7387 stop_charset = end_pos; |
12fbcfebb9ad
(consume_chars): If coding->src_object is nil, don't check annotation.
Kenichi Handa <handa@m17n.org>
parents:
89545
diff
changeset
|
7388 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7389 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7390 /* Compensate for CRLF and conversion. */ |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7391 buf_end -= 1 + MAX_ANNOTATION_LENGTH; |
88365 | 7392 while (buf < buf_end) |
7393 { | |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7394 Lisp_Object trans; |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7395 |
88365 | 7396 if (pos == stop) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7397 { |
88365 | 7398 if (pos == end_pos) |
7399 break; | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7400 if (pos == stop_composition) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7401 buf = handle_composition_annotation (pos, end_pos, coding, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7402 buf, &stop_composition); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7403 if (pos == stop_charset) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7404 buf = handle_charset_annotation (pos, end_pos, coding, |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7405 buf, &stop_charset); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7406 stop = (stop_composition < stop_charset |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
7407 ? stop_composition : stop_charset); |
88365 | 7408 } |
7409 | |
7410 if (! multibytep) | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7411 { |
89462
4e359ebf3984
(decode_coding_iso_2022): Fix handling of invalid
Kenichi Handa <handa@m17n.org>
parents:
89448
diff
changeset
|
7412 EMACS_INT bytes; |
4e359ebf3984
(decode_coding_iso_2022): Fix handling of invalid
Kenichi Handa <handa@m17n.org>
parents:
89448
diff
changeset
|
7413 |
89933
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
7414 if (coding->encoder == encode_coding_raw_text) |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
7415 c = *src++, pos++; |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
7416 else if ((bytes = MULTIBYTE_LENGTH (src, src_end)) > 0) |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
7417 c = STRING_CHAR_ADVANCE_NO_UNIFY (src), pos += bytes; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7418 else |
89917
1763eef5ad02
(encode_coding_utf_8): Fix handling of raw-byte char.
Kenichi Handa <handa@m17n.org>
parents:
89905
diff
changeset
|
7419 c = BYTE8_TO_CHAR (*src), src++, pos++; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7420 } |
88365 | 7421 else |
92992
49c4ea77b83a
(CHAR_STRING_ADVANCE_NO_UNIFY)
Kenichi Handa <handa@m17n.org>
parents:
92458
diff
changeset
|
7422 c = STRING_CHAR_ADVANCE_NO_UNIFY (src), pos++; |
88365 | 7423 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) |
7424 c = '\n'; | |
7425 if (! EQ (eol_type, Qunix)) | |
7426 { | |
7427 if (c == '\n') | |
32443
57fa108c491f
(code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents:
31458
diff
changeset
|
7428 { |
88365 | 7429 if (EQ (eol_type, Qdos)) |
7430 *buf++ = '\r'; | |
7431 else | |
7432 c = '\r'; | |
32443
57fa108c491f
(code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents:
31458
diff
changeset
|
7433 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7434 } |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7435 |
89858
23cb9ed79225
(get_translation_table): Declare it as Lisp_Object.
Kenichi Handa <handa@m17n.org>
parents:
89856
diff
changeset
|
7436 trans = Qnil; |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7437 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans); |
89858
23cb9ed79225
(get_translation_table): Declare it as Lisp_Object.
Kenichi Handa <handa@m17n.org>
parents:
89856
diff
changeset
|
7438 if (NILP (trans)) |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7439 *buf++ = c; |
26847 | 7440 else |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7441 { |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7442 int from_nchars = 1, to_nchars = 1; |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7443 int *lookup_buf_end; |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7444 const unsigned char *p = src; |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7445 int i; |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7446 |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7447 lookup_buf[0] = c; |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7448 for (i = 1; i < max_lookup && p < src_end; i++) |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7449 lookup_buf[i] = STRING_CHAR_ADVANCE (p); |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7450 lookup_buf_end = lookup_buf + i; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7451 trans = get_translation (trans, lookup_buf, lookup_buf_end); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7452 if (INTEGERP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7453 c = XINT (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7454 else if (CONSP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7455 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7456 from_nchars = ASIZE (XCAR (trans)); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7457 trans = XCDR (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7458 if (INTEGERP (trans)) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7459 c = XINT (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7460 else |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7461 { |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7462 to_nchars = ASIZE (trans); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7463 if (buf + to_nchars > buf_end) |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7464 break; |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7465 c = XINT (AREF (trans, 0)); |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7466 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7467 } |
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7468 else |
23881
20d595402dea
(DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents:
23564
diff
changeset
|
7469 break; |
102422
82f82b92314e
(CODING_ISO_CMP_STATUS): New macro.
Kenichi Handa <handa@m17n.org>
parents:
102334
diff
changeset
|
7470 *buf++ = c; |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7471 for (i = 1; i < to_nchars; i++) |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7472 *buf++ = XINT (AREF (trans, i)); |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7473 for (i = 1; i < from_nchars; i++, pos++) |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7474 src += MULTIBYTE_LENGTH_NO_CHECK (src); |
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
7475 } |
88365 | 7476 } |
7477 | |
7478 coding->consumed = src - coding->source; | |
7479 coding->consumed_char = pos - coding->src_pos; | |
7480 coding->charbuf_used = buf - coding->charbuf; | |
7481 coding->chars_at_source = 0; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7482 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7483 |
88365 | 7484 |
7485 /* Encode the text at CODING->src_object into CODING->dst_object. | |
7486 CODING->src_object is a buffer or a string. | |
7487 CODING->dst_object is a buffer or nil. | |
7488 | |
7489 If CODING->src_object is a buffer, it must be the current buffer. | |
7490 In this case, if CODING->src_pos is positive, it is a position of | |
7491 the source text in the buffer, otherwise. the source text is in the | |
7492 gap area of the buffer, and coding->src_pos specifies the offset of | |
7493 the text from GPT (which must be the same as PT). If this is the | |
7494 same buffer as CODING->dst_object, CODING->src_pos must be | |
7495 negative and CODING should not have `pre-write-conversion'. | |
7496 | |
7497 If CODING->src_object is a string, CODING should not have | |
7498 `pre-write-conversion'. | |
7499 | |
7500 If CODING->dst_object is a buffer, the encoded data is inserted at | |
7501 the current point of that buffer. | |
7502 | |
7503 If CODING->dst_object is nil, the encoded data is placed at the | |
7504 memory area specified by CODING->destination. */ | |
7505 | |
7506 static int | |
7507 encode_coding (coding) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7508 struct coding_system *coding; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7509 { |
88365 | 7510 Lisp_Object attrs; |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
7511 Lisp_Object translation_table; |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7512 int max_lookup; |
88365 | 7513 |
7514 attrs = CODING_ID_ATTRS (coding->id); | |
89933
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
7515 if (coding->encoder == encode_coding_raw_text) |
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
7516 translation_table = Qnil, max_lookup = 0; |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
7517 else |
89933
48af0ea7d387
(setup_coding_system): Set coding->common_flags
Kenichi Handa <handa@m17n.org>
parents:
89924
diff
changeset
|
7518 translation_table = get_translation_table (attrs, 1, &max_lookup); |
88365 | 7519 |
7520 if (BUFFERP (coding->dst_object)) | |
7521 { | |
7522 set_buffer_internal (XBUFFER (coding->dst_object)); | |
7523 coding->dst_multibyte | |
7524 = ! NILP (current_buffer->enable_multibyte_characters); | |
7525 } | |
7526 | |
7527 coding->consumed = coding->consumed_char = 0; | |
7528 coding->produced = coding->produced_char = 0; | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7529 record_conversion_result (coding, CODING_RESULT_SUCCESS); |
88365 | 7530 coding->errors = 0; |
7531 | |
7532 ALLOC_CONVERSION_WORK_AREA (coding); | |
7533 | |
7534 do { | |
7535 coding_set_source (coding); | |
89859
b706c5ee6492
(get_translation_table): New arg max_lookup. Caller changed.
Kenichi Handa <handa@m17n.org>
parents:
89858
diff
changeset
|
7536 consume_chars (coding, translation_table, max_lookup); |
88365 | 7537 coding_set_destination (coding); |
7538 (*(coding->encoder)) (coding); | |
7539 } while (coding->consumed_char < coding->src_chars); | |
7540 | |
90809
3c52757d5f6e
(produce_chars): Don't call insert_from_gap if no
Kenichi Handa <handa@m17n.org>
parents:
90772
diff
changeset
|
7541 if (BUFFERP (coding->dst_object) && coding->produced_char > 0) |
88365 | 7542 insert_from_gap (coding->produced_char, coding->produced); |
7543 | |
7544 return (coding->result); | |
7545 } | |
7546 | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7547 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7548 /* Name (or base name) of work buffer for code conversion. */ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7549 static Lisp_Object Vcode_conversion_workbuf_name; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7550 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7551 /* A working buffer used by the top level conversion. Once it is |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7552 created, it is never destroyed. It has the name |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7553 Vcode_conversion_workbuf_name. The other working buffers are |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7554 destroyed after the use is finished, and their names are modified |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7555 versions of Vcode_conversion_workbuf_name. */ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7556 static Lisp_Object Vcode_conversion_reused_workbuf; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7557 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7558 /* 1 iff Vcode_conversion_reused_workbuf is already in use. */ |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7559 static int reused_workbuf_in_use; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7560 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7561 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7562 /* Return a working buffer of code convesion. MULTIBYTE specifies the |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7563 multibyteness of returning buffer. */ |
88365 | 7564 |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
7565 static Lisp_Object |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7566 make_conversion_work_buffer (multibyte) |
89863
428fc37b2ae6
Add many prototypes for static functions.
Kenichi Handa <handa@m17n.org>
parents:
89861
diff
changeset
|
7567 int multibyte; |
88365 | 7568 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7569 Lisp_Object name, workbuf; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7570 struct buffer *current; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7571 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7572 if (reused_workbuf_in_use++) |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7573 { |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7574 name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7575 workbuf = Fget_buffer_create (name); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7576 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7577 else |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7578 { |
99074
10cd979d05ca
(make_conversion_work_buffer): Check that Vcode_conversion_reused_workbuf
Noah Friedman <friedman@splode.com>
parents:
98992
diff
changeset
|
7579 if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) |
98186
1cfa973fde14
(make_conversion_work_buffer): Avoid calling
Kenichi Handa <handa@m17n.org>
parents:
96571
diff
changeset
|
7580 Vcode_conversion_reused_workbuf |
1cfa973fde14
(make_conversion_work_buffer): Avoid calling
Kenichi Handa <handa@m17n.org>
parents:
96571
diff
changeset
|
7581 = Fget_buffer_create (Vcode_conversion_workbuf_name); |
1cfa973fde14
(make_conversion_work_buffer): Avoid calling
Kenichi Handa <handa@m17n.org>
parents:
96571
diff
changeset
|
7582 workbuf = Vcode_conversion_reused_workbuf; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7583 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7584 current = current_buffer; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7585 set_buffer_internal (XBUFFER (workbuf)); |
100262
46114a72fb0e
(make_conversion_work_buffer): Disable buffer modification hooks in
Chong Yidong <cyd@stupidchicken.com>
parents:
100176
diff
changeset
|
7586 /* We can't allow modification hooks to run in the work buffer. For |
46114a72fb0e
(make_conversion_work_buffer): Disable buffer modification hooks in
Chong Yidong <cyd@stupidchicken.com>
parents:
100176
diff
changeset
|
7587 instance, directory_files_internal assumes that file decoding |
46114a72fb0e
(make_conversion_work_buffer): Disable buffer modification hooks in
Chong Yidong <cyd@stupidchicken.com>
parents:
100176
diff
changeset
|
7588 doesn't compile new regexps. */ |
46114a72fb0e
(make_conversion_work_buffer): Disable buffer modification hooks in
Chong Yidong <cyd@stupidchicken.com>
parents:
100176
diff
changeset
|
7589 Fset (Fmake_local_variable (Qinhibit_modification_hooks), Qt); |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
7590 Ferase_buffer (); |
88365 | 7591 current_buffer->undo_list = Qt; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7592 current_buffer->enable_multibyte_characters = multibyte ? Qt : Qnil; |
88365 | 7593 set_buffer_internal (current); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7594 return workbuf; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7595 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7596 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7597 |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7598 static Lisp_Object |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7599 code_conversion_restore (arg) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7600 Lisp_Object arg; |
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
7601 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7602 Lisp_Object current, workbuf; |
90263
80fb4c061e99
(code_conversion_restore): GCPRO arg.
Kenichi Handa <handa@m17n.org>
parents:
90261
diff
changeset
|
7603 struct gcpro gcpro1; |
80fb4c061e99
(code_conversion_restore): GCPRO arg.
Kenichi Handa <handa@m17n.org>
parents:
90261
diff
changeset
|
7604 |
80fb4c061e99
(code_conversion_restore): GCPRO arg.
Kenichi Handa <handa@m17n.org>
parents:
90261
diff
changeset
|
7605 GCPRO1 (arg); |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7606 current = XCAR (arg); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7607 workbuf = XCDR (arg); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7608 if (! NILP (workbuf)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7609 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7610 if (EQ (workbuf, Vcode_conversion_reused_workbuf)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7611 reused_workbuf_in_use = 0; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7612 else if (! NILP (Fbuffer_live_p (workbuf))) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7613 Fkill_buffer (workbuf); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7614 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7615 set_buffer_internal (XBUFFER (current)); |
90263
80fb4c061e99
(code_conversion_restore): GCPRO arg.
Kenichi Handa <handa@m17n.org>
parents:
90261
diff
changeset
|
7616 UNGCPRO; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7617 return Qnil; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7618 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7619 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7620 Lisp_Object |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7621 code_conversion_save (with_work_buf, multibyte) |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7622 int with_work_buf, multibyte; |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7623 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7624 Lisp_Object workbuf = Qnil; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7625 |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7626 if (with_work_buf) |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7627 workbuf = make_conversion_work_buffer (multibyte); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7628 record_unwind_protect (code_conversion_restore, |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7629 Fcons (Fcurrent_buffer (), workbuf)); |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7630 return workbuf; |
17052 | 7631 } |
7632 | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7633 int |
88365 | 7634 decode_coding_gap (coding, chars, bytes) |
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
7635 struct coding_system *coding; |
88365 | 7636 EMACS_INT chars, bytes; |
7637 { | |
7638 int count = specpdl_ptr - specpdl; | |
89448
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7639 Lisp_Object attrs; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7640 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7641 code_conversion_save (0, 0); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7642 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7643 coding->src_object = Fcurrent_buffer (); |
88365 | 7644 coding->src_chars = chars; |
7645 coding->src_bytes = bytes; | |
7646 coding->src_pos = -chars; | |
7647 coding->src_pos_byte = -bytes; | |
7648 coding->src_multibyte = chars < bytes; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7649 coding->dst_object = coding->src_object; |
88365 | 7650 coding->dst_pos = PT; |
7651 coding->dst_pos_byte = PT_BYTE; | |
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
7652 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
88365 | 7653 |
7654 if (CODING_REQUIRE_DETECTION (coding)) | |
7655 detect_coding (coding); | |
89483 | 7656 |
90350
60eaefb08cf7
(DECODE_COMPOSITION_START): If the source is short, set
Kenichi Handa <handa@m17n.org>
parents:
90346
diff
changeset
|
7657 coding->mode |= CODING_MODE_LAST_BLOCK; |
90772
b15334b4a9c3
(coding_alloc_by_making_gap): New arg offset.
Kenichi Handa <handa@m17n.org>
parents:
90737
diff
changeset
|
7658 current_buffer->text->inhibit_shrinking = 1; |
88365 | 7659 decode_coding (coding); |
90772
b15334b4a9c3
(coding_alloc_by_making_gap): New arg offset.
Kenichi Handa <handa@m17n.org>
parents:
90737
diff
changeset
|
7660 current_buffer->text->inhibit_shrinking = 0; |
88365 | 7661 |
89448
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7662 attrs = CODING_ID_ATTRS (coding->id); |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7663 if (! NILP (CODING_ATTR_POST_READ (attrs))) |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7664 { |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7665 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7666 Lisp_Object val; |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7667 |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7668 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7669 val = call1 (CODING_ATTR_POST_READ (attrs), |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7670 make_number (coding->produced_char)); |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7671 CHECK_NATNUM (val); |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7672 coding->produced_char += Z - prev_Z; |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7673 coding->produced += Z_BYTE - prev_Z_BYTE; |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7674 } |
de8b460070cc
(setup_coding_system): If coding has
Kenichi Handa <handa@m17n.org>
parents:
89446
diff
changeset
|
7675 |
88365 | 7676 unbind_to (count, Qnil); |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7677 return coding->result; |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7678 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7679 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7680 int |
88365 | 7681 encode_coding_gap (coding, chars, bytes) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7682 struct coding_system *coding; |
88365 | 7683 EMACS_INT chars, bytes; |
26847 | 7684 { |
88365 | 7685 int count = specpdl_ptr - specpdl; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7686 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7687 code_conversion_save (0, 0); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7688 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7689 coding->src_object = Fcurrent_buffer (); |
88365 | 7690 coding->src_chars = chars; |
7691 coding->src_bytes = bytes; | |
7692 coding->src_pos = -chars; | |
7693 coding->src_pos_byte = -bytes; | |
7694 coding->src_multibyte = chars < bytes; | |
7695 coding->dst_object = coding->src_object; | |
7696 coding->dst_pos = PT; | |
7697 coding->dst_pos_byte = PT_BYTE; | |
7698 | |
7699 encode_coding (coding); | |
7700 | |
7701 unbind_to (count, Qnil); | |
7702 return coding->result; | |
26847 | 7703 } |
7704 | |
88365 | 7705 |
7706 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
7707 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
7708 | |
7709 SRC_OBJECT is a buffer, a string, or Qnil. | |
7710 | |
7711 If it is a buffer, the text is at point of the buffer. FROM and TO | |
7712 are positions in the buffer. | |
7713 | |
7714 If it is a string, the text is at the beginning of the string. | |
7715 FROM and TO are indices to the string. | |
7716 | |
7717 If it is nil, the text is at coding->source. FROM and TO are | |
7718 indices to coding->source. | |
7719 | |
7720 DST_OBJECT is a buffer, Qt, or Qnil. | |
7721 | |
7722 If it is a buffer, the decoded text is inserted at point of the | |
7723 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
7724 is deleted. | |
7725 | |
7726 If it is Qt, a string is made from the decoded text, and | |
7727 set in CODING->dst_object. | |
7728 | |
7729 If it is Qnil, the decoded text is stored at CODING->destination. | |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
7730 The caller must allocate CODING->dst_bytes bytes at |
88365 | 7731 CODING->destination by xmalloc. If the decoded text is longer than |
7732 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
7733 */ | |
26847 | 7734 |
7735 void | |
88365 | 7736 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
7737 dst_object) | |
26847 | 7738 struct coding_system *coding; |
88365 | 7739 Lisp_Object src_object; |
7740 EMACS_INT from, from_byte, to, to_byte; | |
7741 Lisp_Object dst_object; | |
26847 | 7742 { |
88365 | 7743 int count = specpdl_ptr - specpdl; |
7744 unsigned char *destination; | |
7745 EMACS_INT dst_bytes; | |
7746 EMACS_INT chars = to - from; | |
7747 EMACS_INT bytes = to_byte - from_byte; | |
7748 Lisp_Object attrs; | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7749 int saved_pt = -1, saved_pt_byte; |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7750 int need_marker_adjustment = 0; |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7751 Lisp_Object old_deactivate_mark; |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7752 |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7753 old_deactivate_mark = Vdeactivate_mark; |
88365 | 7754 |
7755 if (NILP (dst_object)) | |
7756 { | |
7757 destination = coding->destination; | |
7758 dst_bytes = coding->dst_bytes; | |
7759 } | |
7760 | |
7761 coding->src_object = src_object; | |
7762 coding->src_chars = chars; | |
7763 coding->src_bytes = bytes; | |
7764 coding->src_multibyte = chars < bytes; | |
7765 | |
7766 if (STRINGP (src_object)) | |
7767 { | |
7768 coding->src_pos = from; | |
7769 coding->src_pos_byte = from_byte; | |
7770 } | |
7771 else if (BUFFERP (src_object)) | |
7772 { | |
7773 set_buffer_internal (XBUFFER (src_object)); | |
7774 if (from != GPT) | |
7775 move_gap_both (from, from_byte); | |
7776 if (EQ (src_object, dst_object)) | |
26847 | 7777 { |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7778 struct Lisp_Marker *tail; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7779 |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7780 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) |
26847 | 7781 { |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7782 tail->need_adjustment |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7783 = tail->charpos == (tail->insertion_type ? from : to); |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7784 need_marker_adjustment |= tail->need_adjustment; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7785 } |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7786 saved_pt = PT, saved_pt_byte = PT_BYTE; |
88365 | 7787 TEMP_SET_PT_BOTH (from, from_byte); |
92458
5f5f07a5c076
(decode_coding_object): Inhibit gap shrinking while
Andreas Schwab <schwab@suse.de>
parents:
92406
diff
changeset
|
7788 current_buffer->text->inhibit_shrinking = 1; |
88365 | 7789 del_range_both (from, from_byte, to, to_byte, 1); |
7790 coding->src_pos = -chars; | |
7791 coding->src_pos_byte = -bytes; | |
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
7792 } |
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
7793 else |
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
7794 { |
88365 | 7795 coding->src_pos = from; |
7796 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
|
7797 } |
88365 | 7798 } |
7799 | |
7800 if (CODING_REQUIRE_DETECTION (coding)) | |
7801 detect_coding (coding); | |
7802 attrs = CODING_ID_ATTRS (coding->id); | |
7803 | |
89418
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
7804 if (EQ (dst_object, Qt) |
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
7805 || (! NILP (CODING_ATTR_POST_READ (attrs)) |
a9c2b3712863
(coding_set_source): Fix for the case that the current
Kenichi Handa <handa@m17n.org>
parents:
89404
diff
changeset
|
7806 && NILP (dst_object))) |
88365 | 7807 { |
93321
c3fe9ef79b56
(decode_coding_object): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93197
diff
changeset
|
7808 coding->dst_multibyte = !CODING_FOR_UNIBYTE (coding); |
c3fe9ef79b56
(decode_coding_object): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93197
diff
changeset
|
7809 coding->dst_object = code_conversion_save (1, coding->dst_multibyte); |
88365 | 7810 coding->dst_pos = BEG; |
7811 coding->dst_pos_byte = BEG_BYTE; | |
7812 } | |
7813 else if (BUFFERP (dst_object)) | |
7814 { | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7815 code_conversion_save (0, 0); |
88365 | 7816 coding->dst_object = dst_object; |
7817 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
7818 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
7819 coding->dst_multibyte | |
7820 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
7821 } | |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
7822 else |
29172
46ad5a027334
(run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents:
29093
diff
changeset
|
7823 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7824 code_conversion_save (0, 0); |
88365 | 7825 coding->dst_object = Qnil; |
93322
3b82aab9d8fc
(decode_coding_object): Revert part of last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93321
diff
changeset
|
7826 /* Most callers presume this will return a multibyte result, and they |
3b82aab9d8fc
(decode_coding_object): Revert part of last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93321
diff
changeset
|
7827 won't use `binary' or `raw-text' anyway, so let's not worry about |
3b82aab9d8fc
(decode_coding_object): Revert part of last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93321
diff
changeset
|
7828 CODING_FOR_UNIBYTE. */ |
93323
06e93ffa2e9f
(decode_coding_object): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93322
diff
changeset
|
7829 coding->dst_multibyte = 1; |
88365 | 7830 } |
7831 | |
7832 decode_coding (coding); | |
7833 | |
7834 if (BUFFERP (coding->dst_object)) | |
7835 set_buffer_internal (XBUFFER (coding->dst_object)); | |
7836 | |
7837 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
7838 { | |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7839 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
88365 | 7840 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; |
7841 Lisp_Object val; | |
7842 | |
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
7843 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7844 GCPRO5 (coding->src_object, coding->dst_object, src_object, dst_object, |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7845 old_deactivate_mark); |
90131
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7846 val = safe_call1 (CODING_ATTR_POST_READ (attrs), |
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7847 make_number (coding->produced_char)); |
88365 | 7848 UNGCPRO; |
7849 CHECK_NATNUM (val); | |
7850 coding->produced_char += Z - prev_Z; | |
7851 coding->produced += Z_BYTE - prev_Z_BYTE; | |
7852 } | |
7853 | |
7854 if (EQ (dst_object, Qt)) | |
7855 { | |
7856 coding->dst_object = Fbuffer_string (); | |
7857 } | |
7858 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
7859 { | |
7860 set_buffer_internal (XBUFFER (coding->dst_object)); | |
7861 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
|
7862 { |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7863 destination = xrealloc (destination, coding->produced); |
88365 | 7864 if (! destination) |
26847 | 7865 { |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7866 record_conversion_result (coding, |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7867 CODING_RESULT_INSUFFICIENT_DST); |
88365 | 7868 unbind_to (count, Qnil); |
7869 return; | |
26847 | 7870 } |
88365 | 7871 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
7872 move_gap_both (BEGV, BEGV_BYTE); | |
7873 bcopy (BEGV_ADDR, destination, coding->produced); | |
7874 coding->destination = destination; | |
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
7875 } |
88365 | 7876 } |
7877 | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7878 if (saved_pt >= 0) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7879 { |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7880 /* This is the case of: |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7881 (BUFFERP (src_object) && EQ (src_object, dst_object)) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7882 As we have moved PT while replacing the original buffer |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7883 contents, we must recover it now. */ |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7884 set_buffer_internal (XBUFFER (src_object)); |
92458
5f5f07a5c076
(decode_coding_object): Inhibit gap shrinking while
Andreas Schwab <schwab@suse.de>
parents:
92406
diff
changeset
|
7885 current_buffer->text->inhibit_shrinking = 0; |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7886 if (saved_pt < from) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7887 TEMP_SET_PT_BOTH (saved_pt, saved_pt_byte); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7888 else if (saved_pt < from + chars) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7889 TEMP_SET_PT_BOTH (from, from_byte); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7890 else if (! NILP (current_buffer->enable_multibyte_characters)) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7891 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars), |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7892 saved_pt_byte + (coding->produced - bytes)); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7893 else |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7894 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes), |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7895 saved_pt_byte + (coding->produced - bytes)); |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7896 |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7897 if (need_marker_adjustment) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7898 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7899 struct Lisp_Marker *tail; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7900 |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7901 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7902 if (tail->need_adjustment) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7903 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7904 tail->need_adjustment = 0; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7905 if (tail->insertion_type) |
26847 | 7906 { |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7907 tail->bytepos = from_byte; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7908 tail->charpos = from; |
26847 | 7909 } |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7910 else |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7911 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7912 tail->bytepos = from_byte + coding->produced; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7913 tail->charpos |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7914 = (NILP (current_buffer->enable_multibyte_characters) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7915 ? tail->bytepos : from + coding->produced_char); |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7916 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7917 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7918 } |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7919 } |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7920 |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7921 Vdeactivate_mark = old_deactivate_mark; |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
7922 unbind_to (count, coding->dst_object); |
88365 | 7923 } |
7924 | |
26847 | 7925 |
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
7926 void |
88365 | 7927 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
7928 dst_object) | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7929 struct coding_system *coding; |
88365 | 7930 Lisp_Object src_object; |
7931 EMACS_INT from, from_byte, to, to_byte; | |
7932 Lisp_Object dst_object; | |
7933 { | |
7934 int count = specpdl_ptr - specpdl; | |
7935 EMACS_INT chars = to - from; | |
7936 EMACS_INT bytes = to_byte - from_byte; | |
7937 Lisp_Object attrs; | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7938 int saved_pt = -1, saved_pt_byte; |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7939 int need_marker_adjustment = 0; |
90231
8be9e4c6d687
(encode_coding_object): If a pre-write-conversion
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
7940 int kill_src_buffer = 0; |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7941 Lisp_Object old_deactivate_mark; |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7942 |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7943 old_deactivate_mark = Vdeactivate_mark; |
88365 | 7944 |
7945 coding->src_object = src_object; | |
7946 coding->src_chars = chars; | |
7947 coding->src_bytes = bytes; | |
7948 coding->src_multibyte = chars < bytes; | |
7949 | |
7950 attrs = CODING_ID_ATTRS (coding->id); | |
7951 | |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7952 if (EQ (src_object, dst_object)) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7953 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7954 struct Lisp_Marker *tail; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7955 |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7956 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7957 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7958 tail->need_adjustment |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7959 = tail->charpos == (tail->insertion_type ? from : to); |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7960 need_marker_adjustment |= tail->need_adjustment; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7961 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7962 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
7963 |
88365 | 7964 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
|
7965 { |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
7966 coding->src_object = code_conversion_save (1, coding->src_multibyte); |
88365 | 7967 set_buffer_internal (XBUFFER (coding->src_object)); |
7968 if (STRINGP (src_object)) | |
7969 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
7970 else if (BUFFERP (src_object)) | |
7971 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7972 else |
88365 | 7973 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); |
7974 | |
7975 if (EQ (src_object, dst_object)) | |
7976 { | |
7977 set_buffer_internal (XBUFFER (src_object)); | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
7978 saved_pt = PT, saved_pt_byte = PT_BYTE; |
88365 | 7979 del_range_both (from, from_byte, to, to_byte, 1); |
7980 set_buffer_internal (XBUFFER (coding->src_object)); | |
7981 } | |
7982 | |
90131
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7983 { |
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7984 Lisp_Object args[3]; |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7985 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7986 |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7987 GCPRO5 (coding->src_object, coding->dst_object, src_object, dst_object, |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7988 old_deactivate_mark); |
90131
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7989 args[0] = CODING_ATTR_PRE_WRITE (attrs); |
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7990 args[1] = make_number (BEG); |
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7991 args[2] = make_number (Z); |
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7992 safe_call (3, args); |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
7993 UNGCPRO; |
90131
503a3c779486
(decode_coding_object): Use safe_call1 instead of call1.
Kenichi Handa <handa@m17n.org>
parents:
90127
diff
changeset
|
7994 } |
90231
8be9e4c6d687
(encode_coding_object): If a pre-write-conversion
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
7995 if (XBUFFER (coding->src_object) != current_buffer) |
8be9e4c6d687
(encode_coding_object): If a pre-write-conversion
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
7996 kill_src_buffer = 1; |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
7997 coding->src_object = Fcurrent_buffer (); |
88365 | 7998 if (BEG != GPT) |
7999 move_gap_both (BEG, BEG_BYTE); | |
8000 coding->src_chars = Z - BEG; | |
8001 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
8002 coding->src_pos = BEG; | |
8003 coding->src_pos_byte = BEG_BYTE; | |
8004 coding->src_multibyte = Z < Z_BYTE; | |
8005 } | |
8006 else if (STRINGP (src_object)) | |
8007 { | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8008 code_conversion_save (0, 0); |
88365 | 8009 coding->src_pos = from; |
8010 coding->src_pos_byte = from_byte; | |
8011 } | |
8012 else if (BUFFERP (src_object)) | |
8013 { | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8014 code_conversion_save (0, 0); |
88365 | 8015 set_buffer_internal (XBUFFER (src_object)); |
8016 if (EQ (src_object, dst_object)) | |
8017 { | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8018 saved_pt = PT, saved_pt_byte = PT_BYTE; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8019 coding->src_object = del_range_1 (from, to, 1, 1); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8020 coding->src_pos = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8021 coding->src_pos_byte = 0; |
88365 | 8022 } |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
8023 else |
42105
09cc243e2d14
(code_convert_region): Update coding->cmp_data->char_offset
Richard M. Stallman <rms@gnu.org>
parents:
42104
diff
changeset
|
8024 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8025 if (from < GPT && to >= GPT) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8026 move_gap_both (from, from_byte); |
88365 | 8027 coding->src_pos = from; |
8028 coding->src_pos_byte = from_byte; | |
8029 } | |
64308
93129de4b8a4
(code_convert_region_unwind): ARG is changed to a cons.
Kenichi Handa <handa@m17n.org>
parents:
64251
diff
changeset
|
8030 } |
93129de4b8a4
(code_convert_region_unwind): ARG is changed to a cons.
Kenichi Handa <handa@m17n.org>
parents:
64251
diff
changeset
|
8031 else |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8032 code_conversion_save (0, 0); |
88365 | 8033 |
8034 if (BUFFERP (dst_object)) | |
8035 { | |
8036 coding->dst_object = dst_object; | |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8037 if (EQ (src_object, dst_object)) |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8038 { |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8039 coding->dst_pos = from; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8040 coding->dst_pos_byte = from_byte; |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8041 } |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8042 else |
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8043 { |
95353
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8044 struct buffer *current = current_buffer; |
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8045 |
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8046 set_buffer_temp (XBUFFER (dst_object)); |
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8047 coding->dst_pos = PT; |
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8048 coding->dst_pos_byte = PT_BYTE; |
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8049 move_gap_both (coding->dst_pos, coding->dst_pos_byte); |
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
8050 set_buffer_temp (current); |
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
8051 } |
88365 | 8052 coding->dst_multibyte |
8053 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
8054 } | |
8055 else if (EQ (dst_object, Qt)) | |
8056 { | |
8057 coding->dst_object = Qnil; | |
8058 coding->dst_bytes = coding->src_chars; | |
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
8059 if (coding->dst_bytes == 0) |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
8060 coding->dst_bytes = 1; |
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
8061 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
88365 | 8062 coding->dst_multibyte = 0; |
65506
f376635f5061
(code_convert_region_unwind): Argument format changed.
Kenichi Handa <handa@m17n.org>
parents:
64770
diff
changeset
|
8063 } |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
8064 else |
29172
46ad5a027334
(run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents:
29093
diff
changeset
|
8065 { |
88365 | 8066 coding->dst_object = Qnil; |
8067 coding->dst_multibyte = 0; | |
8068 } | |
8069 | |
8070 encode_coding (coding); | |
8071 | |
8072 if (EQ (dst_object, Qt)) | |
8073 { | |
8074 if (BUFFERP (coding->dst_object)) | |
8075 coding->dst_object = Fbuffer_string (); | |
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
8076 else |
88365 | 8077 { |
8078 coding->dst_object | |
8079 = make_unibyte_string ((char *) coding->destination, | |
8080 coding->produced); | |
8081 xfree (coding->destination); | |
8082 } | |
8083 } | |
8084 | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8085 if (saved_pt >= 0) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8086 { |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8087 /* This is the case of: |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8088 (BUFFERP (src_object) && EQ (src_object, dst_object)) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8089 As we have moved PT while replacing the original buffer |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8090 contents, we must recover it now. */ |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8091 set_buffer_internal (XBUFFER (src_object)); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8092 if (saved_pt < from) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8093 TEMP_SET_PT_BOTH (saved_pt, saved_pt_byte); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8094 else if (saved_pt < from + chars) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8095 TEMP_SET_PT_BOTH (from, from_byte); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8096 else if (! NILP (current_buffer->enable_multibyte_characters)) |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8097 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars), |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8098 saved_pt_byte + (coding->produced - bytes)); |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8099 else |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8100 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes), |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8101 saved_pt_byte + (coding->produced - bytes)); |
91344
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8102 |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8103 if (need_marker_adjustment) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8104 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8105 struct Lisp_Marker *tail; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8106 |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8107 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8108 if (tail->need_adjustment) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8109 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8110 tail->need_adjustment = 0; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8111 if (tail->insertion_type) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8112 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8113 tail->bytepos = from_byte; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8114 tail->charpos = from; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8115 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8116 else |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8117 { |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8118 tail->bytepos = from_byte + coding->produced; |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8119 tail->charpos |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8120 = (NILP (current_buffer->enable_multibyte_characters) |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8121 ? tail->bytepos : from + coding->produced_char); |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8122 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8123 } |
56f3473b139e
(decode_coding_object): Adjuste marker positions after
Kenichi Handa <handa@m17n.org>
parents:
91327
diff
changeset
|
8124 } |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8125 } |
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
8126 |
90231
8be9e4c6d687
(encode_coding_object): If a pre-write-conversion
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
8127 if (kill_src_buffer) |
8be9e4c6d687
(encode_coding_object): If a pre-write-conversion
Kenichi Handa <handa@m17n.org>
parents:
90224
diff
changeset
|
8128 Fkill_buffer (coding->src_object); |
91838
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
8129 |
7bed61cbed0c
(decode_coding_object, encode_coding_object): Preserve
Kenichi Handa <handa@m17n.org>
parents:
91807
diff
changeset
|
8130 Vdeactivate_mark = old_deactivate_mark; |
88365 | 8131 unbind_to (count, Qnil); |
58637
ff8a37b5299b
(Vcode_conversion_workbuf_name): New variable.
Kenichi Handa <handa@m17n.org>
parents:
58502
diff
changeset
|
8132 } |
ff8a37b5299b
(Vcode_conversion_workbuf_name): New variable.
Kenichi Handa <handa@m17n.org>
parents:
58502
diff
changeset
|
8133 |
ff8a37b5299b
(Vcode_conversion_workbuf_name): New variable.
Kenichi Handa <handa@m17n.org>
parents:
58502
diff
changeset
|
8134 |
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
8135 Lisp_Object |
88365 | 8136 preferred_coding_system () |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8137 { |
88365 | 8138 int id = coding_categories[coding_priorities[0]].id; |
8139 | |
8140 return CODING_ID_NAME (id); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8141 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8142 |
17052 | 8143 |
8144 #ifdef emacs | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8145 /*** 8. Emacs Lisp library functions ***/ |
17052 | 8146 |
8147 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
|
8148 doc: /* Return t if OBJECT is nil or a coding-system. |
88365 | 8149 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
|
8150 about coding-system objects. */) |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8151 (object) |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8152 Lisp_Object object; |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8153 { |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8154 if (NILP (object) |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8155 || CODING_SYSTEM_ID (object) >= 0) |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8156 return Qt; |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8157 if (! SYMBOLP (object) |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8158 || NILP (Fget (object, Qcoding_system_define_form))) |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8159 return Qnil; |
90272
f1df126ec7de
Sync to HEAD for handling autoload-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
90263
diff
changeset
|
8160 return Qt; |
17052 | 8161 } |
8162 | |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
8163 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
|
8164 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
|
8165 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
|
8166 (prompt) |
17052 | 8167 Lisp_Object prompt; |
8168 { | |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8169 Lisp_Object val; |
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
8170 do |
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
8171 { |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8172 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8173 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
|
8174 } |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
46293
diff
changeset
|
8175 while (SCHARS (val) == 0); |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8176 return (Fintern (val, Qnil)); |
17052 | 8177 } |
8178 | |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
8179 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
|
8180 doc: /* Read a coding system from the minibuffer, prompting with string PROMPT. |
79107
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8181 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM. |
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8182 Ignores case when completing coding systems (all Emacs coding systems |
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8183 are lower-case). */) |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8184 (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
|
8185 Lisp_Object prompt, default_coding_system; |
17052 | 8186 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
8187 Lisp_Object val; |
79107
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8188 int count = SPECPDL_INDEX (); |
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8189 |
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
8190 if (SYMBOLP (default_coding_system)) |
45396
cab845213388
* coding.c (Fread_coding_system, code_convert_region1)
Ken Raeburn <raeburn@raeburn.org>
parents:
45239
diff
changeset
|
8191 default_coding_system = SYMBOL_NAME (default_coding_system); |
79107
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8192 specbind (Qcompletion_ignore_case, Qt); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8193 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
|
8194 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
|
8195 default_coding_system, Qnil); |
79107
cce707ee192e
(Qcompletion_ignore_case): New external Lisp_Object.
Glenn Morris <rgm@gnu.org>
parents:
78313
diff
changeset
|
8196 unbind_to (count, Qnil); |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
46293
diff
changeset
|
8197 return (SCHARS (val) == 0 ? Qnil : Fintern (val, Qnil)); |
17052 | 8198 } |
8199 | |
8200 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
8201 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
|
8202 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
|
8203 If valid, return CODING-SYSTEM, else signal a `coding-system-error' error. |
89892 | 8204 It is valid if it is nil or a symbol defined as a coding system by the |
8205 function `define-coding-system'. */) | |
88365 | 8206 (coding_system) |
17052 | 8207 Lisp_Object coding_system; |
8208 { | |
52794
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8209 Lisp_Object define_form; |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8210 |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8211 define_form = Fget (coding_system, Qcoding_system_define_form); |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8212 if (! NILP (define_form)) |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8213 { |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8214 Fput (coding_system, Qcoding_system_define_form, Qnil); |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8215 safe_eval (define_form); |
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
8216 } |
17052 | 8217 if (!NILP (Fcoding_system_p (coding_system))) |
8218 return coding_system; | |
71972
eaa3c19b94d2
(Fcheck_coding_system): Use xsignal1. Remove loop.
Kim F. Storm <storm@cua.dk>
parents:
71084
diff
changeset
|
8219 xsignal1 (Qcoding_system_error, coding_system); |
17052 | 8220 } |
88365 | 8221 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
8222 |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8223 /* Detect how the bytes at SRC of length SRC_BYTES are encoded. If |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8224 HIGHEST is nonzero, return the coding system of the highest |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8225 priority among the detected coding systems. Otherwize return a |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8226 list of detected coding systems sorted by their priorities. If |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8227 MULTIBYTEP is nonzero, it is assumed that the bytes are in correct |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8228 multibyte form but contains only ASCII and eight-bit chars. |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8229 Otherwise, the bytes are raw bytes. |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8230 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8231 CODING-SYSTEM controls the detection as below: |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8232 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8233 If it is nil, detect both text-format and eol-format. If the |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8234 text-format part of CODING-SYSTEM is already specified |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8235 (e.g. `iso-latin-1'), detect only eol-format. If the eol-format |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8236 part of CODING-SYSTEM is already specified (e.g. `undecided-unix'), |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8237 detect only text-format. */ |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8238 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8239 Lisp_Object |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8240 detect_coding_system (src, src_chars, src_bytes, highest, multibytep, |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8241 coding_system) |
46548
cb1914307488
(encode_eol, detect_coding, detect_eol):
Ken Raeburn <raeburn@raeburn.org>
parents:
46462
diff
changeset
|
8242 const unsigned char *src; |
91807
507bcfb4342c
* coding.c (coding_set_destination): Use BEG_BYTE rather than hardcoding 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91622
diff
changeset
|
8243 EMACS_INT src_chars, src_bytes; |
507bcfb4342c
* coding.c (coding_set_destination): Use BEG_BYTE rather than hardcoding 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91622
diff
changeset
|
8244 int highest; |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
8245 int multibytep; |
88365 | 8246 Lisp_Object coding_system; |
17052 | 8247 { |
89483 | 8248 const unsigned char *src_end = src + src_bytes; |
88365 | 8249 Lisp_Object attrs, eol_type; |
100135
0e17542db552
(detect_coding_system): Initialize utf_16_le_eol to -1, val to
Kenichi Handa <handa@m17n.org>
parents:
100133
diff
changeset
|
8250 Lisp_Object val = Qnil; |
88365 | 8251 struct coding_system coding; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8252 int id; |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8253 struct coding_detection_info detect_info; |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8254 enum coding_category base_category; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8255 int null_byte_found = 0, eight_bit_found = 0; |
88365 | 8256 |
8257 if (NILP (coding_system)) | |
8258 coding_system = Qundecided; | |
8259 setup_coding_system (coding_system, &coding); | |
8260 attrs = CODING_ID_ATTRS (coding.id); | |
8261 eol_type = CODING_ID_EOL_TYPE (coding.id); | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8262 coding_system = CODING_ATTR_BASE_NAME (attrs); |
88365 | 8263 |
8264 coding.source = src; | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8265 coding.src_chars = src_chars; |
88365 | 8266 coding.src_bytes = src_bytes; |
8267 coding.src_multibyte = multibytep; | |
8268 coding.consumed = 0; | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8269 coding.mode |= CODING_MODE_LAST_BLOCK; |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8270 coding.head_ascii = 0; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8271 |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8272 detect_info.checked = detect_info.found = detect_info.rejected = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8273 |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8274 /* At first, detect text-format if necessary. */ |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8275 base_category = XINT (CODING_ATTR_CATEGORY (attrs)); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8276 if (base_category == coding_category_undecided) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8277 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8278 enum coding_category category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8279 struct coding_system *this; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8280 int c, i; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8281 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8282 /* Skip all ASCII bytes except for a few ISO2022 controls. */ |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8283 for (; src < src_end; src++) |
17052 | 8284 { |
88365 | 8285 c = *src; |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8286 if (c & 0x80) |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8287 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8288 eight_bit_found = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8289 if (null_byte_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8290 break; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8291 } |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8292 else if (c < 0x20) |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8293 { |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8294 if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8295 && ! inhibit_iso_escape_detection |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8296 && ! detect_info.checked) |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8297 { |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8298 if (detect_coding_iso_2022 (&coding, &detect_info)) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8299 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8300 /* We have scanned the whole data. */ |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8301 if (! (detect_info.rejected & CATEGORY_MASK_ISO_7_ELSE)) |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8302 { |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8303 /* We didn't find an 8-bit code. We may |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8304 have found a null-byte, but it's very |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8305 rare that a binary file confirm to |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8306 ISO-2022. */ |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8307 src = src_end; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8308 coding.head_ascii = src - coding.source; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8309 } |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8310 detect_info.rejected |= ~CATEGORY_MASK_ISO_ESCAPE; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8311 break; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8312 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8313 } |
101040 | 8314 else if (! c && !inhibit_null_byte_detection) |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8315 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8316 null_byte_found = 1; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8317 if (eight_bit_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8318 break; |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8319 } |
95585
862c7386145c
(detect_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95533
diff
changeset
|
8320 if (! eight_bit_found) |
862c7386145c
(detect_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95533
diff
changeset
|
8321 coding.head_ascii++; |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8322 } |
95585
862c7386145c
(detect_coding): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95533
diff
changeset
|
8323 else if (! eight_bit_found) |
95533
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8324 coding.head_ascii++; |
831c8ee4d884
(detect_coding): Fix handling of coding->head_ascii.
Kenichi Handa <handa@m17n.org>
parents:
95397
diff
changeset
|
8325 } |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8326 |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8327 if (null_byte_found || eight_bit_found |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8328 || coding.head_ascii < coding.src_bytes |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8329 || detect_info.found) |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8330 { |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8331 if (coding.head_ascii == coding.src_bytes) |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8332 /* As all bytes are 7-bit, we can ignore non-ISO-2022 codings. */ |
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8333 for (i = 0; i < coding_category_raw_text; i++) |
88365 | 8334 { |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8335 category = coding_priorities[i]; |
90594
a965377e6761
(detect_coding_system): Fix for handling off
Kenichi Handa <handa@m17n.org>
parents:
90587
diff
changeset
|
8336 this = coding_categories + category; |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8337 if (detect_info.found & (1 << category)) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8338 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8339 } |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8340 else |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8341 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8342 if (null_byte_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8343 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8344 detect_info.checked |= ~CATEGORY_MASK_UTF_16; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8345 detect_info.rejected |= ~CATEGORY_MASK_UTF_16; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8346 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8347 for (i = 0; i < coding_category_raw_text; i++) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8348 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8349 category = coding_priorities[i]; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8350 this = coding_categories + category; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8351 |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8352 if (this->id < 0) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8353 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8354 /* No coding system of this category is defined. */ |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8355 detect_info.rejected |= (1 << category); |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8356 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8357 else if (category >= coding_category_raw_text) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8358 continue; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8359 else if (detect_info.checked & (1 << category)) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8360 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8361 if (highest |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8362 && (detect_info.found & (1 << category))) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8363 break; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8364 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8365 else if ((*(this->detector)) (&coding, &detect_info) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8366 && highest |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8367 && (detect_info.found & (1 << category))) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8368 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8369 if (category == coding_category_utf_16_auto) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8370 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8371 if (detect_info.found & CATEGORY_MASK_UTF_16_LE) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8372 category = coding_category_utf_16_le; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8373 else |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8374 category = coding_category_utf_16_be; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8375 } |
89974
2fef8edebd5c
(detect_coding_utf_16): Don't set detect_info->found if
Kenichi Handa <handa@m17n.org>
parents:
89933
diff
changeset
|
8376 break; |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8377 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8378 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8379 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8380 } |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8381 |
101197
ee5f395f3c19
(detect_coding_system): Fix handling of null_byte_fount.
Kenichi Handa <handa@m17n.org>
parents:
101174
diff
changeset
|
8382 if ((detect_info.rejected & CATEGORY_MASK_ANY) == CATEGORY_MASK_ANY |
ee5f395f3c19
(detect_coding_system): Fix handling of null_byte_fount.
Kenichi Handa <handa@m17n.org>
parents:
101174
diff
changeset
|
8383 || null_byte_found) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8384 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8385 detect_info.found = CATEGORY_MASK_RAW_TEXT; |
101197
ee5f395f3c19
(detect_coding_system): Fix handling of null_byte_fount.
Kenichi Handa <handa@m17n.org>
parents:
101174
diff
changeset
|
8386 id = CODING_SYSTEM_ID (Qno_conversion); |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8387 val = Fcons (make_number (id), Qnil); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8388 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8389 else if (! detect_info.rejected && ! detect_info.found) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8390 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8391 detect_info.found = CATEGORY_MASK_ANY; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8392 id = coding_categories[coding_category_undecided].id; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8393 val = Fcons (make_number (id), Qnil); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8394 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8395 else if (highest) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8396 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8397 if (detect_info.found) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8398 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8399 detect_info.found = 1 << category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8400 val = Fcons (make_number (this->id), Qnil); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8401 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8402 else |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8403 for (i = 0; i < coding_category_raw_text; i++) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8404 if (! (detect_info.rejected & (1 << coding_priorities[i]))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8405 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8406 detect_info.found = 1 << coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8407 id = coding_categories[coding_priorities[i]].id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8408 val = Fcons (make_number (id), Qnil); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8409 break; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8410 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8411 } |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8412 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8413 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8414 int mask = detect_info.rejected | detect_info.found; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8415 int found = 0; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8416 |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8417 for (i = coding_category_raw_text - 1; i >= 0; i--) |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8418 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8419 category = coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8420 if (! (mask & (1 << category))) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8421 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8422 found |= 1 << category; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8423 id = coding_categories[category].id; |
90594
a965377e6761
(detect_coding_system): Fix for handling off
Kenichi Handa <handa@m17n.org>
parents:
90587
diff
changeset
|
8424 if (id >= 0) |
a965377e6761
(detect_coding_system): Fix for handling off
Kenichi Handa <handa@m17n.org>
parents:
90587
diff
changeset
|
8425 val = Fcons (make_number (id), val); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8426 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8427 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8428 for (i = coding_category_raw_text - 1; i >= 0; i--) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8429 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8430 category = coding_priorities[i]; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8431 if (detect_info.found & (1 << category)) |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8432 { |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8433 id = coding_categories[category].id; |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8434 val = Fcons (make_number (id), val); |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8435 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8436 } |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8437 detect_info.found |= found; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8438 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8439 } |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8440 else if (base_category == coding_category_utf_8_auto) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8441 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8442 if (detect_coding_utf_8 (&coding, &detect_info)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8443 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8444 struct coding_system *this; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8445 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8446 if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8447 this = coding_categories + coding_category_utf_8_sig; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8448 else |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8449 this = coding_categories + coding_category_utf_8_nosig; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8450 val = Fcons (make_number (this->id), Qnil); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8451 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
8452 } |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8453 else if (base_category == coding_category_utf_16_auto) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8454 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8455 if (detect_coding_utf_16 (&coding, &detect_info)) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8456 { |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8457 struct coding_system *this; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8458 |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8459 if (detect_info.found & CATEGORY_MASK_UTF_16_LE) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8460 this = coding_categories + coding_category_utf_16_le; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8461 else if (detect_info.found & CATEGORY_MASK_UTF_16_BE) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8462 this = coding_categories + coding_category_utf_16_be; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8463 else if (detect_info.rejected & CATEGORY_MASK_UTF_16_LE_NOSIG) |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8464 this = coding_categories + coding_category_utf_16_be_nosig; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8465 else |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8466 this = coding_categories + coding_category_utf_16_le_nosig; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8467 val = Fcons (make_number (this->id), Qnil); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8468 } |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8469 } |
88365 | 8470 else |
8471 { | |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8472 detect_info.found = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8473 val = Fcons (make_number (coding.id), Qnil); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8474 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8475 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8476 /* Then, detect eol-format if necessary. */ |
88365 | 8477 { |
100135
0e17542db552
(detect_coding_system): Initialize utf_16_le_eol to -1, val to
Kenichi Handa <handa@m17n.org>
parents:
100133
diff
changeset
|
8478 int normal_eol = -1, utf_16_be_eol = -1, utf_16_le_eol = -1; |
88365 | 8479 Lisp_Object tail; |
8480 | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8481 if (VECTORP (eol_type)) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8482 { |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8483 if (detect_info.found & ~CATEGORY_MASK_UTF_16) |
93595
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8484 { |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8485 if (null_byte_found) |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8486 normal_eol = EOL_SEEN_LF; |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8487 else |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8488 normal_eol = detect_eol (coding.source, src_bytes, |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8489 coding_category_raw_text); |
ac4d127a841a
(CATEGORY_MASK_ANY): Add CATEGORY_MASK_UTF_16_AUTO.
Kenichi Handa <handa@m17n.org>
parents:
93323
diff
changeset
|
8490 } |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8491 if (detect_info.found & (CATEGORY_MASK_UTF_16_BE |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8492 | CATEGORY_MASK_UTF_16_BE_NOSIG)) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8493 utf_16_be_eol = detect_eol (coding.source, src_bytes, |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8494 coding_category_utf_16_be); |
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8495 if (detect_info.found & (CATEGORY_MASK_UTF_16_LE |
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
8496 | CATEGORY_MASK_UTF_16_LE_NOSIG)) |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8497 utf_16_le_eol = detect_eol (coding.source, src_bytes, |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8498 coding_category_utf_16_le); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8499 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8500 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8501 { |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8502 if (EQ (eol_type, Qunix)) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8503 normal_eol = utf_16_be_eol = utf_16_le_eol = EOL_SEEN_LF; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8504 else if (EQ (eol_type, Qdos)) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8505 normal_eol = utf_16_be_eol = utf_16_le_eol = EOL_SEEN_CRLF; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8506 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8507 normal_eol = utf_16_be_eol = utf_16_le_eol = EOL_SEEN_CR; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8508 } |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8509 |
88365 | 8510 for (tail = val; CONSP (tail); tail = XCDR (tail)) |
8511 { | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8512 enum coding_category category; |
88365 | 8513 int this_eol; |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8514 |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8515 id = XINT (XCAR (tail)); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8516 attrs = CODING_ID_ATTRS (id); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8517 category = XINT (CODING_ATTR_CATEGORY (attrs)); |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8518 eol_type = CODING_ID_EOL_TYPE (id); |
88365 | 8519 if (VECTORP (eol_type)) |
8520 { | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8521 if (category == coding_category_utf_16_be |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8522 || category == coding_category_utf_16_be_nosig) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8523 this_eol = utf_16_be_eol; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8524 else if (category == coding_category_utf_16_le |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8525 || category == coding_category_utf_16_le_nosig) |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8526 this_eol = utf_16_le_eol; |
88365 | 8527 else |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8528 this_eol = normal_eol; |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8529 |
88365 | 8530 if (this_eol == EOL_SEEN_LF) |
8531 XSETCAR (tail, AREF (eol_type, 0)); | |
8532 else if (this_eol == EOL_SEEN_CRLF) | |
8533 XSETCAR (tail, AREF (eol_type, 1)); | |
8534 else if (this_eol == EOL_SEEN_CR) | |
8535 XSETCAR (tail, AREF (eol_type, 2)); | |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8536 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8537 XSETCAR (tail, CODING_ID_NAME (id)); |
88365 | 8538 } |
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8539 else |
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
8540 XSETCAR (tail, CODING_ID_NAME (id)); |
88365 | 8541 } |
8542 } | |
8543 | |
100135
0e17542db552
(detect_coding_system): Initialize utf_16_le_eol to -1, val to
Kenichi Handa <handa@m17n.org>
parents:
100133
diff
changeset
|
8544 return (highest ? (CONSP (val) ? XCAR (val) : Qnil) : val); |
42104
d69c2368e549
(DECODE_COMPOSITION_END): Fixed a typo in the last
Sam Steingold <sds@gnu.org>
parents:
42103
diff
changeset
|
8545 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8546 |
88365 | 8547 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8548 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
|
8549 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
|
8550 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
|
8551 Return a list of possible coding systems ordered by priority. |
102737
f556415c326b
(Fdetect_coding_region, Fcoding_system_priority_list): Improve the
Kenichi Handa <handa@m17n.org>
parents:
102422
diff
changeset
|
8552 The coding systems to try and their priorities follows what |
f556415c326b
(Fdetect_coding_region, Fcoding_system_priority_list): Improve the
Kenichi Handa <handa@m17n.org>
parents:
102422
diff
changeset
|
8553 the function `coding-system-priority-list' (which see) returns. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8554 |
72552
6493d4697ad2
(Fdetect_coding_region, Fdetect_coding_string): Fix
Kenichi Handa <handa@m17n.org>
parents:
72395
diff
changeset
|
8555 If only ASCII characters are found (except for such ISO-2022 control |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8556 characters as ESC), it returns a list of single element `undecided' |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8557 or its subsidiary coding system according to a detected end-of-line |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8558 format. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8559 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8560 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
|
8561 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8562 (start, end, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8563 Lisp_Object start, end, highest; |
17052 | 8564 { |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8565 int from, to; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8566 int from_byte, to_byte; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8567 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
8568 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
|
8569 CHECK_NUMBER_COERCE_MARKER (end); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8570 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8571 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8572 from = XINT (start), to = XINT (end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8573 from_byte = CHAR_TO_BYTE (from); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8574 to_byte = CHAR_TO_BYTE (to); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8575 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8576 if (from < GPT && to >= GPT) |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8577 move_gap_both (to, to_byte); |
88365 | 8578 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8579 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8580 to - from, to_byte - from_byte, |
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
8581 !NILP (highest), |
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
8582 !NILP (current_buffer |
88365 | 8583 ->enable_multibyte_characters), |
8584 Qnil); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8585 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8586 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8587 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
|
8588 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
|
8589 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
|
8590 Return a list of possible coding systems ordered by priority. |
102738
41e7ab490f69
(Fdetect_coding_string): Improve the docstrings.
Kenichi Handa <handa@m17n.org>
parents:
102737
diff
changeset
|
8591 The coding systems to try and their priorities follows what |
41e7ab490f69
(Fdetect_coding_string): Improve the docstrings.
Kenichi Handa <handa@m17n.org>
parents:
102737
diff
changeset
|
8592 the function `coding-system-priority-list' (which see) returns. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8593 |
72552
6493d4697ad2
(Fdetect_coding_region, Fdetect_coding_string): Fix
Kenichi Handa <handa@m17n.org>
parents:
72395
diff
changeset
|
8594 If only ASCII characters are found (except for such ISO-2022 control |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8595 characters as ESC), it returns a list of single element `undecided' |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8596 or its subsidiary coding system according to a detected end-of-line |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8597 format. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8598 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8599 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
|
8600 highest priority. */) |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8601 (string, highest) |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8602 Lisp_Object string, highest; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8603 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
8604 CHECK_STRING (string); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8605 |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
46293
diff
changeset
|
8606 return detect_coding_system (SDATA (string), |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
8607 SCHARS (string), SBYTES (string), |
89483 | 8608 !NILP (highest), STRING_MULTIBYTE (string), |
88365 | 8609 Qnil); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8610 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8611 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8612 |
88365 | 8613 static INLINE int |
8614 char_encodable_p (c, attrs) | |
8615 int c; | |
8616 Lisp_Object attrs; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8617 { |
88365 | 8618 Lisp_Object tail; |
8619 struct charset *charset; | |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8620 Lisp_Object translation_table; |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8621 |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8622 translation_table = CODING_ATTR_TRANS_TBL (attrs); |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
8623 if (! NILP (translation_table)) |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8624 c = translate_char (translation_table, c); |
88365 | 8625 for (tail = CODING_ATTR_CHARSET_LIST (attrs); |
8626 CONSP (tail); tail = XCDR (tail)) | |
8627 { | |
8628 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
8629 if (CHAR_CHARSET_P (c, charset)) | |
8630 break; | |
8631 } | |
8632 return (! NILP (tail)); | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8633 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8634 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8635 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8636 /* Return a list of coding systems that safely encode the text between |
88365 | 8637 START and END. If EXCLUDE is non-nil, it is a list of coding |
8638 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
|
8639 coding systems. In any case, if the text contains only ASCII or is |
88365 | 8640 unibyte, return t. */ |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8641 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8642 DEFUN ("find-coding-systems-region-internal", |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8643 Ffind_coding_systems_region_internal, |
88365 | 8644 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
|
8645 doc: /* Internal use only. */) |
88365 | 8646 (start, end, exclude) |
8647 Lisp_Object start, end, exclude; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8648 { |
88365 | 8649 Lisp_Object coding_attrs_list, safe_codings; |
8650 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
|
8651 const unsigned char *p, *pbeg, *pend; |
88365 | 8652 int c; |
103486
091a55d2d6f7
(Ffind_coding_systems_region_internal): Cache checked characters.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
103474
diff
changeset
|
8653 Lisp_Object tail, elt, work_table; |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8654 |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8655 if (STRINGP (start)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8656 { |
88365 | 8657 if (!STRING_MULTIBYTE (start) |
89483 | 8658 || SCHARS (start) == SBYTES (start)) |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8659 return Qt; |
88365 | 8660 start_byte = 0; |
89483 | 8661 end_byte = SBYTES (start); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8662 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8663 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8664 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
8665 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
|
8666 CHECK_NUMBER_COERCE_MARKER (end); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8667 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
|
8668 args_out_of_range (start, end); |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8669 if (NILP (current_buffer->enable_multibyte_characters)) |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8670 return Qt; |
88365 | 8671 start_byte = CHAR_TO_BYTE (XINT (start)); |
8672 end_byte = CHAR_TO_BYTE (XINT (end)); | |
8673 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
8674 return Qt; | |
8675 | |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8676 if (XINT (start) < GPT && XINT (end) > GPT) |
88365 | 8677 { |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8678 if ((GPT - XINT (start)) < (XINT (end) - GPT)) |
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8679 move_gap_both (XINT (start), start_byte); |
88365 | 8680 else |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8681 move_gap_both (XINT (end), end_byte); |
88365 | 8682 } |
8683 } | |
8684 | |
8685 coding_attrs_list = Qnil; | |
8686 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
8687 if (NILP (exclude) | |
8688 || NILP (Fmemq (XCAR (tail), exclude))) | |
8689 { | |
8690 Lisp_Object attrs; | |
8691 | |
8692 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
8693 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
8694 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8695 { |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8696 ASET (attrs, coding_attr_trans_tbl, |
89861
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
8697 get_translation_table (attrs, 1, NULL)); |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8698 coding_attrs_list = Fcons (attrs, coding_attrs_list); |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8699 } |
88365 | 8700 } |
8701 | |
8702 if (STRINGP (start)) | |
89483 | 8703 p = pbeg = SDATA (start); |
88365 | 8704 else |
8705 p = pbeg = BYTE_POS_ADDR (start_byte); | |
8706 pend = p + (end_byte - start_byte); | |
8707 | |
8708 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
8709 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
8710 | |
103486
091a55d2d6f7
(Ffind_coding_systems_region_internal): Cache checked characters.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
103474
diff
changeset
|
8711 work_table = Fmake_char_table (Qnil, Qnil); |
88365 | 8712 while (p < pend) |
8713 { | |
8714 if (ASCII_BYTE_P (*p)) | |
8715 p++; | |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8716 else |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8717 { |
88365 | 8718 c = STRING_CHAR_ADVANCE (p); |
103486
091a55d2d6f7
(Ffind_coding_systems_region_internal): Cache checked characters.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
103474
diff
changeset
|
8719 if (!NILP (char_table_ref (work_table, c))) |
091a55d2d6f7
(Ffind_coding_systems_region_internal): Cache checked characters.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
103474
diff
changeset
|
8720 /* This character was already checked. Ignore it. */ |
091a55d2d6f7
(Ffind_coding_systems_region_internal): Cache checked characters.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
103474
diff
changeset
|
8721 continue; |
88365 | 8722 |
8723 charset_map_loaded = 0; | |
8724 for (tail = coding_attrs_list; CONSP (tail);) | |
8725 { | |
8726 elt = XCAR (tail); | |
8727 if (NILP (elt)) | |
8728 tail = XCDR (tail); | |
8729 else if (char_encodable_p (c, elt)) | |
8730 tail = XCDR (tail); | |
8731 else if (CONSP (XCDR (tail))) | |
8732 { | |
8733 XSETCAR (tail, XCAR (XCDR (tail))); | |
8734 XSETCDR (tail, XCDR (XCDR (tail))); | |
8735 } | |
8736 else | |
8737 { | |
8738 XSETCAR (tail, Qnil); | |
8739 tail = XCDR (tail); | |
8740 } | |
8741 } | |
8742 if (charset_map_loaded) | |
8743 { | |
8744 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
8745 | |
8746 if (STRINGP (start)) | |
89483 | 8747 pbeg = SDATA (start); |
88365 | 8748 else |
8749 pbeg = BYTE_POS_ADDR (start_byte); | |
8750 p = pbeg + p_offset; | |
8751 pend = pbeg + pend_offset; | |
8752 } | |
103486
091a55d2d6f7
(Ffind_coding_systems_region_internal): Cache checked characters.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
103474
diff
changeset
|
8753 char_table_set (work_table, c, Qt); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8754 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8755 } |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8756 |
89905
37e044cc35f6
(Ffind_coding_systems_region_internal): Include raw-text and
Kenichi Handa <handa@m17n.org>
parents:
89892
diff
changeset
|
8757 safe_codings = list2 (Qraw_text, Qno_conversion); |
88365 | 8758 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) |
8759 if (! NILP (XCAR (tail))) | |
8760 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
49539
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
8761 |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
8762 return safe_codings; |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
8763 } |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
8764 |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
8765 |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8766 DEFUN ("unencodable-char-position", Funencodable_char_position, |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8767 Sunencodable_char_position, 3, 5, 0, |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8768 doc: /* |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8769 Return position of first un-encodable character in a region. |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8770 START and END specify the region and CODING-SYSTEM specifies the |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8771 encoding to check. Return nil if CODING-SYSTEM does encode the region. |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8772 |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8773 If optional 4th argument COUNT is non-nil, it specifies at most how |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8774 many un-encodable characters to search. In this case, the value is a |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8775 list of positions. |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8776 |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8777 If optional 5th argument STRING is non-nil, it is a string to search |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8778 for un-encodable characters. In that case, START and END are indexes |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8779 to the string. */) |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8780 (start, end, coding_system, count, string) |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8781 Lisp_Object start, end, coding_system, count, string; |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8782 { |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8783 int n; |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8784 struct coding_system coding; |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8785 Lisp_Object attrs, charset_list, translation_table; |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8786 Lisp_Object positions; |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8787 int from, to; |
89483 | 8788 const unsigned char *p, *stop, *pend; |
8789 int ascii_compatible; | |
8790 | |
8791 setup_coding_system (Fcheck_coding_system (coding_system), &coding); | |
8792 attrs = CODING_ID_ATTRS (coding.id); | |
8793 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
8794 return Qnil; | |
8795 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
8796 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
89861
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
8797 translation_table = get_translation_table (attrs, 1, NULL); |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8798 |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8799 if (NILP (string)) |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8800 { |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8801 validate_region (&start, &end); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8802 from = XINT (start); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8803 to = XINT (end); |
89483 | 8804 if (NILP (current_buffer->enable_multibyte_characters) |
8805 || (ascii_compatible | |
8806 && (to - from) == (CHAR_TO_BYTE (to) - (CHAR_TO_BYTE (from))))) | |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8807 return Qnil; |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8808 p = CHAR_POS_ADDR (from); |
89483 | 8809 pend = CHAR_POS_ADDR (to); |
8810 if (from < GPT && to >= GPT) | |
8811 stop = GPT_ADDR; | |
48829
f6c59ca557c7
(Funencodable_char_position): Set pend correctly.
Kenichi Handa <handa@m17n.org>
parents:
48230
diff
changeset
|
8812 else |
89483 | 8813 stop = pend; |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8814 } |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8815 else |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8816 { |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8817 CHECK_STRING (string); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8818 CHECK_NATNUM (start); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8819 CHECK_NATNUM (end); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8820 from = XINT (start); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8821 to = XINT (end); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8822 if (from > to |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8823 || to > SCHARS (string)) |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8824 args_out_of_range_3 (string, start, end); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8825 if (! STRING_MULTIBYTE (string)) |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8826 return Qnil; |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8827 p = SDATA (string) + string_char_to_byte (string, from); |
89483 | 8828 stop = pend = SDATA (string) + string_char_to_byte (string, to); |
8829 if (ascii_compatible && (to - from) == (pend - p)) | |
8830 return Qnil; | |
8831 } | |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8832 |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8833 if (NILP (count)) |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8834 n = 1; |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8835 else |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8836 { |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8837 CHECK_NATNUM (count); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8838 n = XINT (count); |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8839 } |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8840 |
89483 | 8841 positions = Qnil; |
8842 while (1) | |
8843 { | |
8844 int c; | |
8845 | |
8846 if (ascii_compatible) | |
8847 while (p < stop && ASCII_BYTE_P (*p)) | |
8848 p++, from++; | |
8849 if (p >= stop) | |
8850 { | |
8851 if (p >= pend) | |
8852 break; | |
8853 stop = pend; | |
8854 p = GAP_END_ADDR; | |
8855 } | |
8856 | |
8857 c = STRING_CHAR_ADVANCE (p); | |
8858 if (! (ASCII_CHAR_P (c) && ascii_compatible) | |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8859 && ! char_charset (translate_char (translation_table, c), |
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8860 charset_list, NULL)) |
89483 | 8861 { |
8862 positions = Fcons (make_number (from), positions); | |
8863 n--; | |
8864 if (n == 0) | |
8865 break; | |
8866 } | |
8867 | |
8868 from++; | |
8869 } | |
8870 | |
8871 return (NILP (count) ? Fcar (positions) : Fnreverse (positions)); | |
8872 } | |
8873 | |
8874 | |
88365 | 8875 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, |
8876 Scheck_coding_systems_region, 3, 3, 0, | |
8877 doc: /* Check if the region is encodable by coding systems. | |
8878 | |
8879 START and END are buffer positions specifying the region. | |
8880 CODING-SYSTEM-LIST is a list of coding systems to check. | |
8881 | |
8882 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
8883 CODING-SYSTEM is a member of CODING-SYSTEM-LIST and can't encode the |
88365 | 8884 whole region, POS0, POS1, ... are buffer positions where non-encodable |
8885 characters are found. | |
8886 | |
8887 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
8888 value is nil. | |
8889 | |
8890 START may be a string. In that case, check if the string is | |
8891 encodable, and the value contains indices to the string instead of | |
102055
4d3a5c88cb2b
(Fcheck_coding_systems_region): Fix typo; Qt -> Qnil.
Kenichi Handa <handa@m17n.org>
parents:
101943
diff
changeset
|
8892 buffer positions. END is ignored. |
4d3a5c88cb2b
(Fcheck_coding_systems_region): Fix typo; Qt -> Qnil.
Kenichi Handa <handa@m17n.org>
parents:
101943
diff
changeset
|
8893 |
102058
4f60db600648
(Fcheck_coding_systems_region): Fix test for unibyte
Andreas Schwab <schwab@suse.de>
parents:
102055
diff
changeset
|
8894 If the current buffer (or START if it is a string) is unibyte, the value |
102055
4d3a5c88cb2b
(Fcheck_coding_systems_region): Fix typo; Qt -> Qnil.
Kenichi Handa <handa@m17n.org>
parents:
101943
diff
changeset
|
8895 is nil. */) |
88365 | 8896 (start, end, coding_system_list) |
8897 Lisp_Object start, end, coding_system_list; | |
8898 { | |
8899 Lisp_Object list; | |
8900 EMACS_INT start_byte, end_byte; | |
8901 int pos; | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
8902 const unsigned char *p, *pbeg, *pend; |
88365 | 8903 int c; |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8904 Lisp_Object tail, elt, attrs; |
88365 | 8905 |
8906 if (STRINGP (start)) | |
8907 { | |
8908 if (!STRING_MULTIBYTE (start) | |
102058
4f60db600648
(Fcheck_coding_systems_region): Fix test for unibyte
Andreas Schwab <schwab@suse.de>
parents:
102055
diff
changeset
|
8909 || SCHARS (start) == SBYTES (start)) |
88365 | 8910 return Qnil; |
8911 start_byte = 0; | |
89483 | 8912 end_byte = SBYTES (start); |
88365 | 8913 pos = 0; |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8914 } |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8915 else |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8916 { |
88365 | 8917 CHECK_NUMBER_COERCE_MARKER (start); |
8918 CHECK_NUMBER_COERCE_MARKER (end); | |
8919 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
8920 args_out_of_range (start, end); | |
8921 if (NILP (current_buffer->enable_multibyte_characters)) | |
8922 return Qnil; | |
8923 start_byte = CHAR_TO_BYTE (XINT (start)); | |
8924 end_byte = CHAR_TO_BYTE (XINT (end)); | |
8925 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
102055
4d3a5c88cb2b
(Fcheck_coding_systems_region): Fix typo; Qt -> Qnil.
Kenichi Handa <handa@m17n.org>
parents:
101943
diff
changeset
|
8926 return Qnil; |
88365 | 8927 |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8928 if (XINT (start) < GPT && XINT (end) > GPT) |
88365 | 8929 { |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8930 if ((GPT - XINT (start)) < (XINT (end) - GPT)) |
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8931 move_gap_both (XINT (start), start_byte); |
88365 | 8932 else |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8933 move_gap_both (XINT (end), end_byte); |
88365 | 8934 } |
89394
6ffca50f25b9
(Fcheck_coding_systems_region): Fix type errors.
Dave Love <fx@gnu.org>
parents:
89373
diff
changeset
|
8935 pos = XINT (start); |
88365 | 8936 } |
8937 | |
8938 list = Qnil; | |
8939 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
8940 { | |
8941 elt = XCAR (tail); | |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8942 attrs = AREF (CODING_SYSTEM_SPEC (elt), 0); |
89861
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
8943 ASET (attrs, coding_attr_trans_tbl, |
7160ded23e55
(get_translation_table): Allow max_lookup to be NULL.
Kenichi Handa <handa@m17n.org>
parents:
89859
diff
changeset
|
8944 get_translation_table (attrs, 1, NULL)); |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
8945 list = Fcons (Fcons (elt, Fcons (attrs, Qnil)), list); |
88365 | 8946 } |
8947 | |
8948 if (STRINGP (start)) | |
89483 | 8949 p = pbeg = SDATA (start); |
88365 | 8950 else |
8951 p = pbeg = BYTE_POS_ADDR (start_byte); | |
8952 pend = p + (end_byte - start_byte); | |
8953 | |
8954 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
8955 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
8956 | |
8957 while (p < pend) | |
8958 { | |
8959 if (ASCII_BYTE_P (*p)) | |
8960 p++; | |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8961 else |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8962 { |
88365 | 8963 c = STRING_CHAR_ADVANCE (p); |
8964 | |
8965 charset_map_loaded = 0; | |
8966 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
8967 { | |
8968 elt = XCDR (XCAR (tail)); | |
8969 if (! char_encodable_p (c, XCAR (elt))) | |
8970 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
8971 } | |
8972 if (charset_map_loaded) | |
8973 { | |
8974 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
8975 | |
8976 if (STRINGP (start)) | |
89483 | 8977 pbeg = SDATA (start); |
88365 | 8978 else |
8979 pbeg = BYTE_POS_ADDR (start_byte); | |
8980 p = pbeg + p_offset; | |
8981 pend = pbeg + pend_offset; | |
8982 } | |
8983 } | |
8984 pos++; | |
8985 } | |
8986 | |
8987 tail = list; | |
8988 list = Qnil; | |
8989 for (; CONSP (tail); tail = XCDR (tail)) | |
8990 { | |
8991 elt = XCAR (tail); | |
8992 if (CONSP (XCDR (XCDR (elt)))) | |
8993 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
8994 list); | |
8995 } | |
8996 | |
8997 return list; | |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8998 } |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
8999 |
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
9000 |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9001 Lisp_Object |
88365 | 9002 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
9003 Lisp_Object start, end, coding_system, dst_object; | |
9004 int encodep, norecord; | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9005 { |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9006 struct coding_system coding; |
88365 | 9007 EMACS_INT from, from_byte, to, to_byte; |
9008 Lisp_Object src_object; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9009 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
9010 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
|
9011 CHECK_NUMBER_COERCE_MARKER (end); |
88365 | 9012 if (NILP (coding_system)) |
9013 coding_system = Qno_conversion; | |
9014 else | |
9015 CHECK_CODING_SYSTEM (coding_system); | |
9016 src_object = Fcurrent_buffer (); | |
9017 if (NILP (dst_object)) | |
9018 dst_object = src_object; | |
9019 else if (! EQ (dst_object, Qt)) | |
9020 CHECK_BUFFER (dst_object); | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9021 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9022 validate_region (&start, &end); |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9023 from = XFASTINT (start); |
88365 | 9024 from_byte = CHAR_TO_BYTE (from); |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9025 to = XFASTINT (end); |
88365 | 9026 to_byte = CHAR_TO_BYTE (to); |
9027 | |
9028 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9029 coding.mode |= CODING_MODE_LAST_BLOCK; |
88365 | 9030 |
9031 if (encodep) | |
9032 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
9033 dst_object); | |
9034 else | |
9035 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
9036 dst_object); | |
9037 if (! norecord) | |
9038 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
9039 | |
9040 return (BUFFERP (dst_object) | |
9041 ? make_number (coding.produced_char) | |
9042 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9043 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9044 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9045 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9046 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
88365 | 9047 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
|
9048 doc: /* Decode the current region from the specified coding system. |
88365 | 9049 When called from a program, takes four arguments: |
9050 START, END, CODING-SYSTEM, and DESTINATION. | |
9051 START and END are buffer positions. | |
9052 | |
9053 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
91083
ff87badce376
(Fdecode_coding_region): Fix typo in docstring.
Kenichi Handa <handa@m17n.org>
parents:
91056
diff
changeset
|
9054 If nil, the region between START and END is replaced by the decoded text. |
98992
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9055 If buffer, the decoded text is inserted in that buffer after point (point |
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9056 does not move). |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
9057 In those cases, the length of the decoded text is returned. |
95353
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
9058 If DESTINATION is t, the decoded text is returned. |
88365 | 9059 |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9060 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
|
9061 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is |
95353
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
9062 not fully specified.) */) |
88365 | 9063 (start, end, coding_system, destination) |
9064 Lisp_Object start, end, coding_system, destination; | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9065 { |
88365 | 9066 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
|
9067 } |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9068 |
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9069 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
88365 | 9070 3, 4, "r\nzCoding system: ", |
9071 doc: /* Encode the current region by specified coding system. | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9072 When called from a program, takes four arguments: |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9073 START, END, CODING-SYSTEM and DESTINATION. |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9074 START and END are buffer positions. |
88365 | 9075 |
9076 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
9077 If nil, the region between START and END is replace by the encoded text. | |
98992
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9078 If buffer, the encoded text is inserted in that buffer after point (point |
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9079 does not move). |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
9080 In those cases, the length of the encoded text is returned. |
95353
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
9081 If DESTINATION is t, the encoded text is returned. |
88365 | 9082 |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9083 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
|
9084 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is |
95353
96d35f50fe34
(encode_coding_raw_text): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
95345
diff
changeset
|
9085 not fully specified.) */) |
88365 | 9086 (start, end, coding_system, destination) |
9087 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
|
9088 { |
88365 | 9089 return code_convert_region (start, end, coding_system, destination, 1, 0); |
17052 | 9090 } |
9091 | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9092 Lisp_Object |
88365 | 9093 code_convert_string (string, coding_system, dst_object, |
9094 encodep, nocopy, norecord) | |
9095 Lisp_Object string, coding_system, dst_object; | |
9096 int encodep, nocopy, norecord; | |
17052 | 9097 { |
9098 struct coding_system coding; | |
88365 | 9099 EMACS_INT chars, bytes; |
17052 | 9100 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
9101 CHECK_STRING (string); |
88365 | 9102 if (NILP (coding_system)) |
9103 { | |
9104 if (! norecord) | |
9105 Vlast_coding_system_used = Qno_conversion; | |
9106 if (NILP (dst_object)) | |
9107 return (nocopy ? Fcopy_sequence (string) : string); | |
9108 } | |
17052 | 9109 |
70520
b6740a317343
(setup_coding_system): For invalid coding-system, set
Kenichi Handa <handa@m17n.org>
parents:
69995
diff
changeset
|
9110 if (NILP (coding_system)) |
88365 | 9111 coding_system = Qno_conversion; |
9112 else | |
9113 CHECK_CODING_SYSTEM (coding_system); | |
9114 if (NILP (dst_object)) | |
9115 dst_object = Qt; | |
9116 else if (! EQ (dst_object, Qt)) | |
9117 CHECK_BUFFER (dst_object); | |
9118 | |
9119 setup_coding_system (coding_system, &coding); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9120 coding.mode |= CODING_MODE_LAST_BLOCK; |
89483 | 9121 chars = SCHARS (string); |
9122 bytes = SBYTES (string); | |
88365 | 9123 if (encodep) |
9124 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
9125 else | |
9126 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
9127 if (! norecord) | |
9128 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
9129 | |
9130 return (BUFFERP (dst_object) | |
9131 ? make_number (coding.produced_char) | |
9132 : coding.dst_object); | |
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9133 } |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9134 |
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
9135 |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9136 /* Encode or decode STRING according to CODING_SYSTEM. |
26847 | 9137 Do not set Vlast_coding_system_used. |
9138 | |
9139 This function is called only from macros DECODE_FILE and | |
9140 ENCODE_FILE, thus we ignore character composition. */ | |
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9141 |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9142 Lisp_Object |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9143 code_convert_string_norecord (string, coding_system, encodep) |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9144 Lisp_Object string, coding_system; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9145 int encodep; |
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
9146 { |
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
9147 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
|
9148 } |
88365 | 9149 |
9150 | |
9151 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
9152 2, 4, 0, | |
9153 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
9154 | |
9155 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
9156 if the decoding operation is trivial. | |
9157 | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9158 Optional fourth arg BUFFER non-nil means that the decoded text is |
98992
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9159 inserted in that buffer after point (point does not move). In this |
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9160 case, the return value is the length of the decoded text. |
88365 | 9161 |
9162 This function sets `last-coding-system-used' to the precise coding system | |
9163 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9164 not fully specified.) */) |
88365 | 9165 (string, coding_system, nocopy, buffer) |
9166 Lisp_Object string, coding_system, nocopy, buffer; | |
9167 { | |
9168 return code_convert_string (string, coding_system, buffer, | |
9169 0, ! NILP (nocopy), 0); | |
9170 } | |
9171 | |
9172 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
9173 2, 4, 0, | |
9174 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
9175 | |
9176 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
9177 itself if the encoding operation is trivial. | |
9178 | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9179 Optional fourth arg BUFFER non-nil means that the encoded text is |
98992
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9180 inserted in that buffer after point (point does not move). In this |
d4659edb9b7b
(Fencode_coding_region, Fdecode_coding_region)
Eli Zaretskii <eliz@gnu.org>
parents:
98951
diff
changeset
|
9181 case, the return value is the length of the encoded text. |
88365 | 9182 |
9183 This function sets `last-coding-system-used' to the precise coding system | |
9184 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
9185 not fully specified.) */) | |
9186 (string, coding_system, nocopy, buffer) | |
9187 Lisp_Object string, coding_system, nocopy, buffer; | |
9188 { | |
9189 return code_convert_string (string, coding_system, buffer, | |
88856 | 9190 1, ! NILP (nocopy), 1); |
88365 | 9191 } |
9192 | |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9193 |
17052 | 9194 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
|
9195 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
|
9196 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
|
9197 (code) |
17052 | 9198 Lisp_Object code; |
9199 { | |
88365 | 9200 Lisp_Object spec, attrs, val; |
9201 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
9202 int c; | |
9203 | |
9204 CHECK_NATNUM (code); | |
9205 c = XFASTINT (code); | |
9206 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
9207 attrs = AREF (spec, 0); | |
9208 | |
9209 if (ASCII_BYTE_P (c) | |
9210 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
9211 return code; | |
9212 | |
9213 val = CODING_ATTR_CHARSET_LIST (attrs); | |
9214 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
|
9215 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
|
9216 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
88365 | 9217 |
9218 if (c <= 0x7F) | |
9219 charset = charset_roman; | |
9220 else if (c >= 0xA0 && c < 0xDF) | |
9221 { | |
9222 charset = charset_kana; | |
9223 c -= 0x80; | |
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
9224 } |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
9225 else |
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
9226 { |
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
9227 int s1 = c >> 8, s2 = c & 0xFF; |
88365 | 9228 |
9229 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
9230 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
9231 error ("Invalid code: %d", code); | |
9232 SJIS_TO_JIS (c); | |
9233 charset = charset_kanji; | |
9234 } | |
9235 c = DECODE_CHAR (charset, c); | |
9236 if (c < 0) | |
9237 error ("Invalid code: %d", code); | |
9238 return make_number (c); | |
17052 | 9239 } |
9240 | |
9241 | |
9242 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0, | |
73949
0d1207b43a5b
(Fencode_sjis_char, Fencode_big5_char): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
72552
diff
changeset
|
9243 doc: /* Encode a Japanese character CH to shift_jis encoding. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9244 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
|
9245 (ch) |
88365 | 9246 Lisp_Object ch; |
17052 | 9247 { |
88365 | 9248 Lisp_Object spec, attrs, charset_list; |
9249 int c; | |
9250 struct charset *charset; | |
9251 unsigned code; | |
9252 | |
9253 CHECK_CHARACTER (ch); | |
9254 c = XFASTINT (ch); | |
9255 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
9256 attrs = AREF (spec, 0); | |
9257 | |
9258 if (ASCII_CHAR_P (c) | |
9259 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
9260 return ch; | |
9261 | |
9262 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
9263 charset = char_charset (c, charset_list, &code); | |
9264 if (code == CHARSET_INVALID_CODE (charset)) | |
9265 error ("Can't encode by shift_jis encoding: %d", c); | |
9266 JIS_TO_SJIS (code); | |
9267 | |
9268 return make_number (code); | |
17052 | 9269 } |
9270 | |
9271 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
|
9272 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
|
9273 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
|
9274 (code) |
17052 | 9275 Lisp_Object code; |
9276 { | |
88365 | 9277 Lisp_Object spec, attrs, val; |
9278 struct charset *charset_roman, *charset_big5, *charset; | |
9279 int c; | |
9280 | |
9281 CHECK_NATNUM (code); | |
9282 c = XFASTINT (code); | |
9283 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
9284 attrs = AREF (spec, 0); | |
9285 | |
9286 if (ASCII_BYTE_P (c) | |
9287 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
9288 return code; | |
9289 | |
9290 val = CODING_ATTR_CHARSET_LIST (attrs); | |
9291 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
9292 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
9293 | |
9294 if (c <= 0x7F) | |
9295 charset = charset_roman; | |
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
9296 else |
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
9297 { |
88365 | 9298 int b1 = c >> 8, b2 = c & 0x7F; |
9299 if (b1 < 0xA1 || b1 > 0xFE | |
9300 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
9301 error ("Invalid code: %d", code); | |
9302 charset = charset_big5; | |
9303 } | |
9304 c = DECODE_CHAR (charset, (unsigned )c); | |
9305 if (c < 0) | |
9306 error ("Invalid code: %d", code); | |
9307 return make_number (c); | |
17052 | 9308 } |
9309 | |
9310 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0, | |
73949
0d1207b43a5b
(Fencode_sjis_char, Fencode_big5_char): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
72552
diff
changeset
|
9311 doc: /* Encode the Big5 character CH to BIG5 coding system. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9312 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
|
9313 (ch) |
17052 | 9314 Lisp_Object ch; |
9315 { | |
88365 | 9316 Lisp_Object spec, attrs, charset_list; |
9317 struct charset *charset; | |
9318 int c; | |
9319 unsigned code; | |
9320 | |
9321 CHECK_CHARACTER (ch); | |
9322 c = XFASTINT (ch); | |
9323 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
9324 attrs = AREF (spec, 0); | |
9325 if (ASCII_CHAR_P (c) | |
9326 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
9327 return ch; | |
9328 | |
9329 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
9330 charset = char_charset (c, charset_list, &code); | |
9331 if (code == CHARSET_INVALID_CODE (charset)) | |
9332 error ("Can't encode by Big5 encoding: %d", c); | |
9333 | |
9334 return make_number (code); | |
17052 | 9335 } |
88365 | 9336 |
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
9337 |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
9338 DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_internal, |
83298
ed09a89e2b25
Fix UTF-8 tty input when first frame is an X frame. Steps towards multiple tty locale support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83292
diff
changeset
|
9339 Sset_terminal_coding_system_internal, 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
|
9340 doc: /* Internal use only. */) |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9341 (coding_system, terminal) |
17052 | 9342 Lisp_Object coding_system; |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9343 Lisp_Object terminal; |
17052 | 9344 { |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9345 struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1)); |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
9346 CHECK_SYMBOL (coding_system); |
83127
5182815e0ee1
Make terminal_coding and keyboard_coding display-local.
Karoly Lorentey <lorentey@elte.hu>
parents:
54320
diff
changeset
|
9347 setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding); |
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
9348 /* We had better not send unsafe characters to terminal. */ |
91041 | 9349 terminal_coding->mode |= CODING_MODE_SAFE_ENCODING; |
88365 | 9350 /* Characer composition should be disabled. */ |
91041 | 9351 terminal_coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; |
83127
5182815e0ee1
Make terminal_coding and keyboard_coding display-local.
Karoly Lorentey <lorentey@elte.hu>
parents:
54320
diff
changeset
|
9352 terminal_coding->src_multibyte = 1; |
5182815e0ee1
Make terminal_coding and keyboard_coding display-local.
Karoly Lorentey <lorentey@elte.hu>
parents:
54320
diff
changeset
|
9353 terminal_coding->dst_multibyte = 0; |
17052 | 9354 return Qnil; |
9355 } | |
9356 | |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9357 DEFUN ("set-safe-terminal-coding-system-internal", |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9358 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
|
9359 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
41006 | 9360 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
|
9361 (coding_system) |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9362 Lisp_Object coding_system; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9363 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
9364 CHECK_SYMBOL (coding_system); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9365 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
|
9366 &safe_terminal_coding); |
88365 | 9367 /* Characer composition should be disabled. */ |
9368 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
|
9369 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
|
9370 safe_terminal_coding.dst_multibyte = 0; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9371 return Qnil; |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9372 } |
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
9373 |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
9374 DEFUN ("terminal-coding-system", Fterminal_coding_system, |
83298
ed09a89e2b25
Fix UTF-8 tty input when first frame is an X frame. Steps towards multiple tty locale support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83292
diff
changeset
|
9375 Sterminal_coding_system, 0, 1, 0, |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9376 doc: /* Return coding system specified for terminal output on the given terminal. |
103052
e68707cf48a5
* keyboard.c (Fset_input_meta_mode): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
103035
diff
changeset
|
9377 TERMINAL may be a terminal object, a frame, or nil for the selected |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9378 frame's terminal device. */) |
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9379 (terminal) |
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9380 Lisp_Object terminal; |
17052 | 9381 { |
91046 | 9382 struct coding_system *terminal_coding |
9383 = TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1)); | |
9384 Lisp_Object coding_system = CODING_ID_NAME (terminal_coding->id); | |
9385 | |
90011
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
9386 /* For backward compatibility, return nil if it is `undecided'. */ |
90359
041f75914d0c
(produce_composition): Compare charbuf[i] instead of
Kenichi Handa <handa@m17n.org>
parents:
90354
diff
changeset
|
9387 return (! EQ (coding_system, Qundecided) ? coding_system : Qnil); |
17052 | 9388 } |
9389 | |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
9390 DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_internal, |
83298
ed09a89e2b25
Fix UTF-8 tty input when first frame is an X frame. Steps towards multiple tty locale support.
Karoly Lorentey <lorentey@elte.hu>
parents:
83292
diff
changeset
|
9391 Sset_keyboard_coding_system_internal, 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
|
9392 doc: /* Internal use only. */) |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9393 (coding_system, terminal) |
17052 | 9394 Lisp_Object coding_system; |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9395 Lisp_Object terminal; |
17052 | 9396 { |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9397 struct terminal *t = get_terminal (terminal, 1); |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
9398 CHECK_SYMBOL (coding_system); |
103655
e2d67c929da2
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
103486
diff
changeset
|
9399 if (NILP (coding_system)) |
e2d67c929da2
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
103486
diff
changeset
|
9400 coding_system = Qno_conversion; |
e2d67c929da2
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
103486
diff
changeset
|
9401 else |
e2d67c929da2
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
103486
diff
changeset
|
9402 Fcheck_coding_system (coding_system); |
e2d67c929da2
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
103486
diff
changeset
|
9403 setup_coding_system (coding_system, TERMINAL_KEYBOARD_CODING (t)); |
88365 | 9404 /* Characer composition should be disabled. */ |
91041 | 9405 TERMINAL_KEYBOARD_CODING (t)->common_flags |
9406 &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
17052 | 9407 return Qnil; |
9408 } | |
9409 | |
9410 DEFUN ("keyboard-coding-system", | |
91046 | 9411 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 1, 0, |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9412 doc: /* Return coding system specified for decoding keyboard input. */) |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9413 (terminal) |
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83423
diff
changeset
|
9414 Lisp_Object terminal; |
17052 | 9415 { |
91046 | 9416 return CODING_ID_NAME (TERMINAL_KEYBOARD_CODING |
9417 (get_terminal (terminal, 1))->id); | |
17052 | 9418 } |
9419 | |
9420 | |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
9421 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
|
9422 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
|
9423 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
|
9424 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
|
9425 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
|
9426 \(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
|
9427 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
|
9428 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9429 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
|
9430 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
|
9431 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
|
9432 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
|
9433 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9434 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
|
9435 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
|
9436 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
|
9437 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
|
9438 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9439 TARGET has a meaning which depends on OPERATION: |
70948
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9440 For file I/O, TARGET is a file name (except for the special case below). |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9441 For process I/O, TARGET is a process name. |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9442 For network I/O, TARGET is a service name or a port number. |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9443 |
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9444 This function looks up what is specified for TARGET in |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9445 `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
|
9446 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
|
9447 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
|
9448 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
|
9449 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
|
9450 which is a list of all the arguments given to this function. |
81611
ae42ad5f89e6
(Ffind_operation_coding_system): Docstring improved.
Kenichi Handa <handa@m17n.org>
parents:
75348
diff
changeset
|
9451 If the function can't decide a coding system, it can return |
ae42ad5f89e6
(Ffind_operation_coding_system): Docstring improved.
Kenichi Handa <handa@m17n.org>
parents:
75348
diff
changeset
|
9452 `undecided' so that the normal code-detection is performed. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9453 |
70948
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9454 If OPERATION is `insert-file-contents', the argument corresponding to |
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9455 TARGET may be a cons (FILENAME . BUFFER). In that case, FILENAME is a |
71084
ccef92f2f7f8
(Ffind_operation_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
71070
diff
changeset
|
9456 file name to look up, and BUFFER is a buffer that contains the file's |
ccef92f2f7f8
(Ffind_operation_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
71070
diff
changeset
|
9457 contents (not yet decoded). If `file-coding-system-alist' specifies a |
71070
0c8ac7192244
(Ffind_operation_coding_system): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
71039
diff
changeset
|
9458 function to call for FILENAME, that function should examine the |
0c8ac7192244
(Ffind_operation_coding_system): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
71039
diff
changeset
|
9459 contents of BUFFER instead of reading the file. |
70948
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9460 |
78152
5e5f359984e5
(Ffind_operation_coding_system): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75348
diff
changeset
|
9461 usage: (find-operation-coding-system OPERATION ARGUMENTS...) */) |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
9462 (nargs, args) |
17052 | 9463 int nargs; |
9464 Lisp_Object *args; | |
9465 { | |
9466 Lisp_Object operation, target_idx, target, val; | |
9467 register Lisp_Object chain; | |
9468 | |
9469 if (nargs < 2) | |
9470 error ("Too few arguments"); | |
9471 operation = args[0]; | |
9472 if (!SYMBOLP (operation) | |
9473 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
9474 error ("Invalid first argument"); |
17052 | 9475 if (nargs < 1 + XINT (target_idx)) |
9476 error ("Too few arguments for operation: %s", | |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
46293
diff
changeset
|
9477 SDATA (SYMBOL_NAME (operation))); |
17052 | 9478 target = args[XINT (target_idx) + 1]; |
9479 if (!(STRINGP (target) | |
70948
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9480 || (EQ (operation, Qinsert_file_contents) && CONSP (target) |
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9481 && STRINGP (XCAR (target)) && BUFFERP (XCDR (target))) |
17052 | 9482 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) |
88365 | 9483 error ("Invalid %dth argument", XINT (target_idx) + 1); |
70948
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9484 if (CONSP (target)) |
7ea8b1c11d80
(Ffind_operation_coding_system): Allow (FILENAME . BUFFER) in TARGET.
Kenichi Handa <handa@m17n.org>
parents:
70704
diff
changeset
|
9485 target = XCAR (target); |
17052 | 9486 |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
9487 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
|
9488 || EQ (operation, Qwrite_region)) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9489 ? 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
|
9490 : (EQ (operation, Qopen_network_stream) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9491 ? Vnetwork_coding_system_alist |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9492 : Vprocess_coding_system_alist)); |
17052 | 9493 if (NILP (chain)) |
9494 return Qnil; | |
9495 | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
9496 for (; CONSP (chain); chain = XCDR (chain)) |
17052 | 9497 { |
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
9498 Lisp_Object elt; |
88365 | 9499 |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
9500 elt = XCAR (chain); |
17052 | 9501 if (CONSP (elt) |
9502 && ((STRINGP (target) | |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
9503 && STRINGP (XCAR (elt)) |
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
9504 && 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
|
9505 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9506 { |
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
9507 val = XCDR (elt); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9508 /* 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
|
9509 function symbol, we return VAL as a coding system. */ |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9510 if (CONSP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9511 return val; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9512 if (! SYMBOLP (val)) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9513 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9514 if (! NILP (Fcoding_system_p (val))) |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9515 return Fcons (val, val); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9516 if (! NILP (Ffboundp (val))) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9517 { |
72188 | 9518 /* We use call1 rather than safe_call1 |
9519 so as to get bug reports about functions called here | |
9520 which don't handle the current interface. */ | |
72180
f3bc55b96df5
(Ffind_operation_coding_system): Revert the change from 2006-05-29.
Eli Zaretskii <eliz@gnu.org>
parents:
71972
diff
changeset
|
9521 val = call1 (val, Flist (nargs, args)); |
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9522 if (CONSP (val)) |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9523 return val; |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9524 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
|
9525 return Fcons (val, val); |
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
9526 } |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9527 return Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
9528 } |
17052 | 9529 } |
9530 return Qnil; | |
9531 } | |
9532 | |
88365 | 9533 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
|
9534 Sset_coding_system_priority, 0, MANY, 0, |
88645 | 9535 doc: /* Assign higher priority to the coding systems given as arguments. |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9536 If multiple coding systems belong to the same category, |
89519
040a08a2a879
(Fread_coding_system): Fix arg of XSETSTRING.
Dave Love <fx@gnu.org>
parents:
89483
diff
changeset
|
9537 all but the first one are ignored. |
040a08a2a879
(Fread_coding_system): Fix arg of XSETSTRING.
Dave Love <fx@gnu.org>
parents:
89483
diff
changeset
|
9538 |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
9539 usage: (set-coding-system-priority &rest coding-systems) */) |
88365 | 9540 (nargs, args) |
9541 int nargs; | |
9542 Lisp_Object *args; | |
9543 { | |
9544 int i, j; | |
9545 int changed[coding_category_max]; | |
9546 enum coding_category priorities[coding_category_max]; | |
9547 | |
9548 bzero (changed, sizeof changed); | |
9549 | |
9550 for (i = j = 0; i < nargs; i++) | |
9551 { | |
9552 enum coding_category category; | |
9553 Lisp_Object spec, attrs; | |
9554 | |
9555 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
9556 attrs = AREF (spec, 0); | |
9557 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
9558 if (changed[category]) | |
9559 /* Ignore this coding system because a coding system of the | |
9560 same category already had a higher priority. */ | |
9561 continue; | |
9562 changed[category] = 1; | |
9563 priorities[j++] = category; | |
9564 if (coding_categories[category].id >= 0 | |
9565 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
9566 setup_coding_system (args[i], &coding_categories[category]); | |
89467
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9567 Fset (AREF (Vcoding_category_table, category), args[i]); |
88365 | 9568 } |
9569 | |
9570 /* Now we have decided top J priorities. Reflect the order of the | |
9571 original priorities to the remaining priorities. */ | |
9572 | |
9573 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
9574 { | |
9575 while (j < coding_category_max | |
9576 && changed[coding_priorities[j]]) | |
9577 j++; | |
9578 if (j == coding_category_max) | |
9579 abort (); | |
9580 priorities[i] = coding_priorities[j]; | |
9581 } | |
9582 | |
9583 bcopy (priorities, coding_priorities, sizeof priorities); | |
89467
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9584 |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9585 /* Update `coding-category-list'. */ |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9586 Vcoding_category_list = Qnil; |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9587 for (i = coding_category_max - 1; i >= 0; i--) |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9588 Vcoding_category_list |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9589 = Fcons (AREF (Vcoding_category_table, priorities[i]), |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
9590 Vcoding_category_list); |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
9591 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9592 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9593 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9594 |
88365 | 9595 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, |
9596 Scoding_system_priority_list, 0, 1, 0, | |
88645 | 9597 doc: /* Return a list of coding systems ordered by their priorities. |
102737
f556415c326b
(Fdetect_coding_region, Fcoding_system_priority_list): Improve the
Kenichi Handa <handa@m17n.org>
parents:
102422
diff
changeset
|
9598 The list contains a subset of coding systems; i.e. coding systems |
f556415c326b
(Fdetect_coding_region, Fcoding_system_priority_list): Improve the
Kenichi Handa <handa@m17n.org>
parents:
102422
diff
changeset
|
9599 assigned to each coding category (see `coding-category-list'). |
f556415c326b
(Fdetect_coding_region, Fcoding_system_priority_list): Improve the
Kenichi Handa <handa@m17n.org>
parents:
102422
diff
changeset
|
9600 |
88645 | 9601 HIGHESTP non-nil means just return the highest priority one. */) |
88365 | 9602 (highestp) |
9603 Lisp_Object highestp; | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9604 { |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
9605 int i; |
22954
928b337d953b
Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents:
22874
diff
changeset
|
9606 Lisp_Object val; |
928b337d953b
Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents:
22874
diff
changeset
|
9607 |
88365 | 9608 for (i = 0, val = Qnil; i < coding_category_max; i++) |
9609 { | |
9610 enum coding_category category = coding_priorities[i]; | |
9611 int id = coding_categories[category].id; | |
9612 Lisp_Object attrs; | |
9613 | |
9614 if (id < 0) | |
9615 continue; | |
9616 attrs = CODING_ID_ATTRS (id); | |
9617 if (! NILP (highestp)) | |
9618 return CODING_ATTR_BASE_NAME (attrs); | |
9619 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
9620 } | |
9621 return Fnreverse (val); | |
9622 } | |
9623 | |
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105877
diff
changeset
|
9624 static const char *const suffixes[] = { "-unix", "-dos", "-mac" }; |
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
9625 |
88365 | 9626 static Lisp_Object |
9627 make_subsidiaries (base) | |
9628 Lisp_Object base; | |
9629 { | |
9630 Lisp_Object subsidiaries; | |
89483 | 9631 int base_name_len = SBYTES (SYMBOL_NAME (base)); |
88365 | 9632 char *buf = (char *) alloca (base_name_len + 6); |
9633 int i; | |
89483 | 9634 |
9635 bcopy (SDATA (SYMBOL_NAME (base)), buf, base_name_len); | |
88365 | 9636 subsidiaries = Fmake_vector (make_number (3), Qnil); |
9637 for (i = 0; i < 3; i++) | |
9638 { | |
9639 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
9640 ASET (subsidiaries, i, intern (buf)); | |
9641 } | |
9642 return subsidiaries; | |
9643 } | |
9644 | |
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
9645 |
49539
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
9646 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, |
88365 | 9647 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
|
9648 doc: /* For internal use only. |
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
9649 usage: (define-coding-system-internal ...) */) |
88365 | 9650 (nargs, args) |
9651 int nargs; | |
9652 Lisp_Object *args; | |
9653 { | |
9654 Lisp_Object name; | |
9655 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
9656 Lisp_Object attrs; /* Vector of attributes. */ | |
9657 Lisp_Object eol_type; | |
9658 Lisp_Object aliases; | |
9659 Lisp_Object coding_type, charset_list, safe_charsets; | |
9660 enum coding_category category; | |
9661 Lisp_Object tail, val; | |
9662 int max_charset_id = 0; | |
9663 int i; | |
9664 | |
9665 if (nargs < coding_arg_max) | |
9666 goto short_args; | |
9667 | |
9668 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
9669 | |
9670 name = args[coding_arg_name]; | |
9671 CHECK_SYMBOL (name); | |
9672 CODING_ATTR_BASE_NAME (attrs) = name; | |
9673 | |
9674 val = args[coding_arg_mnemonic]; | |
9675 if (! STRINGP (val)) | |
9676 CHECK_CHARACTER (val); | |
9677 CODING_ATTR_MNEMONIC (attrs) = val; | |
9678 | |
9679 coding_type = args[coding_arg_coding_type]; | |
9680 CHECK_SYMBOL (coding_type); | |
9681 CODING_ATTR_TYPE (attrs) = coding_type; | |
9682 | |
9683 charset_list = args[coding_arg_charset_list]; | |
9684 if (SYMBOLP (charset_list)) | |
9685 { | |
9686 if (EQ (charset_list, Qiso_2022)) | |
9687 { | |
9688 if (! EQ (coding_type, Qiso_2022)) | |
9689 error ("Invalid charset-list"); | |
9690 charset_list = Viso_2022_charset_list; | |
9691 } | |
9692 else if (EQ (charset_list, Qemacs_mule)) | |
9693 { | |
9694 if (! EQ (coding_type, Qemacs_mule)) | |
9695 error ("Invalid charset-list"); | |
9696 charset_list = Vemacs_mule_charset_list; | |
9697 } | |
9698 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
9699 if (max_charset_id < XFASTINT (XCAR (tail))) | |
9700 max_charset_id = XFASTINT (XCAR (tail)); | |
9701 } | |
9702 else | |
9703 { | |
9704 charset_list = Fcopy_sequence (charset_list); | |
91046 | 9705 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) |
88365 | 9706 { |
9707 struct charset *charset; | |
9708 | |
91046 | 9709 val = XCAR (tail); |
88365 | 9710 CHECK_CHARSET_GET_CHARSET (val, charset); |
9711 if (EQ (coding_type, Qiso_2022) | |
9712 ? CHARSET_ISO_FINAL (charset) < 0 | |
9713 : EQ (coding_type, Qemacs_mule) | |
9714 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
9715 : 0) | |
9716 error ("Can't handle charset `%s'", | |
89483 | 9717 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
9718 | |
9719 XSETCAR (tail, make_number (charset->id)); | |
88365 | 9720 if (max_charset_id < charset->id) |
9721 max_charset_id = charset->id; | |
9722 } | |
9723 } | |
9724 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
9725 | |
102186
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
9726 safe_charsets = make_uninit_string (max_charset_id + 1); |
a12d39ca6870
* coding.h (struct coding_system): Make safe_charsets a pointer to
Andreas Schwab <schwab@suse.de>
parents:
102115
diff
changeset
|
9727 memset (SDATA (safe_charsets), 255, max_charset_id + 1); |
88365 | 9728 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) |
89483 | 9729 SSET (safe_charsets, XFASTINT (XCAR (tail)), 0); |
88365 | 9730 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; |
9731 | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9732 CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9733 |
88365 | 9734 val = args[coding_arg_decode_translation_table]; |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
9735 if (! CHAR_TABLE_P (val) && ! CONSP (val)) |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
9736 CHECK_SYMBOL (val); |
88365 | 9737 CODING_ATTR_DECODE_TBL (attrs) = val; |
9738 | |
9739 val = args[coding_arg_encode_translation_table]; | |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
9740 if (! CHAR_TABLE_P (val) && ! CONSP (val)) |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
9741 CHECK_SYMBOL (val); |
88365 | 9742 CODING_ATTR_ENCODE_TBL (attrs) = val; |
9743 | |
9744 val = args[coding_arg_post_read_conversion]; | |
9745 CHECK_SYMBOL (val); | |
9746 CODING_ATTR_POST_READ (attrs) = val; | |
9747 | |
9748 val = args[coding_arg_pre_write_conversion]; | |
9749 CHECK_SYMBOL (val); | |
9750 CODING_ATTR_PRE_WRITE (attrs) = val; | |
9751 | |
9752 val = args[coding_arg_default_char]; | |
9753 if (NILP (val)) | |
9754 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
9755 else | |
9756 { | |
89483 | 9757 CHECK_CHARACTER (val); |
88365 | 9758 CODING_ATTR_DEFAULT_CHAR (attrs) = val; |
9759 } | |
9760 | |
89483 | 9761 val = args[coding_arg_for_unibyte]; |
9762 CODING_ATTR_FOR_UNIBYTE (attrs) = NILP (val) ? Qnil : Qt; | |
9763 | |
88365 | 9764 val = args[coding_arg_plist]; |
9765 CHECK_LIST (val); | |
9766 CODING_ATTR_PLIST (attrs) = val; | |
9767 | |
9768 if (EQ (coding_type, Qcharset)) | |
9769 { | |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9770 /* 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
|
9771 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
|
9772 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9773 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
|
9774 coding system. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9775 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9776 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
|
9777 charset whose ID is NUM. |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9778 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9779 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
|
9780 of one of them. The list is sorted by dimensions of the |
89648
d5641a606e08
(Fdefine_coding_system_internal): Fix checking of ascii compatibility.
Kenichi Handa <handa@m17n.org>
parents:
89644
diff
changeset
|
9781 charsets. A charset of smaller dimension comes firtst. */ |
88365 | 9782 val = Fmake_vector (make_number (256), Qnil); |
9783 | |
89653
cbaa9fd1aa5c
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89648
diff
changeset
|
9784 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) |
88365 | 9785 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9786 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
|
9787 int dim = CHARSET_DIMENSION (charset); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9788 int idx = (dim - 1) * 4; |
89483 | 9789 |
89653
cbaa9fd1aa5c
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89648
diff
changeset
|
9790 if (CHARSET_ASCII_COMPATIBLE_P (charset)) |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9791 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9792 |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
9793 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
|
9794 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
|
9795 { |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9796 Lisp_Object tmp, tmp2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9797 int dim2; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9798 |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9799 tmp = AREF (val, i); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9800 if (NILP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9801 tmp = XCAR (tail); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9802 else if (NUMBERP (tmp)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9803 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9804 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
|
9805 if (dim < dim2) |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
9806 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
|
9807 else |
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
9808 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
|
9809 } |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
9810 else |
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9811 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9812 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
|
9813 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9814 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
|
9815 if (dim < dim2) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9816 break; |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9817 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9818 if (NILP (tmp2)) |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9819 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
|
9820 else |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9821 { |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9822 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
|
9823 XSETCAR (tmp2, XCAR (tail)); |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9824 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9825 } |
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
9826 ASET (val, i, tmp); |
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
9827 } |
88365 | 9828 } |
9829 ASET (attrs, coding_attr_charset_valids, val); | |
9830 category = coding_category_charset; | |
9831 } | |
9832 else if (EQ (coding_type, Qccl)) | |
9833 { | |
9834 Lisp_Object valids; | |
89483 | 9835 |
88365 | 9836 if (nargs < coding_arg_ccl_max) |
9837 goto short_args; | |
9838 | |
9839 val = args[coding_arg_ccl_decoder]; | |
9840 CHECK_CCL_PROGRAM (val); | |
9841 if (VECTORP (val)) | |
9842 val = Fcopy_sequence (val); | |
9843 ASET (attrs, coding_attr_ccl_decoder, val); | |
9844 | |
9845 val = args[coding_arg_ccl_encoder]; | |
9846 CHECK_CCL_PROGRAM (val); | |
9847 if (VECTORP (val)) | |
9848 val = Fcopy_sequence (val); | |
9849 ASET (attrs, coding_attr_ccl_encoder, val); | |
9850 | |
9851 val = args[coding_arg_ccl_valids]; | |
9852 valids = Fmake_string (make_number (256), make_number (0)); | |
9853 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
9854 { | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9855 int from, to; |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9856 |
88365 | 9857 val = Fcar (tail); |
9858 if (INTEGERP (val)) | |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9859 { |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9860 from = to = XINT (val); |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9861 if (from < 0 || from > 255) |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9862 args_out_of_range_3 (val, make_number (0), make_number (255)); |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9863 } |
88365 | 9864 else |
9865 { | |
9866 CHECK_CONS (val); | |
89483 | 9867 CHECK_NATNUM_CAR (val); |
9868 CHECK_NATNUM_CDR (val); | |
88365 | 9869 from = XINT (XCAR (val)); |
89483 | 9870 if (from > 255) |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9871 args_out_of_range_3 (XCAR (val), |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9872 make_number (0), make_number (255)); |
88365 | 9873 to = XINT (XCDR (val)); |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9874 if (to < from || to > 255) |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9875 args_out_of_range_3 (XCDR (val), |
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9876 XCAR (val), make_number (255)); |
88365 | 9877 } |
89373
4cc9e57fcabc
(decode_coding_ccl, encode_coding_ccl): Call ccl_driver
Kenichi Handa <handa@m17n.org>
parents:
89331
diff
changeset
|
9878 for (i = from; i <= to; i++) |
89483 | 9879 SSET (valids, i, 1); |
88365 | 9880 } |
9881 ASET (attrs, coding_attr_ccl_valids, valids); | |
89483 | 9882 |
88365 | 9883 category = coding_category_ccl; |
9884 } | |
9885 else if (EQ (coding_type, Qutf_16)) | |
9886 { | |
9887 Lisp_Object bom, endian; | |
9888 | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9889 CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9890 |
88365 | 9891 if (nargs < coding_arg_utf16_max) |
9892 goto short_args; | |
9893 | |
9894 bom = args[coding_arg_utf16_bom]; | |
9895 if (! NILP (bom) && ! EQ (bom, Qt)) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
9896 { |
88365 | 9897 CHECK_CONS (bom); |
89483 | 9898 val = XCAR (bom); |
9899 CHECK_CODING_SYSTEM (val); | |
9900 val = XCDR (bom); | |
9901 CHECK_CODING_SYSTEM (val); | |
88365 | 9902 } |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
9903 ASET (attrs, coding_attr_utf_bom, bom); |
88365 | 9904 |
9905 endian = args[coding_arg_utf16_endian]; | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
9906 CHECK_SYMBOL (endian); |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
9907 if (NILP (endian)) |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
9908 endian = Qbig; |
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
9909 else if (! EQ (endian, Qbig) && ! EQ (endian, Qlittle)) |
89483 | 9910 error ("Invalid endian: %s", SDATA (SYMBOL_NAME (endian))); |
88365 | 9911 ASET (attrs, coding_attr_utf_16_endian, endian); |
9912 | |
9913 category = (CONSP (bom) | |
9914 ? coding_category_utf_16_auto | |
9915 : NILP (bom) | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
9916 ? (EQ (endian, Qbig) |
88365 | 9917 ? coding_category_utf_16_be_nosig |
9918 : coding_category_utf_16_le_nosig) | |
89420
c3e67ce6ee0f
(Qsignature, Qendian): Delete these variables.
Kenichi Handa <handa@m17n.org>
parents:
89418
diff
changeset
|
9919 : (EQ (endian, Qbig) |
88365 | 9920 ? coding_category_utf_16_be |
9921 : coding_category_utf_16_le)); | |
9922 } | |
9923 else if (EQ (coding_type, Qiso_2022)) | |
9924 { | |
9925 Lisp_Object initial, reg_usage, request, flags; | |
89442
7349f4473e7f
(detected_mask): Delete unused variable.
Kenichi Handa <handa@m17n.org>
parents:
89429
diff
changeset
|
9926 int i; |
88365 | 9927 |
9928 if (nargs < coding_arg_iso2022_max) | |
9929 goto short_args; | |
9930 | |
9931 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
9932 CHECK_VECTOR (initial); | |
9933 for (i = 0; i < 4; i++) | |
9934 { | |
9935 val = Faref (initial, make_number (i)); | |
9936 if (! NILP (val)) | |
9937 { | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9938 struct charset *charset; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9939 |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9940 CHECK_CHARSET_GET_CHARSET (val, charset); |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9941 ASET (initial, i, make_number (CHARSET_ID (charset))); |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9942 if (i == 0 && CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
9943 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 9944 } |
9945 else | |
9946 ASET (initial, i, make_number (-1)); | |
9947 } | |
9948 | |
9949 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
9950 CHECK_CONS (reg_usage); | |
89483 | 9951 CHECK_NUMBER_CAR (reg_usage); |
9952 CHECK_NUMBER_CDR (reg_usage); | |
88365 | 9953 |
9954 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
9955 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
9956 { | |
9957 int id; | |
89483 | 9958 Lisp_Object tmp; |
88365 | 9959 |
9960 val = Fcar (tail); | |
9961 CHECK_CONS (val); | |
89483 | 9962 tmp = XCAR (val); |
9963 CHECK_CHARSET_GET_ID (tmp, id); | |
9964 CHECK_NATNUM_CDR (val); | |
88365 | 9965 if (XINT (XCDR (val)) >= 4) |
9966 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
89483 | 9967 XSETCAR (val, make_number (id)); |
88365 | 9968 } |
9969 | |
9970 flags = args[coding_arg_iso2022_flags]; | |
9971 CHECK_NATNUM (flags); | |
9972 i = XINT (flags); | |
9973 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
9974 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
9975 | |
9976 ASET (attrs, coding_attr_iso_initial, initial); | |
9977 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
9978 ASET (attrs, coding_attr_iso_request, request); | |
9979 ASET (attrs, coding_attr_iso_flags, flags); | |
9980 setup_iso_safe_charsets (attrs); | |
9981 | |
9982 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
9983 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
9984 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
9985 ? coding_category_iso_7_else | |
9986 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
9987 ? coding_category_iso_7 | |
9988 : coding_category_iso_7_tight); | |
9989 else | |
9990 { | |
9991 int id = XINT (AREF (initial, 1)); | |
9992 | |
88977
3b05c02eebf2
(Fdefine_coding_system_internal): Fix category setting
Kenichi Handa <handa@m17n.org>
parents:
88950
diff
changeset
|
9993 category = (((i & CODING_ISO_FLAG_LOCKING_SHIFT) |
88365 | 9994 || EQ (args[coding_arg_charset_list], Qiso_2022) |
9995 || id < 0) | |
9996 ? coding_category_iso_8_else | |
9997 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
9998 ? coding_category_iso_8_1 | |
9999 : coding_category_iso_8_2); | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
10000 } |
89227
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
10001 if (category != coding_category_iso_8_1 |
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
10002 && category != coding_category_iso_8_2) |
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
10003 CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; |
88365 | 10004 } |
10005 else if (EQ (coding_type, Qemacs_mule)) | |
10006 { | |
10007 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
10008 ASET (attrs, coding_attr_emacs_mule_full, Qt); | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10009 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 10010 category = coding_category_emacs_mule; |
10011 } | |
10012 else if (EQ (coding_type, Qshift_jis)) | |
10013 { | |
10014 | |
10015 struct charset *charset; | |
10016 | |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
10017 if (XINT (Flength (charset_list)) != 3 |
89739
293c9235be3f
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89732
diff
changeset
|
10018 && XINT (Flength (charset_list)) != 4) |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
10019 error ("There should be three or four charsets"); |
88365 | 10020 |
10021 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
10022 if (CHARSET_DIMENSION (charset) != 1) | |
10023 error ("Dimension of charset %s is not one", | |
89483 | 10024 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10025 if (CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10026 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 10027 |
10028 charset_list = XCDR (charset_list); | |
10029 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
10030 if (CHARSET_DIMENSION (charset) != 1) | |
10031 error ("Dimension of charset %s is not one", | |
89483 | 10032 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
88365 | 10033 |
10034 charset_list = XCDR (charset_list); | |
10035 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
10036 if (CHARSET_DIMENSION (charset) != 2) | |
10037 error ("Dimension of charset %s is not two", | |
89483 | 10038 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
88365 | 10039 |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
10040 charset_list = XCDR (charset_list); |
89740
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10041 if (! NILP (charset_list)) |
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10042 { |
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10043 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); |
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10044 if (CHARSET_DIMENSION (charset) != 2) |
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10045 error ("Dimension of charset %s is not two", |
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10046 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
78c1fd14ed42
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89739
diff
changeset
|
10047 } |
89732
8acde12aba89
(get_translation_table): New function.
Kenichi Handa <handa@m17n.org>
parents:
89730
diff
changeset
|
10048 |
88365 | 10049 category = coding_category_sjis; |
10050 Vsjis_coding_system = name; | |
10051 } | |
10052 else if (EQ (coding_type, Qbig5)) | |
10053 { | |
10054 struct charset *charset; | |
10055 | |
10056 if (XINT (Flength (charset_list)) != 2) | |
10057 error ("There should be just two charsets"); | |
10058 | |
10059 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
10060 if (CHARSET_DIMENSION (charset) != 1) | |
10061 error ("Dimension of charset %s is not one", | |
89483 | 10062 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10063 if (CHARSET_ASCII_COMPATIBLE_P (charset)) |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10064 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
88365 | 10065 |
10066 charset_list = XCDR (charset_list); | |
10067 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
10068 if (CHARSET_DIMENSION (charset) != 2) | |
10069 error ("Dimension of charset %s is not two", | |
89483 | 10070 SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); |
88365 | 10071 |
10072 category = coding_category_big5; | |
10073 Vbig5_coding_system = name; | |
10074 } | |
10075 else if (EQ (coding_type, Qraw_text)) | |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10076 { |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10077 category = coding_category_raw_text; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10078 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10079 } |
88365 | 10080 else if (EQ (coding_type, Qutf_8)) |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10081 { |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10082 Lisp_Object bom; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10083 |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10084 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10085 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10086 if (nargs < coding_arg_utf8_max) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10087 goto short_args; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10088 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10089 bom = args[coding_arg_utf8_bom]; |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10090 if (! NILP (bom) && ! EQ (bom, Qt)) |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10091 { |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10092 CHECK_CONS (bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10093 val = XCAR (bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10094 CHECK_CODING_SYSTEM (val); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10095 val = XCDR (bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10096 CHECK_CODING_SYSTEM (val); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10097 } |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10098 ASET (attrs, coding_attr_utf_bom, bom); |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10099 |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10100 category = (CONSP (bom) ? coding_category_utf_8_auto |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10101 : NILP (bom) ? coding_category_utf_8_nosig |
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10102 : coding_category_utf_8_sig); |
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
10103 } |
88365 | 10104 else if (EQ (coding_type, Qundecided)) |
10105 category = coding_category_undecided; | |
10106 else | |
10107 error ("Invalid coding system type: %s", | |
89483 | 10108 SDATA (SYMBOL_NAME (coding_type))); |
88365 | 10109 |
10110 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
89468
7dbbe692f70c
* coding.c (QCcategory): New variable.
Kenichi Handa <handa@m17n.org>
parents:
89467
diff
changeset
|
10111 CODING_ATTR_PLIST (attrs) |
7dbbe692f70c
* coding.c (QCcategory): New variable.
Kenichi Handa <handa@m17n.org>
parents:
89467
diff
changeset
|
10112 = Fcons (QCcategory, Fcons (AREF (Vcoding_category_table, category), |
7dbbe692f70c
* coding.c (QCcategory): New variable.
Kenichi Handa <handa@m17n.org>
parents:
89467
diff
changeset
|
10113 CODING_ATTR_PLIST (attrs))); |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10114 CODING_ATTR_PLIST (attrs) |
93877
62d97ebb13a9
* coding.c (detect_coding_emacs_mule)
Michael Albinus <michael.albinus@gmx.de>
parents:
93595
diff
changeset
|
10115 = Fcons (QCascii_compatible_p, |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10116 Fcons (CODING_ATTR_ASCII_COMPAT (attrs), |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10117 CODING_ATTR_PLIST (attrs))); |
88365 | 10118 |
10119 eol_type = args[coding_arg_eol_type]; | |
10120 if (! NILP (eol_type) | |
10121 && ! EQ (eol_type, Qunix) | |
10122 && ! EQ (eol_type, Qdos) | |
10123 && ! EQ (eol_type, Qmac)) | |
10124 error ("Invalid eol-type"); | |
10125 | |
10126 aliases = Fcons (name, Qnil); | |
10127 | |
10128 if (NILP (eol_type)) | |
10129 { | |
10130 eol_type = make_subsidiaries (name); | |
10131 for (i = 0; i < 3; i++) | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
10132 { |
88365 | 10133 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
10134 | |
10135 this_name = AREF (eol_type, i); | |
10136 this_aliases = Fcons (this_name, Qnil); | |
10137 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
10138 this_spec = Fmake_vector (make_number (3), attrs); | |
10139 ASET (this_spec, 1, this_aliases); | |
10140 ASET (this_spec, 2, this_eol_type); | |
10141 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
10142 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
90289
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10143 val = Fassoc (Fsymbol_name (this_name), Vcoding_system_alist); |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10144 if (NILP (val)) |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10145 Vcoding_system_alist |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10146 = Fcons (Fcons (Fsymbol_name (this_name), Qnil), |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10147 Vcoding_system_alist); |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
10148 } |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10149 } |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
10150 |
88365 | 10151 spec_vec = Fmake_vector (make_number (3), attrs); |
10152 ASET (spec_vec, 1, aliases); | |
10153 ASET (spec_vec, 2, eol_type); | |
10154 | |
10155 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
10156 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
90289
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10157 val = Fassoc (Fsymbol_name (name), Vcoding_system_alist); |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10158 if (NILP (val)) |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10159 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10160 Vcoding_system_alist); |
88365 | 10161 |
10162 { | |
10163 int id = coding_categories[category].id; | |
10164 | |
10165 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
10166 setup_coding_system (name, &coding_categories[category]); | |
10167 } | |
10168 | |
10169 return Qnil; | |
10170 | |
10171 short_args: | |
10172 return Fsignal (Qwrong_number_of_arguments, | |
10173 Fcons (intern ("define-coding-system-internal"), | |
10174 make_number (nargs))); | |
10175 } | |
10176 | |
89571
242f2cc0134b
(Fdefine_coding_system_alias): Update Vcoding_system_list.
Kenichi Handa <handa@m17n.org>
parents:
89562
diff
changeset
|
10177 |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10178 DEFUN ("coding-system-put", Fcoding_system_put, Scoding_system_put, |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10179 3, 3, 0, |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10180 doc: /* Change value in CODING-SYSTEM's property list PROP to VAL. */) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10181 (coding_system, prop, val) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10182 Lisp_Object coding_system, prop, val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10183 { |
89924
7d0f6da3ea6e
(detect_coding): Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
89917
diff
changeset
|
10184 Lisp_Object spec, attrs; |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10185 |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10186 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10187 attrs = AREF (spec, 0); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10188 if (EQ (prop, QCmnemonic)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10189 { |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10190 if (! STRINGP (val)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10191 CHECK_CHARACTER (val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10192 CODING_ATTR_MNEMONIC (attrs) = val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10193 } |
100303
3e044fa54e4f
* coding.c (QCdefault_char): Rename from QCdefalut_char.
Juanma Barranquero <lekktu@gmail.com>
parents:
100262
diff
changeset
|
10194 else if (EQ (prop, QCdefault_char)) |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10195 { |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10196 if (NILP (val)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10197 val = make_number (' '); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10198 else |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10199 CHECK_CHARACTER (val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10200 CODING_ATTR_DEFAULT_CHAR (attrs) = val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10201 } |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10202 else if (EQ (prop, QCdecode_translation_table)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10203 { |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10204 if (! CHAR_TABLE_P (val) && ! CONSP (val)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10205 CHECK_SYMBOL (val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10206 CODING_ATTR_DECODE_TBL (attrs) = val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10207 } |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10208 else if (EQ (prop, QCencode_translation_table)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10209 { |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10210 if (! CHAR_TABLE_P (val) && ! CONSP (val)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10211 CHECK_SYMBOL (val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10212 CODING_ATTR_ENCODE_TBL (attrs) = val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10213 } |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10214 else if (EQ (prop, QCpost_read_conversion)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10215 { |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10216 CHECK_SYMBOL (val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10217 CODING_ATTR_POST_READ (attrs) = val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10218 } |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10219 else if (EQ (prop, QCpre_write_conversion)) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10220 { |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10221 CHECK_SYMBOL (val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10222 CODING_ATTR_PRE_WRITE (attrs) = val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10223 } |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10224 else if (EQ (prop, QCascii_compatible_p)) |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10225 { |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10226 CODING_ATTR_ASCII_COMPAT (attrs) = val; |
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10227 } |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10228 |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10229 CODING_ATTR_PLIST (attrs) |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10230 = Fplist_put (CODING_ATTR_PLIST (attrs), prop, val); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10231 return val; |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10232 } |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10233 |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10234 |
88365 | 10235 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, |
10236 Sdefine_coding_system_alias, 2, 2, 0, | |
10237 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
10238 (alias, coding_system) | |
10239 Lisp_Object alias, coding_system; | |
10240 { | |
90289
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10241 Lisp_Object spec, aliases, eol_type, val; |
88365 | 10242 |
10243 CHECK_SYMBOL (alias); | |
10244 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
10245 aliases = AREF (spec, 1); | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
10246 /* ALIASES should be a list of length more than zero, and the first |
89571
242f2cc0134b
(Fdefine_coding_system_alias): Update Vcoding_system_list.
Kenichi Handa <handa@m17n.org>
parents:
89562
diff
changeset
|
10247 element is a base coding system. Append ALIAS at the tail of the |
242f2cc0134b
(Fdefine_coding_system_alias): Update Vcoding_system_list.
Kenichi Handa <handa@m17n.org>
parents:
89562
diff
changeset
|
10248 list. */ |
88365 | 10249 while (!NILP (XCDR (aliases))) |
10250 aliases = XCDR (aliases); | |
89483 | 10251 XSETCDR (aliases, Fcons (alias, Qnil)); |
88365 | 10252 |
10253 eol_type = AREF (spec, 2); | |
10254 if (VECTORP (eol_type)) | |
10255 { | |
10256 Lisp_Object subsidiaries; | |
10257 int i; | |
10258 | |
10259 subsidiaries = make_subsidiaries (alias); | |
10260 for (i = 0; i < 3; i++) | |
10261 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
10262 AREF (eol_type, i)); | |
10263 } | |
10264 | |
10265 Fputhash (alias, spec, Vcoding_system_hash_table); | |
89571
242f2cc0134b
(Fdefine_coding_system_alias): Update Vcoding_system_list.
Kenichi Handa <handa@m17n.org>
parents:
89562
diff
changeset
|
10266 Vcoding_system_list = Fcons (alias, Vcoding_system_list); |
90289
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10267 val = Fassoc (Fsymbol_name (alias), Vcoding_system_alist); |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10268 if (NILP (val)) |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10269 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
72d8a45f6c9f
(Fdefine_coding_system_internal): Avoid a duplicated
Kenichi Handa <handa@m17n.org>
parents:
90272
diff
changeset
|
10270 Vcoding_system_alist); |
88365 | 10271 |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10272 return Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10273 } |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10274 |
88365 | 10275 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
10276 1, 1, 0, | |
10277 doc: /* Return the base of CODING-SYSTEM. | |
88645 | 10278 Any alias or subsidiary coding system is not a base coding system. */) |
88365 | 10279 (coding_system) |
10280 Lisp_Object coding_system; | |
10281 { | |
10282 Lisp_Object spec, attrs; | |
10283 | |
10284 if (NILP (coding_system)) | |
10285 return (Qno_conversion); | |
10286 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
10287 attrs = AREF (spec, 0); | |
10288 return CODING_ATTR_BASE_NAME (attrs); | |
10289 } | |
10290 | |
10291 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
10292 1, 1, 0, | |
10293 doc: "Return the property list of CODING-SYSTEM.") | |
49539
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10294 (coding_system) |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10295 Lisp_Object coding_system; |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10296 { |
88365 | 10297 Lisp_Object spec, attrs; |
10298 | |
10299 if (NILP (coding_system)) | |
10300 coding_system = Qno_conversion; | |
10301 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
10302 attrs = AREF (spec, 0); | |
10303 return CODING_ATTR_PLIST (attrs); | |
10304 } | |
10305 | |
10306 | |
10307 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
10308 1, 1, 0, | |
88645 | 10309 doc: /* Return the list of aliases of CODING-SYSTEM. */) |
88365 | 10310 (coding_system) |
10311 Lisp_Object coding_system; | |
10312 { | |
10313 Lisp_Object spec; | |
10314 | |
10315 if (NILP (coding_system)) | |
10316 coding_system = Qno_conversion; | |
10317 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
88645 | 10318 return AREF (spec, 1); |
88365 | 10319 } |
10320 | |
10321 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
10322 Scoding_system_eol_type, 1, 1, 0, | |
10323 doc: /* Return eol-type of CODING-SYSTEM. | |
95088
524350e4961c
(Fcoding_system_p): Rename argument to match docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94963
diff
changeset
|
10324 An eol-type is an integer 0, 1, 2, or a vector of coding systems. |
88365 | 10325 |
10326 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
10327 and CR respectively. | |
10328 | |
10329 A vector value indicates that a format of end-of-line should be | |
10330 detected automatically. Nth element of the vector is the subsidiary | |
10331 coding system whose eol-type is N. */) | |
10332 (coding_system) | |
10333 Lisp_Object coding_system; | |
10334 { | |
10335 Lisp_Object spec, eol_type; | |
10336 int n; | |
10337 | |
10338 if (NILP (coding_system)) | |
10339 coding_system = Qno_conversion; | |
10340 if (! CODING_SYSTEM_P (coding_system)) | |
10341 return Qnil; | |
10342 spec = CODING_SYSTEM_SPEC (coding_system); | |
10343 eol_type = AREF (spec, 2); | |
10344 if (VECTORP (eol_type)) | |
10345 return Fcopy_sequence (eol_type); | |
10346 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
10347 return make_number (n); | |
49539
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10348 } |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10349 |
17052 | 10350 #endif /* emacs */ |
10351 | |
10352 | |
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
10353 /*** 9. Post-amble ***/ |
17052 | 10354 |
21514 | 10355 void |
17052 | 10356 init_coding_once () |
10357 { | |
10358 int i; | |
10359 | |
88365 | 10360 for (i = 0; i < coding_category_max; i++) |
10361 { | |
10362 coding_categories[i].id = -1; | |
10363 coding_priorities[i] = i; | |
10364 } | |
17052 | 10365 |
10366 /* ISO2022 specific initialize routine. */ | |
10367 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
|
10368 iso_code_class[i] = ISO_control_0; |
17052 | 10369 for (i = 0x21; i < 0x7F; i++) |
10370 iso_code_class[i] = ISO_graphic_plane_0; | |
10371 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
|
10372 iso_code_class[i] = ISO_control_1; |
17052 | 10373 for (i = 0xA1; i < 0xFF; i++) |
10374 iso_code_class[i] = ISO_graphic_plane_1; | |
10375 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
10376 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
10377 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
10378 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
10379 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
10380 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
10381 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
10382 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
10383 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
10384 | |
88365 | 10385 for (i = 0; i < 256; i++) |
10386 { | |
10387 emacs_mule_bytes[i] = 1; | |
10388 } | |
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
10389 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
|
10390 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
|
10391 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
|
10392 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
|
10393 } |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
10394 |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
10395 #ifdef emacs |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
10396 |
21514 | 10397 void |
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
10398 syms_of_coding () |
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
10399 { |
88365 | 10400 staticpro (&Vcoding_system_hash_table); |
89483 | 10401 { |
10402 Lisp_Object args[2]; | |
10403 args[0] = QCtest; | |
10404 args[1] = Qeq; | |
10405 Vcoding_system_hash_table = Fmake_hash_table (2, args); | |
10406 } | |
88365 | 10407 |
10408 staticpro (&Vsjis_coding_system); | |
10409 Vsjis_coding_system = Qnil; | |
10410 | |
10411 staticpro (&Vbig5_coding_system); | |
10412 Vbig5_coding_system = Qnil; | |
10413 | |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
10414 staticpro (&Vcode_conversion_reused_workbuf); |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
10415 Vcode_conversion_reused_workbuf = Qnil; |
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
10416 |
58637
ff8a37b5299b
(Vcode_conversion_workbuf_name): New variable.
Kenichi Handa <handa@m17n.org>
parents:
58502
diff
changeset
|
10417 staticpro (&Vcode_conversion_workbuf_name); |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10418 Vcode_conversion_workbuf_name = make_pure_c_string (" *code-conversion-work*"); |
58637
ff8a37b5299b
(Vcode_conversion_workbuf_name): New variable.
Kenichi Handa <handa@m17n.org>
parents:
58502
diff
changeset
|
10419 |
89665
9010cefe8d29
(enum iso_code_class_type): Delete ISO_carriage_return.
Kenichi Handa <handa@m17n.org>
parents:
89653
diff
changeset
|
10420 reused_workbuf_in_use = 0; |
88365 | 10421 |
10422 DEFSYM (Qcharset, "charset"); | |
10423 DEFSYM (Qtarget_idx, "target-idx"); | |
10424 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
10425 Fset (Qcoding_system_history, Qnil); |
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
10426 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
10427 /* 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
|
10428 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
|
10429 /* 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
|
10430 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
|
10431 |
88365 | 10432 DEFSYM (Qcall_process, "call-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
10433 /* 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
|
10434 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
|
10435 |
88365 | 10436 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
|
10437 /* 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
|
10438 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
|
10439 |
88365 | 10440 DEFSYM (Qstart_process, "start-process"); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
10441 /* 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
|
10442 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
|
10443 |
88365 | 10444 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
|
10445 /* 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
|
10446 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
|
10447 |
88365 | 10448 DEFSYM (Qcoding_system, "coding-system"); |
10449 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
10450 | |
10451 DEFSYM (Qeol_type, "eol-type"); | |
10452 DEFSYM (Qunix, "unix"); | |
10453 DEFSYM (Qdos, "dos"); | |
10454 | |
10455 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
10456 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
10457 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
10458 DEFSYM (Qdefault_char, "default-char"); | |
10459 DEFSYM (Qundecided, "undecided"); | |
10460 DEFSYM (Qno_conversion, "no-conversion"); | |
10461 DEFSYM (Qraw_text, "raw-text"); | |
10462 | |
10463 DEFSYM (Qiso_2022, "iso-2022"); | |
10464 | |
10465 DEFSYM (Qutf_8, "utf-8"); | |
89483 | 10466 DEFSYM (Qutf_8_emacs, "utf-8-emacs"); |
88365 | 10467 |
10468 DEFSYM (Qutf_16, "utf-16"); | |
10469 DEFSYM (Qbig, "big"); | |
10470 DEFSYM (Qlittle, "little"); | |
10471 | |
10472 DEFSYM (Qshift_jis, "shift-jis"); | |
10473 DEFSYM (Qbig5, "big5"); | |
10474 | |
10475 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
10476 | |
10477 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
17052 | 10478 Fput (Qcoding_system_error, Qerror_conditions, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10479 pure_cons (Qcoding_system_error, pure_cons (Qerror, Qnil))); |
17052 | 10480 Fput (Qcoding_system_error, Qerror_message, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10481 make_pure_c_string ("Invalid coding system")); |
17052 | 10482 |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
10483 /* 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
|
10484 Setting this variable twice is harmless. |
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
10485 But don't staticpro it here--that is done in alloc.c. */ |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10486 Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots"); |
88365 | 10487 |
10488 DEFSYM (Qtranslation_table, "translation-table"); | |
89856
18b52da60a76
(get_translation): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89852
diff
changeset
|
10489 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (2)); |
88365 | 10490 DEFSYM (Qtranslation_table_id, "translation-table-id"); |
10491 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
10492 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
10493 | |
10494 DEFSYM (Qvalid_codes, "valid-codes"); | |
10495 | |
10496 DEFSYM (Qemacs_mule, "emacs-mule"); | |
10497 | |
89468
7dbbe692f70c
* coding.c (QCcategory): New variable.
Kenichi Handa <handa@m17n.org>
parents:
89467
diff
changeset
|
10498 DEFSYM (QCcategory, ":category"); |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10499 DEFSYM (QCmnemonic, ":mnemonic"); |
100303
3e044fa54e4f
* coding.c (QCdefault_char): Rename from QCdefalut_char.
Juanma Barranquero <lekktu@gmail.com>
parents:
100262
diff
changeset
|
10500 DEFSYM (QCdefault_char, ":default-char"); |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10501 DEFSYM (QCdecode_translation_table, ":decode-translation-table"); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10502 DEFSYM (QCencode_translation_table, ":encode-translation-table"); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10503 DEFSYM (QCpost_read_conversion, ":post-read-conversion"); |
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10504 DEFSYM (QCpre_write_conversion, ":pre-write-conversion"); |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10505 DEFSYM (QCascii_compatible_p, ":ascii-compatible-p"); |
89468
7dbbe692f70c
* coding.c (QCcategory): New variable.
Kenichi Handa <handa@m17n.org>
parents:
89467
diff
changeset
|
10506 |
88365 | 10507 Vcoding_category_table |
10508 = Fmake_vector (make_number (coding_category_max), Qnil); | |
10509 staticpro (&Vcoding_category_table); | |
10510 /* Followings are target of code detection. */ | |
10511 ASET (Vcoding_category_table, coding_category_iso_7, | |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10512 intern_c_string ("coding-category-iso-7")); |
88365 | 10513 ASET (Vcoding_category_table, coding_category_iso_7_tight, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10514 intern_c_string ("coding-category-iso-7-tight")); |
88365 | 10515 ASET (Vcoding_category_table, coding_category_iso_8_1, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10516 intern_c_string ("coding-category-iso-8-1")); |
88365 | 10517 ASET (Vcoding_category_table, coding_category_iso_8_2, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10518 intern_c_string ("coding-category-iso-8-2")); |
88365 | 10519 ASET (Vcoding_category_table, coding_category_iso_7_else, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10520 intern_c_string ("coding-category-iso-7-else")); |
88365 | 10521 ASET (Vcoding_category_table, coding_category_iso_8_else, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10522 intern_c_string ("coding-category-iso-8-else")); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10523 ASET (Vcoding_category_table, coding_category_utf_8_auto, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10524 intern_c_string ("coding-category-utf-8-auto")); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10525 ASET (Vcoding_category_table, coding_category_utf_8_nosig, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10526 intern_c_string ("coding-category-utf-8")); |
95397
c99f0a16c077
(CODING_UTF_8_BOM): New macro.
Kenichi Handa <handa@m17n.org>
parents:
95356
diff
changeset
|
10527 ASET (Vcoding_category_table, coding_category_utf_8_sig, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10528 intern_c_string ("coding-category-utf-8-sig")); |
88365 | 10529 ASET (Vcoding_category_table, coding_category_utf_16_be, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10530 intern_c_string ("coding-category-utf-16-be")); |
89467
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10531 ASET (Vcoding_category_table, coding_category_utf_16_auto, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10532 intern_c_string ("coding-category-utf-16-auto")); |
88365 | 10533 ASET (Vcoding_category_table, coding_category_utf_16_le, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10534 intern_c_string ("coding-category-utf-16-le")); |
88365 | 10535 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10536 intern_c_string ("coding-category-utf-16-be-nosig")); |
88365 | 10537 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10538 intern_c_string ("coding-category-utf-16-le-nosig")); |
88365 | 10539 ASET (Vcoding_category_table, coding_category_charset, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10540 intern_c_string ("coding-category-charset")); |
88365 | 10541 ASET (Vcoding_category_table, coding_category_sjis, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10542 intern_c_string ("coding-category-sjis")); |
88365 | 10543 ASET (Vcoding_category_table, coding_category_big5, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10544 intern_c_string ("coding-category-big5")); |
88365 | 10545 ASET (Vcoding_category_table, coding_category_ccl, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10546 intern_c_string ("coding-category-ccl")); |
88365 | 10547 ASET (Vcoding_category_table, coding_category_emacs_mule, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10548 intern_c_string ("coding-category-emacs-mule")); |
88365 | 10549 /* Followings are NOT target of code detection. */ |
10550 ASET (Vcoding_category_table, coding_category_raw_text, | |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10551 intern_c_string ("coding-category-raw-text")); |
88365 | 10552 ASET (Vcoding_category_table, coding_category_undecided, |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10553 intern_c_string ("coding-category-undecided")); |
88365 | 10554 |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10555 DEFSYM (Qinsufficient_source, "insufficient-source"); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10556 DEFSYM (Qinconsistent_eol, "inconsistent-eol"); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10557 DEFSYM (Qinvalid_source, "invalid-source"); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10558 DEFSYM (Qinterrupted, "interrupted"); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10559 DEFSYM (Qinsufficient_memory, "insufficient-memory"); |
90272
f1df126ec7de
Sync to HEAD for handling autoload-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
90263
diff
changeset
|
10560 DEFSYM (Qcoding_system_define_form, "coding-system-define-form"); |
52794
f4d906e31662
(Qcoding_system_define_form): New variable.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
10561 |
17052 | 10562 defsubr (&Scoding_system_p); |
10563 defsubr (&Sread_coding_system); | |
10564 defsubr (&Sread_non_nil_coding_system); | |
10565 defsubr (&Scheck_coding_system); | |
10566 defsubr (&Sdetect_coding_region); | |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10567 defsubr (&Sdetect_coding_string); |
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
10568 defsubr (&Sfind_coding_systems_region_internal); |
46859
a26dd8891732
(unencodable_char_position): New function.
Kenichi Handa <handa@m17n.org>
parents:
46839
diff
changeset
|
10569 defsubr (&Sunencodable_char_position); |
88365 | 10570 defsubr (&Scheck_coding_systems_region); |
17052 | 10571 defsubr (&Sdecode_coding_region); |
10572 defsubr (&Sencode_coding_region); | |
10573 defsubr (&Sdecode_coding_string); | |
10574 defsubr (&Sencode_coding_string); | |
10575 defsubr (&Sdecode_sjis_char); | |
10576 defsubr (&Sencode_sjis_char); | |
10577 defsubr (&Sdecode_big5_char); | |
10578 defsubr (&Sencode_big5_char); | |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
10579 defsubr (&Sset_terminal_coding_system_internal); |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
10580 defsubr (&Sset_safe_terminal_coding_system_internal); |
17052 | 10581 defsubr (&Sterminal_coding_system); |
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
10582 defsubr (&Sset_keyboard_coding_system_internal); |
17052 | 10583 defsubr (&Skeyboard_coding_system); |
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
10584 defsubr (&Sfind_operation_coding_system); |
88365 | 10585 defsubr (&Sset_coding_system_priority); |
49539
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10586 defsubr (&Sdefine_coding_system_internal); |
88365 | 10587 defsubr (&Sdefine_coding_system_alias); |
89759
d11866e9fbf4
(QCmnemonic, QCdefalut_char)
Kenichi Handa <handa@m17n.org>
parents:
89740
diff
changeset
|
10588 defsubr (&Scoding_system_put); |
88365 | 10589 defsubr (&Scoding_system_base); |
10590 defsubr (&Scoding_system_plist); | |
10591 defsubr (&Scoding_system_aliases); | |
10592 defsubr (&Scoding_system_eol_type); | |
10593 defsubr (&Scoding_system_priority_list); | |
17052 | 10594 |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
10595 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
|
10596 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
|
10597 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10598 Do not alter the value of this variable manually. This variable should be |
88365 | 10599 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
|
10600 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
10601 Vcoding_system_list = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
10602 |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
10603 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
|
10604 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
|
10605 Each element is one element list of coding system name. |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10606 This variable is given to `completing-read' as COLLECTION argument. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10607 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10608 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
|
10609 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
|
10610 `define-coding-system-alias'. */); |
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
10611 Vcoding_system_alist = Qnil; |
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
10612 |
17052 | 10613 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
|
10614 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
|
10615 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10616 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
|
10617 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
|
10618 one algorithm agrees with a byte sequence of source text, the coding |
60608
4b80e9c28e8f
(syms_of_coding): Docstring of coding-category-list fixed.
Kenichi Handa <handa@m17n.org>
parents:
60031
diff
changeset
|
10619 system bound to the corresponding coding-category is selected. |
4b80e9c28e8f
(syms_of_coding): Docstring of coding-category-list fixed.
Kenichi Handa <handa@m17n.org>
parents:
60031
diff
changeset
|
10620 |
61166
e3a6dd630fdf
(Vcoding_category_list): Docstring fix.
Kenichi Handa <handa@m17n.org>
parents:
60907
diff
changeset
|
10621 Don't modify this variable directly, but use `set-coding-priority'. */); |
17052 | 10622 { |
10623 int i; | |
10624 | |
10625 Vcoding_category_list = Qnil; | |
88365 | 10626 for (i = coding_category_max - 1; i >= 0; i--) |
17052 | 10627 Vcoding_category_list |
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10628 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10629 Vcoding_category_list); |
17052 | 10630 } |
10631 | |
10632 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
|
10633 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
|
10634 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
|
10635 If the value is a coding system, it is used for decoding on read operation. |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10636 If not, an appropriate element is used from one of the coding system alists. |
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10637 There are three such tables: `file-coding-system-alist', |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10638 `process-coding-system-alist', and `network-coding-system-alist'. */); |
17052 | 10639 Vcoding_system_for_read = Qnil; |
10640 | |
10641 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
|
10642 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
|
10643 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
|
10644 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
|
10645 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
|
10646 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10647 If this does not specify a coding system, an appropriate element |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10648 is used from one of the coding system alists. |
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10649 There are three such tables: `file-coding-system-alist', |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10650 `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
|
10651 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
|
10652 the value of `buffer-file-coding-system' is used. */); |
17052 | 10653 Vcoding_system_for_write = Qnil; |
10654 | |
10655 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
88365 | 10656 doc: /* |
10657 Coding system used in the latest file or process I/O. */); | |
17052 | 10658 Vlast_coding_system_used = Qnil; |
10659 | |
89686
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10660 DEFVAR_LISP ("last-code-conversion-error", &Vlast_code_conversion_error, |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10661 doc: /* |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10662 Error status of the last code conversion. |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10663 |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10664 When an error was detected in the last code conversion, this variable |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10665 is set to one of the following symbols. |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10666 `insufficient-source' |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10667 `inconsistent-eol' |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10668 `invalid-source' |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10669 `interrupted' |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10670 `insufficient-memory' |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10671 When no error was detected, the value doesn't change. So, to check |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10672 the error status of a code conversion by this variable, you must |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10673 explicitly set this variable to nil before performing code |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10674 conversion. */); |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10675 Vlast_code_conversion_error = Qnil; |
9bfefb13fe83
(Qinsufficient_source, Qinconsistent_eol)
Kenichi Handa <handa@m17n.org>
parents:
89676
diff
changeset
|
10676 |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
10677 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
88365 | 10678 doc: /* |
10679 *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
|
10680 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
|
10681 such conversion. */); |
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
10682 inhibit_eol_conversion = 0; |
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
10683 |
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
10684 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
88365 | 10685 doc: /* |
10686 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
|
10687 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
|
10688 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
|
10689 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
|
10690 |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10691 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
88365 | 10692 doc: /* |
10693 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
|
10694 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
|
10695 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
|
10696 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
|
10697 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
|
10698 the file contents. |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10699 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
|
10700 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
|
10701 If VAL is a function symbol, the function must return a coding system |
72323
af796bc81ff0
(syms_of_coding): Improve the docstring
Kenichi Handa <handa@m17n.org>
parents:
72188
diff
changeset
|
10702 or a cons of coding systems which are used as above. The function is |
af796bc81ff0
(syms_of_coding): Improve the docstring
Kenichi Handa <handa@m17n.org>
parents:
72188
diff
changeset
|
10703 called with an argument that is a list of the arguments with which |
81611
ae42ad5f89e6
(Ffind_operation_coding_system): Docstring improved.
Kenichi Handa <handa@m17n.org>
parents:
75348
diff
changeset
|
10704 `find-operation-coding-system' was called. If the function can't decide |
ae42ad5f89e6
(Ffind_operation_coding_system): Docstring improved.
Kenichi Handa <handa@m17n.org>
parents:
75348
diff
changeset
|
10705 a coding system, it can return `undecided' so that the normal |
ae42ad5f89e6
(Ffind_operation_coding_system): Docstring improved.
Kenichi Handa <handa@m17n.org>
parents:
75348
diff
changeset
|
10706 code-detection is performed. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10707 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10708 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
|
10709 and the variable `auto-coding-alist'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10710 Vfile_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10711 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10712 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
88365 | 10713 doc: /* |
10714 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
|
10715 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
|
10716 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
|
10717 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
|
10718 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
|
10719 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
|
10720 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
|
10721 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
|
10722 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
|
10723 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
|
10724 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10725 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10726 Vprocess_coding_system_alist = Qnil; |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10727 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10728 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
88365 | 10729 doc: /* |
10730 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
|
10731 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
|
10732 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
|
10733 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
|
10734 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
|
10735 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
|
10736 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
|
10737 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
|
10738 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
|
10739 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
|
10740 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
|
10741 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10742 See also the function `find-operation-coding-system'. */); |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10743 Vnetwork_coding_system_alist = Qnil; |
17052 | 10744 |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10745 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
|
10746 doc: /* Coding system to use with system messages. |
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
10747 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
|
10748 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
|
10749 |
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
10750 /* 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
|
10751 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
88365 | 10752 doc: /* |
10753 *String displayed in mode line for UNIX-like (LF) end-of-line format. */); | |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10754 eol_mnemonic_unix = make_pure_c_string (":"); |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
10755 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
10756 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
88365 | 10757 doc: /* |
10758 *String displayed in mode line for DOS-like (CRLF) end-of-line format. */); | |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10759 eol_mnemonic_dos = make_pure_c_string ("\\"); |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
10760 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
10761 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
88365 | 10762 doc: /* |
10763 *String displayed in mode line for MAC-like (CR) end-of-line format. */); | |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10764 eol_mnemonic_mac = make_pure_c_string ("/"); |
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
10765 |
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
10766 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
88365 | 10767 doc: /* |
10768 *String displayed in mode line when end-of-line format is not yet determined. */); | |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10769 eol_mnemonic_undecided = make_pure_c_string (":"); |
17052 | 10770 |
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
10771 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
88365 | 10772 doc: /* |
10773 *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
|
10774 Venable_character_translation = Qt; |
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
10775 |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
10776 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
|
10777 &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
|
10778 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
|
10779 Vstandard_translation_table_for_decode = Qnil; |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
10780 |
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
10781 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
|
10782 &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
|
10783 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
|
10784 Vstandard_translation_table_for_encode = Qnil; |
17052 | 10785 |
88365 | 10786 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
|
10787 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
|
10788 While encoding, if a charset (car part of an element) is found, |
88365 | 10789 designate it with the escape sequence identifying revision (cdr part |
10790 of the element). */); | |
10791 Vcharset_revision_table = Qnil; | |
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10792 |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10793 DEFVAR_LISP ("default-process-coding-system", |
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
10794 &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
|
10795 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
|
10796 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
|
10797 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
|
10798 Vdefault_process_coding_system = Qnil; |
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
10799 |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
10800 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
88365 | 10801 doc: /* |
10802 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
|
10803 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
|
10804 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
|
10805 \(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
|
10806 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
|
10807 `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
|
10808 or reading output of a subprocess. |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10809 Only 128th through 159th elements have a meaning. */); |
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
10810 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
|
10811 |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10812 DEFVAR_LISP ("select-safe-coding-system-function", |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10813 &Vselect_safe_coding_system_function, |
88365 | 10814 doc: /* |
10815 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
|
10816 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10817 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
|
10818 coding system which can encode the text in the case that a default |
87778
0ec6f8d26078
(select-safe-coding-system-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
87710
diff
changeset
|
10819 coding system used in each operation can't encode the text. The |
0ec6f8d26078
(select-safe-coding-system-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
87710
diff
changeset
|
10820 function should take care that the buffer is not modified while |
0ec6f8d26078
(select-safe-coding-system-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
87710
diff
changeset
|
10821 the coding system is being selected. |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10822 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10823 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
|
10824 Vselect_safe_coding_system_function = Qnil; |
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
10825 |
48874
3002a87cc629
(coding_system_require_warning): New variable.
Kenichi Handa <handa@m17n.org>
parents:
48829
diff
changeset
|
10826 DEFVAR_BOOL ("coding-system-require-warning", |
3002a87cc629
(coding_system_require_warning): New variable.
Kenichi Handa <handa@m17n.org>
parents:
48829
diff
changeset
|
10827 &coding_system_require_warning, |
3002a87cc629
(coding_system_require_warning): New variable.
Kenichi Handa <handa@m17n.org>
parents:
48829
diff
changeset
|
10828 doc: /* Internal use only. |
49539
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10829 If non-nil, on writing a file, `select-safe-coding-system-function' is |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10830 called even if `coding-system-for-write' is non-nil. The command |
1ad5bfbb831a
(syms_of_coding): Add `...' for symbols in the docstring of
Kenichi Handa <handa@m17n.org>
parents:
48874
diff
changeset
|
10831 `universal-coding-system-argument' binds this variable to t temporarily. */); |
48874
3002a87cc629
(coding_system_require_warning): New variable.
Kenichi Handa <handa@m17n.org>
parents:
48829
diff
changeset
|
10832 coding_system_require_warning = 0; |
3002a87cc629
(coding_system_require_warning): New variable.
Kenichi Handa <handa@m17n.org>
parents:
48829
diff
changeset
|
10833 |
3002a87cc629
(coding_system_require_warning): New variable.
Kenichi Handa <handa@m17n.org>
parents:
48829
diff
changeset
|
10834 |
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
10835 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
10836 &inhibit_iso_escape_detection, |
88365 | 10837 doc: /* |
101040 | 10838 If non-nil, Emacs ignores ISO-2022 escape sequences during code detection. |
10839 | |
10840 When Emacs reads text, it tries to detect how the text is encoded. | |
10841 This code detection is sensitive to escape sequences. If Emacs sees | |
10842 a valid ISO-2022 escape sequence, it assumes the text is encoded in one | |
10843 of the ISO2022 encodings, and decodes text by the corresponding coding | |
10844 system (e.g. `iso-2022-7bit'). | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10845 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10846 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
|
10847 a file as is. In such a case, you can set this variable to non-nil. |
101040 | 10848 Then the code detection will ignore any escape sequences, and no text is |
10849 detected as encoded in some ISO-2022 encoding. The result is that all | |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10850 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
|
10851 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10852 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
|
10853 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
|
10854 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
|
10855 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
|
10856 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
|
10857 |
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10858 The other way to read escape sequences in a file without decoding is |
101040 | 10859 to explicitly specify some coding system that doesn't use ISO-2022 |
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
10860 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
|
10861 inhibit_iso_escape_detection = 0; |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
10862 |
101040 | 10863 DEFVAR_BOOL ("inhibit-null-byte-detection", |
10864 &inhibit_null_byte_detection, | |
10865 doc: /* If non-nil, Emacs ignores null bytes on code detection. | |
10866 By default, Emacs treats it as binary data, and does not attempt to | |
10867 decode it. The effect is as if you specified `no-conversion' for | |
10868 reading that text. | |
10869 | |
10870 Set this to non-nil when a regular text happens to include null bytes. | |
10871 Examples are Index nodes of Info files and null-byte delimited output | |
10872 from GNU Find and GNU Grep. Emacs will then ignore the null bytes and | |
10873 decode text as usual. */); | |
10874 inhibit_null_byte_detection = 0; | |
10875 | |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
10876 DEFVAR_LISP ("translation-table-for-input", &Vtranslation_table_for_input, |
48230
c2ce8280fb97
(Vtranslation_table_for_input): New.
Dave Love <fx@gnu.org>
parents:
48182
diff
changeset
|
10877 doc: /* Char table for translating self-inserting characters. |
95356
90b4a0dc21cc
(Fdecode_coding_region, Fencode_coding_region, Fencode_coding_string):
Juanma Barranquero <lekktu@gmail.com>
parents:
95353
diff
changeset
|
10878 This is applied to the result of input methods, not their input. |
101854
7e576fc18303
(syms_of_coding) <translation-table-for-input>: Modify doc string to
Eli Zaretskii <eliz@gnu.org>
parents:
101776
diff
changeset
|
10879 See also `keyboard-translate-table'. |
7e576fc18303
(syms_of_coding) <translation-table-for-input>: Modify doc string to
Eli Zaretskii <eliz@gnu.org>
parents:
101776
diff
changeset
|
10880 |
7e576fc18303
(syms_of_coding) <translation-table-for-input>: Modify doc string to
Eli Zaretskii <eliz@gnu.org>
parents:
101776
diff
changeset
|
10881 Use of this variable for character code unification was rendered |
7e576fc18303
(syms_of_coding) <translation-table-for-input>: Modify doc string to
Eli Zaretskii <eliz@gnu.org>
parents:
101776
diff
changeset
|
10882 obsolete in Emacs 23.1 and later, since Unicode is now the basis of |
7e576fc18303
(syms_of_coding) <translation-table-for-input>: Modify doc string to
Eli Zaretskii <eliz@gnu.org>
parents:
101776
diff
changeset
|
10883 internal character representation. */); |
48182
9474e269efd1
Reformat some DEFUNs so that etags works.
Dave Love <fx@gnu.org>
parents:
48125
diff
changeset
|
10884 Vtranslation_table_for_input = Qnil; |
89483 | 10885 |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10886 { |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10887 Lisp_Object args[coding_arg_max]; |
89483 | 10888 Lisp_Object plist[16]; |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10889 int i; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10890 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10891 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
|
10892 args[i] = Qnil; |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10893 |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10894 plist[0] = intern_c_string (":name"); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10895 plist[1] = args[coding_arg_name] = Qno_conversion; |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10896 plist[2] = intern_c_string (":mnemonic"); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10897 plist[3] = args[coding_arg_mnemonic] = make_number ('='); |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10898 plist[4] = intern_c_string (":coding-type"); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10899 plist[5] = args[coding_arg_coding_type] = Qraw_text; |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10900 plist[6] = intern_c_string (":ascii-compatible-p"); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10901 plist[7] = args[coding_arg_ascii_compatible_p] = Qt; |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10902 plist[8] = intern_c_string (":default-char"); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10903 plist[9] = args[coding_arg_default_char] = make_number (0); |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10904 plist[10] = intern_c_string (":for-unibyte"); |
89483 | 10905 plist[11] = args[coding_arg_for_unibyte] = Qt; |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10906 plist[12] = intern_c_string (":docstring"); |
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10907 plist[13] = make_pure_c_string ("Do no conversion.\n\ |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10908 \n\ |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10909 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
|
10910 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
|
10911 character."); |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10912 plist[14] = intern_c_string (":eol-type"); |
89483 | 10913 plist[15] = args[coding_arg_eol_type] = Qunix; |
10914 args[coding_arg_plist] = Flist (16, plist); | |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10915 Fdefine_coding_system_internal (coding_arg_max, args); |
90011
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10916 |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10917 plist[1] = args[coding_arg_name] = Qundecided; |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10918 plist[3] = args[coding_arg_mnemonic] = make_number ('-'); |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10919 plist[5] = args[coding_arg_coding_type] = Qundecided; |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10920 /* This is already set. |
90214
460ee00505d5
(QCascii_compatible_p): New variable.
Kenichi Handa <handa@m17n.org>
parents:
90201
diff
changeset
|
10921 plist[7] = args[coding_arg_ascii_compatible_p] = Qt; */ |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10922 plist[8] = intern_c_string (":charset-list"); |
90011
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10923 plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil); |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10924 plist[11] = args[coding_arg_for_unibyte] = Qnil; |
105877
21bdda3ded62
* xterm.c (syms_of_xterm):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
10925 plist[13] = make_pure_c_string ("No conversion on encoding, automatic conversion on decoding."); |
90011
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10926 plist[15] = args[coding_arg_eol_type] = Qnil; |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10927 args[coding_arg_plist] = Flist (16, plist); |
26cef35a1562
(setup_coding_system): If coding_system is nil, use
Kenichi Handa <handa@m17n.org>
parents:
89976
diff
changeset
|
10928 Fdefine_coding_system_internal (coding_arg_max, args); |
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10929 } |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10930 |
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
10931 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
89467
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10932 |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10933 { |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10934 int i; |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10935 |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10936 for (i = 0; i < coding_category_max; i++) |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10937 Fset (AREF (Vcoding_category_table, i), Qno_conversion); |
e911ca706166
(Fset_coding_system_priority): Doc fix. Update values
Kenichi Handa <handa@m17n.org>
parents:
89462
diff
changeset
|
10938 } |
90394
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
10939 #if defined (MSDOS) || defined (WINDOWSNT) |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
10940 system_eol_type = Qdos; |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
10941 #else |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
10942 system_eol_type = Qunix; |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
10943 #endif |
263867fe7b55
(system_eol_type): Sync with HEAD.
Kenichi Handa <handa@m17n.org>
parents:
90380
diff
changeset
|
10944 staticpro (&system_eol_type); |
17052 | 10945 } |
10946 | |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10947 char * |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10948 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
|
10949 int error_number; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10950 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10951 char *str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10952 |
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
10953 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
|
10954 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
|
10955 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10956 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
|
10957 { |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10958 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
|
10959 Vlocale_coding_system, |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10960 0); |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
46293
diff
changeset
|
10961 str = (char *) SDATA (dec); |
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10962 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10963 |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10964 return str; |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10965 } |
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
10966 |
17052 | 10967 #endif /* emacs */ |
29184 | 10968 |
52401 | 10969 /* arch-tag: 3a3a2b01-5ff6-4071-9afe-f5b808d9229d |
10970 (do not change this comment) */ |