e6133e6d927eba8757c2819c960328d2e3b1946c
[sxemacs] / lisp / mule / vietnamese.el
1 ;;; vietnamese.el --- Support for Vietnamese -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
6
7 ;; Keywords: multilingual, Vietnamese
8
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; For Vietnames, the character sets VISCII and VSCII are supported.
27
28 ;;; Code:
29 (eval-when-compile (require 'ccl))
30
31 (eval-and-compile
32
33 (defvar viet-viscii-decode-table
34   [;; VISCII is a full 8-bit code.
35    0 1 ?\e,2F\e(B 3 4 ?\e,2G\e(B ?\e,2g\e(B 7 8 9 10 11 12 13 14 15
36    16 17 18 19 ?\e,2V\e(B 21 22 23 24 ?\e,2[\e(B 26 27 28 29 ?\e,2\\e(B 31
37    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
38    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
39    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
40    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
41    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
42    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 
43    ?\e,2U\e(B ?\e,2!\e(B ?\e,2"\e(B ?\e,2#\e(B ?\e,2$\e(B ?\e,2%\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e,1b\e(B ?\e,1c\e(B ?\e,1d\e(B ?\e,1e\e(B ?\e,1f\e(B ?\e,1g\e(B ?\e,1h\e(B ?\e,1i\e(B ?\e,1j\e(B ?\e,1k\e(B ?\e,1l\e(B ?\e,1m\e(B ?\e,1n\e(B ?\e,1o\e(B
50    ?\e,1p\e(B ?\e,1q\e(B ?\e,1r\e(B ?\e,1s\e(B ?\e,1t\e(B ?\e,1u\e(B ?\e,1v\e(B ?\e,1w\e(B ?\e,1x\e(B ?\e,1y\e(B ?\e,1z\e(B ?\e,1{\e(B ?\e,1|\e(B ?\e,1}\e(B ?\e,1~\e(B ?\e,2f\e(B ]
51   "Vietnamese VISCII decoding table.")
52
53 (defvar viet-viscii-encode-table
54   (let ((table-lower (make-vector 128 0))
55         (table-upper (make-vector 128 0))
56         (i 0)
57         char-component)
58     (while (< i 256)
59       (setq char-component
60             (split-char (aref viet-viscii-decode-table i)))
61       (cond ((eq (car char-component) 'vietnamese-viscii-lower)
62              (aset table-lower (nth 1 char-component) i))
63             ((eq (car char-component) 'vietnamese-viscii-upper)
64              (aset table-upper (nth 1 char-component) i)))
65       (setq i (1+ i)))
66     (cons table-lower table-upper))
67   "Vietnamese VISCII encoding table.
68 Cons of tables for encoding lower-case chars and upper-case characters.
69 Both tables are indexed by the position code of Vietnamese characters.")
70
71 (defvar viet-vscii-decode-table
72   [;; VSCII is a full 8-bit code.
73    0 ?\e,2z\e(B ?\e,2x\e(B 3 ?\e,2W\e(B ?\e,2X\e(B ?\e,2f\e(B 7 8 9 10 11 12 13 14 15
74    16 ?\e,2Q\e(B ?\e,2_\e(B ?\e,2O\e(B ?\e,2V\e(B ?\e,2[\e(B ?\e,2}\e(B ?\e,2\\e(B 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,2`\e(B ?\e,2d\e(B ?\e,2c\e(B ?\e,2a\e(B ?\e,2U\e(B ?\e,2#\e(B ?\e,2'\e(B ?\e,2h\e(B ?\e,2k\e(B ?\e,2(\e(B ?\e,2i\e(B ?\e,2)\e(B ?\e,2.\e(B ?\e,2l\e(B ?\e,2o\e(B ?\e,2n\e(B
82    ?\e,2m\e(B ?\e,28\e(B ?\e,2r\e(B ?\e,2v\e(B ?\e,2u\e(B ?\e,2s\e(B ?\e,2w\e(B ?\e,25\e(B ?\e,26\e(B ?\e,27\e(B ?\e,2^\e(B ?\e,2>\e(B ?\e,2~\e(B ?\e,2y\e(B ?\e,2|\e(B ?\e,2{\e(B
83    160 ?\e,2e\e(B ?\e,2b\e(B ?\e,2j\e(B ?\e,2t\e(B ?\e,2=\e(B ?\e,2_\e(B ?\e,2p\e(B ?\e,1e\e(B ?\e,1b\e(B ?\e,1j\e(B ?\e,1t\e(B ?\e,1>\e(B ?\e,1y\e(B ?\e,1p\e(B ?\e,2"\e(B
84    192 193 194 195 196 ?\e,1`\e(B ?\e,1d\e(B ?\e,1c\e(B ?\e,1a\e(B ?\e,1U\e(B ?\e,2F\e(B ?\e,1"\e(B ?\e,1F\e(B ?\e,1G\e(B ?\e,1!\e(B ?\e,2G\e(B
85    ?\e,2!\e(B ?\e,2%\e(B ?\e,2&\e(B ?\e,2g\e(B ?\e,2%\e(B ?\e,2+\e(B ?\e,1#\e(B ?\e,1%\e(B ?\e,1&\e(B ?\e,1g\e(B ?\e,1$\e(B ?\e,1'\e(B ?\e,1h\e(B ?\e,2,\e(B ?\e,1k\e(B ?\e,1(\e(B
86    ?\e,1i\e(B ?\e,1)\e(B ?\e,1+\e(B ?\e,1,\e(B ?\e,1-\e(B ?\e,1*\e(B ?\e,1.\e(B ?\e,1l\e(B ?\e,1o\e(B ?\e,2-\e(B ?\e,2*\e(B ?\e,20\e(B ?\e,1n\e(B ?\e,1m\e(B ?\e,18\e(B ?\e,1r\e(B
87    ?\e,21\e(B ?\e,1v\e(B ?\e,1u\e(B ?\e,1s\e(B ?\e,1w\e(B ?\e,10\e(B ?\e,11\e(B ?\e,12\e(B ?\e,1/\e(B ?\e,15\e(B ?\e,16\e(B ?\e,17\e(B ?\e,1^\e(B ?\e,1>\e(B ?\e,1~\e(B ?\e,1y\e(B
88    ?\e,22\e(B ?\e,1|\e(B ?\e,1{\e(B ?\e,1z\e(B ?\e,1x\e(B ?\e,1W\e(B ?\e,1X\e(B ?\e,1f\e(B ?\e,1Q\e(B ?\e,1q\e(B ?\e,1O\e(B ?\e,1V\e(B ?\e,1[\e(B ?\e,1}\e(B ?\e,1\\e(B ?\e,2/\e(B]
89   "Vietnamese VSCII decoding table.")
90
91 (defvar viet-vscii-encode-table
92   (let ((table-lower (make-vector 128 0))
93         (table-upper (make-vector 128 0))
94         (i 0)
95         char-component)
96     (while (< i 256)
97       (setq char-component
98             (split-char (aref viet-vscii-decode-table i)))
99       (cond ((eq (car char-component) 'vietnamese-viscii-lower)
100              (aset table-lower (nth 1 char-component) i))
101             ((eq (car char-component) 'vietnamese-viscii-upper)
102              (aset table-upper (nth 1 char-component) i)))
103       (setq i (1+ i)))
104     (cons table-lower table-upper))
105   "Vietnamese VSCII encoding table.
106 Cons of tables for encoding lower-case chars and upper-case characters.
107 Both tables are indexed by the position code of Vietnamese characters.")
108
109 )
110
111 (define-ccl-program ccl-decode-viscii
112   `(3
113     ((read r0)
114      (loop
115       (write-read-repeat r0 ,viet-viscii-decode-table))
116      ))
117   "CCL program to decode VISCII 1.1")
118
119 ;; Multibyte form of a Vietnamese character is as follows (3-byte):
120 ;;   LEADING-CODE-PRIVATE-11 LEADING-CODE-EXTENDED-11 POSITION-CODE
121 ;; where LEADING-CODE-EXTENDED-11 for Vietnamese is
122 ;; `vietnamese-viscii-lower' or `vietnamese-viscii-upper'.
123
124 (defvar leading-code-private-11 #x9E)
125
126 (define-ccl-program ccl-encode-viscii
127   `(1
128      ((read r0)
129       (loop
130        (if (r0 < 128)
131            ;; ASCII
132            (write-read-repeat r0)
133          ;; not ASCII
134          (if (r0 != ,leading-code-private-11)
135              ;; not Vietnamese
136              (write-read-repeat r0)
137            ((read-if (r0 == ,(charset-id 'vietnamese-viscii-lower))
138              (;; Vietnamese lower
139               (read r0)
140               (r0 -= 128)
141               (write-read-repeat r0 ,(car viet-viscii-encode-table)))
142              (if (r0 == ,(charset-id 'vietnamese-viscii-upper))
143                  (;; Vietnamese upper
144                   (read r0)
145                   (r0 -= 128)
146                   (write-read-repeat r0 ,(cdr viet-viscii-encode-table)))
147                ;; not Vietnamese
148                (write-read-repeat r0)))))))))
149   "CCL program to encode VISCII 1.1")
150
151 (define-ccl-program ccl-encode-viscii-font
152   `(0
153     ;; In:  R0:vietnamese-viscii-lower/vietnamese-viscii-upper
154     ;;      R1:position code
155     ;; Out: R1:font code point
156     (if (r0 == ,(charset-id 'vietnamese-viscii-lower))
157         (r1 = r1 ,(car viet-viscii-encode-table))
158       (r1 = r1 ,(cdr viet-viscii-encode-table)))
159     )
160   "CCL program to encode Vietnamese chars to VISCII 1.1 font")
161
162 (define-ccl-program ccl-decode-vscii
163   `(3
164     ((read r0)
165      (loop
166       (write-read-repeat r0 ,viet-vscii-decode-table))
167      ))
168   "CCL program to decode VSCII-1.")
169
170 (define-ccl-program ccl-encode-vscii
171   `(1
172     ((read r0)
173      (loop
174       (if (r0 < 128)
175           ;; ASCII
176           (write-read-repeat r0)
177         ;; not ASCII 
178         (if (r0 != ,leading-code-private-11)
179             ;; not Vietnamese
180             (write-read-repeat r0)
181           (read-if (r0 == ,(charset-id 'vietnamese-viscii-lower))
182                    (;; Vietnamese lower
183                     (read r0)
184                     (r0 -= 128)
185                     (write-read-repeat r0 ,(car viet-vscii-encode-table)))
186                    (if (r0 == ,(charset-id 'vietnamese-viscii-upper))
187                        (;; Vietnamese upper
188                         (read r0)
189                         (r0 -= 128)
190                         (write-read-repeat r0 ,(cdr viet-vscii-encode-table)))
191                      ;; not Vietnamese
192                      (write-read-repeat r0))))))))
193   "CCL program to encode VSCII-1.")
194
195 (define-ccl-program ccl-encode-vscii-font
196   `(0
197     ;; In:  R0:vietnamese-viscii-lower/vietnamese-viscii-upper
198     ;;      R1:position code
199     ;; Out: R1:font code point
200     (if (r0 == ,(charset-id 'vietnamese-viscii-lower))
201         (r1 = r1 ,(car viet-vscii-encode-table))
202       (r1 = r1 ,(cdr viet-vscii-encode-table)))
203     )
204   "CCL program to encode Vietnamese chars to VSCII-1 font.")
205
206
207 (make-coding-system
208  'viscii 'ccl
209  "Coding-system used for VISCII 1.1."
210  `(mnemonic "VISCII"
211    decode ccl-decode-viscii
212    encode ccl-encode-viscii))
213
214 ;; it is not correct, but XEmacs doesn't have `ccl' category...
215 (coding-system-put 'viscii 'category 'iso-8-1)
216
217 ;; (make-coding-system
218 ;;  'vietnamese-viscii 4 ?V
219 ;;  "8-bit encoding for Vietnamese VISCII 1.1 (MIME:VISCII)"
220 ;;  '(ccl-decode-viscii . ccl-encode-viscii)
221 ;;  '((safe-charsets ascii vietnamese-viscii-lower vietnamese-viscii-upper)
222 ;;    (mime-charset . viscii)
223 ;;    (valid-codes (0 . 255))))
224
225 ;; (define-coding-system-alias 'viscii 'vietnamese-viscii)
226
227 (make-coding-system
228  'vscii 'ccl
229  "Coding-system used for VSCII 1.1."
230  `(mnemonic "VSCII"
231    decode ccl-decode-vscii
232    encode ccl-encode-vscii))
233
234 ;; (make-coding-system
235 ;;  'vietnamese-vscii 4 ?v
236 ;;  "8-bit encoding for Vietnamese VSCII-1"
237 ;;  '(ccl-decode-vscii . ccl-encode-vscii)
238 ;;  '((safe-charsets ascii vietnamese-viscii-lower vietnamese-viscii-upper)
239 ;;    (valid-codes (0 . 255))))
240
241 ;; (define-coding-system-alias 'vscii 'vietnamese-vscii)
242
243 (make-coding-system
244  'viqr 'no-conversion
245  "Coding-system used for VIQR."
246  '(mnemonic "VIQR"
247    eol-type lf
248    post-read-conversion viqr-post-read-conversion
249    pre-write-conversion viqr-pre-write-conversion))
250
251 ;; (make-coding-system
252 ;;  'vietnamese-viqr 0 ?q
253 ;;  "Vietnamese latin transcription (VIQR)"
254 ;;  nil
255 ;;  '((safe-charsets ascii vietnamese-viscii-lower vietnamese-viscii-upper)
256 ;;    (post-read-conversion . viqr-post-read-conversion)
257 ;;    (pre-write-conversion . viqr-pre-write-conversion)
258 ;;    (charset-origin-alist
259 ;;     (vietnamese-viscii-lower "VISCII" viet-encode-viscii-char)
260 ;;     (vietnamese-viscii-upper "VISCII" viet-encode-viscii-char))))
261
262 ;; (define-coding-system-alias 'viqr 'vietnamese-viqr)
263
264 ;; For VISCII users
265 (set-charset-ccl-program 'vietnamese-viscii-lower
266                          'ccl-encode-viscii-font)
267 (set-charset-ccl-program 'vietnamese-viscii-upper
268                          'ccl-encode-viscii-font)
269 ;; For VSCII users
270 (set-charset-ccl-program 'vietnamese-viscii-lower 'ccl-encode-vscii-font)
271 (set-charset-ccl-program 'vietnamese-viscii-upper 'ccl-encode-vscii-font)
272
273 ;; (setq font-ccl-encoder-alist
274 ;;       (cons (cons "viscii" ccl-encode-viscii-font) font-ccl-encoder-alist))
275
276 ;; (setq font-ccl-encoder-alist
277 ;;       (cons (cons "vscii" ccl-encode-vscii-font) font-ccl-encoder-alist))
278
279 ;; (defvar viet-viscii-nonascii-translation-table
280 ;;   (make-translation-table-from-vector viet-viscii-decode-table)
281 ;;   "Value of `nonascii-translation-table' in Vietnamese language environment.")
282
283 (set-language-info-alist
284  "Vietnamese" '((charset vietnamese-viscii-lower vietnamese-viscii-upper)
285                 (coding-system viscii vscii viqr)
286                 (coding-priority viscii)
287                 (input-method . "vietnamese-viqr")
288                 (features viet-util)
289                 (sample-text . "Vietnamese (Ti\e,1*\e(Bng Vi\e,1.\e(Bt)     Ch\e,1`\e(Bo b\e,1U\e(Bn")
290                 (documentation . "For Vietnamese, Emacs uses special charsets internally.
291 They can be decoded from and encoded to VISCC, VSCII, and VIQR.
292 Current setting put higher priority to the coding system VISCII than VSCII.
293 If you prefer VSCII, please do: (prefer-coding-system 'vietnamese-vscii)")
294                 ))
295
296 ;;; vietnamese.el ends here