Mercurial > emacs
annotate src/coding.c @ 19181:917138730635
(detect_eol_type): Fix previous change.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Wed, 06 Aug 1997 01:09:16 +0000 |
| parents | 04ed7c3f5cee |
| children | 1701f2296f99 |
| rev | line source |
|---|---|
| 17052 | 1 /* Coding system handler (conversion, detection, and etc). |
|
18269
888bfd80db2c
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18180
diff
changeset
|
2 Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN. |
|
888bfd80db2c
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18180
diff
changeset
|
3 Licensed to the Free Software Foundation. |
| 17052 | 4 |
| 17071 | 5 This file is part of GNU Emacs. |
| 6 | |
| 7 GNU Emacs is free software; you can redistribute it and/or modify | |
| 8 it under the terms of the GNU General Public License as published by | |
| 9 the Free Software Foundation; either version 2, or (at your option) | |
| 10 any later version. | |
| 11 | |
| 12 GNU Emacs is distributed in the hope that it will be useful, | |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 GNU General Public License for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU General Public License | |
| 18 along with GNU Emacs; see the file COPYING. If not, write to | |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 20 Boston, MA 02111-1307, USA. */ | |
| 17052 | 21 |
| 22 /*** TABLE OF CONTENTS *** | |
| 23 | |
| 24 1. Preamble | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
25 2. Emacs' internal format (emacs-mule) handlers |
| 17052 | 26 3. ISO2022 handlers |
| 27 4. Shift-JIS and BIG5 handlers | |
| 28 5. End-of-line handlers | |
| 29 6. C library functions | |
| 30 7. Emacs Lisp library functions | |
| 31 8. Post-amble | |
| 32 | |
| 33 */ | |
| 34 | |
| 35 /*** GENERAL NOTE on CODING SYSTEM *** | |
| 36 | |
| 37 Coding system is an encoding mechanism of one or more character | |
| 38 sets. Here's a list of coding systems which Emacs can handle. When | |
| 39 we say "decode", it means converting some other coding system to | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
40 Emacs' internal format (emacs-internal), and when we say "encode", |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
41 it means converting the coding system emacs-mule to some other |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
42 coding system. |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
43 |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
44 0. Emacs' internal format (emacs-mule) |
| 17052 | 45 |
| 46 Emacs itself holds a multi-lingual character in a buffer and a string | |
| 18766 | 47 in a special format. Details are described in section 2. |
| 17052 | 48 |
| 49 1. ISO2022 | |
| 50 | |
| 51 The most famous coding system for multiple character sets. X's | |
| 18766 | 52 Compound Text, various EUCs (Extended Unix Code), and coding |
| 53 systems used in Internet communication such as ISO-2022-JP are | |
| 54 all variants of ISO2022. Details are described in section 3. | |
| 17052 | 55 |
| 56 2. SJIS (or Shift-JIS or MS-Kanji-Code) | |
| 57 | |
| 58 A coding system to encode character sets: ASCII, JISX0201, and | |
| 59 JISX0208. Widely used for PC's in Japan. Details are described in | |
| 18766 | 60 section 4. |
| 17052 | 61 |
| 62 3. BIG5 | |
| 63 | |
| 64 A coding system to encode character sets: ASCII and Big5. Widely | |
| 65 used by Chinese (mainly in Taiwan and Hong Kong). Details are | |
| 18766 | 66 described in section 4. In this file, when we write "BIG5" |
| 67 (all uppercase), we mean the coding system, and when we write | |
| 68 "Big5" (capitalized), we mean the character set. | |
| 69 | |
| 70 4. Other | |
| 71 | |
| 72 If a user wants to read/write a text encoded in a coding system not | |
| 17052 | 73 listed above, he can supply a decoder and an encoder for it in CCL |
| 74 (Code Conversion Language) programs. Emacs executes the CCL program | |
| 75 while reading/writing. | |
| 76 | |
| 18766 | 77 Emacs represents a coding-system by a Lisp symbol that has a property |
| 17052 | 78 `coding-system'. But, before actually using the coding-system, the |
| 79 information about it is set in a structure of type `struct | |
| 18766 | 80 coding_system' for rapid processing. See section 6 for more details. |
| 17052 | 81 |
| 82 */ | |
| 83 | |
| 84 /*** GENERAL NOTES on END-OF-LINE FORMAT *** | |
| 85 | |
| 86 How end-of-line of a text is encoded depends on a system. For | |
| 87 instance, Unix's format is just one byte of `line-feed' code, | |
| 18766 | 88 whereas DOS's format is two-byte sequence of `carriage-return' and |
| 17052 | 89 `line-feed' codes. MacOS's format is one byte of `carriage-return'. |
| 90 | |
| 18766 | 91 Since text characters encoding and end-of-line encoding are |
| 92 independent, any coding system described above can take | |
| 17052 | 93 any format of end-of-line. So, Emacs has information of format of |
| 18766 | 94 end-of-line in each coding-system. See section 6 for more details. |
| 17052 | 95 |
| 96 */ | |
| 97 | |
| 98 /*** GENERAL NOTES on `detect_coding_XXX ()' functions *** | |
| 99 | |
| 100 These functions check if a text between SRC and SRC_END is encoded | |
| 101 in the coding system category XXX. Each returns an integer value in | |
| 102 which appropriate flag bits for the category XXX is set. The flag | |
| 103 bits are defined in macros CODING_CATEGORY_MASK_XXX. Below is the | |
| 104 template of these functions. */ | |
| 105 #if 0 | |
| 106 int | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
107 detect_coding_emacs_mule (src, src_end) |
| 17052 | 108 unsigned char *src, *src_end; |
| 109 { | |
| 110 ... | |
| 111 } | |
| 112 #endif | |
| 113 | |
| 114 /*** GENERAL NOTES on `decode_coding_XXX ()' functions *** | |
| 115 | |
| 116 These functions decode SRC_BYTES length text at SOURCE encoded in | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
117 CODING to Emacs' internal format (emacs-mule). The resulting text |
| 18766 | 118 goes to a place pointed to by DESTINATION, the length of which should |
| 119 not exceed DST_BYTES. The number of bytes actually processed is | |
| 120 returned as *CONSUMED. The return value is the length of the decoded | |
| 121 text. Below is a template of these functions. */ | |
| 17052 | 122 #if 0 |
| 123 decode_coding_XXX (coding, source, destination, src_bytes, dst_bytes, consumed) | |
| 124 struct coding_system *coding; | |
| 125 unsigned char *source, *destination; | |
| 126 int src_bytes, dst_bytes; | |
| 127 int *consumed; | |
| 128 { | |
| 129 ... | |
| 130 } | |
| 131 #endif | |
| 132 | |
| 133 /*** GENERAL NOTES on `encode_coding_XXX ()' functions *** | |
| 134 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
135 These functions encode SRC_BYTES length text at SOURCE of Emacs' |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
136 internal format (emacs-mule) to CODING. The resulting text goes to |
| 18766 | 137 a place pointed to by DESTINATION, the length of which should not |
| 138 exceed DST_BYTES. The number of bytes actually processed is | |
| 139 returned as *CONSUMED. The return value is the length of the | |
| 140 encoded text. Below is a template of these functions. */ | |
| 17052 | 141 #if 0 |
| 142 encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes, consumed) | |
| 143 struct coding_system *coding; | |
| 144 unsigned char *source, *destination; | |
| 145 int src_bytes, dst_bytes; | |
| 146 int *consumed; | |
| 147 { | |
| 148 ... | |
| 149 } | |
| 150 #endif | |
| 151 | |
| 152 /*** COMMONLY USED MACROS ***/ | |
| 153 | |
| 154 /* The following three macros ONE_MORE_BYTE, TWO_MORE_BYTES, and | |
| 155 THREE_MORE_BYTES safely get one, two, and three bytes from the | |
| 156 source text respectively. If there are not enough bytes in the | |
| 157 source, they jump to `label_end_of_loop'. The caller should set | |
| 158 variables `src' and `src_end' to appropriate areas in advance. */ | |
| 159 | |
| 160 #define ONE_MORE_BYTE(c1) \ | |
| 161 do { \ | |
| 162 if (src < src_end) \ | |
| 163 c1 = *src++; \ | |
| 164 else \ | |
| 165 goto label_end_of_loop; \ | |
| 166 } while (0) | |
| 167 | |
| 168 #define TWO_MORE_BYTES(c1, c2) \ | |
| 169 do { \ | |
| 170 if (src + 1 < src_end) \ | |
| 171 c1 = *src++, c2 = *src++; \ | |
| 172 else \ | |
| 173 goto label_end_of_loop; \ | |
| 174 } while (0) | |
| 175 | |
| 176 #define THREE_MORE_BYTES(c1, c2, c3) \ | |
| 177 do { \ | |
| 178 if (src + 2 < src_end) \ | |
| 179 c1 = *src++, c2 = *src++, c3 = *src++; \ | |
| 180 else \ | |
| 181 goto label_end_of_loop; \ | |
| 182 } while (0) | |
| 183 | |
| 184 /* The following three macros DECODE_CHARACTER_ASCII, | |
| 185 DECODE_CHARACTER_DIMENSION1, and DECODE_CHARACTER_DIMENSION2 put | |
| 186 the multi-byte form of a character of each class at the place | |
| 187 pointed by `dst'. The caller should set the variable `dst' to | |
| 188 point to an appropriate area and the variable `coding' to point to | |
| 189 the coding-system of the currently decoding text in advance. */ | |
| 190 | |
| 191 /* Decode one ASCII character C. */ | |
| 192 | |
| 193 #define DECODE_CHARACTER_ASCII(c) \ | |
| 194 do { \ | |
| 195 if (COMPOSING_P (coding->composing)) \ | |
| 196 *dst++ = 0xA0, *dst++ = (c) | 0x80; \ | |
| 197 else \ | |
| 198 *dst++ = (c); \ | |
| 199 } while (0) | |
| 200 | |
| 18766 | 201 /* Decode one DIMENSION1 character whose charset is CHARSET and whose |
| 17052 | 202 position-code is C. */ |
| 203 | |
| 204 #define DECODE_CHARACTER_DIMENSION1(charset, c) \ | |
| 205 do { \ | |
| 206 unsigned char leading_code = CHARSET_LEADING_CODE_BASE (charset); \ | |
| 207 if (COMPOSING_P (coding->composing)) \ | |
| 208 *dst++ = leading_code + 0x20; \ | |
| 209 else \ | |
| 210 *dst++ = leading_code; \ | |
| 211 if (leading_code = CHARSET_LEADING_CODE_EXT (charset)) \ | |
| 212 *dst++ = leading_code; \ | |
| 213 *dst++ = (c) | 0x80; \ | |
| 214 } while (0) | |
| 215 | |
| 18766 | 216 /* Decode one DIMENSION2 character whose charset is CHARSET and whose |
| 17052 | 217 position-codes are C1 and C2. */ |
| 218 | |
| 219 #define DECODE_CHARACTER_DIMENSION2(charset, c1, c2) \ | |
| 220 do { \ | |
| 221 DECODE_CHARACTER_DIMENSION1 (charset, c1); \ | |
| 222 *dst++ = (c2) | 0x80; \ | |
| 223 } while (0) | |
| 224 | |
| 225 | |
| 226 /*** 1. Preamble ***/ | |
| 227 | |
| 228 #include <stdio.h> | |
| 229 | |
| 230 #ifdef emacs | |
| 231 | |
| 232 #include <config.h> | |
| 233 #include "lisp.h" | |
| 234 #include "buffer.h" | |
| 235 #include "charset.h" | |
| 236 #include "ccl.h" | |
| 237 #include "coding.h" | |
| 238 #include "window.h" | |
| 239 | |
| 240 #else /* not emacs */ | |
| 241 | |
| 242 #include "mulelib.h" | |
| 243 | |
| 244 #endif /* not emacs */ | |
| 245 | |
| 246 Lisp_Object Qcoding_system, Qeol_type; | |
| 247 Lisp_Object Qbuffer_file_coding_system; | |
| 248 Lisp_Object Qpost_read_conversion, Qpre_write_conversion; | |
| 249 | |
| 250 extern Lisp_Object Qinsert_file_contents, Qwrite_region; | |
| 251 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | |
| 252 Lisp_Object Qstart_process, Qopen_network_stream; | |
| 253 Lisp_Object Qtarget_idx; | |
| 254 | |
| 255 /* Mnemonic character of each format of end-of-line. */ | |
| 256 int eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac; | |
| 257 /* Mnemonic character to indicate format of end-of-line is not yet | |
| 258 decided. */ | |
| 259 int eol_mnemonic_undecided; | |
| 260 | |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
261 /* Format of end-of-line decided by system. This is CODING_EOL_LF on |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
262 Unix, CODING_EOL_CRLF on DOS/Windows, and CODING_EOL_CR on Mac. */ |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
263 int system_eol_type; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
264 |
| 17052 | 265 #ifdef emacs |
| 266 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
267 Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; |
| 17052 | 268 |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
269 /* Coding system emacs-mule is for converting only end-of-line format. */ |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
270 Lisp_Object Qemacs_mule; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
271 |
| 17052 | 272 /* Coding-systems are handed between Emacs Lisp programs and C internal |
| 273 routines by the following three variables. */ | |
| 274 /* Coding-system for reading files and receiving data from process. */ | |
| 275 Lisp_Object Vcoding_system_for_read; | |
| 276 /* Coding-system for writing files and sending data to process. */ | |
| 277 Lisp_Object Vcoding_system_for_write; | |
| 278 /* Coding-system actually used in the latest I/O. */ | |
| 279 Lisp_Object Vlast_coding_system_used; | |
| 280 | |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
281 /* 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
|
282 int inhibit_eol_conversion; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
283 |
| 17052 | 284 /* Coding-system of what terminal accept for displaying. */ |
| 285 struct coding_system terminal_coding; | |
| 286 | |
| 287 /* Coding-system of what is sent from terminal keyboard. */ | |
| 288 struct coding_system keyboard_coding; | |
| 289 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
290 Lisp_Object Vfile_coding_system_alist; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
291 Lisp_Object Vprocess_coding_system_alist; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
292 Lisp_Object Vnetwork_coding_system_alist; |
| 17052 | 293 |
| 294 #endif /* emacs */ | |
| 295 | |
| 296 Lisp_Object Qcoding_category_index; | |
| 297 | |
| 298 /* List of symbols `coding-category-xxx' ordered by priority. */ | |
| 299 Lisp_Object Vcoding_category_list; | |
| 300 | |
| 301 /* Table of coding-systems currently assigned to each coding-category. */ | |
| 302 Lisp_Object coding_category_table[CODING_CATEGORY_IDX_MAX]; | |
| 303 | |
| 304 /* Table of names of symbol for each coding-category. */ | |
| 305 char *coding_category_name[CODING_CATEGORY_IDX_MAX] = { | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
306 "coding-category-emacs-mule", |
| 17052 | 307 "coding-category-sjis", |
| 308 "coding-category-iso-7", | |
| 309 "coding-category-iso-8-1", | |
| 310 "coding-category-iso-8-2", | |
|
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
311 "coding-category-iso-7-else", |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
312 "coding-category-iso-8-else", |
| 17052 | 313 "coding-category-big5", |
| 314 "coding-category-binary" | |
| 315 }; | |
| 316 | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
317 /* Flag to tell if we look up unification table on character code |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
318 conversion. */ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
319 Lisp_Object Venable_character_unification; |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
320 /* Standard unification table to look up on decoding (reading). */ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
321 Lisp_Object Vstandard_character_unification_table_for_decode; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
322 /* Standard unification table to look up on encoding (writing). */ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
323 Lisp_Object Vstandard_character_unification_table_for_encode; |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
324 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
325 Lisp_Object Qcharacter_unification_table; |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
326 Lisp_Object Qcharacter_unification_table_for_decode; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
327 Lisp_Object Qcharacter_unification_table_for_encode; |
| 17052 | 328 |
| 329 /* Alist of charsets vs revision number. */ | |
| 330 Lisp_Object Vcharset_revision_alist; | |
| 331 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
332 /* Default coding systems used for process I/O. */ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
333 Lisp_Object Vdefault_process_coding_system; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
334 |
| 17052 | 335 |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
336 /*** 2. Emacs internal format (emacs-mule) handlers ***/ |
| 17052 | 337 |
| 338 /* Emacs' internal format for encoding multiple character sets is a | |
| 18766 | 339 kind of multi-byte encoding, i.e. characters are encoded by |
| 340 variable-length sequences of one-byte codes. ASCII characters | |
| 341 and control characters (e.g. `tab', `newline') are represented by | |
| 342 one-byte sequences which are their ASCII codes, in the range 0x00 | |
| 343 through 0x7F. The other characters are represented by a sequence | |
| 344 of `base leading-code', optional `extended leading-code', and one | |
| 345 or two `position-code's. The length of the sequence is determined | |
| 346 by the base leading-code. Leading-code takes the range 0x80 | |
| 347 through 0x9F, whereas extended leading-code and position-code take | |
| 348 the range 0xA0 through 0xFF. See `charset.h' for more details | |
| 349 about leading-code and position-code. | |
| 350 | |
| 351 There's one exception to this rule. Special leading-code | |
| 17052 | 352 `leading-code-composition' denotes that the following several |
| 353 characters should be composed into one character. Leading-codes of | |
| 354 components (except for ASCII) are added 0x20. An ASCII character | |
| 355 component is represented by a 2-byte sequence of `0xA0' and | |
| 18766 | 356 `ASCII-code + 0x80'. See also the comments in `charset.h' for the |
| 357 details of composite character. Hence, we can summarize the code | |
| 17052 | 358 range as follows: |
| 359 | |
| 360 --- CODE RANGE of Emacs' internal format --- | |
| 361 (character set) (range) | |
| 362 ASCII 0x00 .. 0x7F | |
| 363 ELSE (1st byte) 0x80 .. 0x9F | |
| 364 (rest bytes) 0xA0 .. 0xFF | |
| 365 --------------------------------------------- | |
| 366 | |
| 367 */ | |
| 368 | |
| 369 enum emacs_code_class_type emacs_code_class[256]; | |
| 370 | |
| 371 /* Go to the next statement only if *SRC is accessible and the code is | |
| 372 greater than 0xA0. */ | |
| 373 #define CHECK_CODE_RANGE_A0_FF \ | |
| 374 do { \ | |
| 375 if (src >= src_end) \ | |
| 376 goto label_end_of_switch; \ | |
| 377 else if (*src++ < 0xA0) \ | |
| 378 return 0; \ | |
| 379 } while (0) | |
| 380 | |
| 381 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
| 382 Check if a text is encoded in Emacs' internal format. If it is, | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
383 return CODING_CATEGORY_MASK_EMASC_MULE, else return 0. */ |
| 17052 | 384 |
| 385 int | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
386 detect_coding_emacs_mule (src, src_end) |
| 17052 | 387 unsigned char *src, *src_end; |
| 388 { | |
| 389 unsigned char c; | |
| 390 int composing = 0; | |
| 391 | |
| 392 while (src < src_end) | |
| 393 { | |
| 394 c = *src++; | |
| 395 | |
| 396 if (composing) | |
| 397 { | |
| 398 if (c < 0xA0) | |
| 399 composing = 0; | |
| 400 else | |
| 401 c -= 0x20; | |
| 402 } | |
| 403 | |
| 404 switch (emacs_code_class[c]) | |
| 405 { | |
| 406 case EMACS_ascii_code: | |
| 407 case EMACS_linefeed_code: | |
| 408 break; | |
| 409 | |
| 410 case EMACS_control_code: | |
| 411 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) | |
| 412 return 0; | |
| 413 break; | |
| 414 | |
| 415 case EMACS_invalid_code: | |
| 416 return 0; | |
| 417 | |
| 418 case EMACS_leading_code_composition: /* c == 0x80 */ | |
| 419 if (composing) | |
| 420 CHECK_CODE_RANGE_A0_FF; | |
| 421 else | |
| 422 composing = 1; | |
| 423 break; | |
| 424 | |
| 425 case EMACS_leading_code_4: | |
| 426 CHECK_CODE_RANGE_A0_FF; | |
| 427 /* fall down to check it two more times ... */ | |
| 428 | |
| 429 case EMACS_leading_code_3: | |
| 430 CHECK_CODE_RANGE_A0_FF; | |
| 431 /* fall down to check it one more time ... */ | |
| 432 | |
| 433 case EMACS_leading_code_2: | |
| 434 CHECK_CODE_RANGE_A0_FF; | |
| 435 break; | |
| 436 | |
| 437 default: | |
| 438 label_end_of_switch: | |
| 439 break; | |
| 440 } | |
| 441 } | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
442 return CODING_CATEGORY_MASK_EMACS_MULE; |
| 17052 | 443 } |
| 444 | |
| 445 | |
| 446 /*** 3. ISO2022 handlers ***/ | |
| 447 | |
| 448 /* The following note describes the coding system ISO2022 briefly. | |
| 18766 | 449 Since the intention of this note is to help in understanding of |
| 450 the programs in this file, some parts are NOT ACCURATE or OVERLY | |
| 17052 | 451 SIMPLIFIED. For the thorough understanding, please refer to the |
| 452 original document of ISO2022. | |
| 453 | |
| 454 ISO2022 provides many mechanisms to encode several character sets | |
| 18766 | 455 in 7-bit and 8-bit environment. If one chooses 7-bite environment, |
| 17052 | 456 all text is encoded by codes of less than 128. This may make the |
| 18766 | 457 encoded text a little bit longer, but the text gets more stability |
| 458 to pass through several gateways (some of them strip off the MSB). | |
| 459 | |
| 460 There are two kinds of character set: control character set and | |
| 17052 | 461 graphic character set. The former contains control characters such |
| 462 as `newline' and `escape' to provide control functions (control | |
| 18766 | 463 functions are provided also by escape sequences). The latter |
| 17052 | 464 contains graphic characters such as ' A' and '-'. Emacs recognizes |
| 465 two control character sets and many graphic character sets. | |
| 466 | |
| 467 Graphic character sets are classified into one of the following | |
| 468 four classes, DIMENSION1_CHARS94, DIMENSION1_CHARS96, | |
| 469 DIMENSION2_CHARS94, DIMENSION2_CHARS96 according to the number of | |
| 470 bytes (DIMENSION) and the number of characters in one dimension | |
| 471 (CHARS) of the set. In addition, each character set is assigned an | |
| 472 identification tag (called "final character" and denoted as <F> | |
| 473 here after) which is unique in each class. <F> of each character | |
| 474 set is decided by ECMA(*) when it is registered in ISO. Code range | |
| 475 of <F> is 0x30..0x7F (0x30..0x3F are for private use only). | |
| 476 | |
| 477 Note (*): ECMA = European Computer Manufacturers Association | |
| 478 | |
| 479 Here are examples of graphic character set [NAME(<F>)]: | |
| 480 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ... | |
| 481 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ... | |
| 482 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ... | |
| 483 o DIMENSION2_CHARS96 -- none for the moment | |
| 484 | |
| 485 A code area (1byte=8bits) is divided into 4 areas, C0, GL, C1, and GR. | |
| 486 C0 [0x00..0x1F] -- control character plane 0 | |
| 487 GL [0x20..0x7F] -- graphic character plane 0 | |
| 488 C1 [0x80..0x9F] -- control character plane 1 | |
| 489 GR [0xA0..0xFF] -- graphic character plane 1 | |
| 490 | |
| 491 A control character set is directly designated and invoked to C0 or | |
| 492 C1 by an escape sequence. The most common case is that ISO646's | |
| 493 control character set is designated/invoked to C0 and ISO6429's | |
| 494 control character set is designated/invoked to C1, and usually | |
| 495 these designations/invocations are omitted in a coded text. With | |
| 496 7-bit environment, only C0 can be used, and a control character for | |
| 497 C1 is encoded by an appropriate escape sequence to fit in the | |
| 498 environment. All control characters for C1 are defined the | |
| 499 corresponding escape sequences. | |
| 500 | |
| 501 A graphic character set is at first designated to one of four | |
| 502 graphic registers (G0 through G3), then these graphic registers are | |
| 503 invoked to GL or GR. These designations and invocations can be | |
| 504 done independently. The most common case is that G0 is invoked to | |
| 505 GL, G1 is invoked to GR, and ASCII is designated to G0, and usually | |
| 506 these invocations and designations are omitted in a coded text. | |
| 507 With 7-bit environment, only GL can be used. | |
| 508 | |
| 509 When a graphic character set of CHARS94 is invoked to GL, code 0x20 | |
| 510 and 0x7F of GL area work as control characters SPACE and DEL | |
| 511 respectively, and code 0xA0 and 0xFF of GR area should not be used. | |
| 512 | |
| 513 There are two ways of invocation: locking-shift and single-shift. | |
| 514 With locking-shift, the invocation lasts until the next different | |
| 515 invocation, whereas with single-shift, the invocation works only | |
| 516 for the following character and doesn't affect locking-shift. | |
| 517 Invocations are done by the following control characters or escape | |
| 518 sequences. | |
| 519 | |
| 520 ---------------------------------------------------------------------- | |
| 521 function control char escape sequence description | |
| 522 ---------------------------------------------------------------------- | |
| 523 SI (shift-in) 0x0F none invoke G0 to GL | |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
524 SO (shift-out) 0x0E none invoke G1 to GL |
| 17052 | 525 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL |
| 526 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL | |
| 527 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 into GL | |
| 528 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 into GL | |
| 529 ---------------------------------------------------------------------- | |
| 530 The first four are for locking-shift. Control characters for these | |
| 531 functions are defined by macros ISO_CODE_XXX in `coding.h'. | |
| 532 | |
| 533 Designations are done by the following escape sequences. | |
| 534 ---------------------------------------------------------------------- | |
| 535 escape sequence description | |
| 536 ---------------------------------------------------------------------- | |
| 537 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0 | |
| 538 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1 | |
| 539 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2 | |
| 540 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3 | |
| 541 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*) | |
| 542 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1 | |
| 543 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2 | |
| 544 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3 | |
| 545 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**) | |
| 546 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1 | |
| 547 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2 | |
| 548 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3 | |
| 549 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*) | |
| 550 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1 | |
| 551 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2 | |
| 552 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3 | |
| 553 ---------------------------------------------------------------------- | |
| 554 | |
| 555 In this list, "DIMENSION1_CHARS94<F>" means a graphic character set | |
| 556 of dimension 1, chars 94, and final character <F>, and etc. | |
| 557 | |
| 558 Note (*): Although these designations are not allowed in ISO2022, | |
| 559 Emacs accepts them on decoding, and produces them on encoding | |
| 560 CHARS96 character set in a coding system which is characterized as | |
| 561 7-bit environment, non-locking-shift, and non-single-shift. | |
| 562 | |
| 563 Note (**): If <F> is '@', 'A', or 'B', the intermediate character | |
| 564 '(' can be omitted. We call this as "short-form" here after. | |
| 565 | |
| 566 Now you may notice that there are a lot of ways for encoding the | |
| 18766 | 567 same multilingual text in ISO2022. Actually, there exists many |
| 17052 | 568 coding systems such as Compound Text (used in X's inter client |
| 569 communication, ISO-2022-JP (used in Japanese Internet), ISO-2022-KR | |
| 570 (used in Korean Internet), EUC (Extended UNIX Code, used in Asian | |
| 571 localized platforms), and all of these are variants of ISO2022. | |
| 572 | |
| 573 In addition to the above, Emacs handles two more kinds of escape | |
| 574 sequences: ISO6429's direction specification and Emacs' private | |
| 575 sequence for specifying character composition. | |
| 576 | |
| 577 ISO6429's direction specification takes the following format: | |
| 578 o CSI ']' -- end of the current direction | |
| 579 o CSI '0' ']' -- end of the current direction | |
| 580 o CSI '1' ']' -- start of left-to-right text | |
| 581 o CSI '2' ']' -- start of right-to-left text | |
| 582 The control character CSI (0x9B: control sequence introducer) is | |
| 583 abbreviated to the escape sequence ESC '[' in 7-bit environment. | |
| 584 | |
| 585 Character composition specification takes the following format: | |
| 586 o ESC '0' -- start character composition | |
| 587 o ESC '1' -- end character composition | |
| 588 Since these are not standard escape sequences of any ISO, the use | |
| 589 of them for these meaning is restricted to Emacs only. */ | |
| 590 | |
| 591 enum iso_code_class_type iso_code_class[256]; | |
| 592 | |
| 593 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
| 594 Check if a text is encoded in ISO2022. If it is, returns an | |
| 595 integer in which appropriate flag bits any of: | |
| 596 CODING_CATEGORY_MASK_ISO_7 | |
| 597 CODING_CATEGORY_MASK_ISO_8_1 | |
| 598 CODING_CATEGORY_MASK_ISO_8_2 | |
|
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
599 CODING_CATEGORY_MASK_ISO_7_ELSE |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
600 CODING_CATEGORY_MASK_ISO_8_ELSE |
| 17052 | 601 are set. If a code which should never appear in ISO2022 is found, |
| 602 returns 0. */ | |
| 603 | |
| 604 int | |
| 605 detect_coding_iso2022 (src, src_end) | |
| 606 unsigned char *src, *src_end; | |
| 607 { | |
|
18310
a97ed8efcb6a
(detect_coding_iso2022): Initilize mask correctly.
Kenichi Handa <handa@m17n.org>
parents:
18269
diff
changeset
|
608 int mask = (CODING_CATEGORY_MASK_ISO_7 |
|
a97ed8efcb6a
(detect_coding_iso2022): Initilize mask correctly.
Kenichi Handa <handa@m17n.org>
parents:
18269
diff
changeset
|
609 | CODING_CATEGORY_MASK_ISO_8_1 |
|
a97ed8efcb6a
(detect_coding_iso2022): Initilize mask correctly.
Kenichi Handa <handa@m17n.org>
parents:
18269
diff
changeset
|
610 | CODING_CATEGORY_MASK_ISO_8_2 |
|
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
611 | CODING_CATEGORY_MASK_ISO_7_ELSE |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
612 | CODING_CATEGORY_MASK_ISO_8_ELSE |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
613 ); |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
614 int g1 = 0; /* 1 iff designating to G1. */ |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
615 int c, i; |
| 17052 | 616 |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
617 while (src < src_end) |
| 17052 | 618 { |
| 619 c = *src++; | |
| 620 switch (c) | |
| 621 { | |
| 622 case ISO_CODE_ESC: | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
623 if (src >= src_end) |
| 17052 | 624 break; |
| 625 c = *src++; | |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
626 if ((c >= '(' && c <= '/')) |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
627 { |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
628 /* Designation sequence for a charset of dimension 1. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
629 if (src >= src_end) |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
630 break; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
631 c = *src++; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
632 if (c < ' ' || c >= 0x80) |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
633 /* Invalid designation sequence. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
634 return 0; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
635 } |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
636 else if (c == '$') |
| 17052 | 637 { |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
638 /* Designation sequence for a charset of dimension 2. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
639 if (src >= src_end) |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
640 break; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
641 c = *src++; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
642 if (c >= '@' && c <= 'B') |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
643 /* Designation for JISX0208.1978, GB2312, or JISX0208. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
644 ; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
645 else if (c >= '(' && c <= '/') |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
646 { |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
647 if (src >= src_end) |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
648 break; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
649 c = *src++; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
650 if (c < ' ' || c >= 0x80) |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
651 /* Invalid designation sequence. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
652 return 0; |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
653 } |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
654 else |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
655 /* Invalid designation sequence. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
656 return 0; |
| 17052 | 657 } |
| 658 else if (c == 'N' || c == 'O' || c == 'n' || c == 'o') | |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
659 /* Locking shift. */ |
|
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
660 mask &= (CODING_CATEGORY_MASK_ISO_7_ELSE |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
661 | CODING_CATEGORY_MASK_ISO_8_ELSE); |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
662 else if (c == '0' || c == '1' || c == '2') |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
663 /* Start/end composition. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
664 ; |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
665 else |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
666 /* Invalid escape sequence. */ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
667 return 0; |
| 17052 | 668 break; |
| 669 | |
| 670 case ISO_CODE_SO: | |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
671 mask &= (CODING_CATEGORY_MASK_ISO_7_ELSE |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
672 | CODING_CATEGORY_MASK_ISO_8_ELSE); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
673 break; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
674 |
| 17052 | 675 case ISO_CODE_CSI: |
| 676 case ISO_CODE_SS2: | |
| 677 case ISO_CODE_SS3: | |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
678 return CODING_CATEGORY_MASK_ISO_8_ELSE; |
| 17052 | 679 |
| 680 default: | |
| 681 if (c < 0x80) | |
| 682 break; | |
| 683 else if (c < 0xA0) | |
| 684 return 0; | |
| 685 else | |
| 686 { | |
|
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
687 unsigned char *src_begin = src; |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
688 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
689 mask &= ~(CODING_CATEGORY_MASK_ISO_7 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
690 | CODING_CATEGORY_MASK_ISO_7_ELSE); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
691 while (src < src_end && *src >= 0xA0) |
|
18787
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
692 src++; |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
693 if ((src - src_begin - 1) & 1 && src < src_end) |
| 17052 | 694 mask &= ~CODING_CATEGORY_MASK_ISO_8_2; |
| 695 } | |
| 696 break; | |
| 697 } | |
| 698 } | |
| 699 | |
| 700 return mask; | |
| 701 } | |
| 702 | |
| 703 /* Decode a character of which charset is CHARSET and the 1st position | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
704 code is C1. If dimension of CHARSET is 2, the 2nd position code is |
| 17052 | 705 fetched from SRC and set to C2. If CHARSET is negative, it means |
| 706 that we are decoding ill formed text, and what we can do is just to | |
| 707 read C1 as is. */ | |
| 708 | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
709 #define DECODE_ISO_CHARACTER(charset, c1) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
710 do { \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
711 int c_alt, charset_alt = (charset); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
712 if (COMPOSING_HEAD_P (coding->composing)) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
713 { \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
714 *dst++ = LEADING_CODE_COMPOSITION; \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
715 if (COMPOSING_WITH_RULE_P (coding->composing)) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
716 /* To tell composition rules are embeded. */ \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
717 *dst++ = 0xFF; \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
718 coding->composing += 2; \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
719 } \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
720 if ((charset) >= 0) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
721 { \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
722 if (CHARSET_DIMENSION (charset) == 2) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
723 ONE_MORE_BYTE (c2); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
724 if (!NILP (unification_table) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
725 && ((c_alt = unify_char (unification_table, \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
726 -1, (charset), c1, c2)) >= 0)) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
727 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
728 } \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
729 if (charset_alt == CHARSET_ASCII || charset_alt < 0) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
730 DECODE_CHARACTER_ASCII (c1); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
731 else if (CHARSET_DIMENSION (charset_alt) == 1) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
732 DECODE_CHARACTER_DIMENSION1 (charset_alt, c1); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
733 else \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
734 DECODE_CHARACTER_DIMENSION2 (charset_alt, c1, c2); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
735 if (COMPOSING_WITH_RULE_P (coding->composing)) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
736 /* To tell a composition rule follows. */ \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
737 coding->composing = COMPOSING_WITH_RULE_RULE; \ |
| 17052 | 738 } while (0) |
| 739 | |
| 740 /* Set designation state into CODING. */ | |
| 741 #define DECODE_DESIGNATION(reg, dimension, chars, final_char) \ | |
| 742 do { \ | |
|
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
743 int charset = ISO_CHARSET_TABLE (make_number (dimension), \ |
|
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
744 make_number (chars), \ |
|
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
745 make_number (final_char)); \ |
| 17052 | 746 if (charset >= 0) \ |
| 747 { \ | |
| 748 if (coding->direction == 1 \ | |
| 749 && CHARSET_REVERSE_CHARSET (charset) >= 0) \ | |
| 750 charset = CHARSET_REVERSE_CHARSET (charset); \ | |
| 751 CODING_SPEC_ISO_DESIGNATION (coding, reg) = charset; \ | |
| 752 } \ | |
| 753 } while (0) | |
| 754 | |
| 755 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ | |
| 756 | |
| 757 int | |
| 758 decode_coding_iso2022 (coding, source, destination, | |
| 759 src_bytes, dst_bytes, consumed) | |
| 760 struct coding_system *coding; | |
| 761 unsigned char *source, *destination; | |
| 762 int src_bytes, dst_bytes; | |
| 763 int *consumed; | |
| 764 { | |
| 765 unsigned char *src = source; | |
| 766 unsigned char *src_end = source + src_bytes; | |
| 767 unsigned char *dst = destination; | |
| 768 unsigned char *dst_end = destination + dst_bytes; | |
| 769 /* Since the maximum bytes produced by each loop is 7, we subtract 6 | |
| 770 from DST_END to assure that overflow checking is necessary only | |
| 771 at the head of loop. */ | |
| 772 unsigned char *adjusted_dst_end = dst_end - 6; | |
| 773 int charset; | |
| 774 /* Charsets invoked to graphic plane 0 and 1 respectively. */ | |
| 775 int charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); | |
| 776 int charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
777 Lisp_Object unification_table |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
778 = coding->character_unification_table_for_decode; |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
779 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
780 if (!NILP (Venable_character_unification) && NILP (unification_table)) |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
781 unification_table = Vstandard_character_unification_table_for_decode; |
| 17052 | 782 |
| 783 while (src < src_end && dst < adjusted_dst_end) | |
| 784 { | |
| 785 /* SRC_BASE remembers the start position in source in each loop. | |
| 786 The loop will be exited when there's not enough source text | |
| 787 to analyze long escape sequence or 2-byte code (within macros | |
| 788 ONE_MORE_BYTE or TWO_MORE_BYTES). In that case, SRC is reset | |
| 789 to SRC_BASE before exiting. */ | |
| 790 unsigned char *src_base = src; | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
791 int c1 = *src++, c2; |
| 17052 | 792 |
| 793 switch (iso_code_class [c1]) | |
| 794 { | |
| 795 case ISO_0x20_or_0x7F: | |
| 796 if (!coding->composing | |
| 797 && (charset0 < 0 || CHARSET_CHARS (charset0) == 94)) | |
| 798 { | |
| 799 /* This is SPACE or DEL. */ | |
| 800 *dst++ = c1; | |
| 801 break; | |
| 802 } | |
| 803 /* This is a graphic character, we fall down ... */ | |
| 804 | |
| 805 case ISO_graphic_plane_0: | |
| 806 if (coding->composing == COMPOSING_WITH_RULE_RULE) | |
| 807 { | |
| 808 /* This is a composition rule. */ | |
| 809 *dst++ = c1 | 0x80; | |
| 810 coding->composing = COMPOSING_WITH_RULE_TAIL; | |
| 811 } | |
| 812 else | |
| 813 DECODE_ISO_CHARACTER (charset0, c1); | |
| 814 break; | |
| 815 | |
| 816 case ISO_0xA0_or_0xFF: | |
| 817 if (charset1 < 0 || CHARSET_CHARS (charset1) == 94) | |
| 818 { | |
| 819 /* Invalid code. */ | |
| 820 *dst++ = c1; | |
| 821 break; | |
| 822 } | |
| 823 /* This is a graphic character, we fall down ... */ | |
| 824 | |
| 825 case ISO_graphic_plane_1: | |
| 826 DECODE_ISO_CHARACTER (charset1, c1); | |
| 827 break; | |
| 828 | |
| 829 case ISO_control_code: | |
| 830 /* All ISO2022 control characters in this class have the | |
| 831 same representation in Emacs internal format. */ | |
| 832 *dst++ = c1; | |
| 833 break; | |
| 834 | |
| 835 case ISO_carriage_return: | |
| 836 if (coding->eol_type == CODING_EOL_CR) | |
| 837 { | |
| 838 *dst++ = '\n'; | |
| 839 } | |
| 840 else if (coding->eol_type == CODING_EOL_CRLF) | |
| 841 { | |
| 842 ONE_MORE_BYTE (c1); | |
| 843 if (c1 == ISO_CODE_LF) | |
| 844 *dst++ = '\n'; | |
| 845 else | |
| 846 { | |
| 847 src--; | |
| 848 *dst++ = c1; | |
| 849 } | |
| 850 } | |
| 851 else | |
| 852 { | |
| 853 *dst++ = c1; | |
| 854 } | |
| 855 break; | |
| 856 | |
| 857 case ISO_shift_out: | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
858 if (CODING_SPEC_ISO_DESIGNATION (coding, 1) < 0) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
859 goto label_invalid_escape_sequence; |
| 17052 | 860 CODING_SPEC_ISO_INVOCATION (coding, 0) = 1; |
| 861 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); | |
| 862 break; | |
| 863 | |
| 864 case ISO_shift_in: | |
| 865 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0; | |
| 866 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); | |
| 867 break; | |
| 868 | |
| 869 case ISO_single_shift_2_7: | |
| 870 case ISO_single_shift_2: | |
| 871 /* SS2 is handled as an escape sequence of ESC 'N' */ | |
| 872 c1 = 'N'; | |
| 873 goto label_escape_sequence; | |
| 874 | |
| 875 case ISO_single_shift_3: | |
| 876 /* SS2 is handled as an escape sequence of ESC 'O' */ | |
| 877 c1 = 'O'; | |
| 878 goto label_escape_sequence; | |
| 879 | |
| 880 case ISO_control_sequence_introducer: | |
| 881 /* CSI is handled as an escape sequence of ESC '[' ... */ | |
| 882 c1 = '['; | |
| 883 goto label_escape_sequence; | |
| 884 | |
| 885 case ISO_escape: | |
| 886 ONE_MORE_BYTE (c1); | |
| 887 label_escape_sequence: | |
| 888 /* Escape sequences handled by Emacs are invocation, | |
| 889 designation, direction specification, and character | |
| 890 composition specification. */ | |
| 891 switch (c1) | |
| 892 { | |
| 893 case '&': /* revision of following character set */ | |
| 894 ONE_MORE_BYTE (c1); | |
| 895 if (!(c1 >= '@' && c1 <= '~')) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
896 goto label_invalid_escape_sequence; |
| 17052 | 897 ONE_MORE_BYTE (c1); |
| 898 if (c1 != ISO_CODE_ESC) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
899 goto label_invalid_escape_sequence; |
| 17052 | 900 ONE_MORE_BYTE (c1); |
| 901 goto label_escape_sequence; | |
| 902 | |
| 903 case '$': /* designation of 2-byte character set */ | |
| 904 ONE_MORE_BYTE (c1); | |
| 905 if (c1 >= '@' && c1 <= 'B') | |
| 906 { /* designation of JISX0208.1978, GB2312.1980, | |
| 907 or JISX0208.1980 */ | |
| 908 DECODE_DESIGNATION (0, 2, 94, c1); | |
| 909 } | |
| 910 else if (c1 >= 0x28 && c1 <= 0x2B) | |
| 911 { /* designation of DIMENSION2_CHARS94 character set */ | |
| 912 ONE_MORE_BYTE (c2); | |
| 913 DECODE_DESIGNATION (c1 - 0x28, 2, 94, c2); | |
| 914 } | |
| 915 else if (c1 >= 0x2C && c1 <= 0x2F) | |
| 916 { /* designation of DIMENSION2_CHARS96 character set */ | |
| 917 ONE_MORE_BYTE (c2); | |
| 918 DECODE_DESIGNATION (c1 - 0x2C, 2, 96, c2); | |
| 919 } | |
| 920 else | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
921 goto label_invalid_escape_sequence; |
| 17052 | 922 break; |
| 923 | |
| 924 case 'n': /* invocation of locking-shift-2 */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
925 if (CODING_SPEC_ISO_DESIGNATION (coding, 2) < 0) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
926 goto label_invalid_escape_sequence; |
| 17052 | 927 CODING_SPEC_ISO_INVOCATION (coding, 0) = 2; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
928 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); |
| 17052 | 929 break; |
| 930 | |
| 931 case 'o': /* invocation of locking-shift-3 */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
932 if (CODING_SPEC_ISO_DESIGNATION (coding, 3) < 0) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
933 goto label_invalid_escape_sequence; |
| 17052 | 934 CODING_SPEC_ISO_INVOCATION (coding, 0) = 3; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
935 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); |
| 17052 | 936 break; |
| 937 | |
| 938 case 'N': /* invocation of single-shift-2 */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
939 if (CODING_SPEC_ISO_DESIGNATION (coding, 2) < 0) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
940 goto label_invalid_escape_sequence; |
| 17052 | 941 ONE_MORE_BYTE (c1); |
| 942 charset = CODING_SPEC_ISO_DESIGNATION (coding, 2); | |
| 943 DECODE_ISO_CHARACTER (charset, c1); | |
| 944 break; | |
| 945 | |
| 946 case 'O': /* invocation of single-shift-3 */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
947 if (CODING_SPEC_ISO_DESIGNATION (coding, 3) < 0) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
948 goto label_invalid_escape_sequence; |
| 17052 | 949 ONE_MORE_BYTE (c1); |
| 950 charset = CODING_SPEC_ISO_DESIGNATION (coding, 3); | |
| 951 DECODE_ISO_CHARACTER (charset, c1); | |
| 952 break; | |
| 953 | |
| 954 case '0': /* start composing without embeded rules */ | |
| 955 coding->composing = COMPOSING_NO_RULE_HEAD; | |
| 956 break; | |
| 957 | |
| 958 case '1': /* end composing */ | |
| 959 coding->composing = COMPOSING_NO; | |
| 960 break; | |
| 961 | |
| 962 case '2': /* start composing with embeded rules */ | |
| 963 coding->composing = COMPOSING_WITH_RULE_HEAD; | |
| 964 break; | |
| 965 | |
| 966 case '[': /* specification of direction */ | |
| 967 /* For the moment, nested direction is not supported. | |
| 968 So, the value of `coding->direction' is 0 or 1: 0 | |
| 969 means left-to-right, 1 means right-to-left. */ | |
| 970 ONE_MORE_BYTE (c1); | |
| 971 switch (c1) | |
| 972 { | |
| 973 case ']': /* end of the current direction */ | |
| 974 coding->direction = 0; | |
| 975 | |
| 976 case '0': /* end of the current direction */ | |
| 977 case '1': /* start of left-to-right direction */ | |
| 978 ONE_MORE_BYTE (c1); | |
| 979 if (c1 == ']') | |
| 980 coding->direction = 0; | |
| 981 else | |
| 982 goto label_invalid_escape_sequence; | |
| 983 break; | |
| 984 | |
| 985 case '2': /* start of right-to-left direction */ | |
| 986 ONE_MORE_BYTE (c1); | |
| 987 if (c1 == ']') | |
| 988 coding->direction= 1; | |
| 989 else | |
| 990 goto label_invalid_escape_sequence; | |
| 991 break; | |
| 992 | |
| 993 default: | |
| 994 goto label_invalid_escape_sequence; | |
| 995 } | |
| 996 break; | |
| 997 | |
| 998 default: | |
| 999 if (c1 >= 0x28 && c1 <= 0x2B) | |
| 1000 { /* designation of DIMENSION1_CHARS94 character set */ | |
| 1001 ONE_MORE_BYTE (c2); | |
| 1002 DECODE_DESIGNATION (c1 - 0x28, 1, 94, c2); | |
| 1003 } | |
| 1004 else if (c1 >= 0x2C && c1 <= 0x2F) | |
| 1005 { /* designation of DIMENSION1_CHARS96 character set */ | |
| 1006 ONE_MORE_BYTE (c2); | |
| 1007 DECODE_DESIGNATION (c1 - 0x2C, 1, 96, c2); | |
| 1008 } | |
| 1009 else | |
| 1010 { | |
| 1011 goto label_invalid_escape_sequence; | |
| 1012 } | |
| 1013 } | |
| 1014 /* We must update these variables now. */ | |
| 1015 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); | |
| 1016 charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1); | |
| 1017 break; | |
| 1018 | |
| 1019 label_invalid_escape_sequence: | |
| 1020 { | |
| 1021 int length = src - src_base; | |
| 1022 | |
| 1023 bcopy (src_base, dst, length); | |
| 1024 dst += length; | |
| 1025 } | |
| 1026 } | |
| 1027 continue; | |
| 1028 | |
| 1029 label_end_of_loop: | |
| 1030 coding->carryover_size = src - src_base; | |
| 1031 bcopy (src_base, coding->carryover, coding->carryover_size); | |
| 1032 src = src_base; | |
| 1033 break; | |
| 1034 } | |
| 1035 | |
| 1036 /* If this is the last block of the text to be decoded, we had | |
| 1037 better just flush out all remaining codes in the text although | |
| 1038 they are not valid characters. */ | |
| 1039 if (coding->last_block) | |
| 1040 { | |
| 1041 bcopy (src, dst, src_end - src); | |
| 1042 dst += (src_end - src); | |
| 1043 src = src_end; | |
| 1044 } | |
| 1045 *consumed = src - source; | |
| 1046 return dst - destination; | |
| 1047 } | |
| 1048 | |
| 18766 | 1049 /* ISO2022 encoding stuff. */ |
| 17052 | 1050 |
| 1051 /* | |
| 18766 | 1052 It is not enough to say just "ISO2022" on encoding, we have to |
| 17052 | 1053 specify more details. In Emacs, each coding-system of ISO2022 |
| 1054 variant has the following specifications: | |
| 1055 1. Initial designation to G0 thru G3. | |
| 1056 2. Allows short-form designation? | |
| 1057 3. ASCII should be designated to G0 before control characters? | |
| 1058 4. ASCII should be designated to G0 at end of line? | |
| 1059 5. 7-bit environment or 8-bit environment? | |
| 1060 6. Use locking-shift? | |
| 1061 7. Use Single-shift? | |
| 1062 And the following two are only for Japanese: | |
| 1063 8. Use ASCII in place of JIS0201-1976-Roman? | |
| 1064 9. Use JISX0208-1983 in place of JISX0208-1978? | |
| 1065 These specifications are encoded in `coding->flags' as flag bits | |
| 1066 defined by macros CODING_FLAG_ISO_XXX. See `coding.h' for more | |
| 18766 | 1067 details. |
| 17052 | 1068 */ |
| 1069 | |
| 1070 /* Produce codes (escape sequence) for designating CHARSET to graphic | |
| 1071 register REG. If <final-char> of CHARSET is '@', 'A', or 'B' and | |
| 1072 the coding system CODING allows, produce designation sequence of | |
| 1073 short-form. */ | |
| 1074 | |
| 1075 #define ENCODE_DESIGNATION(charset, reg, coding) \ | |
| 1076 do { \ | |
| 1077 unsigned char final_char = CHARSET_ISO_FINAL_CHAR (charset); \ | |
| 1078 char *intermediate_char_94 = "()*+"; \ | |
| 1079 char *intermediate_char_96 = ",-./"; \ | |
| 1080 Lisp_Object temp \ | |
| 1081 = Fassq (make_number (charset), Vcharset_revision_alist); \ | |
| 1082 if (! NILP (temp)) \ | |
| 1083 { \ | |
| 1084 *dst++ = ISO_CODE_ESC; \ | |
| 1085 *dst++ = '&'; \ | |
| 1086 *dst++ = XINT (XCONS (temp)->cdr) + '@'; \ | |
| 1087 } \ | |
| 1088 *dst++ = ISO_CODE_ESC; \ | |
| 1089 if (CHARSET_DIMENSION (charset) == 1) \ | |
| 1090 { \ | |
| 1091 if (CHARSET_CHARS (charset) == 94) \ | |
| 1092 *dst++ = (unsigned char) (intermediate_char_94[reg]); \ | |
| 1093 else \ | |
| 1094 *dst++ = (unsigned char) (intermediate_char_96[reg]); \ | |
| 1095 } \ | |
| 1096 else \ | |
| 1097 { \ | |
| 1098 *dst++ = '$'; \ | |
| 1099 if (CHARSET_CHARS (charset) == 94) \ | |
| 1100 { \ | |
| 1101 if (! (coding->flags & CODING_FLAG_ISO_SHORT_FORM) \ | |
| 1102 || reg != 0 \ | |
| 1103 || final_char < '@' || final_char > 'B') \ | |
| 1104 *dst++ = (unsigned char) (intermediate_char_94[reg]); \ | |
| 1105 } \ | |
| 1106 else \ | |
| 1107 *dst++ = (unsigned char) (intermediate_char_96[reg]); \ | |
| 1108 } \ | |
| 1109 *dst++ = final_char; \ | |
| 1110 CODING_SPEC_ISO_DESIGNATION (coding, reg) = charset; \ | |
| 1111 } while (0) | |
| 1112 | |
| 1113 /* The following two macros produce codes (control character or escape | |
| 1114 sequence) for ISO2022 single-shift functions (single-shift-2 and | |
| 1115 single-shift-3). */ | |
| 1116 | |
| 1117 #define ENCODE_SINGLE_SHIFT_2 \ | |
| 1118 do { \ | |
| 1119 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ | |
| 1120 *dst++ = ISO_CODE_ESC, *dst++ = 'N'; \ | |
| 1121 else \ | |
| 1122 *dst++ = ISO_CODE_SS2; \ | |
| 1123 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
| 1124 } while (0) | |
| 1125 | |
| 1126 #define ENCODE_SINGLE_SHIFT_3 \ | |
| 1127 do { \ | |
| 1128 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ | |
| 1129 *dst++ = ISO_CODE_ESC, *dst++ = 'O'; \ | |
| 1130 else \ | |
| 1131 *dst++ = ISO_CODE_SS3; \ | |
| 1132 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 1; \ | |
| 1133 } while (0) | |
| 1134 | |
| 1135 /* The following four macros produce codes (control character or | |
| 1136 escape sequence) for ISO2022 locking-shift functions (shift-in, | |
| 1137 shift-out, locking-shift-2, and locking-shift-3). */ | |
| 1138 | |
| 1139 #define ENCODE_SHIFT_IN \ | |
| 1140 do { \ | |
| 1141 *dst++ = ISO_CODE_SI; \ | |
| 1142 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0; \ | |
| 1143 } while (0) | |
| 1144 | |
| 1145 #define ENCODE_SHIFT_OUT \ | |
| 1146 do { \ | |
| 1147 *dst++ = ISO_CODE_SO; \ | |
| 1148 CODING_SPEC_ISO_INVOCATION (coding, 0) = 1; \ | |
| 1149 } while (0) | |
| 1150 | |
| 1151 #define ENCODE_LOCKING_SHIFT_2 \ | |
| 1152 do { \ | |
| 1153 *dst++ = ISO_CODE_ESC, *dst++ = 'n'; \ | |
| 1154 CODING_SPEC_ISO_INVOCATION (coding, 0) = 2; \ | |
| 1155 } while (0) | |
| 1156 | |
| 1157 #define ENCODE_LOCKING_SHIFT_3 \ | |
| 1158 do { \ | |
| 1159 *dst++ = ISO_CODE_ESC, *dst++ = 'o'; \ | |
| 1160 CODING_SPEC_ISO_INVOCATION (coding, 0) = 3; \ | |
| 1161 } while (0) | |
| 1162 | |
| 18766 | 1163 /* Produce codes for a DIMENSION1 character whose character set is |
| 1164 CHARSET and whose position-code is C1. Designation and invocation | |
| 17052 | 1165 sequences are also produced in advance if necessary. */ |
| 1166 | |
| 1167 | |
| 1168 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ | |
| 1169 do { \ | |
| 1170 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \ | |
| 1171 { \ | |
| 1172 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ | |
| 1173 *dst++ = c1 & 0x7F; \ | |
| 1174 else \ | |
| 1175 *dst++ = c1 | 0x80; \ | |
| 1176 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
| 1177 break; \ | |
| 1178 } \ | |
| 1179 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \ | |
| 1180 { \ | |
| 1181 *dst++ = c1 & 0x7F; \ | |
| 1182 break; \ | |
| 1183 } \ | |
| 1184 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \ | |
| 1185 { \ | |
| 1186 *dst++ = c1 | 0x80; \ | |
| 1187 break; \ | |
| 1188 } \ | |
| 1189 else \ | |
| 1190 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
| 1191 must invoke it, or, at first, designate it to some graphic \ | |
| 1192 register. Then repeat the loop to actually produce the \ | |
| 1193 character. */ \ | |
| 1194 dst = encode_invocation_designation (charset, coding, dst); \ | |
| 1195 } while (1) | |
| 1196 | |
| 18766 | 1197 /* Produce codes for a DIMENSION2 character whose character set is |
| 1198 CHARSET and whose position-codes are C1 and C2. Designation and | |
| 17052 | 1199 invocation codes are also produced in advance if necessary. */ |
| 1200 | |
| 1201 #define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2) \ | |
| 1202 do { \ | |
| 1203 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \ | |
| 1204 { \ | |
| 1205 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ | |
| 1206 *dst++ = c1 & 0x7F, *dst++ = c2 & 0x7F; \ | |
| 1207 else \ | |
| 1208 *dst++ = c1 | 0x80, *dst++ = c2 | 0x80; \ | |
| 1209 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \ | |
| 1210 break; \ | |
| 1211 } \ | |
| 1212 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \ | |
| 1213 { \ | |
| 1214 *dst++ = c1 & 0x7F, *dst++= c2 & 0x7F; \ | |
| 1215 break; \ | |
| 1216 } \ | |
| 1217 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \ | |
| 1218 { \ | |
| 1219 *dst++ = c1 | 0x80, *dst++= c2 | 0x80; \ | |
| 1220 break; \ | |
| 1221 } \ | |
| 1222 else \ | |
| 1223 /* Since CHARSET is not yet invoked to any graphic planes, we \ | |
| 1224 must invoke it, or, at first, designate it to some graphic \ | |
| 1225 register. Then repeat the loop to actually produce the \ | |
| 1226 character. */ \ | |
| 1227 dst = encode_invocation_designation (charset, coding, dst); \ | |
| 1228 } while (1) | |
| 1229 | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1230 #define ENCODE_ISO_CHARACTER(charset, c1, c2) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1231 do { \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1232 int c_alt, charset_alt; \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1233 if (!NILP (unification_table) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1234 && ((c_alt = unify_char (unification_table, -1, charset, c1, c2)) \ |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1235 >= 0)) \ |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1236 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1237 else \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1238 charset_alt = charset; \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1239 if (CHARSET_DIMENSION (charset_alt) == 1) \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1240 ENCODE_ISO_CHARACTER_DIMENSION1 (charset_alt, c1); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1241 else \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1242 ENCODE_ISO_CHARACTER_DIMENSION2 (charset_alt, c1, c2); \ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1243 } while (0) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1244 |
| 17052 | 1245 /* Produce designation and invocation codes at a place pointed by DST |
| 1246 to use CHARSET. The element `spec.iso2022' of *CODING is updated. | |
| 1247 Return new DST. */ | |
| 1248 | |
| 1249 unsigned char * | |
| 1250 encode_invocation_designation (charset, coding, dst) | |
| 1251 int charset; | |
| 1252 struct coding_system *coding; | |
| 1253 unsigned char *dst; | |
| 1254 { | |
| 1255 int reg; /* graphic register number */ | |
| 1256 | |
| 1257 /* At first, check designations. */ | |
| 1258 for (reg = 0; reg < 4; reg++) | |
| 1259 if (charset == CODING_SPEC_ISO_DESIGNATION (coding, reg)) | |
| 1260 break; | |
| 1261 | |
| 1262 if (reg >= 4) | |
| 1263 { | |
| 1264 /* CHARSET is not yet designated to any graphic registers. */ | |
| 1265 /* At first check the requested designation. */ | |
| 1266 reg = CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset); | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
1267 if (reg == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION) |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
1268 /* Since CHARSET requests no special designation, designate it |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
1269 to graphic register 0. */ |
| 17052 | 1270 reg = 0; |
| 1271 | |
| 1272 ENCODE_DESIGNATION (charset, reg, coding); | |
| 1273 } | |
| 1274 | |
| 1275 if (CODING_SPEC_ISO_INVOCATION (coding, 0) != reg | |
| 1276 && CODING_SPEC_ISO_INVOCATION (coding, 1) != reg) | |
| 1277 { | |
| 1278 /* Since the graphic register REG is not invoked to any graphic | |
| 1279 planes, invoke it to graphic plane 0. */ | |
| 1280 switch (reg) | |
| 1281 { | |
| 1282 case 0: /* graphic register 0 */ | |
| 1283 ENCODE_SHIFT_IN; | |
| 1284 break; | |
| 1285 | |
| 1286 case 1: /* graphic register 1 */ | |
| 1287 ENCODE_SHIFT_OUT; | |
| 1288 break; | |
| 1289 | |
| 1290 case 2: /* graphic register 2 */ | |
| 1291 if (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT) | |
| 1292 ENCODE_SINGLE_SHIFT_2; | |
| 1293 else | |
| 1294 ENCODE_LOCKING_SHIFT_2; | |
| 1295 break; | |
| 1296 | |
| 1297 case 3: /* graphic register 3 */ | |
| 1298 if (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT) | |
| 1299 ENCODE_SINGLE_SHIFT_3; | |
| 1300 else | |
| 1301 ENCODE_LOCKING_SHIFT_3; | |
| 1302 break; | |
| 1303 } | |
| 1304 } | |
| 1305 return dst; | |
| 1306 } | |
| 1307 | |
| 1308 /* The following two macros produce codes for indicating composition. */ | |
| 1309 #define ENCODE_COMPOSITION_NO_RULE_START *dst++ = ISO_CODE_ESC, *dst++ = '0' | |
| 1310 #define ENCODE_COMPOSITION_WITH_RULE_START *dst++ = ISO_CODE_ESC, *dst++ = '2' | |
| 1311 #define ENCODE_COMPOSITION_END *dst++ = ISO_CODE_ESC, *dst++ = '1' | |
| 1312 | |
| 1313 /* The following three macros produce codes for indicating direction | |
| 1314 of text. */ | |
| 1315 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \ | |
| 1316 do { \ | |
| 1317 if (coding->flags == CODING_FLAG_ISO_SEVEN_BITS) \ | |
| 1318 *dst++ = ISO_CODE_ESC, *dst++ = '['; \ | |
| 1319 else \ | |
| 1320 *dst++ = ISO_CODE_CSI; \ | |
| 1321 } while (0) | |
| 1322 | |
| 1323 #define ENCODE_DIRECTION_R2L \ | |
| 1324 ENCODE_CONTROL_SEQUENCE_INTRODUCER, *dst++ = '2', *dst++ = ']' | |
| 1325 | |
| 1326 #define ENCODE_DIRECTION_L2R \ | |
| 1327 ENCODE_CONTROL_SEQUENCE_INTRODUCER, *dst++ = '0', *dst++ = ']' | |
| 1328 | |
| 1329 /* Produce codes for designation and invocation to reset the graphic | |
| 1330 planes and registers to initial state. */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1331 #define ENCODE_RESET_PLANE_AND_REGISTER \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1332 do { \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1333 int reg; \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1334 if (CODING_SPEC_ISO_INVOCATION (coding, 0) != 0) \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1335 ENCODE_SHIFT_IN; \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1336 for (reg = 0; reg < 4; reg++) \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1337 if (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, reg) >= 0 \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1338 && (CODING_SPEC_ISO_DESIGNATION (coding, reg) \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1339 != CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, reg))) \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1340 ENCODE_DESIGNATION \ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1341 (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, reg), reg, coding); \ |
| 17052 | 1342 } while (0) |
| 1343 | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1344 /* Produce designation sequences of charsets in the line started from |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1345 *SRC to a place pointed by DSTP. |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1346 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1347 If the current block ends before any end-of-line, we may fail to |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1348 find all the necessary *designations. */ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1349 encode_designation_at_bol (coding, table, src, src_end, dstp) |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1350 struct coding_system *coding; |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1351 Lisp_Object table; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1352 unsigned char *src, *src_end, **dstp; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1353 { |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1354 int charset, c, found = 0, reg; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1355 /* 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
|
1356 int r[4]; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1357 unsigned char *dst = *dstp; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1358 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1359 for (reg = 0; reg < 4; reg++) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1360 r[reg] = -1; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1361 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1362 while (src < src_end && *src != '\n' && found < 4) |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1363 { |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1364 int bytes = BYTES_BY_CHAR_HEAD (*src); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1365 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1366 if (NILP (table)) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1367 charset = CHARSET_AT (src); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1368 else |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1369 { |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1370 int c_alt, c1, c2; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1371 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1372 SPLIT_STRING(src, bytes, charset, c1, c2); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1373 if ((c_alt = unify_char (table, -1, charset, c1, c2)) >= 0) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1374 charset = CHAR_CHARSET (c_alt); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1375 } |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1376 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1377 reg = CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset); |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
1378 if (r[reg] == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION) |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1379 { |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1380 found++; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1381 r[reg] = charset; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1382 } |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1383 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1384 src += bytes; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1385 } |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1386 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1387 if (found) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1388 { |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1389 for (reg = 0; reg < 4; reg++) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1390 if (r[reg] >= 0 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1391 && CODING_SPEC_ISO_DESIGNATION (coding, reg) != r[reg]) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1392 ENCODE_DESIGNATION (r[reg], reg, coding); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1393 *dstp = dst; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1394 } |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1395 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1396 |
| 17052 | 1397 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ |
| 1398 | |
| 1399 int | |
| 1400 encode_coding_iso2022 (coding, source, destination, | |
| 1401 src_bytes, dst_bytes, consumed) | |
| 1402 struct coding_system *coding; | |
| 1403 unsigned char *source, *destination; | |
| 1404 int src_bytes, dst_bytes; | |
| 1405 int *consumed; | |
| 1406 { | |
| 1407 unsigned char *src = source; | |
| 1408 unsigned char *src_end = source + src_bytes; | |
| 1409 unsigned char *dst = destination; | |
| 1410 unsigned char *dst_end = destination + dst_bytes; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1411 /* Since the maximum bytes produced by each loop is 20, we subtract 19 |
| 17052 | 1412 from DST_END to assure overflow checking is necessary only at the |
| 1413 head of loop. */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1414 unsigned char *adjusted_dst_end = dst_end - 19; |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1415 Lisp_Object unification_table |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1416 = coding->character_unification_table_for_encode; |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1417 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1418 if (!NILP (Venable_character_unification) && NILP (unification_table)) |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1419 unification_table = Vstandard_character_unification_table_for_encode; |
| 17052 | 1420 |
| 1421 while (src < src_end && dst < adjusted_dst_end) | |
| 1422 { | |
| 1423 /* SRC_BASE remembers the start position in source in each loop. | |
| 1424 The loop will be exited when there's not enough source text | |
| 1425 to analyze multi-byte codes (within macros ONE_MORE_BYTE, | |
| 1426 TWO_MORE_BYTES, and THREE_MORE_BYTES). In that case, SRC is | |
| 1427 reset to SRC_BASE before exiting. */ | |
| 1428 unsigned char *src_base = src; | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1429 int charset, c1, c2, c3, c4; |
| 17052 | 1430 |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1431 if (coding->flags & CODING_FLAG_ISO_DESIGNATE_AT_BOL |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1432 && CODING_SPEC_ISO_BOL (coding)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1433 { |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1434 /* We have to produce designation sequences if any now. */ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1435 encode_designation_at_bol (coding, unification_table, |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1436 src, src_end, &dst); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1437 CODING_SPEC_ISO_BOL (coding) = 0; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1438 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1439 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1440 c1 = *src++; |
| 17052 | 1441 /* If we are seeing a component of a composite character, we are |
| 1442 seeing a leading-code specially encoded for composition, or a | |
| 1443 composition rule if composing with rule. We must set C1 | |
| 1444 to a normal leading-code or an ASCII code. If we are not at | |
| 1445 a composed character, we must reset the composition state. */ | |
| 1446 if (COMPOSING_P (coding->composing)) | |
| 1447 { | |
| 1448 if (c1 < 0xA0) | |
| 1449 { | |
| 1450 /* We are not in a composite character any longer. */ | |
| 1451 coding->composing = COMPOSING_NO; | |
| 1452 ENCODE_COMPOSITION_END; | |
| 1453 } | |
| 1454 else | |
| 1455 { | |
| 1456 if (coding->composing == COMPOSING_WITH_RULE_RULE) | |
| 1457 { | |
| 1458 *dst++ = c1 & 0x7F; | |
| 1459 coding->composing = COMPOSING_WITH_RULE_HEAD; | |
| 1460 continue; | |
| 1461 } | |
| 1462 else if (coding->composing == COMPOSING_WITH_RULE_HEAD) | |
| 1463 coding->composing = COMPOSING_WITH_RULE_RULE; | |
| 1464 if (c1 == 0xA0) | |
| 1465 { | |
| 1466 /* This is an ASCII component. */ | |
| 1467 ONE_MORE_BYTE (c1); | |
| 1468 c1 &= 0x7F; | |
| 1469 } | |
| 1470 else | |
| 1471 /* This is a leading-code of non ASCII component. */ | |
| 1472 c1 -= 0x20; | |
| 1473 } | |
| 1474 } | |
| 1475 | |
| 1476 /* Now encode one character. C1 is a control character, an | |
| 1477 ASCII character, or a leading-code of multi-byte character. */ | |
| 1478 switch (emacs_code_class[c1]) | |
| 1479 { | |
| 1480 case EMACS_ascii_code: | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1481 ENCODE_ISO_CHARACTER (CHARSET_ASCII, c1, /* dummy */ c2); |
| 17052 | 1482 break; |
| 1483 | |
| 1484 case EMACS_control_code: | |
| 1485 if (coding->flags & CODING_FLAG_ISO_RESET_AT_CNTL) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1486 ENCODE_RESET_PLANE_AND_REGISTER; |
| 17052 | 1487 *dst++ = c1; |
| 1488 break; | |
| 1489 | |
| 1490 case EMACS_carriage_return_code: | |
| 1491 if (!coding->selective) | |
| 1492 { | |
| 1493 if (coding->flags & CODING_FLAG_ISO_RESET_AT_CNTL) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1494 ENCODE_RESET_PLANE_AND_REGISTER; |
| 17052 | 1495 *dst++ = c1; |
| 1496 break; | |
| 1497 } | |
| 1498 /* fall down to treat '\r' as '\n' ... */ | |
| 1499 | |
| 1500 case EMACS_linefeed_code: | |
| 1501 if (coding->flags & CODING_FLAG_ISO_RESET_AT_EOL) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1502 ENCODE_RESET_PLANE_AND_REGISTER; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1503 if (coding->flags & CODING_FLAG_ISO_INIT_AT_BOL) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1504 bcopy (coding->spec.iso2022.initial_designation, |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1505 coding->spec.iso2022.current_designation, |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1506 sizeof coding->spec.iso2022.initial_designation); |
| 17052 | 1507 if (coding->eol_type == CODING_EOL_LF |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
1508 || coding->eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 1509 *dst++ = ISO_CODE_LF; |
| 1510 else if (coding->eol_type == CODING_EOL_CRLF) | |
| 1511 *dst++ = ISO_CODE_CR, *dst++ = ISO_CODE_LF; | |
| 1512 else | |
| 1513 *dst++ = ISO_CODE_CR; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1514 CODING_SPEC_ISO_BOL (coding) = 1; |
| 17052 | 1515 break; |
| 1516 | |
| 1517 case EMACS_leading_code_2: | |
| 1518 ONE_MORE_BYTE (c2); | |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1519 if (c2 < 0xA0) |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1520 { |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1521 /* invalid sequence */ |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1522 *dst++ = c1; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1523 *dst++ = c2; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1524 } |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1525 else |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1526 ENCODE_ISO_CHARACTER (c1, c2, /* dummy */ c3); |
| 17052 | 1527 break; |
| 1528 | |
| 1529 case EMACS_leading_code_3: | |
| 1530 TWO_MORE_BYTES (c2, c3); | |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1531 if (c2 < 0xA0 || c3 < 0xA0) |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1532 { |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1533 /* invalid sequence */ |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1534 *dst++ = c1; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1535 *dst++ = c2; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1536 *dst++ = c3; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1537 } |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1538 else if (c1 < LEADING_CODE_PRIVATE_11) |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1539 ENCODE_ISO_CHARACTER (c1, c2, c3); |
| 17052 | 1540 else |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1541 ENCODE_ISO_CHARACTER (c2, c3, /* dummy */ c4); |
| 17052 | 1542 break; |
| 1543 | |
| 1544 case EMACS_leading_code_4: | |
| 1545 THREE_MORE_BYTES (c2, c3, c4); | |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1546 if (c2 < 0xA0 || c3 < 0xA0 || c4 < 0xA0) |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1547 { |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1548 /* invalid sequence */ |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1549 *dst++ = c1; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1550 *dst++ = c2; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1551 *dst++ = c3; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1552 *dst++ = c4; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1553 } |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1554 else |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1555 ENCODE_ISO_CHARACTER (c2, c3, c4); |
| 17052 | 1556 break; |
| 1557 | |
| 1558 case EMACS_leading_code_composition: | |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1559 ONE_MORE_BYTE (c2); |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1560 if (c2 < 0xA0) |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1561 { |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1562 /* invalid sequence */ |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1563 *dst++ = c1; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1564 *dst++ = c2; |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1565 } |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
1566 else if (c2 == 0xFF) |
| 17052 | 1567 { |
| 1568 coding->composing = COMPOSING_WITH_RULE_HEAD; | |
| 1569 ENCODE_COMPOSITION_WITH_RULE_START; | |
| 1570 } | |
| 1571 else | |
| 1572 { | |
| 1573 /* Rewind one byte because it is a character code of | |
| 1574 composition elements. */ | |
| 1575 src--; | |
| 1576 coding->composing = COMPOSING_NO_RULE_HEAD; | |
| 1577 ENCODE_COMPOSITION_NO_RULE_START; | |
| 1578 } | |
| 1579 break; | |
| 1580 | |
| 1581 case EMACS_invalid_code: | |
| 1582 *dst++ = c1; | |
| 1583 break; | |
| 1584 } | |
| 1585 continue; | |
| 1586 label_end_of_loop: | |
|
19068
36b06087dc31
(encode_coding_iso2022): When source data ends not at
Kenichi Handa <handa@m17n.org>
parents:
19052
diff
changeset
|
1587 /* We reach here because the source date ends not at character |
|
36b06087dc31
(encode_coding_iso2022): When source data ends not at
Kenichi Handa <handa@m17n.org>
parents:
19052
diff
changeset
|
1588 boundary. */ |
|
36b06087dc31
(encode_coding_iso2022): When source data ends not at
Kenichi Handa <handa@m17n.org>
parents:
19052
diff
changeset
|
1589 coding->carryover_size = src_end - src_base; |
| 17052 | 1590 bcopy (src_base, coding->carryover, coding->carryover_size); |
|
19068
36b06087dc31
(encode_coding_iso2022): When source data ends not at
Kenichi Handa <handa@m17n.org>
parents:
19052
diff
changeset
|
1591 src = src_end; |
| 17052 | 1592 break; |
| 1593 } | |
| 1594 | |
| 1595 /* If this is the last block of the text to be encoded, we must | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1596 reset graphic planes and registers to the initial state. */ |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1597 if (src >= src_end && coding->last_block) |
| 17052 | 1598 { |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1599 ENCODE_RESET_PLANE_AND_REGISTER; |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1600 if (coding->carryover_size > 0 |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1601 && coding->carryover_size < (dst_end - dst)) |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1602 { |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1603 bcopy (coding->carryover, dst, coding->carryover_size); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1604 dst += coding->carryover_size; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1605 coding->carryover_size = 0; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
1606 } |
| 17052 | 1607 } |
| 1608 *consumed = src - source; | |
| 1609 return dst - destination; | |
| 1610 } | |
| 1611 | |
| 1612 | |
| 1613 /*** 4. SJIS and BIG5 handlers ***/ | |
| 1614 | |
| 18766 | 1615 /* Although SJIS and BIG5 are not ISO's coding system, they are used |
| 17052 | 1616 quite widely. So, for the moment, Emacs supports them in the bare |
| 1617 C code. But, in the future, they may be supported only by CCL. */ | |
| 1618 | |
| 1619 /* SJIS is a coding system encoding three character sets: ASCII, right | |
| 1620 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded | |
| 1621 as is. A character of charset katakana-jisx0201 is encoded by | |
| 1622 "position-code + 0x80". A character of charset japanese-jisx0208 | |
| 1623 is encoded in 2-byte but two position-codes are divided and shifted | |
| 1624 so that it fit in the range below. | |
| 1625 | |
| 1626 --- CODE RANGE of SJIS --- | |
| 1627 (character set) (range) | |
| 1628 ASCII 0x00 .. 0x7F | |
| 1629 KATAKANA-JISX0201 0xA0 .. 0xDF | |
| 1630 JISX0208 (1st byte) 0x80 .. 0x9F and 0xE0 .. 0xFF | |
| 1631 (2nd byte) 0x40 .. 0xFF | |
| 1632 ------------------------------- | |
| 1633 | |
| 1634 */ | |
| 1635 | |
| 1636 /* BIG5 is a coding system encoding two character sets: ASCII and | |
| 1637 Big5. An ASCII character is encoded as is. Big5 is a two-byte | |
| 1638 character set and is encoded in two-byte. | |
| 1639 | |
| 1640 --- CODE RANGE of BIG5 --- | |
| 1641 (character set) (range) | |
| 1642 ASCII 0x00 .. 0x7F | |
| 1643 Big5 (1st byte) 0xA1 .. 0xFE | |
| 1644 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | |
| 1645 -------------------------- | |
| 1646 | |
| 1647 Since the number of characters in Big5 is larger than maximum | |
| 1648 characters in Emacs' charset (96x96), it can't be handled as one | |
| 1649 charset. So, in Emacs, Big5 is divided into two: `charset-big5-1' | |
| 1650 and `charset-big5-2'. Both are DIMENSION2 and CHARS94. The former | |
| 1651 contains frequently used characters and the latter contains less | |
| 1652 frequently used characters. */ | |
| 1653 | |
| 1654 /* Macros to decode or encode a character of Big5 in BIG5. B1 and B2 | |
| 1655 are the 1st and 2nd position-codes of Big5 in BIG5 coding system. | |
| 1656 C1 and C2 are the 1st and 2nd position-codes of of Emacs' internal | |
| 1657 format. CHARSET is `charset_big5_1' or `charset_big5_2'. */ | |
| 1658 | |
| 1659 /* Number of Big5 characters which have the same code in 1st byte. */ | |
| 1660 #define BIG5_SAME_ROW (0xFF - 0xA1 + 0x7F - 0x40) | |
| 1661 | |
| 1662 #define DECODE_BIG5(b1, b2, charset, c1, c2) \ | |
| 1663 do { \ | |
| 1664 unsigned int temp \ | |
| 1665 = (b1 - 0xA1) * BIG5_SAME_ROW + b2 - (b2 < 0x7F ? 0x40 : 0x62); \ | |
| 1666 if (b1 < 0xC9) \ | |
| 1667 charset = charset_big5_1; \ | |
| 1668 else \ | |
| 1669 { \ | |
| 1670 charset = charset_big5_2; \ | |
| 1671 temp -= (0xC9 - 0xA1) * BIG5_SAME_ROW; \ | |
| 1672 } \ | |
| 1673 c1 = temp / (0xFF - 0xA1) + 0x21; \ | |
| 1674 c2 = temp % (0xFF - 0xA1) + 0x21; \ | |
| 1675 } while (0) | |
| 1676 | |
| 1677 #define ENCODE_BIG5(charset, c1, c2, b1, b2) \ | |
| 1678 do { \ | |
| 1679 unsigned int temp = (c1 - 0x21) * (0xFF - 0xA1) + (c2 - 0x21); \ | |
| 1680 if (charset == charset_big5_2) \ | |
| 1681 temp += BIG5_SAME_ROW * (0xC9 - 0xA1); \ | |
| 1682 b1 = temp / BIG5_SAME_ROW + 0xA1; \ | |
| 1683 b2 = temp % BIG5_SAME_ROW; \ | |
| 1684 b2 += b2 < 0x3F ? 0x40 : 0x62; \ | |
| 1685 } while (0) | |
| 1686 | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1687 #define DECODE_SJIS_BIG5_CHARACTER(charset, c1, c2) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1688 do { \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1689 int c_alt, charset_alt = (charset); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1690 if (!NILP (unification_table) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1691 && ((c_alt = unify_char (unification_table, \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1692 -1, (charset), c1, c2)) >= 0)) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1693 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1694 if (charset_alt == CHARSET_ASCII || charset_alt < 0) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1695 DECODE_CHARACTER_ASCII (c1); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1696 else if (CHARSET_DIMENSION (charset_alt) == 1) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1697 DECODE_CHARACTER_DIMENSION1 (charset_alt, c1); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1698 else \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1699 DECODE_CHARACTER_DIMENSION2 (charset_alt, c1, c2); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1700 } while (0) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1701 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1702 #define ENCODE_SJIS_BIG5_CHARACTER(charset, c1, c2) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1703 do { \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1704 int c_alt, charset_alt; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1705 if (!NILP (unification_table) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1706 && ((c_alt = unify_char (unification_table, -1, charset, c1, c2)) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1707 >= 0)) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1708 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1709 else \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1710 charset_alt = charset; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1711 if (charset_alt == charset_ascii) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1712 *dst++ = c1; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1713 else if (CHARSET_DIMENSION (charset_alt) == 1) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1714 { \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1715 if (sjis_p && charset_alt == charset_katakana_jisx0201) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1716 *dst++ = c1; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1717 else \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1718 *dst++ = charset_alt, *dst++ = c1; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1719 } \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1720 else \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1721 { \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1722 c1 &= 0x7F, c2 &= 0x7F; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1723 if (sjis_p && charset_alt == charset_jisx0208) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1724 { \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1725 unsigned char s1, s2; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1726 \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1727 ENCODE_SJIS (c1, c2, s1, s2); \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1728 *dst++ = s1, *dst++ = s2; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1729 } \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1730 else if (!sjis_p \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1731 && (charset_alt == charset_big5_1 \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1732 || charset_alt == charset_big5_2)) \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1733 { \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1734 unsigned char b1, b2; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1735 \ |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
1736 ENCODE_BIG5 (charset_alt, c1, c2, b1, b2); \ |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1737 *dst++ = b1, *dst++ = b2; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1738 } \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1739 else \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1740 *dst++ = charset_alt, *dst++ = c1, *dst++ = c2; \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1741 } \ |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1742 } while (0); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1743 |
| 17052 | 1744 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". |
| 1745 Check if a text is encoded in SJIS. If it is, return | |
| 1746 CODING_CATEGORY_MASK_SJIS, else return 0. */ | |
| 1747 | |
| 1748 int | |
| 1749 detect_coding_sjis (src, src_end) | |
| 1750 unsigned char *src, *src_end; | |
| 1751 { | |
| 1752 unsigned char c; | |
| 1753 | |
| 1754 while (src < src_end) | |
| 1755 { | |
| 1756 c = *src++; | |
| 1757 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) | |
| 1758 return 0; | |
| 1759 if ((c >= 0x80 && c < 0xA0) || c >= 0xE0) | |
| 1760 { | |
| 1761 if (src < src_end && *src++ < 0x40) | |
| 1762 return 0; | |
| 1763 } | |
| 1764 } | |
| 1765 return CODING_CATEGORY_MASK_SJIS; | |
| 1766 } | |
| 1767 | |
| 1768 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". | |
| 1769 Check if a text is encoded in BIG5. If it is, return | |
| 1770 CODING_CATEGORY_MASK_BIG5, else return 0. */ | |
| 1771 | |
| 1772 int | |
| 1773 detect_coding_big5 (src, src_end) | |
| 1774 unsigned char *src, *src_end; | |
| 1775 { | |
| 1776 unsigned char c; | |
| 1777 | |
| 1778 while (src < src_end) | |
| 1779 { | |
| 1780 c = *src++; | |
| 1781 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) | |
| 1782 return 0; | |
| 1783 if (c >= 0xA1) | |
| 1784 { | |
| 1785 if (src >= src_end) | |
| 1786 break; | |
| 1787 c = *src++; | |
| 1788 if (c < 0x40 || (c >= 0x7F && c <= 0xA0)) | |
| 1789 return 0; | |
| 1790 } | |
| 1791 } | |
| 1792 return CODING_CATEGORY_MASK_BIG5; | |
| 1793 } | |
| 1794 | |
| 1795 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". | |
| 1796 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ | |
| 1797 | |
| 1798 int | |
| 1799 decode_coding_sjis_big5 (coding, source, destination, | |
| 1800 src_bytes, dst_bytes, consumed, sjis_p) | |
| 1801 struct coding_system *coding; | |
| 1802 unsigned char *source, *destination; | |
| 1803 int src_bytes, dst_bytes; | |
| 1804 int *consumed; | |
| 1805 int sjis_p; | |
| 1806 { | |
| 1807 unsigned char *src = source; | |
| 1808 unsigned char *src_end = source + src_bytes; | |
| 1809 unsigned char *dst = destination; | |
| 1810 unsigned char *dst_end = destination + dst_bytes; | |
| 1811 /* Since the maximum bytes produced by each loop is 4, we subtract 3 | |
| 1812 from DST_END to assure overflow checking is necessary only at the | |
| 1813 head of loop. */ | |
| 1814 unsigned char *adjusted_dst_end = dst_end - 3; | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1815 Lisp_Object unification_table |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1816 = coding->character_unification_table_for_decode; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1817 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1818 if (!NILP (Venable_character_unification) && NILP (unification_table)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1819 unification_table = Vstandard_character_unification_table_for_decode; |
| 17052 | 1820 |
| 1821 while (src < src_end && dst < adjusted_dst_end) | |
| 1822 { | |
| 1823 /* SRC_BASE remembers the start position in source in each loop. | |
| 1824 The loop will be exited when there's not enough source text | |
| 1825 to analyze two-byte character (within macro ONE_MORE_BYTE). | |
| 1826 In that case, SRC is reset to SRC_BASE before exiting. */ | |
| 1827 unsigned char *src_base = src; | |
| 1828 unsigned char c1 = *src++, c2, c3, c4; | |
| 1829 | |
| 1830 if (c1 == '\r') | |
| 1831 { | |
| 1832 if (coding->eol_type == CODING_EOL_CRLF) | |
| 1833 { | |
| 1834 ONE_MORE_BYTE (c2); | |
| 1835 if (c2 == '\n') | |
| 1836 *dst++ = c2; | |
| 1837 else | |
| 1838 /* To process C2 again, SRC is subtracted by 1. */ | |
| 1839 *dst++ = c1, src--; | |
| 1840 } | |
| 1841 else | |
| 1842 *dst++ = c1; | |
| 1843 } | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1844 else if (c1 < 0x20) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1845 *dst++ = c1; |
| 17052 | 1846 else if (c1 < 0x80) |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1847 DECODE_SJIS_BIG5_CHARACTER (charset_ascii, c1, /* dummy */ c2); |
| 17052 | 1848 else if (c1 < 0xA0 || c1 >= 0xE0) |
| 1849 { | |
| 1850 /* SJIS -> JISX0208, BIG5 -> Big5 (only if 0xE0 <= c1 < 0xFF) */ | |
| 1851 if (sjis_p) | |
| 1852 { | |
| 1853 ONE_MORE_BYTE (c2); | |
| 1854 DECODE_SJIS (c1, c2, c3, c4); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1855 DECODE_SJIS_BIG5_CHARACTER (charset_jisx0208, c3, c4); |
| 17052 | 1856 } |
| 1857 else if (c1 >= 0xE0 && c1 < 0xFF) | |
| 1858 { | |
| 1859 int charset; | |
| 1860 | |
| 1861 ONE_MORE_BYTE (c2); | |
| 1862 DECODE_BIG5 (c1, c2, charset, c3, c4); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1863 DECODE_SJIS_BIG5_CHARACTER (charset, c3, c4); |
| 17052 | 1864 } |
| 1865 else /* Invalid code */ | |
| 1866 *dst++ = c1; | |
| 1867 } | |
| 1868 else | |
| 1869 { | |
| 1870 /* SJIS -> JISX0201-Kana, BIG5 -> Big5 */ | |
| 1871 if (sjis_p) | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1872 DECODE_SJIS_BIG5_CHARACTER (charset_katakana_jisx0201, c1, /* dummy */ c2); |
| 17052 | 1873 else |
| 1874 { | |
| 1875 int charset; | |
| 1876 | |
| 1877 ONE_MORE_BYTE (c2); | |
| 1878 DECODE_BIG5 (c1, c2, charset, c3, c4); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1879 DECODE_SJIS_BIG5_CHARACTER (charset, c3, c4); |
| 17052 | 1880 } |
| 1881 } | |
| 1882 continue; | |
| 1883 | |
| 1884 label_end_of_loop: | |
| 1885 coding->carryover_size = src - src_base; | |
| 1886 bcopy (src_base, coding->carryover, coding->carryover_size); | |
| 1887 src = src_base; | |
| 1888 break; | |
| 1889 } | |
| 1890 | |
| 1891 *consumed = src - source; | |
| 1892 return dst - destination; | |
| 1893 } | |
| 1894 | |
| 1895 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". | |
| 1896 This function can encode `charset_ascii', `charset_katakana_jisx0201', | |
| 1897 `charset_jisx0208', `charset_big5_1', and `charset_big5-2'. We are | |
| 1898 sure that all these charsets are registered as official charset | |
| 1899 (i.e. do not have extended leading-codes). Characters of other | |
| 1900 charsets are produced without any encoding. If SJIS_P is 1, encode | |
| 1901 SJIS text, else encode BIG5 text. */ | |
| 1902 | |
| 1903 int | |
| 1904 encode_coding_sjis_big5 (coding, source, destination, | |
| 1905 src_bytes, dst_bytes, consumed, sjis_p) | |
| 1906 struct coding_system *coding; | |
| 1907 unsigned char *source, *destination; | |
| 1908 int src_bytes, dst_bytes; | |
| 1909 int *consumed; | |
| 1910 int sjis_p; | |
| 1911 { | |
| 1912 unsigned char *src = source; | |
| 1913 unsigned char *src_end = source + src_bytes; | |
| 1914 unsigned char *dst = destination; | |
| 1915 unsigned char *dst_end = destination + dst_bytes; | |
| 1916 /* Since the maximum bytes produced by each loop is 2, we subtract 1 | |
| 1917 from DST_END to assure overflow checking is necessary only at the | |
| 1918 head of loop. */ | |
| 1919 unsigned char *adjusted_dst_end = dst_end - 1; | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1920 Lisp_Object unification_table |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1921 = coding->character_unification_table_for_encode; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1922 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1923 if (!NILP (Venable_character_unification) && NILP (unification_table)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1924 unification_table = Vstandard_character_unification_table_for_encode; |
| 17052 | 1925 |
| 1926 while (src < src_end && dst < adjusted_dst_end) | |
| 1927 { | |
| 1928 /* SRC_BASE remembers the start position in source in each loop. | |
| 1929 The loop will be exited when there's not enough source text | |
| 1930 to analyze multi-byte codes (within macros ONE_MORE_BYTE and | |
| 1931 TWO_MORE_BYTES). In that case, SRC is reset to SRC_BASE | |
| 1932 before exiting. */ | |
| 1933 unsigned char *src_base = src; | |
| 1934 unsigned char c1 = *src++, c2, c3, c4; | |
| 1935 | |
| 1936 if (coding->composing) | |
| 1937 { | |
| 1938 if (c1 == 0xA0) | |
| 1939 { | |
| 1940 ONE_MORE_BYTE (c1); | |
| 1941 c1 &= 0x7F; | |
| 1942 } | |
| 1943 else if (c1 >= 0xA0) | |
| 1944 c1 -= 0x20; | |
| 1945 else | |
| 1946 coding->composing = 0; | |
| 1947 } | |
| 1948 | |
| 1949 switch (emacs_code_class[c1]) | |
| 1950 { | |
| 1951 case EMACS_ascii_code: | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1952 ENCODE_SJIS_BIG5_CHARACTER (charset_ascii, c1, /* dummy */ c2); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1953 break; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1954 |
| 17052 | 1955 case EMACS_control_code: |
| 1956 *dst++ = c1; | |
| 1957 break; | |
| 1958 | |
| 1959 case EMACS_carriage_return_code: | |
| 1960 if (!coding->selective) | |
| 1961 { | |
| 1962 *dst++ = c1; | |
| 1963 break; | |
| 1964 } | |
| 1965 /* fall down to treat '\r' as '\n' ... */ | |
| 1966 | |
| 1967 case EMACS_linefeed_code: | |
| 1968 if (coding->eol_type == CODING_EOL_LF | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
1969 || coding->eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 1970 *dst++ = '\n'; |
| 1971 else if (coding->eol_type == CODING_EOL_CRLF) | |
| 1972 *dst++ = '\r', *dst++ = '\n'; | |
| 1973 else | |
| 1974 *dst++ = '\r'; | |
| 1975 break; | |
| 1976 | |
| 1977 case EMACS_leading_code_2: | |
| 1978 ONE_MORE_BYTE (c2); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1979 ENCODE_SJIS_BIG5_CHARACTER (c1, c2, /* dummy */ c3); |
| 17052 | 1980 break; |
| 1981 | |
| 1982 case EMACS_leading_code_3: | |
| 1983 TWO_MORE_BYTES (c2, c3); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1984 ENCODE_SJIS_BIG5_CHARACTER (c1, c2, c3); |
| 17052 | 1985 break; |
| 1986 | |
| 1987 case EMACS_leading_code_4: | |
| 1988 THREE_MORE_BYTES (c2, c3, c4); | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
1989 ENCODE_SJIS_BIG5_CHARACTER (c2, c3, c4); |
| 17052 | 1990 break; |
| 1991 | |
| 1992 case EMACS_leading_code_composition: | |
| 1993 coding->composing = 1; | |
| 1994 break; | |
| 1995 | |
| 1996 default: /* i.e. case EMACS_invalid_code: */ | |
| 1997 *dst++ = c1; | |
| 1998 } | |
| 1999 continue; | |
| 2000 | |
| 2001 label_end_of_loop: | |
|
19068
36b06087dc31
(encode_coding_iso2022): When source data ends not at
Kenichi Handa <handa@m17n.org>
parents:
19052
diff
changeset
|
2002 coding->carryover_size = src_end - src_base; |
| 17052 | 2003 bcopy (src_base, coding->carryover, coding->carryover_size); |
|
19068
36b06087dc31
(encode_coding_iso2022): When source data ends not at
Kenichi Handa <handa@m17n.org>
parents:
19052
diff
changeset
|
2004 src = src_end; |
| 17052 | 2005 break; |
| 2006 } | |
| 2007 | |
| 2008 *consumed = src - source; | |
| 2009 return dst - destination; | |
| 2010 } | |
| 2011 | |
| 2012 | |
| 2013 /*** 5. End-of-line handlers ***/ | |
| 2014 | |
| 2015 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". | |
| 2016 This function is called only when `coding->eol_type' is | |
| 2017 CODING_EOL_CRLF or CODING_EOL_CR. */ | |
| 2018 | |
| 2019 decode_eol (coding, source, destination, src_bytes, dst_bytes, consumed) | |
| 2020 struct coding_system *coding; | |
| 2021 unsigned char *source, *destination; | |
| 2022 int src_bytes, dst_bytes; | |
| 2023 int *consumed; | |
| 2024 { | |
| 2025 unsigned char *src = source; | |
| 2026 unsigned char *src_end = source + src_bytes; | |
| 2027 unsigned char *dst = destination; | |
| 2028 unsigned char *dst_end = destination + dst_bytes; | |
| 2029 int produced; | |
| 2030 | |
| 2031 switch (coding->eol_type) | |
| 2032 { | |
| 2033 case CODING_EOL_CRLF: | |
| 2034 { | |
| 2035 /* Since the maximum bytes produced by each loop is 2, we | |
| 2036 subtract 1 from DST_END to assure overflow checking is | |
| 2037 necessary only at the head of loop. */ | |
| 2038 unsigned char *adjusted_dst_end = dst_end - 1; | |
| 2039 | |
| 2040 while (src < src_end && dst < adjusted_dst_end) | |
| 2041 { | |
| 2042 unsigned char *src_base = src; | |
| 2043 unsigned char c = *src++; | |
| 2044 if (c == '\r') | |
| 2045 { | |
| 2046 ONE_MORE_BYTE (c); | |
| 2047 if (c != '\n') | |
| 2048 *dst++ = '\r'; | |
|
17137
bd8d38879c97
(decode_eol): Fix bug of converting CRLF to LF.
Kenichi Handa <handa@m17n.org>
parents:
17119
diff
changeset
|
2049 *dst++ = c; |
| 17052 | 2050 } |
| 2051 else | |
| 2052 *dst++ = c; | |
| 2053 continue; | |
| 2054 | |
| 2055 label_end_of_loop: | |
| 2056 coding->carryover_size = src - src_base; | |
| 2057 bcopy (src_base, coding->carryover, coding->carryover_size); | |
| 2058 src = src_base; | |
| 2059 break; | |
| 2060 } | |
| 2061 *consumed = src - source; | |
| 2062 produced = dst - destination; | |
| 2063 break; | |
| 2064 } | |
| 2065 | |
| 2066 case CODING_EOL_CR: | |
| 2067 produced = (src_bytes > dst_bytes) ? dst_bytes : src_bytes; | |
| 2068 bcopy (source, destination, produced); | |
| 2069 dst_end = destination + produced; | |
| 2070 while (dst < dst_end) | |
| 2071 if (*dst++ == '\r') dst[-1] = '\n'; | |
| 2072 *consumed = produced; | |
| 2073 break; | |
| 2074 | |
| 2075 default: /* i.e. case: CODING_EOL_LF */ | |
| 2076 produced = (src_bytes > dst_bytes) ? dst_bytes : src_bytes; | |
| 2077 bcopy (source, destination, produced); | |
| 2078 *consumed = produced; | |
| 2079 break; | |
| 2080 } | |
| 2081 | |
| 2082 return produced; | |
| 2083 } | |
| 2084 | |
| 2085 /* See "GENERAL NOTES about `encode_coding_XXX ()' functions". Encode | |
| 2086 format of end-of-line according to `coding->eol_type'. If | |
| 2087 `coding->selective' is 1, code '\r' in source text also means | |
| 2088 end-of-line. */ | |
| 2089 | |
| 2090 encode_eol (coding, source, destination, src_bytes, dst_bytes, consumed) | |
| 2091 struct coding_system *coding; | |
| 2092 unsigned char *source, *destination; | |
| 2093 int src_bytes, dst_bytes; | |
| 2094 int *consumed; | |
| 2095 { | |
| 2096 unsigned char *src = source; | |
| 2097 unsigned char *dst = destination; | |
| 2098 int produced; | |
| 2099 | |
| 2100 if (src_bytes <= 0) | |
| 2101 return 0; | |
| 2102 | |
| 2103 switch (coding->eol_type) | |
| 2104 { | |
| 2105 case CODING_EOL_LF: | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2106 case CODING_EOL_UNDECIDED: |
| 17052 | 2107 produced = (src_bytes > dst_bytes) ? dst_bytes : src_bytes; |
| 2108 bcopy (source, destination, produced); | |
| 2109 if (coding->selective) | |
| 2110 { | |
| 2111 int i = produced; | |
| 2112 while (i--) | |
| 2113 if (*dst++ == '\r') dst[-1] = '\n'; | |
| 2114 } | |
| 2115 *consumed = produced; | |
| 2116 | |
| 2117 case CODING_EOL_CRLF: | |
| 2118 { | |
| 2119 unsigned char c; | |
| 2120 unsigned char *src_end = source + src_bytes; | |
| 2121 unsigned char *dst_end = destination + dst_bytes; | |
| 2122 /* Since the maximum bytes produced by each loop is 2, we | |
| 2123 subtract 1 from DST_END to assure overflow checking is | |
| 2124 necessary only at the head of loop. */ | |
| 2125 unsigned char *adjusted_dst_end = dst_end - 1; | |
| 2126 | |
| 2127 while (src < src_end && dst < adjusted_dst_end) | |
| 2128 { | |
| 2129 c = *src++; | |
| 2130 if (c == '\n' || (c == '\r' && coding->selective)) | |
| 2131 *dst++ = '\r', *dst++ = '\n'; | |
| 2132 else | |
| 2133 *dst++ = c; | |
| 2134 } | |
| 2135 produced = dst - destination; | |
| 2136 *consumed = src - source; | |
| 2137 break; | |
| 2138 } | |
| 2139 | |
| 2140 default: /* i.e. case CODING_EOL_CR: */ | |
| 2141 produced = (src_bytes > dst_bytes) ? dst_bytes : src_bytes; | |
| 2142 bcopy (source, destination, produced); | |
| 2143 { | |
| 2144 int i = produced; | |
| 2145 while (i--) | |
| 2146 if (*dst++ == '\n') dst[-1] = '\r'; | |
| 2147 } | |
| 2148 *consumed = produced; | |
| 2149 } | |
| 2150 | |
| 2151 return produced; | |
| 2152 } | |
| 2153 | |
| 2154 | |
| 2155 /*** 6. C library functions ***/ | |
| 2156 | |
| 2157 /* In Emacs Lisp, coding system is represented by a Lisp symbol which | |
| 2158 has a property `coding-system'. The value of this property is a | |
| 2159 vector of length 5 (called as coding-vector). Among elements of | |
| 2160 this vector, the first (element[0]) and the fifth (element[4]) | |
| 2161 carry important information for decoding/encoding. Before | |
| 2162 decoding/encoding, this information should be set in fields of a | |
| 2163 structure of type `coding_system'. | |
| 2164 | |
| 2165 A value of property `coding-system' can be a symbol of another | |
| 2166 subsidiary coding-system. In that case, Emacs gets coding-vector | |
| 2167 from that symbol. | |
| 2168 | |
| 2169 `element[0]' contains information to be set in `coding->type'. The | |
| 2170 value and its meaning is as follows: | |
| 2171 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2172 0 -- coding_type_emacs_mule |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2173 1 -- coding_type_sjis |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2174 2 -- coding_type_iso2022 |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2175 3 -- coding_type_big5 |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2176 4 -- coding_type_ccl encoder/decoder written in CCL |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2177 nil -- coding_type_no_conversion |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2178 t -- coding_type_undecided (automatic conversion on decoding, |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2179 no-conversion on encoding) |
| 17052 | 2180 |
| 2181 `element[4]' contains information to be set in `coding->flags' and | |
| 2182 `coding->spec'. The meaning varies by `coding->type'. | |
| 2183 | |
| 2184 If `coding->type' is `coding_type_iso2022', element[4] is a vector | |
| 2185 of length 32 (of which the first 13 sub-elements are used now). | |
| 2186 Meanings of these sub-elements are: | |
| 2187 | |
| 2188 sub-element[N] where N is 0 through 3: to be set in `coding->spec.iso2022' | |
| 2189 If the value is an integer of valid charset, the charset is | |
| 2190 assumed to be designated to graphic register N initially. | |
| 2191 | |
| 2192 If the value is minus, it is a minus value of charset which | |
| 2193 reserves graphic register N, which means that the charset is | |
| 2194 not designated initially but should be designated to graphic | |
| 2195 register N just before encoding a character in that charset. | |
| 2196 | |
| 2197 If the value is nil, graphic register N is never used on | |
| 2198 encoding. | |
| 2199 | |
| 2200 sub-element[N] where N is 4 through 11: to be set in `coding->flags' | |
| 2201 Each value takes t or nil. See the section ISO2022 of | |
| 2202 `coding.h' for more information. | |
| 2203 | |
| 2204 If `coding->type' is `coding_type_big5', element[4] is t to denote | |
| 2205 BIG5-ETen or nil to denote BIG5-HKU. | |
| 2206 | |
| 2207 If `coding->type' takes the other value, element[4] is ignored. | |
| 2208 | |
| 2209 Emacs Lisp's coding system also carries information about format of | |
| 2210 end-of-line in a value of property `eol-type'. If the value is | |
| 2211 integer, 0 means CODING_EOL_LF, 1 means CODING_EOL_CRLF, and 2 | |
| 2212 means CODING_EOL_CR. If it is not integer, it should be a vector | |
| 2213 of subsidiary coding systems of which property `eol-type' has one | |
| 2214 of above values. | |
| 2215 | |
| 2216 */ | |
| 2217 | |
| 2218 /* Extract information for decoding/encoding from CODING_SYSTEM_SYMBOL | |
| 2219 and set it in CODING. If CODING_SYSTEM_SYMBOL is invalid, CODING | |
| 2220 is setup so that no conversion is necessary and return -1, else | |
| 2221 return 0. */ | |
| 2222 | |
| 2223 int | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2224 setup_coding_system (coding_system, coding) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2225 Lisp_Object coding_system; |
| 17052 | 2226 struct coding_system *coding; |
| 2227 { | |
| 2228 Lisp_Object type, eol_type; | |
| 2229 | |
| 18766 | 2230 /* At first, set several fields to default values. */ |
| 17052 | 2231 coding->require_flushing = 0; |
| 2232 coding->last_block = 0; | |
| 2233 coding->selective = 0; | |
| 2234 coding->composing = 0; | |
| 2235 coding->direction = 0; | |
| 2236 coding->carryover_size = 0; | |
| 2237 coding->post_read_conversion = coding->pre_write_conversion = Qnil; | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2238 coding->character_unification_table_for_decode = Qnil; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2239 coding->character_unification_table_for_encode = Qnil; |
| 17052 | 2240 |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2241 Vlast_coding_system_used = coding->symbol = coding_system; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2242 eol_type = Qnil; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2243 /* Get value of property `coding-system' until we get a vector. |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2244 While doing that, also get values of properties |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2245 `post-read-conversion', `pre-write-conversion', |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2246 `character-unification-table-for-decode', |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2247 `character-unification-table-for-encode' and `eol-type'. */ |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2248 while (!NILP (coding_system) && SYMBOLP (coding_system)) |
| 17052 | 2249 { |
| 2250 if (NILP (coding->post_read_conversion)) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2251 coding->post_read_conversion = Fget (coding_system, |
| 17052 | 2252 Qpost_read_conversion); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2253 if (NILP (coding->pre_write_conversion)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2254 coding->pre_write_conversion = Fget (coding_system, |
| 17052 | 2255 Qpre_write_conversion); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
2256 if (!inhibit_eol_conversion && NILP (eol_type)) |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2257 eol_type = Fget (coding_system, Qeol_type); |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2258 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2259 if (NILP (coding->character_unification_table_for_decode)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2260 coding->character_unification_table_for_decode |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2261 = Fget (coding_system, Qcharacter_unification_table_for_decode); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2262 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2263 if (NILP (coding->character_unification_table_for_encode)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2264 coding->character_unification_table_for_encode |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2265 = Fget (coding_system, Qcharacter_unification_table_for_encode); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2266 |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2267 coding_system = Fget (coding_system, Qcoding_system); |
| 17052 | 2268 } |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2269 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2270 while (!NILP (coding->character_unification_table_for_decode) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2271 && SYMBOLP (coding->character_unification_table_for_decode)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2272 coding->character_unification_table_for_decode |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2273 = Fget (coding->character_unification_table_for_decode, |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2274 Qcharacter_unification_table_for_decode); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2275 if (!NILP (coding->character_unification_table_for_decode) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2276 && !CHAR_TABLE_P (coding->character_unification_table_for_decode)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2277 coding->character_unification_table_for_decode = Qnil; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2278 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2279 while (!NILP (coding->character_unification_table_for_encode) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2280 && SYMBOLP (coding->character_unification_table_for_encode)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2281 coding->character_unification_table_for_encode |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2282 = Fget (coding->character_unification_table_for_encode, |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2283 Qcharacter_unification_table_for_encode); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2284 if (!NILP (coding->character_unification_table_for_encode) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2285 && !CHAR_TABLE_P (coding->character_unification_table_for_encode)) |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2286 coding->character_unification_table_for_encode = Qnil; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
2287 |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2288 if (!VECTORP (coding_system) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2289 || XVECTOR (coding_system)->size != 5) |
| 17052 | 2290 goto label_invalid_coding_system; |
| 2291 | |
| 2292 if (VECTORP (eol_type)) | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2293 coding->eol_type = CODING_EOL_UNDECIDED; |
| 17052 | 2294 else if (XFASTINT (eol_type) == 1) |
| 2295 coding->eol_type = CODING_EOL_CRLF; | |
| 2296 else if (XFASTINT (eol_type) == 2) | |
| 2297 coding->eol_type = CODING_EOL_CR; | |
| 2298 else | |
| 2299 coding->eol_type = CODING_EOL_LF; | |
| 2300 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2301 type = XVECTOR (coding_system)->contents[0]; |
| 17052 | 2302 switch (XFASTINT (type)) |
| 2303 { | |
| 2304 case 0: | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2305 coding->type = coding_type_emacs_mule; |
| 17052 | 2306 break; |
| 2307 | |
| 2308 case 1: | |
| 2309 coding->type = coding_type_sjis; | |
| 2310 break; | |
| 2311 | |
| 2312 case 2: | |
| 2313 coding->type = coding_type_iso2022; | |
| 2314 { | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2315 Lisp_Object val = XVECTOR (coding_system)->contents[4]; |
| 17052 | 2316 Lisp_Object *flags; |
| 2317 int i, charset, default_reg_bits = 0; | |
| 2318 | |
| 2319 if (!VECTORP (val) || XVECTOR (val)->size != 32) | |
| 2320 goto label_invalid_coding_system; | |
| 2321 | |
| 2322 flags = XVECTOR (val)->contents; | |
| 2323 coding->flags | |
| 2324 = ((NILP (flags[4]) ? 0 : CODING_FLAG_ISO_SHORT_FORM) | |
| 2325 | (NILP (flags[5]) ? 0 : CODING_FLAG_ISO_RESET_AT_EOL) | |
| 2326 | (NILP (flags[6]) ? 0 : CODING_FLAG_ISO_RESET_AT_CNTL) | |
| 2327 | (NILP (flags[7]) ? 0 : CODING_FLAG_ISO_SEVEN_BITS) | |
| 2328 | (NILP (flags[8]) ? 0 : CODING_FLAG_ISO_LOCKING_SHIFT) | |
| 2329 | (NILP (flags[9]) ? 0 : CODING_FLAG_ISO_SINGLE_SHIFT) | |
| 2330 | (NILP (flags[10]) ? 0 : CODING_FLAG_ISO_USE_ROMAN) | |
| 2331 | (NILP (flags[11]) ? 0 : CODING_FLAG_ISO_USE_OLDJIS) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2332 | (NILP (flags[12]) ? 0 : CODING_FLAG_ISO_NO_DIRECTION) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2333 | (NILP (flags[13]) ? 0 : CODING_FLAG_ISO_INIT_AT_BOL) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2334 | (NILP (flags[14]) ? 0 : CODING_FLAG_ISO_DESIGNATE_AT_BOL)); |
| 17052 | 2335 |
| 2336 /* Invoke graphic register 0 to plane 0. */ | |
| 2337 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0; | |
| 2338 /* Invoke graphic register 1 to plane 1 if we can use full 8-bit. */ | |
| 2339 CODING_SPEC_ISO_INVOCATION (coding, 1) | |
| 2340 = (coding->flags & CODING_FLAG_ISO_SEVEN_BITS ? -1 : 1); | |
| 2341 /* Not single shifting at first. */ | |
| 2342 CODING_SPEC_ISO_SINGLE_SHIFTING(coding) = 0; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2343 /* Beginning of buffer should also be regarded as bol. */ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2344 CODING_SPEC_ISO_BOL(coding) = 1; |
| 17052 | 2345 |
| 2346 /* Checks FLAGS[REG] (REG = 0, 1, 2 3) and decide designations. | |
| 2347 FLAGS[REG] can be one of below: | |
| 2348 integer CHARSET: CHARSET occupies register I, | |
| 2349 t: designate nothing to REG initially, but can be used | |
| 2350 by any charsets, | |
| 2351 list of integer, nil, or t: designate the first | |
| 2352 element (if integer) to REG initially, the remaining | |
| 2353 elements (if integer) is designated to REG on request, | |
| 2354 if an element is t, REG can be used by any charset, | |
| 2355 nil: REG is never used. */ | |
|
17190
6637001cdb4b
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17137
diff
changeset
|
2356 for (charset = 0; charset <= MAX_CHARSET; charset++) |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
2357 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
2358 = CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION; |
| 17052 | 2359 for (i = 0; i < 4; i++) |
| 2360 { | |
| 2361 if (INTEGERP (flags[i]) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2362 && (charset = XINT (flags[i]), CHARSET_VALID_P (charset)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2363 || (charset = get_charset_id (flags[i])) >= 0) |
| 17052 | 2364 { |
| 2365 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset; | |
| 2366 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) = i; | |
| 2367 } | |
| 2368 else if (EQ (flags[i], Qt)) | |
| 2369 { | |
| 2370 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; | |
| 2371 default_reg_bits |= 1 << i; | |
| 2372 } | |
| 2373 else if (CONSP (flags[i])) | |
| 2374 { | |
| 2375 Lisp_Object tail = flags[i]; | |
| 2376 | |
| 2377 if (INTEGERP (XCONS (tail)->car) | |
| 2378 && (charset = XINT (XCONS (tail)->car), | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2379 CHARSET_VALID_P (charset)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2380 || (charset = get_charset_id (XCONS (tail)->car)) >= 0) |
| 17052 | 2381 { |
| 2382 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset; | |
| 2383 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) =i; | |
| 2384 } | |
| 2385 else | |
| 2386 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; | |
| 2387 tail = XCONS (tail)->cdr; | |
| 2388 while (CONSP (tail)) | |
| 2389 { | |
| 2390 if (INTEGERP (XCONS (tail)->car) | |
| 2391 && (charset = XINT (XCONS (tail)->car), | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2392 CHARSET_VALID_P (charset)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2393 || (charset = get_charset_id (XCONS (tail)->car)) >= 0) |
| 17052 | 2394 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
| 2395 = i; | |
| 2396 else if (EQ (XCONS (tail)->car, Qt)) | |
| 2397 default_reg_bits |= 1 << i; | |
| 2398 tail = XCONS (tail)->cdr; | |
| 2399 } | |
| 2400 } | |
| 2401 else | |
| 2402 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; | |
| 2403 | |
| 2404 CODING_SPEC_ISO_DESIGNATION (coding, i) | |
| 2405 = CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i); | |
| 2406 } | |
| 2407 | |
| 2408 if (! (coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT)) | |
| 2409 { | |
| 2410 /* REG 1 can be used only by locking shift in 7-bit env. */ | |
| 2411 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) | |
| 2412 default_reg_bits &= ~2; | |
| 2413 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)) | |
| 2414 /* Without any shifting, only REG 0 and 1 can be used. */ | |
| 2415 default_reg_bits &= 3; | |
| 2416 } | |
| 2417 | |
|
17190
6637001cdb4b
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17137
diff
changeset
|
2418 for (charset = 0; charset <= MAX_CHARSET; charset++) |
| 17052 | 2419 if (CHARSET_VALID_P (charset) |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
2420 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
2421 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)) |
| 17052 | 2422 { |
| 2423 /* We have not yet decided where to designate CHARSET. */ | |
| 2424 int reg_bits = default_reg_bits; | |
| 2425 | |
| 2426 if (CHARSET_CHARS (charset) == 96) | |
| 2427 /* A charset of CHARS96 can't be designated to REG 0. */ | |
| 2428 reg_bits &= ~1; | |
| 2429 | |
| 2430 if (reg_bits) | |
| 2431 /* There exist some default graphic register. */ | |
| 2432 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | |
| 2433 = (reg_bits & 1 | |
| 2434 ? 0 : (reg_bits & 2 ? 1 : (reg_bits & 4 ? 2 : 3))); | |
| 2435 else | |
| 2436 /* We anyway have to designate CHARSET to somewhere. */ | |
| 2437 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | |
| 2438 = (CHARSET_CHARS (charset) == 94 | |
| 2439 ? 0 | |
| 2440 : ((coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT | |
| 2441 || ! coding->flags & CODING_FLAG_ISO_SEVEN_BITS) | |
| 2442 ? 1 | |
| 2443 : (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT | |
| 2444 ? 2 : 0))); | |
| 2445 } | |
| 2446 } | |
| 2447 coding->require_flushing = 1; | |
| 2448 break; | |
| 2449 | |
| 2450 case 3: | |
| 2451 coding->type = coding_type_big5; | |
| 2452 coding->flags | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2453 = (NILP (XVECTOR (coding_system)->contents[4]) |
| 17052 | 2454 ? CODING_FLAG_BIG5_HKU |
| 2455 : CODING_FLAG_BIG5_ETEN); | |
| 2456 break; | |
| 2457 | |
| 2458 case 4: | |
| 2459 coding->type = coding_type_ccl; | |
| 2460 { | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2461 Lisp_Object val = XVECTOR (coding_system)->contents[4]; |
| 17052 | 2462 if (CONSP (val) |
| 2463 && VECTORP (XCONS (val)->car) | |
| 2464 && VECTORP (XCONS (val)->cdr)) | |
| 2465 { | |
| 2466 setup_ccl_program (&(coding->spec.ccl.decoder), XCONS (val)->car); | |
| 2467 setup_ccl_program (&(coding->spec.ccl.encoder), XCONS (val)->cdr); | |
| 2468 } | |
| 2469 else | |
| 2470 goto label_invalid_coding_system; | |
| 2471 } | |
| 2472 coding->require_flushing = 1; | |
| 2473 break; | |
| 2474 | |
| 2475 default: | |
| 2476 if (EQ (type, Qt)) | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2477 coding->type = coding_type_undecided; |
| 17052 | 2478 else |
| 2479 coding->type = coding_type_no_conversion; | |
| 2480 break; | |
| 2481 } | |
| 2482 return 0; | |
| 2483 | |
| 2484 label_invalid_coding_system: | |
| 2485 coding->type = coding_type_no_conversion; | |
|
17485
abfa77a2693b
(setup_coding_system): Setup coding->eol_type as LF
Kenichi Handa <handa@m17n.org>
parents:
17368
diff
changeset
|
2486 coding->eol_type = CODING_EOL_LF; |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2487 coding->symbol = coding->pre_write_conversion = coding->post_read_conversion |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2488 = Qnil; |
| 17052 | 2489 return -1; |
| 2490 } | |
| 2491 | |
| 2492 /* Emacs has a mechanism to automatically detect a coding system if it | |
| 2493 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, | |
| 2494 it's impossible to distinguish some coding systems accurately | |
| 2495 because they use the same range of codes. So, at first, coding | |
| 2496 systems are categorized into 7, those are: | |
| 2497 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2498 o coding-category-emacs-mule |
| 17052 | 2499 |
| 2500 The category for a coding system which has the same code range | |
| 2501 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
|
2502 symbol) `emacs-mule' by default. |
| 17052 | 2503 |
| 2504 o coding-category-sjis | |
| 2505 | |
| 2506 The category for a coding system which has the same code range | |
| 2507 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
|
2508 symbol) `japanese-shift-jis' by default. |
| 17052 | 2509 |
| 2510 o coding-category-iso-7 | |
| 2511 | |
| 2512 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
|
2513 as ISO2022 of 7-bit environment. This doesn't use any locking |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2514 shift and single shift functions. Assigned the coding-system |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2515 (Lisp symbol) `iso-2022-7bit' by default. |
| 17052 | 2516 |
| 2517 o coding-category-iso-8-1 | |
| 2518 | |
| 2519 The category for a coding system which has the same code range | |
| 2520 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
|
2521 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
|
2522 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
|
2523 symbol) `iso-latin-1' by default. |
| 17052 | 2524 |
| 2525 o coding-category-iso-8-2 | |
| 2526 | |
| 2527 The category for a coding system which has the same code range | |
| 2528 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
|
2529 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
|
2530 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
|
2531 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
|
2532 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2533 o coding-category-iso-7-else |
| 17052 | 2534 |
| 2535 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
|
2536 as ISO2022 of 7-bit environemnt but uses locking shift or |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2537 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
|
2538 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
|
2539 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2540 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
|
2541 |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2542 The category for a coding system which has the same code range |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2543 as ISO2022 of 8-bit environemnt but uses locking shift or |
|
954e6be0a757
(detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents:
18766
diff
changeset
|
2544 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
|
2545 symbol) `iso-2022-8bit-ss2' by default. |
| 17052 | 2546 |
| 2547 o coding-category-big5 | |
| 2548 | |
| 2549 The category for a coding system which has the same code range | |
| 2550 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
|
2551 `cn-big5' by default. |
| 17052 | 2552 |
| 2553 o coding-category-binary | |
| 2554 | |
| 2555 The category for a coding system not categorized in any of the | |
| 2556 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
|
2557 `no-conversion' by default. |
| 17052 | 2558 |
| 2559 Each of them is a Lisp symbol and the value is an actual | |
| 2560 `coding-system's (this is also a Lisp symbol) assigned by a user. | |
| 2561 What Emacs does actually is to detect a category of coding system. | |
| 2562 Then, it uses a `coding-system' assigned to it. If Emacs can't | |
| 2563 decide only one possible category, it selects a category of the | |
| 2564 highest priority. Priorities of categories are also specified by a | |
| 2565 user in a Lisp variable `coding-category-list'. | |
| 2566 | |
| 2567 */ | |
| 2568 | |
| 2569 /* Detect how a text of length SRC_BYTES pointed by SRC is encoded. | |
| 2570 If it detects possible coding systems, return an integer in which | |
| 2571 appropriate flag bits are set. Flag bits are defined by macros | |
| 2572 CODING_CATEGORY_MASK_XXX in `coding.h'. */ | |
| 2573 | |
| 2574 int | |
| 2575 detect_coding_mask (src, src_bytes) | |
| 2576 unsigned char *src; | |
| 2577 int src_bytes; | |
| 2578 { | |
| 2579 register unsigned char c; | |
| 2580 unsigned char *src_end = src + src_bytes; | |
| 2581 int mask; | |
| 2582 | |
| 2583 /* At first, skip all ASCII characters and control characters except | |
| 2584 for three ISO2022 specific control characters. */ | |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2585 label_loop_detect_coding: |
| 17052 | 2586 while (src < src_end) |
| 2587 { | |
| 2588 c = *src; | |
| 2589 if (c >= 0x80 | |
| 2590 || (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)) | |
| 2591 break; | |
| 2592 src++; | |
| 2593 } | |
| 2594 | |
| 2595 if (src >= src_end) | |
| 2596 /* We found nothing other than ASCII. There's nothing to do. */ | |
| 2597 return CODING_CATEGORY_MASK_ANY; | |
| 2598 | |
| 2599 /* The text seems to be encoded in some multilingual coding system. | |
| 2600 Now, try to find in which coding system the text is encoded. */ | |
| 2601 if (c < 0x80) | |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2602 { |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2603 /* i.e. (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) */ |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2604 /* C is an ISO2022 specific control code of C0. */ |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2605 mask = detect_coding_iso2022 (src, src_end); |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2606 src++; |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2607 if (mask == CODING_CATEGORY_MASK_ANY) |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2608 /* No valid ISO2022 code follows C. Try again. */ |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2609 goto label_loop_detect_coding; |
|
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
2610 } |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2611 else if (c == ISO_CODE_SS2 || c == ISO_CODE_SS3) |
| 17052 | 2612 /* C is an ISO2022 specific control code of C1, |
| 2613 or the first byte of SJIS's 2-byte character code, | |
| 2614 or a leading code of Emacs. */ | |
| 2615 mask = (detect_coding_iso2022 (src, src_end) | |
| 2616 | detect_coding_sjis (src, src_end) | |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2617 | detect_coding_emacs_mule (src, src_end) |
|
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2618 | CODING_CATEGORY_MASK_BINARY); |
| 17052 | 2619 |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2620 else if (c == ISO_CODE_CSI |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2621 && (src < src_end |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2622 && (*src == ']' |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2623 || (src + 1 < src_end |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2624 && src[1] == ']' |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2625 && (*src == '0' || *src == '1' || *src == '2'))))) |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2626 /* C is an ISO2022's control-sequence-introducer. */ |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2627 mask = (detect_coding_iso2022 (src, src_end) |
|
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2628 | detect_coding_sjis (src, src_end) |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2629 | detect_coding_emacs_mule (src, src_end) |
|
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2630 | CODING_CATEGORY_MASK_BINARY); |
|
19052
302a7b2a6948
(encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents:
18910
diff
changeset
|
2631 |
| 17052 | 2632 else if (c < 0xA0) |
| 2633 /* C is the first byte of SJIS character code, | |
| 2634 or a leading-code of Emacs. */ | |
| 2635 mask = (detect_coding_sjis (src, src_end) | |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2636 | detect_coding_emacs_mule (src, src_end) |
|
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2637 | CODING_CATEGORY_MASK_BINARY); |
| 17052 | 2638 |
| 2639 else | |
| 2640 /* C is a character of ISO2022 in graphic plane right, | |
| 2641 or a SJIS's 1-byte character code (i.e. JISX0201), | |
| 2642 or the first byte of BIG5's 2-byte code. */ | |
| 2643 mask = (detect_coding_iso2022 (src, src_end) | |
| 2644 | detect_coding_sjis (src, src_end) | |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2645 | detect_coding_big5 (src, src_end) |
|
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
2646 | CODING_CATEGORY_MASK_BINARY); |
| 17052 | 2647 |
| 2648 return mask; | |
| 2649 } | |
| 2650 | |
| 2651 /* Detect how a text of length SRC_BYTES pointed by SRC is encoded. | |
| 2652 The information of the detected coding system is set in CODING. */ | |
| 2653 | |
| 2654 void | |
| 2655 detect_coding (coding, src, src_bytes) | |
| 2656 struct coding_system *coding; | |
| 2657 unsigned char *src; | |
| 2658 int src_bytes; | |
| 2659 { | |
| 2660 int mask = detect_coding_mask (src, src_bytes); | |
| 2661 int idx; | |
| 2662 | |
| 2663 if (mask == CODING_CATEGORY_MASK_ANY) | |
| 2664 /* We found nothing other than ASCII. There's nothing to do. */ | |
| 2665 return; | |
| 2666 | |
| 2667 if (!mask) | |
| 2668 /* The source text seems to be encoded in unknown coding system. | |
| 2669 Emacs regards the category of such a kind of coding system as | |
| 2670 `coding-category-binary'. We assume that a user has assigned | |
| 2671 an appropriate coding system for a `coding-category-binary'. */ | |
| 2672 idx = CODING_CATEGORY_IDX_BINARY; | |
| 2673 else | |
| 2674 { | |
| 2675 /* We found some plausible coding systems. Let's use a coding | |
| 2676 system of the highest priority. */ | |
| 2677 Lisp_Object val = Vcoding_category_list; | |
| 2678 | |
| 2679 if (CONSP (val)) | |
| 2680 while (!NILP (val)) | |
| 2681 { | |
| 2682 idx = XFASTINT (Fget (XCONS (val)->car, Qcoding_category_index)); | |
| 2683 if ((idx < CODING_CATEGORY_IDX_MAX) && (mask & (1 << idx))) | |
| 2684 break; | |
| 2685 val = XCONS (val)->cdr; | |
| 2686 } | |
| 2687 else | |
| 2688 val = Qnil; | |
| 2689 | |
| 2690 if (NILP (val)) | |
| 2691 { | |
| 2692 /* For unknown reason, `Vcoding_category_list' contains none | |
| 2693 of found categories. Let's use any of them. */ | |
| 2694 for (idx = 0; idx < CODING_CATEGORY_IDX_MAX; idx++) | |
| 2695 if (mask & (1 << idx)) | |
| 2696 break; | |
| 2697 } | |
| 2698 } | |
| 2699 setup_coding_system (XSYMBOL (coding_category_table[idx])->value, coding); | |
| 2700 } | |
| 2701 | |
| 2702 /* Detect how end-of-line of a text of length SRC_BYTES pointed by SRC | |
| 2703 is encoded. Return one of CODING_EOL_LF, CODING_EOL_CRLF, | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2704 CODING_EOL_CR, and CODING_EOL_UNDECIDED. */ |
| 17052 | 2705 |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2706 #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
|
2707 |
| 17052 | 2708 int |
| 2709 detect_eol_type (src, src_bytes) | |
| 2710 unsigned char *src; | |
| 2711 int src_bytes; | |
| 2712 { | |
| 2713 unsigned char *src_end = src + src_bytes; | |
| 2714 unsigned char c; | |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2715 int total = 0; /* How many end-of-lines are found so far. */ |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2716 int eol_type = CODING_EOL_UNDECIDED; |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2717 int this_eol_type; |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2718 |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2719 while (src < src_end && total < MAX_EOL_CHECK_COUNT) |
| 17052 | 2720 { |
| 2721 c = *src++; | |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2722 if (c == '\n' || c == '\r') |
| 17052 | 2723 { |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2724 total++; |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2725 if (c == '\n') |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2726 this_eol_type = CODING_EOL_LF; |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2727 else if (src >= src_end || *src != '\n') |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2728 this_eol_type = CODING_EOL_CR; |
| 17052 | 2729 else |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2730 this_eol_type = CODING_EOL_CRLF, src++; |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2731 |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2732 if (eol_type == CODING_EOL_UNDECIDED) |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2733 /* This is the first end-of-line. */ |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2734 eol_type = this_eol_type; |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2735 else if (eol_type != this_eol_type) |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2736 /* The found type is different from what found before. |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2737 We had better not decode end-of-line. */ |
|
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2738 return CODING_EOL_LF; |
| 17052 | 2739 } |
| 2740 } | |
|
19173
04ed7c3f5cee
(detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents:
19134
diff
changeset
|
2741 |
|
19181
917138730635
(detect_eol_type): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
19173
diff
changeset
|
2742 return eol_type; |
| 17052 | 2743 } |
| 2744 | |
| 2745 /* Detect how end-of-line of a text of length SRC_BYTES pointed by SRC | |
| 2746 is encoded. If it detects an appropriate format of end-of-line, it | |
| 2747 sets the information in *CODING. */ | |
| 2748 | |
| 2749 void | |
| 2750 detect_eol (coding, src, src_bytes) | |
| 2751 struct coding_system *coding; | |
| 2752 unsigned char *src; | |
| 2753 int src_bytes; | |
| 2754 { | |
| 2755 Lisp_Object val; | |
| 2756 int eol_type = detect_eol_type (src, src_bytes); | |
| 2757 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2758 if (eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 2759 /* We found no end-of-line in the source text. */ |
| 2760 return; | |
| 2761 | |
| 2762 val = Fget (coding->symbol, Qeol_type); | |
| 2763 if (VECTORP (val) && XVECTOR (val)->size == 3) | |
| 2764 setup_coding_system (XVECTOR (val)->contents[eol_type], coding); | |
| 2765 } | |
| 2766 | |
| 2767 /* See "GENERAL NOTES about `decode_coding_XXX ()' functions". Before | |
| 2768 decoding, it may detect coding system and format of end-of-line if | |
| 2769 those are not yet decided. */ | |
| 2770 | |
| 2771 int | |
| 2772 decode_coding (coding, source, destination, src_bytes, dst_bytes, consumed) | |
| 2773 struct coding_system *coding; | |
| 2774 unsigned char *source, *destination; | |
| 2775 int src_bytes, dst_bytes; | |
| 2776 int *consumed; | |
| 2777 { | |
| 2778 int produced; | |
| 2779 | |
| 2780 if (src_bytes <= 0) | |
| 2781 { | |
| 2782 *consumed = 0; | |
| 2783 return 0; | |
| 2784 } | |
| 2785 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2786 if (coding->type == coding_type_undecided) |
| 17052 | 2787 detect_coding (coding, source, src_bytes); |
| 2788 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2789 if (coding->eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 2790 detect_eol (coding, source, src_bytes); |
| 2791 | |
| 2792 coding->carryover_size = 0; | |
| 2793 switch (coding->type) | |
| 2794 { | |
| 2795 case coding_type_no_conversion: | |
| 2796 label_no_conversion: | |
| 2797 produced = (src_bytes > dst_bytes) ? dst_bytes : src_bytes; | |
| 2798 bcopy (source, destination, produced); | |
| 2799 *consumed = produced; | |
| 2800 break; | |
| 2801 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2802 case coding_type_emacs_mule: |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2803 case coding_type_undecided: |
| 17052 | 2804 if (coding->eol_type == CODING_EOL_LF |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2805 || coding->eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 2806 goto label_no_conversion; |
| 2807 produced = decode_eol (coding, source, destination, | |
| 2808 src_bytes, dst_bytes, consumed); | |
| 2809 break; | |
| 2810 | |
| 2811 case coding_type_sjis: | |
| 2812 produced = decode_coding_sjis_big5 (coding, source, destination, | |
| 2813 src_bytes, dst_bytes, consumed, | |
| 2814 1); | |
| 2815 break; | |
| 2816 | |
| 2817 case coding_type_iso2022: | |
| 2818 produced = decode_coding_iso2022 (coding, source, destination, | |
| 2819 src_bytes, dst_bytes, consumed); | |
| 2820 break; | |
| 2821 | |
| 2822 case coding_type_big5: | |
| 2823 produced = decode_coding_sjis_big5 (coding, source, destination, | |
| 2824 src_bytes, dst_bytes, consumed, | |
| 2825 0); | |
| 2826 break; | |
| 2827 | |
| 2828 case coding_type_ccl: | |
| 2829 produced = ccl_driver (&coding->spec.ccl.decoder, source, destination, | |
| 2830 src_bytes, dst_bytes, consumed); | |
| 2831 break; | |
| 2832 } | |
| 2833 | |
| 2834 return produced; | |
| 2835 } | |
| 2836 | |
| 2837 /* See "GENERAL NOTES about `encode_coding_XXX ()' functions". */ | |
| 2838 | |
| 2839 int | |
| 2840 encode_coding (coding, source, destination, src_bytes, dst_bytes, consumed) | |
| 2841 struct coding_system *coding; | |
| 2842 unsigned char *source, *destination; | |
| 2843 int src_bytes, dst_bytes; | |
| 2844 int *consumed; | |
| 2845 { | |
| 2846 int produced; | |
| 2847 | |
| 2848 switch (coding->type) | |
| 2849 { | |
| 2850 case coding_type_no_conversion: | |
| 2851 label_no_conversion: | |
| 2852 produced = (src_bytes > dst_bytes) ? dst_bytes : src_bytes; | |
| 2853 if (produced > 0) | |
| 2854 { | |
| 2855 bcopy (source, destination, produced); | |
| 2856 if (coding->selective) | |
| 2857 { | |
| 2858 unsigned char *p = destination, *pend = destination + produced; | |
| 2859 while (p < pend) | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2860 if (*p++ == '\015') p[-1] = '\n'; |
| 17052 | 2861 } |
| 2862 } | |
| 2863 *consumed = produced; | |
| 2864 break; | |
| 2865 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2866 case coding_type_emacs_mule: |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2867 case coding_type_undecided: |
| 17052 | 2868 if (coding->eol_type == CODING_EOL_LF |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
2869 || coding->eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 2870 goto label_no_conversion; |
| 2871 produced = encode_eol (coding, source, destination, | |
| 2872 src_bytes, dst_bytes, consumed); | |
| 2873 break; | |
| 2874 | |
| 2875 case coding_type_sjis: | |
| 2876 produced = encode_coding_sjis_big5 (coding, source, destination, | |
| 2877 src_bytes, dst_bytes, consumed, | |
| 2878 1); | |
| 2879 break; | |
| 2880 | |
| 2881 case coding_type_iso2022: | |
| 2882 produced = encode_coding_iso2022 (coding, source, destination, | |
| 2883 src_bytes, dst_bytes, consumed); | |
| 2884 break; | |
| 2885 | |
| 2886 case coding_type_big5: | |
| 2887 produced = encode_coding_sjis_big5 (coding, source, destination, | |
| 2888 src_bytes, dst_bytes, consumed, | |
| 2889 0); | |
| 2890 break; | |
| 2891 | |
| 2892 case coding_type_ccl: | |
| 2893 produced = ccl_driver (&coding->spec.ccl.encoder, source, destination, | |
| 2894 src_bytes, dst_bytes, consumed); | |
| 2895 break; | |
| 2896 } | |
| 2897 | |
| 2898 return produced; | |
| 2899 } | |
| 2900 | |
| 2901 #define CONVERSION_BUFFER_EXTRA_ROOM 256 | |
| 2902 | |
| 2903 /* Return maximum size (bytes) of a buffer enough for decoding | |
| 2904 SRC_BYTES of text encoded in CODING. */ | |
| 2905 | |
| 2906 int | |
| 2907 decoding_buffer_size (coding, src_bytes) | |
| 2908 struct coding_system *coding; | |
| 2909 int src_bytes; | |
| 2910 { | |
| 2911 int magnification; | |
| 2912 | |
| 2913 if (coding->type == coding_type_iso2022) | |
| 2914 magnification = 3; | |
| 2915 else if (coding->type == coding_type_ccl) | |
| 2916 magnification = coding->spec.ccl.decoder.buf_magnification; | |
| 2917 else | |
| 2918 magnification = 2; | |
| 2919 | |
| 2920 return (src_bytes * magnification + CONVERSION_BUFFER_EXTRA_ROOM); | |
| 2921 } | |
| 2922 | |
| 2923 /* Return maximum size (bytes) of a buffer enough for encoding | |
| 2924 SRC_BYTES of text to CODING. */ | |
| 2925 | |
| 2926 int | |
| 2927 encoding_buffer_size (coding, src_bytes) | |
| 2928 struct coding_system *coding; | |
| 2929 int src_bytes; | |
| 2930 { | |
| 2931 int magnification; | |
| 2932 | |
| 2933 if (coding->type == coding_type_ccl) | |
| 2934 magnification = coding->spec.ccl.encoder.buf_magnification; | |
| 2935 else | |
| 2936 magnification = 3; | |
| 2937 | |
| 2938 return (src_bytes * magnification + CONVERSION_BUFFER_EXTRA_ROOM); | |
| 2939 } | |
| 2940 | |
| 2941 #ifndef MINIMUM_CONVERSION_BUFFER_SIZE | |
| 2942 #define MINIMUM_CONVERSION_BUFFER_SIZE 1024 | |
| 2943 #endif | |
| 2944 | |
| 2945 char *conversion_buffer; | |
| 2946 int conversion_buffer_size; | |
| 2947 | |
| 2948 /* Return a pointer to a SIZE bytes of buffer to be used for encoding | |
| 2949 or decoding. Sufficient memory is allocated automatically. If we | |
| 2950 run out of memory, return NULL. */ | |
| 2951 | |
| 2952 char * | |
| 2953 get_conversion_buffer (size) | |
| 2954 int size; | |
| 2955 { | |
| 2956 if (size > conversion_buffer_size) | |
| 2957 { | |
| 2958 char *buf; | |
| 2959 int real_size = conversion_buffer_size * 2; | |
| 2960 | |
| 2961 while (real_size < size) real_size *= 2; | |
| 2962 buf = (char *) xmalloc (real_size); | |
| 2963 xfree (conversion_buffer); | |
| 2964 conversion_buffer = buf; | |
| 2965 conversion_buffer_size = real_size; | |
| 2966 } | |
| 2967 return conversion_buffer; | |
| 2968 } | |
| 2969 | |
| 2970 | |
| 2971 #ifdef emacs | |
| 2972 /*** 7. Emacs Lisp library functions ***/ | |
| 2973 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
2974 DEFUN ("coding-system-spec", Fcoding_system_spec, Scoding_system_spec, |
| 17052 | 2975 1, 1, 0, |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
2976 "Return coding-spec of CODING-SYSTEM.\n\ |
| 17052 | 2977 If CODING-SYSTEM is not a valid coding-system, return nil.") |
| 2978 (obj) | |
| 2979 Lisp_Object obj; | |
| 2980 { | |
| 2981 while (SYMBOLP (obj) && !NILP (obj)) | |
| 2982 obj = Fget (obj, Qcoding_system); | |
| 2983 return ((NILP (obj) || !VECTORP (obj) || XVECTOR (obj)->size != 5) | |
| 2984 ? Qnil : obj); | |
| 2985 } | |
| 2986 | |
| 2987 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0, | |
| 2988 "Return t if OBJECT is nil or a coding-system.\n\ | |
| 2989 See document of make-coding-system for coding-system object.") | |
| 2990 (obj) | |
| 2991 Lisp_Object obj; | |
| 2992 { | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
2993 return ((NILP (obj) || !NILP (Fcoding_system_spec (obj))) ? Qt : Qnil); |
| 17052 | 2994 } |
| 2995 | |
|
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
2996 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
|
2997 Sread_non_nil_coding_system, 1, 1, 0, |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
2998 "Read a coding system from the minibuffer, prompting with string PROMPT.") |
| 17052 | 2999 (prompt) |
| 3000 Lisp_Object prompt; | |
| 3001 { | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3002 Lisp_Object val; |
|
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
3003 do |
|
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
3004 { |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3005 val = Fcompleting_read (prompt, Vobarray, Qcoding_system_spec, |
|
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
3006 Qt, Qnil, Qnil, Qnil); |
|
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
3007 } |
|
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
3008 while (XSTRING (val)->size == 0); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3009 return (Fintern (val, Qnil)); |
| 17052 | 3010 } |
| 3011 | |
| 3012 DEFUN ("read-coding-system", Fread_coding_system, Sread_coding_system, 1, 1, 0, | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3013 "Read a coding system or nil from the minibuffer, prompting with string PROMPT.") |
| 17052 | 3014 (prompt) |
| 3015 Lisp_Object prompt; | |
| 3016 { | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3017 Lisp_Object val = Fcompleting_read (prompt, Vobarray, Qcoding_system_p, |
|
17717
4891aaecc5cc
(Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents:
17485
diff
changeset
|
3018 Qt, Qnil, Qnil, Qnil); |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3019 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
| 17052 | 3020 } |
| 3021 | |
| 3022 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, | |
| 3023 1, 1, 0, | |
| 3024 "Check validity of CODING-SYSTEM.\n\ | |
| 3025 If valid, return CODING-SYSTEM, else `coding-system-error' is signaled.\n\ | |
| 3026 CODING-SYSTEM is valid if it is a symbol and has \"coding-system\" property.\n\ | |
| 3027 The value of property should be a vector of length 5.") | |
| 3028 (coding_system) | |
| 3029 Lisp_Object coding_system; | |
| 3030 { | |
| 3031 CHECK_SYMBOL (coding_system, 0); | |
| 3032 if (!NILP (Fcoding_system_p (coding_system))) | |
| 3033 return coding_system; | |
| 3034 while (1) | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3035 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
| 17052 | 3036 } |
| 3037 | |
| 3038 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, | |
| 3039 2, 2, 0, | |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3040 "Detect coding system of the text in the region between START and END.\n\ |
|
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3041 Return a list of possible coding systems ordered by priority.\n\ |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3042 If only ASCII characters are found, it returns `undecided'\n\ |
|
19134
8fa6e23f8d22
(detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents:
19118
diff
changeset
|
3043 or its subsidiary coding system according to a detected end-of-line format.") |
| 17052 | 3044 (b, e) |
| 3045 Lisp_Object b, e; | |
| 3046 { | |
| 3047 int coding_mask, eol_type; | |
| 3048 Lisp_Object val; | |
| 3049 int beg, end; | |
| 3050 | |
| 3051 validate_region (&b, &e); | |
| 3052 beg = XINT (b), end = XINT (e); | |
| 3053 if (beg < GPT && end >= GPT) move_gap (end); | |
| 3054 | |
| 3055 coding_mask = detect_coding_mask (POS_ADDR (beg), end - beg); | |
| 3056 eol_type = detect_eol_type (POS_ADDR (beg), end - beg); | |
| 3057 | |
| 3058 if (coding_mask == CODING_CATEGORY_MASK_ANY) | |
| 3059 { | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3060 val = intern ("undecided"); |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3061 if (eol_type != CODING_EOL_UNDECIDED) |
| 17052 | 3062 { |
| 3063 Lisp_Object val2 = Fget (val, Qeol_type); | |
| 3064 if (VECTORP (val2)) | |
| 3065 val = XVECTOR (val2)->contents[eol_type]; | |
| 3066 } | |
| 3067 } | |
| 3068 else | |
| 3069 { | |
| 3070 Lisp_Object val2; | |
| 3071 | |
| 3072 /* At first, gather possible coding-systems in VAL in a reverse | |
| 3073 order. */ | |
| 3074 val = Qnil; | |
| 3075 for (val2 = Vcoding_category_list; | |
| 3076 !NILP (val2); | |
| 3077 val2 = XCONS (val2)->cdr) | |
| 3078 { | |
| 3079 int idx | |
| 3080 = XFASTINT (Fget (XCONS (val2)->car, Qcoding_category_index)); | |
| 3081 if (coding_mask & (1 << idx)) | |
| 3082 val = Fcons (Fsymbol_value (XCONS (val2)->car), val); | |
| 3083 } | |
| 3084 | |
| 3085 /* Then, change the order of the list, while getting subsidiary | |
| 3086 coding-systems. */ | |
| 3087 val2 = val; | |
| 3088 val = Qnil; | |
| 3089 for (; !NILP (val2); val2 = XCONS (val2)->cdr) | |
| 3090 { | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3091 if (eol_type == CODING_EOL_UNDECIDED) |
| 17052 | 3092 val = Fcons (XCONS (val2)->car, val); |
| 3093 else | |
| 3094 { | |
| 3095 Lisp_Object val3 = Fget (XCONS (val2)->car, Qeol_type); | |
| 3096 if (VECTORP (val3)) | |
| 3097 val = Fcons (XVECTOR (val3)->contents[eol_type], val); | |
| 3098 else | |
| 3099 val = Fcons (XCONS (val2)->car, val); | |
| 3100 } | |
| 3101 } | |
| 3102 } | |
| 3103 | |
| 3104 return val; | |
| 3105 } | |
| 3106 | |
| 3107 /* Scan text in the region between *BEGP and *ENDP, skip characters | |
| 3108 which we never have to encode to (iff ENCODEP is 1) or decode from | |
| 3109 coding system CODING at the head and tail, then set BEGP and ENDP | |
| 3110 to the addresses of start and end of the text we actually convert. */ | |
| 3111 | |
| 3112 void | |
| 3113 shrink_conversion_area (begp, endp, coding, encodep) | |
| 3114 unsigned char **begp, **endp; | |
| 3115 struct coding_system *coding; | |
| 3116 int encodep; | |
| 3117 { | |
| 3118 register unsigned char *beg_addr = *begp, *end_addr = *endp; | |
| 3119 | |
| 3120 if (coding->eol_type != CODING_EOL_LF | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3121 && coding->eol_type != CODING_EOL_UNDECIDED) |
| 17052 | 3122 /* Since we anyway have to convert end-of-line format, it is not |
| 3123 worth skipping at most 100 bytes or so. */ | |
| 3124 return; | |
| 3125 | |
| 3126 if (encodep) /* for encoding */ | |
| 3127 { | |
| 3128 switch (coding->type) | |
| 3129 { | |
| 3130 case coding_type_no_conversion: | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3131 case coding_type_emacs_mule: |
|
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3132 case coding_type_undecided: |
| 17052 | 3133 /* We need no conversion. */ |
| 3134 *begp = *endp; | |
| 3135 return; | |
| 3136 case coding_type_ccl: | |
| 3137 /* We can't skip any data. */ | |
| 3138 return; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3139 case coding_type_iso2022: |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3140 if (coding->flags & CODING_FLAG_ISO_DESIGNATE_AT_BOL) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3141 { |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3142 unsigned char *bol = beg_addr; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3143 while (beg_addr < end_addr && *beg_addr < 0x80) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3144 { |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3145 beg_addr++; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3146 if (*(beg_addr - 1) == '\n') |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3147 bol = beg_addr; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3148 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3149 beg_addr = bol; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3150 goto label_skip_tail; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3151 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3152 /* fall down ... */ |
| 17052 | 3153 default: |
| 3154 /* We can skip all ASCII characters at the head and tail. */ | |
| 3155 while (beg_addr < end_addr && *beg_addr < 0x80) beg_addr++; | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3156 label_skip_tail: |
| 17052 | 3157 while (beg_addr < end_addr && *(end_addr - 1) < 0x80) end_addr--; |
| 3158 break; | |
| 3159 } | |
| 3160 } | |
| 3161 else /* for decoding */ | |
| 3162 { | |
| 3163 switch (coding->type) | |
| 3164 { | |
| 3165 case coding_type_no_conversion: | |
| 3166 /* We need no conversion. */ | |
| 3167 *begp = *endp; | |
| 3168 return; | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3169 case coding_type_emacs_mule: |
| 17052 | 3170 if (coding->eol_type == CODING_EOL_LF) |
| 3171 { | |
| 3172 /* We need no conversion. */ | |
| 3173 *begp = *endp; | |
| 3174 return; | |
| 3175 } | |
| 3176 /* We can skip all but carriage-return. */ | |
| 3177 while (beg_addr < end_addr && *beg_addr != '\r') beg_addr++; | |
| 3178 while (beg_addr < end_addr && *(end_addr - 1) != '\r') end_addr--; | |
| 3179 break; | |
| 3180 case coding_type_sjis: | |
| 3181 case coding_type_big5: | |
| 3182 /* We can skip all ASCII characters at the head. */ | |
| 3183 while (beg_addr < end_addr && *beg_addr < 0x80) beg_addr++; | |
| 3184 /* We can skip all ASCII characters at the tail except for | |
| 3185 the second byte of SJIS or BIG5 code. */ | |
| 3186 while (beg_addr < end_addr && *(end_addr - 1) < 0x80) end_addr--; | |
| 3187 if (end_addr != *endp) | |
| 3188 end_addr++; | |
| 3189 break; | |
| 3190 case coding_type_ccl: | |
| 3191 /* We can't skip any data. */ | |
| 3192 return; | |
| 3193 default: /* i.e. case coding_type_iso2022: */ | |
| 3194 { | |
| 3195 unsigned char c; | |
| 3196 | |
| 3197 /* We can skip all ASCII characters except for a few | |
| 3198 control codes at the head. */ | |
| 3199 while (beg_addr < end_addr && (c = *beg_addr) < 0x80 | |
| 3200 && c != ISO_CODE_CR && c != ISO_CODE_SO | |
| 3201 && c != ISO_CODE_SI && c != ISO_CODE_ESC) | |
| 3202 beg_addr++; | |
| 3203 } | |
| 3204 break; | |
| 3205 } | |
| 3206 } | |
| 3207 *begp = beg_addr; | |
| 3208 *endp = end_addr; | |
| 3209 return; | |
| 3210 } | |
| 3211 | |
| 3212 /* Encode to (iff ENCODEP is 1) or decode form coding system CODING a | |
| 3213 text between B and E. B and E are buffer position. */ | |
| 3214 | |
| 3215 Lisp_Object | |
| 3216 code_convert_region (b, e, coding, encodep) | |
| 3217 Lisp_Object b, e; | |
| 3218 struct coding_system *coding; | |
| 3219 int encodep; | |
| 3220 { | |
| 3221 int beg, end, len, consumed, produced; | |
| 3222 char *buf; | |
| 3223 unsigned char *begp, *endp; | |
| 3224 int pos = PT; | |
| 3225 | |
| 3226 validate_region (&b, &e); | |
| 3227 beg = XINT (b), end = XINT (e); | |
| 3228 if (beg < GPT && end >= GPT) | |
| 3229 move_gap (end); | |
| 3230 | |
| 3231 if (encodep && !NILP (coding->pre_write_conversion)) | |
| 3232 { | |
| 3233 /* We must call a pre-conversion function which may put a new | |
| 3234 text to be converted in a new buffer. */ | |
| 3235 struct buffer *old = current_buffer, *new; | |
| 3236 | |
| 3237 TEMP_SET_PT (beg); | |
| 3238 call2 (coding->pre_write_conversion, b, e); | |
| 3239 if (old != current_buffer) | |
| 3240 { | |
| 3241 /* Replace the original text by the text just generated. */ | |
| 3242 len = ZV - BEGV; | |
| 3243 new = current_buffer; | |
| 3244 set_buffer_internal (old); | |
| 3245 del_range (beg, end); | |
| 3246 insert_from_buffer (new, 1, len, 0); | |
| 3247 end = beg + len; | |
| 3248 } | |
| 3249 } | |
| 3250 | |
| 3251 /* We may be able to shrink the conversion region. */ | |
| 3252 begp = POS_ADDR (beg); endp = begp + (end - beg); | |
| 3253 shrink_conversion_area (&begp, &endp, coding, encodep); | |
| 3254 | |
| 3255 if (begp == endp) | |
| 3256 /* We need no conversion. */ | |
| 3257 len = end - beg; | |
| 3258 else | |
| 3259 { | |
| 3260 beg += begp - POS_ADDR (beg); | |
| 3261 end = beg + (endp - begp); | |
| 3262 | |
| 3263 if (encodep) | |
| 3264 len = encoding_buffer_size (coding, end - beg); | |
| 3265 else | |
| 3266 len = decoding_buffer_size (coding, end - beg); | |
| 3267 buf = get_conversion_buffer (len); | |
| 3268 | |
| 3269 coding->last_block = 1; | |
| 3270 produced = (encodep | |
| 3271 ? encode_coding (coding, POS_ADDR (beg), buf, end - beg, len, | |
| 3272 &consumed) | |
| 3273 : decode_coding (coding, POS_ADDR (beg), buf, end - beg, len, | |
| 3274 &consumed)); | |
| 3275 | |
| 3276 len = produced + (beg - XINT (b)) + (XINT (e) - end); | |
| 3277 | |
| 3278 TEMP_SET_PT (beg); | |
| 3279 insert (buf, produced); | |
| 3280 del_range (PT, PT + end - beg); | |
| 3281 if (pos >= end) | |
| 3282 pos = PT + (pos - end); | |
| 3283 else if (pos > beg) | |
| 3284 pos = beg; | |
| 3285 TEMP_SET_PT (pos); | |
| 3286 } | |
| 3287 | |
| 3288 if (!encodep && !NILP (coding->post_read_conversion)) | |
| 3289 { | |
| 3290 /* We must call a post-conversion function which may alter | |
| 3291 the text just converted. */ | |
| 3292 Lisp_Object insval; | |
| 3293 | |
| 3294 beg = XINT (b); | |
| 3295 TEMP_SET_PT (beg); | |
| 3296 insval = call1 (coding->post_read_conversion, make_number (len)); | |
| 3297 CHECK_NUMBER (insval, 0); | |
| 3298 len = XINT (insval); | |
| 3299 } | |
| 3300 | |
| 3301 return make_number (len); | |
| 3302 } | |
| 3303 | |
| 3304 Lisp_Object | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3305 code_convert_string (str, coding, encodep, nocopy) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3306 Lisp_Object str, nocopy; |
| 17052 | 3307 struct coding_system *coding; |
| 3308 int encodep; | |
| 3309 { | |
| 3310 int len, consumed, produced; | |
| 3311 char *buf; | |
| 3312 unsigned char *begp, *endp; | |
| 3313 int head_skip, tail_skip; | |
| 3314 struct gcpro gcpro1; | |
| 3315 | |
| 3316 if (encodep && !NILP (coding->pre_write_conversion) | |
| 3317 || !encodep && !NILP (coding->post_read_conversion)) | |
| 3318 { | |
| 3319 /* Since we have to call Lisp functions which assume target text | |
| 3320 is in a buffer, after setting a temporary buffer, call | |
| 3321 code_convert_region. */ | |
| 3322 int count = specpdl_ptr - specpdl; | |
| 3323 int len = XSTRING (str)->size; | |
| 3324 Lisp_Object result; | |
| 3325 struct buffer *old = current_buffer; | |
| 3326 | |
| 3327 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
| 3328 temp_output_buffer_setup (" *code-converting-work*"); | |
| 3329 set_buffer_internal (XBUFFER (Vstandard_output)); | |
| 3330 insert_from_string (str, 0, len, 0); | |
| 3331 code_convert_region (make_number (BEGV), make_number (ZV), | |
| 3332 coding, encodep); | |
| 3333 result = make_buffer_string (BEGV, ZV, 0); | |
| 3334 set_buffer_internal (old); | |
| 3335 return unbind_to (count, result); | |
| 3336 } | |
| 3337 | |
| 3338 /* We may be able to shrink the conversion region. */ | |
| 3339 begp = XSTRING (str)->data; | |
| 3340 endp = begp + XSTRING (str)->size; | |
| 3341 shrink_conversion_area (&begp, &endp, coding, encodep); | |
| 3342 | |
| 3343 if (begp == endp) | |
| 3344 /* We need no conversion. */ | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3345 return (NILP (nocopy) ? Fcopy_sequence (str) : str); |
| 17052 | 3346 |
| 3347 head_skip = begp - XSTRING (str)->data; | |
| 3348 tail_skip = XSTRING (str)->size - head_skip - (endp - begp); | |
| 3349 | |
| 3350 GCPRO1 (str); | |
| 3351 | |
| 3352 if (encodep) | |
| 3353 len = encoding_buffer_size (coding, endp - begp); | |
| 3354 else | |
| 3355 len = decoding_buffer_size (coding, endp - begp); | |
| 3356 buf = get_conversion_buffer (len + head_skip + tail_skip); | |
| 3357 | |
| 3358 bcopy (XSTRING (str)->data, buf, head_skip); | |
| 3359 coding->last_block = 1; | |
| 3360 produced = (encodep | |
| 3361 ? encode_coding (coding, XSTRING (str)->data + head_skip, | |
| 3362 buf + head_skip, endp - begp, len, &consumed) | |
| 3363 : decode_coding (coding, XSTRING (str)->data + head_skip, | |
| 3364 buf + head_skip, endp - begp, len, &consumed)); | |
| 3365 bcopy (XSTRING (str)->data + head_skip + (endp - begp), | |
| 3366 buf + head_skip + produced, | |
| 3367 tail_skip); | |
| 3368 | |
| 3369 UNGCPRO; | |
| 3370 | |
| 3371 return make_string (buf, head_skip + produced + tail_skip); | |
| 3372 } | |
| 3373 | |
| 3374 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3375 3, 3, "r\nzCoding system: ", |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3376 "Decode current region by specified coding system.\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3377 When called from a program, takes three arguments:\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3378 START, END, and CODING-SYSTEM. START END are buffer positions.\n\ |
| 17052 | 3379 Return length of decoded text.") |
| 3380 (b, e, coding_system) | |
| 3381 Lisp_Object b, e, coding_system; | |
| 3382 { | |
| 3383 struct coding_system coding; | |
| 3384 | |
| 3385 CHECK_NUMBER_COERCE_MARKER (b, 0); | |
| 3386 CHECK_NUMBER_COERCE_MARKER (e, 1); | |
| 3387 CHECK_SYMBOL (coding_system, 2); | |
| 3388 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3389 if (NILP (coding_system)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3390 return make_number (XFASTINT (e) - XFASTINT (b)); |
| 17052 | 3391 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
| 3392 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data); | |
| 3393 | |
| 3394 return code_convert_region (b, e, &coding, 0); | |
| 3395 } | |
| 3396 | |
| 3397 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3398 3, 3, "r\nzCoding system: ", |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3399 "Encode current region by specified coding system.\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3400 When called from a program, takes three arguments:\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3401 START, END, and CODING-SYSTEM. START END are buffer positions.\n\ |
| 17052 | 3402 Return length of encoded text.") |
| 3403 (b, e, coding_system) | |
| 3404 Lisp_Object b, e, coding_system; | |
| 3405 { | |
| 3406 struct coding_system coding; | |
| 3407 | |
| 3408 CHECK_NUMBER_COERCE_MARKER (b, 0); | |
| 3409 CHECK_NUMBER_COERCE_MARKER (e, 1); | |
| 3410 CHECK_SYMBOL (coding_system, 2); | |
| 3411 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3412 if (NILP (coding_system)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3413 return make_number (XFASTINT (e) - XFASTINT (b)); |
| 17052 | 3414 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
| 3415 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data); | |
| 3416 | |
| 3417 return code_convert_region (b, e, &coding, 1); | |
| 3418 } | |
| 3419 | |
| 3420 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3421 2, 3, 0, |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3422 "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3423 Optional arg NOCOPY non-nil means return STRING itself if there's no need\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3424 of decoding.") |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3425 (string, coding_system, nocopy) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3426 Lisp_Object string, coding_system, nocopy; |
| 17052 | 3427 { |
| 3428 struct coding_system coding; | |
| 3429 | |
| 3430 CHECK_STRING (string, 0); | |
| 3431 CHECK_SYMBOL (coding_system, 1); | |
| 3432 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3433 if (NILP (coding_system)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3434 return (NILP (nocopy) ? Fcopy_sequence (string) : string); |
| 17052 | 3435 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
| 3436 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data); | |
| 3437 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3438 return code_convert_string (string, &coding, 0, nocopy); |
| 17052 | 3439 } |
| 3440 | |
| 3441 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3442 2, 3, 0, |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3443 "Encode STRING to CODING-SYSTEM, and return the result.\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3444 Optional arg NOCOPY non-nil means return STRING itself if there's no need\n\ |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3445 of encoding.") |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3446 (string, coding_system, nocopy) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3447 Lisp_Object string, coding_system, nocopy; |
| 17052 | 3448 { |
| 3449 struct coding_system coding; | |
| 3450 | |
| 3451 CHECK_STRING (string, 0); | |
| 3452 CHECK_SYMBOL (coding_system, 1); | |
| 3453 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3454 if (NILP (coding_system)) |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3455 return (NILP (nocopy) ? Fcopy_sequence (string) : string); |
| 17052 | 3456 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
| 3457 error ("Invalid coding-system: %s", XSYMBOL (coding_system)->name->data); | |
| 3458 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3459 return code_convert_string (string, &coding, 1, nocopy); |
| 17052 | 3460 } |
| 3461 | |
| 3462 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3463 "Decode a JISX0208 character of shift-jis encoding.\n\ |
| 17052 | 3464 CODE is the character code in SJIS.\n\ |
| 3465 Return the corresponding character.") | |
| 3466 (code) | |
| 3467 Lisp_Object code; | |
| 3468 { | |
| 3469 unsigned char c1, c2, s1, s2; | |
| 3470 Lisp_Object val; | |
| 3471 | |
| 3472 CHECK_NUMBER (code, 0); | |
| 3473 s1 = (XFASTINT (code)) >> 8, s2 = (XFASTINT (code)) & 0xFF; | |
| 3474 DECODE_SJIS (s1, s2, c1, c2); | |
| 3475 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_jisx0208, c1, c2)); | |
| 3476 return val; | |
| 3477 } | |
| 3478 | |
| 3479 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0, | |
| 3480 "Encode a JISX0208 character CHAR to SJIS coding-system.\n\ | |
| 3481 Return the corresponding character code in SJIS.") | |
| 3482 (ch) | |
| 3483 Lisp_Object ch; | |
| 3484 { | |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
3485 int charset, c1, c2, s1, s2; |
| 17052 | 3486 Lisp_Object val; |
| 3487 | |
| 3488 CHECK_NUMBER (ch, 0); | |
| 3489 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); | |
| 3490 if (charset == charset_jisx0208) | |
| 3491 { | |
| 3492 ENCODE_SJIS (c1, c2, s1, s2); | |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
3493 XSETFASTINT (val, (s1 << 8) | s2); |
| 17052 | 3494 } |
| 3495 else | |
| 3496 XSETFASTINT (val, 0); | |
| 3497 return val; | |
| 3498 } | |
| 3499 | |
| 3500 DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0, | |
| 3501 "Decode a Big5 character CODE of BIG5 coding-system.\n\ | |
| 3502 CODE is the character code in BIG5.\n\ | |
| 3503 Return the corresponding character.") | |
| 3504 (code) | |
| 3505 Lisp_Object code; | |
| 3506 { | |
| 3507 int charset; | |
| 3508 unsigned char b1, b2, c1, c2; | |
| 3509 Lisp_Object val; | |
| 3510 | |
| 3511 CHECK_NUMBER (code, 0); | |
| 3512 b1 = (XFASTINT (code)) >> 8, b2 = (XFASTINT (code)) & 0xFF; | |
| 3513 DECODE_BIG5 (b1, b2, charset, c1, c2); | |
| 3514 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset, c1, c2)); | |
| 3515 return val; | |
| 3516 } | |
| 3517 | |
| 3518 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0, | |
| 3519 "Encode the Big5 character CHAR to BIG5 coding-system.\n\ | |
| 3520 Return the corresponding character code in Big5.") | |
| 3521 (ch) | |
| 3522 Lisp_Object ch; | |
| 3523 { | |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
3524 int charset, c1, c2, b1, b2; |
| 17052 | 3525 Lisp_Object val; |
| 3526 | |
| 3527 CHECK_NUMBER (ch, 0); | |
| 3528 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); | |
| 3529 if (charset == charset_big5_1 || charset == charset_big5_2) | |
| 3530 { | |
| 3531 ENCODE_BIG5 (charset, c1, c2, b1, b2); | |
|
17320
9d15bec5f47e
(detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents:
17304
diff
changeset
|
3532 XSETFASTINT (val, (b1 << 8) | b2); |
| 17052 | 3533 } |
| 3534 else | |
| 3535 XSETFASTINT (val, 0); | |
| 3536 return val; | |
| 3537 } | |
| 3538 | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3539 DEFUN ("set-terminal-coding-system-internal", |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3540 Fset_terminal_coding_system_internal, |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3541 Sset_terminal_coding_system_internal, 1, 1, 0, "") |
| 17052 | 3542 (coding_system) |
| 3543 Lisp_Object coding_system; | |
| 3544 { | |
| 3545 CHECK_SYMBOL (coding_system, 0); | |
| 3546 setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding); | |
| 3547 return Qnil; | |
| 3548 } | |
| 3549 | |
| 3550 DEFUN ("terminal-coding-system", | |
| 3551 Fterminal_coding_system, Sterminal_coding_system, 0, 0, 0, | |
| 3552 "Return coding-system of your terminal.") | |
| 3553 () | |
| 3554 { | |
| 3555 return terminal_coding.symbol; | |
| 3556 } | |
| 3557 | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3558 DEFUN ("set-keyboard-coding-system-internal", |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3559 Fset_keyboard_coding_system_internal, |
|
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3560 Sset_keyboard_coding_system_internal, 1, 1, 0, "") |
| 17052 | 3561 (coding_system) |
| 3562 Lisp_Object coding_system; | |
| 3563 { | |
| 3564 CHECK_SYMBOL (coding_system, 0); | |
| 3565 setup_coding_system (Fcheck_coding_system (coding_system), &keyboard_coding); | |
| 3566 return Qnil; | |
| 3567 } | |
| 3568 | |
| 3569 DEFUN ("keyboard-coding-system", | |
| 3570 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 0, 0, | |
| 3571 "Return coding-system of what is sent from terminal keyboard.") | |
| 3572 () | |
| 3573 { | |
| 3574 return keyboard_coding.symbol; | |
| 3575 } | |
| 3576 | |
| 3577 | |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3578 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
|
3579 Sfind_operation_coding_system, 1, MANY, 0, |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3580 "Choose a coding system for an operation based on the target name.\n\ |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3581 The value names a pair of coding systems: (DECODING-SYSTEM ENCODING-SYSTEM).\n\ |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3582 DECODING-SYSTEM is the coding system to use for decoding\n\ |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3583 \(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system\n\ |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3584 for encoding (in case OPERATION does encoding).\n\ |
|
17304
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3585 \n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3586 The first argument OPERATION specifies an I/O primitive:\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3587 For file I/O, `insert-file-contents' or `write-region'.\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3588 For process I/O, `call-process', `call-process-region', or `start-process'.\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3589 For network I/O, `open-network-stream'.\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3590 \n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3591 The remaining arguments should be the same arguments that were passed\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3592 to the primitive. Depending on which primitive, one of those arguments\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3593 is selected as the TARGET. For example, if OPERATION does file I/O,\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3594 whichever argument specifies the file name is TARGET.\n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3595 \n\ |
|
ecacd8936926
(Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
17190
diff
changeset
|
3596 TARGET has a meaning which depends on OPERATION:\n\ |
| 17052 | 3597 For file I/O, TARGET is a file name.\n\ |
| 3598 For process I/O, TARGET is a process name.\n\ | |
| 3599 For network I/O, TARGET is a service name or a port number\n\ | |
| 3600 \n\ | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3601 This function looks up what specified for TARGET in,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3602 `file-coding-system-alist', `process-coding-system-alist',\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3603 or `network-coding-system-alist' depending on OPERATION.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3604 They may specify a coding system, a cons of coding systems,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3605 or a function symbol to call.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3606 In the last case, we call the function with one argument,\n\ |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3607 which is a list of all the arguments given to this function.") |
| 17052 | 3608 (nargs, args) |
| 3609 int nargs; | |
| 3610 Lisp_Object *args; | |
| 3611 { | |
| 3612 Lisp_Object operation, target_idx, target, val; | |
| 3613 register Lisp_Object chain; | |
| 3614 | |
| 3615 if (nargs < 2) | |
| 3616 error ("Too few arguments"); | |
| 3617 operation = args[0]; | |
| 3618 if (!SYMBOLP (operation) | |
| 3619 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx))) | |
| 3620 error ("Invalid first arguement"); | |
| 3621 if (nargs < 1 + XINT (target_idx)) | |
| 3622 error ("Too few arguments for operation: %s", | |
| 3623 XSYMBOL (operation)->name->data); | |
| 3624 target = args[XINT (target_idx) + 1]; | |
| 3625 if (!(STRINGP (target) | |
| 3626 || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | |
| 3627 error ("Invalid %dth argument", XINT (target_idx) + 1); | |
| 3628 | |
|
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18536
diff
changeset
|
3629 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
|
3630 || EQ (operation, Qwrite_region)) |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3631 ? 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
|
3632 : (EQ (operation, Qopen_network_stream) |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3633 ? Vnetwork_coding_system_alist |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3634 : Vprocess_coding_system_alist)); |
| 17052 | 3635 if (NILP (chain)) |
| 3636 return Qnil; | |
| 3637 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3638 for (; CONSP (chain); chain = XCONS (chain)->cdr) |
| 17052 | 3639 { |
| 3640 Lisp_Object elt = XCONS (chain)->car; | |
| 3641 | |
| 3642 if (CONSP (elt) | |
| 3643 && ((STRINGP (target) | |
| 3644 && STRINGP (XCONS (elt)->car) | |
| 3645 && fast_string_match (XCONS (elt)->car, target) >= 0) | |
| 3646 || (INTEGERP (target) && EQ (target, XCONS (elt)->car)))) | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3647 { |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3648 val = XCONS (elt)->cdr; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3649 if (CONSP (val)) |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3650 return val; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3651 if (! SYMBOLP (val)) |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3652 return Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3653 if (! NILP (Fcoding_system_p (val))) |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3654 return Fcons (val, val); |
|
18860
f55d91d45bde
(Ffind_operation_coding_system): Use Ffboundp to
Richard M. Stallman <rms@gnu.org>
parents:
18787
diff
changeset
|
3655 if (!NILP (Ffboundp (val))) |
|
18747
17039a6e64cf
(Ffind_coding_system): Use call1, not call2.
Richard M. Stallman <rms@gnu.org>
parents:
18650
diff
changeset
|
3656 return call1 (val, Flist (nargs, args)); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3657 return Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3658 } |
| 17052 | 3659 } |
| 3660 return Qnil; | |
| 3661 } | |
| 3662 | |
| 3663 #endif /* emacs */ | |
| 3664 | |
| 3665 | |
| 3666 /*** 8. Post-amble ***/ | |
| 3667 | |
| 3668 init_coding_once () | |
| 3669 { | |
| 3670 int i; | |
| 3671 | |
|
17835
f36ffb6f1208
Name change through the code:
Kenichi Handa <handa@m17n.org>
parents:
17725
diff
changeset
|
3672 /* Emacs' internal format specific initialize routine. */ |
| 17052 | 3673 for (i = 0; i <= 0x20; i++) |
| 3674 emacs_code_class[i] = EMACS_control_code; | |
| 3675 emacs_code_class[0x0A] = EMACS_linefeed_code; | |
| 3676 emacs_code_class[0x0D] = EMACS_carriage_return_code; | |
| 3677 for (i = 0x21 ; i < 0x7F; i++) | |
| 3678 emacs_code_class[i] = EMACS_ascii_code; | |
| 3679 emacs_code_class[0x7F] = EMACS_control_code; | |
| 3680 emacs_code_class[0x80] = EMACS_leading_code_composition; | |
| 3681 for (i = 0x81; i < 0xFF; i++) | |
| 3682 emacs_code_class[i] = EMACS_invalid_code; | |
| 3683 emacs_code_class[LEADING_CODE_PRIVATE_11] = EMACS_leading_code_3; | |
| 3684 emacs_code_class[LEADING_CODE_PRIVATE_12] = EMACS_leading_code_3; | |
| 3685 emacs_code_class[LEADING_CODE_PRIVATE_21] = EMACS_leading_code_4; | |
| 3686 emacs_code_class[LEADING_CODE_PRIVATE_22] = EMACS_leading_code_4; | |
| 3687 | |
| 3688 /* ISO2022 specific initialize routine. */ | |
| 3689 for (i = 0; i < 0x20; i++) | |
| 3690 iso_code_class[i] = ISO_control_code; | |
| 3691 for (i = 0x21; i < 0x7F; i++) | |
| 3692 iso_code_class[i] = ISO_graphic_plane_0; | |
| 3693 for (i = 0x80; i < 0xA0; i++) | |
| 3694 iso_code_class[i] = ISO_control_code; | |
| 3695 for (i = 0xA1; i < 0xFF; i++) | |
| 3696 iso_code_class[i] = ISO_graphic_plane_1; | |
| 3697 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F; | |
| 3698 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF; | |
| 3699 iso_code_class[ISO_CODE_CR] = ISO_carriage_return; | |
| 3700 iso_code_class[ISO_CODE_SO] = ISO_shift_out; | |
| 3701 iso_code_class[ISO_CODE_SI] = ISO_shift_in; | |
| 3702 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7; | |
| 3703 iso_code_class[ISO_CODE_ESC] = ISO_escape; | |
| 3704 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2; | |
| 3705 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; | |
| 3706 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; | |
| 3707 | |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3708 conversion_buffer_size = MINIMUM_CONVERSION_BUFFER_SIZE; |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3709 conversion_buffer = (char *) xmalloc (MINIMUM_CONVERSION_BUFFER_SIZE); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3710 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3711 setup_coding_system (Qnil, &keyboard_coding); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3712 setup_coding_system (Qnil, &terminal_coding); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3713 |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3714 #if defined (MSDOS) || defined (WINDOWSNT) |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3715 system_eol_type = CODING_EOL_CRLF; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3716 #else |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3717 system_eol_type = CODING_EOL_LF; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3718 #endif |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3719 } |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3720 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3721 #ifdef emacs |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3722 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3723 syms_of_coding () |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3724 { |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3725 Qtarget_idx = intern ("target-idx"); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3726 staticpro (&Qtarget_idx); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3727 |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3728 /* 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
|
3729 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
|
3730 /* 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
|
3731 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
|
3732 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3733 Qcall_process = intern ("call-process"); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3734 staticpro (&Qcall_process); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3735 /* 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
|
3736 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
|
3737 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3738 Qcall_process_region = intern ("call-process-region"); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3739 staticpro (&Qcall_process_region); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3740 /* 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
|
3741 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
|
3742 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3743 Qstart_process = intern ("start-process"); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3744 staticpro (&Qstart_process); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3745 /* 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
|
3746 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
|
3747 |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3748 Qopen_network_stream = intern ("open-network-stream"); |
|
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3749 staticpro (&Qopen_network_stream); |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3750 /* 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
|
3751 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
|
3752 |
| 17052 | 3753 Qcoding_system = intern ("coding-system"); |
| 3754 staticpro (&Qcoding_system); | |
| 3755 | |
| 3756 Qeol_type = intern ("eol-type"); | |
| 3757 staticpro (&Qeol_type); | |
| 3758 | |
| 3759 Qbuffer_file_coding_system = intern ("buffer-file-coding-system"); | |
| 3760 staticpro (&Qbuffer_file_coding_system); | |
| 3761 | |
| 3762 Qpost_read_conversion = intern ("post-read-conversion"); | |
| 3763 staticpro (&Qpost_read_conversion); | |
| 3764 | |
| 3765 Qpre_write_conversion = intern ("pre-write-conversion"); | |
| 3766 staticpro (&Qpre_write_conversion); | |
| 3767 | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3768 Qcoding_system_spec = intern ("coding-system-spec"); |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3769 staticpro (&Qcoding_system_spec); |
| 17052 | 3770 |
| 3771 Qcoding_system_p = intern ("coding-system-p"); | |
| 3772 staticpro (&Qcoding_system_p); | |
| 3773 | |
| 3774 Qcoding_system_error = intern ("coding-system-error"); | |
| 3775 staticpro (&Qcoding_system_error); | |
| 3776 | |
| 3777 Fput (Qcoding_system_error, Qerror_conditions, | |
| 3778 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil))); | |
| 3779 Fput (Qcoding_system_error, Qerror_message, | |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3780 build_string ("Invalid coding system")); |
| 17052 | 3781 |
| 3782 Qcoding_category_index = intern ("coding-category-index"); | |
| 3783 staticpro (&Qcoding_category_index); | |
| 3784 | |
| 3785 { | |
| 3786 int i; | |
| 3787 for (i = 0; i < CODING_CATEGORY_IDX_MAX; i++) | |
| 3788 { | |
| 3789 coding_category_table[i] = intern (coding_category_name[i]); | |
| 3790 staticpro (&coding_category_table[i]); | |
| 3791 Fput (coding_category_table[i], Qcoding_category_index, | |
| 3792 make_number (i)); | |
| 3793 } | |
| 3794 } | |
| 3795 | |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3796 Qcharacter_unification_table = intern ("character-unification-table"); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3797 staticpro (&Qcharacter_unification_table); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3798 Fput (Qcharacter_unification_table, Qchar_table_extra_slots, |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3799 make_number (0)); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3800 |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3801 Qcharacter_unification_table_for_decode |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3802 = intern ("character-unification-table-for-decode"); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3803 staticpro (&Qcharacter_unification_table_for_decode); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3804 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3805 Qcharacter_unification_table_for_encode |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3806 = intern ("character-unification-table-for-encode"); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3807 staticpro (&Qcharacter_unification_table_for_encode); |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3808 |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3809 Qemacs_mule = intern ("emacs-mule"); |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3810 staticpro (&Qemacs_mule); |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3811 |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3812 defsubr (&Scoding_system_spec); |
| 17052 | 3813 defsubr (&Scoding_system_p); |
| 3814 defsubr (&Sread_coding_system); | |
| 3815 defsubr (&Sread_non_nil_coding_system); | |
| 3816 defsubr (&Scheck_coding_system); | |
| 3817 defsubr (&Sdetect_coding_region); | |
| 3818 defsubr (&Sdecode_coding_region); | |
| 3819 defsubr (&Sencode_coding_region); | |
| 3820 defsubr (&Sdecode_coding_string); | |
| 3821 defsubr (&Sencode_coding_string); | |
| 3822 defsubr (&Sdecode_sjis_char); | |
| 3823 defsubr (&Sencode_sjis_char); | |
| 3824 defsubr (&Sdecode_big5_char); | |
| 3825 defsubr (&Sencode_big5_char); | |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3826 defsubr (&Sset_terminal_coding_system_internal); |
| 17052 | 3827 defsubr (&Sterminal_coding_system); |
|
18002
a14261786239
(encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents:
17835
diff
changeset
|
3828 defsubr (&Sset_keyboard_coding_system_internal); |
| 17052 | 3829 defsubr (&Skeyboard_coding_system); |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3830 defsubr (&Sfind_operation_coding_system); |
| 17052 | 3831 |
| 3832 DEFVAR_LISP ("coding-category-list", &Vcoding_category_list, | |
| 3833 "List of coding-categories (symbols) ordered by priority."); | |
| 3834 { | |
| 3835 int i; | |
| 3836 | |
| 3837 Vcoding_category_list = Qnil; | |
| 3838 for (i = CODING_CATEGORY_IDX_MAX - 1; i >= 0; i--) | |
| 3839 Vcoding_category_list | |
| 3840 = Fcons (coding_category_table[i], Vcoding_category_list); | |
| 3841 } | |
| 3842 | |
| 3843 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read, | |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
3844 "Specify the coding system for read operations.\n\ |
|
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
3845 It is useful to bind this variable with `let', but do not set it globally. |
| 17052 | 3846 If the value is a coding system, it is used for decoding on read operation.\n\ |
|
18910
50c89868f8c7
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
18860
diff
changeset
|
3847 If not, an appropriate element is used from one of the coding system alists:\n\ |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
3848 There are three such tables, `file-coding-system-alist',\n\ |
|
18910
50c89868f8c7
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
18860
diff
changeset
|
3849 `process-coding-system-alist', and `network-coding-system-alist'."); |
| 17052 | 3850 Vcoding_system_for_read = Qnil; |
| 3851 | |
| 3852 DEFVAR_LISP ("coding-system-for-write", &Vcoding_system_for_write, | |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
3853 "Specify the coding system for write operations.\n\ |
|
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
3854 It is useful to bind this variable with `let', but do not set it globally. |
| 17052 | 3855 If the value is a coding system, it is used for encoding on write operation.\n\ |
|
18910
50c89868f8c7
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
18860
diff
changeset
|
3856 If not, an appropriate element is used from one of the coding system alists:\n\ |
|
19118
16ef8c28e4e0
(detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents:
19068
diff
changeset
|
3857 There are three such tables, `file-coding-system-alist',\n\ |
|
18910
50c89868f8c7
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
18860
diff
changeset
|
3858 `process-coding-system-alist', and `network-coding-system-alist'."); |
| 17052 | 3859 Vcoding_system_for_write = Qnil; |
| 3860 | |
| 3861 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used, | |
|
18910
50c89868f8c7
(syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
18860
diff
changeset
|
3862 "Coding system used in the latest file or process I/O."); |
| 17052 | 3863 Vlast_coding_system_used = Qnil; |
| 3864 | |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3865 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion, |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3866 "*Non-nil inhibit code conversion of end-of-line format in any cases."); |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3867 inhibit_eol_conversion = 0; |
|
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3868 |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3869 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3870 "Alist to decide a coding system to use for a file I/O operation.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3871 The format is ((PATTERN . VAL) ...),\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3872 where PATTERN is a regular expression matching a file name,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3873 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3874 If VAL is a coding system, it is used for both decoding and encoding\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3875 the file contents.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3876 If VAL is a cons of coding systems, the car part is used for decoding,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3877 and the cdr part is used for encoding.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3878 If VAL is a function symbol, the function must return a coding system\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3879 or a cons of coding systems which are used as above.\n\ |
|
17119
2cfb31c15ced
(create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
3880 \n\ |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3881 See also the function `find-operation-coding-system'."); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3882 Vfile_coding_system_alist = Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3883 |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3884 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3885 "Alist to decide a coding system to use for a process I/O operation.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3886 The format is ((PATTERN . VAL) ...),\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3887 where PATTERN is a regular expression matching a program name,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3888 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3889 If VAL is a coding system, it is used for both decoding what received\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3890 from the program and encoding what sent to the program.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3891 If VAL is a cons of coding systems, the car part is used for decoding,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3892 and the cdr part is used for encoding.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3893 If VAL is a function symbol, the function must return a coding system\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3894 or a cons of coding systems which are used as above.\n\ |
| 17052 | 3895 \n\ |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3896 See also the function `find-operation-coding-system'."); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3897 Vprocess_coding_system_alist = Qnil; |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3898 |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3899 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3900 "Alist to decide a coding system to use for a network I/O operation.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3901 The format is ((PATTERN . VAL) ...),\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3902 where PATTERN is a regular expression matching a network service name\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3903 or is a port number to connect to,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3904 VAL is a coding system, a cons of coding systems, or a function symbol.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3905 If VAL is a coding system, it is used for both decoding what received\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3906 from the network stream and encoding what sent to the network stream.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3907 If VAL is a cons of coding systems, the car part is used for decoding,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3908 and the cdr part is used for encoding.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3909 If VAL is a function symbol, the function must return a coding system\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3910 or a cons of coding systems which are used as above.\n\ |
| 17052 | 3911 \n\ |
|
18650
aa3f2820e2ac
(Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents:
18613
diff
changeset
|
3912 See also the function `find-operation-coding-system'."); |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3913 Vnetwork_coding_system_alist = Qnil; |
| 17052 | 3914 |
| 3915 DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix, | |
| 3916 "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) ."); | |
|
18523
6b5af78c8b21
(syms_of_coding): Change initial values of eol_mnemonic_... variables.
Richard M. Stallman <rms@gnu.org>
parents:
18310
diff
changeset
|
3917 eol_mnemonic_unix = ':'; |
| 17052 | 3918 |
| 3919 DEFVAR_INT ("eol-mnemonic-dos", &eol_mnemonic_dos, | |
| 3920 "Mnemonic character indicating DOS-like end-of-line format (i.e. CRLF)."); | |
|
18523
6b5af78c8b21
(syms_of_coding): Change initial values of eol_mnemonic_... variables.
Richard M. Stallman <rms@gnu.org>
parents:
18310
diff
changeset
|
3921 eol_mnemonic_dos = '\\'; |
| 17052 | 3922 |
| 3923 DEFVAR_INT ("eol-mnemonic-mac", &eol_mnemonic_mac, | |
| 3924 "Mnemonic character indicating MAC-like end-of-line format (i.e. CR)."); | |
|
18523
6b5af78c8b21
(syms_of_coding): Change initial values of eol_mnemonic_... variables.
Richard M. Stallman <rms@gnu.org>
parents:
18310
diff
changeset
|
3925 eol_mnemonic_mac = '/'; |
| 17052 | 3926 |
| 3927 DEFVAR_INT ("eol-mnemonic-undecided", &eol_mnemonic_undecided, | |
| 3928 "Mnemonic character indicating end-of-line format is not yet decided."); | |
|
18523
6b5af78c8b21
(syms_of_coding): Change initial values of eol_mnemonic_... variables.
Richard M. Stallman <rms@gnu.org>
parents:
18310
diff
changeset
|
3929 eol_mnemonic_undecided = ':'; |
| 17052 | 3930 |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3931 DEFVAR_LISP ("enable-character-unification", &Venable_character_unification, |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3932 "Non-nil means ISO 2022 encoder/decoder do character unification."); |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3933 Venable_character_unification = Qt; |
|
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3934 |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3935 DEFVAR_LISP ("standard-character-unification-table-for-decode", |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3936 &Vstandard_character_unification_table_for_decode, |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3937 "Table for unifying characters when reading."); |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3938 Vstandard_character_unification_table_for_decode = Qnil; |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3939 |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3940 DEFVAR_LISP ("standard-character-unification-table-for-encode", |
|
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3941 &Vstandard_character_unification_table_for_encode, |
|
17725
92f042f73be2
(Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents:
17717
diff
changeset
|
3942 "Table for unifying characters when writing."); |
|
18536
69c0e220b626
(Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents:
18523
diff
changeset
|
3943 Vstandard_character_unification_table_for_encode = Qnil; |
| 17052 | 3944 |
| 3945 DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_alist, | |
| 3946 "Alist of charsets vs revision numbers.\n\ | |
| 3947 While encoding, if a charset (car part of an element) is found,\n\ | |
| 3948 designate it with the escape sequence identifing revision (cdr part of the element)."); | |
| 3949 Vcharset_revision_alist = Qnil; | |
|
18180
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3950 |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3951 DEFVAR_LISP ("default-process-coding-system", |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3952 &Vdefault_process_coding_system, |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3953 "Cons of coding systems used for process I/O by default.\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3954 The car part is used for decoding a process output,\n\ |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3955 the cdr part is used for encoding a text to be sent to a process."); |
|
5f4c4da24e75
(Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
18002
diff
changeset
|
3956 Vdefault_process_coding_system = Qnil; |
| 17052 | 3957 } |
| 3958 | |
| 3959 #endif /* emacs */ |
