Mercurial > emacs
annotate src/coding.c @ 89331:1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
(detect_coding_utf_8, detect_coding_utf_16)
(detect_coding_emacs_mule, detect_coding_iso_2022)
(detect_coding_sjis, detect_coding_big5)
(detect_coding_ccl, detect_coding_charset): Change argument MASK
to DETECT_INFO. Update DETECT_INFO and return 1 if the byte
sequence is valid in this coding system. Callers changed.
(MAX_ANNOTATION_LENGTH): New macro.
(ADD_ANNOTATION_DATA): New macro.
(ADD_COMPOSITION_DATA): Argument changed. Callers changed. Call
ADD_ANNOTATION_DATA. The format of annotation data changed.
(ADD_CHARSET_DATA): New macro.
(emacs_mule_char): New argument ID. Callers changed.
(decode_coding_emacs_mule, decode_coding_iso_2022)
(decode_coding_sjis, decode_coding_big5, decode_coding_charset):
Produce charset annotation data in coding->charbuf.
(encode_coding_emacs_mule, encode_coding_iso_2022): Pay attention
to charset annotation data in coding->charbuf.
(setup_coding_system): Add CODING_ANNOTATE_CHARSET_MASK
coding->common_flags if the coding system is iso-2022 based and
uses designation.
(produce_composition): Adjusted for the new annotation data
format.
(produce_charset): New function.
(produce_annotation): Handle charset annotation.
(handle_composition_annotation, handle_charset_annotation): New
functions.
(consume_chars): Handle charset annotation. Utilize the above two
functions.
(encode_coding_object): If SRC_OBJECT and DST_OBJECT are the same
buffer, get the deleted text as a string and set
coding->src_object to that string.
(detect_coding, detect_coding_system): Use the new struct
coding_detection_info.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Mon, 06 Jan 2003 11:37:17 +0000 |
| parents | 1fd77c471ee6 |
| children | 4cc9e57fcabc |
| rev | line source |
|---|---|
| 88936 | 1 /* Coding system handler (conversion, detection, etc). |
| 20708 | 2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. |
|
18269
888bfd80db2c
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18180
diff
changeset
|
3 Licensed to the Free Software Foundation. |
|
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
4 Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
| 88365 | 5 Copyright (C) 2001, 2002 |
| 6 National Institute of Advanced Industrial Science and Technology (AIST) | |
| 7 Registration Number H13PRO009 | |
| 17052 | 8 |
| 17071 | 9 This file is part of GNU Emacs. |
| 10 | |
| 11 GNU Emacs is free software; you can redistribute it and/or modify | |
| 12 it under the terms of the GNU General Public License as published by | |
| 13 the Free Software Foundation; either version 2, or (at your option) | |
| 14 any later version. | |
| 15 | |
| 16 GNU Emacs is distributed in the hope that it will be useful, | |
| 17 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 GNU General Public License for more details. | |
| 20 | |
| 21 You should have received a copy of the GNU General Public License | |
| 22 along with GNU Emacs; see the file COPYING. If not, write to | |
| 23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 24 Boston, MA 02111-1307, USA. */ | |
| 17052 | 25 |
| 26 /*** TABLE OF CONTENTS *** | |
| 27 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
28 0. General comments |
| 17052 | 29 1. Preamble |
| 88365 | 30 2. Emacs' internal format (emacs-utf-8) handlers |
| 31 3. UTF-8 handlers | |
| 32 4. UTF-16 handlers | |
| 33 5. Charset-base coding systems handlers | |
| 34 6. emacs-mule (old Emacs' internal format) handlers | |
| 35 7. ISO2022 handlers | |
| 36 8. Shift-JIS and BIG5 handlers | |
| 37 9. CCL handlers | |
| 38 10. C library functions | |
| 39 11. Emacs Lisp library functions | |
| 40 12. Postamble | |
| 17052 | 41 |
| 42 */ | |
| 43 | |
| 88365 | 44 /*** 0. General comments *** |
| 45 | |
| 46 | |
| 47 CODING SYSTEM | |
| 48 | |
| 88485 | 49 A coding system is an object for an encoding mechanism that contains |
| 50 information about how to convert byte sequences to character | |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
51 sequences and vice versa. When we say "decode", it means converting |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
52 a byte sequence of a specific coding system into a character |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
53 sequence that is represented by Emacs' internal coding system |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
54 `emacs-utf-8', and when we say "encode", it means converting a |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
55 character sequence of emacs-utf-8 to a byte sequence of a specific |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
56 coding system. |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
57 |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
58 In Emacs Lisp, a coding system is represented by a Lisp symbol. In |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
59 C level, a coding system is represented by a vector of attributes |
| 88485 | 60 stored in the hash table Vcharset_hash_table. The conversion from |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
61 coding system symbol to attributes vector is done by looking up |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
62 Vcharset_hash_table by the symbol. |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
63 |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
64 Coding systems are classified into the following types depending on |
| 88485 | 65 the encoding mechanism. Here's a brief description of the types. |
| 88365 | 66 |
| 67 o UTF-8 | |
| 68 | |
| 69 o UTF-16 | |
| 70 | |
| 71 o Charset-base coding system | |
| 72 | |
| 73 A coding system defined by one or more (coded) character sets. | |
| 88485 | 74 Decoding and encoding are done by a code converter defined for each |
| 88365 | 75 character set. |
| 76 | |
| 88485 | 77 o Old Emacs internal format (emacs-mule) |
| 78 | |
| 79 The coding system adopted by old versions of Emacs (20 and 21). | |
| 88365 | 80 |
| 81 o ISO2022-base coding system | |
| 17052 | 82 |
| 83 The most famous coding system for multiple character sets. X's | |
| 88365 | 84 Compound Text, various EUCs (Extended Unix Code), and coding systems |
| 85 used in the Internet communication such as ISO-2022-JP are all | |
| 86 variants of ISO2022. | |
| 87 | |
| 88 o SJIS (or Shift-JIS or MS-Kanji-Code) | |
| 89 | |
| 17052 | 90 A coding system to encode character sets: ASCII, JISX0201, and |
| 91 JISX0208. Widely used for PC's in Japan. Details are described in | |
| 88365 | 92 section 8. |
| 93 | |
| 94 o BIG5 | |
| 95 | |
| 96 A coding system to encode character sets: ASCII and Big5. Widely | |
| 88771 | 97 used for Chinese (mainly in Taiwan and Hong Kong). Details are |
| 88365 | 98 described in section 8. In this file, when we write "big5" (all |
| 99 lowercase), we mean the coding system, and when we write "Big5" | |
| 100 (capitalized), we mean the character set. | |
| 101 | |
| 102 o CCL | |
| 103 | |
| 88485 | 104 If a user wants to decode/encode text encoded in a coding system |
| 88365 | 105 not listed above, he can supply a decoder and an encoder for it in |
| 106 CCL (Code Conversion Language) programs. Emacs executes the CCL | |
| 107 program while decoding/encoding. | |
| 108 | |
| 109 o Raw-text | |
| 110 | |
| 88771 | 111 A coding system for text containing raw eight-bit data. Emacs |
| 88485 | 112 treats each byte of source text as a character (except for |
| 88365 | 113 end-of-line conversion). |
| 114 | |
| 115 o No-conversion | |
| 116 | |
| 117 Like raw text, but don't do end-of-line conversion. | |
| 118 | |
| 119 | |
| 120 END-OF-LINE FORMAT | |
| 121 | |
| 88485 | 122 How text end-of-line is encoded depends on operating system. For |
| 88365 | 123 instance, Unix's format is just one byte of LF (line-feed) code, |
| 18766 | 124 whereas DOS's format is two-byte sequence of `carriage-return' and |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
125 `line-feed' codes. MacOS's format is usually one byte of |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
126 `carriage-return'. |
| 17052 | 127 |
| 88485 | 128 Since text character encoding and end-of-line encoding are |
| 88365 | 129 independent, any coding system described above can take any format |
| 130 of end-of-line (except for no-conversion). | |
| 17052 | 131 |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
132 STRUCT CODING_SYSTEM |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
133 |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
134 Before using a coding system for code conversion (i.e. decoding and |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
135 encoding), we setup a structure of type `struct coding_system'. |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
136 This structure keeps various information about a specific code |
| 88485 | 137 conversion (e.g. the location of source and destination data). |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
138 |
| 17052 | 139 */ |
| 140 | |
| 88365 | 141 /* COMMON MACROS */ |
| 142 | |
| 143 | |
| 17052 | 144 /*** GENERAL NOTES on `detect_coding_XXX ()' functions *** |
| 145 | |
| 88365 | 146 These functions check if a byte sequence specified as a source in |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
147 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
|
148 DETECT_INFO. |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
149 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
150 Return 1 if the byte sequence conforms to XXX, otherwise return 0. |
| 88365 | 151 |
| 152 Below is the template of these functions. */ | |
| 153 | |
| 17052 | 154 #if 0 |
| 88365 | 155 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
156 detect_coding_XXX (coding, detect_info) |
| 88365 | 157 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
158 struct coding_detection_info *detect_info; |
| 17052 | 159 { |
| 88365 | 160 unsigned char *src = coding->source; |
| 161 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 162 int multibytep = coding->src_multibyte; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
163 int consumed_chars = 0; |
| 88365 | 164 int found = 0; |
| 165 ...; | |
| 166 | |
| 167 while (1) | |
| 168 { | |
| 169 /* Get one byte from the source. If the souce is exausted, jump | |
| 170 to no_more_source:. */ | |
| 171 ONE_MORE_BYTE (c); | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
172 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
173 if (! __C_conforms_to_XXX___ (c)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
174 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
175 if (! __C_strongly_suggests_XXX__ (c)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
176 found = CATEGORY_MASK_XXX; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
177 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
178 /* The byte sequence is invalid for XXX. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
179 detect_info->rejected |= CATEGORY_MASK_XXX; |
| 88365 | 180 return 0; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
181 |
| 88365 | 182 no_more_source: |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
183 /* The source exausted successfully. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
184 detect_info->found |= found; |
| 88365 | 185 return 1; |
| 17052 | 186 } |
| 187 #endif | |
| 188 | |
| 189 /*** GENERAL NOTES on `decode_coding_XXX ()' functions *** | |
| 190 | |
| 88365 | 191 These functions decode a byte sequence specified as a source by |
| 192 CODING. The resulting multibyte text goes to a place pointed to by | |
| 193 CODING->charbuf, the length of which should not exceed | |
| 194 CODING->charbuf_size; | |
| 195 | |
| 196 These functions set the information of original and decoded texts in | |
| 197 CODING->consumed, CODING->consumed_char, and CODING->charbuf_used. | |
| 198 They also set CODING->result to one of CODING_RESULT_XXX indicating | |
| 199 how the decoding is finished. | |
| 200 | |
| 201 Below is the template of these functions. */ | |
| 202 | |
| 17052 | 203 #if 0 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
204 static void |
| 88365 | 205 decode_coding_XXXX (coding) |
| 17052 | 206 struct coding_system *coding; |
| 207 { | |
| 88365 | 208 unsigned char *src = coding->source + coding->consumed; |
| 209 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 210 /* SRC_BASE remembers the start position in source in each loop. | |
| 211 The loop will be exited when there's not enough source code, or | |
| 212 when there's no room in CHARBUF for a decoded character. */ | |
| 213 unsigned char *src_base; | |
| 214 /* A buffer to produce decoded characters. */ | |
| 215 int *charbuf = coding->charbuf; | |
| 216 int *charbuf_end = charbuf + coding->charbuf_size; | |
| 217 int multibytep = coding->src_multibyte; | |
| 218 | |
| 219 while (1) | |
| 220 { | |
| 221 src_base = src; | |
| 222 if (charbuf < charbuf_end) | |
| 223 /* No more room to produce a decoded character. */ | |
| 224 break; | |
| 225 ONE_MORE_BYTE (c); | |
| 226 /* Decode it. */ | |
| 227 } | |
| 228 | |
| 229 no_more_source: | |
| 230 if (src_base < src_end | |
| 231 && coding->mode & CODING_MODE_LAST_BLOCK) | |
| 232 /* If the source ends by partial bytes to construct a character, | |
| 233 treat them as eight-bit raw data. */ | |
| 234 while (src_base < src_end && charbuf < charbuf_end) | |
| 235 *charbuf++ = *src_base++; | |
| 236 /* Remember how many bytes and characters we consumed. If the | |
| 237 source is multibyte, the bytes and chars are not identical. */ | |
| 238 coding->consumed = coding->consumed_char = src_base - coding->source; | |
| 239 /* Remember how many characters we produced. */ | |
| 240 coding->charbuf_used = charbuf - coding->charbuf; | |
| 17052 | 241 } |
| 242 #endif | |
| 243 | |
| 244 /*** GENERAL NOTES on `encode_coding_XXX ()' functions *** | |
| 245 | |
| 88365 | 246 These functions encode SRC_BYTES length text at SOURCE of Emacs' |
| 247 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
|
248 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
|
249 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
|
250 |
| 88365 | 251 These functions set the information of original and encoded texts in |
| 252 the members produced, produced_char, consumed, and consumed_char of | |
| 253 the structure *CODING. They also set the member result to one of | |
| 254 CODING_RESULT_XXX indicating how the encoding finished. | |
| 255 | |
| 256 DST_BYTES zero means that source area and destination area are | |
| 257 overlapped, which means that we can produce a encoded text until it | |
| 258 reaches at the head of not-yet-encoded source text. | |
| 259 | |
| 260 Below is a template of these functions. */ | |
| 17052 | 261 #if 0 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
262 static void |
| 88365 | 263 encode_coding_XXX (coding) |
| 17052 | 264 struct coding_system *coding; |
| 265 { | |
| 88365 | 266 int multibytep = coding->dst_multibyte; |
| 267 int *charbuf = coding->charbuf; | |
| 268 int *charbuf_end = charbuf->charbuf + coding->charbuf_used; | |
| 269 unsigned char *dst = coding->destination + coding->produced; | |
| 270 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 271 unsigned char *adjusted_dst_end = dst_end - _MAX_BYTES_PRODUCED_IN_LOOP_; | |
| 272 int produced_chars = 0; | |
| 273 | |
| 274 for (; charbuf < charbuf_end && dst < adjusted_dst_end; charbuf++) | |
| 275 { | |
| 276 int c = *charbuf; | |
| 277 /* Encode C into DST, and increment DST. */ | |
| 278 } | |
| 279 label_no_more_destination: | |
| 280 /* How many chars and bytes we produced. */ | |
| 281 coding->produced_char += produced_chars; | |
| 282 coding->produced = dst - coding->destination; | |
| 17052 | 283 } |
| 284 #endif | |
| 285 | |
| 286 | |
| 287 /*** 1. Preamble ***/ | |
| 288 | |
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
289 #include <config.h> |
| 17052 | 290 #include <stdio.h> |
| 291 | |
| 292 #include "lisp.h" | |
| 293 #include "buffer.h" | |
| 88365 | 294 #include "character.h" |
| 17052 | 295 #include "charset.h" |
| 88365 | 296 #include "ccl.h" |
| 26847 | 297 #include "composite.h" |
| 17052 | 298 #include "coding.h" |
| 299 #include "window.h" | |
| 300 | |
| 88365 | 301 Lisp_Object Vcoding_system_hash_table; |
| 302 | |
| 303 Lisp_Object Qcoding_system, Qcoding_aliases, Qeol_type; | |
|
88646
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
304 Lisp_Object Qunix, Qdos; |
|
d3b1f30e2267
(Qmac): Remove (duplicated) definition.
Dave Love <fx@gnu.org>
parents:
88645
diff
changeset
|
305 extern Lisp_Object Qmac; /* frame.c */ |
| 17052 | 306 Lisp_Object Qbuffer_file_coding_system; |
| 307 Lisp_Object Qpost_read_conversion, Qpre_write_conversion; | |
| 88365 | 308 Lisp_Object Qdefault_char; |
|
19612
783efd6c7c1e
(Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents:
19546
diff
changeset
|
309 Lisp_Object Qno_conversion, Qundecided; |
| 88365 | 310 Lisp_Object Qcharset, Qiso_2022, Qutf_8, Qutf_16, Qshift_jis, Qbig5; |
| 311 Lisp_Object Qutf_16_be_nosig, Qutf_16_be, Qutf_16_le_nosig, Qutf_16_le; | |
| 312 Lisp_Object Qsignature, Qendian, Qbig, Qlittle; | |
|
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
313 Lisp_Object Qcoding_system_history; |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
314 Lisp_Object Qvalid_codes; |
| 17052 | 315 |
| 316 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | |
| 317 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | |
| 318 Lisp_Object Qstart_process, Qopen_network_stream; | |
| 319 Lisp_Object Qtarget_idx; | |
| 320 | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
321 Lisp_Object Vselect_safe_coding_system_function; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
322 |
|
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
323 /* 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
|
324 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
|
325 /* Mnemonic string to indicate format of end-of-line is not yet |
| 17052 | 326 decided. */ |
|
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
327 Lisp_Object eol_mnemonic_undecided; |
| 17052 | 328 |
| 329 #ifdef emacs | |
| 330 | |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
331 Lisp_Object Vcoding_system_list, Vcoding_system_alist; |
|
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
332 |
|
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
333 Lisp_Object Qcoding_system_p, Qcoding_system_error; |
| 17052 | 334 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
335 /* 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
|
336 end-of-line format. */ |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
337 Lisp_Object Qemacs_mule, Qraw_text; |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
338 |
| 17052 | 339 /* Coding-systems are handed between Emacs Lisp programs and C internal |
| 340 routines by the following three variables. */ | |
| 341 /* Coding-system for reading files and receiving data from process. */ | |
| 342 Lisp_Object Vcoding_system_for_read; | |
| 343 /* Coding-system for writing files and sending data to process. */ | |
| 344 Lisp_Object Vcoding_system_for_write; | |
| 345 /* Coding-system actually used in the latest I/O. */ | |
| 346 Lisp_Object Vlast_coding_system_used; | |
| 347 | |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
348 /* A vector of length 256 which contains information about special |
| 22529 | 349 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
|
350 Lisp_Object Vlatin_extra_code_table; |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
351 |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
352 /* 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
|
353 int inhibit_eol_conversion; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
354 |
|
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
355 /* Flag to inhibit ISO2022 escape sequence detection. */ |
|
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
356 int inhibit_iso_escape_detection; |
|
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
357 |
|
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
358 /* 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
|
359 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
|
360 |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
361 /* Coding system to be used to encode text for terminal display. */ |
| 17052 | 362 struct coding_system terminal_coding; |
| 363 | |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
364 /* 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
|
365 terminal coding system is nil. */ |
|
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
366 struct coding_system safe_terminal_coding; |
|
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
367 |
|
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
368 /* Coding system of what is sent from terminal keyboard. */ |
| 17052 | 369 struct coding_system keyboard_coding; |
| 370 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
371 Lisp_Object Vfile_coding_system_alist; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
372 Lisp_Object Vprocess_coding_system_alist; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
373 Lisp_Object Vnetwork_coding_system_alist; |
| 17052 | 374 |
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
375 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
|
376 |
| 17052 | 377 #endif /* emacs */ |
| 378 | |
|
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
379 /* 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
|
380 conversion. */ |
|
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
381 Lisp_Object Venable_character_translation; |
|
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
382 /* 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
|
383 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
|
384 /* 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
|
385 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
|
386 |
|
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
387 Lisp_Object Qtranslation_table; |
|
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
388 Lisp_Object Qtranslation_table_id; |
|
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
389 Lisp_Object Qtranslation_table_for_decode; |
|
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
390 Lisp_Object Qtranslation_table_for_encode; |
| 17052 | 391 |
| 392 /* Alist of charsets vs revision number. */ | |
| 88365 | 393 static Lisp_Object Vcharset_revision_table; |
| 17052 | 394 |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
395 /* Default coding systems used for process I/O. */ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
396 Lisp_Object Vdefault_process_coding_system; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
397 |
|
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
398 /* Global flag to tell that we can't call post-read-conversion and |
|
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
399 pre-write-conversion functions. Usually the value is zero, but it |
|
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
400 is set to 1 temporarily while such functions are running. This is |
|
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
401 to avoid infinite recursive call. */ |
|
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
402 static int inhibit_pre_post_conversion; |
|
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
403 |
| 88365 | 404 /* Two special coding systems. */ |
| 405 Lisp_Object Vsjis_coding_system; | |
| 406 Lisp_Object Vbig5_coding_system; | |
| 407 | |
| 408 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
409 static int detect_coding_utf_8 P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
410 struct coding_detection_info *info)); |
| 88365 | 411 static void decode_coding_utf_8 P_ ((struct coding_system *)); |
| 412 static int encode_coding_utf_8 P_ ((struct coding_system *)); | |
| 413 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
414 static int detect_coding_utf_16 P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
415 struct coding_detection_info *info)); |
| 88365 | 416 static void decode_coding_utf_16 P_ ((struct coding_system *)); |
| 417 static int encode_coding_utf_16 P_ ((struct coding_system *)); | |
| 418 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
419 static int detect_coding_iso_2022 P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
420 struct coding_detection_info *info)); |
| 88365 | 421 static void decode_coding_iso_2022 P_ ((struct coding_system *)); |
| 422 static int encode_coding_iso_2022 P_ ((struct coding_system *)); | |
| 423 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
424 static int detect_coding_emacs_mule P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
425 struct coding_detection_info *info)); |
| 88365 | 426 static void decode_coding_emacs_mule P_ ((struct coding_system *)); |
| 427 static int encode_coding_emacs_mule P_ ((struct coding_system *)); | |
| 428 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
429 static int detect_coding_sjis P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
430 struct coding_detection_info *info)); |
| 88365 | 431 static void decode_coding_sjis P_ ((struct coding_system *)); |
| 432 static int encode_coding_sjis P_ ((struct coding_system *)); | |
| 433 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
434 static int detect_coding_big5 P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
435 struct coding_detection_info *info)); |
| 88365 | 436 static void decode_coding_big5 P_ ((struct coding_system *)); |
| 437 static int encode_coding_big5 P_ ((struct coding_system *)); | |
| 438 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
439 static int detect_coding_ccl P_ ((struct coding_system *, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
440 struct coding_detection_info *info)); |
| 88365 | 441 static void decode_coding_ccl P_ ((struct coding_system *)); |
| 442 static int encode_coding_ccl P_ ((struct coding_system *)); | |
| 443 | |
| 444 static void decode_coding_raw_text P_ ((struct coding_system *)); | |
| 445 static int encode_coding_raw_text P_ ((struct coding_system *)); | |
| 446 | |
| 447 | |
| 448 /* ISO2022 section */ | |
| 449 | |
| 450 #define CODING_ISO_INITIAL(coding, reg) \ | |
| 451 (XINT (AREF (AREF (CODING_ID_ATTRS ((coding)->id), \ | |
| 452 coding_attr_iso_initial), \ | |
| 453 reg))) | |
| 454 | |
| 455 | |
| 456 #define CODING_ISO_REQUEST(coding, charset_id) \ | |
| 457 ((charset_id <= (coding)->max_charset_id \ | |
| 458 ? (coding)->safe_charsets[charset_id] \ | |
| 459 : -1)) | |
| 460 | |
| 461 | |
| 462 #define CODING_ISO_FLAGS(coding) \ | |
| 463 ((coding)->spec.iso_2022.flags) | |
| 464 #define CODING_ISO_DESIGNATION(coding, reg) \ | |
| 465 ((coding)->spec.iso_2022.current_designation[reg]) | |
| 466 #define CODING_ISO_INVOCATION(coding, plane) \ | |
| 467 ((coding)->spec.iso_2022.current_invocation[plane]) | |
| 468 #define CODING_ISO_SINGLE_SHIFTING(coding) \ | |
| 469 ((coding)->spec.iso_2022.single_shifting) | |
| 470 #define CODING_ISO_BOL(coding) \ | |
| 471 ((coding)->spec.iso_2022.bol) | |
| 472 #define CODING_ISO_INVOKED_CHARSET(coding, plane) \ | |
| 473 CODING_ISO_DESIGNATION ((coding), CODING_ISO_INVOCATION ((coding), (plane))) | |
| 474 | |
| 475 /* Control characters of ISO2022. */ | |
| 476 /* code */ /* function */ | |
| 477 #define ISO_CODE_LF 0x0A /* line-feed */ | |
| 478 #define ISO_CODE_CR 0x0D /* carriage-return */ | |
| 479 #define ISO_CODE_SO 0x0E /* shift-out */ | |
| 480 #define ISO_CODE_SI 0x0F /* shift-in */ | |
| 481 #define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */ | |
| 482 #define ISO_CODE_ESC 0x1B /* escape */ | |
| 483 #define ISO_CODE_SS2 0x8E /* single-shift-2 */ | |
| 484 #define ISO_CODE_SS3 0x8F /* single-shift-3 */ | |
| 485 #define ISO_CODE_CSI 0x9B /* control-sequence-introducer */ | |
| 486 | |
| 487 /* All code (1-byte) of ISO2022 is classified into one of the | |
| 488 followings. */ | |
| 489 enum iso_code_class_type | |
| 490 { | |
| 491 ISO_control_0, /* Control codes in the range | |
| 492 0x00..0x1F and 0x7F, except for the | |
| 493 following 5 codes. */ | |
| 494 ISO_carriage_return, /* ISO_CODE_CR (0x0D) */ | |
| 495 ISO_shift_out, /* ISO_CODE_SO (0x0E) */ | |
| 496 ISO_shift_in, /* ISO_CODE_SI (0x0F) */ | |
| 497 ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ | |
| 498 ISO_escape, /* ISO_CODE_SO (0x1B) */ | |
| 499 ISO_control_1, /* Control codes in the range | |
| 500 0x80..0x9F, except for the | |
| 501 following 3 codes. */ | |
| 502 ISO_single_shift_2, /* ISO_CODE_SS2 (0x8E) */ | |
| 503 ISO_single_shift_3, /* ISO_CODE_SS3 (0x8F) */ | |
| 504 ISO_control_sequence_introducer, /* ISO_CODE_CSI (0x9B) */ | |
| 505 ISO_0x20_or_0x7F, /* Codes of the values 0x20 or 0x7F. */ | |
| 506 ISO_graphic_plane_0, /* Graphic codes in the range 0x21..0x7E. */ | |
| 507 ISO_0xA0_or_0xFF, /* Codes of the values 0xA0 or 0xFF. */ | |
| 508 ISO_graphic_plane_1 /* Graphic codes in the range 0xA1..0xFE. */ | |
| 509 }; | |
| 510 | |
| 511 /** The macros CODING_ISO_FLAG_XXX defines a flag bit of the | |
| 512 `iso-flags' attribute of an iso2022 coding system. */ | |
| 513 | |
| 514 /* If set, produce long-form designation sequence (e.g. ESC $ ( A) | |
| 515 instead of the correct short-form sequence (e.g. ESC $ A). */ | |
| 516 #define CODING_ISO_FLAG_LONG_FORM 0x0001 | |
| 517 | |
| 518 /* If set, reset graphic planes and registers at end-of-line to the | |
| 519 initial state. */ | |
| 520 #define CODING_ISO_FLAG_RESET_AT_EOL 0x0002 | |
| 521 | |
| 522 /* If set, reset graphic planes and registers before any control | |
| 523 characters to the initial state. */ | |
| 524 #define CODING_ISO_FLAG_RESET_AT_CNTL 0x0004 | |
| 525 | |
| 526 /* If set, encode by 7-bit environment. */ | |
| 527 #define CODING_ISO_FLAG_SEVEN_BITS 0x0008 | |
| 528 | |
| 529 /* If set, use locking-shift function. */ | |
| 530 #define CODING_ISO_FLAG_LOCKING_SHIFT 0x0010 | |
| 531 | |
| 532 /* If set, use single-shift function. Overwrite | |
| 533 CODING_ISO_FLAG_LOCKING_SHIFT. */ | |
| 534 #define CODING_ISO_FLAG_SINGLE_SHIFT 0x0020 | |
| 535 | |
| 536 /* If set, use designation escape sequence. */ | |
| 537 #define CODING_ISO_FLAG_DESIGNATION 0x0040 | |
| 538 | |
| 539 /* If set, produce revision number sequence. */ | |
| 540 #define CODING_ISO_FLAG_REVISION 0x0080 | |
| 541 | |
| 542 /* If set, produce ISO6429's direction specifying sequence. */ | |
| 543 #define CODING_ISO_FLAG_DIRECTION 0x0100 | |
| 544 | |
| 545 /* If set, assume designation states are reset at beginning of line on | |
| 546 output. */ | |
| 547 #define CODING_ISO_FLAG_INIT_AT_BOL 0x0200 | |
| 548 | |
| 549 /* If set, designation sequence should be placed at beginning of line | |
| 550 on output. */ | |
| 551 #define CODING_ISO_FLAG_DESIGNATE_AT_BOL 0x0400 | |
| 552 | |
| 553 /* If set, do not encode unsafe charactes on output. */ | |
| 554 #define CODING_ISO_FLAG_SAFE 0x0800 | |
| 555 | |
| 556 /* If set, extra latin codes (128..159) are accepted as a valid code | |
| 557 on input. */ | |
| 558 #define CODING_ISO_FLAG_LATIN_EXTRA 0x1000 | |
| 559 | |
| 560 #define CODING_ISO_FLAG_COMPOSITION 0x2000 | |
| 561 | |
| 562 #define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 | |
| 563 | |
|
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
564 #define CODING_ISO_FLAG_USE_ROMAN 0x8000 |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
565 |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
566 #define CODING_ISO_FLAG_USE_OLDJIS 0x10000 |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
567 |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
568 #define CODING_ISO_FLAG_FULL_SUPPORT 0x100000 |
| 88365 | 569 |
| 570 /* A character to be produced on output if encoding of the original | |
| 571 character is prohibited by CODING_ISO_FLAG_SAFE. */ | |
| 572 #define CODING_INHIBIT_CHARACTER_SUBSTITUTION '?' | |
| 573 | |
| 574 | |
| 575 /* UTF-16 section */ | |
| 576 #define CODING_UTF_16_BOM(coding) \ | |
| 577 ((coding)->spec.utf_16.bom) | |
| 578 | |
| 579 #define CODING_UTF_16_ENDIAN(coding) \ | |
| 580 ((coding)->spec.utf_16.endian) | |
| 581 | |
| 582 #define CODING_UTF_16_SURROGATE(coding) \ | |
| 583 ((coding)->spec.utf_16.surrogate) | |
| 584 | |
| 585 | |
| 586 /* CCL section */ | |
| 587 #define CODING_CCL_DECODER(coding) \ | |
| 588 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_decoder) | |
| 589 #define CODING_CCL_ENCODER(coding) \ | |
| 590 AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_encoder) | |
| 591 #define CODING_CCL_VALIDS(coding) \ | |
| 592 (XSTRING (AREF (CODING_ID_ATTRS ((coding)->id), coding_attr_ccl_valids)) \ | |
| 593 ->data) | |
| 594 | |
| 88771 | 595 /* Index for each coding category in `coding_categories' */ |
| 88365 | 596 |
| 597 enum coding_category | |
| 598 { | |
| 599 coding_category_iso_7, | |
| 600 coding_category_iso_7_tight, | |
| 601 coding_category_iso_8_1, | |
| 602 coding_category_iso_8_2, | |
| 603 coding_category_iso_7_else, | |
| 604 coding_category_iso_8_else, | |
| 605 coding_category_utf_8, | |
| 606 coding_category_utf_16_auto, | |
| 607 coding_category_utf_16_be, | |
| 608 coding_category_utf_16_le, | |
| 609 coding_category_utf_16_be_nosig, | |
| 610 coding_category_utf_16_le_nosig, | |
| 611 coding_category_charset, | |
| 612 coding_category_sjis, | |
| 613 coding_category_big5, | |
| 614 coding_category_ccl, | |
| 615 coding_category_emacs_mule, | |
| 616 /* All above are targets of code detection. */ | |
| 617 coding_category_raw_text, | |
| 618 coding_category_undecided, | |
| 619 coding_category_max | |
| 620 }; | |
| 621 | |
| 622 /* Definitions of flag bits used in detect_coding_XXXX. */ | |
| 623 #define CATEGORY_MASK_ISO_7 (1 << coding_category_iso_7) | |
| 624 #define CATEGORY_MASK_ISO_7_TIGHT (1 << coding_category_iso_7_tight) | |
| 625 #define CATEGORY_MASK_ISO_8_1 (1 << coding_category_iso_8_1) | |
| 626 #define CATEGORY_MASK_ISO_8_2 (1 << coding_category_iso_8_2) | |
| 627 #define CATEGORY_MASK_ISO_7_ELSE (1 << coding_category_iso_7_else) | |
| 628 #define CATEGORY_MASK_ISO_8_ELSE (1 << coding_category_iso_8_else) | |
| 629 #define CATEGORY_MASK_UTF_8 (1 << coding_category_utf_8) | |
| 630 #define CATEGORY_MASK_UTF_16_BE (1 << coding_category_utf_16_be) | |
| 631 #define CATEGORY_MASK_UTF_16_LE (1 << coding_category_utf_16_le) | |
| 632 #define CATEGORY_MASK_UTF_16_BE_NOSIG (1 << coding_category_utf_16_be_nosig) | |
| 633 #define CATEGORY_MASK_UTF_16_LE_NOSIG (1 << coding_category_utf_16_le_nosig) | |
| 634 #define CATEGORY_MASK_CHARSET (1 << coding_category_charset) | |
| 635 #define CATEGORY_MASK_SJIS (1 << coding_category_sjis) | |
| 636 #define CATEGORY_MASK_BIG5 (1 << coding_category_big5) | |
| 637 #define CATEGORY_MASK_CCL (1 << coding_category_ccl) | |
| 638 #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
|
639 #define CATEGORY_MASK_RAW_TEXT (1 << coding_category_raw_text) |
| 88365 | 640 |
| 641 /* This value is returned if detect_coding_mask () find nothing other | |
| 642 than ASCII characters. */ | |
| 643 #define CATEGORY_MASK_ANY \ | |
| 644 (CATEGORY_MASK_ISO_7 \ | |
| 645 | CATEGORY_MASK_ISO_7_TIGHT \ | |
| 646 | CATEGORY_MASK_ISO_8_1 \ | |
| 647 | CATEGORY_MASK_ISO_8_2 \ | |
| 648 | CATEGORY_MASK_ISO_7_ELSE \ | |
| 649 | CATEGORY_MASK_ISO_8_ELSE \ | |
| 650 | CATEGORY_MASK_UTF_8 \ | |
| 651 | CATEGORY_MASK_UTF_16_BE \ | |
| 652 | CATEGORY_MASK_UTF_16_LE \ | |
| 653 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
| 654 | CATEGORY_MASK_UTF_16_LE_NOSIG \ | |
| 655 | CATEGORY_MASK_CHARSET \ | |
| 656 | CATEGORY_MASK_SJIS \ | |
| 657 | CATEGORY_MASK_BIG5 \ | |
| 658 | CATEGORY_MASK_CCL \ | |
| 659 | CATEGORY_MASK_EMACS_MULE) | |
| 660 | |
| 661 | |
| 662 #define CATEGORY_MASK_ISO_7BIT \ | |
| 663 (CATEGORY_MASK_ISO_7 | CATEGORY_MASK_ISO_7_TIGHT) | |
| 664 | |
| 665 #define CATEGORY_MASK_ISO_8BIT \ | |
| 666 (CATEGORY_MASK_ISO_8_1 | CATEGORY_MASK_ISO_8_2) | |
| 667 | |
| 668 #define CATEGORY_MASK_ISO_ELSE \ | |
| 669 (CATEGORY_MASK_ISO_7_ELSE | CATEGORY_MASK_ISO_8_ELSE) | |
| 670 | |
| 671 #define CATEGORY_MASK_ISO_ESCAPE \ | |
| 672 (CATEGORY_MASK_ISO_7 \ | |
| 673 | CATEGORY_MASK_ISO_7_TIGHT \ | |
| 674 | CATEGORY_MASK_ISO_7_ELSE \ | |
| 675 | CATEGORY_MASK_ISO_8_ELSE) | |
| 676 | |
| 677 #define CATEGORY_MASK_ISO \ | |
| 678 ( CATEGORY_MASK_ISO_7BIT \ | |
| 679 | CATEGORY_MASK_ISO_8BIT \ | |
| 680 | CATEGORY_MASK_ISO_ELSE) | |
| 681 | |
| 682 #define CATEGORY_MASK_UTF_16 \ | |
| 683 (CATEGORY_MASK_UTF_16_BE \ | |
| 684 | CATEGORY_MASK_UTF_16_LE \ | |
| 685 | CATEGORY_MASK_UTF_16_BE_NOSIG \ | |
| 686 | CATEGORY_MASK_UTF_16_LE_NOSIG) | |
| 687 | |
| 688 | |
| 689 /* List of symbols `coding-category-xxx' ordered by priority. This | |
| 690 variable is exposed to Emacs Lisp. */ | |
| 691 static Lisp_Object Vcoding_category_list; | |
| 692 | |
| 693 /* Table of coding categories (Lisp symbols). This variable is for | |
| 694 internal use oly. */ | |
| 695 static Lisp_Object Vcoding_category_table; | |
| 696 | |
| 697 /* Table of coding-categories ordered by priority. */ | |
| 698 static enum coding_category coding_priorities[coding_category_max]; | |
| 699 | |
| 700 /* Nth element is a coding context for the coding system bound to the | |
| 701 Nth coding category. */ | |
| 702 static struct coding_system coding_categories[coding_category_max]; | |
| 703 | |
| 704 static int detected_mask[coding_category_raw_text] = | |
| 705 { CATEGORY_MASK_ISO, | |
| 706 CATEGORY_MASK_ISO, | |
| 707 CATEGORY_MASK_ISO, | |
| 708 CATEGORY_MASK_ISO, | |
| 709 CATEGORY_MASK_ISO, | |
| 710 CATEGORY_MASK_ISO, | |
| 711 CATEGORY_MASK_UTF_8, | |
| 712 CATEGORY_MASK_UTF_16, | |
| 713 CATEGORY_MASK_UTF_16, | |
| 714 CATEGORY_MASK_UTF_16, | |
| 715 CATEGORY_MASK_UTF_16, | |
| 716 CATEGORY_MASK_UTF_16, | |
| 717 CATEGORY_MASK_CHARSET, | |
| 718 CATEGORY_MASK_SJIS, | |
| 719 CATEGORY_MASK_BIG5, | |
| 720 CATEGORY_MASK_CCL, | |
| 721 CATEGORY_MASK_EMACS_MULE | |
| 722 }; | |
| 723 | |
| 724 /*** Commonly used macros and functions ***/ | |
| 725 | |
| 726 #ifndef min | |
| 727 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
| 728 #endif | |
| 729 #ifndef max | |
| 730 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
| 731 #endif | |
| 732 | |
| 733 #define CODING_GET_INFO(coding, attrs, eol_type, charset_list) \ | |
| 734 do { \ | |
| 735 attrs = CODING_ID_ATTRS (coding->id); \ | |
| 736 eol_type = CODING_ID_EOL_TYPE (coding->id); \ | |
| 737 if (VECTORP (eol_type)) \ | |
| 738 eol_type = Qunix; \ | |
| 739 charset_list = CODING_ATTR_CHARSET_LIST (attrs); \ | |
| 740 } while (0) | |
| 741 | |
| 742 | |
| 743 /* Safely get one byte from the source text pointed by SRC which ends | |
| 744 at SRC_END, and set C to that byte. If there are not enough bytes | |
| 745 in the source, it jumps to `no_more_source'. The caller | |
| 746 should declare and set these variables appropriately in advance: | |
| 747 src, src_end, multibytep | |
| 748 */ | |
| 749 | |
| 750 #define ONE_MORE_BYTE(c) \ | |
| 751 do { \ | |
| 752 if (src == src_end) \ | |
| 753 { \ | |
| 754 if (src_base < src) \ | |
| 755 coding->result = CODING_RESULT_INSUFFICIENT_SRC; \ | |
| 756 goto no_more_source; \ | |
| 757 } \ | |
| 758 c = *src++; \ | |
| 759 if (multibytep && (c & 0x80)) \ | |
| 760 { \ | |
| 761 if ((c & 0xFE) != 0xC0) \ | |
| 762 error ("Undecodable char found"); \ | |
| 763 c = ((c & 1) << 6) | *src++; \ | |
| 764 } \ | |
| 765 consumed_chars++; \ | |
| 766 } while (0) | |
| 767 | |
| 768 | |
| 769 #define ONE_MORE_BYTE_NO_CHECK(c) \ | |
| 770 do { \ | |
| 771 c = *src++; \ | |
| 772 if (multibytep && (c & 0x80)) \ | |
| 773 { \ | |
| 774 if ((c & 0xFE) != 0xC0) \ | |
| 775 error ("Undecodable char found"); \ | |
| 776 c = ((c & 1) << 6) | *src++; \ | |
| 777 } \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
778 consumed_chars++; \ |
| 88365 | 779 } while (0) |
| 780 | |
| 781 | |
| 782 /* Store a byte C in the place pointed by DST and increment DST to the | |
| 783 next free point, and increment PRODUCED_CHARS. The caller should | |
| 784 assure that C is 0..127, and declare and set the variable `dst' | |
| 785 appropriately in advance. | |
| 786 */ | |
| 787 | |
| 788 | |
| 789 #define EMIT_ONE_ASCII_BYTE(c) \ | |
| 790 do { \ | |
| 791 produced_chars++; \ | |
| 792 *dst++ = (c); \ | |
| 793 } while (0) | |
| 794 | |
| 795 | |
| 796 /* Like EMIT_ONE_ASCII_BYTE byt store two bytes; C1 and C2. */ | |
| 797 | |
| 798 #define EMIT_TWO_ASCII_BYTES(c1, c2) \ | |
| 799 do { \ | |
| 800 produced_chars += 2; \ | |
| 801 *dst++ = (c1), *dst++ = (c2); \ | |
| 802 } while (0) | |
| 803 | |
| 804 | |
| 805 /* Store a byte C in the place pointed by DST and increment DST to the | |
| 806 next free point, and increment PRODUCED_CHARS. If MULTIBYTEP is | |
| 807 nonzero, store in an appropriate multibyte from. The caller should | |
| 808 declare and set the variables `dst' and `multibytep' appropriately | |
| 809 in advance. */ | |
| 810 | |
| 811 #define EMIT_ONE_BYTE(c) \ | |
| 812 do { \ | |
| 813 produced_chars++; \ | |
| 814 if (multibytep) \ | |
| 815 { \ | |
| 816 int ch = (c); \ | |
| 817 if (ch >= 0x80) \ | |
| 818 ch = BYTE8_TO_CHAR (ch); \ | |
| 819 CHAR_STRING_ADVANCE (ch, dst); \ | |
| 820 } \ | |
| 821 else \ | |
| 822 *dst++ = (c); \ | |
| 823 } while (0) | |
| 824 | |
| 825 | |
| 826 /* Like EMIT_ONE_BYTE, but emit two bytes; C1 and C2. */ | |
| 827 | |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
828 #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
|
829 do { \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
830 produced_chars += 2; \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
831 if (multibytep) \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
832 { \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
833 int ch; \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
834 \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
835 ch = (c1); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
836 if (ch >= 0x80) \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
837 ch = BYTE8_TO_CHAR (ch); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
838 CHAR_STRING_ADVANCE (ch, dst); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
839 ch = (c2); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
840 if (ch >= 0x80) \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
841 ch = BYTE8_TO_CHAR (ch); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
842 CHAR_STRING_ADVANCE (ch, dst); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
843 } \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
844 else \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
845 { \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
846 *dst++ = (c1); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
847 *dst++ = (c2); \ |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
848 } \ |
| 88365 | 849 } while (0) |
| 850 | |
| 851 | |
| 852 #define EMIT_THREE_BYTES(c1, c2, c3) \ | |
| 853 do { \ | |
| 854 EMIT_ONE_BYTE (c1); \ | |
| 855 EMIT_TWO_BYTES (c2, c3); \ | |
| 856 } while (0) | |
| 857 | |
| 858 | |
| 859 #define EMIT_FOUR_BYTES(c1, c2, c3, c4) \ | |
| 860 do { \ | |
| 861 EMIT_TWO_BYTES (c1, c2); \ | |
| 862 EMIT_TWO_BYTES (c3, c4); \ | |
| 863 } while (0) | |
| 864 | |
| 865 | |
| 866 #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ | |
| 867 do { \ | |
| 868 charset_map_loaded = 0; \ | |
| 869 c = DECODE_CHAR (charset, code); \ | |
| 870 if (charset_map_loaded) \ | |
| 871 { \ | |
| 872 unsigned char *orig = coding->source; \ | |
| 873 EMACS_INT offset; \ | |
| 874 \ | |
| 875 coding_set_source (coding); \ | |
| 876 offset = coding->source - orig; \ | |
| 877 src += offset; \ | |
| 878 src_base += offset; \ | |
| 879 src_end += offset; \ | |
| 880 } \ | |
| 881 } while (0) | |
| 882 | |
| 883 | |
| 884 #define ASSURE_DESTINATION(bytes) \ | |
| 885 do { \ | |
| 886 if (dst + (bytes) >= dst_end) \ | |
| 887 { \ | |
| 888 int more_bytes = charbuf_end - charbuf + (bytes); \ | |
| 889 \ | |
| 890 dst = alloc_destination (coding, more_bytes, dst); \ | |
| 891 dst_end = coding->destination + coding->dst_bytes; \ | |
| 892 } \ | |
| 893 } while (0) | |
| 894 | |
| 895 | |
| 896 | |
| 897 static void | |
| 898 coding_set_source (coding) | |
| 899 struct coding_system *coding; | |
| 900 { | |
| 901 if (BUFFERP (coding->src_object)) | |
| 902 { | |
| 903 if (coding->src_pos < 0) | |
| 904 coding->source = GAP_END_ADDR + coding->src_pos_byte; | |
| 905 else | |
| 906 { | |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
907 struct buffer *buf = XBUFFER (coding->src_object); |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
908 EMACS_INT gpt_byte = BUF_GPT_BYTE (buf); |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
909 unsigned char *beg_addr = BUF_BEG_ADDR (buf); |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
910 |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
911 coding->source = beg_addr + coding->src_pos_byte - 1; |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
912 if (coding->src_pos_byte >= gpt_byte) |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
913 coding->source += BUF_GAP_SIZE (buf); |
| 88365 | 914 } |
| 915 } | |
| 916 else if (STRINGP (coding->src_object)) | |
| 917 { | |
| 918 coding->source = (XSTRING (coding->src_object)->data | |
| 919 + coding->src_pos_byte); | |
| 920 } | |
| 921 else | |
| 922 /* Otherwise, the source is C string and is never relocated | |
| 923 automatically. Thus we don't have to update anything. */ | |
| 924 ; | |
| 925 } | |
| 926 | |
| 927 static void | |
| 928 coding_set_destination (coding) | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
929 struct coding_system *coding; |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
930 { |
| 88365 | 931 if (BUFFERP (coding->dst_object)) |
| 932 { | |
| 933 if (coding->src_pos < 0) | |
|
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
934 { |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
935 coding->destination = BEG_ADDR + coding->dst_pos_byte - 1; |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
936 coding->dst_bytes = (GAP_END_ADDR |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
937 - (coding->src_bytes - coding->consumed) |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
938 - coding->destination); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
939 } |
| 88365 | 940 else |
|
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
941 { |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
942 /* 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
|
943 of the buffer. */ |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
944 coding->destination = (BUF_BEG_ADDR (XBUFFER (coding->dst_object)) |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
945 + coding->dst_pos_byte - 1); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
946 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
|
947 - coding->destination); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
948 } |
| 88365 | 949 } |
| 950 else | |
| 951 /* Otherwise, the destination is C string and is never relocated | |
| 952 automatically. Thus we don't have to update anything. */ | |
| 953 ; | |
| 954 } | |
| 955 | |
| 956 | |
| 957 static void | |
| 958 coding_alloc_by_realloc (coding, bytes) | |
| 959 struct coding_system *coding; | |
| 960 EMACS_INT bytes; | |
| 961 { | |
| 962 coding->destination = (unsigned char *) xrealloc (coding->destination, | |
| 963 coding->dst_bytes + bytes); | |
| 964 coding->dst_bytes += bytes; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
965 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
966 |
| 88365 | 967 static void |
| 968 coding_alloc_by_making_gap (coding, bytes) | |
| 969 struct coding_system *coding; | |
| 970 EMACS_INT bytes; | |
| 971 { | |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
972 if (BUFFERP (coding->dst_object) |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
973 && EQ (coding->src_object, coding->dst_object)) |
| 88365 | 974 { |
| 975 EMACS_INT add = coding->src_bytes - coding->consumed; | |
| 976 | |
| 977 GAP_SIZE -= add; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add; | |
| 978 make_gap (bytes); | |
| 979 GAP_SIZE += add; ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add; | |
| 980 } | |
| 981 else | |
| 982 { | |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
983 Lisp_Object this_buffer; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
984 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
985 this_buffer = Fcurrent_buffer (); |
| 88365 | 986 set_buffer_internal (XBUFFER (coding->dst_object)); |
| 987 make_gap (bytes); | |
| 988 set_buffer_internal (XBUFFER (this_buffer)); | |
| 989 } | |
| 990 } | |
| 991 | |
| 992 | |
| 993 static unsigned char * | |
| 994 alloc_destination (coding, nbytes, dst) | |
| 995 struct coding_system *coding; | |
| 996 int nbytes; | |
| 997 unsigned char *dst; | |
| 998 { | |
| 999 EMACS_INT offset = dst - coding->destination; | |
| 1000 | |
| 1001 if (BUFFERP (coding->dst_object)) | |
| 1002 coding_alloc_by_making_gap (coding, nbytes); | |
| 1003 else | |
| 1004 coding_alloc_by_realloc (coding, nbytes); | |
| 1005 coding->result = CODING_RESULT_SUCCESS; | |
| 1006 coding_set_destination (coding); | |
| 1007 dst = coding->destination + offset; | |
| 1008 return dst; | |
| 1009 } | |
| 1010 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1011 /** Macros for annotations. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1012 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1013 /* Maximum length of annotation data (sum of annotations for |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1014 composition and charset). */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1015 #define MAX_ANNOTATION_LENGTH (5 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 + 5) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1016 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1017 /* 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
|
1018 format: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1019 [ -LENGTH ANNOTATION_MASK FROM TO ... ] |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1020 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
|
1021 ANNOTATION_MASK is one of CODING_ANNOTATE_XXX_MASK. |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1022 FROM and TO specify the range of text annotated. They are relative |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1023 to coding->src_pos (on encoding) or coding->dst_pos (on decoding). |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1024 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1025 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
|
1026 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1027 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
|
1028 follows: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1029 ... METHOD [ COMPOSITION-COMPONENTS ... ] |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1030 METHOD is one of enum composition_method. |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1031 Optionnal COMPOSITION-COMPONENTS are characters and composition |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1032 rules. |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1033 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1034 In the case of CODING_ANNOTATE_CHARSET_MASK, one element CHARSET-ID |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1035 follows. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1036 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1037 #define ADD_ANNOTATION_DATA(buf, len, mask, from, to) \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1038 do { \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1039 *(buf)++ = -(len); \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1040 *(buf)++ = (mask); \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1041 *(buf)++ = (from); \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1042 *(buf)++ = (to); \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1043 coding->annotated = 1; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1044 } while (0); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1045 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1046 #define ADD_COMPOSITION_DATA(buf, from, to, method) \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1047 do { \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1048 ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_COMPOSITION_MASK, from, to); \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1049 *buf++ = method; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1050 } while (0) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1051 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1052 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1053 #define ADD_CHARSET_DATA(buf, from, to, id) \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1054 do { \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1055 ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_CHARSET_MASK, from, to); \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1056 *buf++ = id; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1057 } while (0) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1058 |
| 88365 | 1059 |
| 1060 /*** 2. Emacs' internal format (emacs-utf-8) ***/ | |
| 1061 | |
| 1062 | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
1063 |
| 17052 | 1064 |
| 88365 | 1065 /*** 3. UTF-8 ***/ |
| 1066 | |
| 1067 /* 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
|
1068 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
|
1069 return 0. */ |
| 88365 | 1070 |
| 1071 #define UTF_8_1_OCTET_P(c) ((c) < 0x80) | |
| 1072 #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80) | |
| 1073 #define UTF_8_2_OCTET_LEADING_P(c) (((c) & 0xE0) == 0xC0) | |
| 1074 #define UTF_8_3_OCTET_LEADING_P(c) (((c) & 0xF0) == 0xE0) | |
| 1075 #define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0) | |
| 1076 #define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8) | |
| 1077 | |
| 1078 static int | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1079 detect_coding_utf_8 (coding, detect_info) |
| 88365 | 1080 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1081 struct coding_detection_info *detect_info; |
| 88365 | 1082 { |
| 1083 unsigned char *src = coding->source, *src_base = src; | |
| 1084 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 1085 int multibytep = coding->src_multibyte; | |
| 1086 int consumed_chars = 0; | |
| 1087 int found = 0; | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1088 int incomplete; |
| 88365 | 1089 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1090 detect_info->checked |= CATEGORY_MASK_UTF_8; |
| 88365 | 1091 /* A coding system of this category is always ASCII compatible. */ |
| 1092 src += coding->head_ascii; | |
| 1093 | |
| 1094 while (1) | |
| 1095 { | |
| 1096 int c, c1, c2, c3, c4; | |
| 1097 | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1098 incomplete = 0; |
| 88365 | 1099 ONE_MORE_BYTE (c); |
| 1100 if (UTF_8_1_OCTET_P (c)) | |
| 1101 continue; | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1102 incomplete = 1; |
| 88365 | 1103 ONE_MORE_BYTE (c1); |
| 1104 if (! UTF_8_EXTRA_OCTET_P (c1)) | |
| 1105 break; | |
| 1106 if (UTF_8_2_OCTET_LEADING_P (c)) | |
| 1107 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1108 found = CATEGORY_MASK_UTF_8; |
| 88365 | 1109 continue; |
| 1110 } | |
| 1111 ONE_MORE_BYTE (c2); | |
| 1112 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
| 1113 break; | |
| 1114 if (UTF_8_3_OCTET_LEADING_P (c)) | |
| 1115 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1116 found = CATEGORY_MASK_UTF_8; |
| 88365 | 1117 continue; |
| 1118 } | |
| 1119 ONE_MORE_BYTE (c3); | |
| 1120 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
| 1121 break; | |
| 1122 if (UTF_8_4_OCTET_LEADING_P (c)) | |
| 1123 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1124 found = CATEGORY_MASK_UTF_8; |
| 88365 | 1125 continue; |
| 1126 } | |
| 1127 ONE_MORE_BYTE (c4); | |
| 1128 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
| 1129 break; | |
| 1130 if (UTF_8_5_OCTET_LEADING_P (c)) | |
| 1131 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1132 found = CATEGORY_MASK_UTF_8; |
| 88365 | 1133 continue; |
| 1134 } | |
| 1135 break; | |
| 1136 } | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1137 detect_info->rejected |= CATEGORY_MASK_UTF_8; |
| 88365 | 1138 return 0; |
| 1139 | |
| 1140 no_more_source: | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1141 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1142 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1143 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
|
1144 return 0; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1145 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1146 detect_info->found |= found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1147 return 1; |
| 88365 | 1148 } |
| 1149 | |
| 1150 | |
| 1151 static void | |
| 1152 decode_coding_utf_8 (coding) | |
| 1153 struct coding_system *coding; | |
| 1154 { | |
| 1155 unsigned char *src = coding->source + coding->consumed; | |
| 1156 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 1157 unsigned char *src_base; | |
| 1158 int *charbuf = coding->charbuf; | |
| 1159 int *charbuf_end = charbuf + coding->charbuf_size; | |
| 1160 int consumed_chars = 0, consumed_chars_base; | |
| 1161 int multibytep = coding->src_multibyte; | |
| 1162 Lisp_Object attr, eol_type, charset_list; | |
| 1163 | |
| 1164 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
| 1165 | |
| 1166 while (1) | |
| 1167 { | |
| 1168 int c, c1, c2, c3, c4, c5; | |
| 1169 | |
| 1170 src_base = src; | |
| 1171 consumed_chars_base = consumed_chars; | |
| 1172 | |
| 1173 if (charbuf >= charbuf_end) | |
| 1174 break; | |
| 1175 | |
| 1176 ONE_MORE_BYTE (c1); | |
| 1177 if (UTF_8_1_OCTET_P(c1)) | |
| 1178 { | |
| 1179 c = c1; | |
| 1180 if (c == '\r') | |
| 1181 { | |
| 1182 if (EQ (eol_type, Qdos)) | |
| 1183 { | |
| 1184 if (src == src_end) | |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1185 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1186 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1187 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1188 } |
| 88365 | 1189 if (*src == '\n') |
| 1190 ONE_MORE_BYTE (c); | |
| 1191 } | |
| 1192 else if (EQ (eol_type, Qmac)) | |
| 1193 c = '\n'; | |
| 1194 } | |
| 1195 } | |
| 1196 else | |
| 1197 { | |
| 1198 ONE_MORE_BYTE (c2); | |
| 1199 if (! UTF_8_EXTRA_OCTET_P (c2)) | |
| 1200 goto invalid_code; | |
| 1201 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
|
1202 { |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1203 c = ((c1 & 0x1F) << 6) | (c2 & 0x3F); |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1204 /* Reject overlong sequences here and below. Encoders |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1205 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
|
1206 and they mess up read/write invariance. */ |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1207 if (c < 128) |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1208 goto invalid_code; |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1209 } |
| 88365 | 1210 else |
| 1211 { | |
| 1212 ONE_MORE_BYTE (c3); | |
| 1213 if (! UTF_8_EXTRA_OCTET_P (c3)) | |
| 1214 goto invalid_code; | |
| 1215 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
|
1216 { |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1217 c = (((c1 & 0xF) << 12) |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1218 | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); |
|
89184
88a9e962e183
(decode_coding_utf_8): Treat surrogates as invalid.
Dave Love <fx@gnu.org>
parents:
89042
diff
changeset
|
1219 if (c < 0x800 |
|
88a9e962e183
(decode_coding_utf_8): Treat surrogates as invalid.
Dave Love <fx@gnu.org>
parents:
89042
diff
changeset
|
1220 || (c >= 0xd800 && c < 0xe000)) /* surrogates (invalid) */ |
|
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1221 goto invalid_code; |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1222 } |
| 88365 | 1223 else |
| 1224 { | |
| 1225 ONE_MORE_BYTE (c4); | |
| 1226 if (! UTF_8_EXTRA_OCTET_P (c4)) | |
| 1227 goto invalid_code; | |
| 1228 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
|
1229 { |
| 88365 | 1230 c = (((c1 & 0x7) << 18) | ((c2 & 0x3F) << 12) |
| 1231 | ((c3 & 0x3F) << 6) | (c4 & 0x3F)); | |
|
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1232 if (c < 0x10000) |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1233 goto invalid_code; |
|
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1234 } |
| 88365 | 1235 else |
| 1236 { | |
| 1237 ONE_MORE_BYTE (c5); | |
| 1238 if (! UTF_8_EXTRA_OCTET_P (c5)) | |
| 1239 goto invalid_code; | |
| 1240 if (UTF_8_5_OCTET_LEADING_P (c1)) | |
| 1241 { | |
| 1242 c = (((c1 & 0x3) << 24) | ((c2 & 0x3F) << 18) | |
| 1243 | ((c3 & 0x3F) << 12) | ((c4 & 0x3F) << 6) | |
| 1244 | (c5 & 0x3F)); | |
|
88669
0bc5868f9f61
(decode_coding_utf_8): Reject overlong sequences.
Dave Love <fx@gnu.org>
parents:
88646
diff
changeset
|
1245 if ((c > MAX_CHAR) || (c < 0x200000)) |
| 88365 | 1246 goto invalid_code; |
| 1247 } | |
| 1248 else | |
| 1249 goto invalid_code; | |
| 1250 } | |
| 1251 } | |
| 1252 } | |
| 1253 } | |
| 1254 | |
| 1255 *charbuf++ = c; | |
| 1256 continue; | |
| 1257 | |
| 1258 invalid_code: | |
| 1259 src = src_base; | |
| 1260 consumed_chars = consumed_chars_base; | |
| 1261 ONE_MORE_BYTE (c); | |
| 1262 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); | |
| 1263 coding->errors++; | |
| 1264 } | |
| 1265 | |
| 1266 no_more_source: | |
| 1267 coding->consumed_char += consumed_chars_base; | |
| 1268 coding->consumed = src_base - coding->source; | |
| 1269 coding->charbuf_used = charbuf - coding->charbuf; | |
| 1270 } | |
| 1271 | |
| 1272 | |
| 1273 static int | |
| 1274 encode_coding_utf_8 (coding) | |
| 1275 struct coding_system *coding; | |
| 1276 { | |
| 1277 int multibytep = coding->dst_multibyte; | |
| 1278 int *charbuf = coding->charbuf; | |
| 1279 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 1280 unsigned char *dst = coding->destination + coding->produced; | |
| 1281 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
|
1282 int produced_chars = 0; |
| 88365 | 1283 int c; |
| 1284 | |
| 1285 if (multibytep) | |
| 1286 { | |
| 1287 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
| 1288 | |
| 1289 while (charbuf < charbuf_end) | |
| 1290 { | |
| 1291 unsigned char str[MAX_MULTIBYTE_LENGTH], *p, *pend = str; | |
| 1292 | |
| 1293 ASSURE_DESTINATION (safe_room); | |
| 1294 c = *charbuf++; | |
|
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1295 if (CHAR_BYTE8_P (c)) |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1296 { |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1297 c = CHAR_TO_BYTE8 (c); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1298 EMIT_ONE_BYTE (c); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1299 } |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1300 else |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1301 { |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1302 CHAR_STRING_ADVANCE (c, pend); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1303 for (p = str; p < pend; p++) |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1304 EMIT_ONE_BYTE (*p); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
1305 } |
| 88365 | 1306 } |
| 1307 } | |
| 1308 else | |
| 1309 { | |
| 1310 int safe_room = MAX_MULTIBYTE_LENGTH; | |
| 1311 | |
| 1312 while (charbuf < charbuf_end) | |
| 1313 { | |
| 1314 ASSURE_DESTINATION (safe_room); | |
| 1315 c = *charbuf++; | |
| 1316 dst += CHAR_STRING (c, dst); | |
| 1317 produced_chars++; | |
| 1318 } | |
| 1319 } | |
| 1320 coding->result = CODING_RESULT_SUCCESS; | |
| 1321 coding->produced_char += produced_chars; | |
| 1322 coding->produced = dst - coding->destination; | |
| 1323 return 0; | |
| 1324 } | |
| 1325 | |
| 1326 | |
| 1327 /* 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
|
1328 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
|
1329 If it is, return 1, else return 0. */ |
| 88365 | 1330 |
| 1331 #define UTF_16_HIGH_SURROGATE_P(val) \ | |
| 1332 (((val) & 0xFC00) == 0xD800) | |
| 1333 | |
| 1334 #define UTF_16_LOW_SURROGATE_P(val) \ | |
| 1335 (((val) & 0xFC00) == 0xDC00) | |
| 1336 | |
| 1337 #define UTF_16_INVALID_P(val) \ | |
| 1338 (((val) == 0xFFFE) \ | |
| 1339 || ((val) == 0xFFFF) \ | |
| 1340 || UTF_16_LOW_SURROGATE_P (val)) | |
| 1341 | |
| 1342 | |
| 1343 static int | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1344 detect_coding_utf_16 (coding, detect_info) |
| 88365 | 1345 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1346 struct coding_detection_info *detect_info; |
| 88365 | 1347 { |
| 1348 unsigned char *src = coding->source, *src_base = src; | |
| 1349 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 1350 int multibytep = coding->src_multibyte; | |
| 1351 int consumed_chars = 0; | |
| 1352 int c1, c2; | |
| 1353 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1354 detect_info->checked |= CATEGORY_MASK_UTF_16; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1355 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1356 if (coding->mode & CODING_MODE_LAST_BLOCK |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1357 && (coding->src_bytes & 1)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1358 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1359 detect_info->rejected |= CATEGORY_MASK_UTF_16; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1360 return 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1361 } |
| 88365 | 1362 ONE_MORE_BYTE (c1); |
| 1363 ONE_MORE_BYTE (c2); | |
| 1364 | |
| 1365 if ((c1 == 0xFF) && (c2 == 0xFE)) | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1366 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1367 detect_info->found |= CATEGORY_MASK_UTF_16_LE; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1368 detect_info->rejected |= CATEGORY_MASK_UTF_16_BE; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1369 } |
| 88365 | 1370 else if ((c1 == 0xFE) && (c2 == 0xFF)) |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1371 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1372 detect_info->found |= CATEGORY_MASK_UTF_16_BE; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1373 detect_info->rejected |= CATEGORY_MASK_UTF_16_LE; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1374 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1375 no_more_source: |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1376 return 1; |
| 88365 | 1377 } |
| 1378 | |
| 1379 static void | |
| 1380 decode_coding_utf_16 (coding) | |
| 1381 struct coding_system *coding; | |
| 1382 { | |
| 1383 unsigned char *src = coding->source + coding->consumed; | |
| 1384 unsigned char *src_end = coding->source + coding->src_bytes; | |
|
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
1385 unsigned char *src_base; |
| 88365 | 1386 int *charbuf = coding->charbuf; |
| 1387 int *charbuf_end = charbuf + coding->charbuf_size; | |
| 1388 int consumed_chars = 0, consumed_chars_base; | |
| 1389 int multibytep = coding->src_multibyte; | |
| 1390 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
| 1391 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); | |
| 1392 int surrogate = CODING_UTF_16_SURROGATE (coding); | |
| 1393 Lisp_Object attr, eol_type, charset_list; | |
| 1394 | |
| 1395 CODING_GET_INFO (coding, attr, eol_type, charset_list); | |
| 1396 | |
| 1397 if (bom != utf_16_without_bom) | |
| 1398 { | |
| 1399 int c, c1, c2; | |
| 1400 | |
| 1401 src_base = src; | |
| 1402 ONE_MORE_BYTE (c1); | |
| 1403 ONE_MORE_BYTE (c2); | |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1404 c = (c1 << 8) | c2; |
| 88365 | 1405 if (bom == utf_16_with_bom) |
| 1406 { | |
| 1407 if (endian == utf_16_big_endian | |
| 1408 ? c != 0xFFFE : c != 0xFEFF) | |
| 1409 { | |
| 1410 /* We are sure that there's enouph room at CHARBUF. */ | |
| 1411 *charbuf++ = c1; | |
| 1412 *charbuf++ = c2; | |
| 1413 coding->errors++; | |
| 1414 } | |
| 1415 } | |
| 1416 else | |
| 1417 { | |
| 1418 if (c == 0xFFFE) | |
| 1419 CODING_UTF_16_ENDIAN (coding) | |
| 1420 = endian = utf_16_big_endian; | |
| 1421 else if (c == 0xFEFF) | |
| 1422 CODING_UTF_16_ENDIAN (coding) | |
| 1423 = endian = utf_16_little_endian; | |
| 1424 else | |
| 1425 { | |
| 1426 CODING_UTF_16_ENDIAN (coding) | |
| 1427 = endian = utf_16_big_endian; | |
| 1428 src = src_base; | |
| 1429 } | |
| 1430 } | |
| 1431 CODING_UTF_16_BOM (coding) = utf_16_with_bom; | |
| 1432 } | |
| 1433 | |
| 1434 while (1) | |
| 1435 { | |
| 1436 int c, c1, c2; | |
| 1437 | |
| 1438 src_base = src; | |
| 1439 consumed_chars_base = consumed_chars; | |
| 1440 | |
| 1441 if (charbuf + 2 >= charbuf_end) | |
| 1442 break; | |
| 1443 | |
| 1444 ONE_MORE_BYTE (c1); | |
| 1445 ONE_MORE_BYTE (c2); | |
| 1446 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
|
1447 ? ((c1 << 8) | c2) : ((c2 << 8) | c1)); |
| 88365 | 1448 if (surrogate) |
| 1449 { | |
| 1450 if (! UTF_16_LOW_SURROGATE_P (c)) | |
| 1451 { | |
| 1452 if (endian == utf_16_big_endian) | |
| 1453 c1 = surrogate >> 8, c2 = surrogate & 0xFF; | |
| 1454 else | |
| 1455 c1 = surrogate & 0xFF, c2 = surrogate >> 8; | |
| 1456 *charbuf++ = c1; | |
| 1457 *charbuf++ = c2; | |
| 1458 coding->errors++; | |
| 1459 if (UTF_16_HIGH_SURROGATE_P (c)) | |
| 1460 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
| 1461 else | |
| 1462 *charbuf++ = c; | |
| 1463 } | |
| 1464 else | |
| 1465 { | |
| 1466 c = ((surrogate - 0xD800) << 10) | (c - 0xDC00); | |
| 1467 CODING_UTF_16_SURROGATE (coding) = surrogate = 0; | |
| 1468 *charbuf++ = c; | |
| 1469 } | |
| 1470 } | |
| 1471 else | |
| 1472 { | |
| 1473 if (UTF_16_HIGH_SURROGATE_P (c)) | |
| 1474 CODING_UTF_16_SURROGATE (coding) = surrogate = c; | |
| 1475 else | |
| 1476 *charbuf++ = c; | |
| 1477 } | |
| 1478 } | |
| 1479 | |
| 1480 no_more_source: | |
| 1481 coding->consumed_char += consumed_chars_base; | |
| 1482 coding->consumed = src_base - coding->source; | |
| 1483 coding->charbuf_used = charbuf - coding->charbuf; | |
| 1484 } | |
| 1485 | |
| 1486 static int | |
| 1487 encode_coding_utf_16 (coding) | |
| 1488 struct coding_system *coding; | |
| 1489 { | |
| 1490 int multibytep = coding->dst_multibyte; | |
| 1491 int *charbuf = coding->charbuf; | |
| 1492 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 1493 unsigned char *dst = coding->destination + coding->produced; | |
| 1494 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 1495 int safe_room = 8; | |
| 1496 enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); | |
| 1497 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; | |
| 1498 int produced_chars = 0; | |
| 1499 Lisp_Object attrs, eol_type, charset_list; | |
| 1500 int c; | |
| 1501 | |
| 1502 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 1503 | |
| 1504 if (bom == utf_16_with_bom) | |
| 1505 { | |
| 1506 ASSURE_DESTINATION (safe_room); | |
| 1507 if (big_endian) | |
| 1508 EMIT_TWO_BYTES (0xFF, 0xFE); | |
| 1509 else | |
| 1510 EMIT_TWO_BYTES (0xFE, 0xFF); | |
| 1511 CODING_UTF_16_BOM (coding) = utf_16_without_bom; | |
| 1512 } | |
| 1513 | |
| 1514 while (charbuf < charbuf_end) | |
| 1515 { | |
| 1516 ASSURE_DESTINATION (safe_room); | |
| 1517 c = *charbuf++; | |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1518 if (c >= MAX_UNICODE_CHAR) |
|
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
1519 c = coding->default_char; |
| 88365 | 1520 |
| 1521 if (c < 0x10000) | |
| 1522 { | |
| 1523 if (big_endian) | |
| 1524 EMIT_TWO_BYTES (c >> 8, c & 0xFF); | |
| 1525 else | |
| 1526 EMIT_TWO_BYTES (c & 0xFF, c >> 8); | |
| 1527 } | |
| 1528 else | |
| 1529 { | |
| 1530 int c1, c2; | |
| 1531 | |
| 1532 c -= 0x10000; | |
| 1533 c1 = (c >> 10) + 0xD800; | |
| 1534 c2 = (c & 0x3FF) + 0xDC00; | |
| 1535 if (big_endian) | |
| 1536 EMIT_FOUR_BYTES (c1 >> 8, c1 & 0xFF, c2 >> 8, c2 & 0xFF); | |
| 1537 else | |
| 1538 EMIT_FOUR_BYTES (c1 & 0xFF, c1 >> 8, c2 & 0xFF, c2 >> 8); | |
| 1539 } | |
| 1540 } | |
| 1541 coding->result = CODING_RESULT_SUCCESS; | |
| 1542 coding->produced = dst - coding->destination; | |
| 1543 coding->produced_char += produced_chars; | |
| 1544 return 0; | |
| 1545 } | |
| 1546 | |
| 1547 | |
| 1548 /*** 6. Old Emacs' internal format (emacs-mule) ***/ | |
| 17052 | 1549 |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1550 /* Emacs' internal format for representation of multiple character |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1551 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
|
1552 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
|
1553 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1554 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
|
1555 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
|
1556 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
|
1557 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1558 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
|
1559 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
|
1560 code + 0x20). |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1561 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1562 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
|
1563 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
|
1564 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1565 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
|
1566 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
|
1567 `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
|
1568 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
|
1569 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
|
1570 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
|
1571 and position-code. |
| 18766 | 1572 |
| 17052 | 1573 --- 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
|
1574 character set range |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1575 ------------- ----- |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1576 ascii 0x00..0x7F |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1577 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
|
1578 eight-bit-graphic 0xA0..0xBF |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1579 ELSE 0x81..0x9D + [0xA0..0xFF]+ |
| 17052 | 1580 --------------------------------------------- |
| 1581 | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1582 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
|
1583 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
|
1584 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
|
1585 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
|
1586 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1587 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
|
1588 form. |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1589 |
| 88365 | 1590 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
|
1591 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
|
1592 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1593 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
|
1594 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
|
1595 where, |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1596 METHOD is 0xF0 plus one of composition method (enum |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1597 composition_method), |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1598 |
| 88365 | 1599 BYTES is 0xA0 plus a byte length of this composition data, |
| 1600 | |
| 1601 CHARS is 0x20 plus a number of characters composed by this | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1602 data, |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1603 |
| 88365 | 1604 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
|
1605 rules encoded by two-byte of ASCII codes. |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1606 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1607 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
|
1608 also recognized as composition data on decoding. |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1609 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1610 0x80 MSEQ ... |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1611 0x80 0xFF MSEQ RULE MSEQ RULE ... MSEQ |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1612 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1613 Here, |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1614 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
|
1615 ASCII: 0xA0 ASCII_CODE+0x80, |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1616 other: LEADING_CODE+0x20 FOLLOWING-BYTE ..., |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1617 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
|
1618 represents a composition rule. |
| 17052 | 1619 */ |
| 1620 | |
| 88365 | 1621 char emacs_mule_bytes[256]; |
| 1622 | |
| 1623 int | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1624 emacs_mule_char (coding, src, nbytes, nchars, id) |
| 88365 | 1625 struct coding_system *coding; |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1626 unsigned char *src; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1627 int *nbytes, *nchars, *id; |
| 88365 | 1628 { |
| 1629 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 1630 int multibytep = coding->src_multibyte; | |
| 1631 unsigned char *src_base = src; | |
| 1632 struct charset *charset; | |
| 1633 unsigned code; | |
| 1634 int c; | |
| 1635 int consumed_chars = 0; | |
| 1636 | |
| 1637 ONE_MORE_BYTE (c); | |
| 1638 switch (emacs_mule_bytes[c]) | |
| 1639 { | |
| 1640 case 2: | |
| 1641 if (! (charset = emacs_mule_charset[c])) | |
| 1642 goto invalid_code; | |
| 1643 ONE_MORE_BYTE (c); | |
| 1644 code = c & 0x7F; | |
| 1645 break; | |
| 1646 | |
| 1647 case 3: | |
|
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
1648 if (c == EMACS_MULE_LEADING_CODE_PRIVATE_11 |
|
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
1649 || c == EMACS_MULE_LEADING_CODE_PRIVATE_12) |
| 88365 | 1650 { |
| 1651 ONE_MORE_BYTE (c); | |
| 1652 if (! (charset = emacs_mule_charset[c])) | |
| 1653 goto invalid_code; | |
| 1654 ONE_MORE_BYTE (c); | |
| 1655 code = c & 0x7F; | |
| 1656 } | |
| 1657 else | |
| 1658 { | |
| 1659 if (! (charset = emacs_mule_charset[c])) | |
| 1660 goto invalid_code; | |
| 1661 ONE_MORE_BYTE (c); | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1662 code = (c & 0x7F) << 8; |
| 88365 | 1663 ONE_MORE_BYTE (c); |
| 1664 code |= c & 0x7F; | |
| 1665 } | |
| 1666 break; | |
| 1667 | |
| 1668 case 4: | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1669 ONE_MORE_BYTE (c); |
| 88365 | 1670 if (! (charset = emacs_mule_charset[c])) |
| 1671 goto invalid_code; | |
| 1672 ONE_MORE_BYTE (c); | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1673 code = (c & 0x7F) << 8; |
| 88365 | 1674 ONE_MORE_BYTE (c); |
| 1675 code |= c & 0x7F; | |
| 1676 break; | |
| 1677 | |
| 1678 case 1: | |
| 1679 code = c; | |
|
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
1680 charset = CHARSET_FROM_ID (ASCII_BYTE_P (code) |
|
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
1681 ? charset_ascii : charset_eight_bit); |
| 88365 | 1682 break; |
| 1683 | |
| 1684 default: | |
| 1685 abort (); | |
| 1686 } | |
| 1687 c = DECODE_CHAR (charset, code); | |
| 1688 if (c < 0) | |
| 1689 goto invalid_code; | |
| 1690 *nbytes = src - src_base; | |
| 1691 *nchars = consumed_chars; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1692 if (id) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1693 *id = charset->id; |
| 88365 | 1694 return c; |
| 1695 | |
| 1696 no_more_source: | |
| 1697 return -2; | |
| 1698 | |
| 1699 invalid_code: | |
| 1700 return -1; | |
| 1701 } | |
| 1702 | |
| 17052 | 1703 |
| 1704 /* 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
|
1705 Check if a text is encoded in `emacs-mule'. If it is, return 1, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1706 else return 0. */ |
| 17052 | 1707 |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
1708 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1709 detect_coding_emacs_mule (coding, detect_info) |
| 88365 | 1710 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1711 struct coding_detection_info *detect_info; |
| 17052 | 1712 { |
| 88365 | 1713 unsigned char *src = coding->source, *src_base = src; |
| 1714 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 1715 int multibytep = coding->src_multibyte; | |
| 1716 int consumed_chars = 0; | |
| 1717 int c; | |
| 1718 int found = 0; | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1719 int incomplete; |
| 88365 | 1720 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1721 detect_info->checked |= CATEGORY_MASK_EMACS_MULE; |
| 88365 | 1722 /* A coding system of this category is always ASCII compatible. */ |
| 1723 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
|
1724 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1725 while (1) |
| 17052 | 1726 { |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1727 incomplete = 0; |
| 88365 | 1728 ONE_MORE_BYTE (c); |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1729 incomplete = 1; |
| 88365 | 1730 |
| 1731 if (c == 0x80) | |
| 17052 | 1732 { |
| 88365 | 1733 /* Perhaps the start of composite character. We simple skip |
| 1734 it because analyzing it is too heavy for detecting. But, | |
| 1735 at least, we check that the composite character | |
| 1736 constitues of more than 4 bytes. */ | |
| 1737 unsigned char *src_base; | |
| 1738 | |
| 1739 repeat: | |
| 1740 src_base = src; | |
| 1741 do | |
| 1742 { | |
| 1743 ONE_MORE_BYTE (c); | |
| 1744 } | |
| 1745 while (c >= 0xA0); | |
| 1746 | |
| 1747 if (src - src_base <= 4) | |
| 1748 break; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1749 found = CATEGORY_MASK_EMACS_MULE; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1750 if (c == 0x80) |
| 88365 | 1751 goto repeat; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1752 } |
| 88365 | 1753 |
| 1754 if (c < 0x80) | |
| 1755 { | |
| 1756 if (c < 0x20 | |
| 1757 && (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)) | |
| 1758 break; | |
| 1759 } | |
| 1760 else | |
| 1761 { | |
| 1762 unsigned char *src_base = src - 1; | |
| 1763 | |
| 1764 do | |
| 1765 { | |
| 1766 ONE_MORE_BYTE (c); | |
| 1767 } | |
| 1768 while (c >= 0xA0); | |
| 1769 if (src - src_base != emacs_mule_bytes[*src_base]) | |
| 1770 break; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1771 found = CATEGORY_MASK_EMACS_MULE; |
| 88365 | 1772 } |
| 1773 } | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1774 detect_info->rejected |= CATEGORY_MASK_EMACS_MULE; |
| 88365 | 1775 return 0; |
| 1776 | |
| 1777 no_more_source: | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1778 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1779 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1780 detect_info->rejected |= CATEGORY_MASK_EMACS_MULE; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1781 return 0; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
1782 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1783 detect_info->found |= found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1784 return 1; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1785 } |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1786 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1787 |
| 88365 | 1788 /* 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
|
1789 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1790 /* Decode a character represented as a component of composition |
| 88365 | 1791 sequence of Emacs 20/21 style at SRC. Set C to that character and |
| 1792 update SRC to the head of next character (or an encoded composition | |
| 1793 rule). If SRC doesn't points a composition component, set C to -1. | |
| 1794 If SRC points an invalid byte sequence, global exit by a return | |
| 1795 value 0. */ | |
| 1796 | |
| 1797 #define DECODE_EMACS_MULE_COMPOSITION_CHAR(buf) \ | |
| 1798 if (1) \ | |
| 1799 { \ | |
| 1800 int c; \ | |
| 1801 int nbytes, nchars; \ | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1802 \ |
| 88365 | 1803 if (src == src_end) \ |
| 1804 break; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1805 c = emacs_mule_char (coding, src, &nbytes, &nchars, NULL);\ |
| 88365 | 1806 if (c < 0) \ |
| 1807 { \ | |
| 1808 if (c == -2) \ | |
| 1809 break; \ | |
| 1810 goto invalid_code; \ | |
| 1811 } \ | |
| 1812 *buf++ = c; \ | |
| 1813 src += nbytes; \ | |
| 1814 consumed_chars += nchars; \ | |
| 1815 } \ | |
| 1816 else | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1817 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1818 |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1819 /* Decode a composition rule represented as a component of composition |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1820 sequence of Emacs 20 style at SRC. Store the decoded rule in *BUF, |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1821 and increment BUF. If SRC points an invalid byte sequence, set C |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1822 to -1. */ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1823 |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1824 #define DECODE_EMACS_MULE_COMPOSITION_RULE_20(buf) \ |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1825 do { \ |
| 88365 | 1826 int c, gref, nref; \ |
| 1827 \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1828 if (src >= src_end) \ |
| 88365 | 1829 goto invalid_code; \ |
| 1830 ONE_MORE_BYTE_NO_CHECK (c); \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1831 c -= 0x20; \ |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
1832 if (c < 0 || c >= 81) \ |
| 88365 | 1833 goto invalid_code; \ |
| 1834 \ | |
| 1835 gref = c / 9, nref = c % 9; \ | |
| 1836 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ | |
| 1837 } while (0) | |
| 1838 | |
| 1839 | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1840 /* Decode a composition rule represented as a component of composition |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1841 sequence of Emacs 21 style at SRC. Store the decoded rule in *BUF, |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1842 and increment BUF. If SRC points an invalid byte sequence, set C |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1843 to -1. */ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1844 |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1845 #define DECODE_EMACS_MULE_COMPOSITION_RULE_21(buf) \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1846 do { \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1847 int gref, nref; \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1848 \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1849 if (src + 1>= src_end) \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1850 goto invalid_code; \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1851 ONE_MORE_BYTE_NO_CHECK (gref); \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1852 gref -= 0x20; \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1853 ONE_MORE_BYTE_NO_CHECK (nref); \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1854 nref -= 0x20; \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1855 if (gref < 0 || gref >= 81 \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1856 || nref < 0 || nref >= 81) \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1857 goto invalid_code; \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1858 *buf++ = COMPOSITION_ENCODE_RULE (gref, nref); \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1859 } while (0) |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1860 |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1861 |
| 88365 | 1862 #define DECODE_EMACS_MULE_21_COMPOSITION(c) \ |
| 1863 do { \ | |
| 1864 /* Emacs 21 style format. The first three bytes at SRC are \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1865 (METHOD - 0xF2), (BYTES - 0xA0), (CHARS - 0xA0), where BYTES is \ |
| 88365 | 1866 the byte length of this composition information, CHARS is the \ |
| 1867 number of characters composed by this composition. */ \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1868 enum composition_method method = c - 0xF2; \ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1869 int *charbuf_base = charbuf; \ |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1870 int from, to; \ |
| 88365 | 1871 int consumed_chars_limit; \ |
| 1872 int nbytes, nchars; \ | |
| 1873 \ | |
| 1874 ONE_MORE_BYTE (c); \ | |
| 1875 nbytes = c - 0xA0; \ | |
| 1876 if (nbytes < 3) \ | |
| 1877 goto invalid_code; \ | |
| 1878 ONE_MORE_BYTE (c); \ | |
| 1879 nchars = c - 0xA0; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1880 from = coding->produced + char_offset; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1881 to = from + nchars; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1882 ADD_COMPOSITION_DATA (charbuf, from, to, method); \ |
| 88365 | 1883 consumed_chars_limit = consumed_chars_base + nbytes; \ |
| 1884 if (method != COMPOSITION_RELATIVE) \ | |
| 1885 { \ | |
| 1886 int i = 0; \ | |
| 1887 while (consumed_chars < consumed_chars_limit) \ | |
| 1888 { \ | |
| 1889 if (i % 2 && method != COMPOSITION_WITH_ALTCHARS) \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1890 DECODE_EMACS_MULE_COMPOSITION_RULE_21 (charbuf); \ |
| 88365 | 1891 else \ |
| 1892 DECODE_EMACS_MULE_COMPOSITION_CHAR (charbuf); \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1893 i++; \ |
| 88365 | 1894 } \ |
| 1895 if (consumed_chars < consumed_chars_limit) \ | |
| 1896 goto invalid_code; \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1897 charbuf_base[0] -= i; \ |
| 88365 | 1898 } \ |
| 1899 } while (0) | |
| 1900 | |
| 1901 | |
| 1902 #define DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION(c) \ | |
| 1903 do { \ | |
| 1904 /* Emacs 20 style format for relative composition. */ \ | |
| 1905 /* Store multibyte form of characters to be composed. */ \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1906 enum composition_method method = COMPOSITION_RELATIVE; \ |
| 88365 | 1907 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ |
| 1908 int *buf = components; \ | |
| 1909 int i, j; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1910 int from, to; \ |
| 88365 | 1911 \ |
| 1912 src = src_base; \ | |
| 1913 ONE_MORE_BYTE (c); /* skip 0x80 */ \ | |
| 1914 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
| 1915 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
| 1916 if (i < 2) \ | |
| 1917 goto invalid_code; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1918 from = coding->produced_char + char_offset; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1919 to = from + i; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1920 ADD_COMPOSITION_DATA (charbuf, from, to, method); \ |
| 88365 | 1921 for (j = 0; j < i; j++) \ |
| 1922 *charbuf++ = components[j]; \ | |
| 1923 } while (0) | |
| 1924 | |
| 1925 | |
| 1926 #define DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION(c) \ | |
| 1927 do { \ | |
| 1928 /* Emacs 20 style format for rule-base composition. */ \ | |
| 1929 /* Store multibyte form of characters to be composed. */ \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1930 enum composition_method method = COMPOSITION_WITH_RULE; \ |
| 88365 | 1931 int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ |
| 1932 int *buf = components; \ | |
| 1933 int i, j; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1934 int from, to; \ |
| 88365 | 1935 \ |
| 1936 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ | |
| 1937 for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ | |
| 1938 { \ | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
1939 DECODE_EMACS_MULE_COMPOSITION_RULE_20 (buf); \ |
| 88365 | 1940 DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ |
| 1941 } \ | |
| 1942 if (i < 1 || (buf - components) % 2 == 0) \ | |
| 1943 goto invalid_code; \ | |
| 1944 if (charbuf + i + (i / 2) + 1 < charbuf_end) \ | |
| 1945 goto no_more_source; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1946 from = coding->produced_char + char_offset; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1947 to = from + i; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1948 ADD_COMPOSITION_DATA (buf, from, to, method); \ |
| 88365 | 1949 for (j = 0; j < i; j++) \ |
| 1950 *charbuf++ = components[j]; \ | |
| 1951 for (j = 0; j < i; j += 2) \ | |
| 1952 *charbuf++ = components[j]; \ | |
| 1953 } while (0) | |
| 1954 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1955 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1956 static void |
| 88365 | 1957 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
|
1958 struct coding_system *coding; |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1959 { |
| 88365 | 1960 unsigned char *src = coding->source + coding->consumed; |
| 1961 unsigned char *src_end = coding->source + coding->src_bytes; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
1962 unsigned char *src_base; |
| 88365 | 1963 int *charbuf = coding->charbuf; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1964 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
| 88365 | 1965 int consumed_chars = 0, consumed_chars_base; |
| 1966 int multibytep = coding->src_multibyte; | |
| 1967 Lisp_Object attrs, eol_type, charset_list; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1968 int char_offset = coding->produced_char; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1969 int last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
1970 int last_id = charset_ascii; |
| 88365 | 1971 |
| 1972 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 1973 | |
| 1974 while (1) | |
| 1975 { | |
| 1976 int c; | |
| 1977 | |
| 1978 src_base = src; | |
| 1979 consumed_chars_base = consumed_chars; | |
| 1980 | |
| 1981 if (charbuf >= charbuf_end) | |
| 1982 break; | |
| 1983 | |
| 1984 ONE_MORE_BYTE (c); | |
| 1985 | |
| 1986 if (c < 0x80) | |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1987 { |
| 88365 | 1988 if (c == '\r') |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1989 { |
| 88365 | 1990 if (EQ (eol_type, Qdos)) |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1991 { |
| 88365 | 1992 if (src == src_end) |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1993 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1994 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1995 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
1996 } |
| 88365 | 1997 if (*src == '\n') |
| 1998 ONE_MORE_BYTE (c); | |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
1999 } |
| 88365 | 2000 else if (EQ (eol_type, Qmac)) |
| 2001 c = '\n'; | |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2002 } |
| 88365 | 2003 *charbuf++ = c; |
| 2004 char_offset++; | |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2005 } |
| 88365 | 2006 else if (c == 0x80) |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2007 { |
| 88365 | 2008 ONE_MORE_BYTE (c); |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2009 if (c - 0xF2 >= COMPOSITION_RELATIVE |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2010 && c - 0xF2 <= COMPOSITION_WITH_RULE_ALTCHARS) |
| 88365 | 2011 DECODE_EMACS_MULE_21_COMPOSITION (c); |
| 2012 else if (c < 0xC0) | |
| 2013 DECODE_EMACS_MULE_20_RELATIVE_COMPOSITION (c); | |
| 2014 else if (c == 0xFF) | |
| 2015 DECODE_EMACS_MULE_20_RULEBASE_COMPOSITION (c); | |
| 2016 else | |
| 2017 goto invalid_code; | |
|
32806
9502d0a5b2ad
(decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents:
32745
diff
changeset
|
2018 } |
| 88365 | 2019 else if (c < 0xA0 && emacs_mule_bytes[c] > 1) |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2020 { |
| 88365 | 2021 int nbytes, nchars; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2022 int id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2023 |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2024 src = src_base; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2025 consumed_chars = consumed_chars_base; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2026 c = emacs_mule_char (coding, src, &nbytes, &nchars, &id); |
| 88365 | 2027 if (c < 0) |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2028 { |
| 88365 | 2029 if (c == -2) |
| 2030 break; | |
| 2031 goto invalid_code; | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2032 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2033 if (last_id != id) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2034 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2035 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2036 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2037 last_id = id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2038 last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2039 } |
| 88365 | 2040 *charbuf++ = c; |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2041 src += nbytes; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2042 consumed_chars += nchars; |
| 88365 | 2043 char_offset++; |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2044 } |
| 88365 | 2045 continue; |
| 2046 | |
| 2047 invalid_code: | |
| 2048 src = src_base; | |
| 2049 consumed_chars = consumed_chars_base; | |
| 2050 ONE_MORE_BYTE (c); | |
| 2051 *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
|
2052 char_offset++; |
| 88365 | 2053 coding->errors++; |
| 2054 } | |
| 2055 | |
| 2056 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2057 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2058 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
| 88365 | 2059 coding->consumed_char += consumed_chars_base; |
| 2060 coding->consumed = src_base - coding->source; | |
| 2061 coding->charbuf_used = charbuf - coding->charbuf; | |
| 2062 } | |
| 2063 | |
| 2064 | |
| 2065 #define EMACS_MULE_LEADING_CODES(id, codes) \ | |
| 2066 do { \ | |
| 2067 if (id < 0xA0) \ | |
| 2068 codes[0] = id, codes[1] = 0; \ | |
| 2069 else if (id < 0xE0) \ | |
| 2070 codes[0] = 0x9A, codes[1] = id; \ | |
| 2071 else if (id < 0xF0) \ | |
| 2072 codes[0] = 0x9B, codes[1] = id; \ | |
| 2073 else if (id < 0xF5) \ | |
| 2074 codes[0] = 0x9C, codes[1] = id; \ | |
| 2075 else \ | |
| 2076 codes[0] = 0x9D, codes[1] = id; \ | |
| 2077 } while (0); | |
| 2078 | |
| 2079 | |
| 2080 static int | |
| 2081 encode_coding_emacs_mule (coding) | |
| 2082 struct coding_system *coding; | |
| 2083 { | |
| 2084 int multibytep = coding->dst_multibyte; | |
| 2085 int *charbuf = coding->charbuf; | |
| 2086 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 2087 unsigned char *dst = coding->destination + coding->produced; | |
| 2088 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 2089 int safe_room = 8; | |
| 2090 int produced_chars = 0; | |
| 2091 Lisp_Object attrs, eol_type, charset_list; | |
| 2092 int c; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2093 int preferred_charset_id = -1; |
| 88365 | 2094 |
| 2095 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 2096 | |
| 2097 while (charbuf < charbuf_end) | |
| 2098 { | |
| 2099 ASSURE_DESTINATION (safe_room); | |
| 2100 c = *charbuf++; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2101 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2102 if (c < 0) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2103 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2104 /* Handle an annotation. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2105 switch (*charbuf) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2106 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2107 case CODING_ANNOTATE_COMPOSITION_MASK: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2108 /* Not yet implemented. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2109 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2110 case CODING_ANNOTATE_CHARSET_MASK: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2111 preferred_charset_id = charbuf[3]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2112 if (preferred_charset_id >= 0 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2113 && NILP (Fmemq (make_number (preferred_charset_id), |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2114 charset_list))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2115 preferred_charset_id = -1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2116 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2117 default: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2118 abort (); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2119 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2120 charbuf += -c - 1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2121 continue; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2122 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2123 |
| 88365 | 2124 if (ASCII_CHAR_P (c)) |
| 2125 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
|
2126 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
|
2127 { |
|
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
2128 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
|
2129 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
|
2130 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2131 else |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2132 { |
| 88365 | 2133 struct charset *charset; |
| 2134 unsigned code; | |
| 2135 int dimension; | |
| 2136 int emacs_mule_id; | |
| 2137 unsigned char leading_codes[2]; | |
| 2138 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2139 if (preferred_charset_id >= 0) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2140 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2141 charset = CHARSET_FROM_ID (preferred_charset_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2142 if (! CHAR_CHARSET_P (c, charset)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2143 charset = char_charset (c, charset_list, NULL); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2144 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2145 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2146 charset = char_charset (c, charset_list, &code); |
| 88365 | 2147 if (! charset) |
| 2148 { | |
| 2149 c = coding->default_char; | |
| 2150 if (ASCII_CHAR_P (c)) | |
| 2151 { | |
| 2152 EMIT_ONE_ASCII_BYTE (c); | |
| 2153 continue; | |
| 2154 } | |
| 2155 charset = char_charset (c, charset_list, &code); | |
| 2156 } | |
| 2157 dimension = CHARSET_DIMENSION (charset); | |
| 2158 emacs_mule_id = CHARSET_EMACS_MULE_ID (charset); | |
| 2159 EMACS_MULE_LEADING_CODES (emacs_mule_id, leading_codes); | |
| 2160 EMIT_ONE_BYTE (leading_codes[0]); | |
| 2161 if (leading_codes[1]) | |
| 2162 EMIT_ONE_BYTE (leading_codes[1]); | |
| 2163 if (dimension == 1) | |
| 2164 EMIT_ONE_BYTE (code); | |
| 2165 else | |
| 2166 { | |
| 2167 EMIT_ONE_BYTE (code >> 8); | |
| 2168 EMIT_ONE_BYTE (code & 0xFF); | |
| 2169 } | |
| 17052 | 2170 } |
| 88365 | 2171 } |
| 2172 coding->result = CODING_RESULT_SUCCESS; | |
| 2173 coding->produced_char += produced_chars; | |
| 2174 coding->produced = dst - coding->destination; | |
| 2175 return 0; | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2176 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2177 |
| 17052 | 2178 |
| 88365 | 2179 /*** 7. ISO2022 handlers ***/ |
| 17052 | 2180 |
| 2181 /* 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
|
2182 Since the intention of this note is to help understand the |
| 88771 | 2183 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
|
2184 SIMPLIFIED. For thorough understanding, please refer to the |
| 88771 | 2185 original document of ISO2022. This is equivalent to the standard |
| 2186 ECMA-35, obtainable from <URL:http://www.ecma.ch/> (*). | |
| 17052 | 2187 |
| 2188 ISO2022 provides many mechanisms to encode several character sets | |
| 88771 | 2189 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
|
2190 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
|
2191 text a little bit longer, but the text passes more easily through |
| 88771 | 2192 several types of gateway, some of which strip off the MSB (Most |
| 2193 Significant Bit). | |
| 2194 | |
| 2195 There are two kinds of character sets: control character sets and | |
| 2196 graphic character sets. The former contain control characters such | |
| 17052 | 2197 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
|
2198 functions are also provided by escape sequences). The latter |
| 88771 | 2199 contain graphic characters such as 'A' and '-'. Emacs recognizes |
| 17052 | 2200 two control character sets and many graphic character sets. |
| 2201 | |
| 2202 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
|
2203 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
|
2204 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
|
2205 - DIMENSION1_CHARS94 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2206 - DIMENSION1_CHARS96 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2207 - DIMENSION2_CHARS94 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2208 - DIMENSION2_CHARS96 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2209 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2210 In addition, each character set is assigned an identification tag, |
| 88771 | 2211 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
|
2212 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
|
2213 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
|
2214 (0x30..0x3F are for private use only). |
| 17052 | 2215 |
| 2216 Note (*): ECMA = European Computer Manufacturers Association | |
| 2217 | |
| 88771 | 2218 Here are examples of graphic character sets [NAME(<F>)]: |
| 17052 | 2219 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ... |
| 2220 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ... | |
| 2221 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ... | |
| 2222 o DIMENSION2_CHARS96 -- none for the moment | |
| 2223 | |
|
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2224 A code area (1 byte=8 bits) is divided into 4 areas, C0, GL, C1, and GR. |
| 17052 | 2225 C0 [0x00..0x1F] -- control character plane 0 |
| 2226 GL [0x20..0x7F] -- graphic character plane 0 | |
| 2227 C1 [0x80..0x9F] -- control character plane 1 | |
| 2228 GR [0xA0..0xFF] -- graphic character plane 1 | |
| 2229 | |
| 2230 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
|
2231 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
|
2232 - 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
|
2233 - 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
|
2234 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
|
2235 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
|
2236 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
|
2237 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
|
2238 defined to have corresponding escape sequences. |
| 17052 | 2239 |
| 2240 A graphic character set is at first designated to one of four | |
| 2241 graphic registers (G0 through G3), then these graphic registers are | |
| 2242 invoked to GL or GR. These designations and invocations can be | |
| 2243 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
|
2244 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
|
2245 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
|
2246 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
|
2247 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2248 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
|
2249 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
|
2250 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
|
2251 be used. |
| 17052 | 2252 |
| 2253 There are two ways of invocation: locking-shift and single-shift. | |
| 2254 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
|
2255 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
|
2256 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
|
2257 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
|
2258 escape sequences: |
| 17052 | 2259 |
| 2260 ---------------------------------------------------------------------- | |
|
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2261 abbrev function cntrl escape seq description |
| 17052 | 2262 ---------------------------------------------------------------------- |
|
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2263 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
|
2264 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
|
2265 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
|
2266 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
|
2267 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
|
2268 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
|
2269 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
|
2270 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
|
2271 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char |
| 17052 | 2272 ---------------------------------------------------------------------- |
|
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2273 (*) 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
|
2274 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2275 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
|
2276 ISO_CODE_XXX in `coding.h'. |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2277 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2278 Designations are done by the following escape sequences: |
| 17052 | 2279 ---------------------------------------------------------------------- |
| 2280 escape sequence description | |
| 2281 ---------------------------------------------------------------------- | |
| 2282 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0 | |
| 2283 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1 | |
| 2284 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2 | |
| 2285 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3 | |
| 2286 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*) | |
| 2287 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1 | |
| 2288 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2 | |
| 2289 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3 | |
| 2290 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**) | |
| 2291 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1 | |
| 2292 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2 | |
| 2293 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3 | |
| 2294 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*) | |
| 2295 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1 | |
| 2296 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2 | |
| 2297 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3 | |
| 2298 ---------------------------------------------------------------------- | |
| 2299 | |
| 2300 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
|
2301 of dimension 1, chars 94, and final character <F>, etc... |
| 17052 | 2302 |
| 2303 Note (*): Although these designations are not allowed in ISO2022, | |
| 2304 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
|
2305 CHARS96 character sets in a coding system which is characterized as |
| 17052 | 2306 7-bit environment, non-locking-shift, and non-single-shift. |
| 2307 | |
| 2308 Note (**): If <F> is '@', 'A', or 'B', the intermediate character | |
| 88365 | 2309 '(' must be omitted. We refer to this as "short-form" hereafter. |
| 2310 | |
| 88771 | 2311 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
|
2312 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
|
2313 coding systems such as Compound Text (used in X11's inter client |
| 88771 | 2314 communication, ISO-2022-JP (used in Japanese Internet), ISO-2022-KR |
| 2315 (used in Korean Internet), EUC (Extended UNIX Code, used in Asian | |
| 17052 | 2316 localized platforms), and all of these are variants of ISO2022. |
| 2317 | |
| 2318 In addition to the above, Emacs handles two more kinds of escape | |
| 2319 sequences: ISO6429's direction specification and Emacs' private | |
| 2320 sequence for specifying character composition. | |
| 2321 | |
|
24425
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2322 ISO6429's direction specification takes the following form: |
| 17052 | 2323 o CSI ']' -- end of the current direction |
| 2324 o CSI '0' ']' -- end of the current direction | |
| 2325 o CSI '1' ']' -- start of left-to-right text | |
| 2326 o CSI '2' ']' -- start of right-to-left text | |
| 2327 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
|
2328 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
|
2329 |
|
61c6b3be1d51
Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents:
24344
diff
changeset
|
2330 Character composition specification takes the following form: |
| 26847 | 2331 o ESC '0' -- start relative composition |
| 2332 o ESC '1' -- end composition | |
| 2333 o ESC '2' -- start rule-base composition (*) | |
| 2334 o ESC '3' -- start relative composition with alternate chars (**) | |
| 2335 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
|
2336 Since these are not standard escape sequences of any ISO standard, |
| 88771 | 2337 the use of them with these meanings is restricted to Emacs only. |
| 2338 | |
| 2339 (*) This form is used only in Emacs 20.7 and older versions, | |
| 2340 but newer versions can safely decode it. | |
| 2341 (**) This form is used only in Emacs 21.1 and newer versions, | |
| 2342 and older versions can't decode it. | |
| 2343 | |
| 2344 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
|
2345 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
|
2346 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2347 COMPOSITION_RELATIVE: |
| 26847 | 2348 ESC 0 CHAR [ CHAR ] ESC 1 |
| 88771 | 2349 COMPOSITION_WITH_RULE: |
| 26847 | 2350 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
|
2351 COMPOSITION_WITH_ALTCHARS: |
| 26847 | 2352 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
|
2353 COMPOSITION_WITH_RULE_ALTCHARS: |
| 26847 | 2354 ESC 4 ALTCHAR [ RULE ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 */ |
| 17052 | 2355 |
| 2356 enum iso_code_class_type iso_code_class[256]; | |
| 2357 | |
| 88365 | 2358 #define SAFE_CHARSET_P(coding, id) \ |
| 2359 ((id) <= (coding)->max_charset_id \ | |
| 2360 && (coding)->safe_charsets[id] >= 0) | |
| 2361 | |
| 2362 | |
| 2363 #define SHIFT_OUT_OK(category) \ | |
| 2364 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0) | |
| 2365 | |
| 2366 static void | |
|
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
2367 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
|
2368 Lisp_Object attrs; |
| 88365 | 2369 { |
| 2370 Lisp_Object charset_list, safe_charsets; | |
| 2371 Lisp_Object request; | |
| 2372 Lisp_Object reg_usage; | |
| 2373 Lisp_Object tail; | |
| 2374 int reg94, reg96; | |
| 2375 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
| 2376 int max_charset_id; | |
| 2377 | |
| 2378 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
| 2379 if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) | |
| 2380 && ! EQ (charset_list, Viso_2022_charset_list)) | |
| 2381 { | |
| 2382 CODING_ATTR_CHARSET_LIST (attrs) | |
| 2383 = charset_list = Viso_2022_charset_list; | |
| 2384 ASET (attrs, coding_attr_safe_charsets, Qnil); | |
| 2385 } | |
| 2386 | |
| 2387 if (STRINGP (AREF (attrs, coding_attr_safe_charsets))) | |
| 2388 return; | |
| 2389 | |
| 2390 max_charset_id = 0; | |
| 2391 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
| 2392 { | |
| 2393 int id = XINT (XCAR (tail)); | |
| 2394 if (max_charset_id < id) | |
| 2395 max_charset_id = id; | |
| 2396 } | |
| 2397 | |
| 2398 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
| 2399 make_number (255)); | |
| 2400 request = AREF (attrs, coding_attr_iso_request); | |
| 2401 reg_usage = AREF (attrs, coding_attr_iso_usage); | |
| 2402 reg94 = XINT (XCAR (reg_usage)); | |
| 2403 reg96 = XINT (XCDR (reg_usage)); | |
| 2404 | |
| 2405 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
| 2406 { | |
| 2407 Lisp_Object id; | |
| 2408 Lisp_Object reg; | |
| 2409 struct charset *charset; | |
| 2410 | |
| 2411 id = XCAR (tail); | |
| 2412 charset = CHARSET_FROM_ID (XINT (id)); | |
|
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2413 reg = Fcdr (Fassq (id, request)); |
| 88365 | 2414 if (! NILP (reg)) |
| 2415 XSTRING (safe_charsets)->data[XINT (id)] = XINT (reg); | |
| 2416 else if (charset->iso_chars_96) | |
| 2417 { | |
| 2418 if (reg96 < 4) | |
| 2419 XSTRING (safe_charsets)->data[XINT (id)] = reg96; | |
| 2420 } | |
| 2421 else | |
| 2422 { | |
| 2423 if (reg94 < 4) | |
| 2424 XSTRING (safe_charsets)->data[XINT (id)] = reg94; | |
| 2425 } | |
| 2426 } | |
| 2427 ASET (attrs, coding_attr_safe_charsets, safe_charsets); | |
| 2428 } | |
| 2429 | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2430 |
| 17052 | 2431 /* 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
|
2432 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
|
2433 If it is, return 1, else return 0. */ |
| 17052 | 2434 |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
2435 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2436 detect_coding_iso_2022 (coding, detect_info) |
| 88365 | 2437 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2438 struct coding_detection_info *detect_info; |
| 17052 | 2439 { |
| 88365 | 2440 unsigned char *src = coding->source, *src_base = src; |
| 2441 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 2442 int multibytep = coding->src_multibyte; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2443 int single_shifting = 0; |
| 88365 | 2444 int id; |
| 2445 int c, c1; | |
| 2446 int consumed_chars = 0; | |
| 2447 int i; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2448 int rejected = 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2449 int found = 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2450 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2451 detect_info->checked |= CATEGORY_MASK_ISO; |
| 88365 | 2452 |
| 2453 for (i = coding_category_iso_7; i <= coding_category_iso_8_else; i++) | |
| 2454 { | |
| 2455 struct coding_system *this = &(coding_categories[i]); | |
| 2456 Lisp_Object attrs, val; | |
| 2457 | |
| 2458 attrs = CODING_ID_ATTRS (this->id); | |
| 2459 if (CODING_ISO_FLAGS (this) & CODING_ISO_FLAG_FULL_SUPPORT | |
| 2460 && ! EQ (CODING_ATTR_SAFE_CHARSETS (attrs), Viso_2022_charset_list)) | |
| 2461 setup_iso_safe_charsets (attrs); | |
| 2462 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
| 2463 this->max_charset_id = XSTRING (val)->size - 1; | |
| 2464 this->safe_charsets = (char *) XSTRING (val)->data; | |
| 2465 } | |
| 2466 | |
| 2467 /* A coding system of this category is always ASCII compatible. */ | |
| 2468 src += coding->head_ascii; | |
| 2469 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2470 while (rejected != CATEGORY_MASK_ISO) |
| 88365 | 2471 { |
| 2472 ONE_MORE_BYTE (c); | |
| 17052 | 2473 switch (c) |
| 2474 { | |
| 2475 case ISO_CODE_ESC: | |
|
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2476 if (inhibit_iso_escape_detection) |
|
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2477 break; |
|
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2478 single_shifting = 0; |
| 88365 | 2479 ONE_MORE_BYTE (c); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2480 if (c >= '(' && c <= '/') |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2481 { |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2482 /* Designation sequence for a charset of dimension 1. */ |
| 88365 | 2483 ONE_MORE_BYTE (c1); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2484 if (c1 < ' ' || c1 >= 0x80 |
| 88365 | 2485 || (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
|
2486 /* Invalid designation sequence. Just ignore. */ |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2487 break; |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2488 } |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2489 else if (c == '$') |
| 17052 | 2490 { |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2491 /* Designation sequence for a charset of dimension 2. */ |
| 88365 | 2492 ONE_MORE_BYTE (c); |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2493 if (c >= '@' && c <= 'B') |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2494 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2495 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
|
2496 else if (c >= '(' && c <= '/') |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2497 { |
| 88365 | 2498 ONE_MORE_BYTE (c1); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2499 if (c1 < ' ' || c1 >= 0x80 |
| 88365 | 2500 || (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
|
2501 /* Invalid designation sequence. Just ignore. */ |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2502 break; |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2503 } |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2504 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2505 /* Invalid designation sequence. Just ignore it. */ |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2506 break; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2507 } |
|
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2508 else if (c == 'N' || c == 'O') |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2509 { |
|
23116
6736da064f4a
(detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents:
23089
diff
changeset
|
2510 /* ESC <Fe> for SS2 or SS3. */ |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2511 single_shifting = 1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2512 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
|
2513 break; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2514 } |
| 26847 | 2515 else if (c >= '0' && c <= '4') |
| 2516 { | |
| 2517 /* ESC <Fp> for start/end composition. */ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2518 found |= CATEGORY_MASK_ISO; |
| 26847 | 2519 break; |
| 2520 } | |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
2521 else |
| 88365 | 2522 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2523 /* Invalid escape sequence. Just ignore it. */ |
| 88365 | 2524 break; |
| 2525 } | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2526 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2527 /* 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
|
2528 rejected |= CATEGORY_MASK_ISO_8BIT; |
| 88365 | 2529 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7], |
| 2530 id)) | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2531 found |= CATEGORY_MASK_ISO_7; |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2532 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2533 rejected |= CATEGORY_MASK_ISO_7; |
| 88365 | 2534 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_tight], |
| 2535 id)) | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2536 found |= CATEGORY_MASK_ISO_7_TIGHT; |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2537 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2538 rejected |= CATEGORY_MASK_ISO_7_TIGHT; |
| 88365 | 2539 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7_else], |
| 2540 id)) | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2541 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
|
2542 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2543 rejected |= CATEGORY_MASK_ISO_7_ELSE; |
| 88365 | 2544 if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_8_else], |
| 2545 id)) | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2546 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
|
2547 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2548 rejected |= CATEGORY_MASK_ISO_8_ELSE; |
| 17052 | 2549 break; |
| 2550 | |
| 2551 case ISO_CODE_SO: | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2552 case ISO_CODE_SI: |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2553 /* Locking shift out/in. */ |
|
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2554 if (inhibit_iso_escape_detection) |
|
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
2555 break; |
|
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2556 single_shifting = 0; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2557 rejected |= CATEGORY_MASK_ISO_7BIT | CATEGORY_MASK_ISO_8BIT; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2558 found |= CATEGORY_MASK_ISO_ELSE; |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2559 break; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2560 |
| 17052 | 2561 case ISO_CODE_CSI: |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2562 /* Control sequence introducer. */ |
|
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2563 single_shifting = 0; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2564 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
|
2565 found |= CATEGORY_MASK_ISO_8_ELSE; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2566 goto check_extra_latin; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2567 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2568 |
| 17052 | 2569 case ISO_CODE_SS2: |
| 2570 case ISO_CODE_SS3: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2571 /* Single shift. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2572 if (inhibit_iso_escape_detection) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2573 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2574 single_shifting = 1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2575 rejected |= CATEGORY_MASK_ISO_7BIT; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2576 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
|
2577 & CODING_ISO_FLAG_SINGLE_SHIFT) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2578 found |= CATEGORY_MASK_ISO_8_1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2579 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
|
2580 & CODING_ISO_FLAG_SINGLE_SHIFT) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2581 found |= CATEGORY_MASK_ISO_8_2; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2582 goto check_extra_latin; |
| 17052 | 2583 |
| 2584 default: | |
| 2585 if (c < 0x80) | |
|
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2586 { |
|
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2587 single_shifting = 0; |
|
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2588 break; |
|
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2589 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2590 if (c >= 0xA0) |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
2591 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2592 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
|
2593 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
|
2594 /* 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
|
2595 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
|
2596 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
|
2597 only when we are not single shifting. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2598 if (! single_shifting |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2599 && ! (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
|
2600 { |
|
29299
b33b38d81020
(detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents:
29275
diff
changeset
|
2601 int i = 1; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2602 while (src < src_end) |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2603 { |
| 88365 | 2604 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
|
2605 if (c < 0xA0) |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2606 break; |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2607 i++; |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2608 } |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2609 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2610 if (i & 1 && src < src_end) |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2611 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
|
2612 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2613 found |= CATEGORY_MASK_ISO_8_2; |
|
23088
45c36d636f66
(detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents:
23082
diff
changeset
|
2614 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2615 break; |
| 17052 | 2616 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2617 check_extra_latin: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2618 single_shifting = 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2619 if (! VECTORP (Vlatin_extra_code_table) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2620 || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2621 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2622 rejected = CATEGORY_MASK_ISO; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2623 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2624 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2625 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
|
2626 & CODING_ISO_FLAG_LATIN_EXTRA) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2627 found |= CATEGORY_MASK_ISO_8_1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2628 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2629 rejected |= CATEGORY_MASK_ISO_8_1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2630 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
|
2631 & CODING_ISO_FLAG_LATIN_EXTRA) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2632 found |= CATEGORY_MASK_ISO_8_2; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2633 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2634 rejected |= CATEGORY_MASK_ISO_8_2; |
| 17052 | 2635 } |
| 2636 } | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2637 detect_info->rejected |= CATEGORY_MASK_ISO; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2638 return 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2639 |
| 88365 | 2640 no_more_source: |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2641 detect_info->rejected |= rejected; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2642 detect_info->found |= (found & ~rejected); |
| 88365 | 2643 return 1; |
| 17052 | 2644 } |
| 2645 | |
| 2646 | |
| 2647 /* Set designation state into CODING. */ | |
| 88365 | 2648 #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
| 2649 do { \ | |
| 2650 int id, prev; \ | |
| 2651 \ | |
| 2652 if (final < '0' || final >= 128 \ | |
| 2653 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ | |
| 2654 || !SAFE_CHARSET_P (coding, id)) \ | |
| 2655 { \ | |
| 2656 CODING_ISO_DESIGNATION (coding, reg) = -2; \ | |
| 2657 goto invalid_code; \ | |
| 2658 } \ | |
| 2659 prev = CODING_ISO_DESIGNATION (coding, reg); \ | |
|
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2660 if (id == charset_jisx0201_roman) \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2661 { \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2662 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
|
2663 id = charset_ascii; \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2664 } \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2665 else if (id == charset_jisx0208_1978) \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2666 { \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2667 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
|
2668 id = charset_jisx0208; \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
2669 } \ |
| 88365 | 2670 CODING_ISO_DESIGNATION (coding, reg) = id; \ |
| 2671 /* If there was an invalid designation to REG previously, and this \ | |
| 2672 designation is ASCII to REG, we should keep this designation \ | |
| 2673 sequence. */ \ | |
| 2674 if (prev == -2 && id == charset_ascii) \ | |
| 2675 goto invalid_code; \ | |
| 17052 | 2676 } while (0) |
| 2677 | |
| 88365 | 2678 |
| 2679 #define MAYBE_FINISH_COMPOSITION() \ | |
| 2680 do { \ | |
| 2681 int i; \ | |
| 2682 if (composition_state == COMPOSING_NO) \ | |
| 2683 break; \ | |
| 2684 /* It is assured that we have enough room for producing \ | |
| 2685 characters stored in the table `components'. */ \ | |
| 2686 if (charbuf + component_idx > charbuf_end) \ | |
| 2687 goto no_more_source; \ | |
| 2688 composition_state = COMPOSING_NO; \ | |
| 2689 if (method == COMPOSITION_RELATIVE \ | |
| 2690 || method == COMPOSITION_WITH_ALTCHARS) \ | |
| 2691 { \ | |
| 2692 for (i = 0; i < component_idx; i++) \ | |
| 2693 *charbuf++ = components[i]; \ | |
| 2694 char_offset += component_idx; \ | |
| 2695 } \ | |
| 2696 else \ | |
| 2697 { \ | |
| 2698 for (i = 0; i < component_idx; i += 2) \ | |
| 2699 *charbuf++ = components[i]; \ | |
| 2700 char_offset += (component_idx / 2) + 1; \ | |
| 2701 } \ | |
| 2702 } while (0) | |
| 2703 | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
2704 |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2705 /* Handle composition start sequence ESC 0, ESC 2, ESC 3, or ESC 4. |
|
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2706 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
|
2707 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1 |
| 88365 | 2708 ESC 3 : altchar composition : ESC 3 CHAR ... ESC 0 CHAR ... ESC 1 |
| 2709 ESC 4 : alt&rule composition : ESC 4 CHAR RULE ... CHAR ESC 0 CHAR ... ESC 1 | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
2710 */ |
| 26847 | 2711 |
| 88365 | 2712 #define DECODE_COMPOSITION_START(c1) \ |
| 26847 | 2713 do { \ |
| 88365 | 2714 if (c1 == '0' \ |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2715 && composition_state == COMPOSING_COMPONENT_RULE) \ |
| 26847 | 2716 { \ |
| 88365 | 2717 component_len = component_idx; \ |
| 2718 composition_state = COMPOSING_CHAR; \ | |
| 26847 | 2719 } \ |
| 2720 else \ | |
| 2721 { \ | |
| 88365 | 2722 unsigned char *p; \ |
| 2723 \ | |
| 2724 MAYBE_FINISH_COMPOSITION (); \ | |
| 2725 if (charbuf + MAX_COMPOSITION_COMPONENTS > charbuf_end) \ | |
| 2726 goto no_more_source; \ | |
| 2727 for (p = src; p < src_end - 1; p++) \ | |
| 2728 if (*p == ISO_CODE_ESC && p[1] == '1') \ | |
| 2729 break; \ | |
| 2730 if (p == src_end - 1) \ | |
| 2731 { \ | |
| 2732 if (coding->mode & CODING_MODE_LAST_BLOCK) \ | |
| 2733 goto invalid_code; \ | |
| 2734 goto no_more_source; \ | |
| 2735 } \ | |
| 2736 \ | |
| 2737 /* This is surely the start of a composition. */ \ | |
| 2738 method = (c1 == '0' ? COMPOSITION_RELATIVE \ | |
| 2739 : c1 == '2' ? COMPOSITION_WITH_RULE \ | |
| 2740 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \ | |
| 2741 : COMPOSITION_WITH_RULE_ALTCHARS); \ | |
| 2742 composition_state = (c1 <= '2' ? COMPOSING_CHAR \ | |
| 2743 : COMPOSING_COMPONENT_CHAR); \ | |
| 2744 component_idx = component_len = 0; \ | |
| 26847 | 2745 } \ |
| 2746 } while (0) | |
| 2747 | |
| 88365 | 2748 |
| 2749 /* Handle compositoin end sequence ESC 1. */ | |
| 2750 | |
| 2751 #define DECODE_COMPOSITION_END() \ | |
| 2752 do { \ | |
| 2753 int nchars = (component_len > 0 ? component_idx - component_len \ | |
| 2754 : method == COMPOSITION_RELATIVE ? component_idx \ | |
| 2755 : (component_idx + 1) / 2); \ | |
| 2756 int i; \ | |
| 2757 int *saved_charbuf = charbuf; \ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2758 int from = coding->produced_char + char_offset; \ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2759 int to = from + nchars; \ |
| 88365 | 2760 \ |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2761 ADD_COMPOSITION_DATA (charbuf, from, to, method); \ |
| 88365 | 2762 if (method != COMPOSITION_RELATIVE) \ |
| 2763 { \ | |
| 2764 if (component_len == 0) \ | |
| 2765 for (i = 0; i < component_idx; i++) \ | |
| 2766 *charbuf++ = components[i]; \ | |
| 2767 else \ | |
| 2768 for (i = 0; i < component_len; i++) \ | |
| 2769 *charbuf++ = components[i]; \ | |
| 2770 *saved_charbuf = saved_charbuf - charbuf; \ | |
| 2771 } \ | |
| 2772 if (method == COMPOSITION_WITH_RULE) \ | |
| 2773 for (i = 0; i < component_idx; i += 2, char_offset++) \ | |
| 2774 *charbuf++ = components[i]; \ | |
| 2775 else \ | |
| 2776 for (i = component_len; i < component_idx; i++, char_offset++) \ | |
| 2777 *charbuf++ = components[i]; \ | |
| 2778 coding->annotated = 1; \ | |
| 2779 composition_state = COMPOSING_NO; \ | |
| 2780 } while (0) | |
| 2781 | |
| 2782 | |
| 26847 | 2783 /* Decode a composition rule from the byte C1 (and maybe one more byte |
| 2784 from SRC) and store one encoded composition rule in | |
| 2785 coding->cmp_data. */ | |
| 2786 | |
| 2787 #define DECODE_COMPOSITION_RULE(c1) \ | |
| 2788 do { \ | |
| 2789 (c1) -= 32; \ | |
| 2790 if (c1 < 81) /* old format (before ver.21) */ \ | |
| 2791 { \ | |
| 2792 int gref = (c1) / 9; \ | |
| 2793 int nref = (c1) % 9; \ | |
| 2794 if (gref == 4) gref = 10; \ | |
| 2795 if (nref == 4) nref = 10; \ | |
| 88365 | 2796 c1 = COMPOSITION_ENCODE_RULE (gref, nref); \ |
| 26847 | 2797 } \ |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2798 else if (c1 < 93) /* new format (after ver.21) */ \ |
| 26847 | 2799 { \ |
| 2800 ONE_MORE_BYTE (c2); \ | |
| 88365 | 2801 c1 = COMPOSITION_ENCODE_RULE (c1 - 81, c2 - 32); \ |
| 26847 | 2802 } \ |
| 88365 | 2803 else \ |
| 2804 c1 = 0; \ | |
| 26847 | 2805 } while (0) |
| 2806 | |
| 2807 | |
| 17052 | 2808 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ |
| 2809 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2810 static void |
| 88365 | 2811 decode_coding_iso_2022 (coding) |
| 17052 | 2812 struct coding_system *coding; |
| 2813 { | |
| 88365 | 2814 unsigned char *src = coding->source + coding->consumed; |
| 2815 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 2816 unsigned char *src_base; | |
| 2817 int *charbuf = coding->charbuf; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2818 int *charbuf_end |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2819 = charbuf + coding->charbuf_size - 4 - MAX_ANNOTATION_LENGTH; |
| 88365 | 2820 int consumed_chars = 0, consumed_chars_base; |
| 2821 int multibytep = coding->src_multibyte; | |
| 17052 | 2822 /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
| 88365 | 2823 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
| 2824 int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
| 2825 struct charset *charset; | |
| 2826 int c; | |
| 2827 /* For handling composition sequence. */ | |
| 2828 #define COMPOSING_NO 0 | |
| 2829 #define COMPOSING_CHAR 1 | |
| 2830 #define COMPOSING_RULE 2 | |
| 2831 #define COMPOSING_COMPONENT_CHAR 3 | |
| 2832 #define COMPOSING_COMPONENT_RULE 4 | |
| 2833 | |
| 2834 int composition_state = COMPOSING_NO; | |
| 2835 enum composition_method method; | |
| 2836 int components[MAX_COMPOSITION_COMPONENTS * 2 + 1]; | |
| 2837 int component_idx; | |
| 2838 int component_len; | |
| 2839 Lisp_Object attrs, eol_type, charset_list; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2840 int char_offset = coding->produced_char; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2841 int last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
2842 int last_id = charset_ascii; |
| 88365 | 2843 |
| 2844 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 2845 setup_iso_safe_charsets (attrs); | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2846 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2847 while (1) |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2848 { |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2849 int c1, c2; |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2850 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2851 src_base = src; |
| 88365 | 2852 consumed_chars_base = consumed_chars; |
| 2853 | |
| 2854 if (charbuf >= charbuf_end) | |
| 2855 break; | |
| 2856 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2857 ONE_MORE_BYTE (c1); |
| 17052 | 2858 |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2859 /* We produce at most one character. */ |
| 17052 | 2860 switch (iso_code_class [c1]) |
| 2861 { | |
| 2862 case ISO_0x20_or_0x7F: | |
| 88365 | 2863 if (composition_state != COMPOSING_NO) |
| 26847 | 2864 { |
| 88365 | 2865 if (composition_state == COMPOSING_RULE |
| 2866 || composition_state == COMPOSING_COMPONENT_RULE) | |
| 2867 { | |
| 2868 DECODE_COMPOSITION_RULE (c1); | |
| 2869 components[component_idx++] = c1; | |
| 2870 composition_state--; | |
| 2871 continue; | |
| 2872 } | |
| 26847 | 2873 } |
| 88365 | 2874 if (charset_id_0 < 0 |
| 2875 || ! 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
|
2876 /* This is SPACE or DEL. */ |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2877 charset = CHARSET_FROM_ID (charset_ascii); |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2878 else |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2879 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
|
2880 break; |
| 17052 | 2881 |
| 2882 case ISO_graphic_plane_0: | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2883 if (composition_state != COMPOSING_NO) |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2884 { |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2885 if (composition_state == COMPOSING_RULE |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2886 || composition_state == COMPOSING_COMPONENT_RULE) |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2887 { |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2888 DECODE_COMPOSITION_RULE (c1); |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2889 components[component_idx++] = c1; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2890 composition_state--; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2891 continue; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
2892 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2893 } |
| 88365 | 2894 charset = CHARSET_FROM_ID (charset_id_0); |
| 17052 | 2895 break; |
| 2896 | |
| 2897 case ISO_0xA0_or_0xFF: | |
| 88365 | 2898 if (charset_id_1 < 0 |
| 2899 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) | |
| 2900 || CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) | |
| 2901 goto invalid_code; | |
| 17052 | 2902 /* This is a graphic character, we fall down ... */ |
| 2903 | |
| 2904 case ISO_graphic_plane_1: | |
| 88365 | 2905 if (charset_id_1 < 0) |
| 2906 goto invalid_code; | |
| 2907 charset = CHARSET_FROM_ID (charset_id_1); | |
| 17052 | 2908 break; |
| 2909 | |
| 88365 | 2910 case ISO_carriage_return: |
| 2911 if (c1 == '\r') | |
| 2912 { | |
| 2913 if (EQ (eol_type, Qdos)) | |
| 2914 { | |
| 2915 if (src == src_end) | |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2916 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2917 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2918 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
2919 } |
| 88365 | 2920 if (*src == '\n') |
| 2921 ONE_MORE_BYTE (c1); | |
| 2922 } | |
| 2923 else if (EQ (eol_type, Qmac)) | |
| 2924 c1 = '\n'; | |
| 2925 } | |
| 2926 /* fall through */ | |
| 2927 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2928 case ISO_control_0: |
| 88365 | 2929 MAYBE_FINISH_COMPOSITION (); |
| 2930 charset = CHARSET_FROM_ID (charset_ascii); | |
| 17052 | 2931 break; |
| 2932 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2933 case ISO_control_1: |
| 88365 | 2934 MAYBE_FINISH_COMPOSITION (); |
| 2935 goto invalid_code; | |
| 17052 | 2936 |
| 2937 case ISO_shift_out: | |
| 88365 | 2938 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
| 2939 || CODING_ISO_DESIGNATION (coding, 1) < 0) | |
| 2940 goto invalid_code; | |
| 2941 CODING_ISO_INVOCATION (coding, 0) = 1; | |
| 2942 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
2943 continue; |
| 17052 | 2944 |
| 2945 case ISO_shift_in: | |
| 88365 | 2946 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)) |
| 2947 goto invalid_code; | |
| 2948 CODING_ISO_INVOCATION (coding, 0) = 0; | |
| 2949 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
|
2950 continue; |
| 17052 | 2951 |
| 2952 case ISO_single_shift_2_7: | |
| 2953 case ISO_single_shift_2: | |
| 88365 | 2954 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
| 2955 goto invalid_code; | |
| 17052 | 2956 /* SS2 is handled as an escape sequence of ESC 'N' */ |
| 2957 c1 = 'N'; | |
| 2958 goto label_escape_sequence; | |
| 2959 | |
| 2960 case ISO_single_shift_3: | |
| 88365 | 2961 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT)) |
| 2962 goto invalid_code; | |
| 17052 | 2963 /* SS2 is handled as an escape sequence of ESC 'O' */ |
| 2964 c1 = 'O'; | |
| 2965 goto label_escape_sequence; | |
| 2966 | |
| 2967 case ISO_control_sequence_introducer: | |
| 2968 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
| 2969 c1 = '['; | |
| 2970 goto label_escape_sequence; | |
| 2971 | |
| 2972 case ISO_escape: | |
| 2973 ONE_MORE_BYTE (c1); | |
| 2974 label_escape_sequence: | |
| 88365 | 2975 /* Escape sequences handled here are invocation, |
| 17052 | 2976 designation, direction specification, and character |
| 2977 composition specification. */ | |
| 2978 switch (c1) | |
| 2979 { | |
| 2980 case '&': /* revision of following character set */ | |
| 2981 ONE_MORE_BYTE (c1); | |
| 2982 if (!(c1 >= '@' && c1 <= '~')) | |
| 88365 | 2983 goto invalid_code; |
| 17052 | 2984 ONE_MORE_BYTE (c1); |
| 2985 if (c1 != ISO_CODE_ESC) | |
| 88365 | 2986 goto invalid_code; |
| 17052 | 2987 ONE_MORE_BYTE (c1); |
| 2988 goto label_escape_sequence; | |
| 2989 | |
| 2990 case '$': /* designation of 2-byte character set */ | |
| 88365 | 2991 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
| 2992 goto invalid_code; | |
| 17052 | 2993 ONE_MORE_BYTE (c1); |
| 2994 if (c1 >= '@' && c1 <= 'B') | |
| 2995 { /* 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
|
2996 or JISX0208.1980 */ |
| 88365 | 2997 DECODE_DESIGNATION (0, 2, 0, c1); |
| 17052 | 2998 } |
| 2999 else if (c1 >= 0x28 && c1 <= 0x2B) | |
| 3000 { /* designation of DIMENSION2_CHARS94 character set */ | |
| 3001 ONE_MORE_BYTE (c2); | |
| 88365 | 3002 DECODE_DESIGNATION (c1 - 0x28, 2, 0, c2); |
| 17052 | 3003 } |
| 3004 else if (c1 >= 0x2C && c1 <= 0x2F) | |
| 3005 { /* designation of DIMENSION2_CHARS96 character set */ | |
| 3006 ONE_MORE_BYTE (c2); | |
| 88365 | 3007 DECODE_DESIGNATION (c1 - 0x2C, 2, 1, c2); |
| 17052 | 3008 } |
| 3009 else | |
| 88365 | 3010 goto invalid_code; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3011 /* We must update these variables now. */ |
| 88365 | 3012 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
| 3013 charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3014 continue; |
| 17052 | 3015 |
| 3016 case 'n': /* invocation of locking-shift-2 */ | |
| 88365 | 3017 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
| 3018 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
| 3019 goto invalid_code; | |
| 3020 CODING_ISO_INVOCATION (coding, 0) = 2; | |
| 3021 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
|
3022 continue; |
| 17052 | 3023 |
| 3024 case 'o': /* invocation of locking-shift-3 */ | |
| 88365 | 3025 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) |
| 3026 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
| 3027 goto invalid_code; | |
| 3028 CODING_ISO_INVOCATION (coding, 0) = 3; | |
| 3029 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
|
3030 continue; |
| 17052 | 3031 |
| 3032 case 'N': /* invocation of single-shift-2 */ | |
| 88365 | 3033 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
| 3034 || CODING_ISO_DESIGNATION (coding, 2) < 0) | |
| 3035 goto invalid_code; | |
| 3036 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 2)); | |
| 17052 | 3037 ONE_MORE_BYTE (c1); |
|
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
3038 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
| 88365 | 3039 goto invalid_code; |
| 17052 | 3040 break; |
| 3041 | |
| 3042 case 'O': /* invocation of single-shift-3 */ | |
| 88365 | 3043 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
| 3044 || CODING_ISO_DESIGNATION (coding, 3) < 0) | |
| 3045 goto invalid_code; | |
| 3046 charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 3)); | |
| 17052 | 3047 ONE_MORE_BYTE (c1); |
|
30578
705b94e152b1
(decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents:
30487
diff
changeset
|
3048 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
| 88365 | 3049 goto invalid_code; |
| 17052 | 3050 break; |
| 3051 | |
| 26847 | 3052 case '0': case '2': case '3': case '4': /* start composition */ |
| 88365 | 3053 if (! (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK)) |
| 3054 goto invalid_code; | |
| 26847 | 3055 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
|
3056 continue; |
| 17052 | 3057 |
| 26847 | 3058 case '1': /* end composition */ |
| 88365 | 3059 if (composition_state == COMPOSING_NO) |
| 3060 goto invalid_code; | |
| 3061 DECODE_COMPOSITION_END (); | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3062 continue; |
| 17052 | 3063 |
| 3064 case '[': /* specification of direction */ | |
| 88365 | 3065 if (! CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DIRECTION) |
| 3066 goto invalid_code; | |
| 17052 | 3067 /* 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
|
3068 So, `coding->mode & CODING_MODE_DIRECTION' zero means |
| 88365 | 3069 left-to-right, and nozero means right-to-left. */ |
| 17052 | 3070 ONE_MORE_BYTE (c1); |
| 3071 switch (c1) | |
| 3072 { | |
| 3073 case ']': /* end of the current direction */ | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3074 coding->mode &= ~CODING_MODE_DIRECTION; |
| 17052 | 3075 |
| 3076 case '0': /* end of the current direction */ | |
| 3077 case '1': /* start of left-to-right direction */ | |
| 3078 ONE_MORE_BYTE (c1); | |
| 3079 if (c1 == ']') | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3080 coding->mode &= ~CODING_MODE_DIRECTION; |
| 17052 | 3081 else |
| 88365 | 3082 goto invalid_code; |
| 17052 | 3083 break; |
| 3084 | |
| 3085 case '2': /* start of right-to-left direction */ | |
| 3086 ONE_MORE_BYTE (c1); | |
| 3087 if (c1 == ']') | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3088 coding->mode |= CODING_MODE_DIRECTION; |
| 17052 | 3089 else |
| 88365 | 3090 goto invalid_code; |
| 17052 | 3091 break; |
| 3092 | |
| 3093 default: | |
| 88365 | 3094 goto invalid_code; |
| 17052 | 3095 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3096 continue; |
| 17052 | 3097 |
| 3098 default: | |
| 88365 | 3099 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
| 3100 goto invalid_code; | |
| 17052 | 3101 if (c1 >= 0x28 && c1 <= 0x2B) |
| 3102 { /* designation of DIMENSION1_CHARS94 character set */ | |
| 3103 ONE_MORE_BYTE (c2); | |
| 88365 | 3104 DECODE_DESIGNATION (c1 - 0x28, 1, 0, c2); |
| 17052 | 3105 } |
| 3106 else if (c1 >= 0x2C && c1 <= 0x2F) | |
| 3107 { /* designation of DIMENSION1_CHARS96 character set */ | |
| 3108 ONE_MORE_BYTE (c2); | |
| 88365 | 3109 DECODE_DESIGNATION (c1 - 0x2C, 1, 1, c2); |
| 17052 | 3110 } |
| 3111 else | |
| 88365 | 3112 goto invalid_code; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3113 /* We must update these variables now. */ |
| 88365 | 3114 charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
| 3115 charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3116 continue; |
| 17052 | 3117 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3118 } |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3119 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3120 if (charset->id != charset_ascii |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3121 && last_id != charset->id) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3122 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3123 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3124 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3125 last_id = charset->id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3126 last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3127 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3128 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3129 /* Now we know CHARSET and 1st position code C1 of a character. |
| 88365 | 3130 Produce a decoded character while getting 2nd position code |
| 3131 C2 if necessary. */ | |
| 3132 c1 &= 0x7F; | |
| 3133 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
|
3134 { |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3135 ONE_MORE_BYTE (c2); |
| 88365 | 3136 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3137 /* C2 is not in a valid range. */ |
| 88365 | 3138 goto invalid_code; |
| 3139 c1 = (c1 << 8) | (c2 & 0x7F); | |
| 3140 if (CHARSET_DIMENSION (charset) > 2) | |
| 3141 { | |
| 3142 ONE_MORE_BYTE (c2); | |
| 3143 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) | |
| 3144 /* C2 is not in a valid range. */ | |
| 3145 goto invalid_code; | |
| 3146 c1 = (c1 << 8) | (c2 & 0x7F); | |
| 3147 } | |
| 17052 | 3148 } |
| 88365 | 3149 |
| 3150 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); | |
| 3151 if (c < 0) | |
| 3152 { | |
| 3153 MAYBE_FINISH_COMPOSITION (); | |
| 3154 for (; src_base < src; src_base++, char_offset++) | |
| 3155 { | |
| 3156 if (ASCII_BYTE_P (*src_base)) | |
| 3157 *charbuf++ = *src_base; | |
| 3158 else | |
| 3159 *charbuf++ = BYTE8_TO_CHAR (*src_base); | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3160 char_offset++; |
| 88365 | 3161 } |
| 3162 } | |
| 3163 else if (composition_state == COMPOSING_NO) | |
| 3164 { | |
| 3165 *charbuf++ = c; | |
| 3166 char_offset++; | |
| 3167 } | |
| 3168 else | |
|
88585
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3169 { |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3170 components[component_idx++] = c; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3171 if (method == COMPOSITION_WITH_RULE |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3172 || (method == COMPOSITION_WITH_RULE_ALTCHARS |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3173 && composition_state == COMPOSING_COMPONENT_CHAR)) |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3174 composition_state++; |
|
c7772f702227
(ONE_MORE_BYTE_NO_CHECK): Increment consumed_chars.
Kenichi Handa <handa@m17n.org>
parents:
88573
diff
changeset
|
3175 } |
| 17052 | 3176 continue; |
| 3177 | |
| 88365 | 3178 invalid_code: |
| 3179 MAYBE_FINISH_COMPOSITION (); | |
| 3180 src = src_base; | |
| 3181 consumed_chars = consumed_chars_base; | |
| 3182 ONE_MORE_BYTE (c); | |
| 3183 *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
|
3184 char_offset++; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3185 coding->errors++; |
| 88365 | 3186 } |
| 3187 | |
| 3188 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3189 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3190 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
| 88365 | 3191 coding->consumed_char += consumed_chars_base; |
| 3192 coding->consumed = src_base - coding->source; | |
| 3193 coding->charbuf_used = charbuf - coding->charbuf; | |
| 17052 | 3194 } |
| 3195 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3196 |
| 18766 | 3197 /* ISO2022 encoding stuff. */ |
| 17052 | 3198 |
| 3199 /* | |
| 18766 | 3200 It is not enough to say just "ISO2022" on encoding, we have to |
| 88365 | 3201 specify more details. In Emacs, each coding system of ISO2022 |
| 17052 | 3202 variant has the following specifications: |
| 88365 | 3203 1. Initial designation to G0 thru G3. |
| 17052 | 3204 2. Allows short-form designation? |
| 3205 3. ASCII should be designated to G0 before control characters? | |
| 3206 4. ASCII should be designated to G0 at end of line? | |
| 3207 5. 7-bit environment or 8-bit environment? | |
| 3208 6. Use locking-shift? | |
| 3209 7. Use Single-shift? | |
| 3210 And the following two are only for Japanese: | |
| 3211 8. Use ASCII in place of JIS0201-1976-Roman? | |
| 3212 9. Use JISX0208-1983 in place of JISX0208-1978? | |
| 88365 | 3213 These specifications are encoded in CODING_ISO_FLAGS (coding) as flag bits |
| 3214 defined by macros CODING_ISO_FLAG_XXX. See `coding.h' for more | |
| 18766 | 3215 details. |
| 17052 | 3216 */ |
| 3217 | |
| 3218 /* 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
|
3219 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
|
3220 '@', '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
|
3221 designation sequence of short-form. */ |
| 17052 | 3222 |
| 3223 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
| 3224 do { \ | |
| 88365 | 3225 unsigned char final_char = CHARSET_ISO_FINAL (charset); \ |
| 17052 | 3226 char *intermediate_char_94 = "()*+"; \ |
| 3227 char *intermediate_char_96 = ",-./"; \ | |
| 88365 | 3228 int revision = -1; \ |
| 3229 int c; \ | |
| 3230 \ | |
| 3231 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ | |
| 88856 | 3232 revision = CHARSET_ISO_REVISION (charset); \ |
| 88365 | 3233 \ |
| 3234 if (revision >= 0) \ | |
|
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
3235 { \ |
| 88365 | 3236 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '&'); \ |
| 3237 EMIT_ONE_BYTE ('@' + revision); \ | |
| 17052 | 3238 } \ |
| 88365 | 3239 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ |
| 17052 | 3240 if (CHARSET_DIMENSION (charset) == 1) \ |
| 3241 { \ | |
| 88365 | 3242 if (! CHARSET_ISO_CHARS_96 (charset)) \ |
| 3243 c = intermediate_char_94[reg]; \ | |
| 17052 | 3244 else \ |
| 88365 | 3245 c = intermediate_char_96[reg]; \ |
| 3246 EMIT_ONE_ASCII_BYTE (c); \ | |
| 17052 | 3247 } \ |
| 3248 else \ | |
| 3249 { \ | |
| 88365 | 3250 EMIT_ONE_ASCII_BYTE ('$'); \ |
| 3251 if (! CHARSET_ISO_CHARS_96 (charset)) \ | |
| 17052 | 3252 { \ |
| 88365 | 3253 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
|
3254 || reg != 0 \ |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3255 || final_char < '@' || final_char > 'B') \ |
| 88365 | 3256 EMIT_ONE_ASCII_BYTE (intermediate_char_94[reg]); \ |
| 17052 | 3257 } \ |
| 3258 else \ | |
| 88365 | 3259 EMIT_ONE_ASCII_BYTE (intermediate_char_96[reg]); \ |
| 17052 | 3260 } \ |
| 88365 | 3261 EMIT_ONE_ASCII_BYTE (final_char); \ |
| 3262 \ | |
| 3263 CODING_ISO_DESIGNATION (coding, reg) = CHARSET_ID (charset); \ | |
| 17052 | 3264 } while (0) |
| 3265 | |
| 88365 | 3266 |
| 17052 | 3267 /* The following two macros produce codes (control character or escape |
| 3268 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
| 3269 single-shift-3). */ | |
| 3270 | |
| 88365 | 3271 #define ENCODE_SINGLE_SHIFT_2 \ |
| 3272 do { \ | |
| 3273 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
| 3274 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'N'); \ | |
| 3275 else \ | |
| 3276 EMIT_ONE_BYTE (ISO_CODE_SS2); \ | |
| 3277 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
| 17052 | 3278 } while (0) |
| 3279 | |
| 88365 | 3280 |
| 3281 #define ENCODE_SINGLE_SHIFT_3 \ | |
| 3282 do { \ | |
| 3283 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
| 3284 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'O'); \ | |
| 3285 else \ | |
| 3286 EMIT_ONE_BYTE (ISO_CODE_SS3); \ | |
| 3287 CODING_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
| 17052 | 3288 } while (0) |
| 3289 | |
| 88365 | 3290 |
| 17052 | 3291 /* The following four macros produce codes (control character or |
| 3292 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
| 3293 shift-out, locking-shift-2, and locking-shift-3). */ | |
| 3294 | |
| 88365 | 3295 #define ENCODE_SHIFT_IN \ |
| 3296 do { \ | |
| 3297 EMIT_ONE_ASCII_BYTE (ISO_CODE_SI); \ | |
| 3298 CODING_ISO_INVOCATION (coding, 0) = 0; \ | |
| 17052 | 3299 } while (0) |
| 3300 | |
| 88365 | 3301 |
| 3302 #define ENCODE_SHIFT_OUT \ | |
| 3303 do { \ | |
| 3304 EMIT_ONE_ASCII_BYTE (ISO_CODE_SO); \ | |
| 3305 CODING_ISO_INVOCATION (coding, 0) = 1; \ | |
| 17052 | 3306 } while (0) |
| 3307 | |
| 88365 | 3308 |
| 3309 #define ENCODE_LOCKING_SHIFT_2 \ | |
| 3310 do { \ | |
| 3311 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
| 3312 CODING_ISO_INVOCATION (coding, 0) = 2; \ | |
| 17052 | 3313 } while (0) |
| 3314 | |
| 88365 | 3315 |
| 3316 #define ENCODE_LOCKING_SHIFT_3 \ | |
| 3317 do { \ | |
| 3318 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, 'n'); \ | |
| 3319 CODING_ISO_INVOCATION (coding, 0) = 3; \ | |
| 17052 | 3320 } while (0) |
| 3321 | |
| 88365 | 3322 |
| 18766 | 3323 /* Produce codes for a DIMENSION1 character whose character set is |
| 3324 CHARSET and whose position-code is C1. Designation and invocation | |
| 17052 | 3325 sequences are also produced in advance if necessary. */ |
| 3326 | |
|
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3327 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
|
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3328 do { \ |
| 88365 | 3329 int id = CHARSET_ID (charset); \ |
|
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3330 \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3331 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
|
3332 && id == charset_ascii) \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3333 { \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3334 id = charset_jisx0201_roman; \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3335 charset = CHARSET_FROM_ID (id); \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3336 } \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3337 \ |
| 88365 | 3338 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
|
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3339 { \ |
| 88365 | 3340 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ |
| 3341 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ | |
|
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3342 else \ |
| 88365 | 3343 EMIT_ONE_BYTE (c1 | 0x80); \ |
| 3344 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
|
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3345 break; \ |
|
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3346 } \ |
| 88365 | 3347 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
|
3348 { \ |
| 88365 | 3349 EMIT_ONE_ASCII_BYTE (c1 & 0x7F); \ |
|
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3350 break; \ |
|
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3351 } \ |
| 88365 | 3352 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
|
3353 { \ |
| 88365 | 3354 EMIT_ONE_BYTE (c1 | 0x80); \ |
|
19285
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3355 break; \ |
|
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3356 } \ |
|
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3357 else \ |
|
af3d00fde172
(Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents:
19280
diff
changeset
|
3358 /* 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
|
3359 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
|
3360 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
|
3361 character. */ \ |
| 88365 | 3362 dst = encode_invocation_designation (charset, coding, dst, \ |
| 3363 &produced_chars); \ | |
| 17052 | 3364 } while (1) |
| 3365 | |
| 88365 | 3366 |
| 3367 /* Produce codes for a DIMENSION2 character whose character set is | |
| 3368 CHARSET and whose position-codes are C1 and C2. Designation and | |
| 3369 invocation codes are also produced in advance if necessary. */ | |
| 3370 | |
| 3371 #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
|
3372 do { \ |
| 88365 | 3373 int id = CHARSET_ID (charset); \ |
|
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3374 \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3375 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
|
3376 && id == charset_jisx0208) \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3377 { \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3378 id = charset_jisx0208_1978; \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3379 charset = CHARSET_FROM_ID (id); \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3380 } \ |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3381 \ |
| 88365 | 3382 if (CODING_ISO_SINGLE_SHIFTING (coding)) \ |
| 3383 { \ | |
| 3384 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) \ | |
| 3385 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
| 3386 else \ | |
| 3387 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
| 3388 CODING_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
| 3389 break; \ | |
| 3390 } \ | |
| 3391 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 0)) \ | |
| 3392 { \ | |
| 3393 EMIT_TWO_ASCII_BYTES ((c1) & 0x7F, (c2) & 0x7F); \ | |
| 3394 break; \ | |
| 3395 } \ | |
| 3396 else if (id == CODING_ISO_INVOKED_CHARSET (coding, 1)) \ | |
| 3397 { \ | |
| 3398 EMIT_TWO_BYTES ((c1) | 0x80, (c2) | 0x80); \ | |
| 3399 break; \ | |
| 3400 } \ | |
| 3401 else \ | |
| 3402 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
| 3403 must invoke it, or, at first, designate it to some graphic \ | |
| 3404 register. Then repeat the loop to actually produce the \ | |
| 3405 character. */ \ | |
| 3406 dst = encode_invocation_designation (charset, coding, dst, \ | |
| 3407 &produced_chars); \ | |
| 3408 } while (1) | |
| 3409 | |
| 3410 | |
| 3411 #define ENCODE_ISO_CHARACTER(charset, c) \ | |
| 3412 do { \ | |
| 3413 int code = ENCODE_CHAR ((charset),(c)); \ | |
| 3414 \ | |
| 3415 if (CHARSET_DIMENSION (charset) == 1) \ | |
| 3416 ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ | |
| 3417 else \ | |
| 3418 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
|
3419 } while (0) |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3420 |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
3421 |
| 17052 | 3422 /* Produce designation and invocation codes at a place pointed by DST |
| 88365 | 3423 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. |
| 17052 | 3424 Return new DST. */ |
| 3425 | |
| 3426 unsigned char * | |
| 88365 | 3427 encode_invocation_designation (charset, coding, dst, p_nchars) |
| 3428 struct charset *charset; | |
| 17052 | 3429 struct coding_system *coding; |
| 3430 unsigned char *dst; | |
| 88365 | 3431 int *p_nchars; |
| 17052 | 3432 { |
| 88365 | 3433 int multibytep = coding->dst_multibyte; |
| 3434 int produced_chars = *p_nchars; | |
| 17052 | 3435 int reg; /* graphic register number */ |
| 88365 | 3436 int id = CHARSET_ID (charset); |
| 17052 | 3437 |
| 3438 /* At first, check designations. */ | |
| 3439 for (reg = 0; reg < 4; reg++) | |
| 88365 | 3440 if (id == CODING_ISO_DESIGNATION (coding, reg)) |
| 17052 | 3441 break; |
| 3442 | |
| 3443 if (reg >= 4) | |
| 3444 { | |
| 3445 /* CHARSET is not yet designated to any graphic registers. */ | |
| 3446 /* At first check the requested designation. */ | |
| 88365 | 3447 reg = CODING_ISO_REQUEST (coding, id); |
| 3448 if (reg < 0) | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3449 /* Since CHARSET requests no special designation, designate it |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3450 to graphic register 0. */ |
| 17052 | 3451 reg = 0; |
| 3452 | |
| 3453 ENCODE_DESIGNATION (charset, reg, coding); | |
| 3454 } | |
| 3455 | |
| 88365 | 3456 if (CODING_ISO_INVOCATION (coding, 0) != reg |
| 3457 && CODING_ISO_INVOCATION (coding, 1) != reg) | |
| 17052 | 3458 { |
| 3459 /* Since the graphic register REG is not invoked to any graphic | |
| 3460 planes, invoke it to graphic plane 0. */ | |
| 3461 switch (reg) | |
| 3462 { | |
| 3463 case 0: /* graphic register 0 */ | |
| 3464 ENCODE_SHIFT_IN; | |
| 3465 break; | |
| 3466 | |
| 3467 case 1: /* graphic register 1 */ | |
| 3468 ENCODE_SHIFT_OUT; | |
| 3469 break; | |
| 3470 | |
| 3471 case 2: /* graphic register 2 */ | |
| 88365 | 3472 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
| 17052 | 3473 ENCODE_SINGLE_SHIFT_2; |
| 3474 else | |
| 3475 ENCODE_LOCKING_SHIFT_2; | |
| 3476 break; | |
| 3477 | |
| 3478 case 3: /* graphic register 3 */ | |
| 88365 | 3479 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
| 17052 | 3480 ENCODE_SINGLE_SHIFT_3; |
| 3481 else | |
| 3482 ENCODE_LOCKING_SHIFT_3; | |
| 3483 break; | |
| 3484 } | |
| 3485 } | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3486 |
| 88365 | 3487 *p_nchars = produced_chars; |
| 17052 | 3488 return dst; |
| 3489 } | |
| 3490 | |
| 3491 /* The following three macros produce codes for indicating direction | |
| 3492 of text. */ | |
| 88365 | 3493 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ |
| 3494 do { \ | |
| 3495 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \ | |
| 3496 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \ | |
| 3497 else \ | |
| 3498 EMIT_ONE_BYTE (ISO_CODE_CSI); \ | |
| 17052 | 3499 } while (0) |
| 3500 | |
| 88365 | 3501 |
| 3502 #define ENCODE_DIRECTION_R2L() \ | |
| 3503 do { \ | |
| 3504 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
| 3505 EMIT_TWO_ASCII_BYTES ('2', ']'); \ | |
| 3506 } while (0) | |
| 3507 | |
| 3508 | |
| 3509 #define ENCODE_DIRECTION_L2R() \ | |
| 3510 do { \ | |
| 3511 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \ | |
| 3512 EMIT_TWO_ASCII_BYTES ('0', ']'); \ | |
| 3513 } while (0) | |
| 3514 | |
| 17052 | 3515 |
| 3516 /* Produce codes for designation and invocation to reset the graphic | |
| 3517 planes and registers to initial state. */ | |
| 88365 | 3518 #define ENCODE_RESET_PLANE_AND_REGISTER() \ |
| 3519 do { \ | |
| 3520 int reg; \ | |
| 3521 struct charset *charset; \ | |
| 3522 \ | |
| 3523 if (CODING_ISO_INVOCATION (coding, 0) != 0) \ | |
| 3524 ENCODE_SHIFT_IN; \ | |
| 3525 for (reg = 0; reg < 4; reg++) \ | |
| 3526 if (CODING_ISO_INITIAL (coding, reg) >= 0 \ | |
| 3527 && (CODING_ISO_DESIGNATION (coding, reg) \ | |
| 3528 != CODING_ISO_INITIAL (coding, reg))) \ | |
| 3529 { \ | |
| 3530 charset = CHARSET_FROM_ID (CODING_ISO_INITIAL (coding, reg)); \ | |
| 3531 ENCODE_DESIGNATION (charset, reg, coding); \ | |
| 3532 } \ | |
| 17052 | 3533 } while (0) |
| 3534 | |
| 88365 | 3535 |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3536 /* 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
|
3537 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
|
3538 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3539 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
|
3540 find all the necessary designations. */ |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
3541 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3542 static unsigned char * |
| 88365 | 3543 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
|
3544 struct coding_system *coding; |
| 88365 | 3545 int *charbuf, *charbuf_end; |
| 3546 unsigned char *dst; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3547 { |
| 88365 | 3548 struct charset *charset; |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3549 /* 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
|
3550 int r[4]; |
| 88365 | 3551 int c, found = 0, reg; |
| 3552 int produced_chars = 0; | |
| 3553 int multibytep = coding->dst_multibyte; | |
| 3554 Lisp_Object attrs; | |
| 3555 Lisp_Object charset_list; | |
| 3556 | |
| 3557 attrs = CODING_ID_ATTRS (coding->id); | |
| 3558 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
| 3559 if (EQ (charset_list, Qiso_2022)) | |
| 3560 charset_list = Viso_2022_charset_list; | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3561 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3562 for (reg = 0; reg < 4; reg++) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3563 r[reg] = -1; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3564 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3565 while (found < 4) |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3566 { |
| 88365 | 3567 int id; |
| 3568 | |
| 3569 c = *charbuf++; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3570 if (c == '\n') |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3571 break; |
| 88365 | 3572 charset = char_charset (c, charset_list, NULL); |
| 3573 id = CHARSET_ID (charset); | |
| 3574 reg = CODING_ISO_REQUEST (coding, id); | |
| 3575 if (reg >= 0 && r[reg] < 0) | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3576 { |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3577 found++; |
| 88365 | 3578 r[reg] = id; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3579 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3580 } |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3581 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3582 if (found) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3583 { |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3584 for (reg = 0; reg < 4; reg++) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3585 if (r[reg] >= 0 |
| 88365 | 3586 && CODING_ISO_DESIGNATION (coding, reg) != r[reg]) |
| 3587 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
|
3588 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3589 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3590 return dst; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3591 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3592 |
| 17052 | 3593 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
| 3594 | |
| 88365 | 3595 static int |
| 3596 encode_coding_iso_2022 (coding) | |
| 17052 | 3597 struct coding_system *coding; |
| 3598 { | |
| 88365 | 3599 int multibytep = coding->dst_multibyte; |
| 3600 int *charbuf = coding->charbuf; | |
| 3601 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 3602 unsigned char *dst = coding->destination + coding->produced; | |
| 3603 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 3604 int safe_room = 16; | |
| 3605 int bol_designation | |
| 3606 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL | |
| 3607 && CODING_ISO_BOL (coding)); | |
| 3608 int produced_chars = 0; | |
| 3609 Lisp_Object attrs, eol_type, charset_list; | |
| 3610 int ascii_compatible; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3611 int c; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3612 int preferred_charset_id = -1; |
| 88365 | 3613 |
| 3614 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
|
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3615 setup_iso_safe_charsets (attrs); |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3616 /* Charset list may have been changed. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3617 charset_list = CODING_ATTR_CHARSET_LIST (attrs); \ |
|
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3618 coding->safe_charsets |
|
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
3619 = (char *) XSTRING (CODING_ATTR_SAFE_CHARSETS(attrs))->data; |
| 88365 | 3620 |
| 3621 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
| 3622 | |
| 3623 while (charbuf < charbuf_end) | |
| 3624 { | |
| 3625 ASSURE_DESTINATION (safe_room); | |
| 3626 | |
| 3627 if (bol_designation) | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3628 { |
| 88365 | 3629 unsigned char *dst_prev = dst; |
| 3630 | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3631 /* We have to produce designation sequences if any now. */ |
| 88365 | 3632 dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); |
| 3633 bol_designation = 0; | |
| 3634 /* We are sure that designation sequences are all ASCII bytes. */ | |
| 3635 produced_chars += dst - dst_prev; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3636 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3637 |
| 88365 | 3638 c = *charbuf++; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3639 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3640 if (c < 0) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3641 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3642 /* Handle an annotation. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3643 switch (*charbuf) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3644 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3645 case CODING_ANNOTATE_COMPOSITION_MASK: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3646 /* Not yet implemented. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3647 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3648 case CODING_ANNOTATE_CHARSET_MASK: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3649 preferred_charset_id = charbuf[3]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3650 if (preferred_charset_id >= 0 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3651 && NILP (Fmemq (make_number (preferred_charset_id), |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3652 charset_list))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3653 preferred_charset_id = -1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3654 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3655 default: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3656 abort (); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3657 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3658 charbuf += -c - 1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3659 continue; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3660 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3661 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3662 /* 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
|
3663 if (c < 0x20 || c == 0x7F) |
| 17052 | 3664 { |
| 88365 | 3665 if (c == '\n' |
| 3666 || (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
|
3667 { |
| 88365 | 3668 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) |
| 3669 ENCODE_RESET_PLANE_AND_REGISTER (); | |
| 3670 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_INIT_AT_BOL) | |
| 3671 { | |
| 3672 int i; | |
| 3673 | |
| 3674 for (i = 0; i < 4; i++) | |
| 3675 CODING_ISO_DESIGNATION (coding, i) | |
| 3676 = CODING_ISO_INITIAL (coding, i); | |
| 3677 } | |
| 3678 bol_designation | |
| 3679 = 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
|
3680 } |
| 88365 | 3681 else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) |
| 3682 ENCODE_RESET_PLANE_AND_REGISTER (); | |
| 3683 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
|
3684 } |
| 88365 | 3685 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
|
3686 { |
| 88365 | 3687 if (ascii_compatible) |
| 3688 EMIT_ONE_ASCII_BYTE (c); | |
| 3689 else | |
|
88681
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3690 { |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3691 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
|
3692 ENCODE_ISO_CHARACTER (charset, c); |
|
2cdfbffa8a0d
(CODING_ISO_FLAG_USE_ROMAN): New macro
Kenichi Handa <handa@m17n.org>
parents:
88669
diff
changeset
|
3693 } |
| 17052 | 3694 } |
|
88690
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3695 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
|
3696 { |
|
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
3697 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
|
3698 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
|
3699 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3700 else |
| 88365 | 3701 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3702 struct charset *charset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3703 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3704 if (preferred_charset_id >= 0) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3705 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3706 charset = CHARSET_FROM_ID (preferred_charset_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3707 if (! CHAR_CHARSET_P (c, charset)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3708 charset = char_charset (c, charset_list, NULL); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3709 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3710 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3711 charset = char_charset (c, charset_list, NULL); |
| 88365 | 3712 if (!charset) |
| 3713 { | |
|
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3714 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
|
3715 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3716 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3717 charset = CHARSET_FROM_ID (charset_ascii); |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3718 } |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3719 else |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3720 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3721 c = coding->default_char; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
3722 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
|
3723 } |
| 88365 | 3724 } |
| 3725 ENCODE_ISO_CHARACTER (charset, c); | |
| 3726 } | |
| 3727 } | |
| 3728 | |
| 3729 if (coding->mode & CODING_MODE_LAST_BLOCK | |
| 3730 && CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_EOL) | |
| 3731 { | |
| 3732 ASSURE_DESTINATION (safe_room); | |
| 3733 ENCODE_RESET_PLANE_AND_REGISTER (); | |
| 3734 } | |
| 3735 coding->result = CODING_RESULT_SUCCESS; | |
| 3736 CODING_ISO_BOL (coding) = bol_designation; | |
| 3737 coding->produced_char += produced_chars; | |
| 3738 coding->produced = dst - coding->destination; | |
| 3739 return 0; | |
| 17052 | 3740 } |
| 3741 | |
| 3742 | |
| 88365 | 3743 /*** 8,9. SJIS and BIG5 handlers ***/ |
| 3744 | |
| 3745 /* Although SJIS and BIG5 are not ISO's coding system, they are used | |
| 17052 | 3746 quite widely. So, for the moment, Emacs supports them in the bare |
| 3747 C code. But, in the future, they may be supported only by CCL. */ | |
| 3748 | |
| 3749 /* SJIS is a coding system encoding three character sets: ASCII, right | |
| 3750 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
| 3751 as is. A character of charset katakana-jisx0201 is encoded by | |
| 3752 "position-code + 0x80". A character of charset japanese-jisx0208 | |
| 3753 is encoded in 2-byte but two position-codes are divided and shifted | |
| 88365 | 3754 so that it fit in the range below. |
| 17052 | 3755 |
| 3756 --- CODE RANGE of SJIS --- | |
| 3757 (character set) (range) | |
| 3758 ASCII 0x00 .. 0x7F | |
| 88365 | 3759 KATAKANA-JISX0201 0xA0 .. 0xDF |
|
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
3760 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
|
3761 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC |
| 17052 | 3762 ------------------------------- |
| 3763 | |
| 3764 */ | |
| 3765 | |
| 3766 /* BIG5 is a coding system encoding two character sets: ASCII and | |
| 3767 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
| 88365 | 3768 character set and is encoded in two-byte. |
| 17052 | 3769 |
| 3770 --- CODE RANGE of BIG5 --- | |
| 3771 (character set) (range) | |
| 3772 ASCII 0x00 .. 0x7F | |
| 3773 Big5 (1st byte) 0xA1 .. 0xFE | |
| 3774 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
| 3775 -------------------------- | |
| 3776 | |
| 88365 | 3777 */ |
| 17052 | 3778 |
| 3779 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
| 3780 Check if a text is encoded in SJIS. If it is, return | |
| 88365 | 3781 CATEGORY_MASK_SJIS, else return 0. */ |
| 17052 | 3782 |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3783 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3784 detect_coding_sjis (coding, detect_info) |
| 88365 | 3785 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3786 struct coding_detection_info *detect_info; |
| 17052 | 3787 { |
| 88365 | 3788 unsigned char *src = coding->source, *src_base = src; |
| 3789 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 3790 int multibytep = coding->src_multibyte; | |
| 3791 int consumed_chars = 0; | |
| 3792 int found = 0; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3793 int c; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3794 int incomplete; |
| 88365 | 3795 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3796 detect_info->checked |= CATEGORY_MASK_SJIS; |
| 88365 | 3797 /* A coding system of this category is always ASCII compatible. */ |
| 3798 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
|
3799 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3800 while (1) |
| 17052 | 3801 { |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3802 incomplete = 0; |
| 88365 | 3803 ONE_MORE_BYTE (c); |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3804 incomplete = 1; |
|
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3805 if (c < 0x80) |
|
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3806 continue; |
| 88365 | 3807 if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xEF)) |
| 17052 | 3808 { |
| 88365 | 3809 ONE_MORE_BYTE (c); |
|
36647
0a75ccbe42b2
(detect_coding_sjis): Do more rigid check.
Kenichi Handa <handa@m17n.org>
parents:
36520
diff
changeset
|
3810 if (c < 0x40 || c == 0x7F || c > 0xFC) |
| 88365 | 3811 break; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3812 found = CATEGORY_MASK_SJIS; |
| 17052 | 3813 } |
| 88365 | 3814 else if (c >= 0xA0 && c < 0xE0) |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3815 found = CATEGORY_MASK_SJIS; |
| 88365 | 3816 else |
| 3817 break; | |
| 3818 } | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3819 detect_info->rejected |= CATEGORY_MASK_SJIS; |
| 88365 | 3820 return 0; |
| 3821 | |
| 3822 no_more_source: | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3823 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3824 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3825 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
|
3826 return 0; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3827 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3828 detect_info->found |= found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3829 return 1; |
| 17052 | 3830 } |
| 3831 | |
| 3832 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
| 3833 Check if a text is encoded in BIG5. If it is, return | |
| 88365 | 3834 CATEGORY_MASK_BIG5, else return 0. */ |
| 17052 | 3835 |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
3836 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3837 detect_coding_big5 (coding, detect_info) |
| 88365 | 3838 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3839 struct coding_detection_info *detect_info; |
| 17052 | 3840 { |
| 88365 | 3841 unsigned char *src = coding->source, *src_base = src; |
| 3842 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 3843 int multibytep = coding->src_multibyte; | |
| 3844 int consumed_chars = 0; | |
| 3845 int found = 0; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3846 int c; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3847 int incomplete; |
| 88365 | 3848 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3849 detect_info->checked |= CATEGORY_MASK_BIG5; |
| 88365 | 3850 /* A coding system of this category is always ASCII compatible. */ |
| 3851 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
|
3852 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3853 while (1) |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3854 { |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3855 incomplete = 0; |
| 88365 | 3856 ONE_MORE_BYTE (c); |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3857 incomplete = 1; |
| 88365 | 3858 if (c < 0x80) |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3859 continue; |
| 88365 | 3860 if (c >= 0xA1) |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3861 { |
| 88365 | 3862 ONE_MORE_BYTE (c); |
| 3863 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
|
3864 return 0; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3865 found = CATEGORY_MASK_BIG5; |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3866 } |
| 88365 | 3867 else |
| 3868 break; | |
| 3869 } | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3870 detect_info->rejected |= CATEGORY_MASK_BIG5; |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3871 return 0; |
| 88365 | 3872 |
| 3873 no_more_source: | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3874 if (incomplete && coding->mode & CODING_MODE_LAST_BLOCK) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3875 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3876 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
|
3877 return 0; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3878 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3879 detect_info->found |= found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3880 return 1; |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3881 } |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
3882 |
| 17052 | 3883 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". |
| 3884 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
| 3885 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3886 static void |
| 88365 | 3887 decode_coding_sjis (coding) |
| 17052 | 3888 struct coding_system *coding; |
| 3889 { | |
| 88365 | 3890 unsigned char *src = coding->source + coding->consumed; |
| 3891 unsigned char *src_end = coding->source + coding->src_bytes; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3892 unsigned char *src_base; |
| 88365 | 3893 int *charbuf = coding->charbuf; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3894 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
| 88365 | 3895 int consumed_chars = 0, consumed_chars_base; |
| 3896 int multibytep = coding->src_multibyte; | |
| 3897 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
| 3898 Lisp_Object attrs, eol_type, charset_list, val; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3899 int char_offset = coding->produced_char; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3900 int last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3901 int last_id = charset_ascii; |
| 88365 | 3902 |
| 3903 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 3904 | |
| 3905 val = charset_list; | |
| 3906 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
|
3907 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3908 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
| 88365 | 3909 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3910 while (1) |
| 17052 | 3911 { |
| 88365 | 3912 int c, c1; |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3913 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3914 src_base = src; |
| 88365 | 3915 consumed_chars_base = consumed_chars; |
| 3916 | |
| 3917 if (charbuf >= charbuf_end) | |
| 3918 break; | |
| 3919 | |
| 3920 ONE_MORE_BYTE (c); | |
| 3921 | |
| 3922 if (c == '\r') | |
| 17052 | 3923 { |
| 88365 | 3924 if (EQ (eol_type, Qdos)) |
| 17052 | 3925 { |
| 88365 | 3926 if (src == src_end) |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3927 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3928 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3929 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
3930 } |
| 88365 | 3931 if (*src == '\n') |
| 3932 ONE_MORE_BYTE (c); | |
| 17052 | 3933 } |
| 88365 | 3934 else if (EQ (eol_type, Qmac)) |
| 3935 c = '\n'; | |
| 17052 | 3936 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
3937 else |
| 88365 | 3938 { |
| 3939 struct charset *charset; | |
| 3940 | |
| 3941 if (c < 0x80) | |
| 3942 charset = charset_roman; | |
| 3943 else | |
| 17052 | 3944 { |
| 88365 | 3945 if (c >= 0xF0) |
| 3946 goto invalid_code; | |
| 3947 if (c < 0xA0 || c >= 0xE0) | |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3948 { |
|
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
3949 /* SJIS -> JISX0208 */ |
| 88365 | 3950 ONE_MORE_BYTE (c1); |
| 3951 if (c1 < 0x40 || c1 == 0x7F || c1 > 0xFC) | |
| 3952 goto invalid_code; | |
| 3953 c = (c << 8) | c1; | |
| 3954 SJIS_TO_JIS (c); | |
| 3955 charset = charset_kanji; | |
|
24870
b0f6eab5deeb
(decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents:
24822
diff
changeset
|
3956 } |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3957 else |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3958 { |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3959 /* SJIS -> JISX0201-Kana */ |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3960 c &= 0x7F; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3961 charset = charset_kana; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
3962 } |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
3963 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3964 if (charset->id != charset_ascii |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3965 && last_id != charset->id) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3966 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3967 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3968 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3969 last_id = charset->id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3970 last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3971 } |
| 88365 | 3972 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
| 3973 } | |
| 3974 *charbuf++ = c; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3975 char_offset++; |
| 88365 | 3976 continue; |
| 3977 | |
| 3978 invalid_code: | |
| 3979 src = src_base; | |
| 3980 consumed_chars = consumed_chars_base; | |
| 3981 ONE_MORE_BYTE (c); | |
| 3982 *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
|
3983 char_offset++; |
| 88365 | 3984 coding->errors++; |
| 3985 } | |
| 3986 | |
| 3987 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3988 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
3989 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
| 88365 | 3990 coding->consumed_char += consumed_chars_base; |
| 3991 coding->consumed = src_base - coding->source; | |
| 3992 coding->charbuf_used = charbuf - coding->charbuf; | |
| 3993 } | |
| 3994 | |
| 3995 static void | |
| 3996 decode_coding_big5 (coding) | |
| 3997 struct coding_system *coding; | |
| 3998 { | |
| 3999 unsigned char *src = coding->source + coding->consumed; | |
| 4000 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 4001 unsigned char *src_base; | |
| 4002 int *charbuf = coding->charbuf; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4003 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
| 88365 | 4004 int consumed_chars = 0, consumed_chars_base; |
| 4005 int multibytep = coding->src_multibyte; | |
| 4006 struct charset *charset_roman, *charset_big5; | |
| 4007 Lisp_Object attrs, eol_type, charset_list, val; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4008 int char_offset = coding->produced_char; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4009 int last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4010 int last_id = charset_ascii; |
| 88365 | 4011 |
| 4012 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 4013 val = charset_list; | |
| 4014 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
| 4015 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
| 4016 | |
| 4017 while (1) | |
| 4018 { | |
| 4019 int c, c1; | |
| 4020 | |
| 4021 src_base = src; | |
| 4022 consumed_chars_base = consumed_chars; | |
| 4023 | |
| 4024 if (charbuf >= charbuf_end) | |
| 4025 break; | |
| 4026 | |
| 4027 ONE_MORE_BYTE (c); | |
| 4028 | |
| 4029 if (c == '\r') | |
| 4030 { | |
| 4031 if (EQ (eol_type, Qdos)) | |
| 4032 { | |
| 4033 if (src == src_end) | |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4034 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4035 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4036 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4037 } |
| 88365 | 4038 if (*src == '\n') |
| 4039 ONE_MORE_BYTE (c); | |
| 4040 } | |
| 4041 else if (EQ (eol_type, Qmac)) | |
| 4042 c = '\n'; | |
| 4043 } | |
| 4044 else | |
| 4045 { | |
| 4046 struct charset *charset; | |
| 4047 if (c < 0x80) | |
| 4048 charset = charset_roman; | |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4049 else |
|
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4050 { |
|
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4051 /* BIG5 -> Big5 */ |
| 88365 | 4052 if (c < 0xA1 || c > 0xFE) |
| 4053 goto invalid_code; | |
| 4054 ONE_MORE_BYTE (c1); | |
| 4055 if (c1 < 0x40 || (c1 > 0x7E && c1 < 0xA1) || c1 > 0xFE) | |
| 4056 goto invalid_code; | |
| 4057 c = c << 8 | c1; | |
| 4058 charset = charset_big5; | |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4059 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4060 if (charset->id != charset_ascii |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4061 && last_id != charset->id) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4062 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4063 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4064 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4065 last_id = charset->id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4066 last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4067 } |
| 88365 | 4068 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4069 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4070 |
| 88365 | 4071 *charbuf++ = c; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4072 char_offset++; |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4073 continue; |
|
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4074 |
| 88365 | 4075 invalid_code: |
| 17052 | 4076 src = src_base; |
| 88365 | 4077 consumed_chars = consumed_chars_base; |
| 4078 ONE_MORE_BYTE (c); | |
| 4079 *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
|
4080 char_offset++; |
| 88365 | 4081 coding->errors++; |
| 4082 } | |
| 4083 | |
| 4084 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4085 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4086 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
| 88365 | 4087 coding->consumed_char += consumed_chars_base; |
| 4088 coding->consumed = src_base - coding->source; | |
| 4089 coding->charbuf_used = charbuf - coding->charbuf; | |
| 17052 | 4090 } |
| 4091 | |
| 4092 /* 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
|
4093 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
|
4094 `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
|
4095 are sure that all these charsets are registered as official charset |
| 17052 | 4096 (i.e. do not have extended leading-codes). Characters of other |
| 4097 charsets are produced without any encoding. If SJIS_P is 1, encode | |
| 4098 SJIS text, else encode BIG5 text. */ | |
| 4099 | |
| 88365 | 4100 static int |
| 4101 encode_coding_sjis (coding) | |
| 17052 | 4102 struct coding_system *coding; |
| 4103 { | |
| 88365 | 4104 int multibytep = coding->dst_multibyte; |
| 4105 int *charbuf = coding->charbuf; | |
| 4106 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 4107 unsigned char *dst = coding->destination + coding->produced; | |
| 4108 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 4109 int safe_room = 4; | |
| 4110 int produced_chars = 0; | |
| 4111 Lisp_Object attrs, eol_type, charset_list, val; | |
| 4112 int ascii_compatible; | |
| 4113 struct charset *charset_roman, *charset_kanji, *charset_kana; | |
| 4114 int c; | |
| 4115 | |
| 4116 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 4117 val = charset_list; | |
| 4118 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
| 4119 charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
| 4120 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); | |
| 4121 | |
| 4122 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
| 4123 | |
| 4124 while (charbuf < charbuf_end) | |
| 4125 { | |
| 4126 ASSURE_DESTINATION (safe_room); | |
| 4127 c = *charbuf++; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4128 /* Now encode the character C. */ |
| 88365 | 4129 if (ASCII_CHAR_P (c) && ascii_compatible) |
| 4130 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
|
4131 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
|
4132 { |
|
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4133 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
|
4134 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
|
4135 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4136 else |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4137 { |
| 88365 | 4138 unsigned code; |
| 4139 struct charset *charset = char_charset (c, charset_list, &code); | |
| 4140 | |
| 4141 if (!charset) | |
| 4142 { | |
|
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4143 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
|
4144 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4145 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4146 charset = CHARSET_FROM_ID (charset_ascii); |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4147 } |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4148 else |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4149 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4150 c = coding->default_char; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4151 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
|
4152 } |
| 88365 | 4153 } |
| 4154 if (code == CHARSET_INVALID_CODE (charset)) | |
| 4155 abort (); | |
| 4156 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
|
4157 { |
| 88365 | 4158 int c1, c2; |
| 4159 JIS_TO_SJIS (code); | |
| 4160 c1 = code >> 8, c2 = code & 0xFF; | |
| 4161 EMIT_TWO_BYTES (c1, c2); | |
| 4162 } | |
| 4163 else if (charset == charset_kana) | |
| 4164 EMIT_ONE_BYTE (code | 0x80); | |
| 4165 else | |
| 4166 EMIT_ONE_ASCII_BYTE (code & 0x7F); | |
| 4167 } | |
| 4168 } | |
| 4169 coding->result = CODING_RESULT_SUCCESS; | |
| 4170 coding->produced_char += produced_chars; | |
| 4171 coding->produced = dst - coding->destination; | |
| 4172 return 0; | |
| 4173 } | |
| 4174 | |
| 4175 static int | |
| 4176 encode_coding_big5 (coding) | |
| 4177 struct coding_system *coding; | |
| 4178 { | |
| 4179 int multibytep = coding->dst_multibyte; | |
| 4180 int *charbuf = coding->charbuf; | |
| 4181 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 4182 unsigned char *dst = coding->destination + coding->produced; | |
| 4183 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 4184 int safe_room = 4; | |
| 4185 int produced_chars = 0; | |
| 4186 Lisp_Object attrs, eol_type, charset_list, val; | |
| 4187 int ascii_compatible; | |
| 4188 struct charset *charset_roman, *charset_big5; | |
| 4189 int c; | |
| 4190 | |
| 4191 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 4192 val = charset_list; | |
| 4193 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
| 4194 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
| 4195 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
| 4196 | |
| 4197 while (charbuf < charbuf_end) | |
| 4198 { | |
| 4199 ASSURE_DESTINATION (safe_room); | |
| 4200 c = *charbuf++; | |
| 4201 /* Now encode the character C. */ | |
| 4202 if (ASCII_CHAR_P (c) && ascii_compatible) | |
| 4203 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
|
4204 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
|
4205 { |
|
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4206 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
|
4207 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
|
4208 } |
| 88365 | 4209 else |
| 4210 { | |
| 4211 unsigned code; | |
| 4212 struct charset *charset = char_charset (c, charset_list, &code); | |
| 4213 | |
| 4214 if (! charset) | |
| 4215 { | |
|
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4216 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
|
4217 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4218 code = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4219 charset = CHARSET_FROM_ID (charset_ascii); |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4220 } |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4221 else |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4222 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4223 c = coding->default_char; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4224 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
|
4225 } |
| 88365 | 4226 } |
| 4227 if (code == CHARSET_INVALID_CODE (charset)) | |
| 4228 abort (); | |
| 4229 if (charset == charset_big5) | |
| 4230 { | |
| 4231 int c1, c2; | |
| 4232 | |
| 4233 c1 = code >> 8, c2 = code & 0xFF; | |
| 4234 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
|
4235 } |
| 17052 | 4236 else |
| 88365 | 4237 EMIT_ONE_ASCII_BYTE (code & 0x7F); |
| 17052 | 4238 } |
| 88365 | 4239 } |
| 4240 coding->result = CODING_RESULT_SUCCESS; | |
| 4241 coding->produced_char += produced_chars; | |
| 4242 coding->produced = dst - coding->destination; | |
| 4243 return 0; | |
| 17052 | 4244 } |
| 4245 | |
| 4246 | |
| 88365 | 4247 /*** 10. CCL handlers ***/ |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4248 |
|
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4249 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
|
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4250 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
|
4251 encoder/decoder are written in CCL program. If it is, return |
| 88365 | 4252 CATEGORY_MASK_CCL, else return 0. */ |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4253 |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
4254 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4255 detect_coding_ccl (coding, detect_info) |
| 88365 | 4256 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4257 struct coding_detection_info *detect_info; |
| 88365 | 4258 { |
| 4259 unsigned char *src = coding->source, *src_base = src; | |
| 4260 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 4261 int multibytep = coding->src_multibyte; | |
| 4262 int consumed_chars = 0; | |
| 4263 int found = 0; | |
| 4264 unsigned char *valids = CODING_CCL_VALIDS (coding); | |
| 4265 int head_ascii = coding->head_ascii; | |
| 4266 Lisp_Object attrs; | |
| 4267 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4268 detect_info->checked |= CATEGORY_MASK_CCL; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4269 |
| 88365 | 4270 coding = &coding_categories[coding_category_ccl]; |
| 4271 attrs = CODING_ID_ATTRS (coding->id); | |
| 4272 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
| 4273 src += head_ascii; | |
| 4274 | |
| 4275 while (1) | |
| 4276 { | |
| 4277 int c; | |
| 4278 ONE_MORE_BYTE (c); | |
| 4279 if (! valids[c]) | |
| 4280 break; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4281 if ((valids[c] > 1)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4282 found = CATEGORY_MASK_CCL; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4283 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4284 detect_info->rejected |= CATEGORY_MASK_CCL; |
| 88365 | 4285 return 0; |
| 4286 | |
| 4287 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4288 detect_info->found |= found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4289 return 1; |
| 88365 | 4290 } |
| 4291 | |
| 4292 static void | |
| 4293 decode_coding_ccl (coding) | |
| 4294 struct coding_system *coding; | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4295 { |
|
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
4296 const unsigned char *src = coding->source + coding->consumed; |
| 88365 | 4297 unsigned char *src_end = coding->source + coding->src_bytes; |
| 4298 int *charbuf = coding->charbuf; | |
| 4299 int *charbuf_end = charbuf + coding->charbuf_size; | |
| 4300 int consumed_chars = 0; | |
| 4301 int multibytep = coding->src_multibyte; | |
| 4302 struct ccl_program ccl; | |
| 4303 int source_charbuf[1024]; | |
| 4304 int source_byteidx[1024]; | |
| 4305 | |
| 4306 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); | |
| 4307 | |
| 4308 while (src < src_end) | |
| 4309 { | |
|
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
4310 const unsigned char *p = src; |
| 88365 | 4311 int *source, *source_end; |
| 4312 int i = 0; | |
| 4313 | |
| 4314 if (multibytep) | |
| 4315 while (i < 1024 && p < src_end) | |
| 4316 { | |
| 4317 source_byteidx[i] = p - src; | |
| 4318 source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | |
| 4319 } | |
| 4320 else | |
| 4321 while (i < 1024 && p < src_end) | |
| 4322 source_charbuf[i++] = *p++; | |
| 4323 | |
| 4324 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) | |
| 4325 ccl.last_block = 1; | |
| 4326 | |
| 4327 source = source_charbuf; | |
| 4328 source_end = source + i; | |
| 4329 while (source < source_end) | |
| 4330 { | |
| 4331 ccl_driver (&ccl, source, charbuf, | |
| 4332 source_end - source, charbuf_end - charbuf); | |
| 4333 source += ccl.consumed; | |
| 4334 charbuf += ccl.produced; | |
| 4335 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
| 4336 break; | |
| 4337 } | |
| 4338 if (source < source_end) | |
| 4339 src += source_byteidx[source - source_charbuf]; | |
| 4340 else | |
| 4341 src = p; | |
| 4342 consumed_chars += source - source_charbuf; | |
| 4343 | |
| 4344 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
| 4345 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
| 4346 break; | |
| 4347 } | |
| 4348 | |
| 4349 switch (ccl.status) | |
| 4350 { | |
| 4351 case CCL_STAT_SUSPEND_BY_SRC: | |
| 4352 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
| 4353 break; | |
| 4354 case CCL_STAT_SUSPEND_BY_DST: | |
| 4355 break; | |
| 4356 case CCL_STAT_QUIT: | |
| 4357 case CCL_STAT_INVALID_CMD: | |
| 4358 coding->result = CODING_RESULT_INTERRUPT; | |
| 4359 break; | |
| 4360 default: | |
| 4361 coding->result = CODING_RESULT_SUCCESS; | |
| 4362 break; | |
| 4363 } | |
| 4364 coding->consumed_char += consumed_chars; | |
| 4365 coding->consumed = src - coding->source; | |
| 4366 coding->charbuf_used = charbuf - coding->charbuf; | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4367 } |
|
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4368 |
| 88365 | 4369 static int |
| 4370 encode_coding_ccl (coding) | |
| 4371 struct coding_system *coding; | |
| 4372 { | |
| 4373 struct ccl_program ccl; | |
| 4374 int multibytep = coding->dst_multibyte; | |
| 4375 int *charbuf = coding->charbuf; | |
| 4376 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 4377 unsigned char *dst = coding->destination + coding->produced; | |
| 4378 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 4379 unsigned char *adjusted_dst_end = dst_end - 1; | |
| 4380 int destination_charbuf[1024]; | |
| 4381 int i, produced_chars = 0; | |
| 4382 | |
| 4383 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); | |
| 4384 | |
| 4385 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; | |
| 4386 ccl.dst_multibyte = coding->dst_multibyte; | |
| 4387 | |
| 4388 while (charbuf < charbuf_end && dst < adjusted_dst_end) | |
| 4389 { | |
| 4390 int dst_bytes = dst_end - dst; | |
| 4391 if (dst_bytes > 1024) | |
| 4392 dst_bytes = 1024; | |
| 4393 | |
| 4394 ccl_driver (&ccl, charbuf, destination_charbuf, | |
| 4395 charbuf_end - charbuf, dst_bytes); | |
| 4396 charbuf += ccl.consumed; | |
| 4397 if (multibytep) | |
| 4398 for (i = 0; i < ccl.produced; i++) | |
| 4399 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); | |
| 4400 else | |
| 4401 { | |
| 4402 for (i = 0; i < ccl.produced; i++) | |
| 4403 *dst++ = destination_charbuf[i] & 0xFF; | |
| 4404 produced_chars += ccl.produced; | |
| 4405 } | |
| 4406 } | |
| 4407 | |
| 4408 switch (ccl.status) | |
| 4409 { | |
| 4410 case CCL_STAT_SUSPEND_BY_SRC: | |
| 4411 coding->result = CODING_RESULT_INSUFFICIENT_SRC; | |
| 4412 break; | |
| 4413 case CCL_STAT_SUSPEND_BY_DST: | |
| 4414 coding->result = CODING_RESULT_INSUFFICIENT_DST; | |
| 4415 break; | |
| 4416 case CCL_STAT_QUIT: | |
| 4417 case CCL_STAT_INVALID_CMD: | |
| 4418 coding->result = CODING_RESULT_INTERRUPT; | |
| 4419 break; | |
| 4420 default: | |
| 4421 coding->result = CODING_RESULT_SUCCESS; | |
| 4422 break; | |
| 4423 } | |
| 4424 | |
| 4425 coding->produced_char += produced_chars; | |
| 4426 coding->produced = dst - coding->destination; | |
| 4427 return 0; | |
| 4428 } | |
| 4429 | |
| 4430 | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4431 |
| 88365 | 4432 /*** 10, 11. no-conversion handlers ***/ |
| 17052 | 4433 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4434 /* 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
|
4435 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4436 static void |
| 88365 | 4437 decode_coding_raw_text (coding) |
| 17052 | 4438 struct coding_system *coding; |
| 4439 { | |
| 88365 | 4440 coding->chars_at_source = 1; |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4441 coding->consumed_char = 0; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
4442 coding->consumed = 0; |
| 88365 | 4443 coding->result = CODING_RESULT_SUCCESS; |
| 4444 } | |
| 4445 | |
| 4446 static int | |
| 4447 encode_coding_raw_text (coding) | |
| 4448 struct coding_system *coding; | |
| 4449 { | |
| 4450 int multibytep = coding->dst_multibyte; | |
| 4451 int *charbuf = coding->charbuf; | |
| 4452 int *charbuf_end = coding->charbuf + coding->charbuf_used; | |
| 4453 unsigned char *dst = coding->destination + coding->produced; | |
| 4454 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 4455 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
|
4456 int c; |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4457 |
| 88365 | 4458 if (multibytep) |
| 4459 { | |
| 4460 int safe_room = MAX_MULTIBYTE_LENGTH * 2; | |
| 4461 | |
| 4462 if (coding->src_multibyte) | |
| 4463 while (charbuf < charbuf_end) | |
| 4464 { | |
| 4465 ASSURE_DESTINATION (safe_room); | |
| 4466 c = *charbuf++; | |
| 4467 if (ASCII_CHAR_P (c)) | |
| 4468 EMIT_ONE_ASCII_BYTE (c); | |
| 4469 else if (CHAR_BYTE8_P (c)) | |
| 4470 { | |
| 4471 c = CHAR_TO_BYTE8 (c); | |
| 4472 EMIT_ONE_BYTE (c); | |
| 4473 } | |
| 4474 else | |
| 4475 { | |
| 4476 unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | |
| 4477 | |
| 4478 CHAR_STRING_ADVANCE (c, p1); | |
| 4479 while (p0 < p1) | |
|
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4480 { |
|
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4481 EMIT_ONE_BYTE (*p0); |
|
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4482 p0++; |
|
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
4483 } |
| 88365 | 4484 } |
| 4485 } | |
| 4486 else | |
| 4487 while (charbuf < charbuf_end) | |
| 4488 { | |
| 4489 ASSURE_DESTINATION (safe_room); | |
| 4490 c = *charbuf++; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4491 EMIT_ONE_BYTE (c); |
| 88365 | 4492 } |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4493 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4494 else |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4495 { |
| 88365 | 4496 if (coding->src_multibyte) |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4497 { |
| 88365 | 4498 int safe_room = MAX_MULTIBYTE_LENGTH; |
| 4499 | |
| 4500 while (charbuf < charbuf_end) | |
| 4501 { | |
| 4502 ASSURE_DESTINATION (safe_room); | |
| 4503 c = *charbuf++; | |
| 4504 if (ASCII_CHAR_P (c)) | |
| 4505 *dst++ = c; | |
| 4506 else if (CHAR_BYTE8_P (c)) | |
| 4507 *dst++ = CHAR_TO_BYTE8 (c); | |
| 4508 else | |
| 4509 CHAR_STRING_ADVANCE (c, dst); | |
| 4510 produced_chars++; | |
| 4511 } | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4512 } |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
4513 else |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4514 { |
| 88365 | 4515 ASSURE_DESTINATION (charbuf_end - charbuf); |
| 4516 while (charbuf < charbuf_end && dst < dst_end) | |
| 4517 *dst++ = *charbuf++; | |
| 4518 produced_chars = dst - (coding->destination + coding->dst_bytes); | |
| 4519 } | |
| 4520 } | |
| 4521 coding->result = CODING_RESULT_SUCCESS; | |
| 4522 coding->produced_char += produced_chars; | |
| 4523 coding->produced = dst - coding->destination; | |
| 4524 return 0; | |
| 4525 } | |
| 4526 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4527 /* 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
|
4528 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
|
4529 is, return 1, else return 0. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4530 |
| 88365 | 4531 static int |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4532 detect_coding_charset (coding, detect_info) |
| 88365 | 4533 struct coding_system *coding; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4534 struct coding_detection_info *detect_info; |
| 88365 | 4535 { |
| 4536 unsigned char *src = coding->source, *src_base = src; | |
| 4537 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 4538 int multibytep = coding->src_multibyte; | |
| 4539 int consumed_chars = 0; | |
| 4540 Lisp_Object attrs, valids; | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
4541 int found = 0; |
| 88365 | 4542 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4543 detect_info->checked |= CATEGORY_MASK_CHARSET; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4544 |
| 88365 | 4545 coding = &coding_categories[coding_category_charset]; |
| 4546 attrs = CODING_ID_ATTRS (coding->id); | |
| 4547 valids = AREF (attrs, coding_attr_charset_valids); | |
| 4548 | |
| 4549 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
| 4550 src += coding->head_ascii; | |
| 4551 | |
| 4552 while (1) | |
| 4553 { | |
| 4554 int c; | |
| 4555 | |
| 4556 ONE_MORE_BYTE (c); | |
| 4557 if (NILP (AREF (valids, c))) | |
| 4558 break; | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
4559 if (c >= 0x80) |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4560 found = CATEGORY_MASK_CHARSET; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4561 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4562 detect_info->rejected |= CATEGORY_MASK_CHARSET; |
| 88365 | 4563 return 0; |
| 4564 | |
| 4565 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4566 detect_info->found |= found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4567 return 1; |
| 88365 | 4568 } |
| 4569 | |
| 4570 static void | |
| 4571 decode_coding_charset (coding) | |
| 4572 struct coding_system *coding; | |
| 4573 { | |
| 4574 unsigned char *src = coding->source + coding->consumed; | |
| 4575 unsigned char *src_end = coding->source + coding->src_bytes; | |
| 4576 unsigned char *src_base; | |
| 4577 int *charbuf = coding->charbuf; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4578 int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; |
| 88365 | 4579 int consumed_chars = 0, consumed_chars_base; |
| 4580 int multibytep = coding->src_multibyte; | |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4581 Lisp_Object attrs, eol_type, charset_list, valids; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4582 int char_offset = coding->produced_char; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4583 int last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4584 int last_id = charset_ascii; |
| 88365 | 4585 |
| 4586 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4587 valids = AREF (attrs, coding_attr_charset_valids); |
| 88365 | 4588 |
| 4589 while (1) | |
| 4590 { | |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4591 int c; |
| 88365 | 4592 |
| 4593 src_base = src; | |
| 4594 consumed_chars_base = consumed_chars; | |
| 4595 | |
| 4596 if (charbuf >= charbuf_end) | |
| 4597 break; | |
| 4598 | |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4599 ONE_MORE_BYTE (c); |
| 88365 | 4600 if (c == '\r') |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4601 { |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4602 /* Here we assume that no charset maps '\r' to something |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4603 else. */ |
| 88365 | 4604 if (EQ (eol_type, Qdos)) |
| 4605 { | |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4606 if (src == src_end) |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4607 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4608 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4609 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4610 } |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
4611 if (*src == '\n') |
| 88365 | 4612 ONE_MORE_BYTE (c); |
| 4613 } | |
| 4614 else if (EQ (eol_type, Qmac)) | |
| 4615 c = '\n'; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4616 } |
| 88365 | 4617 else |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4618 { |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4619 Lisp_Object val; |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4620 struct charset *charset; |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4621 int dim; |
|
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4622 int len = 1; |
|
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4623 unsigned code = c; |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4624 |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4625 val = AREF (valids, c); |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4626 if (NILP (val)) |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4627 goto invalid_code; |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4628 if (INTEGERP (val)) |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4629 { |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4630 charset = CHARSET_FROM_ID (XFASTINT (val)); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4631 dim = CHARSET_DIMENSION (charset); |
|
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4632 while (len < dim) |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4633 { |
|
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4634 ONE_MORE_BYTE (c); |
|
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4635 code = (code << 8) | c; |
|
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4636 len++; |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4637 } |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4638 CODING_DECODE_CHAR (coding, src, src_base, src_end, |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4639 charset, code, c); |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4640 } |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4641 else |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4642 { |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4643 /* VAL is a list of charset IDs. It is assured that the |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4644 list is sorted by charset dimensions (smaller one |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4645 comes first). */ |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4646 while (CONSP (val)) |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4647 { |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4648 charset = CHARSET_FROM_ID (XFASTINT (XCAR (val))); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4649 dim = CHARSET_DIMENSION (charset); |
|
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4650 while (len < dim) |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4651 { |
|
88598
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4652 ONE_MORE_BYTE (c); |
|
b88195f69856
(decode_coding_charset): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88597
diff
changeset
|
4653 code = (code << 8) | c; |
|
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
4654 len++; |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4655 } |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4656 CODING_DECODE_CHAR (coding, src, src_base, |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4657 src_end, charset, code, c); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4658 if (c >= 0) |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4659 break; |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4660 val = XCDR (val); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4661 } |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
4662 } |
| 88365 | 4663 if (c < 0) |
| 4664 goto invalid_code; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4665 if (charset->id != charset_ascii |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4666 && last_id != charset->id) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4667 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4668 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4669 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4670 last_id = charset->id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4671 last_offset = char_offset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4672 } |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
4673 } |
| 88365 | 4674 *charbuf++ = c; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4675 char_offset++; |
| 88365 | 4676 continue; |
| 4677 | |
| 4678 invalid_code: | |
| 4679 src = src_base; | |
| 4680 consumed_chars = consumed_chars_base; | |
| 4681 ONE_MORE_BYTE (c); | |
| 4682 *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
|
4683 char_offset++; |
| 88365 | 4684 coding->errors++; |
| 4685 } | |
| 4686 | |
| 4687 no_more_source: | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4688 if (last_id != charset_ascii) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4689 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); |
| 88365 | 4690 coding->consumed_char += consumed_chars_base; |
| 4691 coding->consumed = src_base - coding->source; | |
| 4692 coding->charbuf_used = charbuf - coding->charbuf; | |
| 4693 } | |
| 4694 | |
| 4695 static int | |
| 4696 encode_coding_charset (coding) | |
| 4697 struct coding_system *coding; | |
| 4698 { | |
| 4699 int multibytep = coding->dst_multibyte; | |
| 4700 int *charbuf = coding->charbuf; | |
| 4701 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 4702 unsigned char *dst = coding->destination + coding->produced; | |
| 4703 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 4704 int safe_room = MAX_MULTIBYTE_LENGTH; | |
| 4705 int produced_chars = 0; | |
| 4706 Lisp_Object attrs, eol_type, charset_list; | |
| 4707 int ascii_compatible; | |
| 4708 int c; | |
| 4709 | |
| 4710 CODING_GET_INFO (coding, attrs, eol_type, charset_list); | |
| 4711 ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | |
| 4712 | |
| 4713 while (charbuf < charbuf_end) | |
| 4714 { | |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4715 struct charset *charset; |
| 88365 | 4716 unsigned code; |
| 4717 | |
| 4718 ASSURE_DESTINATION (safe_room); | |
| 4719 c = *charbuf++; | |
| 4720 if (ascii_compatible && ASCII_CHAR_P (c)) | |
| 4721 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
|
4722 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
|
4723 { |
|
7f284ac55b07
(encode_coding_emacs_mule): Pay attention to raw-8-bit chars.
Kenichi Handa <handa@m17n.org>
parents:
88681
diff
changeset
|
4724 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
|
4725 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
|
4726 } |
| 88365 | 4727 else |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4728 { |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4729 charset = char_charset (c, charset_list, &code); |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4730 if (charset) |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4731 { |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4732 if (CHARSET_DIMENSION (charset) == 1) |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4733 EMIT_ONE_BYTE (code); |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4734 else if (CHARSET_DIMENSION (charset) == 2) |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4735 EMIT_TWO_BYTES (code >> 8, code & 0xFF); |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4736 else if (CHARSET_DIMENSION (charset) == 3) |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4737 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
|
4738 else |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4739 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
|
4740 (code >> 8) & 0xFF, code & 0xFF); |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4741 } |
|
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4742 else |
|
88573
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4743 { |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4744 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
|
4745 c = CODING_INHIBIT_CHARACTER_SUBSTITUTION; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4746 else |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4747 c = coding->default_char; |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4748 EMIT_ONE_BYTE (c); |
|
133bf7ab1bad
(encode_coding_iso_2022): If coding requires safe
Kenichi Handa <handa@m17n.org>
parents:
88544
diff
changeset
|
4749 } |
|
88465
ae455bb40718
(decode_coding_charset, encode_coding_charset): Handle
Kenichi Handa <handa@m17n.org>
parents:
88456
diff
changeset
|
4750 } |
| 88365 | 4751 } |
| 4752 | |
| 4753 coding->result = CODING_RESULT_SUCCESS; | |
| 4754 coding->produced_char += produced_chars; | |
| 4755 coding->produced = dst - coding->destination; | |
| 4756 return 0; | |
| 17052 | 4757 } |
| 4758 | |
| 4759 | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
4760 /*** 7. C library functions ***/ |
| 17052 | 4761 |
| 88365 | 4762 /* Setup coding context CODING from information about CODING_SYSTEM. |
| 4763 If CODING_SYSTEM is nil, `no-conversion' is assumed. If | |
| 4764 CODING_SYSTEM is invalid, signal an error. */ | |
| 4765 | |
| 4766 void | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4767 setup_coding_system (coding_system, coding) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
4768 Lisp_Object coding_system; |
| 17052 | 4769 struct coding_system *coding; |
| 4770 { | |
| 88365 | 4771 Lisp_Object attrs; |
| 4772 Lisp_Object eol_type; | |
| 4773 Lisp_Object coding_type; | |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
4774 Lisp_Object val; |
| 17052 | 4775 |
|
24460
be35d27a4bfb
(setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents:
24425
diff
changeset
|
4776 if (NILP (coding_system)) |
| 88365 | 4777 coding_system = Qno_conversion; |
| 4778 | |
| 4779 CHECK_CODING_SYSTEM_GET_ID (coding_system, coding->id); | |
| 4780 | |
| 4781 attrs = CODING_ID_ATTRS (coding->id); | |
| 4782 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
| 4783 | |
| 4784 coding->mode = 0; | |
| 4785 coding->head_ascii = -1; | |
| 4786 coding->common_flags | |
| 4787 = (VECTORP (eol_type) ? CODING_REQUIRE_DETECTION_MASK : 0); | |
| 4788 | |
| 4789 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
| 4790 coding->max_charset_id = XSTRING (val)->size - 1; | |
| 4791 coding->safe_charsets = (char *) XSTRING (val)->data; | |
| 4792 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); | |
| 4793 | |
| 4794 coding_type = CODING_ATTR_TYPE (attrs); | |
| 4795 if (EQ (coding_type, Qundecided)) | |
| 4796 { | |
| 4797 coding->detector = NULL; | |
| 4798 coding->decoder = decode_coding_raw_text; | |
| 4799 coding->encoder = encode_coding_raw_text; | |
| 4800 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | |
| 4801 } | |
| 4802 else if (EQ (coding_type, Qiso_2022)) | |
| 4803 { | |
| 4804 int i; | |
| 4805 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4806 enum coding_category category = XINT (CODING_ATTR_CATEGORY (attrs)); |
| 88365 | 4807 |
| 4808 /* Invoke graphic register 0 to plane 0. */ | |
| 4809 CODING_ISO_INVOCATION (coding, 0) = 0; | |
| 4810 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ | |
| 4811 CODING_ISO_INVOCATION (coding, 1) | |
| 4812 = (flags & CODING_ISO_FLAG_SEVEN_BITS ? -1 : 1); | |
| 4813 /* Setup the initial status of designation. */ | |
| 4814 for (i = 0; i < 4; i++) | |
| 4815 CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); | |
| 4816 /* Not single shifting initially. */ | |
| 4817 CODING_ISO_SINGLE_SHIFTING (coding) = 0; | |
| 4818 /* Beginning of buffer should also be regarded as bol. */ | |
| 4819 CODING_ISO_BOL (coding) = 1; | |
| 4820 coding->detector = detect_coding_iso_2022; | |
| 4821 coding->decoder = decode_coding_iso_2022; | |
| 4822 coding->encoder = encode_coding_iso_2022; | |
| 4823 if (flags & CODING_ISO_FLAG_SAFE) | |
| 4824 coding->mode |= CODING_MODE_SAFE_ENCODING; | |
|
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4825 coding->common_flags |
| 88365 | 4826 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
| 4827 | CODING_REQUIRE_FLUSHING_MASK); | |
| 4828 if (flags & CODING_ISO_FLAG_COMPOSITION) | |
| 4829 coding->common_flags |= CODING_ANNOTATE_COMPOSITION_MASK; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4830 if (flags & CODING_ISO_FLAG_DESIGNATION) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
4831 coding->common_flags |= CODING_ANNOTATE_CHARSET_MASK; |
| 88365 | 4832 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
|
4833 { |
| 88365 | 4834 setup_iso_safe_charsets (attrs); |
| 4835 val = CODING_ATTR_SAFE_CHARSETS (attrs); | |
| 4836 coding->max_charset_id = XSTRING (val)->size - 1; | |
| 4837 coding->safe_charsets = (char *) XSTRING (val)->data; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
4838 } |
| 88365 | 4839 CODING_ISO_FLAGS (coding) = flags; |
| 4840 } | |
| 4841 else if (EQ (coding_type, Qcharset)) | |
| 4842 { | |
| 4843 coding->detector = detect_coding_charset; | |
| 4844 coding->decoder = decode_coding_charset; | |
| 4845 coding->encoder = encode_coding_charset; | |
| 4846 coding->common_flags | |
| 4847 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
| 4848 } | |
| 4849 else if (EQ (coding_type, Qutf_8)) | |
| 4850 { | |
| 4851 coding->detector = detect_coding_utf_8; | |
| 4852 coding->decoder = decode_coding_utf_8; | |
| 4853 coding->encoder = encode_coding_utf_8; | |
|
34888
b469d29c0815
(SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34813
diff
changeset
|
4854 coding->common_flags |
| 88365 | 4855 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
| 4856 } | |
| 4857 else if (EQ (coding_type, Qutf_16)) | |
| 4858 { | |
| 4859 val = AREF (attrs, coding_attr_utf_16_bom); | |
| 4860 CODING_UTF_16_BOM (coding) = (CONSP (val) ? utf_16_detect_bom | |
| 4861 : EQ (val, Qt) ? utf_16_with_bom | |
| 4862 : utf_16_without_bom); | |
| 4863 val = AREF (attrs, coding_attr_utf_16_endian); | |
| 4864 CODING_UTF_16_ENDIAN (coding) = (NILP (val) ? utf_16_big_endian | |
| 4865 : utf_16_little_endian); | |
|
88438
3a34b722dd71
(encode_coding_utf_8): Initialize produced_chars to 0.
Kenichi Handa <handa@m17n.org>
parents:
88430
diff
changeset
|
4866 CODING_UTF_16_SURROGATE (coding) = 0; |
| 88365 | 4867 coding->detector = detect_coding_utf_16; |
| 4868 coding->decoder = decode_coding_utf_16; | |
| 4869 coding->encoder = encode_coding_utf_16; | |
|
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4870 coding->common_flags |
| 88365 | 4871 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
| 4872 } | |
| 4873 else if (EQ (coding_type, Qccl)) | |
| 4874 { | |
| 4875 coding->detector = detect_coding_ccl; | |
| 4876 coding->decoder = decode_coding_ccl; | |
| 4877 coding->encoder = encode_coding_ccl; | |
|
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4878 coding->common_flags |
| 88365 | 4879 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK |
| 4880 | CODING_REQUIRE_FLUSHING_MASK); | |
| 4881 } | |
| 4882 else if (EQ (coding_type, Qemacs_mule)) | |
| 4883 { | |
| 4884 coding->detector = detect_coding_emacs_mule; | |
| 4885 coding->decoder = decode_coding_emacs_mule; | |
| 4886 coding->encoder = encode_coding_emacs_mule; | |
| 4887 coding->common_flags | |
| 4888 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
| 4889 if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) | |
| 4890 && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) | |
| 4891 { | |
| 4892 Lisp_Object tail, safe_charsets; | |
| 4893 int max_charset_id = 0; | |
| 4894 | |
| 4895 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
| 4896 tail = XCDR (tail)) | |
| 4897 if (max_charset_id < XFASTINT (XCAR (tail))) | |
| 4898 max_charset_id = XFASTINT (XCAR (tail)); | |
| 4899 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
| 4900 make_number (255)); | |
| 4901 for (tail = Vemacs_mule_charset_list; CONSP (tail); | |
| 4902 tail = XCDR (tail)) | |
| 4903 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
| 4904 coding->max_charset_id = max_charset_id; | |
| 4905 coding->safe_charsets = (char *) XSTRING (safe_charsets)->data; | |
| 4906 } | |
| 4907 } | |
| 4908 else if (EQ (coding_type, Qshift_jis)) | |
| 4909 { | |
| 4910 coding->detector = detect_coding_sjis; | |
| 4911 coding->decoder = decode_coding_sjis; | |
| 4912 coding->encoder = encode_coding_sjis; | |
| 4913 coding->common_flags | |
| 4914 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); | |
| 4915 } | |
| 4916 else if (EQ (coding_type, Qbig5)) | |
| 4917 { | |
| 4918 coding->detector = detect_coding_big5; | |
| 4919 coding->decoder = decode_coding_big5; | |
| 4920 coding->encoder = encode_coding_big5; | |
|
20227
71008f909642
(setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents:
20150
diff
changeset
|
4921 coding->common_flags |
| 88365 | 4922 |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); |
| 4923 } | |
| 4924 else /* EQ (coding_type, Qraw_text) */ | |
| 4925 { | |
| 4926 coding->detector = NULL; | |
| 4927 coding->decoder = decode_coding_raw_text; | |
| 4928 coding->encoder = encode_coding_raw_text; | |
| 4929 coding->common_flags |= CODING_FOR_UNIBYTE_MASK; | |
| 4930 } | |
| 4931 | |
| 4932 return; | |
| 17052 | 4933 } |
| 4934 | |
| 88365 | 4935 /* Return raw-text or one of its subsidiaries that has the same |
| 4936 eol_type as CODING-SYSTEM. */ | |
| 4937 | |
| 4938 Lisp_Object | |
| 4939 raw_text_coding_system (coding_system) | |
| 4940 Lisp_Object coding_system; | |
| 26847 | 4941 { |
|
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
4942 Lisp_Object spec, attrs; |
| 88365 | 4943 Lisp_Object eol_type, raw_text_eol_type; |
| 4944 | |
| 4945 spec = CODING_SYSTEM_SPEC (coding_system); | |
| 4946 attrs = AREF (spec, 0); | |
| 4947 | |
| 4948 if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text)) | |
| 4949 return coding_system; | |
| 4950 | |
| 4951 eol_type = AREF (spec, 2); | |
| 4952 if (VECTORP (eol_type)) | |
| 4953 return Qraw_text; | |
| 4954 spec = CODING_SYSTEM_SPEC (Qraw_text); | |
| 4955 raw_text_eol_type = AREF (spec, 2); | |
| 4956 return (EQ (eol_type, Qunix) ? AREF (raw_text_eol_type, 0) | |
| 4957 : EQ (eol_type, Qdos) ? AREF (raw_text_eol_type, 1) | |
| 4958 : AREF (raw_text_eol_type, 2)); | |
| 26847 | 4959 } |
| 4960 | |
| 88365 | 4961 |
| 4962 /* If CODING_SYSTEM doesn't specify end-of-line format but PARENT | |
| 4963 does, return one of the subsidiary that has the same eol-spec as | |
| 4964 PARENT. Otherwise, return CODING_SYSTEM. */ | |
| 4965 | |
| 4966 Lisp_Object | |
| 4967 coding_inherit_eol_type (coding_system, parent) | |
| 88473 | 4968 Lisp_Object coding_system, parent; |
|
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4969 { |
| 88365 | 4970 Lisp_Object spec, attrs, eol_type; |
| 4971 | |
| 4972 spec = CODING_SYSTEM_SPEC (coding_system); | |
| 4973 attrs = AREF (spec, 0); | |
| 4974 eol_type = AREF (spec, 2); | |
| 4975 if (VECTORP (eol_type)) | |
| 4976 { | |
| 4977 Lisp_Object parent_spec; | |
| 4978 Lisp_Object parent_eol_type; | |
| 4979 | |
| 4980 parent_spec | |
| 4981 = CODING_SYSTEM_SPEC (buffer_defaults.buffer_file_coding_system); | |
| 4982 parent_eol_type = AREF (parent_spec, 2); | |
| 4983 if (EQ (parent_eol_type, Qunix)) | |
| 4984 coding_system = AREF (eol_type, 0); | |
| 4985 else if (EQ (parent_eol_type, Qdos)) | |
| 4986 coding_system = AREF (eol_type, 1); | |
| 4987 else if (EQ (parent_eol_type, Qmac)) | |
| 4988 coding_system = AREF (eol_type, 2); | |
| 4989 } | |
| 4990 return coding_system; | |
|
22616
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4991 } |
|
c493ce6a31e4
(setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents:
22529
diff
changeset
|
4992 |
| 17052 | 4993 /* Emacs has a mechanism to automatically detect a coding system if it |
| 4994 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
| 4995 it's impossible to distinguish some coding systems accurately | |
| 4996 because they use the same range of codes. So, at first, coding | |
| 4997 systems are categorized into 7, those are: | |
| 4998 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
4999 o coding-category-emacs-mule |
| 17052 | 5000 |
| 5001 The category for a coding system which has the same code range | |
| 5002 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
|
5003 symbol) `emacs-mule' by default. |
| 17052 | 5004 |
| 5005 o coding-category-sjis | |
| 5006 | |
| 5007 The category for a coding system which has the same code range | |
| 5008 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
|
5009 symbol) `japanese-shift-jis' by default. |
| 17052 | 5010 |
| 5011 o coding-category-iso-7 | |
| 5012 | |
| 5013 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
|
5014 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
|
5015 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
|
5016 charsets. Assigned the coding-system (Lisp symbol) |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5017 `iso-2022-7bit' by default. |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5018 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5019 o coding-category-iso-7-tight |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5020 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5021 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
|
5022 encode/decode only the specified charsets. |
| 17052 | 5023 |
| 5024 o coding-category-iso-8-1 | |
| 5025 | |
| 5026 The category for a coding system which has the same code range | |
| 5027 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
|
5028 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
|
5029 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
|
5030 symbol) `iso-latin-1' by default. |
| 17052 | 5031 |
| 5032 o coding-category-iso-8-2 | |
| 5033 | |
| 5034 The category for a coding system which has the same code range | |
| 5035 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
|
5036 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
|
5037 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
|
5038 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
|
5039 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5040 o coding-category-iso-7-else |
| 17052 | 5041 |
| 5042 The category for a coding system which has the same code range | |
| 88365 | 5043 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
|
5044 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
|
5045 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
|
5046 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5047 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
|
5048 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
5049 The category for a coding system which has the same code range |
| 88365 | 5050 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
|
5051 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
|
5052 symbol) `iso-2022-8bit-ss2' by default. |
| 17052 | 5053 |
| 5054 o coding-category-big5 | |
| 5055 | |
| 5056 The category for a coding system which has the same code range | |
| 5057 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
|
5058 `cn-big5' by default. |
| 17052 | 5059 |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5060 o coding-category-utf-8 |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5061 |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5062 The category for a coding system which has the same code range |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5063 as UTF-8 (cf. RFC2279). Assigned the coding-system (Lisp |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5064 symbol) `utf-8' by default. |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5065 |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5066 o coding-category-utf-16-be |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5067 |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5068 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
|
5069 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
|
5070 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
|
5071 `utf-16-be' by default. |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5072 |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5073 o coding-category-utf-16-le |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5074 |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5075 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
|
5076 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
|
5077 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
|
5078 symbol) `utf-16-le' by default. |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5079 |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5080 o coding-category-ccl |
|
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5081 |
|
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5082 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
|
5083 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
|
5084 coding system is assigned. |
|
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
5085 |
| 17052 | 5086 o coding-category-binary |
| 5087 | |
| 5088 The category for a coding system not categorized in any of the | |
| 5089 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
|
5090 `no-conversion' by default. |
| 17052 | 5091 |
| 5092 Each of them is a Lisp symbol and the value is an actual | |
| 88365 | 5093 `coding-system's (this is also a Lisp symbol) assigned by a user. |
| 17052 | 5094 What Emacs does actually is to detect a category of coding system. |
| 5095 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
| 88365 | 5096 decide only one possible category, it selects a category of the |
| 17052 | 5097 highest priority. Priorities of categories are also specified by a |
| 5098 user in a Lisp variable `coding-category-list'. | |
| 5099 | |
| 5100 */ | |
| 5101 | |
| 88365 | 5102 #define EOL_SEEN_NONE 0 |
| 5103 #define EOL_SEEN_LF 1 | |
| 5104 #define EOL_SEEN_CR 2 | |
| 5105 #define EOL_SEEN_CRLF 4 | |
| 5106 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5107 /* Detect how end-of-line of a text of length SRC_BYTES pointed by |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5108 SOURCE is encoded. If CATEGORY is one of |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5109 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
|
5110 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
|
5111 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5112 Return one of EOL_SEEN_XXX. */ |
| 17052 | 5113 |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
5114 #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
|
5115 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5116 static int |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5117 detect_eol (source, src_bytes, category) |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5118 unsigned char *source; |
| 88365 | 5119 EMACS_INT src_bytes; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5120 enum coding_category category; |
| 17052 | 5121 { |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5122 unsigned char *src = source, *src_end = src + src_bytes; |
| 17052 | 5123 unsigned char c; |
| 88365 | 5124 int total = 0; |
| 5125 int eol_seen = EOL_SEEN_NONE; | |
| 5126 | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5127 if ((1 << category) & CATEGORY_MASK_UTF_16) |
| 88365 | 5128 { |
| 5129 int msb, lsb; | |
| 5130 | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5131 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
|
5132 | coding_category_utf_16_le_nosig); |
| 88365 | 5133 lsb = 1 - msb; |
| 5134 | |
| 5135 while (src + 1 < src_end) | |
| 17052 | 5136 { |
| 88365 | 5137 c = src[lsb]; |
| 5138 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
|
5139 { |
| 88365 | 5140 int this_eol; |
| 5141 | |
| 5142 if (c == '\n') | |
| 5143 this_eol = EOL_SEEN_LF; | |
| 5144 else if (src + 3 >= src_end | |
| 5145 || src[msb + 2] != 0 | |
| 5146 || src[lsb + 2] != '\n') | |
| 5147 this_eol = EOL_SEEN_CR; | |
| 5148 else | |
| 5149 this_eol = EOL_SEEN_CRLF; | |
| 5150 | |
| 5151 if (eol_seen == EOL_SEEN_NONE) | |
| 5152 /* This is the first end-of-line. */ | |
| 5153 eol_seen = this_eol; | |
| 5154 else if (eol_seen != this_eol) | |
| 5155 { | |
| 5156 /* The found type is different from what found before. */ | |
| 5157 eol_seen = EOL_SEEN_LF; | |
| 5158 break; | |
| 5159 } | |
| 5160 if (++total == MAX_EOL_CHECK_COUNT) | |
| 5161 break; | |
| 5162 } | |
| 5163 src += 2; | |
| 5164 } | |
| 5165 } | |
| 5166 else | |
| 5167 { | |
| 5168 while (src < src_end) | |
| 5169 { | |
| 5170 c = *src++; | |
| 5171 if (c == '\n' || c == '\r') | |
| 5172 { | |
| 5173 int this_eol; | |
| 5174 | |
| 5175 if (c == '\n') | |
| 5176 this_eol = EOL_SEEN_LF; | |
| 5177 else if (src >= src_end || *src != '\n') | |
| 5178 this_eol = EOL_SEEN_CR; | |
| 5179 else | |
| 5180 this_eol = EOL_SEEN_CRLF, src++; | |
| 5181 | |
| 5182 if (eol_seen == EOL_SEEN_NONE) | |
| 5183 /* This is the first end-of-line. */ | |
| 5184 eol_seen = this_eol; | |
| 5185 else if (eol_seen != this_eol) | |
| 5186 { | |
| 5187 /* The found type is different from what found before. */ | |
| 5188 eol_seen = EOL_SEEN_LF; | |
| 5189 break; | |
| 5190 } | |
| 5191 if (++total == MAX_EOL_CHECK_COUNT) | |
| 5192 break; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5193 } |
| 17052 | 5194 } |
| 5195 } | |
| 88365 | 5196 return eol_seen; |
| 17052 | 5197 } |
| 5198 | |
| 88365 | 5199 |
| 5200 static void | |
| 5201 adjust_coding_eol_type (coding, eol_seen) | |
| 5202 struct coding_system *coding; | |
| 5203 int eol_seen; | |
| 5204 { | |
|
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
5205 Lisp_Object eol_type; |
| 88365 | 5206 |
| 5207 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
| 5208 if (eol_seen & EOL_SEEN_LF) | |
| 5209 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); | |
|
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
5210 else if (eol_seen & EOL_SEEN_CRLF) |
| 88365 | 5211 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 1)); |
|
88862
108e2535280d
(adjust_coding_eol_type): Fix eol_type/eol_seen mixup.
Dave Love <fx@gnu.org>
parents:
88856
diff
changeset
|
5212 else if (eol_seen & EOL_SEEN_CR) |
| 88365 | 5213 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 2)); |
| 5214 } | |
| 5215 | |
| 5216 /* Detect how a text specified in CODING is encoded. If a coding | |
| 5217 system is detected, update fields of CODING by the detected coding | |
| 5218 system. */ | |
| 5219 | |
| 5220 void | |
| 5221 detect_coding (coding) | |
| 5222 struct coding_system *coding; | |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5223 { |
| 88365 | 5224 unsigned char *src, *src_end; |
| 5225 Lisp_Object attrs, coding_type; | |
| 5226 | |
| 5227 coding->consumed = coding->consumed_char = 0; | |
| 5228 coding->produced = coding->produced_char = 0; | |
| 5229 coding_set_source (coding); | |
| 5230 | |
| 5231 src_end = coding->source + coding->src_bytes; | |
| 5232 | |
| 5233 /* If we have not yet decided the text encoding type, detect it | |
| 5234 now. */ | |
| 5235 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) | |
| 5236 { | |
| 5237 int c, i; | |
| 5238 | |
| 5239 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
|
5240 { |
| 88365 | 5241 c = *src; |
| 5242 if (c & 0x80 || (c < 0x20 && (c == ISO_CODE_ESC | |
| 5243 || c == ISO_CODE_SI | |
| 5244 || c == ISO_CODE_SO))) | |
| 5245 break; | |
| 5246 } | |
| 5247 coding->head_ascii = src - (coding->source + coding->consumed); | |
| 5248 | |
| 5249 if (coding->head_ascii < coding->src_bytes) | |
| 5250 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5251 struct coding_detection_info detect_info; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5252 enum coding_category category; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5253 struct coding_system *this; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5254 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5255 detect_info.checked = detect_info.found = detect_info.rejected = 0; |
| 88365 | 5256 for (i = 0; i < coding_category_raw_text; i++) |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5257 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5258 category = coding_priorities[i]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5259 this = coding_categories + category; |
| 88365 | 5260 if (this->id < 0) |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5261 { |
| 88365 | 5262 /* No coding system of this category is defined. */ |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5263 detect_info.rejected |= (1 << category); |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5264 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5265 else if (category >= coding_category_raw_text) |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5266 continue; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5267 else if (detect_info.checked & (1 << category)) |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5268 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5269 if (detect_info.found & (1 << category)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5270 break; |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5271 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5272 else if ((*(this->detector)) (coding, &detect_info) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5273 && detect_info.found & (1 << category)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5274 break; |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5275 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5276 if (i < coding_category_raw_text) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5277 setup_coding_system (CODING_ID_NAME (this->id), coding); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5278 else if (detect_info.rejected == CATEGORY_MASK_ANY) |
| 88365 | 5279 setup_coding_system (Qraw_text, coding); |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5280 else if (detect_info.rejected) |
| 88365 | 5281 for (i = 0; i < coding_category_raw_text; i++) |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5282 if (! (detect_info.rejected & (1 << coding_priorities[i]))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5283 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5284 this = coding_categories + coding_priorities[i]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5285 setup_coding_system (CODING_ID_NAME (this->id), coding); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5286 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5287 } |
| 88365 | 5288 } |
| 5289 } | |
| 5290 | |
| 5291 attrs = CODING_ID_ATTRS (coding->id); | |
| 5292 coding_type = CODING_ATTR_TYPE (attrs); | |
| 5293 | |
| 5294 /* If we have not yet decided the EOL type, detect it now. But, the | |
| 5295 detection is impossible for a CCL based coding system, in which | |
| 5296 case, we detct the EOL type after decoding. */ | |
| 5297 if (VECTORP (CODING_ID_EOL_TYPE (coding->id)) | |
| 5298 && ! EQ (coding_type, Qccl)) | |
| 5299 { | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5300 int eol_seen = detect_eol (coding->source, coding->src_bytes, |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
5301 XINT (CODING_ATTR_CATEGORY (attrs))); |
| 88365 | 5302 |
| 5303 if (eol_seen != EOL_SEEN_NONE) | |
| 5304 adjust_coding_eol_type (coding, eol_seen); | |
| 5305 } | |
| 5306 } | |
| 5307 | |
| 5308 | |
| 5309 static void | |
| 5310 decode_eol (coding) | |
| 5311 struct coding_system *coding; | |
| 5312 { | |
| 5313 if (VECTORP (CODING_ID_EOL_TYPE (coding->id))) | |
| 5314 { | |
| 5315 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
| 5316 unsigned char *pend = p + coding->produced; | |
| 5317 int eol_seen = EOL_SEEN_NONE; | |
| 5318 | |
| 5319 for (; p < pend; p++) | |
| 5320 { | |
| 5321 if (*p == '\n') | |
| 5322 eol_seen |= EOL_SEEN_LF; | |
| 5323 else if (*p == '\r') | |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5324 { |
| 88365 | 5325 if (p + 1 < pend && *(p + 1) == '\n') |
| 5326 { | |
| 5327 eol_seen |= EOL_SEEN_CRLF; | |
| 5328 p++; | |
| 5329 } | |
| 5330 else | |
| 5331 eol_seen |= EOL_SEEN_CR; | |
|
28022
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5332 } |
|
6c41f3276340
Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents:
27943
diff
changeset
|
5333 } |
| 88365 | 5334 if (eol_seen != EOL_SEEN_NONE) |
| 5335 adjust_coding_eol_type (coding, eol_seen); | |
| 5336 } | |
| 5337 | |
| 5338 if (EQ (CODING_ID_EOL_TYPE (coding->id), Qmac)) | |
| 5339 { | |
| 5340 unsigned char *p = CHAR_POS_ADDR (coding->dst_pos); | |
| 5341 unsigned char *pend = p + coding->produced; | |
| 5342 | |
| 5343 for (; p < pend; p++) | |
| 5344 if (*p == '\r') | |
| 5345 *p = '\n'; | |
| 5346 } | |
| 5347 else if (EQ (CODING_ID_EOL_TYPE (coding->id), Qdos)) | |
| 5348 { | |
| 5349 unsigned char *p, *pbeg, *pend; | |
| 5350 Lisp_Object undo_list; | |
| 5351 | |
| 5352 move_gap_both (coding->dst_pos + coding->produced_char, | |
| 5353 coding->dst_pos_byte + coding->produced); | |
| 5354 undo_list = current_buffer->undo_list; | |
| 5355 current_buffer->undo_list = Qt; | |
| 88856 | 5356 del_range_2 (coding->dst_pos, coding->dst_pos_byte, GPT, GPT_BYTE, 0); |
| 88365 | 5357 current_buffer->undo_list = undo_list; |
| 5358 pbeg = GPT_ADDR; | |
| 5359 pend = pbeg + coding->produced; | |
| 5360 | |
| 5361 for (p = pend - 1; p >= pbeg; p--) | |
| 5362 if (*p == '\r') | |
| 5363 { | |
| 5364 safe_bcopy ((char *) (p + 1), (char *) p, pend - p - 1); | |
| 5365 pend--; | |
| 5366 } | |
| 5367 coding->produced_char -= coding->produced - (pend - pbeg); | |
| 5368 coding->produced = pend - pbeg; | |
| 5369 insert_from_gap (coding->produced_char, coding->produced); | |
| 17052 | 5370 } |
| 5371 } | |
| 5372 | |
| 88365 | 5373 static void |
| 5374 translate_chars (coding, table) | |
| 17052 | 5375 struct coding_system *coding; |
| 88365 | 5376 Lisp_Object table; |
| 17052 | 5377 { |
| 88365 | 5378 int *charbuf = coding->charbuf; |
| 5379 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 5380 int c; | |
| 5381 | |
| 5382 if (coding->chars_at_source) | |
| 5383 return; | |
| 5384 | |
| 5385 while (charbuf < charbuf_end) | |
| 5386 { | |
| 5387 c = *charbuf; | |
| 5388 if (c < 0) | |
| 5389 charbuf += c; | |
| 5390 else | |
| 5391 *charbuf++ = translate_char (table, c); | |
| 5392 } | |
| 17052 | 5393 } |
| 5394 | |
| 88365 | 5395 static int |
| 5396 produce_chars (coding) | |
| 5397 struct coding_system *coding; | |
| 17052 | 5398 { |
| 88365 | 5399 unsigned char *dst = coding->destination + coding->produced; |
| 5400 unsigned char *dst_end = coding->destination + coding->dst_bytes; | |
| 5401 int produced; | |
| 5402 int produced_chars = 0; | |
| 5403 | |
| 5404 if (! coding->chars_at_source) | |
| 5405 { | |
| 5406 /* Characters are in coding->charbuf. */ | |
| 5407 int *buf = coding->charbuf; | |
| 5408 int *buf_end = buf + coding->charbuf_used; | |
| 5409 unsigned char *adjusted_dst_end; | |
| 5410 | |
| 5411 if (BUFFERP (coding->src_object) | |
| 5412 && EQ (coding->src_object, coding->dst_object)) | |
| 5413 dst_end = coding->source + coding->consumed; | |
| 5414 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
| 5415 | |
| 5416 while (buf < buf_end) | |
| 5417 { | |
| 5418 int c = *buf++; | |
| 5419 | |
| 5420 if (dst >= adjusted_dst_end) | |
| 5421 { | |
| 5422 dst = alloc_destination (coding, | |
| 5423 buf_end - buf + MAX_MULTIBYTE_LENGTH, | |
| 5424 dst); | |
| 5425 dst_end = coding->destination + coding->dst_bytes; | |
| 5426 adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH; | |
| 5427 } | |
| 5428 if (c >= 0) | |
| 5429 { | |
| 5430 if (coding->dst_multibyte | |
| 5431 || ! CHAR_BYTE8_P (c)) | |
| 5432 CHAR_STRING_ADVANCE (c, dst); | |
| 5433 else | |
| 5434 *dst++ = CHAR_TO_BYTE8 (c); | |
| 5435 produced_chars++; | |
| 5436 } | |
| 5437 else | |
| 5438 /* This is an annotation data. */ | |
| 5439 buf -= c + 1; | |
| 5440 } | |
|
30833
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5441 } |
|
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5442 else |
|
2db6e42a6ba3
(MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents:
30756
diff
changeset
|
5443 { |
| 88365 | 5444 unsigned char *src = coding->source; |
| 5445 unsigned char *src_end = src + coding->src_bytes; | |
| 5446 Lisp_Object eol_type; | |
| 5447 | |
| 5448 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
| 5449 | |
| 5450 if (coding->src_multibyte != coding->dst_multibyte) | |
|
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5451 { |
| 88365 | 5452 if (coding->src_multibyte) |
|
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5453 { |
|
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5454 int multibytep = 1; |
| 88365 | 5455 int consumed_chars; |
| 5456 | |
| 5457 while (1) | |
|
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5458 { |
| 88365 | 5459 unsigned char *src_base = src; |
| 5460 int c; | |
| 5461 | |
| 5462 ONE_MORE_BYTE (c); | |
| 5463 if (c == '\r') | |
| 5464 { | |
| 5465 if (EQ (eol_type, Qdos)) | |
| 5466 { | |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5467 if (src == src_end) |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5468 { |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5469 coding->result = CODING_RESULT_INSUFFICIENT_SRC; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5470 goto no_more_source; |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5471 } |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5472 if (*src == '\n') |
| 88365 | 5473 c = *src++; |
| 5474 } | |
| 5475 else if (EQ (eol_type, Qmac)) | |
| 5476 c = '\n'; | |
| 5477 } | |
| 5478 if (dst == dst_end) | |
| 5479 { | |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5480 coding->consumed = src - coding->source; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5481 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5482 if (EQ (coding->src_object, coding->dst_object)) |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5483 dst_end = src; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5484 if (dst == dst_end) |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5485 { |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5486 dst = alloc_destination (coding, src_end - src + 1, |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5487 dst); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5488 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
|
5489 coding_set_source (coding); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5490 src = coding->source + coding->consumed; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5491 src_end = coding->source + coding->src_bytes; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5492 } |
| 88365 | 5493 } |
| 5494 *dst++ = c; | |
| 5495 produced_chars++; | |
| 5496 } | |
| 5497 no_more_source: | |
| 5498 ; | |
| 5499 } | |
| 5500 else | |
| 5501 while (src < src_end) | |
| 5502 { | |
|
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
5503 int multibytep = 1; |
| 88365 | 5504 int c = *src++; |
| 5505 | |
| 5506 if (c == '\r') | |
| 5507 { | |
| 5508 if (EQ (eol_type, Qdos)) | |
| 5509 { | |
| 5510 if (src < src_end | |
| 5511 && *src == '\n') | |
| 5512 c = *src++; | |
| 5513 } | |
| 5514 else if (EQ (eol_type, Qmac)) | |
| 5515 c = '\n'; | |
| 5516 } | |
| 5517 if (dst >= dst_end - 1) | |
| 5518 { | |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5519 coding->consumed = src - coding->source; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5520 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5521 if (EQ (coding->src_object, coding->dst_object)) |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5522 dst_end = src; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5523 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
|
5524 { |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5525 dst = alloc_destination (coding, src_end - src + 2, |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5526 dst); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5527 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
|
5528 coding_set_source (coding); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5529 src = coding->source + coding->consumed; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5530 src_end = coding->source + coding->src_bytes; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5531 } |
| 88365 | 5532 } |
| 5533 EMIT_ONE_BYTE (c); | |
| 5534 } | |
| 5535 } | |
| 5536 else | |
| 5537 { | |
| 5538 if (!EQ (coding->src_object, coding->dst_object)) | |
| 5539 { | |
| 5540 int require = coding->src_bytes - coding->dst_bytes; | |
| 5541 | |
| 5542 if (require > 0) | |
| 5543 { | |
| 5544 EMACS_INT offset = src - coding->source; | |
| 5545 | |
| 5546 dst = alloc_destination (coding, require, dst); | |
| 5547 coding_set_source (coding); | |
| 5548 src = coding->source + offset; | |
| 5549 src_end = coding->source + coding->src_bytes; | |
|
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5550 } |
|
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5551 } |
| 88365 | 5552 produced_chars = coding->src_chars; |
| 5553 while (src < src_end) | |
|
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5554 { |
| 88365 | 5555 int c = *src++; |
| 5556 | |
| 5557 if (c == '\r') | |
| 5558 { | |
| 5559 if (EQ (eol_type, Qdos)) | |
| 5560 { | |
| 5561 if (src < src_end | |
| 5562 && *src == '\n') | |
| 5563 c = *src++; | |
| 5564 produced_chars--; | |
| 5565 } | |
| 5566 else if (EQ (eol_type, Qmac)) | |
| 5567 c = '\n'; | |
| 5568 } | |
| 5569 *dst++ = c; | |
|
34892
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5570 } |
|
3868f2e7355a
(setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents:
34888
diff
changeset
|
5571 } |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5572 coding->consumed = coding->src_bytes; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
5573 coding->consumed_char = coding->src_chars; |
| 88365 | 5574 } |
| 5575 | |
| 5576 produced = dst - (coding->destination + coding->produced); | |
| 5577 if (BUFFERP (coding->dst_object)) | |
| 5578 insert_from_gap (produced_chars, produced); | |
| 5579 coding->produced += produced; | |
| 5580 coding->produced_char += produced_chars; | |
| 5581 return produced_chars; | |
| 5582 } | |
| 5583 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5584 /* 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
|
5585 CHARBUF. CHARBUF is an array: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5586 [ -LENGTH ANNOTATION_MASK FROM TO METHOD COMP_LEN [ COMPONENTS... ] ] |
| 88365 | 5587 */ |
| 5588 | |
| 5589 static INLINE void | |
| 5590 produce_composition (coding, charbuf) | |
| 5591 struct coding_system *coding; | |
| 5592 int *charbuf; | |
| 5593 { | |
| 5594 int len; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5595 EMACS_INT from, to; |
| 88365 | 5596 enum composition_method method; |
| 5597 Lisp_Object components; | |
| 5598 | |
| 5599 len = -charbuf[0]; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5600 from = coding->dst_pos + charbuf[2]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5601 to = coding->dst_pos + charbuf[3]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5602 method = (enum composition_method) (charbuf[4]); |
| 88365 | 5603 |
| 5604 if (method == COMPOSITION_RELATIVE) | |
| 5605 components = Qnil; | |
| 5606 else | |
| 5607 { | |
| 5608 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; | |
| 5609 int i; | |
| 5610 | |
| 5611 len -= 5; | |
| 5612 charbuf += 5; | |
| 5613 for (i = 0; i < len; i++) | |
| 5614 args[i] = make_number (charbuf[i]); | |
| 5615 components = (method == COMPOSITION_WITH_ALTCHARS | |
| 5616 ? Fstring (len, args) : Fvector (len, args)); | |
| 5617 } | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5618 compose_text (from, to, components, Qnil, coding->dst_object); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5619 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5620 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5621 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5622 /* 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
|
5623 the annotation data at CHARBUF. CHARBUF is an array: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5624 [ -LENGTH ANNOTATION_MASK FROM TO CHARSET-ID ] |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5625 */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5626 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5627 static INLINE void |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5628 produce_charset (coding, charbuf) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5629 struct coding_system *coding; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5630 int *charbuf; |
| 88365 | 5631 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5632 EMACS_INT from = coding->dst_pos + charbuf[2]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5633 EMACS_INT to = coding->dst_pos + charbuf[3]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5634 struct charset *charset = CHARSET_FROM_ID (charbuf[4]); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5635 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5636 Fput_text_property (make_number (from), make_number (to), |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5637 Qcharset, CHARSET_NAME (charset), |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5638 coding->dst_object); |
| 88365 | 5639 } |
| 5640 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5641 |
| 88365 | 5642 #define CHARBUF_SIZE 0x4000 |
| 5643 | |
| 5644 #define ALLOC_CONVERSION_WORK_AREA(coding) \ | |
| 5645 do { \ | |
| 5646 int size = CHARBUF_SIZE;; \ | |
| 5647 \ | |
| 5648 coding->charbuf = NULL; \ | |
| 5649 while (size > 1024) \ | |
| 5650 { \ | |
| 5651 coding->charbuf = (int *) alloca (sizeof (int) * size); \ | |
| 5652 if (coding->charbuf) \ | |
| 5653 break; \ | |
| 5654 size >>= 1; \ | |
| 5655 } \ | |
| 5656 if (! coding->charbuf) \ | |
| 5657 { \ | |
| 5658 coding->result = CODING_RESULT_INSUFFICIENT_MEM; \ | |
| 5659 return coding->result; \ | |
| 5660 } \ | |
| 5661 coding->charbuf_size = size; \ | |
| 5662 } while (0) | |
| 5663 | |
|
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5664 |
|
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5665 static void |
| 88365 | 5666 produce_annotation (coding) |
|
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5667 struct coding_system *coding; |
|
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5668 { |
| 88365 | 5669 int *charbuf = coding->charbuf; |
| 5670 int *charbuf_end = charbuf + coding->charbuf_used; | |
| 5671 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5672 if (NILP (coding->dst_object)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5673 return; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5674 |
| 88365 | 5675 while (charbuf < charbuf_end) |
| 5676 { | |
| 5677 if (*charbuf >= 0) | |
| 5678 charbuf++; | |
| 5679 else | |
|
29877
7b43e1fb478a
(decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents:
29725
diff
changeset
|
5680 { |
| 88365 | 5681 int len = -*charbuf; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5682 switch (charbuf[1]) |
|
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5683 { |
| 88365 | 5684 case CODING_ANNOTATE_COMPOSITION_MASK: |
| 5685 produce_composition (coding, charbuf); | |
| 5686 break; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5687 case CODING_ANNOTATE_CHARSET_MASK: |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5688 produce_charset (coding, charbuf); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5689 break; |
| 88365 | 5690 default: |
| 5691 abort (); | |
|
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5692 } |
| 88365 | 5693 charbuf += len; |
|
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5694 } |
|
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5695 } |
|
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5696 } |
|
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5697 |
| 88365 | 5698 /* Decode the data at CODING->src_object into CODING->dst_object. |
| 5699 CODING->src_object is a buffer, a string, or nil. | |
| 5700 CODING->dst_object is a buffer. | |
| 5701 | |
| 5702 If CODING->src_object is a buffer, it must be the current buffer. | |
| 5703 In this case, if CODING->src_pos is positive, it is a position of | |
| 5704 the source text in the buffer, otherwise, the source text is in the | |
| 5705 gap area of the buffer, and CODING->src_pos specifies the offset of | |
| 5706 the text from GPT (which must be the same as PT). If this is the | |
| 5707 same buffer as CODING->dst_object, CODING->src_pos must be | |
| 5708 negative. | |
| 5709 | |
| 5710 If CODING->src_object is a string, CODING->src_pos in an index to | |
| 5711 that string. | |
| 5712 | |
| 5713 If CODING->src_object is nil, CODING->source must already point to | |
| 5714 the non-relocatable memory area. In this case, CODING->src_pos is | |
| 5715 an offset from CODING->source. | |
| 5716 | |
| 5717 The decoded data is inserted at the current point of the buffer | |
| 5718 CODING->dst_object. | |
| 5719 */ | |
| 5720 | |
| 5721 static int | |
| 5722 decode_coding (coding) | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5723 struct coding_system *coding; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5724 { |
| 88365 | 5725 Lisp_Object attrs; |
| 5726 | |
| 5727 if (BUFFERP (coding->src_object) | |
| 5728 && coding->src_pos > 0 | |
| 5729 && coding->src_pos < GPT | |
| 5730 && coding->src_pos + coding->src_chars > GPT) | |
| 5731 move_gap_both (coding->src_pos, coding->src_pos_byte); | |
| 5732 | |
| 5733 if (BUFFERP (coding->dst_object)) | |
| 5734 { | |
| 5735 if (current_buffer != XBUFFER (coding->dst_object)) | |
| 5736 set_buffer_internal (XBUFFER (coding->dst_object)); | |
| 5737 if (GPT != PT) | |
| 5738 move_gap_both (PT, PT_BYTE); | |
| 5739 } | |
| 5740 | |
| 5741 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
|
5742 coding->produced = coding->produced_char = 0; |
| 88365 | 5743 coding->chars_at_source = 0; |
| 5744 coding->result = CODING_RESULT_SUCCESS; | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5745 coding->errors = 0; |
| 88365 | 5746 |
| 5747 ALLOC_CONVERSION_WORK_AREA (coding); | |
| 5748 | |
| 5749 attrs = CODING_ID_ATTRS (coding->id); | |
| 5750 | |
| 5751 do | |
| 5752 { | |
| 5753 coding_set_source (coding); | |
| 5754 coding->annotated = 0; | |
| 5755 (*(coding->decoder)) (coding); | |
| 5756 if (!NILP (CODING_ATTR_DECODE_TBL (attrs))) | |
|
89207
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
5757 translate_chars (coding, CODING_ATTR_DECODE_TBL (attrs)); |
|
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
5758 else if (!NILP (Vstandard_translation_table_for_decode)) |
|
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
5759 translate_chars (coding, Vstandard_translation_table_for_decode); |
| 88365 | 5760 coding_set_destination (coding); |
| 5761 produce_chars (coding); | |
| 5762 if (coding->annotated) | |
| 5763 produce_annotation (coding); | |
| 5764 } | |
| 5765 while (coding->consumed < coding->src_bytes | |
| 5766 && ! coding->result); | |
| 5767 | |
| 5768 if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qccl) | |
| 5769 && SYMBOLP (CODING_ID_EOL_TYPE (coding->id)) | |
| 5770 && ! EQ (CODING_ID_EOL_TYPE (coding->id), Qunix)) | |
| 5771 decode_eol (coding); | |
| 5772 | |
| 5773 coding->carryover_bytes = 0; | |
| 5774 if (coding->consumed < coding->src_bytes) | |
| 5775 { | |
| 5776 int nbytes = coding->src_bytes - coding->consumed; | |
| 5777 unsigned char *src; | |
| 5778 | |
| 5779 coding_set_source (coding); | |
| 5780 coding_set_destination (coding); | |
| 5781 src = coding->source + coding->consumed; | |
| 5782 | |
| 5783 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
|
5784 { |
| 88365 | 5785 /* Flush out unprocessed data as binary chars. We are sure |
| 5786 that the number of data is less than the size of | |
| 5787 coding->charbuf. */ | |
| 5788 while (nbytes-- > 0) | |
| 5789 { | |
| 5790 int c = *src++; | |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5791 |
|
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
5792 coding->charbuf[coding->charbuf_used++] = (c & 0x80 ? - c : c); |
| 88365 | 5793 } |
| 5794 produce_chars (coding); | |
|
29725
2bc397e9b09a
(setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents:
29663
diff
changeset
|
5795 } |
| 88365 | 5796 else |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5797 { |
| 88365 | 5798 /* Record unprocessed bytes in coding->carryover. We are |
| 5799 sure that the number of data is less than the size of | |
| 5800 coding->carryover. */ | |
| 5801 unsigned char *p = coding->carryover; | |
| 5802 | |
| 5803 coding->carryover_bytes = nbytes; | |
| 5804 while (nbytes-- > 0) | |
| 5805 *p++ = *src++; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5806 } |
| 88365 | 5807 coding->consumed = coding->src_bytes; |
| 5808 } | |
| 5809 | |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
5810 return coding->result; |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5811 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5812 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5813 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5814 /* Extract an annotation data from a composition starting at POS and |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5815 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
|
5816 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
|
5817 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
|
5818 next element of BUF. |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5819 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5820 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
|
5821 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
|
5822 return BUF. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5823 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5824 static INLINE int * |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5825 handle_composition_annotation (pos, limit, coding, buf, stop) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5826 EMACS_INT pos, limit; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5827 struct coding_system *coding; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5828 int *buf; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5829 EMACS_INT *stop; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5830 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5831 EMACS_INT start, end; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5832 Lisp_Object prop; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5833 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5834 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
|
5835 || end > limit) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5836 *stop = limit; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5837 else if (start > pos) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5838 *stop = start; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5839 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5840 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5841 if (start == pos) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5842 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5843 /* We found a composition. Store the corresponding |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5844 annotation data in BUF. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5845 int *head = buf; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5846 enum composition_method method = COMPOSITION_METHOD (prop); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5847 int nchars = COMPOSITION_LENGTH (prop); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5848 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5849 ADD_COMPOSITION_DATA (buf, 0, nchars, method); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5850 if (method != COMPOSITION_RELATIVE) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5851 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5852 Lisp_Object components; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5853 int len, i, i_byte; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5854 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5855 components = COMPOSITION_COMPONENTS (prop); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5856 if (VECTORP (components)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5857 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5858 len = XVECTOR (components)->size; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5859 for (i = 0; i < len; i++) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5860 *buf++ = XINT (AREF (components, i)); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5861 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5862 else if (STRINGP (components)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5863 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5864 len = XSTRING (components)->size; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5865 i = i_byte = 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5866 while (i < len) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5867 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5868 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
|
5869 buf++; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5870 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5871 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5872 else if (INTEGERP (components)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5873 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5874 len = 1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5875 *buf++ = XINT (components); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5876 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5877 else if (CONSP (components)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5878 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5879 for (len = 0; CONSP (components); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5880 len++, components = XCDR (components)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5881 *buf++ = XINT (XCAR (components)); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5882 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5883 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5884 abort (); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5885 *head -= len; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5886 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5887 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5888 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5889 if (find_composition (end, limit, &start, &end, &prop, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5890 coding->src_object) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5891 && end <= limit) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5892 *stop = start; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5893 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5894 *stop = limit; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5895 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5896 return buf; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5897 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5898 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5899 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5900 /* Extract an annotation data from a text property `charset' at POS of |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5901 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
|
5902 *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
|
5903 (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
|
5904 BUF. |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5905 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5906 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
|
5907 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
|
5908 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5909 static INLINE int * |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5910 handle_charset_annotation (pos, limit, coding, buf, stop) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5911 EMACS_INT pos, limit; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5912 struct coding_system *coding; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5913 int *buf; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5914 EMACS_INT *stop; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5915 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5916 Lisp_Object val, next; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5917 int id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5918 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5919 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
|
5920 if (! NILP (val) && CHARSETP (val)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5921 id = XINT (CHARSET_SYMBOL_ID (val)); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5922 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5923 id = -1; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5924 ADD_CHARSET_DATA (buf, 0, 0, id); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5925 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
|
5926 coding->src_object, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5927 make_number (limit)); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5928 *stop = XINT (next); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5929 return buf; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5930 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5931 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5932 |
| 88365 | 5933 static void |
| 5934 consume_chars (coding) | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5935 struct coding_system *coding; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5936 { |
| 88365 | 5937 int *buf = coding->charbuf; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5938 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
|
5939 const unsigned char *src = coding->source + coding->consumed; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5940 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
|
5941 EMACS_INT end_pos = coding->src_pos + coding->src_chars; |
| 88365 | 5942 int multibytep = coding->src_multibyte; |
| 5943 Lisp_Object eol_type; | |
| 5944 int c; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5945 EMACS_INT stop, stop_composition, stop_charset; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5946 int id; |
| 88365 | 5947 |
| 5948 eol_type = CODING_ID_EOL_TYPE (coding->id); | |
| 5949 if (VECTORP (eol_type)) | |
| 5950 eol_type = Qunix; | |
| 5951 | |
| 5952 /* Note: composition handling is not yet implemented. */ | |
| 5953 coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
| 5954 | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5955 if (coding->common_flags & CODING_ANNOTATE_COMPOSITION_MASK) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5956 stop = stop_composition = pos; |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5957 else |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5958 stop = stop_composition = end_pos; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5959 if (coding->common_flags & CODING_ANNOTATE_CHARSET_MASK) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5960 stop = stop_charset = pos; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5961 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5962 stop_charset = end_pos; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5963 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5964 /* Compensate for CRLF and annotation. */ |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5965 buf_end -= 1 + MAX_ANNOTATION_LENGTH; |
| 88365 | 5966 while (buf < buf_end) |
| 5967 { | |
| 5968 if (pos == stop) | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5969 { |
| 88365 | 5970 int *p; |
| 5971 | |
| 5972 if (pos == end_pos) | |
| 5973 break; | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5974 if (pos == stop_composition) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5975 buf = handle_composition_annotation (pos, end_pos, coding, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5976 buf, &stop_composition); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5977 if (pos == stop_charset) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5978 buf = handle_charset_annotation (pos, end_pos, coding, |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5979 buf, &stop_charset); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5980 stop = (stop_composition < stop_charset |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
5981 ? stop_composition : stop_charset); |
| 88365 | 5982 } |
| 5983 | |
| 5984 if (! multibytep) | |
| 5985 c = *src++; | |
| 5986 else | |
| 5987 c = STRING_CHAR_ADVANCE (src); | |
| 5988 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) | |
| 5989 c = '\n'; | |
| 5990 if (! EQ (eol_type, Qunix)) | |
| 5991 { | |
| 5992 if (c == '\n') | |
| 5993 { | |
| 5994 if (EQ (eol_type, Qdos)) | |
| 5995 *buf++ = '\r'; | |
| 5996 else | |
| 5997 c = '\r'; | |
| 5998 } | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
5999 } |
| 88365 | 6000 *buf++ = c; |
| 6001 pos++; | |
| 6002 } | |
| 6003 | |
| 6004 coding->consumed = src - coding->source; | |
| 6005 coding->consumed_char = pos - coding->src_pos; | |
| 6006 coding->charbuf_used = buf - coding->charbuf; | |
| 6007 coding->chars_at_source = 0; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6008 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6009 |
| 88365 | 6010 |
| 6011 /* Encode the text at CODING->src_object into CODING->dst_object. | |
| 6012 CODING->src_object is a buffer or a string. | |
| 6013 CODING->dst_object is a buffer or nil. | |
| 6014 | |
| 6015 If CODING->src_object is a buffer, it must be the current buffer. | |
| 6016 In this case, if CODING->src_pos is positive, it is a position of | |
| 6017 the source text in the buffer, otherwise. the source text is in the | |
| 6018 gap area of the buffer, and coding->src_pos specifies the offset of | |
| 6019 the text from GPT (which must be the same as PT). If this is the | |
| 6020 same buffer as CODING->dst_object, CODING->src_pos must be | |
| 6021 negative and CODING should not have `pre-write-conversion'. | |
| 6022 | |
| 6023 If CODING->src_object is a string, CODING should not have | |
| 6024 `pre-write-conversion'. | |
| 6025 | |
| 6026 If CODING->dst_object is a buffer, the encoded data is inserted at | |
| 6027 the current point of that buffer. | |
| 6028 | |
| 6029 If CODING->dst_object is nil, the encoded data is placed at the | |
| 6030 memory area specified by CODING->destination. */ | |
| 6031 | |
| 6032 static int | |
| 6033 encode_coding (coding) | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6034 struct coding_system *coding; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6035 { |
| 88365 | 6036 Lisp_Object attrs; |
| 6037 | |
| 6038 attrs = CODING_ID_ATTRS (coding->id); | |
| 6039 | |
| 6040 if (BUFFERP (coding->dst_object)) | |
| 6041 { | |
| 6042 set_buffer_internal (XBUFFER (coding->dst_object)); | |
| 6043 coding->dst_multibyte | |
| 6044 = ! NILP (current_buffer->enable_multibyte_characters); | |
| 6045 } | |
| 6046 | |
| 6047 coding->consumed = coding->consumed_char = 0; | |
| 6048 coding->produced = coding->produced_char = 0; | |
| 6049 coding->result = CODING_RESULT_SUCCESS; | |
| 6050 coding->errors = 0; | |
| 6051 | |
| 6052 ALLOC_CONVERSION_WORK_AREA (coding); | |
| 6053 | |
| 6054 do { | |
| 6055 coding_set_source (coding); | |
| 6056 consume_chars (coding); | |
| 6057 | |
| 6058 if (!NILP (CODING_ATTR_ENCODE_TBL (attrs))) | |
|
89207
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
6059 translate_chars (coding, CODING_ATTR_ENCODE_TBL (attrs)); |
|
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
6060 else if (!NILP (Vstandard_translation_table_for_encode)) |
|
c232917f49f7
(decode_coding): Fix args to translate_chars. Pay
Kenichi Handa <handa@m17n.org>
parents:
89193
diff
changeset
|
6061 translate_chars (coding, Vstandard_translation_table_for_encode); |
| 88365 | 6062 |
| 6063 coding_set_destination (coding); | |
| 6064 (*(coding->encoder)) (coding); | |
| 6065 } while (coding->consumed_char < coding->src_chars); | |
| 6066 | |
| 6067 if (BUFFERP (coding->dst_object)) | |
| 6068 insert_from_gap (coding->produced_char, coding->produced); | |
| 6069 | |
| 6070 return (coding->result); | |
| 6071 } | |
| 6072 | |
| 6073 /* Work buffer */ | |
| 6074 | |
| 6075 /* List of currently used working buffer. */ | |
| 6076 Lisp_Object Vcode_conversion_work_buf_list; | |
| 6077 | |
| 6078 /* A working buffer used by the top level conversion. */ | |
| 6079 Lisp_Object Vcode_conversion_reused_work_buf; | |
| 6080 | |
| 6081 | |
| 6082 /* Return a working buffer that can be freely used by the following | |
| 6083 code conversion. MULTIBYTEP specifies the multibyteness of the | |
| 6084 buffer. */ | |
| 6085 | |
| 6086 Lisp_Object | |
| 6087 make_conversion_work_buffer (multibytep) | |
| 6088 int multibytep; | |
| 6089 { | |
| 6090 struct buffer *current = current_buffer; | |
| 6091 Lisp_Object buf; | |
| 6092 | |
| 6093 if (NILP (Vcode_conversion_work_buf_list)) | |
| 6094 { | |
| 6095 if (NILP (Vcode_conversion_reused_work_buf)) | |
| 6096 Vcode_conversion_reused_work_buf | |
| 6097 = Fget_buffer_create (build_string (" *code-conversion-work*")); | |
| 6098 Vcode_conversion_work_buf_list | |
| 6099 = Fcons (Vcode_conversion_reused_work_buf, Qnil); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6100 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6101 else |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6102 { |
| 88856 | 6103 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); |
| 88365 | 6104 char str[128]; |
| 6105 | |
| 6106 sprintf (str, " *code-conversion-work*<%d>", depth); | |
| 6107 Vcode_conversion_work_buf_list | |
| 6108 = Fcons (Fget_buffer_create (build_string (str)), | |
| 6109 Vcode_conversion_work_buf_list); | |
| 6110 } | |
| 6111 | |
| 6112 buf = XCAR (Vcode_conversion_work_buf_list); | |
| 6113 set_buffer_internal (XBUFFER (buf)); | |
| 6114 current_buffer->undo_list = Qt; | |
| 6115 Ferase_buffer (); | |
|
88950
ad258ee59fbb
* coding.c (make_conversion_work_buffer): Adjusted for the change
Kenichi Handa <handa@m17n.org>
parents:
88936
diff
changeset
|
6116 Fset_buffer_multibyte (multibytep ? Qt : Qnil, Qnil); |
| 88365 | 6117 set_buffer_internal (current); |
| 6118 return buf; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6119 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6120 |
| 88365 | 6121 static struct coding_system *saved_coding; |
| 6122 | |
| 6123 Lisp_Object | |
| 6124 code_conversion_restore (info) | |
| 6125 Lisp_Object info; | |
|
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
6126 { |
| 88856 | 6127 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); |
| 88365 | 6128 Lisp_Object buf; |
| 6129 | |
| 6130 if (depth > 0) | |
| 6131 { | |
| 6132 buf = XCAR (Vcode_conversion_work_buf_list); | |
| 6133 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); | |
| 6134 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) | |
| 6135 Fkill_buffer (buf); | |
| 6136 } | |
| 6137 | |
| 88856 | 6138 if (EQ (saved_coding->dst_object, Qt) |
| 88365 | 6139 && saved_coding->destination) |
| 6140 xfree (saved_coding->destination); | |
| 6141 | |
| 6142 return save_excursion_restore (info); | |
|
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
6143 } |
|
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
6144 |
| 88365 | 6145 |
| 6146 int | |
| 6147 decode_coding_gap (coding, chars, bytes) | |
| 26847 | 6148 struct coding_system *coding; |
| 88365 | 6149 EMACS_INT chars, bytes; |
| 6150 { | |
| 6151 int count = specpdl_ptr - specpdl; | |
| 6152 | |
| 6153 saved_coding = coding; | |
| 6154 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
| 6155 | |
| 6156 coding->src_object = Fcurrent_buffer (); | |
| 6157 coding->src_chars = chars; | |
| 6158 coding->src_bytes = bytes; | |
| 6159 coding->src_pos = -chars; | |
| 6160 coding->src_pos_byte = -bytes; | |
| 6161 coding->src_multibyte = chars < bytes; | |
| 6162 coding->dst_object = coding->src_object; | |
| 6163 coding->dst_pos = PT; | |
| 6164 coding->dst_pos_byte = PT_BYTE; | |
|
88443
6b86cf30a0b9
(produce_chars): Set the variable `multibytep' correctly.
Kenichi Handa <handa@m17n.org>
parents:
88438
diff
changeset
|
6165 coding->dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
|
89279
1fd77c471ee6
(decode_coding_utf_8): When eol_type is Qdos, handle
Kenichi Handa <handa@m17n.org>
parents:
89227
diff
changeset
|
6166 coding->mode |= CODING_MODE_LAST_BLOCK; |
| 88365 | 6167 |
| 6168 if (CODING_REQUIRE_DETECTION (coding)) | |
| 6169 detect_coding (coding); | |
| 6170 | |
| 6171 decode_coding (coding); | |
| 6172 | |
| 6173 unbind_to (count, Qnil); | |
| 6174 return coding->result; | |
| 6175 } | |
| 6176 | |
| 6177 int | |
| 6178 encode_coding_gap (coding, chars, bytes) | |
| 6179 struct coding_system *coding; | |
| 6180 EMACS_INT chars, bytes; | |
| 26847 | 6181 { |
| 88365 | 6182 int count = specpdl_ptr - specpdl; |
| 6183 Lisp_Object buffer; | |
| 6184 | |
| 6185 saved_coding = coding; | |
| 6186 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
| 6187 | |
| 6188 buffer = Fcurrent_buffer (); | |
| 6189 coding->src_object = buffer; | |
| 6190 coding->src_chars = chars; | |
| 6191 coding->src_bytes = bytes; | |
| 6192 coding->src_pos = -chars; | |
| 6193 coding->src_pos_byte = -bytes; | |
| 6194 coding->src_multibyte = chars < bytes; | |
| 6195 coding->dst_object = coding->src_object; | |
| 6196 coding->dst_pos = PT; | |
| 6197 coding->dst_pos_byte = PT_BYTE; | |
| 6198 | |
| 6199 encode_coding (coding); | |
| 6200 | |
| 6201 unbind_to (count, Qnil); | |
| 6202 return coding->result; | |
| 26847 | 6203 } |
| 6204 | |
| 88365 | 6205 |
| 6206 /* Decode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | |
| 6207 SRC_OBJECT into DST_OBJECT by coding context CODING. | |
| 6208 | |
| 6209 SRC_OBJECT is a buffer, a string, or Qnil. | |
| 6210 | |
| 6211 If it is a buffer, the text is at point of the buffer. FROM and TO | |
| 6212 are positions in the buffer. | |
| 6213 | |
| 6214 If it is a string, the text is at the beginning of the string. | |
| 6215 FROM and TO are indices to the string. | |
| 6216 | |
| 6217 If it is nil, the text is at coding->source. FROM and TO are | |
| 6218 indices to coding->source. | |
| 6219 | |
| 6220 DST_OBJECT is a buffer, Qt, or Qnil. | |
| 6221 | |
| 6222 If it is a buffer, the decoded text is inserted at point of the | |
| 6223 buffer. If the buffer is the same as SRC_OBJECT, the source text | |
| 6224 is deleted. | |
| 6225 | |
| 6226 If it is Qt, a string is made from the decoded text, and | |
| 6227 set in CODING->dst_object. | |
| 6228 | |
| 6229 If it is Qnil, the decoded text is stored at CODING->destination. | |
| 6230 The called must allocate CODING->dst_bytes bytes at | |
| 6231 CODING->destination by xmalloc. If the decoded text is longer than | |
| 6232 CODING->dst_bytes, CODING->destination is relocated by xrealloc. | |
| 6233 */ | |
| 26847 | 6234 |
|
29275
b4ea9178e480
(DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents:
29247
diff
changeset
|
6235 void |
| 88365 | 6236 decode_coding_object (coding, src_object, from, from_byte, to, to_byte, |
| 6237 dst_object) | |
| 26847 | 6238 struct coding_system *coding; |
| 88365 | 6239 Lisp_Object src_object; |
| 6240 EMACS_INT from, from_byte, to, to_byte; | |
| 6241 Lisp_Object dst_object; | |
| 26847 | 6242 { |
| 88365 | 6243 int count = specpdl_ptr - specpdl; |
| 6244 unsigned char *destination; | |
| 6245 EMACS_INT dst_bytes; | |
| 6246 EMACS_INT chars = to - from; | |
| 6247 EMACS_INT bytes = to_byte - from_byte; | |
| 6248 Lisp_Object attrs; | |
| 6249 | |
| 6250 saved_coding = coding; | |
| 6251 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
| 6252 | |
| 6253 if (NILP (dst_object)) | |
| 6254 { | |
| 6255 destination = coding->destination; | |
| 6256 dst_bytes = coding->dst_bytes; | |
| 6257 } | |
| 6258 | |
| 6259 coding->src_object = src_object; | |
| 6260 coding->src_chars = chars; | |
| 6261 coding->src_bytes = bytes; | |
| 6262 coding->src_multibyte = chars < bytes; | |
| 6263 | |
| 6264 if (STRINGP (src_object)) | |
| 6265 { | |
| 6266 coding->src_pos = from; | |
| 6267 coding->src_pos_byte = from_byte; | |
| 6268 } | |
| 6269 else if (BUFFERP (src_object)) | |
| 6270 { | |
| 6271 set_buffer_internal (XBUFFER (src_object)); | |
| 6272 if (from != GPT) | |
| 6273 move_gap_both (from, from_byte); | |
| 6274 if (EQ (src_object, dst_object)) | |
| 26847 | 6275 { |
| 88365 | 6276 TEMP_SET_PT_BOTH (from, from_byte); |
| 6277 del_range_both (from, from_byte, to, to_byte, 1); | |
| 6278 coding->src_pos = -chars; | |
| 6279 coding->src_pos_byte = -bytes; | |
|
20931
068eb408c911
(decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents:
20803
diff
changeset
|
6280 } |
|
42661
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
6281 else |
|
e85e4d9494b1
(code_convert_region): Don't copy old text if undo disabled.
Richard M. Stallman <rms@gnu.org>
parents:
42105
diff
changeset
|
6282 { |
| 88365 | 6283 coding->src_pos = from; |
| 6284 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
|
6285 } |
| 88365 | 6286 } |
| 6287 | |
| 6288 if (CODING_REQUIRE_DETECTION (coding)) | |
| 6289 detect_coding (coding); | |
| 6290 attrs = CODING_ID_ATTRS (coding->id); | |
| 6291 | |
| 6292 if (! NILP (CODING_ATTR_POST_READ (attrs)) | |
| 6293 || EQ (dst_object, Qt)) | |
| 6294 { | |
| 6295 coding->dst_object = make_conversion_work_buffer (1); | |
| 6296 coding->dst_pos = BEG; | |
| 6297 coding->dst_pos_byte = BEG_BYTE; | |
| 6298 coding->dst_multibyte = 1; | |
| 6299 } | |
| 6300 else if (BUFFERP (dst_object)) | |
| 6301 { | |
| 6302 coding->dst_object = dst_object; | |
| 6303 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | |
| 6304 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); | |
| 6305 coding->dst_multibyte | |
| 6306 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
| 6307 } | |
| 6308 else | |
| 6309 { | |
| 6310 coding->dst_object = Qnil; | |
| 6311 coding->dst_multibyte = 1; | |
| 6312 } | |
| 6313 | |
| 6314 decode_coding (coding); | |
| 6315 | |
| 6316 if (BUFFERP (coding->dst_object)) | |
| 6317 set_buffer_internal (XBUFFER (coding->dst_object)); | |
| 6318 | |
| 6319 if (! NILP (CODING_ATTR_POST_READ (attrs))) | |
| 6320 { | |
| 6321 struct gcpro gcpro1, gcpro2; | |
| 6322 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; | |
| 6323 Lisp_Object val; | |
| 6324 | |
|
88506
a7f0d13affa5
(decode_coding_object): Move point to coding->dst_pos before
Kenichi Handa <handa@m17n.org>
parents:
88497
diff
changeset
|
6325 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); |
| 88365 | 6326 GCPRO2 (coding->src_object, coding->dst_object); |
| 6327 val = call1 (CODING_ATTR_POST_READ (attrs), | |
| 6328 make_number (coding->produced_char)); | |
| 6329 UNGCPRO; | |
| 6330 CHECK_NATNUM (val); | |
| 6331 coding->produced_char += Z - prev_Z; | |
| 6332 coding->produced += Z_BYTE - prev_Z_BYTE; | |
| 6333 } | |
| 6334 | |
| 6335 if (EQ (dst_object, Qt)) | |
| 6336 { | |
| 6337 coding->dst_object = Fbuffer_string (); | |
| 6338 } | |
| 6339 else if (NILP (dst_object) && BUFFERP (coding->dst_object)) | |
| 6340 { | |
| 6341 set_buffer_internal (XBUFFER (coding->dst_object)); | |
| 6342 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
|
6343 { |
| 88365 | 6344 destination |
| 6345 = (unsigned char *) xrealloc (destination, coding->produced); | |
| 6346 if (! destination) | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6347 { |
| 88365 | 6348 coding->result = CODING_RESULT_INSUFFICIENT_DST; |
| 6349 unbind_to (count, Qnil); | |
| 6350 return; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6351 } |
| 88365 | 6352 if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
| 6353 move_gap_both (BEGV, BEGV_BYTE); | |
| 6354 bcopy (BEGV_ADDR, destination, coding->produced); | |
| 6355 coding->destination = destination; | |
|
23279
ca159e828a68
(ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents:
23258
diff
changeset
|
6356 } |
| 88365 | 6357 } |
| 6358 | |
| 6359 unbind_to (count, Qnil); | |
| 6360 } | |
| 6361 | |
| 6362 | |
| 6363 void | |
| 6364 encode_coding_object (coding, src_object, from, from_byte, to, to_byte, | |
| 6365 dst_object) | |
| 6366 struct coding_system *coding; | |
| 6367 Lisp_Object src_object; | |
| 6368 EMACS_INT from, from_byte, to, to_byte; | |
| 6369 Lisp_Object dst_object; | |
| 6370 { | |
| 6371 int count = specpdl_ptr - specpdl; | |
| 6372 EMACS_INT chars = to - from; | |
| 6373 EMACS_INT bytes = to_byte - from_byte; | |
| 6374 Lisp_Object attrs; | |
| 6375 | |
| 6376 saved_coding = coding; | |
| 6377 record_unwind_protect (code_conversion_restore, save_excursion_save ()); | |
| 6378 | |
| 6379 coding->src_object = src_object; | |
| 6380 coding->src_chars = chars; | |
| 6381 coding->src_bytes = bytes; | |
| 6382 coding->src_multibyte = chars < bytes; | |
| 6383 | |
| 6384 attrs = CODING_ID_ATTRS (coding->id); | |
| 6385 | |
| 6386 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
|
6387 { |
| 88365 | 6388 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); |
| 6389 set_buffer_internal (XBUFFER (coding->src_object)); | |
| 6390 if (STRINGP (src_object)) | |
| 6391 insert_from_string (src_object, from, from_byte, chars, bytes, 0); | |
| 6392 else if (BUFFERP (src_object)) | |
| 6393 insert_from_buffer (XBUFFER (src_object), from, chars, 0); | |
| 6394 else | |
| 6395 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); | |
| 6396 | |
| 6397 if (EQ (src_object, dst_object)) | |
| 6398 { | |
| 6399 set_buffer_internal (XBUFFER (src_object)); | |
| 6400 del_range_both (from, from_byte, to, to_byte, 1); | |
| 6401 set_buffer_internal (XBUFFER (coding->src_object)); | |
| 6402 } | |
| 6403 | |
|
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6404 call2 (CODING_ATTR_PRE_WRITE (attrs), |
|
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6405 make_number (BEG), make_number (Z)); |
|
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6406 coding->src_object = Fcurrent_buffer (); |
| 88365 | 6407 if (BEG != GPT) |
| 6408 move_gap_both (BEG, BEG_BYTE); | |
| 6409 coding->src_chars = Z - BEG; | |
| 6410 coding->src_bytes = Z_BYTE - BEG_BYTE; | |
| 6411 coding->src_pos = BEG; | |
| 6412 coding->src_pos_byte = BEG_BYTE; | |
| 6413 coding->src_multibyte = Z < Z_BYTE; | |
| 6414 } | |
| 6415 else if (STRINGP (src_object)) | |
| 6416 { | |
| 6417 coding->src_pos = from; | |
| 6418 coding->src_pos_byte = from_byte; | |
| 6419 } | |
| 6420 else if (BUFFERP (src_object)) | |
| 6421 { | |
| 6422 set_buffer_internal (XBUFFER (src_object)); | |
| 6423 if (EQ (src_object, dst_object)) | |
| 6424 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6425 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
|
6426 coding->src_pos = 0; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6427 coding->src_pos_byte = 0; |
| 88365 | 6428 } |
|
23514
7bad909cd6f1
(setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents:
23475
diff
changeset
|
6429 else |
| 88365 | 6430 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6431 if (from < GPT && to >= GPT) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6432 move_gap_both (from, from_byte); |
| 88365 | 6433 coding->src_pos = from; |
| 6434 coding->src_pos_byte = from_byte; | |
| 6435 } | |
| 6436 } | |
| 6437 | |
| 6438 if (BUFFERP (dst_object)) | |
| 6439 { | |
| 6440 coding->dst_object = dst_object; | |
|
89042
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6441 if (EQ (src_object, dst_object)) |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6442 { |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6443 coding->dst_pos = from; |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6444 coding->dst_pos_byte = from_byte; |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6445 } |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6446 else |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6447 { |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6448 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6449 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); |
|
2b9f8973f240
(coding_set_destination): Fix coding->destination for
Kenichi Handa <handa@m17n.org>
parents:
88977
diff
changeset
|
6450 } |
| 88365 | 6451 coding->dst_multibyte |
| 6452 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); | |
| 6453 } | |
| 6454 else if (EQ (dst_object, Qt)) | |
| 6455 { | |
| 6456 coding->dst_object = Qnil; | |
| 6457 coding->dst_bytes = coding->src_chars; | |
|
88510
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6458 if (coding->dst_bytes == 0) |
|
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6459 coding->dst_bytes = 1; |
|
d266b8fb8761
(encode_coding_object): Give correct arguments ot
Kenichi Handa <handa@m17n.org>
parents:
88506
diff
changeset
|
6460 coding->destination = (unsigned char *) xmalloc (coding->dst_bytes); |
| 88365 | 6461 coding->dst_multibyte = 0; |
| 6462 } | |
| 6463 else | |
| 6464 { | |
| 6465 coding->dst_object = Qnil; | |
| 6466 coding->dst_multibyte = 0; | |
| 6467 } | |
| 6468 | |
| 6469 encode_coding (coding); | |
| 6470 | |
| 6471 if (EQ (dst_object, Qt)) | |
| 6472 { | |
| 6473 if (BUFFERP (coding->dst_object)) | |
| 6474 coding->dst_object = Fbuffer_string (); | |
| 6475 else | |
| 6476 { | |
| 6477 coding->dst_object | |
| 6478 = make_unibyte_string ((char *) coding->destination, | |
| 6479 coding->produced); | |
| 6480 xfree (coding->destination); | |
| 6481 } | |
| 6482 } | |
| 6483 | |
| 6484 unbind_to (count, Qnil); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6485 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6486 |
|
29005
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6487 |
|
b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents:
28512
diff
changeset
|
6488 Lisp_Object |
| 88365 | 6489 preferred_coding_system () |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6490 { |
| 88365 | 6491 int id = coding_categories[coding_priorities[0]].id; |
| 6492 | |
| 6493 return CODING_ID_NAME (id); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6494 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6495 |
| 17052 | 6496 |
| 6497 #ifdef emacs | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
6498 /*** 8. Emacs Lisp library functions ***/ |
| 17052 | 6499 |
| 6500 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
|
6501 doc: /* Return t if OBJECT is nil or a coding-system. |
| 88365 | 6502 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
|
6503 about coding-system objects. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6504 (obj) |
| 17052 | 6505 Lisp_Object obj; |
| 6506 { | |
| 88365 | 6507 return ((NILP (obj) || CODING_SYSTEM_P (obj)) ? Qt : Qnil); |
| 17052 | 6508 } |
| 6509 | |
|
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6510 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
|
6511 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
|
6512 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
|
6513 (prompt) |
| 17052 | 6514 Lisp_Object prompt; |
| 6515 { | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6516 Lisp_Object val; |
|
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6517 do |
|
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6518 { |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6519 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
|
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6520 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
|
6521 } |
|
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
6522 while (XSTRING (val)->size == 0); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6523 return (Fintern (val, Qnil)); |
| 17052 | 6524 } |
| 6525 | |
|
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6526 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
|
6527 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
|
6528 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6529 (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
|
6530 Lisp_Object prompt, default_coding_system; |
| 17052 | 6531 { |
|
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
6532 Lisp_Object val; |
|
19758
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6533 if (SYMBOLP (default_coding_system)) |
|
49a1662b68dd
(Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents:
19750
diff
changeset
|
6534 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
6535 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
|
6536 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
|
6537 default_coding_system, Qnil); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
6538 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
| 17052 | 6539 } |
| 6540 | |
| 6541 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
| 6542 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
|
6543 doc: /* Check validity of CODING-SYSTEM. |
| 89218 | 6544 If valid, return CODING-SYSTEM, else signal a `coding-system-error' error. */) |
| 88365 | 6545 (coding_system) |
| 17052 | 6546 Lisp_Object coding_system; |
| 6547 { | |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6548 CHECK_SYMBOL (coding_system); |
| 17052 | 6549 if (!NILP (Fcoding_system_p (coding_system))) |
| 6550 return coding_system; | |
| 6551 while (1) | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
6552 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
| 17052 | 6553 } |
| 88365 | 6554 |
|
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
6555 |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6556 /* 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
|
6557 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
|
6558 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
|
6559 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
|
6560 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
|
6561 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
|
6562 Otherwise, the bytes are raw bytes. |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6563 |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6564 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
|
6565 |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6566 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
|
6567 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
|
6568 (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
|
6569 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
|
6570 detect only text-format. */ |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6571 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6572 Lisp_Object |
| 88365 | 6573 detect_coding_system (src, src_bytes, highest, multibytep, coding_system) |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6574 unsigned char *src; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6575 int src_bytes, highest; |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6576 int multibytep; |
| 88365 | 6577 Lisp_Object coding_system; |
| 17052 | 6578 { |
| 88365 | 6579 unsigned char *src_end = src + src_bytes; |
| 6580 int mask = CATEGORY_MASK_ANY; | |
| 6581 Lisp_Object attrs, eol_type; | |
| 6582 Lisp_Object val; | |
| 6583 struct coding_system coding; | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6584 int id; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6585 struct coding_detection_info detect_info; |
| 88365 | 6586 |
| 6587 if (NILP (coding_system)) | |
| 6588 coding_system = Qundecided; | |
| 6589 setup_coding_system (coding_system, &coding); | |
| 6590 attrs = CODING_ID_ATTRS (coding.id); | |
| 6591 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
|
6592 coding_system = CODING_ATTR_BASE_NAME (attrs); |
| 88365 | 6593 |
| 6594 coding.source = src; | |
| 6595 coding.src_bytes = src_bytes; | |
| 6596 coding.src_multibyte = multibytep; | |
| 6597 coding.consumed = 0; | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6598 coding.mode |= CODING_MODE_LAST_BLOCK; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6599 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6600 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
|
6601 |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6602 /* At first, detect text-format if necessary. */ |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6603 if (XINT (CODING_ATTR_CATEGORY (attrs)) == coding_category_undecided) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6604 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6605 enum coding_category category; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6606 struct coding_system *this; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6607 int c, i; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6608 |
| 88365 | 6609 for (; src < src_end; src++) |
| 17052 | 6610 { |
| 88365 | 6611 c = *src; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6612 if (c & 0x80 |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6613 || (c < 0x20 && (c == ISO_CODE_ESC |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6614 || c == ISO_CODE_SI |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
6615 || c == ISO_CODE_SO))) |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6616 break; |
| 17052 | 6617 } |
| 88365 | 6618 coding.head_ascii = src - coding.source; |
| 6619 | |
| 6620 if (src < src_end) | |
| 6621 for (i = 0; i < coding_category_raw_text; i++) | |
| 6622 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6623 category = coding_priorities[i]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6624 this = coding_categories + category; |
| 88365 | 6625 |
| 6626 if (this->id < 0) | |
| 6627 { | |
| 6628 /* No coding system of this category is defined. */ | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6629 detect_info.rejected |= (1 << category); |
| 88365 | 6630 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6631 else if (category >= coding_category_raw_text) |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6632 continue; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6633 else if (detect_info.checked & (1 << category)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6634 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6635 if (highest |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6636 && (detect_info.found & (1 << category))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6637 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6638 } |
| 88365 | 6639 else |
| 6640 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6641 if ((*(this->detector)) (&coding, &detect_info) |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6642 && highest |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6643 && (detect_info.found & (1 << category))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6644 break; |
| 88365 | 6645 } |
| 6646 } | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6647 |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6648 |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6649 if (detect_info.rejected == CATEGORY_MASK_ANY) |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6650 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6651 detect_info.found = CATEGORY_MASK_RAW_TEXT; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6652 id = coding_categories[coding_category_raw_text].id; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6653 val = Fcons (make_number (id), Qnil); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6654 } |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6655 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
|
6656 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6657 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
|
6658 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
|
6659 val = Fcons (make_number (id), Qnil); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6660 } |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6661 else if (highest) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6662 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6663 if (detect_info.found) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6664 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6665 detect_info.found = 1 << category; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6666 val = Fcons (make_number (this->id), Qnil); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6667 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6668 else |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6669 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
|
6670 if (! (detect_info.rejected & (1 << coding_priorities[i]))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6671 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6672 detect_info.found = 1 << coding_priorities[i]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6673 id = coding_categories[coding_priorities[i]].id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6674 val = Fcons (make_number (id), Qnil); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6675 break; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6676 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6677 } |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6678 else |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6679 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6680 int mask = detect_info.rejected | detect_info.found; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6681 int found = 0; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6682 val = Qnil; |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6683 |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6684 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
|
6685 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6686 category = coding_priorities[i]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6687 if (! (mask & (1 << category))) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6688 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6689 found |= 1 << category; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6690 id = coding_categories[category].id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6691 val = Fcons (make_number (id), val); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6692 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6693 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6694 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
|
6695 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6696 category = coding_priorities[i]; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6697 if (detect_info.found & (1 << category)) |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6698 { |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6699 id = coding_categories[category].id; |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6700 val = Fcons (make_number (id), val); |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6701 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6702 } |
|
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6703 detect_info.found |= found; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6704 } |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6705 } |
| 88365 | 6706 else |
| 6707 { | |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6708 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
|
6709 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
|
6710 } |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6711 |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6712 /* Then, detect eol-format if necessary. */ |
| 88365 | 6713 { |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6714 int normal_eol = -1, utf_16_be_eol = -1, utf_16_le_eol; |
| 88365 | 6715 Lisp_Object tail; |
| 6716 | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6717 if (VECTORP (eol_type)) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6718 { |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6719 if (detect_info.found & ~CATEGORY_MASK_UTF_16) |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6720 normal_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
|
6721 coding_category_raw_text); |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6722 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
|
6723 | 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
|
6724 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
|
6725 coding_category_utf_16_be); |
|
89331
1892a75ffcac
(CATEGORY_MASK_RAW_TEXT): New macro.
Kenichi Handa <handa@m17n.org>
parents:
89279
diff
changeset
|
6726 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
|
6727 | 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
|
6728 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
|
6729 coding_category_utf_16_le); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6730 } |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6731 else |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6732 { |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6733 if (EQ (eol_type, Qunix)) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6734 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
|
6735 else if (EQ (eol_type, Qdos)) |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6736 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
|
6737 else |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6738 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
|
6739 } |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6740 |
| 88365 | 6741 for (tail = val; CONSP (tail); tail = XCDR (tail)) |
| 6742 { | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6743 enum coding_category category; |
| 88365 | 6744 int this_eol; |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6745 |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6746 id = XINT (XCAR (tail)); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6747 attrs = CODING_ID_ATTRS (id); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6748 category = XINT (CODING_ATTR_CATEGORY (attrs)); |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6749 eol_type = CODING_ID_EOL_TYPE (id); |
| 88365 | 6750 if (VECTORP (eol_type)) |
| 6751 { | |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6752 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
|
6753 || 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
|
6754 this_eol = utf_16_be_eol; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6755 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
|
6756 || 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
|
6757 this_eol = utf_16_le_eol; |
| 88365 | 6758 else |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6759 this_eol = normal_eol; |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6760 |
| 88365 | 6761 if (this_eol == EOL_SEEN_LF) |
| 6762 XSETCAR (tail, AREF (eol_type, 0)); | |
| 6763 else if (this_eol == EOL_SEEN_CRLF) | |
| 6764 XSETCAR (tail, AREF (eol_type, 1)); | |
| 6765 else if (this_eol == EOL_SEEN_CR) | |
| 6766 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
|
6767 else |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6768 XSETCAR (tail, CODING_ID_NAME (id)); |
| 88365 | 6769 } |
|
89193
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6770 else |
|
311d061195ef
(detect_coding_utf_8): Check incomplete byte sequence.
Kenichi Handa <handa@m17n.org>
parents:
89184
diff
changeset
|
6771 XSETCAR (tail, CODING_ID_NAME (id)); |
| 88365 | 6772 } |
| 6773 } | |
| 6774 | |
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
6775 return (highest ? XCAR (val) : val); |
|
42104
d69c2368e549
(DECODE_COMPOSITION_END): Fixed a typo in the last
Sam Steingold <sds@gnu.org>
parents:
42103
diff
changeset
|
6776 } |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6777 |
| 88365 | 6778 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6779 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
|
6780 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
|
6781 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
|
6782 Return a list of possible coding systems ordered by priority. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6783 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6784 If only ASCII characters are found, it returns a list of single element |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6785 `undecided' or its subsidiary coding system according to a detected |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6786 end-of-line format. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6787 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6788 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
|
6789 highest priority. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6790 (start, end, highest) |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6791 Lisp_Object start, end, highest; |
| 17052 | 6792 { |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6793 int from, to; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6794 int from_byte, to_byte; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6795 |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6796 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
|
6797 CHECK_NUMBER_COERCE_MARKER (end); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6798 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6799 validate_region (&start, &end); |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6800 from = XINT (start), to = XINT (end); |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6801 from_byte = CHAR_TO_BYTE (from); |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6802 to_byte = CHAR_TO_BYTE (to); |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6803 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6804 if (from < GPT && to >= GPT) |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6805 move_gap_both (to, to_byte); |
| 88365 | 6806 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6807 return detect_coding_system (BYTE_POS_ADDR (from_byte), |
| 88365 | 6808 to_byte - from_byte, |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6809 !NILP (highest), |
|
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6810 !NILP (current_buffer |
| 88365 | 6811 ->enable_multibyte_characters), |
| 6812 Qnil); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6813 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6814 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6815 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
|
6816 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
|
6817 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
|
6818 Return a list of possible coding systems ordered by priority. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6819 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6820 If only ASCII characters are found, it returns a list of single element |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6821 `undecided' or its subsidiary coding system according to a detected |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6822 end-of-line format. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6823 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6824 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
|
6825 highest priority. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
6826 (string, highest) |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6827 Lisp_Object string, highest; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6828 { |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6829 CHECK_STRING (string); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6830 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
6831 return detect_coding_system (XSTRING (string)->data, |
| 88365 | 6832 STRING_BYTES (XSTRING (string)), |
|
34531
37f85e931855
(ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents:
34197
diff
changeset
|
6833 !NILP (highest), |
| 88365 | 6834 STRING_MULTIBYTE (string), |
| 6835 Qnil); | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6836 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6837 |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6838 |
| 88365 | 6839 static INLINE int |
| 6840 char_encodable_p (c, attrs) | |
| 6841 int c; | |
| 6842 Lisp_Object attrs; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6843 { |
| 88365 | 6844 Lisp_Object tail; |
| 6845 struct charset *charset; | |
| 6846 | |
| 6847 for (tail = CODING_ATTR_CHARSET_LIST (attrs); | |
| 6848 CONSP (tail); tail = XCDR (tail)) | |
| 6849 { | |
| 6850 charset = CHARSET_FROM_ID (XINT (XCAR (tail))); | |
| 6851 if (CHAR_CHARSET_P (c, charset)) | |
| 6852 break; | |
| 6853 } | |
| 6854 return (! NILP (tail)); | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6855 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6856 |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6857 |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6858 /* Return a list of coding systems that safely encode the text between |
| 88365 | 6859 START and END. If EXCLUDE is non-nil, it is a list of coding |
| 6860 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
|
6861 coding systems. In any case, if the text contains only ASCII or is |
| 88365 | 6862 unibyte, return t. */ |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6863 |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6864 DEFUN ("find-coding-systems-region-internal", |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6865 Ffind_coding_systems_region_internal, |
| 88365 | 6866 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
|
6867 doc: /* Internal use only. */) |
| 88365 | 6868 (start, end, exclude) |
| 6869 Lisp_Object start, end, exclude; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6870 { |
| 88365 | 6871 Lisp_Object coding_attrs_list, safe_codings; |
| 6872 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
|
6873 const unsigned char *p, *pbeg, *pend; |
| 88365 | 6874 int c; |
| 6875 Lisp_Object tail, elt; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6876 |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6877 if (STRINGP (start)) |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6878 { |
| 88365 | 6879 if (!STRING_MULTIBYTE (start) |
|
88889
4548f224c603
(Ffind_coding_systems_region_internal): Detect an
Kenichi Handa <handa@m17n.org>
parents:
88876
diff
changeset
|
6880 || XSTRING (start)->size == STRING_BYTES (XSTRING (start))) |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6881 return Qt; |
| 88365 | 6882 start_byte = 0; |
| 6883 end_byte = STRING_BYTES (XSTRING (start)); | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6884 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6885 else |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6886 { |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
6887 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
|
6888 CHECK_NUMBER_COERCE_MARKER (end); |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6889 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
|
6890 args_out_of_range (start, end); |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6891 if (NILP (current_buffer->enable_multibyte_characters)) |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6892 return Qt; |
| 88365 | 6893 start_byte = CHAR_TO_BYTE (XINT (start)); |
| 6894 end_byte = CHAR_TO_BYTE (XINT (end)); | |
| 6895 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
| 6896 return Qt; | |
| 6897 | |
| 6898 if (start < GPT && end > GPT) | |
| 6899 { | |
| 6900 if ((GPT - start) < (end - GPT)) | |
| 6901 move_gap_both (start, start_byte); | |
| 6902 else | |
| 6903 move_gap_both (end, end_byte); | |
| 6904 } | |
| 6905 } | |
| 6906 | |
| 6907 coding_attrs_list = Qnil; | |
| 6908 for (tail = Vcoding_system_list; CONSP (tail); tail = XCDR (tail)) | |
| 6909 if (NILP (exclude) | |
| 6910 || NILP (Fmemq (XCAR (tail), exclude))) | |
| 6911 { | |
| 6912 Lisp_Object attrs; | |
| 6913 | |
| 6914 attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | |
| 6915 if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | |
| 6916 && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | |
| 6917 coding_attrs_list = Fcons (attrs, coding_attrs_list); | |
| 6918 } | |
| 6919 | |
| 6920 if (STRINGP (start)) | |
| 6921 p = pbeg = XSTRING (start)->data; | |
| 6922 else | |
| 6923 p = pbeg = BYTE_POS_ADDR (start_byte); | |
| 6924 pend = p + (end_byte - start_byte); | |
| 6925 | |
| 6926 while (p < pend && ASCII_BYTE_P (*p)) p++; | |
| 6927 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
| 6928 | |
| 6929 while (p < pend) | |
| 6930 { | |
| 6931 if (ASCII_BYTE_P (*p)) | |
| 6932 p++; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6933 else |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6934 { |
| 88365 | 6935 c = STRING_CHAR_ADVANCE (p); |
| 6936 | |
| 6937 charset_map_loaded = 0; | |
| 6938 for (tail = coding_attrs_list; CONSP (tail);) | |
| 6939 { | |
| 6940 elt = XCAR (tail); | |
| 6941 if (NILP (elt)) | |
| 6942 tail = XCDR (tail); | |
| 6943 else if (char_encodable_p (c, elt)) | |
| 6944 tail = XCDR (tail); | |
| 6945 else if (CONSP (XCDR (tail))) | |
| 6946 { | |
| 6947 XSETCAR (tail, XCAR (XCDR (tail))); | |
| 6948 XSETCDR (tail, XCDR (XCDR (tail))); | |
| 6949 } | |
| 6950 else | |
| 6951 { | |
| 6952 XSETCAR (tail, Qnil); | |
| 6953 tail = XCDR (tail); | |
| 6954 } | |
| 6955 } | |
| 6956 if (charset_map_loaded) | |
| 6957 { | |
| 6958 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
| 6959 | |
| 6960 if (STRINGP (start)) | |
| 6961 pbeg = XSTRING (start)->data; | |
| 6962 else | |
| 6963 pbeg = BYTE_POS_ADDR (start_byte); | |
| 6964 p = pbeg + p_offset; | |
| 6965 pend = pbeg + pend_offset; | |
| 6966 } | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6967 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6968 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
6969 |
| 88365 | 6970 safe_codings = Qnil; |
| 6971 for (tail = coding_attrs_list; CONSP (tail); tail = XCDR (tail)) | |
| 6972 if (! NILP (XCAR (tail))) | |
| 6973 safe_codings = Fcons (CODING_ATTR_BASE_NAME (XCAR (tail)), safe_codings); | |
| 6974 | |
| 6975 return safe_codings; | |
| 6976 } | |
| 6977 | |
| 6978 | |
| 6979 DEFUN ("check-coding-systems-region", Fcheck_coding_systems_region, | |
| 6980 Scheck_coding_systems_region, 3, 3, 0, | |
| 6981 doc: /* Check if the region is encodable by coding systems. | |
| 6982 | |
| 6983 START and END are buffer positions specifying the region. | |
| 6984 CODING-SYSTEM-LIST is a list of coding systems to check. | |
| 6985 | |
| 6986 The value is an alist ((CODING-SYSTEM POS0 POS1 ...) ...), where | |
| 6987 CODING-SYSTEM is a member of CODING-SYSTEM-LIst and can't encode the | |
| 6988 whole region, POS0, POS1, ... are buffer positions where non-encodable | |
| 6989 characters are found. | |
| 6990 | |
| 6991 If all coding systems in CODING-SYSTEM-LIST can encode the region, the | |
| 6992 value is nil. | |
| 6993 | |
| 6994 START may be a string. In that case, check if the string is | |
| 6995 encodable, and the value contains indices to the string instead of | |
| 6996 buffer positions. END is ignored. */) | |
| 6997 (start, end, coding_system_list) | |
| 6998 Lisp_Object start, end, coding_system_list; | |
| 6999 { | |
| 7000 Lisp_Object list; | |
| 7001 EMACS_INT start_byte, end_byte; | |
| 7002 int pos; | |
|
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
7003 const unsigned char *p, *pbeg, *pend; |
| 88365 | 7004 int c; |
| 7005 Lisp_Object tail, elt; | |
| 7006 | |
| 7007 if (STRINGP (start)) | |
| 7008 { | |
| 7009 if (!STRING_MULTIBYTE (start) | |
| 7010 && XSTRING (start)->size != STRING_BYTES (XSTRING (start))) | |
| 7011 return Qnil; | |
| 7012 start_byte = 0; | |
| 7013 end_byte = STRING_BYTES (XSTRING (start)); | |
| 7014 pos = 0; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7015 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7016 else |
| 88365 | 7017 { |
| 7018 CHECK_NUMBER_COERCE_MARKER (start); | |
| 7019 CHECK_NUMBER_COERCE_MARKER (end); | |
| 7020 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end)) | |
| 7021 args_out_of_range (start, end); | |
| 7022 if (NILP (current_buffer->enable_multibyte_characters)) | |
| 7023 return Qnil; | |
| 7024 start_byte = CHAR_TO_BYTE (XINT (start)); | |
| 7025 end_byte = CHAR_TO_BYTE (XINT (end)); | |
| 7026 if (XINT (end) - XINT (start) == end_byte - start_byte) | |
| 7027 return Qt; | |
| 7028 | |
| 7029 if (start < GPT && end > GPT) | |
| 7030 { | |
| 7031 if ((GPT - start) < (end - GPT)) | |
| 7032 move_gap_both (start, start_byte); | |
| 7033 else | |
| 7034 move_gap_both (end, end_byte); | |
| 7035 } | |
| 7036 pos = start; | |
| 7037 } | |
| 7038 | |
| 7039 list = Qnil; | |
| 7040 for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) | |
| 7041 { | |
| 7042 elt = XCAR (tail); | |
| 7043 list = Fcons (Fcons (elt, Fcons (AREF (CODING_SYSTEM_SPEC (elt), 0), | |
| 7044 Qnil)), | |
| 7045 list); | |
| 7046 } | |
| 7047 | |
| 7048 if (STRINGP (start)) | |
| 7049 p = pbeg = XSTRING (start)->data; | |
| 7050 else | |
| 7051 p = pbeg = BYTE_POS_ADDR (start_byte); | |
| 7052 pend = p + (end_byte - start_byte); | |
| 7053 | |
| 7054 while (p < pend && ASCII_BYTE_P (*p)) p++, pos++; | |
| 7055 while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--; | |
| 7056 | |
| 7057 while (p < pend) | |
| 7058 { | |
| 7059 if (ASCII_BYTE_P (*p)) | |
| 7060 p++; | |
| 7061 else | |
| 7062 { | |
| 7063 c = STRING_CHAR_ADVANCE (p); | |
| 7064 | |
| 7065 charset_map_loaded = 0; | |
| 7066 for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
| 7067 { | |
| 7068 elt = XCDR (XCAR (tail)); | |
| 7069 if (! char_encodable_p (c, XCAR (elt))) | |
| 7070 XSETCDR (elt, Fcons (make_number (pos), XCDR (elt))); | |
| 7071 } | |
| 7072 if (charset_map_loaded) | |
| 7073 { | |
| 7074 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; | |
| 7075 | |
| 7076 if (STRINGP (start)) | |
| 7077 pbeg = XSTRING (start)->data; | |
| 7078 else | |
| 7079 pbeg = BYTE_POS_ADDR (start_byte); | |
| 7080 p = pbeg + p_offset; | |
| 7081 pend = pbeg + pend_offset; | |
| 7082 } | |
| 7083 } | |
| 7084 pos++; | |
| 7085 } | |
| 7086 | |
| 7087 tail = list; | |
| 7088 list = Qnil; | |
| 7089 for (; CONSP (tail); tail = XCDR (tail)) | |
| 7090 { | |
| 7091 elt = XCAR (tail); | |
| 7092 if (CONSP (XCDR (XCDR (elt)))) | |
| 7093 list = Fcons (Fcons (XCAR (elt), Fnreverse (XCDR (XCDR (elt)))), | |
| 7094 list); | |
| 7095 } | |
| 7096 | |
| 7097 return list; | |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7098 } |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7099 |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
7100 |
| 88365 | 7101 |
|
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7102 Lisp_Object |
| 88365 | 7103 code_convert_region (start, end, coding_system, dst_object, encodep, norecord) |
| 7104 Lisp_Object start, end, coding_system, dst_object; | |
| 7105 int encodep, norecord; | |
|
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7106 { |
|
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7107 struct coding_system coding; |
| 88365 | 7108 EMACS_INT from, from_byte, to, to_byte; |
| 7109 Lisp_Object src_object; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7110 |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7111 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
|
7112 CHECK_NUMBER_COERCE_MARKER (end); |
| 88365 | 7113 if (NILP (coding_system)) |
| 7114 coding_system = Qno_conversion; | |
| 7115 else | |
| 7116 CHECK_CODING_SYSTEM (coding_system); | |
| 7117 src_object = Fcurrent_buffer (); | |
| 7118 if (NILP (dst_object)) | |
| 7119 dst_object = src_object; | |
| 7120 else if (! EQ (dst_object, Qt)) | |
| 7121 CHECK_BUFFER (dst_object); | |
|
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7122 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7123 validate_region (&start, &end); |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7124 from = XFASTINT (start); |
| 88365 | 7125 from_byte = CHAR_TO_BYTE (from); |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7126 to = XFASTINT (end); |
| 88365 | 7127 to_byte = CHAR_TO_BYTE (to); |
| 7128 | |
| 7129 setup_coding_system (coding_system, &coding); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7130 coding.mode |= CODING_MODE_LAST_BLOCK; |
| 88365 | 7131 |
| 7132 if (encodep) | |
| 7133 encode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
| 7134 dst_object); | |
| 7135 else | |
| 7136 decode_coding_object (&coding, src_object, from, from_byte, to, to_byte, | |
| 7137 dst_object); | |
| 7138 if (! norecord) | |
| 7139 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
| 7140 | |
| 7141 if (coding.result != CODING_RESULT_SUCCESS) | |
| 7142 error ("Code conversion error: %d", coding.result); | |
| 7143 | |
| 7144 return (BUFFERP (dst_object) | |
| 7145 ? make_number (coding.produced_char) | |
| 7146 : coding.dst_object); | |
|
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7147 } |
|
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7148 |
| 88365 | 7149 |
|
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7150 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
| 88365 | 7151 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
|
7152 doc: /* Decode the current region from the specified coding system. |
| 88365 | 7153 When called from a program, takes four arguments: |
| 7154 START, END, CODING-SYSTEM, and DESTINATION. | |
| 7155 START and END are buffer positions. | |
| 7156 | |
| 7157 Optional 4th arguments DESTINATION specifies where the decoded text goes. | |
| 7158 If nil, the region between START and END is replace by the decoded text. | |
| 7159 If buffer, the decoded text is inserted in the buffer. | |
| 7160 If t, the decoded text is returned. | |
| 7161 | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7162 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
|
7163 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7164 not fully specified.) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7165 It returns the length of the decoded text. */) |
| 88365 | 7166 (start, end, coding_system, destination) |
| 7167 Lisp_Object start, end, coding_system, destination; | |
|
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7168 { |
| 88365 | 7169 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
|
7170 } |
|
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7171 |
|
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7172 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
| 88365 | 7173 3, 4, "r\nzCoding system: ", |
| 7174 doc: /* Encode the current region by specified coding system. | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7175 When called from a program, takes three arguments: |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7176 START, END, and CODING-SYSTEM. START and END are buffer positions. |
| 88365 | 7177 |
| 7178 Optional 4th arguments DESTINATION specifies where the encoded text goes. | |
| 7179 If nil, the region between START and END is replace by the encoded text. | |
| 7180 If buffer, the encoded text is inserted in the buffer. | |
| 7181 If t, the encoded text is returned. | |
| 7182 | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7183 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
|
7184 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7185 not fully specified.) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7186 It returns the length of the encoded text. */) |
| 88365 | 7187 (start, end, coding_system, destination) |
| 7188 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
|
7189 { |
| 88365 | 7190 return code_convert_region (start, end, coding_system, destination, 1, 0); |
| 17052 | 7191 } |
| 7192 | |
|
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7193 Lisp_Object |
| 88365 | 7194 code_convert_string (string, coding_system, dst_object, |
| 7195 encodep, nocopy, norecord) | |
| 7196 Lisp_Object string, coding_system, dst_object; | |
| 7197 int encodep, nocopy, norecord; | |
| 17052 | 7198 { |
| 7199 struct coding_system coding; | |
| 88365 | 7200 EMACS_INT chars, bytes; |
| 17052 | 7201 |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7202 CHECK_STRING (string); |
| 88365 | 7203 if (NILP (coding_system)) |
| 7204 { | |
| 7205 if (! norecord) | |
| 7206 Vlast_coding_system_used = Qno_conversion; | |
| 7207 if (NILP (dst_object)) | |
| 7208 return (nocopy ? Fcopy_sequence (string) : string); | |
| 7209 } | |
| 17052 | 7210 |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
7211 if (NILP (coding_system)) |
| 88365 | 7212 coding_system = Qno_conversion; |
| 7213 else | |
| 7214 CHECK_CODING_SYSTEM (coding_system); | |
| 7215 if (NILP (dst_object)) | |
| 7216 dst_object = Qt; | |
| 7217 else if (! EQ (dst_object, Qt)) | |
| 7218 CHECK_BUFFER (dst_object); | |
| 7219 | |
| 7220 setup_coding_system (coding_system, &coding); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7221 coding.mode |= CODING_MODE_LAST_BLOCK; |
| 88365 | 7222 chars = XSTRING (string)->size; |
| 7223 bytes = STRING_BYTES (XSTRING (string)); | |
| 7224 if (encodep) | |
| 7225 encode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
| 7226 else | |
| 7227 decode_coding_object (&coding, string, 0, 0, chars, bytes, dst_object); | |
| 7228 if (! norecord) | |
| 7229 Vlast_coding_system_used = CODING_ID_NAME (coding.id); | |
| 7230 | |
| 7231 if (coding.result != CODING_RESULT_SUCCESS) | |
| 7232 error ("Code conversion error: %d", coding.result); | |
| 7233 | |
| 7234 return (BUFFERP (dst_object) | |
| 7235 ? make_number (coding.produced_char) | |
| 7236 : coding.dst_object); | |
|
20803
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7237 } |
|
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7238 |
|
0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20794
diff
changeset
|
7239 |
|
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7240 /* Encode or decode STRING according to CODING_SYSTEM. |
| 26847 | 7241 Do not set Vlast_coding_system_used. |
| 7242 | |
| 7243 This function is called only from macros DECODE_FILE and | |
| 7244 ENCODE_FILE, thus we ignore character composition. */ | |
|
22341
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7245 |
|
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7246 Lisp_Object |
|
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7247 code_convert_string_norecord (string, coding_system, encodep) |
|
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7248 Lisp_Object string, coding_system; |
|
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7249 int encodep; |
|
572ba933a4bf
(code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents:
22329
diff
changeset
|
7250 { |
|
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7251 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
|
7252 } |
| 88365 | 7253 |
| 7254 | |
| 7255 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
| 7256 2, 4, 0, | |
| 7257 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. | |
| 7258 | |
| 7259 Optional third arg NOCOPY non-nil means it is OK to return STRING itself | |
| 7260 if the decoding operation is trivial. | |
| 7261 | |
| 7262 Optional fourth arg BUFFER non-nil meant that the decoded text is | |
|
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
7263 inserted in BUFFER instead of returned as a string. In this case, |
| 88365 | 7264 the return value is BUFFER. |
| 7265 | |
| 7266 This function sets `last-coding-system-used' to the precise coding system | |
| 7267 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
| 7268 not fully specified. */) | |
| 7269 (string, coding_system, nocopy, buffer) | |
| 7270 Lisp_Object string, coding_system, nocopy, buffer; | |
| 7271 { | |
| 7272 return code_convert_string (string, coding_system, buffer, | |
| 7273 0, ! NILP (nocopy), 0); | |
| 7274 } | |
| 7275 | |
| 7276 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
| 7277 2, 4, 0, | |
| 7278 doc: /* Encode STRING to CODING-SYSTEM, and return the result. | |
| 7279 | |
| 7280 Optional third arg NOCOPY non-nil means it is OK to return STRING | |
| 7281 itself if the encoding operation is trivial. | |
| 7282 | |
| 7283 Optional fourth arg BUFFER non-nil meant that the encoded text is | |
|
88845
64b8f6168269
(Fset_coding_system_priority): Allow null arg list.
Dave Love <fx@gnu.org>
parents:
88771
diff
changeset
|
7284 inserted in BUFFER instead of returned as a string. In this case, |
| 88365 | 7285 the return value is BUFFER. |
| 7286 | |
| 7287 This function sets `last-coding-system-used' to the precise coding system | |
| 7288 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is | |
| 7289 not fully specified.) */) | |
| 7290 (string, coding_system, nocopy, buffer) | |
| 7291 Lisp_Object string, coding_system, nocopy, buffer; | |
| 7292 { | |
| 7293 return code_convert_string (string, coding_system, buffer, | |
| 88856 | 7294 1, ! NILP (nocopy), 1); |
| 88365 | 7295 } |
| 7296 | |
|
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7297 |
| 17052 | 7298 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
|
7299 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
|
7300 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
|
7301 (code) |
| 17052 | 7302 Lisp_Object code; |
| 7303 { | |
| 88365 | 7304 Lisp_Object spec, attrs, val; |
| 7305 struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; | |
| 7306 int c; | |
| 7307 | |
| 7308 CHECK_NATNUM (code); | |
| 7309 c = XFASTINT (code); | |
| 7310 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
| 7311 attrs = AREF (spec, 0); | |
| 7312 | |
| 7313 if (ASCII_BYTE_P (c) | |
| 7314 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
| 7315 return code; | |
| 7316 | |
| 7317 val = CODING_ATTR_CHARSET_LIST (attrs); | |
| 7318 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
|
7319 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
|
7320 charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); |
| 88365 | 7321 |
| 7322 if (c <= 0x7F) | |
| 7323 charset = charset_roman; | |
| 7324 else if (c >= 0xA0 && c < 0xDF) | |
| 7325 { | |
| 7326 charset = charset_kana; | |
| 7327 c -= 0x80; | |
|
24065
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
7328 } |
|
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
7329 else |
|
7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents:
24056
diff
changeset
|
7330 { |
|
88497
d2b9e0d4c2f6
(Fdecode_sjis_char): Fix typo (0x7F->0xFF). Fix the
Kenichi Handa <handa@m17n.org>
parents:
88485
diff
changeset
|
7331 int s1 = c >> 8, s2 = c & 0xFF; |
| 88365 | 7332 |
| 7333 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF | |
| 7334 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) | |
| 7335 error ("Invalid code: %d", code); | |
| 7336 SJIS_TO_JIS (c); | |
| 7337 charset = charset_kanji; | |
| 7338 } | |
| 7339 c = DECODE_CHAR (charset, c); | |
| 7340 if (c < 0) | |
| 7341 error ("Invalid code: %d", code); | |
| 7342 return make_number (c); | |
| 17052 | 7343 } |
| 7344 | |
| 88365 | 7345 |
| 17052 | 7346 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0, |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7347 doc: /* Encode a Japanese character CHAR to shift_jis encoding. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7348 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
|
7349 (ch) |
| 88365 | 7350 Lisp_Object ch; |
| 17052 | 7351 { |
| 88365 | 7352 Lisp_Object spec, attrs, charset_list; |
| 7353 int c; | |
| 7354 struct charset *charset; | |
| 7355 unsigned code; | |
| 7356 | |
| 7357 CHECK_CHARACTER (ch); | |
| 7358 c = XFASTINT (ch); | |
| 7359 CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); | |
| 7360 attrs = AREF (spec, 0); | |
| 7361 | |
| 7362 if (ASCII_CHAR_P (c) | |
| 7363 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
| 7364 return ch; | |
| 7365 | |
| 7366 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
| 7367 charset = char_charset (c, charset_list, &code); | |
| 7368 if (code == CHARSET_INVALID_CODE (charset)) | |
| 7369 error ("Can't encode by shift_jis encoding: %d", c); | |
| 7370 JIS_TO_SJIS (code); | |
| 7371 | |
| 7372 return make_number (code); | |
| 17052 | 7373 } |
| 7374 | |
| 7375 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
|
7376 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
|
7377 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
|
7378 (code) |
| 17052 | 7379 Lisp_Object code; |
| 7380 { | |
| 88365 | 7381 Lisp_Object spec, attrs, val; |
| 7382 struct charset *charset_roman, *charset_big5, *charset; | |
| 7383 int c; | |
| 7384 | |
| 7385 CHECK_NATNUM (code); | |
| 7386 c = XFASTINT (code); | |
| 7387 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
| 7388 attrs = AREF (spec, 0); | |
| 7389 | |
| 7390 if (ASCII_BYTE_P (c) | |
| 7391 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
| 7392 return code; | |
| 7393 | |
| 7394 val = CODING_ATTR_CHARSET_LIST (attrs); | |
| 7395 charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); | |
| 7396 charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); | |
| 7397 | |
| 7398 if (c <= 0x7F) | |
| 7399 charset = charset_roman; | |
|
24324
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
7400 else |
|
2eec590faf26
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents:
24316
diff
changeset
|
7401 { |
| 88365 | 7402 int b1 = c >> 8, b2 = c & 0x7F; |
| 7403 if (b1 < 0xA1 || b1 > 0xFE | |
| 7404 || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) | |
| 7405 error ("Invalid code: %d", code); | |
| 7406 charset = charset_big5; | |
| 7407 } | |
| 7408 c = DECODE_CHAR (charset, (unsigned )c); | |
| 7409 if (c < 0) | |
| 7410 error ("Invalid code: %d", code); | |
| 7411 return make_number (c); | |
| 17052 | 7412 } |
| 7413 | |
| 7414 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0, | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7415 doc: /* Encode the Big5 character CHAR to BIG5 coding system. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7416 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
|
7417 (ch) |
| 17052 | 7418 Lisp_Object ch; |
| 7419 { | |
| 88365 | 7420 Lisp_Object spec, attrs, charset_list; |
| 7421 struct charset *charset; | |
| 7422 int c; | |
| 7423 unsigned code; | |
| 7424 | |
| 7425 CHECK_CHARACTER (ch); | |
| 7426 c = XFASTINT (ch); | |
| 7427 CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); | |
| 7428 attrs = AREF (spec, 0); | |
| 7429 if (ASCII_CHAR_P (c) | |
| 7430 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) | |
| 7431 return ch; | |
| 7432 | |
| 7433 charset_list = CODING_ATTR_CHARSET_LIST (attrs); | |
| 7434 charset = char_charset (c, charset_list, &code); | |
| 7435 if (code == CHARSET_INVALID_CODE (charset)) | |
| 7436 error ("Can't encode by Big5 encoding: %d", c); | |
| 7437 | |
| 7438 return make_number (code); | |
| 17052 | 7439 } |
| 88365 | 7440 |
|
20680
dd46027e8412
(code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents:
20668
diff
changeset
|
7441 |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7442 DEFUN ("set-terminal-coding-system-internal", |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7443 Fset_terminal_coding_system_internal, |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7444 Sset_terminal_coding_system_internal, 1, 1, 0, |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7445 doc: /* Internal use only. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7446 (coding_system) |
| 88473 | 7447 Lisp_Object coding_system; |
| 17052 | 7448 { |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7449 CHECK_SYMBOL (coding_system); |
| 88365 | 7450 setup_coding_system (Fcheck_coding_system (coding_system), |
| 7451 &terminal_coding); | |
| 7452 | |
|
20150
402b6e5f4b58
(encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents:
20105
diff
changeset
|
7453 /* We had better not send unsafe characters to terminal. */ |
| 88365 | 7454 terminal_coding.mode |= CODING_MODE_SAFE_ENCODING; |
| 7455 /* Characer composition should be disabled. */ | |
| 7456 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
|
7457 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
|
7458 terminal_coding.dst_multibyte = 0; |
| 17052 | 7459 return Qnil; |
| 7460 } | |
| 7461 | |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7462 DEFUN ("set-safe-terminal-coding-system-internal", |
|
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7463 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
|
7464 Sset_safe_terminal_coding_system_internal, 1, 1, 0, |
| 41006 | 7465 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
|
7466 (coding_system) |
| 88473 | 7467 Lisp_Object coding_system; |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7468 { |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7469 CHECK_SYMBOL (coding_system); |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7470 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
|
7471 &safe_terminal_coding); |
| 88365 | 7472 /* Characer composition should be disabled. */ |
| 7473 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
|
7474 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
|
7475 safe_terminal_coding.dst_multibyte = 0; |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7476 return Qnil; |
|
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7477 } |
|
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
7478 |
| 17052 | 7479 DEFUN ("terminal-coding-system", |
| 7480 Fterminal_coding_system, Sterminal_coding_system, 0, 0, 0, | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7481 doc: /* Return coding system specified for terminal output. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7482 () |
| 17052 | 7483 { |
| 88365 | 7484 return CODING_ID_NAME (terminal_coding.id); |
| 17052 | 7485 } |
| 7486 | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7487 DEFUN ("set-keyboard-coding-system-internal", |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
7488 Fset_keyboard_coding_system_internal, |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7489 Sset_keyboard_coding_system_internal, 1, 1, 0, |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7490 doc: /* Internal use only. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7491 (coding_system) |
| 17052 | 7492 Lisp_Object coding_system; |
| 7493 { | |
|
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Jan?k <Pavel@Janik.cz>
parents:
40461
diff
changeset
|
7494 CHECK_SYMBOL (coding_system); |
| 88365 | 7495 setup_coding_system (Fcheck_coding_system (coding_system), |
| 7496 &keyboard_coding); | |
| 7497 /* Characer composition should be disabled. */ | |
| 7498 keyboard_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; | |
| 17052 | 7499 return Qnil; |
| 7500 } | |
| 7501 | |
| 7502 DEFUN ("keyboard-coding-system", | |
| 7503 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 0, 0, | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7504 doc: /* Return coding system specified for decoding keyboard input. */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7505 () |
| 17052 | 7506 { |
| 88365 | 7507 return CODING_ID_NAME (keyboard_coding.id); |
| 17052 | 7508 } |
| 7509 | |
| 7510 | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
7511 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
|
7512 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
|
7513 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
|
7514 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
|
7515 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
|
7516 \(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
|
7517 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
|
7518 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7519 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
|
7520 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
|
7521 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
|
7522 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
|
7523 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7524 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
|
7525 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
|
7526 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
|
7527 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
|
7528 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7529 TARGET has a meaning which depends on OPERATION: |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7530 For file I/O, TARGET is a file name. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7531 For process I/O, TARGET is a process name. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7532 For network I/O, TARGET is a service name or a port number |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7533 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7534 This function looks up what specified for TARGET in, |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7535 `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
|
7536 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
|
7537 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
|
7538 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
|
7539 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
|
7540 which is a list of all the arguments given to this function. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7541 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7542 usage: (find-operation-coding-system OPERATION ARGUMENTS ...) */) |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
7543 (nargs, args) |
| 17052 | 7544 int nargs; |
| 7545 Lisp_Object *args; | |
| 7546 { | |
| 7547 Lisp_Object operation, target_idx, target, val; | |
| 7548 register Lisp_Object chain; | |
| 7549 | |
| 7550 if (nargs < 2) | |
| 7551 error ("Too few arguments"); | |
| 7552 operation = args[0]; | |
| 7553 if (!SYMBOLP (operation) | |
| 7554 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
| 88365 | 7555 error ("Invalid first arguement"); |
| 17052 | 7556 if (nargs < 1 + XINT (target_idx)) |
| 7557 error ("Too few arguments for operation: %s", | |
| 7558 XSYMBOL (operation)->name->data); | |
| 7559 target = args[XINT (target_idx) + 1]; | |
| 7560 if (!(STRINGP (target) | |
| 7561 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
| 88365 | 7562 error ("Invalid %dth argument", XINT (target_idx) + 1); |
| 17052 | 7563 |
|
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
7564 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
|
7565 || EQ (operation, Qwrite_region)) |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7566 ? 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
|
7567 : (EQ (operation, Qopen_network_stream) |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7568 ? Vnetwork_coding_system_alist |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7569 : Vprocess_coding_system_alist)); |
| 17052 | 7570 if (NILP (chain)) |
| 7571 return Qnil; | |
| 7572 | |
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7573 for (; CONSP (chain); chain = XCDR (chain)) |
| 17052 | 7574 { |
|
19747
bed06df9cbc5
(setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents:
19743
diff
changeset
|
7575 Lisp_Object elt; |
| 88365 | 7576 |
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7577 elt = XCAR (chain); |
| 17052 | 7578 if (CONSP (elt) |
| 7579 && ((STRINGP (target) | |
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7580 && STRINGP (XCAR (elt)) |
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7581 && 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
|
7582 || (INTEGERP (target) && EQ (target, XCAR (elt))))) |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7583 { |
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents:
25370
diff
changeset
|
7584 val = XCDR (elt); |
|
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7585 /* 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
|
7586 function symbol, we return VAL as a coding system. */ |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7587 if (CONSP (val)) |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7588 return val; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7589 if (! SYMBOLP (val)) |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7590 return Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7591 if (! NILP (Fcoding_system_p (val))) |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7592 return Fcons (val, val); |
|
19763
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7593 if (! NILP (Ffboundp (val))) |
|
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7594 { |
|
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7595 val = call1 (val, Flist (nargs, args)); |
|
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7596 if (CONSP (val)) |
|
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7597 return val; |
|
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7598 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
|
7599 return Fcons (val, val); |
|
ab2fd2c85986
(Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents:
19758
diff
changeset
|
7600 } |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7601 return Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
7602 } |
| 17052 | 7603 } |
| 7604 return Qnil; | |
| 7605 } | |
| 7606 | |
| 88365 | 7607 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
|
7608 Sset_coding_system_priority, 0, MANY, 0, |
| 88645 | 7609 doc: /* Assign higher priority to the coding systems given as arguments. |
|
88544
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7610 usage: (set-coding-system-priority CODING-SYSTEM ...) */) |
| 88365 | 7611 (nargs, args) |
| 7612 int nargs; | |
| 7613 Lisp_Object *args; | |
| 7614 { | |
| 7615 int i, j; | |
| 7616 int changed[coding_category_max]; | |
| 7617 enum coding_category priorities[coding_category_max]; | |
| 7618 | |
| 7619 bzero (changed, sizeof changed); | |
| 7620 | |
| 7621 for (i = j = 0; i < nargs; i++) | |
| 7622 { | |
| 7623 enum coding_category category; | |
| 7624 Lisp_Object spec, attrs; | |
| 7625 | |
| 7626 CHECK_CODING_SYSTEM_GET_SPEC (args[i], spec); | |
| 7627 attrs = AREF (spec, 0); | |
| 7628 category = XINT (CODING_ATTR_CATEGORY (attrs)); | |
| 7629 if (changed[category]) | |
| 7630 /* Ignore this coding system because a coding system of the | |
| 7631 same category already had a higher priority. */ | |
| 7632 continue; | |
| 7633 changed[category] = 1; | |
| 7634 priorities[j++] = category; | |
| 7635 if (coding_categories[category].id >= 0 | |
| 7636 && ! EQ (args[i], CODING_ID_NAME (coding_categories[category].id))) | |
| 7637 setup_coding_system (args[i], &coding_categories[category]); | |
| 7638 } | |
| 7639 | |
| 7640 /* Now we have decided top J priorities. Reflect the order of the | |
| 7641 original priorities to the remaining priorities. */ | |
| 7642 | |
| 7643 for (i = j, j = 0; i < coding_category_max; i++, j++) | |
| 7644 { | |
| 7645 while (j < coding_category_max | |
| 7646 && changed[coding_priorities[j]]) | |
| 7647 j++; | |
| 7648 if (j == coding_category_max) | |
| 7649 abort (); | |
| 7650 priorities[i] = coding_priorities[j]; | |
| 7651 } | |
| 7652 | |
| 7653 bcopy (priorities, coding_priorities, sizeof priorities); | |
| 7654 return Qnil; | |
| 7655 } | |
| 7656 | |
| 7657 DEFUN ("coding-system-priority-list", Fcoding_system_priority_list, | |
| 7658 Scoding_system_priority_list, 0, 1, 0, | |
| 88645 | 7659 doc: /* Return a list of coding systems ordered by their priorities. |
| 7660 HIGHESTP non-nil means just return the highest priority one. */) | |
| 88365 | 7661 (highestp) |
| 7662 Lisp_Object highestp; | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7663 { |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
7664 int i; |
| 88365 | 7665 Lisp_Object val; |
| 7666 | |
| 7667 for (i = 0, val = Qnil; i < coding_category_max; i++) | |
| 7668 { | |
| 7669 enum coding_category category = coding_priorities[i]; | |
| 7670 int id = coding_categories[category].id; | |
| 7671 Lisp_Object attrs; | |
| 7672 | |
| 7673 if (id < 0) | |
| 7674 continue; | |
| 7675 attrs = CODING_ID_ATTRS (id); | |
| 7676 if (! NILP (highestp)) | |
| 7677 return CODING_ATTR_BASE_NAME (attrs); | |
| 7678 val = Fcons (CODING_ATTR_BASE_NAME (attrs), val); | |
| 7679 } | |
| 7680 return Fnreverse (val); | |
| 7681 } | |
| 7682 | |
|
88631
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7683 static char *suffixes[] = { "-unix", "-dos", "-mac" }; |
|
780b91d4a7e5
(setup_iso_safe_charsets): Fix arg decl for K&R.
Dave Love <fx@gnu.org>
parents:
88607
diff
changeset
|
7684 |
| 88365 | 7685 static Lisp_Object |
| 7686 make_subsidiaries (base) | |
| 7687 Lisp_Object base; | |
| 7688 { | |
| 7689 Lisp_Object subsidiaries; | |
| 7690 int base_name_len = STRING_BYTES (XSYMBOL (base)->name); | |
| 7691 char *buf = (char *) alloca (base_name_len + 6); | |
| 7692 int i; | |
| 7693 | |
| 7694 bcopy (XSYMBOL (base)->name->data, buf, base_name_len); | |
| 7695 subsidiaries = Fmake_vector (make_number (3), Qnil); | |
| 7696 for (i = 0; i < 3; i++) | |
| 7697 { | |
| 7698 bcopy (suffixes[i], buf + base_name_len, strlen (suffixes[i]) + 1); | |
| 7699 ASET (subsidiaries, i, intern (buf)); | |
| 7700 } | |
| 7701 return subsidiaries; | |
| 7702 } | |
| 7703 | |
| 7704 | |
| 7705 DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal, | |
| 7706 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
|
7707 doc: /* For internal use only. |
|
f464d728344c
(Vchar_coding_system_table, Qchar_coding_system):
Dave Love <fx@gnu.org>
parents:
88510
diff
changeset
|
7708 usage: (define-coding-system-internal ...) */) |
| 88365 | 7709 (nargs, args) |
| 7710 int nargs; | |
| 7711 Lisp_Object *args; | |
| 7712 { | |
| 7713 Lisp_Object name; | |
| 7714 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ | |
| 7715 Lisp_Object attrs; /* Vector of attributes. */ | |
| 7716 Lisp_Object eol_type; | |
| 7717 Lisp_Object aliases; | |
| 7718 Lisp_Object coding_type, charset_list, safe_charsets; | |
| 7719 enum coding_category category; | |
| 7720 Lisp_Object tail, val; | |
| 7721 int max_charset_id = 0; | |
| 7722 int i; | |
| 7723 | |
| 7724 if (nargs < coding_arg_max) | |
| 7725 goto short_args; | |
| 7726 | |
| 7727 attrs = Fmake_vector (make_number (coding_attr_last_index), Qnil); | |
| 7728 | |
| 7729 name = args[coding_arg_name]; | |
| 7730 CHECK_SYMBOL (name); | |
| 7731 CODING_ATTR_BASE_NAME (attrs) = name; | |
| 7732 | |
| 7733 val = args[coding_arg_mnemonic]; | |
| 7734 if (! STRINGP (val)) | |
| 7735 CHECK_CHARACTER (val); | |
| 7736 CODING_ATTR_MNEMONIC (attrs) = val; | |
| 7737 | |
| 7738 coding_type = args[coding_arg_coding_type]; | |
| 7739 CHECK_SYMBOL (coding_type); | |
| 7740 CODING_ATTR_TYPE (attrs) = coding_type; | |
| 7741 | |
| 7742 charset_list = args[coding_arg_charset_list]; | |
| 7743 if (SYMBOLP (charset_list)) | |
| 7744 { | |
| 7745 if (EQ (charset_list, Qiso_2022)) | |
| 7746 { | |
| 7747 if (! EQ (coding_type, Qiso_2022)) | |
| 7748 error ("Invalid charset-list"); | |
| 7749 charset_list = Viso_2022_charset_list; | |
| 7750 } | |
| 7751 else if (EQ (charset_list, Qemacs_mule)) | |
| 7752 { | |
| 7753 if (! EQ (coding_type, Qemacs_mule)) | |
| 7754 error ("Invalid charset-list"); | |
| 7755 charset_list = Vemacs_mule_charset_list; | |
| 7756 } | |
| 7757 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
| 7758 if (max_charset_id < XFASTINT (XCAR (tail))) | |
| 7759 max_charset_id = XFASTINT (XCAR (tail)); | |
| 7760 } | |
| 7761 else | |
| 7762 { | |
| 7763 charset_list = Fcopy_sequence (charset_list); | |
| 7764 for (tail = charset_list; !NILP (tail); tail = Fcdr (tail)) | |
| 7765 { | |
| 7766 struct charset *charset; | |
| 7767 | |
| 7768 val = Fcar (tail); | |
| 7769 CHECK_CHARSET_GET_CHARSET (val, charset); | |
| 7770 if (EQ (coding_type, Qiso_2022) | |
| 7771 ? CHARSET_ISO_FINAL (charset) < 0 | |
| 7772 : EQ (coding_type, Qemacs_mule) | |
| 7773 ? CHARSET_EMACS_MULE_ID (charset) < 0 | |
| 7774 : 0) | |
| 7775 error ("Can't handle charset `%s'", | |
| 7776 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
| 7777 | |
| 7778 XCAR (tail) = make_number (charset->id); | |
| 7779 if (max_charset_id < charset->id) | |
| 7780 max_charset_id = charset->id; | |
| 7781 } | |
| 7782 } | |
| 7783 CODING_ATTR_CHARSET_LIST (attrs) = charset_list; | |
| 7784 | |
| 7785 safe_charsets = Fmake_string (make_number (max_charset_id + 1), | |
| 7786 make_number (255)); | |
| 7787 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
| 7788 XSTRING (safe_charsets)->data[XFASTINT (XCAR (tail))] = 0; | |
| 7789 CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; | |
| 7790 | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7791 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
|
7792 |
| 88365 | 7793 val = args[coding_arg_decode_translation_table]; |
| 7794 if (! NILP (val)) | |
| 7795 CHECK_CHAR_TABLE (val); | |
| 7796 CODING_ATTR_DECODE_TBL (attrs) = val; | |
| 7797 | |
| 7798 val = args[coding_arg_encode_translation_table]; | |
| 7799 if (! NILP (val)) | |
| 7800 CHECK_CHAR_TABLE (val); | |
| 7801 CODING_ATTR_ENCODE_TBL (attrs) = val; | |
| 7802 | |
| 7803 val = args[coding_arg_post_read_conversion]; | |
| 7804 CHECK_SYMBOL (val); | |
| 7805 CODING_ATTR_POST_READ (attrs) = val; | |
| 7806 | |
| 7807 val = args[coding_arg_pre_write_conversion]; | |
| 7808 CHECK_SYMBOL (val); | |
| 7809 CODING_ATTR_PRE_WRITE (attrs) = val; | |
| 7810 | |
| 7811 val = args[coding_arg_default_char]; | |
| 7812 if (NILP (val)) | |
| 7813 CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); | |
| 7814 else | |
| 7815 { | |
| 7816 CHECK_CHARACTER (val); | |
| 7817 CODING_ATTR_DEFAULT_CHAR (attrs) = val; | |
| 7818 } | |
| 7819 | |
| 7820 val = args[coding_arg_plist]; | |
| 7821 CHECK_LIST (val); | |
| 7822 CODING_ATTR_PLIST (attrs) = val; | |
| 7823 | |
| 7824 if (EQ (coding_type, Qcharset)) | |
| 7825 { | |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7826 /* 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
|
7827 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
|
7828 |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7829 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
|
7830 coding system. |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7831 |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7832 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
|
7833 charset whose ID is NUM. |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7834 |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7835 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
|
7836 of one of them. The list is sorted by dimensions of the |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7837 charsets. A charset of smaller dimension comes firtst. |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7838 */ |
| 88365 | 7839 val = Fmake_vector (make_number (256), Qnil); |
| 7840 | |
| 7841 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) | |
| 7842 { | |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7843 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
|
7844 int dim = CHARSET_DIMENSION (charset); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7845 int idx = (dim - 1) * 4; |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7846 |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7847 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
|
7848 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
|
7849 |
|
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7850 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
|
7851 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
|
7852 { |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7853 Lisp_Object tmp, tmp2; |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7854 int dim2; |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7855 |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7856 tmp = AREF (val, i); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7857 if (NILP (tmp)) |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7858 tmp = XCAR (tail); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7859 else if (NUMBERP (tmp)) |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7860 { |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7861 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
|
7862 if (dim < dim2) |
|
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7863 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
|
7864 else |
|
88607
18436bf3d6dd
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
88598
diff
changeset
|
7865 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
|
7866 } |
|
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7867 else |
|
88597
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7868 { |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7869 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
|
7870 { |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7871 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
|
7872 if (dim < dim2) |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7873 break; |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7874 } |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7875 if (NILP (tmp2)) |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7876 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
|
7877 else |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7878 { |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7879 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
|
7880 XSETCAR (tmp2, XCAR (tail)); |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7881 } |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7882 } |
|
74b74f59bc09
(decode_coding_charset): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
88587
diff
changeset
|
7883 ASET (val, i, tmp); |
|
88477
5f974cbba7b3
(coding_set_source): Delete the local variable beg_byte.
Kenichi Handa <handa@m17n.org>
parents:
88473
diff
changeset
|
7884 } |
| 88365 | 7885 } |
| 7886 ASET (attrs, coding_attr_charset_valids, val); | |
| 7887 category = coding_category_charset; | |
| 7888 } | |
| 7889 else if (EQ (coding_type, Qccl)) | |
| 7890 { | |
| 7891 Lisp_Object valids; | |
| 7892 | |
| 7893 if (nargs < coding_arg_ccl_max) | |
| 7894 goto short_args; | |
| 7895 | |
| 7896 val = args[coding_arg_ccl_decoder]; | |
| 7897 CHECK_CCL_PROGRAM (val); | |
| 7898 if (VECTORP (val)) | |
| 7899 val = Fcopy_sequence (val); | |
| 7900 ASET (attrs, coding_attr_ccl_decoder, val); | |
| 7901 | |
| 7902 val = args[coding_arg_ccl_encoder]; | |
| 7903 CHECK_CCL_PROGRAM (val); | |
| 7904 if (VECTORP (val)) | |
| 7905 val = Fcopy_sequence (val); | |
| 7906 ASET (attrs, coding_attr_ccl_encoder, val); | |
| 7907 | |
| 7908 val = args[coding_arg_ccl_valids]; | |
| 7909 valids = Fmake_string (make_number (256), make_number (0)); | |
| 7910 for (tail = val; !NILP (tail); tail = Fcdr (tail)) | |
| 7911 { | |
| 7912 val = Fcar (tail); | |
| 7913 if (INTEGERP (val)) | |
| 88856 | 7914 ASET (valids, XINT (val), make_number (1)); |
| 88365 | 7915 else |
| 7916 { | |
| 7917 int from, to; | |
| 7918 | |
| 7919 CHECK_CONS (val); | |
| 7920 CHECK_NUMBER (XCAR (val)); | |
| 7921 CHECK_NUMBER (XCDR (val)); | |
| 7922 from = XINT (XCAR (val)); | |
| 7923 to = XINT (XCDR (val)); | |
| 7924 for (i = from; i <= to; i++) | |
| 88856 | 7925 ASET (valids, i, make_number (1)); |
| 88365 | 7926 } |
| 7927 } | |
| 7928 ASET (attrs, coding_attr_ccl_valids, valids); | |
| 7929 | |
| 7930 category = coding_category_ccl; | |
| 7931 } | |
| 7932 else if (EQ (coding_type, Qutf_16)) | |
| 7933 { | |
| 7934 Lisp_Object bom, endian; | |
| 7935 | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7936 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
|
7937 |
| 88365 | 7938 if (nargs < coding_arg_utf16_max) |
| 7939 goto short_args; | |
| 7940 | |
| 7941 bom = args[coding_arg_utf16_bom]; | |
| 7942 if (! NILP (bom) && ! EQ (bom, Qt)) | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
7943 { |
| 88365 | 7944 CHECK_CONS (bom); |
| 7945 CHECK_CODING_SYSTEM (XCAR (bom)); | |
| 7946 CHECK_CODING_SYSTEM (XCDR (bom)); | |
| 7947 } | |
| 7948 ASET (attrs, coding_attr_utf_16_bom, bom); | |
| 7949 | |
| 7950 endian = args[coding_arg_utf16_endian]; | |
| 7951 ASET (attrs, coding_attr_utf_16_endian, endian); | |
| 7952 | |
| 7953 category = (CONSP (bom) | |
| 7954 ? coding_category_utf_16_auto | |
| 7955 : NILP (bom) | |
| 7956 ? (NILP (endian) | |
| 7957 ? coding_category_utf_16_be_nosig | |
| 7958 : coding_category_utf_16_le_nosig) | |
| 7959 : (NILP (endian) | |
| 7960 ? coding_category_utf_16_be | |
| 7961 : coding_category_utf_16_le)); | |
| 7962 } | |
| 7963 else if (EQ (coding_type, Qiso_2022)) | |
| 7964 { | |
| 7965 Lisp_Object initial, reg_usage, request, flags; | |
|
88430
6418a272b97e
* coding.c: Delete unused variables.
Kenichi Handa <handa@m17n.org>
parents:
88365
diff
changeset
|
7966 int i, id; |
| 88365 | 7967 |
| 7968 if (nargs < coding_arg_iso2022_max) | |
| 7969 goto short_args; | |
| 7970 | |
| 7971 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); | |
| 7972 CHECK_VECTOR (initial); | |
| 7973 for (i = 0; i < 4; i++) | |
| 7974 { | |
| 7975 val = Faref (initial, make_number (i)); | |
| 7976 if (! NILP (val)) | |
| 7977 { | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7978 struct charset *charset; |
|
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7979 |
|
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
7980 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
|
7981 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
|
7982 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
|
7983 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
| 88365 | 7984 } |
| 7985 else | |
| 7986 ASET (initial, i, make_number (-1)); | |
| 7987 } | |
| 7988 | |
| 7989 reg_usage = args[coding_arg_iso2022_reg_usage]; | |
| 7990 CHECK_CONS (reg_usage); | |
| 7991 CHECK_NATNUM (XCAR (reg_usage)); | |
| 7992 CHECK_NATNUM (XCDR (reg_usage)); | |
| 7993 | |
| 7994 request = Fcopy_sequence (args[coding_arg_iso2022_request]); | |
| 7995 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) | |
| 7996 { | |
| 7997 int id; | |
| 7998 | |
| 7999 val = Fcar (tail); | |
| 8000 CHECK_CONS (val); | |
| 8001 CHECK_CHARSET_GET_ID (XCAR (val), id); | |
| 8002 CHECK_NATNUM (XCDR (val)); | |
| 8003 if (XINT (XCDR (val)) >= 4) | |
| 8004 error ("Invalid graphic register number: %d", XINT (XCDR (val))); | |
| 8005 XCAR (val) = make_number (id); | |
| 8006 } | |
| 8007 | |
| 8008 flags = args[coding_arg_iso2022_flags]; | |
| 8009 CHECK_NATNUM (flags); | |
| 8010 i = XINT (flags); | |
| 8011 if (EQ (args[coding_arg_charset_list], Qiso_2022)) | |
| 8012 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); | |
| 8013 | |
| 8014 ASET (attrs, coding_attr_iso_initial, initial); | |
| 8015 ASET (attrs, coding_attr_iso_usage, reg_usage); | |
| 8016 ASET (attrs, coding_attr_iso_request, request); | |
| 8017 ASET (attrs, coding_attr_iso_flags, flags); | |
| 8018 setup_iso_safe_charsets (attrs); | |
| 8019 | |
| 8020 if (i & CODING_ISO_FLAG_SEVEN_BITS) | |
| 8021 category = ((i & (CODING_ISO_FLAG_LOCKING_SHIFT | |
| 8022 | CODING_ISO_FLAG_SINGLE_SHIFT)) | |
| 8023 ? coding_category_iso_7_else | |
| 8024 : EQ (args[coding_arg_charset_list], Qiso_2022) | |
| 8025 ? coding_category_iso_7 | |
| 8026 : coding_category_iso_7_tight); | |
| 8027 else | |
| 8028 { | |
| 8029 int id = XINT (AREF (initial, 1)); | |
| 8030 | |
|
88977
3b05c02eebf2
(Fdefine_coding_system_internal): Fix category setting
Kenichi Handa <handa@m17n.org>
parents:
88950
diff
changeset
|
8031 category = (((i & CODING_ISO_FLAG_LOCKING_SHIFT) |
| 88365 | 8032 || EQ (args[coding_arg_charset_list], Qiso_2022) |
| 8033 || id < 0) | |
| 8034 ? coding_category_iso_8_else | |
| 8035 : (CHARSET_DIMENSION (CHARSET_FROM_ID (id)) == 1) | |
| 8036 ? coding_category_iso_8_1 | |
| 8037 : coding_category_iso_8_2); | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8038 } |
|
89227
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
8039 if (category != coding_category_iso_8_1 |
|
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
8040 && category != coding_category_iso_8_2) |
|
101ee928c088
(Fdefine_coding_system_internal): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
89225
diff
changeset
|
8041 CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; |
| 88365 | 8042 } |
| 8043 else if (EQ (coding_type, Qemacs_mule)) | |
| 8044 { | |
| 8045 if (EQ (args[coding_arg_charset_list], Qemacs_mule)) | |
| 8046 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
|
8047 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
| 88365 | 8048 category = coding_category_emacs_mule; |
| 8049 } | |
| 8050 else if (EQ (coding_type, Qshift_jis)) | |
| 8051 { | |
| 8052 | |
| 8053 struct charset *charset; | |
| 8054 | |
| 8055 if (XINT (Flength (charset_list)) != 3) | |
| 8056 error ("There should be just three charsets"); | |
| 8057 | |
| 8058 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
| 8059 if (CHARSET_DIMENSION (charset) != 1) | |
| 8060 error ("Dimension of charset %s is not one", | |
| 8061 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8062 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
|
8063 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
| 88365 | 8064 |
| 8065 charset_list = XCDR (charset_list); | |
| 8066 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
| 8067 if (CHARSET_DIMENSION (charset) != 1) | |
| 8068 error ("Dimension of charset %s is not one", | |
| 8069 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
| 8070 | |
| 8071 charset_list = XCDR (charset_list); | |
| 8072 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
| 8073 if (CHARSET_DIMENSION (charset) != 2) | |
| 8074 error ("Dimension of charset %s is not two", | |
| 8075 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
| 8076 | |
| 8077 category = coding_category_sjis; | |
| 8078 Vsjis_coding_system = name; | |
| 8079 } | |
| 8080 else if (EQ (coding_type, Qbig5)) | |
| 8081 { | |
| 8082 struct charset *charset; | |
| 8083 | |
| 8084 if (XINT (Flength (charset_list)) != 2) | |
| 8085 error ("There should be just two charsets"); | |
| 8086 | |
| 8087 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
| 8088 if (CHARSET_DIMENSION (charset) != 1) | |
| 8089 error ("Dimension of charset %s is not one", | |
| 8090 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
|
89225
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8091 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
|
8092 CODING_ATTR_ASCII_COMPAT (attrs) = Qt; |
| 88365 | 8093 |
| 8094 charset_list = XCDR (charset_list); | |
| 8095 charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | |
| 8096 if (CHARSET_DIMENSION (charset) != 2) | |
| 8097 error ("Dimension of charset %s is not two", | |
| 8098 XSYMBOL (CHARSET_NAME (charset))->name->data); | |
| 8099 | |
| 8100 category = coding_category_big5; | |
| 8101 Vbig5_coding_system = name; | |
| 8102 } | |
| 8103 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
|
8104 { |
|
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8105 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
|
8106 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
|
8107 } |
| 88365 | 8108 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
|
8109 { |
|
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8110 category = coding_category_utf_8; |
|
32058afc72e2
(detect_coding_charset): If only ASCII bytes are found, return 0.
Kenichi Handa <handa@m17n.org>
parents:
89221
diff
changeset
|
8111 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
|
8112 } |
| 88365 | 8113 else if (EQ (coding_type, Qundecided)) |
| 8114 category = coding_category_undecided; | |
| 8115 else | |
| 8116 error ("Invalid coding system type: %s", | |
| 8117 XSYMBOL (coding_type)->name->data); | |
| 8118 | |
| 8119 CODING_ATTR_CATEGORY (attrs) = make_number (category); | |
| 8120 | |
| 8121 eol_type = args[coding_arg_eol_type]; | |
| 8122 if (! NILP (eol_type) | |
| 8123 && ! EQ (eol_type, Qunix) | |
| 8124 && ! EQ (eol_type, Qdos) | |
| 8125 && ! EQ (eol_type, Qmac)) | |
| 8126 error ("Invalid eol-type"); | |
| 8127 | |
| 8128 aliases = Fcons (name, Qnil); | |
| 8129 | |
| 8130 if (NILP (eol_type)) | |
| 8131 { | |
| 8132 eol_type = make_subsidiaries (name); | |
| 8133 for (i = 0; i < 3; i++) | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8134 { |
| 88365 | 8135 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; |
| 8136 | |
| 8137 this_name = AREF (eol_type, i); | |
| 8138 this_aliases = Fcons (this_name, Qnil); | |
| 8139 this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); | |
| 8140 this_spec = Fmake_vector (make_number (3), attrs); | |
| 8141 ASET (this_spec, 1, this_aliases); | |
| 8142 ASET (this_spec, 2, this_eol_type); | |
| 8143 Fputhash (this_name, this_spec, Vcoding_system_hash_table); | |
| 8144 Vcoding_system_list = Fcons (this_name, Vcoding_system_list); | |
| 8145 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (this_name), Qnil), | |
| 8146 Vcoding_system_alist); | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8147 } |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8148 } |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8149 |
| 88365 | 8150 spec_vec = Fmake_vector (make_number (3), attrs); |
| 8151 ASET (spec_vec, 1, aliases); | |
| 8152 ASET (spec_vec, 2, eol_type); | |
| 8153 | |
| 8154 Fputhash (name, spec_vec, Vcoding_system_hash_table); | |
| 8155 Vcoding_system_list = Fcons (name, Vcoding_system_list); | |
| 8156 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), | |
| 8157 Vcoding_system_alist); | |
| 8158 | |
| 8159 { | |
| 8160 int id = coding_categories[category].id; | |
| 8161 | |
| 8162 if (id < 0 || EQ (name, CODING_ID_NAME (id))) | |
| 8163 setup_coding_system (name, &coding_categories[category]); | |
| 8164 } | |
| 8165 | |
| 8166 return Qnil; | |
| 8167 | |
| 8168 short_args: | |
| 8169 return Fsignal (Qwrong_number_of_arguments, | |
| 8170 Fcons (intern ("define-coding-system-internal"), | |
| 8171 make_number (nargs))); | |
| 8172 } | |
| 8173 | |
| 88645 | 8174 /* Fixme: should this record the alias relationships for |
| 8175 diagnostics? */ | |
| 88365 | 8176 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, |
| 8177 Sdefine_coding_system_alias, 2, 2, 0, | |
| 8178 doc: /* Define ALIAS as an alias for CODING-SYSTEM. */) | |
| 8179 (alias, coding_system) | |
| 8180 Lisp_Object alias, coding_system; | |
| 8181 { | |
| 8182 Lisp_Object spec, aliases, eol_type; | |
| 8183 | |
| 8184 CHECK_SYMBOL (alias); | |
| 8185 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
| 8186 aliases = AREF (spec, 1); | |
| 8187 while (!NILP (XCDR (aliases))) | |
| 8188 aliases = XCDR (aliases); | |
| 8189 XCDR (aliases) = Fcons (alias, Qnil); | |
| 8190 | |
| 8191 eol_type = AREF (spec, 2); | |
| 8192 if (VECTORP (eol_type)) | |
| 8193 { | |
| 8194 Lisp_Object subsidiaries; | |
| 8195 int i; | |
| 8196 | |
| 8197 subsidiaries = make_subsidiaries (alias); | |
| 8198 for (i = 0; i < 3; i++) | |
| 8199 Fdefine_coding_system_alias (AREF (subsidiaries, i), | |
| 8200 AREF (eol_type, i)); | |
| 8201 | |
| 8202 ASET (spec, 2, subsidiaries); | |
| 8203 } | |
| 8204 | |
| 8205 Fputhash (alias, spec, Vcoding_system_hash_table); | |
| 88485 | 8206 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (alias), Qnil), |
| 8207 Vcoding_system_alist); | |
| 88365 | 8208 |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8209 return Qnil; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8210 } |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8211 |
| 88365 | 8212 DEFUN ("coding-system-base", Fcoding_system_base, Scoding_system_base, |
| 8213 1, 1, 0, | |
| 8214 doc: /* Return the base of CODING-SYSTEM. | |
| 88645 | 8215 Any alias or subsidiary coding system is not a base coding system. */) |
| 88365 | 8216 (coding_system) |
| 8217 Lisp_Object coding_system; | |
| 8218 { | |
| 8219 Lisp_Object spec, attrs; | |
| 8220 | |
| 8221 if (NILP (coding_system)) | |
| 8222 return (Qno_conversion); | |
| 8223 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
| 8224 attrs = AREF (spec, 0); | |
| 8225 return CODING_ATTR_BASE_NAME (attrs); | |
| 8226 } | |
| 8227 | |
| 8228 DEFUN ("coding-system-plist", Fcoding_system_plist, Scoding_system_plist, | |
| 8229 1, 1, 0, | |
| 8230 doc: "Return the property list of CODING-SYSTEM.") | |
| 8231 (coding_system) | |
| 8232 Lisp_Object coding_system; | |
|
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
8233 { |
| 88365 | 8234 Lisp_Object spec, attrs; |
| 8235 | |
| 8236 if (NILP (coding_system)) | |
| 8237 coding_system = Qno_conversion; | |
| 8238 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
| 8239 attrs = AREF (spec, 0); | |
| 8240 return CODING_ATTR_PLIST (attrs); | |
| 8241 } | |
| 8242 | |
| 8243 | |
| 8244 DEFUN ("coding-system-aliases", Fcoding_system_aliases, Scoding_system_aliases, | |
| 8245 1, 1, 0, | |
| 88645 | 8246 doc: /* Return the list of aliases of CODING-SYSTEM. */) |
| 88365 | 8247 (coding_system) |
| 8248 Lisp_Object coding_system; | |
| 8249 { | |
| 8250 Lisp_Object spec; | |
| 8251 | |
| 8252 if (NILP (coding_system)) | |
| 8253 coding_system = Qno_conversion; | |
| 8254 CHECK_CODING_SYSTEM_GET_SPEC (coding_system, spec); | |
| 88645 | 8255 return AREF (spec, 1); |
| 88365 | 8256 } |
| 8257 | |
| 8258 DEFUN ("coding-system-eol-type", Fcoding_system_eol_type, | |
| 8259 Scoding_system_eol_type, 1, 1, 0, | |
| 8260 doc: /* Return eol-type of CODING-SYSTEM. | |
| 8261 An eol-type is integer 0, 1, 2, or a vector of coding systems. | |
| 8262 | |
| 8263 Integer values 0, 1, and 2 indicate a format of end-of-line; LF, CRLF, | |
| 8264 and CR respectively. | |
| 8265 | |
| 8266 A vector value indicates that a format of end-of-line should be | |
| 8267 detected automatically. Nth element of the vector is the subsidiary | |
| 8268 coding system whose eol-type is N. */) | |
| 8269 (coding_system) | |
| 8270 Lisp_Object coding_system; | |
| 8271 { | |
| 8272 Lisp_Object spec, eol_type; | |
| 8273 int n; | |
| 8274 | |
| 8275 if (NILP (coding_system)) | |
| 8276 coding_system = Qno_conversion; | |
| 8277 if (! CODING_SYSTEM_P (coding_system)) | |
| 8278 return Qnil; | |
| 8279 spec = CODING_SYSTEM_SPEC (coding_system); | |
| 8280 eol_type = AREF (spec, 2); | |
| 8281 if (VECTORP (eol_type)) | |
| 8282 return Fcopy_sequence (eol_type); | |
| 8283 n = EQ (eol_type, Qunix) ? 0 : EQ (eol_type, Qdos) ? 1 : 2; | |
| 8284 return make_number (n); | |
|
22226
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
8285 } |
|
557fac086b1b
(ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22186
diff
changeset
|
8286 |
| 17052 | 8287 #endif /* emacs */ |
| 8288 | |
| 8289 | |
|
22874
b133f07a76db
(Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22812
diff
changeset
|
8290 /*** 9. Post-amble ***/ |
| 17052 | 8291 |
| 21514 | 8292 void |
| 17052 | 8293 init_coding_once () |
| 8294 { | |
| 8295 int i; | |
| 8296 | |
| 88365 | 8297 for (i = 0; i < coding_category_max; i++) |
| 8298 { | |
| 8299 coding_categories[i].id = -1; | |
| 8300 coding_priorities[i] = i; | |
| 8301 } | |
| 17052 | 8302 |
| 8303 /* ISO2022 specific initialize routine. */ | |
| 8304 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
|
8305 iso_code_class[i] = ISO_control_0; |
| 17052 | 8306 for (i = 0x21; i < 0x7F; i++) |
| 8307 iso_code_class[i] = ISO_graphic_plane_0; | |
| 8308 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
|
8309 iso_code_class[i] = ISO_control_1; |
| 17052 | 8310 for (i = 0xA1; i < 0xFF; i++) |
| 8311 iso_code_class[i] = ISO_graphic_plane_1; | |
| 8312 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
| 8313 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
| 8314 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
| 8315 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
| 8316 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
| 8317 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
| 8318 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
| 8319 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
| 8320 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
| 8321 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
| 8322 | |
|
26067
f54ca66e2571
(code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents:
25860
diff
changeset
|
8323 inhibit_pre_post_conversion = 0; |
| 88365 | 8324 |
| 8325 for (i = 0; i < 256; i++) | |
| 8326 { | |
| 8327 emacs_mule_bytes[i] = 1; | |
| 8328 } | |
|
88876
af9012fdad56
(LEADING_CODE_PRIVATE_11, LEADING_CODE_PRIVATE_12,
Kenichi Handa <handa@m17n.org>
parents:
88862
diff
changeset
|
8329 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
|
8330 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
|
8331 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
|
8332 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
|
8333 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8334 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8335 #ifdef emacs |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8336 |
| 21514 | 8337 void |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8338 syms_of_coding () |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
8339 { |
| 88365 | 8340 staticpro (&Vcoding_system_hash_table); |
| 8341 Vcoding_system_hash_table = Fmakehash (Qeq); | |
| 8342 | |
| 8343 staticpro (&Vsjis_coding_system); | |
| 8344 Vsjis_coding_system = Qnil; | |
| 8345 | |
| 8346 staticpro (&Vbig5_coding_system); | |
| 8347 Vbig5_coding_system = Qnil; | |
| 8348 | |
| 8349 staticpro (&Vcode_conversion_work_buf_list); | |
| 8350 Vcode_conversion_work_buf_list = Qnil; | |
| 8351 | |
| 8352 staticpro (&Vcode_conversion_reused_work_buf); | |
| 8353 Vcode_conversion_reused_work_buf = Qnil; | |
| 8354 | |
| 8355 DEFSYM (Qcharset, "charset"); | |
| 8356 DEFSYM (Qtarget_idx, "target-idx"); | |
| 8357 DEFSYM (Qcoding_system_history, "coding-system-history"); | |
|
19750
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
8358 Fset (Qcoding_system_history, Qnil); |
|
95e4e1cba6ac
(Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19747
diff
changeset
|
8359 |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8360 /* 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
|
8361 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
|
8362 /* 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
|
8363 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
|
8364 |
| 88365 | 8365 DEFSYM (Qcall_process, "call-process"); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8366 /* 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
|
8367 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
|
8368 |
| 88365 | 8369 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
|
8370 /* 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
|
8371 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
|
8372 |
| 88365 | 8373 DEFSYM (Qstart_process, "start-process"); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8374 /* 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
|
8375 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
|
8376 |
| 88365 | 8377 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
|
8378 /* 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
|
8379 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
|
8380 |
| 88365 | 8381 DEFSYM (Qcoding_system, "coding-system"); |
| 8382 DEFSYM (Qcoding_aliases, "coding-aliases"); | |
| 8383 | |
| 8384 DEFSYM (Qeol_type, "eol-type"); | |
| 8385 DEFSYM (Qunix, "unix"); | |
| 8386 DEFSYM (Qdos, "dos"); | |
| 8387 | |
| 8388 DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); | |
| 8389 DEFSYM (Qpost_read_conversion, "post-read-conversion"); | |
| 8390 DEFSYM (Qpre_write_conversion, "pre-write-conversion"); | |
| 8391 DEFSYM (Qdefault_char, "default-char"); | |
| 8392 DEFSYM (Qundecided, "undecided"); | |
| 8393 DEFSYM (Qno_conversion, "no-conversion"); | |
| 8394 DEFSYM (Qraw_text, "raw-text"); | |
| 8395 | |
| 8396 DEFSYM (Qiso_2022, "iso-2022"); | |
| 8397 | |
| 8398 DEFSYM (Qutf_8, "utf-8"); | |
| 8399 | |
| 8400 DEFSYM (Qutf_16, "utf-16"); | |
| 8401 DEFSYM (Qutf_16_be, "utf-16-be"); | |
| 8402 DEFSYM (Qutf_16_be_nosig, "utf-16-be-nosig"); | |
| 8403 DEFSYM (Qutf_16_le, "utf-16-l3"); | |
| 8404 DEFSYM (Qutf_16_le_nosig, "utf-16-le-nosig"); | |
| 8405 DEFSYM (Qsignature, "signature"); | |
| 8406 DEFSYM (Qendian, "endian"); | |
| 8407 DEFSYM (Qbig, "big"); | |
| 8408 DEFSYM (Qlittle, "little"); | |
| 8409 | |
| 8410 DEFSYM (Qshift_jis, "shift-jis"); | |
| 8411 DEFSYM (Qbig5, "big5"); | |
| 8412 | |
| 8413 DEFSYM (Qcoding_system_p, "coding-system-p"); | |
| 8414 | |
| 8415 DEFSYM (Qcoding_system_error, "coding-system-error"); | |
| 17052 | 8416 Fput (Qcoding_system_error, Qerror_conditions, |
| 8417 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
| 8418 Fput (Qcoding_system_error, Qerror_message, | |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8419 build_string ("Invalid coding system")); |
| 17052 | 8420 |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8421 /* 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
|
8422 Setting this variable twice is harmless. |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8423 But don't staticpro it here--that is done in alloc.c. */ |
|
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8424 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
| 88365 | 8425 |
| 8426 DEFSYM (Qtranslation_table, "translation-table"); | |
| 8427 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); | |
| 8428 DEFSYM (Qtranslation_table_id, "translation-table-id"); | |
| 8429 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); | |
| 8430 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); | |
| 8431 | |
| 8432 DEFSYM (Qvalid_codes, "valid-codes"); | |
| 8433 | |
| 8434 DEFSYM (Qemacs_mule, "emacs-mule"); | |
| 8435 | |
| 8436 Vcoding_category_table | |
| 8437 = Fmake_vector (make_number (coding_category_max), Qnil); | |
| 8438 staticpro (&Vcoding_category_table); | |
| 8439 /* Followings are target of code detection. */ | |
| 8440 ASET (Vcoding_category_table, coding_category_iso_7, | |
| 8441 intern ("coding-category-iso-7")); | |
| 8442 ASET (Vcoding_category_table, coding_category_iso_7_tight, | |
| 8443 intern ("coding-category-iso-7-tight")); | |
| 8444 ASET (Vcoding_category_table, coding_category_iso_8_1, | |
| 8445 intern ("coding-category-iso-8-1")); | |
| 8446 ASET (Vcoding_category_table, coding_category_iso_8_2, | |
| 8447 intern ("coding-category-iso-8-2")); | |
| 8448 ASET (Vcoding_category_table, coding_category_iso_7_else, | |
| 8449 intern ("coding-category-iso-7-else")); | |
| 8450 ASET (Vcoding_category_table, coding_category_iso_8_else, | |
| 8451 intern ("coding-category-iso-8-else")); | |
| 8452 ASET (Vcoding_category_table, coding_category_utf_8, | |
| 8453 intern ("coding-category-utf-8")); | |
| 8454 ASET (Vcoding_category_table, coding_category_utf_16_be, | |
| 8455 intern ("coding-category-utf-16-be")); | |
| 8456 ASET (Vcoding_category_table, coding_category_utf_16_le, | |
| 8457 intern ("coding-category-utf-16-le")); | |
| 8458 ASET (Vcoding_category_table, coding_category_utf_16_be_nosig, | |
| 8459 intern ("coding-category-utf-16-be-nosig")); | |
| 8460 ASET (Vcoding_category_table, coding_category_utf_16_le_nosig, | |
| 8461 intern ("coding-category-utf-16-le-nosig")); | |
| 8462 ASET (Vcoding_category_table, coding_category_charset, | |
| 8463 intern ("coding-category-charset")); | |
| 8464 ASET (Vcoding_category_table, coding_category_sjis, | |
| 8465 intern ("coding-category-sjis")); | |
| 8466 ASET (Vcoding_category_table, coding_category_big5, | |
| 8467 intern ("coding-category-big5")); | |
| 8468 ASET (Vcoding_category_table, coding_category_ccl, | |
| 8469 intern ("coding-category-ccl")); | |
| 8470 ASET (Vcoding_category_table, coding_category_emacs_mule, | |
| 8471 intern ("coding-category-emacs-mule")); | |
| 8472 /* Followings are NOT target of code detection. */ | |
| 8473 ASET (Vcoding_category_table, coding_category_raw_text, | |
| 8474 intern ("coding-category-raw-text")); | |
| 8475 ASET (Vcoding_category_table, coding_category_undecided, | |
| 8476 intern ("coding-category-undecided")); | |
| 8477 | |
| 17052 | 8478 defsubr (&Scoding_system_p); |
| 8479 defsubr (&Sread_coding_system); | |
| 8480 defsubr (&Sread_non_nil_coding_system); | |
| 8481 defsubr (&Scheck_coding_system); | |
| 8482 defsubr (&Sdetect_coding_region); | |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8483 defsubr (&Sdetect_coding_string); |
|
30487
6165da9c89c6
(Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
30384
diff
changeset
|
8484 defsubr (&Sfind_coding_systems_region_internal); |
| 88365 | 8485 defsubr (&Scheck_coding_systems_region); |
| 17052 | 8486 defsubr (&Sdecode_coding_region); |
| 8487 defsubr (&Sencode_coding_region); | |
| 8488 defsubr (&Sdecode_coding_string); | |
| 8489 defsubr (&Sencode_coding_string); | |
| 8490 defsubr (&Sdecode_sjis_char); | |
| 8491 defsubr (&Sencode_sjis_char); | |
| 8492 defsubr (&Sdecode_big5_char); | |
| 8493 defsubr (&Sencode_big5_char); | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8494 defsubr (&Sset_terminal_coding_system_internal); |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8495 defsubr (&Sset_safe_terminal_coding_system_internal); |
| 17052 | 8496 defsubr (&Sterminal_coding_system); |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
8497 defsubr (&Sset_keyboard_coding_system_internal); |
| 17052 | 8498 defsubr (&Skeyboard_coding_system); |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
8499 defsubr (&Sfind_operation_coding_system); |
| 88365 | 8500 defsubr (&Sset_coding_system_priority); |
| 8501 defsubr (&Sdefine_coding_system_internal); | |
| 8502 defsubr (&Sdefine_coding_system_alias); | |
| 8503 defsubr (&Scoding_system_base); | |
| 8504 defsubr (&Scoding_system_plist); | |
| 8505 defsubr (&Scoding_system_aliases); | |
| 8506 defsubr (&Scoding_system_eol_type); | |
| 8507 defsubr (&Scoding_system_priority_list); | |
| 17052 | 8508 |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8509 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
|
8510 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
|
8511 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8512 Do not alter the value of this variable manually. This variable should be |
| 88365 | 8513 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
|
8514 `define-coding-system-alias'. */); |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8515 Vcoding_system_list = Qnil; |
|
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8516 |
|
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8517 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
|
8518 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
|
8519 Each element is one element list of coding system name. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8520 This variable is given to `completing-read' as TABLE argument. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8521 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8522 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
|
8523 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
|
8524 `define-coding-system-alias'. */); |
|
20105
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8525 Vcoding_system_alist = Qnil; |
|
c017642863c2
(Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
19824
diff
changeset
|
8526 |
| 17052 | 8527 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
|
8528 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
|
8529 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8530 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
|
8531 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
|
8532 one algorithm agrees with a byte sequence of source text, the coding |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8533 system bound to the corresponding coding-category is selected. */); |
| 17052 | 8534 { |
| 8535 int i; | |
| 8536 | |
| 8537 Vcoding_category_list = Qnil; | |
| 88365 | 8538 for (i = coding_category_max - 1; i >= 0; i--) |
| 17052 | 8539 Vcoding_category_list |
|
20718
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8540 = Fcons (XVECTOR (Vcoding_category_table)->contents[i], |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8541 Vcoding_category_list); |
| 17052 | 8542 } |
| 8543 | |
| 8544 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
|
8545 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
|
8546 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
|
8547 If the value is a coding system, it is used for decoding on read operation. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8548 If not, an appropriate element is used from one of the coding system alists: |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8549 There are three such tables, `file-coding-system-alist', |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8550 `process-coding-system-alist', and `network-coding-system-alist'. */); |
| 17052 | 8551 Vcoding_system_for_read = Qnil; |
| 8552 | |
| 8553 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
|
8554 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
|
8555 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
|
8556 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
|
8557 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
|
8558 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8559 If this does not specify a coding system, an appropriate element |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8560 is used from one of the coding system alists: |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8561 There are three such tables, `file-coding-system-alist', |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8562 `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
|
8563 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
|
8564 the value of `buffer-file-coding-system' is used. */); |
| 17052 | 8565 Vcoding_system_for_write = Qnil; |
| 8566 | |
| 8567 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
| 88365 | 8568 doc: /* |
| 8569 Coding system used in the latest file or process I/O. */); | |
| 17052 | 8570 Vlast_coding_system_used = Qnil; |
| 8571 | |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8572 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
| 88365 | 8573 doc: /* |
| 8574 *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
|
8575 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
|
8576 such conversion. */); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8577 inhibit_eol_conversion = 0; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
8578 |
|
21574
30394e3ae7f8
(syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents:
21520
diff
changeset
|
8579 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system, |
| 88365 | 8580 doc: /* |
| 8581 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
|
8582 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
|
8583 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
|
8584 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
|
8585 |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8586 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
| 88365 | 8587 doc: /* |
| 8588 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
|
8589 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
|
8590 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
|
8591 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
|
8592 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
|
8593 the file contents. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8594 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
|
8595 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
|
8596 If VAL is a function symbol, the function must return a coding system |
|
41678
5aa97e545399
(syms_of_coding) <Qchar_coding_system>: Give it an
Dave Love <fx@gnu.org>
parents:
41624
diff
changeset
|
8597 or a cons of coding systems which are used as above. The function gets |
|
5aa97e545399
(syms_of_coding) <Qchar_coding_system>: Give it an
Dave Love <fx@gnu.org>
parents:
41624
diff
changeset
|
8598 the arguments with which `find-operation-coding-systems' was called. |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8599 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8600 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
|
8601 and the variable `auto-coding-alist'. */); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8602 Vfile_coding_system_alist = Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8603 |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8604 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
| 88365 | 8605 doc: /* |
| 8606 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
|
8607 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
|
8608 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
|
8609 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
|
8610 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
|
8611 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
|
8612 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
|
8613 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
|
8614 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
|
8615 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
|
8616 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8617 See also the function `find-operation-coding-system'. */); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8618 Vprocess_coding_system_alist = Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8619 |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8620 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
| 88365 | 8621 doc: /* |
| 8622 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
|
8623 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
|
8624 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
|
8625 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
|
8626 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
|
8627 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
|
8628 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
|
8629 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
|
8630 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
|
8631 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
|
8632 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
|
8633 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8634 See also the function `find-operation-coding-system'. */); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8635 Vnetwork_coding_system_alist = Qnil; |
| 17052 | 8636 |
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8637 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
|
8638 doc: /* Coding system to use with system messages. |
|
6f20449b7e12
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41006
diff
changeset
|
8639 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
|
8640 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
|
8641 |
|
29182
1d1c27067af4
(encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents:
29172
diff
changeset
|
8642 /* 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
|
8643 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix, |
| 88365 | 8644 doc: /* |
| 8645 *String displayed in mode line for UNIX-like (LF) end-of-line format. */); | |
|
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8646 eol_mnemonic_unix = build_string (":"); |
|
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8647 |
|
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8648 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos, |
| 88365 | 8649 doc: /* |
| 8650 *String displayed in mode line for DOS-like (CRLF) end-of-line format. */); | |
|
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8651 eol_mnemonic_dos = build_string ("\\"); |
|
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8652 |
|
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8653 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac, |
| 88365 | 8654 doc: /* |
| 8655 *String displayed in mode line for MAC-like (CR) end-of-line format. */); | |
|
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8656 eol_mnemonic_mac = build_string ("/"); |
|
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8657 |
|
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8658 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided, |
| 88365 | 8659 doc: /* |
| 8660 *String displayed in mode line when end-of-line format is not yet determined. */); | |
|
24200
b9d9fccad516
(syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents:
24178
diff
changeset
|
8661 eol_mnemonic_undecided = build_string (":"); |
| 17052 | 8662 |
|
22119
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8663 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation, |
| 88365 | 8664 doc: /* |
| 8665 *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
|
8666 Venable_character_translation = Qt; |
|
592bb8b9bcfd
Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents:
22020
diff
changeset
|
8667 |
|
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8668 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
|
8669 &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
|
8670 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
|
8671 Vstandard_translation_table_for_decode = Qnil; |
|
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8672 |
|
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22166
diff
changeset
|
8673 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
|
8674 &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
|
8675 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
|
8676 Vstandard_translation_table_for_encode = Qnil; |
| 17052 | 8677 |
| 88365 | 8678 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
|
8679 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
|
8680 While encoding, if a charset (car part of an element) is found, |
| 88365 | 8681 designate it with the escape sequence identifying revision (cdr part |
| 8682 of the element). */); | |
| 8683 Vcharset_revision_table = Qnil; | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8684 |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8685 DEFVAR_LISP ("default-process-coding-system", |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
8686 &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
|
8687 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
|
8688 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
|
8689 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
|
8690 Vdefault_process_coding_system = Qnil; |
|
19280
e755044718ee
(ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
19193
diff
changeset
|
8691 |
|
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8692 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table, |
| 88365 | 8693 doc: /* |
| 8694 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
|
8695 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
|
8696 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
|
8697 \(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
|
8698 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
|
8699 `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
|
8700 or reading output of a subprocess. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8701 Only 128th through 159th elements has a meaning. */); |
|
19365
d9374f5ebd3a
(CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents:
19285
diff
changeset
|
8702 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
|
8703 |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8704 DEFVAR_LISP ("select-safe-coding-system-function", |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8705 &Vselect_safe_coding_system_function, |
| 88365 | 8706 doc: /* |
| 8707 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
|
8708 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8709 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
|
8710 coding system which can encode the text in the case that a default |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8711 coding system used in each operation can't encode the text. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8712 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8713 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
|
8714 Vselect_safe_coding_system_function = Qnil; |
|
c600dea3b06b
Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents:
20708
diff
changeset
|
8715 |
|
30292
14a9937df1f5
(syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents:
30263
diff
changeset
|
8716 DEFVAR_BOOL ("inhibit-iso-escape-detection", |
|
30204
35aec8514228
(inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents:
29985
diff
changeset
|
8717 &inhibit_iso_escape_detection, |
| 88365 | 8718 doc: /* |
| 8719 If non-nil, Emacs ignores ISO2022's escape sequence on code detection. | |
|
40713
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8720 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8721 By default, on reading a file, Emacs tries to detect how the text is |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8722 encoded. This code detection is sensitive to escape sequences. If |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8723 the sequence is valid as ISO2022, the code is determined as one of |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8724 the ISO2022 encodings, and the file is decoded by the corresponding |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8725 coding system (e.g. `iso-2022-7bit'). |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8726 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8727 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
|
8728 a file as is. In such a case, you can set this variable to non-nil. |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8729 Then, as the code detection ignores any escape sequences, no file is |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8730 detected as encoded in some ISO2022 encoding. The result is that all |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8731 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
|
8732 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8733 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
|
8734 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
|
8735 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
|
8736 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
|
8737 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
|
8738 |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8739 The other way to read escape sequences in a file without decoding is |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8740 to explicitly specify some coding system that doesn't use ISO2022's |
|
42351475da08
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Jan?k <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
8741 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
|
8742 inhibit_iso_escape_detection = 0; |
|
88456
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8743 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8744 { |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8745 Lisp_Object args[coding_arg_max]; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8746 Lisp_Object plist[14]; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8747 int i; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8748 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8749 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
|
8750 args[i] = Qnil; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8751 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8752 plist[0] = intern (":name"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8753 plist[1] = args[coding_arg_name] = Qno_conversion; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8754 plist[2] = intern (":mnemonic"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8755 plist[3] = args[coding_arg_mnemonic] = make_number ('='); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8756 plist[4] = intern (":coding-type"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8757 plist[5] = args[coding_arg_coding_type] = Qraw_text; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8758 plist[6] = intern (":ascii-compatible-p"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8759 plist[7] = args[coding_arg_ascii_compatible_p] = Qt; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8760 plist[8] = intern (":default-char"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8761 plist[9] = args[coding_arg_default_char] = make_number (0); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8762 plist[10] = intern (":docstring"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8763 plist[11] = build_string ("Do no conversion.\n\ |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8764 \n\ |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8765 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
|
8766 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
|
8767 character."); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8768 plist[12] = intern (":eol-type"); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8769 plist[13] = args[coding_arg_eol_type] = Qunix; |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8770 args[coding_arg_plist] = Flist (14, plist); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8771 Fdefine_coding_system_internal (coding_arg_max, args); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8772 } |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8773 |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8774 setup_coding_system (Qno_conversion, &keyboard_coding); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8775 setup_coding_system (Qno_conversion, &terminal_coding); |
|
a7b309f72920
(coding_alloc_by_making_gap): Check the case that the
Kenichi Handa <handa@m17n.org>
parents:
88443
diff
changeset
|
8776 setup_coding_system (Qno_conversion, &safe_terminal_coding); |
| 17052 | 8777 } |
| 8778 | |
|
26088
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8779 char * |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8780 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
|
8781 int error_number; |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8782 { |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8783 char *str; |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8784 |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26240
diff
changeset
|
8785 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
|
8786 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
|
8787 |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8788 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
|
8789 { |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8790 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
|
8791 Vlocale_coding_system, |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8792 0); |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8793 str = (char *) XSTRING (dec)->data; |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8794 } |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8795 |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8796 return str; |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8797 } |
|
b7aa6ac26872
Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents:
26067
diff
changeset
|
8798 |
| 17052 | 8799 #endif /* emacs */ |
