Add ethiopic, thai-xtis and vietnamese.
[chise/xemacs-chise.git] / lisp / mule / vietnamese.el
1 ;;; vietnamese.el --- Support for Vietnamese
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 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 ;; For Vietnames, the character sets VISCII and VSCII are supported.
29
30 ;;; Code:
31
32 (eval-and-compile
33
34 (defvar viet-viscii-decode-table
35   [;; VISCII is a full 8-bit code.
36    0 1 ?\e.2\eNF 3 4 ?\eNG ?\eNg 7 8 9 10 11 12 13 14 15
37    16 17 18 19 ?\e.2\eNV 21 22 23 24 ?\eN[ 26 27 28 29 ?\eN\ 31
38    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
39    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
40    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
41    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
42    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
43    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 
44    ?\e.2\eNU ?\eN! ?\eN" ?\eN# ?\eN$ ?\eN% ?\eN& ?\eN' ?\eN( ?\eN) ?\eN* ?\eN+ ?\eN, ?\eN- ?\eN. ?\eN/
45    ?\e.2\eN0 ?\eN1 ?\eN2 ?\eN5 ?\eN~ ?\eN> ?\eN6 ?\eN7 ?\eN8 ?\eNv ?\eNw ?\eNo ?\eN| ?\eN{ ?\eNx ?\eNO
46    ?\e.2\eNu ?\e.1\eN! ?\eN" ?\eN# ?\eN$ ?\eN% ?\eN& ?\eN' ?\eN( ?\eN) ?\eN* ?\eN+ ?\eN, ?\eN- ?\eN. ?\eN/
47    ?\e.1\eN0 ?\eN1 ?\eN2 ?\e.2\eN^ ?\eN= ?\e.1\eN5 ?\eN6 ?\eN7 ?\eN8 ?\e.2\eNq ?\eNQ ?\eNW ?\eNX ?\e.1\eN= ?\eN> ?\e.2\eN_
48    ?\e.2\eN` ?\eNa ?\eNb ?\eNc ?\eNd ?\eNe ?\e.1\eNF ?\eNG ?\e.2\eNh ?\eNi ?\eNj ?\eNk ?\eNl ?\eNm ?\eNn ?\e.1\eNO
49    ?\e.2\eNp ?\e.1\eNQ ?\e.2\eNr ?\eNs ?\eNt ?\e.1\eNU ?\eNV ?\eNW ?\eNX ?\e.2\eNy ?\eNz ?\e.1\eN[ ?\eN\ ?\e.2\eN} ?\e.1\eN^ ?\eN_
50    ?\e.1\eN` ?\eNa ?\eNb ?\eNc ?\eNd ?\eNe ?\eNf ?\eNg ?\eNh ?\eNi ?\eNj ?\eNk ?\eNl ?\eNm ?\eNn ?\eNo
51    ?\e.1\eNp ?\eNq ?\eNr ?\eNs ?\eNt ?\eNu ?\eNv ?\eNw ?\eNx ?\eNy ?\eNz ?\eN{ ?\eN| ?\eN} ?\eN~ ?\e.2\eNf ]
52   "Vietnamese VISCII decoding table.")
53
54 (defun split-char-or-char-int (char)
55   "Return list of charset and one or two position-codes of CHAR.
56 CHAR must be character or integer."
57   (if (characterp char)
58       (split-char char)
59     (let ((c (int-char char)))
60       (if c
61           (split-char c)
62         (list 'ascii c)
63         ))))
64
65 (defvar viet-viscii-encode-table
66   (let ((table-lower (make-vector 128 0))
67         (table-upper (make-vector 128 0))
68         (i 0)
69         char-component)
70     (while (< i 256)
71       (setq char-component
72             (split-char-or-char-int (aref viet-viscii-decode-table i)))
73       (cond ((eq (car char-component) 'vietnamese-viscii-lower)
74              (aset table-lower (nth 1 char-component) i))
75             ((eq (car char-component) 'vietnamese-viscii-upper)
76              (aset table-upper (nth 1 char-component) i)))
77       (setq i (1+ i)))
78     (cons table-lower table-upper))
79   "Vietnamese VISCII encoding table.
80 Cons of tables for encoding lower-case chars and upper-case characters.
81 Both tables are indexed by the position code of Vietnamese characters.")
82
83 (defvar viet-vscii-decode-table
84   [;; VSCII is a full 8-bit code.
85    0 ?\e.2\eNz ?\eNx 3 ?\eNW ?\eNX ?\eNf 7 8 9 10 11 12 13 14 15
86    16 ?\e.2\eNQ ?\eN_ ?\eNO ?\eNV ?\eN[ ?\eN} ?\eN\ 24 25 26 27 28 29 30 31
87    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
88    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
89    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
90    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
91    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
92    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 
93    ?\e.2\eN` ?\eNd ?\eNc ?\eNa ?\eNU ?\eN# ?\eN' ?\eNh ?\eNk ?\eN( ?\eNi ?\eN) ?\eN. ?\eNl ?\eNo ?\eNn
94    ?\e.2\eNm ?\eN8 ?\eNr ?\eNv ?\eNu ?\eNs ?\eNw ?\eN5 ?\eN6 ?\eN7 ?\eN^ ?\eN> ?\eN~ ?\eNy ?\eN| ?\eN{
95    160 ?\e.2\eNe ?\eNb ?\eNj ?\eNt ?\eN= ?\eN_ ?\eNp ?\e.1\eNe ?\eNb ?\eNj ?\eNt ?\eN> ?\eNy ?\eNp ?\e.2\eN"
96    192 193 194 195 196 ?\e.1\eN` ?\eNd ?\eNc ?\eNa ?\eNU ?\e.2\eNF ?\e.1\eN" ?\eNF ?\eNG ?\eN! ?\e.2\eNG
97    ?\e.2\eN! ?\eN% ?\eN& ?\eNg ?\eN% ?\eN+ ?\e.1\eN# ?\eN% ?\eN& ?\eNg ?\eN$ ?\eN' ?\eNh ?\e.2\eN, ?\e.1\eNk ?\eN(
98    ?\e.1\eNi ?\eN) ?\eN+ ?\eN, ?\eN- ?\eN* ?\eN. ?\eNl ?\eNo ?\e.2\eN- ?\eN* ?\eN0 ?\e.1\eNn ?\eNm ?\eN8 ?\eNr
99    ?\e.2\eN1 ?\e.1\eNv ?\eNu ?\eNs ?\eNw ?\eN0 ?\eN1 ?\eN2 ?\eN/ ?\eN5 ?\eN6 ?\eN7 ?\eN^ ?\eN> ?\eN~ ?\eNy
100    ?\e.2\eN2 ?\e.1\eN| ?\eN{ ?\eNz ?\eNx ?\eNW ?\eNX ?\eNf ?\eNQ ?\eNq ?\eNO ?\eNV ?\eN[ ?\eN} ?\eN\ ?\e.2\eN/]
101   "Vietnamese VSCII decoding table.")
102
103 (defvar viet-vscii-encode-table
104   (let ((table-lower (make-vector 128 0))
105         (table-upper (make-vector 128 0))
106         (i 0)
107         char-component)
108     (while (< i 256)
109       (setq char-component
110             (split-char-or-char-int (aref viet-vscii-decode-table i)))
111       (cond ((eq (car char-component) 'vietnamese-viscii-lower)
112              (aset table-lower (nth 1 char-component) i))
113             ((eq (car char-component) 'vietnamese-viscii-upper)
114              (aset table-upper (nth 1 char-component) i)))
115       (setq i (1+ i)))
116     (cons table-lower table-upper))
117   "Vietnamese VSCII encoding table.
118 Cons of tables for encoding lower-case chars and upper-case characters.
119 Both tables are indexed by the position code of Vietnamese characters.")
120
121 )
122
123 (define-ccl-program ccl-decode-viscii
124   `(3
125     ((read r0)
126      (loop
127       (write-read-repeat r0 ,viet-viscii-decode-table))
128      ))
129   "CCL program to decode VISCII 1.1")
130
131 ;; Multibyte form of a Vietnamese character is as follows (3-byte):
132 ;;   LEADING-CODE-PRIVATE-11 LEADING-CODE-EXTENDED-11 POSITION-CODE
133 ;; where LEADING-CODE-EXTENDED-11 for Vietnamese is
134 ;; `vietnamese-viscii-lower' or `vietnamese-viscii-upper'.
135
136 (defvar leading-code-private-11 #x9E)
137
138 (define-ccl-program ccl-encode-viscii
139   `(1
140      ((read r0)
141       (loop
142        (if (r0 < 128)
143            ;; ASCII
144            (write-read-repeat r0)
145          ;; not ASCII
146          (if (r0 != ,leading-code-private-11)
147              ;; not Vietnamese
148              (write-read-repeat r0)
149            ((read-if (r0 == ,(charset-id 'vietnamese-viscii-lower))
150              (;; Vietnamese lower
151               (read r0)
152               (r0 -= 128)
153               (write-read-repeat r0 ,(car viet-viscii-encode-table)))
154              (if (r0 == ,(charset-id 'vietnamese-viscii-upper))
155                  (;; Vietnamese upper
156                   (read r0)
157                   (r0 -= 128)
158                   (write-read-repeat r0 ,(cdr viet-viscii-encode-table)))
159                ;; not Vietnamese
160                (write-read-repeat r0)))))))))
161   "CCL program to encode VISCII 1.1")
162
163 (define-ccl-program ccl-encode-viscii-font
164   `(0
165     ;; In:  R0:vietnamese-viscii-lower/vietnamese-viscii-upper
166     ;;      R1:position code
167     ;; Out: R1:font code point
168     (if (r0 == ,(charset-id 'vietnamese-viscii-lower))
169         (r1 = r1 ,(car viet-viscii-encode-table))
170       (r1 = r1 ,(cdr viet-viscii-encode-table)))
171     )
172   "CCL program to encode Vietnamese chars to VISCII 1.1 font")
173
174 (define-ccl-program ccl-decode-vscii
175   `(3
176     ((read r0)
177      (loop
178       (write-read-repeat r0 ,viet-vscii-decode-table))
179      ))
180   "CCL program to decode VSCII-1.")
181
182 (define-ccl-program ccl-encode-vscii
183   `(1
184     ((read r0)
185      (loop
186       (if (r0 < 128)
187           ;; ASCII
188           (write-read-repeat r0)
189         ;; not ASCII 
190         (if (r0 != ,leading-code-private-11)
191             ;; not Vietnamese
192             (write-read-repeat r0)
193           (read-if (r0 == ,(charset-id 'vietnamese-viscii-lower))
194                    (;; Vietnamese lower
195                     (read r0)
196                     (r0 -= 128)
197                     (write-read-repeat r0 ,(car viet-vscii-encode-table)))
198                    (if (r0 == ,(charset-id 'vietnamese-viscii-upper))
199                        (;; Vietnamese upper
200                         (read r0)
201                         (r0 -= 128)
202                         (write-read-repeat r0 ,(cdr viet-viscii-encode-table)))
203                      ;; not Vietnamese
204                      (write-read-repeat r0))))))))
205   "CCL program to encode VSCII-1.")
206
207 (define-ccl-program ccl-encode-vscii-font
208   `(0
209     ;; In:  R0:vietnamese-viscii-lower/vietnamese-viscii-upper
210     ;;      R1:position code
211     ;; Out: R1:font code point
212     (if (r0 == ,(charset-id 'vietnamese-viscii-lower))
213         (r1 = r1 ,(car viet-vscii-encode-table))
214       (r1 = r1 ,(cdr viet-vscii-encode-table)))
215     )
216   "CCL program to encode Vietnamese chars to VSCII-1 font.")
217
218
219 (make-coding-system
220  'viscii 'ccl
221  "Coding-system used for VISCII 1.1."
222  `(mnemonic "VISCII"
223    decode ,ccl-decode-viscii
224    encode ,ccl-encode-viscii))
225
226 ;; (make-coding-system
227 ;;  'vietnamese-viscii 4 ?V
228 ;;  "8-bit encoding for Vietnamese VISCII 1.1 (MIME:VISCII)"
229 ;;  (cons ccl-decode-viscii ccl-encode-viscii))
230
231 ;; (define-coding-system-alias 'viscii 'vietnamese-viscii)
232
233 (make-coding-system
234  'vscii 'ccl
235  "Coding-system used for VSCII 1.1."
236  `(mnemonic "VSCII"
237    decode ,ccl-decode-vscii
238    encode ,ccl-encode-vscii))
239
240 ;; (make-coding-system
241 ;;  'vietnamese-vscii 4 ?v
242 ;;  "8-bit encoding for Vietnamese VSCII-1"
243 ;;  (cons ccl-decode-vscii ccl-encode-vscii))
244
245 ;; (define-coding-system-alias 'vscii 'vietnamese-vscii)
246
247 (make-coding-system
248  'viqr 'no-conversion
249  "Coding-system used for VIQR."
250  '(mnemonic "VIQR"
251    eol-type lf
252    post-read-conversion viqr-post-read-conversion
253    pre-write-conversion viqr-pre-write-conversion))
254
255 ;; (make-coding-system
256 ;;  'vietnamese-viqr 0 ?q
257 ;;  "Vietnamese latin transcription (VIQR)"
258 ;;  nil)
259 ;; (put 'vietnamese-viqr 'post-read-conversion 'viqr-post-read-conversion)
260 ;; (put 'vietnamese-viqr 'pre-write-conversion 'viqr-pre-write-conversion)
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 (set-language-info-alist
280  "Vietnamese" '((setup-function . setup-vietnamese-environment)
281                 (charset . (vietnamese-viscii-lower
282                             vietnamese-viscii-upper))
283                 (coding-system . (viscii vscii viqr))
284                 (sample-text . "Vietnamese (Ti\e.1\eN*ng Vi\eN.t)  Ch\eN`o b\eNUn")
285                 (documentation . "\
286 For Vietnamese, Emacs uses special charasets internally.
287 They can be decoded from and encoded to VISCC, VSCII, and VIQR.")
288                 ))
289
290 ;;; vietnamese.el ends here