annotate src/coding.c @ 35034:4b4cc897a985

Fix a typo.
author Eli Zaretskii <eliz@gnu.org>
date Thu, 04 Jan 2001 08:01:10 +0000
parents 8cd5e6ad71a2
children e3e1ff3616fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1 /* Coding system handler (conversion, detection, and etc).
20708
ed9ed828415e Update copyright year.
Richard M. Stallman <rms@gnu.org>
parents: 20680
diff changeset
2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
18269
888bfd80db2c Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents: 18180
diff changeset
3 Licensed to the Free Software Foundation.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4
17071
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
5 This file is part of GNU Emacs.
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
6
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
8 it under the terms of the GNU General Public License as published by
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
10 any later version.
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
11
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
15 GNU General Public License for more details.
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
16
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
17 You should have received a copy of the GNU General Public License
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
20 Boston, MA 02111-1307, USA. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 /*** TABLE OF CONTENTS ***
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
24 0. General comments
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
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
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 3. ISO2022 handlers
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 4. Shift-JIS and BIG5 handlers
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
29 5. CCL handlers
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
30 6. End-of-line handlers
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
31 7. C library functions
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
32 8. Emacs Lisp library functions
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
33 9. Post-amble
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
37 /*** 0. General comments ***/
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
38
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
39
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 /*** GENERAL NOTE on CODING SYSTEM ***
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 Coding system is an encoding mechanism of one or more character
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 sets. Here's a list of coding systems which Emacs can handle. When
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 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
45 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
46 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
47 coding system.
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
48
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
49 0. Emacs' internal format (emacs-mule)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 Emacs itself holds a multi-lingual character in a buffer and a string
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
52 in a special format. Details are described in section 2.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 1. ISO2022
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 The most famous coding system for multiple character sets. X's
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
57 Compound Text, various EUCs (Extended Unix Code), and coding
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
58 systems used in Internet communication such as ISO-2022-JP are
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
59 all variants of ISO2022. Details are described in section 3.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 2. SJIS (or Shift-JIS or MS-Kanji-Code)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 A coding system to encode character sets: ASCII, JISX0201, and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 JISX0208. Widely used for PC's in Japan. Details are described in
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
65 section 4.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 3. BIG5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 A coding system to encode character sets: ASCII and Big5. Widely
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 used by Chinese (mainly in Taiwan and Hong Kong). Details are
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
71 described in section 4. In this file, when we write "BIG5"
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
72 (all uppercase), we mean the coding system, and when we write
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
73 "Big5" (capitalized), we mean the character set.
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
74
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
75 4. Raw text
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
76
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
77 A coding system for a text containing random 8-bit code. Emacs does
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
78 no code conversion on such a text except for end-of-line format.
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
79
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
80 5. Other
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
81
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
82 If a user wants to read/write a text encoded in a coding system not
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 listed above, he can supply a decoder and an encoder for it in CCL
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 (Code Conversion Language) programs. Emacs executes the CCL program
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 while reading/writing.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
87 Emacs represents a coding system by a Lisp symbol that has a property
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
88 `coding-system'. But, before actually using the coding system, the
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 information about it is set in a structure of type `struct
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
90 coding_system' for rapid processing. See section 6 for more details.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 /*** GENERAL NOTES on END-OF-LINE FORMAT ***
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 How end-of-line of a text is encoded depends on a system. For
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 instance, Unix's format is just one byte of `line-feed' code,
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
98 whereas DOS's format is two-byte sequence of `carriage-return' and
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
99 `line-feed' codes. MacOS's format is usually one byte of
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
100 `carriage-return'.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
102 Since text characters encoding and end-of-line encoding are
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
103 independent, any coding system described above can take
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 any format of end-of-line. So, Emacs has information of format of
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
105 end-of-line in each coding-system. See section 6 for more details.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 /*** GENERAL NOTES on `detect_coding_XXX ()' functions ***
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 These functions check if a text between SRC and SRC_END is encoded
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 in the coding system category XXX. Each returns an integer value in
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 which appropriate flag bits for the category XXX is set. The flag
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 bits are defined in macros CODING_CATEGORY_MASK_XXX. Below is the
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
115 template of these functions. If MULTIBYTEP is nonzero, 8-bit codes
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
116 of the range 0x80..0x9F are in multibyte form. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 #if 0
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 int
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
119 detect_coding_emacs_mule (src, src_end, multibytep)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
121 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 #endif
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 /*** GENERAL NOTES on `decode_coding_XXX ()' functions ***
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
129 These functions decode SRC_BYTES length of unibyte text at SOURCE
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
130 encoded in CODING to Emacs' internal format. The resulting
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
131 multibyte text goes to a place pointed to by DESTINATION, the length
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
132 of which should not exceed DST_BYTES.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
133
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
134 These functions set the information of original and decoded texts in
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
135 the members produced, produced_char, consumed, and consumed_char of
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
136 the structure *CODING. They also set the member result to one of
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
137 CODING_FINISH_XXX indicating how the decoding finished.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
138
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
139 DST_BYTES zero means that source area and destination area are
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
140 overlapped, which means that we can produce a decoded text until it
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
141 reaches at the head of not-yet-decoded source text.
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
142
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
143 Below is a template of these functions. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 #if 0
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
145 static void
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
146 decode_coding_XXX (coding, source, destination, src_bytes, dst_bytes)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 #endif
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 /*** GENERAL NOTES on `encode_coding_XXX ()' functions ***
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
157 These functions encode SRC_BYTES length text at SOURCE of Emacs'
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
158 internal multibyte format to CODING. The resulting unibyte text
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
159 goes to a place pointed to by DESTINATION, the length of which
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
160 should not exceed DST_BYTES.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
161
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
162 These functions set the information of original and encoded texts in
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
163 the members produced, produced_char, consumed, and consumed_char of
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
164 the structure *CODING. They also set the member result to one of
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
165 CODING_FINISH_XXX indicating how the encoding finished.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
166
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
167 DST_BYTES zero means that source area and destination area are
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
168 overlapped, which means that we can produce a encoded text until it
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
169 reaches at the head of not-yet-encoded source text.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
170
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
171 Below is a template of these functions. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 #if 0
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
173 static void
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
174 encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 #endif
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 /*** COMMONLY USED MACROS ***/
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
185 /* The following two macros ONE_MORE_BYTE and TWO_MORE_BYTES safely
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
186 get one, two, and three bytes from the source text respectively.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
187 If there are not enough bytes in the source, they jump to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
188 `label_end_of_loop'. The caller should set variables `coding',
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
189 `src' and `src_end' to appropriate pointer in advance. These
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
190 macros are called from decoding routines `decode_coding_XXX', thus
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
191 it is assumed that the source text is unibyte. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
192
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
193 #define ONE_MORE_BYTE(c1) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
194 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
195 if (src >= src_end) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
196 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
197 coding->result = CODING_FINISH_INSUFFICIENT_SRC; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
198 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
199 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
200 c1 = *src++; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
201 } while (0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
202
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
203 #define TWO_MORE_BYTES(c1, c2) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
204 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
205 if (src + 1 >= src_end) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
206 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
207 coding->result = CODING_FINISH_INSUFFICIENT_SRC; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
208 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
209 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
210 c1 = *src++; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
211 c2 = *src++; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
214
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
215 /* Like ONE_MORE_BYTE, but 8-bit bytes of data at SRC are in multibyte
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
216 form if MULTIBYTEP is nonzero. */
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
217
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
218 #define ONE_MORE_BYTE_CHECK_MULTIBYTE(c1, multibytep) \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
219 do { \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
220 if (src >= src_end) \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
221 { \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
222 coding->result = CODING_FINISH_INSUFFICIENT_SRC; \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
223 goto label_end_of_loop; \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
224 } \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
225 c1 = *src++; \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
226 if (multibytep && c1 == LEADING_CODE_8_BIT_CONTROL) \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
227 c1 = *src++ - 0x20; \
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
228 } while (0)
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
229
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
230 /* Set C to the next character at the source text pointed by `src'.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
231 If there are not enough characters in the source, jump to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
232 `label_end_of_loop'. The caller should set variables `coding'
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
233 `src', `src_end', and `translation_table' to appropriate pointers
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
234 in advance. This macro is used in encoding routines
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
235 `encode_coding_XXX', thus it assumes that the source text is in
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
236 multibyte form except for 8-bit characters. 8-bit characters are
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
237 in multibyte form if coding->src_multibyte is nonzero, else they
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
238 are represented by a single byte. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
239
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
240 #define ONE_MORE_CHAR(c) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
241 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
242 int len = src_end - src; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
243 int bytes; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
244 if (len <= 0) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
245 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
246 coding->result = CODING_FINISH_INSUFFICIENT_SRC; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
247 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
248 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
249 if (coding->src_multibyte \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
250 || UNIBYTE_STR_AS_MULTIBYTE_P (src, len, bytes)) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
251 c = STRING_CHAR_AND_LENGTH (src, len, bytes); \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
252 else \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
253 c = *src, bytes = 1; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
254 if (!NILP (translation_table)) \
31455
0b33b8c5d16e (encode_coding_sjis_big5): Use translation table for
Kenichi Handa <handa@m17n.org>
parents: 31123
diff changeset
255 c = translate_char (translation_table, c, -1, 0, 0); \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
256 src += bytes; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
259
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
260 /* Produce a multibyte form of characater C to `dst'. Jump to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
261 `label_end_of_loop' if there's not enough space at `dst'.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
262
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
263 If we are now in the middle of composition sequence, the decoded
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
264 character may be ALTCHAR (for the current composition). In that
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
265 case, the character goes to coding->cmp_data->data instead of
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
266 `dst'.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
267
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
268 This macro is used in decoding routines. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
269
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
270 #define EMIT_CHAR(c) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
271 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
272 if (! COMPOSING_P (coding) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
273 || coding->composing == COMPOSITION_RELATIVE \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
274 || coding->composing == COMPOSITION_WITH_RULE) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
275 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
276 int bytes = CHAR_BYTES (c); \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
277 if ((dst + bytes) > (dst_bytes ? dst_end : src)) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
278 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
279 coding->result = CODING_FINISH_INSUFFICIENT_DST; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
280 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
281 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
282 dst += CHAR_STRING (c, dst); \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
283 coding->produced_char++; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
284 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
285 \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
286 if (COMPOSING_P (coding) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
287 && coding->composing != COMPOSITION_RELATIVE) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
288 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
289 CODING_ADD_COMPOSITION_COMPONENT (coding, c); \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
290 coding->composition_rule_follows \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
291 = coding->composing != COMPOSITION_WITH_ALTCHARS; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
292 } \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
295
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
296 #define EMIT_ONE_BYTE(c) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
297 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
298 if (dst >= (dst_bytes ? dst_end : src)) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
299 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
300 coding->result = CODING_FINISH_INSUFFICIENT_DST; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
301 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
302 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
303 *dst++ = c; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
305
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
306 #define EMIT_TWO_BYTES(c1, c2) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
307 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
308 if (dst + 2 > (dst_bytes ? dst_end : src)) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
309 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
310 coding->result = CODING_FINISH_INSUFFICIENT_DST; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
311 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
312 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
313 *dst++ = c1, *dst++ = c2; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
314 } while (0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
315
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
316 #define EMIT_BYTES(from, to) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
317 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
318 if (dst + (to - from) > (dst_bytes ? dst_end : src)) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
319 { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
320 coding->result = CODING_FINISH_INSUFFICIENT_DST; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
321 goto label_end_of_loop; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
322 } \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
323 while (from < to) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
324 *dst++ = *from++; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
325 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328 /*** 1. Preamble ***/
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
330 #ifdef emacs
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
331 #include <config.h>
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
332 #endif
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
333
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334 #include <stdio.h>
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 #ifdef emacs
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338 #include "lisp.h"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 #include "buffer.h"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340 #include "charset.h"
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
341 #include "composite.h"
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 #include "ccl.h"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
343 #include "coding.h"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
344 #include "window.h"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
345
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346 #else /* not emacs */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
348 #include "mulelib.h"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
350 #endif /* not emacs */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
351
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
352 Lisp_Object Qcoding_system, Qeol_type;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
353 Lisp_Object Qbuffer_file_coding_system;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
354 Lisp_Object Qpost_read_conversion, Qpre_write_conversion;
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
355 Lisp_Object Qno_conversion, Qundecided;
19750
95e4e1cba6ac (Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19747
diff changeset
356 Lisp_Object Qcoding_system_history;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
357 Lisp_Object Qsafe_chars;
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
358 Lisp_Object Qvalid_codes;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360 extern Lisp_Object Qinsert_file_contents, Qwrite_region;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 Lisp_Object Qstart_process, Qopen_network_stream;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 Lisp_Object Qtarget_idx;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
365 Lisp_Object Vselect_safe_coding_system_function;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
366
24200
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
367 /* Mnemonic string for each format of end-of-line. */
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
368 Lisp_Object eol_mnemonic_unix, eol_mnemonic_dos, eol_mnemonic_mac;
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
369 /* Mnemonic string to indicate format of end-of-line is not yet
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
370 decided. */
24200
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
371 Lisp_Object eol_mnemonic_undecided;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
373 /* Format of end-of-line decided by system. This is CODING_EOL_LF on
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
374 Unix, CODING_EOL_CRLF on DOS/Windows, and CODING_EOL_CR on Mac. */
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
375 int system_eol_type;
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
376
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 #ifdef emacs
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
379 Lisp_Object Vcoding_system_list, Vcoding_system_alist;
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
380
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
381 Lisp_Object Qcoding_system_p, Qcoding_system_error;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
383 /* Coding system emacs-mule and raw-text are for converting only
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
384 end-of-line format. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
385 Lisp_Object Qemacs_mule, Qraw_text;
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
386
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 /* Coding-systems are handed between Emacs Lisp programs and C internal
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 routines by the following three variables. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 /* Coding-system for reading files and receiving data from process. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 Lisp_Object Vcoding_system_for_read;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 /* Coding-system for writing files and sending data to process. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 Lisp_Object Vcoding_system_for_write;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393 /* Coding-system actually used in the latest I/O. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 Lisp_Object Vlast_coding_system_used;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
396 /* A vector of length 256 which contains information about special
22529
d9eac134a41b Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22502
diff changeset
397 Latin codes (especially for dealing with Microsoft codes). */
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
398 Lisp_Object Vlatin_extra_code_table;
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
399
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
400 /* Flag to inhibit code conversion of end-of-line format. */
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
401 int inhibit_eol_conversion;
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
402
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
403 /* Flag to inhibit ISO2022 escape sequence detection. */
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
404 int inhibit_iso_escape_detection;
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
405
21574
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
406 /* Flag to make buffer-file-coding-system inherit from process-coding. */
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
407 int inherit_process_coding_system;
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
408
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
409 /* Coding system to be used to encode text for terminal display. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 struct coding_system terminal_coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
411
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
412 /* Coding system to be used to encode text for terminal display when
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
413 terminal coding system is nil. */
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
414 struct coding_system safe_terminal_coding;
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
415
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
416 /* Coding system of what is sent from terminal keyboard. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 struct coding_system keyboard_coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418
22979
ceb8e4a89a32 (default_buffer_file_coding): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22964
diff changeset
419 /* Default coding system to be used to write a file. */
ceb8e4a89a32 (default_buffer_file_coding): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22964
diff changeset
420 struct coding_system default_buffer_file_coding;
ceb8e4a89a32 (default_buffer_file_coding): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22964
diff changeset
421
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
422 Lisp_Object Vfile_coding_system_alist;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
423 Lisp_Object Vprocess_coding_system_alist;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
424 Lisp_Object Vnetwork_coding_system_alist;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
426 Lisp_Object Vlocale_coding_system;
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
427
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 #endif /* emacs */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
430 Lisp_Object Qcoding_category, Qcoding_category_index;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 /* List of symbols `coding-category-xxx' ordered by priority. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433 Lisp_Object Vcoding_category_list;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
435 /* Table of coding categories (Lisp symbols). */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
436 Lisp_Object Vcoding_category_table;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 /* Table of names of symbol for each coding-category. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439 char *coding_category_name[CODING_CATEGORY_IDX_MAX] = {
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
440 "coding-category-emacs-mule",
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 "coding-category-sjis",
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442 "coding-category-iso-7",
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
443 "coding-category-iso-7-tight",
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 "coding-category-iso-8-1",
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445 "coding-category-iso-8-2",
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
446 "coding-category-iso-7-else",
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
447 "coding-category-iso-8-else",
23027
0dc823b2335f (coding_category_name): Fix the order of initial
Kenichi Handa <handa@m17n.org>
parents: 22979
diff changeset
448 "coding-category-ccl",
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449 "coding-category-big5",
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
450 "coding-category-utf-8",
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
451 "coding-category-utf-16-be",
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
452 "coding-category-utf-16-le",
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
453 "coding-category-raw-text",
23027
0dc823b2335f (coding_category_name): Fix the order of initial
Kenichi Handa <handa@m17n.org>
parents: 22979
diff changeset
454 "coding-category-binary"
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 };
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
457 /* Table of pointers to coding systems corresponding to each coding
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
458 categories. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
459 struct coding_system *coding_system_table[CODING_CATEGORY_IDX_MAX];
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
460
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
461 /* Table of coding category masks. Nth element is a mask for a coding
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
462 cateogry of which priority is Nth. */
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
463 static
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
464 int coding_priorities[CODING_CATEGORY_IDX_MAX];
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
465
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
466 /* Flag to tell if we look up translation table on character code
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
467 conversion. */
22119
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
468 Lisp_Object Venable_character_translation;
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
469 /* Standard translation table to look up on decoding (reading). */
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
470 Lisp_Object Vstandard_translation_table_for_decode;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
471 /* Standard translation table to look up on encoding (writing). */
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
472 Lisp_Object Vstandard_translation_table_for_encode;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
473
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
474 Lisp_Object Qtranslation_table;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
475 Lisp_Object Qtranslation_table_id;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
476 Lisp_Object Qtranslation_table_for_decode;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
477 Lisp_Object Qtranslation_table_for_encode;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
479 /* Alist of charsets vs revision number. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 Lisp_Object Vcharset_revision_alist;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
482 /* Default coding systems used for process I/O. */
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
483 Lisp_Object Vdefault_process_coding_system;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
484
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
485 /* Global flag to tell that we can't call post-read-conversion and
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
486 pre-write-conversion functions. Usually the value is zero, but it
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
487 is set to 1 temporarily while such functions are running. This is
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
488 to avoid infinite recursive call. */
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
489 static int inhibit_pre_post_conversion;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
490
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
491 /* Char-table containing safe coding systems of each character. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
492 Lisp_Object Vchar_coding_system_table;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
493 Lisp_Object Qchar_coding_system;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
494
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
495 /* Return `safe-chars' property of coding system CODING. Don't check
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
496 validity of CODING. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
497
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
498 Lisp_Object
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
499 coding_safe_chars (coding)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
500 struct coding_system *coding;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
501 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
502 Lisp_Object coding_spec, plist, safe_chars;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
503
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
504 coding_spec = Fget (coding->symbol, Qcoding_system);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
505 plist = XVECTOR (coding_spec)->contents[3];
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
506 safe_chars = Fplist_get (XVECTOR (coding_spec)->contents[3], Qsafe_chars);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
507 return (CHAR_TABLE_P (safe_chars) ? safe_chars : Qt);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
508 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
509
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
510 #define CODING_SAFE_CHAR_P(safe_chars, c) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
511 (EQ (safe_chars, Qt) || !NILP (CHAR_TABLE_REF (safe_chars, c)))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
512
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
514 /*** 2. Emacs internal format (emacs-mule) handlers ***/
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
515
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
516 /* Emacs' internal format for representation of multiple character
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
517 sets is a kind of multi-byte encoding, i.e. characters are
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
518 represented by variable-length sequences of one-byte codes.
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
519
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
520 ASCII characters and control characters (e.g. `tab', `newline') are
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
521 represented by one-byte sequences which are their ASCII codes, in
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
522 the range 0x00 through 0x7F.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
523
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
524 8-bit characters of the range 0x80..0x9F are represented by
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
525 two-byte sequences of LEADING_CODE_8_BIT_CONTROL and (their 8-bit
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
526 code + 0x20).
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
527
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
528 8-bit characters of the range 0xA0..0xFF are represented by
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
529 one-byte sequences which are their 8-bit code.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
530
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
531 The other characters are represented by a sequence of `base
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
532 leading-code', optional `extended leading-code', and one or two
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
533 `position-code's. The length of the sequence is determined by the
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
534 base leading-code. Leading-code takes the range 0x81 through 0x9D,
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
535 whereas extended leading-code and position-code take the range 0xA0
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
536 through 0xFF. See `charset.h' for more details about leading-code
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
537 and position-code.
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
538
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539 --- CODE RANGE of Emacs' internal format ---
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
540 character set range
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
541 ------------- -----
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
542 ascii 0x00..0x7F
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
543 eight-bit-control LEADING_CODE_8_BIT_CONTROL + 0xA0..0xBF
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
544 eight-bit-graphic 0xA0..0xBF
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
545 ELSE 0x81..0x9D + [0xA0..0xFF]+
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 ---------------------------------------------
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
548 As this is the internal character representation, the format is
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
549 usually not used externally (i.e. in a file or in a data sent to a
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
550 process). But, it is possible to have a text externally in this
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
551 format (i.e. by encoding by the coding system `emacs-mule').
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
552
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
553 In that case, a sequence of one-byte codes has a slightly different
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
554 form.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
555
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
556 At first, all characters in eight-bit-control are represented by
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
557 one-byte sequences which are their 8-bit code.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
558
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
559 Next, character composition data are represented by the byte
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
560 sequence of the form: 0x80 METHOD BYTES CHARS COMPONENT ...,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
561 where,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
562 METHOD is 0xF0 plus one of composition method (enum
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
563 composition_method),
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
564
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
565 BYTES is 0x20 plus a byte length of this composition data,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
566
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
567 CHARS is 0x20 plus a number of characters composed by this
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
568 data,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
569
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
570 COMPONENTs are characters of multibye form or composition
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
571 rules encoded by two-byte of ASCII codes.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
572
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
573 In addition, for backward compatibility, the following formats are
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
574 also recognized as composition data on decoding.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
575
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
576 0x80 MSEQ ...
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
577 0x80 0xFF MSEQ RULE MSEQ RULE ... MSEQ
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
578
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
579 Here,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
580 MSEQ is a multibyte form but in these special format:
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
581 ASCII: 0xA0 ASCII_CODE+0x80,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
582 other: LEADING_CODE+0x20 FOLLOWING-BYTE ...,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
583 RULE is a one byte code of the range 0xA0..0xF0 that
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
584 represents a composition rule.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
585 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
586
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
587 enum emacs_code_class_type emacs_code_class[256];
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
589 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
590 Check if a text is encoded in Emacs' internal format. If it is,
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
591 return CODING_CATEGORY_MASK_EMACS_MULE, else return 0. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
593 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
594 detect_coding_emacs_mule (src, src_end, multibytep)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
595 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
596 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
597 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 unsigned char c;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599 int composing = 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
600 /* Dummy for ONE_MORE_BYTE. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
601 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
602 struct coding_system *coding = &dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
603
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
604 while (1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
606 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 if (composing)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610 if (c < 0xA0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611 composing = 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
612 else if (c == 0xA0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
613 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
614 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
615 c &= 0x7F;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
616 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617 else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618 c -= 0x20;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
619 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
620
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
621 if (c < 0x20)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
622 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
623 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
624 return 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
625 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
626 else if (c >= 0x80 && c < 0xA0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
627 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
628 if (c == 0x80)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
629 /* Old leading code for a composite character. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
630 composing = 1;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
631 else
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
632 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
633 unsigned char *src_base = src - 1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
634 int bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
635
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
636 if (!UNIBYTE_STR_AS_MULTIBYTE_P (src_base, src_end - src_base,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
637 bytes))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
638 return 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
639 src = src_base + bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
640 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
641 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
642 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
643 label_end_of_loop:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
644 return CODING_CATEGORY_MASK_EMACS_MULE;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
645 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
646
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
647
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
648 /* Record the starting position START and METHOD of one composition. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
649
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
650 #define CODING_ADD_COMPOSITION_START(coding, start, method) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
651 do { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
652 struct composition_data *cmp_data = coding->cmp_data; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
653 int *data = cmp_data->data + cmp_data->used; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
654 coding->cmp_data_start = cmp_data->used; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
655 data[0] = -1; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
656 data[1] = cmp_data->char_offset + start; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
657 data[3] = (int) method; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
658 cmp_data->used += 4; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
659 } while (0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
660
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
661 /* Record the ending position END of the current composition. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
662
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
663 #define CODING_ADD_COMPOSITION_END(coding, end) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
664 do { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
665 struct composition_data *cmp_data = coding->cmp_data; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
666 int *data = cmp_data->data + coding->cmp_data_start; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
667 data[0] = cmp_data->used - coding->cmp_data_start; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
668 data[2] = cmp_data->char_offset + end; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
669 } while (0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
670
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
671 /* Record one COMPONENT (alternate character or composition rule). */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
672
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
673 #define CODING_ADD_COMPOSITION_COMPONENT(coding, component) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
674 (coding->cmp_data->data[coding->cmp_data->used++] = component)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
675
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
676
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
677 /* Get one byte from a data pointed by SRC and increment SRC. If SRC
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
678 is not less than SRC_END, return -1 without inccrementing Src. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
679
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
680 #define SAFE_ONE_MORE_BYTE() (src >= src_end ? -1 : *src++)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
681
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
682
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
683 /* Decode a character represented as a component of composition
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
684 sequence of Emacs 20 style at SRC. Set C to that character, store
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
685 its multibyte form sequence at P, and set P to the end of that
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
686 sequence. If no valid character is found, set C to -1. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
687
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
688 #define DECODE_EMACS_MULE_COMPOSITION_CHAR(c, p) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
689 do { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
690 int bytes; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
691 \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
692 c = SAFE_ONE_MORE_BYTE (); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
693 if (c < 0) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
694 break; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
695 if (CHAR_HEAD_P (c)) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
696 c = -1; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
697 else if (c == 0xA0) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
698 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
699 c = SAFE_ONE_MORE_BYTE (); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
700 if (c < 0xA0) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
701 c = -1; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
702 else \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
703 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
704 c -= 0xA0; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
705 *p++ = c; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
706 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
707 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
708 else if (BASE_LEADING_CODE_P (c - 0x20)) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
709 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
710 unsigned char *p0 = p; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
711 \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
712 c -= 0x20; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
713 *p++ = c; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
714 bytes = BYTES_BY_CHAR_HEAD (c); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
715 while (--bytes) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
716 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
717 c = SAFE_ONE_MORE_BYTE (); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
718 if (c < 0) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
719 break; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
720 *p++ = c; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
721 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
722 if (UNIBYTE_STR_AS_MULTIBYTE_P (p0, p - p0, bytes)) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
723 c = STRING_CHAR (p0, bytes); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
724 else \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
725 c = -1; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
726 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
727 else \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
728 c = -1; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
729 } while (0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
730
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
731
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
732 /* Decode a composition rule represented as a component of composition
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
733 sequence of Emacs 20 style at SRC. Set C to the rule. If not
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
734 valid rule is found, set C to -1. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
735
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
736 #define DECODE_EMACS_MULE_COMPOSITION_RULE(c) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
737 do { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
738 c = SAFE_ONE_MORE_BYTE (); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
739 c -= 0xA0; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
740 if (c < 0 || c >= 81) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
741 c = -1; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
742 else \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
743 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
744 gref = c / 9, nref = c % 9; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
745 c = COMPOSITION_ENCODE_RULE (gref, nref); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
746 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
747 } while (0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
748
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
749
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
750 /* Decode composition sequence encoded by `emacs-mule' at the source
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
751 pointed by SRC. SRC_END is the end of source. Store information
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
752 of the composition in CODING->cmp_data.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
753
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
754 For backward compatibility, decode also a composition sequence of
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
755 Emacs 20 style. In that case, the composition sequence contains
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
756 characters that should be extracted into a buffer or string. Store
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
757 those characters at *DESTINATION in multibyte form.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
758
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
759 If we encounter an invalid byte sequence, return 0.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
760 If we encounter an insufficient source or destination, or
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
761 insufficient space in CODING->cmp_data, return 1.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
762 Otherwise, return consumed bytes in the source.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
763
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
764 */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
765 static INLINE int
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
766 decode_composition_emacs_mule (coding, src, src_end,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
767 destination, dst_end, dst_bytes)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
768 struct coding_system *coding;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
769 unsigned char *src, *src_end, **destination, *dst_end;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
770 int dst_bytes;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
771 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
772 unsigned char *dst = *destination;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
773 int method, data_len, nchars;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
774 unsigned char *src_base = src++;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
775 /* Store compoments of composition. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
776 int component[COMPOSITION_DATA_MAX_BUNCH_LENGTH];
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
777 int ncomponent;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
778 /* Store multibyte form of characters to be composed. This is for
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
779 Emacs 20 style composition sequence. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
780 unsigned char buf[MAX_COMPOSITION_COMPONENTS * MAX_MULTIBYTE_LENGTH];
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
781 unsigned char *bufp = buf;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
782 int c, i, gref, nref;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
783
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
784 if (coding->cmp_data->used + COMPOSITION_DATA_MAX_BUNCH_LENGTH
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
785 >= COMPOSITION_DATA_SIZE)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
786 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
787 coding->result = CODING_FINISH_INSUFFICIENT_CMP;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
788 return -1;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
789 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
790
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
791 ONE_MORE_BYTE (c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
792 if (c - 0xF0 >= COMPOSITION_RELATIVE
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
793 && c - 0xF0 <= COMPOSITION_WITH_RULE_ALTCHARS)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
794 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
795 int with_rule;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
796
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
797 method = c - 0xF0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
798 with_rule = (method == COMPOSITION_WITH_RULE
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
799 || method == COMPOSITION_WITH_RULE_ALTCHARS);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
800 ONE_MORE_BYTE (c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
801 data_len = c - 0xA0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
802 if (data_len < 4
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
803 || src_base + data_len > src_end)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
804 return 0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
805 ONE_MORE_BYTE (c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
806 nchars = c - 0xA0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
807 if (c < 1)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
808 return 0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
809 for (ncomponent = 0; src < src_base + data_len; ncomponent++)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
810 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
811 if (ncomponent % 2 && with_rule)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
812 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
813 ONE_MORE_BYTE (gref);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
814 gref -= 32;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
815 ONE_MORE_BYTE (nref);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
816 nref -= 32;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
817 c = COMPOSITION_ENCODE_RULE (gref, nref);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
818 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
819 else
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
820 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
821 int bytes;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
822 if (UNIBYTE_STR_AS_MULTIBYTE_P (src, src_end - src, bytes))
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
823 c = STRING_CHAR (src, bytes);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
824 else
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
825 c = *src, bytes = 1;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
826 src += bytes;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
827 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
828 component[ncomponent] = c;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
829 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
830 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
831 else
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
832 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
833 /* This may be an old Emacs 20 style format. See the comment at
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
834 the section 2 of this file. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
835 while (src < src_end && !CHAR_HEAD_P (*src)) src++;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
836 if (src == src_end
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
837 && !(coding->mode & CODING_MODE_LAST_BLOCK))
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
838 goto label_end_of_loop;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
839
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
840 src_end = src;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
841 src = src_base + 1;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
842 if (c < 0xC0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
843 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
844 method = COMPOSITION_RELATIVE;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
845 for (ncomponent = 0; ncomponent < MAX_COMPOSITION_COMPONENTS;)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
846 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
847 DECODE_EMACS_MULE_COMPOSITION_CHAR (c, bufp);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
848 if (c < 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
849 break;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
850 component[ncomponent++] = c;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
851 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
852 if (ncomponent < 2)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
853 return 0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
854 nchars = ncomponent;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
855 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
856 else if (c == 0xFF)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
857 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
858 method = COMPOSITION_WITH_RULE;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
859 src++;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
860 DECODE_EMACS_MULE_COMPOSITION_CHAR (c, bufp);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
861 if (c < 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
862 return 0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
863 component[0] = c;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
864 for (ncomponent = 1;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
865 ncomponent < MAX_COMPOSITION_COMPONENTS * 2 - 1;)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
866 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
867 DECODE_EMACS_MULE_COMPOSITION_RULE (c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
868 if (c < 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
869 break;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
870 component[ncomponent++] = c;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
871 DECODE_EMACS_MULE_COMPOSITION_CHAR (c, bufp);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
872 if (c < 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
873 break;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
874 component[ncomponent++] = c;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
875 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
876 if (ncomponent < 3)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
877 return 0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
878 nchars = (ncomponent + 1) / 2;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
879 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
880 else
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
881 return 0;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
882 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
883
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
884 if (buf == bufp || dst + (bufp - buf) <= (dst_bytes ? dst_end : src))
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
885 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
886 CODING_ADD_COMPOSITION_START (coding, coding->produced_char, method);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
887 for (i = 0; i < ncomponent; i++)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
888 CODING_ADD_COMPOSITION_COMPONENT (coding, component[i]);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
889 CODING_ADD_COMPOSITION_END (coding, coding->produced_char + nchars);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
890 if (buf < bufp)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
891 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
892 unsigned char *p = buf;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
893 EMIT_BYTES (p, bufp);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
894 *destination += bufp - buf;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
895 coding->produced_char += nchars;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
896 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
897 return (src - src_base);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
898 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
899 label_end_of_loop:
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
900 return -1;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
901 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
902
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
903 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
904
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
905 static void
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
906 decode_coding_emacs_mule (coding, source, destination, src_bytes, dst_bytes)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
907 struct coding_system *coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
908 unsigned char *source, *destination;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
909 int src_bytes, dst_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
910 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
911 unsigned char *src = source;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
912 unsigned char *src_end = source + src_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
913 unsigned char *dst = destination;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
914 unsigned char *dst_end = destination + dst_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
915 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
916 The loop will be exited when there's not enough source code, or
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
917 when there's not enough destination area to produce a
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
918 character. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
919 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
920
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
921 coding->produced_char = 0;
29663
ebf778ab6b42 (decode_coding_emacs_mule): Always set src_base at the
Kenichi Handa <handa@m17n.org>
parents: 29299
diff changeset
922 while ((src_base = src) < src_end)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
923 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
924 unsigned char tmp[MAX_MULTIBYTE_LENGTH], *p;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
925 int bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
926
32806
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
927 if (*src == '\r')
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
928 {
33828
ef38af5ee8d2 (decode_coding_emacs_mule): Fix the case of
Eli Zaretskii <eliz@gnu.org>
parents: 32896
diff changeset
929 int c = *src++;
ef38af5ee8d2 (decode_coding_emacs_mule): Fix the case of
Eli Zaretskii <eliz@gnu.org>
parents: 32896
diff changeset
930
32806
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
931 if (coding->eol_type == CODING_EOL_CR)
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
932 c = '\n';
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
933 else if (coding->eol_type == CODING_EOL_CRLF)
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
934 {
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
935 ONE_MORE_BYTE (c);
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
936 if (c != '\n')
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
937 {
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
938 if (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
939 {
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
940 coding->result = CODING_FINISH_INCONSISTENT_EOL;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
941 goto label_end_of_loop;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
942 }
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
943 src--;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
944 c = '\r';
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
945 }
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
946 }
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
947 *dst++ = c;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
948 coding->produced_char++;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
949 continue;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
950 }
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
951 else if (*src == '\n')
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
952 {
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
953 if ((coding->eol_type == CODING_EOL_CR
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
954 || coding->eol_type == CODING_EOL_CRLF)
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
955 && coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
956 {
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
957 coding->result = CODING_FINISH_INCONSISTENT_EOL;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
958 goto label_end_of_loop;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
959 }
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
960 *dst++ = *src++;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
961 coding->produced_char++;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
962 continue;
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
963 }
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
964 else if (*src == 0x80)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
965 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
966 /* Start of composition data. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
967 int consumed = decode_composition_emacs_mule (coding, src, src_end,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
968 &dst, dst_end,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
969 dst_bytes);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
970 if (consumed < 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
971 goto label_end_of_loop;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
972 else if (consumed > 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
973 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
974 src += consumed;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
975 continue;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
976 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
977 bytes = CHAR_STRING (*src, tmp);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
978 p = tmp;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
979 src++;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
980 }
32806
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
981 else if (UNIBYTE_STR_AS_MULTIBYTE_P (src, src_end - src, bytes))
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
982 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
983 p = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
984 src += bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
985 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
986 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
987 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
988 bytes = CHAR_STRING (*src, tmp);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
989 p = tmp;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
990 src++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
991 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
992 if (dst + bytes >= (dst_bytes ? dst_end : src))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
993 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
994 coding->result = CODING_FINISH_INSUFFICIENT_DST;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
995 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
996 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
997 while (bytes--) *dst++ = *p++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
998 coding->produced_char++;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
999 }
32806
9502d0a5b2ad (decode_coding_emacs_mule): If coding->eol_type is CR
Eli Zaretskii <eliz@gnu.org>
parents: 32745
diff changeset
1000 label_end_of_loop:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1001 coding->consumed = coding->consumed_char = src_base - source;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1002 coding->produced = dst - destination;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1003 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1004
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1005
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1006 /* Encode composition data stored at DATA into a special byte sequence
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1007 starting by 0x80. Update CODING->cmp_data_start and maybe
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1008 CODING->cmp_data for the next call. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1009
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1010 #define ENCODE_COMPOSITION_EMACS_MULE(coding, data) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1011 do { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1012 unsigned char buf[1024], *p0 = buf, *p; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1013 int len = data[0]; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1014 int i; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1015 \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1016 buf[0] = 0x80; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1017 buf[1] = 0xF0 + data[3]; /* METHOD */ \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1018 buf[3] = 0xA0 + (data[2] - data[1]); /* COMPOSED-CHARS */ \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1019 p = buf + 4; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1020 if (data[3] == COMPOSITION_WITH_RULE \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1021 || data[3] == COMPOSITION_WITH_RULE_ALTCHARS) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1022 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1023 p += CHAR_STRING (data[4], p); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1024 for (i = 5; i < len; i += 2) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1025 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1026 int gref, nref; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1027 COMPOSITION_DECODE_RULE (data[i], gref, nref); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1028 *p++ = 0x20 + gref; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1029 *p++ = 0x20 + nref; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1030 p += CHAR_STRING (data[i + 1], p); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1031 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1032 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1033 else \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1034 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1035 for (i = 4; i < len; i++) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1036 p += CHAR_STRING (data[i], p); \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1037 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1038 buf[2] = 0xA0 + (p - buf); /* COMPONENTS-BYTES */ \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1039 \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1040 if (dst + (p - buf) + 4 > (dst_bytes ? dst_end : src)) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1041 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1042 coding->result = CODING_FINISH_INSUFFICIENT_DST; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1043 goto label_end_of_loop; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1044 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1045 while (p0 < p) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1046 *dst++ = *p0++; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1047 coding->cmp_data_start += data[0]; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1048 if (coding->cmp_data_start == coding->cmp_data->used \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1049 && coding->cmp_data->next) \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1050 { \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1051 coding->cmp_data = coding->cmp_data->next; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1052 coding->cmp_data_start = 0; \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1053 } \
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1054 } while (0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1055
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1056
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1057 static void encode_eol P_ ((struct coding_system *, unsigned char *,
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1058 unsigned char *, int, int));
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1059
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1060 static void
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1061 encode_coding_emacs_mule (coding, source, destination, src_bytes, dst_bytes)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1062 struct coding_system *coding;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1063 unsigned char *source, *destination;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1064 int src_bytes, dst_bytes;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1065 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1066 unsigned char *src = source;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1067 unsigned char *src_end = source + src_bytes;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1068 unsigned char *dst = destination;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1069 unsigned char *dst_end = destination + dst_bytes;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1070 unsigned char *src_base;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1071 int c;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1072 int char_offset;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1073 int *data;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1074
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1075 Lisp_Object translation_table;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1076
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1077 translation_table = Qnil;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1078
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1079 /* Optimization for the case that there's no composition. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1080 if (!coding->cmp_data || coding->cmp_data->used == 0)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1081 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1082 encode_eol (coding, source, destination, src_bytes, dst_bytes);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1083 return;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1084 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1085
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1086 char_offset = coding->cmp_data->char_offset;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1087 data = coding->cmp_data->data + coding->cmp_data_start;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1088 while (1)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1089 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1090 src_base = src;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1091
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1092 /* If SRC starts a composition, encode the information about the
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1093 composition in advance. */
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1094 if (coding->cmp_data_start < coding->cmp_data->used
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1095 && char_offset + coding->consumed_char == data[1])
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1096 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1097 ENCODE_COMPOSITION_EMACS_MULE (coding, data);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1098 char_offset = coding->cmp_data->char_offset;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1099 data = coding->cmp_data->data + coding->cmp_data_start;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1100 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1101
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1102 ONE_MORE_CHAR (c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1103 if (c == '\n' && (coding->eol_type == CODING_EOL_CRLF
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1104 || coding->eol_type == CODING_EOL_CR))
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1105 {
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1106 if (coding->eol_type == CODING_EOL_CRLF)
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1107 EMIT_TWO_BYTES ('\r', c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1108 else
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1109 EMIT_ONE_BYTE ('\r');
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1110 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1111 else if (SINGLE_BYTE_CHAR_P (c))
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1112 EMIT_ONE_BYTE (c);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1113 else
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1114 EMIT_BYTES (src_base, src);
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1115 coding->consumed_char++;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1116 }
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1117 label_end_of_loop:
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1118 coding->consumed = src_base - source;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1119 coding->produced = coding->produced_char = dst - destination;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1120 return;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1121 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1122
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1123
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1124 /*** 3. ISO2022 handlers ***/
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1125
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1126 /* The following note describes the coding system ISO2022 briefly.
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1127 Since the intention of this note is to help understand the
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1128 functions in this file, some parts are NOT ACCURATE or OVERLY
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1129 SIMPLIFIED. For thorough understanding, please refer to the
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1130 original document of ISO2022.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1131
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1132 ISO2022 provides many mechanisms to encode several character sets
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1133 in 7-bit and 8-bit environments. For 7-bite environments, all text
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1134 is encoded using bytes less than 128. This may make the encoded
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1135 text a little bit longer, but the text passes more easily through
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1136 several gateways, some of which strip off MSB (Most Signigant Bit).
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1137
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1138 There are two kinds of character sets: control character set and
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1139 graphic character set. The former contains control characters such
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1140 as `newline' and `escape' to provide control functions (control
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1141 functions are also provided by escape sequences). The latter
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1142 contains graphic characters such as 'A' and '-'. Emacs recognizes
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1143 two control character sets and many graphic character sets.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1144
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1145 Graphic character sets are classified into one of the following
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1146 four classes, according to the number of bytes (DIMENSION) and
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1147 number of characters in one dimension (CHARS) of the set:
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1148 - DIMENSION1_CHARS94
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1149 - DIMENSION1_CHARS96
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1150 - DIMENSION2_CHARS94
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1151 - DIMENSION2_CHARS96
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1152
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1153 In addition, each character set is assigned an identification tag,
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1154 unique for each set, called "final character" (denoted as <F>
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1155 hereafter). The <F> of each character set is decided by ECMA(*)
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1156 when it is registered in ISO. The code range of <F> is 0x30..0x7F
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1157 (0x30..0x3F are for private use only).
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1158
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1159 Note (*): ECMA = European Computer Manufacturers Association
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1160
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1161 Here are examples of graphic character set [NAME(<F>)]:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1162 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1163 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1164 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1165 o DIMENSION2_CHARS96 -- none for the moment
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1166
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1167 A code area (1 byte=8 bits) is divided into 4 areas, C0, GL, C1, and GR.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1168 C0 [0x00..0x1F] -- control character plane 0
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1169 GL [0x20..0x7F] -- graphic character plane 0
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1170 C1 [0x80..0x9F] -- control character plane 1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1171 GR [0xA0..0xFF] -- graphic character plane 1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1172
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1173 A control character set is directly designated and invoked to C0 or
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1174 C1 by an escape sequence. The most common case is that:
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1175 - ISO646's control character set is designated/invoked to C0, and
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1176 - ISO6429's control character set is designated/invoked to C1,
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1177 and usually these designations/invocations are omitted in encoded
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1178 text. In a 7-bit environment, only C0 can be used, and a control
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1179 character for C1 is encoded by an appropriate escape sequence to
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1180 fit into the environment. All control characters for C1 are
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1181 defined to have corresponding escape sequences.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1182
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1183 A graphic character set is at first designated to one of four
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1184 graphic registers (G0 through G3), then these graphic registers are
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1185 invoked to GL or GR. These designations and invocations can be
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1186 done independently. The most common case is that G0 is invoked to
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1187 GL, G1 is invoked to GR, and ASCII is designated to G0. Usually
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1188 these invocations and designations are omitted in encoded text.
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1189 In a 7-bit environment, only GL can be used.
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1190
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1191 When a graphic character set of CHARS94 is invoked to GL, codes
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1192 0x20 and 0x7F of the GL area work as control characters SPACE and
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1193 DEL respectively, and codes 0xA0 and 0xFF of the GR area should not
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1194 be used.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1195
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1196 There are two ways of invocation: locking-shift and single-shift.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1197 With locking-shift, the invocation lasts until the next different
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1198 invocation, whereas with single-shift, the invocation affects the
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1199 following character only and doesn't affect the locking-shift
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1200 state. Invocations are done by the following control characters or
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1201 escape sequences:
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1202
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1203 ----------------------------------------------------------------------
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1204 abbrev function cntrl escape seq description
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1205 ----------------------------------------------------------------------
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1206 SI/LS0 (shift-in) 0x0F none invoke G0 into GL
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1207 SO/LS1 (shift-out) 0x0E none invoke G1 into GL
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1208 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1209 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1210 LS1R (locking-shift-1 right) none ESC '~' invoke G1 into GR (*)
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1211 LS2R (locking-shift-2 right) none ESC '}' invoke G2 into GR (*)
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1212 LS3R (locking-shift 3 right) none ESC '|' invoke G3 into GR (*)
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1213 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 for one char
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1214 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1215 ----------------------------------------------------------------------
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1216 (*) These are not used by any known coding system.
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1217
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1218 Control characters for these functions are defined by macros
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1219 ISO_CODE_XXX in `coding.h'.
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1220
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1221 Designations are done by the following escape sequences:
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1222 ----------------------------------------------------------------------
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1223 escape sequence description
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1224 ----------------------------------------------------------------------
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1225 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1226 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1227 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1228 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1229 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1230 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1231 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1232 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1233 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1234 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1235 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1236 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1237 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1238 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1239 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1240 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1241 ----------------------------------------------------------------------
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1242
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1243 In this list, "DIMENSION1_CHARS94<F>" means a graphic character set
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1244 of dimension 1, chars 94, and final character <F>, etc...
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1245
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1246 Note (*): Although these designations are not allowed in ISO2022,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1247 Emacs accepts them on decoding, and produces them on encoding
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1248 CHARS96 character sets in a coding system which is characterized as
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1249 7-bit environment, non-locking-shift, and non-single-shift.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1250
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1251 Note (**): If <F> is '@', 'A', or 'B', the intermediate character
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1252 '(' can be omitted. We refer to this as "short-form" hereafter.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1253
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1254 Now you may notice that there are a lot of ways for encoding the
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1255 same multilingual text in ISO2022. Actually, there exist many
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1256 coding systems such as Compound Text (used in X11's inter client
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1257 communication, ISO-2022-JP (used in Japanese internet), ISO-2022-KR
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1258 (used in Korean internet), EUC (Extended UNIX Code, used in Asian
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1259 localized platforms), and all of these are variants of ISO2022.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1260
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1261 In addition to the above, Emacs handles two more kinds of escape
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1262 sequences: ISO6429's direction specification and Emacs' private
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1263 sequence for specifying character composition.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1264
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1265 ISO6429's direction specification takes the following form:
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1266 o CSI ']' -- end of the current direction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1267 o CSI '0' ']' -- end of the current direction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1268 o CSI '1' ']' -- start of left-to-right text
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1269 o CSI '2' ']' -- start of right-to-left text
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1270 The control character CSI (0x9B: control sequence introducer) is
24425
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1271 abbreviated to the escape sequence ESC '[' in a 7-bit environment.
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1272
61c6b3be1d51 Comment for ISO 2022 encoding mechanism modified.
Kenichi Handa <handa@m17n.org>
parents: 24344
diff changeset
1273 Character composition specification takes the following form:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1274 o ESC '0' -- start relative composition
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1275 o ESC '1' -- end composition
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1276 o ESC '2' -- start rule-base composition (*)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1277 o ESC '3' -- start relative composition with alternate chars (**)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1278 o ESC '4' -- start rule-base composition with alternate chars (**)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1279 Since these are not standard escape sequences of any ISO standard,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1280 the use of them for these meaning is restricted to Emacs only.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1281
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1282 (*) This form is used only in Emacs 20.5 and the older versions,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1283 but the newer versions can safely decode it.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1284 (**) This form is used only in Emacs 21.1 and the newer versions,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1285 and the older versions can't decode it.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1286
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1287 Here's a list of examples usages of these composition escape
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1288 sequences (categorized by `enum composition_method').
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1289
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1290 COMPOSITION_RELATIVE:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1291 ESC 0 CHAR [ CHAR ] ESC 1
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1292 COMPOSITOIN_WITH_RULE:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1293 ESC 2 CHAR [ RULE CHAR ] ESC 1
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1294 COMPOSITION_WITH_ALTCHARS:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1295 ESC 3 ALTCHAR [ ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1296 COMPOSITION_WITH_RULE_ALTCHARS:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1297 ESC 4 ALTCHAR [ RULE ALTCHAR ] ESC 0 CHAR [ CHAR ] ESC 1 */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1298
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1299 enum iso_code_class_type iso_code_class[256];
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1300
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1301 #define CHARSET_OK(idx, charset, c) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1302 (coding_system_table[idx] \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1303 && (charset == CHARSET_ASCII \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1304 || (safe_chars = coding_safe_chars (coding_system_table[idx]), \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1305 CODING_SAFE_CHAR_P (safe_chars, c))) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1306 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding_system_table[idx], \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1307 charset) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1308 != CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1309
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1310 #define SHIFT_OUT_OK(idx) \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1311 (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding_system_table[idx], 1) >= 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1312
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1313 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1314 Check if a text is encoded in ISO2022. If it is, returns an
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1315 integer in which appropriate flag bits any of:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1316 CODING_CATEGORY_MASK_ISO_7
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1317 CODING_CATEGORY_MASK_ISO_7_TIGHT
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1318 CODING_CATEGORY_MASK_ISO_8_1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1319 CODING_CATEGORY_MASK_ISO_8_2
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
1320 CODING_CATEGORY_MASK_ISO_7_ELSE
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
1321 CODING_CATEGORY_MASK_ISO_8_ELSE
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1322 are set. If a code which should never appear in ISO2022 is found,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1323 returns 0. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1324
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1325 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1326 detect_coding_iso2022 (src, src_end, multibytep)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1327 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1328 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1329 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1330 int mask = CODING_CATEGORY_MASK_ISO;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1331 int mask_found = 0;
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1332 int reg[4], shift_out = 0, single_shifting = 0;
34988
8cd5e6ad71a2 (detect_coding_iso2022, setup_coding_system): Remove
Eli Zaretskii <eliz@gnu.org>
parents: 34892
diff changeset
1333 int c, c1, charset;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1334 /* Dummy for ONE_MORE_BYTE. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1335 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1336 struct coding_system *coding = &dummy_coding;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1337 Lisp_Object safe_chars;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1338
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1339 reg[0] = CHARSET_ASCII, reg[1] = reg[2] = reg[3] = -1;
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1340 while (mask && src < src_end)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1341 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1342 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1343 switch (c)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1344 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1345 case ISO_CODE_ESC:
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1346 if (inhibit_iso_escape_detection)
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1347 break;
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1348 single_shifting = 0;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1349 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1350 if (c >= '(' && c <= '/')
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1351 {
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1352 /* Designation sequence for a charset of dimension 1. */
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1353 ONE_MORE_BYTE_CHECK_MULTIBYTE (c1, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1354 if (c1 < ' ' || c1 >= 0x80
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1355 || (charset = iso_charset_table[0][c >= ','][c1]) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1356 /* Invalid designation sequence. Just ignore. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1357 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1358 reg[(c - '(') % 4] = charset;
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1359 }
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1360 else if (c == '$')
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1361 {
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1362 /* Designation sequence for a charset of dimension 2. */
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1363 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1364 if (c >= '@' && c <= 'B')
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1365 /* Designation for JISX0208.1978, GB2312, or JISX0208. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1366 reg[0] = charset = iso_charset_table[1][0][c];
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1367 else if (c >= '(' && c <= '/')
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
1368 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1369 ONE_MORE_BYTE_CHECK_MULTIBYTE (c1, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1370 if (c1 < ' ' || c1 >= 0x80
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1371 || (charset = iso_charset_table[1][c >= ','][c1]) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1372 /* Invalid designation sequence. Just ignore. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1373 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1374 reg[(c - '(') % 4] = charset;
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
1375 }
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1376 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1377 /* Invalid designation sequence. Just ignore. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1378 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1379 }
23116
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1380 else if (c == 'N' || c == 'O')
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1381 {
23116
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1382 /* ESC <Fe> for SS2 or SS3. */
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1383 mask &= CODING_CATEGORY_MASK_ISO_7_ELSE;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1384 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1385 }
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1386 else if (c >= '0' && c <= '4')
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1387 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1388 /* ESC <Fp> for start/end composition. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1389 mask_found |= CODING_CATEGORY_MASK_ISO;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1390 break;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1391 }
19134
8fa6e23f8d22 (detect_coding_iso2022): Do not exclude posibility of
Kenichi Handa <handa@m17n.org>
parents: 19118
diff changeset
1392 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1393 /* Invalid escape sequence. Just ignore. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1394 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1395
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1396 /* We found a valid designation sequence for CHARSET. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1397 mask &= ~CODING_CATEGORY_MASK_ISO_8BIT;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1398 c = MAKE_CHAR (charset, 0, 0);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1399 if (CHARSET_OK (CODING_CATEGORY_IDX_ISO_7, charset, c))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1400 mask_found |= CODING_CATEGORY_MASK_ISO_7;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1401 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1402 mask &= ~CODING_CATEGORY_MASK_ISO_7;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1403 if (CHARSET_OK (CODING_CATEGORY_IDX_ISO_7_TIGHT, charset, c))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1404 mask_found |= CODING_CATEGORY_MASK_ISO_7_TIGHT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1405 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1406 mask &= ~CODING_CATEGORY_MASK_ISO_7_TIGHT;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1407 if (CHARSET_OK (CODING_CATEGORY_IDX_ISO_7_ELSE, charset, c))
23116
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1408 mask_found |= CODING_CATEGORY_MASK_ISO_7_ELSE;
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1409 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1410 mask &= ~CODING_CATEGORY_MASK_ISO_7_ELSE;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1411 if (CHARSET_OK (CODING_CATEGORY_IDX_ISO_8_ELSE, charset, c))
23116
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1412 mask_found |= CODING_CATEGORY_MASK_ISO_8_ELSE;
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
1413 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1414 mask &= ~CODING_CATEGORY_MASK_ISO_8_ELSE;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1415 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1416
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1417 case ISO_CODE_SO:
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1418 if (inhibit_iso_escape_detection)
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1419 break;
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1420 single_shifting = 0;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1421 if (shift_out == 0
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1422 && (reg[1] >= 0
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1423 || SHIFT_OUT_OK (CODING_CATEGORY_IDX_ISO_7_ELSE)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1424 || SHIFT_OUT_OK (CODING_CATEGORY_IDX_ISO_8_ELSE)))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1425 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1426 /* Locking shift out. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1427 mask &= ~CODING_CATEGORY_MASK_ISO_7BIT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1428 mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1429 }
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1430 break;
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1431
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1432 case ISO_CODE_SI:
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1433 if (inhibit_iso_escape_detection)
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1434 break;
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1435 single_shifting = 0;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1436 if (shift_out == 1)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1437 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1438 /* Locking shift in. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1439 mask &= ~CODING_CATEGORY_MASK_ISO_7BIT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1440 mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1441 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1442 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1443
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1444 case ISO_CODE_CSI:
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1445 single_shifting = 0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1446 case ISO_CODE_SS2:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1447 case ISO_CODE_SS3:
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1448 {
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1449 int newmask = CODING_CATEGORY_MASK_ISO_8_ELSE;
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1450
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1451 if (inhibit_iso_escape_detection)
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
1452 break;
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
1453 if (c != ISO_CODE_CSI)
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
1454 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1455 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_1]->flags
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1456 & CODING_FLAG_ISO_SINGLE_SHIFT)
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
1457 newmask |= CODING_CATEGORY_MASK_ISO_8_1;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1458 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_2]->flags
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1459 & CODING_FLAG_ISO_SINGLE_SHIFT)
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
1460 newmask |= CODING_CATEGORY_MASK_ISO_8_2;
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1461 single_shifting = 1;
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
1462 }
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1463 if (VECTORP (Vlatin_extra_code_table)
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1464 && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1465 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1466 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_1]->flags
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1467 & CODING_FLAG_ISO_LATIN_EXTRA)
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1468 newmask |= CODING_CATEGORY_MASK_ISO_8_1;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1469 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_2]->flags
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1470 & CODING_FLAG_ISO_LATIN_EXTRA)
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1471 newmask |= CODING_CATEGORY_MASK_ISO_8_2;
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1472 }
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1473 mask &= newmask;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1474 mask_found |= newmask;
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1475 }
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1476 break;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1477
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1478 default:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1479 if (c < 0x80)
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1480 {
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1481 single_shifting = 0;
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1482 break;
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1483 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1484 else if (c < 0xA0)
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
1485 {
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1486 single_shifting = 0;
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1487 if (VECTORP (Vlatin_extra_code_table)
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1488 && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
1489 {
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1490 int newmask = 0;
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1491
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1492 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_1]->flags
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1493 & CODING_FLAG_ISO_LATIN_EXTRA)
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1494 newmask |= CODING_CATEGORY_MASK_ISO_8_1;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1495 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_2]->flags
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1496 & CODING_FLAG_ISO_LATIN_EXTRA)
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1497 newmask |= CODING_CATEGORY_MASK_ISO_8_2;
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1498 mask &= newmask;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1499 mask_found |= newmask;
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
1500 }
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1501 else
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
1502 return 0;
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
1503 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1504 else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1505 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1506 mask &= ~(CODING_CATEGORY_MASK_ISO_7BIT
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
1507 | CODING_CATEGORY_MASK_ISO_7_ELSE);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1508 mask_found |= CODING_CATEGORY_MASK_ISO_8_1;
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1509 /* Check the length of succeeding codes of the range
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1510 0xA0..0FF. If the byte length is odd, we exclude
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1511 CODING_CATEGORY_MASK_ISO_8_2. We can check this only
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1512 when we are not single shifting. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1513 if (!single_shifting
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1514 && mask & CODING_CATEGORY_MASK_ISO_8_2)
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1515 {
29299
b33b38d81020 (detect_coding_iso2022): Fix code for checking
Kenichi Handa <handa@m17n.org>
parents: 29275
diff changeset
1516 int i = 1;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1517 while (src < src_end)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1518 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
1519 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1520 if (c < 0xA0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1521 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1522 i++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1523 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1524
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1525 if (i & 1 && src < src_end)
23088
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1526 mask &= ~CODING_CATEGORY_MASK_ISO_8_2;
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1527 else
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1528 mask_found |= CODING_CATEGORY_MASK_ISO_8_2;
45c36d636f66 (detect_coding_iso2022): Don't check the byte length of
Kenichi Handa <handa@m17n.org>
parents: 23082
diff changeset
1529 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1530 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1531 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1532 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1533 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1534 label_end_of_loop:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1535 return (mask & mask_found);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1536 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1537
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1538 /* Decode a character of which charset is CHARSET, the 1st position
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1539 code is C1, the 2nd position code is C2, and return the decoded
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1540 character code. If the variable `translation_table' is non-nil,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1541 returned the translated code. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1542
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1543 #define DECODE_ISO_CHARACTER(charset, c1, c2) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1544 (NILP (translation_table) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1545 ? MAKE_CHAR (charset, c1, c2) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1546 : translate_char (translation_table, -1, charset, c1, c2))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1547
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1548 /* Set designation state into CODING. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1549 #define DECODE_DESIGNATION(reg, dimension, chars, final_char) \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1550 do { \
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1551 int charset, c; \
23881
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
1552 \
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
1553 if (final_char < '0' || final_char >= 128) \
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
1554 goto label_invalid_code; \
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
1555 charset = ISO_CHARSET_TABLE (make_number (dimension), \
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
1556 make_number (chars), \
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
1557 make_number (final_char)); \
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1558 c = MAKE_CHAR (charset, 0, 0); \
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1559 if (charset >= 0 \
21331
4c89837392b3 (CHARSET_OK): Don't reject safe charsets.
Kenichi Handa <handa@m17n.org>
parents: 21321
diff changeset
1560 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) == reg \
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1561 || CODING_SAFE_CHAR_P (safe_chars, c))) \
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1562 { \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1563 if (coding->spec.iso2022.last_invalid_designation_register == 0 \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1564 && reg == 0 \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1565 && charset == CHARSET_ASCII) \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1566 { \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1567 /* We should insert this designation sequence as is so \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1568 that it is surely written back to a file. */ \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1569 coding->spec.iso2022.last_invalid_designation_register = -1; \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1570 goto label_invalid_code; \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1571 } \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1572 coding->spec.iso2022.last_invalid_designation_register = -1; \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1573 if ((coding->mode & CODING_MODE_DIRECTION) \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1574 && CHARSET_REVERSE_CHARSET (charset) >= 0) \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1575 charset = CHARSET_REVERSE_CHARSET (charset); \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1576 CODING_SPEC_ISO_DESIGNATION (coding, reg) = charset; \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1577 } \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1578 else \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1579 { \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1580 coding->spec.iso2022.last_invalid_designation_register = reg; \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1581 goto label_invalid_code; \
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1582 } \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1583 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1584
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1585 /* Allocate a memory block for storing information about compositions.
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1586 The block is chained to the already allocated blocks. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1587
29275
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1588 void
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1589 coding_allocate_composition_data (coding, char_offset)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1590 struct coding_system *coding;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1591 int char_offset;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1592 {
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1593 struct composition_data *cmp_data
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1594 = (struct composition_data *) xmalloc (sizeof *cmp_data);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1595
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1596 cmp_data->char_offset = char_offset;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1597 cmp_data->used = 0;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1598 cmp_data->prev = coding->cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1599 cmp_data->next = NULL;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1600 if (coding->cmp_data)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1601 coding->cmp_data->next = cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1602 coding->cmp_data = cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1603 coding->cmp_data_start = 0;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1604 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1605
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1606 /* Handle composition start sequence ESC 0, ESC 2, ESC 3, or ESC 4.
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1607 ESC 0 : relative composition : ESC 0 CHAR ... ESC 1
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1608 ESC 2 : rulebase composition : ESC 2 CHAR RULE CHAR RULE ... CHAR ESC 1
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1609 ESC 3 : altchar composition : ESC 3 ALT ... ESC 0 CHAR ... ESC 1
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1610 ESC 4 : alt&rule composition : ESC 4 ALT RULE .. ALT ESC 0 CHAR ... ESC 1
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
1611 */
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1612
29275
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1613 #define DECODE_COMPOSITION_START(c1) \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1614 do { \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1615 if (coding->composing == COMPOSITION_DISABLED) \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1616 { \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1617 *dst++ = ISO_CODE_ESC; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1618 *dst++ = c1 & 0x7f; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1619 coding->produced_char += 2; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1620 } \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1621 else if (!COMPOSING_P (coding)) \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1622 { \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1623 /* This is surely the start of a composition. We must be sure \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1624 that coding->cmp_data has enough space to store the \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1625 information about the composition. If not, terminate the \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1626 current decoding loop, allocate one more memory block for \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1627 coding->cmp_data in the calller, then start the decoding \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1628 loop again. We can't allocate memory here directly because \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1629 it may cause buffer/string relocation. */ \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1630 if (!coding->cmp_data \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1631 || (coding->cmp_data->used + COMPOSITION_DATA_MAX_BUNCH_LENGTH \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1632 >= COMPOSITION_DATA_SIZE)) \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1633 { \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1634 coding->result = CODING_FINISH_INSUFFICIENT_CMP; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1635 goto label_end_of_loop; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1636 } \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1637 coding->composing = (c1 == '0' ? COMPOSITION_RELATIVE \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1638 : c1 == '2' ? COMPOSITION_WITH_RULE \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1639 : c1 == '3' ? COMPOSITION_WITH_ALTCHARS \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1640 : COMPOSITION_WITH_RULE_ALTCHARS); \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1641 CODING_ADD_COMPOSITION_START (coding, coding->produced_char, \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1642 coding->composing); \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1643 coding->composition_rule_follows = 0; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1644 } \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1645 else \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1646 { \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1647 /* We are already handling a composition. If the method is \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1648 the following two, the codes following the current escape \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1649 sequence are actual characters stored in a buffer. */ \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1650 if (coding->composing == COMPOSITION_WITH_ALTCHARS \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1651 || coding->composing == COMPOSITION_WITH_RULE_ALTCHARS) \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1652 { \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1653 coding->composing = COMPOSITION_RELATIVE; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1654 coding->composition_rule_follows = 0; \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1655 } \
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
1656 } \
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1657 } while (0)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1658
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1659 /* Handle compositoin end sequence ESC 1. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1660
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1661 #define DECODE_COMPOSITION_END(c1) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1662 do { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1663 if (coding->composing == COMPOSITION_DISABLED) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1664 { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1665 *dst++ = ISO_CODE_ESC; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1666 *dst++ = c1; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1667 coding->produced_char += 2; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1668 } \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1669 else \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1670 { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1671 CODING_ADD_COMPOSITION_END (coding, coding->produced_char); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1672 coding->composing = COMPOSITION_NO; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1673 } \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1674 } while (0)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1675
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1676 /* Decode a composition rule from the byte C1 (and maybe one more byte
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1677 from SRC) and store one encoded composition rule in
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1678 coding->cmp_data. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1679
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1680 #define DECODE_COMPOSITION_RULE(c1) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1681 do { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1682 int rule = 0; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1683 (c1) -= 32; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1684 if (c1 < 81) /* old format (before ver.21) */ \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1685 { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1686 int gref = (c1) / 9; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1687 int nref = (c1) % 9; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1688 if (gref == 4) gref = 10; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1689 if (nref == 4) nref = 10; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1690 rule = COMPOSITION_ENCODE_RULE (gref, nref); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1691 } \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1692 else if (c1 < 93) /* new format (after ver.21) */ \
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1693 { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1694 ONE_MORE_BYTE (c2); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1695 rule = COMPOSITION_ENCODE_RULE (c1 - 81, c2 - 32); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1696 } \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1697 CODING_ADD_COMPOSITION_COMPONENT (coding, rule); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1698 coding->composition_rule_follows = 0; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1699 } while (0)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1700
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1701
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1702 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1703
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1704 static void
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1705 decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1706 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1707 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1708 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1709 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1710 unsigned char *src = source;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1711 unsigned char *src_end = source + src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1712 unsigned char *dst = destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1713 unsigned char *dst_end = destination + dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1714 /* Charsets invoked to graphic plane 0 and 1 respectively. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1715 int charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1716 int charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1717 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1718 The loop will be exited when there's not enough source code
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1719 (within macro ONE_MORE_BYTE), or when there's not enough
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1720 destination area to produce a character (within macro
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1721 EMIT_CHAR). */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1722 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1723 int c, charset;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1724 Lisp_Object translation_table;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1725 Lisp_Object safe_chars;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1726
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
1727 safe_chars = coding_safe_chars (coding);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1728
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1729 if (NILP (Venable_character_translation))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1730 translation_table = Qnil;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1731 else
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1732 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1733 translation_table = coding->translation_table_for_decode;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1734 if (NILP (translation_table))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1735 translation_table = Vstandard_translation_table_for_decode;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1736 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1737
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1738 coding->result = CODING_FINISH_NORMAL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1739
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1740 while (1)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1741 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1742 int c1, c2;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1743
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1744 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1745 ONE_MORE_BYTE (c1);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1746
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1747 /* We produce no character or one character. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1748 switch (iso_code_class [c1])
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1749 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1750 case ISO_0x20_or_0x7F:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1751 if (COMPOSING_P (coding) && coding->composition_rule_follows)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1752 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1753 DECODE_COMPOSITION_RULE (c1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1754 continue;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1755 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1756 if (charset0 < 0 || CHARSET_CHARS (charset0) == 94)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1757 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1758 /* This is SPACE or DEL. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1759 charset = CHARSET_ASCII;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1760 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1761 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1762 /* This is a graphic character, we fall down ... */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1763
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1764 case ISO_graphic_plane_0:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1765 if (COMPOSING_P (coding) && coding->composition_rule_follows)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1766 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1767 DECODE_COMPOSITION_RULE (c1);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1768 continue;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1769 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1770 charset = charset0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1771 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1772
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1773 case ISO_0xA0_or_0xFF:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1774 if (charset1 < 0 || CHARSET_CHARS (charset1) == 94
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1775 || coding->flags & CODING_FLAG_ISO_SEVEN_BITS)
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
1776 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1777 /* This is a graphic character, we fall down ... */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1778
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1779 case ISO_graphic_plane_1:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1780 if (charset1 < 0)
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
1781 goto label_invalid_code;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1782 charset = charset1;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1783 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1784
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1785 case ISO_control_0:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1786 if (COMPOSING_P (coding))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1787 DECODE_COMPOSITION_END ('1');
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1788
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1789 /* All ISO2022 control characters in this class have the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1790 same representation in Emacs internal format. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1791 if (c1 == '\n'
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1792 && (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1793 && (coding->eol_type == CODING_EOL_CR
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1794 || coding->eol_type == CODING_EOL_CRLF))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1795 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1796 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1797 goto label_end_of_loop;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1798 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1799 charset = CHARSET_ASCII;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1800 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1801
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1802 case ISO_control_1:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1803 if (COMPOSING_P (coding))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1804 DECODE_COMPOSITION_END ('1');
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1805 goto label_invalid_code;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1806
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1807 case ISO_carriage_return:
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1808 if (COMPOSING_P (coding))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1809 DECODE_COMPOSITION_END ('1');
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1810
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1811 if (coding->eol_type == CODING_EOL_CR)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1812 c1 = '\n';
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1813 else if (coding->eol_type == CODING_EOL_CRLF)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1814 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1815 ONE_MORE_BYTE (c1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1816 if (c1 != ISO_CODE_LF)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1817 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1818 if (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1819 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1820 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1821 goto label_end_of_loop;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1822 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1823 src--;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1824 c1 = '\r';
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1825 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1826 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1827 charset = CHARSET_ASCII;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1828 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1829
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1830 case ISO_shift_out:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1831 if (! (coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1832 || CODING_SPEC_ISO_DESIGNATION (coding, 1) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1833 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1834 CODING_SPEC_ISO_INVOCATION (coding, 0) = 1;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1835 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1836 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1837
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1838 case ISO_shift_in:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1839 if (! (coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1840 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1841 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1842 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1843 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1844
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1845 case ISO_single_shift_2_7:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1846 case ISO_single_shift_2:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1847 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1848 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1849 /* SS2 is handled as an escape sequence of ESC 'N' */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1850 c1 = 'N';
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1851 goto label_escape_sequence;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1852
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1853 case ISO_single_shift_3:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1854 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1855 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1856 /* SS2 is handled as an escape sequence of ESC 'O' */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1857 c1 = 'O';
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1858 goto label_escape_sequence;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1859
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1860 case ISO_control_sequence_introducer:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1861 /* CSI is handled as an escape sequence of ESC '[' ... */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1862 c1 = '[';
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1863 goto label_escape_sequence;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1864
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1865 case ISO_escape:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1866 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1867 label_escape_sequence:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1868 /* Escape sequences handled by Emacs are invocation,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1869 designation, direction specification, and character
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1870 composition specification. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1871 switch (c1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1872 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1873 case '&': /* revision of following character set */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1874 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1875 if (!(c1 >= '@' && c1 <= '~'))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1876 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1877 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1878 if (c1 != ISO_CODE_ESC)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1879 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1880 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1881 goto label_escape_sequence;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1882
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1883 case '$': /* designation of 2-byte character set */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1884 if (! (coding->flags & CODING_FLAG_ISO_DESIGNATION))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1885 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1886 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1887 if (c1 >= '@' && c1 <= 'B')
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1888 { /* designation of JISX0208.1978, GB2312.1980,
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
1889 or JISX0208.1980 */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1890 DECODE_DESIGNATION (0, 2, 94, c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1891 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1892 else if (c1 >= 0x28 && c1 <= 0x2B)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1893 { /* designation of DIMENSION2_CHARS94 character set */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1894 ONE_MORE_BYTE (c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1895 DECODE_DESIGNATION (c1 - 0x28, 2, 94, c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1896 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1897 else if (c1 >= 0x2C && c1 <= 0x2F)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1898 { /* designation of DIMENSION2_CHARS96 character set */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1899 ONE_MORE_BYTE (c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1900 DECODE_DESIGNATION (c1 - 0x2C, 2, 96, c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1901 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1902 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1903 goto label_invalid_code;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1904 /* We must update these variables now. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1905 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1906 charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1907 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1908
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1909 case 'n': /* invocation of locking-shift-2 */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1910 if (! (coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1911 || CODING_SPEC_ISO_DESIGNATION (coding, 2) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1912 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1913 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
1914 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1915 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1916
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1917 case 'o': /* invocation of locking-shift-3 */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1918 if (! (coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1919 || CODING_SPEC_ISO_DESIGNATION (coding, 3) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1920 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1921 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
1922 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1923 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1924
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1925 case 'N': /* invocation of single-shift-2 */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1926 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1927 || CODING_SPEC_ISO_DESIGNATION (coding, 2) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1928 goto label_invalid_code;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1929 charset = CODING_SPEC_ISO_DESIGNATION (coding, 2);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1930 ONE_MORE_BYTE (c1);
30578
705b94e152b1 (decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents: 30487
diff changeset
1931 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0))
705b94e152b1 (decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents: 30487
diff changeset
1932 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1933 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1934
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1935 case 'O': /* invocation of single-shift-3 */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1936 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1937 || CODING_SPEC_ISO_DESIGNATION (coding, 3) < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1938 goto label_invalid_code;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1939 charset = CODING_SPEC_ISO_DESIGNATION (coding, 3);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1940 ONE_MORE_BYTE (c1);
30578
705b94e152b1 (decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents: 30487
diff changeset
1941 if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0))
705b94e152b1 (decode_coding_iso2022): More strict check for handling single
Kenichi Handa <handa@m17n.org>
parents: 30487
diff changeset
1942 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1943 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1944
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1945 case '0': case '2': case '3': case '4': /* start composition */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1946 DECODE_COMPOSITION_START (c1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1947 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1948
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1949 case '1': /* end composition */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
1950 DECODE_COMPOSITION_END (c1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1951 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1952
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1953 case '[': /* specification of direction */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1954 if (coding->flags & CODING_FLAG_ISO_NO_DIRECTION)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1955 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1956 /* For the moment, nested direction is not supported.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1957 So, `coding->mode & CODING_MODE_DIRECTION' zero means
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1958 left-to-right, and nozero means right-to-left. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1959 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1960 switch (c1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1961 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1962 case ']': /* end of the current direction */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1963 coding->mode &= ~CODING_MODE_DIRECTION;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1964
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1965 case '0': /* end of the current direction */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1966 case '1': /* start of left-to-right direction */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1967 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1968 if (c1 == ']')
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1969 coding->mode &= ~CODING_MODE_DIRECTION;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1970 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1971 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1972 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1973
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1974 case '2': /* start of right-to-left direction */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1975 ONE_MORE_BYTE (c1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1976 if (c1 == ']')
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1977 coding->mode |= CODING_MODE_DIRECTION;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1978 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1979 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1980 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1981
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1982 default:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1983 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1984 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
1985 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1986
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1987 default:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1988 if (! (coding->flags & CODING_FLAG_ISO_DESIGNATION))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
1989 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1990 if (c1 >= 0x28 && c1 <= 0x2B)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1991 { /* designation of DIMENSION1_CHARS94 character set */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1992 ONE_MORE_BYTE (c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1993 DECODE_DESIGNATION (c1 - 0x28, 1, 94, c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1994 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1995 else if (c1 >= 0x2C && c1 <= 0x2F)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1996 { /* designation of DIMENSION1_CHARS96 character set */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1997 ONE_MORE_BYTE (c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1998 DECODE_DESIGNATION (c1 - 0x2C, 1, 96, c2);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1999 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2000 else
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2001 goto label_invalid_code;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2002 /* We must update these variables now. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2003 charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2004 charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2005 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2006 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2007 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2008
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2009 /* Now we know CHARSET and 1st position code C1 of a character.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2010 Produce a multibyte sequence for that character while getting
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2011 2nd position code C2 if necessary. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2012 if (CHARSET_DIMENSION (charset) == 2)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2013 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2014 ONE_MORE_BYTE (c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2015 if (c1 < 0x80 ? c2 < 0x20 || c2 >= 0x80 : c2 < 0xA0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2016 /* C2 is not in a valid range. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2017 goto label_invalid_code;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2018 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2019 c = DECODE_ISO_CHARACTER (charset, c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2020 EMIT_CHAR (c);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2021 continue;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2022
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2023 label_invalid_code:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2024 coding->errors++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2025 if (COMPOSING_P (coding))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2026 DECODE_COMPOSITION_END ('1');
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2027 src = src_base;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2028 c = *src++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2029 EMIT_CHAR (c);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2030 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2031
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2032 label_end_of_loop:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2033 coding->consumed = coding->consumed_char = src_base - source;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2034 coding->produced = dst - destination;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2035 return;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2036 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2037
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2038
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2039 /* ISO2022 encoding stuff. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2040
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2041 /*
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2042 It is not enough to say just "ISO2022" on encoding, we have to
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2043 specify more details. In Emacs, each coding system of ISO2022
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2044 variant has the following specifications:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2045 1. Initial designation to G0 thru G3.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2046 2. Allows short-form designation?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2047 3. ASCII should be designated to G0 before control characters?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2048 4. ASCII should be designated to G0 at end of line?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2049 5. 7-bit environment or 8-bit environment?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2050 6. Use locking-shift?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2051 7. Use Single-shift?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2052 And the following two are only for Japanese:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2053 8. Use ASCII in place of JIS0201-1976-Roman?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2054 9. Use JISX0208-1983 in place of JISX0208-1978?
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2055 These specifications are encoded in `coding->flags' as flag bits
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2056 defined by macros CODING_FLAG_ISO_XXX. See `coding.h' for more
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2057 details.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2058 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2059
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2060 /* Produce codes (escape sequence) for designating CHARSET to graphic
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2061 register REG at DST, and increment DST. If <final-char> of CHARSET is
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2062 '@', 'A', or 'B' and the coding system CODING allows, produce
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2063 designation sequence of short-form. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2064
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2065 #define ENCODE_DESIGNATION(charset, reg, coding) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2066 do { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2067 unsigned char final_char = CHARSET_ISO_FINAL_CHAR (charset); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2068 char *intermediate_char_94 = "()*+"; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2069 char *intermediate_char_96 = ",-./"; \
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
2070 int revision = CODING_SPEC_ISO_REVISION_NUMBER(coding, charset); \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2071 \
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
2072 if (revision < 255) \
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
2073 { \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2074 *dst++ = ISO_CODE_ESC; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2075 *dst++ = '&'; \
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
2076 *dst++ = '@' + revision; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2077 } \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2078 *dst++ = ISO_CODE_ESC; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2079 if (CHARSET_DIMENSION (charset) == 1) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2080 { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2081 if (CHARSET_CHARS (charset) == 94) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2082 *dst++ = (unsigned char) (intermediate_char_94[reg]); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2083 else \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2084 *dst++ = (unsigned char) (intermediate_char_96[reg]); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2085 } \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2086 else \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2087 { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2088 *dst++ = '$'; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2089 if (CHARSET_CHARS (charset) == 94) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2090 { \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2091 if (! (coding->flags & CODING_FLAG_ISO_SHORT_FORM) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2092 || reg != 0 \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2093 || final_char < '@' || final_char > 'B') \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2094 *dst++ = (unsigned char) (intermediate_char_94[reg]); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2095 } \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2096 else \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2097 *dst++ = (unsigned char) (intermediate_char_96[reg]); \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2098 } \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2099 *dst++ = final_char; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2100 CODING_SPEC_ISO_DESIGNATION (coding, reg) = charset; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2101 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2102
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2103 /* The following two macros produce codes (control character or escape
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2104 sequence) for ISO2022 single-shift functions (single-shift-2 and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2105 single-shift-3). */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2106
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2107 #define ENCODE_SINGLE_SHIFT_2 \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2108 do { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2109 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2110 *dst++ = ISO_CODE_ESC, *dst++ = 'N'; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2111 else \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2112 *dst++ = ISO_CODE_SS2; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2113 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 1; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2114 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2115
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2116 #define ENCODE_SINGLE_SHIFT_3 \
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2117 do { \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2118 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2119 *dst++ = ISO_CODE_ESC, *dst++ = 'O'; \
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2120 else \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2121 *dst++ = ISO_CODE_SS3; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2122 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 1; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2123 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2124
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2125 /* The following four macros produce codes (control character or
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2126 escape sequence) for ISO2022 locking-shift functions (shift-in,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2127 shift-out, locking-shift-2, and locking-shift-3). */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2128
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2129 #define ENCODE_SHIFT_IN \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2130 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2131 *dst++ = ISO_CODE_SI; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2132 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2133 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2134
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2135 #define ENCODE_SHIFT_OUT \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2136 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2137 *dst++ = ISO_CODE_SO; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2138 CODING_SPEC_ISO_INVOCATION (coding, 0) = 1; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2139 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2140
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2141 #define ENCODE_LOCKING_SHIFT_2 \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2142 do { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2143 *dst++ = ISO_CODE_ESC, *dst++ = 'n'; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2144 CODING_SPEC_ISO_INVOCATION (coding, 0) = 2; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2145 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2146
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2147 #define ENCODE_LOCKING_SHIFT_3 \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2148 do { \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2149 *dst++ = ISO_CODE_ESC, *dst++ = 'o'; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2150 CODING_SPEC_ISO_INVOCATION (coding, 0) = 3; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2151 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2152
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2153 /* Produce codes for a DIMENSION1 character whose character set is
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2154 CHARSET and whose position-code is C1. Designation and invocation
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2155 sequences are also produced in advance if necessary. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2156
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2157 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2158 do { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2159 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2160 { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2161 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2162 *dst++ = c1 & 0x7F; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2163 else \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2164 *dst++ = c1 | 0x80; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2165 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2166 break; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2167 } \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2168 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2169 { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2170 *dst++ = c1 & 0x7F; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2171 break; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2172 } \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2173 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2174 { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2175 *dst++ = c1 | 0x80; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2176 break; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2177 } \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2178 else \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2179 /* Since CHARSET is not yet invoked to any graphic planes, we \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2180 must invoke it, or, at first, designate it to some graphic \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2181 register. Then repeat the loop to actually produce the \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2182 character. */ \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2183 dst = encode_invocation_designation (charset, coding, dst); \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2184 } while (1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2185
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2186 /* Produce codes for a DIMENSION2 character whose character set is
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2187 CHARSET and whose position-codes are C1 and C2. Designation and
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2188 invocation codes are also produced in advance if necessary. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2189
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2190 #define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2191 do { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2192 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2193 { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2194 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2195 *dst++ = c1 & 0x7F, *dst++ = c2 & 0x7F; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2196 else \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2197 *dst++ = c1 | 0x80, *dst++ = c2 | 0x80; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2198 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2199 break; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2200 } \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2201 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2202 { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2203 *dst++ = c1 & 0x7F, *dst++= c2 & 0x7F; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2204 break; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2205 } \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2206 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2207 { \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2208 *dst++ = c1 | 0x80, *dst++= c2 | 0x80; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2209 break; \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2210 } \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2211 else \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2212 /* Since CHARSET is not yet invoked to any graphic planes, we \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2213 must invoke it, or, at first, designate it to some graphic \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2214 register. Then repeat the loop to actually produce the \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2215 character. */ \
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
2216 dst = encode_invocation_designation (charset, coding, dst); \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2217 } while (1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2218
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2219 #define ENCODE_ISO_CHARACTER(c) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2220 do { \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2221 int charset, c1, c2; \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2222 \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2223 SPLIT_CHAR (c, charset, c1, c2); \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2224 if (CHARSET_DEFINED_P (charset)) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2225 { \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2226 if (CHARSET_DIMENSION (charset) == 1) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2227 { \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2228 if (charset == CHARSET_ASCII \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2229 && coding->flags & CODING_FLAG_ISO_USE_ROMAN) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2230 charset = charset_latin_jisx0201; \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2231 ENCODE_ISO_CHARACTER_DIMENSION1 (charset, c1); \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2232 } \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2233 else \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2234 { \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2235 if (charset == charset_jisx0208 \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2236 && coding->flags & CODING_FLAG_ISO_USE_OLDJIS) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2237 charset = charset_jisx0208_1978; \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2238 ENCODE_ISO_CHARACTER_DIMENSION2 (charset, c1, c2); \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2239 } \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2240 } \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2241 else \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2242 { \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2243 *dst++ = c1; \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2244 if (c2 >= 0) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2245 *dst++ = c2; \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2246 } \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2247 } while (0)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2248
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2249
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2250 /* Instead of encoding character C, produce one or two `?'s. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2251
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2252 #define ENCODE_UNSAFE_CHARACTER(c) \
24506
219c99669e4b (ENCODE_ISO_CHARACTER): Check validity of CHARSET. If
Kenichi Handa <handa@m17n.org>
parents: 24460
diff changeset
2253 do { \
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2254 ENCODE_ISO_CHARACTER (CODING_INHIBIT_CHARACTER_SUBSTITUTION); \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2255 if (CHARSET_WIDTH (CHAR_CHARSET (c)) > 1) \
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2256 ENCODE_ISO_CHARACTER (CODING_INHIBIT_CHARACTER_SUBSTITUTION); \
22119
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
2257 } while (0)
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2258
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2259
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2260 /* Produce designation and invocation codes at a place pointed by DST
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2261 to use CHARSET. The element `spec.iso2022' of *CODING is updated.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2262 Return new DST. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2263
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2264 unsigned char *
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2265 encode_invocation_designation (charset, coding, dst)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2266 int charset;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2267 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2268 unsigned char *dst;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2269 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2270 int reg; /* graphic register number */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2271
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2272 /* At first, check designations. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2273 for (reg = 0; reg < 4; reg++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2274 if (charset == CODING_SPEC_ISO_DESIGNATION (coding, reg))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2275 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2276
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2277 if (reg >= 4)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2278 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2279 /* CHARSET is not yet designated to any graphic registers. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2280 /* At first check the requested designation. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2281 reg = CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset);
18002
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
2282 if (reg == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
2283 /* Since CHARSET requests no special designation, designate it
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
2284 to graphic register 0. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2285 reg = 0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2286
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2287 ENCODE_DESIGNATION (charset, reg, coding);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2288 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2289
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2290 if (CODING_SPEC_ISO_INVOCATION (coding, 0) != reg
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2291 && CODING_SPEC_ISO_INVOCATION (coding, 1) != reg)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2292 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2293 /* Since the graphic register REG is not invoked to any graphic
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2294 planes, invoke it to graphic plane 0. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2295 switch (reg)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2296 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2297 case 0: /* graphic register 0 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2298 ENCODE_SHIFT_IN;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2299 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2300
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2301 case 1: /* graphic register 1 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2302 ENCODE_SHIFT_OUT;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2303 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2304
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2305 case 2: /* graphic register 2 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2306 if (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2307 ENCODE_SINGLE_SHIFT_2;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2308 else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2309 ENCODE_LOCKING_SHIFT_2;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2310 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2311
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2312 case 3: /* graphic register 3 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2313 if (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2314 ENCODE_SINGLE_SHIFT_3;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2315 else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2316 ENCODE_LOCKING_SHIFT_3;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2317 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2318 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2319 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2320
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2321 return dst;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2322 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2323
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2324 /* Produce 2-byte codes for encoded composition rule RULE. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2325
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2326 #define ENCODE_COMPOSITION_RULE(rule) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2327 do { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2328 int gref, nref; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2329 COMPOSITION_DECODE_RULE (rule, gref, nref); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2330 *dst++ = 32 + 81 + gref; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2331 *dst++ = 32 + nref; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2332 } while (0)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2333
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2334 /* Produce codes for indicating the start of a composition sequence
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2335 (ESC 0, ESC 3, or ESC 4). DATA points to an array of integers
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2336 which specify information about the composition. See the comment
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2337 in coding.h for the format of DATA. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2338
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2339 #define ENCODE_COMPOSITION_START(coding, data) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2340 do { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2341 coding->composing = data[3]; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2342 *dst++ = ISO_CODE_ESC; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2343 if (coding->composing == COMPOSITION_RELATIVE) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2344 *dst++ = '0'; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2345 else \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2346 { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2347 *dst++ = (coding->composing == COMPOSITION_WITH_ALTCHARS \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2348 ? '3' : '4'); \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2349 coding->cmp_data_index = coding->cmp_data_start + 4; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2350 coding->composition_rule_follows = 0; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2351 } \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2352 } while (0)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2353
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2354 /* Produce codes for indicating the end of the current composition. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2355
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2356 #define ENCODE_COMPOSITION_END(coding, data) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2357 do { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2358 *dst++ = ISO_CODE_ESC; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2359 *dst++ = '1'; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2360 coding->cmp_data_start += data[0]; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2361 coding->composing = COMPOSITION_NO; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2362 if (coding->cmp_data_start == coding->cmp_data->used \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2363 && coding->cmp_data->next) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2364 { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2365 coding->cmp_data = coding->cmp_data->next; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2366 coding->cmp_data_start = 0; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2367 } \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2368 } while (0)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2369
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2370 /* Produce composition start sequence ESC 0. Here, this sequence
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2371 doesn't mean the start of a new composition but means that we have
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2372 just produced components (alternate chars and composition rules) of
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2373 the composition and the actual text follows in SRC. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2374
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2375 #define ENCODE_COMPOSITION_FAKE_START(coding) \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2376 do { \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2377 *dst++ = ISO_CODE_ESC; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2378 *dst++ = '0'; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2379 coding->composing = COMPOSITION_RELATIVE; \
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2380 } while (0)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2381
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2382 /* The following three macros produce codes for indicating direction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2383 of text. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2384 #define ENCODE_CONTROL_SEQUENCE_INTRODUCER \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2385 do { \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2386 if (coding->flags == CODING_FLAG_ISO_SEVEN_BITS) \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2387 *dst++ = ISO_CODE_ESC, *dst++ = '['; \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2388 else \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2389 *dst++ = ISO_CODE_CSI; \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2390 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2391
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2392 #define ENCODE_DIRECTION_R2L \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2393 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst), *dst++ = '2', *dst++ = ']'
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2394
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2395 #define ENCODE_DIRECTION_L2R \
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2396 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst), *dst++ = '0', *dst++ = ']'
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2397
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2398 /* Produce codes for designation and invocation to reset the graphic
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2399 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
2400 #define ENCODE_RESET_PLANE_AND_REGISTER \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2401 do { \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2402 int reg; \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2403 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
2404 ENCODE_SHIFT_IN; \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2405 for (reg = 0; reg < 4; reg++) \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2406 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
2407 && (CODING_SPEC_ISO_DESIGNATION (coding, reg) \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2408 != 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
2409 ENCODE_DESIGNATION \
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2410 (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, reg), reg, coding); \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2411 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2412
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2413 /* Produce designation sequences of charsets in the line started from
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2414 SRC to a place pointed by DST, and return updated DST.
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2415
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2416 If the current block ends before any end-of-line, we may fail to
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2417 find all the necessary designations. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2418
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2419 static unsigned char *
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2420 encode_designation_at_bol (coding, translation_table, src, src_end, dst)
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2421 struct coding_system *coding;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2422 Lisp_Object translation_table;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2423 unsigned char *src, *src_end, *dst;
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2424 {
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2425 int charset, c, found = 0, reg;
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2426 /* 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
2427 int r[4];
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2428
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2429 for (reg = 0; reg < 4; reg++)
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2430 r[reg] = -1;
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2431
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2432 while (found < 4)
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2433 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2434 ONE_MORE_CHAR (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2435 if (c == '\n')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2436 break;
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2437
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2438 charset = CHAR_CHARSET (c);
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2439 reg = CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2440 if (reg != CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION && r[reg] < 0)
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2441 {
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2442 found++;
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2443 r[reg] = charset;
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2444 }
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2445 }
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2446
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2447 label_end_of_loop:
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2448 if (found)
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2449 {
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2450 for (reg = 0; reg < 4; reg++)
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2451 if (r[reg] >= 0
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2452 && CODING_SPEC_ISO_DESIGNATION (coding, reg) != r[reg])
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2453 ENCODE_DESIGNATION (r[reg], reg, coding);
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2454 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2455
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2456 return dst;
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2457 }
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2458
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2459 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2460
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2461 static void
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2462 encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2463 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2464 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2465 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2466 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2467 unsigned char *src = source;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2468 unsigned char *src_end = source + src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2469 unsigned char *dst = destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2470 unsigned char *dst_end = destination + dst_bytes;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2471 /* Since the maximum bytes produced by each loop is 20, we subtract 19
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2472 from DST_END to assure overflow checking is necessary only at the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2473 head of loop. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2474 unsigned char *adjusted_dst_end = dst_end - 19;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2475 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2476 The loop will be exited when there's not enough source text to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2477 analyze multi-byte codes (within macro ONE_MORE_CHAR), or when
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2478 there's not enough destination area to produce encoded codes
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2479 (within macro EMIT_BYTES). */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2480 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2481 int c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2482 Lisp_Object translation_table;
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2483 Lisp_Object safe_chars;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2484
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2485 safe_chars = coding_safe_chars (coding);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2486
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2487 if (NILP (Venable_character_translation))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2488 translation_table = Qnil;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2489 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2490 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2491 translation_table = coding->translation_table_for_encode;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2492 if (NILP (translation_table))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2493 translation_table = Vstandard_translation_table_for_encode;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2494 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2495
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2496 coding->consumed_char = 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2497 coding->errors = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2498 while (1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2499 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2500 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2501
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2502 if (dst >= (dst_bytes ? adjusted_dst_end : (src - 19)))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2503 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2504 coding->result = CODING_FINISH_INSUFFICIENT_DST;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2505 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2506 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2507
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2508 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
2509 && CODING_SPEC_ISO_BOL (coding))
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2510 {
17725
92f042f73be2 (Valternate_charset_table): The valiable deleted.
Kenichi Handa <handa@m17n.org>
parents: 17717
diff changeset
2511 /* We have to produce designation sequences if any now. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2512 dst = encode_designation_at_bol (coding, translation_table,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2513 src, src_end, dst);
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2514 CODING_SPEC_ISO_BOL (coding) = 0;
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2515 }
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
2516
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2517 /* Check composition start and end. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2518 if (coding->composing != COMPOSITION_DISABLED
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2519 && coding->cmp_data_start < coding->cmp_data->used)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2520 {
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2521 struct composition_data *cmp_data = coding->cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2522 int *data = cmp_data->data + coding->cmp_data_start;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2523 int this_pos = cmp_data->char_offset + coding->consumed_char;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2524
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2525 if (coding->composing == COMPOSITION_RELATIVE)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2526 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2527 if (this_pos == data[2])
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2528 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2529 ENCODE_COMPOSITION_END (coding, data);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2530 cmp_data = coding->cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2531 data = cmp_data->data + coding->cmp_data_start;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2532 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2533 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2534 else if (COMPOSING_P (coding))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2535 {
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2536 /* COMPOSITION_WITH_ALTCHARS or COMPOSITION_WITH_RULE_ALTCHAR */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2537 if (coding->cmp_data_index == coding->cmp_data_start + data[0])
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2538 /* We have consumed components of the composition.
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2539 What follows in SRC is the compositions's base
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2540 text. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2541 ENCODE_COMPOSITION_FAKE_START (coding);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2542 else
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2543 {
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2544 int c = cmp_data->data[coding->cmp_data_index++];
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2545 if (coding->composition_rule_follows)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2546 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2547 ENCODE_COMPOSITION_RULE (c);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2548 coding->composition_rule_follows = 0;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2549 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2550 else
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2551 {
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2552 if (coding->flags & CODING_FLAG_ISO_SAFE
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2553 && ! CODING_SAFE_CHAR_P (safe_chars, c))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2554 ENCODE_UNSAFE_CHARACTER (c);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2555 else
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2556 ENCODE_ISO_CHARACTER (c);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2557 if (coding->composing == COMPOSITION_WITH_RULE_ALTCHARS)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2558 coding->composition_rule_follows = 1;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2559 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2560 continue;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2561 }
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2562 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2563 if (!COMPOSING_P (coding))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2564 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2565 if (this_pos == data[1])
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2566 {
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2567 ENCODE_COMPOSITION_START (coding, data);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2568 continue;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2569 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2570 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2571 }
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
2572
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2573 ONE_MORE_CHAR (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2574
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2575 /* Now encode the character C. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2576 if (c < 0x20 || c == 0x7F)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2577 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2578 if (c == '\r')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2579 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2580 if (! (coding->mode & CODING_MODE_SELECTIVE_DISPLAY))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2581 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2582 if (coding->flags & CODING_FLAG_ISO_RESET_AT_CNTL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2583 ENCODE_RESET_PLANE_AND_REGISTER;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2584 *dst++ = c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2585 continue;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2586 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2587 /* fall down to treat '\r' as '\n' ... */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2588 c = '\n';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2589 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2590 if (c == '\n')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2591 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2592 if (coding->flags & CODING_FLAG_ISO_RESET_AT_EOL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2593 ENCODE_RESET_PLANE_AND_REGISTER;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2594 if (coding->flags & CODING_FLAG_ISO_INIT_AT_BOL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2595 bcopy (coding->spec.iso2022.initial_designation,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2596 coding->spec.iso2022.current_designation,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2597 sizeof coding->spec.iso2022.initial_designation);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2598 if (coding->eol_type == CODING_EOL_LF
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2599 || coding->eol_type == CODING_EOL_UNDECIDED)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2600 *dst++ = ISO_CODE_LF;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2601 else if (coding->eol_type == CODING_EOL_CRLF)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2602 *dst++ = ISO_CODE_CR, *dst++ = ISO_CODE_LF;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2603 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2604 *dst++ = ISO_CODE_CR;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2605 CODING_SPEC_ISO_BOL (coding) = 1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2606 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2607 else
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2608 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2609 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
2610 ENCODE_RESET_PLANE_AND_REGISTER;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2611 *dst++ = c;
19052
302a7b2a6948 (encode_coding_iso2022): Write out invalid multibyte
Kenichi Handa <handa@m17n.org>
parents: 18910
diff changeset
2612 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2613 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2614 else if (ASCII_BYTE_P (c))
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2615 ENCODE_ISO_CHARACTER (c);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2616 else if (SINGLE_BYTE_CHAR_P (c))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2617 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2618 *dst++ = c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2619 coding->errors++;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2620 }
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2621 else if (coding->flags & CODING_FLAG_ISO_SAFE
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2622 && ! CODING_SAFE_CHAR_P (safe_chars, c))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2623 ENCODE_UNSAFE_CHARACTER (c);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2624 else
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
2625 ENCODE_ISO_CHARACTER (c);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2626
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2627 coding->consumed_char++;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2628 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2629
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2630 label_end_of_loop:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2631 coding->consumed = src_base - source;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2632 coding->produced = coding->produced_char = dst - destination;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2633 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2634
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2635
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2636 /*** 4. SJIS and BIG5 handlers ***/
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2637
18766
ac2e7e21abb0 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 18747
diff changeset
2638 /* Although SJIS and BIG5 are not ISO's coding system, they are used
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2639 quite widely. So, for the moment, Emacs supports them in the bare
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2640 C code. But, in the future, they may be supported only by CCL. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2641
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2642 /* SJIS is a coding system encoding three character sets: ASCII, right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2643 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2644 as is. A character of charset katakana-jisx0201 is encoded by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2645 "position-code + 0x80". A character of charset japanese-jisx0208
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2646 is encoded in 2-byte but two position-codes are divided and shifted
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2647 so that it fit in the range below.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2648
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2649 --- CODE RANGE of SJIS ---
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2650 (character set) (range)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2651 ASCII 0x00 .. 0x7F
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2652 KATAKANA-JISX0201 0xA0 .. 0xDF
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
2653 JISX0208 (1st byte) 0x81 .. 0x9F and 0xE0 .. 0xEF
23564
6eb3e346d1fd (DECODE_CHARACTER_ASCII): Check validity of inserted
Kenichi Handa <handa@m17n.org>
parents: 23542
diff changeset
2654 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2655 -------------------------------
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2656
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2657 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2658
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2659 /* BIG5 is a coding system encoding two character sets: ASCII and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2660 Big5. An ASCII character is encoded as is. Big5 is a two-byte
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2661 character set and is encoded in two-byte.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2662
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2663 --- CODE RANGE of BIG5 ---
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2664 (character set) (range)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2665 ASCII 0x00 .. 0x7F
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2666 Big5 (1st byte) 0xA1 .. 0xFE
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2667 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2668 --------------------------
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2669
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2670 Since the number of characters in Big5 is larger than maximum
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2671 characters in Emacs' charset (96x96), it can't be handled as one
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2672 charset. So, in Emacs, Big5 is divided into two: `charset-big5-1'
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2673 and `charset-big5-2'. Both are DIMENSION2 and CHARS94. The former
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2674 contains frequently used characters and the latter contains less
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2675 frequently used characters. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2676
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2677 /* Macros to decode or encode a character of Big5 in BIG5. B1 and B2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2678 are the 1st and 2nd position-codes of Big5 in BIG5 coding system.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2679 C1 and C2 are the 1st and 2nd position-codes of of Emacs' internal
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2680 format. CHARSET is `charset_big5_1' or `charset_big5_2'. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2681
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2682 /* Number of Big5 characters which have the same code in 1st byte. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2683 #define BIG5_SAME_ROW (0xFF - 0xA1 + 0x7F - 0x40)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2684
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2685 #define DECODE_BIG5(b1, b2, charset, c1, c2) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2686 do { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2687 unsigned int temp \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2688 = (b1 - 0xA1) * BIG5_SAME_ROW + b2 - (b2 < 0x7F ? 0x40 : 0x62); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2689 if (b1 < 0xC9) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2690 charset = charset_big5_1; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2691 else \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2692 { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2693 charset = charset_big5_2; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2694 temp -= (0xC9 - 0xA1) * BIG5_SAME_ROW; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2695 } \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2696 c1 = temp / (0xFF - 0xA1) + 0x21; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2697 c2 = temp % (0xFF - 0xA1) + 0x21; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2698 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2699
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2700 #define ENCODE_BIG5(charset, c1, c2, b1, b2) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2701 do { \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2702 unsigned int temp = (c1 - 0x21) * (0xFF - 0xA1) + (c2 - 0x21); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2703 if (charset == charset_big5_2) \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2704 temp += BIG5_SAME_ROW * (0xC9 - 0xA1); \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2705 b1 = temp / BIG5_SAME_ROW + 0xA1; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2706 b2 = temp % BIG5_SAME_ROW; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2707 b2 += b2 < 0x3F ? 0x40 : 0x62; \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2708 } while (0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2709
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2710 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2711 Check if a text is encoded in SJIS. If it is, return
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2712 CODING_CATEGORY_MASK_SJIS, else return 0. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2713
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2714 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2715 detect_coding_sjis (src, src_end, multibytep)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2716 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2717 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2718 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2719 int c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2720 /* Dummy for ONE_MORE_BYTE. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2721 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2722 struct coding_system *coding = &dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2723
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2724 while (1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2725 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2726 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
31458
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2727 if (c >= 0x81)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2728 {
31458
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2729 if (c <= 0x9F || (c >= 0xE0 && c <= 0xEF))
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2730 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2731 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
31458
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2732 if (c < 0x40 || c == 0x7F || c > 0xFC)
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2733 return 0;
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2734 }
ec8a58b2ec83 (detect_coding_sjis): Check the byte sequence more regidly.
Kenichi Handa <handa@m17n.org>
parents: 31457
diff changeset
2735 else if (c > 0xDF)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2736 return 0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2737 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2738 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2739 label_end_of_loop:
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2740 return CODING_CATEGORY_MASK_SJIS;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2741 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2742
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2743 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2744 Check if a text is encoded in BIG5. If it is, return
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2745 CODING_CATEGORY_MASK_BIG5, else return 0. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2746
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2747 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2748 detect_coding_big5 (src, src_end, multibytep)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2749 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2750 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2751 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2752 int c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2753 /* Dummy for ONE_MORE_BYTE. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2754 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2755 struct coding_system *coding = &dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2756
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2757 while (1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2758 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2759 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2760 if (c >= 0xA1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2761 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2762 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2763 if (c < 0x40 || (c >= 0x7F && c <= 0xA0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2764 return 0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2765 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2766 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2767 label_end_of_loop:
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2768 return CODING_CATEGORY_MASK_BIG5;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2769 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2770
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2771 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2772 Check if a text is encoded in UTF-8. If it is, return
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2773 CODING_CATEGORY_MASK_UTF_8, else return 0. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2774
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2775 #define UTF_8_1_OCTET_P(c) ((c) < 0x80)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2776 #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2777 #define UTF_8_2_OCTET_LEADING_P(c) (((c) & 0xE0) == 0xC0)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2778 #define UTF_8_3_OCTET_LEADING_P(c) (((c) & 0xF0) == 0xE0)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2779 #define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2780 #define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2781 #define UTF_8_6_OCTET_LEADING_P(c) (((c) & 0xFE) == 0xFC)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2782
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2783 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2784 detect_coding_utf_8 (src, src_end, multibytep)
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2785 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2786 int multibytep;
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2787 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2788 unsigned char c;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2789 int seq_maybe_bytes;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2790 /* Dummy for ONE_MORE_BYTE. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2791 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2792 struct coding_system *coding = &dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2793
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2794 while (1)
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2795 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2796 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2797 if (UTF_8_1_OCTET_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2798 continue;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2799 else if (UTF_8_2_OCTET_LEADING_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2800 seq_maybe_bytes = 1;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2801 else if (UTF_8_3_OCTET_LEADING_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2802 seq_maybe_bytes = 2;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2803 else if (UTF_8_4_OCTET_LEADING_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2804 seq_maybe_bytes = 3;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2805 else if (UTF_8_5_OCTET_LEADING_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2806 seq_maybe_bytes = 4;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2807 else if (UTF_8_6_OCTET_LEADING_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2808 seq_maybe_bytes = 5;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2809 else
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2810 return 0;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2811
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2812 do
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2813 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2814 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2815 if (!UTF_8_EXTRA_OCTET_P (c))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2816 return 0;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2817 seq_maybe_bytes--;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2818 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2819 while (seq_maybe_bytes > 0);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2820 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2821
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2822 label_end_of_loop:
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2823 return CODING_CATEGORY_MASK_UTF_8;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2824 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2825
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2826 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2827 Check if a text is encoded in UTF-16 Big Endian (endian == 1) or
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2828 Little Endian (otherwise). If it is, return
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2829 CODING_CATEGORY_MASK_UTF_16_BE or CODING_CATEGORY_MASK_UTF_16_LE,
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2830 else return 0. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2831
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2832 #define UTF_16_INVALID_P(val) \
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2833 (((val) == 0xFFFE) \
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2834 || ((val) == 0xFFFF))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2835
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2836 #define UTF_16_HIGH_SURROGATE_P(val) \
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2837 (((val) & 0xD800) == 0xD800)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2838
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2839 #define UTF_16_LOW_SURROGATE_P(val) \
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2840 (((val) & 0xDC00) == 0xDC00)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2841
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2842 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2843 detect_coding_utf_16 (src, src_end, multibytep)
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2844 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2845 int multibytep;
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2846 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2847 unsigned char c1, c2;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2848 /* Dummy for TWO_MORE_BYTES. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2849 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2850 struct coding_system *coding = &dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2851
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2852 ONE_MORE_BYTE_CHECK_MULTIBYTE (c1, multibytep);
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
2853 ONE_MORE_BYTE_CHECK_MULTIBYTE (c2, multibytep);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2854
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2855 if ((c1 == 0xFF) && (c2 == 0xFE))
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2856 return CODING_CATEGORY_MASK_UTF_16_LE;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2857 else if ((c1 == 0xFE) && (c2 == 0xFF))
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2858 return CODING_CATEGORY_MASK_UTF_16_BE;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2859
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2860 label_end_of_loop:
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2861 return 0;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2862 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
2863
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2864 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2865 If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2866
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2867 static void
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2868 decode_coding_sjis_big5 (coding, source, destination,
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2869 src_bytes, dst_bytes, sjis_p)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2870 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2871 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2872 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2873 int sjis_p;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2874 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2875 unsigned char *src = source;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2876 unsigned char *src_end = source + src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2877 unsigned char *dst = destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2878 unsigned char *dst_end = destination + dst_bytes;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2879 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2880 The loop will be exited when there's not enough source code
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2881 (within macro ONE_MORE_BYTE), or when there's not enough
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2882 destination area to produce a character (within macro
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2883 EMIT_CHAR). */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2884 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2885 Lisp_Object translation_table;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2886
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2887 if (NILP (Venable_character_translation))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2888 translation_table = Qnil;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2889 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2890 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2891 translation_table = coding->translation_table_for_decode;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2892 if (NILP (translation_table))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2893 translation_table = Vstandard_translation_table_for_decode;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2894 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2895
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2896 coding->produced_char = 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2897 while (1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2898 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2899 int c, charset, c1, c2;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2900
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2901 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2902 ONE_MORE_BYTE (c1);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2903
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2904 if (c1 < 0x80)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2905 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2906 charset = CHARSET_ASCII;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2907 if (c1 < 0x20)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2908 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2909 if (c1 == '\r')
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2910 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2911 if (coding->eol_type == CODING_EOL_CRLF)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2912 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2913 ONE_MORE_BYTE (c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2914 if (c2 == '\n')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2915 c1 = c2;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2916 else if (coding->mode
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2917 & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2918 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2919 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2920 goto label_end_of_loop;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2921 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2922 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2923 /* To process C2 again, SRC is subtracted by 1. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2924 src--;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2925 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2926 else if (coding->eol_type == CODING_EOL_CR)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2927 c1 = '\n';
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2928 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2929 else if (c1 == '\n'
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2930 && (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2931 && (coding->eol_type == CODING_EOL_CR
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2932 || coding->eol_type == CODING_EOL_CRLF))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2933 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2934 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2935 goto label_end_of_loop;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2936 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2937 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2938 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2939 else
24870
b0f6eab5deeb (decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents: 24822
diff changeset
2940 {
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2941 if (sjis_p)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2942 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2943 if (c1 >= 0xF0)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2944 goto label_invalid_code;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2945 if (c1 < 0xA0 || c1 >= 0xE0)
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2946 {
22616
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
2947 /* SJIS -> JISX0208 */
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
2948 ONE_MORE_BYTE (c2);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2949 if (c2 < 0x40 || c2 == 0x7F || c2 > 0xFC)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2950 goto label_invalid_code;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2951 DECODE_SJIS (c1, c2, c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2952 charset = charset_jisx0208;
24870
b0f6eab5deeb (decode_coding_sjis_big5): Avoid compiler warning.
Kenichi Handa <handa@m17n.org>
parents: 24822
diff changeset
2953 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2954 else
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2955 /* SJIS -> JISX0201-Kana */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2956 charset = charset_katakana_jisx0201;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2957 }
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2958 else
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2959 {
22616
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
2960 /* BIG5 -> Big5 */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2961 if (c1 < 0xA1 || c1 > 0xFE)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2962 goto label_invalid_code;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2963 ONE_MORE_BYTE (c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2964 if (c2 < 0x40 || (c2 > 0x7E && c2 < 0xA1) || c2 > 0xFE)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2965 goto label_invalid_code;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2966 DECODE_BIG5 (c1, c2, charset, c1, c2);
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2967 }
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2968 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2969
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2970 c = DECODE_ISO_CHARACTER (charset, c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2971 EMIT_CHAR (c);
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2972 continue;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
2973
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2974 label_invalid_code:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2975 coding->errors++;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2976 src = src_base;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2977 c = *src++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2978 EMIT_CHAR (c);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2979 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2980
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2981 label_end_of_loop:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2982 coding->consumed = coding->consumed_char = src_base - source;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2983 coding->produced = dst - destination;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2984 return;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2985 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2986
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2987 /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions".
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2988 This function can encode charsets `ascii', `katakana-jisx0201',
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2989 `japanese-jisx0208', `chinese-big5-1', and `chinese-big5-2'. We
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2990 are sure that all these charsets are registered as official charset
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2991 (i.e. do not have extended leading-codes). Characters of other
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2992 charsets are produced without any encoding. If SJIS_P is 1, encode
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2993 SJIS text, else encode BIG5 text. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2994
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
2995 static void
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2996 encode_coding_sjis_big5 (coding, source, destination,
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
2997 src_bytes, dst_bytes, sjis_p)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2998 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2999 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3000 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3001 int sjis_p;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3002 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3003 unsigned char *src = source;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3004 unsigned char *src_end = source + src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3005 unsigned char *dst = destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3006 unsigned char *dst_end = destination + dst_bytes;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3007 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3008 The loop will be exited when there's not enough source text to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3009 analyze multi-byte codes (within macro ONE_MORE_CHAR), or when
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3010 there's not enough destination area to produce encoded codes
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3011 (within macro EMIT_BYTES). */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3012 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3013 Lisp_Object translation_table;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3014
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3015 if (NILP (Venable_character_translation))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3016 translation_table = Qnil;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3017 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3018 {
31455
0b33b8c5d16e (encode_coding_sjis_big5): Use translation table for
Kenichi Handa <handa@m17n.org>
parents: 31123
diff changeset
3019 translation_table = coding->translation_table_for_encode;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3020 if (NILP (translation_table))
31455
0b33b8c5d16e (encode_coding_sjis_big5): Use translation table for
Kenichi Handa <handa@m17n.org>
parents: 31123
diff changeset
3021 translation_table = Vstandard_translation_table_for_encode;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3022 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3023
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3024 while (1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3025 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3026 int c, charset, c1, c2;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3027
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3028 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3029 ONE_MORE_CHAR (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3030
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3031 /* Now encode the character C. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3032 if (SINGLE_BYTE_CHAR_P (c))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3033 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3034 switch (c)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3035 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3036 case '\r':
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3037 if (!coding->mode & CODING_MODE_SELECTIVE_DISPLAY)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3038 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3039 EMIT_ONE_BYTE (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3040 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3041 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3042 c = '\n';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3043 case '\n':
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3044 if (coding->eol_type == CODING_EOL_CRLF)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3045 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3046 EMIT_TWO_BYTES ('\r', c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3047 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3048 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3049 else if (coding->eol_type == CODING_EOL_CR)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3050 c = '\r';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3051 default:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3052 EMIT_ONE_BYTE (c);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3053 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3054 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3055 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3056 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3057 SPLIT_CHAR (c, charset, c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3058 if (sjis_p)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3059 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3060 if (charset == charset_jisx0208
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3061 || charset == charset_jisx0208_1978)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3062 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3063 ENCODE_SJIS (c1, c2, c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3064 EMIT_TWO_BYTES (c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3065 }
31455
0b33b8c5d16e (encode_coding_sjis_big5): Use translation table for
Kenichi Handa <handa@m17n.org>
parents: 31123
diff changeset
3066 else if (charset == charset_katakana_jisx0201)
0b33b8c5d16e (encode_coding_sjis_big5): Use translation table for
Kenichi Handa <handa@m17n.org>
parents: 31123
diff changeset
3067 EMIT_ONE_BYTE (c1 | 0x80);
31457
b1c66af9aba5 (encode_coding_sjis_big5): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 31455
diff changeset
3068 else if (charset == charset_latin_jisx0201)
b1c66af9aba5 (encode_coding_sjis_big5): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 31455
diff changeset
3069 EMIT_ONE_BYTE (c1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3070 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3071 /* There's no way other than producing the internal
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3072 codes as is. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3073 EMIT_BYTES (src_base, src);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3074 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3075 else
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3076 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3077 if (charset == charset_big5_1 || charset == charset_big5_2)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3078 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3079 ENCODE_BIG5 (charset, c1, c2, c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3080 EMIT_TWO_BYTES (c1, c2);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3081 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3082 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3083 /* There's no way other than producing the internal
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3084 codes as is. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3085 EMIT_BYTES (src_base, src);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3086 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3087 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3088 coding->consumed_char++;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3089 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3090
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3091 label_end_of_loop:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3092 coding->consumed = src_base - source;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3093 coding->produced = coding->produced_char = dst - destination;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3094 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3095
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3096
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3097 /*** 5. CCL handlers ***/
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3098
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3099 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3100 Check if a text is encoded in a coding system of which
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3101 encoder/decoder are written in CCL program. If it is, return
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3102 CODING_CATEGORY_MASK_CCL, else return 0. */
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3103
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3104 static int
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3105 detect_coding_ccl (src, src_end, multibytep)
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3106 unsigned char *src, *src_end;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3107 int multibytep;
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3108 {
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3109 unsigned char *valid;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3110 int c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3111 /* Dummy for ONE_MORE_BYTE. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3112 struct coding_system dummy_coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3113 struct coding_system *coding = &dummy_coding;
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3114
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3115 /* No coding system is assigned to coding-category-ccl. */
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3116 if (!coding_system_table[CODING_CATEGORY_IDX_CCL])
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3117 return 0;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3118
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3119 valid = coding_system_table[CODING_CATEGORY_IDX_CCL]->spec.ccl.valid_codes;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3120 while (1)
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3121 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3122 ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3123 if (! valid[c])
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3124 return 0;
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3125 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3126 label_end_of_loop:
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3127 return CODING_CATEGORY_MASK_CCL;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3128 }
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3129
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3130
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3131 /*** 6. End-of-line handlers ***/
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3132
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3133 /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3134
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3135 static void
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3136 decode_eol (coding, source, destination, src_bytes, dst_bytes)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3137 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3138 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3139 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3140 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3141 unsigned char *src = source;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3142 unsigned char *dst = destination;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3143 unsigned char *src_end = src + src_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3144 unsigned char *dst_end = dst + dst_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3145 Lisp_Object translation_table;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3146 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3147 The loop will be exited when there's not enough source code
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3148 (within macro ONE_MORE_BYTE), or when there's not enough
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3149 destination area to produce a character (within macro
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3150 EMIT_CHAR). */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3151 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3152 int c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3153
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3154 translation_table = Qnil;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3155 switch (coding->eol_type)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3156 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3157 case CODING_EOL_CRLF:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3158 while (1)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3159 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3160 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3161 ONE_MORE_BYTE (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3162 if (c == '\r')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3163 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3164 ONE_MORE_BYTE (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3165 if (c != '\n')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3166 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3167 if (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3168 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3169 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3170 goto label_end_of_loop;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3171 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3172 src--;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3173 c = '\r';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3174 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3175 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3176 else if (c == '\n'
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3177 && (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3178 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3179 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3180 goto label_end_of_loop;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3181 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3182 EMIT_CHAR (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3183 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3184 break;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3185
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3186 case CODING_EOL_CR:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3187 while (1)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3188 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3189 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3190 ONE_MORE_BYTE (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3191 if (c == '\n')
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
3192 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3193 if (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3194 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3195 coding->result = CODING_FINISH_INCONSISTENT_EOL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3196 goto label_end_of_loop;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3197 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
3198 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3199 else if (c == '\r')
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3200 c = '\n';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3201 EMIT_CHAR (c);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3202 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3203 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3204
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3205 default: /* no need for EOL handling */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3206 while (1)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3207 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3208 src_base = src;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3209 ONE_MORE_BYTE (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3210 EMIT_CHAR (c);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3211 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3212 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3213
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3214 label_end_of_loop:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3215 coding->consumed = coding->consumed_char = src_base - source;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3216 coding->produced = dst - destination;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3217 return;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3218 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3219
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3220 /* See "GENERAL NOTES about `encode_coding_XXX ()' functions". Encode
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3221 format of end-of-line according to `coding->eol_type'. It also
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3222 convert multibyte form 8-bit characers to unibyte if
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3223 CODING->src_multibyte is nonzero. If `coding->mode &
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3224 CODING_MODE_SELECTIVE_DISPLAY' is nonzero, code '\r' in source text
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3225 also means end-of-line. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3226
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3227 static void
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3228 encode_eol (coding, source, destination, src_bytes, dst_bytes)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3229 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3230 unsigned char *source, *destination;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3231 int src_bytes, dst_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3232 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3233 unsigned char *src = source;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3234 unsigned char *dst = destination;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3235 unsigned char *src_end = src + src_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3236 unsigned char *dst_end = dst + dst_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3237 Lisp_Object translation_table;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3238 /* SRC_BASE remembers the start position in source in each loop.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3239 The loop will be exited when there's not enough source text to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3240 analyze multi-byte codes (within macro ONE_MORE_CHAR), or when
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3241 there's not enough destination area to produce encoded codes
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3242 (within macro EMIT_BYTES). */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3243 unsigned char *src_base;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3244 int c;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3245 int selective_display = coding->mode & CODING_MODE_SELECTIVE_DISPLAY;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3246
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3247 translation_table = Qnil;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3248 if (coding->src_multibyte
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3249 && *(src_end - 1) == LEADING_CODE_8_BIT_CONTROL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3250 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3251 src_end--;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3252 src_bytes--;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3253 coding->result = CODING_FINISH_INSUFFICIENT_SRC;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3254 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
3255
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3256 if (coding->eol_type == CODING_EOL_CRLF)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3257 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3258 while (src < src_end)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3259 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3260 src_base = src;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3261 c = *src++;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3262 if (c >= 0x20)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3263 EMIT_ONE_BYTE (c);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3264 else if (c == '\n' || (c == '\r' && selective_display))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3265 EMIT_TWO_BYTES ('\r', '\n');
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3266 else
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3267 EMIT_ONE_BYTE (c);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3268 }
29093
176708661b08 (encode_eol): Fix a bug of DOS style EOL encoding.
Kenichi Handa <handa@m17n.org>
parents: 29005
diff changeset
3269 src_base = src;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3270 label_end_of_loop:
29182
1d1c27067af4 (encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents: 29172
diff changeset
3271 ;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3272 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3273 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3274 {
31123
097593e77185 (encode_eol): Fix bug for the case of dst_bytes being zero. Set
Kenichi Handa <handa@m17n.org>
parents: 30951
diff changeset
3275 if (!dst_bytes || src_bytes <= dst_bytes)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3276 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3277 safe_bcopy (src, dst, src_bytes);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3278 src_base = src_end;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3279 dst += src_bytes;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3280 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
3281 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3282 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3283 if (coding->src_multibyte
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3284 && *(src + dst_bytes - 1) == LEADING_CODE_8_BIT_CONTROL)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3285 dst_bytes--;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3286 safe_bcopy (src, dst, dst_bytes);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3287 src_base = src + dst_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3288 dst = destination + dst_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3289 coding->result = CODING_FINISH_INSUFFICIENT_DST;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3290 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3291 if (coding->eol_type == CODING_EOL_CR)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3292 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3293 for (src = destination; src < dst; src++)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3294 if (*src == '\n') *src = '\r';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3295 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3296 else if (selective_display)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3297 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3298 for (src = destination; src < dst; src++)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3299 if (*src == '\r') *src = '\n';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3300 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3301 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3302 if (coding->src_multibyte)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3303 dst = destination + str_as_unibyte (destination, dst - destination);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3304
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3305 coding->consumed = src_base - source;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
3306 coding->produced = dst - destination;
31123
097593e77185 (encode_eol): Fix bug for the case of dst_bytes being zero. Set
Kenichi Handa <handa@m17n.org>
parents: 30951
diff changeset
3307 coding->produced_char = coding->produced;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3308 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3309
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3310
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3311 /*** 7. C library functions ***/
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3312
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3313 /* In Emacs Lisp, coding system is represented by a Lisp symbol which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3314 has a property `coding-system'. The value of this property is a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3315 vector of length 5 (called as coding-vector). Among elements of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3316 this vector, the first (element[0]) and the fifth (element[4])
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3317 carry important information for decoding/encoding. Before
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3318 decoding/encoding, this information should be set in fields of a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3319 structure of type `coding_system'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3320
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3321 A value of property `coding-system' can be a symbol of another
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3322 subsidiary coding-system. In that case, Emacs gets coding-vector
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3323 from that symbol.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3324
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3325 `element[0]' contains information to be set in `coding->type'. The
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3326 value and its meaning is as follows:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3327
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3328 0 -- coding_type_emacs_mule
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3329 1 -- coding_type_sjis
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3330 2 -- coding_type_iso2022
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3331 3 -- coding_type_big5
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3332 4 -- coding_type_ccl encoder/decoder written in CCL
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3333 nil -- coding_type_no_conversion
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3334 t -- coding_type_undecided (automatic conversion on decoding,
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3335 no-conversion on encoding)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3336
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3337 `element[4]' contains information to be set in `coding->flags' and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3338 `coding->spec'. The meaning varies by `coding->type'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3339
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3340 If `coding->type' is `coding_type_iso2022', element[4] is a vector
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3341 of length 32 (of which the first 13 sub-elements are used now).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3342 Meanings of these sub-elements are:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3343
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3344 sub-element[N] where N is 0 through 3: to be set in `coding->spec.iso2022'
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3345 If the value is an integer of valid charset, the charset is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3346 assumed to be designated to graphic register N initially.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3347
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3348 If the value is minus, it is a minus value of charset which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3349 reserves graphic register N, which means that the charset is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3350 not designated initially but should be designated to graphic
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3351 register N just before encoding a character in that charset.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3352
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3353 If the value is nil, graphic register N is never used on
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3354 encoding.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3355
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3356 sub-element[N] where N is 4 through 11: to be set in `coding->flags'
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3357 Each value takes t or nil. See the section ISO2022 of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3358 `coding.h' for more information.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3359
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3360 If `coding->type' is `coding_type_big5', element[4] is t to denote
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3361 BIG5-ETen or nil to denote BIG5-HKU.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3362
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3363 If `coding->type' takes the other value, element[4] is ignored.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3364
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3365 Emacs Lisp's coding system also carries information about format of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3366 end-of-line in a value of property `eol-type'. If the value is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3367 integer, 0 means CODING_EOL_LF, 1 means CODING_EOL_CRLF, and 2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3368 means CODING_EOL_CR. If it is not integer, it should be a vector
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3369 of subsidiary coding systems of which property `eol-type' has one
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3370 of above values.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3371
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3372 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3373
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3374 /* Extract information for decoding/encoding from CODING_SYSTEM_SYMBOL
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3375 and set it in CODING. If CODING_SYSTEM_SYMBOL is invalid, CODING
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3376 is setup so that no conversion is necessary and return -1, else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3377 return 0. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3378
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3379 int
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
3380 setup_coding_system (coding_system, coding)
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
3381 Lisp_Object coding_system;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3382 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3383 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3384 Lisp_Object coding_spec, coding_type, eol_type, plist;
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3385 Lisp_Object val;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3386
34591
9d5d795f9315 (setup_coding_system): Clear all members of the struct
Kenichi Handa <handa@m17n.org>
parents: 34536
diff changeset
3387 /* At first, zero clear all members. */
9d5d795f9315 (setup_coding_system): Clear all members of the struct
Kenichi Handa <handa@m17n.org>
parents: 34536
diff changeset
3388 bzero (coding, sizeof (struct coding_system));
9d5d795f9315 (setup_coding_system): Clear all members of the struct
Kenichi Handa <handa@m17n.org>
parents: 34536
diff changeset
3389
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3390 /* Initialize some fields required for all kinds of coding systems. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3391 coding->symbol = coding_system;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3392 coding->heading_ascii = -1;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3393 coding->post_read_conversion = coding->pre_write_conversion = Qnil;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3394 coding->composing = COMPOSITION_DISABLED;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3395 coding->cmp_data = NULL;
24460
be35d27a4bfb (setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents: 24425
diff changeset
3396
be35d27a4bfb (setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents: 24425
diff changeset
3397 if (NILP (coding_system))
be35d27a4bfb (setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents: 24425
diff changeset
3398 goto label_invalid_coding_system;
be35d27a4bfb (setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents: 24425
diff changeset
3399
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3400 coding_spec = Fget (coding_system, Qcoding_system);
24460
be35d27a4bfb (setup_coding_system): Check for CODING_SYSTEM = nil.
Kenichi Handa <handa@m17n.org>
parents: 24425
diff changeset
3401
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3402 if (!VECTORP (coding_spec)
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3403 || XVECTOR (coding_spec)->size != 5
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3404 || !CONSP (XVECTOR (coding_spec)->contents[3]))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3405 goto label_invalid_coding_system;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3406
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3407 eol_type = inhibit_eol_conversion ? Qnil : Fget (coding_system, Qeol_type);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3408 if (VECTORP (eol_type))
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3409 {
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3410 coding->eol_type = CODING_EOL_UNDECIDED;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3411 coding->common_flags = CODING_REQUIRE_DETECTION_MASK;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3412 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3413 else if (XFASTINT (eol_type) == 1)
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3414 {
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3415 coding->eol_type = CODING_EOL_CRLF;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3416 coding->common_flags
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3417 = CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3418 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3419 else if (XFASTINT (eol_type) == 2)
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3420 {
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3421 coding->eol_type = CODING_EOL_CR;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3422 coding->common_flags
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3423 = CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3424 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3425 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3426 coding->eol_type = CODING_EOL_LF;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3427
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3428 coding_type = XVECTOR (coding_spec)->contents[0];
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3429 /* Try short cut. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3430 if (SYMBOLP (coding_type))
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3431 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3432 if (EQ (coding_type, Qt))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3433 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3434 coding->type = coding_type_undecided;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3435 coding->common_flags |= CODING_REQUIRE_DETECTION_MASK;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3436 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3437 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3438 coding->type = coding_type_no_conversion;
34197
78561a43cdd1 (setup_coding_system): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 33931
diff changeset
3439 /* Initialize this member. Any thing other than
78561a43cdd1 (setup_coding_system): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 33931
diff changeset
3440 CODING_CATEGORY_IDX_UTF_16_BE and
78561a43cdd1 (setup_coding_system): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 33931
diff changeset
3441 CODING_CATEGORY_IDX_UTF_16_LE are ok because they have
78561a43cdd1 (setup_coding_system): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 33931
diff changeset
3442 special treatment in detect_eol. */
78561a43cdd1 (setup_coding_system): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 33931
diff changeset
3443 coding->category_idx = CODING_CATEGORY_IDX_EMACS_MULE;
78561a43cdd1 (setup_coding_system): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 33931
diff changeset
3444
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3445 return 0;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3446 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3447
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3448 /* Get values of coding system properties:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3449 `post-read-conversion', `pre-write-conversion',
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3450 `translation-table-for-decode', `translation-table-for-encode'. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3451 plist = XVECTOR (coding_spec)->contents[3];
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3452 /* Pre & post conversion functions should be disabled if
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3453 inhibit_eol_conversion is nozero. This is the case that a code
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3454 conversion function is called while those functions are running. */
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3455 if (! inhibit_pre_post_conversion)
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3456 {
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3457 coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion);
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3458 coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion);
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
3459 }
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3460 val = Fplist_get (plist, Qtranslation_table_for_decode);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3461 if (SYMBOLP (val))
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3462 val = Fget (val, Qtranslation_table_for_decode);
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3463 coding->translation_table_for_decode = CHAR_TABLE_P (val) ? val : Qnil;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3464 val = Fplist_get (plist, Qtranslation_table_for_encode);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3465 if (SYMBOLP (val))
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3466 val = Fget (val, Qtranslation_table_for_encode);
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
3467 coding->translation_table_for_encode = CHAR_TABLE_P (val) ? val : Qnil;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3468 val = Fplist_get (plist, Qcoding_category);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3469 if (!NILP (val))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3470 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3471 val = Fget (val, Qcoding_category_index);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3472 if (INTEGERP (val))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3473 coding->category_idx = XINT (val);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3474 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3475 goto label_invalid_coding_system;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3476 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3477 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3478 goto label_invalid_coding_system;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3479
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3480 /* If the coding system has non-nil `composition' property, enable
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3481 composition handling. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3482 val = Fplist_get (plist, Qcomposition);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3483 if (!NILP (val))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3484 coding->composing = COMPOSITION_NO;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3485
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3486 switch (XFASTINT (coding_type))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3487 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3488 case 0:
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3489 coding->type = coding_type_emacs_mule;
34888
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
3490 coding->common_flags
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
3491 |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
b469d29c0815 (SAFE_ONE_MORE_BYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34813
diff changeset
3492 coding->composing = COMPOSITION_NO;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3493 if (!NILP (coding->post_read_conversion))
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3494 coding->common_flags |= CODING_REQUIRE_DECODING_MASK;
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3495 if (!NILP (coding->pre_write_conversion))
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3496 coding->common_flags |= CODING_REQUIRE_ENCODING_MASK;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3497 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3498
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3499 case 1:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3500 coding->type = coding_type_sjis;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3501 coding->common_flags
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3502 |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3503 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3504
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3505 case 2:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3506 coding->type = coding_type_iso2022;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3507 coding->common_flags
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3508 |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3509 {
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3510 Lisp_Object val, temp;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3511 Lisp_Object *flags;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3512 int i, charset, reg_bits = 0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3513
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3514 val = XVECTOR (coding_spec)->contents[4];
19747
bed06df9cbc5 (setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents: 19743
diff changeset
3515
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3516 if (!VECTORP (val) || XVECTOR (val)->size != 32)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3517 goto label_invalid_coding_system;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3518
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3519 flags = XVECTOR (val)->contents;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3520 coding->flags
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3521 = ((NILP (flags[4]) ? 0 : CODING_FLAG_ISO_SHORT_FORM)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3522 | (NILP (flags[5]) ? 0 : CODING_FLAG_ISO_RESET_AT_EOL)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3523 | (NILP (flags[6]) ? 0 : CODING_FLAG_ISO_RESET_AT_CNTL)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3524 | (NILP (flags[7]) ? 0 : CODING_FLAG_ISO_SEVEN_BITS)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3525 | (NILP (flags[8]) ? 0 : CODING_FLAG_ISO_LOCKING_SHIFT)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3526 | (NILP (flags[9]) ? 0 : CODING_FLAG_ISO_SINGLE_SHIFT)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3527 | (NILP (flags[10]) ? 0 : CODING_FLAG_ISO_USE_ROMAN)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3528 | (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
3529 | (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
3530 | (NILP (flags[13]) ? 0 : CODING_FLAG_ISO_INIT_AT_BOL)
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
3531 | (NILP (flags[14]) ? 0 : CODING_FLAG_ISO_DESIGNATE_AT_BOL)
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
3532 | (NILP (flags[15]) ? 0 : CODING_FLAG_ISO_SAFE)
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
3533 | (NILP (flags[16]) ? 0 : CODING_FLAG_ISO_LATIN_EXTRA)
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
3534 );
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3535
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3536 /* Invoke graphic register 0 to plane 0. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3537 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3538 /* Invoke graphic register 1 to plane 1 if we can use full 8-bit. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3539 CODING_SPEC_ISO_INVOCATION (coding, 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3540 = (coding->flags & CODING_FLAG_ISO_SEVEN_BITS ? -1 : 1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3541 /* Not single shifting at first. */
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
3542 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
3543 /* Beginning of buffer should also be regarded as bol. */
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
3544 CODING_SPEC_ISO_BOL (coding) = 1;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3545
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3546 for (charset = 0; charset <= MAX_CHARSET; charset++)
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3547 CODING_SPEC_ISO_REVISION_NUMBER (coding, charset) = 255;
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3548 val = Vcharset_revision_alist;
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3549 while (CONSP (val))
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3550 {
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3551 charset = get_charset_id (Fcar_safe (XCAR (val)));
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3552 if (charset >= 0
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3553 && (temp = Fcdr_safe (XCAR (val)), INTEGERP (temp))
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3554 && (i = XINT (temp), (i >= 0 && (i + '@') < 128)))
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3555 CODING_SPEC_ISO_REVISION_NUMBER (coding, charset) = i;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3556 val = XCDR (val);
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3557 }
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3558
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3559 /* Checks FLAGS[REG] (REG = 0, 1, 2 3) and decide designations.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3560 FLAGS[REG] can be one of below:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3561 integer CHARSET: CHARSET occupies register I,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3562 t: designate nothing to REG initially, but can be used
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3563 by any charsets,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3564 list of integer, nil, or t: designate the first
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3565 element (if integer) to REG initially, the remaining
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3566 elements (if integer) is designated to REG on request,
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3567 if an element is t, REG can be used by any charsets,
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3568 nil: REG is never used. */
17190
6637001cdb4b Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents: 17137
diff changeset
3569 for (charset = 0; charset <= MAX_CHARSET; charset++)
18002
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
3570 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
3571 = CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3572 for (i = 0; i < 4; i++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3573 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3574 if (INTEGERP (flags[i])
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
3575 && (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
3576 || (charset = get_charset_id (flags[i])) >= 0)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3577 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3578 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3579 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) = i;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3580 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3581 else if (EQ (flags[i], Qt))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3582 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3583 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3584 reg_bits |= 1 << i;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3585 coding->flags |= CODING_FLAG_ISO_DESIGNATION;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3586 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3587 else if (CONSP (flags[i]))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3588 {
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
3589 Lisp_Object tail;
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
3590 tail = flags[i];
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3591
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3592 coding->flags |= CODING_FLAG_ISO_DESIGNATION;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3593 if (INTEGERP (XCAR (tail))
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3594 && (charset = XINT (XCAR (tail)),
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
3595 CHARSET_VALID_P (charset))
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3596 || (charset = get_charset_id (XCAR (tail))) >= 0)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3597 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3598 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3599 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) =i;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3600 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3601 else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3602 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3603 tail = XCDR (tail);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3604 while (CONSP (tail))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3605 {
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3606 if (INTEGERP (XCAR (tail))
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3607 && (charset = XINT (XCAR (tail)),
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
3608 CHARSET_VALID_P (charset))
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3609 || (charset = get_charset_id (XCAR (tail))) >= 0)
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3610 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
3611 = i;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3612 else if (EQ (XCAR (tail), Qt))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3613 reg_bits |= 1 << i;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3614 tail = XCDR (tail);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3615 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3616 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3617 else
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3618 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3619
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3620 CODING_SPEC_ISO_DESIGNATION (coding, i)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3621 = CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3622 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3623
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3624 if (reg_bits && ! (coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3625 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3626 /* REG 1 can be used only by locking shift in 7-bit env. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3627 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3628 reg_bits &= ~2;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3629 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3630 /* Without any shifting, only REG 0 and 1 can be used. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3631 reg_bits &= 3;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3632 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3633
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3634 if (reg_bits)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3635 for (charset = 0; charset <= MAX_CHARSET; charset++)
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
3636 {
30263
b8083f5b4b7c (setup_coding_system): Don't override the explicitly specified
Kenichi Handa <handa@m17n.org>
parents: 30204
diff changeset
3637 if (CHARSET_VALID_P (charset)
b8083f5b4b7c (setup_coding_system): Don't override the explicitly specified
Kenichi Handa <handa@m17n.org>
parents: 30204
diff changeset
3638 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
b8083f5b4b7c (setup_coding_system): Don't override the explicitly specified
Kenichi Handa <handa@m17n.org>
parents: 30204
diff changeset
3639 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3640 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3641 /* There exist some default graphic registers to be
30263
b8083f5b4b7c (setup_coding_system): Don't override the explicitly specified
Kenichi Handa <handa@m17n.org>
parents: 30204
diff changeset
3642 used by CHARSET. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3643
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3644 /* We had better avoid designating a charset of
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3645 CHARS96 to REG 0 as far as possible. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3646 if (CHARSET_CHARS (charset) == 96)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3647 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3648 = (reg_bits & 2
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3649 ? 1 : (reg_bits & 4 ? 2 : (reg_bits & 8 ? 3 : 0)));
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3650 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3651 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3652 = (reg_bits & 1
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3653 ? 0 : (reg_bits & 2 ? 1 : (reg_bits & 4 ? 2 : 3)));
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3654 }
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
3655 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3656 }
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3657 coding->common_flags |= CODING_REQUIRE_FLUSHING_MASK;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3658 coding->spec.iso2022.last_invalid_designation_register = -1;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3659 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3660
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3661 case 3:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3662 coding->type = coding_type_big5;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3663 coding->common_flags
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3664 |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3665 coding->flags
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
3666 = (NILP (XVECTOR (coding_spec)->contents[4])
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3667 ? CODING_FLAG_BIG5_HKU
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3668 : CODING_FLAG_BIG5_ETEN);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3669 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3670
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3671 case 4:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3672 coding->type = coding_type_ccl;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3673 coding->common_flags
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3674 |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3675 {
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
3676 val = XVECTOR (coding_spec)->contents[4];
25067
23910b121ced (setup_coding_system): Get compiled CCL code by just
Kenichi Handa <handa@m17n.org>
parents: 24870
diff changeset
3677 if (! CONSP (val)
23910b121ced (setup_coding_system): Get compiled CCL code by just
Kenichi Handa <handa@m17n.org>
parents: 24870
diff changeset
3678 || setup_ccl_program (&(coding->spec.ccl.decoder),
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3679 XCAR (val)) < 0
25067
23910b121ced (setup_coding_system): Get compiled CCL code by just
Kenichi Handa <handa@m17n.org>
parents: 24870
diff changeset
3680 || setup_ccl_program (&(coding->spec.ccl.encoder),
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3681 XCDR (val)) < 0)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3682 goto label_invalid_coding_system;
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3683
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3684 bzero (coding->spec.ccl.valid_codes, 256);
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3685 val = Fplist_get (plist, Qvalid_codes);
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3686 if (CONSP (val))
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3687 {
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3688 Lisp_Object this;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3689
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3690 for (; CONSP (val); val = XCDR (val))
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3691 {
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3692 this = XCAR (val);
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3693 if (INTEGERP (this)
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3694 && XINT (this) >= 0 && XINT (this) < 256)
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3695 coding->spec.ccl.valid_codes[XINT (this)] = 1;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3696 else if (CONSP (this)
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3697 && INTEGERP (XCAR (this))
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3698 && INTEGERP (XCDR (this)))
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3699 {
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3700 int start = XINT (XCAR (this));
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
3701 int end = XINT (XCDR (this));
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3702
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3703 if (start >= 0 && start <= end && end < 256)
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
3704 while (start <= end)
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3705 coding->spec.ccl.valid_codes[start++] = 1;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3706 }
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3707 }
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3708 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3709 }
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3710 coding->common_flags |= CODING_REQUIRE_FLUSHING_MASK;
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
3711 coding->spec.ccl.cr_carryover = 0;
34892
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
3712 coding->spec.ccl.eight_bit_carryover[0] = 0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3713 break;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3714
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
3715 case 5:
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
3716 coding->type = coding_type_raw_text;
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
3717 break;
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
3718
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3719 default:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3720 goto label_invalid_coding_system;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3721 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3722 return 0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3723
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3724 label_invalid_coding_system:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3725 coding->type = coding_type_no_conversion;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3726 coding->category_idx = CODING_CATEGORY_IDX_BINARY;
20227
71008f909642 (setup_coding_system): Initialize common_flags member
Kenichi Handa <handa@m17n.org>
parents: 20150
diff changeset
3727 coding->common_flags = 0;
17485
abfa77a2693b (setup_coding_system): Setup coding->eol_type as LF
Kenichi Handa <handa@m17n.org>
parents: 17368
diff changeset
3728 coding->eol_type = CODING_EOL_LF;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3729 coding->pre_write_conversion = coding->post_read_conversion = Qnil;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3730 return -1;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3731 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3732
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3733 /* Free memory blocks allocated for storing composition information. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3734
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3735 void
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3736 coding_free_composition_data (coding)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3737 struct coding_system *coding;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3738 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3739 struct composition_data *cmp_data = coding->cmp_data, *next;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3740
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3741 if (!cmp_data)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3742 return;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3743 /* Memory blocks are chained. At first, rewind to the first, then,
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3744 free blocks one by one. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3745 while (cmp_data->prev)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3746 cmp_data = cmp_data->prev;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3747 while (cmp_data)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3748 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3749 next = cmp_data->next;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3750 xfree (cmp_data);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3751 cmp_data = next;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3752 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3753 coding->cmp_data = NULL;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3754 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3755
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3756 /* Set `char_offset' member of all memory blocks pointed by
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3757 coding->cmp_data to POS. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3758
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3759 void
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3760 coding_adjust_composition_offset (coding, pos)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3761 struct coding_system *coding;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3762 int pos;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3763 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3764 struct composition_data *cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3765
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3766 for (cmp_data = coding->cmp_data; cmp_data; cmp_data = cmp_data->next)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3767 cmp_data->char_offset = pos;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3768 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
3769
22616
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3770 /* Setup raw-text or one of its subsidiaries in the structure
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3771 coding_system CODING according to the already setup value eol_type
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3772 in CODING. CODING should be setup for some coding system in
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3773 advance. */
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3774
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3775 void
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3776 setup_raw_text_coding_system (coding)
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3777 struct coding_system *coding;
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3778 {
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3779 if (coding->type != coding_type_raw_text)
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3780 {
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3781 coding->symbol = Qraw_text;
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3782 coding->type = coding_type_raw_text;
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3783 if (coding->eol_type != CODING_EOL_UNDECIDED)
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3784 {
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
3785 Lisp_Object subsidiaries;
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
3786 subsidiaries = Fget (Qraw_text, Qeol_type);
22616
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3787
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3788 if (VECTORP (subsidiaries)
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3789 && XVECTOR (subsidiaries)->size == 3)
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3790 coding->symbol
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3791 = XVECTOR (subsidiaries)->contents[coding->eol_type];
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3792 }
24667
6156dc5f5ce0 [andrewi]
Andrew Innes <andrewi@gnu.org>
parents: 24568
diff changeset
3793 setup_coding_system (coding->symbol, coding);
22616
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3794 }
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3795 return;
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3796 }
c493ce6a31e4 (setup_raw_text_coding_system): New function.
Kenichi Handa <handa@m17n.org>
parents: 22529
diff changeset
3797
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3798 /* Emacs has a mechanism to automatically detect a coding system if it
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3799 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3800 it's impossible to distinguish some coding systems accurately
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3801 because they use the same range of codes. So, at first, coding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3802 systems are categorized into 7, those are:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3803
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
3804 o coding-category-emacs-mule
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3805
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3806 The category for a coding system which has the same code range
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3807 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
3808 symbol) `emacs-mule' by default.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3809
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3810 o coding-category-sjis
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3811
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3812 The category for a coding system which has the same code range
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3813 as SJIS. Assigned the coding-system (Lisp
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3814 symbol) `japanese-shift-jis' by default.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3815
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3816 o coding-category-iso-7
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3817
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3818 The category for a coding system which has the same code range
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3819 as ISO2022 of 7-bit environment. This doesn't use any locking
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3820 shift and single shift functions. This can encode/decode all
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3821 charsets. Assigned the coding-system (Lisp symbol)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3822 `iso-2022-7bit' by default.
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3823
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3824 o coding-category-iso-7-tight
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3825
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3826 Same as coding-category-iso-7 except that this can
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3827 encode/decode only the specified charsets.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3828
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3829 o coding-category-iso-8-1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3830
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3831 The category for a coding system which has the same code range
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3832 as ISO2022 of 8-bit environment and graphic plane 1 used only
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3833 for DIMENSION1 charset. This doesn't use any locking shift
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3834 and single shift functions. Assigned the coding-system (Lisp
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3835 symbol) `iso-latin-1' by default.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3836
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3837 o coding-category-iso-8-2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3838
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3839 The category for a coding system which has the same code range
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3840 as ISO2022 of 8-bit environment and graphic plane 1 used only
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3841 for DIMENSION2 charset. This doesn't use any locking shift
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3842 and single shift functions. Assigned the coding-system (Lisp
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3843 symbol) `japanese-iso-8bit' by default.
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3844
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3845 o coding-category-iso-7-else
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3846
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3847 The category for a coding system which has the same code range
18787
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3848 as ISO2022 of 7-bit environemnt but uses locking shift or
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3849 single shift functions. Assigned the coding-system (Lisp
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3850 symbol) `iso-2022-7bit-lock' by default.
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3851
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3852 o coding-category-iso-8-else
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3853
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3854 The category for a coding system which has the same code range
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3855 as ISO2022 of 8-bit environemnt but uses locking shift or
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3856 single shift functions. Assigned the coding-system (Lisp
954e6be0a757 (detect_coding_iso2022): Distinguish coding-category-iso-7-else and
Kenichi Handa <handa@m17n.org>
parents: 18766
diff changeset
3857 symbol) `iso-2022-8bit-ss2' by default.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3858
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3859 o coding-category-big5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3860
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3861 The category for a coding system which has the same code range
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3862 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
3863 `cn-big5' by default.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3864
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3865 o coding-category-utf-8
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3866
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3867 The category for a coding system which has the same code range
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3868 as UTF-8 (cf. RFC2279). Assigned the coding-system (Lisp
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3869 symbol) `utf-8' by default.
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3870
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3871 o coding-category-utf-16-be
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3872
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3873 The category for a coding system in which a text has an
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3874 Unicode signature (cf. Unicode Standard) in the order of BIG
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3875 endian at the head. Assigned the coding-system (Lisp symbol)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3876 `utf-16-be' by default.
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3877
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3878 o coding-category-utf-16-le
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3879
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3880 The category for a coding system in which a text has an
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3881 Unicode signature (cf. Unicode Standard) in the order of
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3882 LITTLE endian at the head. Assigned the coding-system (Lisp
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3883 symbol) `utf-16-le' by default.
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3884
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3885 o coding-category-ccl
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3886
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3887 The category for a coding system of which encoder/decoder is
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3888 written in CCL programs. The default value is nil, i.e., no
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3889 coding system is assigned.
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
3890
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3891 o coding-category-binary
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3892
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3893 The category for a coding system not categorized in any of the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3894 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
3895 `no-conversion' by default.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3896
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3897 Each of them is a Lisp symbol and the value is an actual
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3898 `coding-system's (this is also a Lisp symbol) assigned by a user.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3899 What Emacs does actually is to detect a category of coding system.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3900 Then, it uses a `coding-system' assigned to it. If Emacs can't
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3901 decide only one possible category, it selects a category of the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3902 highest priority. Priorities of categories are also specified by a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3903 user in a Lisp variable `coding-category-list'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3904
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3905 */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3906
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3907 static
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3908 int ascii_skip_code[256];
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3909
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3910 /* Detect how a text of length SRC_BYTES pointed by SOURCE is encoded.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3911 If it detects possible coding systems, return an integer in which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3912 appropriate flag bits are set. Flag bits are defined by macros
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3913 CODING_CATEGORY_MASK_XXX in `coding.h'. If PRIORITIES is non-NULL,
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3914 it should point the table `coding_priorities'. In that case, only
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3915 the flag bit for a coding system of the highest priority is set in
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3916 the returned value. If MULTIBYTEP is nonzero, 8-bit codes of the
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3917 range 0x80..0x9F are in multibyte form.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3918
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3919 How many ASCII characters are at the head is returned as *SKIP. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3920
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3921 static int
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3922 detect_coding_mask (source, src_bytes, priorities, skip, multibytep)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3923 unsigned char *source;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3924 int src_bytes, *priorities, *skip;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3925 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3926 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3927 register unsigned char c;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3928 unsigned char *src = source, *src_end = source + src_bytes;
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3929 unsigned int mask, utf16_examined_p, iso2022_examined_p;
34988
8cd5e6ad71a2 (detect_coding_iso2022, setup_coding_system): Remove
Eli Zaretskii <eliz@gnu.org>
parents: 34892
diff changeset
3930 int i;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3931
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3932 /* At first, skip all ASCII characters and control characters except
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3933 for three ISO2022 specific control characters. */
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3934 ascii_skip_code[ISO_CODE_SO] = 0;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3935 ascii_skip_code[ISO_CODE_SI] = 0;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3936 ascii_skip_code[ISO_CODE_ESC] = 0;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3937
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
3938 label_loop_detect_coding:
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3939 while (src < src_end && ascii_skip_code[*src]) src++;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3940 *skip = src - source;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3941
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3942 if (src >= src_end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3943 /* We found nothing other than ASCII. There's nothing to do. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3944 return 0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3945
22329
4786b00d2973 (detect_coding_mask): Initilize local variable C.
Kenichi Handa <handa@m17n.org>
parents: 22254
diff changeset
3946 c = *src;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3947 /* The text seems to be encoded in some multilingual coding system.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3948 Now, try to find in which coding system the text is encoded. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3949 if (c < 0x80)
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
3950 {
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
3951 /* 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
3952 /* C is an ISO2022 specific control code of C0. */
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3953 mask = detect_coding_iso2022 (src, src_end, multibytep);
19743
b228f82192d5 (detect_coding_mask): Re-work previous change.
Richard M. Stallman <rms@gnu.org>
parents: 19688
diff changeset
3954 if (mask == 0)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3955 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3956 /* No valid ISO2022 code follows C. Try again. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3957 src++;
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3958 if (c == ISO_CODE_ESC)
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3959 ascii_skip_code[ISO_CODE_ESC] = 1;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3960 else
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
3961 ascii_skip_code[ISO_CODE_SO] = ascii_skip_code[ISO_CODE_SI] = 1;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3962 goto label_loop_detect_coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3963 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3964 if (priorities)
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3965 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3966 for (i = 0; i < CODING_CATEGORY_IDX_MAX; i++)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3967 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3968 if (mask & priorities[i])
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3969 return priorities[i];
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3970 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3971 return CODING_CATEGORY_MASK_RAW_TEXT;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3972 }
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
3973 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3974 else
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3975 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3976 int try;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3977
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3978 if (multibytep && c == LEADING_CODE_8_BIT_CONTROL)
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3979 c = *src++ - 0x20;
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
3980
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3981 if (c < 0xA0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3982 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3983 /* C is the first byte of SJIS character code,
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3984 or a leading-code of Emacs' internal format (emacs-mule),
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3985 or the first byte of UTF-16. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3986 try = (CODING_CATEGORY_MASK_SJIS
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3987 | CODING_CATEGORY_MASK_EMACS_MULE
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3988 | CODING_CATEGORY_MASK_UTF_16_BE
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
3989 | CODING_CATEGORY_MASK_UTF_16_LE);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3990
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3991 /* Or, if C is a special latin extra code,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3992 or is an ISO2022 specific control code of C1 (SS2 or SS3),
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3993 or is an ISO2022 control-sequence-introducer (CSI),
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3994 we should also consider the possibility of ISO2022 codings. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3995 if ((VECTORP (Vlatin_extra_code_table)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3996 && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3997 || (c == ISO_CODE_SS2 || c == ISO_CODE_SS3)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3998 || (c == ISO_CODE_CSI
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
3999 && (src < src_end
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4000 && (*src == ']'
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4001 || ((*src == '0' || *src == '1' || *src == '2')
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4002 && src + 1 < src_end
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4003 && src[1] == ']')))))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4004 try |= (CODING_CATEGORY_MASK_ISO_8_ELSE
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4005 | CODING_CATEGORY_MASK_ISO_8BIT);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4006 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4007 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4008 /* C is a character of ISO2022 in graphic plane right,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4009 or a SJIS's 1-byte character code (i.e. JISX0201),
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4010 or the first byte of BIG5's 2-byte code,
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4011 or the first byte of UTF-8/16. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4012 try = (CODING_CATEGORY_MASK_ISO_8_ELSE
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4013 | CODING_CATEGORY_MASK_ISO_8BIT
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4014 | CODING_CATEGORY_MASK_SJIS
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4015 | CODING_CATEGORY_MASK_BIG5
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4016 | CODING_CATEGORY_MASK_UTF_8
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4017 | CODING_CATEGORY_MASK_UTF_16_BE
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4018 | CODING_CATEGORY_MASK_UTF_16_LE);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4019
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4020 /* Or, we may have to consider the possibility of CCL. */
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4021 if (coding_system_table[CODING_CATEGORY_IDX_CCL]
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4022 && (coding_system_table[CODING_CATEGORY_IDX_CCL]
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4023 ->spec.ccl.valid_codes)[c])
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4024 try |= CODING_CATEGORY_MASK_CCL;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4025
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4026 mask = 0;
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4027 utf16_examined_p = iso2022_examined_p = 0;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4028 if (priorities)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4029 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4030 for (i = 0; i < CODING_CATEGORY_IDX_MAX; i++)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4031 {
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4032 if (!iso2022_examined_p
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4033 && (priorities[i] & try & CODING_CATEGORY_MASK_ISO))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4034 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4035 mask |= detect_coding_iso2022 (src, src_end);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4036 iso2022_examined_p = 1;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4037 }
22009
8a2d45cadd66 (detect_coding_mask): Check also coding-category-binary.
Richard M. Stallman <rms@gnu.org>
parents: 21939
diff changeset
4038 else if (priorities[i] & try & CODING_CATEGORY_MASK_SJIS)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4039 mask |= detect_coding_sjis (src, src_end, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4040 else if (priorities[i] & try & CODING_CATEGORY_MASK_UTF_8)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4041 mask |= detect_coding_utf_8 (src, src_end, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4042 else if (!utf16_examined_p
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4043 && (priorities[i] & try &
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4044 CODING_CATEGORY_MASK_UTF_16_BE_LE))
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4045 {
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4046 mask |= detect_coding_utf_16 (src, src_end, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4047 utf16_examined_p = 1;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4048 }
22009
8a2d45cadd66 (detect_coding_mask): Check also coding-category-binary.
Richard M. Stallman <rms@gnu.org>
parents: 21939
diff changeset
4049 else if (priorities[i] & try & CODING_CATEGORY_MASK_BIG5)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4050 mask |= detect_coding_big5 (src, src_end, multibytep);
22009
8a2d45cadd66 (detect_coding_mask): Check also coding-category-binary.
Richard M. Stallman <rms@gnu.org>
parents: 21939
diff changeset
4051 else if (priorities[i] & try & CODING_CATEGORY_MASK_EMACS_MULE)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4052 mask |= detect_coding_emacs_mule (src, src_end, multibytep);
23027
0dc823b2335f (coding_category_name): Fix the order of initial
Kenichi Handa <handa@m17n.org>
parents: 22979
diff changeset
4053 else if (priorities[i] & try & CODING_CATEGORY_MASK_CCL)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4054 mask |= detect_coding_ccl (src, src_end, multibytep);
22009
8a2d45cadd66 (detect_coding_mask): Check also coding-category-binary.
Richard M. Stallman <rms@gnu.org>
parents: 21939
diff changeset
4055 else if (priorities[i] & CODING_CATEGORY_MASK_RAW_TEXT)
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4056 mask |= CODING_CATEGORY_MASK_RAW_TEXT;
22009
8a2d45cadd66 (detect_coding_mask): Check also coding-category-binary.
Richard M. Stallman <rms@gnu.org>
parents: 21939
diff changeset
4057 else if (priorities[i] & CODING_CATEGORY_MASK_BINARY)
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4058 mask |= CODING_CATEGORY_MASK_BINARY;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4059 if (mask & priorities[i])
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4060 return priorities[i];
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4061 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4062 return CODING_CATEGORY_MASK_RAW_TEXT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4063 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4064 if (try & CODING_CATEGORY_MASK_ISO)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4065 mask |= detect_coding_iso2022 (src, src_end, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4066 if (try & CODING_CATEGORY_MASK_SJIS)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4067 mask |= detect_coding_sjis (src, src_end, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4068 if (try & CODING_CATEGORY_MASK_BIG5)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4069 mask |= detect_coding_big5 (src, src_end, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4070 if (try & CODING_CATEGORY_MASK_UTF_8)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4071 mask |= detect_coding_utf_8 (src, src_end, multibytep);
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4072 if (try & CODING_CATEGORY_MASK_UTF_16_BE_LE)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4073 mask |= detect_coding_utf_16 (src, src_end, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4074 if (try & CODING_CATEGORY_MASK_EMACS_MULE)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4075 mask |= detect_coding_emacs_mule (src, src_end, multibytep);
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
4076 if (try & CODING_CATEGORY_MASK_CCL)
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
4077 mask |= detect_coding_ccl (src, src_end, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4078 }
22009
8a2d45cadd66 (detect_coding_mask): Check also coding-category-binary.
Richard M. Stallman <rms@gnu.org>
parents: 21939
diff changeset
4079 return (mask | CODING_CATEGORY_MASK_RAW_TEXT | CODING_CATEGORY_MASK_BINARY);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4080 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4081
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4082 /* Detect how a text of length SRC_BYTES pointed by SRC is encoded.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4083 The information of the detected coding system is set in CODING. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4084
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4085 void
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4086 detect_coding (coding, src, src_bytes)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4087 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4088 unsigned char *src;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4089 int src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4090 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4091 unsigned int idx;
34988
8cd5e6ad71a2 (detect_coding_iso2022, setup_coding_system): Remove
Eli Zaretskii <eliz@gnu.org>
parents: 34892
diff changeset
4092 int skip, mask;
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
4093 Lisp_Object val;
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
4094
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
4095 val = Vcoding_category_list;
34593
f727eb496b4e (detect_coding): Call detect_coding_mask with a correct MULTIBYTEP
Kenichi Handa <handa@m17n.org>
parents: 34591
diff changeset
4096 mask = detect_coding_mask (src, src_bytes, coding_priorities, &skip,
f727eb496b4e (detect_coding): Call detect_coding_mask with a correct MULTIBYTEP
Kenichi Handa <handa@m17n.org>
parents: 34591
diff changeset
4097 coding->src_multibyte);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4098 coding->heading_ascii = skip;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4099
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4100 if (!mask) return;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4101
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4102 /* We found a single coding system of the highest priority in MASK. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4103 idx = 0;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4104 while (mask && ! (mask & 1)) mask >>= 1, idx++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4105 if (! mask)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4106 idx = CODING_CATEGORY_IDX_RAW_TEXT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4107
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4108 val = XSYMBOL (XVECTOR (Vcoding_category_table)->contents[idx])->value;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4109
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4110 if (coding->eol_type != CODING_EOL_UNDECIDED)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4111 {
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
4112 Lisp_Object tmp;
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
4113
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
4114 tmp = Fget (val, Qeol_type);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4115 if (VECTORP (tmp))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4116 val = XVECTOR (tmp)->contents[coding->eol_type];
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4117 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4118
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4119 /* Setup this new coding system while preserving some slots. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4120 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4121 int src_multibyte = coding->src_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4122 int dst_multibyte = coding->dst_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4123
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4124 setup_coding_system (val, coding);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4125 coding->src_multibyte = src_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4126 coding->dst_multibyte = dst_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4127 coding->heading_ascii = skip;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4128 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4129 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4130
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4131 /* Detect how end-of-line of a text of length SRC_BYTES pointed by
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4132 SOURCE is encoded. Return one of CODING_EOL_LF, CODING_EOL_CRLF,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4133 CODING_EOL_CR, and CODING_EOL_UNDECIDED.
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4134
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4135 How many non-eol characters are at the head is returned as *SKIP. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4136
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4137 #define MAX_EOL_CHECK_COUNT 3
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4138
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4139 static int
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4140 detect_eol_type (source, src_bytes, skip)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4141 unsigned char *source;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4142 int src_bytes, *skip;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4143 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4144 unsigned char *src = source, *src_end = src + src_bytes;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4145 unsigned char c;
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4146 int total = 0; /* How many end-of-lines are found so far. */
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4147 int eol_type = CODING_EOL_UNDECIDED;
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4148 int this_eol_type;
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4149
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4150 *skip = 0;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4151
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4152 while (src < src_end && total < MAX_EOL_CHECK_COUNT)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4153 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4154 c = *src++;
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4155 if (c == '\n' || c == '\r')
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4156 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4157 if (*skip == 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4158 *skip = src - 1 - source;
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4159 total++;
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4160 if (c == '\n')
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4161 this_eol_type = CODING_EOL_LF;
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4162 else if (src >= src_end || *src != '\n')
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4163 this_eol_type = CODING_EOL_CR;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4164 else
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4165 this_eol_type = CODING_EOL_CRLF, src++;
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4166
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4167 if (eol_type == CODING_EOL_UNDECIDED)
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4168 /* This is the first end-of-line. */
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4169 eol_type = this_eol_type;
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4170 else if (eol_type != this_eol_type)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4171 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4172 /* The found type is different from what found before. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4173 eol_type = CODING_EOL_INCONSISTENT;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4174 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4175 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4176 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4177 }
19173
04ed7c3f5cee (detect_eol_type): If EOL representation does not
Richard M. Stallman <rms@gnu.org>
parents: 19134
diff changeset
4178
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4179 if (*skip == 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4180 *skip = src_end - source;
19181
917138730635 (detect_eol_type): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 19173
diff changeset
4181 return eol_type;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4182 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4183
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4184 /* Like detect_eol_type, but detect EOL type in 2-octet
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4185 big-endian/little-endian format for coding systems utf-16-be and
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4186 utf-16-le. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4187
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4188 static int
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4189 detect_eol_type_in_2_octet_form (source, src_bytes, skip, big_endian_p)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4190 unsigned char *source;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4191 int src_bytes, *skip;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4192 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4193 unsigned char *src = source, *src_end = src + src_bytes;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4194 unsigned int c1, c2;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4195 int total = 0; /* How many end-of-lines are found so far. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4196 int eol_type = CODING_EOL_UNDECIDED;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4197 int this_eol_type;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4198 int msb, lsb;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4199
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4200 if (big_endian_p)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4201 msb = 0, lsb = 1;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4202 else
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4203 msb = 1, lsb = 0;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4204
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4205 *skip = 0;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4206
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4207 while ((src + 1) < src_end && total < MAX_EOL_CHECK_COUNT)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4208 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4209 c1 = (src[msb] << 8) | (src[lsb]);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4210 src += 2;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4211
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4212 if (c1 == '\n' || c1 == '\r')
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4213 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4214 if (*skip == 0)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4215 *skip = src - 2 - source;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4216 total++;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4217 if (c1 == '\n')
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4218 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4219 this_eol_type = CODING_EOL_LF;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4220 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4221 else
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4222 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4223 if ((src + 1) >= src_end)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4224 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4225 this_eol_type = CODING_EOL_CR;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4226 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4227 else
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4228 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4229 c2 = (src[msb] << 8) | (src[lsb]);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4230 if (c2 == '\n')
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4231 this_eol_type = CODING_EOL_CRLF, src += 2;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4232 else
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4233 this_eol_type = CODING_EOL_CR;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4234 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4235 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4236
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4237 if (eol_type == CODING_EOL_UNDECIDED)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4238 /* This is the first end-of-line. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4239 eol_type = this_eol_type;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4240 else if (eol_type != this_eol_type)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4241 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4242 /* The found type is different from what found before. */
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4243 eol_type = CODING_EOL_INCONSISTENT;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4244 break;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4245 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4246 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4247 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4248
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4249 if (*skip == 0)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4250 *skip = src_end - source;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4251 return eol_type;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4252 }
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4253
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4254 /* Detect how end-of-line of a text of length SRC_BYTES pointed by SRC
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4255 is encoded. If it detects an appropriate format of end-of-line, it
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4256 sets the information in *CODING. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4257
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4258 void
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4259 detect_eol (coding, src, src_bytes)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4260 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4261 unsigned char *src;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4262 int src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4263 {
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
4264 Lisp_Object val;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4265 int skip;
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4266 int eol_type;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4267
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4268 switch (coding->category_idx)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4269 {
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4270 case CODING_CATEGORY_IDX_UTF_16_BE:
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4271 eol_type = detect_eol_type_in_2_octet_form (src, src_bytes, &skip, 1);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4272 break;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4273 case CODING_CATEGORY_IDX_UTF_16_LE:
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4274 eol_type = detect_eol_type_in_2_octet_form (src, src_bytes, &skip, 0);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4275 break;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4276 default:
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4277 eol_type = detect_eol_type (src, src_bytes, &skip);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4278 break;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
4279 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4280
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4281 if (coding->heading_ascii > skip)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4282 coding->heading_ascii = skip;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4283 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4284 skip = coding->heading_ascii;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4285
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
4286 if (eol_type == CODING_EOL_UNDECIDED)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4287 return;
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4288 if (eol_type == CODING_EOL_INCONSISTENT)
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4289 {
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4290 #if 0
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4291 /* This code is suppressed until we find a better way to
19613
666288d82ae1 (detect_eol): Do not select no-conversion even if EOL
Kenichi Handa <handa@m17n.org>
parents: 19612
diff changeset
4292 distinguish raw text file and binary file. */
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4293
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4294 /* If we have already detected that the coding is raw-text, the
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4295 coding should actually be no-conversion. */
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4296 if (coding->type == coding_type_raw_text)
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4297 {
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4298 setup_coding_system (Qno_conversion, coding);
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4299 return;
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4300 }
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4301 /* Else, let's decode only text code anyway. */
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4302 #endif /* 0 */
19743
b228f82192d5 (detect_coding_mask): Re-work previous change.
Richard M. Stallman <rms@gnu.org>
parents: 19688
diff changeset
4303 eol_type = CODING_EOL_LF;
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4304 }
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
4305
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
4306 val = Fget (coding->symbol, Qeol_type);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4307 if (VECTORP (val) && XVECTOR (val)->size == 3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4308 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4309 int src_multibyte = coding->src_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4310 int dst_multibyte = coding->dst_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4311
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4312 setup_coding_system (XVECTOR (val)->contents[eol_type], coding);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4313 coding->src_multibyte = src_multibyte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4314 coding->dst_multibyte = dst_multibyte;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4315 coding->heading_ascii = skip;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4316 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4317 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4318
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4319 #define CONVERSION_BUFFER_EXTRA_ROOM 256
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4320
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4321 #define DECODING_BUFFER_MAG(coding) \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4322 (coding->type == coding_type_iso2022 \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4323 ? 3 \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4324 : (coding->type == coding_type_ccl \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4325 ? coding->spec.ccl.decoder.buf_magnification \
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4326 : 2))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4327
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4328 /* Return maximum size (bytes) of a buffer enough for decoding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4329 SRC_BYTES of text encoded in CODING. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4330
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4331 int
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4332 decoding_buffer_size (coding, src_bytes)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4333 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4334 int src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4335 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4336 return (src_bytes * DECODING_BUFFER_MAG (coding)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4337 + CONVERSION_BUFFER_EXTRA_ROOM);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4338 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4339
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4340 /* Return maximum size (bytes) of a buffer enough for encoding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4341 SRC_BYTES of text to CODING. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4342
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4343 int
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4344 encoding_buffer_size (coding, src_bytes)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4345 struct coding_system *coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4346 int src_bytes;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4347 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4348 int magnification;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4349
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4350 if (coding->type == coding_type_ccl)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4351 magnification = coding->spec.ccl.encoder.buf_magnification;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4352 else if (CODING_REQUIRE_ENCODING (coding))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4353 magnification = 3;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4354 else
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4355 magnification = 1;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4356
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4357 return (src_bytes * magnification + CONVERSION_BUFFER_EXTRA_ROOM);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4358 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4359
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4360 /* Working buffer for code conversion. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4361 struct conversion_buffer
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4362 {
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4363 int size; /* size of data. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4364 int on_stack; /* 1 if allocated by alloca. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4365 unsigned char *data;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4366 };
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4367
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4368 /* Don't use alloca for allocating memory space larger than this, lest
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4369 we overflow their stack. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4370 #define MAX_ALLOCA 16*1024
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4371
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4372 /* Allocate LEN bytes of memory for BUF (struct conversion_buffer). */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4373 #define allocate_conversion_buffer(buf, len) \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4374 do { \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4375 if (len < MAX_ALLOCA) \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4376 { \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4377 buf.data = (unsigned char *) alloca (len); \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4378 buf.on_stack = 1; \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4379 } \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4380 else \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4381 { \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4382 buf.data = (unsigned char *) xmalloc (len); \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4383 buf.on_stack = 0; \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4384 } \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4385 buf.size = len; \
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4386 } while (0)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4387
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4388 /* Double the allocated memory for *BUF. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4389 static void
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4390 extend_conversion_buffer (buf)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4391 struct conversion_buffer *buf;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4392 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4393 if (buf->on_stack)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4394 {
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4395 unsigned char *save = buf->data;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4396 buf->data = (unsigned char *) xmalloc (buf->size * 2);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4397 bcopy (save, buf->data, buf->size);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4398 buf->on_stack = 0;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4399 }
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4400 else
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4401 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4402 buf->data = (unsigned char *) xrealloc (buf->data, buf->size * 2);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4403 }
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4404 buf->size *= 2;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4405 }
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4406
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4407 /* Free the allocated memory for BUF if it is not on stack. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4408 static void
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4409 free_conversion_buffer (buf)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4410 struct conversion_buffer *buf;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4411 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4412 if (!buf->on_stack)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4413 xfree (buf->data);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4414 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4415
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4416 int
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4417 ccl_coding_driver (coding, source, destination, src_bytes, dst_bytes, encodep)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4418 struct coding_system *coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4419 unsigned char *source, *destination;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4420 int src_bytes, dst_bytes, encodep;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4421 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4422 struct ccl_program *ccl
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4423 = encodep ? &coding->spec.ccl.encoder : &coding->spec.ccl.decoder;
34892
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4424 unsigned char *dst = destination;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4425
23116
6736da064f4a (detect_coding_iso2022): Handle ESC N and ESC O
Kenichi Handa <handa@m17n.org>
parents: 23089
diff changeset
4426 ccl->last_block = coding->mode & CODING_MODE_LAST_BLOCK;
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4427 if (encodep)
34813
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4428 {
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4429 /* On encoding, EOL format is converted within ccl_driver. For
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4430 that, setup proper information in the structure CCL. */
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4431 ccl->eol_type = coding->eol_type;
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4432 if (ccl->eol_type ==CODING_EOL_UNDECIDED)
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4433 ccl->eol_type = CODING_EOL_LF;
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4434 ccl->cr_consumed = coding->spec.ccl.cr_carryover;
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4435 }
30756
b72c2759ac70 (ccl_coding_driver): Initialize ccl->multibyte.
Kenichi Handa <handa@m17n.org>
parents: 30674
diff changeset
4436 ccl->multibyte = coding->src_multibyte;
34892
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4437 if (coding->spec.ccl.eight_bit_carryover[0] != 0)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4438 {
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4439 /* Move carryover bytes to DESTINATION. */
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4440 unsigned char *p = coding->spec.ccl.eight_bit_carryover;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4441 while (*p)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4442 *dst++ = *p++;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4443 coding->spec.ccl.eight_bit_carryover[0] = 0;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4444 if (dst_bytes)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4445 dst_bytes -= dst - destination;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4446 }
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4447
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4448 coding->produced = (ccl_driver (ccl, source, dst, src_bytes, dst_bytes,
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4449 &(coding->consumed))
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4450 + dst - destination);
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4451
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4452 if (encodep)
34813
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4453 {
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4454 coding->produced_char = coding->produced;
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4455 coding->spec.ccl.cr_carryover = ccl->cr_consumed;
e112f39ea5b6 (ccl_coding_driver): Initialize ccl->cr_consumed.
Kenichi Handa <handa@m17n.org>
parents: 34593
diff changeset
4456 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4457 else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4458 {
34892
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4459 /* On decoding, the destination should always multibyte. But,
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4460 CCL program might have been generated an invalid multibyte
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4461 sequence. Here we make such a sequence valid as
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4462 multibyte. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4463 int bytes
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4464 = dst_bytes ? dst_bytes : source + coding->consumed - destination;
34892
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4465
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4466 if ((coding->consumed < src_bytes
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4467 || !ccl->last_block)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4468 && coding->produced >= 1
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4469 && destination[coding->produced - 1] >= 0x80)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4470 {
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4471 /* We should not convert the tailing 8-bit codes to
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4472 multibyte form even if they doesn't form a valid
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4473 multibyte sequence. They may form a valid sequence in
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4474 the next call. */
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4475 int carryover = 0;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4476
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4477 if (destination[coding->produced - 1] < 0xA0)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4478 carryover = 1;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4479 else if (coding->produced >= 2)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4480 {
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4481 if (destination[coding->produced - 2] >= 0x80)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4482 {
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4483 if (destination[coding->produced - 2] < 0xA0)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4484 carryover = 2;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4485 else if (coding->produced >= 3
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4486 && destination[coding->produced - 3] >= 0x80
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4487 && destination[coding->produced - 3] < 0xA0)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4488 carryover = 3;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4489 }
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4490 }
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4491 if (carryover > 0)
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4492 {
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4493 BCOPY_SHORT (destination + coding->produced - carryover,
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4494 coding->spec.ccl.eight_bit_carryover,
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4495 carryover);
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4496 coding->spec.ccl.eight_bit_carryover[carryover] = 0;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4497 coding->produced -= carryover;
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4498 }
3868f2e7355a (setup_coding_system): Initialize
Kenichi Handa <handa@m17n.org>
parents: 34888
diff changeset
4499 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4500 coding->produced = str_as_multibyte (destination, bytes,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4501 coding->produced,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4502 &(coding->produced_char));
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4503 }
23201
392b44751a22 (ccl_coding_driver): Always calculate correct mulibyte
Kenichi Handa <handa@m17n.org>
parents: 23153
diff changeset
4504
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4505 switch (ccl->status)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4506 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4507 case CCL_STAT_SUSPEND_BY_SRC:
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4508 coding->result = CODING_FINISH_INSUFFICIENT_SRC;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4509 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4510 case CCL_STAT_SUSPEND_BY_DST:
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4511 coding->result = CODING_FINISH_INSUFFICIENT_DST;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4512 break;
23279
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
4513 case CCL_STAT_QUIT:
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
4514 case CCL_STAT_INVALID_CMD:
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4515 coding->result = CODING_FINISH_INTERRUPT;
23279
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
4516 break;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4517 default:
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4518 coding->result = CODING_FINISH_NORMAL;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4519 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4520 }
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4521 return coding->result;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4522 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4523
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4524 /* Decode EOL format of the text at PTR of BYTES length destructively
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4525 according to CODING->eol_type. This is called after the CCL
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4526 program produced a decoded text at PTR. If we do CRLF->LF
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4527 conversion, update CODING->produced and CODING->produced_char. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4528
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4529 static void
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4530 decode_eol_post_ccl (coding, ptr, bytes)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4531 struct coding_system *coding;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4532 unsigned char *ptr;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4533 int bytes;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4534 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4535 Lisp_Object val, saved_coding_symbol;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4536 unsigned char *pend = ptr + bytes;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4537 int dummy;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4538
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4539 /* Remember the current coding system symbol. We set it back when
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4540 an inconsistent EOL is found so that `last-coding-system-used' is
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4541 set to the coding system that doesn't specify EOL conversion. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4542 saved_coding_symbol = coding->symbol;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4543
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4544 coding->spec.ccl.cr_carryover = 0;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4545 if (coding->eol_type == CODING_EOL_UNDECIDED)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4546 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4547 /* Here, to avoid the call of setup_coding_system, we directly
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4548 call detect_eol_type. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4549 coding->eol_type = detect_eol_type (ptr, bytes, &dummy);
29877
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4550 if (coding->eol_type == CODING_EOL_INCONSISTENT)
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4551 coding->eol_type = CODING_EOL_LF;
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4552 if (coding->eol_type != CODING_EOL_UNDECIDED)
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4553 {
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4554 val = Fget (coding->symbol, Qeol_type);
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4555 if (VECTORP (val) && XVECTOR (val)->size == 3)
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4556 coding->symbol = XVECTOR (val)->contents[coding->eol_type];
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4557 }
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4558 coding->mode |= CODING_MODE_INHIBIT_INCONSISTENT_EOL;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4559 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4560
29877
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4561 if (coding->eol_type == CODING_EOL_LF
7b43e1fb478a (decode_eol_post_ccl): Special handling for undecided
Eli Zaretskii <eliz@gnu.org>
parents: 29725
diff changeset
4562 || coding->eol_type == CODING_EOL_UNDECIDED)
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4563 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4564 /* We have nothing to do. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4565 ptr = pend;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4566 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4567 else if (coding->eol_type == CODING_EOL_CRLF)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4568 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4569 unsigned char *pstart = ptr, *p = ptr;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4570
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4571 if (! (coding->mode & CODING_MODE_LAST_BLOCK)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4572 && *(pend - 1) == '\r')
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4573 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4574 /* If the last character is CR, we can't handle it here
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4575 because LF will be in the not-yet-decoded source text.
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4576 Recorded that the CR is not yet processed. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4577 coding->spec.ccl.cr_carryover = 1;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4578 coding->produced--;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4579 coding->produced_char--;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4580 pend--;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4581 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4582 while (ptr < pend)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4583 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4584 if (*ptr == '\r')
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4585 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4586 if (ptr + 1 < pend && *(ptr + 1) == '\n')
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4587 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4588 *p++ = '\n';
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4589 ptr += 2;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4590 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4591 else
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4592 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4593 if (coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4594 goto undo_eol_conversion;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4595 *p++ = *ptr++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4596 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4597 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4598 else if (*ptr == '\n'
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4599 && coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4600 goto undo_eol_conversion;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4601 else
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4602 *p++ = *ptr++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4603 continue;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4604
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4605 undo_eol_conversion:
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4606 /* We have faced with inconsistent EOL format at PTR.
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4607 Convert all LFs before PTR back to CRLFs. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4608 for (p--, ptr--; p >= pstart; p--)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4609 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4610 if (*p == '\n')
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4611 *ptr-- = '\n', *ptr-- = '\r';
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4612 else
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4613 *ptr-- = *p;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4614 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4615 /* If carryover is recorded, cancel it because we don't
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4616 convert CRLF anymore. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4617 if (coding->spec.ccl.cr_carryover)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4618 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4619 coding->spec.ccl.cr_carryover = 0;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4620 coding->produced++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4621 coding->produced_char++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4622 pend++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4623 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4624 p = ptr = pend;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4625 coding->eol_type = CODING_EOL_LF;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4626 coding->symbol = saved_coding_symbol;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4627 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4628 if (p < pend)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4629 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4630 /* As each two-byte sequence CRLF was converted to LF, (PEND
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4631 - P) is the number of deleted characters. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4632 coding->produced -= pend - p;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4633 coding->produced_char -= pend - p;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4634 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4635 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4636 else /* i.e. coding->eol_type == CODING_EOL_CR */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4637 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4638 unsigned char *p = ptr;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4639
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4640 for (; ptr < pend; ptr++)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4641 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4642 if (*ptr == '\r')
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4643 *ptr = '\n';
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4644 else if (*ptr == '\n'
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4645 && coding->mode & CODING_MODE_INHIBIT_INCONSISTENT_EOL)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4646 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4647 for (; p < ptr; p++)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4648 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4649 if (*p == '\n')
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4650 *p = '\r';
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4651 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4652 ptr = pend;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4653 coding->eol_type = CODING_EOL_LF;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4654 coding->symbol = saved_coding_symbol;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4655 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4656 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4657 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4658 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4659
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4660 /* See "GENERAL NOTES about `decode_coding_XXX ()' functions". Before
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4661 decoding, it may detect coding system and format of end-of-line if
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4662 those are not yet decided. The source should be unibyte, the
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4663 result is multibyte if CODING->dst_multibyte is nonzero, else
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4664 unibyte. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4665
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4666 int
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4667 decode_coding (coding, source, destination, src_bytes, dst_bytes)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4668 struct coding_system *coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4669 unsigned char *source, *destination;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4670 int src_bytes, dst_bytes;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4671 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4672 if (coding->type == coding_type_undecided)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4673 detect_coding (coding, source, src_bytes);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4674
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4675 if (coding->eol_type == CODING_EOL_UNDECIDED
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4676 && coding->type != coding_type_ccl)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4677 detect_eol (coding, source, src_bytes);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4678
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4679 coding->produced = coding->produced_char = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4680 coding->consumed = coding->consumed_char = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4681 coding->errors = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4682 coding->result = CODING_FINISH_NORMAL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4683
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4684 switch (coding->type)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4685 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4686 case coding_type_sjis:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4687 decode_coding_sjis_big5 (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4688 src_bytes, dst_bytes, 1);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4689 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4690
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4691 case coding_type_iso2022:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4692 decode_coding_iso2022 (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4693 src_bytes, dst_bytes);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4694 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4695
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4696 case coding_type_big5:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4697 decode_coding_sjis_big5 (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4698 src_bytes, dst_bytes, 0);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4699 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4700
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4701 case coding_type_emacs_mule:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4702 decode_coding_emacs_mule (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4703 src_bytes, dst_bytes);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4704 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4705
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4706 case coding_type_ccl:
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4707 if (coding->spec.ccl.cr_carryover)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4708 {
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4709 /* Set the CR which is not processed by the previous call of
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4710 decode_eol_post_ccl in DESTINATION. */
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4711 *destination = '\r';
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4712 coding->produced++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4713 coding->produced_char++;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4714 dst_bytes--;
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4715 }
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4716 ccl_coding_driver (coding, source,
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4717 destination + coding->spec.ccl.cr_carryover,
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4718 src_bytes, dst_bytes, 0);
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4719 if (coding->eol_type != CODING_EOL_LF)
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
4720 decode_eol_post_ccl (coding, destination, coding->produced);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4721 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4722
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4723 default:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4724 decode_eol (coding, source, destination, src_bytes, dst_bytes);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4725 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4726
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4727 if (coding->result == CODING_FINISH_INSUFFICIENT_SRC
32896
3d8fb019040f (decode_coding): Fix previous change (check also
Kenichi Handa <handa@m17n.org>
parents: 32806
diff changeset
4728 && coding->mode & CODING_MODE_LAST_BLOCK
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4729 && coding->consumed == src_bytes)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4730 coding->result = CODING_FINISH_NORMAL;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4731
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4732 if (coding->mode & CODING_MODE_LAST_BLOCK
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4733 && coding->result == CODING_FINISH_INSUFFICIENT_SRC)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4734 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4735 unsigned char *src = source + coding->consumed;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4736 unsigned char *dst = destination + coding->produced;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4737
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4738 src_bytes -= coding->consumed;
30847
91e24edb537a (encode_coding): Fix the bug of not flushing ISO escape sequence at
Kenichi Handa <handa@m17n.org>
parents: 30833
diff changeset
4739 coding->errors++;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4740 if (COMPOSING_P (coding))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4741 DECODE_COMPOSITION_END ('1');
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4742 while (src_bytes--)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4743 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4744 int c = *src++;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4745 dst += CHAR_STRING (c, dst);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4746 coding->produced_char++;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4747 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4748 coding->consumed = coding->consumed_char = src - source;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4749 coding->produced = dst - destination;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4750 coding->result = CODING_FINISH_NORMAL;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4751 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4752
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4753 if (!coding->dst_multibyte)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4754 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4755 coding->produced = str_as_unibyte (destination, coding->produced);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4756 coding->produced_char = coding->produced;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4757 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4758
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4759 return coding->result;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4760 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4761
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4762 /* See "GENERAL NOTES about `encode_coding_XXX ()' functions". The
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4763 multibyteness of the source is CODING->src_multibyte, the
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4764 multibyteness of the result is always unibyte. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4765
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4766 int
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4767 encode_coding (coding, source, destination, src_bytes, dst_bytes)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4768 struct coding_system *coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4769 unsigned char *source, *destination;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4770 int src_bytes, dst_bytes;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4771 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4772 coding->produced = coding->produced_char = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4773 coding->consumed = coding->consumed_char = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4774 coding->errors = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4775 coding->result = CODING_FINISH_NORMAL;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4776
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4777 switch (coding->type)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4778 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4779 case coding_type_sjis:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4780 encode_coding_sjis_big5 (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4781 src_bytes, dst_bytes, 1);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4782 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4783
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4784 case coding_type_iso2022:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4785 encode_coding_iso2022 (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4786 src_bytes, dst_bytes);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4787 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4788
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4789 case coding_type_big5:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4790 encode_coding_sjis_big5 (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4791 src_bytes, dst_bytes, 0);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4792 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4793
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4794 case coding_type_emacs_mule:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4795 encode_coding_emacs_mule (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4796 src_bytes, dst_bytes);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4797 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4798
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4799 case coding_type_ccl:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4800 ccl_coding_driver (coding, source, destination,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4801 src_bytes, dst_bytes, 1);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4802 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4803
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4804 default:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4805 encode_eol (coding, source, destination, src_bytes, dst_bytes);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4806 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4807
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4808 if (coding->mode & CODING_MODE_LAST_BLOCK
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4809 && coding->result == CODING_FINISH_INSUFFICIENT_SRC)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4810 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4811 unsigned char *src = source + coding->consumed;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4812 unsigned char *src_end = src + src_bytes;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4813 unsigned char *dst = destination + coding->produced;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4814
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4815 if (coding->type == coding_type_iso2022)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4816 ENCODE_RESET_PLANE_AND_REGISTER;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4817 if (COMPOSING_P (coding))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4818 *dst++ = ISO_CODE_ESC, *dst++ = '1';
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4819 if (coding->consumed < src_bytes)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4820 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4821 int len = src_bytes - coding->consumed;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4822
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4823 BCOPY_SHORT (source + coding->consumed, dst, len);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4824 if (coding->src_multibyte)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4825 len = str_as_unibyte (dst, len);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4826 dst += len;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4827 coding->consumed = src_bytes;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4828 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4829 coding->produced = coding->produced_char = dst - destination;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
4830 coding->result = CODING_FINISH_NORMAL;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4831 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4832
30847
91e24edb537a (encode_coding): Fix the bug of not flushing ISO escape sequence at
Kenichi Handa <handa@m17n.org>
parents: 30833
diff changeset
4833 if (coding->result == CODING_FINISH_INSUFFICIENT_SRC
91e24edb537a (encode_coding): Fix the bug of not flushing ISO escape sequence at
Kenichi Handa <handa@m17n.org>
parents: 30833
diff changeset
4834 && coding->consumed == src_bytes)
91e24edb537a (encode_coding): Fix the bug of not flushing ISO escape sequence at
Kenichi Handa <handa@m17n.org>
parents: 30833
diff changeset
4835 coding->result = CODING_FINISH_NORMAL;
91e24edb537a (encode_coding): Fix the bug of not flushing ISO escape sequence at
Kenichi Handa <handa@m17n.org>
parents: 30833
diff changeset
4836
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4837 return coding->result;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4838 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4839
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4840 /* Scan text in the region between *BEG and *END (byte positions),
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4841 skip characters which we don't have to decode by coding system
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4842 CODING at the head and tail, then set *BEG and *END to the region
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4843 of the text we actually have to convert. The caller should move
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4844 the gap out of the region in advance if the region is from a
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4845 buffer.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4846
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4847 If STR is not NULL, *BEG and *END are indices into STR. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4848
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4849 static void
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4850 shrink_decoding_region (beg, end, coding, str)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4851 int *beg, *end;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4852 struct coding_system *coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4853 unsigned char *str;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4854 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4855 unsigned char *begp_orig, *begp, *endp_orig, *endp, c;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4856 int eol_conversion;
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4857 Lisp_Object translation_table;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4858
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4859 if (coding->type == coding_type_ccl
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4860 || coding->type == coding_type_undecided
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4861 || coding->eol_type != CODING_EOL_LF
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4862 || !NILP (coding->post_read_conversion)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4863 || coding->composing != COMPOSITION_DISABLED)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4864 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4865 /* We can't skip any data. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4866 return;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4867 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4868 if (coding->type == coding_type_no_conversion
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4869 || coding->type == coding_type_raw_text
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4870 || coding->type == coding_type_emacs_mule)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4871 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4872 /* We need no conversion, but don't have to skip any data here.
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4873 Decoding routine handles them effectively anyway. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4874 return;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4875 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4876
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4877 translation_table = coding->translation_table_for_decode;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4878 if (NILP (translation_table) && !NILP (Venable_character_translation))
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4879 translation_table = Vstandard_translation_table_for_decode;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4880 if (CHAR_TABLE_P (translation_table))
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4881 {
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4882 int i;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4883 for (i = 0; i < 128; i++)
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4884 if (!NILP (CHAR_TABLE_REF (translation_table, i)))
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4885 break;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4886 if (i < 128)
29247
c748b4b1c785 (shrink_decoding_region): Initialize eol_conversion.
Dave Love <fx@gnu.org>
parents: 29184
diff changeset
4887 /* Some ASCII character should be translated. We give up
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4888 shrinking. */
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4889 return;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4890 }
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
4891
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4892 if (coding->heading_ascii >= 0)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4893 /* Detection routine has already found how much we can skip at the
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4894 head. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4895 *beg += coding->heading_ascii;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4896
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4897 if (str)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4898 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4899 begp_orig = begp = str + *beg;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4900 endp_orig = endp = str + *end;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4901 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4902 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4903 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
4904 begp_orig = begp = BYTE_POS_ADDR (*beg);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4905 endp_orig = endp = begp + *end - *beg;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4906 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4907
29247
c748b4b1c785 (shrink_decoding_region): Initialize eol_conversion.
Dave Love <fx@gnu.org>
parents: 29184
diff changeset
4908 eol_conversion = (coding->eol_type == CODING_EOL_CR
c748b4b1c785 (shrink_decoding_region): Initialize eol_conversion.
Dave Love <fx@gnu.org>
parents: 29184
diff changeset
4909 || coding->eol_type == CODING_EOL_CRLF);
c748b4b1c785 (shrink_decoding_region): Initialize eol_conversion.
Dave Love <fx@gnu.org>
parents: 29184
diff changeset
4910
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4911 switch (coding->type)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4912 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4913 case coding_type_sjis:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4914 case coding_type_big5:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4915 /* We can skip all ASCII characters at the head. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4916 if (coding->heading_ascii < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4917 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4918 if (eol_conversion)
21273
3d9e12cf2e63 (shrink_decoding_region): If EOL_CONVERSION is nonzero,
Kenichi Handa <handa@m17n.org>
parents: 21253
diff changeset
4919 while (begp < endp && *begp < 0x80 && *begp != '\r') begp++;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4920 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4921 while (begp < endp && *begp < 0x80) begp++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4922 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4923 /* We can skip all ASCII characters at the tail except for the
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4924 second byte of SJIS or BIG5 code. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4925 if (eol_conversion)
21273
3d9e12cf2e63 (shrink_decoding_region): If EOL_CONVERSION is nonzero,
Kenichi Handa <handa@m17n.org>
parents: 21253
diff changeset
4926 while (begp < endp && endp[-1] < 0x80 && endp[-1] != '\r') endp--;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4927 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4928 while (begp < endp && endp[-1] < 0x80) endp--;
21744
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4929 /* Do not consider LF as ascii if preceded by CR, since that
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4930 confuses eol decoding. */
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4931 if (begp < endp && endp < endp_orig && endp[-1] == '\r' && endp[0] == '\n')
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4932 endp++;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4933 if (begp < endp && endp < endp_orig && endp[-1] >= 0x80)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4934 endp++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4935 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4936
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
4937 case coding_type_iso2022:
23426
088cb2a804c7 (shrink_decoding_region): If a charset other than ascii
Kenichi Handa <handa@m17n.org>
parents: 23402
diff changeset
4938 if (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, 0) != CHARSET_ASCII)
088cb2a804c7 (shrink_decoding_region): If a charset other than ascii
Kenichi Handa <handa@m17n.org>
parents: 23402
diff changeset
4939 /* We can't skip any data. */
088cb2a804c7 (shrink_decoding_region): If a charset other than ascii
Kenichi Handa <handa@m17n.org>
parents: 23402
diff changeset
4940 break;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4941 if (coding->heading_ascii < 0)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4942 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4943 /* We can skip all ASCII characters at the head except for a
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4944 few control codes. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4945 while (begp < endp && (c = *begp) < 0x80
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4946 && c != ISO_CODE_CR && c != ISO_CODE_SO
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4947 && c != ISO_CODE_SI && c != ISO_CODE_ESC
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4948 && (!eol_conversion || c != ISO_CODE_LF))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4949 begp++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4950 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4951 switch (coding->category_idx)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4952 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4953 case CODING_CATEGORY_IDX_ISO_8_1:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4954 case CODING_CATEGORY_IDX_ISO_8_2:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4955 /* We can skip all ASCII characters at the tail. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4956 if (eol_conversion)
21273
3d9e12cf2e63 (shrink_decoding_region): If EOL_CONVERSION is nonzero,
Kenichi Handa <handa@m17n.org>
parents: 21253
diff changeset
4957 while (begp < endp && (c = endp[-1]) < 0x80 && c != '\r') endp--;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4958 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4959 while (begp < endp && endp[-1] < 0x80) endp--;
21744
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4960 /* Do not consider LF as ascii if preceded by CR, since that
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4961 confuses eol decoding. */
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4962 if (begp < endp && endp < endp_orig && endp[-1] == '\r' && endp[0] == '\n')
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
4963 endp++;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4964 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4965
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4966 case CODING_CATEGORY_IDX_ISO_7:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
4967 case CODING_CATEGORY_IDX_ISO_7_TIGHT:
23325
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4968 {
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4969 /* We can skip all charactes at the tail except for 8-bit
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4970 codes and ESC and the following 2-byte at the tail. */
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4971 unsigned char *eight_bit = NULL;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4972
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4973 if (eol_conversion)
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4974 while (begp < endp
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4975 && (c = endp[-1]) != ISO_CODE_ESC && c != '\r')
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4976 {
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4977 if (!eight_bit && c & 0x80) eight_bit = endp;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4978 endp--;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4979 }
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4980 else
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4981 while (begp < endp
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4982 && (c = endp[-1]) != ISO_CODE_ESC)
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4983 {
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4984 if (!eight_bit && c & 0x80) eight_bit = endp;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4985 endp--;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4986 }
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4987 /* Do not consider LF as ascii if preceded by CR, since that
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4988 confuses eol decoding. */
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4989 if (begp < endp && endp < endp_orig
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4990 && endp[-1] == '\r' && endp[0] == '\n')
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4991 endp++;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4992 if (begp < endp && endp[-1] == ISO_CODE_ESC)
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4993 {
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4994 if (endp + 1 < endp_orig && end[0] == '(' && end[1] == 'B')
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4995 /* This is an ASCII designation sequence. We can
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4996 surely skip the tail. But, if we have
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4997 encountered an 8-bit code, skip only the codes
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4998 after that. */
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
4999 endp = eight_bit ? eight_bit : endp + 2;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5000 else
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5001 /* Hmmm, we can't skip the tail. */
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5002 endp = endp_orig;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5003 }
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5004 else if (eight_bit)
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5005 endp = eight_bit;
bbd06336cd0c (check_composing_code): If the current composing
Kenichi Handa <handa@m17n.org>
parents: 23315
diff changeset
5006 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5007 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5008 break;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5009
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5010 default:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5011 abort ();
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5012 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5013 *beg += begp - begp_orig;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5014 *end += endp - endp_orig;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5015 return;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5016 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5017
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5018 /* Like shrink_decoding_region but for encoding. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5019
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5020 static void
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5021 shrink_encoding_region (beg, end, coding, str)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5022 int *beg, *end;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5023 struct coding_system *coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5024 unsigned char *str;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5025 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5026 unsigned char *begp_orig, *begp, *endp_orig, *endp;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5027 int eol_conversion;
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5028 Lisp_Object translation_table;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5029
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5030 if (coding->type == coding_type_ccl
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5031 || coding->eol_type == CODING_EOL_CRLF
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5032 || coding->eol_type == CODING_EOL_CR
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5033 || coding->cmp_data && coding->cmp_data->used > 0)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5034 {
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5035 /* We can't skip any data. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5036 return;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5037 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5038 if (coding->type == coding_type_no_conversion
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5039 || coding->type == coding_type_raw_text
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5040 || coding->type == coding_type_emacs_mule
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5041 || coding->type == coding_type_undecided)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5042 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5043 /* We need no conversion, but don't have to skip any data here.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5044 Encoding routine handles them effectively anyway. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5045 return;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5046 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5047
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5048 translation_table = coding->translation_table_for_encode;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5049 if (NILP (translation_table) && !NILP (Venable_character_translation))
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5050 translation_table = Vstandard_translation_table_for_encode;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5051 if (CHAR_TABLE_P (translation_table))
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5052 {
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5053 int i;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5054 for (i = 0; i < 128; i++)
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5055 if (!NILP (CHAR_TABLE_REF (translation_table, i)))
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5056 break;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5057 if (i < 128)
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5058 /* Some ASCII character should be tranlsated. We give up
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5059 shrinking. */
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5060 return;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5061 }
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5062
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5063 if (str)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5064 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5065 begp_orig = begp = str + *beg;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5066 endp_orig = endp = str + *end;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5067 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5068 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5069 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5070 begp_orig = begp = BYTE_POS_ADDR (*beg);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5071 endp_orig = endp = begp + *end - *beg;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5072 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5073
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5074 eol_conversion = (coding->eol_type == CODING_EOL_CR
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5075 || coding->eol_type == CODING_EOL_CRLF);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5076
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5077 /* Here, we don't have to check coding->pre_write_conversion because
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5078 the caller is expected to have handled it already. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5079 switch (coding->type)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5080 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5081 case coding_type_iso2022:
23426
088cb2a804c7 (shrink_decoding_region): If a charset other than ascii
Kenichi Handa <handa@m17n.org>
parents: 23402
diff changeset
5082 if (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, 0) != CHARSET_ASCII)
088cb2a804c7 (shrink_decoding_region): If a charset other than ascii
Kenichi Handa <handa@m17n.org>
parents: 23402
diff changeset
5083 /* We can't skip any data. */
088cb2a804c7 (shrink_decoding_region): If a charset other than ascii
Kenichi Handa <handa@m17n.org>
parents: 23402
diff changeset
5084 break;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5085 if (coding->flags & CODING_FLAG_ISO_DESIGNATE_AT_BOL)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5086 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5087 unsigned char *bol = begp;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5088 while (begp < endp && *begp < 0x80)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5089 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5090 begp++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5091 if (begp[-1] == '\n')
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5092 bol = begp;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5093 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5094 begp = bol;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5095 goto label_skip_tail;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5096 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5097 /* fall down ... */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5098
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5099 case coding_type_sjis:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5100 case coding_type_big5:
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5101 /* We can skip all ASCII characters at the head and tail. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5102 if (eol_conversion)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5103 while (begp < endp && *begp < 0x80 && *begp != '\n') begp++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5104 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5105 while (begp < endp && *begp < 0x80) begp++;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5106 label_skip_tail:
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5107 if (eol_conversion)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5108 while (begp < endp && endp[-1] < 0x80 && endp[-1] != '\n') endp--;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5109 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5110 while (begp < endp && *(endp - 1) < 0x80) endp--;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5111 break;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5112
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5113 default:
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5114 abort ();
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5115 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5116
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5117 *beg += begp - begp_orig;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5118 *end += endp - endp_orig;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5119 return;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5120 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5121
23339
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5122 /* As shrinking conversion region requires some overhead, we don't try
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5123 shrinking if the length of conversion region is less than this
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5124 value. */
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5125 static int shrink_conversion_region_threshhold = 1024;
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5126
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5127 #define SHRINK_CONVERSION_REGION(beg, end, coding, str, encodep) \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5128 do { \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5129 if (*(end) - *(beg) > shrink_conversion_region_threshhold) \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5130 { \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5131 if (encodep) shrink_encoding_region (beg, end, coding, str); \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5132 else shrink_decoding_region (beg, end, coding, str); \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5133 } \
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5134 } while (0)
2da87b489590 (check_composing_code): Fix previous change. Now it
Kenichi Handa <handa@m17n.org>
parents: 23325
diff changeset
5135
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5136 static Lisp_Object
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5137 code_convert_region_unwind (dummy)
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5138 Lisp_Object dummy;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5139 {
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5140 inhibit_pre_post_conversion = 0;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5141 return Qnil;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5142 }
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5143
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5144 /* Store information about all compositions in the range FROM and TO
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5145 of OBJ in memory blocks pointed by CODING->cmp_data. OBJ is a
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5146 buffer or a string, defaults to the current buffer. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5147
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5148 void
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5149 coding_save_composition (coding, from, to, obj)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5150 struct coding_system *coding;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5151 int from, to;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5152 Lisp_Object obj;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5153 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5154 Lisp_Object prop;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5155 int start, end;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5156
27943
c2e0998057f9 (coding_save_composition): Be sure to allocate
Kenichi Handa <handa@m17n.org>
parents: 27271
diff changeset
5157 if (coding->composing == COMPOSITION_DISABLED)
c2e0998057f9 (coding_save_composition): Be sure to allocate
Kenichi Handa <handa@m17n.org>
parents: 27271
diff changeset
5158 return;
c2e0998057f9 (coding_save_composition): Be sure to allocate
Kenichi Handa <handa@m17n.org>
parents: 27271
diff changeset
5159 if (!coding->cmp_data)
c2e0998057f9 (coding_save_composition): Be sure to allocate
Kenichi Handa <handa@m17n.org>
parents: 27271
diff changeset
5160 coding_allocate_composition_data (coding, from);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5161 if (!find_composition (from, to, &start, &end, &prop, obj)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5162 || end > to)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5163 return;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5164 if (start < from
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5165 && (!find_composition (end, to, &start, &end, &prop, obj)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5166 || end > to))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5167 return;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5168 coding->composing = COMPOSITION_NO;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5169 do
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5170 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5171 if (COMPOSITION_VALID_P (start, end, prop))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5172 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5173 enum composition_method method = COMPOSITION_METHOD (prop);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5174 if (coding->cmp_data->used + COMPOSITION_DATA_MAX_BUNCH_LENGTH
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5175 >= COMPOSITION_DATA_SIZE)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5176 coding_allocate_composition_data (coding, from);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5177 /* For relative composition, we remember start and end
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5178 positions, for the other compositions, we also remember
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5179 components. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5180 CODING_ADD_COMPOSITION_START (coding, start - from, method);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5181 if (method != COMPOSITION_RELATIVE)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5182 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5183 /* We must store a*/
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5184 Lisp_Object val, ch;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5185
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5186 val = COMPOSITION_COMPONENTS (prop);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5187 if (CONSP (val))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5188 while (CONSP (val))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5189 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5190 ch = XCAR (val), val = XCDR (val);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5191 CODING_ADD_COMPOSITION_COMPONENT (coding, XINT (ch));
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5192 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5193 else if (VECTORP (val) || STRINGP (val))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5194 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5195 int len = (VECTORP (val)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5196 ? XVECTOR (val)->size : XSTRING (val)->size);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5197 int i;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5198 for (i = 0; i < len; i++)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5199 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5200 ch = (STRINGP (val)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5201 ? Faref (val, make_number (i))
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5202 : XVECTOR (val)->contents[i]);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5203 CODING_ADD_COMPOSITION_COMPONENT (coding, XINT (ch));
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5204 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5205 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5206 else /* INTEGERP (val) */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5207 CODING_ADD_COMPOSITION_COMPONENT (coding, XINT (val));
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5208 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5209 CODING_ADD_COMPOSITION_END (coding, end - from);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5210 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5211 start = end;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5212 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5213 while (start < to
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5214 && find_composition (start, to, &start, &end, &prop, obj)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5215 && end <= to);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5216
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5217 /* Make coding->cmp_data point to the first memory block. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5218 while (coding->cmp_data->prev)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5219 coding->cmp_data = coding->cmp_data->prev;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5220 coding->cmp_data_start = 0;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5221 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5222
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5223 /* Reflect the saved information about compositions to OBJ.
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5224 CODING->cmp_data points to a memory block for the informaiton. OBJ
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5225 is a buffer or a string, defaults to the current buffer. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5226
29275
b4ea9178e480 (DECODE_COMPOSITION_START): If coding->cmp_data is not
Kenichi Handa <handa@m17n.org>
parents: 29247
diff changeset
5227 void
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5228 coding_restore_composition (coding, obj)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5229 struct coding_system *coding;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5230 Lisp_Object obj;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5231 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5232 struct composition_data *cmp_data = coding->cmp_data;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5233
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5234 if (!cmp_data)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5235 return;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5236
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5237 while (cmp_data->prev)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5238 cmp_data = cmp_data->prev;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5239
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5240 while (cmp_data)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5241 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5242 int i;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5243
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5244 for (i = 0; i < cmp_data->used && cmp_data->data[i] > 0;
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5245 i += cmp_data->data[i])
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5246 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5247 int *data = cmp_data->data + i;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5248 enum composition_method method = (enum composition_method) data[3];
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5249 Lisp_Object components;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5250
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5251 if (method == COMPOSITION_RELATIVE)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5252 components = Qnil;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5253 else
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5254 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5255 int len = data[0] - 4, j;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5256 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1];
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5257
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5258 for (j = 0; j < len; j++)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5259 args[j] = make_number (data[4 + j]);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5260 components = (method == COMPOSITION_WITH_ALTCHARS
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5261 ? Fstring (len, args) : Fvector (len, args));
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5262 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5263 compose_text (data[1], data[2], components, Qnil, obj);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5264 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5265 cmp_data = cmp_data->next;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5266 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5267 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5268
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5269 /* Decode (if ENCODEP is zero) or encode (if ENCODEP is nonzero) the
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5270 text from FROM to TO (byte positions are FROM_BYTE and TO_BYTE) by
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5271 coding system CODING, and return the status code of code conversion
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5272 (currently, this value has no meaning).
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5273
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5274 How many characters (and bytes) are converted to how many
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5275 characters (and bytes) are recorded in members of the structure
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5276 CODING.
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5277
21190
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5278 If REPLACE is nonzero, we do various things as if the original text
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5279 is deleted and a new text is inserted. See the comments in
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5280 replace_range (insdel.c) to know what we are doing.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5281
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5282 If REPLACE is zero, it is assumed that the source text is unibyte.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5283 Otherwize, it is assumed that the source text is multibyte. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5284
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5285 int
21190
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5286 code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5287 int from, from_byte, to, to_byte, encodep, replace;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5288 struct coding_system *coding;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5289 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5290 int len = to - from, len_byte = to_byte - from_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5291 int require, inserted, inserted_byte;
27271
7b495b311f18 (code_convert_region): Initialize total_skip.
Andreas Schwab <schwab@suse.de>
parents: 26900
diff changeset
5292 int head_skip, tail_skip, total_skip = 0;
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
5293 Lisp_Object saved_coding_symbol;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5294 int first = 1;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5295 unsigned char *src, *dst;
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
5296 Lisp_Object deletion;
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5297 int orig_point = PT, orig_len = len;
23537
28cd5faf93dd (code_convert_region): While preserving the orignal
Kenichi Handa <handa@m17n.org>
parents: 23514
diff changeset
5298 int prev_Z;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5299 int multibyte_p = !NILP (current_buffer->enable_multibyte_characters);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5300
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
5301 deletion = Qnil;
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
5302 saved_coding_symbol = Qnil;
21190
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5303
21576
8043d47984fd (code_convert_region): If point in the conversion
Kenichi Handa <handa@m17n.org>
parents: 21574
diff changeset
5304 if (from < PT && PT < to)
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5305 {
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5306 TEMP_SET_PT_BOTH (from, from_byte);
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5307 orig_point = from;
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5308 }
21576
8043d47984fd (code_convert_region): If point in the conversion
Kenichi Handa <handa@m17n.org>
parents: 21574
diff changeset
5309
21190
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5310 if (replace)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5311 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5312 int saved_from = from;
30315
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5313 int saved_inhibit_modification_hooks;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5314
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5315 prepare_to_modify_buffer (from, to, &from);
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5316 if (saved_from != from)
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5317 {
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5318 to = from + len;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5319 from_byte = CHAR_TO_BYTE (from), to_byte = CHAR_TO_BYTE (to);
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5320 len_byte = to_byte - from_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5321 }
30315
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5322
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5323 /* The code conversion routine can not preserve text properties
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5324 for now. So, we must remove all text properties in the
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5325 region. Here, we must suppress all modification hooks. */
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5326 saved_inhibit_modification_hooks = inhibit_modification_hooks;
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5327 inhibit_modification_hooks = 1;
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5328 Fset_text_properties (make_number (from), make_number (to), Qnil, Qnil);
8067ad173141 (code_convert_region): Delete text properties before shrinking the
Kenichi Handa <handa@m17n.org>
parents: 30292
diff changeset
5329 inhibit_modification_hooks = saved_inhibit_modification_hooks;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5330 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5331
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5332 if (! encodep && CODING_REQUIRE_DETECTION (coding))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5333 {
21321
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5334 /* We must detect encoding of text and eol format. */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5335
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5336 if (from < GPT && to > GPT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5337 move_gap_both (from, from_byte);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5338 if (coding->type == coding_type_undecided)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5339 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5340 detect_coding (coding, BYTE_POS_ADDR (from_byte), len_byte);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5341 if (coding->type == coding_type_undecided)
32443
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5342 {
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5343 /* It seems that the text contains only ASCII, but we
32745
70dcd0333504 Fix a typo in a comment.
Eli Zaretskii <eliz@gnu.org>
parents: 32445
diff changeset
5344 should not leave it undecided because the deeper
32443
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5345 decoding routine (decode_coding) tries to detect the
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5346 encodings again in vain. */
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5347 coding->type = coding_type_emacs_mule;
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5348 coding->category_idx = CODING_CATEGORY_IDX_EMACS_MULE;
57fa108c491f (code_convert_region): Be sure to initialize coding->category_idx.
Kenichi Handa <handa@m17n.org>
parents: 31458
diff changeset
5349 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5350 }
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
5351 if (coding->eol_type == CODING_EOL_UNDECIDED
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
5352 && coding->type != coding_type_ccl)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5353 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5354 saved_coding_symbol = coding->symbol;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5355 detect_eol (coding, BYTE_POS_ADDR (from_byte), len_byte);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5356 if (coding->eol_type == CODING_EOL_UNDECIDED)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5357 coding->eol_type = CODING_EOL_LF;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5358 /* We had better recover the original eol format if we
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5359 encounter an inconsitent eol format while decoding. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5360 coding->mode |= CODING_MODE_INHIBIT_INCONSISTENT_EOL;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5361 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5362 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5363
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5364 /* Now we convert the text. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5365
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5366 /* For encoding, we must process pre-write-conversion in advance. */
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5367 if (! inhibit_pre_post_conversion
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5368 && encodep
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5369 && SYMBOLP (coding->pre_write_conversion)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5370 && ! NILP (Ffboundp (coding->pre_write_conversion)))
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5371 {
21140
179c73d91f70 (code_convert_region): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 21132
diff changeset
5372 /* The function in pre-write-conversion may put a new text in a
179c73d91f70 (code_convert_region): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 21132
diff changeset
5373 new buffer. */
23542
eaf358b2e8dd (code_convert_region): Kill the work buffer created by
Kenichi Handa <handa@m17n.org>
parents: 23537
diff changeset
5374 struct buffer *prev = current_buffer;
eaf358b2e8dd (code_convert_region): Kill the work buffer created by
Kenichi Handa <handa@m17n.org>
parents: 23537
diff changeset
5375 Lisp_Object new;
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5376 int count = specpdl_ptr - specpdl;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5377
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5378 record_unwind_protect (code_convert_region_unwind, Qnil);
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5379 /* We should not call any more pre-write/post-read-conversion
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5380 functions while this pre-write-conversion is running. */
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5381 inhibit_pre_post_conversion = 1;
21520
ca4819c36ab9 (code_convert_region): Fix mixing of Lisp_Object and
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
5382 call2 (coding->pre_write_conversion,
ca4819c36ab9 (code_convert_region): Fix mixing of Lisp_Object and
Andreas Schwab <schwab@suse.de>
parents: 21514
diff changeset
5383 make_number (from), make_number (to));
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5384 inhibit_pre_post_conversion = 0;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5385 /* Discard the unwind protect. */
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5386 specpdl_ptr--;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5387
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5388 if (current_buffer != prev)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5389 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5390 len = ZV - BEGV;
23542
eaf358b2e8dd (code_convert_region): Kill the work buffer created by
Kenichi Handa <handa@m17n.org>
parents: 23537
diff changeset
5391 new = Fcurrent_buffer ();
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5392 set_buffer_internal_1 (prev);
26742
936b39bd05b4 * editfns.c (Fdelete_and_extract_region): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26526
diff changeset
5393 del_range_2 (from, from_byte, to, to_byte, 0);
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5394 TEMP_SET_PT_BOTH (from, from_byte);
23542
eaf358b2e8dd (code_convert_region): Kill the work buffer created by
Kenichi Handa <handa@m17n.org>
parents: 23537
diff changeset
5395 insert_from_buffer (XBUFFER (new), 1, len, 0);
eaf358b2e8dd (code_convert_region): Kill the work buffer created by
Kenichi Handa <handa@m17n.org>
parents: 23537
diff changeset
5396 Fkill_buffer (new);
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5397 if (orig_point >= to)
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5398 orig_point += len - orig_len;
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5399 else if (orig_point > from)
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5400 orig_point = from;
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5401 orig_len = len;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5402 to = from + len;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5403 from_byte = CHAR_TO_BYTE (from);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5404 to_byte = CHAR_TO_BYTE (to);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5405 len_byte = to_byte - from_byte;
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5406 TEMP_SET_PT_BOTH (from, from_byte);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5407 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5408 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5409
21321
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5410 if (replace)
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5411 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1);
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5412
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5413 if (coding->composing != COMPOSITION_DISABLED)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5414 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5415 if (encodep)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5416 coding_save_composition (coding, from, to, Fcurrent_buffer ());
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5417 else
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5418 coding_allocate_composition_data (coding, from);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5419 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5420
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5421 /* Try to skip the heading and tailing ASCIIs. */
29985
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5422 if (coding->type != coding_type_ccl)
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5423 {
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5424 int from_byte_orig = from_byte, to_byte_orig = to_byte;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5425
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5426 if (from < GPT && GPT < to)
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5427 move_gap_both (from, from_byte);
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5428 SHRINK_CONVERSION_REGION (&from_byte, &to_byte, coding, NULL, encodep);
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5429 if (from_byte == to_byte
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5430 && (encodep || NILP (coding->post_read_conversion))
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5431 && ! CODING_REQUIRE_FLUSHING (coding))
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5432 {
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5433 coding->produced = len_byte;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5434 coding->produced_char = len;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5435 if (!replace)
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5436 /* We must record and adjust for this new text now. */
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5437 adjust_after_insert (from, from_byte_orig, to, to_byte_orig, len);
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5438 return 0;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5439 }
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5440
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5441 head_skip = from_byte - from_byte_orig;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5442 tail_skip = to_byte_orig - to_byte;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5443 total_skip = head_skip + tail_skip;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5444 from += head_skip;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5445 to -= tail_skip;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5446 len -= total_skip; len_byte -= total_skip;
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5447 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5448
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5449 /* For converion, we must put the gap before the text in addition to
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5450 making the gap larger for efficient decoding. The required gap
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5451 size starts from 2000 which is the magic number used in make_gap.
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5452 But, after one batch of conversion, it will be incremented if we
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5453 find that it is not enough . */
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5454 require = 2000;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5455
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5456 if (GAP_SIZE < require)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5457 make_gap (require - GAP_SIZE);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5458 move_gap_both (from, from_byte);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5459
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5460 inserted = inserted_byte = 0;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5461
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5462 GAP_SIZE += len_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5463 ZV -= len;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5464 Z -= len;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5465 ZV_BYTE -= len_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5466 Z_BYTE -= len_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5467
25370
20d8158841b0 (code_convert_region): Compute beg/end_unchanged per
Gerd Moellmann <gerd@gnu.org>
parents: 25067
diff changeset
5468 if (GPT - BEG < BEG_UNCHANGED)
20d8158841b0 (code_convert_region): Compute beg/end_unchanged per
Gerd Moellmann <gerd@gnu.org>
parents: 25067
diff changeset
5469 BEG_UNCHANGED = GPT - BEG;
20d8158841b0 (code_convert_region): Compute beg/end_unchanged per
Gerd Moellmann <gerd@gnu.org>
parents: 25067
diff changeset
5470 if (Z - GPT < END_UNCHANGED)
20d8158841b0 (code_convert_region): Compute beg/end_unchanged per
Gerd Moellmann <gerd@gnu.org>
parents: 25067
diff changeset
5471 END_UNCHANGED = Z - GPT;
23258
2f8585bcea90 (code_convert_region): Update beg_unchanged and
Kenichi Handa <handa@m17n.org>
parents: 23201
diff changeset
5472
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5473 if (!encodep && coding->src_multibyte)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5474 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5475 /* Decoding routines expects that the source text is unibyte.
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5476 We must convert 8-bit characters of multibyte form to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5477 unibyte. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5478 int len_byte_orig = len_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5479 len_byte = str_as_unibyte (GAP_END_ADDR - len_byte, len_byte);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5480 if (len_byte < len_byte_orig)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5481 safe_bcopy (GAP_END_ADDR - len_byte_orig, GAP_END_ADDR - len_byte,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5482 len_byte);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5483 coding->src_multibyte = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5484 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5485
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5486 for (;;)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5487 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5488 int result;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5489
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5490 /* The buffer memory is now:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5491 +--------+converted-text+---------+-------original-text-------+---+
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5492 |<-from->|<--inserted-->|---------|<--------len_byte--------->|---|
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5493 |<---------------------- GAP ----------------------->| */
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5494 src = GAP_END_ADDR - len_byte;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5495 dst = GPT_ADDR + inserted_byte;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5496
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5497 if (encodep)
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5498 result = encode_coding (coding, src, dst, len_byte, 0);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5499 else
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5500 result = decode_coding (coding, src, dst, len_byte, 0);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5501
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5502 /* The buffer memory is now:
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5503 +--------+-------converted-text----+--+------original-text----+---+
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5504 |<-from->|<-inserted->|<-produced->|--|<-(len_byte-consumed)->|---|
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5505 |<---------------------- GAP ----------------------->| */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5506
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5507 inserted += coding->produced_char;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5508 inserted_byte += coding->produced;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5509 len_byte -= coding->consumed;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5510
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5511 if (result == CODING_FINISH_INSUFFICIENT_CMP)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5512 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5513 coding_allocate_composition_data (coding, from + inserted);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5514 continue;
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5515 }
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5516
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5517 src += coding->consumed;
26240
93f3d2337323 (code_convert_region): Update `dst' correctly.
Kenichi Handa <handa@m17n.org>
parents: 26088
diff changeset
5518 dst += coding->produced;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5519
23279
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5520 if (result == CODING_FINISH_NORMAL)
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5521 {
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5522 src += len_byte;
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5523 break;
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5524 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5525 if (! encodep && result == CODING_FINISH_INCONSISTENT_EOL)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5526 {
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5527 unsigned char *pend = dst, *p = pend - inserted_byte;
24706
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5528 Lisp_Object eol_type;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5529
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5530 /* Encode LFs back to the original eol format (CR or CRLF). */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5531 if (coding->eol_type == CODING_EOL_CR)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5532 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5533 while (p < pend) if (*p++ == '\n') p[-1] = '\r';
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5534 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5535 else
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5536 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5537 int count = 0;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5538
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5539 while (p < pend) if (*p++ == '\n') count++;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5540 if (src - dst < count)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5541 {
24706
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5542 /* We don't have sufficient room for encoding LFs
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5543 back to CRLF. We must record converted and
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5544 not-yet-converted text back to the buffer
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5545 content, enlarge the gap, then record them out of
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5546 the buffer contents again. */
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5547 int add = len_byte + inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5548
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5549 GAP_SIZE -= add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5550 ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5551 GPT += inserted_byte; GPT_BYTE += inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5552 make_gap (count - GAP_SIZE);
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5553 GAP_SIZE += add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5554 ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5555 GPT -= inserted_byte; GPT_BYTE -= inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5556 /* Don't forget to update SRC, DST, and PEND. */
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5557 src = GAP_END_ADDR - len_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5558 dst = GPT_ADDR + inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5559 pend = dst;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5560 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5561 inserted += count;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5562 inserted_byte += count;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5563 coding->produced += count;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5564 p = dst = pend + count;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5565 while (count)
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5566 {
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5567 *--p = *--pend;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5568 if (*p == '\n') count--, *--p = '\r';
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5569 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5570 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5571
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5572 /* Suppress eol-format conversion in the further conversion. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5573 coding->eol_type = CODING_EOL_LF;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5574
24706
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5575 /* Set the coding system symbol to that for Unix-like EOL. */
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5576 eol_type = Fget (saved_coding_symbol, Qeol_type);
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5577 if (VECTORP (eol_type)
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5578 && XVECTOR (eol_type)->size == 3
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5579 && SYMBOLP (XVECTOR (eol_type)->contents[CODING_EOL_LF]))
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5580 coding->symbol = XVECTOR (eol_type)->contents[CODING_EOL_LF];
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5581 else
778b3f056f7f (code_convert_region): If eol format is inconsistent,
Kenichi Handa <handa@m17n.org>
parents: 24667
diff changeset
5582 coding->symbol = saved_coding_symbol;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5583
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5584 continue;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5585 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5586 if (len_byte <= 0)
23881
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5587 {
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5588 if (coding->type != coding_type_ccl
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5589 || coding->mode & CODING_MODE_LAST_BLOCK)
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5590 break;
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5591 coding->mode |= CODING_MODE_LAST_BLOCK;
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5592 continue;
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5593 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5594 if (result == CODING_FINISH_INSUFFICIENT_SRC)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5595 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5596 /* The source text ends in invalid codes. Let's just
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5597 make them valid buffer contents, and finish conversion. */
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5598 inserted += len_byte;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5599 inserted_byte += len_byte;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5600 while (len_byte--)
21744
64c815fe1bdc (shrink_decoding_region): Do not consider LF as ascii
Richard M. Stallman <rms@gnu.org>
parents: 21664
diff changeset
5601 *dst++ = *src++;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5602 break;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5603 }
23279
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5604 if (result == CODING_FINISH_INTERRUPT)
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5605 {
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5606 /* The conversion procedure was interrupted by a user. */
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5607 break;
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5608 }
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5609 /* Now RESULT == CODING_FINISH_INSUFFICIENT_DST */
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5610 if (coding->consumed < 1)
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5611 {
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5612 /* It's quite strange to require more memory without
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5613 consuming any bytes. Perhaps CCL program bug. */
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5614 break;
ca159e828a68 (ccl_coding_driver): If ccl_driver is interrupted by a
Kenichi Handa <handa@m17n.org>
parents: 23258
diff changeset
5615 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5616 if (first)
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5617 {
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5618 /* We have just done the first batch of conversion which was
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5619 stoped because of insufficient gap. Let's reconsider the
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5620 required gap size (i.e. SRT - DST) now.
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5621
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5622 We have converted ORIG bytes (== coding->consumed) into
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5623 NEW bytes (coding->produced). To convert the remaining
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5624 LEN bytes, we may need REQUIRE bytes of gap, where:
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5625 REQUIRE + LEN_BYTE = LEN_BYTE * (NEW / ORIG)
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5626 REQUIRE = LEN_BYTE * (NEW - ORIG) / ORIG
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5627 Here, we are sure that NEW >= ORIG. */
21190
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5628 float ratio = coding->produced - coding->consumed;
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5629 ratio /= coding->consumed;
d704dd953837 (code_convert_region): The 6th arg name is changed to
Kenichi Handa <handa@m17n.org>
parents: 21140
diff changeset
5630 require = len_byte * ratio;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5631 first = 0;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5632 }
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5633 if ((src - dst) < (require + 2000))
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5634 {
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5635 /* See the comment above the previous call of make_gap. */
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5636 int add = len_byte + inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5637
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5638 GAP_SIZE -= add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5639 ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5640 GPT += inserted_byte; GPT_BYTE += inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5641 make_gap (require + 2000);
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5642 GAP_SIZE += add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5643 ZV -= add; Z -= add; ZV_BYTE -= add; Z_BYTE -= add;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5644 GPT -= inserted_byte; GPT_BYTE -= inserted_byte;
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5645 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5646 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5647 if (src - dst > 0) *dst = 0; /* Put an anchor. */
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5648
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5649 if (encodep && coding->dst_multibyte)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5650 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5651 /* The output is unibyte. We must convert 8-bit characters to
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5652 multibyte form. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5653 if (inserted_byte * 2 > GAP_SIZE)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5654 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5655 GAP_SIZE -= inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5656 ZV += inserted_byte; Z += inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5657 ZV_BYTE += inserted_byte; Z_BYTE += inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5658 GPT += inserted_byte; GPT_BYTE += inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5659 make_gap (inserted_byte - GAP_SIZE);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5660 GAP_SIZE += inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5661 ZV -= inserted_byte; Z -= inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5662 ZV_BYTE -= inserted_byte; Z_BYTE -= inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5663 GPT -= inserted_byte; GPT_BYTE -= inserted_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5664 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5665 inserted_byte = str_to_multibyte (GPT_ADDR, GAP_SIZE, inserted_byte);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5666 }
21140
179c73d91f70 (code_convert_region): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 21132
diff changeset
5667
21321
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5668 /* If we have shrinked the conversion area, adjust it now. */
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5669 if (total_skip > 0)
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5670 {
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5671 if (tail_skip > 0)
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5672 safe_bcopy (GAP_END_ADDR, GPT_ADDR + inserted_byte, tail_skip);
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5673 inserted += total_skip; inserted_byte += total_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5674 GAP_SIZE += total_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5675 GPT -= head_skip; GPT_BYTE -= head_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5676 ZV -= total_skip; ZV_BYTE -= total_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5677 Z -= total_skip; Z_BYTE -= total_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5678 from -= head_skip; from_byte -= head_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5679 to += tail_skip; to_byte += tail_skip;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5680 }
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5681
23537
28cd5faf93dd (code_convert_region): While preserving the orignal
Kenichi Handa <handa@m17n.org>
parents: 23514
diff changeset
5682 prev_Z = Z;
21321
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5683 adjust_after_replace (from, from_byte, deletion, inserted, inserted_byte);
23537
28cd5faf93dd (code_convert_region): While preserving the orignal
Kenichi Handa <handa@m17n.org>
parents: 23514
diff changeset
5684 inserted = Z - prev_Z;
21140
179c73d91f70 (code_convert_region): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 21132
diff changeset
5685
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5686 if (!encodep && coding->cmp_data && coding->cmp_data->used)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5687 coding_restore_composition (coding, Fcurrent_buffer ());
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5688 coding_free_composition_data (coding);
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5689
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5690 if (! inhibit_pre_post_conversion
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5691 && ! encodep && ! NILP (coding->post_read_conversion))
21062
839b22ad1e42 (code_convert_region): Handle the case that codes
Kenichi Handa <handa@m17n.org>
parents: 20999
diff changeset
5692 {
21140
179c73d91f70 (code_convert_region): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 21132
diff changeset
5693 Lisp_Object val;
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5694 int count = specpdl_ptr - specpdl;
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5695
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5696 if (from != PT)
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5697 TEMP_SET_PT_BOTH (from, from_byte);
23537
28cd5faf93dd (code_convert_region): While preserving the orignal
Kenichi Handa <handa@m17n.org>
parents: 23514
diff changeset
5698 prev_Z = Z;
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5699 record_unwind_protect (code_convert_region_unwind, Qnil);
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5700 /* We should not call any more pre-write/post-read-conversion
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5701 functions while this post-read-conversion is running. */
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5702 inhibit_pre_post_conversion = 1;
21140
179c73d91f70 (code_convert_region): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents: 21132
diff changeset
5703 val = call1 (coding->post_read_conversion, make_number (inserted));
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5704 inhibit_pre_post_conversion = 0;
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5705 /* Discard the unwind protect. */
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
5706 specpdl_ptr--;
23537
28cd5faf93dd (code_convert_region): While preserving the orignal
Kenichi Handa <handa@m17n.org>
parents: 23514
diff changeset
5707 CHECK_NUMBER (val, 0);
23881
20d595402dea (DECODE_DESIGNATION): Jump to label_invalid_code if
Kenichi Handa <handa@m17n.org>
parents: 23564
diff changeset
5708 inserted += Z - prev_Z;
23514
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5709 }
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5710
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5711 if (orig_point >= from)
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5712 {
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5713 if (orig_point >= from + orig_len)
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5714 orig_point += inserted - orig_len;
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5715 else
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5716 orig_point = from;
7bad909cd6f1 (setup_coding_system): Fix setting up
Kenichi Handa <handa@m17n.org>
parents: 23475
diff changeset
5717 TEMP_SET_PT (orig_point);
21062
839b22ad1e42 (code_convert_region): Handle the case that codes
Kenichi Handa <handa@m17n.org>
parents: 20999
diff changeset
5718 }
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5719
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5720 if (replace)
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5721 {
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5722 signal_after_change (from, to - from, inserted);
26900
a8f4cebb614d (code_convert_region): Fix the secoding arg to
Kenichi Handa <handa@m17n.org>
parents: 26847
diff changeset
5723 update_compositions (from, from + inserted, CHECK_BORDER);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
5724 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5725
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5726 {
21321
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5727 coding->consumed = to_byte - from_byte;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5728 coding->consumed_char = to - from;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5729 coding->produced = inserted_byte;
27b08da98abe (code_convert_region): Handle skipped ASCII characters
Kenichi Handa <handa@m17n.org>
parents: 21308
diff changeset
5730 coding->produced_char = inserted;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5731 }
21132
75c6408013e5 (code_convert_region): Fix previous change. Adjusted
Richard M. Stallman <rms@gnu.org>
parents: 21067
diff changeset
5732
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
5733 return 0;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5734 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5735
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5736 Lisp_Object
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5737 run_pre_post_conversion_on_str (str, coding, encodep)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5738 Lisp_Object str;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5739 struct coding_system *coding;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5740 int encodep;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5741 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5742 int count = specpdl_ptr - specpdl;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5743 struct gcpro gcpro1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5744 int multibyte = STRING_MULTIBYTE (str);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5745
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5746 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5747 record_unwind_protect (code_convert_region_unwind, Qnil);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5748 GCPRO1 (str);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5749 temp_output_buffer_setup (" *code-converting-work*");
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5750 set_buffer_internal (XBUFFER (Vstandard_output));
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5751 /* We must insert the contents of STR as is without
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5752 unibyte<->multibyte conversion. For that, we adjust the
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5753 multibyteness of the working buffer to that of STR. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5754 Ferase_buffer ();
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5755 current_buffer->enable_multibyte_characters = multibyte ? Qt : Qnil;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5756 insert_from_string (str, 0, 0,
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5757 XSTRING (str)->size, STRING_BYTES (XSTRING (str)), 0);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5758 UNGCPRO;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5759 inhibit_pre_post_conversion = 1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5760 if (encodep)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5761 call2 (coding->pre_write_conversion, make_number (BEG), make_number (Z));
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5762 else
29172
46ad5a027334 (run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents: 29093
diff changeset
5763 {
46ad5a027334 (run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents: 29093
diff changeset
5764 TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
46ad5a027334 (run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents: 29093
diff changeset
5765 call1 (coding->post_read_conversion, make_number (Z - BEG));
46ad5a027334 (run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents: 29093
diff changeset
5766 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5767 inhibit_pre_post_conversion = 0;
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5768 str = make_buffer_string (BEG, Z, 1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5769 return unbind_to (count, str);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5770 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5771
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5772 Lisp_Object
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5773 decode_coding_string (str, coding, nocopy)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5774 Lisp_Object str;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5775 struct coding_system *coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5776 int nocopy;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5777 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5778 int len;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5779 struct conversion_buffer buf;
34988
8cd5e6ad71a2 (detect_coding_iso2022, setup_coding_system): Remove
Eli Zaretskii <eliz@gnu.org>
parents: 34892
diff changeset
5780 int from, to_byte;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5781 struct gcpro gcpro1;
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
5782 Lisp_Object saved_coding_symbol;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5783 int result;
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5784 int require_decoding;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5785 int shrinked_bytes = 0;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5786 Lisp_Object newstr;
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5787 int consumed, consumed_char, produced, produced_char;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5788
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5789 from = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5790 to_byte = STRING_BYTES (XSTRING (str));
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5791
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
5792 saved_coding_symbol = Qnil;
34536
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5793 coding->src_multibyte = STRING_MULTIBYTE (str);
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5794 coding->dst_multibyte = 1;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5795 if (CODING_REQUIRE_DETECTION (coding))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5796 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5797 /* See the comments in code_convert_region. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5798 if (coding->type == coding_type_undecided)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5799 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5800 detect_coding (coding, XSTRING (str)->data, to_byte);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5801 if (coding->type == coding_type_undecided)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5802 coding->type = coding_type_emacs_mule;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5803 }
29725
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
5804 if (coding->eol_type == CODING_EOL_UNDECIDED
2bc397e9b09a (setup_coding_system) <4>: Reset member `cr_carryover'.
Kenichi Handa <handa@m17n.org>
parents: 29663
diff changeset
5805 && coding->type != coding_type_ccl)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5806 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5807 saved_coding_symbol = coding->symbol;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5808 detect_eol (coding, XSTRING (str)->data, to_byte);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5809 if (coding->eol_type == CODING_EOL_UNDECIDED)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5810 coding->eol_type = CODING_EOL_LF;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5811 /* We had better recover the original eol format if we
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5812 encounter an inconsitent eol format while decoding. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5813 coding->mode |= CODING_MODE_INHIBIT_INCONSISTENT_EOL;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5814 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5815 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5816
34536
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5817 if (coding->type == coding_type_no_conversion
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5818 || coding->type == coding_type_raw_text)
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5819 coding->dst_multibyte = 0;
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5820
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5821 require_decoding = CODING_REQUIRE_DECODING (coding);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5822
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5823 if (STRING_MULTIBYTE (str))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5824 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5825 /* Decoding routines expect the source text to be unibyte. */
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5826 str = Fstring_as_unibyte (str);
29932
37a3b3eae862 (decode_coding_string): Re-fetch STRING_BYTES after
Andreas Schwab <schwab@suse.de>
parents: 29877
diff changeset
5827 to_byte = STRING_BYTES (XSTRING (str));
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5828 nocopy = 1;
34536
aa667988f2b0 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 34531
diff changeset
5829 coding->src_multibyte = 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5830 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5831
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5832 /* Try to skip the heading and tailing ASCIIs. */
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5833 if (require_decoding && coding->type != coding_type_ccl)
29985
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5834 {
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5835 SHRINK_CONVERSION_REGION (&from, &to_byte, coding, XSTRING (str)->data,
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5836 0);
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5837 if (from == to_byte)
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5838 require_decoding = 0;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5839 shrinked_bytes = from + (STRING_BYTES (XSTRING (str)) - to_byte);
29985
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5840 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5841
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5842 if (!require_decoding)
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5843 {
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5844 coding->consumed = STRING_BYTES (XSTRING (str));
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5845 coding->consumed_char = XSTRING (str)->size;
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5846 if (coding->dst_multibyte)
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5847 {
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5848 str = Fstring_as_multibyte (str);
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5849 nocopy = 1;
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5850 }
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5851 coding->produced = STRING_BYTES (XSTRING (str));
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5852 coding->produced_char = XSTRING (str)->size;
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5853 return (nocopy ? str : Fcopy_sequence (str));
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5854 }
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5855
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5856 if (coding->composing != COMPOSITION_DISABLED)
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5857 coding_allocate_composition_data (coding, from);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5858 len = decoding_buffer_size (coding, to_byte - from);
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5859 allocate_conversion_buffer (buf, len);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5860
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5861 consumed = consumed_char = produced = produced_char = 0;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5862 while (1)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5863 {
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5864 result = decode_coding (coding, XSTRING (str)->data + from + consumed,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5865 buf.data + produced, to_byte - from - consumed,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5866 buf.size - produced);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5867 consumed += coding->consumed;
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5868 consumed_char += coding->consumed_char;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5869 produced += coding->produced;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5870 produced_char += coding->produced_char;
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5871 if (result == CODING_FINISH_NORMAL
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5872 || (result == CODING_FINISH_INSUFFICIENT_SRC
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5873 && coding->consumed == 0))
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5874 break;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5875 if (result == CODING_FINISH_INSUFFICIENT_CMP)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5876 coding_allocate_composition_data (coding, from + produced_char);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5877 else if (result == CODING_FINISH_INSUFFICIENT_DST)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5878 extend_conversion_buffer (&buf);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5879 else if (result == CODING_FINISH_INCONSISTENT_EOL)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5880 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5881 /* Recover the original EOL format. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5882 if (coding->eol_type == CODING_EOL_CR)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5883 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5884 unsigned char *p;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5885 for (p = buf.data; p < buf.data + produced; p++)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5886 if (*p == '\n') *p = '\r';
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5887 }
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5888 else if (coding->eol_type == CODING_EOL_CRLF)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5889 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5890 int num_eol = 0;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5891 unsigned char *p0, *p1;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5892 for (p0 = buf.data, p1 = p0 + produced; p0 < p1; p0++)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5893 if (*p0 == '\n') num_eol++;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5894 if (produced + num_eol >= buf.size)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5895 extend_conversion_buffer (&buf);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5896 for (p0 = buf.data + produced, p1 = p0 + num_eol; p0 > buf.data;)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5897 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5898 *--p1 = *--p0;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5899 if (*p0 == '\n') *--p1 = '\r';
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5900 }
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5901 produced += num_eol;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5902 produced_char += num_eol;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5903 }
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5904 coding->eol_type = CODING_EOL_LF;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5905 coding->symbol = saved_coding_symbol;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5906 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5907 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
5908
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5909 coding->consumed = consumed;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5910 coding->consumed_char = consumed_char;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5911 coding->produced = produced;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5912 coding->produced_char = produced_char;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5913
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5914 if (coding->dst_multibyte)
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5915 newstr = make_uninit_multibyte_string (produced_char + shrinked_bytes,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5916 produced + shrinked_bytes);
30581
6c7a9202a815 (coding_restore_composition): Pay attention to the case that
Kenichi Handa <handa@m17n.org>
parents: 30578
diff changeset
5917 else
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5918 newstr = make_uninit_string (produced + shrinked_bytes);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5919 if (from > 0)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5920 bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5921 bcopy (buf.data, XSTRING (newstr)->data + from, produced);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5922 if (shrinked_bytes > from)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5923 bcopy (XSTRING (str)->data + to_byte,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5924 XSTRING (newstr)->data + from + produced,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5925 shrinked_bytes - from);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5926 free_conversion_buffer (&buf);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5927
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5928 if (coding->cmp_data && coding->cmp_data->used)
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5929 coding_restore_composition (coding, newstr);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5930 coding_free_composition_data (coding);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5931
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5932 if (SYMBOLP (coding->post_read_conversion)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5933 && !NILP (Ffboundp (coding->post_read_conversion)))
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5934 newstr = run_pre_post_conversion_on_str (newstr, coding, 0);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5935
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5936 return newstr;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5937 }
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5938
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5939 Lisp_Object
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5940 encode_coding_string (str, coding, nocopy)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5941 Lisp_Object str;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5942 struct coding_system *coding;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5943 int nocopy;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5944 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5945 int len;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5946 struct conversion_buffer buf;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5947 int from, to, to_byte;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5948 int result;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5949 int shrinked_bytes = 0;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5950 Lisp_Object newstr;
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5951 int consumed, consumed_char, produced, produced_char;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5952
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5953 if (SYMBOLP (coding->pre_write_conversion)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5954 && !NILP (Ffboundp (coding->pre_write_conversion)))
29172
46ad5a027334 (run_pre_post_conversion_on_str): Set point to the
Kenichi Handa <handa@m17n.org>
parents: 29093
diff changeset
5955 str = run_pre_post_conversion_on_str (str, coding, 1);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5956
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5957 from = 0;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5958 to = XSTRING (str)->size;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5959 to_byte = STRING_BYTES (XSTRING (str));
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5960
32445
05513a882886 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 32443
diff changeset
5961 /* Encoding routines determine the multibyteness of the source text
05513a882886 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 32443
diff changeset
5962 by coding->src_multibyte. */
05513a882886 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 32443
diff changeset
5963 coding->src_multibyte = STRING_MULTIBYTE (str);
05513a882886 (decode_coding_string): Set coding->src_multibyte and
Kenichi Handa <handa@m17n.org>
parents: 32443
diff changeset
5964 coding->dst_multibyte = 0;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5965 if (! CODING_REQUIRE_ENCODING (coding))
22723
04b653d7f842 (code_convert_string): Count characters again if we
Kenichi Handa <handa@m17n.org>
parents: 22717
diff changeset
5966 {
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5967 coding->consumed = STRING_BYTES (XSTRING (str));
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5968 coding->consumed_char = XSTRING (str)->size;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5969 if (STRING_MULTIBYTE (str))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5970 {
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5971 str = Fstring_as_unibyte (str);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5972 nocopy = 1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5973 }
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5974 coding->produced = STRING_BYTES (XSTRING (str));
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5975 coding->produced_char = XSTRING (str)->size;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5976 return (nocopy ? str : Fcopy_sequence (str));
22723
04b653d7f842 (code_convert_string): Count characters again if we
Kenichi Handa <handa@m17n.org>
parents: 22717
diff changeset
5977 }
04b653d7f842 (code_convert_string): Count characters again if we
Kenichi Handa <handa@m17n.org>
parents: 22717
diff changeset
5978
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5979 if (coding->composing != COMPOSITION_DISABLED)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5980 coding_save_composition (coding, from, to, str);
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5981
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5982 /* Try to skip the heading and tailing ASCIIs. */
29985
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5983 if (coding->type != coding_type_ccl)
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5984 {
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5985 SHRINK_CONVERSION_REGION (&from, &to_byte, coding, XSTRING (str)->data,
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5986 1);
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5987 if (from == to_byte)
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5988 return (nocopy ? str : Fcopy_sequence (str));
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5989 shrinked_bytes = from + (STRING_BYTES (XSTRING (str)) - to_byte);
29985
c17e78d8c720 (code_convert_region): Even if the length of text is
Kenichi Handa <handa@m17n.org>
parents: 29932
diff changeset
5990 }
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5991
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
5992 len = encoding_buffer_size (coding, to_byte - from);
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5993 allocate_conversion_buffer (buf, len);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5994
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
5995 consumed = consumed_char = produced = produced_char = 0;
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5996 while (1)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5997 {
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5998 result = encode_coding (coding, XSTRING (str)->data + from + consumed,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
5999 buf.data + produced, to_byte - from - consumed,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6000 buf.size - produced);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6001 consumed += coding->consumed;
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6002 consumed_char += coding->consumed_char;
30951
e6acd4b6a8d5 (encode_coding_string): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 30950
diff changeset
6003 produced += coding->produced;
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6004 produced_char += coding->produced_char;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6005 if (result == CODING_FINISH_NORMAL
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6006 || (result == CODING_FINISH_INSUFFICIENT_SRC
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6007 && coding->consumed == 0))
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6008 break;
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6009 /* Now result should be CODING_FINISH_INSUFFICIENT_DST. */
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6010 extend_conversion_buffer (&buf);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6011 }
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6012
30950
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6013 coding->consumed = consumed;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6014 coding->consumed_char = consumed_char;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6015 coding->produced = produced;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6016 coding->produced_char = produced_char;
5682de5cfdac (decode_coding_string): Set members consumed,
Kenichi Handa <handa@m17n.org>
parents: 30847
diff changeset
6017
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6018 newstr = make_uninit_string (produced + shrinked_bytes);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6019 if (from > 0)
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6020 bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6021 bcopy (buf.data, XSTRING (newstr)->data + from, produced);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6022 if (shrinked_bytes > from)
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6023 bcopy (XSTRING (str)->data + to_byte,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6024 XSTRING (newstr)->data + from + produced,
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6025 shrinked_bytes - from);
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6026
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6027 free_conversion_buffer (&buf);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6028 coding_free_composition_data (coding);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6029
30833
2db6e42a6ba3 (MINIMUM_CONVERSION_BUFFER_SIZE): Macro deleted.
Kenichi Handa <handa@m17n.org>
parents: 30756
diff changeset
6030 return newstr;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6031 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6032
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6033
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6034 #ifdef emacs
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6035 /*** 8. Emacs Lisp library functions ***/
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6036
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6037 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6038 "Return t if OBJECT is nil or a coding-system.\n\
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6039 See the documentation of `make-coding-system' for information\n\
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6040 about coding-system objects.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6041 (obj)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6042 Lisp_Object obj;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6043 {
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6044 if (NILP (obj))
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6045 return Qt;
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6046 if (!SYMBOLP (obj))
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6047 return Qnil;
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6048 /* Get coding-spec vector for OBJ. */
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6049 obj = Fget (obj, Qcoding_system);
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6050 return ((VECTORP (obj) && XVECTOR (obj)->size == 5)
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6051 ? Qt : Qnil);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6052 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6053
17717
4891aaecc5cc (Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents: 17485
diff changeset
6054 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
6055 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
6056 "Read a coding system from the minibuffer, prompting with string PROMPT.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6057 (prompt)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6058 Lisp_Object prompt;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6059 {
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6060 Lisp_Object val;
17717
4891aaecc5cc (Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents: 17485
diff changeset
6061 do
4891aaecc5cc (Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents: 17485
diff changeset
6062 {
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6063 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil,
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6064 Qt, Qnil, Qcoding_system_history, Qnil, Qnil);
17717
4891aaecc5cc (Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents: 17485
diff changeset
6065 }
4891aaecc5cc (Fread_coding_system, Fread_non_nil_coding_system):
Richard M. Stallman <rms@gnu.org>
parents: 17485
diff changeset
6066 while (XSTRING (val)->size == 0);
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6067 return (Fintern (val, Qnil));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6068 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6069
19758
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6070 DEFUN ("read-coding-system", Fread_coding_system, Sread_coding_system, 1, 2, 0,
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6071 "Read a coding system from the minibuffer, prompting with string PROMPT.\n\
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6072 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM.")
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6073 (prompt, default_coding_system)
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6074 Lisp_Object prompt, default_coding_system;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6075 {
19747
bed06df9cbc5 (setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents: 19743
diff changeset
6076 Lisp_Object val;
19758
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6077 if (SYMBOLP (default_coding_system))
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6078 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name);
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
6079 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil,
19758
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6080 Qt, Qnil, Qcoding_system_history,
49a1662b68dd (Fread_coding_system): New optional arg DEFAULT_CODING_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 19750
diff changeset
6081 default_coding_system, Qnil);
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6082 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6083 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6084
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6085 DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6086 1, 1, 0,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6087 "Check validity of CODING-SYSTEM.\n\
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6088 If valid, return CODING-SYSTEM, else signal a `coding-system-error' error.\n\
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6089 It is valid if it is a symbol with a non-nil `coding-system' property.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6090 The value of property should be a vector of length 5.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6091 (coding_system)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6092 Lisp_Object coding_system;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6093 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6094 CHECK_SYMBOL (coding_system, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6095 if (!NILP (Fcoding_system_p (coding_system)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6096 return coding_system;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6097 while (1)
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6098 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6099 }
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6100
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6101 Lisp_Object
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6102 detect_coding_system (src, src_bytes, highest, multibytep)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6103 unsigned char *src;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6104 int src_bytes, highest;
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6105 int multibytep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6106 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6107 int coding_mask, eol_type;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6108 Lisp_Object val, tmp;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6109 int dummy;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6110
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6111 coding_mask = detect_coding_mask (src, src_bytes, NULL, &dummy, multibytep);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6112 eol_type = detect_eol_type (src, src_bytes, &dummy);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6113 if (eol_type == CODING_EOL_INCONSISTENT)
23082
910740dcedb5 (detect_coding_system): If detect_eol_type returns
Kenichi Handa <handa@m17n.org>
parents: 23067
diff changeset
6114 eol_type = CODING_EOL_UNDECIDED;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6115
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6116 if (!coding_mask)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6117 {
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6118 val = Qundecided;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6119 if (eol_type != CODING_EOL_UNDECIDED)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6120 {
19747
bed06df9cbc5 (setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents: 19743
diff changeset
6121 Lisp_Object val2;
bed06df9cbc5 (setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents: 19743
diff changeset
6122 val2 = Fget (Qundecided, Qeol_type);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6123 if (VECTORP (val2))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6124 val = XVECTOR (val2)->contents[eol_type];
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6125 }
22460
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6126 return (highest ? val : Fcons (val, Qnil));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6127 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6128
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6129 /* At first, gather possible coding systems in VAL. */
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6130 val = Qnil;
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6131 for (tmp = Vcoding_category_list; CONSP (tmp); tmp = XCDR (tmp))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6132 {
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6133 Lisp_Object category_val, category_index;
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6134
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6135 category_index = Fget (XCAR (tmp), Qcoding_category_index);
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6136 category_val = Fsymbol_value (XCAR (tmp));
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6137 if (!NILP (category_val)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6138 && NATNUMP (category_index)
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6139 && (coding_mask & (1 << XFASTINT (category_index))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6140 {
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6141 val = Fcons (category_val, val);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6142 if (highest)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6143 break;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6144 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6145 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6146 if (!highest)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6147 val = Fnreverse (val);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6148
22254
1deb7d79af00 (detect_coding_system): Treat CODING_EOL_INCONSISTENT
Richard M. Stallman <rms@gnu.org>
parents: 22226
diff changeset
6149 /* Then, replace the elements with subsidiary coding systems. */
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6150 for (tmp = val; CONSP (tmp); tmp = XCDR (tmp))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6151 {
22254
1deb7d79af00 (detect_coding_system): Treat CODING_EOL_INCONSISTENT
Richard M. Stallman <rms@gnu.org>
parents: 22226
diff changeset
6152 if (eol_type != CODING_EOL_UNDECIDED
1deb7d79af00 (detect_coding_system): Treat CODING_EOL_INCONSISTENT
Richard M. Stallman <rms@gnu.org>
parents: 22226
diff changeset
6153 && eol_type != CODING_EOL_INCONSISTENT)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6154 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6155 Lisp_Object eol;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6156 eol = Fget (XCAR (tmp), Qeol_type);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6157 if (VECTORP (eol))
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6158 XCAR (tmp) = XVECTOR (eol)->contents[eol_type];
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6159 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6160 }
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6161 return (highest ? XCAR (val) : val);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6162 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6163
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6164 DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6165 2, 3, 0,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6166 "Detect coding system of the text in the region between START and END.\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6167 Return a list of possible coding systems ordered by priority.\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6168 \n\
22460
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6169 If only ASCII characters are found, it returns a list of single element\n\
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6170 `undecided' or its subsidiary coding system according to a detected\n\
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6171 end-of-line format.\n\
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6172 \n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6173 If optional argument HIGHEST is non-nil, return the coding system of\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6174 highest priority.")
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6175 (start, end, highest)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6176 Lisp_Object start, end, highest;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6177 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6178 int from, to;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6179 int from_byte, to_byte;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6180
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6181 CHECK_NUMBER_COERCE_MARKER (start, 0);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6182 CHECK_NUMBER_COERCE_MARKER (end, 1);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6183
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6184 validate_region (&start, &end);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6185 from = XINT (start), to = XINT (end);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6186 from_byte = CHAR_TO_BYTE (from);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6187 to_byte = CHAR_TO_BYTE (to);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6188
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6189 if (from < GPT && to >= GPT)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6190 move_gap_both (to, to_byte);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6191
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6192 return detect_coding_system (BYTE_POS_ADDR (from_byte),
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6193 to_byte - from_byte,
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6194 !NILP (highest),
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6195 !NILP (current_buffer
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6196 ->enable_multibyte_characters));
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6197 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6198
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6199 DEFUN ("detect-coding-string", Fdetect_coding_string, Sdetect_coding_string,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6200 1, 2, 0,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6201 "Detect coding system of the text in STRING.\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6202 Return a list of possible coding systems ordered by priority.\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6203 \n\
22460
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6204 If only ASCII characters are found, it returns a list of single element\n\
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6205 `undecided' or its subsidiary coding system according to a detected\n\
7ca919476042 (detect_coding_system): Always return a list of HIGHEST is zero.
Kenichi Handa <handa@m17n.org>
parents: 22341
diff changeset
6206 end-of-line format.\n\
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6207 \n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6208 If optional argument HIGHEST is non-nil, return the coding system of\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6209 highest priority.")
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6210 (string, highest)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6211 Lisp_Object string, highest;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6212 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6213 CHECK_STRING (string, 0);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6214
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6215 return detect_coding_system (XSTRING (string)->data,
21244
50929073a0ba Use STRING_BYTES and SET_STRING_BYTES.
Richard M. Stallman <rms@gnu.org>
parents: 21190
diff changeset
6216 STRING_BYTES (XSTRING (string)),
34531
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6217 !NILP (highest),
37f85e931855 (ONE_MORE_BYTE_CHECK_MULTIBYTE): New macro.
Kenichi Handa <handa@m17n.org>
parents: 34197
diff changeset
6218 STRING_MULTIBYTE (string));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6219 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6220
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6221 /* Return an intersection of lists L1 and L2. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6222
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6223 static Lisp_Object
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6224 intersection (l1, l2)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6225 Lisp_Object l1, l2;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6226 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6227 Lisp_Object val;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6228
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6229 for (val = Qnil; CONSP (l1); l1 = XCDR (l1))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6230 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6231 if (!NILP (Fmemq (XCAR (l1), l2)))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6232 val = Fcons (XCAR (l1), val);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6233 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6234 return val;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6235 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6236
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6237
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6238 /* Subroutine for Fsafe_coding_systems_region_internal.
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6239
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6240 Return a list of coding systems that safely encode the multibyte
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6241 text between P and PEND. SAFE_CODINGS, if non-nil, is a list of
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6242 possible coding systems. If it is nil, it means that we have not
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6243 yet found any coding systems.
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6244
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6245 WORK_TABLE is a copy of the char-table Vchar_coding_system_table. An
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6246 element of WORK_TABLE is set to t once the element is looked up.
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6247
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6248 If a non-ASCII single byte char is found, set
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6249 *single_byte_char_found to 1. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6250
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6251 static Lisp_Object
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6252 find_safe_codings (p, pend, safe_codings, work_table, single_byte_char_found)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6253 unsigned char *p, *pend;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6254 Lisp_Object safe_codings, work_table;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6255 int *single_byte_char_found;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6256 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6257 int c, len, idx;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6258 Lisp_Object val;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6259
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6260 while (p < pend)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6261 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6262 c = STRING_CHAR_AND_LENGTH (p, pend - p, len);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6263 p += len;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6264 if (ASCII_BYTE_P (c))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6265 /* We can ignore ASCII characters here. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6266 continue;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6267 if (SINGLE_BYTE_CHAR_P (c))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6268 *single_byte_char_found = 1;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6269 if (NILP (safe_codings))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6270 continue;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6271 /* Check the safe coding systems for C. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6272 val = char_table_ref_and_index (work_table, c, &idx);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6273 if (EQ (val, Qt))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6274 /* This element was already checked. Ignore it. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6275 continue;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6276 /* Remember that we checked this element. */
30674
9aad40936cfe *coding.c (find_safe_codings): CHAR_TABLE_SET index must be a lisp object.
Ken Raeburn <raeburn@raeburn.org>
parents: 30581
diff changeset
6277 CHAR_TABLE_SET (work_table, make_number (idx), Qt);
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6278
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6279 /* If there are some safe coding systems for C and we have
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6280 already found the other set of coding systems for the
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6281 different characters, get the intersection of them. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6282 if (!EQ (safe_codings, Qt) && !NILP (val))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6283 val = intersection (safe_codings, val);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6284 safe_codings = val;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6285 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6286 return safe_codings;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6287 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6288
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6289
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6290 /* Return a list of coding systems that safely encode the text between
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6291 START and END. If the text contains only ASCII or is unibyte,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6292 return t. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6293
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6294 DEFUN ("find-coding-systems-region-internal",
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6295 Ffind_coding_systems_region_internal,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6296 Sfind_coding_systems_region_internal, 2, 2, 0,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6297 "Internal use only.")
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6298 (start, end)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6299 Lisp_Object start, end;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6300 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6301 Lisp_Object work_table, safe_codings;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6302 int non_ascii_p = 0;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6303 int single_byte_char_found = 0;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6304 unsigned char *p1, *p1end, *p2, *p2end, *p;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6305
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6306 if (STRINGP (start))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6307 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6308 if (!STRING_MULTIBYTE (start))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6309 return Qt;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6310 p1 = XSTRING (start)->data, p1end = p1 + STRING_BYTES (XSTRING (start));
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6311 p2 = p2end = p1end;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6312 if (XSTRING (start)->size != STRING_BYTES (XSTRING (start)))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6313 non_ascii_p = 1;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6314 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6315 else
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6316 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6317 int from, to, stop;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6318
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6319 CHECK_NUMBER_COERCE_MARKER (start, 0);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6320 CHECK_NUMBER_COERCE_MARKER (end, 1);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6321 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6322 args_out_of_range (start, end);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6323 if (NILP (current_buffer->enable_multibyte_characters))
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6324 return Qt;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6325 from = CHAR_TO_BYTE (XINT (start));
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6326 to = CHAR_TO_BYTE (XINT (end));
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6327 stop = from < GPT_BYTE && GPT_BYTE < to ? GPT_BYTE : to;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6328 p1 = BYTE_POS_ADDR (from), p1end = p1 + (stop - from);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6329 if (stop == to)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6330 p2 = p2end = p1end;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6331 else
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6332 p2 = BYTE_POS_ADDR (stop), p2end = p2 + (to - stop);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6333 if (XINT (end) - XINT (start) != to - from)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6334 non_ascii_p = 1;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6335 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6336
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6337 if (!non_ascii_p)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6338 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6339 /* We are sure that the text contains no multibyte character.
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6340 Check if it contains eight-bit-graphic. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6341 p = p1;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6342 for (p = p1; p < p1end && ASCII_BYTE_P (*p); p++);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6343 if (p == p1end)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6344 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6345 for (p = p2; p < p2end && ASCII_BYTE_P (*p); p++);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6346 if (p == p2end)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6347 return Qt;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6348 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6349 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6350
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6351 /* The text contains non-ASCII characters. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6352 work_table = Fcopy_sequence (Vchar_coding_system_table);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6353 safe_codings = find_safe_codings (p1, p1end, Qt, work_table,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6354 &single_byte_char_found);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6355 if (p2 < p2end)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6356 safe_codings = find_safe_codings (p2, p2end, safe_codings, work_table,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6357 &single_byte_char_found);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6358
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6359 if (!single_byte_char_found)
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6360 {
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6361 /* Append generic coding systems. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6362 Lisp_Object args[2];
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6363 args[0] = safe_codings;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6364 args[1] = Fchar_table_extra_slot (Vchar_coding_system_table,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6365 make_number (0));
30674
9aad40936cfe *coding.c (find_safe_codings): CHAR_TABLE_SET index must be a lisp object.
Ken Raeburn <raeburn@raeburn.org>
parents: 30581
diff changeset
6366 safe_codings = Fappend (2, args);
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6367 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6368 else
33931
6ed22a848efa (Ffind_coding_systems_region_internal): Be sure to
Kenichi Handa <handa@m17n.org>
parents: 33828
diff changeset
6369 safe_codings = Fcons (Qraw_text,
6ed22a848efa (Ffind_coding_systems_region_internal): Be sure to
Kenichi Handa <handa@m17n.org>
parents: 33828
diff changeset
6370 Fcons (Qemacs_mule,
6ed22a848efa (Ffind_coding_systems_region_internal): Be sure to
Kenichi Handa <handa@m17n.org>
parents: 33828
diff changeset
6371 Fcons (Qno_conversion, safe_codings)));
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6372 return safe_codings;
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6373 }
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6374
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
6375
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6376 Lisp_Object
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6377 code_convert_region1 (start, end, coding_system, encodep)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6378 Lisp_Object start, end, coding_system;
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6379 int encodep;
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6380 {
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6381 struct coding_system coding;
34988
8cd5e6ad71a2 (detect_coding_iso2022, setup_coding_system): Remove
Eli Zaretskii <eliz@gnu.org>
parents: 34892
diff changeset
6382 int from, to;
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6383
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6384 CHECK_NUMBER_COERCE_MARKER (start, 0);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6385 CHECK_NUMBER_COERCE_MARKER (end, 1);
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6386 CHECK_SYMBOL (coding_system, 2);
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6387
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6388 validate_region (&start, &end);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6389 from = XFASTINT (start);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6390 to = XFASTINT (end);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6391
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6392 if (NILP (coding_system))
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6393 return make_number (to - from);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6394
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6395 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6396 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6397
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6398 coding.mode |= CODING_MODE_LAST_BLOCK;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6399 coding.src_multibyte = coding.dst_multibyte
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6400 = !NILP (current_buffer->enable_multibyte_characters);
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
6401 code_convert_region (from, CHAR_TO_BYTE (from), to, CHAR_TO_BYTE (to),
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
6402 &coding, encodep, 1);
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6403 Vlast_coding_system_used = coding.symbol;
20931
068eb408c911 (decode_coding_iso2022): Update coding->fake_multibyte.
Kenichi Handa <handa@m17n.org>
parents: 20803
diff changeset
6404 return make_number (coding.produced_char);
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6405 }
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6406
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6407 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region,
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6408 3, 3, "r\nzCoding system: ",
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6409 "Decode the current region by specified coding system.\n\
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6410 When called from a program, takes three arguments:\n\
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6411 START, END, and CODING-SYSTEM. START and END are buffer positions.\n\
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6412 This function sets `last-coding-system-used' to the precise coding system\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6413 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6414 not fully specified.)\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6415 It returns the length of the decoded text.")
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6416 (start, end, coding_system)
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6417 Lisp_Object start, end, coding_system;
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6418 {
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6419 return code_convert_region1 (start, end, coding_system, 0);
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6420 }
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6421
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6422 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region,
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6423 3, 3, "r\nzCoding system: ",
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6424 "Encode the current region by specified coding system.\n\
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6425 When called from a program, takes three arguments:\n\
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6426 START, END, and CODING-SYSTEM. START and END are buffer positions.\n\
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6427 This function sets `last-coding-system-used' to the precise coding system\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6428 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6429 not fully specified.)\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6430 It returns the length of the encoded text.")
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6431 (start, end, coding_system)
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6432 Lisp_Object start, end, coding_system;
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6433 {
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6434 return code_convert_region1 (start, end, coding_system, 1);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6435 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6436
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6437 Lisp_Object
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6438 code_convert_string1 (string, coding_system, nocopy, encodep)
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6439 Lisp_Object string, coding_system, nocopy;
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6440 int encodep;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6441 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6442 struct coding_system coding;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6443
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6444 CHECK_STRING (string, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6445 CHECK_SYMBOL (coding_system, 1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6446
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6447 if (NILP (coding_system))
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6448 return (NILP (nocopy) ? Fcopy_sequence (string) : string);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6449
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6450 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6451 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6452
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6453 coding.mode |= CODING_MODE_LAST_BLOCK;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6454 string = (encodep
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6455 ? encode_coding_string (string, &coding, !NILP (nocopy))
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6456 : decode_coding_string (string, &coding, !NILP (nocopy)));
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6457 Vlast_coding_system_used = coding.symbol;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6458
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6459 return string;
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6460 }
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6461
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6462 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string,
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6463 2, 3, 0,
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6464 "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6465 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6466 if the decoding operation is trivial.\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6467 This function sets `last-coding-system-used' to the precise coding system\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6468 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6469 not fully specified.)")
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6470 (string, coding_system, nocopy)
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6471 Lisp_Object string, coding_system, nocopy;
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6472 {
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6473 return code_convert_string1 (string, coding_system, nocopy, 0);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6474 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6475
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6476 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
6477 2, 3, 0,
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6478 "Encode STRING to CODING-SYSTEM, and return the result.\n\
19815
e68cab4f1f70 (Fencode_coding_string, Fdecode_coding_string): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 19763
diff changeset
6479 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6480 if the encoding operation is trivial.\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6481 This function sets `last-coding-system-used' to the precise coding system\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6482 used (which may be different from CODING-SYSTEM if CODING-SYSTEM is\n\
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6483 not fully specified.)")
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6484 (string, coding_system, nocopy)
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6485 Lisp_Object string, coding_system, nocopy;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6486 {
22020
e144ad749084 (code_convert_region1): Set Vlast_coding_system_used.
Richard M. Stallman <rms@gnu.org>
parents: 22009
diff changeset
6487 return code_convert_string1 (string, coding_system, nocopy, 1);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6488 }
20803
0fa2183c587d (ENCODE_ISO_CHARACTER): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 20794
diff changeset
6489
22341
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6490 /* Encode or decode STRING according to CODING_SYSTEM.
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6491 Do not set Vlast_coding_system_used.
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6492
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6493 This function is called only from macros DECODE_FILE and
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6494 ENCODE_FILE, thus we ignore character composition. */
22341
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6495
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6496 Lisp_Object
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6497 code_convert_string_norecord (string, coding_system, encodep)
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6498 Lisp_Object string, coding_system;
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6499 int encodep;
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6500 {
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6501 struct coding_system coding;
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6502
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6503 CHECK_STRING (string, 0);
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6504 CHECK_SYMBOL (coding_system, 1);
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6505
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6506 if (NILP (coding_system))
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6507 return string;
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6508
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6509 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0)
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6510 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data);
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6511
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6512 coding.composing = COMPOSITION_DISABLED;
22341
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6513 coding.mode |= CODING_MODE_LAST_BLOCK;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6514 return (encodep
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6515 ? encode_coding_string (string, &coding, 1)
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6516 : decode_coding_string (string, &coding, 1));
22341
572ba933a4bf (code_convert_string_norecord): New function.
Karl Heuer <kwzh@gnu.org>
parents: 22329
diff changeset
6517 }
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6518
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6519 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0,
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6520 "Decode a Japanese character which has CODE in shift_jis encoding.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6521 Return the corresponding character.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6522 (code)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6523 Lisp_Object code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6524 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6525 unsigned char c1, c2, s1, s2;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6526 Lisp_Object val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6527
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6528 CHECK_NUMBER (code, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6529 s1 = (XFASTINT (code)) >> 8, s2 = (XFASTINT (code)) & 0xFF;
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6530 if (s1 == 0)
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6531 {
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6532 if (s2 < 0x80)
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6533 XSETFASTINT (val, s2);
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6534 else if (s2 >= 0xA0 || s2 <= 0xDF)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6535 XSETFASTINT (val, MAKE_CHAR (charset_katakana_jisx0201, s2, 0));
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6536 else
24344
8b7ef7fb9e2e (Fdecode_sjis_char): In case of error, use %x for
Kenichi Handa <handa@m17n.org>
parents: 24324
diff changeset
6537 error ("Invalid Shift JIS code: %x", XFASTINT (code));
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6538 }
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6539 else
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6540 {
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6541 if ((s1 < 0x80 || s1 > 0x9F && s1 < 0xE0 || s1 > 0xEF)
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6542 || (s2 < 0x40 || s2 == 0x7F || s2 > 0xFC))
24344
8b7ef7fb9e2e (Fdecode_sjis_char): In case of error, use %x for
Kenichi Handa <handa@m17n.org>
parents: 24324
diff changeset
6543 error ("Invalid Shift JIS code: %x", XFASTINT (code));
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6544 DECODE_SJIS (s1, s2, c1, c2);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6545 XSETFASTINT (val, MAKE_CHAR (charset_jisx0208, c1, c2));
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6546 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6547 return val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6548 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6549
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6550 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0,
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6551 "Encode a Japanese character CHAR to shift_jis encoding.\n\
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6552 Return the corresponding code in SJIS.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6553 (ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6554 Lisp_Object ch;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6555 {
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
6556 int charset, c1, c2, s1, s2;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6557 Lisp_Object val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6558
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6559 CHECK_NUMBER (ch, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6560 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2);
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6561 if (charset == CHARSET_ASCII)
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6562 {
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6563 val = ch;
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6564 }
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6565 else if (charset == charset_jisx0208
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6566 && c1 > 0x20 && c1 < 0x7F && c2 > 0x20 && c2 < 0x7F)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6567 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6568 ENCODE_SJIS (c1, c2, s1, s2);
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
6569 XSETFASTINT (val, (s1 << 8) | s2);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6570 }
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6571 else if (charset == charset_katakana_jisx0201
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6572 && c1 > 0x20 && c2 < 0xE0)
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6573 {
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6574 XSETFASTINT (val, c1 | 0x80);
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6575 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6576 else
24065
7e291dea6141 (Fdecode_sjis_char): Decode Japanese Katakana character
Kenichi Handa <handa@m17n.org>
parents: 24056
diff changeset
6577 error ("Can't encode to shift_jis: %d", XFASTINT (ch));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6578 return val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6579 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6580
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6581 DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0,
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6582 "Decode a Big5 character which has CODE in BIG5 coding system.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6583 Return the corresponding character.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6584 (code)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6585 Lisp_Object code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6586 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6587 int charset;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6588 unsigned char b1, b2, c1, c2;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6589 Lisp_Object val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6590
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6591 CHECK_NUMBER (code, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6592 b1 = (XFASTINT (code)) >> 8, b2 = (XFASTINT (code)) & 0xFF;
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6593 if (b1 == 0)
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6594 {
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6595 if (b2 >= 0x80)
24344
8b7ef7fb9e2e (Fdecode_sjis_char): In case of error, use %x for
Kenichi Handa <handa@m17n.org>
parents: 24324
diff changeset
6596 error ("Invalid BIG5 code: %x", XFASTINT (code));
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6597 val = code;
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6598 }
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6599 else
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6600 {
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6601 if ((b1 < 0xA1 || b1 > 0xFE)
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6602 || (b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE))
24344
8b7ef7fb9e2e (Fdecode_sjis_char): In case of error, use %x for
Kenichi Handa <handa@m17n.org>
parents: 24324
diff changeset
6603 error ("Invalid BIG5 code: %x", XFASTINT (code));
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6604 DECODE_BIG5 (b1, b2, charset, c1, c2);
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6605 XSETFASTINT (val, MAKE_CHAR (charset, c1, c2));
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6606 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6607 return val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6608 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6609
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6610 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0,
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6611 "Encode the Big5 character CHAR to BIG5 coding system.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6612 Return the corresponding character code in Big5.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6613 (ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6614 Lisp_Object ch;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6615 {
17320
9d15bec5f47e (detect_coding_iso2022, detect_coding_mask): Ignore
Kenichi Handa <handa@m17n.org>
parents: 17304
diff changeset
6616 int charset, c1, c2, b1, b2;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6617 Lisp_Object val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6618
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6619 CHECK_NUMBER (ch, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6620 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2);
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6621 if (charset == CHARSET_ASCII)
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6622 {
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6623 val = ch;
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6624 }
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6625 else if ((charset == charset_big5_1
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6626 && (XFASTINT (ch) >= 0x250a1 && XFASTINT (ch) <= 0x271ec))
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6627 || (charset == charset_big5_2
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6628 && XFASTINT (ch) >= 0x290a1 && XFASTINT (ch) <= 0x2bdb2))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6629 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6630 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
6631 XSETFASTINT (val, (b1 << 8) | b2);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6632 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6633 else
24324
2eec590faf26 (Fdecode_sjis_char, Fencode_sjis_char): Hanlde
Kenichi Handa <handa@m17n.org>
parents: 24316
diff changeset
6634 error ("Can't encode to Big5: %d", XFASTINT (ch));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6635 return val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6636 }
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6637
18002
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
6638 DEFUN ("set-terminal-coding-system-internal",
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
6639 Fset_terminal_coding_system_internal,
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
6640 Sset_terminal_coding_system_internal, 1, 1, 0, "")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6641 (coding_system)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6642 Lisp_Object coding_system;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6643 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6644 CHECK_SYMBOL (coding_system, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6645 setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding);
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
6646 /* We had better not send unsafe characters to terminal. */
19285
af3d00fde172 (Fset_terminal_coding_system_internal): Set
Kenichi Handa <handa@m17n.org>
parents: 19280
diff changeset
6647 terminal_coding.flags |= CODING_FLAG_ISO_SAFE;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6648 /* Characer composition should be disabled. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6649 terminal_coding.composing = COMPOSITION_DISABLED;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6650 terminal_coding.src_multibyte = 1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6651 terminal_coding.dst_multibyte = 0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6652 return Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6653 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6654
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6655 DEFUN ("set-safe-terminal-coding-system-internal",
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6656 Fset_safe_terminal_coding_system_internal,
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6657 Sset_safe_terminal_coding_system_internal, 1, 1, 0, "")
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6658 (coding_system)
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6659 Lisp_Object coding_system;
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6660 {
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6661 CHECK_SYMBOL (coding_system, 0);
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6662 setup_coding_system (Fcheck_coding_system (coding_system),
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6663 &safe_terminal_coding);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6664 /* Characer composition should be disabled. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6665 safe_terminal_coding.composing = COMPOSITION_DISABLED;
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6666 safe_terminal_coding.src_multibyte = 1;
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6667 safe_terminal_coding.dst_multibyte = 0;
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6668 return Qnil;
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6669 }
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6670
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6671 DEFUN ("terminal-coding-system",
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6672 Fterminal_coding_system, Sterminal_coding_system, 0, 0, 0,
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6673 "Return coding system specified for terminal output.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6674 ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6675 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6676 return terminal_coding.symbol;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6677 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6678
18002
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
6679 DEFUN ("set-keyboard-coding-system-internal",
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
6680 Fset_keyboard_coding_system_internal,
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
6681 Sset_keyboard_coding_system_internal, 1, 1, 0, "")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6682 (coding_system)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6683 Lisp_Object coding_system;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6684 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6685 CHECK_SYMBOL (coding_system, 0);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6686 setup_coding_system (Fcheck_coding_system (coding_system), &keyboard_coding);
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6687 /* Characer composition should be disabled. */
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6688 keyboard_coding.composing = COMPOSITION_DISABLED;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6689 return Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6690 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6691
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6692 DEFUN ("keyboard-coding-system",
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6693 Fkeyboard_coding_system, Skeyboard_coding_system, 0, 0, 0,
20680
dd46027e8412 (code_convert_region): Always count chars inserted
Richard M. Stallman <rms@gnu.org>
parents: 20668
diff changeset
6694 "Return coding system specified for decoding keyboard input.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6695 ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6696 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6697 return keyboard_coding.symbol;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6698 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6699
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6700
18536
69c0e220b626 (Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents: 18523
diff changeset
6701 DEFUN ("find-operation-coding-system", Ffind_operation_coding_system,
69c0e220b626 (Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents: 18523
diff changeset
6702 Sfind_operation_coding_system, 1, MANY, 0,
69c0e220b626 (Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents: 18523
diff changeset
6703 "Choose a coding system for an operation based on the target name.\n\
23201
392b44751a22 (ccl_coding_driver): Always calculate correct mulibyte
Kenichi Handa <handa@m17n.org>
parents: 23153
diff changeset
6704 The value names a pair of coding systems: (DECODING-SYSTEM . ENCODING-SYSTEM).\n\
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6705 DECODING-SYSTEM is the coding system to use for decoding\n\
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6706 \(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system\n\
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6707 for encoding (in case OPERATION does encoding).\n\
17304
ecacd8936926 (Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 17190
diff changeset
6708 \n\
ecacd8936926 (Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 17190
diff changeset
6709 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
6710 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
6711 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
6712 For network I/O, `open-network-stream'.\n\
ecacd8936926 (Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 17190
diff changeset
6713 \n\
ecacd8936926 (Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 17190
diff changeset
6714 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
6715 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
6716 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
6717 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
6718 \n\
ecacd8936926 (Ffind_coding_system): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 17190
diff changeset
6719 TARGET has a meaning which depends on OPERATION:\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6720 For file I/O, TARGET is a file name.\n\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6721 For process I/O, TARGET is a process name.\n\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6722 For network I/O, TARGET is a service name or a port number\n\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6723 \n\
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6724 This function looks up what specified for TARGET in,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6725 `file-coding-system-alist', `process-coding-system-alist',\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6726 or `network-coding-system-alist' depending on OPERATION.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6727 They may specify a coding system, a cons of coding systems,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6728 or a function symbol to call.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6729 In the last case, we call the function with one argument,\n\
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6730 which is a list of all the arguments given to this function.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6731 (nargs, args)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6732 int nargs;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6733 Lisp_Object *args;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6734 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6735 Lisp_Object operation, target_idx, target, val;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6736 register Lisp_Object chain;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6737
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6738 if (nargs < 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6739 error ("Too few arguments");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6740 operation = args[0];
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6741 if (!SYMBOLP (operation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6742 || !INTEGERP (target_idx = Fget (operation, Qtarget_idx)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6743 error ("Invalid first arguement");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6744 if (nargs < 1 + XINT (target_idx))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6745 error ("Too few arguments for operation: %s",
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6746 XSYMBOL (operation)->name->data);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6747 target = args[XINT (target_idx) + 1];
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6748 if (!(STRINGP (target)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6749 || (EQ (operation, Qopen_network_stream) && INTEGERP (target))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6750 error ("Invalid %dth argument", XINT (target_idx) + 1);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6751
18613
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18536
diff changeset
6752 chain = ((EQ (operation, Qinsert_file_contents)
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18536
diff changeset
6753 || EQ (operation, Qwrite_region))
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6754 ? Vfile_coding_system_alist
18613
614b916ff5bf Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents: 18536
diff changeset
6755 : (EQ (operation, Qopen_network_stream)
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6756 ? Vnetwork_coding_system_alist
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6757 : Vprocess_coding_system_alist));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6758 if (NILP (chain))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6759 return Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6760
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6761 for (; CONSP (chain); chain = XCDR (chain))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6762 {
19747
bed06df9cbc5 (setup_coding_system, Ffind_operation_coding_system)
Richard M. Stallman <rms@gnu.org>
parents: 19743
diff changeset
6763 Lisp_Object elt;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6764 elt = XCAR (chain);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6765
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6766 if (CONSP (elt)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6767 && ((STRINGP (target)
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6768 && STRINGP (XCAR (elt))
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6769 && fast_string_match (XCAR (elt), target) >= 0)
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6770 || (INTEGERP (target) && EQ (target, XCAR (elt)))))
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6771 {
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6772 val = XCDR (elt);
19763
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6773 /* Here, if VAL is both a valid coding system and a valid
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6774 function symbol, we return VAL as a coding system. */
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6775 if (CONSP (val))
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6776 return val;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6777 if (! SYMBOLP (val))
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6778 return Qnil;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6779 if (! NILP (Fcoding_system_p (val)))
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6780 return Fcons (val, val);
19763
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6781 if (! NILP (Ffboundp (val)))
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6782 {
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6783 val = call1 (val, Flist (nargs, args));
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6784 if (CONSP (val))
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6785 return val;
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6786 if (SYMBOLP (val) && ! NILP (Fcoding_system_p (val)))
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6787 return Fcons (val, val);
ab2fd2c85986 (Ffind_operation_coding_system): If a function in
Kenichi Handa <handa@m17n.org>
parents: 19758
diff changeset
6788 }
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6789 return Qnil;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
6790 }
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6791 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6792 return Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6793 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6794
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6795 DEFUN ("update-coding-systems-internal", Fupdate_coding_systems_internal,
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6796 Supdate_coding_systems_internal, 0, 0, 0,
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6797 "Update internal database for ISO2022 and CCL based coding systems.\n\
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6798 When values of any coding categories are changed, you must\n\
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6799 call this function")
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6800 ()
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6801 {
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6802 int i;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6803
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6804 for (i = CODING_CATEGORY_IDX_EMACS_MULE; i < CODING_CATEGORY_IDX_MAX; i++)
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6805 {
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6806 Lisp_Object val;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6807
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6808 val = XSYMBOL (XVECTOR (Vcoding_category_table)->contents[i])->value;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6809 if (!NILP (val))
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6810 {
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6811 if (! coding_system_table[i])
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6812 coding_system_table[i] = ((struct coding_system *)
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6813 xmalloc (sizeof (struct coding_system)));
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6814 setup_coding_system (val, coding_system_table[i]);
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6815 }
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6816 else if (coding_system_table[i])
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6817 {
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6818 xfree (coding_system_table[i]);
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6819 coding_system_table[i] = NULL;
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6820 }
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6821 }
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6822
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6823 return Qnil;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6824 }
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6825
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6826 DEFUN ("set-coding-priority-internal", Fset_coding_priority_internal,
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6827 Sset_coding_priority_internal, 0, 0, 0,
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6828 "Update internal database for the current value of `coding-category-list'.\n\
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6829 This function is internal use only.")
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6830 ()
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6831 {
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6832 int i = 0, idx;
22954
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
6833 Lisp_Object val;
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
6834
928b337d953b Avoid using initializers for Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents: 22874
diff changeset
6835 val = Vcoding_category_list;
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6836
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6837 while (CONSP (val) && i < CODING_CATEGORY_IDX_MAX)
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6838 {
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6839 if (! SYMBOLP (XCAR (val)))
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6840 break;
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6841 idx = XFASTINT (Fget (XCAR (val), Qcoding_category_index));
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6842 if (idx >= CODING_CATEGORY_IDX_MAX)
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6843 break;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6844 coding_priorities[i++] = (1 << idx);
25662
0a7261c1d487 Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
parents: 25370
diff changeset
6845 val = XCDR (val);
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6846 }
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6847 /* If coding-category-list is valid and contains all coding
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6848 categories, `i' should be CODING_CATEGORY_IDX_MAX now. If not,
28022
6c41f3276340 Add comments on coding-category-utf-8,
Kenichi Handa <handa@m17n.org>
parents: 27943
diff changeset
6849 the following code saves Emacs from crashing. */
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6850 while (i < CODING_CATEGORY_IDX_MAX)
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6851 coding_priorities[i++] = CODING_CATEGORY_MASK_RAW_TEXT;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6852
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6853 return Qnil;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6854 }
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6855
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6856 #endif /* emacs */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6857
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6858
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
6859 /*** 9. Post-amble ***/
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6860
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21505
diff changeset
6861 void
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6862 init_coding_once ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6863 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6864 int i;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6865
17835
f36ffb6f1208 Name change through the code:
Kenichi Handa <handa@m17n.org>
parents: 17725
diff changeset
6866 /* Emacs' internal format specific initialize routine. */
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6867 for (i = 0; i <= 0x20; i++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6868 emacs_code_class[i] = EMACS_control_code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6869 emacs_code_class[0x0A] = EMACS_linefeed_code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6870 emacs_code_class[0x0D] = EMACS_carriage_return_code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6871 for (i = 0x21 ; i < 0x7F; i++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6872 emacs_code_class[i] = EMACS_ascii_code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6873 emacs_code_class[0x7F] = EMACS_control_code;
26847
2f17ea330dae Include composite.h.
Kenichi Handa <handa@m17n.org>
parents: 26742
diff changeset
6874 for (i = 0x80; i < 0xFF; i++)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6875 emacs_code_class[i] = EMACS_invalid_code;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6876 emacs_code_class[LEADING_CODE_PRIVATE_11] = EMACS_leading_code_3;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6877 emacs_code_class[LEADING_CODE_PRIVATE_12] = EMACS_leading_code_3;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6878 emacs_code_class[LEADING_CODE_PRIVATE_21] = EMACS_leading_code_4;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6879 emacs_code_class[LEADING_CODE_PRIVATE_22] = EMACS_leading_code_4;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6880
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6881 /* ISO2022 specific initialize routine. */
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6882 for (i = 0; i < 0x20; i++)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6883 iso_code_class[i] = ISO_control_0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6884 for (i = 0x21; i < 0x7F; i++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6885 iso_code_class[i] = ISO_graphic_plane_0;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6886 for (i = 0x80; i < 0xA0; i++)
29005
b396df3a5181 (ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
Kenichi Handa <handa@m17n.org>
parents: 28512
diff changeset
6887 iso_code_class[i] = ISO_control_1;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6888 for (i = 0xA1; i < 0xFF; i++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6889 iso_code_class[i] = ISO_graphic_plane_1;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6890 iso_code_class[0x20] = iso_code_class[0x7F] = ISO_0x20_or_0x7F;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6891 iso_code_class[0xA0] = iso_code_class[0xFF] = ISO_0xA0_or_0xFF;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6892 iso_code_class[ISO_CODE_CR] = ISO_carriage_return;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6893 iso_code_class[ISO_CODE_SO] = ISO_shift_out;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6894 iso_code_class[ISO_CODE_SI] = ISO_shift_in;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6895 iso_code_class[ISO_CODE_SS2_7] = ISO_single_shift_2_7;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6896 iso_code_class[ISO_CODE_ESC] = ISO_escape;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6897 iso_code_class[ISO_CODE_SS2] = ISO_single_shift_2;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6898 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6899 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6900
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6901 setup_coding_system (Qnil, &keyboard_coding);
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6902 setup_coding_system (Qnil, &terminal_coding);
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
6903 setup_coding_system (Qnil, &safe_terminal_coding);
22979
ceb8e4a89a32 (default_buffer_file_coding): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22964
diff changeset
6904 setup_coding_system (Qnil, &default_buffer_file_coding);
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6905
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6906 bzero (coding_system_table, sizeof coding_system_table);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6907
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6908 bzero (ascii_skip_code, sizeof ascii_skip_code);
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6909 for (i = 0; i < 128; i++)
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6910 ascii_skip_code[i] = 1;
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
6911
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6912 #if defined (MSDOS) || defined (WINDOWSNT)
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6913 system_eol_type = CODING_EOL_CRLF;
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6914 #else
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6915 system_eol_type = CODING_EOL_LF;
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6916 #endif
26067
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
6917
f54ca66e2571 (code_convert_string): Add record_unwind_protect to
Kenichi Handa <handa@m17n.org>
parents: 25860
diff changeset
6918 inhibit_pre_post_conversion = 0;
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6919 }
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6920
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6921 #ifdef emacs
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6922
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21505
diff changeset
6923 void
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6924 syms_of_coding ()
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6925 {
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6926 Qtarget_idx = intern ("target-idx");
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6927 staticpro (&Qtarget_idx);
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6928
19750
95e4e1cba6ac (Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19747
diff changeset
6929 Qcoding_system_history = intern ("coding-system-history");
95e4e1cba6ac (Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19747
diff changeset
6930 staticpro (&Qcoding_system_history);
95e4e1cba6ac (Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19747
diff changeset
6931 Fset (Qcoding_system_history, Qnil);
95e4e1cba6ac (Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19747
diff changeset
6932
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6933 /* Target FILENAME is the first argument. */
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6934 Fput (Qinsert_file_contents, Qtarget_idx, make_number (0));
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6935 /* Target FILENAME is the third argument. */
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6936 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
6937
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6938 Qcall_process = intern ("call-process");
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6939 staticpro (&Qcall_process);
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6940 /* Target PROGRAM is the first argument. */
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6941 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
6942
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6943 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
6944 staticpro (&Qcall_process_region);
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6945 /* Target PROGRAM is the third argument. */
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6946 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
6947
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6948 Qstart_process = intern ("start-process");
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6949 staticpro (&Qstart_process);
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6950 /* Target PROGRAM is the third argument. */
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6951 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
6952
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6953 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
6954 staticpro (&Qopen_network_stream);
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6955 /* Target SERVICE is the fourth argument. */
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
6956 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
6957
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6958 Qcoding_system = intern ("coding-system");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6959 staticpro (&Qcoding_system);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6960
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6961 Qeol_type = intern ("eol-type");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6962 staticpro (&Qeol_type);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6963
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6964 Qbuffer_file_coding_system = intern ("buffer-file-coding-system");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6965 staticpro (&Qbuffer_file_coding_system);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6966
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6967 Qpost_read_conversion = intern ("post-read-conversion");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6968 staticpro (&Qpost_read_conversion);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6969
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6970 Qpre_write_conversion = intern ("pre-write-conversion");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6971 staticpro (&Qpre_write_conversion);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6972
19612
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6973 Qno_conversion = intern ("no-conversion");
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6974 staticpro (&Qno_conversion);
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6975
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6976 Qundecided = intern ("undecided");
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6977 staticpro (&Qundecided);
783efd6c7c1e (Qno_conversion, Qundecided): New variables.
Kenichi Handa <handa@m17n.org>
parents: 19546
diff changeset
6978
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6979 Qcoding_system_p = intern ("coding-system-p");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6980 staticpro (&Qcoding_system_p);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6981
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6982 Qcoding_system_error = intern ("coding-system-error");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6983 staticpro (&Qcoding_system_error);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6984
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6985 Fput (Qcoding_system_error, Qerror_conditions,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6986 Fcons (Qcoding_system_error, Fcons (Qerror, Qnil)));
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6987 Fput (Qcoding_system_error, Qerror_message,
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
6988 build_string ("Invalid coding system"));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6989
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6990 Qcoding_category = intern ("coding-category");
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6991 staticpro (&Qcoding_category);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6992 Qcoding_category_index = intern ("coding-category-index");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6993 staticpro (&Qcoding_category_index);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6994
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6995 Vcoding_category_table
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6996 = Fmake_vector (make_number (CODING_CATEGORY_IDX_MAX), Qnil);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
6997 staticpro (&Vcoding_category_table);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6998 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6999 int i;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7000 for (i = 0; i < CODING_CATEGORY_IDX_MAX; i++)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7001 {
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7002 XVECTOR (Vcoding_category_table)->contents[i]
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7003 = intern (coding_category_name[i]);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7004 Fput (XVECTOR (Vcoding_category_table)->contents[i],
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7005 Qcoding_category_index, make_number (i));
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7006 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7007 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7008
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7009 Qtranslation_table = intern ("translation-table");
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7010 staticpro (&Qtranslation_table);
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
7011 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1));
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7012
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7013 Qtranslation_table_id = intern ("translation-table-id");
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7014 staticpro (&Qtranslation_table_id);
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7015
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7016 Qtranslation_table_for_decode = intern ("translation-table-for-decode");
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7017 staticpro (&Qtranslation_table_for_decode);
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7018
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7019 Qtranslation_table_for_encode = intern ("translation-table-for-encode");
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7020 staticpro (&Qtranslation_table_for_encode);
18536
69c0e220b626 (Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents: 18523
diff changeset
7021
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7022 Qsafe_chars = intern ("safe-chars");
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7023 staticpro (&Qsafe_chars);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7024
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7025 Qchar_coding_system = intern ("char-coding-system");
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7026 staticpro (&Qchar_coding_system);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7027
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7028 /* Intern this now in case it isn't already done.
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7029 Setting this variable twice is harmless.
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7030 But don't staticpro it here--that is done in alloc.c. */
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7031 Qchar_table_extra_slots = intern ("char-table-extra-slots");
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7032 Fput (Qsafe_chars, Qchar_table_extra_slots, make_number (0));
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7033 Fput (Qchar_coding_system, Qchar_table_extra_slots, make_number (1));
20150
402b6e5f4b58 (encode_designation_at_bol): Fix bug of finding graphic
Kenichi Handa <handa@m17n.org>
parents: 20105
diff changeset
7034
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
7035 Qvalid_codes = intern ("valid-codes");
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
7036 staticpro (&Qvalid_codes);
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
7037
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7038 Qemacs_mule = intern ("emacs-mule");
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7039 staticpro (&Qemacs_mule);
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7040
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7041 Qraw_text = intern ("raw-text");
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7042 staticpro (&Qraw_text);
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7043
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7044 defsubr (&Scoding_system_p);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7045 defsubr (&Sread_coding_system);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7046 defsubr (&Sread_non_nil_coding_system);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7047 defsubr (&Scheck_coding_system);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7048 defsubr (&Sdetect_coding_region);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7049 defsubr (&Sdetect_coding_string);
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7050 defsubr (&Sfind_coding_systems_region_internal);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7051 defsubr (&Sdecode_coding_region);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7052 defsubr (&Sencode_coding_region);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7053 defsubr (&Sdecode_coding_string);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7054 defsubr (&Sencode_coding_string);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7055 defsubr (&Sdecode_sjis_char);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7056 defsubr (&Sencode_sjis_char);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7057 defsubr (&Sdecode_big5_char);
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7058 defsubr (&Sencode_big5_char);
18002
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
7059 defsubr (&Sset_terminal_coding_system_internal);
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
7060 defsubr (&Sset_safe_terminal_coding_system_internal);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7061 defsubr (&Sterminal_coding_system);
18002
a14261786239 (encode_invocation_designation): Use macro
Kenichi Handa <handa@m17n.org>
parents: 17835
diff changeset
7062 defsubr (&Sset_keyboard_coding_system_internal);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7063 defsubr (&Skeyboard_coding_system);
18536
69c0e220b626 (Vstandard_character_unification_table_for_decode):
Kenichi Handa <handa@m17n.org>
parents: 18523
diff changeset
7064 defsubr (&Sfind_operation_coding_system);
22874
b133f07a76db (Qvalid_codes): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22812
diff changeset
7065 defsubr (&Supdate_coding_systems_internal);
22226
557fac086b1b (ascii_skip_code): New variable.
Kenichi Handa <handa@m17n.org>
parents: 22186
diff changeset
7066 defsubr (&Sset_coding_priority_internal);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7067
20105
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7068 DEFVAR_LISP ("coding-system-list", &Vcoding_system_list,
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7069 "List of coding systems.\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7070 \n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7071 Do not alter the value of this variable manually. This variable should be\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7072 updated by the functions `make-coding-system' and\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7073 `define-coding-system-alias'.");
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7074 Vcoding_system_list = Qnil;
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7075
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7076 DEFVAR_LISP ("coding-system-alist", &Vcoding_system_alist,
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7077 "Alist of coding system names.\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7078 Each element is one element list of coding system name.\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7079 This variable is given to `completing-read' as TABLE argument.\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7080 \n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7081 Do not alter the value of this variable manually. This variable should be\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7082 updated by the functions `make-coding-system' and\n\
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7083 `define-coding-system-alias'.");
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7084 Vcoding_system_alist = Qnil;
c017642863c2 (Qcoding_system_spec): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 19824
diff changeset
7085
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7086 DEFVAR_LISP ("coding-category-list", &Vcoding_category_list,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7087 "List of coding-categories (symbols) ordered by priority.");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7088 {
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7089 int i;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7090
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7091 Vcoding_category_list = Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7092 for (i = CODING_CATEGORY_IDX_MAX - 1; i >= 0; i--)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7093 Vcoding_category_list
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7094 = Fcons (XVECTOR (Vcoding_category_table)->contents[i],
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7095 Vcoding_category_list);
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7096 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7097
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7098 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read,
19118
16ef8c28e4e0 (detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents: 19068
diff changeset
7099 "Specify the coding system for read operations.\n\
19193
1701f2296f99 (syms_of_coding): Doc syntax fixes.
Richard M. Stallman <rms@gnu.org>
parents: 19181
diff changeset
7100 It is useful to bind this variable with `let', but do not set it globally.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7101 If the value is a coding system, it is used for decoding on read operation.\n\
18910
50c89868f8c7 (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 18860
diff changeset
7102 If not, an appropriate element is used from one of the coding system alists:\n\
19118
16ef8c28e4e0 (detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents: 19068
diff changeset
7103 There are three such tables, `file-coding-system-alist',\n\
18910
50c89868f8c7 (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 18860
diff changeset
7104 `process-coding-system-alist', and `network-coding-system-alist'.");
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7105 Vcoding_system_for_read = Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7106
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7107 DEFVAR_LISP ("coding-system-for-write", &Vcoding_system_for_write,
19118
16ef8c28e4e0 (detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents: 19068
diff changeset
7108 "Specify the coding system for write operations.\n\
24766
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7109 Programs bind this variable with `let', but you should not set it globally.\n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7110 If the value is a coding system, it is used for encoding of output,\n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7111 when writing it to a file and when sending it to a file or subprocess.\n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7112 \n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7113 If this does not specify a coding system, an appropriate element\n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7114 is used from one of the coding system alists:\n\
19118
16ef8c28e4e0 (detect_coding_mask): Include CODING_CATEGORY_MASK_BINARY in the
Richard M. Stallman <rms@gnu.org>
parents: 19068
diff changeset
7115 There are three such tables, `file-coding-system-alist',\n\
24766
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7116 `process-coding-system-alist', and `network-coding-system-alist'.\n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7117 For output to files, if the above procedure does not specify a coding system,\n\
c15dcedcb81c (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 24706
diff changeset
7118 the value of `buffer-file-coding-system' is used.");
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7119 Vcoding_system_for_write = Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7120
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7121 DEFVAR_LISP ("last-coding-system-used", &Vlast_coding_system_used,
18910
50c89868f8c7 (syms_of_coding): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 18860
diff changeset
7122 "Coding system used in the latest file or process I/O.");
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7123 Vlast_coding_system_used = Qnil;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7124
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7125 DEFVAR_BOOL ("inhibit-eol-conversion", &inhibit_eol_conversion,
24056
d20160af7b6e (syms_of_coding): Doc fix for inhibit-eol-conversion.
Dave Love <fx@gnu.org>
parents: 23881
diff changeset
7126 "*Non-nil means always inhibit code conversion of end-of-line format.\n\
24178
38e26ebed6f7 (syms_of_coding): Doc fix for inhibit-eol-conversion.
Dave Love <fx@gnu.org>
parents: 24065
diff changeset
7127 See info node `Coding Systems' and info node `Text and Binary' concerning\n\
38e26ebed6f7 (syms_of_coding): Doc fix for inhibit-eol-conversion.
Dave Love <fx@gnu.org>
parents: 24065
diff changeset
7128 such conversion.");
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7129 inhibit_eol_conversion = 0;
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7130
21574
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
7131 DEFVAR_BOOL ("inherit-process-coding-system", &inherit_process_coding_system,
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
7132 "Non-nil means process buffer inherits coding system of process output.\n\
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
7133 Bind it to t if the process output is to be treated as if it were a file\n\
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
7134 read from some filesystem.");
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
7135 inherit_process_coding_system = 0;
30394e3ae7f8 (syms_of_coding): Declare and define inherit-process-coding-system.
Eli Zaretskii <eliz@gnu.org>
parents: 21520
diff changeset
7136
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7137 DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist,
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7138 "Alist to decide a coding system to use for a file I/O operation.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7139 The format is ((PATTERN . VAL) ...),\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7140 where PATTERN is a regular expression matching a file name,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7141 VAL is a coding system, a cons of coding systems, or a function symbol.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7142 If VAL is a coding system, it is used for both decoding and encoding\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7143 the file contents.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7144 If VAL is a cons of coding systems, the car part is used for decoding,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7145 and the cdr part is used for encoding.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7146 If VAL is a function symbol, the function must return a coding system\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7147 or a cons of coding systems which are used as above.\n\
17119
2cfb31c15ced (create_process, Fopen_network_stream): Typo in indexes
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
7148 \n\
23089
20486aa49e7d (file-coding-system-alist, select-safe-coding-system-function): Doc fix.
Andreas Schwab <schwab@suse.de>
parents: 23088
diff changeset
7149 See also the function `find-operation-coding-system'\n\
22812
70f58e77fda7 (syms_of_coding): Mention auto-coding-alist in the
Kenichi Handa <handa@m17n.org>
parents: 22790
diff changeset
7150 and the variable `auto-coding-alist'.");
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7151 Vfile_coding_system_alist = Qnil;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7152
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7153 DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist,
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7154 "Alist to decide a coding system to use for a process I/O operation.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7155 The format is ((PATTERN . VAL) ...),\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7156 where PATTERN is a regular expression matching a program name,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7157 VAL is a coding system, a cons of coding systems, or a function symbol.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7158 If VAL is a coding system, it is used for both decoding what received\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7159 from the program and encoding what sent to the program.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7160 If VAL is a cons of coding systems, the car part is used for decoding,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7161 and the cdr part is used for encoding.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7162 If VAL is a function symbol, the function must return a coding system\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7163 or a cons of coding systems which are used as above.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7164 \n\
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7165 See also the function `find-operation-coding-system'.");
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7166 Vprocess_coding_system_alist = Qnil;
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7167
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7168 DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist,
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7169 "Alist to decide a coding system to use for a network I/O operation.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7170 The format is ((PATTERN . VAL) ...),\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7171 where PATTERN is a regular expression matching a network service name\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7172 or is a port number to connect to,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7173 VAL is a coding system, a cons of coding systems, or a function symbol.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7174 If VAL is a coding system, it is used for both decoding what received\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7175 from the network stream and encoding what sent to the network stream.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7176 If VAL is a cons of coding systems, the car part is used for decoding,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7177 and the cdr part is used for encoding.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7178 If VAL is a function symbol, the function must return a coding system\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7179 or a cons of coding systems which are used as above.\n\
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7180 \n\
18650
aa3f2820e2ac (Qemacs_mule, inhibit_eol_conversion): New variables.
Kenichi Handa <handa@m17n.org>
parents: 18613
diff changeset
7181 See also the function `find-operation-coding-system'.");
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7182 Vnetwork_coding_system_alist = Qnil;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7183
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7184 DEFVAR_LISP ("locale-coding-system", &Vlocale_coding_system,
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7185 "Coding system to use with system messages.");
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7186 Vlocale_coding_system = Qnil;
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7187
29182
1d1c27067af4 (encode_eol): Add null statement after label.
Dave Love <fx@gnu.org>
parents: 29172
diff changeset
7188 /* The eol mnemonics are reset in startup.el system-dependently. */
24200
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7189 DEFVAR_LISP ("eol-mnemonic-unix", &eol_mnemonic_unix,
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7190 "*String displayed in mode line for UNIX-like (LF) end-of-line format.");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7191 eol_mnemonic_unix = build_string (":");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7192
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7193 DEFVAR_LISP ("eol-mnemonic-dos", &eol_mnemonic_dos,
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7194 "*String displayed in mode line for DOS-like (CRLF) end-of-line format.");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7195 eol_mnemonic_dos = build_string ("\\");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7196
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7197 DEFVAR_LISP ("eol-mnemonic-mac", &eol_mnemonic_mac,
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7198 "*String displayed in mode line for MAC-like (CR) end-of-line format.");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7199 eol_mnemonic_mac = build_string ("/");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7200
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7201 DEFVAR_LISP ("eol-mnemonic-undecided", &eol_mnemonic_undecided,
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7202 "*String displayed in mode line when end-of-line format is not yet determined.");
b9d9fccad516 (syms_of_coding): eol-mnemonic-* variables are now
Eli Zaretskii <eliz@gnu.org>
parents: 24178
diff changeset
7203 eol_mnemonic_undecided = build_string (":");
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7204
22119
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
7205 DEFVAR_LISP ("enable-character-translation", &Venable_character_translation,
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7206 "*Non-nil enables character translation while encoding and decoding.");
22119
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
7207 Venable_character_translation = Qt;
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
7208
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7209 DEFVAR_LISP ("standard-translation-table-for-decode",
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7210 &Vstandard_translation_table_for_decode,
22119
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
7211 "Table for translating characters while decoding.");
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7212 Vstandard_translation_table_for_decode = Qnil;
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7213
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7214 DEFVAR_LISP ("standard-translation-table-for-encode",
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7215 &Vstandard_translation_table_for_encode,
22119
592bb8b9bcfd Change terms unify/unification to
Kenichi Handa <handa@m17n.org>
parents: 22020
diff changeset
7216 "Table for translationg characters while encoding.");
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22166
diff changeset
7217 Vstandard_translation_table_for_encode = Qnil;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7218
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7219 DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_alist,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7220 "Alist of charsets vs revision numbers.\n\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7221 While encoding, if a charset (car part of an element) is found,\n\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7222 designate it with the escape sequence identifing revision (cdr part of the element).");
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7223 Vcharset_revision_alist = Qnil;
18180
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7224
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7225 DEFVAR_LISP ("default-process-coding-system",
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7226 &Vdefault_process_coding_system,
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7227 "Cons of coding systems used for process I/O by default.\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7228 The car part is used for decoding a process output,\n\
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7229 the cdr part is used for encoding a text to be sent to a process.");
5f4c4da24e75 (Vcoding_system_alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 18002
diff changeset
7230 Vdefault_process_coding_system = Qnil;
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
7231
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
7232 DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table,
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
7233 "Table of extra Latin codes in the range 128..159 (inclusive).\n\
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
7234 This is a vector of length 256.\n\
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
7235 If Nth element is non-nil, the existence of code N in a file\n\
19750
95e4e1cba6ac (Qcoding_system_history): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19747
diff changeset
7236 \(or output of subprocess) doesn't prevent it to be detected as\n\
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
7237 a coding system of ISO 2022 variant which has a flag\n\
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
7238 `accept-latin-extra-code' t (e.g. iso-latin-1) on reading a file\n\
19280
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
7239 or reading output of a subprocess.\n\
e755044718ee (ENCODE_ISO_CHARACTER_DIMENSION1): Pay attention to
Kenichi Handa <handa@m17n.org>
parents: 19193
diff changeset
7240 Only 128th through 159th elements has a meaning.");
19365
d9374f5ebd3a (CODING_FLAG_ISO_LATIN_EXTRA): New macro.
Kenichi Handa <handa@m17n.org>
parents: 19285
diff changeset
7241 Vlatin_extra_code_table = Fmake_vector (make_number (256), Qnil);
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7242
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7243 DEFVAR_LISP ("select-safe-coding-system-function",
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7244 &Vselect_safe_coding_system_function,
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7245 "Function to call to select safe coding system for encoding a text.\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7246 \n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7247 If set, this function is called to force a user to select a proper\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7248 coding system which can encode the text in the case that a default\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7249 coding system used in each operation can't encode the text.\n\
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7250 \n\
23089
20486aa49e7d (file-coding-system-alist, select-safe-coding-system-function): Doc fix.
Andreas Schwab <schwab@suse.de>
parents: 23088
diff changeset
7251 The default value is `select-safe-coding-system' (which see).");
20718
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7252 Vselect_safe_coding_system_function = Qnil;
c600dea3b06b Vselect_safe_coding_system_function): New variable.
Kenichi Handa <handa@m17n.org>
parents: 20708
diff changeset
7253
30487
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7254 DEFVAR_LISP ("char-coding-system-table", &Vchar_coding_system_table,
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7255 "Char-table containing safe coding systems of each characters.\n\
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7256 Each element doesn't include such generic coding systems that can\n\
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7257 encode any characters. They are in the first extra slot.");
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7258 Vchar_coding_system_table = Fmake_char_table (Qchar_coding_system, Qnil);
6165da9c89c6 (Qsafe_charsets): This variable deleted.
Kenichi Handa <handa@m17n.org>
parents: 30384
diff changeset
7259
30292
14a9937df1f5 (syms_of_coding): Fix typo in spelling of variable
Gerd Moellmann <gerd@gnu.org>
parents: 30263
diff changeset
7260 DEFVAR_BOOL ("inhibit-iso-escape-detection",
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7261 &inhibit_iso_escape_detection,
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7262 "If non-nil, Emacs ignores ISO2022's escape sequence on code detection.\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7263 \n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7264 By default, on reading a file, Emacs tries to detect how the text is\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7265 encoded. This code detection is sensitive to escape sequences. If\n\
30384
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7266 the sequence is valid as ISO2022, the code is determined as one of\n\
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7267 the ISO2022 encodings, and the file is decoded by the corresponding\n\
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7268 coding system (e.g. `iso-2022-7bit').\n\
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7269 \n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7270 However, there may be a case that you want to read escape sequences in\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7271 a file as is. In such a case, you can set this variable to non-nil.\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7272 Then, as the code detection ignores any escape sequences, no file is\n\
30384
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7273 detected as encoded in some ISO2022 encoding. The result is that all\n\
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7274 escape sequences become visible in a buffer.\n\
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7275 \n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7276 The default value is nil, and it is strongly recommended not to change\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7277 it. That is because many Emacs Lisp source files that contain\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7278 non-ASCII characters are encoded by the coding system `iso-2022-7bit'\n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7279 in Emacs's distribution, and they won't be decoded correctly on\n\
30384
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7280 reading if you suppress escape sequence detection.\n\
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7281 \n\
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7282 The other way to read escape sequences in a file without decoding is\n\
30384
d81bc1a374d6 (syms_of_coding): Doc fix for inhibit-iso-escape-detection.
Eli Zaretskii <eliz@gnu.org>
parents: 30315
diff changeset
7283 to explicitly specify some coding system that doesn't use ISO2022's\n\
30204
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7284 escape sequence (e.g `latin-1') on reading by \\[universal-coding-system-argument].");
35aec8514228 (inhibit_iso_escape_detection): New variable.
Kenichi Handa <handa@m17n.org>
parents: 29985
diff changeset
7285 inhibit_iso_escape_detection = 0;
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7286 }
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7287
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7288 char *
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7289 emacs_strerror (error_number)
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7290 int error_number;
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7291 {
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7292 char *str;
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7293
26526
b7438760079b * callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents: 26240
diff changeset
7294 synchronize_system_messages_locale ();
26088
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7295 str = strerror (error_number);
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7296
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7297 if (! NILP (Vlocale_coding_system))
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7298 {
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7299 Lisp_Object dec = code_convert_string_norecord (build_string (str),
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7300 Vlocale_coding_system,
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7301 0);
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7302 str = (char *) XSTRING (dec)->data;
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7303 }
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7304
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7305 return str;
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7306 }
b7aa6ac26872 Add support for large files, 64-bit Solaris, system locale codings.
Paul Eggert <eggert@twinsun.com>
parents: 26067
diff changeset
7307
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7308 #endif /* emacs */
29184
446621f88d68 Fix junk from last checkin.
Dave Love <fx@gnu.org>
parents: 29182
diff changeset
7309