1 ;;; mcs-xm.el --- MIME charset implementation for XEmacs-mule
3 ;; Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
8 ;; This file is part of APEL (A Portable Emacs Library).
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.
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.
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.
27 ;; This module requires Emacs 20.0.93, XEmacs 20.3-b5 (with mule)
35 (defun encode-mime-charset-region (start end charset &optional lbt)
36 "Encode the text between START and END as MIME CHARSET."
37 (let ((cs (mime-charset-to-coding-system charset lbt)))
39 (encode-coding-region start end cs)
43 (defcustom mime-charset-decoder-alist
45 '((hz-gb-2312 . decode-mime-charset-region-for-hz)
46 (t . decode-mime-charset-region-default))))
47 (if (featurep 'utf-2000)
50 '(iso-2022-jp . decode-mime-charset-region-with-iso646-unification)
51 '(iso-2022-jp-2 . decode-mime-charset-region-with-iso646-unification)
53 "Alist MIME-charset vs. decoder function."
55 :type '(repeat (cons mime-charset function)))
57 (defsubst decode-mime-charset-region-default (start end charset lbt)
58 (let ((cs (mime-charset-to-coding-system charset lbt)))
60 (decode-coding-region start end cs)
63 (unless (featurep 'utf-2000)
66 (defun decode-mime-charset-region-for-hz (start end charset lbt)
69 (narrow-to-region start end)
70 (decode-coding-region (point-min)(point-max)
71 (mime-charset-to-coding-system 'raw-text lbt))
72 (decode-hz-region (point-min)(point-max)))
73 (decode-hz-region start end)))
75 (defun decode-mime-charset-region (start end charset &optional lbt)
76 "Decode the text between START and END as MIME CHARSET."
78 (setq charset (intern (downcase charset)))
80 (let ((func (cdr (or (assq charset mime-charset-decoder-alist)
81 (assq t mime-charset-decoder-alist)))))
82 (funcall func start end charset lbt)))
84 (defsubst encode-mime-charset-string (string charset &optional lbt)
85 "Encode the STRING as MIME CHARSET."
86 (let ((cs (mime-charset-to-coding-system charset lbt)))
88 (encode-coding-string string cs)
91 ;; (defsubst decode-mime-charset-string (string charset)
92 ;; "Decode the STRING as MIME CHARSET."
93 ;; (let ((cs (mime-charset-to-coding-system charset)))
95 ;; (decode-coding-string string cs)
97 (defun decode-mime-charset-string (string charset &optional lbt)
98 "Decode the STRING as MIME CHARSET."
101 (decode-mime-charset-region (point-min)(point-max) charset lbt)
105 (defvar charsets-mime-charset-alist
106 '(((ascii) . us-ascii)
107 ((ascii latin-iso8859-1) . iso-8859-1)
108 ((ascii latin-iso8859-2) . iso-8859-2)
109 ((ascii latin-iso8859-3) . iso-8859-3)
110 ((ascii latin-iso8859-4) . iso-8859-4)
111 ((ascii cyrillic-iso8859-5) . iso-8859-5)
112 ;;; ((ascii cyrillic-iso8859-5) . koi8-r)
113 ((ascii arabic-iso8859-6) . iso-8859-6)
114 ((ascii greek-iso8859-7) . iso-8859-7)
115 ((ascii hebrew-iso8859-8) . iso-8859-8)
116 ((ascii latin-iso8859-9) . iso-8859-9)
117 ((ascii latin-jisx0201
118 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
119 ((ascii latin-jisx0201
120 katakana-jisx0201 japanese-jisx0208) . shift_jis)
121 ((ascii korean-ksc5601) . euc-kr)
122 ((ascii chinese-gb2312) . gb2312)
123 ((ascii chinese-big5-1 chinese-big5-2) . big5)
124 ((ascii thai-xtis) . tis-620)
125 ((ascii latin-iso8859-1 greek-iso8859-7
126 latin-jisx0201 japanese-jisx0208-1978
127 chinese-gb2312 japanese-jisx0208
128 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
129 ;; ((ascii latin-iso8859-1 greek-iso8859-7
130 ;; latin-jisx0201 japanese-jisx0208-1978
131 ;; chinese-gb2312 japanese-jisx0208
132 ;; korean-ksc5601 japanese-jisx0212
133 ;; chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
137 (defun coding-system-to-mime-charset (coding-system)
138 "Convert CODING-SYSTEM to a MIME-charset.
139 Return nil if corresponding MIME-charset is not found."
141 (coding-system-name (coding-system-base coding-system)))
142 (or (car (rassq coding-system mime-charset-coding-system-alist))
145 (defun mime-charset-list ()
146 "Return a list of all existing MIME-charset."
147 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
148 (rest (coding-system-list))
151 (setq cs (coding-system-name (coding-system-base (car rest))))
152 (or (rassq cs mime-charset-coding-system-alist)
154 (setq dest (cons cs dest)))
155 (setq rest (cdr rest)))
163 (product-provide (provide 'mcs-xm) (require 'apel-ver))
165 ;;; mcs-xm.el ends here