~alpha, not ~ftp !
[emacs.git] / lisp / language / cyrillic.el
blobf476075cb25ae4c586a890213dfe5f06fb9fd32c
1 ;;; cyrillic.el --- support for Cyrillic -*- coding: iso-2022-7bit; -*-
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
6 ;; Keywords: multilingual, Cyrillic
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; The character set ISO8859-5 is supported. See
28 ;; http://www.ecma.ch/ecma1/STAND/ECMA-113.HTM. KOI-8 and
29 ;; ALTERNATIVNYJ are converted to ISO8859-5 internally.
31 ;;; Code:
33 ;; Cyrillic (general)
35 ;; ISO-8859-5 staff
37 (make-coding-system
38 'cyrillic-iso-8bit 2 ?5
39 "ISO 2022 based 8-bit encoding for Cyrillic script (MIME:ISO-8859-5)"
40 '(ascii cyrillic-iso8859-5 nil nil
41 nil nil nil nil nil nil nil)
42 '((safe-charsets ascii cyrillic-iso8859-5)
43 (mime-charset . iso-8859-5)))
45 (define-coding-system-alias 'iso-8859-5 'cyrillic-iso-8bit)
47 (set-language-info-alist
48 "Cyrillic-ISO" '((charset cyrillic-iso8859-5)
49 (coding-system cyrillic-iso-8bit)
50 (coding-priority cyrillic-iso-8bit)
51 (input-method . "cyrillic-yawerty")
52 (nonascii-translation . cyrillic-iso8859-5)
53 (unibyte-display . cyrillic-iso-8bit)
54 (features cyril-util)
55 (sample-text . "Russian (\e,L@caaZXY\e(B) \e,L7T`PRabRcYbU\e(B!")
56 (documentation . "Support for Cyrillic ISO-8859-5."))
57 '("Cyrillic"))
59 ;; KOI-8 staff
61 (defvar cyrillic-koi8-r-decode-table
63 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
64 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
65 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
66 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
67 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
68 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
69 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
70 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
71 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
72 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
73 160 161 162 ?\e,Lq\e(B 164 165 166 167 168 169 170 171 172 173 174 175
74 176 177 178 ?\e,L!\e(B 180 181 182 183 184 185 186 187 188 189 190 191
75 ?\e,Ln\e(B ?\e,LP\e(B ?\e,LQ\e(B ?\e,Lf\e(B ?\e,LT\e(B ?\e,LU\e(B ?\e,Ld\e(B ?\e,LS\e(B ?\e,Le\e(B ?\e,LX\e(B ?\e,LY\e(B ?\e,LZ\e(B ?\e,L[\e(B ?\e,L\\e(B ?\e,L]\e(B ?\e,L^\e(B
76 ?\e,L_\e(B ?\e,Lo\e(B ?\e,L`\e(B ?\e,La\e(B ?\e,Lb\e(B ?\e,Lc\e(B ?\e,LV\e(B ?\e,LR\e(B ?\e,Ll\e(B ?\e,Lk\e(B ?\e,LW\e(B ?\e,Lh\e(B ?\e,Lm\e(B ?\e,Li\e(B ?\e,Lg\e(B ?\e,Lj\e(B
77 ?\e,LN\e(B ?\e,L0\e(B ?\e,L1\e(B ?\e,LF\e(B ?\e,L4\e(B ?\e,L5\e(B ?\e,LD\e(B ?\e,L3\e(B ?\e,LE\e(B ?\e,L8\e(B ?\e,L9\e(B ?\e,L:\e(B ?\e,L;\e(B ?\e,L<\e(B ?\e,L=\e(B ?\e,L>\e(B
78 ?\e,L?\e(B ?\e,LO\e(B ?\e,L@\e(B ?\e,LA\e(B ?\e,LB\e(B ?\e,LC\e(B ?\e,L6\e(B ?\e,L2\e(B ?\e,LL\e(B ?\e,LK\e(B ?\e,L7\e(B ?\e,LH\e(B ?\e,LM\e(B ?\e,LI\e(B ?\e,LG\e(B ?\e,LJ\e(B ]
79 "Cyrillic KOI8-R decoding table.")
81 (let ((table (make-translation-table-from-vector
82 cyrillic-koi8-r-decode-table)))
83 (define-translation-table 'cyrillic-koi8-r-nonascii-translation-table table)
84 (define-translation-table 'cyrillic-koi8-r-encode-table
85 (char-table-extra-slot table 0)))
87 (define-ccl-program ccl-decode-koi8
88 `(3
89 ((loop
90 (r0 = 0)
91 (read r1)
92 (if (r1 < 128)
93 (write-repeat r1)
94 ((translate-character cyrillic-koi8-r-nonascii-translation-table r0 r1)
95 (write-multibyte-character r0 r1)
96 (repeat))))))
97 "CCL program to decode KOI8.")
99 (define-ccl-program ccl-encode-koi8
101 ((loop
102 (read-multibyte-character r0 r1)
103 (if (r0 == ,(charset-id 'cyrillic-iso8859-5))
104 (translate-character cyrillic-koi8-r-encode-table r0 r1))
105 (if (r0 != ,(charset-id 'eight-bit-graphic))
106 (if (r0 != ,(charset-id 'eight-bit-control))
107 (r1 = ??)))
108 (write-repeat r1))))
109 "CCL program to encode KOI8.")
111 (make-coding-system
112 'cyrillic-koi8 4
113 ;; We used to use ?K. It is true that ?K is more strictly correct,
114 ;; but it is also used for Korean.
115 ;; So people who use koi8 for languages other than Russian
116 ;; will have to forgive us.
117 ?R "KOI8 8-bit encoding for Cyrillic (MIME: KOI8-R)"
118 '(ccl-decode-koi8 . ccl-encode-koi8)
119 `((safe-chars . ,(let ((table (make-char-table 'safe-chars))
120 (i 0))
121 (while (< i 256)
122 (aset table (aref cyrillic-koi8-r-decode-table i) t)
123 (setq i (1+ i)))
124 table))
125 (mime-charset . koi8-r)
126 (valid-codes (0 . 127) 163 179 (192 . 255))
127 (charset-origin-alist (cyrillic-iso8859-5 "KOI8-R"
128 cyrillic-encode-koi8-r-char))))
130 (define-coding-system-alias 'koi8-r 'cyrillic-koi8)
131 (define-coding-system-alias 'koi8 'cyrillic-koi8)
133 (define-ccl-program ccl-encode-koi8-font
135 ((translate-character cyrillic-koi8-r-encode-table r0 r1)))
136 "CCL program to encode Cyrillic chars to KOI font.")
138 (setq font-ccl-encoder-alist
139 (cons '("koi8" . ccl-encode-koi8-font) font-ccl-encoder-alist))
141 (set-language-info-alist
142 "Cyrillic-KOI8" `((charset cyrillic-iso8859-5)
143 (nonascii-translation
144 . ,(get 'cyrillic-koi8-r-nonascii-translation-table
145 'translation-table))
146 (coding-system cyrillic-koi8)
147 (coding-priority cyrillic-koi8)
148 (input-method . "cyrillic-jcuken")
149 (features cyril-util)
150 (unibyte-display . cyrillic-koi8)
151 (sample-text . "Russian (\e,L@caaZXY\e(B) \e,L7T`PRabRcYbU\e(B!")
152 (documentation . "Support for Cyrillic KOI8-R."))
153 '("Cyrillic"))
155 ;;; ALTERNATIVNYJ stuff
157 (defvar cyrillic-alternativnyj-decode-table
159 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
160 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
161 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
162 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
163 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
164 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
165 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
166 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
167 ?\e,L0\e(B ?\e,L1\e(B ?\e,L2\e(B ?\e,L3\e(B ?\e,L4\e(B ?\e,L5\e(B ?\e,L6\e(B ?\e,L7\e(B ?\e,L8\e(B ?\e,L9\e(B ?\e,L:\e(B ?\e,L;\e(B ?\e,L<\e(B ?\e,L=\e(B ?\e,L>\e(B ?\e,L?\e(B
168 ?\e,L@\e(B ?\e,LA\e(B ?\e,LB\e(B ?\e,LC\e(B ?\e,LD\e(B ?\e,LE\e(B ?\e,LF\e(B ?\e,LG\e(B ?\e,LH\e(B ?\e,LI\e(B ?\e,LJ\e(B ?\e,LK\e(B ?\e,LL\e(B ?\e,LM\e(B ?\e,LN\e(B ?\e,LO\e(B
169 ?\e,LP\e(B ?\e,LQ\e(B ?\e,LR\e(B ?\e,LS\e(B ?\e,LT\e(B ?\e,LU\e(B ?\e,LV\e(B ?\e,LW\e(B ?\e,LX\e(B ?\e,LY\e(B ?\e,LZ\e(B ?\e,L[\e(B ?\e,L\\e(B ?\e,L]\e(B ?\e,L^\e(B ?\e,L_\e(B
170 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
171 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
172 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
173 ?\e,L`\e(B ?\e,La\e(B ?\e,Lb\e(B ?\e,Lc\e(B ?\e,Ld\e(B ?\e,Le\e(B ?\e,Lf\e(B ?\e,Lg\e(B ?\e,Lh\e(B ?\e,Li\e(B ?\e,Lj\e(B ?\e,Lk\e(B ?\e,Ll\e(B ?\e,Lm\e(B ?\e,Ln\e(B ?\e,Lo\e(B
174 ?\e,L!\e(B ?\e,Lq\e(B ?\e,L$\e(B ?\e,Lt\e(B ?\e,L'\e(B ?\e,Lw\e(B ?\e,L.\e(B ?\e,L~\e(B 248 249 250 251 ?\e,Lp\e(B 253 254 ?\e,L \e(B]
175 "Cyrillic ALTERNATIVNYJ decoding table.")
177 (let ((table (make-translation-table-from-vector
178 cyrillic-alternativnyj-decode-table)))
179 (define-translation-table 'cyrillic-alternativnyj-nonascii-translation-table
180 table)
181 (define-translation-table 'cyrillic-alternativnyj-encode-table
182 (char-table-extra-slot table 0)))
185 (define-ccl-program ccl-decode-alternativnyj
187 ((loop
188 (r0 = 0)
189 (read r1)
190 (if (r1 < 128)
191 (write-repeat r1)
192 ((translate-character cyrillic-alternativnyj-nonascii-translation-table
193 r0 r1)
194 (write-multibyte-character r0 r1)
195 (repeat))))))
196 "CCL program to decode Alternativnyj.")
198 (define-ccl-program ccl-encode-alternativnyj
200 ((loop
201 (read-multibyte-character r0 r1)
202 (translate-character cyrillic-alternativnyj-encode-table r0 r1)
203 (if (r0 != ,(charset-id 'eight-bit-graphic))
204 (if (r0 != ,(charset-id 'eight-bit-control))
205 (r1 = ??)))
206 (write-repeat r1))))
207 "CCL program to encode Alternativnyj.")
209 (make-coding-system
210 'cyrillic-alternativnyj 4 ?A
211 "ALTERNATIVNYJ 8-bit encoding for Cyrillic"
212 '(ccl-decode-alternativnyj . ccl-encode-alternativnyj)
213 `((safe-chars . ,(let ((table (make-char-table 'safe-chars))
214 (i 0))
215 (while (< i 256)
216 (aset table (aref cyrillic-alternativnyj-decode-table i)
218 (setq i (1+ i)))
219 table))
220 (valid-codes (0 . 175) (224 . 241) 255)))
223 (define-coding-system-alias 'alternativnyj 'cyrillic-alternativnyj)
225 (define-ccl-program ccl-encode-alternativnyj-font
227 ((translate-character cyrillic-alternativnyj-encode-table r0 r1)))
228 "CCL program to encode Cyrillic chars to Alternativnyj font.")
230 (setq font-ccl-encoder-alist
231 (cons '("alternativnyj" . ccl-encode-alternativnyj-font)
232 font-ccl-encoder-alist))
234 (set-language-info-alist
235 "Cyrillic-ALT" `((charset cyrillic-iso8859-5)
236 (nonascii-translation
237 . ,(get 'cyrillic-alternativnyj-nonascii-translation-table
238 'translation-table))
239 (coding-system cyrillic-alternativnyj)
240 (coding-priority cyrillic-alternativnyj)
241 (input-method . "cyrillic-jcuken")
242 (features cyril-util)
243 (unibyte-display . cyrillic-alternativnyj)
244 (sample-text . "Russian (\e,L@caaZXY\e(B) \e,L7T`PRabRcYbU\e(B!")
245 (documentation . "Support for Cyrillic ALTERNATIVNYJ."))
246 '("Cyrillic"))
248 (provide 'cyrillic)
250 ;;; cyrillic.el ends here