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