610dce0c9aee7510fbafc3420a1cd7f246a6e677
[chise/xemacs-chise.git.1] / lisp / mule / cyrillic.el
1 ;;; cyrillic.el --- Support for Cyrillic -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 1995,1999 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
6
7 ;; Keywords: multilingual, Cyrillic
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;; 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; The character set ISO8859-5 is supported.
29 ;; KOI-8, Windows-1251, and ALTERNATIVNYJ are converted to ISO8859-5
30 ;; internally.
31
32 ;;; Code:
33
34 ;; Cyrillic syntax
35 (modify-syntax-entry 'cyrillic-iso8859-5 "w")
36 (modify-syntax-entry ?\e,L-\e(B ".")
37 (modify-syntax-entry ?\e,Lp\e(B ".")
38 (modify-syntax-entry ?\e,L}\e(B ".")
39
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;;; CYRILLIC
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43
44 ;; ISO-8859-5
45
46 (make-coding-system
47  'iso-8859-5 'iso2022
48  "ISO-8859-5 (ISO 2022 based 8-bit encoding for Cyrillic script)"
49  '(charset-g0 ascii
50    charset-g1 cyrillic-iso8859-5
51    charset-g2 t
52    charset-g3 t
53    mnemonic "ISO8/Cyr"
54    ))
55
56 (set-language-info-alist
57  "Cyrillic-ISO" '((charset cyrillic-iso8859-5)
58                   (tutorial . "TUTORIAL.ru")
59                   (coding-system iso-8859-5)
60                   (coding-priority iso-8859-5)
61                   (input-method . "cyrillic-yawerty")
62                   (features cyril-util)
63                   (sample-text . "Russian (\e,L@caaZXY\e(B)       \e,L7T`PRabRcYbU\e(B!")
64                   (documentation . "Support for Cyrillic ISO-8859-5."))
65  '("Cyrillic"))
66
67 ;; KOI-8
68
69 (eval-and-compile
70
71 (defvar cyrillic-koi8-r-decode-table
72   [
73    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
74    16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
75    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
76    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
77    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
78    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
79    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
80    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
81    ?\e$B(!\e(B ?\e$B("\e(B ?\e$B(#\e(B ?\e$B($\e(B ?\e$B(&\e(B ?\e$B(%\e(B ?\e$B('\e(B ?\e$B()\e(B ?\e$B((\e(B ?\e$B(*\e(B ?\e$B(+\e(B 32  ?\e$(G#'\e(B ?\e$(G#+\e(B ?\e$(G#/\e(B 32
82    32  ?\e$(C"F\e(B 32  32  ?\e$B"#\e(B 32  ?\e$B"e\e(B ?\e$A!V\e(B ?\e$A!\\e(B ?\e$A!]\e(B ?\e,L \e(B  32  ?\e,A0\e(B  ?\e,A2\e(B  ?\e,A7\e(B  ?\e,Aw\e(B
83    ?\e$(G#D\e(B 32  32  ?\e,Lq\e(B  32  32  32  32  32  32  32  32  32  32  32  ?\e$(G#E\e(B
84    32  32  ?\e$(G#G\e(B ?\e,L!\e(B  32  32  32  32  32  32  32  32  ?\e$(G#F\e(B 32  32  ?\e,A)\e(B
85    ?\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 
86    ?\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 
87    ?\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 
88    ?\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 ]
89   "Cyrillic KOI8-R decoding table.")
90
91 (defvar cyrillic-koi8-r-encode-table
92   (let ((table (make-vector 256 32))
93         (i 0))
94     (while (< i 256)
95       (let* ((ch (aref cyrillic-koi8-r-decode-table i))
96              (split (split-char ch)))
97         (cond ((eq (car split) 'cyrillic-iso8859-5)
98                (aset table (logior (nth 1 split) 128) i)
99                )
100               ((eq ch 32))
101               ((eq (car split) 'ascii)
102                (aset table ch i)
103                )))
104       (setq i (1+ i)))
105     table)
106   "Cyrillic KOI8-R encoding table.")
107
108 )
109
110 (define-ccl-program ccl-decode-koi8
111   `(3
112     ((read r0)
113      (loop
114       (write-read-repeat r0 ,cyrillic-koi8-r-decode-table))))
115   "CCL program to decode KOI8.")
116
117 (define-ccl-program ccl-encode-koi8
118   `(1
119     ((read r0)
120      (loop
121       (if (r0 != ,(charset-id 'cyrillic-iso8859-5))
122           (write-read-repeat r0)
123         ((read r0)
124          (write-read-repeat r0 , cyrillic-koi8-r-encode-table))))))
125   "CCL program to encode KOI8.")
126
127 ;; (define-coding-system-alias 'koi8-r 'cyrillic-koi8)
128 ;; (define-coding-system-alias 'koi8 'cyrillic-koi8)
129
130 (make-coding-system
131  'koi8-r 'ccl
132  "KOI8-R 8-bit encoding for Cyrillic."
133  '(decode ccl-decode-koi8
134    encode ccl-encode-koi8
135    mnemonic "KOI8"))
136
137 ;; `iso-8-1' is not correct, but XEmacs doesn't have a `ccl' category
138 (coding-system-put 'koi8-r 'category 'iso-8-1)
139
140 ;; (define-ccl-program ccl-encode-koi8-font
141 ;;   `(0
142 ;;     ((r1 |= 128)
143 ;;      (r1 = r1 ,cyrillic-koi8-r-encode-table)))
144 ;;   "CCL program to encode Cyrillic chars to KOI font.")
145
146 ;; (setq font-ccl-encoder-alist
147 ;;       (cons (cons "koi8" ccl-encode-koi8-font) font-ccl-encoder-alist))
148
149 ;; (defvar cyrillic-koi8-r-nonascii-translation-table
150 ;;   (make-translation-table-from-vector cyrillic-koi8-r-decode-table)
151 ;;   "Value of `nonascii-translation-table' in Cyrillic-KOI8 language environment..")
152
153 (set-language-info-alist
154  "Cyrillic-KOI8" '((charset cyrillic-iso8859-5)
155                    (coding-system koi8-r)
156                    (coding-priority koi8-r)
157                    (input-method . "cyrillic-yawerty")
158                    (features cyril-util)
159                    (tutorial . "TUTORIAL.ru")
160                    (sample-text . "Russian (\e,L@caaZXY\e(B)      \e,L7T`PRabRcYbU\e(B!")
161                    (documentation . "Support for Cyrillic KOI8-R."))
162  '("Cyrillic"))
163
164 ;;; WINDOWS-1251
165
166 (eval-and-compile
167
168 (defvar cyrillic-windows-1251-decode-table
169   [
170    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
171    16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
172    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
173    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
174    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
175    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
176    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
177    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
178    ?\e,L"\e(B ?\e,L#\e(B 32 ?\e,Ls\e(B 32 32 32 32 32 32 ?\e,L)\e(B 32 ?\e,L*\e(B ?\e,L,\e(B ?\e,L+\e(B ?\e,L/\e(B ;"
179    ?\e,Lr\e(B 32 32 32 32 32 32 32 32 32 ?\e,Ly\e(B 32 ?\e,Lz\e(B ?\e,L|\e(B ?\e,L{\e(B ?\e,L\7f\e(B
180    ?\e,L \e(B ?\e,L.\e(B ?\e,L~\e(B ?\e,L(\e(B ?\e,A$\e(B 32 ?\e,A&\e(B ?\e,L}\e(B ?\e,L!\e(B ?\e,A)\e(B ?\e,L$\e(B ?\e,A+\e(B ?\e,A,\e(B ?\e,L-\e(B ?\e,A.\e(B ?\e,L'\e(B
181    ?\e,A0\e(B ?\e,A1\e(B ?\e,L&\e(B ?\e,Lv\e(B 32 ?\e,A5\e(B ?\e,A6\e(B ?\e,A7\e(B ?\e,Lq\e(B ?\e,Lp\e(B ?\e,Lt\e(B ?\e,A;\e(B ?\e,Lx\e(B ?\e,L%\e(B ?\e,Lu\e(B ?\e,Lw\e(B
182   ?\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
183   ?\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
184   ?\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
185   ?\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 ]
186    "Cyrillic Windows-1251 decoding table.")
187
188 (defvar cyrillic-windows-1251-encode-table
189   (let ((table (make-vector 256 32))
190         (i 0))
191     (while (< i 256)
192       (let* ((ch (aref cyrillic-windows-1251-decode-table i))
193              (split (split-char ch)))
194         (cond ((eq (car split) 'cyrillic-iso8859-5)
195                (aset table (logior (nth 1 split) 128) i)
196                )
197               ((eq ch 32))
198               ((eq (car split) 'ascii)
199                (aset table ch i)
200                )))
201       (setq i (1+ i)))
202     table)
203   "Cyrillic Windows-1251 encoding table.")
204
205 )
206
207 (define-ccl-program ccl-decode-windows1251
208   `(3
209     ((read r0)
210      (loop
211       (write-read-repeat r0 ,cyrillic-windows-1251-decode-table))))
212   "CCL program to decode Windows-1251.")
213
214 (define-ccl-program ccl-encode-windows1251
215   `(1
216     ((read r0)
217      (loop
218       (if (r0 != ,(charset-id 'cyrillic-iso8859-5))
219           (write-read-repeat r0)
220         ((read r0)
221          (write-read-repeat r0 , cyrillic-windows-1251-encode-table))))))
222   "CCL program to encode Windows-1251.")
223
224 (make-coding-system
225  'windows-1251 'ccl
226  "Coding-system used for Windows-1251."
227  '(decode ccl-decode-windows1251
228    encode ccl-encode-windows1251
229    mnemonic "CyrW"))
230
231 ;; `iso-8-1' is not correct, but XEmacs doesn't have a `ccl' category
232 (coding-system-put 'windows-1251 'category 'iso-8-1)
233
234 (set-language-info-alist
235  "Cyrillic-Win" '((charset cyrillic-iso8859-5)
236                    (coding-system windows-1251)
237                    (coding-priority windows-1251)
238                    (input-method . "cyrillic-yawerty")
239                    (features cyril-util)
240                    (tutorial . "TUTORIAL.ru")
241                    (sample-text . "Russian (\e,L@caaZXY\e(B)      \e,L7T`PRabRcYbU\e(B!")
242                    (documentation . "Support for Cyrillic Windows-1251."))
243  '("Cyrillic"))
244
245 ;;; ALTERNATIVNYJ
246
247 (eval-and-compile
248
249 (defvar cyrillic-alternativnyj-decode-table
250   [
251    0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
252    16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
253    32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47
254    48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63
255    64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79
256    80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95
257    96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111
258    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
259    ?\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
260    ?\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
261    ?\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
262    32  32  32  32  32  32  32  32  32  32  32  32  32  32  32  32
263    32  32  32  32  32  32  32  32  32  32  32  32  32  32  32  32
264    32  32  32  32  32  32  32  32  32  32  32  32  32  32  32  32
265    ?\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
266    ?\e,L!\e(B  ?\e,Lq\e(B   32  32  32  32  32  32  32  32  32  32  32  32  32 ?\e,Lp\e(B]
267   "Cyrillic ALTERNATIVNYJ decoding table.")
268
269 (defvar cyrillic-alternativnyj-encode-table
270   (let ((table (make-vector 256 32))
271         (i 0))
272     (while (< i 256)
273       (let* ((ch (aref cyrillic-alternativnyj-decode-table i))
274              (split (split-char ch)))
275         (if (eq (car split) 'cyrillic-iso8859-5)
276             (aset table (logior (nth 1 split) 128) i)
277           (if (/= ch 32)
278               (aset table ch i))))
279       (setq i (1+ i)))
280     table)
281   "Cyrillic ALTERNATIVNYJ encoding table.")
282   
283 )
284
285
286 (define-ccl-program ccl-decode-alternativnyj
287   `(3
288     ((read r0)
289      (loop
290       (write-read-repeat r0 ,cyrillic-alternativnyj-decode-table))))
291   "CCL program to decode Alternativnyj.")
292
293 (define-ccl-program ccl-encode-alternativnyj
294   `(1
295     ((read r0)
296      (loop
297       (if (r0 != ,(charset-id 'cyrillic-iso8859-5))
298           (write-read-repeat r0)
299         ((read r0)
300          (write-read-repeat r0 ,cyrillic-alternativnyj-encode-table))))))
301   "CCL program to encode Alternativnyj.")
302
303 ;; (define-coding-system-alias 'alternativnyj 'cyrillic-alternativnyj)
304
305 (make-coding-system
306  'alternativnyj 'ccl
307  "Coding-system used for Alternativnyj"
308  '(decode ccl-decode-alternativnyj
309    encode ccl-encode-alternativnyj
310    mnemonic "Cy.Alt"))
311
312 ;; `iso-8-1' is not correct, but XEmacs doesn't have `ccl' category
313 (coding-system-put 'alternativnyj 'category 'iso-8-1)
314
315 ;; (define-ccl-program ccl-encode-alternativnyj-font
316 ;;   '(0
317 ;;     ((r1 |= 128)
318 ;;      (r1 = r1 ,cyrillic-alternativnyj-encode-table)))
319 ;;   "CCL program to encode Cyrillic chars to Alternativnyj font.")
320
321 ;; (setq font-ccl-encoder-alist
322 ;;       (cons (cons "alternativnyj" ccl-encode-alternativnyj-font)
323 ;;             font-ccl-encoder-alist))
324
325 ;; (defvar cyrillic-alternativnyj-nonascii-translation-table
326 ;;   (make-translation-table-from-vector cyrillic-alternativnyj-decode-table)
327 ;;   "Value of `nonascii-translation-table' in Cyrillic-ALT language environment.")
328
329 (set-language-info-alist
330  "Cyrillic-ALT" '((charset cyrillic-iso8859-5)
331                   (coding-system alternativnyj)
332                   (coding-priority alternativnyj)
333                   (input-method . "cyrillic-yawerty")
334                   (features cyril-util)
335                   (tutorial . "TUTORIAL.ru")
336                   (sample-text . "Russian (\e,L@caaZXY\e(B)       \e,L7T`PRabRcYbU\e(B!")
337                   (documentation . "Support for Cyrillic ALTERNATIVNYJ."))
338  '("Cyrillic"))
339
340 ;;; cyrillic.el ends here