Initial Commit
[packages] / xemacs-packages / mew / mew / mew-mule.el
1 ;;; mew-mule.el --- Environment of Mule common for Mew
2
3 ;; Author:  Kazu Yamamoto <Kazu@Mew.org>
4 ;; Created: Jul 15, 1998
5 ;; Revised: Aug 30, 1999
6
7 ;;; Code:
8
9 (defconst mew-mule-version "mew-mule.el version 0.03")
10 (require 'mew-func)
11 (if (featurep 'mule)
12     (require 'mew-lang-jp))
13 ;;
14 ;; Charset
15 ;;
16
17 (defun mew-charset-guess-string (str)
18   (save-excursion
19     (mew-set-buffer-tmp)
20     (insert-string str)
21     (mew-charset-guess-region (point-min) (point-max))))
22
23 (defun mew-charset-guess-region (beg end)
24   "Guess minimum charset name."
25   (interactive "r")
26   (if (not mew-mule-p)
27       (save-excursion
28         (goto-char beg)
29         (if (re-search-forward "[\200-\377]" end t)
30             "iso-8859-1"
31           mew-us-ascii))
32     (let* ((tcsl (mew-find-cs-region beg end))
33            (N (length tcsl))
34            (alst mew-cs-database)
35            i a acsl aret csl ret)
36       (while alst
37         (setq a (car alst))
38         (setq acsl (nth 1 a))
39         (setq aret (nth 0 a))
40         (setq alst (cdr alst))
41         (catch 'loop
42           (setq i 0)
43           (while (< i N)
44             (if (member (nth i tcsl) acsl)
45                 ()
46               (setq aret nil)
47               (setq acsl nil)
48               (throw 'loop nil))
49             (setq i (1+ i))))
50         (if (null ret)
51             (setq ret aret)
52           (if (and acsl (< (length acsl) (length csl)))
53               (setq ret aret csl acsl))))
54       (or ret mew-error-charset-unknown))))
55
56 (defun mew-charset-sanity-check (beg end)
57   "Eliminate illegal characters"
58   (interactive "r")
59   (if (and (not (equal mew-mule-ver 0))
60            (member mew-lc-kana (mew-find-cs-region beg end)))
61       (progn
62         (require 'mew-lang-jp)
63         (mew-zenkaku-katakana-region beg end)
64         (message "Converted Hankaku Kana to Zenkaku Kana!!")
65         (ding)
66         (sit-for 1))))
67
68 (defvar mew-charset-list
69   (mapcar (function (lambda (x) (nth 0 x))) mew-cs-database))
70
71 (defun mew-charset-to-data (charset)
72   (if charset
73       (mew-assoc-case-equal charset mew-cs-database 0)))
74
75 (defun mew-charset-to-cs (charset)
76   (if charset
77       (nth 2 (mew-assoc-case-equal charset mew-cs-database 0))))
78
79 (defun mew-charset-to-cte (charset)
80   (if charset
81       ;; used for body
82       (nth 3 (mew-assoc-case-equal charset mew-cs-database 0))))
83
84 (provide 'mew-mule)
85
86 ;;; Copyright Notice:
87
88 ;; Copyright (C) 1998, 1999 Mew developing team.
89 ;; All rights reserved.
90
91 ;; Redistribution and use in source and binary forms, with or without
92 ;; modification, are permitted provided that the following conditions
93 ;; are met:
94 ;; 
95 ;; 1. Redistributions of source code must retain the above copyright
96 ;;    notice, this list of conditions and the following disclaimer.
97 ;; 2. Redistributions in binary form must reproduce the above copyright
98 ;;    notice, this list of conditions and the following disclaimer in the
99 ;;    documentation and/or other materials provided with the distribution.
100 ;; 3. Neither the name of the team nor the names of its contributors
101 ;;    may be used to endorse or promote products derived from this software
102 ;;    without specific prior written permission.
103 ;; 
104 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
105 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
106 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
107 ;; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
108 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
111 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
112 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
113 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
114 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115
116 ;;; mew-mule.el ends here