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