* pccl-om.el (ccl-cascading-read): New facility.
[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)
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)))
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)
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)))
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 latin-iso8859-1 greek-iso8859-7
85             latin-jisx0201 japanese-jisx0208-1978
86             chinese-gb2312 japanese-jisx0208
87             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
88     ((ascii latin-iso8859-1 greek-iso8859-7
89             latin-jisx0201 japanese-jisx0208-1978
90             chinese-gb2312 japanese-jisx0208
91             korean-ksc5601 japanese-jisx0212
92             chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
93     ((ascii latin-iso8859-1 latin-iso8859-2
94             cyrillic-iso8859-5 greek-iso8859-7
95             latin-jisx0201 japanese-jisx0208-1978
96             chinese-gb2312 japanese-jisx0208
97             korean-ksc5601 japanese-jisx0212
98             chinese-cns11643-1 chinese-cns11643-2
99             chinese-cns11643-3 chinese-cns11643-4
100             chinese-cns11643-5 chinese-cns11643-6
101             chinese-cns11643-7)                         . iso-2022-int-1)
102     ))
103
104
105 (defun coding-system-to-mime-charset (coding-system)
106   "Convert CODING-SYSTEM to a MIME-charset.
107 Return nil if corresponding MIME-charset is not found."
108   (or (car (rassq coding-system mime-charset-coding-system-alist))
109       (coding-system-get coding-system 'mime-charset)))
110
111 (defun mime-charset-list ()
112   "Return a list of all existing MIME-charset."
113   (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
114         (rest coding-system-list)
115         cs)
116     (while rest
117       (setq cs (car rest))
118       (unless (rassq cs mime-charset-coding-system-alist)
119         (if (setq cs (coding-system-get cs 'mime-charset))
120             (or (rassq cs mime-charset-coding-system-alist)
121                 (memq cs dest)  
122                 (setq dest (cons cs dest))
123                 )))
124       (setq rest (cdr rest)))
125     dest))
126
127
128 ;;; @ end
129 ;;;
130
131 (require 'mcs-20)
132
133 (provide 'mcs-e20)
134
135 ;;; mcs-e20.el ends here