This commit was manufactured by cvs2svn to create branch 'XEmacs-21_4'.
[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.  KOI-8 and ALTERNATIVNYJ
29 ;; are converted to ISO8859-5 internally.
30
31 ;;; Code:
32
33 ;; For syntax of Cyrillic
34 (modify-syntax-entry 'cyrillic-iso8859-5 "w")
35 (modify-syntax-entry ?\e,L-\e(B ".")
36 (modify-syntax-entry ?\e,Lp\e(B ".")
37 (modify-syntax-entry ?\e,L}\e(B ".")
38
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;;; CYRILLIC
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42
43 ;; ISO-8859-5 staff
44
45 ;; (make-coding-system
46 ;;  'cyrillic-iso-8bit 2 ?5
47 ;;  "ISO 2022 based 8-bit encoding for Cyrillic script (MIME:ISO-8859-5)"
48 ;;  '(ascii cyrillic-iso8859-5  nil nil
49 ;;    nil nil nil nil nil nil nil)
50 ;;  '((safe-charsets ascii cyrillic-iso8859-5)
51 ;;    (mime-charset . iso-8859-5)))
52
53 ;; (define-coding-system-alias 'iso-8859-5 'cyrillic-iso-8bit)
54
55 (make-coding-system
56  'iso-8859-5 'iso2022
57  "MIME ISO-8859-5"
58  '(charset-g0 ascii
59    charset-g1 cyrillic-iso8859-5
60    charset-g2 t
61    charset-g3 t
62    mnemonic "ISO8/Cyr"
63    ))
64
65 (set-language-info-alist
66  "Cyrillic-ISO" '((charset cyrillic-iso8859-5)
67                   (tutorial . "TUTORIAL.ru")
68                   (coding-system iso-8859-5)
69                   (coding-priority iso-8859-5)
70                   (input-method . "cyrillic-yawerty")
71                   (features cyril-util)
72                   (sample-text . "Russian (\e,L@caaZXY\e(B)       \e,L7T`PRabRcYbU\e(B!")
73                   (documentation . "Support for Cyrillic ISO-8859-5."))
74  '("Cyrillic"))
75
76 ;; KOI-8 staff
77
78 (eval-and-compile
79
80 (defvar cyrillic-koi8-r-decode-table
81   [
82    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
83    16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
84    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
85    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
86    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
87    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
88    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
89    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
90    ?\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
91    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!\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yrillic KOI8-R decoding table.")
99
100 (defvar cyrillic-koi8-r-encode-table
101   (let ((table (make-vector 256 32))
102         (i 0))
103     (while (< i 256)
104       (let* ((ch (aref cyrillic-koi8-r-decode-table i))
105              (split (split-char ch)))
106         (cond ((eq (car split) 'cyrillic-iso8859-5)
107                (aset table (logior (nth 1 split) 128) i)
108                )
109               ((eq ch 32))
110               ((eq (car split) 'ascii)
111                (aset table ch i)
112                )))
113       (setq i (1+ i)))
114     table)
115   "Cyrillic KOI8-R encoding table.")
116
117 )
118
119 (define-ccl-program ccl-decode-koi8
120   `(3
121     ((read r0)
122      (loop
123       (write-read-repeat r0 ,cyrillic-koi8-r-decode-table))))
124   "CCL program to decode KOI8.")
125
126 (define-ccl-program ccl-encode-koi8
127   `(1
128     ((read r0)
129      (loop
130       (if (r0 != ,(charset-id 'cyrillic-iso8859-5))
131           (write-read-repeat r0)
132         ((read r0)
133          (write-read-repeat r0 , cyrillic-koi8-r-encode-table))))))
134   "CCL program to encode KOI8.")
135
136 ;; (make-coding-system
137 ;;  'cyrillic-koi8 4
138 ;;  ;; We used to use ?K.  It is true that ?K is more strictly correct,
139 ;;  ;; but it is also used for Korean.
140 ;;  ;; So people who use koi8 for languages other than Russian
141 ;;  ;; will have to forgive us.
142 ;;  ?R "KOI8 8-bit encoding for Cyrillic (MIME: KOI8-R)"
143 ;;  '(ccl-decode-koi8 . ccl-encode-koi8)
144 ;;  '((safe-charsets ascii cyrillic-iso8859-5)
145 ;;    (mime-charset . koi8-r)
146 ;;    (valid-codes (0 . 127) 163 179 (192 . 255))
147 ;;    (charset-origin-alist (cyrillic-iso8859-5 "KOI8-R"
148 ;;                                              cyrillic-encode-koi8-r-char))))
149
150 ;; (define-coding-system-alias 'koi8-r 'cyrillic-koi8)
151 ;; (define-coding-system-alias 'koi8 'cyrillic-koi8)
152
153 (make-coding-system
154  'koi8-r 'ccl
155  "Coding-system used for KOI8-R."
156  `(decode ,ccl-decode-koi8
157    encode ,ccl-encode-koi8
158    mnemonic "KOI8"))
159
160 ;; it is not correct, but XEmacs doesn't have `ccl' category...
161 (coding-system-put 'koi8-r 'category 'iso-8-1)
162
163 ;; (define-ccl-program ccl-encode-koi8-font
164 ;;   `(0
165 ;;     ((r1 |= 128)
166 ;;      (r1 = r1 ,cyrillic-koi8-r-encode-table)))
167 ;;   "CCL program to encode Cyrillic chars to KOI font.")
168
169 ;; (setq font-ccl-encoder-alist
170 ;;       (cons (cons "koi8" ccl-encode-koi8-font) font-ccl-encoder-alist))
171
172 ;; (defvar cyrillic-koi8-r-nonascii-translation-table
173 ;;   (make-translation-table-from-vector cyrillic-koi8-r-decode-table)
174 ;;   "Value of `nonascii-translation-table' in Cyrillic-KOI8 language environment..")
175
176 (set-language-info-alist
177  "Cyrillic-KOI8" '((charset cyrillic-iso8859-5)
178                    (coding-system koi8-r)
179                    (coding-priority koi8-r)
180                    (input-method . "cyrillic-yawerty")
181                    (features cyril-util)
182                    (tutorial . "TUTORIAL.ru")
183                    (sample-text . "Russian (\e,L@caaZXY\e(B)      \e,L7T`PRabRcYbU\e(B!")
184                    (documentation . "Support for Cyrillic KOI8-R."))
185  '("Cyrillic"))
186
187 ;;; ALTERNATIVNYJ staff
188
189 (eval-and-compile
190
191 (defvar cyrillic-alternativnyj-decode-table
192   [
193    0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
194    16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
195    32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47
196    48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63
197    64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79
198    80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95
199    96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111
200    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
201    ?\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
202    ?\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
203    ?\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
204    32  32  32  32  32  32  32  32  32  32  32  32  32  32  32  32
205    32  32  32  32  32  32  32  32  32  32  32  32  32  32  32  32
206    32  32  32  32  32  32  32  32  32  32  32  32  32  32  32  32
207    ?\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
208    ?\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]
209   "Cyrillic ALTERNATIVNYJ decoding table.")
210
211 (defvar cyrillic-alternativnyj-encode-table
212   (let ((table (make-vector 256 32))
213         (i 0))
214     (while (< i 256)
215       (let* ((ch (aref cyrillic-alternativnyj-decode-table i))
216              (split (split-char ch)))
217         (if (eq (car split) 'cyrillic-iso8859-5)
218             (aset table (logior (nth 1 split) 128) i)
219           (if (/= ch 32)
220               (aset table ch i))))
221       (setq i (1+ i)))
222     table)
223   "Cyrillic ALTERNATIVNYJ encoding table.")
224   
225 )
226
227
228 (define-ccl-program ccl-decode-alternativnyj
229   `(3
230     ((read r0)
231      (loop
232       (write-read-repeat r0 ,cyrillic-alternativnyj-decode-table))))
233   "CCL program to decode Alternativnyj.")
234
235 (define-ccl-program ccl-encode-alternativnyj
236   `(1
237     ((read r0)
238      (loop
239       (if (r0 != ,(charset-id 'cyrillic-iso8859-5))
240           (write-read-repeat r0)
241         ((read r0)
242          (write-read-repeat r0 ,cyrillic-alternativnyj-encode-table))))))
243   "CCL program to encode Alternativnyj.")
244
245 ;; (make-coding-system
246 ;;  'cyrillic-alternativnyj 4 ?A
247 ;;  "ALTERNATIVNYJ 8-bit encoding for Cyrillic"
248 ;;  '(ccl-decode-alternativnyj . ccl-encode-alternativnyj)
249 ;;  '((safe-charsets ascii cyrillic-iso8859-5)
250 ;;    (valid-codes (0 . 175) (224 . 241) 255)
251 ;;    (charset-origin-alist (cyrillic-iso8859-5 "ALTERNATIVNYJ"
252 ;;                                              cyrillic-encode-koi8-r-char))))
253
254
255 ;; (define-coding-system-alias 'alternativnyj 'cyrillic-alternativnyj)
256
257 (make-coding-system
258  'alternativnyj 'ccl
259  "Coding-system used for Alternativnyj"
260  `(decode ,ccl-decode-alternativnyj
261    encode ,ccl-encode-alternativnyj
262    mnemonic "Cy.Alt"))
263
264 ;; it is not correct, but XEmacs doesn't have `ccl' category...
265 (coding-system-put 'alternativnyj 'category 'iso-8-1)
266
267 ;; (define-ccl-program ccl-encode-alternativnyj-font
268 ;;   '(0
269 ;;     ((r1 |= 128)
270 ;;      (r1 = r1 ,cyrillic-alternativnyj-encode-table)))
271 ;;   "CCL program to encode Cyrillic chars to Alternativnyj font.")
272
273 ;; (setq font-ccl-encoder-alist
274 ;;       (cons (cons "alternativnyj" ccl-encode-alternativnyj-font)
275 ;;             font-ccl-encoder-alist))
276
277 ;; (defvar cyrillic-alternativnyj-nonascii-translation-table
278 ;;   (make-translation-table-from-vector cyrillic-alternativnyj-decode-table)
279 ;;   "Value of `nonascii-translation-table' in Cyrillic-ALT language environment.")
280
281 (set-language-info-alist
282  "Cyrillic-ALT" '((charset cyrillic-iso8859-5)
283                   (coding-system alternativnyj)
284                   (coding-priority alternativnyj)
285                   (input-method . "cyrillic-yawerty")
286                   (features cyril-util)
287                   (tutorial . "TUTORIAL.ru")
288                   (sample-text . "Russian (\e,L@caaZXY\e(B)       \e,L7T`PRabRcYbU\e(B!")
289                   (documentation . "Support for Cyrillic ALTERNATIVNYJ."))
290  '("Cyrillic"))
291
292 ;;; cyrillic.el ends here