annotate lisp/international/utf-16.el @ 47612:2d55f7e8ff64

Use built-in network primitives. (server-program, server-previous-string): Remove. (server-previous-strings): New var. (server-socket-name): New var. (server-log): Minor change to the output format. (server-sentinel): Clean up global state when a client disconnects. (server-unquote-arg): New fun. (server-start): Use server-socket-name and make-network-process. (server-process-filter): Now talks to the clients directly. Normalize file name after unquoting and decoding. (server-buffer-done): Just close the connection. (server-switch-buffer): Handle the case where all windows are dedicated or minibuffers.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 25 Sep 2002 19:54:13 +0000
parents e83401f8d61c
children 797c350a7f8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46677
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; utf-16.el --- UTF-16 encoding/decoding
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2001, 2002 Free Software Foundation, Inc.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
4
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: Unicode, UTF-16, i18n
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
7
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
9
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; any later version.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
14
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
19
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
24
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
26
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27 ;; Support for UTF-16, which is a two-byte encoding (modulo
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; surrogates) of Unicode, written either in little or big endian
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; order: coding-systems `mule-utf-16-le' and `mule-utf-16-be'.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; (utf-16-le is used by the DozeN'T clipboard, for instance.) The
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; data are preceeded by a two-byte signature which identifies their
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; byte sex. These are used by the coding-category-utf-16-{b,l}e code
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
33 ;; to identify the coding, but ignored on decoding.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
34
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
35 ;; Note that un-decodable sequences aren't (yet?) preserved as raw
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;; bytes, as they are with utf-8, so reading and writing as utf-16 can
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ;; corrupt data.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
38
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ;;; Code:
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
40
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;; We end up with trivially different -le and -be versions of most
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
42 ;; things below, sometimes with commonality abstracted into a let
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;; binding for maintenance convenience.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
44
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
45 ;; We'd need new charsets distinct from ascii and eight-bit-control to
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
46 ;; deal with untranslated sequences, since we can't otherwise
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
47 ;; distinguish the bytes, as we can with utf-8.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
48
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
49 ;; ;; Do a multibyte write for bytes in r3 and r4.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
50 ;; ;; Intended for untranslatable utf-16 sequences.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
51 ;; (define-ccl-program ccl-mule-utf-16-untrans
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
52 ;; `(0
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
53 ;; (if (r3 < 128)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
54 ;; (r0 = ,(charset-id 'ascii))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
55 ;; (if (r3 < 160)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
56 ;; (r0 = ,(charset-id 'eight-bit-control))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
57 ;; (r0 = ,(charset-id 'eight-bit-graphic))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
58 ;; (if (r4 < 128)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
59 ;; (r0 = ,(charset-id 'ascii))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
60 ;; (if (r4 < 160)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
61 ;; (r0 = ,(charset-id 'eight-bit-control))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
62 ;; (r0 = ,(charset-id 'eight-bit-graphic))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
63 ;; (r1 = r4)))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
64 ;; "Do a multibyte write for bytes in r3 and r4.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
65 ;; First swap them if we're big endian, indicated by r5==0.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
66 ;; Intended for untranslatable utf-16 sequences.")
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
67
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
68 ;; Needed in macro expansion, so can't be let-bound. Zapped after use.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
69 (eval-and-compile
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
70 (defconst utf-16-decode-ucs
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
71 ;; We have the unicode in r1. Output is character codes in r0, r1,
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
72 ;; and r2 if appropriate.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
73 `((lookup-integer utf-8-subst-table r0 r3)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
74 (if r7 (r1 = r3)) ; got a translation
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
75 (if (r1 < 128)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
76 (r0 = ,(charset-id 'ascii))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
77 (if (r1 < 160)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
78 (r0 = ,(charset-id 'eight-bit-control))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
79 (if (r1 < 256)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
80 ((r0 = ,(charset-id 'latin-iso8859-1))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
81 (r1 -= 128))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
82 (if (r1 < #x2500)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
83 ((r0 = ,(charset-id 'mule-unicode-0100-24ff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
84 (r1 -= #x100)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
85 (r2 = (((r1 / 96) + 32) << 7))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (r1 %= 96)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
87 (r1 += (r2 + 32)))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
88 (if (r1 < #x3400)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
89 ((r0 = ,(charset-id 'mule-unicode-2500-33ff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
90 (r1 -= #x2500)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
91 (r2 = (((r1 / 96) + 32) << 7))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
92 (r1 %= 96)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
93 (r1 += (r2 + 32)))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
94 (if (r1 < #xd800) ; 2 untranslated bytes
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
95 ;; ;; Assume this is rare, so don't worry about the
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
96 ;; ;; overhead of the call.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
97 ;; (call mule-utf-16-untrans)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
98 ((r0 = ,(charset-id 'mule-unicode-e000-ffff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
99 (r1 = 15037)) ; U+fffd
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
100 (if (r1 < #xe000) ; surrogate
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
101 ;; ((call mule-utf-16-untrans)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
102 ;; (write-multibyte-character r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
103 ;; (read r3 r4)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
104 ;; (call mule-utf-16-untrans))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
105 ((read r3 r4)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
106 (r0 = ,(charset-id 'mule-unicode-e000-ffff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (r1 = 15037))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
108 ((r0 = ,(charset-id 'mule-unicode-e000-ffff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
109 (r1 -= #xe000)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
110 (r2 = (((r1 / 96) + 32) << 7))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
111 (r1 %= 96)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
112 (r1 += (r2 + 32)))))))))))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
113
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
114 (define-ccl-program ccl-decode-mule-utf-16-le
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
115 `(2 ; 2 bytes -> 1 to 4 bytes
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
116 ((read r0 r1) ; signature
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
117 (loop
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
118 (read r3 r4)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
119 (r1 = (r4 <8 r3))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
120 ,utf-16-decode-ucs
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
121 (translate-character utf-8-translation-table-for-decode r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
122 (write-multibyte-character r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
123 (repeat))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
124 "Decode little endian UTF-16 (ignoring signature bytes).
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
125 Basic decoding is done into the charsets ascii, latin-iso8859-1 and
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
126 mule-unicode-*. Un-representable Unicode characters are
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
127 decoded as U+fffd. The result is run through translation table
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
128 `utf-8-translation-table-for-decode' if that is defined.")
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
129
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
130 (define-ccl-program ccl-decode-mule-utf-16-be
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
131 `(2 ; 2 bytes -> 1 to 4 bytes
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
132 ((read r0 r1) ; signature
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
133 (loop
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
134 (read r3 r4)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (r1 = (r3 <8 r4))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
136 ,utf-16-decode-ucs
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
137 (translate-character utf-8-translation-table-for-decode r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
138 (write-multibyte-character r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
139 (repeat))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
140 "Decode big endian UTF-16 (ignoring signature bytes).
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
141 Basic decoding is done into the charsets ascii, latin-iso8859-1 and
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
142 mule-unicode-*. Un-representable Unicode characters are
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
143 decoded as U+fffd. The result is run through translation table
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
144 `utf-8-non-latin-8859-table'.")
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
145
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
146 (makunbound 'utf-16-decode-ucs) ; done with it
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
147
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
148 (eval-and-compile
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
149 (defconst utf-16-decode-to-ucs
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
150 ;; CCL which, given the result of a multibyte read in r0 and r1,
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
151 ;; sets r0 to the character's Unicode if the charset is one of the
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
152 ;; basic utf-8 coding system ones. Otherwise set to U+fffd.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
153 `(if (r0 == ,(charset-id 'ascii))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
154 (r0 = r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
155 (if (r0 == ,(charset-id 'latin-iso8859-1))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
156 (r0 = (r1 + 128))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
157 (if (r0 == ,(charset-id 'eight-bit-control))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
158 (r0 = r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
159 (if (r0 == ,(charset-id 'eight-bit-graphic))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
160 (r0 = r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
161 ((r2 = (r1 & #x7f))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
162 (r1 >>= 7)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
163 (r3 = ((r1 - 32) * 96))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
164 (r3 += (r2 - 32))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
165 (if (r0 == ,(charset-id 'mule-unicode-0100-24ff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
166 (r0 = (r3 + #x100))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
167 (if (r0 == ,(charset-id 'mule-unicode-2500-33ff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
168 (r0 = (r3 + #x2500))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
169 (if (r0 == ,(charset-id 'mule-unicode-e000-ffff))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
170 (r0 = (r3 + #xe000))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
171 (r0 = #xfffd)))))))))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
172
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
173 (define-ccl-program ccl-encode-mule-utf-16-le
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
174 `(1
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
175 ((write #xff)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
176 (write #xfe)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
177 (loop
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
178 (read-multibyte-character r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
179 (translate-character ucs-mule-to-mule-unicode r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
180 ,utf-16-decode-to-ucs
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
181 (write (r0 & 255))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
182 (write (r0 >> 8))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
183 (repeat))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
184 "Encode to little endian UTF-16 with signature.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
185 Characters from the charsets ascii, eight-bit-control,
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
186 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
187 after translation through the table `ucs-mule-to-mule-unicode'.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
188 Others are encoded as U+FFFD.")
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
189
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
190 (define-ccl-program ccl-encode-mule-utf-16-be
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
191 `(1
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
192 ((write #xfe)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
193 (write #xff)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
194 (loop
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
195 (read-multibyte-character r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
196 (translate-character ucs-mule-to-mule-unicode r0 r1)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
197 ,utf-16-decode-to-ucs
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
198 (write (r0 >> 8))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
199 (write (r0 & 255))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
200 (repeat))))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
201 "Encode to big endian UTF-16 with signature.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
202 Characters from the charsets ascii, eight-bit-control,
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
203 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
204 after translation through the table `ucs-mule-to-mule-unicode'.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
205 Others are encoded as U+FFFD.")
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
206
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
207 (makunbound 'utf-16-decode-to-ucs)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
208
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
209 (let ((doc "
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
210
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
211 Assumes and ignores the leading two-byte signature.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
212
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
213 The supported Emacs character sets are the following, plus others
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
214 which may be included in the translation table
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
215 `ucs-mule-to-mule-unicode':
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
216 ascii
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
217 eight-bit-control
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
218 latin-iso8859-1
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
219 mule-unicode-0100-24ff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
220 mule-unicode-2500-33ff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
221 mule-unicode-e000-ffff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
222
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
223 Note that Unicode characters out of the ranges U+0000-U+33FF and
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
224 U+E200-U+FFFF are decoded as U+FFFD, effectively corrupting the data
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
225 if they are re-encoded. Emacs characters without Unicode conversions
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
226 are encoded as U+FFFD."))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
227 (make-coding-system
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
228 'mule-utf-16-le 4
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
229 ?u ; Mule-UCS uses ?U, but code-pages uses that for koi8-u.
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
230 (concat
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
231 "Little endian UTF-16 encoding for Emacs-supported Unicode characters."
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
232 doc)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
233
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
234 '(ccl-decode-mule-utf-16-le . ccl-encode-mule-utf-16-le)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
235 '((safe-charsets
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
236 ascii
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
237 eight-bit-control
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
238 latin-iso8859-1
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
239 mule-unicode-0100-24ff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
240 mule-unicode-2500-33ff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
241 mule-unicode-e000-ffff)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
242 (mime-charset . utf-16le)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
243 (coding-category . coding-category-utf-16-le)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
244 (valid-codes (0 . 255))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
245 (pre-write-conversion . utf-16-le-pre-write-conversion)))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
246
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
247 (make-coding-system
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
248 'mule-utf-16-be 4 ?u
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
249 (concat
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
250 "Big endian UTF-16 encoding for Emacs-supported Unicode characters."
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
251 doc)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
252
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
253 '(ccl-decode-mule-utf-16-be . ccl-encode-mule-utf-16-be)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
254 '((safe-charsets
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
255 ascii
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
256 eight-bit-control
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
257 latin-iso8859-1
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
258 mule-unicode-0100-24ff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
259 mule-unicode-2500-33ff
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
260 mule-unicode-e000-ffff)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
261 (mime-charset . utf-16be)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
262 (coding-category . coding-category-utf-16-be)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
263 (valid-codes (0 . 255))
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
264 (pre-write-conversion . utf-16-be-pre-write-conversion)))
47384
e83401f8d61c (utf-16-le-pre-write-conversion)
Dave Love <fx@gnu.org>
parents: 46677
diff changeset
265
e83401f8d61c (utf-16-le-pre-write-conversion)
Dave Love <fx@gnu.org>
parents: 46677
diff changeset
266 (register-char-codings 'mule-utf-16-le ucs-mule-to-mule-unicode)
e83401f8d61c (utf-16-le-pre-write-conversion)
Dave Love <fx@gnu.org>
parents: 46677
diff changeset
267 (register-char-codings 'mule-utf-16-be ucs-mule-to-mule-unicode))
46677
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
268
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
269 (define-coding-system-alias 'utf-16-le 'mule-utf-16-le)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
270 (define-coding-system-alias 'utf-16-be 'mule-utf-16-be)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
271
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
272 (provide 'utf-16)
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
273
86e8d59e2e49 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
274 ;;; utf-16.el ends here