771
|
1 ;;; unicode.el --- Unicode support -*- coding: iso-2022-7bit; -*-
|
|
2
|
778
|
3 ;; Copyright (C) 2001, 2002 Ben Wing.
|
771
|
4
|
|
5 ;; Keywords: multilingual, Unicode
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
|
23
|
|
24 ;;; Synched up with: Not in FSF.
|
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; Lisp support for Unicode, e.g. initialize the translation tables.
|
|
29
|
|
30 ;;; Code:
|
|
31
|
778
|
32 ; ;; Subsets of Unicode.
|
|
33
|
2297
|
34 ; #### what is this bogosity ... "chars 96, final ?2" !!?!
|
778
|
35 ; (make-charset 'mule-unicode-2500-33ff
|
|
36 ; "Unicode characters of the range U+2500..U+33FF."
|
|
37 ; '(dimension
|
|
38 ; 2
|
|
39 ; registry "ISO10646-1"
|
|
40 ; chars 96
|
|
41 ; columns 1
|
|
42 ; direction l2r
|
|
43 ; final ?2
|
|
44 ; graphic 0
|
|
45 ; short-name "Unicode subset 2"
|
|
46 ; long-name "Unicode subset (U+2500..U+33FF)"
|
|
47 ; ))
|
|
48
|
|
49
|
|
50 ; (make-charset 'mule-unicode-e000-ffff
|
|
51 ; "Unicode characters of the range U+E000..U+FFFF."
|
|
52 ; '(dimension
|
|
53 ; 2
|
|
54 ; registry "ISO10646-1"
|
|
55 ; chars 96
|
|
56 ; columns 1
|
|
57 ; direction l2r
|
|
58 ; final ?3
|
|
59 ; graphic 0
|
|
60 ; short-name "Unicode subset 3"
|
|
61 ; long-name "Unicode subset (U+E000+FFFF)"
|
|
62 ; ))
|
|
63
|
|
64
|
|
65 ; (make-charset 'mule-unicode-0100-24ff
|
|
66 ; "Unicode characters of the range U+0100..U+24FF."
|
|
67 ; '(dimension
|
|
68 ; 2
|
|
69 ; registry "ISO10646-1"
|
|
70 ; chars 96
|
|
71 ; columns 1
|
|
72 ; direction l2r
|
|
73 ; final ?1
|
|
74 ; graphic 0
|
|
75 ; short-name "Unicode subset"
|
|
76 ; long-name "Unicode subset (U+0100..U+24FF)"
|
|
77 ; ))
|
|
78
|
|
79
|
771
|
80 ;; NOTE: This takes only a fraction of a second on my Pentium III
|
|
81 ;; 700Mhz even with a totally optimization-disabled XEmacs.
|
|
82 (defun load-unicode-tables ()
|
|
83 "Initialize the Unicode translation tables for all standard charsets."
|
780
|
84 (let ((parse-args
|
|
85 '(("unicode/unicode-consortium"
|
877
|
86 ;; Due to the braindamaged way Mule treats the ASCII and Control-1
|
|
87 ;; charsets' types, trying to load them results in out-of-range
|
|
88 ;; warnings at unicode.c:1439. They're no-ops anyway, they're
|
|
89 ;; hardwired in unicode.c (unicode_to_ichar, ichar_to_unicode).
|
|
90 ;; ("8859-1.TXT" ascii #x00 #x7F #x0)
|
|
91 ;; ("8859-1.TXT" control-1 #x80 #x9F #x-80)
|
|
92 ;; The 8859-1.TXT G1 assignments are half no-ops, hardwired in
|
|
93 ;; unicode.c ichar_to_unicode, but not in unicode_to_ichar.
|
780
|
94 ("8859-1.TXT" latin-iso8859-1 #xA0 #xFF #x-80)
|
|
95 ;; "8859-10.TXT"
|
|
96 ;; "8859-13.TXT"
|
|
97 ("8859-14.TXT" latin-iso8859-14 #xA0 #xFF #x-80)
|
|
98 ("8859-15.TXT" latin-iso8859-15 #xA0 #xFF #x-80)
|
|
99 ("8859-2.TXT" latin-iso8859-2 #xA0 #xFF #x-80)
|
|
100 ("8859-3.TXT" latin-iso8859-3 #xA0 #xFF #x-80)
|
|
101 ("8859-4.TXT" latin-iso8859-4 #xA0 #xFF #x-80)
|
|
102 ("8859-5.TXT" cyrillic-iso8859-5 #xA0 #xFF #x-80)
|
|
103 ("8859-6.TXT" arabic-iso8859-6 #xA0 #xFF #x-80)
|
|
104 ("8859-7.TXT" greek-iso8859-7 #xA0 #xFF #x-80)
|
|
105 ("8859-8.TXT" hebrew-iso8859-8 #xA0 #xFF #x-80)
|
|
106 ("8859-9.TXT" latin-iso8859-9 #xA0 #xFF #x-80)
|
|
107 ;; charset for Big5 does not matter; specifying `big5' will
|
|
108 ;; automatically make the right thing happen
|
|
109 ("BIG5.TXT" chinese-big5-1 nil nil nil big5)
|
|
110 ("CNS11643.TXT" chinese-cns11643-1 #x10000 #x1FFFF #x-10000)
|
|
111 ("CNS11643.TXT" chinese-cns11643-2 #x20000 #x2FFFF #x-20000)
|
|
112 ;; "CP1250.TXT"
|
|
113 ;; "CP1251.TXT"
|
|
114 ;; "CP1252.TXT"
|
|
115 ;; "CP1253.TXT"
|
|
116 ;; "CP1254.TXT"
|
|
117 ;; "CP1255.TXT"
|
|
118 ;; "CP1256.TXT"
|
|
119 ;; "CP1257.TXT"
|
|
120 ;; "CP1258.TXT"
|
|
121 ;; "CP874.TXT"
|
|
122 ;; "CP932.TXT"
|
|
123 ;; "CP936.TXT"
|
|
124 ;; "CP949.TXT"
|
|
125 ;; "CP950.TXT"
|
|
126 ;; "GB12345.TXT"
|
|
127 ("GB2312.TXT" chinese-gb2312)
|
2297
|
128 ;; "HANGUL.TXT"
|
|
129 ;; #### shouldn't JIS X 0201's upper limit be 7f?
|
780
|
130 ("JIS0201.TXT" latin-jisx0201 #x21 #x80)
|
|
131 ("JIS0201.TXT" katakana-jisx0201 #xA0 #xFF #x-80)
|
|
132 ("JIS0208.TXT" japanese-jisx0208 nil nil nil ignore-first-column)
|
|
133 ("JIS0212.TXT" japanese-jisx0212)
|
|
134 ;; "JOHAB.TXT"
|
|
135 ;; "KOI8-R.TXT"
|
|
136 ;; "KSC5601.TXT"
|
|
137 ;; note that KSC5601.TXT as currently distributed is NOT what
|
|
138 ;; it claims to be! see comments in KSX1001.TXT.
|
|
139 ("KSX1001.TXT" korean-ksc5601)
|
|
140 ;; "OLD5601.TXT"
|
|
141 ;; "SHIFTJIS.TXT"
|
|
142 )
|
|
143 ("unicode/mule-ucs"
|
2297
|
144 ;; #### we don't support surrogates?!??
|
780
|
145 ;; use these instead of the above ones once we support surrogates
|
|
146 ;;("chinese-cns11643-1.txt" chinese-cns11643-1)
|
|
147 ;;("chinese-cns11643-2.txt" chinese-cns11643-2)
|
|
148 ;;("chinese-cns11643-3.txt" chinese-cns11643-3)
|
|
149 ;;("chinese-cns11643-4.txt" chinese-cns11643-4)
|
|
150 ;;("chinese-cns11643-5.txt" chinese-cns11643-5)
|
|
151 ;;("chinese-cns11643-6.txt" chinese-cns11643-6)
|
|
152 ;;("chinese-cns11643-7.txt" chinese-cns11643-7)
|
|
153 ("chinese-sisheng.txt" chinese-sisheng)
|
|
154 ("ethiopic.txt" ethiopic)
|
|
155 ("indian-is13194.txt" indian-is13194)
|
|
156 ("ipa.txt" ipa)
|
|
157 ("thai-tis620.txt" thai-tis620)
|
|
158 ("tibetan.txt" tibetan)
|
|
159 ("vietnamese-viscii-lower.txt" vietnamese-viscii-lower)
|
|
160 ("vietnamese-viscii-upper.txt" vietnamese-viscii-upper)
|
|
161 )
|
|
162 ("unicode/other"
|
|
163 ("lao.txt" lao)
|
|
164 )
|
771
|
165 )))
|
780
|
166 (mapcar #'(lambda (tables)
|
|
167 (let ((undir
|
|
168 (expand-file-name (car tables) data-directory)))
|
|
169 (mapcar #'(lambda (args)
|
1318
|
170 (apply 'load-unicode-mapping-table
|
780
|
171 (expand-file-name (car args) undir)
|
|
172 (cdr args)))
|
|
173 (cdr tables))))
|
771
|
174 parse-args)))
|
|
175
|
|
176 (defun init-unicode-at-startup ()
|
|
177 (load-unicode-tables))
|
|
178
|
|
179 (make-coding-system
|
|
180 'utf-16 'unicode
|
|
181 "UTF-16"
|
|
182 '(mnemonic "UTF-16"
|
|
183 documentation
|
|
184 "UTF-16 Unicode encoding -- the standard (almost-) fixed-width
|
|
185 two-byte encoding, with surrogates. It will be fixed-width if all
|
|
186 characters are in the BMP (Basic Multilingual Plane -- first 65536
|
|
187 codepoints). Cannot represent characters with codepoints above
|
|
188 0x10FFFF (a little more than 1,000,000). Unicode and ISO guarantee
|
|
189 never to encode any characters outside this range -- all the rest are
|
|
190 for private, corporate or internal use."
|
|
191 type utf-16))
|
|
192
|
|
193 (make-coding-system
|
|
194 'utf-16-bom 'unicode
|
|
195 "UTF-16 w/BOM"
|
|
196 '(mnemonic "UTF16-BOM"
|
|
197 documentation
|
|
198 "UTF-16 Unicode encoding with byte order mark (BOM) at the beginning.
|
|
199 The BOM is Unicode character U+FEFF -- i.e. the first two bytes are
|
|
200 0xFE and 0xFF, respectively, or reversed in a little-endian
|
|
201 representation. It has been sanctioned by the Unicode Consortium for
|
|
202 use at the beginning of a Unicode stream as a marker of the byte order
|
|
203 of the stream, and commonly appears in Unicode files under Microsoft
|
|
204 Windows, where it also functions as a magic cookie identifying a
|
|
205 Unicode file. The character is called \"ZERO WIDTH NO-BREAK SPACE\"
|
|
206 and is suitable as a byte-order marker because:
|
|
207
|
|
208 -- it has no displayable representation
|
|
209 -- due to its semantics it never normally appears at the beginning
|
|
210 of a stream
|
|
211 -- its reverse U+FFFE is not a legal Unicode character
|
|
212 -- neither byte sequence is at all likely in any other standard
|
|
213 encoding, particularly at the beginning of a stream
|
|
214
|
|
215 This coding system will insert a BOM at the beginning of a stream when
|
|
216 writing and strip it off when reading."
|
|
217 type utf-16
|
|
218 need-bom t))
|
|
219
|
|
220 (make-coding-system
|
|
221 'utf-16-little-endian 'unicode
|
|
222 "UTF-16 Little Endian"
|
|
223 '(mnemonic "UTF16-LE"
|
|
224 documentation
|
|
225 "Little-endian version of UTF-16 Unicode encoding.
|
|
226 See `utf-16' coding system."
|
|
227 type utf-16
|
|
228 little-endian t))
|
|
229
|
|
230 (make-coding-system
|
|
231 'utf-16-little-endian-bom 'unicode
|
|
232 "UTF-16 Little Endian w/BOM"
|
|
233 '(mnemonic "MSW-Unicode"
|
|
234 documentation
|
|
235 "Little-endian version of UTF-16 Unicode encoding, with byte order mark.
|
|
236 Standard encoding for representing Unicode under MS Windows. See
|
|
237 `utf-16-bom' coding system."
|
|
238 type utf-16
|
|
239 little-endian t
|
|
240 need-bom t))
|
|
241
|
|
242 (make-coding-system
|
|
243 'ucs-4 'unicode
|
|
244 "UCS-4"
|
|
245 '(mnemonic "UCS4"
|
|
246 documentation
|
|
247 "UCS-4 Unicode encoding -- fully fixed-width four-byte encoding."
|
|
248 type ucs-4))
|
|
249
|
|
250 (make-coding-system
|
|
251 'ucs-4-little-endian 'unicode
|
|
252 "UCS-4 Little Endian"
|
|
253 '(mnemonic "UCS4-LE"
|
|
254 documentation
|
2297
|
255 ;; #### I don't think this is permitted by ISO 10646, only Unicode.
|
|
256 ;; Call it UTF-32 instead?
|
771
|
257 "Little-endian version of UCS-4 Unicode encoding. See `ucs-4' coding system."
|
|
258 type ucs-4
|
|
259 little-endian t))
|
|
260
|
|
261 (make-coding-system
|
|
262 'utf-8 'unicode
|
|
263 "UTF-8"
|
|
264 '(mnemonic "UTF8"
|
|
265 documentation
|
|
266 "UTF-8 Unicode encoding -- ASCII-compatible 8-bit variable-width encoding
|
2297
|
267 sharing the following principles with the Mule-internal encoding:
|
771
|
268
|
|
269 -- All ASCII characters (codepoints 0 through 127) are represented
|
|
270 by themselves (i.e. using one byte, with the same value as the
|
|
271 ASCII codepoint), and these bytes are disjoint from bytes
|
|
272 representing non-ASCII characters.
|
|
273
|
|
274 This means that any 8-bit clean application can safely process
|
|
275 UTF-8-encoded text as it were ASCII, with no corruption (e.g. a
|
|
276 '/' byte is always a slash character, never the second byte of
|
|
277 some other character, as with Big5, so a pathname encoded in
|
|
278 UTF-8 can safely be split up into components and reassembled
|
|
279 again using standard ASCII processes).
|
|
280
|
|
281 -- Leading bytes and non-leading bytes in the encoding of a
|
|
282 character are disjoint, so moving backwards is easy.
|
|
283
|
|
284 -- Given only the leading byte, you know how many following bytes
|
|
285 are present.
|
|
286 "
|
|
287 type utf-8))
|
|
288
|
985
|
289 (make-coding-system
|
|
290 'utf-8-bom 'unicode
|
|
291 "UTF-8 w/BOM"
|
|
292 '(mnemonic "MSW-UTF8"
|
|
293 documentation
|
|
294 "UTF-8 Unicode encoding, with byte order mark.
|
|
295 Standard encoding for representing UTF-8 under MS Windows."
|
|
296 type utf-8
|
|
297 little-endian t
|
|
298 need-bom t))
|
|
299
|
771
|
300 ;; #### UTF-7 is not yet implemented, and it's tricky to do. There's
|
|
301 ;; an implementation in appendix A.1 of the Unicode Standard, Version
|
|
302 ;; 2.0, but I don't know its licensing characteristics.
|
|
303
|
|
304 ; (make-coding-system
|
|
305 ; 'utf-7 'unicode
|
|
306 ; "UTF-7"
|
|
307 ; '(mnemonic "UTF7"
|
|
308 ; documentation
|
|
309 ; "UTF-7 Unicode encoding -- 7-bit-ASCII modal Internet-mail-compatible
|
|
310 ; encoding especially designed for headers, with the following
|
|
311 ; properties:
|
|
312
|
|
313 ; -- Only characters that are considered safe for passing through any mail
|
|
314 ; gateway without damage are used.
|
|
315
|
|
316 ; -- This is a modal encoding, with two states. The first, default
|
|
317 ; state encodes the most common Unicode characters (upper and
|
|
318 ; lowercase letters, digits, and 9 common punctuation marks) as
|
|
319 ; themselves, and the second state, entered using '+' and
|
|
320 ; terminated with '-' or any character disallowed in state 2,
|
|
321 ; encodes any Unicode characters by first converting to UTF-16,
|
|
322 ; most significant byte first, and then to a slightly modified
|
|
323 ; Base64 encoding. (Thus, UTF-7 has the same limitations on the
|
|
324 ; characters it can encode as UTF-16.)
|
|
325
|
|
326 ; -- The modified Base64 encoding deviates from standard Base64 in
|
|
327 ; that it omits the `=' pad character. This is eliminated so as to
|
|
328 ; avoid conflicts with the use of `=' as an escape in the
|
|
329 ; Quoted-Printable encoding and the related Q encoding for headers:
|
|
330 ; With this modification, non-whitespace chars in UTF-7 will be
|
|
331 ; represented in Quoted-Printable and in Q as-is, with no further
|
|
332 ; encoding.
|
|
333
|
|
334 ; For more information, see Appendix A.1 of The Unicode Standard 2.0, or
|
|
335 ; wherever it is in v3.0."
|
|
336 ; type utf-7))
|