annotate src/mule-charset.h @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents
children 54cc21c15cbb
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,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
140 - Japanese-JISX0201-Kana (half-width katakana, the right half of JISX0201).
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
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 Note that Printing-ASCII and Japanese-JISX0201-Kana are 94-character
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
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
150 Character set Representation (PC == position-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
151 ------------- --------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
152 Printing-ASCII PC-1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
153 Japanese-JISX0208 PC-1 + 0x80 / PC-2 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
154 Japanese-JISX0201-Kana 0x8E / PC-1 + 0x80
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
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161 - Japanese-JISX0201-Roman (the left half of JISX0201; this
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162 character set is very similar to Printing-ASCII and is a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 94-character charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164 - Japanese-JISX0208
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 - Japanese-JISX0201-Kana.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 It uses 7-bit bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168 Unlike Japanese EUC, this is a "modal" encoding, which
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 means that there are multiple states that the encoding can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 be in, which affect how the bytes are to be interpreted.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171 Special sequences of bytes (called "escape sequences")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172 are used to change states.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174 The encoding is as follows:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 Character set Representation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 ------------- --------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 Printing-ASCII PC-1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179 Japanese-JISX0201-Roman PC-1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180 Japanese-JISX0201-Kana PC-1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181 Japanese-JISX0208 PC-1 / PC-2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 Escape sequence ASCII equivalent Meaning
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 --------------- ---------------- -------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186 0x1B 0x28 0x4A ESC ( J invoke Japanese-JISX0201-Roman
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 0x1B 0x28 0x49 ESC ( I invoke Japanese-JISX0201-Kana
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188 0x1B 0x24 0x42 ESC $ B invoke Japanese-JISX0208
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190 Initially, Printing-ASCII is invoked.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 3. Internal Mule Encodings
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 ==========================
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 In XEmacs/Mule, each character set is assigned a unique number,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196 called a "leading byte". This is used in the encodings of a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 character. Leading bytes are in the range 0x80 - 0xFF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 (except for ASCII, which has a leading byte of 0), although
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 some leading bytes are reserved.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 Charsets whose leading byte is in the range 0x80 - 0x9F are
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 called "official" and are used for built-in charsets.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 Other charsets are called "private" and have leading bytes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204 in the range 0xA0 - 0xFF; these are user-defined charsets.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 More specifically:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 Character set Leading byte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 ------------- ------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 ASCII 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 Composite 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212 Dimension-1 Official 0x81 - 0x8D
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 (0x8E is free)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 Control 0x8F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 Dimension-2 Official 0x90 - 0x99
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 (0x9A - 0x9D are free;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 0x9E and 0x9F are reserved)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 Dimension-1 Private 0xA0 - 0xEF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219 Dimension-2 Private 0xF0 - 0xFF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 There are two internal encodings for characters in XEmacs/Mule.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 One is called "string encoding" and is an 8-bit encoding that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 is used for representing characters in a buffer or string.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 It uses 1 to 4 bytes per character. The other is called
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225 "character encoding" and is a 19-bit encoding that is used
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 for representing characters individually in a variable.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228 (In the following descriptions, we'll ignore composite
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 characters for the moment. We also give a general (structural)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230 overview first, followed later by the exact details.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232 A. Internal String Encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 ASCII characters are encoded using their position code directly.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 Other characters are encoded using their leading byte followed
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 by their position code(s) with the high bit set. Characters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237 in private character sets have their leading byte prefixed with
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 a "leading byte prefix", which is either 0x9E or 0x9F. (No
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 character sets are ever assigned these leading bytes.) Specifically:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 Character set Encoding (PC == position-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 ------------- -------- (LB == leading-byte)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243 ASCII PC1 |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 Control-1 LB | PC1 + 0xA0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 Dimension-1 official LB | PC1 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 Dimension-1 private 0x9E | LB | PC1 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 Dimension-2 official LB | PC1 | PC2 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 Dimension-2 private 0x9F | LB | PC1 + 0x80 | PC2 + 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 The basic characteristic of this encoding is that the first byte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 of all characters is in the range 0x00 - 0x9F, and the second and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 following bytes of all characters is in the range 0xA0 - 0xFF.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 This means that it is impossible to get out of sync, or more
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 specifically:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 1. Given any byte position, the beginning of the character it is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 within can be determined in constant time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 2. Given any byte position at the beginning of a character, the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 beginning of the next character can be determined in constant
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
260 time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261 3. Given any byte position at the beginning of a character, the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 beginning of the previous character can be determined in constant
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263 time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 4. Textual searches can simply treat encoded strings as if they
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265 were encoded in a one-byte-per-character fashion rather than
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266 the actual multi-byte encoding.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 None of the standard non-modal encodings meet all of these
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 conditions. For example, EUC satisfies only (2) and (3), while
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 Shift-JIS and Big5 (not yet described) satisfy only (2). (All
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271 non-modal encodings must satisfy (2), in order to be unambiguous.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273 B. Internal Character Encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 One 19-bit word represents a single character. The word is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276 separated into three fields:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 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
279 <------------> <------------------> <------------------>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280 Field: 1 2 3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282 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
283
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 Character set Field 1 Field 2 Field 3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 ------------- ------- ------- -------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286 ASCII 0 0 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 range: (00 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 Control-1 0 1 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 range: (00 - 1F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 Dimension-1 official 0 LB - 0x80 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291 range: (01 - 0D) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 Dimension-1 private 0 LB - 0x80 PC1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 range: (20 - 6F) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 Dimension-2 official LB - 0x8F PC1 PC2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 range: (01 - 0A) (20 - 7F) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 Dimension-2 private LB - 0xE1 PC1 PC2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 range: (0F - 1E) (20 - 7F) (20 - 7F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298 Composite 0x1F ? ?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 Note that character codes 0 - 255 are the same as the "binary encoding"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 described above.
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 /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305 About Unicode support:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307 Adding Unicode support is very desirable. Unicode will likely be a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 very common representation in the future, and thus we should
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 represent Unicode characters using three bytes instead of four.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 This means we need to find leading bytes for Unicode. Given that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 there are 65,536 characters in Unicode and we can attach 96x96 =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312 9,216 characters per leading byte, we need eight leading bytes for
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
313 Unicode. We currently have four free (0x9A - 0x9D), and with a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
314 little bit of rearranging we can get five: ASCII doesn't really
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
315 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
316 with a little change to the functions that assume that 0x80 is the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
317 lowest leading byte.) This means we still need to dump three
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
318 leading bytes and move them into private space. The CNS charsets
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
319 are good candidates since they are rarely used, and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
320 JAPANESE_JISX0208_1978 is becoming less and less used and could
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
321 also be dumped. */
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 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
325 /* Definition of leading bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
326 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
327
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
328 #define MIN_LEADING_BYTE 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
329 /* These need special treatment in a string and/or character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
330 #define LEADING_BYTE_ASCII 0x8E /* Omitted in a buffer */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
331 #define LEADING_BYTE_COMPOSITE 0x80 /* for a composite character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
332 #define LEADING_BYTE_CONTROL_1 0x8F /* represent normal 80-9F */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
333
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
334 /** The following are for 1-byte characters in an official charset. **/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
335
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
336 #define LEADING_BYTE_LATIN_1 0x81 /* Right half of ISO 8859-1 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
337 #define LEADING_BYTE_LATIN_2 0x82 /* Right half of ISO 8859-2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
338 #define LEADING_BYTE_LATIN_3 0x83 /* Right half of ISO 8859-3 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
339 #define LEADING_BYTE_LATIN_4 0x84 /* Right half of ISO 8859-4 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
340 #define LEADING_BYTE_THAI 0x85 /* TIS620-2533 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
341 #define LEADING_BYTE_GREEK 0x86 /* Right half of ISO 8859-7 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
342 #define LEADING_BYTE_ARABIC 0x87 /* Right half of ISO 8859-6 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
343 #define LEADING_BYTE_HEBREW 0x88 /* Right half of ISO 8859-8 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
344 #define LEADING_BYTE_JAPANESE_JISX0201_KANA 0x89 /* Right half of JIS X0201-1976 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
345 #define LEADING_BYTE_JAPANESE_JISX0201_ROMAN 0x8A /* Left half of JIS X0201-1976 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
346 #define LEADING_BYTE_CYRILLIC 0x8C /* Right half of ISO 8859-5 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
347 #define LEADING_BYTE_LATIN_5 0x8D /* Right half of ISO 8859-9 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
348
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
349 #define MIN_LEADING_BYTE_OFFICIAL_1 LEADING_BYTE_LATIN_1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
350 #define MAX_LEADING_BYTE_OFFICIAL_1 LEADING_BYTE_LATIN_5
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
351
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
352 /** The following are for 2-byte characters in an official charset. **/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
353
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
354 #define LEADING_BYTE_JAPANESE_JISX0208_1978 0x90/* Japanese JIS X0208-1978 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
355 #define LEADING_BYTE_CHINESE_GB 0x91 /* Chinese Hanzi GB2312-1980 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
356 #define LEADING_BYTE_JAPANESE_JISX0208 0x92 /* Japanese JIS X0208-1983 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
357 #define LEADING_BYTE_KOREAN_KSC5601 0x93 /* Hangul KS C5601-1987 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
358 #define LEADING_BYTE_JAPANESE_JISX0212 0x94 /* Japanese JIS X0212-1990 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
359 #define LEADING_BYTE_CHINESE_CNS11643_1 0x95 /* Chinese CNS11643 Set 1 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
360 #define LEADING_BYTE_CHINESE_CNS11643_2 0x96 /* Chinese CNS11643 Set 2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
361 #define LEADING_BYTE_CHINESE_BIG5_1 0x97 /* Big5 Level 1 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
362 #define LEADING_BYTE_CHINESE_BIG5_2 0x98 /* Big5 Level 2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
363 /* 0x99 unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
364 /* 0x9A unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
365 /* 0x9B unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
366 /* 0x9C unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
367 /* 0x9D unused */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
368
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
369 #define MIN_LEADING_BYTE_OFFICIAL_2 LEADING_BYTE_JAPANESE_JISX0208_1978
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
370 #define MAX_LEADING_BYTE_OFFICIAL_2 LEADING_BYTE_CHINESE_BIG5_2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
371
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
372 /** The following are for 1- and 2-byte characters in a private charset. **/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
373
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
374 #define PRE_LEADING_BYTE_PRIVATE_1 0x9E /* 1-byte char-set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
375 #define PRE_LEADING_BYTE_PRIVATE_2 0x9F /* 2-byte char-set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
376
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
377 #define MIN_LEADING_BYTE_PRIVATE_1 0xA0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
378 #define MAX_LEADING_BYTE_PRIVATE_1 0xEF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
379 #define MIN_LEADING_BYTE_PRIVATE_2 0xF0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
380 #define MAX_LEADING_BYTE_PRIVATE_2 0xFF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
381
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
382 #define NUM_LEADING_BYTES 128
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 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
386 /* Operations on leading bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
387 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
388
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
389 /* Is this leading byte for a private charset? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
390
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
391 #define LEADING_BYTE_PRIVATE_P(lb) ((lb) >= MIN_LEADING_BYTE_PRIVATE_1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
392
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
393 /* Is this a prefix for a private leading byte? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
394
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
395 INLINE int LEADING_BYTE_PREFIX_P (unsigned char lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
396 INLINE int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
397 LEADING_BYTE_PREFIX_P (unsigned char lb)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
398 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
399 return (lb == PRE_LEADING_BYTE_PRIVATE_1 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
400 lb == PRE_LEADING_BYTE_PRIVATE_2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
401 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
402
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
403 /* Given a private leading byte, return the leading byte prefix stored
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
404 in a string */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
405
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
406 #define PRIVATE_LEADING_BYTE_PREFIX(lb) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
407 ((lb) < MIN_LEADING_BYTE_PRIVATE_2 ? PRE_LEADING_BYTE_PRIVATE_1 \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
408 : PRE_LEADING_BYTE_PRIVATE_2)
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
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
413 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
414 /* Operations on individual bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
415 /* of any format */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
416 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
417
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
418 /* Argument `c' should be (unsigned int) or (unsigned char). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
419 /* Note that SP and DEL are not included. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
420
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
421 #define BYTE_ASCII_P(c) ((c) < 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
422 #define BYTE_C0_P(c) ((c) < 0x20)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
423 /* Do some forced casting just to make *sure* things are gotten right. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
424 #define BYTE_C1_P(c) ((unsigned int) ((unsigned int) (c) - 0x80) < 0x20)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
425
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
426
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
427 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
428 /* Operations on individual bytes */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
429 /* in a Mule-formatted string */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
430 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
431
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
432 /* Does this byte represent the first byte of a character? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
433
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
434 #define BUFBYTE_FIRST_BYTE_P(c) ((c) < 0xA0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
435
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
436 /* Does this byte represent the first byte of a multi-byte character? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
437
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
438 #define BUFBYTE_LEADING_BYTE_P(c) BYTE_C1_P (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
439
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
440
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
441 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
442 /* Information about a particular character set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
443 /************************************************************************/
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 Lisp_Charset
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
446 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
447 struct lcrecord_header header;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
448
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
449 Lisp_Object name;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
450 Lisp_Object doc_string, registry;
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 reverse_direction_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
453
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
454 Lisp_Object ccl_program;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
455
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
456 unsigned int leading_byte :8;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
457
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
458 /* Number of bytes (1 - 4) required in the internal representation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
459 for characters in this character set. This is *not* the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
460 same as the number of bytes used in the encoding (i.e.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
461 the "dimension" of the character set). That value can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
462 be derived from the TYPE. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
463 unsigned int rep_bytes :3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
464
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
465 /* Number of columns a character in this charset takes up, on TTY
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
466 devices. Not used for X devices. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
467 unsigned int columns :2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
468 /* Direction of this character set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
469 unsigned int direction :1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
470
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
471 /* Type of this character set (94, 96, 94x94, 96x96) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
472 unsigned int type :2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
473
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
474 /* Which half of font to be used to display this character set */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
475 unsigned int graphic :2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
476
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
477 /* Final byte of this character set in ISO2022 designating escape sequence */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
478 Bufbyte final;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
479 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
480
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
481 DECLARE_LRECORD (charset, struct Lisp_Charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
482 #define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
483 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
484 #define CHARSETP(x) RECORDP (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
485 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
486 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
487 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
488
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
489 #define CHARSET_TYPE_94 0 /* This charset includes 94 characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
490 #define CHARSET_TYPE_96 1 /* This charset includes 96 characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
491 #define CHARSET_TYPE_94X94 2 /* This charset includes 94x94 characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
492 #define CHARSET_TYPE_96X96 3 /* This charset includes 96x96 characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
493
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
494 #define CHARSET_LEFT_TO_RIGHT 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
495 #define CHARSET_RIGHT_TO_LEFT 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
496
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
497 #define CHARSET_NAME(cs) ((cs)->name)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
498 #define CHARSET_LEADING_BYTE(cs) ((cs)->leading_byte)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
499 #define CHARSET_REP_BYTES(cs) ((cs)->rep_bytes)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
500 #define CHARSET_COLUMNS(cs) ((cs)->columns)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
501 #define CHARSET_GRAPHIC(cs) ((cs)->graphic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
502 #define CHARSET_TYPE(cs) ((cs)->type)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
503 #define CHARSET_DIRECTION(cs) ((cs)->direction)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
504 #define CHARSET_FINAL(cs) ((cs)->final)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
505 #define CHARSET_DOC_STRING(cs) ((cs)->doc_string)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
506 #define CHARSET_REGISTRY(cs) ((cs)->registry)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
507 #define CHARSET_CCL_PROGRAM(cs) ((cs)->ccl_program)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
508 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
509
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
510 INLINE int CHARSET_DIMENSION (struct Lisp_Charset *cs);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
511 INLINE int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
512 CHARSET_DIMENSION (struct Lisp_Charset *cs)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
513 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
514 return (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
515 CHARSET_TYPE (cs) == CHARSET_TYPE_96) ? 1 : 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
516 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
517
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
518 INLINE int CHARSET_CHARS (struct Lisp_Charset *cs);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
519 INLINE int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
520 CHARSET_CHARS (struct Lisp_Charset *cs)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
521 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
522 return (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
523 CHARSET_TYPE (cs) == CHARSET_TYPE_94X94) ? 94 : 96;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
524 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
525
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
526 #define CHARSET_PRIVATE_P(cs) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
527 LEADING_BYTE_PRIVATE_P (CHARSET_LEADING_BYTE (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
528
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
529 #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
530 #define XCHARSET_REP_BYTES(cs) CHARSET_REP_BYTES (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
531 #define XCHARSET_COLUMNS(cs) CHARSET_COLUMNS (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
532 #define XCHARSET_GRAPHIC(cs) CHARSET_GRAPHIC (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
533 #define XCHARSET_TYPE(cs) CHARSET_TYPE (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
534 #define XCHARSET_DIRECTION(cs) CHARSET_DIRECTION (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
535 #define XCHARSET_FINAL(cs) CHARSET_FINAL (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
536 #define XCHARSET_DOC_STRING(cs) CHARSET_DOC_STRING (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
537 #define XCHARSET_REGISTRY(cs) CHARSET_REGISTRY (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
538 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
539 #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
540 #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
541 #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
542 #define XCHARSET_PRIVATE_P(cs) CHARSET_PRIVATE_P (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
543 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
544 CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
545
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
546 /* Table of charsets indexed by (leading byte - 128). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
547 extern Lisp_Object charset_by_leading_byte[128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
548
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
549 /* Table of charsets indexed by type/final-byte/direction. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
550 extern Lisp_Object charset_by_attributes[4][128][2];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
551
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
552 /* Table of number of bytes in the string representation of a character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
553 indexed by the first byte of that representation.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
554
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
555 This value can be derived other ways -- e.g. something like
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
556
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
557 (BYTE_ASCII_P (first_byte) ? 1 :
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
558 XCHARSET_REP_BYTES (CHARSET_BY_LEADING_BYTE (first_byte)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
559
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
560 but it's faster this way. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
561 extern Bytecount rep_bytes_by_first_byte[0xA0];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
562
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
563 #ifdef ERROR_CHECK_TYPECHECK
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
564 /* 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
565 This way, out-ot-range values will get caught rather than automatically
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
566 truncated. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
567 INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (int lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
568 INLINE Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
569 CHARSET_BY_LEADING_BYTE (int lb)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
570 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
571 assert (lb >= 0x80 && lb <= 0xFF);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
572 return charset_by_leading_byte[lb - 128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
573 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
574
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
575 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
576
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
577 #define CHARSET_BY_LEADING_BYTE(lb) (charset_by_leading_byte[(lb) - 128])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
578
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
579 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
580
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
581 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
582 (charset_by_attributes[type][final][dir])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
583
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
584 #ifdef ERROR_CHECK_TYPECHECK
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
585
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
586 /* Number of bytes in the string representation of a character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
587 INLINE int REP_BYTES_BY_FIRST_BYTE (int fb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
588 INLINE int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
589 REP_BYTES_BY_FIRST_BYTE (int fb)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
590 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
591 assert (fb >= 0 && fb < 0xA0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
592 return rep_bytes_by_first_byte[fb];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
593 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
594
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
595 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
596 #define REP_BYTES_BY_FIRST_BYTE(fb) (rep_bytes_by_first_byte[fb])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
597 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
598
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
599 extern Lisp_Object Vcharset_ascii;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
600 extern Lisp_Object Vcharset_control_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
601 extern Lisp_Object Vcharset_latin_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
602 extern Lisp_Object Vcharset_latin_2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
603 extern Lisp_Object Vcharset_latin_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
604 extern Lisp_Object Vcharset_latin_4;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
605 extern Lisp_Object Vcharset_latin_5;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
606 extern Lisp_Object Vcharset_greek;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
607 extern Lisp_Object Vcharset_thai;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
608 extern Lisp_Object Vcharset_arabic;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
609 extern Lisp_Object Vcharset_hebrew;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
610 extern Lisp_Object Vcharset_cyrillic;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
611 extern Lisp_Object Vcharset_japanese_jisx0201_kana;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
612 extern Lisp_Object Vcharset_japanese_jisx0201_roman;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
613 extern Lisp_Object Vcharset_japanese_jisx0208_1978;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
614 extern Lisp_Object Vcharset_japanese_jisx0208;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
615 extern Lisp_Object Vcharset_japanese_jisx0212;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
616 extern Lisp_Object Vcharset_korean_ksc5601;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
617 extern Lisp_Object Vcharset_chinese_gb;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
618 extern Lisp_Object Vcharset_chinese_big5_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
619 extern Lisp_Object Vcharset_chinese_big5_2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
620 extern Lisp_Object Vcharset_chinese_cns11643_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
621 extern Lisp_Object Vcharset_chinese_cns11643_2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
622 extern Lisp_Object Vcharset_composite;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
623
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
624
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
625 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
626 /* Dealing with characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
627 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
628
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
629 /* Is this character represented by more than one byte in a string? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
630
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
631 #define CHAR_MULTIBYTE_P(c) ((c) >= 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
632
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
633 #define CHAR_ASCII_P(c) (!CHAR_MULTIBYTE_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
634
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
635 /* The bit fields of character are divided into 3 parts:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
636 FIELD1(5bits):FIELD2(7bits):FIELD3(7bits) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
637
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
638 #define CHAR_FIELD1_MASK (0x1F << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
639 #define CHAR_FIELD2_MASK (0x7F << 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
640 #define CHAR_FIELD3_MASK 0x7F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
641
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
642 /* Macros to access each field of a character code of C. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
643
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
644 #define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
645 #define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
646 #define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
647
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
648 /* Field 1, if non-zero, usually holds a leading byte for a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
649 dimension-2 charset. Field 2, if non-zero, usually holds a leading
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
650 byte for a dimension-1 charset. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
651
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
652 /* Converting between field values and leading bytes. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
653
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
654 #define FIELD2_TO_OFFICIAL_LEADING_BYTE 0x80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
655 #define FIELD2_TO_PRIVATE_LEADING_BYTE 0x80
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 FIELD1_TO_OFFICIAL_LEADING_BYTE 0x8F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
658 #define FIELD1_TO_PRIVATE_LEADING_BYTE 0xE1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
659
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
660 /* Minimum and maximum allowed values for the fields. */
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_FIELD2_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
663 (MIN_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
664 #define MAX_CHAR_FIELD2_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
665 (MAX_LEADING_BYTE_OFFICIAL_1 - FIELD2_TO_OFFICIAL_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 #define MIN_CHAR_FIELD1_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
668 (MIN_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
669 #define MAX_CHAR_FIELD1_OFFICIAL \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
670 (MAX_LEADING_BYTE_OFFICIAL_2 - FIELD1_TO_OFFICIAL_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
671
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
672 #define MIN_CHAR_FIELD2_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
673 (MIN_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
674 #define MAX_CHAR_FIELD2_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
675 (MAX_LEADING_BYTE_PRIVATE_1 - FIELD2_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
676
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
677 #define MIN_CHAR_FIELD1_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
678 (MIN_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
679 #define MAX_CHAR_FIELD1_PRIVATE \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
680 (MAX_LEADING_BYTE_PRIVATE_2 - FIELD1_TO_PRIVATE_LEADING_BYTE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
681
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
682 /* Minimum character code of each <type> character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
683
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
684 #define MIN_CHAR_OFFICIAL_TYPE9N (MIN_CHAR_FIELD2_OFFICIAL << 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
685 #define MIN_CHAR_PRIVATE_TYPE9N (MIN_CHAR_FIELD2_PRIVATE << 7)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
686 #define MIN_CHAR_OFFICIAL_TYPE9NX9N (MIN_CHAR_FIELD1_OFFICIAL << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
687 #define MIN_CHAR_PRIVATE_TYPE9NX9N (MIN_CHAR_FIELD1_PRIVATE << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
688 #define MIN_CHAR_COMPOSITION (0x1F << 14)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
689
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
690 /* Leading byte of a character.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
691
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
692 NOTE: This takes advantage of the fact that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
693 FIELD2_TO_OFFICIAL_LEADING_BYTE and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
694 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
695 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
696
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
697 INLINE Bufbyte CHAR_LEADING_BYTE (Emchar c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
698 INLINE Bufbyte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
699 CHAR_LEADING_BYTE (Emchar c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
700 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
701 if (CHAR_ASCII_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
702 return LEADING_BYTE_ASCII;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
703 else if (c < 0xA0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
704 return LEADING_BYTE_CONTROL_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
705 else if (c < MIN_CHAR_OFFICIAL_TYPE9NX9N)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
706 return CHAR_FIELD2 (c) + FIELD2_TO_OFFICIAL_LEADING_BYTE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
707 else if (c < MIN_CHAR_PRIVATE_TYPE9NX9N)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
708 return CHAR_FIELD1 (c) + FIELD1_TO_OFFICIAL_LEADING_BYTE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
709 else if (c < MIN_CHAR_COMPOSITION)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
710 return CHAR_FIELD1 (c) + FIELD1_TO_PRIVATE_LEADING_BYTE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
711 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
712 return LEADING_BYTE_COMPOSITE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
713 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
714
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
715 #define CHAR_CHARSET(c) CHARSET_BY_LEADING_BYTE (CHAR_LEADING_BYTE (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
716
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
717 /* Return a character whose charset is CHARSET and position-codes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
718 are C1 and C2. TYPE9N character ignores C2.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
719
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
720 NOTE: This takes advantage of the fact that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
721 FIELD2_TO_OFFICIAL_LEADING_BYTE and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
722 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
723 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
724
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
725 INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
726 INLINE Emchar
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
727 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
728 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
729 if (EQ (charset, Vcharset_ascii))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
730 return c1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
731 else if (EQ (charset, Vcharset_control_1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
732 return c1 | 0x80;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
733 else if (EQ (charset, Vcharset_composite))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
734 return (0x1F << 14) | ((c1) << 7) | (c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
735 else if (XCHARSET_DIMENSION (charset) == 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
736 return ((XCHARSET_LEADING_BYTE (charset) -
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
737 FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) | (c1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
738 else if (!XCHARSET_PRIVATE_P (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
739 return ((XCHARSET_LEADING_BYTE (charset) -
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
740 FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
741 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
742 return ((XCHARSET_LEADING_BYTE (charset) -
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
743 FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | ((c1) << 7) | (c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
744 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
745
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
746 /* The charset of character C is set to CHARSET, and the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
747 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
748 is 0. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
749
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
750 /* BREAKUP_CHAR_1_UNSAFE assumes that the charset has already been
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
751 calculated, and just computes c1 and 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 BREAKUP_CHAR also computes and stores the charset. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
754
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
755 #define BREAKUP_CHAR_1_UNSAFE(c, charset, c1, c2) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
756 XCHARSET_DIMENSION (charset) == 1 \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
757 ? ((c1) = CHAR_FIELD3 (c), (c2) = 0) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
758 : ((c1) = CHAR_FIELD2 (c), \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
759 (c2) = CHAR_FIELD3 (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
760
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
761 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
762 INLINE void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
763 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
764 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
765 *charset = CHAR_CHARSET (c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
766 BREAKUP_CHAR_1_UNSAFE (c, *charset, *c1, *c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
767 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
768
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
769 #define BREAKUP_CHAR(c, charset, c1, c2) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
770 breakup_char_1 (c, &(charset), &(c1), &(c2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
771
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
772
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 /* Composite characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
776 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
777
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
778 extern Lisp_Object Vcomposite_char_int2string_hashtable;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
779 extern Lisp_Object Vcomposite_char_string2int_hashtable;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
780
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
781 Emchar lookup_composite_char (Bufbyte *str, int len);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
782 Lisp_Object composite_char_string (Emchar ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
783
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
784
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
785
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
786 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
787 /* Exported functions */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
788 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
789
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
790 Lisp_Object Fget_charset (Lisp_Object);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
791 Lisp_Object Ffind_charset (Lisp_Object);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
792
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
793 int copy_internal_to_external (CONST Bufbyte *internal, Bytecount len,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
794 unsigned char *external);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
795 Bytecount copy_external_to_internal (CONST unsigned char *external,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
796 int len, Bufbyte *internal);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
797
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
798 #endif /* _XEMACS_MULE_CHARSET_H */