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