annotate src/mule-charset.h @ 100:4be1180a9e89 r20-1b2

Import from CVS: tag r20-1b2
author cvs
date Mon, 13 Aug 2007 09:15:11 +0200
parents c7528f8e288d
children 3d6bfa290dbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 /* Header for multilingual functions.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5 This file is part of XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10 later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15 for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 /* Rewritten by Ben Wing <wing@666.com>. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 #ifndef _XEMACS_MULE_CHARSET_H
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27 #define _XEMACS_MULE_CHARSET_H
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29 /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 1. Character Sets
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 =================
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
33 A character set (or "charset") is an ordered set of characters.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 A particular character in a charset is indexed using one or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35 more "position codes", which are non-negative integers.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 The number of position codes needed to identify a particular
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37 character in a charset is called the "dimension" of the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 charset. In XEmacs/Mule, all charsets have 1 or 2 dimensions,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 and the size of all charsets (except for a few special cases)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 is either 94, 96, 94 by 94, or 96 by 96. The range of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41 position codes used to index characters from any of these
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 types of character sets is as follows:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 Charset type Position code 1 Position code 2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 ------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46 94 33 - 126 N/A
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 96 32 - 127 N/A
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 94x94 33 - 126 33 - 126
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 96x96 32 - 127 32 - 127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 Note that in the above cases position codes do not start at
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 an expected value such as 0 or 1. The reason for this will
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53 become clear later.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55 For example, Latin-1 is a 96-character charset, and JISX0208
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 (the Japanese national character set) is a 94x94-character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 charset.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 [Note that, although the ranges above define the *valid*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 position codes for a charset, some of the slots in a particular
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61 charset may in fact be empty. This is the case for JISX0208,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 for example, where (e.g.) all the slots whose first
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63 position code is in the range 118 - 127 are empty.]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 There are three charsets that do not follow the above rules.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 All of them have one dimension, and have ranges of position
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67 codes as follows:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 Charset name Position code 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70 ------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 ASCII 0 - 127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 Control-1 0 - 31
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73 Composite 0 - some large number
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 (The upper bound of the position code for composite characters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 has not yet been determined, but it will probably be at
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 least 16,383).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79 ASCII is the union of two subsidiary character sets:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80 Printing-ASCII (the printing ASCII character set,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 consisting of position codes 33 - 126, like for a standard
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 94-character charset) and Control-ASCII (the non-printing
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83 characters that would appear in a binary file with codes 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 - 32 and 127).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 Control-1 contains the non-printing characters that would
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87 appear in a binary file with codes 128 - 159.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 Composite contains characters that are generated by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 overstriking one or more characters from other charsets.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 Note that some characters in ASCII, and all characters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 in Control-1, are "control" (non-printing) characters.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94 These have no printed representation but instead control
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 some other function of the printing (e.g. TAB or 8 moves
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 the current character position to the next tab stop).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 All other characters in all charsets are "graphic"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 (printing) characters.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 When a binary file is read in, the bytes in the file are
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 assigned to character sets as follows:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 Bytes Character set Range
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 --------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105 0 - 127 ASCII 0 - 127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 128 - 159 Control-1 0 - 31
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 160 - 255 Latin-1 32 - 127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 This is a bit ad-hoc but gets the job done.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 2. Encodings
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 ============
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 An "encoding" is a way of numerically representing
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 characters from one or more character sets. If an encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 only encompasses one character set, then the position codes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117 for the characters in that character set could be used
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118 directly. This is not possible, however, if more than one
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119 character set is to be used in the encoding.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121 For example, the conversion detailed above between bytes in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 a binary file and characters is effectively an encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 that encompasses the three character sets ASCII, Control-1,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124 and Latin-1 in a stream of 8-bit bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126 Thus, an encoding can be viewed as a way of encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 characters from a specified group of character sets using a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 stream of bytes, each of which contains a fixed number of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
129 bits (but not necessarily 8, as in the common usage of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
130 "byte").
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 Here are descriptions of a couple of common
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 encodings:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
135
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 A. Japanese EUC (Extended Unix Code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
138 This encompasses the character sets:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
139 - Printing-ASCII,
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
140 - Katakana-JISX0201 (half-width katakana, the right half of JISX0201).
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 - Japanese-JISX0208
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142 - Japanese-JISX0212
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 It uses 8-bit bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
145 Note that Printing-ASCII and Katakana-JISX0201 are 94-character
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
146 charsets, while Japanese-JISX0208 is a 94x94-character charset.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
147
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
148 The encoding is as follows:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
149
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
150 Character set Representation (PC == position-code)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
151 ------------- --------------
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
152 Printing-ASCII PC1
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
153 Japanese-JISX0208 PC1 + 0x80 | PC2 + 0x80
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
154 Katakana-JISX0201 0x8E | PC1 + 0x80
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
155
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
156
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157 B. JIS7
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 This encompasses the character sets:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 - Printing-ASCII
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
161 - Latin-JISX0201 (the left half of JISX0201; this character set is
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
162 very similar to Printing-ASCII and is a 94-character charset)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 - Japanese-JISX0208
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
164 - Katakana-JISX0201
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 It uses 7-bit bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167 Unlike Japanese EUC, this is a "modal" encoding, which
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168 means that there are multiple states that the encoding can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 be in, which affect how the bytes are to be interpreted.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 Special sequences of bytes (called "escape sequences")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171 are used to change states.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 The encoding is as follows:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
175 Character set Representation
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
176 ------------- --------------
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
177 Printing-ASCII PC1
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
178 Latin-JISX0201 PC1
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
179 Katakana-JISX0201 PC1
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
180 Japanese-JISX0208 PC1 | PC2
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182 Escape sequence ASCII equivalent Meaning
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 --------------- ---------------- -------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
185 0x1B 0x28 0x4A ESC ( J invoke Latin-JISX0201
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
186 0x1B 0x28 0x49 ESC ( I invoke Katakana-JISX0201
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 0x1B 0x24 0x42 ESC $ B invoke Japanese-JISX0208
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 Initially, Printing-ASCII is invoked.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191 3. Internal Mule Encodings
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 ==========================
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 In XEmacs/Mule, each character set is assigned a unique number,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 called a "leading byte". This is used in the encodings of a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196 character. Leading bytes are in the range 0x80 - 0xFF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 (except for ASCII, which has a leading byte of 0), although
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 some leading bytes are reserved.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200 Charsets whose leading byte is in the range 0x80 - 0x9F are
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 called "official" and are used for built-in charsets.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 Other charsets are called "private" and have leading bytes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 in the range 0xA0 - 0xFF; these are user-defined charsets.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 More specifically:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 Character set Leading byte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 ------------- ------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 ASCII 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 Composite 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 Dimension-1 Official 0x81 - 0x8D
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212 (0x8E is free)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 Control 0x8F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 Dimension-2 Official 0x90 - 0x99
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 (0x9A - 0x9D are free;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 0x9E and 0x9F are reserved)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 Dimension-1 Private 0xA0 - 0xEF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 Dimension-2 Private 0xF0 - 0xFF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220 There are two internal encodings for characters in XEmacs/Mule.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 One is called "string encoding" and is an 8-bit encoding that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 is used for representing characters in a buffer or string.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 It uses 1 to 4 bytes per character. The other is called
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 "character encoding" and is a 19-bit encoding that is used
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225 for representing characters individually in a variable.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 (In the following descriptions, we'll ignore composite
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228 characters for the moment. We also give a general (structural)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 overview first, followed later by the exact details.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 A. Internal String Encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233 ASCII characters are encoded using their position code directly.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 Other characters are encoded using their leading byte followed
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 by their position code(s) with the high bit set. Characters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 in private character sets have their leading byte prefixed with
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237 a "leading byte prefix", which is either 0x9E or 0x9F. (No
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 character sets are ever assigned these leading bytes.) Specifically:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240 Character set Encoding (PC == position-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 ------------- -------- (LB == leading-byte)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 ASCII PC1 |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243 Control-1 LB | PC1 + 0xA0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 Dimension-1 official LB | PC1 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 Dimension-1 private 0x9E | LB | PC1 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 Dimension-2 official LB | PC1 | PC2 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 Dimension-2 private 0x9F | LB | PC1 + 0x80 | PC2 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 The basic characteristic of this encoding is that the first byte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 of all characters is in the range 0x00 - 0x9F, and the second and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 following bytes of all characters is in the range 0xA0 - 0xFF.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 This means that it is impossible to get out of sync, or more
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 specifically:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 1. Given any byte position, the beginning of the character it is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 within can be determined in constant time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 2. Given any byte position at the beginning of a character, the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 beginning of the next character can be determined in constant
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
260 3. Given any byte position at the beginning of a character, the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261 beginning of the previous character can be determined in constant
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263 4. Textual searches can simply treat encoded strings as if they
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 were encoded in a one-byte-per-character fashion rather than
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265 the actual multi-byte encoding.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267 None of the standard non-modal encodings meet all of these
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 conditions. For example, EUC satisfies only (2) and (3), while
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 Shift-JIS and Big5 (not yet described) satisfy only (2). (All
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 non-modal encodings must satisfy (2), in order to be unambiguous.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272 B. Internal Character Encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274 One 19-bit word represents a single character. The word is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 separated into three fields:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277 Bit number: 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 <------------> <------------------> <------------------>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
279 Field: 1 2 3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281 Note that fields 2 and 3 hold 7 bits each, while field 1 holds 5 bits.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
283 Character set Field 1 Field 2 Field 3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 ------------- ------- ------- -------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 ASCII 0 0 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286 range: (00 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 Control-1 0 1 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 range: (00 - 1F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 Dimension-1 official 0 LB - 0x80 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 range: (01 - 0D) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291 Dimension-1 private 0 LB - 0x80 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 range: (20 - 6F) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 Dimension-2 official LB - 0x8F PC1 PC2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 range: (01 - 0A) (20 - 7F) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 Dimension-2 private LB - 0xE1 PC1 PC2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 range: (0F - 1E) (20 - 7F) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 Composite 0x1F ? ?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299 Note that character codes 0 - 255 are the same as the "binary encoding"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 described above.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
302
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
303 /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
304 About Unicode support:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306 Adding Unicode support is very desirable. Unicode will likely be a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307 very common representation in the future, and thus we should
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 represent Unicode characters using three bytes instead of four.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 This means we need to find leading bytes for Unicode. Given that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 there are 65,536 characters in Unicode and we can attach 96x96 =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 9,216 characters per leading byte, we need eight leading bytes for
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312 Unicode. We currently have four free (0x9A - 0x9D), and with a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
313 little bit of rearranging we can get five: ASCII doesn't really
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
314 need to take up a leading byte. (We could just as well use 0x7F,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
315 with a little change to the functions that assume that 0x80 is the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
316 lowest leading byte.) This means we still need to dump three
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
317 leading bytes and move them into private space. The CNS charsets
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
318 are good candidates since they are rarely used, and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
319 JAPANESE_JISX0208_1978 is becoming less and less used and could
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
320 also be dumped. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
321
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
322
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
323 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
324 /* Definition of leading bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
325 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
326
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
327 #define MIN_LEADING_BYTE 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
328 /* These need special treatment in a string and/or character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
329 #define LEADING_BYTE_ASCII 0x8E /* Omitted in a buffer */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
330 #define LEADING_BYTE_COMPOSITE 0x80 /* for a composite character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
331 #define LEADING_BYTE_CONTROL_1 0x8F /* represent normal 80-9F */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
332
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
333 /** The following are for 1-byte characters in an official charset. **/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
334
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
335 #define LEADING_BYTE_LATIN_ISO8859_1 0x81 /* Right half of ISO 8859-1 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
336 #define LEADING_BYTE_LATIN_ISO8859_2 0x82 /* Right half of ISO 8859-2 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
337 #define LEADING_BYTE_LATIN_ISO8859_3 0x83 /* Right half of ISO 8859-3 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
338 #define LEADING_BYTE_LATIN_ISO8859_4 0x84 /* Right half of ISO 8859-4 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
339 #define LEADING_BYTE_THAI_TIS620 0x85 /* TIS620-2533 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
340 #define LEADING_BYTE_GREEK_ISO8859_7 0x86 /* Right half of ISO 8859-7 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
341 #define LEADING_BYTE_ARABIC_ISO8859_6 0x87 /* Right half of ISO 8859-6 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
342 #define LEADING_BYTE_HEBREW_ISO8859_8 0x88 /* Right half of ISO 8859-8 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
343 #define LEADING_BYTE_KATAKANA_JISX0201 0x89 /* Right half of JIS X0201-1976 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
344 #define LEADING_BYTE_LATIN_JISX0201 0x8A /* Left half of JIS X0201-1976 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
345 #define LEADING_BYTE_CYRILLIC_ISO8859_5 0x8C /* Right half of ISO 8859-5 */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
346 #define LEADING_BYTE_LATIN_ISO8859_9 0x8D /* Right half of ISO 8859-9 */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
347
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
348 #define MIN_LEADING_BYTE_OFFICIAL_1 LEADING_BYTE_LATIN_ISO8859_1
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
349 #define MAX_LEADING_BYTE_OFFICIAL_1 LEADING_BYTE_LATIN_ISO8859_9
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
350
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
351 /** The following are for 2-byte characters in an official charset. **/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
352
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
353 #define LEADING_BYTE_JAPANESE_JISX0208_1978 0x90/* Japanese JIS X0208-1978 */
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
354 #define LEADING_BYTE_CHINESE_GB2312 0x91 /* Chinese Hanzi GB2312-1980 */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
355 #define LEADING_BYTE_JAPANESE_JISX0208 0x92 /* Japanese JIS X0208-1983 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
356 #define LEADING_BYTE_KOREAN_KSC5601 0x93 /* Hangul KS C5601-1987 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
357 #define LEADING_BYTE_JAPANESE_JISX0212 0x94 /* Japanese JIS X0212-1990 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
358 #define LEADING_BYTE_CHINESE_CNS11643_1 0x95 /* Chinese CNS11643 Set 1 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
359 #define LEADING_BYTE_CHINESE_CNS11643_2 0x96 /* Chinese CNS11643 Set 2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
360 #define LEADING_BYTE_CHINESE_BIG5_1 0x97 /* Big5 Level 1 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
361 #define LEADING_BYTE_CHINESE_BIG5_2 0x98 /* Big5 Level 2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
362 /* 0x99 unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
363 /* 0x9A unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
364 /* 0x9B unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
365 /* 0x9C unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
366 /* 0x9D unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
367
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
368 #define MIN_LEADING_BYTE_OFFICIAL_2 LEADING_BYTE_JAPANESE_JISX0208_1978
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
369 #define MAX_LEADING_BYTE_OFFICIAL_2 LEADING_BYTE_CHINESE_BIG5_2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
370
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
371 /** The following are for 1- and 2-byte characters in a private charset. **/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
372
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
373 #define PRE_LEADING_BYTE_PRIVATE_1 0x9E /* 1-byte char-set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
374 #define PRE_LEADING_BYTE_PRIVATE_2 0x9F /* 2-byte char-set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
375
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
376 #define MIN_LEADING_BYTE_PRIVATE_1 0xA0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
377 #define MAX_LEADING_BYTE_PRIVATE_1 0xEF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
378 #define MIN_LEADING_BYTE_PRIVATE_2 0xF0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
379 #define MAX_LEADING_BYTE_PRIVATE_2 0xFF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
380
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
381 #define NUM_LEADING_BYTES 128
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
382
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
383
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
384 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
385 /* Operations on leading bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
386 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
387
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
388 /* Is this leading byte for a private charset? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
389
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
390 #define LEADING_BYTE_PRIVATE_P(lb) ((lb) >= MIN_LEADING_BYTE_PRIVATE_1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
391
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
392 /* Is this a prefix for a private leading byte? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
393
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
394 INLINE int LEADING_BYTE_PREFIX_P (unsigned char lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
395 INLINE int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
396 LEADING_BYTE_PREFIX_P (unsigned char lb)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
397 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
398 return (lb == PRE_LEADING_BYTE_PRIVATE_1 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
399 lb == PRE_LEADING_BYTE_PRIVATE_2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
400 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
401
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
402 /* Given a private leading byte, return the leading byte prefix stored
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
403 in a string */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
404
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
405 #define PRIVATE_LEADING_BYTE_PREFIX(lb) \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
406 ((lb) < MIN_LEADING_BYTE_PRIVATE_2 ? \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
407 PRE_LEADING_BYTE_PRIVATE_1 : \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
408 PRE_LEADING_BYTE_PRIVATE_2)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
409
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
410
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
411 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
412 /* Operations on individual bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
413 /* of any format */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
414 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
415
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
416 /* Argument `c' should be (unsigned int) or (unsigned char). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
417 /* Note that SP and DEL are not included. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
418
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
419 #define BYTE_ASCII_P(c) ((c) < 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
420 #define BYTE_C0_P(c) ((c) < 0x20)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
421 /* Do some forced casting just to make *sure* things are gotten right. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
422 #define BYTE_C1_P(c) ((unsigned int) ((unsigned int) (c) - 0x80) < 0x20)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
423
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
424
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
425 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
426 /* Operations on individual bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
427 /* in a Mule-formatted string */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
428 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
429
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
430 /* Does this byte represent the first byte of a character? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
431
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
432 #define BUFBYTE_FIRST_BYTE_P(c) ((c) < 0xA0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
433
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
434 /* Does this byte represent the first byte of a multi-byte character? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
435
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
436 #define BUFBYTE_LEADING_BYTE_P(c) BYTE_C1_P (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
437
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
438
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
439 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
440 /* Information about a particular character set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
441 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
442
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
443 struct Lisp_Charset
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
444 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
445 struct lcrecord_header header;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
446
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
447 Lisp_Object name;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
448 Lisp_Object doc_string, registry;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
449
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
450 Lisp_Object reverse_direction_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
451
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
452 Lisp_Object ccl_program;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
453
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
454 unsigned int leading_byte :8;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
455
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
456 /* Number of bytes (1 - 4) required in the internal representation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
457 for characters in this character set. This is *not* the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
458 same as the number of bytes used in the encoding (i.e.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
459 the "dimension" of the character set). That value can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
460 be derived from the TYPE. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
461 unsigned int rep_bytes :3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
462
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
463 /* Number of columns a character in this charset takes up, on TTY
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
464 devices. Not used for X devices. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
465 unsigned int columns :2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
466 /* Direction of this character set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
467 unsigned int direction :1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
468
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
469 /* Type of this character set (94, 96, 94x94, 96x96) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
470 unsigned int type :2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
471
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
472 /* Which half of font to be used to display this character set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
473 unsigned int graphic :2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
474
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
475 /* Final byte of this character set in ISO2022 designating escape sequence */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
476 Bufbyte final;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
477 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
478
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
479 DECLARE_LRECORD (charset, struct Lisp_Charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
480 #define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
481 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
482 #define CHARSETP(x) RECORDP (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
483 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
484 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
485 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
486
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
487 #define CHARSET_TYPE_94 0 /* This charset includes 94 characters. */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
488 #define CHARSET_TYPE_96 1 /* This charset includes 96 characters. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
489 #define CHARSET_TYPE_94X94 2 /* This charset includes 94x94 characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
490 #define CHARSET_TYPE_96X96 3 /* This charset includes 96x96 characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
491
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
492 #define CHARSET_LEFT_TO_RIGHT 0
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
493 #define CHARSET_RIGHT_TO_LEFT 1
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
494
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
495 #define CHARSET_NAME(cs) ((cs)->name)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
496 #define CHARSET_LEADING_BYTE(cs) ((cs)->leading_byte)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
497 #define CHARSET_REP_BYTES(cs) ((cs)->rep_bytes)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
498 #define CHARSET_COLUMNS(cs) ((cs)->columns)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
499 #define CHARSET_GRAPHIC(cs) ((cs)->graphic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
500 #define CHARSET_TYPE(cs) ((cs)->type)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
501 #define CHARSET_DIRECTION(cs) ((cs)->direction)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
502 #define CHARSET_FINAL(cs) ((cs)->final)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
503 #define CHARSET_DOC_STRING(cs) ((cs)->doc_string)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
504 #define CHARSET_REGISTRY(cs) ((cs)->registry)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
505 #define CHARSET_CCL_PROGRAM(cs) ((cs)->ccl_program)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
506 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
507
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
508 /* Optimized using inside knowledge of CHARSET_TYPE values */
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
509 #define CHARSET_DIMENSION(cs) ((CHARSET_TYPE (cs) <= CHARSET_TYPE_96) ? 1 : 2)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
510 #define CHARSET_CHARS(cs) ((CHARSET_TYPE (cs) & 0x1) ? 96 : 94)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
511
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
512 #define CHARSET_PRIVATE_P(cs) LEADING_BYTE_PRIVATE_P (CHARSET_LEADING_BYTE (cs))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
513
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
514 #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
515 #define XCHARSET_REP_BYTES(cs) CHARSET_REP_BYTES (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
516 #define XCHARSET_COLUMNS(cs) CHARSET_COLUMNS (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
517 #define XCHARSET_GRAPHIC(cs) CHARSET_GRAPHIC (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
518 #define XCHARSET_TYPE(cs) CHARSET_TYPE (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
519 #define XCHARSET_DIRECTION(cs) CHARSET_DIRECTION (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
520 #define XCHARSET_FINAL(cs) CHARSET_FINAL (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
521 #define XCHARSET_DOC_STRING(cs) CHARSET_DOC_STRING (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
522 #define XCHARSET_REGISTRY(cs) CHARSET_REGISTRY (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
523 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
524 #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
525 #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
526 #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
527 #define XCHARSET_PRIVATE_P(cs) CHARSET_PRIVATE_P (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
528 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
529 CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
530
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
531 /* Table of charsets indexed by (leading byte - 128). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
532 extern Lisp_Object charset_by_leading_byte[128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
533
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
534 /* Table of charsets indexed by type/final-byte/direction. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
535 extern Lisp_Object charset_by_attributes[4][128][2];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
536
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
537 /* Table of number of bytes in the string representation of a character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
538 indexed by the first byte of that representation.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
539
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
540 This value can be derived other ways -- e.g. something like
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
541
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
542 (BYTE_ASCII_P (first_byte) ? 1 :
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
543 XCHARSET_REP_BYTES (CHARSET_BY_LEADING_BYTE (first_byte)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
544
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
545 but it's faster this way. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
546 extern Bytecount rep_bytes_by_first_byte[0xA0];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
547
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
548 #ifdef ERROR_CHECK_TYPECHECK
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
549 /* int not Bufbyte even though that is the actual type of a leading byte.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
550 This way, out-ot-range values will get caught rather than automatically
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
551 truncated. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
552 INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (int lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
553 INLINE Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
554 CHARSET_BY_LEADING_BYTE (int lb)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
555 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
556 assert (lb >= 0x80 && lb <= 0xFF);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
557 return charset_by_leading_byte[lb - 128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
558 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
559
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
560 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
561
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
562 #define CHARSET_BY_LEADING_BYTE(lb) (charset_by_leading_byte[(lb) - 128])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
563
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
564 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
565
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
566 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
567 (charset_by_attributes[type][final][dir])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
568
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
569 #ifdef ERROR_CHECK_TYPECHECK
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
570
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
571 /* Number of bytes in the string representation of a character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
572 INLINE int REP_BYTES_BY_FIRST_BYTE (int fb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
573 INLINE int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
574 REP_BYTES_BY_FIRST_BYTE (int fb)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
575 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
576 assert (fb >= 0 && fb < 0xA0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
577 return rep_bytes_by_first_byte[fb];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
578 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
579
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
580 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
581 #define REP_BYTES_BY_FIRST_BYTE(fb) (rep_bytes_by_first_byte[fb])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
582 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
583
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
584 extern Lisp_Object Vcharset_ascii;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
585 extern Lisp_Object Vcharset_control_1;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
586 extern Lisp_Object Vcharset_latin_iso8859_1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
587 extern Lisp_Object Vcharset_latin_iso8859_2;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
588 extern Lisp_Object Vcharset_latin_iso8859_3;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
589 extern Lisp_Object Vcharset_latin_iso8859_4;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
590 extern Lisp_Object Vcharset_cyrillic_iso8859_5;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
591 extern Lisp_Object Vcharset_arabic_iso8859_6;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
592 extern Lisp_Object Vcharset_greek_iso8859_7;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
593 extern Lisp_Object Vcharset_hebrew_iso8859_8;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
594 extern Lisp_Object Vcharset_latin_iso8859_9;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
595 extern Lisp_Object Vcharset_thai_tis620;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
596 extern Lisp_Object Vcharset_katakana_jisx0201;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
597 extern Lisp_Object Vcharset_latin_jisx0201;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
598 extern Lisp_Object Vcharset_japanese_jisx0208_1978;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
599 extern Lisp_Object Vcharset_japanese_jisx0208;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
600 extern Lisp_Object Vcharset_japanese_jisx0212;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
601 extern Lisp_Object Vcharset_korean_ksc5601;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
602 extern Lisp_Object Vcharset_chinese_gb2312;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
603 extern Lisp_Object Vcharset_chinese_big5_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
604 extern Lisp_Object Vcharset_chinese_big5_2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
605 extern Lisp_Object Vcharset_chinese_cns11643_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
606 extern Lisp_Object Vcharset_chinese_cns11643_2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
607 extern Lisp_Object Vcharset_composite;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
608
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
609
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
610 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
611 /* Dealing with characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
612 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
613
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
614 /* Is this character represented by more than one byte in a string? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
615
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
616 #define CHAR_MULTIBYTE_P(c) ((c) >= 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
617
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
618 #define CHAR_ASCII_P(c) (!CHAR_MULTIBYTE_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
619
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
620 /* The bit fields of character are divided into 3 parts:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
621 FIELD1(5bits):FIELD2(7bits):FIELD3(7bits) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
622
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
623 #define CHAR_FIELD1_MASK (0x1F << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
624 #define CHAR_FIELD2_MASK (0x7F << 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
625 #define CHAR_FIELD3_MASK 0x7F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
626
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
627 /* Macros to access each field of a character code of C. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
628
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
629 #define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
630 #define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
631 #define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
632
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
633 /* Field 1, if non-zero, usually holds a leading byte for a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
634 dimension-2 charset. Field 2, if non-zero, usually holds a leading
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
635 byte for a dimension-1 charset. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
636
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
637 /* Converting between field values and leading bytes. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
638
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
639 #define FIELD2_TO_OFFICIAL_LEADING_BYTE 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
640 #define FIELD2_TO_PRIVATE_LEADING_BYTE 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
641
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
642 #define FIELD1_TO_OFFICIAL_LEADING_BYTE 0x8F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
643 #define FIELD1_TO_PRIVATE_LEADING_BYTE 0xE1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
644
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
645 /* Minimum and maximum allowed values for the fields. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
646
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
647 #define MIN_CHAR_FIELD2_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
648 (MIN_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
649 #define MAX_CHAR_FIELD2_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
650 (MAX_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
651
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
652 #define MIN_CHAR_FIELD1_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
653 (MIN_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
654 #define MAX_CHAR_FIELD1_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
655 (MAX_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
656
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
657 #define MIN_CHAR_FIELD2_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
658 (MIN_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
659 #define MAX_CHAR_FIELD2_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
660 (MAX_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
661
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
662 #define MIN_CHAR_FIELD1_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
663 (MIN_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
664 #define MAX_CHAR_FIELD1_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
665 (MAX_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
666
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
667 /* Minimum character code of each <type> character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
668
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
669 #define MIN_CHAR_OFFICIAL_TYPE9N (MIN_CHAR_FIELD2_OFFICIAL << 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
670 #define MIN_CHAR_PRIVATE_TYPE9N (MIN_CHAR_FIELD2_PRIVATE << 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
671 #define MIN_CHAR_OFFICIAL_TYPE9NX9N (MIN_CHAR_FIELD1_OFFICIAL << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
672 #define MIN_CHAR_PRIVATE_TYPE9NX9N (MIN_CHAR_FIELD1_PRIVATE << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
673 #define MIN_CHAR_COMPOSITION (0x1F << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
674
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
675 /* Leading byte of a character.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
676
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
677 NOTE: This takes advantage of the fact that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
678 FIELD2_TO_OFFICIAL_LEADING_BYTE and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
679 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
680 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
681
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
682 INLINE Bufbyte CHAR_LEADING_BYTE (Emchar c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
683 INLINE Bufbyte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
684 CHAR_LEADING_BYTE (Emchar c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
685 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
686 if (CHAR_ASCII_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
687 return LEADING_BYTE_ASCII;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
688 else if (c < 0xA0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
689 return LEADING_BYTE_CONTROL_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
690 else if (c < MIN_CHAR_OFFICIAL_TYPE9NX9N)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
691 return CHAR_FIELD2 (c) + FIELD2_TO_OFFICIAL_LEADING_BYTE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
692 else if (c < MIN_CHAR_PRIVATE_TYPE9NX9N)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
693 return CHAR_FIELD1 (c) + FIELD1_TO_OFFICIAL_LEADING_BYTE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
694 else if (c < MIN_CHAR_COMPOSITION)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
695 return CHAR_FIELD1 (c) + FIELD1_TO_PRIVATE_LEADING_BYTE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
696 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
697 return LEADING_BYTE_COMPOSITE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
698 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
699
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
700 #define CHAR_CHARSET(c) CHARSET_BY_LEADING_BYTE (CHAR_LEADING_BYTE (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
701
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
702 /* Return a character whose charset is CHARSET and position-codes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
703 are C1 and C2. TYPE9N character ignores C2.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
704
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
705 NOTE: This takes advantage of the fact that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
706 FIELD2_TO_OFFICIAL_LEADING_BYTE and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
707 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
708 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
709
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
710 INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
711 INLINE Emchar
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
712 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
713 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
714 if (EQ (charset, Vcharset_ascii))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
715 return c1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
716 else if (EQ (charset, Vcharset_control_1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
717 return c1 | 0x80;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
718 else if (EQ (charset, Vcharset_composite))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
719 return (0x1F << 14) | ((c1) << 7) | (c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
720 else if (XCHARSET_DIMENSION (charset) == 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
721 return ((XCHARSET_LEADING_BYTE (charset) -
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
722 FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) | (c1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
723 else if (!XCHARSET_PRIVATE_P (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
724 return ((XCHARSET_LEADING_BYTE (charset) -
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
725 FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
726 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
727 return ((XCHARSET_LEADING_BYTE (charset) -
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
728 FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
729 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
730
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
731 /* The charset of character C is set to CHARSET, and the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
732 position-codes of C are set to C1 and C2. C2 of TYPE9N character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
733 is 0. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
734
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
735 /* BREAKUP_CHAR_1_UNSAFE assumes that the charset has already been
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
736 calculated, and just computes c1 and c2.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
737
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
738 BREAKUP_CHAR also computes and stores the charset. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
739
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
740 #define BREAKUP_CHAR_1_UNSAFE(c, charset, c1, c2) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
741 XCHARSET_DIMENSION (charset) == 1 \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
742 ? ((c1) = CHAR_FIELD3 (c), (c2) = 0) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
743 : ((c1) = CHAR_FIELD2 (c), \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
744 (c2) = CHAR_FIELD3 (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
745
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
746 INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
747 INLINE void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
748 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
749 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
750 *charset = CHAR_CHARSET (c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
751 BREAKUP_CHAR_1_UNSAFE (c, *charset, *c1, *c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
752 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
753
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
754 #define BREAKUP_CHAR(c, charset, c1, c2) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
755 breakup_char_1 (c, &(charset), &(c1), &(c2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
756
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
757
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
758
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
759 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
760 /* Composite characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
761 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
762
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
763 extern Lisp_Object Vcomposite_char_int2string_hashtable;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
764 extern Lisp_Object Vcomposite_char_string2int_hashtable;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
765
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
766 Emchar lookup_composite_char (Bufbyte *str, int len);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
767 Lisp_Object composite_char_string (Emchar ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
768
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
769
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
770
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
771 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
772 /* Exported functions */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
773 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
774
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
775 Lisp_Object Fget_charset (Lisp_Object);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
776 Lisp_Object Ffind_charset (Lisp_Object);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
777
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
778 int copy_internal_to_external (CONST Bufbyte *internal, Bytecount len,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
779 unsigned char *external);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
780 Bytecount copy_external_to_internal (CONST unsigned char *external,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
781 int len, Bufbyte *internal);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
782
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
783 #endif /* _XEMACS_MULE_CHARSET_H */