(charsets-mime-charset-alist): Add setting for `tis-620'.
[elisp/apel.git] / mcs-e20.el
1 ;;; mcs-e20.el --- MIME charset implementation for Emacs 20.1 and 20.2
2
3 ;; Copyright (C) 1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
7
8 ;; This file is part of APEL (A Portable Emacs Library).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;    This module requires Emacs 20.1 and 20.2.
28
29 ;;; Code:
30
31 (defsubst encode-mime-charset-region (start end charset &optional lbt)
32   "Encode the text between START and END as MIME CHARSET."
33   (let (cs)
34     (if (and enable-multibyte-characters
35              (setq cs (mime-charset-to-coding-system charset lbt)))
36         (encode-coding-region start end cs)
37       )))
38
39 (defsubst decode-mime-charset-region (start end charset &optional lbt)
40   "Decode the text between START and END as MIME CHARSET."
41   (let (cs)
42     (if (and enable-multibyte-characters
43              (setq cs (mime-charset-to-coding-system charset lbt)))
44         (decode-coding-region start end cs)
45       )))
46
47
48 (defsubst encode-mime-charset-string (string charset &optional lbt)
49   "Encode the STRING as MIME CHARSET."
50   (let (cs)
51     (if (and enable-multibyte-characters
52              (setq cs (mime-charset-to-coding-system charset lbt)))
53         (encode-coding-string string cs)
54       string)))
55
56 (defsubst decode-mime-charset-string (string charset &optional lbt)
57   "Decode the STRING as MIME CHARSET."
58   (let (cs)
59     (if (and enable-multibyte-characters
60              (setq cs (mime-charset-to-coding-system charset lbt)))
61         (decode-coding-string string cs)
62       string)))
63
64
65 (defvar charsets-mime-charset-alist
66   '(((ascii)                                            . us-ascii)
67     ((ascii latin-iso8859-1)                            . iso-8859-1)
68     ((ascii latin-iso8859-2)                            . iso-8859-2)
69     ((ascii latin-iso8859-3)                            . iso-8859-3)
70     ((ascii latin-iso8859-4)                            . iso-8859-4)
71 ;;; ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
72     ((ascii cyrillic-iso8859-5)                         . koi8-r)
73     ((ascii arabic-iso8859-6)                           . iso-8859-6)
74     ((ascii greek-iso8859-7)                            . iso-8859-7)
75     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
76     ((ascii latin-iso8859-9)                            . iso-8859-9)
77     ((ascii latin-jisx0201
78             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
79     ((ascii latin-jisx0201
80             katakana-jisx0201 japanese-jisx0208)        . shift_jis)
81     ((ascii korean-ksc5601)                             . euc-kr)
82     ((ascii chinese-gb2312)                             . gb2312)
83     ((ascii chinese-big5-1 chinese-big5-2)              . big5)
84     ((ascii thai-tis620 composition)                    . tis-620)
85     ((ascii latin-iso8859-1 greek-iso8859-7
86             latin-jisx0201 japanese-jisx0208-1978
87             chinese-gb2312 japanese-jisx0208
88             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
89 ;     ((ascii latin-iso8859-1 greek-iso8859-7
90 ;           latin-jisx0201 japanese-jisx0208-1978
91 ;           chinese-gb2312 japanese-jisx0208
92 ;           korean-ksc5601 japanese-jisx0212
93 ;           chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
94 ;     ((ascii latin-iso8859-1 latin-iso8859-2
95 ;           cyrillic-iso8859-5 greek-iso8859-7
96 ;           latin-jisx0201 japanese-jisx0208-1978
97 ;           chinese-gb2312 japanese-jisx0208
98 ;           korean-ksc5601 japanese-jisx0212
99 ;           chinese-cns11643-1 chinese-cns11643-2
100 ;           chinese-cns11643-3 chinese-cns11643-4
101 ;           chinese-cns11643-5 chinese-cns11643-6
102 ;           chinese-cns11643-7)                         . iso-2022-int-1)
103     ))
104
105 (defun-maybe coding-system-get (coding-system prop)
106   "Extract a value from CODING-SYSTEM's property list for property PROP."
107   (plist-get (coding-system-plist coding-system) prop)
108   )
109
110 (defun coding-system-to-mime-charset (coding-system)
111   "Convert CODING-SYSTEM to a MIME-charset.
112 Return nil if corresponding MIME-charset is not found."
113   (or (car (rassq coding-system mime-charset-coding-system-alist))
114       (coding-system-get coding-system 'mime-charset)
115       ))
116
117 (defun-maybe-cond mime-charset-list ()
118   "Return a list of all existing MIME-charset."
119   ((boundp 'coding-system-list)
120    (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
121          (rest coding-system-list)
122          cs)
123      (while rest
124        (setq cs (car rest))
125        (unless (rassq cs mime-charset-coding-system-alist)
126          (if (setq cs (coding-system-get cs 'mime-charset))
127              (or (rassq cs mime-charset-coding-system-alist)
128                  (memq cs dest)  
129                  (setq dest (cons cs dest))
130                  )))
131        (setq rest (cdr rest)))
132      dest))
133    (t
134     (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
135           (rest (coding-system-list))
136           cs)
137       (while rest
138         (setq cs (car rest))
139         (unless (rassq cs mime-charset-coding-system-alist)
140           (when (setq cs (or (coding-system-get cs 'mime-charset)
141                              (and
142                               (setq cs (aref
143                                         (coding-system-get cs 'coding-spec)
144                                         2))
145                               (string-match "(MIME:[ \t]*\\([^,)]+\\)" cs)
146                               (match-string 1 cs))))
147             (setq cs (intern (downcase cs)))
148             (or (rassq cs mime-charset-coding-system-alist)
149                 (memq cs dest)
150                 (setq dest (cons cs dest))
151                 )))
152         (setq rest (cdr rest)))
153       dest)
154     ))
155
156 ;;; @ end
157 ;;;
158
159 (require 'mcs-20)
160
161 (provide 'mcs-e20)
162
163 ;;; mcs-e20.el ends here